diff --git a/.ci/merge-fixes.sh b/.ci/merge-fixes.sh index 1fb8267df0e..8ee138660ec 100755 --- a/.ci/merge-fixes.sh +++ b/.ci/merge-fixes.sh @@ -14,10 +14,10 @@ else git tag -f test_base git commit -q -m "Uncommitted changes" --no-allow-empty -a for a in $PRs; do + git fetch --unshallow --all > /dev/null 2>&1 && echo "Unshallowed." echo "::group::Merging PR https://github.com/$REPO/pull/$a" git tag -f test_head $GH pr checkout -b pr-$a $a - git fetch --unshallow --all git checkout -q test_head if git merge --no-edit --squash -q pr-$a; then echo "::endgroup::" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7ac9c6154d0..5f466d3a285 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -193,11 +193,12 @@ jobs: run: | ./venv/bin/python3 -m coverage combine src/.coverage/ ./venv/bin/python3 -m coverage xml - find . -name *coverage* + mkdir -p coverage-report + mv coverage.xml coverage-report/ working-directory: ./worktree-image - name: Upload coverage to codecov if: always() && steps.build.outcome == 'success' uses: codecov/codecov-action@v3 with: - files: ./worktree-image/coverage.xml + directory: ./worktree-image/coverage-report diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index 22df4aa0fd5..7fd2064a108 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -34,39 +34,20 @@ permissions: jobs: - # standard-pre for the default platform (used by build.yml etc.) - default-pre: + # standard-pre and standard (without ptest) for the default platform (used by build.yml etc.) + default: uses: ./.github/workflows/docker.yml with: # Build from scratch - docker_targets: "with-system-packages configured with-targets-pre" + docker_targets: "with-system-packages configured with-targets-pre with-targets" # FIXME: duplicated from env.TARGETS targets_pre: all-sage-local - tox_system_factors: >- - ["ubuntu-focal"] - tox_packages_factors: >- - ["standard"] - docker_push_repository: ghcr.io/${{ github.repository }}/ - - # standard for the default platform (used by build.yml etc.) - default: - if: ${{ success() || failure() }} - needs: [default-pre] - uses: ./.github/workflows/docker.yml - with: - # Build incrementally from previous stage (pre) - incremental: true - free_disk_space: true - from_docker_repository: ghcr.io/${{ github.repository }}/ - from_docker_target: "with-targets-pre" - docker_targets: "with-targets with-targets-optional" - # FIXME: duplicated from env.TARGETS targets: build doc-html targets_optional: ptest tox_system_factors: >- ["ubuntu-focal"] tox_packages_factors: >- - ["standard"] + ["standard"] docker_push_repository: ghcr.io/${{ github.repository }}/ # All platforms. This duplicates the default platform, but why not, @@ -83,6 +64,9 @@ jobs: tox_packages_factors: >- ["standard"] docker_push_repository: ghcr.io/${{ github.repository }}/ + # Make sure that all "standard-pre" jobs can start simultaneously, + # so that runners are available by the time that "default" starts. + max_parallel: 50 standard: if: ${{ success() || failure() }} @@ -101,6 +85,8 @@ jobs: tox_packages_factors: >- ["standard"] docker_push_repository: ghcr.io/${{ github.repository }}/ + # Reduce from 30 to 25 because it runs in parallel with 'standard-sitepackages' below + max_parallel: 25 standard-sitepackages: if: ${{ success() || failure() }} @@ -153,8 +139,6 @@ jobs: minimal-pre: if: ${{ success() || failure() }} - # It does not really "need" it. - needs: [standard] uses: ./.github/workflows/docker.yml with: # Build from scratch @@ -164,6 +148,9 @@ jobs: tox_packages_factors: >- ["minimal"] docker_push_repository: ghcr.io/${{ github.repository }}/ + # Reduced from 30 because it may run in parallel with 'standard-sitepackages' above. + # Calibrated for clogging the job pipeline until the "default" job has finished. + max_parallel: 20 minimal: if: ${{ success() || failure() }} diff --git a/.github/workflows/dist.yml b/.github/workflows/dist.yml index fb2229ba7b4..5bf5729039c 100644 --- a/.github/workflows/dist.yml +++ b/.github/workflows/dist.yml @@ -99,7 +99,7 @@ jobs: with: user: __token__ password: ${{ secrets.SAGEMATH_PYPI_API_TOKEN }} - skip_existing: true + skip-existing: true verbose: true if: env.CAN_DEPLOY == 'true' @@ -180,7 +180,7 @@ jobs: with: user: __token__ password: ${{ secrets.SAGEMATH_PYPI_API_TOKEN }} - packages_dir: wheelhouse/ - skip_existing: true + packages-dir: wheelhouse/ + skip-existing: true verbose: true if: env.CAN_DEPLOY == 'true' diff --git a/.github/workflows/doc-build-pdf.yml b/.github/workflows/doc-build-pdf.yml index 2128277fbca..1d14d0c29f7 100644 --- a/.github/workflows/doc-build-pdf.yml +++ b/.github/workflows/doc-build-pdf.yml @@ -66,8 +66,6 @@ jobs: git config --global user.email "ci-sage@example.com" git config --global user.name "Build & Test workflow" .ci/retrofit-worktree.sh worktree-image /sage - # Keep track of changes to built HTML - new_version=$(cat src/VERSION.txt); (cd /sage/local/share/doc/sage/html/en && find . -name "*.html" | xargs sed -i '/class="sidebar-brand-text"/s/Sage [0-9a-z.]* /Sage '$new_version' /'; git init && (echo "*.svg binary"; echo "*.pdf binary") >> .gitattributes && (echo ".buildinfo"; echo '*.inv'; echo '.git*'; echo '*.svg'; echo '*.pdf'; echo '*.png'; echo 'searchindex.js') > .gitignore; git add -A && git commit --quiet -m "old") - name: Download upstream artifact uses: actions/download-artifact@v3 @@ -107,19 +105,20 @@ jobs: id: docbuild if: always() && (steps.incremental.outcome == 'success' || steps.build.outcome == 'success') run: | - make doc-clean doc-uninstall; make doc-pdf + make doc-clean doc-uninstall; make sagemath_doc_html-build-deps sagemath_doc_pdf-no-deps working-directory: ./worktree-image env: MAKE: make -j2 --output-sync=recurse SAGE_NUM_THREADS: 2 - name: Copy docs + id: copy if: always() && steps.docbuild.outcome == 'success' run: | # For some reason the deploy step below cannot find /sage/... # So copy everything from there to local folder mkdir -p ./docs - cp -r -L /sage/local/share/doc/sage/pdf/en/* ./docs + cp -r -L /sage/local/share/doc/sage/pdf ./docs # Zip everything for increased performance zip -r docs-pdf.zip docs diff --git a/.github/workflows/doc-build.yml b/.github/workflows/doc-build.yml index 5eb3998feee..e079fa04beb 100644 --- a/.github/workflows/doc-build.yml +++ b/.github/workflows/doc-build.yml @@ -63,12 +63,12 @@ jobs: mathjax_path_to=$(SAGE_USE_CDNS=yes /sage/sage -python -c "from sage_docbuild.conf import mathjax_path; print(mathjax_path)") new_version=$(cat src/VERSION.txt) # Wipe out chronic diffs between old doc and new doc - (cd /sage/local/share/doc/sage/html/en && \ + (cd /sage/local/share/doc/sage/html && \ find . -name "*.html" | xargs sed -i -e '/class="sidebar-brand-text"/ s/Sage [0-9a-z.]* /Sage '"$new_version"' /' \ -e 's;'"$mathjax_path_from"';'"$mathjax_path_to"';' \ -e '\;; d') # Create git repo from old doc - (cd /sage/local/share/doc/sage/html/en && \ + (cd /sage/local/share/doc/sage/html && \ git init && \ (echo "*.svg binary"; echo "*.pdf binary") >> .gitattributes && \ (echo ".buildinfo"; echo '*.inv'; echo '.git*'; echo '*.svg'; echo '*.pdf'; echo '*.png'; echo 'searchindex.js') > .gitignore; \ @@ -116,9 +116,9 @@ jobs: run: | set -ex export SAGE_USE_CDNS=yes - mv /sage/local/share/doc/sage/html/en/.git /sage/.git-doc + mv /sage/local/share/doc/sage/html/.git /sage/.git-doc make doc-clean doc-uninstall - mkdir -p /sage/local/share/doc/sage/html/en/ && mv /sage/.git-doc /sage/local/share/doc/sage/html/en/.git + mkdir -p /sage/local/share/doc/sage/html/ && mv /sage/.git-doc /sage/local/share/doc/sage/html/.git ./config.status && make sagemath_doc_html-no-deps working-directory: ./worktree-image env: @@ -131,9 +131,9 @@ jobs: run: | set -ex mkdir -p ./docs - (cd /sage/local/share/doc/sage/html/en && git commit -a -m 'new') + (cd /sage/local/share/doc/sage/html && git commit -a -m 'new') # Wipe out chronic diffs between old doc and new doc - (cd /sage/local/share/doc/sage/html/en && \ + (cd /sage/local/share/doc/sage/html && \ find . -name "*.html" | xargs sed -i -e '\;; d') # Create CHANGES.html echo '' > ./docs/CHANGES.html @@ -162,7 +162,7 @@ jobs: EOF echo '' >> ./docs/CHANGES.html echo '' >> ./docs/CHANGES.html - (cd /sage/local/share/doc/sage/html/en && git diff HEAD^; rm -rf .git) > ./docs/diff.txt + (cd /sage/local/share/doc/sage/html && git diff HEAD^ -- *.html; rm -rf .git) > ./docs/diff.txt /sage/sage -python - << EOF import re, html with open('./docs/diff.txt', 'r') as f: @@ -172,7 +172,7 @@ jobs: for block in diff_blocks: match = re.search(r'^diff --git a/(.*) b/\1', block, flags=re.MULTILINE) if match: - path = match.group(1) + path = 'html/' + match.group(1) out_blocks.append(f'

{path}

\n
' + html.escape(block).strip() + '
') output_text = '\n'.join(out_blocks) with open('./docs/diff.html', 'w') as f: @@ -182,11 +182,12 @@ jobs: echo '' >> ./docs/CHANGES.html echo '' >>./docs/CHANGES.html rm ./docs/diff.txt ./docs/diff.html - (cd /sage/local/share/doc/sage/html/en && git reset --hard HEAD) + (cd /sage/local/share/doc/sage/html && git reset --hard HEAD) # For some reason the deploy step below cannot find /sage/... # So copy everything from there to local folder # We also need to replace the symlinks because netlify is not following them - cp -r -L /sage/local/share/doc/sage/html/en/* ./docs + cp -r -L /sage/local/share/doc/sage/html ./docs + cp /sage/local/share/doc/sage/index.html ./docs # Zip everything for increased performance zip -r docs.zip docs @@ -196,3 +197,36 @@ jobs: with: name: docs path: docs.zip + + - name: Build live doc + id: buildlivedoc + if: (success() || failure()) && steps.copy.outcome == 'success' && github.repository == 'sagemath/sage' && github.ref == 'refs/heads/develop' + run: | + set -ex + export SAGE_USE_CDNS=yes + export SAGE_LIVE_DOC=yes + export SAGE_JUPYTER_SERVER=binder:sagemath/sage-binder-env/dev + make doc-clean doc-uninstall + ./config.status && make sagemath_doc_html-no-deps + working-directory: ./worktree-image + env: + MAKE: make -j2 --output-sync=recurse + SAGE_NUM_THREADS: 2 + + - name: Copy live doc + id: copylivedoc + if: (success() || failure()) && steps.buildlivedoc.outcome == 'success' + run: | + set -ex + mkdir -p ./livedoc + cp -r -L /sage/local/share/doc/sage/html ./livedoc + cp /sage/local/share/doc/sage/index.html ./livedoc + zip -r livedoc.zip livedoc + + - name: Upload live doc + if: (success() || failure()) && steps.copylivedoc.outcome == 'success' + uses: actions/upload-artifact@v3 + with: + name: livedoc + path: livedoc.zip + diff --git a/.github/workflows/doc-publish.yml b/.github/workflows/doc-publish.yml index 14337131420..1a42a22dbb8 100644 --- a/.github/workflows/doc-publish.yml +++ b/.github/workflows/doc-publish.yml @@ -72,7 +72,7 @@ jobs: header: preview-comment recreate: true message: | - [Documentation preview for this PR](${{ steps.deploy-netlify.outputs.NETLIFY_URL }}) (built with commit ${{ steps.source-run-info.outputs.sourceHeadSha }}; [changes](${{ steps.deploy-netlify.outputs.NETLIFY_URL }}/CHANGES.html)) is ready! :tada: + [Documentation preview for this PR](${{ steps.deploy-netlify.outputs.NETLIFY_URL }}/html/en) (built with commit ${{ steps.source-run-info.outputs.sourceHeadSha }}; [changes](${{ steps.deploy-netlify.outputs.NETLIFY_URL }}/CHANGES.html)) is ready! :tada: - name: Update deployment status PR check uses: myrotvorets/set-commit-status-action@v2.0.0 @@ -90,5 +90,48 @@ jobs: - name: Report deployment url run: | - echo "::notice::The documentation has being automatically deployed to Netlify. %0A ✅ Preview: ${{ steps.deploy-netlify.outputs.NETLIFY_URL }}" + echo "::notice::The documentation has been deployed - ${{ steps.deploy-netlify.outputs.NETLIFY_URL }}" + + publish-live-doc: + runs-on: ubuntu-latest + if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'develop' + steps: + - name: Download live doc + uses: actions/github-script@v6.4.1 + with: + script: | + var artifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: ${{github.event.workflow_run.id }}, + }); + var matchArtifact = artifacts.data.artifacts.filter((artifact) => { + return artifact.name == "livedoc" + })[0]; + var download = await github.rest.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + var fs = require('fs'); + fs.writeFileSync('${{github.workspace}}/livedoc.zip', Buffer.from(download.data)); + + - name: Extract live doc + run: unzip livedoc.zip -d doc && unzip doc/livedoc.zip -d doc/doc + + - name: Deploy to Netlify + id: deploy-netlify + uses: netlify/actions/cli@master + with: + args: deploy --dir=doc/doc/livedoc --message ${NETLIFY_MESSAGE} --alias ${NETLIFY_ALIAS} + env: + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} + NETLIFY_MESSAGE: Deployed live doc + NETLIFY_ALIAS: deploy-livedoc + + - name: Report deployment url + run: | + echo "::notice::The live documentation has been deployed - ${{ steps.deploy-netlify.outputs.NETLIFY_URL }}" diff --git a/CITATION.cff b/CITATION.cff index 27438597f31..bcd3dad6665 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -4,8 +4,8 @@ title: SageMath abstract: SageMath is a free open-source mathematics software system. authors: - name: "The SageMath Developers" -version: 10.2.beta9 +version: 10.2.rc0 doi: 10.5281/zenodo.593563 -date-released: 2023-10-30 +date-released: 2023-11-05 repository-code: "https://github.com/sagemath/sage" url: "https://www.sagemath.org/" diff --git a/VERSION.txt b/VERSION.txt index b2bf34c0be8..a43284eebe1 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -SageMath version 10.2.beta9, Release Date: 2023-10-30 +SageMath version 10.2.rc0, Release Date: 2023-11-05 diff --git a/build/pkgs/configure/checksums.ini b/build/pkgs/configure/checksums.ini index 5b7360aa36d..bae48b7cfe0 100644 --- a/build/pkgs/configure/checksums.ini +++ b/build/pkgs/configure/checksums.ini @@ -1,4 +1,4 @@ tarball=configure-VERSION.tar.gz -sha1=0f90c993748bfc21ae382ac3ce6c19b434edb36c -md5=b8d9355c732997566f68b60c8a8eb9cc -cksum=2280021929 +sha1=41ec9a0bdf6e5982204b26ce2593e4b5a1863c96 +md5=8ea80ef7438ed62345de677dc921af2e +cksum=2979893163 diff --git a/build/pkgs/configure/package-version.txt b/build/pkgs/configure/package-version.txt index d63934749a3..6a758846d8a 100644 --- a/build/pkgs/configure/package-version.txt +++ b/build/pkgs/configure/package-version.txt @@ -1 +1 @@ -c0221f90a86e4b4bea4b45ff8de54727313bd755 +be0b5cf887fefcdf31df70be0a62b10b7929f28c diff --git a/build/pkgs/cypari/distros/gentoo.txt b/build/pkgs/cypari/distros/gentoo.txt new file mode 100644 index 00000000000..e0a57fa8726 --- /dev/null +++ b/build/pkgs/cypari/distros/gentoo.txt @@ -0,0 +1 @@ +dev-python/cypari2 diff --git a/build/pkgs/cypari/spkg-configure.m4 b/build/pkgs/cypari/spkg-configure.m4 new file mode 100644 index 00000000000..12bbfec1de1 --- /dev/null +++ b/build/pkgs/cypari/spkg-configure.m4 @@ -0,0 +1,5 @@ +SAGE_SPKG_CONFIGURE([cypari], [ + SAGE_SPKG_DEPCHECK([cysignals pari], [ + SAGE_PYTHON_PACKAGE_CHECK([cypari]) + ]) +]) diff --git a/build/pkgs/cysignals/distros/gentoo.txt b/build/pkgs/cysignals/distros/gentoo.txt new file mode 100644 index 00000000000..3d0797368c8 --- /dev/null +++ b/build/pkgs/cysignals/distros/gentoo.txt @@ -0,0 +1 @@ +dev-python/cysignals diff --git a/build/pkgs/cysignals/spkg-configure.m4 b/build/pkgs/cysignals/spkg-configure.m4 new file mode 100644 index 00000000000..4eeee71f579 --- /dev/null +++ b/build/pkgs/cysignals/spkg-configure.m4 @@ -0,0 +1,3 @@ +SAGE_SPKG_CONFIGURE([cysignals], [ + SAGE_PYTHON_PACKAGE_CHECK([cysignals]) +]) diff --git a/build/pkgs/cython/distros/conda.txt b/build/pkgs/cython/distros/conda.txt index f6629e02456..19a32cd69b5 100644 --- a/build/pkgs/cython/distros/conda.txt +++ b/build/pkgs/cython/distros/conda.txt @@ -1 +1,3 @@ -cython +cython>=3.0,!=3.0.3,<4.0 + +# Exclude 3.0.3 because of https://github.com/cython/cython/issues/5748 diff --git a/build/pkgs/cython/install-requires.txt b/build/pkgs/cython/install-requires.txt index 3693d637891..74073ecb57f 100644 --- a/build/pkgs/cython/install-requires.txt +++ b/build/pkgs/cython/install-requires.txt @@ -1 +1,3 @@ -cython >=3.0, <4.0 +cython >=3.0, != 3.0.3, <4.0 + +# Exclude 3.0.3 because of https://github.com/cython/cython/issues/5748 diff --git a/build/pkgs/fplll/checksums.ini b/build/pkgs/fplll/checksums.ini index 22fba10e438..5f9ec9753be 100644 --- a/build/pkgs/fplll/checksums.ini +++ b/build/pkgs/fplll/checksums.ini @@ -1,5 +1,5 @@ tarball=fplll-VERSION.tar.gz -sha1=8353a0db588d891951aa9760fbe490f4e308de8d -md5=7e333d7d0e535d27c591271340e28865 -cksum=2543682321 +sha1=607f5922109d93ddd5a05419682511e26579f9d6 +md5=fa4e1f24994c0345a9530397a3369b27 +cksum=4174005926 upstream_url=https://github.com/fplll/fplll/releases/download/VERSION/fplll-VERSION.tar.gz diff --git a/build/pkgs/fplll/package-version.txt b/build/pkgs/fplll/package-version.txt index 426c1c17944..8ce222e90f7 100644 --- a/build/pkgs/fplll/package-version.txt +++ b/build/pkgs/fplll/package-version.txt @@ -1 +1 @@ -5.4.4 +5.4.5 diff --git a/build/pkgs/fplll/spkg-configure.m4 b/build/pkgs/fplll/spkg-configure.m4 index 4e58e636d79..9eca84dc240 100644 --- a/build/pkgs/fplll/spkg-configure.m4 +++ b/build/pkgs/fplll/spkg-configure.m4 @@ -8,7 +8,7 @@ SAGE_SPKG_CONFIGURE([fplll], [ dnl Trac #31025: FPLLL/FPyLLL make no guarantee regarding compatibility dnl other than "whatever versions were released at the same time should work together" PKG_CHECK_MODULES([FPLLL], - [fplll >= 5.4.4 fplll <= 5.4.4], + [fplll >= 5.4.5 fplll <= 5.4.5], [ AC_MSG_CHECKING([whether BKZ default strategy JSON is installed]) AC_LANG_PUSH([C++]) diff --git a/build/pkgs/fpylll/checksums.ini b/build/pkgs/fpylll/checksums.ini index 0172ce17065..156fc587670 100644 --- a/build/pkgs/fpylll/checksums.ini +++ b/build/pkgs/fpylll/checksums.ini @@ -1,5 +1,5 @@ tarball=fpylll-VERSION.tar.gz -sha1=2dcc29155ee11b4460fc79c2d933b6b8230c89f6 -md5=828b3a382594d34d8788e9ff041125bd -cksum=921330875 -upstream_url=https://github.com/fplll/fpylll/releases/download/VERSION/fpylll-VERSION.tar.gz +sha1=f23835208fc048028c849bb5b566f2fe631df7f4 +md5=c81a1af8ecf57ae740366a110dfbbbaf +cksum=398170701 +upstream_url=https://pypi.io/packages/source/f/fpylll/fpylll-VERSION.tar.gz diff --git a/build/pkgs/fpylll/distros/gentoo.txt b/build/pkgs/fpylll/distros/gentoo.txt new file mode 100644 index 00000000000..34817e9f233 --- /dev/null +++ b/build/pkgs/fpylll/distros/gentoo.txt @@ -0,0 +1 @@ +dev-python/fpylll diff --git a/build/pkgs/fpylll/package-version.txt b/build/pkgs/fpylll/package-version.txt index 416bfb0a221..a918a2aa18d 100644 --- a/build/pkgs/fpylll/package-version.txt +++ b/build/pkgs/fpylll/package-version.txt @@ -1 +1 @@ -0.5.9 +0.6.0 diff --git a/build/pkgs/fpylll/patches/cython3-legacy.patch b/build/pkgs/fpylll/patches/cython3-legacy.patch deleted file mode 100644 index 808c14e9c1b..00000000000 --- a/build/pkgs/fpylll/patches/cython3-legacy.patch +++ /dev/null @@ -1,37 +0,0 @@ -commit b6e12c2b0648e84b26dcf0aac507a5b4d9dde301 -Author: Gonzalo Tornaría -Date: Wed Jul 19 20:38:01 2023 -0300 - - cython3 support using legacy directives - -diff --git a/setup.py b/setup.py -index 274836f..8fc5af5 100755 ---- a/setup.py -+++ b/setup.py -@@ -123,7 +123,12 @@ class build_ext(_build_ext, object): - self.extensions, - include_path=["src"], - build_dir=self.cythonize_dir, -- compiler_directives={"binding": True, "embedsignature": True, "language_level": 2}, -+ compiler_directives={ -+ "binding": True, -+ "embedsignature": True, -+ "language_level": 2, -+ "legacy_implicit_noexcept": True, -+ }, - ) - super(build_ext, self).run() - -diff --git a/src/fpylll/fplll/enumeration_callback_helper.h b/src/fpylll/fplll/enumeration_callback_helper.h -index c099430..706162f 100644 ---- a/src/fpylll/fplll/enumeration_callback_helper.h -+++ b/src/fpylll/fplll/enumeration_callback_helper.h -@@ -5,7 +5,7 @@ - #include - #include - --extern "C" { -+extern "C++" { - bool evaluator_callback_call_obj(PyObject *obj, int n, double *new_sol_coord); - } - diff --git a/build/pkgs/fpylll/spkg-configure.m4 b/build/pkgs/fpylll/spkg-configure.m4 new file mode 100644 index 00000000000..bd3c707f82d --- /dev/null +++ b/build/pkgs/fpylll/spkg-configure.m4 @@ -0,0 +1,5 @@ +SAGE_SPKG_CONFIGURE([fpylll], [ + SAGE_SPKG_DEPCHECK([cysignals fplll numpy], [ + SAGE_PYTHON_PACKAGE_CHECK([fpylll]) + ]) +]) diff --git a/build/pkgs/memory_allocator/distros/gentoo.txt b/build/pkgs/memory_allocator/distros/gentoo.txt new file mode 100644 index 00000000000..cb71f80f6c7 --- /dev/null +++ b/build/pkgs/memory_allocator/distros/gentoo.txt @@ -0,0 +1 @@ +dev-python/memory-allocator diff --git a/build/pkgs/memory_allocator/spkg-configure.m4 b/build/pkgs/memory_allocator/spkg-configure.m4 new file mode 100644 index 00000000000..8cd8d87f124 --- /dev/null +++ b/build/pkgs/memory_allocator/spkg-configure.m4 @@ -0,0 +1,3 @@ +SAGE_SPKG_CONFIGURE([memory_allocator], [ + SAGE_PYTHON_PACKAGE_CHECK([memory_allocator]) +]) diff --git a/build/pkgs/networkx/distros/conda.txt b/build/pkgs/networkx/distros/conda.txt index 96b0bbb2845..c9c5caa1120 100644 --- a/build/pkgs/networkx/distros/conda.txt +++ b/build/pkgs/networkx/distros/conda.txt @@ -1 +1 @@ -networkx<3.2,>=2.4 +networkx<3.3,>=2.4 diff --git a/build/pkgs/networkx/install-requires.txt b/build/pkgs/networkx/install-requires.txt index ea173da7538..5a7e22a60db 100644 --- a/build/pkgs/networkx/install-requires.txt +++ b/build/pkgs/networkx/install-requires.txt @@ -1 +1 @@ -networkx >=2.4, <3.2 +networkx >=2.4, <3.3 diff --git a/build/pkgs/pplpy/distros/gentoo.txt b/build/pkgs/pplpy/distros/gentoo.txt new file mode 100644 index 00000000000..375b6a32c29 --- /dev/null +++ b/build/pkgs/pplpy/distros/gentoo.txt @@ -0,0 +1 @@ +dev-python/pplpy diff --git a/build/pkgs/pplpy/spkg-configure.m4 b/build/pkgs/pplpy/spkg-configure.m4 new file mode 100644 index 00000000000..320ca9456f6 --- /dev/null +++ b/build/pkgs/pplpy/spkg-configure.m4 @@ -0,0 +1,5 @@ +SAGE_SPKG_CONFIGURE([pplpy], [ + SAGE_SPKG_DEPCHECK([cysignals gmpy2 ppl], [ + SAGE_PYTHON_PACKAGE_CHECK([pplpy]) + ]) +]) diff --git a/build/pkgs/primecountpy/distros/gentoo.txt b/build/pkgs/primecountpy/distros/gentoo.txt new file mode 100644 index 00000000000..194fde28b57 --- /dev/null +++ b/build/pkgs/primecountpy/distros/gentoo.txt @@ -0,0 +1 @@ +dev-python/primecountpy diff --git a/build/pkgs/primecountpy/spkg-configure.m4 b/build/pkgs/primecountpy/spkg-configure.m4 new file mode 100644 index 00000000000..f1e2d7ce4f5 --- /dev/null +++ b/build/pkgs/primecountpy/spkg-configure.m4 @@ -0,0 +1,5 @@ +SAGE_SPKG_CONFIGURE([primecountpy], [ + SAGE_SPKG_DEPCHECK([cysignals primecount], [ + SAGE_PYTHON_PACKAGE_CHECK([primecountpy]) + ]) +]) diff --git a/build/pkgs/sage_conf/install-requires.txt b/build/pkgs/sage_conf/install-requires.txt index 1387216d0d4..4b66d1b0602 100644 --- a/build/pkgs/sage_conf/install-requires.txt +++ b/build/pkgs/sage_conf/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sage-conf ~= 10.2b9 +sage-conf ~= 10.2rc0 diff --git a/build/pkgs/sage_docbuild/install-requires.txt b/build/pkgs/sage_docbuild/install-requires.txt index 530594cb2f7..cebed4e3b62 100644 --- a/build/pkgs/sage_docbuild/install-requires.txt +++ b/build/pkgs/sage_docbuild/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sage-docbuild ~= 10.2b9 +sage-docbuild ~= 10.2rc0 diff --git a/build/pkgs/sage_setup/install-requires.txt b/build/pkgs/sage_setup/install-requires.txt index 5a9a50b1773..1631564eec7 100644 --- a/build/pkgs/sage_setup/install-requires.txt +++ b/build/pkgs/sage_setup/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sage-setup ~= 10.2b9 +sage-setup ~= 10.2rc0 diff --git a/build/pkgs/sage_sws2rst/install-requires.txt b/build/pkgs/sage_sws2rst/install-requires.txt index 8f0dd4150d7..628374d5f1a 100644 --- a/build/pkgs/sage_sws2rst/install-requires.txt +++ b/build/pkgs/sage_sws2rst/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sage-sws2rst ~= 10.2b9 +sage-sws2rst ~= 10.2rc0 diff --git a/build/pkgs/sagelib/install-requires.txt b/build/pkgs/sagelib/install-requires.txt index fe389de2e2e..6004e85c25d 100644 --- a/build/pkgs/sagelib/install-requires.txt +++ b/build/pkgs/sagelib/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sagemath-standard ~= 10.2b9 +sagemath-standard ~= 10.2rc0 diff --git a/build/pkgs/sagemath_bliss/install-requires.txt b/build/pkgs/sagemath_bliss/install-requires.txt index dabe7e52643..5ea4526cc33 100644 --- a/build/pkgs/sagemath_bliss/install-requires.txt +++ b/build/pkgs/sagemath_bliss/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sagemath-bliss ~= 10.2b9 +sagemath-bliss ~= 10.2rc0 diff --git a/build/pkgs/sagemath_categories/install-requires.txt b/build/pkgs/sagemath_categories/install-requires.txt index eab5b455322..1d37a18c187 100644 --- a/build/pkgs/sagemath_categories/install-requires.txt +++ b/build/pkgs/sagemath_categories/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sagemath-categories ~= 10.2b9 +sagemath-categories ~= 10.2rc0 diff --git a/build/pkgs/sagemath_coxeter3/install-requires.txt b/build/pkgs/sagemath_coxeter3/install-requires.txt index c07ca4d5a32..8d6115b1868 100644 --- a/build/pkgs/sagemath_coxeter3/install-requires.txt +++ b/build/pkgs/sagemath_coxeter3/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sagemath-coxeter3 ~= 10.2b9 +sagemath-coxeter3 ~= 10.2rc0 diff --git a/build/pkgs/sagemath_environment/install-requires.txt b/build/pkgs/sagemath_environment/install-requires.txt index 7745d13c50c..c870e97dca1 100644 --- a/build/pkgs/sagemath_environment/install-requires.txt +++ b/build/pkgs/sagemath_environment/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sagemath-environment ~= 10.2b9 +sagemath-environment ~= 10.2rc0 diff --git a/build/pkgs/sagemath_mcqd/install-requires.txt b/build/pkgs/sagemath_mcqd/install-requires.txt index 34d46c650c9..cff0dac0026 100644 --- a/build/pkgs/sagemath_mcqd/install-requires.txt +++ b/build/pkgs/sagemath_mcqd/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sagemath-mcqd ~= 10.2b9 +sagemath-mcqd ~= 10.2rc0 diff --git a/build/pkgs/sagemath_meataxe/install-requires.txt b/build/pkgs/sagemath_meataxe/install-requires.txt index 3012f831c3a..464942fef75 100644 --- a/build/pkgs/sagemath_meataxe/install-requires.txt +++ b/build/pkgs/sagemath_meataxe/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sagemath-meataxe ~= 10.2b9 +sagemath-meataxe ~= 10.2rc0 diff --git a/build/pkgs/sagemath_objects/install-requires.txt b/build/pkgs/sagemath_objects/install-requires.txt index 35022da8fde..663b7d78f8b 100644 --- a/build/pkgs/sagemath_objects/install-requires.txt +++ b/build/pkgs/sagemath_objects/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sagemath-objects ~= 10.2b9 +sagemath-objects ~= 10.2rc0 diff --git a/build/pkgs/sagemath_repl/install-requires.txt b/build/pkgs/sagemath_repl/install-requires.txt index 4c33d1b3eb0..917144d154c 100644 --- a/build/pkgs/sagemath_repl/install-requires.txt +++ b/build/pkgs/sagemath_repl/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sagemath-repl ~= 10.2b9 +sagemath-repl ~= 10.2rc0 diff --git a/build/pkgs/sagemath_sirocco/install-requires.txt b/build/pkgs/sagemath_sirocco/install-requires.txt index bd55a958d68..896662f1b95 100644 --- a/build/pkgs/sagemath_sirocco/install-requires.txt +++ b/build/pkgs/sagemath_sirocco/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sagemath-sirocco ~= 10.2b9 +sagemath-sirocco ~= 10.2rc0 diff --git a/build/pkgs/sagemath_tdlib/install-requires.txt b/build/pkgs/sagemath_tdlib/install-requires.txt index 2e291c70e25..c26900d9abf 100644 --- a/build/pkgs/sagemath_tdlib/install-requires.txt +++ b/build/pkgs/sagemath_tdlib/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sagemath-tdlib ~= 10.2b9 +sagemath-tdlib ~= 10.2rc0 diff --git a/build/sage_bootstrap/download/mirror_list.py b/build/sage_bootstrap/download/mirror_list.py index a8baa66da2d..4cab19f5d64 100644 --- a/build/sage_bootstrap/download/mirror_list.py +++ b/build/sage_bootstrap/download/mirror_list.py @@ -170,9 +170,7 @@ def _rank_mirrors(self): timed_mirrors = [] import time, socket log.info('Searching fastest mirror') - timeout = socket.getdefaulttimeout() - if timeout is None: - timeout = 1 + timeout = 1 for mirror in self.mirrors: if not mirror.startswith('http'): log.debug('we currently can only handle http, got %s', mirror) @@ -190,6 +188,11 @@ def _rank_mirrors(self): result_ms = int(1000 * result) log.info(str(result_ms).rjust(5) + 'ms: ' + mirror) timed_mirrors.append((result, mirror)) + timed_mirrors.sort() + if len(timed_mirrors) >= 5 and timed_mirrors[4][0] < 0.3: + # We don't need more than 5 decent mirrors + break + if len(timed_mirrors) == 0: # We cannot reach any mirror directly, most likely firewall issue if 'http_proxy' not in os.environ: @@ -197,7 +200,6 @@ def _rank_mirrors(self): raise MirrorListException('Failed to connect to any mirror, probably no internet connection') log.info('Cannot time mirrors via proxy, using default order') else: - timed_mirrors.sort() self._mirrors = [m[1] for m in timed_mirrors] log.info('Fastest mirror: ' + self.fastest) diff --git a/m4/pyproject_toml_metadata.m4 b/m4/pyproject_toml_metadata.m4 new file mode 100644 index 00000000000..2511fac45f7 --- /dev/null +++ b/m4/pyproject_toml_metadata.m4 @@ -0,0 +1,20 @@ +dnl Standard metadata of SageMath distribution packages +dnl +license = {text = "GNU General Public License (GPL) v2 or later"} +authors = [{name = "The Sage Developers", email = "sage-support@googlegroups.com"}] +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.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: Implementation :: CPython", + "Topic :: Scientific/Engineering :: Mathematics", +] +urls = {Homepage = "https://www.sagemath.org"} +requires-python = ">=3.9, <3.12" diff --git a/pkgs/sage-conf/VERSION.txt b/pkgs/sage-conf/VERSION.txt index d0cd2bc56e3..7694f7787b5 100644 --- a/pkgs/sage-conf/VERSION.txt +++ b/pkgs/sage-conf/VERSION.txt @@ -1 +1 @@ -10.2.beta9 +10.2.rc0 diff --git a/pkgs/sage-conf_conda/VERSION.txt b/pkgs/sage-conf_conda/VERSION.txt index d0cd2bc56e3..7694f7787b5 100644 --- a/pkgs/sage-conf_conda/VERSION.txt +++ b/pkgs/sage-conf_conda/VERSION.txt @@ -1 +1 @@ -10.2.beta9 +10.2.rc0 diff --git a/pkgs/sage-conf_pypi/VERSION.txt b/pkgs/sage-conf_pypi/VERSION.txt index d0cd2bc56e3..7694f7787b5 100644 --- a/pkgs/sage-conf_pypi/VERSION.txt +++ b/pkgs/sage-conf_pypi/VERSION.txt @@ -1 +1 @@ -10.2.beta9 +10.2.rc0 diff --git a/pkgs/sage-docbuild/VERSION.txt b/pkgs/sage-docbuild/VERSION.txt index d0cd2bc56e3..7694f7787b5 100644 --- a/pkgs/sage-docbuild/VERSION.txt +++ b/pkgs/sage-docbuild/VERSION.txt @@ -1 +1 @@ -10.2.beta9 +10.2.rc0 diff --git a/pkgs/sage-setup/VERSION.txt b/pkgs/sage-setup/VERSION.txt index d0cd2bc56e3..7694f7787b5 100644 --- a/pkgs/sage-setup/VERSION.txt +++ b/pkgs/sage-setup/VERSION.txt @@ -1 +1 @@ -10.2.beta9 +10.2.rc0 diff --git a/pkgs/sage-sws2rst/VERSION.txt b/pkgs/sage-sws2rst/VERSION.txt index d0cd2bc56e3..7694f7787b5 100644 --- a/pkgs/sage-sws2rst/VERSION.txt +++ b/pkgs/sage-sws2rst/VERSION.txt @@ -1 +1 @@ -10.2.beta9 +10.2.rc0 diff --git a/pkgs/sagemath-bliss/VERSION.txt b/pkgs/sagemath-bliss/VERSION.txt index d0cd2bc56e3..7694f7787b5 100644 --- a/pkgs/sagemath-bliss/VERSION.txt +++ b/pkgs/sagemath-bliss/VERSION.txt @@ -1 +1 @@ -10.2.beta9 +10.2.rc0 diff --git a/pkgs/sagemath-categories/VERSION.txt b/pkgs/sagemath-categories/VERSION.txt index d0cd2bc56e3..7694f7787b5 100644 --- a/pkgs/sagemath-categories/VERSION.txt +++ b/pkgs/sagemath-categories/VERSION.txt @@ -1 +1 @@ -10.2.beta9 +10.2.rc0 diff --git a/pkgs/sagemath-categories/pyproject.toml.m4 b/pkgs/sagemath-categories/pyproject.toml.m4 index cf4c97f1fd1..94277dccc0e 100644 --- a/pkgs/sagemath-categories/pyproject.toml.m4 +++ b/pkgs/sagemath-categories/pyproject.toml.m4 @@ -12,3 +12,27 @@ requires = [ SPKG_INSTALL_REQUIRES_cysignals ] build-backend = "setuptools.build_meta" + +[project] +name = "sagemath-categories" +description = "Sage: Open Source Mathematics Software: Sage categories and basic rings" +dependencies = [ + SPKG_INSTALL_REQUIRES_sagemath_objects +] +dynamic = ["version"] +include(`pyproject_toml_metadata.m4')dnl' + +[project.optional-dependencies] +test = [ + SPKG_INSTALL_REQUIRES_sagemath_repl +] + +[project.readme] +file = "README.rst" +content-type = "text/x-rst" + +[tool.setuptools] +include-package-data = false + +[tool.setuptools.dynamic] +version = {file = ["VERSION.txt"]} diff --git a/pkgs/sagemath-categories/setup.cfg.m4 b/pkgs/sagemath-categories/setup.cfg.m4 deleted file mode 100644 index f5eb7c72968..00000000000 --- a/pkgs/sagemath-categories/setup.cfg.m4 +++ /dev/null @@ -1,16 +0,0 @@ -include(`sage_spkg_versions.m4')dnl' -*- conf-unix -*- -[metadata] -name = sagemath-categories -version = file: VERSION.txt -description = Sage: Open Source Mathematics Software: Sage categories and basic rings -long_description = file: README.rst -long_description_content_type = text/x-rst -include(`setup_cfg_metadata.m4')dnl' - -[options] -python_requires = >=3.9, <3.12 -install_requires = - SPKG_INSTALL_REQUIRES_sagemath_objects - -[options.extras_require] -test = SPKG_INSTALL_REQUIRES_sagemath_repl diff --git a/pkgs/sagemath-coxeter3/VERSION.txt b/pkgs/sagemath-coxeter3/VERSION.txt index d0cd2bc56e3..7694f7787b5 100644 --- a/pkgs/sagemath-coxeter3/VERSION.txt +++ b/pkgs/sagemath-coxeter3/VERSION.txt @@ -1 +1 @@ -10.2.beta9 +10.2.rc0 diff --git a/pkgs/sagemath-environment/VERSION.txt b/pkgs/sagemath-environment/VERSION.txt index d0cd2bc56e3..7694f7787b5 100644 --- a/pkgs/sagemath-environment/VERSION.txt +++ b/pkgs/sagemath-environment/VERSION.txt @@ -1 +1 @@ -10.2.beta9 +10.2.rc0 diff --git a/pkgs/sagemath-environment/pyproject.toml.m4 b/pkgs/sagemath-environment/pyproject.toml.m4 index fb2db955ed5..4061c8c46eb 100644 --- a/pkgs/sagemath-environment/pyproject.toml.m4 +++ b/pkgs/sagemath-environment/pyproject.toml.m4 @@ -6,3 +6,57 @@ requires = [ SPKG_INSTALL_REQUIRES_wheel ] build-backend = "setuptools.build_meta" + +[project] +name = "sagemath-environment" +description = "Sage: Open Source Mathematics Software: System and software environment" +dependencies = [] +dynamic = ["version"] +include(`pyproject_toml_metadata.m4')dnl' + +[project.optional-dependencies] +conf = [SPKG_INSTALL_REQUIRES_sage_conf] # sage.env can optionally use sage_conf +docbuild = [SPKG_INSTALL_REQUIRES_sage_docbuild] # For "sage --docbuild" +sage = [SPKG_INSTALL_REQUIRES_sagelib] # For "sage", "sage -t", ... +cython = [SPKG_INSTALL_REQUIRES_cython] # For "sage --cython" +pytest = [SPKG_INSTALL_REQUIRES_pytest] # For "sage --pytest" +rst2ipynb = [SPKG_INSTALL_REQUIRES_rst2ipynb] # For "sage --rst2ipynb" +tox = [SPKG_INSTALL_REQUIRES_tox] # For "sage --tox" +sws2rst = [SPKG_INSTALL_REQUIRES_sage_sws2rst] # For "sage --sws2rst" + +[project.readme] +file = "README.rst" +content-type = "text/x-rst" + +[tool.setuptools] +py-modules = [ + "sage.all__sagemath_environment", + "sage.env", + "sage.version", + "sage.misc.all__sagemath_environment", + "sage.misc.package", + "sage.misc.package_dir", + "sage.misc.temporary_file", + "sage.misc.viewer", +] +packages = ["sage.features"] +script-files = [ + # The sage script + "bin/sage", + # Auxiliary scripts for setting up the environment + "bin/sage-env", + "bin/sage-num-threads.py", + "bin/sage-venv-config", + "bin/sage-version.sh", + # Auxiliary script for invoking Python in the Sage environment + "bin/sage-python", + # Not included: + # - bin/sage-env-config -- installed by sage_conf + # - bin/sage-env-config.in -- not to be installed + # - bin/sage-run, bin/sage-runtests, ... -- installed by sagemath-repl + # - bin/sage-ipython -- uses sage.repl, so installed by sagemath-repl +] +include-package-data = false + +[tool.setuptools.dynamic] +version = {file = ["VERSION.txt"]} diff --git a/pkgs/sagemath-environment/setup.cfg.m4 b/pkgs/sagemath-environment/setup.cfg.m4 deleted file mode 100644 index 9e5bb31eeb7..00000000000 --- a/pkgs/sagemath-environment/setup.cfg.m4 +++ /dev/null @@ -1,66 +0,0 @@ -include(`sage_spkg_versions.m4')dnl' -*- conf-unix -*- -[metadata] -name = sagemath-environment -version = file: VERSION.txt -description = Sage: Open Source Mathematics Software: System and software environment -long_description = file: README.rst -long_description_content_type = text/x-rst -include(`setup_cfg_metadata.m4')dnl' - -[options] -python_requires = >=3.9, <3.12 -install_requires = - -py_modules = - sage.all__sagemath_environment - sage.env - sage.version - sage.misc.all__sagemath_environment - sage.misc.package - sage.misc.package_dir - sage.misc.temporary_file - sage.misc.viewer - -packages = - sage.features - -scripts = - # The sage script - bin/sage - # Auxiliary scripts for setting up the environment - bin/sage-env - bin/sage-num-threads.py - bin/sage-venv-config - bin/sage-version.sh - # Auxiliary script for invoking Python in the Sage environment - bin/sage-python - # Not included: - # - bin/sage-env-config -- installed by sage_conf - # - bin/sage-env-config.in -- not to be installed - # - bin/sage-run, bin/sage-runtests, ... -- installed by sagemath-repl - # - bin/sage-ipython -- uses sage.repl, so installed by sagemath-repl - -[options.extras_require] -# sage.env can optionally use sage_conf -conf = SPKG_INSTALL_REQUIRES_sage_conf - -# For "sage --docbuild" -docbuild = SPKG_INSTALL_REQUIRES_sage_docbuild - -# For "sage", "sage -t", ... -sage = SPKG_INSTALL_REQUIRES_sagelib - -# For "sage --cython" -cython = SPKG_INSTALL_REQUIRES_cython - -# For "sage --pytest" -pytest = SPKG_INSTALL_REQUIRES_pytest - -# For "sage --rst2ipynb" -rst2ipynb = SPKG_INSTALL_REQUIRES_rst2ipynb - -# For "sage --tox" -tox = SPKG_INSTALL_REQUIRES_tox - -# For "sage --sws2rst" -sws2rst = SPKG_INSTALL_REQUIRES_sage_sws2rst diff --git a/pkgs/sagemath-mcqd/VERSION.txt b/pkgs/sagemath-mcqd/VERSION.txt index d0cd2bc56e3..7694f7787b5 100644 --- a/pkgs/sagemath-mcqd/VERSION.txt +++ b/pkgs/sagemath-mcqd/VERSION.txt @@ -1 +1 @@ -10.2.beta9 +10.2.rc0 diff --git a/pkgs/sagemath-meataxe/VERSION.txt b/pkgs/sagemath-meataxe/VERSION.txt index d0cd2bc56e3..7694f7787b5 100644 --- a/pkgs/sagemath-meataxe/VERSION.txt +++ b/pkgs/sagemath-meataxe/VERSION.txt @@ -1 +1 @@ -10.2.beta9 +10.2.rc0 diff --git a/pkgs/sagemath-objects/VERSION.txt b/pkgs/sagemath-objects/VERSION.txt index d0cd2bc56e3..7694f7787b5 100644 --- a/pkgs/sagemath-objects/VERSION.txt +++ b/pkgs/sagemath-objects/VERSION.txt @@ -1 +1 @@ -10.2.beta9 +10.2.rc0 diff --git a/pkgs/sagemath-objects/pyproject.toml.m4 b/pkgs/sagemath-objects/pyproject.toml.m4 index d8fda57a8f8..ce80e0fea5d 100644 --- a/pkgs/sagemath-objects/pyproject.toml.m4 +++ b/pkgs/sagemath-objects/pyproject.toml.m4 @@ -11,3 +11,37 @@ requires = [ SPKG_INSTALL_REQUIRES_cysignals ] build-backend = "setuptools.build_meta" + +[project] +name = "sagemath-objects" +description = "Sage: Open Source Mathematics Software: Sage objects, elements, parents, categories, coercion, metaclasses" +dependencies = [ + SPKG_INSTALL_REQUIRES_gmpy2 + SPKG_INSTALL_REQUIRES_cysignals +] +dynamic = ["version"] +include(`pyproject_toml_metadata.m4')dnl' + +[project.optional-dependencies] +# Currently we do not use the sage doctester to test sagemath-objects, +# so we do not list sagemath-repl here. +test = [] + +[project.readme] +file = "README.rst" +content-type = "text/x-rst" + +[tool.setuptools] +include-package-data = false + +[tool.setuptools.dynamic] +version = {file = ["VERSION.txt"]} + +[tool.setuptools.package-data] +"sage.cpython" = [ + "pyx_visit.h", + "string_impl.h", + "cython_metaclass.h", + "python_debug.h", +] +"sage.rings" = ["integer_fake.h"] diff --git a/pkgs/sagemath-objects/setup.cfg.m4 b/pkgs/sagemath-objects/setup.cfg.m4 deleted file mode 100644 index 894c07b5bbf..00000000000 --- a/pkgs/sagemath-objects/setup.cfg.m4 +++ /dev/null @@ -1,31 +0,0 @@ -# -*- conf-unix -*- -[metadata] -name = sagemath-objects -version = file: VERSION.txt -description = Sage: Open Source Mathematics Software: Sage objects, elements, parents, categories, coercion, metaclasses -long_description = file: README.rst -long_description_content_type = text/x-rst -include(`setup_cfg_metadata.m4')dnl' - -[options] -include(`sage_spkg_versions.m4')dnl' -python_requires = >=3.9, <3.12 -install_requires = - SPKG_INSTALL_REQUIRES_gmpy2 - SPKG_INSTALL_REQUIRES_cysignals - -[options.extras_require] -# Currently we do not use the sage doctester to test sagemath-objects, -# so we do not list sagemath-repl here. -test = - - -[options.package_data] -sage.cpython = - pyx_visit.h - string_impl.h - cython_metaclass.h - python_debug.h - -sage.rings = - integer_fake.h diff --git a/pkgs/sagemath-repl/VERSION.txt b/pkgs/sagemath-repl/VERSION.txt index d0cd2bc56e3..7694f7787b5 100644 --- a/pkgs/sagemath-repl/VERSION.txt +++ b/pkgs/sagemath-repl/VERSION.txt @@ -1 +1 @@ -10.2.beta9 +10.2.rc0 diff --git a/pkgs/sagemath-repl/pyproject.toml.m4 b/pkgs/sagemath-repl/pyproject.toml.m4 index fb2db955ed5..dfdfb692c9b 100644 --- a/pkgs/sagemath-repl/pyproject.toml.m4 +++ b/pkgs/sagemath-repl/pyproject.toml.m4 @@ -6,3 +6,69 @@ requires = [ SPKG_INSTALL_REQUIRES_wheel ] build-backend = "setuptools.build_meta" + +[project] +name = "sagemath-repl" +description = "Sage: Open Source Mathematics Software: IPython kernel, Sage preparser, doctester" +dependencies = [ + SPKG_INSTALL_REQUIRES_sagemath_objects + SPKG_INSTALL_REQUIRES_sagemath_environment + SPKG_INSTALL_REQUIRES_ipython + SPKG_INSTALL_REQUIRES_ipywidgets +] +dynamic = ["version"] +include(`pyproject_toml_metadata.m4')dnl' + +[project.readme] +file = "README.rst" +content-type = "text/x-rst" + +[tool.setuptools] +py-modules = [ + "sage.all__sagemath_repl", + "sage.misc.all__sagemath_repl", + "sage.misc.banner", + "sage.misc.sagedoc", + "sage.misc.sage_input", + "sage.misc.sage_eval", +] +packages = [ + "sage.doctest", + "sage.repl", + "sage.repl.display", + "sage.repl.ipython_kernel", + "sage.repl.rich_output", +] +script-files = [ + # Other scripts that should be in the path also for OS packaging of sage: + "bin/sage-eval", + # Included because it is useful for doctesting/coverage testing user scripts too: + "bin/sage-runtests", + "bin/sage-fixdoctests", + "bin/sage-coverage", + # Helper scripts invoked by sage script + # (they would actually belong to something like libexec) + "bin/sage-cachegrind", + "bin/sage-callgrind", + "bin/sage-massif", + "bin/sage-omega", + "bin/sage-valgrind", + "bin/sage-cleaner", + # Uncategorized scripts in alphabetical order + "bin/sage-inline-fortran", + "bin/sage-ipynb2rst", + "bin/sage-ipython", + "bin/sage-notebook", + "bin/sage-preparse", + "bin/sage-run", + "bin/sage-run-cython", + "bin/sage-startuptime.py", +] +include-package-data = false + +[tool.setuptools.dynamic] +version = {file = ["VERSION.txt"]} + +[tool.setuptools.package-data] +"sage.doctest" = ["tests/*"] +"sage.repl.rich_output" = ["example*"] diff --git a/pkgs/sagemath-repl/setup.cfg.m4 b/pkgs/sagemath-repl/setup.cfg.m4 deleted file mode 100644 index f71d7bf6c2a..00000000000 --- a/pkgs/sagemath-repl/setup.cfg.m4 +++ /dev/null @@ -1,64 +0,0 @@ -include(`sage_spkg_versions.m4')dnl' -*- conf-unix -*- -[metadata] -name = sagemath-repl -version = file: VERSION.txt -description = Sage: Open Source Mathematics Software: System and software environment -long_description = file: README.rst -long_description_content_type = text/x-rst -include(`setup_cfg_metadata.m4')dnl' - -[options] -python_requires = >=3.9, <3.12 -install_requires = - SPKG_INSTALL_REQUIRES_sagemath_objects - SPKG_INSTALL_REQUIRES_sagemath_environment - SPKG_INSTALL_REQUIRES_ipython - SPKG_INSTALL_REQUIRES_ipywidgets - -py_modules = - sage.all__sagemath_repl - sage.misc.all__sagemath_repl - sage.misc.banner - sage.misc.sagedoc - sage.misc.sage_input - sage.misc.sage_eval - -packages = - sage.doctest - sage.repl - sage.repl.display - sage.repl.ipython_kernel - sage.repl.rich_output - -scripts = - # Other scripts that should be in the path also for OS packaging of sage: - bin/sage-eval - # Included because it is useful for doctesting/coverage testing user scripts too: - bin/sage-runtests - bin/sage-fixdoctests - bin/sage-coverage - # Helper scripts invoked by sage script - # (they would actually belong to something like libexec) - bin/sage-cachegrind - bin/sage-callgrind - bin/sage-massif - bin/sage-omega - bin/sage-valgrind - bin/sage-cleaner - # Uncategorized scripts in alphabetical order - bin/sage-inline-fortran - bin/sage-ipynb2rst - bin/sage-ipython - bin/sage-notebook - bin/sage-preparse - bin/sage-run - bin/sage-run-cython - bin/sage-startuptime.py - -[options.package_data] - -sage.doctest = - tests/* - -sage.repl.rich_output = - example* diff --git a/pkgs/sagemath-sirocco/VERSION.txt b/pkgs/sagemath-sirocco/VERSION.txt index d0cd2bc56e3..7694f7787b5 100644 --- a/pkgs/sagemath-sirocco/VERSION.txt +++ b/pkgs/sagemath-sirocco/VERSION.txt @@ -1 +1 @@ -10.2.beta9 +10.2.rc0 diff --git a/pkgs/sagemath-tdlib/VERSION.txt b/pkgs/sagemath-tdlib/VERSION.txt index d0cd2bc56e3..7694f7787b5 100644 --- a/pkgs/sagemath-tdlib/VERSION.txt +++ b/pkgs/sagemath-tdlib/VERSION.txt @@ -1 +1 @@ -10.2.beta9 +10.2.rc0 diff --git a/src/VERSION.txt b/src/VERSION.txt index d0cd2bc56e3..7694f7787b5 100644 --- a/src/VERSION.txt +++ b/src/VERSION.txt @@ -1 +1 @@ -10.2.beta9 +10.2.rc0 diff --git a/src/bin/sage-version.sh b/src/bin/sage-version.sh index 392f585e5de..d6b42fe389d 100644 --- a/src/bin/sage-version.sh +++ b/src/bin/sage-version.sh @@ -4,6 +4,6 @@ # which stops "setup.py develop" from rewriting it as a Python file. : # This file is auto-generated by the sage-update-version script, do not edit! -SAGE_VERSION='10.2.beta9' -SAGE_RELEASE_DATE='2023-10-30' -SAGE_VERSION_BANNER='SageMath version 10.2.beta9, Release Date: 2023-10-30' +SAGE_VERSION='10.2.rc0' +SAGE_RELEASE_DATE='2023-11-05' +SAGE_VERSION_BANNER='SageMath version 10.2.rc0, Release Date: 2023-11-05' diff --git a/src/doc/en/developer/coding_in_python.rst b/src/doc/en/developer/coding_in_python.rst index d96106ecc98..e39a3f72c4d 100644 --- a/src/doc/en/developer/coding_in_python.rst +++ b/src/doc/en/developer/coding_in_python.rst @@ -585,6 +585,57 @@ by return initialize_big_data() +Static typing +============= + +Python libraries are increasingly annotated with static typing information; +see the `Python reference on typing `_. + +For typechecking the Sage library, the project uses :ref:`pyright `; +it automatically runs in the GitHub Actions CI and can also be run locally. + +As of Sage 10.2, the Sage library only contains a minimal set of such type +annotations. Pull requests that add more annotations are generally welcome. + +The Sage library makes very extensive use of Cython (see chapter :ref:`chapter-cython`). +Although Cython source code often declares static types for the purpose of +compilation to efficient machine code, this typing information is unfortunately +not visible to static checkers such as Pyright. It is necessary to create `type stub +files (".pyi") `_ +that provide this information. Although various +`tools for writing and maintaining type stub files +`_ +are available, creating stub files for Cython files involves manual work. +There is hope that better tools become available soon, see for example +`cython/cython #5744 `_. +Contributing to the development and testing of such tools likely will have a +greater impact than writing the typestub files manually. + +For Cython modules of the Sage library, these type stub files would be placed +next to the ``.pyx`` and ``.pxd`` files. + +When importing from other Python libraries that do not provide sufficient typing +information, it is possible to augment the library's typing information for +the purposes of typechecking the Sage library: + +- Create typestub files and place them in the directory ``SAGE_ROOT/src/typings``. + For example, the distribution **pplpy** provides the top-level package :mod:`ppl`, + which publishes no typing information. We can create a typestub file + ``SAGE_ROOT/src/typings/ppl.pyi`` or ``SAGE_ROOT/src/typings/ppl/__init__.pyi``. + +- When these typestub files are working well, it is preferable from the viewpoint + of the Sage project that they are "upstreamed", i.e., contributed to the + project that maintains the library. If a new version of the upstream library + becomes available that provides the necessary typing information, we can + update the package in the Sage distribution and remove the typestub files again + from ``SAGE_ROOT/src/typings``. + +- As a fallback, when neither adding typing annotations to source files + nor adding typestub files is welcomed by the upstream project, it is possible + to `contribute typestubs files instead to the typeshed community project + `_. + + Deprecation =========== diff --git a/src/doc/en/reference/references/index.rst b/src/doc/en/reference/references/index.rst index d91866314fc..d9f406d055d 100644 --- a/src/doc/en/reference/references/index.rst +++ b/src/doc/en/reference/references/index.rst @@ -246,6 +246,10 @@ REFERENCES: Symposium, Volume 51, page 20. Australian Computer Society, Inc. 2006. +.. [Ang1997] B. Anglès. 1997. *On some characteristic polynomials attached to + finite Drinfeld modules.* manuscripta mathematica 93, 1 (01 Aug 1997), + 369–379. https://doi.org/10.1007/BF02677478 + .. [AP1986] \S. Arnborg, A. Proskurowski, *Characterization and Recognition of Partial 3-Trees*, SIAM Journal of Alg. and Discrete Methods, @@ -4766,11 +4770,17 @@ REFERENCES: Int. Math. Res. Not. (2015). :doi:`10.1093/imrn/rnv194`, :arxiv:`1408.0320`. -.. [MS2019] \Y. Musleh and \'E. Schost. Computing the characteristic polynomial - of a finite rank two Drinfeld module. In Proceedings of the 2019 +.. [MS2019] \Y. Musleh and \'E. Schost. *Computing the characteristic polynomial + of a finite rank two Drinfeld module*. In Proceedings of the 2019 ACM on International Symposium on Symbolic and Algebraic Computation, pages 307–314. ACM, 2019. +.. [MS2023] \Y. Musleh and \'E. Schost. *Computing the Characteristic Polynomial + of Endomorphisms of a finite Drinfeld Module using Crystalline + Cohomology*. In Proceedings of the 2023 ACM on International + Symposium on Symbolic and Algebraic Computation, pages 461–469. + ACM, 2023. + .. [MSSY2001] Mateescu, A., Salomaa, A., Salomaa, K. and Yu, S., *A sharpening of the Parikh mapping*. Theoret. Informatics Appl. 35 (2001) 551-564. diff --git a/src/sage/algebras/cluster_algebra.py b/src/sage/algebras/cluster_algebra.py index 14669dfed5c..880814feba7 100644 --- a/src/sage/algebras/cluster_algebra.py +++ b/src/sage/algebras/cluster_algebra.py @@ -297,15 +297,16 @@ which might not be a good idea in algebras that are too big. One workaround is to first disable F-polynomials and then recompute only the desired mutations:: - sage: A.reset_exploring_iterator(mutating_F=False) # long time - sage: v = (-1, 1, -2, 2, -1, 1, -1, 1, 1) # long time - sage: seq = A.find_g_vector(v); seq # long time random + sage: # long time + sage: A.reset_exploring_iterator(mutating_F=False) + sage: v = (-1, 1, -2, 2, -1, 1, -1, 1, 1) + sage: seq = A.find_g_vector(v); seq # random [1, 0, 2, 6, 5, 4, 3, 8, 1] - sage: S = A.initial_seed().mutate(seq, inplace=False) # long time - sage: v in S.g_vectors() # long time + sage: S = A.initial_seed().mutate(seq, inplace=False) + sage: v in S.g_vectors() True - sage: A.current_seed().mutate(seq) # long time - sage: A.F_polynomial((-1, 1, -2, 2, -1, 1, -1, 1, 1)) # long time + sage: A.current_seed().mutate(seq) + sage: A.F_polynomial((-1, 1, -2, 2, -1, 1, -1, 1, 1)) u0*u1^2*u2^2*u3*u4*u5*u6*u8 + ... 2*u2 + u4 + u6 + 1 @@ -445,7 +446,7 @@ def _div_(self, other): """ return self.lift() / other.lift() - def d_vector(self): + def d_vector(self) -> tuple: r""" Return the denominator vector of ``self`` as a tuple of integers. @@ -461,7 +462,7 @@ def d_vector(self): minimal = map(min, zip(*monomials)) return tuple(-vector(minimal))[:self.parent().rank()] - def _repr_(self): + def _repr_(self) -> str: r""" Return the string representation of ``self``. @@ -524,7 +525,7 @@ def F_polynomial(self): subs_dict[A.coefficient(i).lift()] = A._U.gen(i) return A._U(self.lift().substitute(subs_dict)) - def is_homogeneous(self): + def is_homogeneous(self) -> bool: r""" Return ``True`` if ``self`` is a homogeneous element of ``self.parent()``. @@ -540,7 +541,7 @@ def is_homogeneous(self): """ return getattr(self, '_is_homogeneous', len(self.homogeneous_components()) == 1) - def homogeneous_components(self): + def homogeneous_components(self) -> dict: r""" Return a dictionary of the homogeneous components of ``self``. @@ -599,10 +600,10 @@ def theta_basis_decomposition(self): A = self.parent() B = A.b_matrix() U = A._U - out = dict() + out = {} zero_A = A(0) zero_U = U(0) - zero_t = (0,)*A.rank() + zero_t = (0,) * A.rank() components = self.homogeneous_components() @@ -612,12 +613,13 @@ def theta_basis_decomposition(self): while f_poly != zero_U: y_exp = min(f_poly.dict()) coeff = f_poly.dict()[y_exp] - g_theta = tuple(g_vect + B*vector(y_exp)) - out[g_theta] = out.get(g_theta, zero_A) + A({zero_t + tuple(y_exp):coeff}) - f_poly -= U({y_exp:coeff}) * A.theta_basis_F_polynomial(g_theta) + g_theta = tuple(g_vect + B * vector(y_exp)) + out[g_theta] = out.get(g_theta, zero_A) + A({zero_t + tuple(y_exp): coeff}) + f_poly -= U({y_exp: coeff}) * A.theta_basis_F_polynomial(g_theta) return out + ############################################################################## # Seeds ############################################################################## @@ -721,7 +723,7 @@ def __eq__(self, other): self.parent() == other.parent() and frozenset(self.g_vectors()) == frozenset(other.g_vectors())) - def __contains__(self, element): + def __contains__(self, element) -> bool: r""" Test whether ``element`` belong to ``self``. @@ -770,7 +772,7 @@ def __hash__(self): """ return hash(frozenset(self.g_vectors())) - def _repr_(self): + def _repr_(self) -> str: r""" Return the string representation of ``self``. @@ -790,12 +792,11 @@ def _repr_(self): and no coefficients over Integer Ring obtained from the initial by mutating along the sequence [0, 1] """ - if self._path == []: + if not self._path: return "The initial seed of a %s" % str(self.parent())[2:] - elif len(self._path) == 1: + if len(self._path) == 1: return "The seed of a %s obtained from the initial by mutating in direction %s" % (str(self.parent())[2:], str(self._path[0])) - else: - return "The seed of a %s obtained from the initial by mutating along the sequence %s" % (str(self.parent())[2:], str(self._path)) + return "The seed of a %s obtained from the initial by mutating along the sequence %s" % (str(self.parent())[2:], str(self._path)) def parent(self): r""" @@ -809,7 +810,7 @@ def parent(self): """ return self._parent - def depth(self): + def depth(self) -> int: r""" Return the length of a mutation sequence from the initial seed of :meth:`parent` to ``self``. @@ -836,7 +837,7 @@ def depth(self): """ return len(self._path) - def path_from_initial_seed(self): + def path_from_initial_seed(self) -> list: r""" Return a mutation sequence from the initial seed of :meth:`parent` to ``self``. @@ -892,7 +893,7 @@ def c_matrix(self): """ return copy(self._C) - def c_vector(self, j): + def c_vector(self, j) -> tuple: r""" Return the ``j``-th c-vector of ``self``. @@ -915,7 +916,7 @@ def c_vector(self, j): """ return tuple(self._C.column(j)) - def c_vectors(self): + def c_vectors(self) -> list[tuple]: r""" Return all the c-vectors of ``self``. @@ -943,7 +944,7 @@ def g_matrix(self): """ return copy(self._G) - def g_vector(self, j): + def g_vector(self, j) -> tuple: r""" Return the ``j``-th g-vector of ``self``. @@ -961,7 +962,7 @@ def g_vector(self, j): """ return tuple(self._G.column(j)) - def g_vectors(self): + def g_vectors(self) -> list[tuple]: r""" Return all the g-vectors of ``self``. @@ -992,7 +993,7 @@ def F_polynomial(self, j): """ return self.parent().F_polynomial(self.g_vector(j)) - def F_polynomials(self): + def F_polynomials(self) -> list: r""" Return all the F-polynomials of ``self``. @@ -1026,7 +1027,7 @@ def cluster_variable(self, j): """ return self.parent().cluster_variable(self.g_vector(j)) - def cluster_variables(self): + def cluster_variables(self) -> list: r""" Return all the cluster variables of ``self``. @@ -1105,7 +1106,7 @@ def mutate(self, direction, **kwargs): for k in seq: if k not in range(n): - raise ValueError('cannot mutate in direction ' + str(k)) + raise ValueError(f'cannot mutate in direction {k}') # store new mutation path if to_mutate._path and to_mutate._path[-1] == k: @@ -1329,8 +1330,9 @@ def __classcall__(self, data, **kwargs): # kwargs['cluster_variable_prefix']+str(j) is not the name of an # initial cluster variable nor a coefficient. This will be used in # mutate_initial to name new cluster variables. - splitnames = map(lambda w: w.partition(kwargs['cluster_variable_prefix']), - kwargs['cluster_variable_names'] + kwargs['coefficient_names']) + splitnames = (w.partition(kwargs['cluster_variable_prefix']) + for w in + kwargs['cluster_variable_names'] + kwargs['coefficient_names']) nfi = 1 + max((int(v) for u, _, v in splitnames if u == '' and v.isdigit()), default=-1) kwargs.setdefault('next_free_index', nfi) @@ -1412,7 +1414,7 @@ def __init__(self, B, **kwargs): embedding = SetMorphism(Hom(self, self.ambient()), lambda x: x.lift()) self._populate_coercion_lists_(embedding=embedding) - def _repr_(self): + def _repr_(self) -> str: r""" Return the string representation of ``self``. @@ -1542,14 +1544,14 @@ def coxeter_element(self): ... ValueError: the initial exchange matrix is not acyclic """ - dg = DiGraph(self.b_matrix().apply_map(lambda x: ZZ(0) if x <= 0 else ZZ(1))) + dg = DiGraph(self.b_matrix().apply_map(lambda x: ZZ.zero() if x <= 0 else ZZ.one())) acyclic, coxeter = dg.is_directed_acyclic(certificate=True) if not acyclic: raise ValueError("the initial exchange matrix is not acyclic") return coxeter @cached_method - def is_acyclic(self): + def is_acyclic(self) -> bool: r""" Return ``True`` if the exchange matrix in the initial seed is acyclic, ``False`` otherwise. @@ -1562,7 +1564,7 @@ def is_acyclic(self): sage: A.is_acyclic() False """ - dg = DiGraph(self.b_matrix().apply_map(lambda x: ZZ(0) if x <= 0 else ZZ(1))) + dg = DiGraph(self.b_matrix().apply_map(lambda x: ZZ.zero() if x <= 0 else ZZ.one())) return dg.is_directed_acyclic() def rank(self): @@ -1667,7 +1669,7 @@ def clear_computed_data(self): self.reset_current_seed() self.reset_exploring_iterator() - def contains_seed(self, seed): + def contains_seed(self, seed) -> bool: r""" Test if ``seed`` is a seed of ``self``. @@ -1741,9 +1743,9 @@ def euler_matrix(self): """ if not self.is_acyclic(): raise ValueError("the initial exchange matrix is not acyclic") - return 1 + self.b_matrix().apply_map(lambda x: min(ZZ(0), x)) + return 1 + self.b_matrix().apply_map(lambda x: min(ZZ.zero(), x)) - def d_vector_to_g_vector(self, d): + def d_vector_to_g_vector(self, d) -> tuple: r""" Return the g-vector of an element of ``self`` having d-vector ``d`` @@ -1765,11 +1767,11 @@ def d_vector_to_g_vector(self, d): sage: A.d_vector_to_g_vector((1,0,-1)) (-1, 1, 2) """ - dm = vector(( x if x < 0 else 0 for x in d)) + dm = vector((x if x < 0 else 0 for x in d)) dp = vector(d) - dm - return tuple(- dm - self.euler_matrix()*dp) + return tuple(- dm - self.euler_matrix() * dp) - def g_vector_to_d_vector(self, g): + def g_vector_to_d_vector(self, g) -> tuple: r""" Return the d-vector of an element of ``self`` having g-vector ``g`` @@ -1797,8 +1799,8 @@ def g_vector_to_d_vector(self, g): g = vector(g) for i in c: dp[i] = -min(g[i], 0) - g += min(g[i],0)*E.column(i) - return tuple(-g+dp) + g += min(g[i], 0) * E.column(i) + return tuple(-g + dp) def g_vectors(self, mutating_F=True): r""" @@ -1872,7 +1874,7 @@ def F_polynomials(self): """ return map(self.F_polynomial, self.g_vectors()) - def g_vectors_so_far(self): + def g_vectors_so_far(self) -> list: r""" Return a list of the g-vectors of cluster variables encountered so far. @@ -1886,7 +1888,7 @@ def g_vectors_so_far(self): """ return list(self._path_dict) - def cluster_variables_so_far(self): + def cluster_variables_so_far(self) -> list: r""" Return a list of the cluster variables encountered so far. @@ -1900,7 +1902,7 @@ def cluster_variables_so_far(self): """ return [self.cluster_variable(v) for v in self.g_vectors_so_far()] - def F_polynomials_so_far(self): + def F_polynomials_so_far(self) -> list: r""" Return a list of the F-polynomials encountered so far. @@ -2120,7 +2122,7 @@ def coefficient(self, j): return self.retract(self.base().gen(j)) @cached_method - def coefficients(self): + def coefficients(self) -> tuple: r""" Return the list of coefficients of ``self``. @@ -2138,7 +2140,7 @@ def coefficients(self): else: return () - def coefficient_names(self): + def coefficient_names(self) -> tuple: r""" Return the list of coefficient names. @@ -2174,7 +2176,7 @@ def initial_cluster_variable(self, j): return self.retract(self.ambient().gen(j)) @cached_method - def initial_cluster_variables(self): + def initial_cluster_variables(self) -> tuple: r""" Return the list of initial cluster variables of ``self``. @@ -2186,7 +2188,7 @@ def initial_cluster_variables(self): """ return tuple(map(self.retract, self.ambient().gens()[:self.rank()])) - def initial_cluster_variable_names(self): + def initial_cluster_variable_names(self) -> tuple: r""" Return the list of initial cluster variable names. @@ -2661,17 +2663,17 @@ def theta_basis_F_polynomial(self, g_vector): raise NotImplementedError("currently only implemented for cluster algebras of rank 2") # extract the part of g_vector not coming from the initial cluster - d = tuple( max(x, 0) for x in self.g_vector_to_d_vector(g_vector) ) + d = tuple(max(x, 0) for x in self.g_vector_to_d_vector(g_vector)) g = self.d_vector_to_g_vector(d) - shifts = ((d[0]+g[0])/self._B0[0, 1], (d[1]+g[1])/self._B0[1, 0] ) + shifts = ((d[0] + g[0]) / self._B0[0, 1], (d[1] + g[1]) / self._B0[1, 0]) signs = (self._B0[0, 1].sign(), self._B0[1, 0].sign()) u = list(self._U.gens()) output = self._U.zero() - for p in range(0, d[1] + 1): - for q in range(0, d[0] + 1): - output += self._greedy_coefficient(d, p, q) * u[1] ** (signs[0]*p - shifts[0]) * u[0] ** (signs[1]*q - shifts[1]) + for p in range(d[1] + 1): + for q in range(d[0] + 1): + output += self._greedy_coefficient(d, p, q) * u[1] ** (signs[0] * p - shifts[0]) * u[0] ** (signs[1] * q - shifts[1]) return output @cached_method @@ -2696,7 +2698,7 @@ def _greedy_coefficient(self, d_vector, p, q): p = Integer(p) q = Integer(q) if p == 0 and q == 0: - return Integer(1) + return ZZ.one() sum1 = 0 for k in range(1, p + 1): bino = 0 diff --git a/src/sage/algebras/free_algebra.py b/src/sage/algebras/free_algebra.py index 460b623b877..50793075532 100644 --- a/src/sage/algebras/free_algebra.py +++ b/src/sage/algebras/free_algebra.py @@ -127,7 +127,7 @@ NotImplementedError: polynomials over Free Algebra on 2 generators (a, b) over Integer Ring are not supported in Singular """ -#***************************************************************************** +# *************************************************************************** # Copyright (C) 2005 David Kohel # Copyright (C) 2005,2006 William Stein # Copyright (C) 2011 Simon King @@ -136,8 +136,8 @@ # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# *************************************************************************** from sage.categories.rings import Rings @@ -240,9 +240,9 @@ class FreeAlgebraFactory(UniqueFactory): a*b^2*c^3 """ def create_key(self, base_ring, arg1=None, arg2=None, - sparse=None, order=None, - names=None, name=None, - implementation=None, degrees=None): + sparse=None, order=None, + names=None, name=None, + implementation=None, degrees=None): """ Create the key under which a free algebra is stored. @@ -268,7 +268,7 @@ def create_key(self, base_ring, arg1=None, arg2=None, # this is used for pickling if degrees is None: return (base_ring,) - return tuple(degrees),base_ring + return tuple(degrees), base_ring # test if we can use libSingular/letterplace if implementation == "letterplace": if order is None: @@ -321,7 +321,6 @@ def create_object(self, version, key): Free Associative Unital Algebra on 2 generators (x, y) over Rational Field sage: FreeAlgebra.create_object('4.7.1', (QQ['x','y'],)) is FreeAlgebra(QQ,['x','y']) False - """ if len(key) == 1: from sage.algebras.letterplace.free_algebra_letterplace import FreeAlgebra_letterplace @@ -335,7 +334,7 @@ def create_object(self, version, key): FreeAlgebra = FreeAlgebraFactory('FreeAlgebra') -def is_FreeAlgebra(x): +def is_FreeAlgebra(x) -> bool: """ Return True if x is a free algebra; otherwise, return False. @@ -352,10 +351,9 @@ def is_FreeAlgebra(x): True sage: is_FreeAlgebra(FreeAlgebra(ZZ,10,'x',implementation='letterplace', degrees=list(range(1,11)))) True - """ from sage.algebras.letterplace.free_algebra_letterplace import FreeAlgebra_letterplace - return isinstance(x, (FreeAlgebra_generic,FreeAlgebra_letterplace)) + return isinstance(x, (FreeAlgebra_generic, FreeAlgebra_letterplace)) class FreeAlgebra_generic(CombinatorialFreeModule, Algebra): @@ -383,8 +381,7 @@ class FreeAlgebra_generic(CombinatorialFreeModule, Algebra): TESTS: - Free algebras commute with their base ring. - :: + Free algebras commute with their base ring:: sage: K. = FreeAlgebra(QQ) sage: K.is_commutative() @@ -463,9 +460,11 @@ def one_basis(self): """ return self._indices.one() - def is_field(self, proof=True): + def is_field(self, proof=True) -> bool: """ - Return True if this Free Algebra is a field, which is only if the + Return ``True`` if this Free Algebra is a field. + + This happens only if the base ring is a field and there are no generators EXAMPLES:: @@ -481,9 +480,9 @@ def is_field(self, proof=True): return self.base_ring().is_field(proof) return False - def is_commutative(self): + def is_commutative(self) -> bool: """ - Return True if this free algebra is commutative. + Return ``True`` if this free algebra is commutative. EXAMPLES:: @@ -496,7 +495,7 @@ def is_commutative(self): """ return self.__ngens <= 1 and self.base_ring().is_commutative() - def _repr_(self): + def _repr_(self) -> str: """ Text representation of this free algebra. @@ -514,7 +513,7 @@ def _repr_(self): return "Free Algebra on {} generators {} over {}".format( self.__ngens, self.gens(), self.base_ring()) - def _latex_(self): + def _latex_(self) -> str: r""" Return a latex representation of ``self``. @@ -588,9 +587,9 @@ def _element_constructor_(self, x): return x if P is not self.base_ring(): return self.element_class(self, x) - elif hasattr(x,'letterplace_polynomial'): + elif hasattr(x, 'letterplace_polynomial'): P = x.parent() - if self.has_coerce_map_from(P): # letterplace versus generic + if self.has_coerce_map_from(P): # letterplace versus generic ngens = P.ngens() M = self._indices @@ -598,14 +597,15 @@ def exp_to_monomial(T): out = [] for i in range(len(T)): if T[i]: - out.append((i % ngens,T[i])) + out.append((i % ngens, T[i])) return M(out) - return self.element_class(self, {exp_to_monomial(T):c for T,c in x.letterplace_polynomial().dict().items()}) + return self.element_class(self, {exp_to_monomial(T): c + for T, c in x.letterplace_polynomial().dict().items()}) # ok, not a free algebra element (or should not be viewed as one). if isinstance(x, str): from sage.misc.sage_eval import sage_eval G = self.gens() - d = {str(v): G[i] for i,v in enumerate(self.variable_names())} + d = {str(v): G[i] for i, v in enumerate(self.variable_names())} return self(sage_eval(x, locals=d)) R = self.base_ring() # coercion from free monoid @@ -619,7 +619,7 @@ def exp_to_monomial(T): # Check if it's a factorization from sage.structure.factorization import Factorization if isinstance(x, Factorization): - return self.prod(f**i for f,i in x) + return self.prod(f**i for f, i in x) # coercion via base ring x = R(x) @@ -849,38 +849,50 @@ def g_algebra(self, relations, names=None, order='degrevlex', check=True): sage: (x,y,z) = G.gens() sage: y*x -x*y + z + + TESTS:: + + sage: S = FractionField(QQ['t']) + sage: t = S.gen() + sage: F. = FreeAlgebra(S) + sage: K = F.g_algebra({y*x:-x*y+1+y}) + sage: x,y = K.gens() + sage: 1+t*y*x + (-t)*x*y + t*y + (t + 1) """ from sage.matrix.constructor import Matrix base_ring = self.base_ring() + polynomial_ring = PolynomialRing(base_ring, self.gens()) n = self.__ngens cmat = Matrix(base_ring, n) - dmat = Matrix(self, n) + dmat = Matrix(polynomial_ring, n) for i in range(n): for j in range(i + 1, n): - cmat[i,j] = 1 - for (to_commute,commuted) in relations.items(): - #This is dirty, coercion is broken - assert isinstance(to_commute, FreeAlgebraElement), to_commute.__class__ + cmat[i, j] = 1 + for to_commute, commuted in relations.items(): + # This is dirty, coercion is broken + assert isinstance(to_commute, FreeAlgebraElement), to_commute assert isinstance(commuted, FreeAlgebraElement), commuted - ((v1,e1),(v2,e2)) = list(list(to_commute)[0][0]) + (v1, e1), (v2, e2) = next(iter(to_commute))[0] assert e1 == 1 assert e2 == 1 assert v1 > v2 c_coef = None d_poly = None + reverse_monomial = v2 * v1 for m, c in commuted: - if list(m) == [(v2,1),(v1,1)]: + if m == reverse_monomial: c_coef = c # buggy coercion workaround - d_poly = commuted - self(c) * self(m) + d_poly = commuted - c * self.monomial(m) break - assert c_coef is not None, list(m) + assert c_coef is not None, m v2_ind = self.gens().index(v2) v1_ind = self.gens().index(v1) - cmat[v2_ind,v1_ind] = c_coef + cmat[v2_ind, v1_ind] = c_coef if d_poly: - dmat[v2_ind,v1_ind] = d_poly + dmat[v2_ind, v1_ind] = polynomial_ring(d_poly) from sage.rings.polynomial.plural import g_Algebra return g_Algebra(base_ring, cmat, dmat, names=names or self.variable_names(), @@ -920,18 +932,18 @@ def pbw_element(self, elt): return PBW.zero() l = {} - while elt: # != 0 + while elt: # != 0 lst = list(elt) support = [i[0].to_word() for i in lst] min_elt = support[0] - for word in support[1:len(support)-1]: + for word in support[1:len(support) - 1]: if min_elt.lex_less(word): min_elt = word coeff = lst[support.index(min_elt)][1] min_elt = min_elt.to_monoid_element() l[min_elt] = l.get(min_elt, 0) + coeff elt = elt - coeff * self.lie_polynomial(min_elt) - return PBW.sum_of_terms([(k, v) for k,v in l.items() if v != 0], distinct=True) + return PBW.sum_of_terms([(k, v) for k, v in l.items() if v != 0], distinct=True) def lie_polynomial(self, w): """ @@ -1000,10 +1012,10 @@ def lie_polynomial(self, w): if len(factor) == 1: ret = ret * self(M(factor)) continue - x,y = factor.standard_factorization() + x, y = factor.standard_factorization() x = self.lie_polynomial(M(x)) y = self.lie_polynomial(M(y)) - ret = ret * (x*y - y*x) + ret = ret * (x * y - y * x) return ret diff --git a/src/sage/algebras/hecke_algebras/cubic_hecke_algebra.py b/src/sage/algebras/hecke_algebras/cubic_hecke_algebra.py index 29d444e745f..fdc94b13907 100644 --- a/src/sage/algebras/hecke_algebras/cubic_hecke_algebra.py +++ b/src/sage/algebras/hecke_algebras/cubic_hecke_algebra.py @@ -1467,7 +1467,7 @@ def _an_element_(self): """ n = self.ngens() + 1 base_ring = self.base_ring() - u, v, w = [base_ring(para) for para in self._cubic_equation_parameters] + u, v, w = (base_ring(para) for para in self._cubic_equation_parameters) const = (u*~w - v) * self.one() gens = self.gens() @@ -1521,7 +1521,7 @@ def chevie(self): from sage.interfaces.gap3 import gap3 gap3_function = gap3(gap3_function_str) - na, nb, nc = ['\"%s\"' % indet for indet in self.extension_ring(generic=True).variable_names()] + na, nb, nc = ('\"%s\"' % indet for indet in self.extension_ring(generic=True).variable_names()) return gap3_function(st_number, na, nb, nc) @cached_method diff --git a/src/sage/algebras/hecke_algebras/cubic_hecke_matrix_rep.py b/src/sage/algebras/hecke_algebras/cubic_hecke_matrix_rep.py index ef8ba7316c9..1e8cd3ae0c4 100644 --- a/src/sage/algebras/hecke_algebras/cubic_hecke_matrix_rep.py +++ b/src/sage/algebras/hecke_algebras/cubic_hecke_matrix_rep.py @@ -890,7 +890,7 @@ def invert_gen(matr): """ cfs = ch_algebra.cubic_equation(as_coefficients=True, generic=True) fac = - 1 / cfs[0] - cf0, cf1, cf2, cf3 = [original_base_ring(cf * fac) for cf in cfs] + cf0, cf1, cf2, cf3 = (original_base_ring(cf * fac) for cf in cfs) matri = cf1 * matr.parent().one() matri += cf2 * matr diff --git a/src/sage/calculus/calculus.py b/src/sage/calculus/calculus.py index 37807450ac0..dfaafb4353f 100644 --- a/src/sage/calculus/calculus.py +++ b/src/sage/calculus/calculus.py @@ -663,7 +663,7 @@ def symbolic_sum(expression, v, a, b, algorithm='maxima', hold=False): return result.sage() elif algorithm == 'sympy': - expression,v,a,b = [expr._sympy_() for expr in (expression, v, a, b)] + expression,v,a,b = (expr._sympy_() for expr in (expression, v, a, b)) from sympy import summation from sage.interfaces.sympy import sympy_init sympy_init() @@ -920,7 +920,7 @@ def symbolic_product(expression, v, a, b, algorithm='maxima', hold=False): return result.sage() elif algorithm == 'sympy': - expression,v,a,b = [expr._sympy_() for expr in (expression, v, a, b)] + expression,v,a,b = (expr._sympy_() for expr in (expression, v, a, b)) from sympy import product as sproduct from sage.interfaces.sympy import sympy_init sympy_init() @@ -1744,7 +1744,7 @@ def laplace(ex, t, s, algorithm='maxima'): return ex.parent()(ex._maxima_().laplace(var(t), var(s))) elif algorithm == 'sympy': - ex_sy, t, s = [expr._sympy_() for expr in (ex, t, s)] + ex_sy, t, s = (expr._sympy_() for expr in (ex, t, s)) from sympy import laplace_transform from sage.interfaces.sympy import sympy_init sympy_init() @@ -1923,7 +1923,7 @@ def inverse_laplace(ex, s, t, algorithm='maxima'): return ex.parent()(ex._maxima_().ilt(var(s), var(t))) elif algorithm == 'sympy': - ex_sy, s, t = [expr._sympy_() for expr in (ex, s, t)] + ex_sy, s, t = (expr._sympy_() for expr in (ex, s, t)) from sympy import inverse_laplace_transform from sage.interfaces.sympy import sympy_init sympy_init() diff --git a/src/sage/categories/affine_weyl_groups.py b/src/sage/categories/affine_weyl_groups.py index 4eeea88b6c3..7ae931201a9 100644 --- a/src/sage/categories/affine_weyl_groups.py +++ b/src/sage/categories/affine_weyl_groups.py @@ -28,16 +28,16 @@ class AffineWeylGroups(Category_singleton): EXAMPLES:: sage: C = AffineWeylGroups(); C - Category of affine weyl groups + Category of affine Weyl groups sage: C.super_categories() - [Category of infinite weyl groups] + [Category of infinite Weyl groups] sage: C.example() NotImplemented sage: W = WeylGroup(["A", 4, 1]); W # needs sage.combinat sage.groups Weyl Group of type ['A', 4, 1] (as a matrix group acting on the root space) sage: W.category() # needs sage.combinat sage.groups - Category of irreducible affine weyl groups + Category of irreducible affine Weyl groups TESTS:: @@ -49,7 +49,7 @@ def super_categories(self): EXAMPLES:: sage: AffineWeylGroups().super_categories() - [Category of infinite weyl groups] + [Category of infinite Weyl groups] """ return [WeylGroups().Infinite()] @@ -71,6 +71,17 @@ def additional_structure(self): """ return None + def _repr_object_names(self): + """ + Return the name of the objects of this category. + + EXAMPLES:: + + sage: AffineWeylGroups() + Category of affine Weyl groups + """ + return "affine Weyl groups" + class ParentMethods: @cached_method diff --git a/src/sage/categories/category.py b/src/sage/categories/category.py index fcf25b75fd4..b200f1a7283 100644 --- a/src/sage/categories/category.py +++ b/src/sage/categories/category.py @@ -42,7 +42,7 @@ sage: G.category() # needs sage.groups Join of Category of finite enumerated permutation groups and - Category of finite weyl groups and + Category of finite Weyl groups and Category of well generated finite irreducible complex reflection groups sage: P = PerfectMatchings(3) # needs sage.combinat @@ -2596,13 +2596,13 @@ def category_sample(): Category of G-sets for Symmetric group of order 8! as a permutation group, Category of Hecke modules over Rational Field, Category of Lie algebras over Rational Field, + Category of Weyl groups, Category of additive magmas, ..., Category of fields, ..., Category of graded hopf algebras with basis over Rational Field, ..., Category of modular abelian varieties over Rational Field, ..., Category of simplicial complexes, ..., - Category of vector spaces over Rational Field, ..., - Category of weyl groups, ... + Category of vector spaces over Rational Field, ... """ import sage.categories.all abstract_classes_for_categories = [Category] diff --git a/src/sage/categories/examples/finite_weyl_groups.py b/src/sage/categories/examples/finite_weyl_groups.py index a8b27cd7ffe..5c87f26c3e3 100644 --- a/src/sage/categories/examples/finite_weyl_groups.py +++ b/src/sage/categories/examples/finite_weyl_groups.py @@ -1,12 +1,12 @@ r""" Examples of finite Weyl groups """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2008-2009 Nicolas M. Thiery # # Distributed under the terms of the GNU General Public License (GPL) -# http://www.gnu.org/licenses/ -#****************************************************************************** +# https://www.gnu.org/licenses/ +# ***************************************************************************** from sage.misc.cachefunc import cached_method from sage.structure.parent import Parent @@ -14,6 +14,7 @@ from sage.categories.finite_weyl_groups import FiniteWeylGroups from sage.structure.unique_representation import UniqueRepresentation + class SymmetricGroup(UniqueRepresentation, Parent): r""" An example of finite Weyl group: the symmetric group, with @@ -30,7 +31,7 @@ class SymmetricGroup(UniqueRepresentation, Parent): sage: S The symmetric group on {0, ..., 3} sage: S.category() - Category of finite irreducible weyl groups + Category of finite irreducible Weyl groups The elements of this group are permutations of the set `\{0,\ldots,3\}`:: diff --git a/src/sage/categories/finite_weyl_groups.py b/src/sage/categories/finite_weyl_groups.py index 4210e2f9feb..8e0346eb5ab 100644 --- a/src/sage/categories/finite_weyl_groups.py +++ b/src/sage/categories/finite_weyl_groups.py @@ -1,15 +1,16 @@ r""" Finite Weyl Groups """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2009 Nicolas M. Thiery # # Distributed under the terms of the GNU General Public License (GPL) -# http://www.gnu.org/licenses/ -#****************************************************************************** +# https://www.gnu.org/licenses/ +# ***************************************************************************** from sage.categories.category_with_axiom import CategoryWithAxiom + class FiniteWeylGroups(CategoryWithAxiom): """ The category of finite Weyl groups. @@ -18,9 +19,9 @@ class FiniteWeylGroups(CategoryWithAxiom): sage: C = FiniteWeylGroups() sage: C - Category of finite weyl groups + Category of finite Weyl groups sage: C.super_categories() - [Category of finite Coxeter groups, Category of weyl groups] + [Category of finite Coxeter groups, Category of Weyl groups] sage: C.example() The symmetric group on {0, ..., 3} diff --git a/src/sage/categories/weyl_groups.py b/src/sage/categories/weyl_groups.py index 88879d2b478..79db1d40001 100644 --- a/src/sage/categories/weyl_groups.py +++ b/src/sage/categories/weyl_groups.py @@ -24,7 +24,7 @@ class WeylGroups(Category_singleton): EXAMPLES:: sage: WeylGroups() - Category of weyl groups + Category of Weyl groups sage: WeylGroups().super_categories() [Category of Coxeter groups] @@ -74,6 +74,17 @@ def additional_structure(self): """ return None + def _repr_object_names(self): + """ + Return the name of the objects of this category. + + EXAMPLES:: + + sage: WeylGroups().Finite() + Category of finite Weyl groups + """ + return "Weyl groups" + Finite = LazyImport('sage.categories.finite_weyl_groups', 'FiniteWeylGroups') class ParentMethods: @@ -276,13 +287,13 @@ def quantum_bruhat_graph(self, index_set=()): NPR = lattice.nonparabolic_positive_roots(index_set) NPR_sum = sum(NPR) NPR_data = {} - double_rho = lattice.sum(lattice.positive_roots()) # = 2 * \rho + double_rho = lattice.sum(lattice.positive_roots()) # = 2 * \rho for alpha in NPR: ref = alpha.associated_reflection() alphacheck = alpha.associated_coroot() - NPR_data[alpha] = [self.from_reduced_word(ref), # the element - len(ref) == double_rho.scalar(alphacheck) - 1, # is_quantum - NPR_sum.scalar(alphacheck)] # the scalar + NPR_data[alpha] = [self.from_reduced_word(ref), # the element + len(ref) == double_rho.scalar(alphacheck) - 1, # is_quantum + NPR_sum.scalar(alphacheck)] # the scalar # We also create a temporary cache of lengths as they are # relatively expensive to compute and needed frequently visited = {} @@ -493,14 +504,14 @@ def stanley_symmetric_function_as_polynomial(self, max_length=None): W = self.parent() pieri_factors = W.pieri_factors() from sage.rings.rational_field import QQ - R = QQ[','.join('x%s' % l for l in range(1, pieri_factors.max_length()+1))] + R = QQ[','.join('x%s' % l for l in range(1, pieri_factors.max_length() + 1))] x = R.gens() if self.is_one(): return R.one() - return R(sum(2**(pieri_factors.stanley_symm_poly_weight(u))*x[u.length()-1] * v.stanley_symmetric_function_as_polynomial(max_length=u.length()) - for (u, v) in self.left_pieri_factorizations(max_length) - if u != W.one())) + return R(sum(2**(pieri_factors.stanley_symm_poly_weight(u)) * x[u.length() - 1] * v.stanley_symmetric_function_as_polynomial(max_length=u.length()) + for (u, v) in self.left_pieri_factorizations(max_length) + if u != W.one())) def stanley_symmetric_function(self): r""" diff --git a/src/sage/coding/ag_code_decoders.pyx b/src/sage/coding/ag_code_decoders.pyx index 162c7210fc5..15231e6aa87 100644 --- a/src/sage/coding/ag_code_decoders.pyx +++ b/src/sage/coding/ag_code_decoders.pyx @@ -66,8 +66,8 @@ from sage.rings.function_field.constructor import FunctionField from sage.modules.free_module_element import vector from sage.matrix.constructor import matrix -from .encoder import Encoder -from .decoder import Decoder, DecodingError +from sage.coding.encoder import Encoder +from sage.coding.decoder import Decoder, DecodingError from sage.modules.free_module_element cimport FreeModuleElement from sage.matrix.matrix cimport Matrix diff --git a/src/sage/combinat/backtrack.py b/src/sage/combinat/backtrack.py index 777e511531f..d0669580484 100644 --- a/src/sage/combinat/backtrack.py +++ b/src/sage/combinat/backtrack.py @@ -63,7 +63,7 @@ def __iter__(self): sage: from sage.combinat.permutation import PatternAvoider sage: p = PatternAvoider(Permutations(4), [[1,3,2]]) - sage: len(list(p)) # optional - sage.combinat + sage: len(list(p)) # needs sage.combinat 14 """ # Initialize the stack of generators with the initial data. diff --git a/src/sage/combinat/baxter_permutations.py b/src/sage/combinat/baxter_permutations.py index c4f34c073f5..460969c062c 100644 --- a/src/sage/combinat/baxter_permutations.py +++ b/src/sage/combinat/baxter_permutations.py @@ -332,11 +332,12 @@ def to_pair_of_twin_binary_trees(self, p): EXAMPLES:: - sage: BaxterPermutations().to_pair_of_twin_binary_trees(Permutation([])) + sage: BP = BaxterPermutations() + sage: BP.to_pair_of_twin_binary_trees(Permutation([])) # needs sage.graphs (., .) - sage: BaxterPermutations().to_pair_of_twin_binary_trees(Permutation([1, 2, 3])) + sage: BP.to_pair_of_twin_binary_trees(Permutation([1, 2, 3])) # needs sage.graphs (1[., 2[., 3[., .]]], 3[2[1[., .], .], .]) - sage: BaxterPermutations().to_pair_of_twin_binary_trees(Permutation([3, 4, 1, 2])) + sage: BP.to_pair_of_twin_binary_trees(Permutation([3, 4, 1, 2])) # needs sage.graphs (3[1[., 2[., .]], 4[., .]], 2[1[., .], 4[3[., .], .]]) """ from sage.combinat.binary_tree import LabelledBinaryTree diff --git a/src/sage/combinat/binary_recurrence_sequences.py b/src/sage/combinat/binary_recurrence_sequences.py index b0e1309e189..9c1b9bdf931 100644 --- a/src/sage/combinat/binary_recurrence_sequences.py +++ b/src/sage/combinat/binary_recurrence_sequences.py @@ -35,7 +35,7 @@ True sage: T.is_geometric() True - sage: T.pthpowers(7, 10**30) # optional - sage.symbolic + sage: T.pthpowers(7, 10**30) # needs sage.symbolic Traceback (most recent call last): ... ValueError: the degenerate binary recurrence sequence is geometric or quasigeometric @@ -548,7 +548,7 @@ def pthpowers(self, p, Bound): True sage: T.is_geometric() True - sage: T.pthpowers(7, 10**30) # optional - sage.symbolic + sage: T.pthpowers(7, 10**30) # needs sage.symbolic Traceback (most recent call last): ... ValueError: the degenerate binary recurrence sequence is geometric or @@ -559,7 +559,7 @@ def pthpowers(self, p, Bound): [2, 2, 2^3, 2^5, 2^7, 2^9, 2^11, 2^13, 2^15, 2^17] sage: L.is_quasigeometric() True - sage: L.pthpowers(2, 10**30) # optional - sage.symbolic + sage: L.pthpowers(2, 10**30) # needs sage.symbolic [] .. NOTE:: @@ -1057,7 +1057,7 @@ def _estimated_time(M2, M1, length, p): EXAMPLES:: sage: from sage.combinat.binary_recurrence_sequences import _estimated_time - sage: _estimated_time(2**4*3**2*5*7*11*13*17, 2**4*3**2*5*7*11*13, 20, 7) # optional - sage.symbolic + sage: _estimated_time(2**4*3**2*5*7*11*13*17, 2**4*3**2*5*7*11*13, 20, 7) # needs sage.symbolic 106.211159309421 """ @@ -1093,7 +1093,7 @@ def _find_cong1(p, R, ell): EXAMPLES:: sage: R = BinaryRecurrenceSequence(1,1) - sage: sage.combinat.binary_recurrence_sequences._find_cong1(7, R, 29) # optional - sage.rings.finite_rings + sage: sage.combinat.binary_recurrence_sequences._find_cong1(7, R, 29) # needs sage.rings.finite_rings ([0, 1, 2, 12, 13], 14) """ F = GF(ell) @@ -1143,9 +1143,9 @@ def _is_p_power(a, p): EXAMPLES:: - sage: sage.combinat.binary_recurrence_sequences._is_p_power(2**7, 7) # optional - sage.symbolic + sage: sage.combinat.binary_recurrence_sequences._is_p_power(2**7, 7) # needs sage.symbolic True - sage: sage.combinat.binary_recurrence_sequences._is_p_power(2**7*3**2, 7) # optional - sage.symbolic + sage: sage.combinat.binary_recurrence_sequences._is_p_power(2**7*3**2, 7) # needs sage.symbolic False """ return int(a**(1/p))**p == a diff --git a/src/sage/combinat/binary_tree.py b/src/sage/combinat/binary_tree.py index ce60b4f8c9e..3f7b8ae2fc5 100644 --- a/src/sage/combinat/binary_tree.py +++ b/src/sage/combinat/binary_tree.py @@ -868,7 +868,7 @@ def show(self, with_leaves=False): TESTS:: sage: t1 = BinaryTree([[], [[], None]]) - sage: t1.show() # optional - sage.plot + sage: t1.show() # needs sage.plot """ try: self.graph(with_leaves=with_leaves).show(layout='tree', tree_root=0, tree_orientation="down") @@ -989,13 +989,14 @@ def to_dyck_word_tamari(self): EXAMPLES:: - sage: BinaryTree().to_dyck_word_tamari() # optional - sage.combinat + sage: # needs sage.combinat + sage: BinaryTree().to_dyck_word_tamari() [] - sage: BinaryTree([]).to_dyck_word_tamari() # optional - sage.combinat + sage: BinaryTree([]).to_dyck_word_tamari() [1, 0] - sage: BinaryTree([[None,[]],None]).to_dyck_word_tamari() # optional - sage.combinat + sage: BinaryTree([[None,[]],None]).to_dyck_word_tamari() [1, 1, 0, 0, 1, 0] - sage: BinaryTree([[[], [[], None]], [[], []]]).to_dyck_word_tamari() # optional - sage.combinat + sage: BinaryTree([[[], [[], None]], [[], []]]).to_dyck_word_tamari() [1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0] """ return self.to_dyck_word("L1R0") @@ -1129,9 +1130,9 @@ def tamari_join(self, other): ....: return True sage: all( test_uni_join(p, q) for p in BinaryTrees(3) for q in BinaryTrees(3) ) True - sage: p = BinaryTrees(6).random_element() # optional - sage.combinat - sage: q = BinaryTrees(6).random_element() # optional - sage.combinat - sage: test_uni_join(p, q) # optional - sage.combinat + sage: p = BinaryTrees(6).random_element() # needs sage.combinat + sage: q = BinaryTrees(6).random_element() # needs sage.combinat + sage: test_uni_join(p, q) # needs sage.combinat True Border cases:: @@ -1218,9 +1219,9 @@ def tamari_meet(self, other, side="right"): ....: return True sage: all( test_uni_meet(p, q) for p in BinaryTrees(3) for q in BinaryTrees(3) ) True - sage: p = BinaryTrees(6).random_element() # optional - sage.combinat - sage: q = BinaryTrees(6).random_element() # optional - sage.combinat - sage: test_uni_meet(p, q) # optional - sage.combinat + sage: p = BinaryTrees(6).random_element() # needs sage.combinat + sage: q = BinaryTrees(6).random_element() # needs sage.combinat + sage: test_uni_meet(p, q) # needs sage.combinat True Border cases:: @@ -1256,35 +1257,37 @@ def to_dyck_word(self, usemap="1L0R"): EXAMPLES:: - sage: BinaryTree().to_dyck_word() # optional - sage.combinat + sage: # needs sage.combinat + sage: BinaryTree().to_dyck_word() [] - sage: BinaryTree([]).to_dyck_word() # optional - sage.combinat + sage: BinaryTree([]).to_dyck_word() [1, 0] - sage: BinaryTree([[[], [[], None]], [[], []]]).to_dyck_word() # optional - sage.combinat + sage: BinaryTree([[[], [[], None]], [[], []]]).to_dyck_word() [1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0] - sage: BinaryTree([[None,[]],None]).to_dyck_word() # optional - sage.combinat + sage: BinaryTree([[None,[]],None]).to_dyck_word() [1, 1, 0, 1, 0, 0] - sage: BinaryTree([[None,[]],None]).to_dyck_word("1R0L") # optional - sage.combinat + sage: BinaryTree([[None,[]],None]).to_dyck_word("1R0L") [1, 0, 1, 1, 0, 0] - sage: BinaryTree([[None,[]],None]).to_dyck_word("L1R0") # optional - sage.combinat + sage: BinaryTree([[None,[]],None]).to_dyck_word("L1R0") [1, 1, 0, 0, 1, 0] - sage: BinaryTree([[None,[]],None]).to_dyck_word("R1L0") # optional - sage.combinat + sage: BinaryTree([[None,[]],None]).to_dyck_word("R1L0") [1, 1, 0, 1, 0, 0] - sage: BinaryTree([[None,[]],None]).to_dyck_word("R10L") # optional - sage.combinat + sage: BinaryTree([[None,[]],None]).to_dyck_word("R10L") Traceback (most recent call last): ... ValueError: R10L is not a correct map TESTS:: + sage: # needs sage.combinat sage: bt = BinaryTree([[[], [[], None]], [[], []]]) - sage: bt == bt.to_dyck_word().to_binary_tree() # optional - sage.combinat + sage: bt == bt.to_dyck_word().to_binary_tree() True - sage: bt == bt.to_dyck_word("1R0L").to_binary_tree("1R0L") # optional - sage.combinat + sage: bt == bt.to_dyck_word("1R0L").to_binary_tree("1R0L") True - sage: bt == bt.to_dyck_word("L1R0").to_binary_tree("L1R0") # optional - sage.combinat + sage: bt == bt.to_dyck_word("L1R0").to_binary_tree("L1R0") True - sage: bt == bt.to_dyck_word("R1L0").to_binary_tree("R1L0") # optional - sage.combinat + sage: bt == bt.to_dyck_word("R1L0").to_binary_tree("R1L0") True """ from sage.combinat.dyck_word import DyckWord @@ -1448,9 +1451,9 @@ def tamari_sorting_tuple(self, reverse=False): ((1, 0, 0), 3), ((0, 0, 0), 3)] - sage: t = BinaryTrees(10).random_element() # optional - sage.combinat - sage: u = t.left_right_symmetry() # optional - sage.combinat - sage: t.tamari_sorting_tuple(True) == u.tamari_sorting_tuple() # optional - sage.combinat + sage: t = BinaryTrees(10).random_element() # needs sage.combinat + sage: u = t.left_right_symmetry() # needs sage.combinat + sage: t.tamari_sorting_tuple(True) == u.tamari_sorting_tuple() # needs sage.combinat True REFERENCES: @@ -1617,9 +1620,9 @@ def to_tilting(self): [(0, 1), (2, 3), (4, 5), (6, 7), (4, 7), (8, 9), (10, 11), (8, 11), (4, 11), (12, 13), (4, 13), (2, 13), (0, 13)] - sage: w = DyckWord([1,1,1,1,0,1,1,0,0,0,1,1,0,1,0,1,1,0,1,1,0,0,0,0,0,0]) # optional - sage.combinat - sage: t2 = w.to_binary_tree() # optional - sage.combinat - sage: len(t2.to_tilting()) == t2.node_number() # optional - sage.combinat + sage: w = DyckWord([1,1,1,1,0,1,1,0,0,0,1,1,0,1,0,1,1,0,1,1,0,0,0,0,0,0]) # needs sage.combinat + sage: t2 = w.to_binary_tree() # needs sage.combinat + sage: len(t2.to_tilting()) == t2.node_number() # needs sage.combinat True """ if not self: @@ -2833,36 +2836,37 @@ def q_hook_length_fraction(self, q=None, q_factor=False): only one vertex (which is a leaf):: sage: b = BinaryTree() - sage: b.q_hook_length_fraction() # optional - sage.combinat + sage: b.q_hook_length_fraction() # needs sage.combinat 1 - sage: b.q_hook_length_fraction(q_factor=True) # optional - sage.combinat + sage: b.q_hook_length_fraction(q_factor=True) # needs sage.combinat 1 Nothing different for a tree with one node and two leaves:: sage: b = BinaryTree([]); b [., .] - sage: b.q_hook_length_fraction() # optional - sage.combinat + sage: b.q_hook_length_fraction() # needs sage.combinat 1 - sage: b.q_hook_length_fraction(q_factor=True) # optional - sage.combinat + sage: b.q_hook_length_fraction(q_factor=True) # needs sage.combinat 1 Let us get to a more interesting tree:: + sage: # needs sage.combinat sage: b = BinaryTree([[[],[]],[[],None]]); b [[[., .], [., .]], [[., .], .]] - sage: b.q_hook_length_fraction()(q=1) # optional - sage.combinat + sage: b.q_hook_length_fraction()(q=1) 20 - sage: b.q_hook_length_fraction() # optional - sage.combinat + sage: b.q_hook_length_fraction() q^7 + 2*q^6 + 3*q^5 + 4*q^4 + 4*q^3 + 3*q^2 + 2*q + 1 - sage: b.q_hook_length_fraction(q_factor=True) # optional - sage.combinat + sage: b.q_hook_length_fraction(q_factor=True) q^10 + 2*q^9 + 3*q^8 + 4*q^7 + 4*q^6 + 3*q^5 + 2*q^4 + q^3 - sage: b.q_hook_length_fraction(q=2) # optional - sage.combinat + sage: b.q_hook_length_fraction(q=2) 465 - sage: b.q_hook_length_fraction(q=2, q_factor=True) # optional - sage.combinat + sage: b.q_hook_length_fraction(q=2, q_factor=True) 3720 sage: q = PolynomialRing(ZZ, 'q').gen() - sage: b.q_hook_length_fraction(q=q**2) # optional - sage.combinat + sage: b.q_hook_length_fraction(q=q**2) q^14 + 2*q^12 + 3*q^10 + 4*q^8 + 4*q^6 + 3*q^4 + 2*q^2 + 1 Let us check the fact that `f_{q} (T)` is the generating function @@ -2881,7 +2885,7 @@ def q_hook_length_fraction(self, q=None, q_factor=False): ....: return all( q_hook_length_fraction_2(T) ....: == T.q_hook_length_fraction(q_factor=True) ....: for T in BinaryTrees(i) ) - sage: test_genfun(4) # optional - sage.combinat + sage: test_genfun(4) # needs sage.combinat True """ from sage.combinat.q_analogues import q_binomial @@ -3400,29 +3404,30 @@ def dendriform_shuffle(self, other): sage: l = BinaryTree([g, u]) sage: r = BinaryTree([u, g]) - sage: list(g.dendriform_shuffle(g)) # optional - sage.combinat + sage: list(g.dendriform_shuffle(g)) # needs sage.combinat [[[., .], .], [., [., .]]] - sage: list(l.dendriform_shuffle(l)) # optional - sage.combinat + sage: list(l.dendriform_shuffle(l)) # needs sage.combinat [[[[[., .], .], .], .], [[[., .], [., .]], .], [[., .], [[., .], .]]] - sage: list(l.dendriform_shuffle(r)) # optional - sage.combinat + sage: list(l.dendriform_shuffle(r)) # needs sage.combinat [[[[., .], .], [., .]], [[., .], [., [., .]]]] TESTS:: - sage: list(u.dendriform_shuffle(u)) # optional - sage.combinat + sage: # needs sage.combinat + sage: list(u.dendriform_shuffle(u)) [.] - sage: list(u.dendriform_shuffle(g)) # optional - sage.combinat + sage: list(u.dendriform_shuffle(g)) [[., .]] - sage: list(u.dendriform_shuffle(l)) # optional - sage.combinat + sage: list(u.dendriform_shuffle(l)) [[[., .], .]] - sage: list(u.dendriform_shuffle(r)) # optional - sage.combinat + sage: list(u.dendriform_shuffle(r)) [[., [., .]]] - sage: list(r.dendriform_shuffle(u)) # optional - sage.combinat + sage: list(r.dendriform_shuffle(u)) [[., [., .]]] - sage: list(l.dendriform_shuffle(u)) # optional - sage.combinat + sage: list(l.dendriform_shuffle(u)) [[[., .], .]] """ from sage.combinat.words.shuffle_product import ShuffleProduct_w1w2 @@ -3532,32 +3537,33 @@ def sylvester_class(self, left_to_right=False): ....: if not BinaryTree(tree) == t: ....: return False ....: return True - sage: test_bst_of_sc(4, False) # optional - sage.combinat + sage: test_bst_of_sc(4, False) # needs sage.combinat True - sage: test_bst_of_sc(5, False) # long time # optional - sage.combinat + sage: test_bst_of_sc(5, False) # long time # needs sage.combinat True The same with the left-to-right version of binary search:: - sage: test_bst_of_sc(4, True) # optional - sage.combinat + sage: test_bst_of_sc(4, True) # needs sage.combinat True - sage: test_bst_of_sc(5, True) # long time # optional - sage.combinat + sage: test_bst_of_sc(5, True) # long time # needs sage.combinat True Checking that the sylvester class is the set of linear extensions of the poset of the tree:: - sage: all( sorted(t.canonical_labelling().sylvester_class()) # optional - sage.combinat - ....: == sorted(list(v) for v in t.canonical_labelling().to_poset().linear_extensions()) - ....: for t in BinaryTrees(4) ) + sage: all(sorted(t.canonical_labelling().sylvester_class()) # needs sage.combinat sage.modules + ....: == sorted(list(v) + ....: for v in t.canonical_labelling().to_poset().linear_extensions()) + ....: for t in BinaryTrees(4)) True TESTS:: - sage: list(BinaryTree([[],[]]).sylvester_class()) # optional - sage.combinat + sage: list(BinaryTree([[],[]]).sylvester_class()) # needs sage.combinat [[1, 3, 2], [3, 1, 2]] sage: bt = BinaryTree([[[],None],[[],[]]]) - sage: l = list(bt.sylvester_class()); l # optional - sage.combinat + sage: l = list(bt.sylvester_class()); l # needs sage.combinat [[1, 2, 4, 6, 5, 3], [1, 4, 2, 6, 5, 3], [1, 4, 6, 2, 5, 3], @@ -3578,14 +3584,14 @@ def sylvester_class(self, left_to_right=False): [6, 4, 1, 2, 5, 3], [6, 4, 1, 5, 2, 3], [6, 4, 5, 1, 2, 3]] - sage: len(l) == Integer(bt.q_hook_length_fraction()(q=1)) # optional - sage.combinat + sage: len(l) == Integer(bt.q_hook_length_fraction()(q=1)) # needs sage.combinat True Border cases:: - sage: list(BinaryTree().sylvester_class()) # optional - sage.combinat + sage: list(BinaryTree().sylvester_class()) # needs sage.combinat [[]] - sage: list(BinaryTree([]).sylvester_class()) # optional - sage.combinat + sage: list(BinaryTree([]).sylvester_class()) # needs sage.combinat [[1]] """ if self.is_empty(): @@ -4051,8 +4057,8 @@ def from_tamari_sorting_tuple(key): EXAMPLES:: sage: from sage.combinat.binary_tree import from_tamari_sorting_tuple - sage: t = BinaryTrees(60).random_element() # optional - sage.combinat - sage: from_tamari_sorting_tuple(t.tamari_sorting_tuple()[0]) == t # optional - sage.combinat + sage: t = BinaryTrees(60).random_element() # needs sage.combinat + sage: from_tamari_sorting_tuple(t.tamari_sorting_tuple()[0]) == t # needs sage.combinat True """ if not key: @@ -4256,16 +4262,16 @@ def random_element(self): EXAMPLES:: - sage: BinaryTrees(5).random_element() # random # optional - sage.combinat + sage: BinaryTrees(5).random_element() # random # needs sage.combinat [., [., [., [., [., .]]]]] - sage: BinaryTrees(0).random_element() # optional - sage.combinat + sage: BinaryTrees(0).random_element() # needs sage.combinat . - sage: BinaryTrees(1).random_element() # optional - sage.combinat + sage: BinaryTrees(1).random_element() # needs sage.combinat [., .] TESTS:: - sage: all(BinaryTrees(10).random_element() in BinaryTrees(10) # optional - sage.combinat + sage: all(BinaryTrees(10).random_element() in BinaryTrees(10) # needs sage.combinat ....: for i in range(20)) True """ @@ -4511,17 +4517,17 @@ def random_element(self): EXAMPLES:: - sage: BinaryTrees(5, full=True).random_element() # random # optional - sage.combinat + sage: BinaryTrees(5, full=True).random_element() # random # needs sage.combinat [[], [[], []]] - sage: BinaryTrees(0, full=True).random_element() # optional - sage.combinat + sage: BinaryTrees(0, full=True).random_element() # needs sage.combinat . - sage: BinaryTrees(1, full=True).random_element() # optional - sage.combinat + sage: BinaryTrees(1, full=True).random_element() # needs sage.combinat [., .] TESTS:: sage: B = BinaryTrees(19, full=True) - sage: all(B.random_element() in B for i in range(20)) # optional - sage.combinat + sage: all(B.random_element() in B for i in range(20)) # needs sage.combinat True """ from sage.combinat.dyck_word import CompleteDyckWords_size diff --git a/src/sage/combinat/cartesian_product.py b/src/sage/combinat/cartesian_product.py index cbe219ef169..832c5f1075d 100644 --- a/src/sage/combinat/cartesian_product.py +++ b/src/sage/combinat/cartesian_product.py @@ -51,27 +51,27 @@ class for ``cartesian_product``; sage: F1 = ['a', 'b'] sage: F2 = [1, 2, 3, 4] - sage: F3 = Permutations(3) # optional - sage.combinat + sage: F3 = Permutations(3) sage: from sage.combinat.cartesian_product import CartesianProduct_iters - sage: C = CartesianProduct_iters(F1, F2, F3) # optional - sage.combinat - sage: c = cartesian_product([F1, F2, F3]) # optional - sage.combinat + sage: C = CartesianProduct_iters(F1, F2, F3) + sage: c = cartesian_product([F1, F2, F3]) - sage: type(C.an_element()) # optional - sage.combinat + sage: type(C.an_element()) - sage: type(c.an_element()) # optional - sage.combinat + sage: type(c.an_element()) - sage: l = ['a', 1, Permutation([3,2,1])] # optional - sage.combinat - sage: l in C # optional - sage.combinat + sage: l = ['a', 1, Permutation([3,2,1])] + sage: l in C True - sage: l in c # optional - sage.combinat + sage: l in c False - sage: elt = c(l) # optional - sage.combinat - sage: elt # optional - sage.combinat + sage: elt = c(l) + sage: elt ('a', 1, [3, 2, 1]) - sage: elt in c # optional - sage.combinat + sage: elt in c True - sage: elt.parent() is c # optional - sage.combinat + sage: elt.parent() is c True """ diff --git a/src/sage/combinat/cluster_algebra_quiver/mutation_class.py b/src/sage/combinat/cluster_algebra_quiver/mutation_class.py index 33b33087899..fc6ec540395 100644 --- a/src/sage/combinat/cluster_algebra_quiver/mutation_class.py +++ b/src/sage/combinat/cluster_algebra_quiver/mutation_class.py @@ -76,10 +76,10 @@ def _digraph_mutate(dg, k, frozen=None): sage: from sage.combinat.cluster_algebra_quiver.mutation_class import _digraph_mutate sage: from sage.combinat.cluster_algebra_quiver.quiver import ClusterQuiver - sage: dg = ClusterQuiver(['A',4]).digraph() - sage: dg.edges(sort=True) + sage: dg = ClusterQuiver(['A',4]).digraph() # needs sage.modules + sage: dg.edges(sort=True) # needs sage.modules [(0, 1, (1, -1)), (2, 1, (1, -1)), (2, 3, (1, -1))] - sage: _digraph_mutate(dg,2).edges(sort=True) + sage: _digraph_mutate(dg,2).edges(sort=True) # needs sage.modules [(0, 1, (1, -1)), (1, 2, (1, -1)), (3, 2, (1, -1))] TESTS:: @@ -208,31 +208,31 @@ def _dg_canonical_form(dg, frozen=None): EXAMPLES:: sage: from sage.combinat.cluster_algebra_quiver.mutation_class import _dg_canonical_form - sage: dg = ClusterQuiver(['B',4]).digraph(); dg.edges(sort=True) + sage: dg = ClusterQuiver(['B',4]).digraph(); dg.edges(sort=True) # needs sage.modules [(0, 1, (1, -1)), (2, 1, (1, -1)), (2, 3, (1, -2))] - sage: _dg_canonical_form(dg); dg.edges(sort=True) + sage: _dg_canonical_form(dg); dg.edges(sort=True) # needs sage.modules ({0: 0, 1: 3, 2: 1, 3: 2}, [[0], [3], [1], [2]]) [(0, 3, (1, -1)), (1, 2, (1, -2)), (1, 3, (1, -1))] TESTS:: - sage: dg2 = ClusterQuiver(DiGraph({0:[1,2]})).digraph() - sage: _dg_canonical_form(dg2); dg2.edges(sort=True) + sage: dg2 = ClusterQuiver(DiGraph({0:[1,2]})).digraph() # needs sage.modules + sage: _dg_canonical_form(dg2); dg2.edges(sort=True) # needs sage.modules ({0: 0, 1: 1, 2: 2}, [[0], [1, 2]]) [(0, 1, (1, -1)), (0, 2, (1, -1))] - sage: dg2 = ClusterQuiver(DiGraph({0:[1,2]})).digraph() - sage: _dg_canonical_form(dg2, frozen=[0]); dg2.edges(sort=True) + sage: dg2 = ClusterQuiver(DiGraph({0:[1,2]})).digraph() # needs sage.modules + sage: _dg_canonical_form(dg2, frozen=[0]); dg2.edges(sort=True) # needs sage.modules ({0: 2, 1: 0, 2: 1}, [[2], [0, 1]]) [(2, 0, (1, -1)), (2, 1, (1, -1))] - sage: dg3 = ClusterQuiver(DiGraph({0:[1,2],1:[3]})).digraph() - sage: _dg_canonical_form(dg3, frozen=[0,3]); dg3.edges(sort=True) + sage: dg3 = ClusterQuiver(DiGraph({0:[1,2],1:[3]})).digraph() # needs sage.modules + sage: _dg_canonical_form(dg3, frozen=[0,3]); dg3.edges(sort=True) # needs sage.modules ({0: 2, 1: 1, 2: 0, 3: 3}, [[2], [1], [0], [3]]) [(1, 3, (1, -1)), (2, 0, (1, -1)), (2, 1, (1, -1))] - sage: dg3 = ClusterQuiver(DiGraph({2:[1,3],1:[0],3:[4]})).digraph() - sage: _dg_canonical_form(dg3, frozen=[4,0]); dg3.edges(sort=True) + sage: dg3 = ClusterQuiver(DiGraph({2:[1,3],1:[0],3:[4]})).digraph() # needs sage.modules + sage: _dg_canonical_form(dg3, frozen=[4,0]); dg3.edges(sort=True) # needs sage.modules ({0: 4, 1: 1, 2: 0, 3: 2, 4: 3}, [[4, 3], [1, 2], [0]]) [(0, 1, (1, -1)), (0, 2, (1, -1)), (1, 4, (1, -1)), (2, 3, (1, -1))] """ @@ -292,6 +292,7 @@ def _mutation_class_iter( dg, n, m, depth=infinity, return_dig6=False, show_dept EXAMPLES:: + sage: # needs sage.modules sage: from sage.combinat.cluster_algebra_quiver.mutation_class import _mutation_class_iter sage: from sage.combinat.cluster_algebra_quiver.quiver import ClusterQuiver sage: dg = ClusterQuiver(['A',[1,2],1]).digraph() @@ -392,8 +393,8 @@ def _digraph_to_dig6( dg, hashable=False ): sage: from sage.combinat.cluster_algebra_quiver.mutation_class import _digraph_to_dig6 sage: from sage.combinat.cluster_algebra_quiver.quiver import ClusterQuiver - sage: dg = ClusterQuiver(['A',4]).digraph() - sage: _digraph_to_dig6(dg) + sage: dg = ClusterQuiver(['A',4]).digraph() # needs sage.modules + sage: _digraph_to_dig6(dg) # needs sage.modules ('COD?', {}) """ dig6 = dg.dig6_string() @@ -416,6 +417,7 @@ def _dig6_to_digraph( dig6 ): EXAMPLES:: + sage: # needs sage.modules sage: from sage.combinat.cluster_algebra_quiver.mutation_class import _digraph_to_dig6 sage: from sage.combinat.cluster_algebra_quiver.mutation_class import _dig6_to_digraph sage: from sage.combinat.cluster_algebra_quiver.quiver import ClusterQuiver @@ -451,8 +453,8 @@ def _dig6_to_matrix( dig6 ): sage: from sage.combinat.cluster_algebra_quiver.mutation_class import _digraph_to_dig6, _dig6_to_matrix sage: from sage.combinat.cluster_algebra_quiver.quiver import ClusterQuiver - sage: dg = ClusterQuiver(['A',4]).digraph() - sage: data = _digraph_to_dig6(dg) + sage: dg = ClusterQuiver(['A',4]).digraph() # needs sage.modules + sage: data = _digraph_to_dig6(dg) # needs sage.modules sage: _dig6_to_matrix(data) # needs sage.modules [ 0 1 0 0] [-1 0 -1 0] @@ -474,14 +476,15 @@ def _dg_is_sink_source( dg, v ): EXAMPLES:: + sage: # needs sage.modules sage: from sage.combinat.cluster_algebra_quiver.mutation_class import _dg_is_sink_source sage: from sage.combinat.cluster_algebra_quiver.quiver import ClusterQuiver sage: dg = ClusterQuiver(['A',[1,2],1]).digraph() - sage: _dg_is_sink_source(dg, 0 ) + sage: _dg_is_sink_source(dg, 0) True - sage: _dg_is_sink_source(dg, 1 ) + sage: _dg_is_sink_source(dg, 1) True - sage: _dg_is_sink_source(dg, 2 ) + sage: _dg_is_sink_source(dg, 2) False """ in_edges = [ edge for edge in dg._backend.iterator_in_edges([v],True) ] @@ -504,9 +507,9 @@ def _graph_without_edge_labels(dg, vertices): sage: from sage.combinat.cluster_algebra_quiver.mutation_class import _graph_without_edge_labels sage: from sage.combinat.cluster_algebra_quiver.quiver import ClusterQuiver - sage: dg = ClusterQuiver(['B',4]).digraph(); dg.edges(sort=True) + sage: dg = ClusterQuiver(['B',4]).digraph(); dg.edges(sort=True) # needs sage.modules [(0, 1, (1, -1)), (2, 1, (1, -1)), (2, 3, (1, -2))] - sage: _graph_without_edge_labels(dg, range(4)); dg.edges(sort=True) + sage: _graph_without_edge_labels(dg, range(4)); dg.edges(sort=True) # needs sage.modules ([[4]], ((1, -2),)) [(0, 1, (1, -1)), (2, 1, (1, -1)), (2, 4, (1, -1)), (4, 3, (1, -1))] """ @@ -542,10 +545,10 @@ def _has_two_cycles( dg ): EXAMPLES:: sage: from sage.combinat.cluster_algebra_quiver.mutation_class import _has_two_cycles - sage: _has_two_cycles( DiGraph([[0,1],[1,0]])) + sage: _has_two_cycles(DiGraph([[0,1],[1,0]])) True sage: from sage.combinat.cluster_algebra_quiver.quiver import ClusterQuiver - sage: _has_two_cycles( ClusterQuiver(['A',3]).digraph() ) + sage: _has_two_cycles(ClusterQuiver(['A',3]).digraph()) # needs sage.modules False """ edge_set = dg.edges(sort=True, labels=False) diff --git a/src/sage/combinat/cluster_algebra_quiver/mutation_type.py b/src/sage/combinat/cluster_algebra_quiver/mutation_type.py index 524c95a80df..32f9ccc52d7 100644 --- a/src/sage/combinat/cluster_algebra_quiver/mutation_type.py +++ b/src/sage/combinat/cluster_algebra_quiver/mutation_type.py @@ -55,14 +55,15 @@ def is_mutation_finite(M, nr_of_checks=None): sage: from sage.combinat.cluster_algebra_quiver.mutation_type import is_mutation_finite - sage: Q = ClusterQuiver(['A',10]) + sage: Q = ClusterQuiver(['A',10]) # needs sage.modules sage: M = Q.b_matrix() # needs sage.modules sage: is_mutation_finite(M) # needs sage.modules (True, None) + sage: # needs sage.modules sage: Q = ClusterQuiver([(0,1),(1,2),(2,3),(3,4),(4,5),(5,6),(6,7),(7,8),(2,9)]) - sage: M = Q.b_matrix() # needs sage.modules - sage: is_mutation_finite(M) # random # needs sage.modules + sage: M = Q.b_matrix() + sage: is_mutation_finite(M) # random (False, [9, 6, 9, 8, 9, 4, 0, 4, 5, 2, 1, 0, 1, 0, 7, 1, 9, 2, 5, 7, 8, 6, 3, 0, 2, 5, 4, 2, 6, 9, 2, 7, 3, 5, 3, 7, 9, 5, 9, 0, 2, 7, 9, 2, 4, 2, 1, 6, 9, 4, 3, 5, 0, 8, 2, 9, 5, 3, 7, 0, 1, 8, 3, 7, 2, 7, 3, 4, 8, 0, 4, 9, 5, 2, 8, 4, 8, 1, 7, 8, 9, 1, 5, 0, 8, 7, 4, 8, 9, 8, 0, 7, 4, 7, 1, 2, 8, 6, 1, 3, 9, 3, 9, 1, 3, 2, 4, 9, 5, 1, 2, 9, 4, 8, 5, 3, 4, 6, 8, 9, 2, 5, 9, 4, 6, 2, 1, 4, 9, 6, 0, 9, 8, 0, 4, 7, 9, 2, 1, 6]) Check that :trac:`19495` is fixed:: @@ -100,6 +101,7 @@ def _triangles(dg): EXAMPLES:: + sage: # needs sage.modules sage: from sage.combinat.cluster_algebra_quiver.mutation_type import _triangles sage: Q = ClusterQuiver(['A',3]) sage: _triangles(Q.digraph()) @@ -154,6 +156,7 @@ def _all_induced_cycles_iter( dg ): EXAMPLES:: + sage: # needs sage.modules sage: from sage.combinat.cluster_algebra_quiver.mutation_type import _all_induced_cycles_iter sage: Q = ClusterQuiver(['A',[6,0],1]); Q Quiver on 6 vertices of type ['D', 6] @@ -220,6 +223,7 @@ def _reset_dg(dg, vertices, dict_in_out, del_vertices): EXAMPLES:: + sage: # needs sage.modules sage: from sage.combinat.cluster_algebra_quiver.mutation_type import _reset_dg sage: dg = ClusterQuiver(['A',[2,2],1]).digraph(); dg Digraph on 4 vertices @@ -326,6 +330,7 @@ def _connected_mutation_type(dg): EXAMPLES:: + sage: # needs sage.modules sage: from sage.combinat.cluster_algebra_quiver.mutation_type import _connected_mutation_type sage: from sage.combinat.cluster_algebra_quiver.quiver import ClusterQuiver sage: dg = ClusterQuiver(['A',3]).digraph(); _connected_mutation_type( dg ) @@ -820,15 +825,14 @@ def _connected_mutation_type_AAtildeD(dg, ret_conn_vert=False): EXAMPLES:: + sage: # needs sage.modules sage: from sage.combinat.cluster_algebra_quiver.mutation_type import _connected_mutation_type_AAtildeD sage: Q = ClusterQuiver(['A',[7,0],1]); Q.mutate([0,1,4]) sage: _connected_mutation_type_AAtildeD(Q.digraph(),ret_conn_vert=True) [['D', 7], [0, 4]] - sage: Q2 = ClusterQuiver(['A',[5,2],1]); Q2.mutate([4,5]) sage: _connected_mutation_type_AAtildeD(Q2.digraph() ) ['A', [2, 5], 1] - sage: Q3 = ClusterQuiver(['E',6]); Q3.mutate([5,2,1]) sage: _connected_mutation_type_AAtildeD(Q3.digraph(),ret_conn_vert=True) 'unknown' @@ -1305,6 +1309,7 @@ def _mutation_type_from_data( n, dig6, compute_if_necessary=True ): EXAMPLES:: + sage: # needs sage.modules sage: from sage.combinat.cluster_algebra_quiver.mutation_class import _digraph_to_dig6 sage: from sage.combinat.cluster_algebra_quiver.mutation_type import _mutation_type_from_data sage: from sage.combinat.cluster_algebra_quiver.quiver import ClusterQuiver diff --git a/src/sage/combinat/cluster_algebra_quiver/quiver.py b/src/sage/combinat/cluster_algebra_quiver/quiver.py index 028f8abb797..3c4f1c65a87 100644 --- a/src/sage/combinat/cluster_algebra_quiver/quiver.py +++ b/src/sage/combinat/cluster_algebra_quiver/quiver.py @@ -2150,18 +2150,17 @@ def d_vector_fan(self): EXAMPLES:: + sage: # needs sage.geometry.polyhedron sage.libs.singular sage: Fd = ClusterQuiver([[1,2]]).d_vector_fan(); Fd Rational polyhedral fan in 2-d lattice N sage: Fd.ngenerating_cones() 5 - sage: Fd = ClusterQuiver([[1,2],[2,3]]).d_vector_fan(); Fd Rational polyhedral fan in 3-d lattice N sage: Fd.ngenerating_cones() 14 sage: Fd.is_smooth() True - sage: Fd = ClusterQuiver([[1,2],[2,3],[3,1]]).d_vector_fan(); Fd Rational polyhedral fan in 3-d lattice N sage: Fd.ngenerating_cones() @@ -2176,12 +2175,13 @@ def d_vector_fan(self): ... ValueError: only makes sense for quivers of finite type """ + if not(self.is_finite()): + raise ValueError('only makes sense for quivers of finite type') + from .cluster_seed import ClusterSeed from sage.geometry.fan import Fan from sage.geometry.cone import Cone - if not (self.is_finite()): - raise ValueError('only makes sense for quivers of finite type') seed = ClusterSeed(self) return Fan([Cone(s.d_matrix().columns()) for s in seed.mutation_class()]) diff --git a/src/sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py b/src/sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py index 60e9e78c3bf..2e36b619716 100644 --- a/src/sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py +++ b/src/sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py @@ -669,7 +669,7 @@ def _repr_(self): EXAMPLES:: - sage: QuiverMutationType(['A', 2]) # indirect doctest + sage: QuiverMutationType(['A', 2]) # indirect doctest ['A', 2] """ return self._description @@ -816,22 +816,22 @@ def standard_quiver(self): sage: mut_type = QuiverMutationType( ['A',5] ); mut_type ['A', 5] - sage: mut_type.standard_quiver() + sage: mut_type.standard_quiver() # needs sage.modules Quiver on 5 vertices of type ['A', 5] sage: mut_type = QuiverMutationType( ['A',[5,3], 1] ); mut_type ['A', [3, 5], 1] - sage: mut_type.standard_quiver() + sage: mut_type.standard_quiver() # needs sage.modules Quiver on 8 vertices of type ['A', [3, 5], 1] sage: mut_type = QuiverMutationType(['A',3],['B',3]); mut_type [ ['A', 3], ['B', 3] ] - sage: mut_type.standard_quiver() + sage: mut_type.standard_quiver() # needs sage.modules Quiver on 6 vertices of type [ ['A', 3], ['B', 3] ] sage: mut_type = QuiverMutationType(['A',3],['B',3],['X',6]); mut_type [ ['A', 3], ['B', 3], ['X', 6] ] - sage: mut_type.standard_quiver() + sage: mut_type.standard_quiver() # needs sage.modules Quiver on 12 vertices of type [ ['A', 3], ['B', 3], ['X', 6] ] """ from .quiver import ClusterQuiver @@ -2237,31 +2237,28 @@ def _save_data_dig6(n, types='ClassicalExceptional', verbose=False): TESTS:: + sage: # needs sage.modules sage: from sage.combinat.cluster_algebra_quiver.quiver_mutation_type import save_quiver_data - sage: save_quiver_data(2) # indirect doctest + sage: save_quiver_data(2) # indirect doctest The following types are saved to file ... and will now be used to determine quiver mutation types: [('A', 1)] The following types are saved to file ... and will now be used to determine quiver mutation types: [('A', (1, 1), 1), ('A', 2), ('B', 2), ('BC', 1, 1), ('G', 2)] - - sage: save_quiver_data(2,up_to=False) # indirect doctest + sage: save_quiver_data(2, up_to=False) # indirect doctest The following types are saved to file ... and will now be used to determine quiver mutation types: [('A', (1, 1), 1), ('A', 2), ('B', 2), ('BC', 1, 1), ('G', 2)] - - sage: save_quiver_data(2,up_to=False, types='Classical') # indirect doctest + sage: save_quiver_data(2, up_to=False, types='Classical') # indirect doctest The following types are saved to file ... and will now be used to determine quiver mutation types: [('A', (1, 1), 1), ('A', 2), ('B', 2), ('BC', 1, 1)] - - sage: save_quiver_data(2,up_to=False, types='Exceptional') # indirect doctest + sage: save_quiver_data(2, up_to=False, types='Exceptional') # indirect doctest The following types are saved to file ... and will now be used to determine quiver mutation types: [('G', 2)] - - sage: save_quiver_data(2,up_to=False, verbose=False) # indirect doctest + sage: save_quiver_data(2, up_to=False, verbose=False) # indirect doctest """ data = {} possible_types = ['Classical', 'ClassicalExceptional', 'Exceptional'] @@ -2311,6 +2308,7 @@ def save_quiver_data(n, up_to=True, types='ClassicalExceptional', verbose=True): TESTS:: + sage: # needs sage.modules sage: from sage.combinat.cluster_algebra_quiver.quiver_mutation_type import save_quiver_data sage: save_quiver_data(2) @@ -2319,22 +2317,18 @@ def save_quiver_data(n, up_to=True, types='ClassicalExceptional', verbose=True): The following types are saved to file ... and will now be used to determine quiver mutation types: [('A', (1, 1), 1), ('A', 2), ('B', 2), ('BC', 1, 1), ('G', 2)] - sage: save_quiver_data(2,up_to=False) The following types are saved to file ... and will now be used to determine quiver mutation types: [('A', (1, 1), 1), ('A', 2), ('B', 2), ('BC', 1, 1), ('G', 2)] - sage: save_quiver_data(2,up_to=False, types='Classical') The following types are saved to file ... and will now be used to determine quiver mutation types: [('A', (1, 1), 1), ('A', 2), ('B', 2), ('BC', 1, 1)] - sage: save_quiver_data(2,up_to=False, types='Exceptional') The following types are saved to file ... and will now be used to determine quiver mutation types: [('G', 2)] - sage: save_quiver_data(2,up_to=False, verbose=False) """ from sage.combinat.cluster_algebra_quiver.mutation_type import load_data @@ -2398,7 +2392,7 @@ def _mutation_type_error(data): EXAMPLES:: - sage: QuiverMutationType( 'Christian', 'Stump' ) # indirect doctest + sage: QuiverMutationType( 'Christian', 'Stump' ) # indirect doctest Traceback (most recent call last): ... ValueError: ['Christian', 'Stump'] is not a valid quiver mutation type diff --git a/src/sage/combinat/colored_permutations.py b/src/sage/combinat/colored_permutations.py index ff9a67e3083..2d6a6c31aaa 100644 --- a/src/sage/combinat/colored_permutations.py +++ b/src/sage/combinat/colored_permutations.py @@ -259,14 +259,14 @@ def to_matrix(self): sage: s1,s2,t = C.gens() sage: x = s1*s2*t*s2; x.one_line_form() [(1, 2), (0, 1), (0, 3)] - sage: M = x.to_matrix(); M + sage: M = x.to_matrix(); M # needs sage.rings.number_field [ 0 1 0] [zeta4 0 0] [ 0 0 1] The matrix multiplication is in the *opposite* order:: - sage: M == s2.to_matrix()*t.to_matrix()*s2.to_matrix()*s1.to_matrix() + sage: M == s2.to_matrix()*t.to_matrix()*s2.to_matrix()*s1.to_matrix() # needs sage.rings.number_field True """ Cp = CyclotomicField(self.parent()._m) @@ -541,14 +541,14 @@ def coxeter_matrix(self): EXAMPLES:: sage: C = ColoredPermutations(3, 4) - sage: C.coxeter_matrix() + sage: C.coxeter_matrix() # needs sage.modules [1 3 2 2] [3 1 3 2] [2 3 1 4] [2 2 4 1] sage: C = ColoredPermutations(1, 4) - sage: C.coxeter_matrix() + sage: C.coxeter_matrix() # needs sage.modules [1 3 2] [3 1 3] [2 3 1] @@ -556,7 +556,7 @@ def coxeter_matrix(self): TESTS:: sage: S = SignedPermutations(4) - sage: S.coxeter_matrix() + sage: S.coxeter_matrix() # needs sage.modules [1 3 2 2] [3 1 3 2] [2 3 1 4] @@ -676,7 +676,7 @@ def matrix_group(self): EXAMPLES:: sage: C = ColoredPermutations(4, 3) - sage: C.matrix_group() + sage: C.matrix_group() # needs sage.modules Matrix group over Cyclotomic Field of order 4 and degree 2 with 3 generators ( [0 1 0] [1 0 0] [ 1 0 0] [1 0 0] [0 0 1] [ 0 1 0] @@ -693,7 +693,7 @@ def as_permutation_group(self): EXAMPLES:: sage: C = ColoredPermutations(4, 3) - sage: C.as_permutation_group() + sage: C.as_permutation_group() # needs sage.groups Complex reflection group G(4, 1, 3) as a permutation group """ from sage.groups.perm_gps.permgroup_named import ComplexReflectionGroup @@ -896,8 +896,8 @@ def codegrees(self): sage: C = ColoredPermutations(3, 2) sage: f = prod(q - ds - 1 for ds in C.codegrees()) sage: d = lambda x: sum(1 for e in x.to_matrix().eigenvalues() if e == 1) - sage: g = sum(det(x.to_matrix()) * q**d(x) for x in C) - sage: f == g + sage: g = sum(det(x.to_matrix()) * q**d(x) for x in C) # needs sage.modules sage.rings.number_field + sage: f == g # needs sage.modules sage.rings.number_field True """ # Special case for the usual symmetric group @@ -1156,7 +1156,7 @@ def to_matrix(self): sage: S = SignedPermutations(4) sage: s1,s2,s3,s4 = S.gens() sage: x = s4*s1*s2*s3*s4 - sage: M = x.to_matrix(); M + sage: M = x.to_matrix(); M # needs sage.modules [ 0 1 0 0] [ 0 0 1 0] [ 0 0 0 -1] @@ -1164,8 +1164,8 @@ def to_matrix(self): The matrix multiplication is in the *opposite* order:: - sage: m1,m2,m3,m4 = [g.to_matrix() for g in S.gens()] - sage: M == m4 * m3 * m2 * m1 * m4 + sage: m1,m2,m3,m4 = [g.to_matrix() for g in S.gens()] # needs sage.modules + sage: M == m4 * m3 * m2 * m1 * m4 # needs sage.modules True """ return self._perm.to_matrix() * diagonal_matrix(self._colors) @@ -1344,8 +1344,9 @@ class SignedPermutations(ColoredPermutations): This is a finite Coxeter group of type `B_n`:: - sage: S.canonical_representation() - Finite Coxeter group over Number Field in a with defining polynomial x^2 - 2 with a = 1.414213562373095? with Coxeter matrix: + sage: S.canonical_representation() # needs sage.modules + Finite Coxeter group over Number Field in a with defining polynomial x^2 - 2 + with a = 1.414213562373095? with Coxeter matrix: [1 3 2 2] [3 1 3 2] [2 3 1 4] diff --git a/src/sage/combinat/combinat.py b/src/sage/combinat/combinat.py index 4c182f7c0da..451f8093393 100644 --- a/src/sage/combinat/combinat.py +++ b/src/sage/combinat/combinat.py @@ -319,17 +319,18 @@ def bell_number(n, algorithm='flint', **options) -> Integer: EXAMPLES:: - sage: bell_number(10) # optional - sage.libs.flint + sage: # needs sage.libs.flint + sage: bell_number(10) 115975 - sage: bell_number(2) # optional - sage.libs.flint + sage: bell_number(2) 2 - sage: bell_number(-10) # optional - sage.libs.flint + sage: bell_number(-10) Traceback (most recent call last): ... ArithmeticError: Bell numbers not defined for negative indices - sage: bell_number(1) # optional - sage.libs.flint + sage: bell_number(1) 1 - sage: bell_number(1/3) # optional - sage.libs.flint + sage: bell_number(1/3) Traceback (most recent call last): ... TypeError: no conversion of this rational to integer @@ -339,17 +340,17 @@ def bell_number(n, algorithm='flint', **options) -> Integer: first time, we deem the precision too low, we use our guess to (temporarily) raise mpmath's precision and the Bell number is recomputed. :: - sage: k = bell_number(30, 'mpmath'); k # optional - mpmath + sage: k = bell_number(30, 'mpmath'); k # needs mpmath 846749014511809332450147 - sage: k == bell_number(30) # optional - mpmath sage.libs.flint + sage: k == bell_number(30) # needs mpmath sage.libs.flint True If you knows what precision is necessary before computing the Bell number, you can use the ``prec`` option:: - sage: k2 = bell_number(30, 'mpmath', prec=30); k2 # optional - mpmath + sage: k2 = bell_number(30, 'mpmath', prec=30); k2 # needs mpmath 846749014511809332450147 - sage: k == k2 # optional - mpmath + sage: k == k2 # needs mpmath True .. WARNING:: @@ -357,18 +358,18 @@ def bell_number(n, algorithm='flint', **options) -> Integer: Running mpmath with the precision set too low can result in incorrect results:: - sage: k = bell_number(30, 'mpmath', prec=15); k # optional - mpmath + sage: k = bell_number(30, 'mpmath', prec=15); k # needs mpmath 846749014511809388871680 - sage: k == bell_number(30) # optional - mpmath sage.libs.flint + sage: k == bell_number(30) # needs mpmath sage.libs.flint False TESTS:: - sage: all(bell_number(n) == bell_number(n,'dobinski') for n in range(100)) # optional - sage.libs.flint + sage: all(bell_number(n) == bell_number(n,'dobinski') for n in range(100)) # needs sage.libs.flint True - sage: all(bell_number(n) == bell_number(n,'gap') for n in range(100)) # optional - sage.libs.flint sage.libs.gap + sage: all(bell_number(n) == bell_number(n,'gap') for n in range(100)) # needs sage.libs.flint sage.libs.gap True - sage: all(bell_number(n) == bell_number(n,'mpmath', prec=500) # optional - mpmath sage.libs.flint + sage: all(bell_number(n) == bell_number(n,'mpmath', prec=500) # needs mpmath sage.libs.flint ....: for n in range(200, 220)) True @@ -548,12 +549,12 @@ def euler_number(n, algorithm='flint') -> Integer: EXAMPLES:: - sage: [euler_number(i) for i in range(10)] # optional - sage.libs.flint + sage: [euler_number(i) for i in range(10)] # needs sage.libs.flint [1, 0, -1, 0, 5, 0, -61, 0, 1385, 0] sage: x = PowerSeriesRing(QQ, 'x').gen().O(10) - sage: 2/(exp(x)+exp(-x)) # optional - sage.symbolic + sage: 2/(exp(x)+exp(-x)) 1 - 1/2*x^2 + 5/24*x^4 - 61/720*x^6 + 277/8064*x^8 + O(x^10) - sage: [euler_number(i)/factorial(i) for i in range(11)] # optional - sage.libs.flint + sage: [euler_number(i)/factorial(i) for i in range(11)] # needs sage.libs.flint [1, 0, -1/2, 0, 5/24, 0, -61/720, 0, 277/8064, 0, -50521/3628800] sage: euler_number(-1) Traceback (most recent call last): @@ -562,7 +563,7 @@ def euler_number(n, algorithm='flint') -> Integer: TESTS:: - sage: euler_number(6, 'maxima') # optional - sage.symbolic + sage: euler_number(6, 'maxima') # needs sage.symbolic -61 REFERENCES: @@ -706,21 +707,21 @@ def fibonacci(n, algorithm="pari") -> Integer: EXAMPLES:: - sage: fibonacci(10) # optional - sage.libs.pari + sage: fibonacci(10) # needs sage.libs.pari 55 - sage: fibonacci(10, algorithm='gap') # optional - sage.libs.gap + sage: fibonacci(10, algorithm='gap') # needs sage.libs.gap 55 :: - sage: fibonacci(-100) # optional - sage.libs.pari + sage: fibonacci(-100) # needs sage.libs.pari -354224848179261915075 - sage: fibonacci(100) # optional - sage.libs.pari + sage: fibonacci(100) # needs sage.libs.pari 354224848179261915075 :: - sage: fibonacci(0) # optional - sage.libs.pari + sage: fibonacci(0) # needs sage.libs.pari 0 sage: fibonacci(1/2) Traceback (most recent call last): @@ -759,17 +760,18 @@ def lucas_number1(n, P, Q): EXAMPLES:: - sage: lucas_number1(5,1,-1) # optional - sage.libs.gap + sage: # needs sage.libs.gap + sage: lucas_number1(5,1,-1) 5 - sage: lucas_number1(6,1,-1) # optional - sage.libs.gap + sage: lucas_number1(6,1,-1) 8 - sage: lucas_number1(7,1,-1) # optional - sage.libs.gap + sage: lucas_number1(7,1,-1) 13 - sage: lucas_number1(7,1,-2) # optional - sage.libs.gap + sage: lucas_number1(7,1,-2) 43 - sage: lucas_number1(5,2,3/5) # optional - sage.libs.gap + sage: lucas_number1(5,2,3/5) 229/25 - sage: lucas_number1(5,2,1.5) # optional - sage.libs.gap + sage: lucas_number1(5,2,1.5) 1/4 There was a conjecture that the sequence `L_n` defined by @@ -779,7 +781,7 @@ def lucas_number1(n, P, Q): sage: def lucas(n): ....: return Integer((5/2)*lucas_number1(n,1,-1) + (1/2)*lucas_number2(n,1,-1)) - sage: [[lucas(n), is_prime(lucas(n)), n+1, is_prime(n+1)] for n in range(15)] # optional - sage.libs.gap + sage: [[lucas(n), is_prime(lucas(n)), n+1, is_prime(n+1)] for n in range(15)] # needs sage.libs.gap [[1, False, 1, False], [3, True, 2, True], [4, False, 3, True], @@ -827,26 +829,27 @@ def lucas_number2(n, P, Q): EXAMPLES:: - sage: [lucas_number2(i,1,-1) for i in range(10)] # optional - sage.libs.gap + sage: [lucas_number2(i,1,-1) for i in range(10)] # needs sage.libs.gap [2, 1, 3, 4, 7, 11, 18, 29, 47, 76] - sage: [fibonacci(i-1)+fibonacci(i+1) for i in range(10)] # optional - sage.libs.pari + sage: [fibonacci(i-1)+fibonacci(i+1) for i in range(10)] # needs sage.libs.pari [2, 1, 3, 4, 7, 11, 18, 29, 47, 76] :: - sage: n = lucas_number2(5,2,3); n # optional - sage.libs.gap + sage: # needs sage.libs.gap + sage: n = lucas_number2(5,2,3); n 2 - sage: type(n) # optional - sage.libs.gap + sage: type(n) - sage: n = lucas_number2(5,2,-3/9); n # optional - sage.libs.gap + sage: n = lucas_number2(5,2,-3/9); n 418/9 - sage: type(n) # optional - sage.libs.gap + sage: type(n) The case `P=1`, `Q=-1` is the Lucas sequence in Brualdi's Introductory Combinatorics, 4th ed., Prentice-Hall, 2004:: - sage: [lucas_number2(n,1,-1) for n in range(10)] # optional - sage.libs.gap + sage: [lucas_number2(n,1,-1) for n in range(10)] # needs sage.libs.gap [2, 1, 3, 4, 7, 11, 18, 29, 47, 76] """ n = ZZ(n) @@ -875,20 +878,21 @@ def stirling_number1(n, k, algorithm="gap") -> Integer: EXAMPLES:: - sage: stirling_number1(3,2) # optional - sage.libs.gap + sage: # needs sage.libs.gap + sage: stirling_number1(3,2) 3 - sage: stirling_number1(5,2) # optional - sage.libs.gap + sage: stirling_number1(5,2) 50 - sage: 9*stirling_number1(9,5) + stirling_number1(9,4) # optional - sage.libs.gap + sage: 9*stirling_number1(9,5) + stirling_number1(9,4) 269325 - sage: stirling_number1(10,5) # optional - sage.libs.gap + sage: stirling_number1(10,5) 269325 Indeed, `S_1(n,k) = S_1(n-1,k-1) + (n-1)S_1(n-1,k)`. TESTS:: - sage: stirling_number1(10,5, algorithm='flint') # optional - sage.libs.flint + sage: stirling_number1(10,5, algorithm='flint') # needs sage.libs.flint 269325 sage: s_sage = stirling_number1(50,3, algorithm="mutta") @@ -981,13 +985,13 @@ def stirling_number2(n, k, algorithm=None) -> Integer: 1900842429486 sage: type(n) - sage: n = stirling_number2(20, 11, algorithm='gap'); n # optional - sage.libs.gap + sage: n_gap = stirling_number2(20, 11, algorithm='gap'); n_gap # needs sage.libs.gap 1900842429486 - sage: type(n) # optional - sage.libs.gap + sage: type(n_gap) # needs sage.libs.gap - sage: n = stirling_number2(20, 11, algorithm='flint'); n # optional - sage.libs.flint + sage: n_flint = stirling_number2(20, 11, algorithm='flint'); n_flint # needs sage.libs.flint 1900842429486 - sage: type(n) # optional - sage.libs.flint + sage: type(n_flint) # needs sage.libs.flint Sage's implementation splitting the computation of the Stirling @@ -996,7 +1000,7 @@ def stirling_number2(n, k, algorithm=None) -> Integer: For `n<200`:: - sage: for n in Subsets(range(100,200), 5).random_element(): # optional - sage.libs.flint sage.libs.gap + sage: for n in Subsets(range(100,200), 5).random_element(): # needs sage.libs.flint sage.libs.gap ....: for k in Subsets(range(n), 5).random_element(): ....: s_sage = stirling_number2(n,k) ....: s_flint = stirling_number2(n,k, algorithm = "flint") @@ -1006,7 +1010,7 @@ def stirling_number2(n, k, algorithm=None) -> Integer: For `n\geq 200`:: - sage: for n in Subsets(range(200,300), 5).random_element(): # optional - sage.libs.flint sage.libs.gap + sage: for n in Subsets(range(200,300), 5).random_element(): # needs sage.libs.flint sage.libs.gap ....: for k in Subsets(range(n), 5).random_element(): ....: s_sage = stirling_number2(n,k) ....: s_flint = stirling_number2(n,k, algorithm = "flint") @@ -1014,7 +1018,7 @@ def stirling_number2(n, k, algorithm=None) -> Integer: ....: if not (s_sage == s_flint and s_sage == s_gap): ....: print("Error with n<200") - sage: stirling_number2(20, 3, algorithm="maxima") # optional - sage.symbolic + sage: stirling_number2(20, 3, algorithm="maxima") # needs sage.symbolic 580606446 sage: s_sage = stirling_number2(5, 3, algorithm="namba") @@ -1092,7 +1096,7 @@ def polygonal_number(s, n): A non-integer input returns an error:: - sage: polygonal_number(3.5, 1) + sage: polygonal_number(3.5, 1) # needs sage.rings.real_mpfr Traceback (most recent call last): ... TypeError: Attempt to coerce non-integral RealNumber to Integer @@ -1173,11 +1177,12 @@ def __init__(self, l, copy=True): Test indirectly that we copy the input (see :trac:`18184`):: - sage: L = IntegerListsLex(element_class=Partition) # optional - sage.combinat - sage: x = [3, 2, 1] # optional - sage.combinat - sage: P = L(x) # optional - sage.combinat - sage: x[0] = 5 # optional - sage.combinat - sage: list(P) # optional - sage.combinat + sage: # needs sage.combinat + sage: L = IntegerListsLex(element_class=Partition) + sage: x = [3, 2, 1] + sage: P = L(x) + sage: x[0] = 5 + sage: list(P) [3, 2, 1] """ if copy: @@ -1511,22 +1516,23 @@ class CombinatorialElement(CombinatorialObject, Element, EXAMPLES:: + sage: # needs sage.combinat sage: from sage.combinat.combinat import CombinatorialElement - sage: e = CombinatorialElement(Partitions(6), [3,2,1]) # optional - sage.combinat - sage: e == loads(dumps(e)) # optional - sage.combinat + sage: e = CombinatorialElement(Partitions(6), [3,2,1]) + sage: e == loads(dumps(e)) True - sage: parent(e) # optional - sage.combinat + sage: parent(e) Partitions of the integer 6 - sage: list(e) # optional - sage.combinat + sage: list(e) [3, 2, 1] Check classcalls:: - sage: class Foo(CombinatorialElement): + sage: class Foo(CombinatorialElement): # needs sage.combinat ....: @staticmethod ....: def __classcall__(cls, x): ....: return x - sage: Foo(17) + sage: Foo(17) # needs sage.combinat 17 """ @@ -1615,7 +1621,7 @@ def is_finite(self) -> bool: EXAMPLES:: - sage: Partitions(5).is_finite() # optional - sage.combinat + sage: Partitions(5).is_finite() # needs sage.combinat True sage: Permutations().is_finite() False @@ -1649,7 +1655,7 @@ def __str__(self) -> str: EXAMPLES:: - sage: str(Partitions(5)) # optional - sage.combinat + sage: str(Partitions(5)) # needs sage.combinat 'Partitions of the integer 5' """ return repr(self) @@ -1658,7 +1664,7 @@ def _repr_(self) -> str: """ EXAMPLES:: - sage: repr(Partitions(5)) # indirect doctest # optional - sage.combinat + sage: repr(Partitions(5)) # indirect doctest # needs sage.combinat 'Partitions of the integer 5' """ if hasattr(self, '_name') and self._name: @@ -1681,7 +1687,7 @@ def __contains__(self, x) -> bool: EXAMPLES:: sage: C = CombinatorialClass() - sage: x in C # optional - sage.symbolic + sage: x in C # needs sage.symbolic Traceback (most recent call last): ... NotImplementedError @@ -1696,11 +1702,12 @@ def __eq__(self, other): EXAMPLES:: - sage: p5 = Partitions(5) # optional - sage.combinat - sage: p6 = Partitions(6) # optional - sage.combinat - sage: repr(p5) == repr(p6) # optional - sage.combinat + sage: # needs sage.combinat + sage: p5 = Partitions(5) + sage: p6 = Partitions(6) + sage: repr(p5) == repr(p6) False - sage: p5 == p6 # optional - sage.combinat + sage: p5 == p6 False """ return repr(self) == repr(other) @@ -1711,9 +1718,9 @@ def __ne__(self, other): EXAMPLES:: - sage: p5 = Partitions(5) # optional - sage.combinat - sage: p6 = Partitions(6) # optional - sage.combinat - sage: p5 != p6 # optional - sage.combinat + sage: p5 = Partitions(5) # needs sage.combinat + sage: p6 = Partitions(6) # needs sage.combinat + sage: p5 != p6 # needs sage.combinat True """ return not (self == other) @@ -1765,14 +1772,15 @@ def __call__(self, x): EXAMPLES:: - sage: p5 = Partitions(5) # optional - sage.combinat - sage: a = [2,2,1] # optional - sage.combinat - sage: type(a) # optional - sage.combinat + sage: # needs sage.combinat + sage: p5 = Partitions(5) + sage: a = [2,2,1] + sage: type(a) - sage: a = p5(a) # optional - sage.combinat - sage: type(a) # optional - sage.combinat + sage: a = p5(a) + sage: type(a) - sage: p5([2,1]) # optional - sage.combinat + sage: p5([2,1]) Traceback (most recent call last): ... ValueError: [2, 1] is not an element of Partitions of the integer 5 @@ -1794,8 +1802,8 @@ def element_class(self): TESTS:: - sage: P5 = Partitions(5) # optional - sage.combinat - sage: P5.element_class # optional - sage.combinat + sage: P5 = Partitions(5) # needs sage.combinat + sage: P5.element_class # needs sage.combinat """ # assert not isinstance(self, Parent) # Raises an alert if we override the proper definition from Parent @@ -1810,9 +1818,9 @@ def _element_constructor_(self, x): TESTS:: - sage: P5 = Partitions(5) # optional - sage.combinat - sage: p = P5([3,2]) # indirect doctest # optional - sage.combinat - sage: type(p) # optional - sage.combinat + sage: P5 = Partitions(5) # needs sage.combinat + sage: p = P5([3,2]) # indirect doctest # needs sage.combinat + sage: type(p) # needs sage.combinat """ # assert not isinstance(self, Parent) # Raises an alert if we override the proper definition from Parent @@ -1947,8 +1955,8 @@ def __iter__(self): EXAMPLES:: - sage: p5 = Partitions(5) # optional - sage.combinat - sage: [i for i in p5] # optional - sage.combinat + sage: p5 = Partitions(5) # needs sage.combinat + sage: [i for i in p5] # needs sage.combinat [[5], [4, 1], [3, 2], [3, 1, 1], [2, 2, 1], [2, 1, 1, 1], [1, 1, 1, 1, 1]] sage: C = CombinatorialClass() sage: iter(C) @@ -2115,7 +2123,7 @@ def filter(self, f, name=None): sage: from sage.combinat.combinat import Permutations_CC sage: P = Permutations_CC(3).filter(lambda x: x.avoids([1,2])) - sage: P.list() # optional - sage.combinat + sage: P.list() # needs sage.combinat [[3, 2, 1]] """ return FilteredCombinatorialClass(self, f, name=name) @@ -2160,15 +2168,15 @@ class by `f`, as a combinatorial class. If the function is not injective, then there may be repeated elements:: - sage: P = Partitions(4) # optional - sage.combinat - sage: P.list() # optional - sage.combinat + sage: P = Partitions(4) # needs sage.combinat + sage: P.list() # needs sage.combinat [[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]] - sage: P.map(len).list() # optional - sage.combinat + sage: P.map(len).list() # needs sage.combinat [1, 2, 2, 3, 4] Use ``is_injective=False`` to get a correct result in this case:: - sage: P.map(len, is_injective=False).list() # optional - sage.combinat + sage: P.map(len, is_injective=False).list() # needs sage.combinat [1, 2, 3, 4] TESTS:: @@ -2224,9 +2232,9 @@ def __contains__(self, x) -> bool: False sage: [4,3,2,1] in P False - sage: Permutation([1,2,3]) in P # optional - sage.combinat + sage: Permutation([1,2,3]) in P # needs sage.combinat False - sage: Permutation([3,2,1]) in P # optional - sage.combinat + sage: Permutation([3,2,1]) in P # needs sage.combinat True """ return x in self.combinatorial_class and self.f(x) @@ -2237,7 +2245,7 @@ def cardinality(self) -> Integer: sage: from sage.combinat.combinat import Permutations_CC sage: P = Permutations_CC(3).filter(lambda x: x.avoids([1,2])) - sage: P.cardinality() # optional - sage.combinat + sage: P.cardinality() # needs sage.combinat 1 """ c = 0 @@ -2251,7 +2259,7 @@ def __iter__(self) -> Iterator: sage: from sage.combinat.combinat import Permutations_CC sage: P = Permutations_CC(3).filter(lambda x: x.avoids([1,2])) - sage: list(P) # optional - sage.combinat + sage: list(P) # needs sage.combinat [[3, 2, 1]] """ for x in self.combinatorial_class: @@ -2480,13 +2488,14 @@ class MapCombinatorialClass(ImageSubobject, CombinatorialClass): EXAMPLES:: - sage: R = SymmetricGroup(10).map(attrcall('reduced_word')) # optional - sage.groups - sage: R.an_element() # optional - sage.groups + sage: # needs sage.groups + sage: R = SymmetricGroup(10).map(attrcall('reduced_word')) + sage: R.an_element() [9, 8, 7, 6, 5, 4, 3, 2] - sage: R.cardinality() # optional - sage.groups + sage: R.cardinality() 3628800 - sage: i = iter(R) # optional - sage.groups - sage: next(i), next(i), next(i) # optional - sage.groups + sage: i = iter(R) + sage: next(i), next(i), next(i) ([], [1, 2, 3, 4, 5, 6, 7, 8, 9], [1]) """ @@ -2494,7 +2503,7 @@ def __init__(self, cc, f, name=None, *, is_injective=True): """ TESTS:: - sage: Partitions(3).map(attrcall('conjugate')) # optional - sage.combinat + sage: Partitions(3).map(attrcall('conjugate')) # needs sage.combinat Image of Partitions of the integer 3 by The map *.conjugate() from Partitions of the integer 3 """ @@ -2623,9 +2632,9 @@ def tuples(S, k, algorithm='itertools'): :: - sage: K. = GF(4, 'a') # optional - sage.rings.finite_rings - sage: mset = [x for x in K if x != 0] # optional - sage.rings.finite_rings - sage: tuples(mset, 2) # optional - sage.rings.finite_rings + sage: K. = GF(4, 'a') # needs sage.rings.finite_rings + sage: mset = [x for x in K if x != 0] # needs sage.rings.finite_rings + sage: tuples(mset, 2) # needs sage.rings.finite_rings [(a, a), (a, a + 1), (a, 1), (a + 1, a), (a + 1, a + 1), (a + 1, 1), (1, a), (1, a + 1), (1, 1)] @@ -2709,16 +2718,16 @@ def number_of_tuples(S, k, algorithm='naive') -> Integer: sage: S = [1,2,3,4,5] sage: number_of_tuples(S,2) 25 - sage: number_of_tuples(S,2, algorithm="gap") # optional - sage.libs.gap + sage: number_of_tuples(S,2, algorithm="gap") # needs sage.libs.gap 25 sage: S = [1,1,2,3,4,5] sage: number_of_tuples(S,2) 25 - sage: number_of_tuples(S,2, algorithm="gap") # optional - sage.libs.gap + sage: number_of_tuples(S,2, algorithm="gap") # needs sage.libs.gap 25 sage: number_of_tuples(S,0) 1 - sage: number_of_tuples(S,0, algorithm="gap") # optional - sage.libs.gap + sage: number_of_tuples(S,0, algorithm="gap") # needs sage.libs.gap 1 """ if algorithm == 'naive': @@ -2770,7 +2779,7 @@ def unordered_tuples(S, k, algorithm='itertools'): We check that this agrees with GAP:: - sage: unordered_tuples(S, 3, algorithm='gap') # optional - sage.libs.gap + sage: unordered_tuples(S, 3, algorithm='gap') # needs sage.libs.gap [(1, 1, 1), (1, 1, 2), (1, 2, 2), (2, 2, 2)] We check the result on strings:: @@ -2778,13 +2787,13 @@ def unordered_tuples(S, k, algorithm='itertools'): sage: S = ["a","b","c"] sage: unordered_tuples(S, 2) [('a', 'a'), ('a', 'b'), ('a', 'c'), ('b', 'b'), ('b', 'c'), ('c', 'c')] - sage: unordered_tuples(S, 2, algorithm='gap') # optional - sage.libs.gap + sage: unordered_tuples(S, 2, algorithm='gap') # needs sage.libs.gap [('a', 'a'), ('a', 'b'), ('a', 'c'), ('b', 'b'), ('b', 'c'), ('c', 'c')] Lastly we check on a multiset:: sage: S = [1,1,2] - sage: unordered_tuples(S, 3) == unordered_tuples(S, 3, 'gap') # optional - sage.libs.gap + sage: unordered_tuples(S, 3) == unordered_tuples(S, 3, 'gap') # needs sage.libs.gap True sage: unordered_tuples(S, 3) [(1, 1, 1), (1, 1, 2), (1, 2, 2), (2, 2, 2)] @@ -2825,16 +2834,16 @@ def number_of_unordered_tuples(S, k, algorithm='naive') -> Integer: sage: S = [1,2,3,4,5] sage: number_of_unordered_tuples(S,2) 15 - sage: number_of_unordered_tuples(S,2, algorithm="gap") # optional - sage.libs.gap + sage: number_of_unordered_tuples(S,2, algorithm="gap") # needs sage.libs.gap 15 sage: S = [1,1,2,3,4,5] sage: number_of_unordered_tuples(S,2) 15 - sage: number_of_unordered_tuples(S,2, algorithm="gap") # optional - sage.libs.gap + sage: number_of_unordered_tuples(S,2, algorithm="gap") # needs sage.libs.gap 15 sage: number_of_unordered_tuples(S,0) 1 - sage: number_of_unordered_tuples(S,0, algorithm="gap") # optional - sage.libs.gap + sage: number_of_unordered_tuples(S,0, algorithm="gap") # needs sage.libs.gap 1 """ if algorithm == 'naive': @@ -2934,19 +2943,19 @@ def bell_polynomial(n: Integer, k: Integer): EXAMPLES:: - sage: bell_polynomial(6,2) # optional - sage.combinat + sage: bell_polynomial(6,2) # needs sage.combinat 10*x2^2 + 15*x1*x3 + 6*x0*x4 - sage: bell_polynomial(6,3) # optional - sage.combinat + sage: bell_polynomial(6,3) # needs sage.combinat 15*x1^3 + 60*x0*x1*x2 + 15*x0^2*x3 TESTS: Check that :trac:`18338` is fixed:: - sage: bell_polynomial(0,0).parent() # optional - sage.combinat + sage: bell_polynomial(0,0).parent() # needs sage.combinat Multivariate Polynomial Ring in x over Integer Ring - sage: for n in (0..4): # optional - sage.combinat + sage: for n in (0..4): # needs sage.combinat ....: print([bell_polynomial(n,k).coefficients() for k in (0..n)]) [[1]] [[], [1]] @@ -2997,12 +3006,12 @@ def fibonacci_sequence(start, stop=None, algorithm=None) -> Iterator: EXAMPLES:: - sage: fibs = [i for i in fibonacci_sequence(10, 20)]; fibs # optional - sage.libs.pari + sage: fibs = [i for i in fibonacci_sequence(10, 20)]; fibs # needs sage.libs.pari [55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181] :: - sage: sum([i for i in fibonacci_sequence(100, 110)]) # optional - sage.libs.pari + sage: sum([i for i in fibonacci_sequence(100, 110)]) # needs sage.libs.pari 69919376923075308730013 .. SEEALSO:: @@ -3036,25 +3045,25 @@ def fibonacci_xrange(start, stop=None, algorithm='pari') -> Iterator: EXAMPLES:: - sage: fibs_in_some_range = [i for i in fibonacci_xrange(10^7, 10^8)] # optional - sage.libs.pari - sage: len(fibs_in_some_range) # optional - sage.libs.pari + sage: fibs_in_some_range = [i for i in fibonacci_xrange(10^7, 10^8)] # needs sage.libs.pari + sage: len(fibs_in_some_range) # needs sage.libs.pari 4 - sage: fibs_in_some_range # optional - sage.libs.pari + sage: fibs_in_some_range # needs sage.libs.pari [14930352, 24157817, 39088169, 63245986] :: - sage: fibs = [i for i in fibonacci_xrange(10, 100)]; fibs # optional - sage.libs.pari + sage: fibs = [i for i in fibonacci_xrange(10, 100)]; fibs # needs sage.libs.pari [13, 21, 34, 55, 89] :: - sage: list(fibonacci_xrange(13, 34)) # optional - sage.libs.pari + sage: list(fibonacci_xrange(13, 34)) # needs sage.libs.pari [13, 21] A solution to the second Project Euler problem:: - sage: sum([i for i in fibonacci_xrange(10^6) if is_even(i)]) # optional - sage.libs.pari + sage: sum([i for i in fibonacci_xrange(10^6) if is_even(i)]) # needs sage.libs.pari 1089154 .. SEEALSO:: @@ -3111,31 +3120,32 @@ def bernoulli_polynomial(x, n: Integer): EXAMPLES:: + sage: # needs sage.libs.flint sage: y = QQ['y'].0 - sage: bernoulli_polynomial(y, 5) # optional - sage.libs.flint + sage: bernoulli_polynomial(y, 5) y^5 - 5/2*y^4 + 5/3*y^3 - 1/6*y - sage: bernoulli_polynomial(y, 5)(12) # optional - sage.libs.flint + sage: bernoulli_polynomial(y, 5)(12) 199870 - sage: bernoulli_polynomial(12, 5) # optional - sage.libs.flint + sage: bernoulli_polynomial(12, 5) 199870 - sage: bernoulli_polynomial(y^2 + 1, 5) # optional - sage.libs.flint + sage: bernoulli_polynomial(y^2 + 1, 5) y^10 + 5/2*y^8 + 5/3*y^6 - 1/6*y^2 sage: P. = ZZ[] - sage: p = bernoulli_polynomial(t, 6) # optional - sage.libs.flint - sage: p.parent() # optional - sage.libs.flint + sage: p = bernoulli_polynomial(t, 6) + sage: p.parent() Univariate Polynomial Ring in t over Rational Field We verify an instance of the formula which is the origin of the Bernoulli polynomials (and numbers):: sage: power_sum = sum(k^4 for k in range(10)) - sage: 5*power_sum == bernoulli_polynomial(10, 5) - bernoulli(5) # optional - sage.libs.flint + sage: 5*power_sum == bernoulli_polynomial(10, 5) - bernoulli(5) # needs sage.libs.flint True TESTS:: sage: x = polygen(QQ, 'x') - sage: bernoulli_polynomial(x, 0).parent() # optional - sage.libs.flint + sage: bernoulli_polynomial(x, 0).parent() Univariate Polynomial Ring in x over Rational Field REFERENCES: diff --git a/src/sage/combinat/combinat_cython.pyx b/src/sage/combinat/combinat_cython.pyx index 68a7de2498e..3b8fb7aefa3 100644 --- a/src/sage/combinat/combinat_cython.pyx +++ b/src/sage/combinat/combinat_cython.pyx @@ -308,7 +308,7 @@ def set_partition_composition(tuple sp1, tuple sp2): sage: sp1 = ((1,-2),(2,-1)) sage: sp2 = ((1,-2),(2,-1)) sage: p, c = set_partition_composition(sp1, sp2) - sage: (SetPartition(p), c) == (SetPartition([[1,-1],[2,-2]]), 0) # optional - sage.combinat + sage: (SetPartition(p), c) == (SetPartition([[1,-1],[2,-2]]), 0) # needs sage.combinat True """ cdef int num_loops = 0 # The number of loops removed diff --git a/src/sage/combinat/combination.py b/src/sage/combinat/combination.py index dca90c2a4e3..8561935b403 100644 --- a/src/sage/combinat/combination.py +++ b/src/sage/combinat/combination.py @@ -148,15 +148,15 @@ class of combinations of ``mset`` of size ``k``. It is possible to take combinations of Sage objects:: - sage: Combinations([vector([1,1]), vector([2,2]), vector([3,3])], 2).list() # optional - sage.modules + sage: Combinations([vector([1,1]), vector([2,2]), vector([3,3])], 2).list() # needs sage.modules [[(1, 1), (2, 2)], [(1, 1), (3, 3)], [(2, 2), (3, 3)]] TESTS: We check that the code works even for non mutable objects:: - sage: l = [vector((0,0)), vector((0,1))] # optional - sage.modules - sage: Combinations(l).list() # optional - sage.modules + sage: l = [vector((0,0)), vector((0,1))] # needs sage.modules + sage: Combinations(l).list() # needs sage.modules [[], [(0, 0)], [(0, 1)], [(0, 0), (0, 1)]] """ # Check to see if everything in mset is unique @@ -269,7 +269,7 @@ def cardinality(self): sage: Combinations([1,2,3]).cardinality() 8 - sage: Combinations(['a','a','b']).cardinality() # optional - sage.libs.gap + sage: Combinations(['a','a','b']).cardinality() # needs sage.libs.gap 6 """ c = 0 @@ -431,7 +431,7 @@ def cardinality(self): EXAMPLES:: sage: mset = [1,1,2,3,4,4,5] - sage: Combinations(mset,2).cardinality() # optional - sage.libs.gap + sage: Combinations(mset,2).cardinality() # needs sage.libs.gap 12 """ from sage.libs.gap.libgap import libgap @@ -656,7 +656,7 @@ def from_rank(r, n, k): ....: for i in range(k): ....: comb[i] = (n - 1) - comb[i] ....: return tuple(comb) - sage: all(from_rank(r, n, k) == from_rank_comb_largest(r, n, k) + sage: all(from_rank(r, n, k) == from_rank_comb_largest(r, n, k) # needs sage.symbolic ....: for n in range(10) for k in range(n+1) for r in range(binomial(n,k))) True """ diff --git a/src/sage/combinat/combinatorial_map.py b/src/sage/combinat/combinatorial_map.py index 0ff4ffe34bc..5ec7871821c 100644 --- a/src/sage/combinat/combinatorial_map.py +++ b/src/sage/combinat/combinatorial_map.py @@ -302,9 +302,9 @@ def __call__(self, *args, **kwds): sage: p = Permutation([1,3,2,4]) sage: cm = type(p).left_tableau; cm Combinatorial map: Robinson-Schensted insertion tableau - sage: cm(p) # optional - sage.combinat + sage: cm(p) # needs sage.combinat [[1, 2, 4], [3]] - sage: cm(Permutation([4,3,2,1])) # optional - sage.combinat + sage: cm(Permutation([4,3,2,1])) # needs sage.combinat [[1], [2], [3], [4]] """ if self._inst is not None: diff --git a/src/sage/combinat/composition.py b/src/sage/combinat/composition.py index 829ba9e8a8e..4d98a25108d 100644 --- a/src/sage/combinat/composition.py +++ b/src/sage/combinat/composition.py @@ -172,18 +172,19 @@ def _ascii_art_(self): """ TESTS:: - sage: ascii_art(Compositions(4).list()) # optional - sage.combinat + sage: # needs sage.combinat + sage: ascii_art(Compositions(4).list()) [ * ] [ * ** * * ] [ * * ** *** * ** * ] [ *, * , * , * , **, ** , ***, **** ] - sage: Partitions.options(diagram_str='#', convention="French") # optional - sage.combinat - sage: ascii_art(Compositions(4).list()) # optional - sage.combinat + sage: Partitions.options(diagram_str='#', convention="French") + sage: ascii_art(Compositions(4).list()) [ # ] [ # # # ## ] [ # # ## # # ## ### ] [ #, ##, #, ###, #, ##, #, #### ] - sage: Partitions.options._reset() # optional - sage.combinat + sage: Partitions.options._reset() """ from sage.typeset.ascii_art import ascii_art return ascii_art(self.to_skew_partition()) @@ -192,20 +193,21 @@ def _unicode_art_(self): """ TESTS:: - sage: unicode_art(Compositions(4).list()) # optional - sage.combinat + sage: # needs sage.combinat + sage: unicode_art(Compositions(4).list()) ⎡ ┌┐ ⎤ ⎢ ├┤ ┌┬┐ ┌┐ ┌┐ ⎥ ⎢ ├┤ ├┼┘ ┌┼┤ ┌┬┬┐ ├┤ ┌┬┐ ┌┐ ⎥ ⎢ ├┤ ├┤ ├┼┘ ├┼┴┘ ┌┼┤ ┌┼┼┘ ┌┬┼┤ ┌┬┬┬┐ ⎥ ⎣ └┘, └┘ , └┘ , └┘ , └┴┘, └┴┘ , └┴┴┘, └┴┴┴┘ ⎦ - sage: Partitions.options(diagram_str='#', convention="French") # optional - sage.combinat - sage: unicode_art(Compositions(4).list()) # optional - sage.combinat + sage: Partitions.options(diagram_str='#', convention="French") + sage: unicode_art(Compositions(4).list()) ⎡ ┌┐ ⎤ ⎢ ├┤ ┌┐ ┌┐ ┌┬┐ ⎥ ⎢ ├┤ ├┤ ├┼┐ ┌┐ └┼┤ ┌┬┐ ┌┬┬┐ ⎥ ⎢ ├┤ ├┼┐ └┼┤ ├┼┬┐ ├┤ └┼┼┐ └┴┼┤ ┌┬┬┬┐ ⎥ ⎣ └┘, └┴┘, └┘, └┴┴┘, └┘, └┴┘, └┘, └┴┴┴┘ ⎦ - sage: Partitions.options._reset() # optional - sage.combinat + sage: Partitions.options._reset() """ from sage.typeset.unicode_art import unicode_art return unicode_art(self.to_skew_partition()) @@ -254,7 +256,7 @@ def conjugate(self) -> Composition: The ribbon shape of the conjugate of `I` is the conjugate of the ribbon shape of `I`:: - sage: all( I.conjugate().to_skew_partition() # optional - sage.combinat + sage: all( I.conjugate().to_skew_partition() # needs sage.combinat ....: == I.to_skew_partition().conjugate() ....: for I in Compositions(4) ) True @@ -1178,11 +1180,11 @@ def to_partition(self): EXAMPLES:: - sage: Composition([2,1,3]).to_partition() # optional - sage.combinat + sage: Composition([2,1,3]).to_partition() # needs sage.combinat [3, 2, 1] - sage: Composition([4,2,2]).to_partition() # optional - sage.combinat + sage: Composition([4,2,2]).to_partition() # needs sage.combinat [4, 2, 2] - sage: Composition([]).to_partition() # optional - sage.combinat + sage: Composition([]).to_partition() # needs sage.combinat [] """ from sage.combinat.partition import Partition @@ -1202,15 +1204,16 @@ def to_skew_partition(self, overlap=1): EXAMPLES:: - sage: Composition([3,4,1]).to_skew_partition() # optional - sage.combinat + sage: # needs sage.combinat + sage: Composition([3,4,1]).to_skew_partition() [6, 6, 3] / [5, 2] - sage: Composition([3,4,1]).to_skew_partition(overlap=0) # optional - sage.combinat + sage: Composition([3,4,1]).to_skew_partition(overlap=0) [8, 7, 3] / [7, 3] - sage: Composition([]).to_skew_partition() # optional - sage.combinat + sage: Composition([]).to_skew_partition() [] / [] - sage: Composition([1,2]).to_skew_partition() # optional - sage.combinat + sage: Composition([1,2]).to_skew_partition() [2, 1] / [] - sage: Composition([2,1]).to_skew_partition() # optional - sage.combinat + sage: Composition([2,1]).to_skew_partition() [2, 2] / [1] """ from sage.combinat.skew_partition import SkewPartition @@ -1264,9 +1267,9 @@ def shuffle_product(self, other, overlap=False): sage: alph = Composition([2,2]) sage: beta = Composition([1,1,3]) - sage: S = alph.shuffle_product(beta); S # optional - sage.combinat + sage: S = alph.shuffle_product(beta); S # needs sage.combinat Shuffle product of [2, 2] and [1, 1, 3] - sage: S.list() # optional - sage.combinat + sage: S.list() # needs sage.combinat [[2, 2, 1, 1, 3], [2, 1, 2, 1, 3], [2, 1, 1, 2, 3], [2, 1, 1, 3, 2], [1, 2, 2, 1, 3], [1, 2, 1, 2, 3], [1, 2, 1, 3, 2], [1, 1, 2, 2, 3], [1, 1, 2, 3, 2], [1, 1, 3, 2, 2]] @@ -1275,9 +1278,9 @@ def shuffle_product(self, other, overlap=False): sage: alph = Composition([2,2]) sage: beta = Composition([1,1,3]) - sage: O = alph.shuffle_product(beta, overlap=True); O # optional - sage.combinat + sage: O = alph.shuffle_product(beta, overlap=True); O # needs sage.combinat Overlapping shuffle product of [2, 2] and [1, 1, 3] - sage: O.list() # optional - sage.combinat + sage: O.list() # needs sage.combinat [[2, 2, 1, 1, 3], [2, 1, 2, 1, 3], [2, 1, 1, 2, 3], [2, 1, 1, 3, 2], [1, 2, 2, 1, 3], [1, 2, 1, 2, 3], [1, 2, 1, 3, 2], [1, 1, 2, 2, 3], [1, 1, 2, 3, 2], [1, 1, 3, 2, 2], @@ -1290,20 +1293,21 @@ def shuffle_product(self, other, overlap=False): composition more than once since a composition can be a shuffle of two compositions in several ways. For example:: + sage: # needs sage.combinat sage: w1 = Composition([1]) - sage: S = w1.shuffle_product(w1); S # optional - sage.combinat + sage: S = w1.shuffle_product(w1); S Shuffle product of [1] and [1] - sage: S.list() # optional - sage.combinat + sage: S.list() [[1, 1], [1, 1]] - sage: O = w1.shuffle_product(w1, overlap=True); O # optional - sage.combinat + sage: O = w1.shuffle_product(w1, overlap=True); O Overlapping shuffle product of [1] and [1] - sage: O.list() # optional - sage.combinat + sage: O.list() [[1, 1], [1, 1], [2]] TESTS:: sage: empty = Composition([]) - sage: empty.shuffle_product(empty).list() # optional - sage.combinat + sage: empty.shuffle_product(empty).list() # needs sage.combinat [[]] """ if overlap: @@ -1400,10 +1404,10 @@ def specht_module(self, base_ring=None): EXAMPLES:: - sage: SM = Composition([1,2,2]).specht_module(QQ); SM # optional - sage.combinat sage.modules + sage: SM = Composition([1,2,2]).specht_module(QQ); SM # needs sage.combinat sage.modules Specht module of [(0, 0), (1, 0), (1, 1), (2, 0), (2, 1)] over Rational Field - sage: s = SymmetricFunctions(QQ).s() # optional - sage.combinat sage.modules - sage: s(SM.frobenius_image()) # optional - sage.combinat sage.modules + sage: s = SymmetricFunctions(QQ).s() # needs sage.combinat sage.modules + sage: s(SM.frobenius_image()) # needs sage.combinat sage.modules s[2, 2, 1] """ from sage.combinat.specht_module import SpechtModule @@ -1428,9 +1432,9 @@ def specht_module_dimension(self, base_ring=None): EXAMPLES:: - sage: Composition([1,2,2]).specht_module_dimension() # optional - sage.combinat sage.modules + sage: Composition([1,2,2]).specht_module_dimension() # needs sage.combinat sage.modules 5 - sage: Composition([1,2,2]).specht_module_dimension(GF(2)) # optional - sage.combinat sage.modules sage.rings.finite_rings + sage: Composition([1,2,2]).specht_module_dimension(GF(2)) # needs sage.combinat sage.modules sage.rings.finite_rings 5 """ from sage.combinat.specht_module import specht_module_rank diff --git a/src/sage/combinat/core.py b/src/sage/combinat/core.py index 88461d33986..41265d793db 100644 --- a/src/sage/combinat/core.py +++ b/src/sage/combinat/core.py @@ -256,7 +256,7 @@ def length(self): sage: c = Core([4,2],3); c.length() 4 - sage: c.to_grassmannian().length() + sage: c.to_grassmannian().length() # needs sage.modules 4 sage: Core([9,5,3,2,1,1], 5).length() @@ -275,17 +275,17 @@ def to_grassmannian(self): EXAMPLES:: sage: c = Core([3,1,1],3) - sage: w = c.to_grassmannian(); w + sage: w = c.to_grassmannian(); w # needs sage.modules [-1 1 1] [-2 2 1] [-2 1 2] sage: c.parent() 3-Cores of length 4 - sage: w.parent() + sage: w.parent() # needs sage.modules Weyl Group of type ['A', 2, 1] (as a matrix group acting on the root space) sage: c = Core([],3) - sage: c.to_grassmannian() + sage: c.to_grassmannian() # needs sage.modules [1 0 0] [0 1 0] [0 0 1] @@ -304,23 +304,25 @@ def affine_symmetric_group_simple_action(self, i): EXAMPLES:: sage: c = Core([4,2],3) - sage: c.affine_symmetric_group_simple_action(0) + sage: c.affine_symmetric_group_simple_action(0) # needs sage.modules [3, 1] - sage: c.affine_symmetric_group_simple_action(1) + sage: c.affine_symmetric_group_simple_action(1) # needs sage.modules [5, 3, 1] - sage: c.affine_symmetric_group_simple_action(2) + sage: c.affine_symmetric_group_simple_action(2) # needs sage.modules [4, 2] This action corresponds to the left action by the `i`-th simple reflection in the affine symmetric group:: sage: c = Core([4,2],3) - sage: W = c.to_grassmannian().parent() + sage: W = c.to_grassmannian().parent() # needs sage.modules sage: i = 0 - sage: c.affine_symmetric_group_simple_action(i).to_grassmannian() == W.simple_reflection(i)*c.to_grassmannian() + sage: (c.affine_symmetric_group_simple_action(i).to_grassmannian() # needs sage.modules + ....: == W.simple_reflection(i)*c.to_grassmannian()) True sage: i = 1 - sage: c.affine_symmetric_group_simple_action(i).to_grassmannian() == W.simple_reflection(i)*c.to_grassmannian() + sage: (c.affine_symmetric_group_simple_action(i).to_grassmannian() # needs sage.modules + ....: == W.simple_reflection(i)*c.to_grassmannian()) True """ mu = self.to_partition() @@ -431,13 +433,13 @@ def weak_le(self, other): sage: c = Core([4,2],3) sage: x = Core([5,3,1],3) - sage: c.weak_le(x) + sage: c.weak_le(x) # needs sage.modules True - sage: c.weak_le([5,3,1]) + sage: c.weak_le([5,3,1]) # needs sage.modules True sage: x = Core([4,2,2,1,1],3) - sage: c.weak_le(x) + sage: c.weak_le(x) # needs sage.modules False sage: x = Core([5,3,1],6) @@ -462,11 +464,11 @@ def weak_covers(self): EXAMPLES:: sage: c = Core([1],3) - sage: c.weak_covers() + sage: c.weak_covers() # needs sage.modules [[1, 1], [2]] sage: c = Core([4,2],3) - sage: c.weak_covers() + sage: c.weak_covers() # needs sage.modules [[5, 3, 1]] """ w = self.to_grassmannian() diff --git a/src/sage/combinat/crystals/crystals.py b/src/sage/combinat/crystals/crystals.py index 5c345fe61d3..fb8f150e479 100644 --- a/src/sage/combinat/crystals/crystals.py +++ b/src/sage/combinat/crystals/crystals.py @@ -104,7 +104,7 @@ One can get (currently) crude plotting via:: - sage: Tab.plot() # optional - sage.plot + sage: Tab.plot() # needs sage.plot Graphics object consisting of 52 graphics primitives If dot2tex is installed, one can obtain nice latex pictures via:: diff --git a/src/sage/combinat/crystals/letters.pyx b/src/sage/combinat/crystals/letters.pyx index cf8d25587d8..368dce3a9fd 100644 --- a/src/sage/combinat/crystals/letters.pyx +++ b/src/sage/combinat/crystals/letters.pyx @@ -1495,7 +1495,7 @@ cdef class Crystal_of_letters_type_E6_element(LetterTuple): sage: all(b.e(i).f(i) == b for i in C.index_set() for b in C if b.e(i) is not None) True sage: G = C.digraph() - sage: G.show(edge_labels=true, figsize=12, vertex_size=1) # optional - sage.plot + sage: G.show(edge_labels=true, figsize=12, vertex_size=1) # needs sage.plot """ def _repr_(self): @@ -1752,7 +1752,7 @@ cdef class Crystal_of_letters_type_E6_element_dual(LetterTuple): sage: all(b.e(i).f(i) == b for i in C.index_set() for b in C if b.e(i) is not None) True sage: G = C.digraph() - sage: G.show(edge_labels=true, figsize=12, vertex_size=1) # optional - sage.plot + sage: G.show(edge_labels=true, figsize=12, vertex_size=1) # needs sage.plot """ def _repr_(self): @@ -1912,7 +1912,7 @@ cdef class Crystal_of_letters_type_E7_element(LetterTuple): sage: all(b.e(i).f(i) == b for i in C.index_set() for b in C if b.e(i) is not None) True sage: G = C.digraph() - sage: G.show(edge_labels=true, figsize=12, vertex_size=1) # optional - sage.plot + sage: G.show(edge_labels=true, figsize=12, vertex_size=1) # needs sage.plot """ def weight(self): diff --git a/src/sage/combinat/crystals/mv_polytopes.py b/src/sage/combinat/crystals/mv_polytopes.py index 67967f88bd0..341ad417443 100644 --- a/src/sage/combinat/crystals/mv_polytopes.py +++ b/src/sage/combinat/crystals/mv_polytopes.py @@ -85,7 +85,7 @@ def _latex_(self): sage: MV = crystals.infinity.MVPolytopes(['A',2]) sage: u = MV.highest_weight_vector() sage: b = u.f_string([1,2,2,1]) - sage: latex(b) # optional - sage.symbolic + sage: latex(b) # needs sage.symbolic \begin{tikzpicture} \draw (0, 0) -- (3/2, -989/1142) -- (3/2, -2967/1142) -- (0, -1978/571); \draw (0, 0) -- (-3/2, -989/1142) -- (-3/2, -2967/1142) -- (0, -1978/571); @@ -218,7 +218,7 @@ def plot(self, P=None, **options): sage: MV = crystals.infinity.MVPolytopes(['C', 2]) sage: b = MV.highest_weight_vector().f_string([1,2,1,2,2,2,1,1,1,1,2,1]) - sage: b.plot() # optional - sage.plot + sage: b.plot() # needs sage.plot Graphics object consisting of 12 graphics primitives Here is the above example placed inside the ambient space diff --git a/src/sage/combinat/degree_sequences.pyx b/src/sage/combinat/degree_sequences.pyx index 2052677a4a4..fa155acdd15 100644 --- a/src/sage/combinat/degree_sequences.pyx +++ b/src/sage/combinat/degree_sequences.pyx @@ -40,8 +40,8 @@ With the object ``DegreeSequences(n)``, one can: For instance:: sage: ds = [3, 3, 2, 2, 2, 2, 2, 1, 1, 0] - sage: g = graphs.DegreeSequence(ds) - sage: g.degree_sequence() + sage: g = graphs.DegreeSequence(ds) # needs networkx sage.graphs + sage: g.degree_sequence() # needs networkx sage.graphs [3, 3, 2, 2, 2, 2, 2, 1, 1, 0] Definitions @@ -236,16 +236,16 @@ The sequences produced by random graphs *are* degree sequences:: sage: n = 30 sage: DS = DegreeSequences(30) - sage: for i in range(10): + sage: for i in range(10): # needs networkx sage.graphs ....: g = graphs.RandomGNP(n,.2) ....: if not g.degree_sequence() in DS: ....: print("Something is very wrong !") Checking that we indeed enumerate *all* the degree sequences for `n=5`:: - sage: ds1 = Set([tuple(g.degree_sequence()) for g in graphs(5)]) + sage: ds1 = Set([tuple(g.degree_sequence()) for g in graphs(5)]) # needs sage.graphs sage: ds2 = Set(map(tuple,list(DegreeSequences(5)))) - sage: ds1 == ds2 + sage: ds1 == ds2 # needs sage.graphs True Checking the consistency of enumeration and test:: diff --git a/src/sage/combinat/designs/database.py b/src/sage/combinat/designs/database.py index 5cf09904130..98b8f0e598e 100644 --- a/src/sage/combinat/designs/database.py +++ b/src/sage/combinat/designs/database.py @@ -2127,7 +2127,7 @@ def QDM_21_5_1_1_1(): [0,14,7,0,None]] for R in zip(*M): - a,b,c,d,e = [G(x) if x is not None else None for x in R] + a,b,c,d,e = (G(x) if x is not None else None for x in R) Mb.append([a,b,c,d,e]) Mb.append([16*c, @@ -2265,7 +2265,7 @@ def QDM_33_6_1_1_1(): times4 = lambda x : None if x is None else 4*x for R in zip(*M): - a,b,c,d,e,f = [None if x is None else G(x) for x in R] + a,b,c,d,e,f = (None if x is None else G(x) for x in R) for i in range(5): Mb.append([a,b,c,d,e,f]) a,b,c,d,e,f = map(times4,[e,a,b,c,d,f]) @@ -3467,7 +3467,7 @@ def DM_39_6_1(): for i in range(3): Mb.append([ a, b, c, d, e, f]) Mb.append([-a,-b,-c,-d,-e,-f]) - a,b,c,d,e,f = [16*x for x in [c,a,b,f,d,e]] + a,b,c,d,e,f = (16*x for x in [c,a,b,f,d,e]) return G,Mb diff --git a/src/sage/combinat/designs/designs_pyx.pyx b/src/sage/combinat/designs/designs_pyx.pyx index 027cc00fbb0..d1800d4382e 100644 --- a/src/sage/combinat/designs/designs_pyx.pyx +++ b/src/sage/combinat/designs/designs_pyx.pyx @@ -804,7 +804,7 @@ def is_quasi_difference_matrix(M,G,int k,int lmbda,int mu,int u,verbose=False): Column 1 contains 2 empty entries instead of the expected lambda.u=1.1=1 False """ - from .difference_family import group_law + from sage.combinat.designs.difference_family import group_law assert k>=2 assert lmbda >=1 diff --git a/src/sage/combinat/designs/evenly_distributed_sets.pyx b/src/sage/combinat/designs/evenly_distributed_sets.pyx index 36d48d50b30..db567154ab4 100644 --- a/src/sage/combinat/designs/evenly_distributed_sets.pyx +++ b/src/sage/combinat/designs/evenly_distributed_sets.pyx @@ -310,7 +310,7 @@ cdef class EvenlyDistributedSetsBacktracker: xe = self.K.multiplicative_generator() ** (self.e) df = [[xe**j*b for b in B] for j in range((self.q-1)/(2*self.e))] if check: - from .difference_family import is_difference_family + from sage.combinat.designs.difference_family import is_difference_family if not is_difference_family(self.K, df, self.q, self.k, 1): raise RuntimeError("a wrong evenly distributed set was " "produced by the Sage library for the parameters:\n" diff --git a/src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx b/src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx index 6b6bd11dfb1..518c7199a77 100644 --- a/src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx +++ b/src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx @@ -47,7 +47,7 @@ Functions """ from sage.misc.cachefunc import cached_function -from .orthogonal_arrays import orthogonal_array +from sage.combinat.designs.orthogonal_arrays import orthogonal_array from sage.rings.integer cimport smallInteger from sage.arith.misc import prime_powers @@ -153,7 +153,7 @@ cpdef find_product_decomposition(int k,int n) noexcept: # faster to use that rather than calling the divisors function continue if is_available(k, n1) and is_available(k, n2): - from .orthogonal_arrays import wilson_construction + from sage.combinat.designs.orthogonal_arrays import wilson_construction return wilson_construction, (None,k,n1,n2,(),False) return False @@ -203,7 +203,7 @@ cpdef find_wilson_decomposition_with_one_truncated_group(int k,int n) noexcept: is_available(k ,m+1) and is_available(k+1,r ) and is_available(k ,u )): - from .orthogonal_arrays import wilson_construction + from sage.combinat.designs.orthogonal_arrays import wilson_construction return wilson_construction, (None,k,r,m,(u,),False) return False @@ -266,7 +266,7 @@ cpdef find_wilson_decomposition_with_two_truncated_groups(int k,int n) noexcept: r2 = r1_p_r2-r1 if is_available(k,r2): assert n == r*m+r1+r2 - from .orthogonal_arrays import wilson_construction + from sage.combinat.designs.orthogonal_arrays import wilson_construction return wilson_construction, (None,k,r,m,(r1,r2),False) return False @@ -306,7 +306,7 @@ cpdef find_construction_3_3(int k,int n) noexcept: if (is_available(k+i, nn ) and is_available(k , mm+i)): - from .orthogonal_arrays_build_recursive import construction_3_3 + from sage.combinat.designs.orthogonal_arrays_build_recursive import construction_3_3 return construction_3_3, (k,nn,mm,i) cpdef find_construction_3_4(int k,int n) noexcept: @@ -349,7 +349,7 @@ cpdef find_construction_3_4(int k,int n) noexcept: if (is_available(k+r+1,nn) and is_available(k , s) and (is_available(k,mm+r) or is_available(k,mm+r+1))): - from .orthogonal_arrays_build_recursive import construction_3_4 + from sage.combinat.designs.orthogonal_arrays_build_recursive import construction_3_4 return construction_3_4, (k,nn,mm,r,s) cpdef find_construction_3_5(int k,int n) noexcept: @@ -399,7 +399,7 @@ cpdef find_construction_3_5(int k,int n) noexcept: (r==0 or is_available(k,r)) and (s==0 or is_available(k,s)) and (t==0 or is_available(k,t))): - from .orthogonal_arrays_build_recursive import construction_3_5 + from sage.combinat.designs.orthogonal_arrays_build_recursive import construction_3_5 return construction_3_5, (k,nn,mm,r,s,t) cpdef find_construction_3_6(int k,int n) noexcept: @@ -440,7 +440,7 @@ cpdef find_construction_3_6(int k,int n) noexcept: if (is_available(k+i,nn) and smallInteger(nn).is_prime_power()): - from .orthogonal_arrays_build_recursive import construction_3_6 + from sage.combinat.designs.orthogonal_arrays_build_recursive import construction_3_6 return construction_3_6, (k,nn,mm,i) cpdef find_q_x(int k,int n) noexcept: @@ -492,7 +492,7 @@ cpdef find_q_x(int k,int n) noexcept: # is_available(k+1,q) and is_available(k, x+2 ) and smallInteger(q).is_prime_power()): - from .orthogonal_arrays_build_recursive import construction_q_x + from sage.combinat.designs.orthogonal_arrays_build_recursive import construction_q_x return construction_q_x, (k,q,x) return False @@ -546,7 +546,7 @@ cpdef find_thwart_lemma_3_5(int k,int N) noexcept: sage: for k,n in kn: # not tested -- too long ....: assert designs.orthogonal_array(k,n,existence=True) is True """ - from .orthogonal_arrays_build_recursive import thwart_lemma_3_5 + from sage.combinat.designs.orthogonal_arrays_build_recursive import thwart_lemma_3_5 cdef int n,m,a,b,c,d,NN,na,nb,nc for n in prime_powers(k+2,N-2): # There must exist a OA(k+3,n) thus n>=k+2 @@ -661,7 +661,7 @@ cpdef find_thwart_lemma_4_1(int k,int n) noexcept: not is_available(k,mm+4)): continue - from .orthogonal_arrays_build_recursive import thwart_lemma_4_1 + from sage.combinat.designs.orthogonal_arrays_build_recursive import thwart_lemma_4_1 return thwart_lemma_4_1,(k,nn,mm) return False @@ -706,7 +706,7 @@ cpdef find_three_factor_product(int k,int n) noexcept: not is_available(k,n2) or not is_available(k,n3)): continue - from .orthogonal_arrays_build_recursive import three_factor_product + from sage.combinat.designs.orthogonal_arrays_build_recursive import three_factor_product return three_factor_product,(k-1,n1,n2,n3) return False @@ -731,7 +731,7 @@ cpdef find_brouwer_separable_design(int k,int n) noexcept: sage: find_brouwer_separable_design(5,14) False """ - from .orthogonal_arrays_build_recursive import brouwer_separable_design + from sage.combinat.designs.orthogonal_arrays_build_recursive import brouwer_separable_design cdef int q,x,baer_subplane_size, max_t, min_t, t,e1,e2,e3,e4 for q in prime_powers(2,n): @@ -945,13 +945,13 @@ cpdef find_brouwer_van_rees_with_one_truncated_column(int k,int n) noexcept: values = int_as_sum(remainder, available_multipliers, r) if values is not None: - from .orthogonal_arrays import wilson_construction + from sage.combinat.designs.orthogonal_arrays import wilson_construction return (wilson_construction, (None,k,r,m,[[(x,1) for x in values]])) return False -from .designs_pyx cimport _OA_cache, _OA_cache_size +from sage.combinat.designs.designs_pyx cimport _OA_cache, _OA_cache_size cdef int is_available(int k,int n) except -1: r""" Return whether Sage can build an OA(k,n) diff --git a/src/sage/combinat/diagram_algebras.py b/src/sage/combinat/diagram_algebras.py index 11d96acced8..2838d1e38df 100644 --- a/src/sage/combinat/diagram_algebras.py +++ b/src/sage/combinat/diagram_algebras.py @@ -2054,9 +2054,9 @@ def order(self): EXAMPLES:: - sage: q = var('q') # optional - sage.symbolic - sage: PA = PartitionAlgebra(2, q) # optional - sage.symbolic - sage: PA.order() # optional - sage.symbolic + sage: q = var('q') # needs sage.symbolic + sage: PA = PartitionAlgebra(2, q) # needs sage.symbolic + sage: PA.order() # needs sage.symbolic 2 """ return self._k @@ -2413,24 +2413,26 @@ class PartitionAlgebra(DiagramBasis, UnitDiagramMixin): :: - sage: q = var('q') # optional - sage.symbolic - sage: PA = PartitionAlgebra(2, q); PA # optional - sage.symbolic + sage: # needs sage.symbolic + sage: q = var('q') + sage: PA = PartitionAlgebra(2, q); PA Partition Algebra of rank 2 with parameter q over Symbolic Ring - sage: PA([[1,2],[-2,-1]])^2 == q*PA([[1,2],[-2,-1]]) # optional - sage.symbolic + sage: PA([[1,2],[-2,-1]])^2 == q*PA([[1,2],[-2,-1]]) True - sage: ((PA([[2, -2], [1, -1]]) - 2*PA([[-2, -1], [1, 2]]))^2 # optional - sage.symbolic + sage: ((PA([[2, -2], [1, -1]]) - 2*PA([[-2, -1], [1, 2]]))^2 ....: == (4*q-4)*PA([[1, 2], [-2, -1]]) + PA([[2, -2], [1, -1]])) True The identity element of the partition algebra is the set partition `\{\{1,-1\}, \{2,-2\}, \ldots, \{k,-k\}\}`:: - sage: P = PA.basis().list() # optional - sage.symbolic - sage: PA.one() # optional - sage.symbolic + sage: # needs sage.symbolic + sage: P = PA.basis().list() + sage: PA.one() P{{-2, 2}, {-1, 1}} - sage: PA.one() * P[7] == P[7] # optional - sage.symbolic + sage: PA.one() * P[7] == P[7] True - sage: P[7] * PA.one() == P[7] # optional - sage.symbolic + sage: P[7] * PA.one() == P[7] True We now give some further examples of the use of the other arguments. @@ -2455,14 +2457,15 @@ class PartitionAlgebra(DiagramBasis, UnitDiagramMixin): of the partition algebra (e.g., ``BrauerAlgebra`` and ``TemperleyLiebAlgebra``) can also be coerced into the partition algebra:: - sage: S = SymmetricGroupAlgebra(SR, 2) # optional - sage.symbolic - sage: B = BrauerAlgebra(2, x, SR) # optional - sage.symbolic - sage: A = PartitionAlgebra(2, x, SR) # optional - sage.symbolic - sage: S([2,1]) * A([[1,-1],[2,-2]]) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: S = SymmetricGroupAlgebra(SR, 2) + sage: B = BrauerAlgebra(2, x, SR) + sage: A = PartitionAlgebra(2, x, SR) + sage: S([2,1]) * A([[1,-1],[2,-2]]) P{{-2, 1}, {-1, 2}} - sage: B([[-1,-2],[2,1]]) * A([[1],[-1],[2,-2]]) # optional - sage.symbolic + sage: B([[-1,-2],[2,1]]) * A([[1],[-1],[2,-2]]) P{{-2}, {-1}, {1, 2}} - sage: A([[1],[-1],[2,-2]]) * B([[-1,-2],[2,1]]) # optional - sage.symbolic + sage: A([[1],[-1],[2,-2]]) * B([[-1,-2],[2,1]]) P{{-2, -1}, {1}, {2}} The same is true if the elements come from a subalgebra of a partition @@ -2492,22 +2495,20 @@ class PartitionAlgebra(DiagramBasis, UnitDiagramMixin): Shorthands for working with basis elements are as follows:: + sage: # needs sage.symbolic sage: S = SymmetricGroupAlgebra(ZZ, 3) - sage: A = PartitionAlgebra(3, x, SR) # optional - sage.symbolic - - sage: A([[1,3],[-1],[-3]]) # pair up the omitted nodes as `{-i, i}`, if possible # optional - sage.symbolic + sage: A = PartitionAlgebra(3, x, SR) + sage: A([[1,3],[-1],[-3]]) # pair up the omitted nodes as `{-i, i}`, if possible P{{-3}, {-2, 2}, {-1}, {1, 3}} - sage: A([[1,3],[-1],[-3]]) == A[[1,3],[-1],[-3]] # optional - sage.symbolic + sage: A([[1,3],[-1],[-3]]) == A[[1,3],[-1],[-3]] True - - sage: A([[1,2]]) # optional - sage.symbolic + sage: A([[1,2]]) P{{-3, 3}, {-2}, {-1}, {1, 2}} - sage: A([[1,2]]) == A[[1,2]] # optional - sage.symbolic + sage: A([[1,2]]) == A[[1,2]] True - - sage: A([2,3,1]) # permutations in one-line notation are imported as well # optional - sage.symbolic + sage: A([2,3,1]) # permutations in one-line notation are imported as well P{{-3, 2}, {-2, 1}, {-1, 3}} - sage: A([2,3,1]) == A(S([2,3,1])) # optional - sage.symbolic + sage: A([2,3,1]) == A(S([2,3,1])) True """ @staticmethod @@ -3595,9 +3596,9 @@ def ambient(self): EXAMPLES:: - sage: x = var('x') # optional - sage.symbolic - sage: BA = BrauerAlgebra(2, x) # optional - sage.symbolic - sage: BA.ambient() # optional - sage.symbolic + sage: x = var('x') # needs sage.symbolic + sage: BA = BrauerAlgebra(2, x) # needs sage.symbolic + sage: BA.ambient() # needs sage.symbolic Partition Algebra of rank 2 with parameter x over Symbolic Ring """ return self.lift.codomain() @@ -3836,11 +3837,12 @@ def jucys_murphy(self, j): EXAMPLES:: - sage: z = var('z') # optional - sage.symbolic - sage: B = BrauerAlgebra(3,z) # optional - sage.symbolic - sage: B.jucys_murphy(1) # optional - sage.symbolic + sage: # needs sage.symbolic + sage: z = var('z') + sage: B = BrauerAlgebra(3,z) + sage: B.jucys_murphy(1) (1/2*z-1/2)*B{{-3, 3}, {-2, 2}, {-1, 1}} - sage: B.jucys_murphy(3) # optional - sage.symbolic + sage: B.jucys_murphy(3) -B{{-3, -2}, {-1, 1}, {2, 3}} - B{{-3, -1}, {-2, 2}, {1, 3}} + B{{-3, 1}, {-2, 2}, {-1, 3}} + B{{-3, 2}, {-2, 3}, {-1, 1}} + (1/2*z-1/2)*B{{-3, 3}, {-2, 2}, {-1, 1}} diff --git a/src/sage/combinat/dlx.py b/src/sage/combinat/dlx.py index 25990fe55fe..58bb1bc624f 100644 --- a/src/sage/combinat/dlx.py +++ b/src/sage/combinat/dlx.py @@ -474,11 +474,12 @@ def AllExactCovers(M): EXAMPLES:: - sage: M = Matrix([[1,1,0],[1,0,1],[0,1,1]]) # no exact covers # optional - sage.modules - sage: for cover in AllExactCovers(M): # optional - sage.modules + sage: # needs sage.modules + sage: M = Matrix([[1,1,0],[1,0,1],[0,1,1]]) # no exact covers + sage: for cover in AllExactCovers(M): ....: print(cover) - sage: M = Matrix([[1,1,0],[1,0,1],[0,0,1],[0,1,0]]) # two exact covers # optional - sage.modules - sage: for cover in AllExactCovers(M): # optional - sage.modules + sage: M = Matrix([[1,1,0],[1,0,1],[0,0,1],[0,1,0]]) # two exact covers + sage: for cover in AllExactCovers(M): ....: print(cover) [(1, 1, 0), (0, 0, 1)] [(1, 0, 1), (0, 1, 0)] @@ -503,11 +504,11 @@ def OneExactCover(M): EXAMPLES:: - sage: M = Matrix([[1,1,0],[1,0,1],[0,1,1]]) # no exact covers # optional - sage.modules - sage: OneExactCover(M) # optional - sage.modules + sage: M = Matrix([[1,1,0],[1,0,1],[0,1,1]]) # no exact covers # needs sage.modules + sage: OneExactCover(M) # needs sage.modules - sage: M = Matrix([[1,1,0],[1,0,1],[0,0,1],[0,1,0]]) # two exact covers # optional - sage.modules - sage: OneExactCover(M) # optional - sage.modules + sage: M = Matrix([[1,1,0],[1,0,1],[0,0,1],[0,1,0]]) # two exact covers # needs sage.modules + sage: OneExactCover(M) # needs sage.modules [(1, 1, 0), (0, 0, 1)] """ for s in AllExactCovers(M): diff --git a/src/sage/combinat/dyck_word.py b/src/sage/combinat/dyck_word.py index 36573003830..41a3c199599 100644 --- a/src/sage/combinat/dyck_word.py +++ b/src/sage/combinat/dyck_word.py @@ -957,7 +957,7 @@ def plot(self, **kwds): EXAMPLES:: sage: w = DyckWords(100).random_element() - sage: w.plot() # optional - sage.plot + sage: w.plot() # needs sage.plot Graphics object consisting of 1 graphics primitive """ from sage.plot.plot import list_plot @@ -1694,6 +1694,7 @@ def to_binary_tree(self, usemap="1L0R"): EXAMPLES:: + sage: # needs sage.graphs sage: dw = DyckWord([1,0]) sage: dw.to_binary_tree() [., .] @@ -1754,11 +1755,11 @@ def to_binary_tree_tamari(self): EXAMPLES:: - sage: DyckWord([1,0]).to_binary_tree_tamari() + sage: DyckWord([1,0]).to_binary_tree_tamari() # needs sage.graphs [., .] - sage: DyckWord([1,0,1,1,0,0]).to_binary_tree_tamari() + sage: DyckWord([1,0,1,1,0,0]).to_binary_tree_tamari() # needs sage.graphs [[., .], [., .]] - sage: DyckWord([1,0,1,0,1,0]).to_binary_tree_tamari() + sage: DyckWord([1,0,1,0,1,0]).to_binary_tree_tamari() # needs sage.graphs [[[., .], .], .] """ # return self.to_binary_tree("L1R0") # slower and recursive @@ -1787,6 +1788,7 @@ def tamari_interval(self, other): EXAMPLES:: + sage: # needs sage.graphs sage: dw = DyckWord([1, 1, 0, 1, 0, 0, 1, 0]) sage: ip = dw.tamari_interval(DyckWord([1, 1, 1, 0, 0, 1, 0, 0])); ip The Tamari interval of size 4 induced by relations [(2, 4), (3, 4), (3, 1), (2, 1)] @@ -2065,9 +2067,10 @@ def characteristic_symmetric_function(self, q=None, sage: R = QQ['q','t'].fraction_field() sage: (q,t) = R.gens() - sage: f = sum(t**D.area()*D.characteristic_symmetric_function() for D in DyckWords(3)); f + sage: f = sum(t**D.area() * D.characteristic_symmetric_function() # needs sage.modules + ....: for D in DyckWords(3)); f (q^3+q^2*t+q*t^2+t^3+q*t)*s[1, 1, 1] + (q^2+q*t+t^2+q+t)*s[2, 1] + s[3] - sage: f.nabla(power=-1) + sage: f.nabla(power=-1) # needs sage.modules s[1, 1, 1] """ from sage.combinat.ncsf_qsym.qsym import QuasiSymmetricFunctions @@ -2482,6 +2485,7 @@ def to_ordered_tree(self): EXAMPLES:: + sage: # needs sage.graphs sage: D = DyckWord([1,1,0,0]) sage: D.to_ordered_tree() [[[]]] @@ -2498,7 +2502,7 @@ def to_ordered_tree(self): TESTS:: sage: D = DyckWord([1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0]) - sage: D == D.to_ordered_tree().to_dyck_word() + sage: D == D.to_ordered_tree().to_dyck_word() # needs sage.graphs True """ from sage.combinat.ordered_tree import OrderedTree @@ -2587,12 +2591,11 @@ def to_triangulation_as_graph(self): EXAMPLES:: - sage: g = DyckWord([1, 1, 0, 0, 1, 0]).to_triangulation_as_graph() - sage: g + sage: g = DyckWord([1, 1, 0, 0, 1, 0]).to_triangulation_as_graph(); g # needs sage.graphs Graph on 5 vertices - sage: g.edges(sort=True, labels=False) + sage: g.edges(sort=True, labels=False) # needs sage.graphs [(0, 1), (0, 4), (1, 2), (1, 3), (1, 4), (2, 3), (3, 4)] - sage: g.show() # not tested + sage: g.show() # not tested # needs sage.graphs """ n = self.number_of_open_symbols() edges = self.to_triangulation() @@ -3177,12 +3180,12 @@ def to_alternating_sign_matrix(self): EXAMPLES:: - sage: DyckWord([1,1,1,0,1,0,0,0]).to_alternating_sign_matrix() + sage: DyckWord([1,1,1,0,1,0,0,0]).to_alternating_sign_matrix() # needs sage.modules [ 0 0 1 0] [ 1 0 -1 1] [ 0 1 0 0] [ 0 0 1 0] - sage: DyckWord([1,0,1,0,1,1,0,0]).to_alternating_sign_matrix() + sage: DyckWord([1,0,1,0,1,1,0,0]).to_alternating_sign_matrix() # needs sage.modules [1 0 0 0] [0 1 0 0] [0 0 0 1] diff --git a/src/sage/combinat/e_one_star.py b/src/sage/combinat/e_one_star.py index 72cff3d147b..a7b9c50b732 100644 --- a/src/sage/combinat/e_one_star.py +++ b/src/sage/combinat/e_one_star.py @@ -160,9 +160,9 @@ sage: P = Patch([Face([0,0], 1), Face([0,0], 2)]) sage: E = E1Star(WordMorphism({1:[1,2],2:[1]})) sage: F = E1Star(WordMorphism({1:[1,1,2],2:[2,1]})) - sage: E(P,5).plot() # optional - sage.plot + sage: E(P,5).plot() # needs sage.plot Graphics object consisting of 21 graphics primitives - sage: F(P,3).plot() # optional - sage.plot + sage: F(P,3).plot() # needs sage.plot Graphics object consisting of 34 graphics primitives Everything works in any dimension (except for the plotting features @@ -491,12 +491,12 @@ def _plot(self, projmat, face_contour, opacity) -> Graphics: sage: face_contour[1] = map(vector, [(0,0,0),(0,1,0),(0,1,1),(0,0,1)]) sage: face_contour[2] = map(vector, [(0,0,0),(0,0,1),(1,0,1),(1,0,0)]) sage: face_contour[3] = map(vector, [(0,0,0),(1,0,0),(1,1,0),(0,1,0)]) - sage: G = f._plot(projmat, face_contour, 0.75) # optional - sage.plot + sage: G = f._plot(projmat, face_contour, 0.75) # needs sage.plot :: sage: f = Face((0,0), 2) - sage: f._plot(None, None, 1) # optional - sage.plot + sage: f._plot(None, None, 1) # needs sage.plot Graphics object consisting of 1 graphics primitive """ v = self.vector() @@ -1103,7 +1103,7 @@ def plot(self, projmat=None, opacity=0.75) -> Graphics: sage: from sage.combinat.e_one_star import E1Star, Face, Patch sage: P = Patch([Face((0,0,0),t) for t in [1,2,3]]) - sage: P.plot() # optional - sage.plot + sage: P.plot() # needs sage.plot Graphics object consisting of 3 graphics primitives :: @@ -1112,7 +1112,7 @@ def plot(self, projmat=None, opacity=0.75) -> Graphics: sage: E = E1Star(sigma) sage: P = Patch([Face((0,0,0),t) for t in [1,2,3]]) sage: P = E(P, 5) - sage: P.plot() # optional - sage.plot + sage: P.plot() # needs sage.plot Graphics object consisting of 57 graphics primitives Plot with a different projection matrix:: @@ -1122,7 +1122,7 @@ def plot(self, projmat=None, opacity=0.75) -> Graphics: sage: P = Patch([Face((0,0,0),t) for t in [1,2,3]]) sage: M = matrix(2, 3, [1,0,-1,0.3,1,-3]) sage: P = E(P, 3) - sage: P.plot(projmat=M) # optional - sage.plot + sage: P.plot(projmat=M) # needs sage.plot Graphics object consisting of 17 graphics primitives Plot patches made of unit segments:: @@ -1130,9 +1130,9 @@ def plot(self, projmat=None, opacity=0.75) -> Graphics: sage: P = Patch([Face([0,0], 1), Face([0,0], 2)]) sage: E = E1Star(WordMorphism({1:[1,2],2:[1]})) sage: F = E1Star(WordMorphism({1:[1,1,2],2:[2,1]})) - sage: E(P,5).plot() # optional - sage.plot + sage: E(P,5).plot() # needs sage.plot Graphics object consisting of 21 graphics primitives - sage: F(P,3).plot() # optional - sage.plot + sage: F(P,3).plot() # needs sage.plot Graphics object consisting of 34 graphics primitives """ if self.dimension() == 2: diff --git a/src/sage/combinat/enumeration_mod_permgroup.pyx b/src/sage/combinat/enumeration_mod_permgroup.pyx index 0da6b2d2638..742202d04ad 100644 --- a/src/sage/combinat/enumeration_mod_permgroup.pyx +++ b/src/sage/combinat/enumeration_mod_permgroup.pyx @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.combinat r""" Tools for enumeration modulo the action of a permutation group """ diff --git a/src/sage/combinat/finite_state_machine.py b/src/sage/combinat/finite_state_machine.py index 8bfddfaf76a..a76958e6e73 100644 --- a/src/sage/combinat/finite_state_machine.py +++ b/src/sage/combinat/finite_state_machine.py @@ -384,6 +384,7 @@ We can also let an automaton act on a :doc:`word `:: + sage: # needs sage.combinat sage: W = Words([-1, 0, 1]); W Finite and infinite words over {-1, 0, 1} sage: w = W([1, 0, 1, 0, -1]); w @@ -983,13 +984,14 @@ def full_group_by(l, key=None): EXAMPLES:: + sage: # needs sage.symbolic sage: from sage.combinat.finite_state_machine import full_group_by - sage: t = [2/x, 1/x, 2/x] # optional - sage.symbolic - sage: r = full_group_by([0, 1, 2], key=lambda i: t[i]) # optional - sage.symbolic - sage: sorted(r, key=lambda p: p[1]) # optional - sage.symbolic + sage: t = [2/x, 1/x, 2/x] + sage: r = full_group_by([0, 1, 2], key=lambda i: t[i]) + sage: sorted(r, key=lambda p: p[1]) [(2/x, [0, 2]), (1/x, [1])] sage: from itertools import groupby - sage: for k, elements in groupby(sorted([0, 1, 2], # optional - sage.symbolic + sage: for k, elements in groupby(sorted([0, 1, 2], ....: key=lambda i:t[i]), ....: key=lambda i:t[i]): ....: print("{} {}".format(k, list(elements))) @@ -3675,6 +3677,7 @@ def __call__(self, *args, **kwargs): We can also let them act on :doc:`words `:: + sage: # needs sage.combinat sage: W = Words([0, 1]); W Finite and infinite words over {0, 1} sage: binary_inverter(W([0, 1, 1, 0, 1, 1])) @@ -3682,6 +3685,7 @@ def __call__(self, *args, **kwargs): Infinite words work as well:: + sage: # needs sage.combinat sage: words.FibonacciWord() word: 0100101001001010010100100101001001010010... sage: binary_inverter(words.FibonacciWord()) @@ -3858,11 +3862,11 @@ def __call__(self, *args, **kwargs): sage: from itertools import islice sage: inverter = Transducer({'A': [('A', 0, 1), ('A', 1, 0)]}, ....: initial_states=['A'], final_states=['A']) - sage: inverter(words.FibonacciWord()) + sage: inverter(words.FibonacciWord()) # needs sage.combinat word: 1011010110110101101011011010110110101101... - sage: inverter(words.FibonacciWord(), automatic_output_type=True) + sage: inverter(words.FibonacciWord(), automatic_output_type=True) # needs sage.combinat word: 1011010110110101101011011010110110101101... - sage: tuple(islice(inverter(words.FibonacciWord(), + sage: tuple(islice(inverter(words.FibonacciWord(), # needs sage.combinat ....: automatic_output_type=False), 10r)) (1, 0, 1, 1, 0, 1, 0, 1, 1, 0) sage: type(inverter((1, 0, 1, 1, 0, 1, 0, 1, 1, 0), @@ -4122,17 +4126,18 @@ def is_Markov_chain(self, is_zero=None): If the probabilities are variables in the symbolic ring, :func:`~sage.symbolic.assumptions.assume` will do the trick:: - sage: var('p q') # optional - sage.symbolic + sage: # needs sage.symbolic + sage: var('p q') (p, q) - sage: F = Transducer([(0, 0, p, 1), (0, 0, q, 0)], # optional - sage.symbolic + sage: F = Transducer([(0, 0, p, 1), (0, 0, q, 0)], ....: on_duplicate_transition=duplicate_transition_add_input) - sage: assume(p + q == 1) # optional - sage.symbolic - sage: (p + q - 1).is_zero() # optional - sage.symbolic + sage: assume(p + q == 1) + sage: (p + q - 1).is_zero() True - sage: F.is_Markov_chain() # optional - sage.symbolic + sage: F.is_Markov_chain() True - sage: forget() # optional - sage.symbolic - sage: del(p, q) # optional - sage.symbolic + sage: forget() + sage: del(p, q) If the probabilities are variables in some polynomial ring, the parameter ``is_zero`` can be used:: @@ -4145,7 +4150,7 @@ def is_Markov_chain(self, is_zero=None): sage: F.state(0).initial_probability = p + q sage: F.is_Markov_chain() False - sage: F.is_Markov_chain(is_zero_polynomial) + sage: F.is_Markov_chain(is_zero_polynomial) # needs sage.libs.singular True """ def default_is_zero(expression): @@ -4326,9 +4331,9 @@ def default_format_transition_label(self, word): #. In the example above, ``'a'`` and ``'alpha'`` should perhaps be symbols:: - sage: var('a alpha a_1') # optional - sage.symbolic + sage: var('a alpha a_1') # needs sage.symbolic (a, alpha, a_1) - sage: print(T.default_format_transition_label([a, alpha, a_1])) # optional - sage.symbolic + sage: print(T.default_format_transition_label([a, alpha, a_1])) # needs sage.symbolic a \alpha a_{1} #. Example of an empty word:: @@ -5039,7 +5044,7 @@ def _matrix_(self, R=None): ....: 3:{'a':(0, 1), 2:(1, 1)}, ....: 4:{4:(1, 1), 3:(0, 1)}}, ....: initial_states=[0]) - sage: B._matrix_() # optional - sage.symbolic + sage: B._matrix_() # needs sage.symbolic [1 1 0 0 0] [0 0 1 1 0] [x 0 0 0 1] @@ -5081,7 +5086,7 @@ def adjacency_matrix(self, input=None, ....: 3:{'a':(0, 1), 2:(1, 1)}, ....: 4:{4:(1, 1), 3:(0, 1)}}, ....: initial_states=[0]) - sage: B.adjacency_matrix() # optional - sage.symbolic + sage: B.adjacency_matrix() # needs sage.symbolic [1 1 0 0 0] [0 0 1 1 0] [x 0 0 0 1] @@ -5090,7 +5095,7 @@ def adjacency_matrix(self, input=None, This is equivalent to:: - sage: matrix(B) # optional - sage.symbolic + sage: matrix(B) # needs sage.symbolic [1 1 0 0 0] [0 0 1 1 0] [x 0 0 0 1] @@ -5105,9 +5110,9 @@ def adjacency_matrix(self, input=None, [1 0 0 0 1] [0 1 1 0 0] [0 0 0 1 1] - sage: var('t') # optional - sage.symbolic + sage: var('t') # needs sage.symbolic t - sage: B.adjacency_matrix(1, entry=(lambda transition: # optional - sage.symbolic + sage: B.adjacency_matrix(1, entry=(lambda transition: # needs sage.symbolic ....: exp(I*transition.word_out[0]*t))) [ 0 1 0 0 0] [ 0 0 0 1 0] @@ -5120,7 +5125,7 @@ def adjacency_matrix(self, input=None, ....: (2, 1, 0)], ....: initial_states=[0], ....: final_states=[0]) - sage: a.adjacency_matrix() # optional - sage.symbolic + sage: a.adjacency_matrix() # needs sage.symbolic [0 1 0] [0 0 1] [1 1 0] @@ -6249,6 +6254,8 @@ def iter_process(self, input_tape=None, initial_state=None, sage: inverter = Transducer({'A': [('A', 0, 1), ('A', 1, 0)]}, ....: initial_states=['A'], final_states=['A']) + + sage: # needs sage.combinat sage: words.FibonacciWord() word: 0100101001001010010100100101001001010010... sage: it = inverter.iter_process( @@ -6258,19 +6265,20 @@ def iter_process(self, input_tape=None, initial_state=None, This can also be done by:: - sage: inverter.iter_process(words.FibonacciWord(), + sage: inverter.iter_process(words.FibonacciWord(), # needs sage.combinat ....: iterator_type='simple', ....: automatic_output_type=True) word: 1011010110110101101011011010110110101101... or even simpler by:: - sage: inverter(words.FibonacciWord()) + sage: inverter(words.FibonacciWord()) # needs sage.combinat word: 1011010110110101101011011010110110101101... To see what is going on, we use :meth:`iter_process` without arguments:: + sage: # needs sage.combinat sage: from itertools import islice sage: it = inverter.iter_process(words.FibonacciWord()) sage: for current in islice(it, 4r): @@ -6399,9 +6407,9 @@ def _iter_process_simple_(self, iterator): sage: inverter = Transducer({'A': [('A', 0, 1), ('A', 1, 0)]}, ....: initial_states=['A'], final_states=['A']) - sage: it = inverter.iter_process(words.FibonacciWord()[:10]) - sage: it_simple = inverter._iter_process_simple_(it) - sage: list(it_simple) + sage: it = inverter.iter_process(words.FibonacciWord()[:10]) # needs sage.combinat + sage: it_simple = inverter._iter_process_simple_(it) # needs sage.combinat + sage: list(it_simple) # needs sage.combinat [1, 0, 1, 1, 0, 1, 0, 1, 1, 0] .. SEEALSO:: @@ -9707,7 +9715,7 @@ def plot(self): TESTS:: - sage: FiniteStateMachine([('A', 'A', 0)]).plot() # optional - sage.plot + sage: FiniteStateMachine([('A', 'A', 0)]).plot() # needs sage.plot Graphics object consisting of 3 graphics primitives """ return self.graph(edge_labels='words_in_out').plot() @@ -9792,9 +9800,9 @@ def number_of_words(self, variable=None, ....: (0, 1, -1), (1, 0, 0)], ....: initial_states=[0], ....: final_states=[0, 1]) - sage: N = NAFpm.number_of_words(); N # optional - sage.symbolic + sage: N = NAFpm.number_of_words(); N # needs sage.symbolic 4/3*2^n - 1/3*(-1)^n - sage: all(len(list(NAFpm.language(s))) # optional - sage.symbolic + sage: all(len(list(NAFpm.language(s))) # needs sage.symbolic ....: - len(list(NAFpm.language(s-1))) == N.subs(n=s) ....: for s in srange(1, 6)) True @@ -9806,10 +9814,10 @@ def number_of_words(self, variable=None, sage: NAFp = Automaton([(0, 0, 0), (0, 1, 1), (1, 0, 0)], ....: initial_states=[0], ....: final_states=[0, 1]) - sage: N = NAFp.number_of_words(); N # optional - sage.symbolic + sage: N = NAFp.number_of_words(); N # needs sage.rings.number_field sage.symbolic 1.170820393249937?*1.618033988749895?^n - 0.1708203932499369?*(-0.618033988749895?)^n - sage: all(len(list(NAFp.language(s))) # optional - sage.symbolic + sage: all(len(list(NAFp.language(s))) # needs sage.rings.number_field sage.symbolic ....: - len(list(NAFp.language(s-1))) == N.subs(n=s) ....: for s in srange(1, 6)) True @@ -9819,14 +9827,15 @@ def number_of_words(self, variable=None, polynomial and then construct a number field generated by its roots. :: + sage: # needs sage.rings.number_field sage.symbolic sage: M = NAFp.adjacency_matrix(entry=lambda t: 1) - sage: M.characteristic_polynomial() # optional - sage.symbolic + sage: M.characteristic_polynomial() x^2 - x - 1 - sage: R. = NumberField(x^2-x-1, embedding=1.6) # optional - sage.symbolic - sage: N = NAFp.number_of_words(base_ring=R); N # optional - sage.symbolic + sage: R. = NumberField(x^2 - x - 1, embedding=1.6) + sage: N = NAFp.number_of_words(base_ring=R); N 1/2*(1/2*sqrt(5) + 1/2)^n*(3*sqrt(1/5) + 1) - 1/2*(-1/2*sqrt(5) + 1/2)^n*(3*sqrt(1/5) - 1) - sage: all(len(list(NAFp.language(s))) # optional - sage.symbolic + sage: all(len(list(NAFp.language(s))) ....: - len(list(NAFp.language(s-1))) == N.subs(n=s) ....: for s in srange(1, 6)) True @@ -9834,11 +9843,12 @@ def number_of_words(self, variable=None, In this special case, we might also use the constant :class:`golden_ratio `:: - sage: R. = NumberField(x^2-x-1, embedding=golden_ratio) # optional - sage.symbolic - sage: N = NAFp.number_of_words(base_ring=R); N # optional - sage.symbolic + sage: # needs sage.rings.number_field sage.symbolic + sage: R. = NumberField(x^2-x-1, embedding=golden_ratio) + sage: N = NAFp.number_of_words(base_ring=R); N 1/5*(3*golden_ratio + 1)*golden_ratio^n - 1/5*(3*golden_ratio - 4)*(-golden_ratio + 1)^n - sage: all(len(list(NAFp.language(s))) # optional - sage.symbolic + sage: all(len(list(NAFp.language(s))) ....: - len(list(NAFp.language(s-1))) == N.subs(n=s) ....: for s in srange(1, 6)) True @@ -9856,9 +9866,9 @@ def number_of_words(self, variable=None, [4 1 0] [0 4 1] [0 0 4] - sage: N = J3.number_of_words(); N # optional - sage.symbolic + sage: N = J3.number_of_words(); N # needs sage.symbolic 1/2*4^(n - 2)*(n - 1)*n + 4^(n - 1)*n + 4^n - sage: all(len(list(J3.language(s))) # optional - sage.symbolic + sage: all(len(list(J3.language(s))) # needs sage.symbolic ....: - len(list(J3.language(s-1))) == N.subs(n=s) ....: for s in range(1, 6)) True @@ -9868,14 +9878,14 @@ def number_of_words(self, variable=None, sage: A = Automaton([(j, j+1, 0) for j in range(3)], ....: initial_states=[0], ....: final_states=list(range(3))) - sage: A.number_of_words() # optional - sage.symbolic + sage: A.number_of_words() # needs sage.symbolic 1/2*0^(n - 2)*(n - 1)*n + 0^(n - 1)*n + 0^n TESTS:: sage: A = Automaton([(0, 0, 0), (0, 1, 0)], ....: initial_states=[0]) - sage: A.number_of_words() # optional - sage.symbolic + sage: A.number_of_words() # needs sage.symbolic Traceback (most recent call last): ... NotImplementedError: Finite State Machine must be deterministic. @@ -9966,12 +9976,14 @@ def asymptotic_moments(self, variable=None): ....: final_states=[0]) sage: T([0, 1, 1]) [0, -1, -1] - sage: moments = T.asymptotic_moments() # optional - sage.symbolic - sage: moments['expectation'] # optional - sage.symbolic + + sage: # needs sage.symbolic + sage: moments = T.asymptotic_moments() + sage: moments['expectation'] -1/2*n + Order(1) - sage: moments['variance'] # optional - sage.symbolic + sage: moments['variance'] 1/4*n + Order(1) - sage: moments['covariance'] # optional - sage.symbolic + sage: moments['covariance'] -1/4*n + Order(1) #. For the case of the Hamming weight of the non-adjacent-form @@ -10034,12 +10046,13 @@ def asymptotic_moments(self, variable=None): Now, we actually compute the asymptotic moments:: - sage: moments = NAFweight.asymptotic_moments() # optional - sage.symbolic - sage: moments['expectation'] # optional - sage.symbolic + sage: # needs sage.symbolic + sage: moments = NAFweight.asymptotic_moments() + sage: moments['expectation'] 1/3*n + Order(1) - sage: moments['variance'] # optional - sage.symbolic + sage: moments['variance'] 2/27*n + Order(1) - sage: moments['covariance'] # optional - sage.symbolic + sage: moments['covariance'] Order(1) #. This is Example 3.16 in [HKW2015]_, where a transducer with @@ -10050,17 +10063,18 @@ def asymptotic_moments(self, variable=None): :: - sage: var('a_1, a_2, a_3, a_4') # optional - sage.symbolic + sage: # needs sage.symbolic + sage: var('a_1, a_2, a_3, a_4') (a_1, a_2, a_3, a_4) - sage: T = Transducer([[0, 0, 0, a_1], [0, 1, 1, a_3], # optional - sage.symbolic + sage: T = Transducer([[0, 0, 0, a_1], [0, 1, 1, a_3], ....: [1, 0, 0, a_4], [1, 1, 1, a_2]], ....: initial_states=[0], final_states=[0, 1]) - sage: moments = T.asymptotic_moments() # optional - sage.symbolic + sage: moments = T.asymptotic_moments() verbose 0 (...) Non-integer output weights lead to significant performance degradation. - sage: moments['expectation'] # optional - sage.symbolic + sage: moments['expectation'] 1/4*(a_1 + a_2 + a_3 + a_4)*n + Order(1) - sage: moments['covariance'] # optional - sage.symbolic + sage: moments['covariance'] -1/4*(a_1 - a_2)*n + Order(1) Therefore, the asymptotic covariance vanishes if and only if @@ -10072,12 +10086,13 @@ def asymptotic_moments(self, variable=None): :ref:`example on Gray code `):: - sage: moments = transducers.GrayCode().asymptotic_moments() # optional - sage.symbolic - sage: moments['expectation'] # optional - sage.symbolic + sage: # needs sage.symbolic + sage: moments = transducers.GrayCode().asymptotic_moments() + sage: moments['expectation'] 1/2*n + Order(1) - sage: moments['variance'] # optional - sage.symbolic + sage: moments['variance'] 1/4*n + Order(1) - sage: moments['covariance'] # optional - sage.symbolic + sage: moments['covariance'] Order(1) #. This is the first part of Example 4.4 in [HKW2015]_, @@ -10093,12 +10108,14 @@ def asymptotic_moments(self, variable=None): Transition from () to (1,): 1|0, Transition from (1,) to (): 0|1, Transition from (1,) to (1,): 1|0] - sage: moments = block10.asymptotic_moments() # optional - sage.symbolic - sage: moments['expectation'] # optional - sage.symbolic + + sage: # needs sage.symbolic + sage: moments = block10.asymptotic_moments() + sage: moments['expectation'] 1/4*n + Order(1) - sage: moments['variance'] # optional - sage.symbolic + sage: moments['variance'] 1/16*n + Order(1) - sage: moments['covariance'] # optional - sage.symbolic + sage: moments['covariance'] Order(1) #. This is the second part of Example 4.4 in [HKW2015]_, @@ -10114,16 +10131,18 @@ def asymptotic_moments(self, variable=None): Transition from () to (1,): 1|0, Transition from (1,) to (): 0|0, Transition from (1,) to (1,): 1|1] - sage: var('N') # optional - sage.symbolic + + sage: # needs sage.symbolic + sage: var('N') N - sage: moments = block11.asymptotic_moments(N) # optional - sage.symbolic - sage: moments['expectation'] # optional - sage.symbolic + sage: moments = block11.asymptotic_moments(N) + sage: moments['expectation'] 1/4*N + Order(1) - sage: moments['variance'] # optional - sage.symbolic + sage: moments['variance'] 5/16*N + Order(1) - sage: correlation = (moments['covariance'].coefficient(N) / # optional - sage.symbolic + sage: correlation = (moments['covariance'].coefficient(N) / ....: (1/2 * sqrt(moments['variance'].coefficient(N)))) - sage: correlation # optional - sage.symbolic + sage: correlation 2/5*sqrt(5) #. This is Example 4.5 in [HKW2015]_, counting the number of @@ -10144,12 +10163,14 @@ def asymptotic_moments(self, variable=None): Transition from 1 to 0: 1|0, Transition from 2 to 2: 0|0, Transition from 2 to 0: 1|1] - sage: moments = T.asymptotic_moments() # optional - sage.symbolic - sage: moments['expectation'] # optional - sage.symbolic + + sage: # needs sage.symbolic + sage: moments = T.asymptotic_moments() + sage: moments['expectation'] Order(1) - sage: moments['variance'] # optional - sage.symbolic + sage: moments['variance'] Order(1) - sage: moments['covariance'] # optional - sage.symbolic + sage: moments['covariance'] Order(1) #. The finite state machine must have a unique final component:: @@ -10222,28 +10243,30 @@ def asymptotic_moments(self, variable=None): #. Non-integer input or output labels lead to a warning:: + sage: # needs sage.symbolic sage: T = Transducer([[0, 0, 0, 0], [0, 0, 1, -1/2]], ....: initial_states=[0], final_states=[0]) - sage: moments = T.asymptotic_moments() # optional - sage.symbolic + sage: moments = T.asymptotic_moments() verbose 0 (...) Non-integer output weights lead to significant performance degradation. - sage: moments['expectation'] # optional - sage.symbolic + sage: moments['expectation'] -1/4*n + Order(1) - sage: moments['variance'] # optional - sage.symbolic + sage: moments['variance'] 1/16*n + Order(1) - sage: moments['covariance'] # optional - sage.symbolic + sage: moments['covariance'] -1/8*n + Order(1) This warning can be silenced by :func:`~sage.misc.verbose.set_verbose`:: + sage: # needs sage.symbolic sage: from sage.misc.verbose import set_verbose sage: set_verbose(-1, "finite_state_machine.py") - sage: moments = T.asymptotic_moments() # optional - sage.symbolic - sage: moments['expectation'] # optional - sage.symbolic + sage: moments = T.asymptotic_moments() + sage: moments['expectation'] -1/4*n + Order(1) - sage: moments['variance'] # optional - sage.symbolic + sage: moments['variance'] 1/16*n + Order(1) - sage: moments['covariance'] # optional - sage.symbolic + sage: moments['covariance'] -1/8*n + Order(1) sage: set_verbose(0, "finite_state_machine.py") @@ -10258,7 +10281,7 @@ def asymptotic_moments(self, variable=None): ....: initial_states=[s], final_states=[s]) sage: T([0, 0]) [2, 1, 2, 1, 2] - sage: T.asymptotic_moments()['expectation'] # optional - sage.symbolic + sage: T.asymptotic_moments()['expectation'] # needs sage.symbolic 3*n + Order(1) The same test for non-integer output:: @@ -10267,7 +10290,7 @@ def asymptotic_moments(self, variable=None): sage: s = FSMState(0, word_out=2/3) sage: T = Transducer([(s, s, 0, 1/2)], ....: initial_states=[s], final_states=[s]) - sage: T.asymptotic_moments()['expectation'] # optional - sage.symbolic + sage: T.asymptotic_moments()['expectation'] # needs sage.symbolic verbose 0 (...) Non-integer output weights lead to significant performance degradation. 7/6*n + Order(1) @@ -10436,11 +10459,11 @@ def moments_waiting_time(self, test=bool, is_zero=None, and the variance are `\sum_{k\ge 1} k2^{-k}=2` and `\sum_{k\ge 1} (k-2)^2 2^{-k}=2`:: - sage: var('k') # optional - sage.symbolic + sage: var('k') # needs sage.symbolic k - sage: sum(k * 2^(-k), k, 1, infinity) # optional - sage.symbolic + sage: sum(k * 2^(-k), k, 1, infinity) # needs sage.symbolic 2 - sage: sum((k-2)^2 * 2^(-k), k, 1, infinity) # optional - sage.symbolic + sage: sum((k-2)^2 * 2^(-k), k, 1, infinity) # needs sage.symbolic 2 We now compute the same expectation and variance by using a @@ -10520,6 +10543,7 @@ def moments_waiting_time(self, test=bool, is_zero=None, :: + sage: # needs sage.libs.singular sage: def test(h, r): ....: R = PolynomialRing( ....: QQ, @@ -10574,6 +10598,7 @@ def moments_waiting_time(self, test=bool, is_zero=None, The expectation of `B_j` is given in [FHP2015]_, Theorem 2. Here, we verify this result by using transducers:: + sage: # needs sage.libs.singular sage: def test(h, r, j): ....: R = PolynomialRing( ....: QQ, @@ -11845,13 +11870,13 @@ def shannon_parry_markov_chain(self): sage: NAF = Automaton([(0, 0, 0), (0, 1, 1), (0, 1, -1), ....: (1, 0, 0)], initial_states=[0], ....: final_states=[0, 1]) - sage: P_NAF = NAF.shannon_parry_markov_chain() # optional - sage.symbolic - sage: P_NAF.transitions() # optional - sage.symbolic + sage: P_NAF = NAF.shannon_parry_markov_chain() # needs sage.symbolic + sage: P_NAF.transitions() # needs sage.symbolic [Transition from 0 to 0: 1/2|0, Transition from 0 to 1: 1/4|1, Transition from 0 to 1: 1/4|-1, Transition from 1 to 0: 1|0] - sage: for s in P_NAF.iter_states(): # optional - sage.symbolic + sage: for s in P_NAF.iter_states(): # needs sage.symbolic ....: print(s.color) 3/4 3/2 @@ -11859,7 +11884,7 @@ def shannon_parry_markov_chain(self): The stationary distribution is also computed and saved as the initial probabilities of the returned Markov chain:: - sage: for s in P_NAF.states(): # optional - sage.symbolic + sage: for s in P_NAF.states(): # needs sage.symbolic ....: print("{} {}".format(s, s.initial_probability)) 0 2/3 1 1/3 @@ -12774,6 +12799,7 @@ class is created and is used during the processing. This can also be used with words as input:: + sage: # needs sage.combinat sage: W = Words([0, 1]); W Finite and infinite words over {0, 1} sage: w = W([0, 1, 0, 0, 1, 1]); w @@ -12784,7 +12810,7 @@ class is created and is used during the processing. In this case it is automatically determined that the output is a word. The call above is equivalent to:: - sage: binary_inverter.process(w, + sage: binary_inverter.process(w, # needs sage.combinat ....: full_output=False, ....: list_of_outputs=False, ....: automatic_output_type=True) diff --git a/src/sage/combinat/finite_state_machine_generators.py b/src/sage/combinat/finite_state_machine_generators.py index 24d027c03d0..aacc520999a 100644 --- a/src/sage/combinat/finite_state_machine_generators.py +++ b/src/sage/combinat/finite_state_machine_generators.py @@ -1079,15 +1079,16 @@ def _parse_recursion_equation_(self, equation, base, function, var, EXAMPLES:: - sage: var('n') # optional - sage.symbolic + sage: # needs sage.symbolic + sage: var('n') n - sage: function('f') # optional - sage.symbolic + sage: function('f') f - sage: transducers._parse_recursion_equation_( # optional - sage.symbolic + sage: transducers._parse_recursion_equation_( ....: f(8*n + 7) == f(2*n + 3) + 5, ....: 2, f, n) RecursionRule(K=3, r=7, k=1, s=3, t=[5]) - sage: transducers._parse_recursion_equation_( # optional - sage.symbolic + sage: transducers._parse_recursion_equation_( ....: f(42) == 5, ....: 2, f, n) {42: [5]} @@ -1096,14 +1097,14 @@ def _parse_recursion_equation_(self, equation, base, function, var, The following tests check that the equations are well-formed:: - sage: transducers._parse_recursion_equation_(f(4*n + 1), 2, f, n) # optional - sage.symbolic + sage: transducers._parse_recursion_equation_(f(4*n + 1), 2, f, n) # needs sage.symbolic Traceback (most recent call last): ... ValueError: f(4*n + 1) is not an equation with ==. :: - sage: transducers._parse_recursion_equation_(f(n) + 1 == f(2*n), # optional - sage.symbolic + sage: transducers._parse_recursion_equation_(f(n) + 1 == f(2*n), # needs sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1111,7 +1112,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n, 5) == 3, # optional - sage.symbolic + sage: transducers._parse_recursion_equation_(f(2*n, 5) == 3, # needs sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1119,7 +1120,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(1/n) == f(n) + 3, # optional - sage.symbolic + sage: transducers._parse_recursion_equation_(f(1/n) == f(n) + 3, # needs sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1127,7 +1128,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(n^2 + 5) == 3, # optional - sage.symbolic + sage: transducers._parse_recursion_equation_(f(n^2 + 5) == 3, # needs sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1135,7 +1136,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(3*n + 5) == f(n) + 7, # optional - sage.symbolic + sage: transducers._parse_recursion_equation_(f(3*n + 5) == f(n) + 7, # needs sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1143,7 +1144,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(n + 5) == f(n) + 7, # optional - sage.symbolic + sage: transducers._parse_recursion_equation_(f(n + 5) == f(n) + 7, # needs sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1151,7 +1152,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_( # optional - sage.symbolic + sage: transducers._parse_recursion_equation_( # needs sage.symbolic ....: f(2*n + 1) == f(n + 1) + f(n) + 2, ....: 2, f, n) Traceback (most recent call last): @@ -1161,7 +1162,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == sin(n) + 2, # optional - sage.symbolic + sage: transducers._parse_recursion_equation_(f(2*n + 1) == sin(n) + 2, # needs sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1170,7 +1171,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_( # optional - sage.symbolic + sage: transducers._parse_recursion_equation_( # needs sage.symbolic ....: f(2*n + 1) == f(n) + n + 2, ....: 2, f, n) Traceback (most recent call last): @@ -1179,7 +1180,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == sin(n), # optional - sage.symbolic + sage: transducers._parse_recursion_equation_(f(2*n + 1) == sin(n), # needs sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1187,7 +1188,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(n, 2), # optional - sage.symbolic + sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(n, 2), # needs sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1195,7 +1196,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(1/n), # optional - sage.symbolic + sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(1/n), # needs sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1203,7 +1204,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(n^2 + 5), # optional - sage.symbolic + sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(n^2 + 5), # needs sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1211,7 +1212,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(3*n + 5), # optional - sage.symbolic + sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(3*n + 5), # needs sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1219,7 +1220,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_( # optional - sage.symbolic + sage: transducers._parse_recursion_equation_( # needs sage.symbolic ....: f(2*n + 1) == f((1/2)*n + 5), ....: QQ(2), f, n) Traceback (most recent call last): @@ -1228,7 +1229,7 @@ def _parse_recursion_equation_(self, equation, base, function, var, :: - sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(2*n + 5), # optional - sage.symbolic + sage: transducers._parse_recursion_equation_(f(2*n + 1) == f(2*n + 5), # needs sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1434,17 +1435,18 @@ def Recursion(self, recursions, base, function=None, var=None, - The following example computes the Hamming weight of the ternary expansion of integers. :: - sage: function('f') # optional - sage.symbolic + sage: # needs sage.symbolic + sage: function('f') f - sage: var('n') # optional - sage.symbolic + sage: var('n') n - sage: T = transducers.Recursion([ # optional - sage.symbolic + sage: T = transducers.Recursion([ ....: f(3*n + 1) == f(n) + 1, ....: f(3*n + 2) == f(n) + 1, ....: f(3*n) == f(n), ....: f(0) == 0], ....: 3, f, n) - sage: T.transitions() # optional - sage.symbolic + sage: T.transitions() [Transition from (0, 0) to (0, 0): 0|-, Transition from (0, 0) to (0, 0): 1|1, Transition from (0, 0) to (0, 0): 2|1] @@ -1452,13 +1454,14 @@ def Recursion(self, recursions, base, function=None, var=None, To illustrate what this transducer does, we consider the example of `n=601`:: - sage: ternary_expansion = 601.digits(base=3) # optional - sage.symbolic - sage: ternary_expansion # optional - sage.symbolic + sage: # needs sage.symbolic + sage: ternary_expansion = 601.digits(base=3) + sage: ternary_expansion [1, 2, 0, 1, 1, 2] - sage: weight_sequence = T(ternary_expansion) # optional - sage.symbolic - sage: weight_sequence # optional - sage.symbolic + sage: weight_sequence = T(ternary_expansion) + sage: weight_sequence [1, 1, 1, 1, 1] - sage: sum(weight_sequence) # optional - sage.symbolic + sage: sum(weight_sequence) 5 Note that the digit zero does not show up in the output because @@ -1468,24 +1471,25 @@ def Recursion(self, recursions, base, function=None, var=None, - The following example computes the Hamming weight of the non-adjacent form, cf. the :wikipedia:`Non-adjacent_form`. :: - sage: function('f') # optional - sage.symbolic + sage: # needs sage.symbolic + sage: function('f') f - sage: var('n') # optional - sage.symbolic + sage: var('n') n - sage: T = transducers.Recursion([ # optional - sage.symbolic + sage: T = transducers.Recursion([ ....: f(4*n + 1) == f(n) + 1, ....: f(4*n - 1) == f(n) + 1, ....: f(2*n) == f(n), ....: f(0) == 0], ....: 2, f, n) - sage: T.transitions() # optional - sage.symbolic + sage: T.transitions() [Transition from (0, 0) to (0, 0): 0|-, Transition from (0, 0) to (1, 1): 1|-, Transition from (1, 1) to (0, 0): 0|1, Transition from (1, 1) to (1, 0): 1|1, Transition from (1, 0) to (1, 1): 0|-, Transition from (1, 0) to (1, 0): 1|-] - sage: [(s.label(), s.final_word_out) # optional - sage.symbolic + sage: [(s.label(), s.final_word_out) ....: for s in T.iter_final_states()] [((0, 0), []), ((1, 1), [1]), @@ -1507,9 +1511,9 @@ def Recursion(self, recursions, base, function=None, var=None, sage: binary_expansion = 29.digits(base=2) sage: binary_expansion [1, 0, 1, 1, 1] - sage: T(binary_expansion) # optional - sage.symbolic + sage: T(binary_expansion) # needs sage.symbolic [1, 1, 1] - sage: sum(T(binary_expansion)) # optional - sage.symbolic + sage: sum(T(binary_expansion)) # needs sage.symbolic 3 Indeed, the given non-adjacent form has three non-zero @@ -1535,11 +1539,12 @@ def Recursion(self, recursions, base, function=None, var=None, the point of view of this method---is a contradicting recursion. We override this by the parameter ``is_zero``. :: - sage: var('n') # optional - sage.symbolic + sage: # needs sage.symbolic + sage: var('n') n - sage: function('f w') # optional - sage.symbolic + sage: function('f w') (f, w) - sage: T = transducers.Recursion([ # optional - sage.symbolic + sage: T = transducers.Recursion([ ....: f(2*n) == f(n) + w(0), ....: f(4*n + 1) == f(n) + w(1, 0), ....: f(4*n - 1) == f(n) + w(-1, 0), @@ -1547,14 +1552,14 @@ def Recursion(self, recursions, base, function=None, var=None, ....: 2, f, n, ....: word_function=w, ....: is_zero=lambda x: sum(x).is_zero()) - sage: T.transitions() # optional - sage.symbolic + sage: T.transitions() [Transition from (0, 0) to (0, 0): 0|0, Transition from (0, 0) to (1, 1): 1|-, Transition from (1, 1) to (0, 0): 0|1,0, Transition from (1, 1) to (1, 0): 1|-1,0, Transition from (1, 0) to (1, 1): 0|-, Transition from (1, 0) to (1, 0): 1|0] - sage: for s in T.iter_states(): # optional - sage.symbolic + sage: for s in T.iter_states(): ....: print("{} {}".format(s, s.final_word_out)) (0, 0) [] (1, 1) [1, 0] @@ -1562,7 +1567,7 @@ def Recursion(self, recursions, base, function=None, var=None, We again consider the example of `n=29`:: - sage: T(29.digits(base=2)) # optional - sage.symbolic + sage: T(29.digits(base=2)) # needs sage.symbolic [1, 0, -1, 0, 0, 1, 0] The same transducer can also be entered bypassing the @@ -1576,22 +1581,23 @@ def Recursion(self, recursions, base, function=None, var=None, ....: (0, [])], ....: 2, ....: is_zero=lambda x: sum(x).is_zero()) - sage: TR == T # optional - sage.symbolic + sage: TR == T # needs sage.symbolic True - Here is an artificial example where some of the `s` are negative:: - sage: function('f') # optional - sage.symbolic + sage: # needs sage.symbolic + sage: function('f') f - sage: var('n') # optional - sage.symbolic + sage: var('n') n - sage: T = transducers.Recursion([ # optional - sage.symbolic + sage: T = transducers.Recursion([ ....: f(2*n + 1) == f(n-1) + 1, ....: f(2*n) == f(n), ....: f(1) == 1, ....: f(0) == 0], 2, f, n) - sage: T.transitions() # optional - sage.symbolic + sage: T.transitions() [Transition from (0, 0) to (0, 0): 0|-, Transition from (0, 0) to (1, 1): 1|-, Transition from (1, 1) to (-1, 1): 0|1, @@ -1602,7 +1608,7 @@ def Recursion(self, recursions, base, function=None, var=None, Transition from (-1, 2) to (0, 0): 1|1, Transition from (1, 2) to (-1, 2): 0|1, Transition from (1, 2) to (1, 2): 1|1] - sage: [(s.label(), s.final_word_out) # optional - sage.symbolic + sage: [(s.label(), s.final_word_out) ....: for s in T.iter_final_states()] [((0, 0), []), ((1, 1), [1]), @@ -1613,7 +1619,8 @@ def Recursion(self, recursions, base, function=None, var=None, - Abelian complexity of the paperfolding sequence (cf. [HKP2015]_, Example 2.8):: - sage: T = transducers.Recursion([ # optional - sage.symbolic + sage: # needs sage.symbolic + sage: T = transducers.Recursion([ ....: f(4*n) == f(2*n), ....: f(4*n+2) == f(2*n+1)+1, ....: f(16*n+1) == f(8*n+1), @@ -1623,7 +1630,7 @@ def Recursion(self, recursions, base, function=None, var=None, ....: f(1) == 2, f(0) == 0] ....: + [f(16*n+jj) == f(2*n+1)+2 for jj in [3,7,9,13]], ....: 2, f, n) - sage: T.transitions() # optional - sage.symbolic + sage: T.transitions() [Transition from (0, 0) to (0, 1): 0|-, Transition from (0, 0) to (1, 1): 1|-, Transition from (0, 1) to (0, 1): 0|-, @@ -1644,7 +1651,7 @@ def Recursion(self, recursions, base, function=None, var=None, Transition from (7, 3) to (2, 1): 1|1, Transition from (2, 1) to (1, 1): 0|1, Transition from (2, 1) to (2, 1): 1|-] - sage: for s in T.iter_states(): # optional - sage.symbolic + sage: for s in T.iter_states(): ....: print("{} {}".format(s, s.final_word_out)) (0, 0) [] (0, 1) [] @@ -1656,52 +1663,53 @@ def Recursion(self, recursions, base, function=None, var=None, (3, 3) [2, 2] (7, 3) [2, 2] (2, 1) [1, 2] - sage: list(sum(T(n.bits())) for n in srange(1, 21)) # optional - sage.symbolic + sage: list(sum(T(n.bits())) for n in srange(1, 21)) [2, 3, 4, 3, 4, 5, 4, 3, 4, 5, 6, 5, 4, 5, 4, 3, 4, 5, 6, 5] - We now demonstrate the use of the ``output_rings`` parameter. If no ``output_rings`` are specified, the output labels are converted into ``ZZ``:: - sage: function('f') # optional - sage.symbolic + sage: # needs sage.symbolic + sage: function('f') f - sage: var('n') # optional - sage.symbolic + sage: var('n') n - sage: T = transducers.Recursion([ # optional - sage.symbolic + sage: T = transducers.Recursion([ ....: f(2*n + 1) == f(n) + 1, ....: f(2*n) == f(n), ....: f(0) == 2], ....: 2, f, n) - sage: for t in T.transitions(): # optional - sage.symbolic + sage: for t in T.transitions(): ....: print([x.parent() for x in t.word_out]) [] [Integer Ring] - sage: [x.parent() for x in T.states()[0].final_word_out] # optional - sage.symbolic + sage: [x.parent() for x in T.states()[0].final_word_out] [Integer Ring] In contrast, if ``output_rings`` is set to the empty list, the results are not converted:: - sage: T = transducers.Recursion([ # optional - sage.symbolic + sage: T = transducers.Recursion([ # needs sage.symbolic ....: f(2*n + 1) == f(n) + 1, ....: f(2*n) == f(n), ....: f(0) == 2], ....: 2, f, n, output_rings=[]) - sage: for t in T.transitions(): # optional - sage.symbolic + sage: for t in T.transitions(): # needs sage.symbolic ....: print([x.parent() for x in t.word_out]) [] [Symbolic Ring] - sage: [x.parent() for x in T.states()[0].final_word_out] # optional - sage.symbolic + sage: [x.parent() for x in T.states()[0].final_word_out] # needs sage.symbolic [Symbolic Ring] Finally, we use a somewhat questionable conversion:: - sage: T = transducers.Recursion([ # optional - sage.rings.finite_rings sage.symbolic + sage: T = transducers.Recursion([ # needs sage.rings.finite_rings sage.symbolic ....: f(2*n + 1) == f(n) + 1, ....: f(2*n) == f(n), ....: f(0) == 0], ....: 2, f, n, output_rings=[GF(5)]) - sage: for t in T.transitions(): # optional - sage.rings.finite_rings sage.symbolic + sage: for t in T.transitions(): # needs sage.rings.finite_rings sage.symbolic ....: print([x.parent() for x in t.word_out]) [] [Finite Field of size 5] @@ -1728,11 +1736,11 @@ def Recursion(self, recursions, base, function=None, var=None, The following tests fail due to missing or superfluous recursions or initial conditions. :: - sage: var('n') # optional - sage.symbolic + sage: var('n') # needs sage.symbolic n - sage: function('f') # optional - sage.symbolic + sage: function('f') # needs sage.symbolic f - sage: transducers.Recursion([f(2*n) == f(n)], # optional - sage.symbolic + sage: transducers.Recursion([f(2*n) == f(n)], # needs sage.symbolic ....: 2, f, n) Traceback (most recent call last): ... @@ -1741,7 +1749,7 @@ def Recursion(self, recursions, base, function=None, var=None, :: - sage: transducers.Recursion([f(2*n + 1) == f(n), # optional - sage.symbolic + sage: transducers.Recursion([f(2*n + 1) == f(n), # needs sage.symbolic ....: f(4*n) == f(2*n) + 1, ....: f(2*n) == f(n) + 1], ....: 2, f, n) @@ -1751,7 +1759,7 @@ def Recursion(self, recursions, base, function=None, var=None, :: - sage: transducers.Recursion([f(2*n + 1) == f(n) + 1, # optional - sage.symbolic + sage: transducers.Recursion([f(2*n + 1) == f(n) + 1, # needs sage.symbolic ....: f(2*n) == f(n), ....: f(0) == 0, ....: f(42) == 42], 2, f, n) @@ -1761,7 +1769,7 @@ def Recursion(self, recursions, base, function=None, var=None, :: - sage: transducers.Recursion([f(2*n + 1) == f(n) + 1, # optional - sage.symbolic + sage: transducers.Recursion([f(2*n + 1) == f(n) + 1, # needs sage.symbolic ....: f(2*n) == f(n - 2) + 4, ....: f(0) == 0], 2, f, n) Traceback (most recent call last): @@ -1771,7 +1779,7 @@ def Recursion(self, recursions, base, function=None, var=None, Here is an example of a transducer with a conflicting rule (it cannot hold for `n = 0`):: - sage: T = transducers.Recursion([ # optional - sage.symbolic + sage: T = transducers.Recursion([ # needs sage.symbolic ....: f(2*n + 1) == f(n - 1), ....: f(2*n) == f(n) + 1, ....: f(1) == 1, diff --git a/src/sage/combinat/free_module.py b/src/sage/combinat/free_module.py index 14711e8713e..3c77ac6ef16 100644 --- a/src/sage/combinat/free_module.py +++ b/src/sage/combinat/free_module.py @@ -151,7 +151,7 @@ class CombinatorialFreeModule(UniqueRepresentation, Module, IndexedGenerators): The constructed module is in the category of modules with basis over the base ring:: - sage: CombinatorialFreeModule(QQ, Partitions()).category() # optional - sage.combinat + sage: CombinatorialFreeModule(QQ, Partitions()).category() # needs sage.combinat Category of vector spaces with basis over Rational Field If furthermore the index set is finite (i.e. in the category @@ -160,7 +160,7 @@ class CombinatorialFreeModule(UniqueRepresentation, Module, IndexedGenerators): sage: CombinatorialFreeModule(QQ, [1,2,3,4]).category() Category of finite dimensional vector spaces with basis over Rational Field - sage: CombinatorialFreeModule(QQ, Partitions(3), # optional - sage.combinat + sage: CombinatorialFreeModule(QQ, Partitions(3), # needs sage.combinat ....: category=Algebras(QQ).WithBasis()).category() Category of finite dimensional algebras with basis over Rational Field @@ -252,11 +252,12 @@ class CombinatorialFreeModule(UniqueRepresentation, Module, IndexedGenerators): TESTS:: - sage: XQ = SchubertPolynomialRing(QQ) # optional - sage.combinat - sage: XZ = SchubertPolynomialRing(ZZ) # optional - sage.combinat - sage: XQ == XZ # optional - sage.combinat + sage: # needs sage.combinat + sage: XQ = SchubertPolynomialRing(QQ) + sage: XZ = SchubertPolynomialRing(ZZ) + sage: XQ == XZ False - sage: XQ == XQ # optional - sage.combinat + sage: XQ == XQ True We check that issue :trac:`28681` is fixed:: @@ -347,21 +348,21 @@ def element_class(self): EXAMPLES:: - sage: A = Algebras(QQ).WithBasis().example(); A # optional - sage.combinat + sage: # needs sage.combinat + sage: A = Algebras(QQ).WithBasis().example(); A An example of an algebra with basis: the free algebra on the generators ('a', 'b', 'c') over Rational Field - - sage: A.element_class.mro() # optional - sage.combinat + sage: A.element_class.mro() [, , ...] - sage: a,b,c = A.algebra_generators() # optional - sage.combinat - sage: a * b # optional - sage.combinat + sage: a,b,c = A.algebra_generators() + sage: a * b B[word: ab] TESTS:: - sage: A.__class__.element_class.__module__ # optional - sage.combinat + sage: A.__class__.element_class.__module__ # needs sage.combinat 'sage.combinat.free_module' """ return self.__make_element_class__(self.Element, @@ -385,9 +386,9 @@ def __init__(self, R, basis_keys=None, element_class=None, category=None, sage: F.category() Category of finite dimensional algebras with basis over Rational Field - sage: F = CombinatorialFreeModule(GF(3), ['a','b','c'], # optional - sage.rings.finite_rings + sage: F = CombinatorialFreeModule(GF(3), ['a','b','c'], # needs sage.rings.finite_rings ....: category=(Modules(GF(3)).WithBasis(), Semigroups())) - sage: F.category() # optional - sage.rings.finite_rings + sage: F.category() # needs sage.rings.finite_rings Join of Category of finite semigroups and Category of finite dimensional vector spaces with basis over Finite Field of size 3 @@ -519,8 +520,8 @@ def _ascii_art_term(self, m): TESTS:: - sage: R = NonCommutativeSymmetricFunctions(QQ).R() # optional - sage.combinat - sage: ascii_art(R.one()) # indirect doctest # optional - sage.combinat + sage: R = NonCommutativeSymmetricFunctions(QQ).R() # needs sage.combinat + sage: ascii_art(R.one()) # indirect doctest # needs sage.combinat 1 """ try: @@ -536,8 +537,8 @@ def _unicode_art_term(self, m): TESTS:: - sage: R = NonCommutativeSymmetricFunctions(QQ).R() # optional - sage.combinat - sage: unicode_art(R.one()) # indirect doctest # optional - sage.combinat + sage: R = NonCommutativeSymmetricFunctions(QQ).R() # needs sage.combinat + sage: unicode_art(R.one()) # indirect doctest # needs sage.combinat 1 """ try: @@ -627,20 +628,20 @@ def _element_constructor_(self, x): Do not rely on the following feature which may be removed in the future:: - sage: QS3 = SymmetricGroupAlgebra(QQ,3) # optional - sage.combinat - sage: QS3([2,3,1]) # indirect doctest # optional - sage.combinat + sage: QS3 = SymmetricGroupAlgebra(QQ,3) # needs sage.combinat + sage: QS3([2,3,1]) # indirect doctest # needs sage.combinat [2, 3, 1] instead, use:: - sage: P = QS3.basis().keys() # optional - sage.combinat - sage: QS3.monomial(P([2,3,1])) # indirect doctest # optional - sage.combinat + sage: P = QS3.basis().keys() # needs sage.combinat + sage: QS3.monomial(P([2,3,1])) # indirect doctest # needs sage.combinat [2, 3, 1] or:: - sage: B = QS3.basis() # optional - sage.combinat - sage: B[P([2,3,1])] # optional - sage.combinat + sage: B = QS3.basis() # needs sage.combinat + sage: B[P([2,3,1])] # needs sage.combinat [2, 3, 1] TODO: The symmetric group algebra (and in general, @@ -692,10 +693,11 @@ def _element_constructor_(self, x): Here is a real life example illustrating that this yielded mathematically wrong results:: - sage: S = SymmetricFunctions(QQ) # optional - sage.combinat - sage: s = S.s(); p = S.p() # optional - sage.combinat - sage: ss = tensor([s,s]); pp = tensor([p,p]) # optional - sage.combinat - sage: a = tensor((s[2],s[2])) # optional - sage.combinat + sage: # needs sage.combinat + sage: S = SymmetricFunctions(QQ) + sage: s = S.s(); p = S.p() + sage: ss = tensor([s,s]); pp = tensor([p,p]) + sage: a = tensor((s[2],s[2])) The following originally used to yield ``p[[2]] # p[[2]]``, and if there was no natural coercion between ``s`` and ``p``, this would @@ -703,7 +705,7 @@ def _element_constructor_(self, x): Since :trac:`15305`, this takes the coercion between ``s`` and ``p`` and lifts it to the tensor product. :: - sage: pp(a) # optional - sage.combinat + sage: pp(a) # needs sage.combinat 1/4*p[1, 1] # p[1, 1] + 1/4*p[1, 1] # p[2] + 1/4*p[2] # p[1, 1] + 1/4*p[2] # p[2] General extensions of the ground ring should probably be reintroduced @@ -717,8 +719,8 @@ def _element_constructor_(self, x): Conversion from the ground ring is implemented for algebras:: - sage: QS3 = SymmetricGroupAlgebra(QQ,3) # optional - sage.combinat - sage: QS3(2) # optional - sage.combinat + sage: QS3 = SymmetricGroupAlgebra(QQ,3) # needs sage.combinat + sage: QS3(2) # needs sage.combinat 2*[1, 2, 3] """ R = self.base_ring() @@ -799,8 +801,8 @@ def _first_ngens(self, n): sage: C._first_ngens(3) (B[0], B[1], B[-1]) - sage: R. = FreeAlgebra(QQ, 2) # optional - sage.combinat - sage: x,y # optional - sage.combinat + sage: R. = FreeAlgebra(QQ, 2) # needs sage.combinat + sage: x,y # needs sage.combinat (x, y) """ try: @@ -836,13 +838,14 @@ def _coerce_map_from_(self, R): sage: C.has_coerce_map_from(CQ) False - sage: CF2 = CombinatorialFreeModule(GF(2), Set([1,2])) # optional - sage.rings.finite_rings - sage: CF2.has_coerce_map_from(C) # optional - sage.rings.finite_rings + sage: # needs sage.rings.finite_rings + sage: CF2 = CombinatorialFreeModule(GF(2), Set([1,2])) + sage: CF2.has_coerce_map_from(C) True - sage: c = C.monomial(1) # optional - sage.rings.finite_rings - sage: CF2(2*c) # optional - sage.rings.finite_rings + sage: c = C.monomial(1) + sage: CF2(2*c) 0 - sage: CF2(3*c) # optional - sage.rings.finite_rings + sage: CF2(3*c) B[1] """ if isinstance(R, CombinatorialFreeModule): @@ -878,8 +881,8 @@ def dimension(self): :: - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat - sage: s.dimension() # optional - sage.combinat + sage: s = SymmetricFunctions(QQ).schur() # needs sage.combinat + sage: s.dimension() # needs sage.combinat +Infinity """ return self._indices.cardinality() @@ -894,11 +897,11 @@ def is_exact(self): EXAMPLES:: - sage: GroupAlgebra(GL(3, GF(7))).is_exact() # optional - sage.groups sage.rings.finite_rings + sage: GroupAlgebra(GL(3, GF(7))).is_exact() # needs sage.groups sage.rings.finite_rings True - sage: GroupAlgebra(GL(3, GF(7)), RR).is_exact() # optional - sage.groups sage.rings.finite_rings + sage: GroupAlgebra(GL(3, GF(7)), RR).is_exact() # needs sage.groups sage.rings.finite_rings False - sage: GroupAlgebra(GL(3, pAdicRing(7))).is_exact() # not implemented correctly (not my fault)! # optional - sage.groups sage.rings.padics + sage: GroupAlgebra(GL(3, pAdicRing(7))).is_exact() # not implemented, needs sage.groups sage.rings.padics False """ # The index set may not have a check for exactness @@ -928,11 +931,12 @@ def set_order(self, order): EXAMPLES:: - sage: QS2 = SymmetricGroupAlgebra(QQ,2) # optional - sage.combinat - sage: b = list(QS2.basis().keys()) # optional - sage.combinat - sage: b.reverse() # optional - sage.combinat - sage: QS2.set_order(b) # optional - sage.combinat - sage: QS2.get_order() # optional - sage.combinat + sage: # needs sage.combinat + sage: QS2 = SymmetricGroupAlgebra(QQ,2) + sage: b = list(QS2.basis().keys()) + sage: b.reverse() + sage: QS2.set_order(b) + sage: QS2.get_order() [[2, 1], [1, 2]] """ self._order = order @@ -946,8 +950,8 @@ def get_order(self): EXAMPLES:: - sage: QS2 = SymmetricGroupAlgebra(QQ,2) # optional - sage.combinat - sage: QS2.get_order() # note: order changed on 2009-03-13 # optional - sage.combinat + sage: QS2 = SymmetricGroupAlgebra(QQ,2) # needs sage.combinat + sage: QS2.get_order() # note: order changed on 2009-03-13 # needs sage.combinat [[2, 1], [1, 2]] """ if self._order is None: @@ -1003,11 +1007,12 @@ def from_vector(self, vector, order=None, coerce=True): EXAMPLES:: - sage: QS3 = SymmetricGroupAlgebra(QQ, 3) # optional - sage.combinat - sage: b = QS3.from_vector(vector((2, 0, 0, 0, 0, 4))); b # optional - sage.combinat + sage: # needs sage.combinat + sage: QS3 = SymmetricGroupAlgebra(QQ, 3) + sage: b = QS3.from_vector(vector((2, 0, 0, 0, 0, 4))); b 2*[1, 2, 3] + 4*[3, 2, 1] - sage: a = 2*QS3([1,2,3]) + 4*QS3([3,2,1]) # optional - sage.combinat - sage: a == b # optional - sage.combinat + sage: a = 2*QS3([1,2,3]) + 4*QS3([3,2,1]) + sage: a == b True """ if order is None: @@ -1134,8 +1139,8 @@ def _sum_of_monomials(self, indices): sage: F = CombinatorialFreeModule(QQ, ['a', 'b', 'c']) sage: F._sum_of_monomials(['a', 'b', 'b']) B['a'] + 2*B['b'] - sage: F = CombinatorialFreeModule(GF(3), ['a', 'b', 'c']) # optional - sage.rings.finite_rings - sage: F._sum_of_monomials(['a', 'b', 'b', 'b']) # optional - sage.rings.finite_rings + sage: F = CombinatorialFreeModule(GF(3), ['a', 'b', 'c']) # needs sage.rings.finite_rings + sage: F._sum_of_monomials(['a', 'b', 'b', 'b']) # needs sage.rings.finite_rings B['a'] """ R = self.base_ring() @@ -1210,26 +1215,28 @@ def _from_dict(self, d, coerce=False, remove_zeros=True): EXAMPLES:: - sage: e = SymmetricFunctions(QQ).elementary() # optional - sage.combinat - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.combinat - sage: a = e([2,1]) + e([1,1,1]); a # optional - sage.combinat + sage: # needs sage.combinat + sage: e = SymmetricFunctions(QQ).elementary() + sage: s = SymmetricFunctions(QQ).schur() + sage: a = e([2,1]) + e([1,1,1]); a e[1, 1, 1] + e[2, 1] - sage: s._from_dict(a.monomial_coefficients()) # optional - sage.combinat + sage: s._from_dict(a.monomial_coefficients()) s[1, 1, 1] + s[2, 1] If the optional argument ``coerce`` is ``True``, then the coefficients are coerced into the base ring of ``self``:: - sage: part = Partition([2,1]) # optional - sage.combinat - sage: d = {part: 1} # optional - sage.combinat - sage: a = s._from_dict(d, coerce=True); a # optional - sage.combinat + sage: # needs sage.combinat + sage: part = Partition([2,1]) + sage: d = {part: 1} + sage: a = s._from_dict(d, coerce=True); a s[2, 1] - sage: a.coefficient(part).parent() # optional - sage.combinat + sage: a.coefficient(part).parent() Rational Field With ``remove_zeros=True``, zero coefficients are removed:: - sage: s._from_dict({part: 0}) # optional - sage.combinat + sage: s._from_dict({part: 0}) # needs sage.combinat 0 .. WARNING:: @@ -1238,7 +1245,7 @@ def _from_dict(self, d, coerce=False, remove_zeros=True): coefficient of the dictionary is zero. Otherwise, this may lead to illegal results:: - sage: list(s._from_dict({part: 0}, remove_zeros=False)) # optional - sage.combinat + sage: list(s._from_dict({part: 0}, remove_zeros=False)) # needs sage.combinat [([2, 1], 0)] """ assert isinstance(d, dict) @@ -1428,9 +1435,9 @@ def _ascii_art_(self, term): """ TESTS:: - sage: R = NonCommutativeSymmetricFunctions(QQ).R() # optional - sage.combinat - sage: Partitions.options(diagram_str="#", convention="french") # optional - sage.combinat - sage: s = ascii_art(tensor((R[1,2], R[3,1,2]))); s # optional - sage.combinat + sage: R = NonCommutativeSymmetricFunctions(QQ).R() # needs sage.combinat + sage: Partitions.options(diagram_str="#", convention="french") # needs sage.combinat + sage: s = ascii_art(tensor((R[1,2], R[3,1,2]))); s # needs sage.combinat R # R # ### ## # @@ -1438,7 +1445,7 @@ def _ascii_art_(self, term): Check that the breakpoints are correct (:trac:`29202`):: - sage: s._breakpoints # optional - sage.combinat + sage: s._breakpoints # needs sage.combinat [6] """ if hasattr(self, "_print_options"): @@ -1457,9 +1464,9 @@ def _unicode_art_(self, term): """ TESTS:: - sage: R = NonCommutativeSymmetricFunctions(QQ).R() # optional - sage.combinat - sage: Partitions.options(diagram_str="#", convention="french") # optional - sage.combinat - sage: s = unicode_art(tensor((R[1,2], R[3,1,2]))); s # optional - sage.combinat + sage: R = NonCommutativeSymmetricFunctions(QQ).R() # needs sage.combinat + sage: Partitions.options(diagram_str="#", convention="french") # needs sage.combinat + sage: s = unicode_art(tensor((R[1,2], R[3,1,2]))); s # needs sage.combinat R ⊗ R ┌┐ ┌┬┬┐ ├┼┐ └┴┼┤ @@ -1468,7 +1475,7 @@ def _unicode_art_(self, term): Check that the breakpoints are correct (:trac:`29202`):: - sage: s._breakpoints # optional - sage.combinat + sage: s._breakpoints # needs sage.combinat [7] """ if hasattr(self, "_print_options"): diff --git a/src/sage/combinat/fully_commutative_elements.py b/src/sage/combinat/fully_commutative_elements.py index 285bd370fb1..c6d072eb432 100644 --- a/src/sage/combinat/fully_commutative_elements.py +++ b/src/sage/combinat/fully_commutative_elements.py @@ -248,7 +248,7 @@ def plot_heap(self): EXAMPLES:: sage: FC = CoxeterGroup(['B', 5]).fully_commutative_elements() - sage: FC([3,2,4,3,1]).plot_heap() # optional - sage.plot + sage: FC([3,2,4,3,1]).plot_heap() # needs sage.plot Graphics object consisting of 15 graphics primitives .. PLOT:: diff --git a/src/sage/combinat/fully_packed_loop.py b/src/sage/combinat/fully_packed_loop.py index ca4bf09b1b0..949ee9c6504 100644 --- a/src/sage/combinat/fully_packed_loop.py +++ b/src/sage/combinat/fully_packed_loop.py @@ -158,7 +158,7 @@ class FullyPackedLoop(Element, metaclass=InheritComparisonClasscallMetaclass): The class also has a plot method:: - sage: fpl.plot() # optional - sage.plot + sage: fpl.plot() # needs sage.plot Graphics object consisting of 3 graphics primitives which gives: @@ -782,7 +782,7 @@ def plot(self, **options): sage: A = AlternatingSignMatrix([[0, 1, 0], [1, -1, 1], [0, 1, 0]]) sage: fpl = FullyPackedLoop(A) - sage: fpl.plot() # optional - sage.plot + sage: fpl.plot() # needs sage.plot Graphics object consisting of 3 graphics primitives The resulting graphics is as follows @@ -799,7 +799,7 @@ def plot(self, **options): sage: A = AlternatingSignMatrix([[0, 1, 0], [1, -1, 1], [0, 1, 0]]) sage: fpl = FullyPackedLoop(A) - sage: fpl.plot(link_color_map='rainbow') # optional - sage.plot + sage: fpl.plot(link_color_map='rainbow') # needs sage.plot Graphics object consisting of 3 graphics primitives .. PLOT:: @@ -812,9 +812,9 @@ def plot(self, **options): You can plot the 42 fully packed loops of size `4 \times 4` using:: - sage: G = [fpl.plot(link_color_map='winter', loop_color='black') # optional - sage.plot + sage: G = [fpl.plot(link_color_map='winter', loop_color='black') # needs sage.plot ....: for fpl in FullyPackedLoops(4)] - sage: graphics_array(G, 7, 6) # optional - sage.plot + sage: graphics_array(G, 7, 6) # needs sage.plot Graphics Array of size 7 x 6 .. PLOT:: @@ -835,7 +835,7 @@ def plot(self, **options): ....: 00000000+-0000+00000000000000+0000000000" sage: a = matrix(20, [{'0':0, '+':1, '-': -1}[i] for i in s]) sage: fpl = FullyPackedLoop(a) - sage: fpl.plot(loop_fill=True, loop_color_map='rainbow') # optional - sage.plot + sage: fpl.plot(loop_fill=True, loop_color_map='rainbow') # needs sage.plot Graphics object consisting of 27 graphics primitives .. PLOT:: diff --git a/src/sage/combinat/growth.py b/src/sage/combinat/growth.py index 23b7a279fdc..951d774931e 100644 --- a/src/sage/combinat/growth.py +++ b/src/sage/combinat/growth.py @@ -487,7 +487,10 @@ from sage.combinat.core import Core, Cores from sage.combinat.k_tableau import WeakTableau, StrongTableau from sage.combinat.shifted_primed_tableau import ShiftedPrimedTableau -from sage.graphs.digraph import DiGraph +from sage.misc.lazy_import import lazy_import + +lazy_import('sage.graphs.digraph', 'DiGraph') +lazy_import('sage.combinat.posets.posets', 'Poset') def _make_partition(l): @@ -619,8 +622,8 @@ class GrowthDiagram(SageObject): Passing the permutation matrix instead gives the same result:: - sage: G = GrowthDiagram(RuleRSK, pi.to_matrix()) - sage: ascii_art([G.P_symbol(), G.Q_symbol()]) + sage: G = GrowthDiagram(RuleRSK, pi.to_matrix()) # needs sage.modules + sage: ascii_art([G.P_symbol(), G.Q_symbol()]) # needs sage.modules [ 1 2 3 1 3 4 ] [ 4 , 2 ] @@ -1358,10 +1361,10 @@ def _process_filling_and_shape(self, filling, shape): ``filling`` is a matrix:: - sage: G = GrowthDiagram(RuleRSK, pi.to_matrix()) # indirect doctest - sage: G._filling + sage: G = GrowthDiagram(RuleRSK, pi.to_matrix()) # indirect doctest # needs sage.modules + sage: G._filling # needs sage.modules {(0, 1): 1, (1, 2): 1, (2, 0): 1, (3, 5): 1, (4, 3): 1, (5, 4): 1} - sage: G.shape() + sage: G.shape() # needs sage.modules [6, 6, 6, 6, 6, 6] / [] ``filling`` is a permutation:: @@ -1390,7 +1393,8 @@ def _process_filling_and_shape(self, filling, shape): ``filling`` is a list of lists and shape is given:: - sage: G = GrowthDiagram(RuleRSK, [[1,0,1],[0,1]], shape=SkewPartition([[3,2],[1]])) # indirect doctest + sage: G = GrowthDiagram(RuleRSK, [[1,0,1],[0,1]], # indirect doctest + ....: shape=SkewPartition([[3,2],[1]])) sage: G._filling {(0, 0): 1, (1, 1): 1, (2, 0): 1} sage: G.shape() @@ -2028,7 +2032,8 @@ def P_symbol(self, P_chain): . 4' 5 sage: Shifted = GrowthDiagram.rules.ShiftedShapes() - sage: labels = [mu if is_even(i) else 0 for i, mu in enumerate(T.to_chain()[::-1])] + U.to_chain()[1:] + sage: labels = [mu if is_even(i) else 0 + ....: for i, mu in enumerate(T.to_chain()[::-1])] + U.to_chain()[1:] sage: G = Shifted({(1,2):1, (2,1):1}, shape=[5,5,5,5,5], labels=labels) sage: G.P_symbol().pp() . . . . 2 @@ -2080,7 +2085,8 @@ def Q_symbol(self, Q_chain): . 4' 5 sage: Shifted = GrowthDiagram.rules.ShiftedShapes() - sage: labels = [mu if is_even(i) else 0 for i, mu in enumerate(T.to_chain()[::-1])] + U.to_chain()[1:] + sage: labels = [mu if is_even(i) else 0 + ....: for i, mu in enumerate(T.to_chain()[::-1])] + U.to_chain()[1:] sage: G = Shifted({(1,2):1, (2,1):1}, shape=[5,5,5,5,5], labels=labels) sage: G.Q_symbol().pp() . . . . 2 diff --git a/src/sage/combinat/integer_lists/base.pyx b/src/sage/combinat/integer_lists/base.pyx index c39937c3ac6..6da2125396e 100644 --- a/src/sage/combinat/integer_lists/base.pyx +++ b/src/sage/combinat/integer_lists/base.pyx @@ -61,7 +61,7 @@ cdef class IntegerListsBackend(): sage: from sage.combinat.integer_lists.base import IntegerListsBackend sage: C = IntegerListsBackend(2, length=3) - sage: C = IntegerListsBackend(min_sum=1.4) + sage: C = IntegerListsBackend(min_sum=1.4) # needs sage.rings.real_mpfr Traceback (most recent call last): ... TypeError: Attempt to coerce non-integral RealNumber to Integer diff --git a/src/sage/combinat/integer_lists/invlex.pyx b/src/sage/combinat/integer_lists/invlex.pyx index f78c5d3b467..b517a108479 100644 --- a/src/sage/combinat/integer_lists/invlex.pyx +++ b/src/sage/combinat/integer_lists/invlex.pyx @@ -560,7 +560,7 @@ class IntegerListsLex(IntegerLists, metaclass=ClasscallMetaclass): :: - sage: Partitions(2, max_slope=-1, length=2).list() # optional - sage.combinat + sage: Partitions(2, max_slope=-1, length=2).list() # needs sage.combinat [] sage: list(IntegerListsLex(0, floor=ConstantFunction(1), min_slope=0)) [[]] diff --git a/src/sage/combinat/integer_vector.py b/src/sage/combinat/integer_vector.py index 65eb4dfc4e9..456eea36f44 100644 --- a/src/sage/combinat/integer_vector.py +++ b/src/sage/combinat/integer_vector.py @@ -92,11 +92,11 @@ def is_gale_ryser(r,s): EXAMPLES:: sage: from sage.combinat.integer_vector import is_gale_ryser - sage: is_gale_ryser([4,2,2], [3,3,1,1]) # optional - sage.combinat + sage: is_gale_ryser([4,2,2], [3,3,1,1]) # needs sage.combinat True - sage: is_gale_ryser([4,2,1,1], [3,3,1,1]) # optional - sage.combinat + sage: is_gale_ryser([4,2,1,1], [3,3,1,1]) # needs sage.combinat True - sage: is_gale_ryser([3,2,1,1], [3,3,1,1]) # optional - sage.combinat + sage: is_gale_ryser([3,2,1,1], [3,3,1,1]) # needs sage.combinat False REMARK: In the literature, what we are calling a @@ -204,47 +204,49 @@ def gale_ryser_theorem(p1, p2, algorithm="gale", Computing the matrix for `p_1=p_2=2+2+1`:: + sage: # needs sage.combinat sage.modules sage: from sage.combinat.integer_vector import gale_ryser_theorem sage: p1 = [2,2,1] sage: p2 = [2,2,1] - sage: print(gale_ryser_theorem(p1, p2)) # not tested # optional - sage.combinat + sage: print(gale_ryser_theorem(p1, p2)) # not tested [1 1 0] [1 0 1] [0 1 0] - sage: A = gale_ryser_theorem(p1, p2) # optional - sage.combinat - sage: rs = [sum(x) for x in A.rows()] # optional - sage.combinat - sage: cs = [sum(x) for x in A.columns()] # optional - sage.combinat - sage: p1 == rs; p2 == cs # optional - sage.combinat + sage: A = gale_ryser_theorem(p1, p2) + sage: rs = [sum(x) for x in A.rows()] + sage: cs = [sum(x) for x in A.columns()] + sage: p1 == rs; p2 == cs True True Or for a non-square matrix with `p_1=3+3+2+1` and `p_2=3+2+2+1+1`, using Ryser's algorithm:: + sage: # needs sage.combinat sage.modules sage: from sage.combinat.integer_vector import gale_ryser_theorem sage: p1 = [3,3,1,1] sage: p2 = [3,3,1,1] - sage: gale_ryser_theorem(p1, p2, algorithm="ryser") # optional - sage.combinat + sage: gale_ryser_theorem(p1, p2, algorithm="ryser") [1 1 1 0] [1 1 0 1] [1 0 0 0] [0 1 0 0] sage: p1 = [4,2,2] sage: p2 = [3,3,1,1] - sage: gale_ryser_theorem(p1, p2, algorithm="ryser") # optional - sage.combinat + sage: gale_ryser_theorem(p1, p2, algorithm="ryser") [1 1 1 1] [1 1 0 0] [1 1 0 0] sage: p1 = [4,2,2,0] sage: p2 = [3,3,1,1,0,0] - sage: gale_ryser_theorem(p1, p2, algorithm="ryser") # optional - sage.combinat + sage: gale_ryser_theorem(p1, p2, algorithm="ryser") [1 1 1 1 0 0] [1 1 0 0 0 0] [1 1 0 0 0 0] [0 0 0 0 0 0] sage: p1 = [3,3,2,1] sage: p2 = [3,2,2,1,1] - sage: print(gale_ryser_theorem(p1, p2, algorithm="gale")) # not tested # optional - sage.combinat + sage: print(gale_ryser_theorem(p1, p2, algorithm="gale")) # not tested [1 1 1 0 0] [1 1 0 0 1] [1 0 1 0 0] @@ -253,7 +255,7 @@ def gale_ryser_theorem(p1, p2, algorithm="gale", With `0` in the sequences, and with unordered inputs:: sage: from sage.combinat.integer_vector import gale_ryser_theorem - sage: gale_ryser_theorem([3,3,0,1,1,0], [3,1,3,1,0], algorithm="ryser") # optional - sage.combinat + sage: gale_ryser_theorem([3,3,0,1,1,0], [3,1,3,1,0], algorithm="ryser") # needs sage.combinat sage.modules [1 1 1 0 0] [1 0 1 1 0] [0 0 0 0 0] @@ -261,7 +263,7 @@ def gale_ryser_theorem(p1, p2, algorithm="gale", [0 0 1 0 0] [0 0 0 0 0] sage: p1 = [3,1,1,1,1]; p2 = [3,2,2,0] - sage: gale_ryser_theorem(p1, p2, algorithm="ryser") # optional - sage.combinat + sage: gale_ryser_theorem(p1, p2, algorithm="ryser") # needs sage.combinat sage.modules [1 1 1 0] [1 0 0 0] [1 0 0 0] @@ -276,7 +278,7 @@ def gale_ryser_theorem(p1, p2, algorithm="gale", ``gale_ryser_theorem`` is then called on these sequences, and the output checked for correction.:: - sage: def test_algorithm(algorithm, low = 10, high = 50): + sage: def test_algorithm(algorithm, low=10, high=50): ....: n,m = randint(low,high), randint(low,high) ....: g = graphs.RandomBipartite(n, m, .3) ....: s1 = sorted(g.degree([(0,i) for i in range(n)]), reverse = True) @@ -288,17 +290,17 @@ def gale_ryser_theorem(p1, p2, algorithm="gale", ....: print("Algorithm %s failed with this input:" % algorithm) ....: print(s1, s2) - sage: for algorithm in ["gale", "ryser"]: # long time # optional - sage.combinat + sage: for algorithm in ["gale", "ryser"]: # long time # needs sage.combinat sage.modules ....: for i in range(50): ....: test_algorithm(algorithm, 3, 10) Null matrix:: - sage: gale_ryser_theorem([0,0,0],[0,0,0,0], algorithm="gale") # optional - sage.combinat + sage: gale_ryser_theorem([0,0,0],[0,0,0,0], algorithm="gale") # needs sage.combinat sage.modules [0 0 0 0] [0 0 0 0] [0 0 0 0] - sage: gale_ryser_theorem([0,0,0],[0,0,0,0], algorithm="ryser") # optional - sage.combinat + sage: gale_ryser_theorem([0,0,0],[0,0,0,0], algorithm="ryser") # needs sage.combinat sage.modules [0 0 0 0] [0 0 0 0] [0 0 0 0] @@ -517,10 +519,10 @@ def specht_module(self, base_ring=None): EXAMPLES:: - sage: SM = IntegerVectors()([2,0,1,0,2]).specht_module(QQ); SM # optional - sage.combinat + sage: SM = IntegerVectors()([2,0,1,0,2]).specht_module(QQ); SM # needs sage.combinat sage.modules Specht module of [(0, 0), (0, 1), (2, 0), (4, 0), (4, 1)] over Rational Field - sage: s = SymmetricFunctions(QQ).s() # optional - sage.combinat - sage: s(SM.frobenius_image()) # optional - sage.combinat + sage: s = SymmetricFunctions(QQ).s() # needs sage.combinat sage.modules + sage: s(SM.frobenius_image()) # needs sage.combinat sage.modules s[2, 2, 1] """ from sage.combinat.specht_module import SpechtModule @@ -541,9 +543,9 @@ def specht_module_dimension(self, base_ring=None): EXAMPLES:: - sage: IntegerVectors()([2,0,1,0,2]).specht_module_dimension() # optional - sage.combinat + sage: IntegerVectors()([2,0,1,0,2]).specht_module_dimension() # needs sage.combinat sage.modules 5 - sage: IntegerVectors()([2,0,1,0,2]).specht_module_dimension(GF(2)) # optional - sage.combinat sage.rings.finite_rings + sage: IntegerVectors()([2,0,1,0,2]).specht_module_dimension(GF(2)) # needs sage.combinat sage.modules sage.rings.finite_rings 5 """ from sage.combinat.specht_module import specht_module_rank @@ -594,7 +596,7 @@ class IntegerVectors(Parent, metaclass=ClasscallMetaclass): Note that trailing zeros are ignored so that ``[3, 0]`` does not show up in the following list (since ``[3]`` does):: - sage: IntegerVectors(3, max_length=2).list() # optional - sage.combinat + sage: IntegerVectors(3, max_length=2).list() [[3], [2, 1], [1, 2], [0, 3]] If ``n`` and ``k`` are both specified, then it returns the class @@ -666,9 +668,9 @@ class IntegerVectors(Parent, metaclass=ClasscallMetaclass): An example showing the same output by using IntegerListsLex:: - sage: IntegerVectors(4, max_length=2).list() # optional - sage.combinat + sage: IntegerVectors(4, max_length=2).list() [[4], [3, 1], [2, 2], [1, 3], [0, 4]] - sage: list(IntegerListsLex(4, max_length=2)) # optional - sage.combinat + sage: list(IntegerListsLex(4, max_length=2)) [[4], [3, 1], [2, 2], [1, 3], [0, 4]] .. SEEALSO:: @@ -1391,12 +1393,12 @@ def __contains__(self, x): """ TESTS:: - sage: [3,2,2,1] in IntegerVectors(8, 4, min_part=1) # optional - sage.combinat + sage: [3,2,2,1] in IntegerVectors(8, 4, min_part=1) # needs sage.combinat True - sage: [3,2,2,1] in IntegerVectors(8, 4, min_part=2) # optional - sage.combinat + sage: [3,2,2,1] in IntegerVectors(8, 4, min_part=2) # needs sage.combinat False - sage: [0,3,0,1,2] in IntegerVectors(6, max_length=3) # optional - sage.combinat + sage: [0,3,0,1,2] in IntegerVectors(6, max_length=3) # needs sage.combinat False """ if isinstance(x, IntegerVector) and x.parent() is self: @@ -1420,17 +1422,17 @@ def cardinality(self): EXAMPLES:: - sage: IntegerVectors(3, 3, min_part=1).cardinality() # optional - sage.combinat + sage: IntegerVectors(3, 3, min_part=1).cardinality() 1 - sage: IntegerVectors(5, 3, min_part=1).cardinality() # optional - sage.combinat + sage: IntegerVectors(5, 3, min_part=1).cardinality() 6 - sage: IntegerVectors(13, 4, max_part=4).cardinality() # optional - sage.combinat + sage: IntegerVectors(13, 4, max_part=4).cardinality() 20 - sage: IntegerVectors(k=4, max_part=3).cardinality() # optional - sage.combinat + sage: IntegerVectors(k=4, max_part=3).cardinality() 256 - sage: IntegerVectors(k=3, min_part=2, max_part=4).cardinality() # optional - sage.combinat + sage: IntegerVectors(k=3, min_part=2, max_part=4).cardinality() 27 - sage: IntegerVectors(13, 4, min_part=2, max_part=4).cardinality() # optional - sage.combinat + sage: IntegerVectors(13, 4, min_part=2, max_part=4).cardinality() 16 """ if self.k is None: diff --git a/src/sage/combinat/interval_posets.py b/src/sage/combinat/interval_posets.py index 2440843bac1..c9f1e99984d 100644 --- a/src/sage/combinat/interval_posets.py +++ b/src/sage/combinat/interval_posets.py @@ -437,13 +437,13 @@ def plot(self, **kwds): EXAMPLES:: sage: ti = TamariIntervalPosets(4)[2] - sage: ti.plot() # optional - sage.plot + sage: ti.plot() # needs sage.plot Graphics object consisting of 6 graphics primitives TESTS:: sage: ti = TamariIntervalPoset(3, [[2,1], [2,3]]) - sage: ti.plot() # optional - sage.plot + sage: ti.plot() # needs sage.plot Graphics object consisting of 6 graphics primitives """ c0 = 'blue' # self.latex_options()["color_increasing"] @@ -611,11 +611,12 @@ def factor(self) -> list[TamariIntervalPoset]: TESTS:: - sage: T = TamariIntervalPosets(20).random_element() # optional - sage.combinat - sage: facs = factor(T) # optional - sage.combinat - sage: all(U.is_connected() for U in facs) # optional - sage.combinat + sage: # needs sage.combinat + sage: T = TamariIntervalPosets(20).random_element() + sage: facs = factor(T) + sage: all(U.is_connected() for U in facs) True - sage: T == prod(facs) # optional - sage.combinat + sage: T == prod(facs) True """ hasse = self.poset().hasse_diagram() @@ -1030,10 +1031,10 @@ def cubical_coordinates(self) -> tuple[int, ...]: sage: ip = TamariIntervalPoset(3,[]) sage: ip.cubical_coordinates() (0, 0) - sage: ip = TamariIntervalPosets(10).random_element() # optional - sage.combinat - sage: len(ip.cubical_coordinates()) # optional - sage.combinat + sage: ip = TamariIntervalPosets(10).random_element() # needs sage.combinat + sage: len(ip.cubical_coordinates()) # needs sage.combinat 9 - sage: sorted(ip.cubical_coordinates() for ip in TamariIntervalPosets(2)) # optional - sage.combinat + sage: sorted(ip.cubical_coordinates() for ip in TamariIntervalPosets(2)) # needs sage.combinat [(-1,), (0,), (1,)] REFERENCES: @@ -1136,7 +1137,7 @@ def rise_contact_involution(self) -> TIP: (4, 3), (3, 2), (2, 1)] sage: t.rise_contact_involution() == tip True - sage: (tip.lower_dyck_word().number_of_touch_points() # optional - sage.combinat + sage: (tip.lower_dyck_word().number_of_touch_points() # needs sage.combinat ....: == t.upper_dyck_word().number_of_initial_rises()) True sage: tip.number_of_tamari_inversions() == t.number_of_tamari_inversions() @@ -1233,7 +1234,7 @@ def insertion(self, i) -> TIP: ....: print(T, i) ....: return False ....: return True - sage: test_equivalence(3) # optional - sage.combinat + sage: test_equivalence(3) # needs sage.combinat True sage: ti = TamariIntervalPosets(3).an_element() @@ -1674,18 +1675,19 @@ def contains_dyck_word(self, dyck_word) -> bool: EXAMPLES:: + sage: # needs sage.combinat sage: ip = TamariIntervalPoset(4,[(2,4),(3,4),(2,1),(3,1)]) - sage: ip.contains_dyck_word(DyckWord([1,1,1,0,0,0,1,0])) # optional - sage.combinat + sage: ip.contains_dyck_word(DyckWord([1,1,1,0,0,0,1,0])) True - sage: ip.contains_dyck_word(DyckWord([1,1,0,1,0,1,0,0])) # optional - sage.combinat + sage: ip.contains_dyck_word(DyckWord([1,1,0,1,0,1,0,0])) True - sage: ip.contains_dyck_word(DyckWord([1,0,1,1,0,1,0,0])) # optional - sage.combinat + sage: ip.contains_dyck_word(DyckWord([1,0,1,1,0,1,0,0])) False - sage: ip.contains_dyck_word(ip.lower_dyck_word()) # optional - sage.combinat + sage: ip.contains_dyck_word(ip.lower_dyck_word()) True - sage: ip.contains_dyck_word(ip.upper_dyck_word()) # optional - sage.combinat + sage: ip.contains_dyck_word(ip.upper_dyck_word()) True - sage: all(ip.contains_dyck_word(bt) for bt in ip.dyck_words()) # optional - sage.combinat + sage: all(ip.contains_dyck_word(bt) for bt in ip.dyck_words()) True """ return self.contains_binary_tree(dyck_word.to_binary_tree_tamari()) @@ -1780,14 +1782,14 @@ def is_initial_interval(self) -> bool: sage: ip = TamariIntervalPoset(4, [(1, 2), (2, 4), (3, 4)]) sage: ip.is_initial_interval() True - sage: ip.lower_dyck_word() # optional - sage.combinat + sage: ip.lower_dyck_word() # needs sage.combinat [1, 0, 1, 0, 1, 0, 1, 0] sage: ip = TamariIntervalPoset(4, [(1, 2), (2, 4), (3, 4), (3, 2)]) sage: ip.is_initial_interval() False - sage: ip.lower_dyck_word() # optional - sage.combinat + sage: ip.lower_dyck_word() # needs sage.combinat [1, 0, 1, 1, 0, 0, 1, 0] - sage: all(DyckWord([1,0,1,0,1,0]).tamari_interval(dw) # optional - sage.combinat + sage: all(DyckWord([1,0,1,0,1,0]).tamari_interval(dw) # needs sage.combinat ....: .is_initial_interval() ....: for dw in DyckWords(3)) True @@ -1810,14 +1812,14 @@ def is_final_interval(self) -> bool: sage: ip = TamariIntervalPoset(4, [(4, 3), (3, 1), (2, 1)]) sage: ip.is_final_interval() True - sage: ip.upper_dyck_word() # optional - sage.combinat + sage: ip.upper_dyck_word() # needs sage.combinat [1, 1, 1, 1, 0, 0, 0, 0] sage: ip = TamariIntervalPoset(4, [(4, 3), (3, 1), (2, 1), (2, 3)]) sage: ip.is_final_interval() False - sage: ip.upper_dyck_word() # optional - sage.combinat + sage: ip.upper_dyck_word() # needs sage.combinat [1, 1, 0, 1, 1, 0, 0, 0] - sage: all(dw.tamari_interval(DyckWord([1, 1, 1, 0, 0, 0])) # optional - sage.combinat + sage: all(dw.tamari_interval(DyckWord([1, 1, 1, 0, 0, 0])) # needs sage.combinat ....: .is_final_interval() ....: for dw in DyckWords(3)) True @@ -1859,15 +1861,16 @@ def lower_dyck_word(self): EXAMPLES:: + sage: # needs sage.combinat sage: ip = TamariIntervalPoset(6, [(3,2),(4,3),(5,2),(6,5),(1,2),(4,5)]); ip The Tamari interval of size 6 induced by relations [(1, 2), (4, 5), (6, 5), (5, 2), (4, 3), (3, 2)] - sage: ip.lower_dyck_word() # optional - sage.combinat + sage: ip.lower_dyck_word() [1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0] - sage: ldw_ff = TamariIntervalPosets.final_forest(ip.lower_dyck_word()) # optional - sage.combinat - sage: ldw_ff == ip.final_forest() # optional - sage.combinat + sage: ldw_ff = TamariIntervalPosets.final_forest(ip.lower_dyck_word()) + sage: ldw_ff == ip.final_forest() True - sage: ip == TamariIntervalPosets.from_dyck_words(ip.lower_dyck_word(), # optional - sage.combinat + sage: ip == TamariIntervalPosets.from_dyck_words(ip.lower_dyck_word(), ....: ip.upper_dyck_word()) True """ @@ -1908,15 +1911,16 @@ def upper_dyck_word(self): EXAMPLES:: + sage: # needs sage.combinat sage: ip = TamariIntervalPoset(6,[(3,2),(4,3),(5,2),(6,5),(1,2),(4,5)]); ip The Tamari interval of size 6 induced by relations [(1, 2), (4, 5), (6, 5), (5, 2), (4, 3), (3, 2)] - sage: ip.upper_dyck_word() # optional - sage.combinat + sage: ip.upper_dyck_word() [1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0] - sage: udw_if = TamariIntervalPosets.initial_forest(ip.upper_dyck_word()) # optional - sage.combinat - sage: udw_if == ip.initial_forest() # optional - sage.combinat + sage: udw_if = TamariIntervalPosets.initial_forest(ip.upper_dyck_word()) + sage: udw_if == ip.initial_forest() True - sage: ip == TamariIntervalPosets.from_dyck_words(ip.lower_dyck_word(), # optional - sage.combinat + sage: ip == TamariIntervalPosets.from_dyck_words(ip.lower_dyck_word(), ....: ip.upper_dyck_word()) True """ @@ -2086,10 +2090,10 @@ def linear_extensions(self) -> Iterator[Permutation]: EXAMPLES:: sage: ip = TamariIntervalPoset(3, [(1,2),(3,2)]) - sage: list(ip.linear_extensions()) # optional - sage.rings.finite_rings sage.modules + sage: list(ip.linear_extensions()) # needs sage.modules sage.rings.finite_rings [[3, 1, 2], [1, 3, 2]] sage: ip = TamariIntervalPoset(4, [(1,2),(2,3),(4,3)]) - sage: list(ip.linear_extensions()) # optional - sage.rings.finite_rings sage.modules + sage: list(ip.linear_extensions()) # needs sage.modules sage.rings.finite_rings [[4, 1, 2, 3], [1, 2, 4, 3], [1, 4, 2, 3]] """ for ext in self._poset.linear_extensions(): @@ -2226,12 +2230,12 @@ def dyck_words(self) -> Iterator: EXAMPLES:: - sage: list(TamariIntervalPoset(4,[(2,4),(3,4),(2,1),(3,1)]).dyck_words()) # optional - sage.combinat + sage: list(TamariIntervalPoset(4,[(2,4),(3,4),(2,1),(3,1)]).dyck_words()) # needs sage.combinat [[1, 1, 1, 0, 0, 1, 0, 0], [1, 1, 1, 0, 0, 0, 1, 0], [1, 1, 0, 1, 0, 1, 0, 0], [1, 1, 0, 1, 0, 0, 1, 0]] - sage: set(TamariIntervalPoset(4,[]).dyck_words()) == set(DyckWords(4)) # optional - sage.combinat + sage: set(TamariIntervalPoset(4,[]).dyck_words()) == set(DyckWords(4)) # needs sage.combinat True """ for ip in self.lower_contained_intervals(): @@ -2308,10 +2312,10 @@ def maximal_chain_dyck_words(self) -> Iterator: EXAMPLES:: sage: ip = TamariIntervalPoset(4,[(2,4),(3,4),(2,1),(3,1)]) - sage: list(ip.maximal_chain_dyck_words()) # optional - sage.combinat + sage: list(ip.maximal_chain_dyck_words()) # needs sage.combinat [[1, 1, 0, 1, 0, 0, 1, 0], [1, 1, 0, 1, 0, 1, 0, 0], [1, 1, 1, 0, 0, 1, 0, 0]] sage: ip = TamariIntervalPoset(4,[]) - sage: list(ip.maximal_chain_dyck_words()) # optional - sage.combinat + sage: list(ip.maximal_chain_dyck_words()) # needs sage.combinat [[1, 0, 1, 0, 1, 0, 1, 0], [1, 1, 0, 0, 1, 0, 1, 0], [1, 1, 0, 1, 0, 0, 1, 0], @@ -2377,11 +2381,11 @@ def tamari_inversions(self) -> list[tuple[int, int]]: sage: ip = TamariIntervalPoset(4,[]) sage: ip.tamari_inversions() [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)] - sage: all(not TamariIntervalPosets.from_binary_trees(bt,bt) # optional - sage.combinat + sage: all(not TamariIntervalPosets.from_binary_trees(bt,bt) # needs sage.combinat ....: .tamari_inversions() ....: for bt in BinaryTrees(3)) True - sage: all(not TamariIntervalPosets.from_binary_trees(bt,bt) # optional - sage.combinat + sage: all(not TamariIntervalPosets.from_binary_trees(bt,bt) # needs sage.combinat ....: .tamari_inversions() ....: for bt in BinaryTrees(4)) True @@ -2504,18 +2508,19 @@ def new_decomposition(self) -> list[TIP]: sage: ex = TamariIntervalPosets(4)[11] sage: ex.number_of_new_components() 3 - sage: ex.new_decomposition() # optional - sage.combinat + sage: ex.new_decomposition() # needs sage.combinat [The Tamari interval of size 1 induced by relations [], The Tamari interval of size 2 induced by relations [], The Tamari interval of size 1 induced by relations []] TESTS:: - sage: ex = TamariIntervalPosets(4).random_element() # optional - sage.combinat - sage: dec = ex.new_decomposition() # optional - sage.combinat - sage: len(dec) == ex.number_of_new_components() # optional - sage.combinat + sage: # needs sage.combinat + sage: ex = TamariIntervalPosets(4).random_element() + sage: dec = ex.new_decomposition() + sage: len(dec) == ex.number_of_new_components() True - sage: all(u.is_new() for u in dec) # optional - sage.combinat + sage: all(u.is_new() for u in dec) True """ from sage.combinat.binary_tree import BinaryTree @@ -3036,11 +3041,12 @@ def final_forest(element) -> TIP: From Dyck words:: - sage: dw = DyckWord([1,0]) # optional - sage.combinat - sage: TamariIntervalPosets.final_forest(dw) # optional - sage.combinat + sage: # needs sage.combinat + sage: dw = DyckWord([1,0]) + sage: TamariIntervalPosets.final_forest(dw) The Tamari interval of size 1 induced by relations [] - sage: dw = DyckWord([1,1,0,1,0,0,1,1,0,0]) # optional - sage.combinat - sage: TamariIntervalPosets.final_forest(dw) # optional - sage.combinat + sage: dw = DyckWord([1,1,0,1,0,0,1,1,0,0]) + sage: TamariIntervalPosets.final_forest(dw) The Tamari interval of size 5 induced by relations [(5, 4), (3, 1), (2, 1)] TESTS:: @@ -3149,11 +3155,12 @@ def initial_forest(element) -> TIP: from Dyck words:: - sage: dw = DyckWord([1,0]) # optional - sage.combinat - sage: TamariIntervalPosets.initial_forest(dw) # optional - sage.combinat + sage: # needs sage.combinat + sage: dw = DyckWord([1,0]) + sage: TamariIntervalPosets.initial_forest(dw) The Tamari interval of size 1 induced by relations [] - sage: dw = DyckWord([1,1,0,1,0,0,1,1,0,0]) # optional - sage.combinat - sage: TamariIntervalPosets.initial_forest(dw) # optional - sage.combinat + sage: dw = DyckWord([1,1,0,1,0,0,1,1,0,0]) + sage: TamariIntervalPosets.initial_forest(dw) The Tamari interval of size 5 induced by relations [(1, 4), (2, 3), (3, 4)] TESTS:: @@ -3274,27 +3281,28 @@ def from_dyck_words(dw1, dw2) -> TIP: EXAMPLES:: - sage: dw1 = DyckWord([1,0,1,0]) # optional - sage.combinat - sage: dw2 = DyckWord([1,1,0,0]) # optional - sage.combinat - sage: TamariIntervalPosets.from_dyck_words(dw1, dw2) # optional - sage.combinat + sage: # needs sage.combinat + sage: dw1 = DyckWord([1,0,1,0]) + sage: dw2 = DyckWord([1,1,0,0]) + sage: TamariIntervalPosets.from_dyck_words(dw1, dw2) The Tamari interval of size 2 induced by relations [] - sage: TamariIntervalPosets.from_dyck_words(dw1,dw1) # optional - sage.combinat + sage: TamariIntervalPosets.from_dyck_words(dw1,dw1) The Tamari interval of size 2 induced by relations [(1, 2)] - sage: TamariIntervalPosets.from_dyck_words(dw2,dw2) # optional - sage.combinat + sage: TamariIntervalPosets.from_dyck_words(dw2,dw2) The Tamari interval of size 2 induced by relations [(2, 1)] - sage: dw1 = DyckWord([1,0,1,1,1,0,0,1,1,0,0,0]) # optional - sage.combinat - sage: dw2 = DyckWord([1,1,1,1,0,1,1,0,0,0,0,0]) # optional - sage.combinat - sage: TamariIntervalPosets.from_dyck_words(dw1,dw2) # optional - sage.combinat + sage: # needs sage.combinat + sage: dw1 = DyckWord([1,0,1,1,1,0,0,1,1,0,0,0]) + sage: dw2 = DyckWord([1,1,1,1,0,1,1,0,0,0,0,0]) + sage: TamariIntervalPosets.from_dyck_words(dw1,dw2) The Tamari interval of size 6 induced by relations [(4, 5), (6, 5), (5, 2), (4, 3), (3, 2)] - - sage: dw3 = DyckWord([1,1,1,0,1,1,1,0,0,0,0,0]) # optional - sage.combinat - sage: TamariIntervalPosets.from_dyck_words(dw1,dw3) # optional - sage.combinat + sage: dw3 = DyckWord([1,1,1,0,1,1,1,0,0,0,0,0]) + sage: TamariIntervalPosets.from_dyck_words(dw1,dw3) Traceback (most recent call last): ... ValueError: the two Dyck words are not comparable on the Tamari lattice - sage: TamariIntervalPosets.from_dyck_words(dw1,DyckWord([1,0])) # optional - sage.combinat + sage: TamariIntervalPosets.from_dyck_words(dw1,DyckWord([1,0])) Traceback (most recent call last): ... ValueError: the two Dyck words are not comparable on the Tamari lattice @@ -3403,7 +3411,7 @@ def from_minimal_schnyder_wood(graph) -> TIP: sage: TIP = TamariIntervalPosets sage: G = DiGraph([(0,-1,0),(0,-2,1),(0,-3,2)], format='list_of_edges') sage: G.set_embedding({-1:[0],-2:[0],-3:[0],0:[-1,-2,-3]}) - sage: TIP.from_minimal_schnyder_wood(G) # optional - sage.combinat + sage: TIP.from_minimal_schnyder_wood(G) # needs sage.combinat The Tamari interval of size 1 induced by relations [] An example from page 14 of [BeBo2009]_:: @@ -3421,7 +3429,7 @@ def from_minimal_schnyder_wood(graph) -> TIP: sage: for k in range(6): ....: embed[k] = data_emb[k] sage: G.set_embedding(embed) - sage: TIP.from_minimal_schnyder_wood(G) # optional - sage.combinat + sage: TIP.from_minimal_schnyder_wood(G) # needs sage.combinat The Tamari interval of size 6 induced by relations [(1, 4), (2, 4), (3, 4), (5, 6), (6, 4), (5, 4), (3, 1), (2, 1)] @@ -3440,7 +3448,7 @@ def from_minimal_schnyder_wood(graph) -> TIP: sage: for k in range(6): ....: embed[k] = data_emb[k] sage: G.set_embedding(embed) - sage: TIP.from_minimal_schnyder_wood(G) # optional - sage.combinat + sage: TIP.from_minimal_schnyder_wood(G) # needs sage.combinat The Tamari interval of size 6 induced by relations [(1, 3), (2, 3), (4, 5), (5, 3), (4, 3), (2, 1)] @@ -3458,7 +3466,7 @@ def from_minimal_schnyder_wood(graph) -> TIP: sage: for k in range(3): ....: embed[k] = data_emb[k] sage: G.set_embedding(embed) - sage: TIP.from_minimal_schnyder_wood(G) # optional - sage.combinat + sage: TIP.from_minimal_schnyder_wood(G) # needs sage.combinat The Tamari interval of size 3 induced by relations [(2, 3), (2, 1)] """ from sage.combinat.dyck_word import DyckWord @@ -3822,14 +3830,15 @@ def random_element(self) -> TIP: EXAMPLES:: - sage: T = TamariIntervalPosets(4).random_element() # optional - sage.combinat - sage: T.parent() # optional - sage.combinat + sage: # needs sage.combinat + sage: T = TamariIntervalPosets(4).random_element() + sage: T.parent() Interval-posets - sage: u = T.lower_dyck_word(); u # random # optional - sage.combinat + sage: u = T.lower_dyck_word(); u # random [1, 1, 0, 1, 0, 0, 1, 0] - sage: v = T.lower_dyck_word(); v # random # optional - sage.combinat + sage: v = T.lower_dyck_word(); v # random [1, 1, 0, 1, 0, 0, 1, 0] - sage: len(u) # optional - sage.combinat + sage: len(u) 8 """ from sage.graphs.schnyder import minimal_schnyder_wood diff --git a/src/sage/combinat/matrices/dancing_links.pyx b/src/sage/combinat/matrices/dancing_links.pyx index f0ecfeacd17..99dc42b3477 100644 --- a/src/sage/combinat/matrices/dancing_links.pyx +++ b/src/sage/combinat/matrices/dancing_links.pyx @@ -920,11 +920,11 @@ cdef class dancing_linksWrapper: sage: from sage.combinat.matrices.dancing_links import dlx_solver sage: rows = [[0,1,2], [0,2], [1], [3]] sage: x = dlx_solver(rows) - sage: s = x.to_sat_solver() + sage: s = x.to_sat_solver() # needs sage.sat Using some optional SAT solvers:: - sage: x.to_sat_solver('cryptominisat') # optional - pycryptosat + sage: x.to_sat_solver('cryptominisat') # optional - pycryptosat # needs sage.sat CryptoMiniSat solver: 4 variables, 7 clauses. """ @@ -979,20 +979,20 @@ cdef class dancing_linksWrapper: sage: rows = [[0,1,2], [3,4,5], [0,1], [2,3,4,5], [0], [1,2,3,4,5]] sage: d = dlx_solver(rows) sage: solutions = [[0,1], [2,3], [4,5]] - sage: d.one_solution_using_sat_solver() in solutions + sage: d.one_solution_using_sat_solver() in solutions # needs sage.sat True Using optional solvers:: - sage: s = d.one_solution_using_sat_solver('glucose') # optional - glucose - sage: s in solutions # optional - glucose + sage: s = d.one_solution_using_sat_solver('glucose') # optional - glucose, needs sage.sat + sage: s in solutions # optional - glucose, needs sage.sat True When no solution is found:: sage: rows = [[0,1,2], [2,3,4,5], [0,1,2,3]] sage: d = dlx_solver(rows) - sage: d.one_solution_using_sat_solver() is None + sage: d.one_solution_using_sat_solver() is None # needs sage.sat True """ sat_solver = self.to_sat_solver(solver) @@ -1026,16 +1026,16 @@ cdef class dancing_linksWrapper: sage: from sage.combinat.matrices.dancing_links import dlx_solver sage: rows = [[0,1,2], [0,2], [1], [3]] sage: d = dlx_solver(rows) - sage: p,x = d.to_milp() - sage: p + sage: p,x = d.to_milp() # needs sage.numerical.mip + sage: p # needs sage.numerical.mip Boolean Program (no objective, 4 variables, ... constraints) - sage: x + sage: x # needs sage.numerical.mip MIPVariable with 4 binary components In the reduction, the boolean variable x_i is True if and only if the i-th row is in the solution:: - sage: p.show() + sage: p.show() # needs sage.numerical.mip Maximization: @@ -1052,7 +1052,7 @@ cdef class dancing_linksWrapper: Using some optional MILP solvers:: - sage: d.to_milp('gurobi') # optional - gurobi sage_numerical_backends_gurobi + sage: d.to_milp('gurobi') # optional - gurobi sage_numerical_backends_gurobi, needs sage.numerical.mip (Boolean Program (no objective, 4 variables, 4 constraints), MIPVariable with 4 binary components) @@ -1106,20 +1106,21 @@ cdef class dancing_linksWrapper: sage: rows = [[0,1,2], [3,4,5], [0,1], [2,3,4,5], [0], [1,2,3,4,5]] sage: d = dlx_solver(rows) sage: solutions = [[0,1], [2,3], [4,5]] - sage: d.one_solution_using_milp_solver() in solutions + sage: d.one_solution_using_milp_solver() in solutions # needs sage.numerical.mip True Using optional solvers:: - sage: s = d.one_solution_using_milp_solver('gurobi') # optional - gurobi sage_numerical_backends_gurobi - sage: s in solutions # optional - gurobi sage_numerical_backends_gurobi + sage: # optional - gurobi sage_numerical_backends_gurobi, needs sage.numerical.mip + sage: s = d.one_solution_using_milp_solver('gurobi') + sage: s in solutions True When no solution is found:: sage: rows = [[0,1,2], [2,3,4,5], [0,1,2,3]] sage: d = dlx_solver(rows) - sage: d.one_solution_using_milp_solver() is None + sage: d.one_solution_using_milp_solver() is None # needs sage.numerical.mip True """ from sage.numerical.mip import MIPSolverException diff --git a/src/sage/combinat/matrices/dlxcpp.py b/src/sage/combinat/matrices/dlxcpp.py index fce16e7d2ad..3cdc3774d76 100644 --- a/src/sage/combinat/matrices/dlxcpp.py +++ b/src/sage/combinat/matrices/dlxcpp.py @@ -94,14 +94,14 @@ def AllExactCovers(M): EXAMPLES: No exact covers:: - sage: M = Matrix([[1,1,0],[1,0,1],[0,1,1]]) # optional - sage.modules - sage: [cover for cover in AllExactCovers(M)] # optional - sage.modules + sage: M = Matrix([[1,1,0],[1,0,1],[0,1,1]]) # needs sage.modules + sage: [cover for cover in AllExactCovers(M)] # needs sage.modules [] Two exact covers:: - sage: M = Matrix([[1,1,0],[1,0,1],[0,0,1],[0,1,0]]) # optional - sage.modules - sage: [cover for cover in AllExactCovers(M)] # optional - sage.modules + sage: M = Matrix([[1,1,0],[1,0,1],[0,0,1],[0,1,0]]) # needs sage.modules + sage: [cover for cover in AllExactCovers(M)] # needs sage.modules [[(1, 1, 0), (0, 0, 1)], [(1, 0, 1), (0, 1, 0)]] """ rows = [] @@ -122,11 +122,12 @@ def OneExactCover(M): EXAMPLES:: - sage: M = Matrix([[1,1,0],[1,0,1],[0,1,1]]) # no exact covers # optional - sage.modules - sage: print(OneExactCover(M)) # optional - sage.modules + sage: # needs sage.modules + sage: M = Matrix([[1,1,0],[1,0,1],[0,1,1]]) # no exact covers + sage: print(OneExactCover(M)) None - sage: M = Matrix([[1,1,0],[1,0,1],[0,0,1],[0,1,0]]) # two exact covers # optional - sage.modules - sage: OneExactCover(M) # optional - sage.modules + sage: M = Matrix([[1,1,0],[1,0,1],[0,0,1],[0,1,0]]) # two exact covers + sage: OneExactCover(M) [(1, 1, 0), (0, 0, 1)] """ diff --git a/src/sage/combinat/multiset_partition_into_sets_ordered.py b/src/sage/combinat/multiset_partition_into_sets_ordered.py index 7bcdfbb92a5..a8855beb412 100755 --- a/src/sage/combinat/multiset_partition_into_sets_ordered.py +++ b/src/sage/combinat/multiset_partition_into_sets_ordered.py @@ -45,7 +45,7 @@ Crystal of ordered multiset partitions into sets on the alphabet `\{1,2,3\}` with 4 letters divided into 2 blocks:: - sage: crystals.Minimaj(3, 4, 2).list() # optional - sage.modules + sage: crystals.Minimaj(3, 4, 2).list() # needs sage.modules [((2, 3, 1), (1,)), ((2, 3), (1, 2)), ((2, 3), (1, 3)), ((2, 1), (1, 2)), ((3, 1), (1, 2)), ((3, 1, 2), (2,)), ((3, 1), (1, 3)), ((3, 1), (2, 3)), ((3, 2), (2, 3)), ((2, 1), (1, 3)), ((2,), (1, 2, 3)), ((3,), (1, 2, 3)), @@ -3197,14 +3197,14 @@ class MinimajCrystal(UniqueRepresentation, Parent): EXAMPLES:: - sage: list(crystals.Minimaj(2,3,2)) # optional - sage.modules + sage: list(crystals.Minimaj(2,3,2)) # needs sage.modules [((2, 1), (1,)), ((2,), (1, 2)), ((1,), (1, 2)), ((1, 2), (2,))] - sage: b = crystals.Minimaj(3, 5, 2).an_element(); b # optional - sage.modules + sage: b = crystals.Minimaj(3, 5, 2).an_element(); b # needs sage.modules ((2, 3, 1), (1, 2)) - sage: b.f(2) # optional - sage.modules + sage: b.f(2) # needs sage.modules ((2, 3, 1), (1, 3)) - sage: b.e(2) # optional - sage.modules + sage: b.e(2) # needs sage.modules """ def __init__(self, n, ell, k): @@ -3213,17 +3213,16 @@ def __init__(self, n, ell, k): TESTS:: - sage: B = crystals.Minimaj(2,3,2) # optional - sage.modules - sage: TestSuite(B).run() # optional - sage.modules - - sage: B = crystals.Minimaj(3, 5, 2) # optional - sage.modules - sage: TestSuite(B).run() # optional - sage.modules - - sage: list(crystals.Minimaj(2,6,3)) # optional - sage.modules + sage: # needs sage.modules + sage: B = crystals.Minimaj(2,3,2) + sage: TestSuite(B).run() + sage: B = crystals.Minimaj(3, 5, 2) + sage: TestSuite(B).run() + sage: list(crystals.Minimaj(2,6,3)) [((1, 2), (2, 1), (1, 2))] - sage: list(crystals.Minimaj(2,5,2)) # blocks too fat for alphabet # optional - sage.modules + sage: list(crystals.Minimaj(2,5,2)) # blocks too fat for alphabet [] - sage: list(crystals.Minimaj(4,2,3)) # more blocks than letters # optional - sage.modules + sage: list(crystals.Minimaj(4,2,3)) # more blocks than letters Traceback (most recent call last): ... ValueError: n (=4), ell (=2), and k (=3) must all be positive integers @@ -3256,7 +3255,7 @@ def _repr_(self): EXAMPLES:: - sage: B = crystals.Minimaj(3,4,2); B # optional - sage.modules + sage: B = crystals.Minimaj(3,4,2); B # needs sage.modules Minimaj Crystal of type A_2 of words of length 4 into 2 blocks """ return ("Minimaj Crystal of type A_%s of words of length %s into %s blocks" @@ -3268,14 +3267,15 @@ def _an_element_(self): EXAMPLES:: - sage: B = crystals.Minimaj(4,5,3) # optional - sage.modules - sage: B.an_element() # optional - sage.modules + sage: # needs sage.modules + sage: B = crystals.Minimaj(4,5,3) + sage: B.an_element() ((2, 3, 1), (1,), (1,)) - sage: B = crystals.Minimaj(2,2,1) # optional - sage.modules - sage: B.an_element() # optional - sage.modules + sage: B = crystals.Minimaj(2,2,1) + sage: B.an_element() ((1, 2),) - sage: B = crystals.Minimaj(1,2,1) # optional - sage.modules - sage: B.an_element() # optional - sage.modules + sage: B = crystals.Minimaj(1,2,1) + sage: B.an_element() Traceback (most recent call last): ... EmptySetError @@ -3291,14 +3291,15 @@ def _element_constructor_(self, x): EXAMPLES:: - sage: B1 = crystals.Minimaj(4,5,3); b = B1.an_element(); b # optional - sage.modules + sage: # needs sage.modules + sage: B1 = crystals.Minimaj(4,5,3); b = B1.an_element(); b ((2, 3, 1), (1,), (1,)) - sage: B1._element_constructor_(list(b)) # optional - sage.modules + sage: B1._element_constructor_(list(b)) ((2, 3, 1), (1,), (1,)) - sage: B1._element_constructor_([[1,2,3], [2], [2]]) # optional - sage.modules + sage: B1._element_constructor_([[1,2,3], [2], [2]]) ((3, 1, 2), (2,), (2,)) - sage: B2 = crystals.Minimaj(5,5,3) # optional - sage.modules - sage: B2._element_constructor_(b) # optional - sage.modules + sage: B2 = crystals.Minimaj(5,5,3) + sage: B2._element_constructor_(b) ((2, 3, 1), (1,), (1,)) """ # Allow ``x`` to be either of: @@ -3322,17 +3323,18 @@ def __contains__(self, x): EXAMPLES:: - sage: B1 = crystals.Minimaj(2,5,3); b1 = B1.an_element(); b1 # optional - sage.modules + sage: # needs sage.modules + sage: B1 = crystals.Minimaj(2,5,3); b1 = B1.an_element(); b1 ((1, 2), (2, 1), (1,)) - sage: B2 = crystals.Minimaj(5,5,3); b2 = B2.an_element(); b2 # optional - sage.modules + sage: B2 = crystals.Minimaj(5,5,3); b2 = B2.an_element(); b2 ((2, 3, 1), (1,), (1,)) - sage: b2a = B2(((1,2), (1,), (1,2))); b2a # optional - sage.modules + sage: b2a = B2(((1,2), (1,), (1,2))); b2a ((2, 1), (1,), (1, 2)) - sage: b1 in B2 # optional - sage.modules + sage: b1 in B2 True - sage: b2 in B1 # optional - sage.modules + sage: b2 in B1 False - sage: b2a in B1 # optional - sage.modules + sage: b2a in B1 True """ if isinstance(x, MinimajCrystal.Element): @@ -3353,24 +3355,26 @@ def from_tableau(self, t): EXAMPLES:: - sage: B = crystals.Minimaj(3,6,3) # optional - sage.modules - sage: b = B.an_element(); b # optional - sage.modules + sage: # needs sage.modules + sage: B = crystals.Minimaj(3,6,3) + sage: b = B.an_element(); b ((3, 1, 2), (2, 1), (1,)) - sage: t = b.to_tableaux_words(); t # optional - sage.modules + sage: t = b.to_tableaux_words(); t [[1], [2, 1], [], [3, 2, 1]] - sage: B.from_tableau(t) # optional - sage.modules + sage: B.from_tableau(t) ((3, 1, 2), (2, 1), (1,)) - sage: B.from_tableau(t) == b # optional - sage.modules + sage: B.from_tableau(t) == b True TESTS:: - sage: B = crystals.Minimaj(3,6,3) # optional - sage.modules - sage: all(mu == B.from_tableau(mu.to_tableaux_words()) for mu in B) # optional - sage.modules + sage: # needs sage.modules + sage: B = crystals.Minimaj(3,6,3) + sage: all(mu == B.from_tableau(mu.to_tableaux_words()) for mu in B) True - sage: t = B.an_element().to_tableaux_words() # optional - sage.modules - sage: B1 = crystals.Minimaj(3,6,2) # optional - sage.modules - sage: B1.from_tableau(t) # optional - sage.modules + sage: t = B.an_element().to_tableaux_words() + sage: B1 = crystals.Minimaj(3,6,2) + sage: B1.from_tableau(t) Traceback (most recent call last): ... ValueError: ((3, 1, 2), (2, 1), (1,)) is not an element of @@ -3390,8 +3394,8 @@ def val(self, q='q'): Verifying Example 4.5 from [BCHOPSY2017]_:: - sage: B = crystals.Minimaj(3, 4, 2) # for `Val_{4,1}^{(3)}` # optional - sage.modules - sage: B.val() # optional - sage.modules + sage: B = crystals.Minimaj(3, 4, 2) # for `Val_{4,1}^{(3)}` # needs sage.modules + sage: B.val() # needs sage.modules (q^2+q+1)*s[2, 1, 1] + q*s[2, 2] """ H = [self._OMPs(list(b)) for b in self.highest_weight_vectors()] @@ -3425,7 +3429,7 @@ def _repr_(self): EXAMPLES:: - sage: crystals.Minimaj(4,5,3).an_element() # optional - sage.modules + sage: crystals.Minimaj(4,5,3).an_element() # needs sage.modules ((2, 3, 1), (1,), (1,)) """ return repr(self._minimaj_blocks_from_word_pair()) @@ -3436,11 +3440,11 @@ def __iter__(self): EXAMPLES:: - sage: b = crystals.Minimaj(4,5,3).an_element(); b # optional - sage.modules + sage: b = crystals.Minimaj(4,5,3).an_element(); b # needs sage.modules ((2, 3, 1), (1,), (1,)) - sage: b.value # optional - sage.modules + sage: b.value # needs sage.modules ([1, 3, 2, 1, 1], (0, 1, 2, 5)) - sage: list(b) # optional - sage.modules + sage: list(b) # needs sage.modules [(2, 3, 1), (1,), (1,)] """ return self._minimaj_blocks_from_word_pair().__iter__() @@ -3451,9 +3455,9 @@ def _latex_(self): EXAMPLES:: - sage: b = crystals.Minimaj(4,5,3).an_element(); b # optional - sage.modules + sage: b = crystals.Minimaj(4,5,3).an_element(); b # needs sage.modules ((2, 3, 1), (1,), (1,)) - sage: latex(b) # optional - sage.modules + sage: latex(b) # needs sage.modules \left(\left(2, 3, 1\right), \left(1\right), \left(1\right)\right) """ return latex(self._minimaj_blocks_from_word_pair()) @@ -3465,10 +3469,10 @@ def _minimaj_blocks_from_word_pair(self): EXAMPLES:: - sage: B = crystals.Minimaj(4,5,3) # optional - sage.modules - sage: b = B.an_element(); b.value # optional - sage.modules + sage: B = crystals.Minimaj(4,5,3) # needs sage.modules + sage: b = B.an_element(); b.value # needs sage.modules ([1, 3, 2, 1, 1], (0, 1, 2, 5)) - sage: b._minimaj_blocks_from_word_pair() # optional - sage.modules + sage: b._minimaj_blocks_from_word_pair() # needs sage.modules ((2, 3, 1), (1,), (1,)) """ return _to_minimaj_blocks(self.to_tableaux_words()) @@ -3480,15 +3484,15 @@ def to_tableaux_words(self): EXAMPLES:: - sage: B = crystals.Minimaj(4,5,3) # optional - sage.modules - sage: b = B.an_element(); b # optional - sage.modules + sage: # needs sage.modules + sage: B = crystals.Minimaj(4,5,3) + sage: b = B.an_element(); b ((2, 3, 1), (1,), (1,)) - sage: b.to_tableaux_words() # optional - sage.modules + sage: b.to_tableaux_words() [[1], [3], [2, 1, 1]] - - sage: b = B([[1,3,4], [3], [3]]); b # optional - sage.modules + sage: b = B([[1,3,4], [3], [3]]); b ((4, 1, 3), (3,), (3,)) - sage: b.to_tableaux_words() # optional - sage.modules + sage: b.to_tableaux_words() [[3, 1], [], [4, 3, 3]] """ w, breaks = self.value @@ -3501,10 +3505,10 @@ def e(self, i): EXAMPLES:: - sage: B = crystals.Minimaj(4,3,2) # optional - sage.modules - sage: b = B([[2,3], [3]]); b # optional - sage.modules + sage: B = crystals.Minimaj(4,3,2) # needs sage.modules + sage: b = B([[2,3], [3]]); b # needs sage.modules ((2, 3), (3,)) - sage: [b.e(i) for i in range(1,4)] # optional - sage.modules + sage: [b.e(i) for i in range(1,4)] # needs sage.modules [((1, 3), (3,)), ((2,), (2, 3)), None] """ P = self.parent() @@ -3520,10 +3524,10 @@ def f(self,i): EXAMPLES:: - sage: B = crystals.Minimaj(4,3,2) # optional - sage.modules - sage: b = B([[2,3], [3]]); b # optional - sage.modules + sage: B = crystals.Minimaj(4,3,2) # needs sage.modules + sage: b = B([[2,3], [3]]); b # needs sage.modules ((2, 3), (3,)) - sage: [b.f(i) for i in range(1,4)] # optional - sage.modules + sage: [b.f(i) for i in range(1,4)] # needs sage.modules [None, None, ((2, 3), (4,))] """ P = self.parent() diff --git a/src/sage/combinat/necklace.py b/src/sage/combinat/necklace.py index 32d345c7e11..0a2ad690c34 100644 --- a/src/sage/combinat/necklace.py +++ b/src/sage/combinat/necklace.py @@ -212,7 +212,7 @@ def cardinality(self) -> Integer: sage: comps = [[],[2,2],[3,2,7],[4,2],[0,4,2],[2,0,4]]+Compositions(4).list() sage: ns = [Necklaces(comp) for comp in comps] - sage: all(n.cardinality() == len(n.list()) for n in ns) + sage: all(n.cardinality() == len(n.list()) for n in ns) # needs sage.libs.pari True """ evaluation = self._content diff --git a/src/sage/combinat/nu_dyck_word.py b/src/sage/combinat/nu_dyck_word.py index 213fb05efc0..ddc54a03612 100644 --- a/src/sage/combinat/nu_dyck_word.py +++ b/src/sage/combinat/nu_dyck_word.py @@ -873,7 +873,7 @@ def plot(self, **kwds): EXAMPLES:: sage: NDW = NuDyckWord('010','010') - sage: NDW.plot() # optional - sage.plot + sage: NDW.plot() # needs sage.plot Graphics object consisting of 1 graphics primitive """ from sage.plot.plot import list_plot diff --git a/src/sage/combinat/ordered_tree.py b/src/sage/combinat/ordered_tree.py index 0b2fa87e3c7..59f4a4ad115 100644 --- a/src/sage/combinat/ordered_tree.py +++ b/src/sage/combinat/ordered_tree.py @@ -359,21 +359,22 @@ def to_parallelogram_polyomino(self, bijection=None): EXAMPLES:: + sage: # needs sage.combinat sage.modules sage: T = OrderedTree([[[], [[], [[]]]], [], [[[],[]]], [], []]) - sage: T.to_parallelogram_polyomino(bijection='Boussicault-Socci') # optional - sage.combinat + sage: T.to_parallelogram_polyomino(bijection='Boussicault-Socci') [[0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1], [1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0]] sage: T = OrderedTree( [] ) - sage: T.to_parallelogram_polyomino() # optional - sage.combinat + sage: T.to_parallelogram_polyomino() [[1], [1]] sage: T = OrderedTree( [[]] ) - sage: T.to_parallelogram_polyomino() # optional - sage.combinat + sage: T.to_parallelogram_polyomino() [[0, 1], [1, 0]] sage: T = OrderedTree( [[],[]] ) - sage: T.to_parallelogram_polyomino() # optional - sage.combinat + sage: T.to_parallelogram_polyomino() [[0, 1, 1], [1, 1, 0]] sage: T = OrderedTree( [[[]]] ) - sage: T.to_parallelogram_polyomino() # optional - sage.combinat + sage: T.to_parallelogram_polyomino() [[0, 0, 1], [1, 0, 0]] """ if (bijection is None) or (bijection == 'Boussicault-Socci'): @@ -389,22 +390,23 @@ def _to_parallelogram_polyomino_Boussicault_Socci(self): EXAMPLES:: + sage: # needs sage.combinat sage.modules sage: T = OrderedTree( ....: [[[], [[], [[]]]], [], [[[],[]]], [], []] ....: ) - sage: T._to_parallelogram_polyomino_Boussicault_Socci() # optional - sage.combinat + sage: T._to_parallelogram_polyomino_Boussicault_Socci() [[0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1], [1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0]] sage: T = OrderedTree( [] ) - sage: T._to_parallelogram_polyomino_Boussicault_Socci() # optional - sage.combinat + sage: T._to_parallelogram_polyomino_Boussicault_Socci() [[1], [1]] sage: T = OrderedTree( [[]] ) - sage: T._to_parallelogram_polyomino_Boussicault_Socci() # optional - sage.combinat + sage: T._to_parallelogram_polyomino_Boussicault_Socci() [[0, 1], [1, 0]] sage: T = OrderedTree( [[],[]] ) - sage: T._to_parallelogram_polyomino_Boussicault_Socci() # optional - sage.combinat + sage: T._to_parallelogram_polyomino_Boussicault_Socci() [[0, 1, 1], [1, 1, 0]] sage: T = OrderedTree( [[[]]] ) - sage: T._to_parallelogram_polyomino_Boussicault_Socci() # optional - sage.combinat + sage: T._to_parallelogram_polyomino_Boussicault_Socci() [[0, 0, 1], [1, 0, 0]] """ from sage.combinat.parallelogram_polyomino import ParallelogramPolyomino @@ -501,13 +503,13 @@ def to_dyck_word(self): EXAMPLES:: sage: T = OrderedTree([[],[]]) - sage: T.to_dyck_word() # optional - sage.combinat + sage: T.to_dyck_word() # needs sage.combinat [1, 0, 1, 0] sage: T = OrderedTree([[],[[]]]) - sage: T.to_dyck_word() # optional - sage.combinat + sage: T.to_dyck_word() # needs sage.combinat [1, 0, 1, 1, 0, 0] sage: T = OrderedTree([[], [[], []], [[], [[]]]]) - sage: T.to_dyck_word() # optional - sage.combinat + sage: T.to_dyck_word() # needs sage.combinat [1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0] """ word = [] @@ -597,14 +599,14 @@ def to_poset(self, root_to_leaf=False): sage: t.to_poset() Finite poset containing 1 elements sage: p = OrderedTree([[[]],[],[]]).to_poset() - sage: p.height(), p.width() + sage: p.height(), p.width() # needs networkx (3, 3) If the tree is labelled, we use its labelling to label the poset. Otherwise, we use the poset canonical labelling:: sage: t = OrderedTree([[[]],[],[]]).canonical_labelling().to_poset() - sage: t.height(), t.width() + sage: t.height(), t.width() # needs networkx (3, 3) """ if self in LabelledOrderedTrees(): @@ -675,7 +677,7 @@ def plot(self): o o o | o - sage: p.plot() # optional - sage.plot + sage: p.plot() # needs sage.plot Graphics object consisting of 10 graphics primitives .. PLOT:: @@ -692,7 +694,7 @@ def plot(self): 2 3 5 | 4 - sage: g.plot() # optional - sage.plot + sage: g.plot() # needs sage.plot Graphics object consisting of 10 graphics primitives .. PLOT:: @@ -1088,18 +1090,18 @@ def random_element(self): EXAMPLES:: - sage: OrderedTrees(5).random_element() # random # optional - sage.combinat + sage: OrderedTrees(5).random_element() # random # needs sage.combinat [[[], []], []] - sage: OrderedTrees(0).random_element() # optional - sage.combinat + sage: OrderedTrees(0).random_element() Traceback (most recent call last): ... EmptySetError: there are no ordered trees of size 0 - sage: OrderedTrees(1).random_element() # optional - sage.combinat + sage: OrderedTrees(1).random_element() # needs sage.combinat [] TESTS:: - sage: all(OrderedTrees(10).random_element() in OrderedTrees(10) # optional - sage.combinat + sage: all(OrderedTrees(10).random_element() in OrderedTrees(10) # needs sage.combinat ....: for i in range(20)) True """ diff --git a/src/sage/combinat/parallelogram_polyomino.py b/src/sage/combinat/parallelogram_polyomino.py index bdba16ab252..190eeedef72 100644 --- a/src/sage/combinat/parallelogram_polyomino.py +++ b/src/sage/combinat/parallelogram_polyomino.py @@ -3703,14 +3703,14 @@ def _plot_diagram(self): sage: pp = ParallelogramPolyomino( ....: [[0, 1, 1, 1, 1], [1, 1, 1, 1, 0]] ....: ) - sage: pp._plot_diagram() # optional - sage.plot + sage: pp._plot_diagram() # needs sage.plot Graphics object consisting of 7 graphics primitives sage: pp = ParallelogramPolyomino([ ....: [0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], ....: [1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0] ....: ]) - sage: pp._plot_diagram() # optional - sage.plot + sage: pp._plot_diagram() # needs sage.plot Graphics object consisting of 25 graphics primitives """ G = Graphics() @@ -3755,14 +3755,14 @@ def _plot_bounce(self, directions=None): sage: pp = ParallelogramPolyomino( ....: [[0, 1, 1, 1, 1], [1, 1, 1, 1, 0]] ....: ) - sage: pp._plot_bounce(directions=[1]) # optional - sage.plot + sage: pp._plot_bounce(directions=[1]) # needs sage.plot Graphics object consisting of 1 graphics primitive sage: pp = ParallelogramPolyomino([ ....: [0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], ....: [1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0] ....: ]) - sage: pp._plot_bounce(directions=[0,1]) # optional - sage.plot + sage: pp._plot_bounce(directions=[0,1]) # needs sage.plot Graphics object consisting of 9 graphics primitives """ @@ -3798,14 +3798,14 @@ def _plot_bounce_values(self, bounce=0): sage: pp = ParallelogramPolyomino( ....: [[0, 1, 1, 1, 1], [1, 1, 1, 1, 0]] ....: ) - sage: pp._plot_bounce_values() # optional - sage.plot + sage: pp._plot_bounce_values() # needs sage.plot Graphics object consisting of 4 graphics primitives sage: pp = ParallelogramPolyomino([ ....: [0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], ....: [1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0] ....: ]) - sage: pp._plot_bounce_values(bounce=1) # optional - sage.plot + sage: pp._plot_bounce_values(bounce=1) # needs sage.plot Graphics object consisting of 10 graphics primitives """ G = Graphics() @@ -3847,14 +3847,14 @@ def _plot_tree(self): sage: pp = ParallelogramPolyomino( ....: [[0, 1, 1, 1, 1], [1, 1, 1, 1, 0]] ....: ) - sage: pp._plot_tree() # optional - sage.plot + sage: pp._plot_tree() # needs sage.plot Graphics object consisting of 2 graphics primitives sage: pp = ParallelogramPolyomino([ ....: [0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1], ....: [1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0] ....: ]) - sage: pp._plot_tree() # optional - sage.plot + sage: pp._plot_tree() # needs sage.plot Graphics object consisting of 2 graphics primitives """ G = Graphics() @@ -3869,7 +3869,7 @@ def plot(self): EXAMPLES:: sage: pp = ParallelogramPolyomino([[0,1],[1,0]]) - sage: pp.plot() # optional - sage.plot + sage: pp.plot() # needs sage.plot Graphics object consisting of 4 graphics primitives sage: pp.set_options( ....: drawing_components=dict( @@ -3879,7 +3879,7 @@ def plot(self): ....: bounce_values=0, ....: ) ....: ) - sage: pp.plot() # optional - sage.plot + sage: pp.plot() # needs sage.plot Graphics object consisting of 7 graphics primitives """ G = Graphics() diff --git a/src/sage/combinat/parking_functions.py b/src/sage/combinat/parking_functions.py index d356cedb2b7..39feb8aa80f 100644 --- a/src/sage/combinat/parking_functions.py +++ b/src/sage/combinat/parking_functions.py @@ -1022,23 +1022,26 @@ def characteristic_quasisymmetric_function(self, q=None, EXAMPLES:: + sage: # needs sage.modules sage: R = QQ['q','t'].fraction_field() sage: (q,t) = R.gens() - sage: cqf = sum(t**PF.area()*PF.characteristic_quasisymmetric_function() for PF in ParkingFunctions(3)); cqf - (q^3+q^2*t+q*t^2+t^3+q*t)*F[1, 1, 1] + (q^2+q*t+t^2+q+t)*F[1, 2] + (q^2+q*t+t^2+q+t)*F[2, 1] + F[3] + sage: cqf = sum(t**PF.area() * PF.characteristic_quasisymmetric_function() + ....: for PF in ParkingFunctions(3)); cqf + (q^3+q^2*t+q*t^2+t^3+q*t)*F[1, 1, 1] + (q^2+q*t+t^2+q+t)*F[1, 2] + + (q^2+q*t+t^2+q+t)*F[2, 1] + F[3] sage: s = SymmetricFunctions(R).s() sage: s(cqf.to_symmetric_function()) (q^3+q^2*t+q*t^2+t^3+q*t)*s[1, 1, 1] + (q^2+q*t+t^2+q+t)*s[2, 1] + s[3] - sage: s(cqf.to_symmetric_function()).nabla(power = -1) + sage: s(cqf.to_symmetric_function()).nabla(power=-1) s[1, 1, 1] :: sage: p = ParkingFunction([3, 1, 2]) - sage: p.characteristic_quasisymmetric_function() + sage: p.characteristic_quasisymmetric_function() # needs sage.modules q*F[2, 1] sage: pf = ParkingFunction([1,2,7,2,1,2,3,2,1]) - sage: pf.characteristic_quasisymmetric_function() + sage: pf.characteristic_quasisymmetric_function() # needs sage.modules q^2*F[1, 1, 1, 2, 1, 3] """ from sage.combinat.ncsf_qsym.qsym import QuasiSymmetricFunctions diff --git a/src/sage/combinat/partition.py b/src/sage/combinat/partition.py index 488315254ef..9966a174cb1 100644 --- a/src/sage/combinat/partition.py +++ b/src/sage/combinat/partition.py @@ -67,7 +67,7 @@ There are `5` partitions of the integer `4`:: - sage: Partitions(4).cardinality() + sage: Partitions(4).cardinality() # needs sage.libs.flint 5 sage: Partitions(4).list() [[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]] @@ -1088,14 +1088,15 @@ def power(self, k): Now let us compare this to the power map on `S_8`:: - sage: G = SymmetricGroup(8) # optional - sage.groups - sage: g = G([(1,2,3,4,5),(6,7,8)]); g # optional - sage.groups + sage: # needs sage.groups + sage: G = SymmetricGroup(8) + sage: g = G([(1,2,3,4,5),(6,7,8)]); g (1,2,3,4,5)(6,7,8) - sage: g^2 # optional - sage.groups + sage: g^2 (1,3,5,2,4)(6,8,7) - sage: g^3 # optional - sage.groups + sage: g^3 (1,4,2,5,3) - sage: g^4 # optional - sage.groups + sage: g^4 (1,5,4,3,2)(6,7,8) :: @@ -1214,10 +1215,10 @@ def sign(self): :: - sage: F = GF(11) # optional - sage.rings.finite_rings - sage: a = F.multiplicative_generator();a # optional - sage.rings.finite_rings + sage: F = GF(11) # needs sage.rings.finite_rings + sage: a = F.multiplicative_generator();a # needs sage.rings.finite_rings 2 - sage: plist = [int(a*F(x)) for x in range(1,11)]; plist # optional - sage.rings.finite_rings + sage: plist = [int(a*F(x)) for x in range(1,11)]; plist # needs sage.rings.finite_rings [2, 4, 6, 8, 10, 1, 3, 5, 7, 9] This corresponds to the permutation (1, 2, 4, 8, 5, 10, 9, 7, 3, 6) @@ -1226,8 +1227,8 @@ def sign(self): :: - sage: p = PermutationGroupElement('(1, 2, 4, 8, 5, 10, 9, 7, 3, 6)') # optional - sage.groups - sage: p.sign() # optional - sage.groups + sage: p = PermutationGroupElement('(1, 2, 4, 8, 5, 10, 9, 7, 3, 6)') # needs sage.groups + sage: p.sign() # needs sage.groups -1 sage: Partition([10]).sign() -1 @@ -1236,12 +1237,12 @@ def sign(self): Now replace `2` by `3`:: - sage: plist = [int(F(3*x)) for x in range(1,11)]; plist # optional - sage.rings.finite_rings + sage: plist = [int(F(3*x)) for x in range(1,11)]; plist # needs sage.rings.finite_rings [3, 6, 9, 1, 4, 7, 10, 2, 5, 8] sage: list(range(1, 11)) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - sage: p = PermutationGroupElement('(3,4,8,7,9)') # optional - sage.groups - sage: p.sign() # optional - sage.groups + sage: p = PermutationGroupElement('(3,4,8,7,9)') # needs sage.groups + sage: p.sign() # needs sage.groups 1 sage: kronecker_symbol(3,11) 1 @@ -1883,56 +1884,59 @@ def cell_poset(self, orientation="SE"): EXAMPLES:: + sage: # needs sage.graphs sage: p = Partition([3,3,1]) - sage: Q = p.cell_poset(); Q # optional - sage.graphs + sage: Q = p.cell_poset(); Q Finite poset containing 7 elements - sage: sorted(Q) # optional - sage.graphs + sage: sorted(Q) [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0)] - sage: sorted(Q.maximal_elements()) # optional - sage.graphs + sage: sorted(Q.maximal_elements()) [(1, 2), (2, 0)] - sage: Q.minimal_elements() # optional - sage.graphs + sage: Q.minimal_elements() [(0, 0)] - sage: sorted(Q.upper_covers((1, 0))) # optional - sage.graphs + sage: sorted(Q.upper_covers((1, 0))) [(1, 1), (2, 0)] - sage: Q.upper_covers((1, 1)) # optional - sage.graphs + sage: Q.upper_covers((1, 1)) [(1, 2)] - sage: P = p.cell_poset(orientation="NW"); P # optional - sage.graphs + sage: # needs sage.graphs + sage: P = p.cell_poset(orientation="NW"); P Finite poset containing 7 elements - sage: sorted(P) # optional - sage.graphs + sage: sorted(P) [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0)] - sage: sorted(P.minimal_elements()) # optional - sage.graphs + sage: sorted(P.minimal_elements()) [(1, 2), (2, 0)] - sage: P.maximal_elements() # optional - sage.graphs + sage: P.maximal_elements() [(0, 0)] - sage: P.upper_covers((2, 0)) # optional - sage.graphs + sage: P.upper_covers((2, 0)) [(1, 0)] - sage: sorted(P.upper_covers((1, 2))) # optional - sage.graphs + sage: sorted(P.upper_covers((1, 2))) [(0, 2), (1, 1)] - sage: sorted(P.upper_covers((1, 1))) # optional - sage.graphs + sage: sorted(P.upper_covers((1, 1))) [(0, 1), (1, 0)] - sage: sorted([len(P.upper_covers(v)) for v in P]) # optional - sage.graphs + sage: sorted([len(P.upper_covers(v)) for v in P]) [0, 1, 1, 1, 1, 2, 2] - sage: R = p.cell_poset(orientation="NE"); R # optional - sage.graphs + sage: # needs sage.graphs + sage: R = p.cell_poset(orientation="NE"); R Finite poset containing 7 elements - sage: sorted(R) # optional - sage.graphs + sage: sorted(R) [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0)] - sage: R.maximal_elements() # optional - sage.graphs + sage: R.maximal_elements() [(0, 2)] - sage: R.minimal_elements() # optional - sage.graphs + sage: R.minimal_elements() [(2, 0)] - sage: sorted([len(R.upper_covers(v)) for v in R]) # optional - sage.graphs + sage: sorted([len(R.upper_covers(v)) for v in R]) [0, 1, 1, 1, 1, 2, 2] - sage: R.is_isomorphic(P) # optional - sage.graphs + sage: R.is_isomorphic(P) False - sage: R.is_isomorphic(P.dual()) # optional - sage.graphs + sage: R.is_isomorphic(P.dual()) False Linear extensions of ``p.cell_poset()`` are in 1-to-1 correspondence with standard Young tableaux of shape `p`:: - sage: all( len(p.cell_poset().linear_extensions()) # optional - sage.graphs + sage: all( len(p.cell_poset().linear_extensions()) # needs sage.graphs ....: == len(p.standard_tableaux()) ....: for n in range(8) for p in Partitions(n) ) True @@ -1940,7 +1944,7 @@ def cell_poset(self, orientation="SE"): This is not the case for northeast orientation:: sage: q = Partition([3, 1]) - sage: q.cell_poset(orientation="NE").is_chain() # optional - sage.graphs + sage: q.cell_poset(orientation="NE").is_chain() # needs sage.graphs True TESTS: @@ -1957,7 +1961,7 @@ def cell_poset(self, orientation="SE"): ....: and c[1] >= d[1]): ....: return False ....: return True - sage: all( check_NW(n) for n in range(8) ) # optional - sage.graphs + sage: all( check_NW(n) for n in range(8) ) # needs sage.graphs True sage: def check_NE(n): @@ -1969,7 +1973,7 @@ def cell_poset(self, orientation="SE"): ....: and c[1] <= d[1]): ....: return False ....: return True - sage: all( check_NE(n) for n in range(8) ) # optional - sage.graphs + sage: all( check_NE(n) for n in range(8) ) # needs sage.graphs True sage: def test_duality(n, ori1, ori2): @@ -1981,11 +1985,11 @@ def cell_poset(self, orientation="SE"): ....: if P.lt(c, d) != Q.lt(d, c): ....: return False ....: return True - sage: all( test_duality(n, "NW", "SE") for n in range(8) ) # optional - sage.graphs + sage: all( test_duality(n, "NW", "SE") for n in range(8) ) # needs sage.graphs True - sage: all( test_duality(n, "NE", "SW") for n in range(8) ) # optional - sage.graphs + sage: all( test_duality(n, "NE", "SW") for n in range(8) ) # needs sage.graphs True - sage: all( test_duality(n, "NE", "SE") for n in range(4) ) # optional - sage.graphs + sage: all( test_duality(n, "NE", "SE") for n in range(4) ) # needs sage.graphs False """ from sage.combinat.posets.posets import Poset @@ -2852,7 +2856,7 @@ def young_subgroup(self): EXAMPLES:: - sage: Partition([4,2]).young_subgroup() # optional - sage.groups + sage: Partition([4,2]).young_subgroup() # needs sage.groups Permutation Group with generators [(), (5,6), (3,4), (2,3), (1,2)] """ gens = [] @@ -3278,9 +3282,9 @@ def hook_product(self, a): EXAMPLES:: - sage: Partition([3,2,1]).hook_product(x) # optional - sage.symbolic + sage: Partition([3,2,1]).hook_product(x) # needs sage.symbolic (2*x + 3)*(x + 2)^2 - sage: Partition([2,2]).hook_product(x) # optional - sage.symbolic + sage: Partition([2,2]).hook_product(x) # needs sage.symbolic 2*(x + 2)*(x + 1) """ @@ -3421,7 +3425,7 @@ def upper_hook(self, i, j, alpha): 3 sage: p.hook_length(0,0) 3 - sage: [ p.upper_hook(i,j,x) for i,j in p.cells() ] # optional - sage.symbolic + sage: [ p.upper_hook(i,j,x) for i,j in p.cells() ] # needs sage.symbolic [2*x + 1, x, x] """ p = self @@ -3443,7 +3447,7 @@ def upper_hook_lengths(self, alpha): EXAMPLES:: - sage: Partition([3,2,1]).upper_hook_lengths(x) # optional - sage.symbolic + sage: Partition([3,2,1]).upper_hook_lengths(x) # needs sage.symbolic [[3*x + 2, 2*x + 1, x], [2*x + 1, x], [x]] sage: Partition([3,2,1]).upper_hook_lengths(1) [[5, 3, 1], [3, 1], [1]] @@ -3473,7 +3477,7 @@ def lower_hook(self, i, j, alpha): 3 sage: p.hook_length(0,0) 3 - sage: [ p.lower_hook(i,j,x) for i,j in p.cells() ] # optional - sage.symbolic + sage: [ p.lower_hook(i,j,x) for i,j in p.cells() ] # needs sage.symbolic [x + 2, 1, 1] """ p = self @@ -3495,7 +3499,7 @@ def lower_hook_lengths(self, alpha): EXAMPLES:: - sage: Partition([3,2,1]).lower_hook_lengths(x) # optional - sage.symbolic + sage: Partition([3,2,1]).lower_hook_lengths(x) # needs sage.symbolic [[2*x + 3, x + 2, 1], [x + 2, 1], [1]] sage: Partition([3,2,1]).lower_hook_lengths(1) [[5, 3, 1], [3, 1], [1]] @@ -4623,12 +4627,12 @@ def from_kbounded_to_grassmannian(self, k): EXAMPLES:: sage: p = Partition([2,1,1]) - sage: p.from_kbounded_to_grassmannian(2) # optional - sage.modules + sage: p.from_kbounded_to_grassmannian(2) # needs sage.modules [-1 1 1] [-2 2 1] [-2 1 2] sage: p = Partition([]) - sage: p.from_kbounded_to_grassmannian(2) # optional - sage.modules + sage: p.from_kbounded_to_grassmannian(2) # needs sage.modules [1 0 0] [0 1 0] [0 0 1] @@ -5068,16 +5072,17 @@ def jacobi_trudi(self): EXAMPLES:: + sage: # needs sage.modules sage: part = Partition([3,2,1]) - sage: jt = part.jacobi_trudi(); jt # optional - sage.modules + sage: jt = part.jacobi_trudi(); jt [h[3] h[1] 0] [h[4] h[2] h[]] [h[5] h[3] h[1]] - sage: s = SymmetricFunctions(QQ).schur() # optional - sage.modules - sage: h = SymmetricFunctions(QQ).homogeneous() # optional - sage.modules - sage: h( s(part) ) # optional - sage.modules + sage: s = SymmetricFunctions(QQ).schur() + sage: h = SymmetricFunctions(QQ).homogeneous() + sage: h( s(part) ) h[3, 2, 1] - h[3, 3] - h[4, 1, 1] + h[5, 1] - sage: jt.det() # optional - sage.modules + sage: jt.det() h[3, 2, 1] - h[3, 3] - h[4, 1, 1] + h[5, 1] """ return SkewPartition([ self, [] ]).jacobi_trudi() @@ -5108,11 +5113,11 @@ def character_polynomial(self): EXAMPLES:: - sage: Partition([1]).character_polynomial() # optional - sage.modules + sage: Partition([1]).character_polynomial() # needs sage.modules x - 1 - sage: Partition([1,1]).character_polynomial() # optional - sage.modules + sage: Partition([1,1]).character_polynomial() # needs sage.modules 1/2*x0^2 - 3/2*x0 - x1 + 1 - sage: Partition([2,1]).character_polynomial() # optional - sage.modules + sage: Partition([2,1]).character_polynomial() # needs sage.modules 1/3*x0^3 - 2*x0^2 + 8/3*x0 - x2 """ # Create the polynomial ring we will use @@ -5310,23 +5315,21 @@ def outline(self, variable=None): EXAMPLES:: - sage: [Partition([5,4]).outline()(x=i) for i in range(-10,11)] # optional - sage.symbolic + sage: # needs sage.symbolic + sage: [Partition([5,4]).outline()(x=i) for i in range(-10,11)] [10, 9, 8, 7, 6, 5, 6, 5, 6, 5, 4, 3, 2, 3, 4, 5, 6, 7, 8, 9, 10] - - sage: Partition([]).outline() # optional - sage.symbolic + sage: Partition([]).outline() abs(x) - - sage: Partition([1]).outline() # optional - sage.symbolic + sage: Partition([1]).outline() abs(x + 1) + abs(x - 1) - abs(x) - - sage: y = SR.var("y") # optional - sage.symbolic - sage: Partition([6,5,1]).outline(variable=y) # optional - sage.symbolic + sage: y = SR.var("y") + sage: Partition([6,5,1]).outline(variable=y) abs(y + 6) - abs(y + 5) + abs(y + 4) - abs(y + 3) + abs(y - 1) - abs(y - 2) + abs(y - 3) TESTS:: - sage: integrate(Partition([1]).outline()-abs(x),(x,-10,10)) # optional - sage.symbolic + sage: integrate(Partition([1]).outline()-abs(x),(x,-10,10)) # needs sage.symbolic 2 """ if variable is None: @@ -5389,17 +5392,18 @@ def dual_equivalence_graph(self, directed=False, coloring=None): EXAMPLES:: + sage: # needs sage.graphs sage: P = Partition([3,1,1]) - sage: G = P.dual_equivalence_graph() # optional - sage.graphs - sage: G.edges(sort=True) # optional - sage.graphs + sage: G = P.dual_equivalence_graph() + sage: G.edges(sort=True) [([[1, 2, 3], [4], [5]], [[1, 2, 4], [3], [5]], 3), ([[1, 2, 4], [3], [5]], [[1, 2, 5], [3], [4]], 4), ([[1, 2, 4], [3], [5]], [[1, 3, 4], [2], [5]], 2), ([[1, 2, 5], [3], [4]], [[1, 3, 5], [2], [4]], 2), ([[1, 3, 4], [2], [5]], [[1, 3, 5], [2], [4]], 4), ([[1, 3, 5], [2], [4]], [[1, 4, 5], [2], [3]], 3)] - sage: G = P.dual_equivalence_graph(directed=True) # optional - sage.graphs - sage: G.edges(sort=True) # optional - sage.graphs + sage: G = P.dual_equivalence_graph(directed=True) + sage: G.edges(sort=True) [([[1, 2, 4], [3], [5]], [[1, 2, 3], [4], [5]], 3), ([[1, 2, 5], [3], [4]], [[1, 2, 4], [3], [5]], 4), ([[1, 3, 4], [2], [5]], [[1, 2, 4], [3], [5]], 2), @@ -5409,20 +5413,20 @@ def dual_equivalence_graph(self, directed=False, coloring=None): TESTS:: - sage: G = Partition([1]).dual_equivalence_graph() # optional - sage.graphs - sage: G.vertices(sort=False) # optional - sage.graphs + sage: # needs sage.graphs + sage: G = Partition([1]).dual_equivalence_graph() + sage: G.vertices(sort=False) [[[1]]] - sage: G = Partition([]).dual_equivalence_graph() # optional - sage.graphs - sage: G.vertices(sort=False) # optional - sage.graphs + sage: G = Partition([]).dual_equivalence_graph() + sage: G.vertices(sort=False) [[]] - sage: P = Partition([3,1,1]) - sage: G = P.dual_equivalence_graph(coloring=lambda x: 'red') # optional - sage.graphs - sage: G2 = P.dual_equivalence_graph(coloring={2: 'black', 3: 'blue', # optional - sage.graphs + sage: G = P.dual_equivalence_graph(coloring=lambda x: 'red') + sage: G2 = P.dual_equivalence_graph(coloring={2: 'black', 3: 'blue', ....: 4: 'cyan', 5: 'grey'}) - sage: G is G2 # optional - sage.graphs + sage: G is G2 False - sage: G == G2 # optional - sage.graphs + sage: G == G2 True """ # We do some custom caching to not recreate the graph, but to make @@ -5491,10 +5495,10 @@ def specht_module(self, base_ring=None): EXAMPLES:: - sage: SM = Partition([2,2,1]).specht_module(QQ); SM # optional - sage.modules + sage: SM = Partition([2,2,1]).specht_module(QQ); SM Specht module of [(0, 0), (0, 1), (1, 0), (1, 1), (2, 0)] over Rational Field - sage: s = SymmetricFunctions(QQ).s() # optional - sage.modules - sage: s(SM.frobenius_image()) # optional - sage.modules + sage: s = SymmetricFunctions(QQ).s() + sage: s(SM.frobenius_image()) # needs sage.modules s[2, 2, 1] """ from sage.combinat.specht_module import SpechtModule @@ -5520,7 +5524,7 @@ def specht_module_dimension(self, base_ring=None): sage: Partition([2,2,1]).specht_module_dimension() 5 - sage: Partition([2,2,1]).specht_module_dimension(GF(2)) # optional - sage.rings.finite_rings + sage: Partition([2,2,1]).specht_module_dimension(GF(2)) # needs sage.rings.finite_rings 5 """ from sage.categories.fields import Fields @@ -5643,7 +5647,7 @@ class Partitions(UniqueRepresentation, Parent): sage: def test(n): ....: return (Partitions(n, max_slope=-1).cardinality() ....: == Partitions(n, parts_in=[1,3..n]).cardinality()) - sage: all(test(n) for n in [10..20]) # optional - sage.libs.gap + sage: all(test(n) for n in [10..20]) # needs sage.libs.gap True The number of partitions of `n` into distinct parts that differ by @@ -5653,7 +5657,7 @@ class Partitions(UniqueRepresentation, Parent): sage: def test(n): ....: return (Partitions(n, max_slope=-2).cardinality() ....: == Partitions(n, parts_in=([1,6..n] + [4,9..n])).cardinality()) - sage: all(test(n) for n in [10..20]) # optional - sage.libs.gap + sage: all(test(n) for n in [10..20]) # needs sage.libs.gap True Here are some more examples illustrating ``min_part``, ``max_part``, @@ -5746,9 +5750,9 @@ class Partitions(UniqueRepresentation, Parent): TESTS:: - sage: TestSuite(Partitions(0)).run() - sage: TestSuite(Partitions(5)).run() - sage: TestSuite(Partitions(5, min_part=2)).run() + sage: TestSuite(Partitions(0)).run() # needs sage.libs.flint + sage: TestSuite(Partitions(5)).run() # needs sage.libs.flint + sage: TestSuite(Partitions(5, min_part=2)).run() # needs sage.libs.flint sage: repr( Partitions(5, min_part=2) ) 'Partitions of the integer 5 satisfying constraints min_part=2' @@ -6517,8 +6521,8 @@ class Partitions_n(Partitions): TESTS:: - sage: TestSuite( sage.combinat.partition.Partitions_n(0) ).run() - sage: TestSuite( sage.combinat.partition.Partitions_n(0) ).run() + sage: TestSuite( sage.combinat.partition.Partitions_n(0) ).run() # needs sage.libs.flint + sage: TestSuite( sage.combinat.partition.Partitions_n(0) ).run() # needs sage.libs.flint """ def __init__(self, n): @@ -6606,30 +6610,33 @@ def cardinality(self, algorithm='flint'): [[5], [4, 1], [3, 2], [3, 1, 1], [2, 2, 1], [2, 1, 1, 1], [1, 1, 1, 1, 1]] sage: len(v) 7 - sage: Partitions(5).cardinality(algorithm='gap') - 7 - sage: Partitions(5).cardinality(algorithm='pari') - 7 - sage: number_of_partitions(5, algorithm='flint') + sage: Partitions(5).cardinality(algorithm='gap') # needs sage.libs.gap 7 :: - sage: Partitions(10).cardinality() - 42 + sage: # needs sage.libs.flint sage: Partitions(3).cardinality() 3 + sage: number_of_partitions(5, algorithm='flint') + 7 sage: Partitions(10).cardinality() 42 - sage: Partitions(3).cardinality(algorithm='pari') - 3 - sage: Partitions(10).cardinality(algorithm='pari') - 42 sage: Partitions(40).cardinality() 37338 sage: Partitions(100).cardinality() 190569292 + :: + + sage: # needs sage.libs.pari + sage: Partitions(3).cardinality(algorithm='pari') + 3 + sage: Partitions(5).cardinality(algorithm='pari') + 7 + sage: Partitions(10).cardinality(algorithm='pari') + 42 + A generating function for `p_n` is given by the reciprocal of Euler's function: @@ -6643,12 +6650,13 @@ def cardinality(self, algorithm='flint'): sage: q = PowerSeriesRing(QQ, 'q', default_prec=9).gen() sage: prod([(1-q^k)^(-1) for k in range(1,9)]) # partial product of 1 + q + 2*q^2 + 3*q^3 + 5*q^4 + 7*q^5 + 11*q^6 + 15*q^7 + 22*q^8 + O(q^9) - sage: [Partitions(k).cardinality() for k in range(2,10)] + sage: [Partitions(k).cardinality() for k in range(2,10)] # needs sage.libs.flint [2, 3, 5, 7, 11, 15, 22, 30] Another consistency test for ``n`` up to 500:: - sage: len([n for n in [1..500] if Partitions(n).cardinality() != Partitions(n).cardinality(algorithm='pari')]) + sage: len([n for n in [1..500] # needs sage.libs.flint sage.libs.pari + ....: if Partitions(n).cardinality() != Partitions(n).cardinality(algorithm='pari')]) 0 For negative inputs, the result is zero (the algorithm is ignored):: @@ -6691,9 +6699,9 @@ def random_element(self, measure='uniform'): EXAMPLES:: - sage: Partitions(5).random_element() # random + sage: Partitions(5).random_element() # random # needs sage.libs.flint [2, 1, 1, 1] - sage: Partitions(5).random_element(measure='Plancherel') # random + sage: Partitions(5).random_element(measure='Plancherel') # random # needs sage.libs.flint [2, 1, 1, 1] """ if measure == 'uniform': @@ -6709,22 +6717,22 @@ def random_element_uniform(self): EXAMPLES:: - sage: Partitions(5).random_element_uniform() # random + sage: Partitions(5).random_element_uniform() # random # needs sage.libs.flint [2, 1, 1, 1] - sage: Partitions(20).random_element_uniform() # random + sage: Partitions(20).random_element_uniform() # random # needs sage.libs.flint [9, 3, 3, 2, 2, 1] TESTS:: - sage: all(Part.random_element_uniform() in Part + sage: all(Part.random_element_uniform() in Part # needs sage.libs.flint ....: for Part in map(Partitions, range(10))) True Check that :trac:`18752` is fixed:: sage: P = Partitions(5) - sage: la = P.random_element_uniform() - sage: la.parent() is P + sage: la = P.random_element_uniform() # needs sage.libs.flint + sage: la.parent() is P # needs sage.libs.flint True ALGORITHM: @@ -7003,7 +7011,7 @@ def __iter__(self): [[]] sage: from sage.combinat.partition import number_of_partitions_length - sage: all( len(Partitions(n, length=k).list()) + sage: all( len(Partitions(n, length=k).list()) # needs sage.libs.flint ....: == number_of_partitions_length(n, k) ....: for n in range(9) for k in range(n+2) ) True @@ -7059,6 +7067,7 @@ def cardinality(self, algorithm='hybrid'): Further examples:: + sage: # needs sage.libs.flint sage: Partitions(5, length=3).cardinality() 2 sage: Partitions(6, length=3).cardinality() @@ -7084,11 +7093,12 @@ def cardinality(self, algorithm='hybrid'): sage: N = [0, 1, 2, 3, 5, 10, 20, 500, 850] sage: K = [0, 1, 2, 3, 5, 10, 11, 20, 21, 250, 499, 500] - sage: all(Partitions(n,length=k).cardinality() == Partitions(n,length=k).cardinality('gap') + sage: all(Partitions(n, length=k).cardinality() # needs sage.libs.flint + ....: == Partitions(n,length=k).cardinality('gap') ....: for n in N for k in K) True sage: P = Partitions(4562, length=2800) - sage: P.cardinality() == P.cardinality('gap') + sage: P.cardinality() == P.cardinality('gap') # needs sage.libs.flint True """ return number_of_partitions_length(self.n, self.k, algorithm) @@ -7117,7 +7127,7 @@ class Partitions_parts_in(Partitions): TESTS:: - sage: TestSuite( sage.combinat.partition.Partitions_parts_in(6, parts=[2,1]) ).run() # optional - sage.libs.gap + sage: TestSuite( sage.combinat.partition.Partitions_parts_in(6, parts=[2,1]) ).run() # needs sage.libs.gap """ @staticmethod @@ -7141,7 +7151,7 @@ def __init__(self, n, parts): TESTS:: - sage: TestSuite(Partitions(5, parts_in=[1,2,3])).run() # optional - sage.libs.gap + sage: TestSuite(Partitions(5, parts_in=[1,2,3])).run() # needs sage.libs.gap """ Partitions.__init__(self) self.n = n @@ -7176,12 +7186,12 @@ def cardinality(self): EXAMPLES:: - sage: Partitions(15, parts_in=[2,3,7]).cardinality() # optional - sage.libs.gap + sage: Partitions(15, parts_in=[2,3,7]).cardinality() # needs sage.libs.gap 5 If you can use all parts 1 through `n`, we'd better get `p(n)`:: - sage: (Partitions(20, parts_in=[1..20]).cardinality() # optional - sage.libs.gap + sage: (Partitions(20, parts_in=[1..20]).cardinality() # needs sage.libs.gap ....: == Partitions(20).cardinality()) True @@ -7190,20 +7200,21 @@ def cardinality(self): Let's check the consistency of GAP's function and our own algorithm that actually generates the partitions:: + sage: # needs sage.libs.gap sage: ps = Partitions(15, parts_in=[1,2,3]) - sage: ps.cardinality() == len(ps.list()) # optional - sage.libs.gap + sage: ps.cardinality() == len(ps.list()) True sage: ps = Partitions(15, parts_in=[]) - sage: ps.cardinality() == len(ps.list()) # optional - sage.libs.gap + sage: ps.cardinality() == len(ps.list()) True sage: ps = Partitions(3000, parts_in=[50,100,500,1000]) - sage: ps.cardinality() == len(ps.list()) # optional - sage.libs.gap + sage: ps.cardinality() == len(ps.list()) True sage: ps = Partitions(10, parts_in=[3,6,9]) - sage: ps.cardinality() == len(ps.list()) # optional - sage.libs.gap + sage: ps.cardinality() == len(ps.list()) True sage: ps = Partitions(0, parts_in=[1,2]) - sage: ps.cardinality() == len(ps.list()) # optional - sage.libs.gap + sage: ps.cardinality() == len(ps.list()) True """ # GAP complains if you give it an empty list @@ -8288,12 +8299,12 @@ def cardinality(self): EXAMPLES:: sage: P = Partitions(5, regular=3) - sage: P.cardinality() + sage: P.cardinality() # needs sage.libs.flint 5 sage: P = Partitions(5, regular=6) - sage: P.cardinality() + sage: P.cardinality() # needs sage.libs.flint 7 - sage: P.cardinality() == Partitions(5).cardinality() + sage: P.cardinality() == Partitions(5).cardinality() # needs sage.libs.flint True TESTS: @@ -8301,16 +8312,16 @@ def cardinality(self): Check the corner case:: sage: P = Partitions(0, regular=3) - sage: P.cardinality() + sage: P.cardinality() # needs sage.libs.flint 1 Check for 1-regular partitions:: sage: P = Partitions(0, regular=1) - sage: P.cardinality() + sage: P.cardinality() # needs sage.libs.flint 1 sage: P = Partitions(5, regular=1) - sage: P.cardinality() + sage: P.cardinality() # needs sage.libs.flint 0 """ @@ -8366,16 +8377,16 @@ class OrderedPartitions(Partitions): sage: OrderedPartitions(3) Ordered partitions of 3 - sage: OrderedPartitions(3).list() # optional - sage.libs.gap + sage: OrderedPartitions(3).list() # needs sage.libs.gap [[3], [2, 1], [1, 2], [1, 1, 1]] sage: OrderedPartitions(3,2) Ordered partitions of 3 of length 2 - sage: OrderedPartitions(3,2).list() # optional - sage.libs.gap + sage: OrderedPartitions(3,2).list() # needs sage.libs.gap [[2, 1], [1, 2]] - sage: OrderedPartitions(10, k=2).list() # optional - sage.libs.gap + sage: OrderedPartitions(10, k=2).list() # needs sage.libs.gap [[9, 1], [8, 2], [7, 3], [6, 4], [5, 5], [4, 6], [3, 7], [2, 8], [1, 9]] - sage: OrderedPartitions(4).list() # optional - sage.libs.gap + sage: OrderedPartitions(4).list() # needs sage.libs.gap [[4], [3, 1], [2, 2], [2, 1, 1], [1, 3], [1, 2, 1], [1, 1, 2], [1, 1, 1, 1]] """ @@ -8406,7 +8417,7 @@ def __init__(self, n, k): TESTS:: - sage: TestSuite( OrderedPartitions(5,3) ).run() # optional - sage.libs.gap + sage: TestSuite( OrderedPartitions(5,3) ).run() # needs sage.libs.gap """ Partitions.__init__(self) self.n = n @@ -8451,9 +8462,9 @@ def list(self): EXAMPLES:: - sage: OrderedPartitions(3).list() # optional - sage.libs.gap + sage: OrderedPartitions(3).list() # needs sage.libs.gap [[3], [2, 1], [1, 2], [1, 1, 1]] - sage: OrderedPartitions(3,2).list() # optional - sage.libs.gap + sage: OrderedPartitions(3,2).list() # needs sage.libs.gap [[2, 1], [1, 2]] """ from sage.libs.gap.libgap import libgap @@ -8473,13 +8484,14 @@ def cardinality(self): EXAMPLES:: - sage: OrderedPartitions(3).cardinality() # optional - sage.libs.gap + sage: # needs sage.libs.gap + sage: OrderedPartitions(3).cardinality() 4 - sage: OrderedPartitions(3,2).cardinality() # optional - sage.libs.gap + sage: OrderedPartitions(3,2).cardinality() 2 - sage: OrderedPartitions(10,2).cardinality() # optional - sage.libs.gap + sage: OrderedPartitions(10,2).cardinality() 9 - sage: OrderedPartitions(15).cardinality() # optional - sage.libs.gap + sage: OrderedPartitions(15).cardinality() 16384 """ from sage.libs.gap.libgap import libgap @@ -8553,12 +8565,12 @@ def cardinality(self): EXAMPLES:: - sage: PartitionsGreatestLE(9, 5).cardinality() # optional - sage.libs.gap + sage: PartitionsGreatestLE(9, 5).cardinality() # needs sage.libs.gap 23 TESTS:: - sage: all(PartitionsGreatestLE(n, a).cardinality() == # optional - sage.libs.gap + sage: all(PartitionsGreatestLE(n, a).cardinality() == # needs sage.libs.gap ....: len(PartitionsGreatestLE(n, a).list()) ....: for n in range(20) for a in range(6)) True @@ -8648,7 +8660,7 @@ def cardinality(self): TESTS:: - sage: all(PartitionsGreatestEQ(n, a).cardinality() == + sage: all(PartitionsGreatestEQ(n, a).cardinality() == # needs sage.libs.flint ....: len(PartitionsGreatestEQ(n, a).list()) ....: for n in range(20) for a in range(6)) True @@ -8906,12 +8918,12 @@ def cardinality(self): EXAMPLES:: sage: P = Partitions(5, restricted=3) - sage: P.cardinality() + sage: P.cardinality() # needs sage.libs.flint 5 sage: P = Partitions(5, restricted=6) - sage: P.cardinality() + sage: P.cardinality() # needs sage.libs.flint 7 - sage: P.cardinality() == Partitions(5).cardinality() + sage: P.cardinality() == Partitions(5).cardinality() # needs sage.libs.flint True """ if self._ell > self.n: @@ -8980,6 +8992,7 @@ def number_of_partitions(n, algorithm='default'): :: + sage: # needs sage.libs.flint sage: number_of_partitions(10) 42 sage: number_of_partitions(3) @@ -9007,7 +9020,7 @@ def number_of_partitions(n, algorithm='default'): sage: q = PowerSeriesRing(QQ, 'q', default_prec=9).gen() sage: prod([(1-q^k)^(-1) for k in range(1,9)]) # partial product of 1 + q + 2*q^2 + 3*q^3 + 5*q^4 + 7*q^5 + 11*q^6 + 15*q^7 + 22*q^8 + O(q^9) - sage: [number_of_partitions(k) for k in range(2,10)] + sage: [number_of_partitions(k) for k in range(2,10)] # needs sage.libs.flint [2, 3, 5, 7, 11, 15, 22, 30] REFERENCES: @@ -9016,6 +9029,7 @@ def number_of_partitions(n, algorithm='default'): TESTS:: + sage: # needs sage.libs.flint sage: n = 500 + randint(0,500) sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0 True @@ -9041,7 +9055,7 @@ def number_of_partitions(n, algorithm='default'): sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0 True sage: n = 100000000 + randint(0,100000000) - sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0 # long time (4s on sage.math, 2011) + sage: number_of_partitions( n - (n % 385) + 369) % 385 == 0 # long time (4s on sage.math, 2011) True """ @@ -9068,20 +9082,21 @@ def number_of_partitions_length(n, k, algorithm='hybrid'): EXAMPLES:: + sage: # needs sage.libs.gap sage: from sage.combinat.partition import number_of_partitions_length - sage: number_of_partitions_length(5, 2) # optional - sage.libs.gap + sage: number_of_partitions_length(5, 2) 2 - sage: number_of_partitions_length(10, 2) # optional - sage.libs.gap + sage: number_of_partitions_length(10, 2) 5 - sage: number_of_partitions_length(10, 4) # optional - sage.libs.gap + sage: number_of_partitions_length(10, 4) 9 - sage: number_of_partitions_length(10, 0) # optional - sage.libs.gap + sage: number_of_partitions_length(10, 0) 0 - sage: number_of_partitions_length(10, 1) # optional - sage.libs.gap + sage: number_of_partitions_length(10, 1) 1 - sage: number_of_partitions_length(0, 0) # optional - sage.libs.gap + sage: number_of_partitions_length(0, 0) 1 - sage: number_of_partitions_length(0, 1) # optional - sage.libs.gap + sage: number_of_partitions_length(0, 1) 0 """ if algorithm == 'hybrid': diff --git a/src/sage/combinat/partition_tuple.py b/src/sage/combinat/partition_tuple.py index 5766027efbc..ac41cf4d473 100644 --- a/src/sage/combinat/partition_tuple.py +++ b/src/sage/combinat/partition_tuple.py @@ -105,7 +105,7 @@ class of modules for the algebras, which are generalisations of the Specht ([1], [1], [1], [1], [1]) sage: PartitionTuples(4,5).an_element() ([1], [], [], [4]) - sage: PartitionTuples(3,2)[:] + sage: PartitionTuples(3,2)[:] # needs sage.libs.flint [([2], [], []), ([1, 1], [], []), ([1], [1], []), @@ -115,7 +115,7 @@ class of modules for the algebras, which are generalisations of the Specht ([], [1], [1]), ([], [], [2]), ([], [], [1, 1])] - sage: PartitionTuples(2,3).list() + sage: PartitionTuples(2,3).list() # needs sage.libs.flint [([3], []), ([2, 1], []), ([1, 1, 1], []), @@ -237,9 +237,10 @@ class of modules for the algebras, which are generalisations of the Specht Attached to a partition tuple is the corresponding Young, or parabolic, subgroup:: - sage: mu.young_subgroup() - Permutation Group with generators [(), (12,13), (11,12), (8,9), (6,7), (3,4), (2,3), (1,2)] - sage: mu.young_subgroup_generators() + sage: mu.young_subgroup() # needs sage.groups + Permutation Group with generators + [(), (12,13), (11,12), (8,9), (6,7), (3,4), (2,3), (1,2)] + sage: mu.young_subgroup_generators() # needs sage.groups [1, 2, 3, 6, 8, 11, 12] """ @@ -1474,7 +1475,7 @@ def to_list(self): TESTS:: - sage: all(mu==PartitionTuple(mu.to_list()) for mu in PartitionTuples(4,4)) + sage: all(mu==PartitionTuple(mu.to_list()) for mu in PartitionTuples(4,4)) # needs sage.libs.flint True """ return [mu.to_list() for mu in self] @@ -1486,7 +1487,7 @@ def young_subgroup(self): EXAMPLES:: - sage: PartitionTuple([[2,1],[4,2],[1]]).young_subgroup() + sage: PartitionTuple([[2,1],[4,2],[1]]).young_subgroup() # needs sage.groups Permutation Group with generators [(), (8,9), (6,7), (5,6), (4,5), (1,2)] """ gens = [] @@ -1955,7 +1956,7 @@ def __contains__(self, mu): True sage: PartitionTuple([[2,1],[],[1,1],[],[3]]) in PartitionTuples() True - sage: all(mu in PartitionTuples() for mu in PartitionTuples(3,8)) + sage: all(mu in PartitionTuples() for mu in PartitionTuples(3,8)) # needs sage.libs.flint True sage: [5,1,1] in PartitionTuples() True @@ -1990,7 +1991,7 @@ def __getitem__(self, r): EXAMPLES:: - sage: PartitionTuples()[10:20] + sage: PartitionTuples()[10:20] # needs sage.libs.flint [([1, 1, 1]), ([2], []), ([1, 1], []), @@ -2074,7 +2075,7 @@ def __init__(self): EXAMPLES:: - sage: TestSuite( PartitionTuples() ).run() + sage: TestSuite( PartitionTuples() ).run() # needs sage.libs.flint """ super().__init__(category=InfiniteEnumeratedSets()) @@ -2096,7 +2097,7 @@ def __iter__(self): EXAMPLES:: - sage: PartitionTuples()[:20] + sage: PartitionTuples()[:20] # needs sage.libs.flint [([]), ([1]), ([], []), @@ -2151,7 +2152,7 @@ def __init__(self, level, category=None): Partition tuples of level 4 sage: PartitionTuples(level=6) Partition tuples of level 6 - sage: TestSuite( PartitionTuples(level=4) ).run() + sage: TestSuite( PartitionTuples(level=4) ).run() # needs sage.libs.flint """ if level not in NN: raise ValueError('level must be a non-negative integer') @@ -2185,7 +2186,7 @@ def __contains__(self, mu): True sage: PartitionTuple([[2,2,1],[],[2]]) in PartitionTuples(level=2) False - sage: all(mu in PartitionTuples(3) for mu in PartitionTuples(3,8)) + sage: all(mu in PartitionTuples(3) for mu in PartitionTuples(3,8)) # needs sage.libs.flint True Check that :trac:`14145` is fixed:: @@ -2202,8 +2203,8 @@ def __iter__(self): EXAMPLES:: - sage: parts=PartitionTuples(3) - sage: [parts[k] for k in range(20)] + sage: parts = PartitionTuples(3) + sage: [parts[k] for k in range(20)] # needs sage.libs.flint [([], [], []), ([1], [], []), ([], [1], []), @@ -2257,7 +2258,7 @@ def __init__(self, size): sage: PartitionTuples(size=6) Partition tuples of size 6 - sage: TestSuite( PartitionTuples(size=6) ).run() + sage: TestSuite( PartitionTuples(size=6) ).run() # needs sage.libs.flint """ if size not in NN: raise ValueError('size must be a non-negative integer') @@ -2289,7 +2290,7 @@ def __contains__(self, mu): True sage: PartitionTuple([[2,1],[],[1,1],[],[3]]) in PartitionTuples(size=7) False - sage: all(mu in PartitionTuples(size=8) for mu in PartitionTuples(3,8)) + sage: all(mu in PartitionTuples(size=8) for mu in PartitionTuples(3,8)) # needs sage.libs.flint True sage: [3, 2, 1] in PartitionTuples(size=7) False @@ -2309,7 +2310,7 @@ def __iter__(self): EXAMPLES:: - sage: PartitionTuples(size=3)[:20] + sage: PartitionTuples(size=3)[:20] # needs sage.libs.flint [([3]), ([2, 1]), ([1, 1, 1]), @@ -2358,8 +2359,8 @@ def __init__(self, level, size): EXAMPLES:: - sage: TestSuite( PartitionTuples(4,2) ).run() - sage: TestSuite( PartitionTuples(level=4, size=5) ).run() + sage: TestSuite( PartitionTuples(4,2) ).run() # needs sage.libs.flint sage.libs.pari + sage: TestSuite( PartitionTuples(level=4, size=5) ).run() # needs sage.libs.flint sage.libs.pari """ if not (level in NN and size in NN): raise ValueError('n and level must be non-negative integers') @@ -2394,7 +2395,7 @@ def __contains__(self, mu): True sage: PartitionTuple([[2,1],[],[1,1],[],[3]]) in PartitionTuples(2,8) False - sage: all(mu in PartitionTuples(3,8) for mu in PartitionTuples(3,8)) + sage: all(mu in PartitionTuples(3,8) for mu in PartitionTuples(3,8)) # needs sage.libs.flint True Check that :trac:`14145` is fixed:: @@ -2415,6 +2416,7 @@ def __iter__(self): EXAMPLES:: + sage: # needs sage.libs.flint sage: PartitionTuples(2,0).list() #indirect doctest [([], [])] sage: PartitionTuples(2,1).list() #indirect doctest @@ -2463,15 +2465,16 @@ def cardinality(self): EXAMPLES:: - sage: PartitionTuples(2,3).cardinality() + sage: PartitionTuples(2,3).cardinality() # needs sage.libs.pari 10 - sage: PartitionTuples(2,8).cardinality() + sage: PartitionTuples(2,8).cardinality() # needs sage.libs.pari 185 TESTS: The following calls used to fail (:trac:`11476`):: + sage: # needs sage.libs.pari sage: PartitionTuples(17,2).cardinality() 170 sage: PartitionTuples(2,17).cardinality() @@ -2523,7 +2526,7 @@ def __init__(self, regular, **kwds): TESTS:: sage: RPT = PartitionTuples(regular=3) - sage: TestSuite(RPT).run() + sage: TestSuite(RPT).run() # needs sage.libs.flint """ if regular not in ZZ or regular < 1: raise ValueError("regular must be an integer greater than 1") @@ -2599,7 +2602,7 @@ def __init__(self, regular): EXAMPLES:: sage: RPT = PartitionTuples(regular=3) - sage: TestSuite(RPT).run() + sage: TestSuite(RPT).run() # needs sage.libs.flint """ RegularPartitionTuples.__init__(self, regular, category=InfiniteEnumeratedSets()) @@ -2620,7 +2623,7 @@ def __iter__(self): EXAMPLES:: - sage: PartitionTuples(regular=2)[:20] + sage: PartitionTuples(regular=2)[:20] # needs sage.libs.flint [([]), ([], []), ([1]), @@ -2668,7 +2671,7 @@ class RegularPartitionTuples_level(PartitionTuples_level): EXAMPLES:: sage: RPT = PartitionTuples(level=4, regular=(2,3,0,2)) - sage: RPT[:24] + sage: RPT[:24] # needs sage.libs.flint [([], [], [], []), ([1], [], [], []), ([], [1], [], []), @@ -2711,7 +2714,7 @@ def __init__(self, level, regular): sage: RPT.category() Category of infinite enumerated sets sage: RPT = PartitionTuples(level=4, regular=3) - sage: TestSuite(RPT).run() + sage: TestSuite(RPT).run() # needs sage.libs.flint """ if level not in NN: raise ValueError('level must be a non-negative integer') @@ -2814,7 +2817,7 @@ def __iter__(self): EXAMPLES:: - sage: PartitionTuples(level=3, regular=(2,1,4))[:24] + sage: PartitionTuples(level=3, regular=(2,1,4))[:24] # needs sage.libs.flint [([], [], []), ([1], [], []), ([], [], [1]), @@ -2839,7 +2842,7 @@ def __iter__(self): ([1], [], [3]), ([1], [], [2, 1]), ([1], [], [1, 1, 1])] - sage: PartitionTuples(level=4, regular=2)[:20] + sage: PartitionTuples(level=4, regular=2)[:20] # needs sage.libs.flint [([], [], [], []), ([1], [], [], []), ([], [1], [], []), @@ -2878,7 +2881,7 @@ def __init__(self, size, regular): EXAMPLES:: sage: RPT = PartitionTuples(size=4, regular=3) - sage: TestSuite(RPT).run() + sage: TestSuite(RPT).run() # needs sage.libs.flint """ if size not in NN: raise ValueError('size must be a non-negative integer') @@ -2936,7 +2939,7 @@ def __iter__(self): EXAMPLES:: - sage: PartitionTuples(size=4, regular=2)[:10] + sage: PartitionTuples(size=4, regular=2)[:10] # needs sage.libs.flint [([4]), ([3, 1]), ([4], []), @@ -2974,7 +2977,7 @@ class RegularPartitionTuples_level_size(PartitionTuples_level_size): EXAMPLES:: - sage: PartitionTuples(level=3, size=7, regular=(2,1,3))[0:24] + sage: PartitionTuples(level=3, size=7, regular=(2,1,3))[0:24] # needs sage.libs.flint [([7], [], []), ([6, 1], [], []), ([5, 2], [], []), @@ -3008,7 +3011,7 @@ def __init__(self, level, size, regular): TESTS:: sage: RPT = PartitionTuples(4,2,3) - sage: TestSuite(RPT).run() + sage: TestSuite(RPT).run() # needs sage.libs.flint sage.libs.pari """ if size not in NN: raise ValueError('size must be a non-negative integer') @@ -3082,7 +3085,7 @@ def __iter__(self): EXAMPLES:: - sage: list(PartitionTuples(3,3,2)) + sage: list(PartitionTuples(3,3,2)) # needs sage.libs.pari [([3], [], []), ([2, 1], [], []), ([2], [1], []), diff --git a/src/sage/combinat/path_tableaux/frieze.py b/src/sage/combinat/path_tableaux/frieze.py index 23ff179039c..7e667743e4a 100644 --- a/src/sage/combinat/path_tableaux/frieze.py +++ b/src/sage/combinat/path_tableaux/frieze.py @@ -84,10 +84,11 @@ class FriezePattern(PathTableau, metaclass=InheritComparisonClasscallMetaclass): This constructs the examples from [HJ18]_:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') - sage: K. = NumberField(x^2 - 3) # optional - sage.rings.number_field - sage: t = path_tableaux.FriezePattern([1,sqrt3,2,sqrt3,1,1], field=K) # optional - sage.rings.number_field - sage: path_tableaux.CylindricalDiagram(t) # optional - sage.rings.number_field + sage: K. = NumberField(x^2 - 3) + sage: t = path_tableaux.FriezePattern([1, sqrt3, 2, sqrt3, 1, 1], field=K) + sage: path_tableaux.CylindricalDiagram(t) [ 0, 1, sqrt3, 2, sqrt3, 1, 1, 0] [ , 0, 1, sqrt3, 2, sqrt3, sqrt3 + 1, 1, 0] [ , , 0, 1, sqrt3, 2, sqrt3 + 2, sqrt3, 1, 0] @@ -96,13 +97,13 @@ class FriezePattern(PathTableau, metaclass=InheritComparisonClasscallMetaclass): [ , , , , , 0, 1, 1, sqrt3, 2, sqrt3, 1, 0] [ , , , , , , 0, 1, sqrt3 + 1, sqrt3 + 2, sqrt3 + 2, sqrt3 + 1, 1, 0] [ , , , , , , , 0, 1, sqrt3, 2, sqrt3, 1, 1, 0] + sage: TestSuite(t).run() - sage: TestSuite(t).run() # optional - sage.rings.number_field - - sage: K. = NumberField(x^2 - 2) # optional - sage.rings.number_field - sage: t = path_tableaux.FriezePattern([1,sqrt2,1,sqrt2,3,2*sqrt2,5,3*sqrt2,1], # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: K. = NumberField(x^2 - 2) + sage: t = path_tableaux.FriezePattern([1, sqrt2, 1, sqrt2, 3, 2*sqrt2, 5, 3*sqrt2, 1], ....: field=K) - sage: path_tableaux.CylindricalDiagram(t) # optional - sage.rings.number_field + sage: path_tableaux.CylindricalDiagram(t) [ 0, 1, sqrt2, 1, sqrt2, 3, 2*sqrt2, 5, 3*sqrt2, 1, 0] [ , 0, 1, sqrt2, 3, 5*sqrt2, 7, 9*sqrt2, 11, 2*sqrt2, 1, 0] [ , , 0, 1, 2*sqrt2, 7, 5*sqrt2, 13, 8*sqrt2, 3, sqrt2, 1, 0] @@ -114,8 +115,7 @@ class FriezePattern(PathTableau, metaclass=InheritComparisonClasscallMetaclass): [ , , , , , , , , 0, 1, 3*sqrt2, 11, 8*sqrt2, 5, 2*sqrt2, 3, sqrt2, 1, 0] [ , , , , , , , , , 0, 1, 2*sqrt2, 3, sqrt2, 1, sqrt2, 1, sqrt2, 1, 0] [ , , , , , , , , , , 0, 1, sqrt2, 1, sqrt2, 3, 2*sqrt2, 5, 3*sqrt2, 1, 0] - - sage: TestSuite(t).run() # optional - sage.rings.number_field + sage: TestSuite(t).run() """ @staticmethod def __classcall_private__(cls, fp, field=QQ): @@ -135,8 +135,8 @@ def __classcall_private__(cls, fp, field=QQ): ValueError: invalid input 2 sage: x = polygen(ZZ, 'x') - sage: K. = NumberField(x^2 - 3) # optional - sage.rings.number_field - sage: t = path_tableaux.FriezePattern([1,sqrt3,2,sqrt3,1,1]) # optional - sage.rings.number_field + sage: K. = NumberField(x^2 - 3) # needs sage.rings.number_field + sage: t = path_tableaux.FriezePattern([1,sqrt3,2,sqrt3,1,1]) # needs sage.rings.number_field Traceback (most recent call last): ... ValueError: [1, sqrt3, 2, sqrt3, 1, 1] is not a sequence in the field Rational Field @@ -278,8 +278,8 @@ def is_positive(self): False sage: x = polygen(ZZ, 'x') - sage: K. = NumberField(x^2 - 3) # optional - sage.rings.number_field - sage: path_tableaux.FriezePattern([1,sqrt3,1], K).is_positive() # optional - sage.rings.number_field + sage: K. = NumberField(x^2 - 3) # needs sage.rings.number_field + sage: path_tableaux.FriezePattern([1,sqrt3,1], K).is_positive() # needs sage.rings.number_field True """ return all(a > 0 for a in self[1:-1]) @@ -316,16 +316,16 @@ def triangulation(self): EXAMPLES:: - sage: path_tableaux.FriezePattern([1,2,7,5,3,7,4,1]).triangulation() # optional - sage.plot sage.symbolic + sage: path_tableaux.FriezePattern([1,2,7,5,3,7,4,1]).triangulation() # needs sage.plot sage.symbolic Graphics object consisting of 25 graphics primitives - sage: path_tableaux.FriezePattern([1,2,1/7,5,3]).triangulation() # optional - sage.plot sage.symbolic + sage: path_tableaux.FriezePattern([1,2,1/7,5,3]).triangulation() # needs sage.plot sage.symbolic Graphics object consisting of 12 graphics primitives sage: x = polygen(ZZ, 'x') - sage: K. = NumberField(x^2 - 2) # optional - sage.rings.number_field - sage: path_tableaux.FriezePattern([1,sqrt2,1,sqrt2,3,2*sqrt2,5,3*sqrt2,1], # optional - sage.plot sage.rings.number_field sage.symbolic + sage: K. = NumberField(x^2 - 2) # needs sage.rings.number_field + sage: path_tableaux.FriezePattern([1,sqrt2,1,sqrt2,3,2*sqrt2,5,3*sqrt2,1], # needs sage.plot sage.rings.number_field sage.symbolic ....: field=K).triangulation() Graphics object consisting of 24 graphics primitives """ @@ -378,18 +378,17 @@ def plot(self, model='UHP'): EXAMPLES:: + sage: # needs sage.plot sage.symbolic sage: t = path_tableaux.FriezePattern([1,2,7,5,3,7,4,1]) - sage: t.plot() # optional - sage.plot sage.symbolic + sage: t.plot() Graphics object consisting of 18 graphics primitives - - sage: t.plot(model='UHP') # optional - sage.plot sage.symbolic + sage: t.plot(model='UHP') Graphics object consisting of 18 graphics primitives - - sage: t.plot(model='PD') # optional - sage.plot sage.symbolic + sage: t.plot(model='PD') Traceback (most recent call last): ... TypeError: '>' not supported between instances of 'NotANumber' and 'Pi' - sage: t.plot(model='KM') # optional - sage.plot sage.symbolic + sage: t.plot(model='KM') Graphics object consisting of 18 graphics primitives """ from sage.geometry.hyperbolic_space.hyperbolic_interface import HyperbolicPlane @@ -413,16 +412,18 @@ def plot(self, model='UHP'): def change_ring(self, R): r""" - Return ``self`` as a frieze pattern with coefficients in ``R`` - assuming there is a canonical coerce map from the base ring of ``self`` + Return ``self`` as a frieze pattern with coefficients in ``R``. + + This assumes that there is a canonical coerce map from the base ring of ``self`` to ``R``. EXAMPLES:: - sage: path_tableaux.FriezePattern([1,2,7,5,3,7,4,1]).change_ring(RealField()) - [0.000000000000000, 1.00000000000000, ... 4.00000000000000, 1.00000000000000, 0.000000000000000] - - sage: path_tableaux.FriezePattern([1,2,7,5,3,7,4,1]).change_ring(GF(7)) + sage: fp = path_tableaux.FriezePattern([1,2,7,5,3,7,4,1]) + sage: fp.change_ring(RealField()) # needs sage.rings.real_mpfr + [0.000000000000000, 1.00000000000000, ... + 4.00000000000000, 1.00000000000000, 0.000000000000000] + sage: fp.change_ring(GF(7)) Traceback (most recent call last): ... TypeError: no base extension defined diff --git a/src/sage/combinat/path_tableaux/path_tableau.py b/src/sage/combinat/path_tableaux/path_tableau.py index e0d612b8f87..66bec5fe5d2 100644 --- a/src/sage/combinat/path_tableaux/path_tableau.py +++ b/src/sage/combinat/path_tableaux/path_tableau.py @@ -389,7 +389,7 @@ def dual_equivalence_graph(self): EXAMPLES:: sage: s = path_tableaux.DyckPath([0,1,2,3,2,3,2,1,0]) - sage: s.dual_equivalence_graph().adjacency_matrix() + sage: s.dual_equivalence_graph().adjacency_matrix() # needs sage.graphs sage.modules [0 1 1 1 0 1 0 1 1 0 0 0 0 0] [1 0 1 1 1 1 1 0 1 0 0 1 1 0] [1 1 0 1 1 1 0 1 0 1 1 1 0 0] @@ -405,7 +405,7 @@ def dual_equivalence_graph(self): [0 1 0 1 1 1 0 1 1 1 1 1 0 1] [0 0 0 0 1 0 1 0 0 1 1 1 1 0] sage: s = path_tableaux.DyckPath([0,1,2,3,2,1,0]) - sage: s.dual_equivalence_graph().edges(sort=True) + sage: s.dual_equivalence_graph().edges(sort=True) # needs sage.graphs [([0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 2, 1, 0], '4,7'), ([0, 1, 0, 1, 0, 1, 0], [0, 1, 2, 1, 0, 1, 0], '2,5'), ([0, 1, 0, 1, 0, 1, 0], [0, 1, 2, 1, 2, 1, 0], '2,7'), diff --git a/src/sage/combinat/path_tableaux/semistandard.py b/src/sage/combinat/path_tableaux/semistandard.py index f92dfcdd6c8..559571e798a 100644 --- a/src/sage/combinat/path_tableaux/semistandard.py +++ b/src/sage/combinat/path_tableaux/semistandard.py @@ -393,8 +393,9 @@ def to_tableau(self): TESTS:: - sage: SST = SemistandardTableaux(shape=[5,5,3],eval=[2,2,3,4,2]) - sage: all(st == path_tableaux.SemistandardPathTableau(st).to_tableau() for st in SST) + sage: SST = SemistandardTableaux(shape=[5,5,3], eval=[2,2,3,4,2]) + sage: all(st == path_tableaux.SemistandardPathTableau(st).to_tableau() # needs sage.modules + ....: for st in SST) True """ from sage.combinat.tableau import from_chain diff --git a/src/sage/combinat/perfect_matching.py b/src/sage/combinat/perfect_matching.py index c9cc93fd7b3..70c8652841c 100644 --- a/src/sage/combinat/perfect_matching.py +++ b/src/sage/combinat/perfect_matching.py @@ -224,7 +224,7 @@ def _latex_(self): EXAMPLES:: sage: P = PerfectMatching([(1,3),(2,5),(4,6)]) - sage: latex(P) # random # optional - sage.graphs + sage: latex(P) # random # needs sage.graphs sage.plot \begin{tikzpicture} ... \end{tikzpicture} @@ -234,7 +234,7 @@ def _latex_(self): Above we added ``random`` since warnings might be displayed once. The second time, there should be no warnings:: - sage: print(P._latex_()) # optional - sage.graphs + sage: print(P._latex_()) # needs sage.graphs sage.plot \begin{tikzpicture} ... \end{tikzpicture} @@ -377,9 +377,9 @@ def loops(self, other=None): sage: loops = sorted(loops, key=len) sage: sorted(loops[0]) ['d', 'f'] - sage: G = SymmetricGroup(4) # optional - sage.groups - sage: g = G([(1,2,3,4)]) # optional - sage.groups - sage: ((loops[1] in [permutation_action(g**i, ['a', 'e', 'c', 'b']) # optional - sage.groups + sage: G = SymmetricGroup(4) # needs sage.groups + sage: g = G([(1,2,3,4)]) # needs sage.groups + sage: ((loops[1] in [permutation_action(g**i, ['a', 'e', 'c', 'b']) # needs sage.groups ....: for i in range(4)]) ....: or (loops[1] in [permutation_action(g**i, ['a', 'b', 'c', 'e']) ....: for i in range(4)])) @@ -455,11 +455,11 @@ def Weingarten_function(self, d, other=None): EXAMPLES:: - sage: var('N') # optional - sage.symbolic + sage: var('N') # needs sage.symbolic N sage: m = PerfectMatching([(1,3),(2,4)]) sage: n = PerfectMatching([(1,2),(3,4)]) - sage: factor(m.Weingarten_function(N, n)) # optional - sage.symbolic + sage: factor(m.Weingarten_function(N, n)) # needs sage.symbolic -1/((N + 2)*(N - 1)*N) """ if other is None: @@ -477,13 +477,13 @@ def to_graph(self): EXAMPLES:: - sage: PerfectMatching([[1,3], [4,2]]).to_graph().edges(sort=True, # optional - sage.graphs + sage: PerfectMatching([[1,3], [4,2]]).to_graph().edges(sort=True, # needs sage.graphs ....: labels=False) [(1, 3), (2, 4)] - sage: PerfectMatching([[1,4], [3,2]]).to_graph().edges(sort=True, # optional - sage.graphs + sage: PerfectMatching([[1,4], [3,2]]).to_graph().edges(sort=True, # needs sage.graphs ....: labels=False) [(1, 4), (2, 3)] - sage: PerfectMatching([]).to_graph().edges(sort=True, labels=False) # optional - sage.graphs + sage: PerfectMatching([]).to_graph().edges(sort=True, labels=False) # needs sage.graphs [] """ from sage.graphs.graph import Graph @@ -768,8 +768,8 @@ def Weingarten_matrix(self, N): EXAMPLES:: - sage: M = PerfectMatchings(4).Weingarten_matrix(var('N')) # optional - sage.symbolic - sage: N*(N-1)*(N+2)*M.apply_map(factor) # optional - sage.symbolic + sage: M = PerfectMatchings(4).Weingarten_matrix(var('N')) # needs sage.symbolic + sage: N*(N-1)*(N+2)*M.apply_map(factor) # needs sage.symbolic [N + 1 -1 -1] [ -1 N + 1 -1] [ -1 -1 N + 1] diff --git a/src/sage/combinat/permutation.py b/src/sage/combinat/permutation.py index eb3e451b0ff..3ed9a0a43fd 100644 --- a/src/sage/combinat/permutation.py +++ b/src/sage/combinat/permutation.py @@ -396,24 +396,25 @@ class Permutation(CombinatorialElement): We construct a :class:`Permutation` from a :class:`PermutationGroupElement`:: - sage: g = PermutationGroupElement([2,1,3]) # optional - sage.groups - sage: Permutation(g) # optional - sage.groups + sage: g = PermutationGroupElement([2,1,3]) # needs sage.groups + sage: Permutation(g) # needs sage.groups [2, 1, 3] From a pair of tableaux of the same shape. This uses the inverse of the Robinson-Schensted algorithm:: + sage: # needs sage.combinat sage: p = [[1, 4, 7], [2, 5], [3], [6]] sage: q = [[1, 2, 5], [3, 6], [4], [7]] - sage: P = Tableau(p) # optional - sage.combinat - sage: Q = Tableau(q) # optional - sage.combinat - sage: Permutation( (p, q) ) # optional - sage.combinat + sage: P = Tableau(p) + sage: Q = Tableau(q) + sage: Permutation( (p, q) ) [3, 6, 5, 2, 7, 4, 1] - sage: Permutation( [p, q] ) # optional - sage.combinat + sage: Permutation( [p, q] ) [3, 6, 5, 2, 7, 4, 1] - sage: Permutation( (P, Q) ) # optional - sage.combinat + sage: Permutation( (P, Q) ) [3, 6, 5, 2, 7, 4, 1] - sage: Permutation( [P, Q] ) # optional - sage.combinat + sage: Permutation( [P, Q] ) [3, 6, 5, 2, 7, 4, 1] TESTS:: @@ -429,9 +430,9 @@ class Permutation(CombinatorialElement): From a pair of empty tableaux :: - sage: Permutation( ([], []) ) # optional - sage.combinat + sage: Permutation( ([], []) ) # needs sage.combinat [] - sage: Permutation( [[], []] ) # optional - sage.combinat + sage: Permutation( [[], []] ) # needs sage.combinat [] """ @staticmethod @@ -470,7 +471,7 @@ def __classcall_private__(cls, l, check=True): return RSK_inverse(*l, output='permutation') elif isinstance(l, (tuple, list)) and len(l) == 2 and \ all(isinstance(x, list) for x in l): - P,Q = [Tableau(_) for _ in l] + P,Q = (Tableau(_) for _ in l) return RSK_inverse(P, Q, 'permutation') # if it's a tuple or nonempty list of tuples, also assume cycle # notation @@ -702,11 +703,11 @@ def _gap_(self, gap): EXAMPLES:: - sage: gap(Permutation([1,2,3])) # optional - sage.libs.gap + sage: gap(Permutation([1,2,3])) # needs sage.libs.gap () - sage: gap(Permutation((1,2,3))) # optional - sage.libs.gap + sage: gap(Permutation((1,2,3))) # needs sage.libs.gap (1,2,3) - sage: type(_) # optional - sage.libs.gap + sage: type(_) # needs sage.libs.gap """ return self.to_permutation_group_element()._gap_(gap) @@ -870,9 +871,9 @@ def to_tableau_by_shape(self, shape): EXAMPLES:: - sage: T = Permutation([3,4,1,2,5]).to_tableau_by_shape([3,2]); T # optional - sage.combinat + sage: T = Permutation([3,4,1,2,5]).to_tableau_by_shape([3,2]); T # needs sage.combinat [[1, 2, 5], [3, 4]] - sage: T.reading_word_permutation() # optional - sage.combinat + sage: T.reading_word_permutation() # needs sage.combinat [3, 4, 1, 2, 5] """ if sum(shape) != len(self): @@ -1141,9 +1142,9 @@ def to_permutation_group_element(self): EXAMPLES:: - sage: Permutation([2,1,4,3]).to_permutation_group_element() # optional - sage.groups + sage: Permutation([2,1,4,3]).to_permutation_group_element() # needs sage.groups (1,2)(3,4) - sage: Permutation([1,2,3]).to_permutation_group_element() # optional - sage.groups + sage: Permutation([1,2,3]).to_permutation_group_element() # needs sage.groups () """ grp = SymmetricGroup(len(self)) @@ -1192,14 +1193,14 @@ def to_matrix(self): EXAMPLES:: - sage: Permutation([1,2,3]).to_matrix() # optional - sage.modules + sage: Permutation([1,2,3]).to_matrix() # needs sage.modules [1 0 0] [0 1 0] [0 0 1] Alternatively:: - sage: matrix(Permutation([1,3,2])) # optional - sage.modules + sage: matrix(Permutation([1,3,2])) # needs sage.modules [1 0 0] [0 0 1] [0 1 0] @@ -1212,16 +1213,16 @@ def to_matrix(self): sage: Permutations.options.mult='r2l' sage: p = Permutation([2,1,3]) sage: q = Permutation([3,1,2]) - sage: (p*q).to_matrix() # optional - sage.modules + sage: (p*q).to_matrix() # needs sage.modules [0 0 1] [0 1 0] [1 0 0] - sage: p.to_matrix()*q.to_matrix() # optional - sage.modules + sage: p.to_matrix()*q.to_matrix() # needs sage.modules [0 0 1] [0 1 0] [1 0 0] sage: Permutations.options.mult='l2r' - sage: (p*q).to_matrix() # optional - sage.modules + sage: (p*q).to_matrix() # needs sage.modules [1 0 0] [0 0 1] [0 1 0] @@ -1242,11 +1243,11 @@ def to_alternating_sign_matrix(self): EXAMPLES:: - sage: m = Permutation([1,2,3]).to_alternating_sign_matrix(); m # optional - sage.combinat sage.modules + sage: m = Permutation([1,2,3]).to_alternating_sign_matrix(); m # needs sage.combinat sage.modules [1 0 0] [0 1 0] [0 0 1] - sage: parent(m) # optional - sage.combinat sage.modules + sage: parent(m) # needs sage.combinat sage.modules Alternating sign matrices of size 3 """ from sage.combinat.alternating_sign_matrix import AlternatingSignMatrix @@ -1256,12 +1257,13 @@ def __mul__(self, rp): """ TESTS:: - sage: SGA = SymmetricGroupAlgebra(QQ, 3) # optional - sage.combinat sage.modules - sage: SM = SGA.specht_module([2,1]) # optional - sage.combinat sage.modules - sage: p213 = Permutations(3)([2,1,3]) # optional - sage.combinat sage.modules - sage: p213 * SGA.an_element() # optional - sage.combinat sage.modules + sage: # needs sage.groups sage.modules + sage: SGA = SymmetricGroupAlgebra(QQ, 3) + sage: SM = SGA.specht_module([2,1]) + sage: p213 = Permutations(3)([2,1,3]) + sage: p213 * SGA.an_element() 3*[1, 2, 3] + [1, 3, 2] + [2, 1, 3] + 2*[3, 1, 2] - sage: p213 * SM.an_element() # optional - sage.combinat sage.modules + sage: p213 * SM.an_element() 2*B[0] - 4*B[1] """ if not isinstance(rp, Permutation) and isinstance(rp, Element): @@ -1301,8 +1303,8 @@ def __rmul__(self, lp) -> Permutation: [3, 2, 1] sage: Permutations.options.mult='l2r' - sage: SGA = SymmetricGroupAlgebra(QQ, 3) # optional - sage.combinat sage.modules - sage: SGA.an_element() * Permutations(3)(p213) # optional - sage.combinat sage.modules + sage: SGA = SymmetricGroupAlgebra(QQ, 3) # needs sage.groups sage.modules + sage: SGA.an_element() * Permutations(3)(p213) # needs sage.groups sage.modules 3*[1, 2, 3] + [2, 1, 3] + 2*[2, 3, 1] + [3, 2, 1] """ if not isinstance(lp, Permutation) and isinstance(lp, Element): @@ -1682,19 +1684,19 @@ def to_digraph(self) -> DiGraph: EXAMPLES:: - sage: d = Permutation([3, 1, 2]).to_digraph() # optional - sage.graphs - sage: d.edges(sort=True, labels=False) # optional - sage.graphs + sage: d = Permutation([3, 1, 2]).to_digraph() # needs sage.graphs + sage: d.edges(sort=True, labels=False) # needs sage.graphs [(1, 3), (2, 1), (3, 2)] sage: P = Permutations(range(1, 10)) - sage: d = Permutation(P.random_element()).to_digraph() # optional - sage.graphs - sage: all(c.is_cycle() # optional - sage.graphs + sage: d = Permutation(P.random_element()).to_digraph() # needs sage.graphs + sage: all(c.is_cycle() # needs sage.graphs ....: for c in d.strongly_connected_components_subgraphs()) True TESTS:: - sage: d = Permutation([1]).to_digraph() # optional - sage.graphs - sage: d.edges(sort=True, labels=False) # optional - sage.graphs + sage: d = Permutation([1]).to_digraph() # needs sage.graphs + sage: d.edges(sort=True, labels=False) # needs sage.graphs [(1, 1)] """ return DiGraph([self, enumerate(self, start=1)], @@ -1726,10 +1728,10 @@ def show(self, representation="cycles", orientation="landscape", **args): EXAMPLES:: sage: P20 = Permutations(20) - sage: P20.random_element().show(representation="cycles") # optional - sage.graphs sage.plot - sage: P20.random_element().show(representation="chord-diagram") # optional - sage.graphs sage.plot - sage: P20.random_element().show(representation="braid") # optional - sage.plot - sage: P20.random_element().show(representation="braid", # optional - sage.plot + sage: P20.random_element().show(representation="cycles") # needs sage.graphs sage.plot + sage: P20.random_element().show(representation="chord-diagram") # needs sage.graphs sage.plot + sage: P20.random_element().show(representation="braid") # needs sage.plot + sage: P20.random_element().show(representation="braid", # needs sage.plot ....: orientation='portrait') TESTS:: @@ -1863,8 +1865,8 @@ def number_of_noninversions(self, k) -> Integer: The number of `2`-noninversions of a permutation `p \in S_n` is `\binom{n}{2}` minus its number of inversions:: - sage: b = binomial(5, 2) - sage: all( x.number_of_noninversions(2) == b - x.number_of_inversions() + sage: b = binomial(5, 2) # needs sage.symbolic + sage: all( x.number_of_noninversions(2) == b - x.number_of_inversions() # needs sage.symbolic ....: for x in Permutations(5) ) True @@ -1913,7 +1915,7 @@ def absolute_length(self) -> Integer: EXAMPLES:: - sage: Permutation([4,2,3,1]).absolute_length() # optional - sage.combinat + sage: Permutation([4,2,3,1]).absolute_length() # needs sage.combinat 1 """ return self.size() - len(self.cycle_type()) @@ -2222,7 +2224,7 @@ def longest_increasing_subsequence_length(self) -> Integer: sage: Permutation([2,3,1,4]).longest_increasing_subsequence_length() 3 - sage: all(i.longest_increasing_subsequence_length() == len(RSK(i)[0][0]) # optional - sage.combinat + sage: all(i.longest_increasing_subsequence_length() == len(RSK(i)[0][0]) # needs sage.combinat ....: for i in Permutations(5)) True sage: Permutation([]).longest_increasing_subsequence_length() @@ -2254,9 +2256,9 @@ def longest_increasing_subsequences(self): EXAMPLES:: - sage: Permutation([2,3,4,1]).longest_increasing_subsequences() # optional - sage.graphs + sage: Permutation([2,3,4,1]).longest_increasing_subsequences() # needs sage.graphs [[2, 3, 4]] - sage: Permutation([5, 7, 1, 2, 6, 4, 3]).longest_increasing_subsequences() # optional - sage.graphs + sage: Permutation([5, 7, 1, 2, 6, 4, 3]).longest_increasing_subsequences() # needs sage.graphs [[1, 2, 6], [1, 2, 4], [1, 2, 3]] .. NOTE:: @@ -2324,7 +2326,7 @@ def longest_increasing_subsequences_number(self): 120770 sage: p = Permutations(50).random_element() - sage: (len(p.longest_increasing_subsequences()) == # optional - sage.graphs + sage: (len(p.longest_increasing_subsequences()) == # needs sage.graphs ....: p.longest_increasing_subsequences_number()) True """ @@ -2363,7 +2365,7 @@ def cycle_type(self): EXAMPLES:: - sage: Permutation([3,1,2,4]).cycle_type() # optional - sage.combinat + sage: Permutation([3,1,2,4]).cycle_type() # needs sage.combinat [3, 1] """ cycle_type = [len(c) for c in self.to_cycles()] @@ -2421,9 +2423,9 @@ def forget_cycles(self): results as a poset under the Bruhat order:: sage: l = [p.forget_cycles().inverse() for p in l] - sage: B = Poset([l, lambda x,y: x.bruhat_lequal(y)]) # optional - sage.combinat sage.graphs + sage: B = Poset([l, lambda x,y: x.bruhat_lequal(y)]) # needs sage.combinat sage.graphs sage: R. = QQ[] - sage: sum(q^B.rank_function()(x) for x in B) # optional - sage.combinat sage.graphs + sage: sum(q^B.rank_function()(x) for x in B) # needs sage.combinat sage.graphs q^5 + 2*q^4 + 3*q^3 + 3*q^2 + 2*q + 1 We check the statement in [CC2013]_ that the posets @@ -2431,8 +2433,8 @@ def forget_cycles(self): sage: l2 = [p for p in P if [len(t) for t in p.to_cycles()] == [1,3,1,1]] sage: l2 = [p.forget_cycles().inverse() for p in l2] - sage: B2 = Poset([l2, lambda x,y: x.bruhat_lequal(y)]) # optional - sage.combinat sage.graphs - sage: B.is_isomorphic(B2) # optional - sage.combinat sage.graphs + sage: B2 = Poset([l2, lambda x,y: x.bruhat_lequal(y)]) # needs sage.combinat sage.graphs + sage: B.is_isomorphic(B2) # needs sage.combinat sage.graphs True .. SEEALSO:: @@ -2758,7 +2760,7 @@ def destandardize(self, weight, ordered_alphabet=None): EXAMPLES:: sage: p = Permutation([1,2,5,3,6,4]) - sage: p.destandardize([3,1,2]) # optional - sage.combinat + sage: p.destandardize([3,1,2]) # needs sage.combinat word: 113132 sage: p = Permutation([2,1,3]) sage: p.destandardize([2,1]) @@ -2769,7 +2771,7 @@ def destandardize(self, weight, ordered_alphabet=None): TESTS:: sage: p = Permutation([4,1,2,3,5,6]) - sage: p.destandardize([2,1,3], ordered_alphabet = [1,'a',3]) # optional - sage.combinat + sage: p.destandardize([2,1,3], ordered_alphabet = [1,'a',3]) # needs sage.combinat word: 311a33 sage: p.destandardize([2,1,3], ordered_alphabet = [1,'a']) Traceback (most recent call last): @@ -3028,9 +3030,9 @@ def rothe_diagram(self): EXAMPLES:: sage: p = Permutation([4,2,1,3]) - sage: D = p.rothe_diagram(); D # optional - sage.combinat + sage: D = p.rothe_diagram(); D # needs sage.combinat [(0, 0), (0, 1), (0, 2), (1, 0)] - sage: D.pp() # optional - sage.combinat + sage: D.pp() # needs sage.combinat O O O . O . . . . . . . @@ -3047,7 +3049,7 @@ def number_of_reduced_words(self): EXAMPLES:: sage: p = Permutation([6,4,2,5,1,8,3,7]) - sage: len(p.reduced_words()) == p.number_of_reduced_words() # optional - sage.combinat + sage: len(p.reduced_words()) == p.number_of_reduced_words() # needs sage.combinat True """ Tx = self.rothe_diagram().peelable_tableaux() @@ -4231,7 +4233,7 @@ def right_permutohedron_interval_iterator(self, other): EXAMPLES:: sage: p = Permutation([2, 1, 4, 5, 3]); q = Permutation([2, 5, 4, 1, 3]) - sage: p.right_permutohedron_interval(q) # indirect doctest # optional - sage.graphs sage.modules sage.rings.finite_rings + sage: p.right_permutohedron_interval(q) # indirect doctest # needs sage.graphs sage.modules [[2, 4, 5, 1, 3], [2, 4, 1, 5, 3], [2, 1, 4, 5, 3], [2, 1, 5, 4, 3], [2, 5, 1, 4, 3], [2, 5, 4, 1, 3]] """ @@ -4258,27 +4260,28 @@ def right_permutohedron_interval(self, other): EXAMPLES:: sage: p = Permutation([2, 1, 4, 5, 3]); q = Permutation([2, 5, 4, 1, 3]) - sage: p.right_permutohedron_interval(q) # optional - sage.graphs sage.modules sage.rings.finite_rings + sage: p.right_permutohedron_interval(q) # needs sage.graphs sage.modules [[2, 4, 5, 1, 3], [2, 4, 1, 5, 3], [2, 1, 4, 5, 3], [2, 1, 5, 4, 3], [2, 5, 1, 4, 3], [2, 5, 4, 1, 3]] TESTS:: - sage: Permutation([]).right_permutohedron_interval(Permutation([])) # optional - sage.graphs sage.modules sage.rings.finite_rings + sage: # needs sage.graphs sage.modules + sage: Permutation([]).right_permutohedron_interval(Permutation([])) [[]] - sage: Permutation([3, 1, 2]).right_permutohedron_interval(Permutation([3, 1, 2])) # optional - sage.graphs sage.modules sage.rings.finite_rings + sage: Permutation([3, 1, 2]).right_permutohedron_interval(Permutation([3, 1, 2])) [[3, 1, 2]] - sage: Permutation([1, 3, 2, 4]).right_permutohedron_interval(Permutation([3, 4, 2, 1])) # optional - sage.graphs sage.modules sage.rings.finite_rings + sage: Permutation([1, 3, 2, 4]).right_permutohedron_interval(Permutation([3, 4, 2, 1])) [[3, 1, 4, 2], [3, 4, 1, 2], [3, 4, 2, 1], [1, 3, 4, 2], [1, 3, 2, 4], [3, 2, 4, 1], [3, 2, 1, 4], [3, 1, 2, 4]] - sage: Permutation([2, 1, 4, 5, 3]).right_permutohedron_interval(Permutation([2, 5, 4, 1, 3])) # optional - sage.graphs sage.modules sage.rings.finite_rings + sage: Permutation([2, 1, 4, 5, 3]).right_permutohedron_interval(Permutation([2, 5, 4, 1, 3])) [[2, 4, 5, 1, 3], [2, 4, 1, 5, 3], [2, 1, 4, 5, 3], [2, 1, 5, 4, 3], [2, 5, 1, 4, 3], [2, 5, 4, 1, 3]] - sage: Permutation([2, 5, 4, 1, 3]).right_permutohedron_interval(Permutation([2, 1, 4, 5, 3])) # optional - sage.graphs sage.modules sage.rings.finite_rings + sage: Permutation([2, 5, 4, 1, 3]).right_permutohedron_interval(Permutation([2, 1, 4, 5, 3])) Traceback (most recent call last): ... ValueError: [2, 5, 4, 1, 3] must be lower or equal than [2, 1, 4, 5, 3] for the right permutohedron order - sage: Permutation([2, 4, 1, 3]).right_permutohedron_interval(Permutation([2, 1, 4, 5, 3])) # optional - sage.graphs sage.modules sage.rings.finite_rings + sage: Permutation([2, 4, 1, 3]).right_permutohedron_interval(Permutation([2, 1, 4, 5, 3])) Traceback (most recent call last): ... ValueError: len([2, 4, 1, 3]) and len([2, 1, 4, 5, 3]) must be equal @@ -4517,7 +4520,7 @@ def has_pattern(self, patt) -> bool: EXAMPLES:: - sage: Permutation([3,5,1,4,6,2]).has_pattern([1,3,2]) # optional - sage.combinat + sage: Permutation([3,5,1,4,6,2]).has_pattern([1,3,2]) # needs sage.combinat True """ p = self @@ -4537,11 +4540,11 @@ def avoids(self, patt) -> bool: EXAMPLES:: - sage: Permutation([6,2,5,4,3,1]).avoids([4,2,3,1]) # optional - sage.combinat + sage: Permutation([6,2,5,4,3,1]).avoids([4,2,3,1]) # needs sage.combinat False - sage: Permutation([6,1,2,5,4,3]).avoids([4,2,3,1]) # optional - sage.combinat + sage: Permutation([6,1,2,5,4,3]).avoids([4,2,3,1]) # needs sage.combinat True - sage: Permutation([6,1,2,5,4,3]).avoids([3,4,1,2]) # optional - sage.combinat + sage: Permutation([6,1,2,5,4,3]).avoids([3,4,1,2]) # needs sage.combinat True """ return not self.has_pattern(patt) @@ -4553,7 +4556,7 @@ def pattern_positions(self, patt) -> list: EXAMPLES:: - sage: Permutation([3,5,1,4,6,2]).pattern_positions([1,3,2]) # optional - sage.combinat + sage: Permutation([3,5,1,4,6,2]).pattern_positions([1,3,2]) # needs sage.combinat [[0, 1, 3], [2, 3, 5], [2, 4, 5]] """ p = self @@ -4578,7 +4581,7 @@ def simion_schmidt(self, avoid=[1,2,3]): sage: P = Permutations(6) sage: p = P([4,5,1,6,3,2]) sage: pl = [ [1,2,3], [1,3,2], [3,1,2], [3,2,1] ] - sage: for q in pl: # optional - sage.combinat + sage: for q in pl: # needs sage.combinat ....: s = p.simion_schmidt(q) ....: print("{} {}".format(s, s.has_pattern(q))) [4, 6, 1, 5, 3, 2] False @@ -4662,23 +4665,24 @@ def permutation_poset(self): EXAMPLES:: - sage: Permutation([3,1,5,4,2]).permutation_poset().cover_relations() # optional - sage.combinat sage.graphs + sage: # needs sage.combinat sage.graphs + sage: Permutation([3,1,5,4,2]).permutation_poset().cover_relations() [[(2, 1), (5, 2)], [(2, 1), (3, 5)], [(2, 1), (4, 4)], [(1, 3), (3, 5)], [(1, 3), (4, 4)]] - sage: Permutation([]).permutation_poset().cover_relations() # optional - sage.combinat sage.graphs + sage: Permutation([]).permutation_poset().cover_relations() [] - sage: Permutation([1,3,2]).permutation_poset().cover_relations() # optional - sage.combinat sage.graphs + sage: Permutation([1,3,2]).permutation_poset().cover_relations() [[(1, 1), (2, 3)], [(1, 1), (3, 2)]] - sage: Permutation([1,2]).permutation_poset().cover_relations() # optional - sage.combinat sage.graphs + sage: Permutation([1,2]).permutation_poset().cover_relations() [[(1, 1), (2, 2)]] - sage: P = Permutation([1,5,2,4,3]) # optional - sage.combinat sage.graphs + sage: P = Permutation([1,5,2,4,3]) This should hold for any `P`:: - sage: P.permutation_poset().greene_shape() == P.RS_partition() # optional - sage.combinat sage.graphs + sage: P.permutation_poset().greene_shape() == P.RS_partition() # needs sage.combinat sage.graphs True """ from sage.combinat.posets.posets import Poset @@ -4750,7 +4754,7 @@ def robinson_schensted(self): EXAMPLES:: - sage: Permutation([6,2,3,1,7,5,4]).robinson_schensted() # optional - sage.combinat + sage: Permutation([6,2,3,1,7,5,4]).robinson_schensted() # needs sage.combinat [[[1, 3, 4], [2, 5], [6, 7]], [[1, 3, 5], [2, 6], [4, 7]]] """ return RSK(self, check_standard=True) @@ -4782,7 +4786,7 @@ def left_tableau(self): EXAMPLES:: - sage: Permutation([1,4,3,2]).left_tableau() # optional - sage.combinat + sage: Permutation([1,4,3,2]).left_tableau() # needs sage.combinat [[1, 2], [3], [4]] """ return RSK(self, check_standard=True)[0] @@ -4795,7 +4799,7 @@ def right_tableau(self): EXAMPLES:: - sage: Permutation([1,4,3,2]).right_tableau() # optional - sage.combinat + sage: Permutation([1,4,3,2]).right_tableau() # needs sage.combinat [[1, 2], [3], [4]] """ return RSK(self, check_standard=True)[1] @@ -4806,17 +4810,17 @@ def increasing_tree(self, compare=min): EXAMPLES:: - sage: Permutation([1,4,3,2]).increasing_tree() # optional - sage.graphs + sage: Permutation([1,4,3,2]).increasing_tree() # needs sage.graphs 1[., 2[3[4[., .], .], .]] - sage: Permutation([4,1,3,2]).increasing_tree() # optional - sage.graphs + sage: Permutation([4,1,3,2]).increasing_tree() # needs sage.graphs 1[4[., .], 2[3[., .], .]] By passing the option ``compare=max`` one can have the decreasing tree instead:: - sage: Permutation([2,3,4,1]).increasing_tree(max) # optional - sage.graphs + sage: Permutation([2,3,4,1]).increasing_tree(max) # needs sage.graphs 4[3[2[., .], .], 1[., .]] - sage: Permutation([2,3,1,4]).increasing_tree(max) # optional - sage.graphs + sage: Permutation([2,3,1,4]).increasing_tree(max) # needs sage.graphs 4[3[2[., .], 1[., .]], .] """ from sage.combinat.binary_tree import LabelledBinaryTree as LBT @@ -4837,17 +4841,17 @@ def increasing_tree_shape(self, compare=min): EXAMPLES:: - sage: Permutation([1,4,3,2]).increasing_tree_shape() # optional - sage.graphs + sage: Permutation([1,4,3,2]).increasing_tree_shape() # needs sage.graphs [., [[[., .], .], .]] - sage: Permutation([4,1,3,2]).increasing_tree_shape() # optional - sage.graphs + sage: Permutation([4,1,3,2]).increasing_tree_shape() # needs sage.graphs [[., .], [[., .], .]] By passing the option ``compare=max`` one can have the decreasing tree instead:: - sage: Permutation([2,3,4,1]).increasing_tree_shape(max) # optional - sage.graphs + sage: Permutation([2,3,4,1]).increasing_tree_shape(max) # needs sage.graphs [[[., .], .], [., .]] - sage: Permutation([2,3,1,4]).increasing_tree_shape(max) # optional - sage.graphs + sage: Permutation([2,3,1,4]).increasing_tree_shape(max) # needs sage.graphs [[[., .], [., .]], .] """ return self.increasing_tree(compare).shape() @@ -4873,22 +4877,22 @@ def binary_search_tree(self, left_to_right=True): EXAMPLES:: - sage: Permutation([1,4,3,2]).binary_search_tree() # optional - sage.graphs + sage: Permutation([1,4,3,2]).binary_search_tree() # needs sage.graphs 1[., 4[3[2[., .], .], .]] - sage: Permutation([4,1,3,2]).binary_search_tree() # optional - sage.graphs + sage: Permutation([4,1,3,2]).binary_search_tree() # needs sage.graphs 4[1[., 3[2[., .], .]], .] By passing the option ``left_to_right=False`` one can have the insertion going from right to left:: - sage: Permutation([1,4,3,2]).binary_search_tree(False) # optional - sage.graphs + sage: Permutation([1,4,3,2]).binary_search_tree(False) # needs sage.graphs 2[1[., .], 3[., 4[., .]]] - sage: Permutation([4,1,3,2]).binary_search_tree(False) # optional - sage.graphs + sage: Permutation([4,1,3,2]).binary_search_tree(False) # needs sage.graphs 2[1[., .], 3[., 4[., .]]] TESTS:: - sage: Permutation([]).binary_search_tree() # optional - sage.graphs + sage: Permutation([]).binary_search_tree() # needs sage.graphs . """ from sage.combinat.binary_tree import LabelledBinaryTree as LBT @@ -4909,17 +4913,17 @@ def binary_search_tree_shape(self, left_to_right=True): EXAMPLES:: - sage: Permutation([1,4,3,2]).binary_search_tree_shape() # optional - sage.graphs + sage: Permutation([1,4,3,2]).binary_search_tree_shape() # needs sage.graphs [., [[[., .], .], .]] - sage: Permutation([4,1,3,2]).binary_search_tree_shape() # optional - sage.graphs + sage: Permutation([4,1,3,2]).binary_search_tree_shape() # needs sage.graphs [[., [[., .], .]], .] By passing the option ``left_to_right=False`` one can have the insertion going from right to left:: - sage: Permutation([1,4,3,2]).binary_search_tree_shape(False) # optional - sage.graphs + sage: Permutation([1,4,3,2]).binary_search_tree_shape(False) # needs sage.graphs [[., .], [., [., .]]] - sage: Permutation([4,1,3,2]).binary_search_tree_shape(False) # optional - sage.graphs + sage: Permutation([4,1,3,2]).binary_search_tree_shape(False) # needs sage.graphs [[., .], [., [., .]]] """ from sage.combinat.binary_tree import binary_search_tree_shape @@ -4966,7 +4970,7 @@ def sylvester_class(self, left_to_right=False): The sylvester class of a permutation in `S_5`:: sage: p = Permutation([3, 5, 1, 2, 4]) - sage: sorted(p.sylvester_class()) # optional - sage.combinat + sage: sorted(p.sylvester_class()) # needs sage.combinat sage.graphs [[1, 3, 2, 5, 4], [1, 3, 5, 2, 4], [1, 5, 3, 2, 4], @@ -4978,20 +4982,20 @@ def sylvester_class(self, left_to_right=False): The sylvester class of a permutation `p` contains `p`:: - sage: all(p in p.sylvester_class() for p in Permutations(4)) # optional - sage.combinat sage.graphs + sage: all(p in p.sylvester_class() for p in Permutations(4)) # needs sage.combinat sage.graphs True Small cases:: - sage: list(Permutation([]).sylvester_class()) # optional - sage.combinat sage.graphs + sage: list(Permutation([]).sylvester_class()) # needs sage.combinat sage.graphs [[]] - sage: list(Permutation([1]).sylvester_class()) # optional - sage.combinat sage.graphs + sage: list(Permutation([1]).sylvester_class()) # needs sage.combinat sage.graphs [[1]] The sylvester classes in `S_3`:: - sage: [sorted(p.sylvester_class()) for p in Permutations(3)] # optional - sage.combinat sage.graphs + sage: [sorted(p.sylvester_class()) for p in Permutations(3)] # needs sage.combinat sage.graphs [[[1, 2, 3]], [[1, 3, 2], [3, 1, 2]], [[2, 1, 3]], @@ -5001,7 +5005,7 @@ def sylvester_class(self, left_to_right=False): The left sylvester classes in `S_3`:: - sage: [sorted(p.sylvester_class(left_to_right=True)) # optional - sage.combinat sage.graphs + sage: [sorted(p.sylvester_class(left_to_right=True)) # needs sage.combinat sage.graphs ....: for p in Permutations(3)] [[[1, 2, 3]], [[1, 3, 2]], @@ -5013,7 +5017,7 @@ def sylvester_class(self, left_to_right=False): A left sylvester class in `S_5`:: sage: p = Permutation([4, 2, 1, 5, 3]) - sage: sorted(p.sylvester_class(left_to_right=True)) # optional - sage.combinat sage.graphs + sage: sorted(p.sylvester_class(left_to_right=True)) # needs sage.combinat sage.graphs [[4, 2, 1, 3, 5], [4, 2, 1, 5, 3], [4, 2, 3, 1, 5], @@ -5036,7 +5040,7 @@ def RS_partition(self): EXAMPLES:: - sage: Permutation([1,4,3,2]).RS_partition() # optional - sage.combinat + sage: Permutation([1,4,3,2]).RS_partition() # needs sage.combinat [2, 1, 1] """ return RSK(self)[1].shape() @@ -5258,16 +5262,17 @@ def hyperoctahedral_double_coset_type(self): EXAMPLES:: + sage: # needs sage.combinat sage: p = Permutation([3, 4, 6, 1, 5, 7, 2, 8]) - sage: p.hyperoctahedral_double_coset_type() # optional - sage.combinat + sage: p.hyperoctahedral_double_coset_type() [3, 1] - sage: all(p.hyperoctahedral_double_coset_type() == # optional - sage.combinat + sage: all(p.hyperoctahedral_double_coset_type() == ....: p.inverse().hyperoctahedral_double_coset_type() ....: for p in Permutations(4)) True - sage: Permutation([]).hyperoctahedral_double_coset_type() # optional - sage.combinat + sage: Permutation([]).hyperoctahedral_double_coset_type() [] - sage: Permutation([3,1,2]).hyperoctahedral_double_coset_type() # optional - sage.combinat + sage: Permutation([3,1,2]).hyperoctahedral_double_coset_type() Traceback (most recent call last): ... ValueError: [3, 1, 2] is a permutation of odd size and has no coset-type @@ -5344,23 +5349,24 @@ def shifted_shuffle(self, other): EXAMPLES:: - sage: Permutation([]).shifted_shuffle(Permutation([])) # optional - sage.graphs + sage: # needs sage.graphs sage.modules + sage: Permutation([]).shifted_shuffle(Permutation([])) [[]] - sage: Permutation([1, 2, 3]).shifted_shuffle(Permutation([1])) # optional - sage.graphs sage.modules sage.rings.finite_rings + sage: Permutation([1, 2, 3]).shifted_shuffle(Permutation([1])) [[4, 1, 2, 3], [1, 2, 3, 4], [1, 2, 4, 3], [1, 4, 2, 3]] - sage: Permutation([1, 2]).shifted_shuffle(Permutation([2, 1])) # optional - sage.graphs sage.modules sage.rings.finite_rings + sage: Permutation([1, 2]).shifted_shuffle(Permutation([2, 1])) [[4, 1, 3, 2], [4, 3, 1, 2], [1, 4, 3, 2], [1, 4, 2, 3], [1, 2, 4, 3], [4, 1, 2, 3]] - sage: Permutation([1]).shifted_shuffle([1]) # optional - sage.graphs sage.modules sage.rings.finite_rings + sage: Permutation([1]).shifted_shuffle([1]) [[2, 1], [1, 2]] sage: p = Permutation([3, 1, 5, 4, 2]) - sage: len(p.shifted_shuffle(Permutation([2, 1, 4, 3]))) # optional - sage.graphs sage.modules sage.rings.finite_rings + sage: len(p.shifted_shuffle(Permutation([2, 1, 4, 3]))) 126 The shifted shuffle product is associative. We can test this on an admittedly toy example:: - sage: all( all( all( sorted(flatten([abs.shifted_shuffle(c) # optional - sage.graphs sage.modules sage.rings.finite_rings + sage: all( all( all( sorted(flatten([abs.shifted_shuffle(c) # needs sage.graphs sage.modules ....: for abs in a.shifted_shuffle(b)])) ....: == sorted(flatten([a.shifted_shuffle(bcs) ....: for bcs in b.shifted_shuffle(c)])) @@ -5373,7 +5379,7 @@ def shifted_shuffle(self, other): permutations as the ``shifted_shuffle`` method on words (but is faster):: - sage: all( all( sorted(p1.shifted_shuffle(p2)) # optional - sage.graphs sage.modules sage.rings.finite_rings + sage: all( all( sorted(p1.shifted_shuffle(p2)) # needs sage.combinat sage.graphs sage.modules sage.rings.finite_rings ....: == sorted([Permutation(p) for p in ....: Word(p1).shifted_shuffle(Word(p2))]) ....: for p2 in Permutations(3) ) @@ -5383,6 +5389,253 @@ def shifted_shuffle(self, other): return self.shifted_concatenation(other, "right").\ right_permutohedron_interval(self.shifted_concatenation(other, "left")) + def nth_roots(self, n): + r""" + Return all n-th roots of ``self`` (as a generator). + + An n-th root of the permutation `\sigma` is a permutation `\gamma` such that `\gamma^n = \sigma`. + + Note that the number of n-th roots only depends on the cycle type of ``self``. + + EXAMPLES:: + + sage: sigma = Permutations(5).identity() + sage: list(sigma.nth_roots(3)) + [[1, 4, 3, 5, 2], [1, 5, 3, 2, 4], [1, 2, 4, 5, 3], [1, 2, 5, 3, 4], [4, 2, 3, 5, 1], [5, 2, 3, 1, 4], [3, 2, 5, 4, 1], + [5, 2, 1, 4, 3], [2, 5, 3, 4, 1], [5, 1, 3, 4, 2], [2, 3, 1, 4, 5], [3, 1, 2, 4, 5], [2, 4, 3, 1, 5], [4, 1, 3, 2, 5], + [3, 2, 4, 1, 5], [4, 2, 1, 3, 5], [1, 3, 4, 2, 5], [1, 4, 2, 3, 5], [1, 3, 5, 4, 2], [1, 5, 2, 4, 3], [1, 2, 3, 4, 5]] + + sage: sigma = Permutation('(1, 3)') + sage: list(sigma.nth_roots(2)) + [] + + For n >= 6, this algorithm begins to be more efficient than naive search + (look at all permutations and test their n-th power). + + .. SEEALSO:: + + * :meth:`has_nth_root` + * :meth:`number_of_nth_roots` + + TESTS: + + We compute the number of square roots of the identity (i.e. involutions in `S_n`, :oeis:`A000085`):: + + sage: [len(list(Permutations(n).identity().nth_roots(2))) for n in range(2,8)] + [2, 4, 10, 26, 76, 232] + + sage: list(Permutation('(1)').nth_roots(2)) + [[1]] + + sage: list(Permutation('').nth_roots(2)) + [[]] + + sage: sigma = Permutations(6).random_element() + sage: list(sigma.nth_roots(1)) == [sigma] + True + + sage: list(Permutations(4).identity().nth_roots(-1)) + Traceback (most recent call last): + ... + ValueError: n must be at least 1 + """ + from sage.combinat.partition import Partitions + from sage.combinat.set_partition import SetPartitions + from itertools import product + from sage.arith.misc import divisors, gcd + + def merging_cycles(list_of_cycles): + """ + Generate all l-cycles such that its n-th power is the product + of cycles in 'cycles' (which contains gcd(l, n) cycles of length l/gcd(l, n)) + """ + lC = len(list_of_cycles) + lperm = len(list_of_cycles[0]) + l = lC*lperm + perm = [0] * l + for j in range(lperm): + perm[j*lC] = list_of_cycles[0][j] + for p in Permutations(lC-1): + for indices in product(*[range(lperm) for _ in range(lC-1)]): + new_perm = list(perm) + for i in range(lC-1): + for j in range(lperm): + new_perm[(p[i] + (indices[i]+j)*lC) % l] = list_of_cycles[i+1][j] + yield Permutation(tuple(new_perm)) + + def rewind(L, n): + """ + Construct the list M such that ``M[(j * n) % len(M)] == L[j]``. + """ + M = [0] * len(L) + m = len(M) + for j in range(m): + M[(j * n) % m] = L[j] + return M + + if n < 1: + raise ValueError('n must be at least 1') + + P = Permutations(self.size()) + + # Creating dict {length: cycles of this length in the cycle decomposition of sigma} + cycles = {} + for c in self.cycle_tuples(singletons=True): + lc = len(c) + if lc not in cycles: + cycles[lc] = [] + cycles[lc].append(c) + + # for each length m, collects all product of cycles which n-th power gives the product prod(cycles[l]) + possibilities = [[] for m in cycles] + for i, m in enumerate(cycles): + N = len(cycles[m]) + parts = [x for x in divisors(n) if gcd(m*x, n) == x] + b = False + for X in Partitions(N, parts_in=parts): + for partition in SetPartitions(N, X): + b = True + poss = [P.identity()] + for pa in partition: + poss = [p*q for p in poss + for q in merging_cycles([rewind(cycles[m][i-1], n//len(pa)) for i in pa])] + possibilities[i] += poss + if not b: + return + + # Product of Possibilities (i.e. final result) + for L in product(*possibilities): + yield P.prod(L) + + def has_nth_root(self, n) -> bool: + r""" + Decide if ``self`` has n-th roots. + + An n-th root of the permutation `\sigma` is a permutation `\gamma` such that `\gamma^n = \sigma`. + + Note that the number of n-th roots only depends on the cycle type of ``self``. + + EXAMPLES:: + + sage: sigma = Permutations(5).identity() + sage: sigma.has_nth_root(3) + True + + sage: sigma = Permutation('(1, 3)') + sage: sigma.has_nth_root(2) + False + + .. SEEALSO:: + + * :meth:`nth_roots` + * :meth:`number_of_nth_roots` + + TESTS: + + We compute the number of permutations that have square roots (i.e. squares in `S_n`, :oeis:`A003483`):: + + sage: [len([p for p in Permutations(n) if p.has_nth_root(2)]) for n in range(2, 7)] + [1, 3, 12, 60, 270] + + sage: Permutation('(1)').has_nth_root(2) + True + + sage: Permutation('').has_nth_root(2) + True + + sage: sigma = Permutations(6).random_element() + sage: sigma.has_nth_root(1) + True + + sage: Permutations(4).identity().has_nth_root(-1) + Traceback (most recent call last): + ... + ValueError: n must be at least 1 + """ + from sage.combinat.partition import Partitions + from sage.arith.misc import divisors, gcd + + if n < 1: + raise ValueError('n must be at least 1') + + cycles = self.cycle_type().to_exp_dict() + + # for each length m, check if the number of m-cycles can come from a n-th power + # (i.e. if you can partition m*Cycles[m] into parts of size l with l = m*gcd(l, n)) + for m, N in cycles.items(): + parts = [x for x in divisors(n) if gcd(m*x, n) == x] + if Partitions(N, parts_in=parts).is_empty(): + return False + return True + + def number_of_nth_roots(self, n): + r""" + Return the number of n-th roots of ``self``. + + An n-th root of the permutation `\sigma` is a permutation `\gamma` such that `\gamma^n = \sigma`. + + Note that the number of n-th roots only depends on the cycle type of ``self``. + + EXAMPLES:: + + sage: Sigma = Permutations(5).identity() + sage: Sigma.number_of_nth_roots(3) + 21 + + sage: Sigma = Permutation('(1, 3)') + sage: Sigma.number_of_nth_roots(2) + 0 + + .. SEEALSO:: + + * :meth:`nth_roots` + * :meth:`has_nth_root` + + TESTS: + + We compute the number of square roots of the identity (i.e. involutions in `S_n`, :oeis:`A000085`), then the number of cubic roots:: + + sage: [Permutations(n).identity().number_of_nth_roots(2) for n in range(2, 10)] + [2, 4, 10, 26, 76, 232, 764, 2620] + + sage: [Permutations(n).identity().number_of_nth_roots(3) for n in range(2, 10)] + [1, 3, 9, 21, 81, 351, 1233, 5769] + + sage: Permutation('(1)').number_of_nth_roots(2) + 1 + + sage: Permutation('').number_of_nth_roots(2) + 1 + + sage: Sigma = Permutations(6).random_element() + sage: Sigma.number_of_nth_roots(1) + 1 + + sage: Permutations(4).identity().number_of_nth_roots(-1) + Traceback (most recent call last): + ... + ValueError: n must be at least 1 + """ + from sage.combinat.partition import Partitions + from sage.combinat.set_partition import SetPartitions + from sage.arith.misc import divisors, gcd + from sage.misc.misc_c import prod + + if n < 1: + raise ValueError('n must be at least 1') + + cycles = self.cycle_type().to_exp_dict() + result = 1 + for m, N in cycles.items(): + parts = [x for x in divisors(n) if gcd(m*x, n) == x] + result *= sum(SetPartitions(N, pa).cardinality() * + prod(factorial(x-1) * m**(x-1) for x in pa) + for pa in Partitions(N, parts_in=parts)) + + if not result: + return 0 + + return result def _tableau_contribution(T): r""" @@ -5390,9 +5643,9 @@ def _tableau_contribution(T): EXAMPLES:: - sage: T = Tableau([[1,1,1],[2]]) # optional - sage.combinat + sage: T = Tableau([[1,1,1],[2]]) # needs sage.combinat sage: from sage.combinat.permutation import _tableau_contribution - sage: _tableau_contribution(T) # optional - sage.combinat + sage: _tableau_contribution(T) # needs sage.combinat 3 """ from sage.combinat.tableau import StandardTableaux @@ -5482,7 +5735,7 @@ class Permutations(UniqueRepresentation, Parent): sage: p = Permutations(['c', 'a', 't'], 2); p Permutations of the set ['c', 'a', 't'] of length 2 - sage: p.list() # optional - sage.libs.gap + sage: p.list() [['c', 'a'], ['c', 't'], ['a', 'c'], ['a', 't'], ['t', 'c'], ['t', 'a']] :: @@ -5496,14 +5749,14 @@ class Permutations(UniqueRepresentation, Parent): sage: p = Permutations([1,1,2], 2); p Permutations of the multi-set [1, 1, 2] of length 2 - sage: p.list() # optional - sage.libs.gap + sage: p.list() # needs sage.libs.gap [[1, 1], [1, 2], [2, 1]] :: sage: p = Permutations(descents=([1], 4)); p Standard permutations of 4 with descents [1] - sage: p.list() # optional - sage.graphs sage.modules sage.rings.finite_rings + sage: p.list() # needs sage.graphs sage.modules [[2, 4, 1, 3], [3, 4, 1, 2], [1, 4, 2, 3], [1, 3, 2, 4], [2, 3, 1, 4]] :: @@ -5526,28 +5779,28 @@ class Permutations(UniqueRepresentation, Parent): sage: p = Permutations(recoils_finer=[2,1]); p Standard permutations whose recoils composition is finer than [2, 1] - sage: p.list() # optional - sage.graphs sage.modules sage.rings.finite_rings + sage: p.list() # needs sage.graphs sage.modules [[3, 1, 2], [1, 2, 3], [1, 3, 2]] :: sage: p = Permutations(recoils_fatter=[2,1]); p Standard permutations whose recoils composition is fatter than [2, 1] - sage: p.list() # optional - sage.graphs + sage: p.list() # needs sage.graphs sage.modules [[3, 1, 2], [3, 2, 1], [1, 3, 2]] :: sage: p = Permutations(recoils=[2,1]); p Standard permutations whose recoils composition is [2, 1] - sage: p.list() # optional - sage.graphs + sage: p.list() # needs sage.graphs sage.modules [[3, 1, 2], [1, 3, 2]] :: sage: p = Permutations(4, avoiding=[1,3,2]); p Standard permutations of 4 avoiding [[1, 3, 2]] - sage: p.list() # optional - sage.combinat + sage: p.list() [[4, 1, 2, 3], [4, 2, 1, 3], [4, 2, 3, 1], @@ -5567,9 +5820,9 @@ class Permutations(UniqueRepresentation, Parent): sage: p = Permutations(5, avoiding=[[3,4,1,2], [4,2,3,1]]); p Standard permutations of 5 avoiding [[3, 4, 1, 2], [4, 2, 3, 1]] - sage: p.cardinality() # optional - sage.combinat + sage: p.cardinality() # needs sage.combinat 88 - sage: p.random_element().parent() is p # optional - sage.combinat + sage: p.random_element().parent() is p # needs sage.combinat True """ @staticmethod @@ -5916,14 +6169,16 @@ class Permutations_mset(Permutations): [2, 2, 1, 1, 2], [2, 2, 1, 2, 1], [2, 2, 2, 1, 1]] - sage: MS = MatrixSpace(GF(2), 2, 2) # optional - sage.modules sage.rings.finite_rings - sage: A = MS([1,0,1,1]) # optional - sage.modules sage.rings.finite_rings - sage: rows = A.rows() # optional - sage.modules sage.rings.finite_rings - sage: rows[0].set_immutable() # optional - sage.modules sage.rings.finite_rings - sage: rows[1].set_immutable() # optional - sage.modules sage.rings.finite_rings - sage: P = Permutations_mset(rows); P # optional - sage.modules sage.rings.finite_rings + + sage: # needs sage.modules + sage: MS = MatrixSpace(GF(2), 2, 2) + sage: A = MS([1,0,1,1]) + sage: rows = A.rows() + sage: rows[0].set_immutable() + sage: rows[1].set_immutable() + sage: P = Permutations_mset(rows); P Permutations of the multi-set [(1, 0), (1, 1)] - sage: sorted(P) # optional - sage.modules sage.rings.finite_rings + sage: sorted(P) [[(1, 0), (1, 1)], [(1, 1), (1, 0)]] """ @staticmethod @@ -6433,7 +6688,7 @@ def __init__(self, mset, k): TESTS:: sage: P = Permutations([1,2,2],2) - sage: TestSuite(P).run() # optional - sage.libs.gap + sage: TestSuite(P).run() # needs sage.libs.gap """ Permutations_mset.__init__(self, mset) self._k = k @@ -6477,7 +6732,7 @@ def cardinality(self): EXAMPLES:: - sage: Permutations([1,2,2], 2).cardinality() # optional - sage.libs.gap + sage: Permutations([1,2,2], 2).cardinality() # needs sage.libs.gap 3 """ return ZZ.sum(1 for z in self) @@ -6486,7 +6741,7 @@ def __iter__(self): """ EXAMPLES:: - sage: Permutations([1,2,2], 2).list() # optional - sage.libs.gap + sage: Permutations([1,2,2], 2).list() # needs sage.libs.gap [[1, 2], [2, 1], [2, 2]] """ mset = self.mset @@ -6595,7 +6850,7 @@ class Arrangements(Permutations): EXAMPLES:: sage: mset = [1,1,2,3,4,4,5] - sage: Arrangements(mset, 2).list() # optional - sage.libs.gap + sage: Arrangements(mset, 2).list() # needs sage.libs.gap [[1, 1], [1, 2], [1, 3], @@ -6618,11 +6873,11 @@ class Arrangements(Permutations): [5, 2], [5, 3], [5, 4]] - sage: Arrangements(mset, 2).cardinality() # optional - sage.libs.gap + sage: Arrangements(mset, 2).cardinality() # needs sage.libs.gap 22 - sage: Arrangements( ["c","a","t"], 2 ).list() # optional - sage.libs.gap + sage: Arrangements( ["c","a","t"], 2 ).list() [['c', 'a'], ['c', 't'], ['a', 'c'], ['a', 't'], ['t', 'c'], ['t', 'a']] - sage: Arrangements( ["c","a","t"], 3 ).list() # optional - sage.libs.gap + sage: Arrangements( ["c","a","t"], 3 ).list() [['c', 'a', 't'], ['c', 't', 'a'], ['a', 'c', 't'], @@ -6654,7 +6909,7 @@ def cardinality(self): EXAMPLES:: sage: A = Arrangements([1,1,2,3,4,4,5], 2) - sage: A.cardinality() # optional - sage.libs.gap + sage: A.cardinality() # needs sage.libs.gap 22 """ one = ZZ.one() @@ -6820,21 +7075,23 @@ def _element_constructor_(self, x, check=True): sage: P([2,3,1]) [2, 3, 1, 4, 5] - sage: G = SymmetricGroup(4) # optional - sage.groups + sage: # needs sage.groups + sage: G = SymmetricGroup(4) sage: P = Permutations(4) - sage: x = G([4,3,1,2]); x # optional - sage.groups + sage: x = G([4,3,1,2]); x (1,4,2,3) - sage: P(x) # optional - sage.groups + sage: P(x) [4, 3, 1, 2] - sage: G(P(x)) # optional - sage.groups + sage: G(P(x)) (1,4,2,3) - sage: P = PermutationGroup([[(1,3,5),(2,4)],[(1,3)]]) # optional - sage.groups - sage: x = P([(3,5),(2,4)]); x # optional - sage.groups + sage: # needs sage.groups + sage: P = PermutationGroup([[(1,3,5),(2,4)],[(1,3)]]) + sage: x = P([(3,5),(2,4)]); x (2,4)(3,5) - sage: Permutations(6)(SymmetricGroup(6)(x)) # optional - sage.groups + sage: Permutations(6)(SymmetricGroup(6)(x)) [1, 4, 5, 2, 3, 6] - sage: Permutations(6)(x) # known bug # optional - sage.groups + sage: Permutations(6)(x) # known bug [1, 4, 5, 2, 3, 6] """ if len(x) < self.n: @@ -6925,20 +7182,20 @@ def _coerce_map_from_(self, G): EXAMPLES:: sage: P = Permutations(6) - sage: P.has_coerce_map_from(SymmetricGroup(6)) # optional - sage.groups + sage: P.has_coerce_map_from(SymmetricGroup(6)) # needs sage.groups True - sage: P.has_coerce_map_from(SymmetricGroup(5)) # optional - sage.groups + sage: P.has_coerce_map_from(SymmetricGroup(5)) # needs sage.groups True - sage: P.has_coerce_map_from(SymmetricGroup(7)) # optional - sage.groups + sage: P.has_coerce_map_from(SymmetricGroup(7)) # needs sage.groups False sage: P.has_coerce_map_from(Permutations(5)) True sage: P.has_coerce_map_from(Permutations(7)) False - sage: P.has_coerce_map_from(groups.misc.Cactus(5)) # optional - sage.groups + sage: P.has_coerce_map_from(groups.misc.Cactus(5)) # needs sage.graphs sage.groups True - sage: P.has_coerce_map_from(groups.misc.Cactus(7)) # optional - sage.groups + sage: P.has_coerce_map_from(groups.misc.Cactus(7)) # needs sage.graphs sage.groups False """ if isinstance(G, SymmetricGroup): @@ -6959,9 +7216,9 @@ def _from_permutation_group_element(self, x): TESTS:: sage: P = Permutations(4) - sage: G = SymmetricGroup(4) # optional - sage.groups - sage: x = G([4,3,1,2]) # optional - sage.groups - sage: P._from_permutation_group_element(x) # optional - sage.groups + sage: G = SymmetricGroup(4) # needs sage.groups + sage: x = G([4,3,1,2]) # needs sage.groups + sage: P._from_permutation_group_element(x) # needs sage.groups [4, 3, 1, 2] """ return self(x.domain()) @@ -6972,11 +7229,12 @@ def _from_cactus_group_element(self, x): EXAMPLES:: - sage: J3 = groups.misc.Cactus(3) # optional - sage.groups - sage: s12,s13,s23 = J3.gens() # optional - sage.groups - sage: elt = s12 * s23 * s13 # optional - sage.groups - sage: P5 = Permutations(5) # optional - sage.groups - sage: P5._from_cactus_group_element(elt) # optional - sage.groups + sage: # needs sage.graphs sage.groups + sage: J3 = groups.misc.Cactus(3) + sage: s12,s13,s23 = J3.gens() + sage: elt = s12 * s23 * s13 + sage: P5 = Permutations(5) + sage: P5._from_cactus_group_element(elt) [1, 3, 2, 4, 5] """ return self(x.to_permutation()) @@ -6988,11 +7246,11 @@ def as_permutation_group(self): EXAMPLES:: sage: P = Permutations(4) - sage: PG = P.as_permutation_group(); PG # optional - sage.groups + sage: PG = P.as_permutation_group(); PG # needs sage.groups Symmetric group of order 4! as a permutation group - sage: G = SymmetricGroup(4) # optional - sage.groups - sage: PG is G # optional - sage.groups + sage: G = SymmetricGroup(4) # needs sage.groups + sage: PG is G # needs sage.groups True """ from sage.groups.perm_gps.permgroup_named import SymmetricGroup @@ -7141,9 +7399,9 @@ def element_in_conjugacy_classes(self, nu): EXAMPLES:: sage: PP = Permutations(5) - sage: PP.element_in_conjugacy_classes([2,2]) # optional - sage.combinat + sage: PP.element_in_conjugacy_classes([2,2]) # needs sage.combinat [2, 1, 4, 3, 5] - sage: PP.element_in_conjugacy_classes([5, 5]) + sage: PP.element_in_conjugacy_classes([5, 5]) # needs sage.combinat Traceback (most recent call last): ... ValueError: the size of the partition (=10) should be at most the size of the permutations (=5) @@ -7177,7 +7435,7 @@ def conjugacy_classes_representatives(self): EXAMPLES:: sage: G = Permutations(5) - sage: G.conjugacy_classes_representatives() # optional - sage.combinat + sage: G.conjugacy_classes_representatives() # needs sage.combinat sage.libs.flint [[1, 2, 3, 4, 5], [2, 1, 3, 4, 5], [2, 1, 4, 3, 5], @@ -7191,10 +7449,10 @@ def conjugacy_classes_representatives(self): Check some border cases:: sage: S = Permutations(0) - sage: S.conjugacy_classes_representatives() # optional - sage.combinat + sage: S.conjugacy_classes_representatives() # needs sage.combinat sage.libs.flint [[]] sage: S = Permutations(1) - sage: S.conjugacy_classes_representatives() # optional - sage.combinat + sage: S.conjugacy_classes_representatives() # needs sage.combinat sage.libs.flint [[1]] """ from sage.combinat.partition import Partitions_n @@ -7208,7 +7466,7 @@ def conjugacy_classes_iterator(self): EXAMPLES:: sage: G = Permutations(4) - sage: list(G.conjugacy_classes_iterator()) == G.conjugacy_classes() # optional - sage.combinat sage.graphs + sage: list(G.conjugacy_classes_iterator()) == G.conjugacy_classes() # needs sage.combinat sage.graphs sage.groups True """ from sage.combinat.partition import Partitions_n @@ -7223,7 +7481,7 @@ def conjugacy_classes(self): EXAMPLES:: sage: G = Permutations(4) - sage: G.conjugacy_classes() # optional - sage.combinat sage.graphs + sage: G.conjugacy_classes() # needs sage.combinat sage.graphs sage.groups [Conjugacy class of cycle type [1, 1, 1, 1] in Standard permutations of 4, Conjugacy class of cycle type [2, 1, 1] in Standard permutations of 4, Conjugacy class of cycle type [2, 2] in Standard permutations of 4, @@ -7244,9 +7502,9 @@ def conjugacy_class(self, g): sage: G = Permutations(5) sage: g = G([2,3,4,1,5]) - sage: G.conjugacy_class(g) # optional - sage.combinat sage.graphs + sage: G.conjugacy_class(g) # needs sage.combinat sage.graphs sage.groups Conjugacy class of cycle type [4, 1] in Standard permutations of 5 - sage: G.conjugacy_class(Partition([2, 1, 1, 1])) # optional - sage.combinat sage.graphs + sage: G.conjugacy_class(Partition([2, 1, 1, 1])) # needs sage.combinat sage.graphs sage.groups Conjugacy class of cycle type [2, 1, 1, 1] in Standard permutations of 5 """ from sage.groups.perm_gps.symgp_conjugacy_class import PermutationsConjugacyClass @@ -7263,17 +7521,17 @@ def algebra(self, base_ring, category=None): EXAMPLES:: + sage: # needs sage.groups sage.modules sage: P = Permutations(4) - sage: A = P.algebra(QQ); A # optional - sage.combinat sage.modules + sage: A = P.algebra(QQ); A Symmetric group algebra of order 4 over Rational Field - - sage: A.category() # optional - sage.combinat sage.modules + sage: A.category() Join of Category of Coxeter group algebras over Rational Field and Category of finite group algebras over Rational Field and Category of finite dimensional cellular algebras with basis over Rational Field - sage: A = P.algebra(QQ, category=Monoids()) # optional - sage.combinat sage.modules - sage: A.category() # optional - sage.combinat sage.modules + sage: A = P.algebra(QQ, category=Monoids()) + sage: A.category() Category of finite dimensional cellular monoid algebras over Rational Field """ from sage.combinat.symmetric_group_algebra import SymmetricGroupAlgebra @@ -7302,9 +7560,9 @@ def cartan_type(self): EXAMPLES:: - sage: A = SymmetricGroup([2,3,7]); A.cartan_type() # optional - sage.combinat sage.groups + sage: A = SymmetricGroup([2,3,7]); A.cartan_type() # needs sage.combinat sage.groups ['A', 2] - sage: A = SymmetricGroup([]); A.cartan_type() # optional - sage.combinat sage.groups + sage: A = SymmetricGroup([]); A.cartan_type() # needs sage.combinat sage.groups ['A', 0] """ from sage.combinat.root_system.cartan_type import CartanType @@ -7569,8 +7827,8 @@ def from_permutation_group_element(pge, parent=None): EXAMPLES:: sage: import sage.combinat.permutation as permutation - sage: pge = PermutationGroupElement([(1,2),(3,4)]) # optional - sage.groups - sage: permutation.from_permutation_group_element(pge) # optional - sage.groups + sage: pge = PermutationGroupElement([(1,2),(3,4)]) # needs sage.groups + sage: permutation.from_permutation_group_element(pge) # needs sage.groups [2, 1, 4, 3] """ if not isinstance(pge, PermutationGroupElement): @@ -7874,39 +8132,36 @@ def bistochastic_as_sum_of_permutations(M, check=True): try to deduce the decomposition from the matrix:: sage: from sage.combinat.permutation import bistochastic_as_sum_of_permutations + + sage: # needs networkx sage.graphs sage.modules sage: L = [] sage: L.append((9,Permutation([4, 1, 3, 5, 2]))) sage: L.append((6,Permutation([5, 3, 4, 1, 2]))) sage: L.append((3,Permutation([3, 1, 4, 2, 5]))) sage: L.append((2,Permutation([1, 4, 2, 3, 5]))) - sage: M = sum([c * p.to_matrix() for (c,p) in L]) # optional - sage.modules - sage: decomp = bistochastic_as_sum_of_permutations(M) # optional - sage.graphs sage.modules - sage: print(decomp) # optional - sage.graphs sage.modules + sage: M = sum([c * p.to_matrix() for (c,p) in L]) + sage: decomp = bistochastic_as_sum_of_permutations(M) + sage: print(decomp) 2*B[[1, 4, 2, 3, 5]] + 3*B[[3, 1, 4, 2, 5]] + 9*B[[4, 1, 3, 5, 2]] + 6*B[[5, 3, 4, 1, 2]] An exception is raised when the matrix is not positive and bistochastic:: - sage: M = Matrix([[2,3],[2,2]]) # optional - sage.modules - sage: decomp = bistochastic_as_sum_of_permutations(M) # optional - sage.graphs sage.modules + sage: # needs sage.modules + sage: M = Matrix([[2,3],[2,2]]) + sage: decomp = bistochastic_as_sum_of_permutations(M) Traceback (most recent call last): ... ValueError: The matrix is not bistochastic - - sage: bistochastic_as_sum_of_permutations(Matrix(GF(7), 2, [2,1,1,2])) # optional - sage.graphs sage.modules sage.rings.finite_rings + sage: bistochastic_as_sum_of_permutations(Matrix(GF(7), 2, [2,1,1,2])) Traceback (most recent call last): ... ValueError: The base ring of the matrix must have a coercion map to RR - - sage: bistochastic_as_sum_of_permutations(Matrix(ZZ, 2, [2,-1,-1,2])) # optional - sage.graphs sage.modules + sage: bistochastic_as_sum_of_permutations(Matrix(ZZ, 2, [2,-1,-1,2])) Traceback (most recent call last): ... ValueError: The matrix should have nonnegative entries """ - from sage.graphs.bipartite_graph import BipartiteGraph - from sage.combinat.free_module import CombinatorialFreeModule - from sage.rings.real_mpfr import RR - n = M.nrows() if n != M.ncols(): @@ -7918,9 +8173,14 @@ def bistochastic_as_sum_of_permutations(M, check=True): if check and not M.is_bistochastic(normalized=False): raise ValueError("The matrix is not bistochastic") + from sage.rings.real_mpfr import RR + if not RR.has_coerce_map_from(M.base_ring()): raise ValueError("The base ring of the matrix must have a coercion map to RR") + from sage.graphs.bipartite_graph import BipartiteGraph + from sage.combinat.free_module import CombinatorialFreeModule + CFM = CombinatorialFreeModule(M.base_ring(), Permutations(n)) value = 0 @@ -7965,12 +8225,12 @@ def bounded_affine_permutation(A): EXAMPLES:: sage: from sage.combinat.permutation import bounded_affine_permutation - sage: A = Matrix(ZZ, [[1,0,0,0], [0,1,0,0]]) # optional - sage.modules - sage: bounded_affine_permutation(A) # optional - sage.modules + sage: A = Matrix(ZZ, [[1,0,0,0], [0,1,0,0]]) # needs sage.modules + sage: bounded_affine_permutation(A) # needs sage.libs.flint sage.modules [5, 6, 3, 4] - sage: A = Matrix(ZZ, [[0,1,0,1,0], [0,0,1,1,0]]) # optional - sage.modules - sage: bounded_affine_permutation(A) # optional - sage.modules + sage: A = Matrix(ZZ, [[0,1,0,1,0], [0,0,1,1,0]]) # needs sage.modules + sage: bounded_affine_permutation(A) # needs sage.libs.flint sage.modules [1, 4, 7, 8, 5] REFERENCES: @@ -8030,7 +8290,7 @@ def __init__(self, d, n): TESTS:: sage: P = Permutations(descents=([1,0,2], 5)) - sage: TestSuite(P).run() # optional - sage.graphs + sage: TestSuite(P).run() # needs sage.graphs sage.modules """ StandardPermutations_n_abstract.__init__(self, n) self._d = d @@ -8068,13 +8328,13 @@ def cardinality(self): sage: def P(D, n): ....: return Permutations(descents=(D, n + 1)) - sage: all(P(D, n).cardinality() == len(P(D, n).list()) # optional - sage.graphs sage.modules sage.rings.finite_rings + sage: all(P(D, n).cardinality() == len(P(D, n).list()) # needs sage.graphs sage.modules ....: for n in range(5) for D in subsets(range(n))) True sage: n = 20 sage: D = [6, 8, 10, 11, 12, 13, 14, 15, 17, 19] - sage: P(D, n).cardinality() # optional - sage.graphs + sage: P(D, n).cardinality() 125291047596 """ @@ -8133,7 +8393,7 @@ def __iter__(self): EXAMPLES:: - sage: Permutations(descents=([2,0],5)).list() # optional - sage.graphs sage.modules sage.rings.finite_rings + sage: Permutations(descents=([2,0],5)).list() # needs sage.graphs sage.modules [[5, 2, 4, 1, 3], [5, 3, 4, 1, 2], [4, 3, 5, 1, 2], @@ -8162,7 +8422,7 @@ def descents_composition_list(dc): EXAMPLES:: sage: import sage.combinat.permutation as permutation - sage: permutation.descents_composition_list([1,2,2]) # optional - sage.graphs sage.modules sage.rings.finite_rings + sage: permutation.descents_composition_list([1,2,2]) # needs sage.graphs sage.modules [[5, 2, 4, 1, 3], [5, 3, 4, 1, 2], [4, 3, 5, 1, 2], @@ -8255,7 +8515,7 @@ def __init__(self, recoils): TESTS:: sage: P = Permutations(recoils_finer=[2,2]) - sage: TestSuite(P).run() # optional - sage.graphs + sage: TestSuite(P).run() # needs sage.graphs """ Permutations.__init__(self, category=FiniteEnumeratedSets()) self.recoils = recoils @@ -8276,7 +8536,7 @@ def __iter__(self): EXAMPLES:: - sage: Permutations(recoils_finer=[2,2]).list() # optional - sage.graphs sage.modules sage.rings.finite_rings + sage: Permutations(recoils_finer=[2,2]).list() # needs sage.graphs sage.modules [[3, 1, 4, 2], [3, 4, 1, 2], [1, 3, 4, 2], @@ -8323,7 +8583,7 @@ def __init__(self, recoils): TESTS:: sage: P = Permutations(recoils_fatter=[2,2]) - sage: TestSuite(P).run() # optional - sage.graphs + sage: TestSuite(P).run() # needs sage.graphs """ Permutations.__init__(self, category=FiniteEnumeratedSets()) self.recoils = recoils @@ -8344,7 +8604,7 @@ def __iter__(self): EXAMPLES:: - sage: Permutations(recoils_fatter=[2,2]).list() # optional - sage.graphs sage.modules sage.rings.finite_rings + sage: Permutations(recoils_fatter=[2,2]).list() # needs sage.graphs sage.modules [[4, 3, 2, 1], [3, 2, 1, 4], [3, 2, 4, 1], @@ -8398,7 +8658,7 @@ def __init__(self, recoils): TESTS:: sage: P = Permutations(recoils=[2,2]) - sage: TestSuite(P).run() # optional - sage.graphs + sage: TestSuite(P).run() # needs sage.graphs """ Permutations.__init__(self, category=FiniteEnumeratedSets()) self.recoils = recoils @@ -8419,7 +8679,7 @@ def __iter__(self): EXAMPLES:: - sage: Permutations(recoils=[2,2]).list() # optional - sage.graphs + sage: Permutations(recoils=[2,2]).list() # needs sage.graphs sage.modules [[3, 1, 4, 2], [3, 4, 1, 2], [1, 3, 4, 2], [1, 3, 2, 4], [3, 1, 2, 4]] """ recoils = self.recoils @@ -8724,16 +8984,17 @@ def to_standard(p, key=None): EXAMPLES:: + sage: # needs sage.combinat sage: import sage.combinat.permutation as permutation - sage: permutation.to_standard([4,2,7]) # optional - sage.combinat + sage: permutation.to_standard([4,2,7]) [2, 1, 3] - sage: permutation.to_standard([1,2,3]) # optional - sage.combinat + sage: permutation.to_standard([1,2,3]) [1, 2, 3] - sage: permutation.to_standard([]) # optional - sage.combinat + sage: permutation.to_standard([]) [] - sage: permutation.to_standard([1,2,3], key=lambda x: -x) # optional - sage.combinat + sage: permutation.to_standard([1,2,3], key=lambda x: -x) [3, 2, 1] - sage: permutation.to_standard([5,8,2,5], key=lambda x: -x) # optional - sage.combinat + sage: permutation.to_standard([5,8,2,5], key=lambda x: -x) [2, 1, 4, 3] TESTS: @@ -8741,7 +9002,7 @@ def to_standard(p, key=None): Does not mutate the list:: sage: a = [1,2,4] - sage: permutation.to_standard(a) # optional - sage.combinat + sage: permutation.to_standard(a) # needs sage.combinat [1, 2, 3] sage: a [1, 2, 4] @@ -8760,8 +9021,8 @@ def to_standard(p, key=None): ....: i += 1 ....: c[smallest_index] = biggest ....: return Permutations()(s) - sage: p = list(Words(100, 1000).random_element()) # optional - sage.combinat - sage: std(p) == permutation.to_standard(p) # optional - sage.combinat + sage: p = list(Words(100, 1000).random_element()) # needs sage.combinat + sage: std(p) == permutation.to_standard(p) # needs sage.combinat True """ ev_dict = evaluation_dict(p) @@ -8791,14 +9052,14 @@ class CyclicPermutations(Permutations_mset): EXAMPLES:: - sage: CyclicPermutations(range(4)).list() # optional - sage.combinat + sage: CyclicPermutations(range(4)).list() # needs sage.combinat [[0, 1, 2, 3], [0, 1, 3, 2], [0, 2, 1, 3], [0, 2, 3, 1], [0, 3, 1, 2], [0, 3, 2, 1]] - sage: CyclicPermutations([1,1,1]).list() # optional - sage.combinat + sage: CyclicPermutations([1,1,1]).list() # needs sage.combinat [[1, 1, 1]] """ @staticmethod @@ -8833,16 +9094,16 @@ def __iter__(self, distinct=False): """ EXAMPLES:: - sage: CyclicPermutations(range(4)).list() # indirect doctest # optional - sage.combinat + sage: CyclicPermutations(range(4)).list() # indirect doctest # needs sage.combinat [[0, 1, 2, 3], [0, 1, 3, 2], [0, 2, 1, 3], [0, 2, 3, 1], [0, 3, 1, 2], [0, 3, 2, 1]] - sage: CyclicPermutations([1,1,1]).list() # optional - sage.combinat + sage: CyclicPermutations([1,1,1]).list() # needs sage.combinat [[1, 1, 1]] - sage: CyclicPermutations([1,1,1]).list(distinct=True) # optional - sage.combinat + sage: CyclicPermutations([1,1,1]).list(distinct=True) # needs sage.combinat [[1, 1, 1], [1, 1, 1]] """ if distinct: @@ -8863,7 +9124,7 @@ def list(self, distinct=False): """ EXAMPLES:: - sage: CyclicPermutations(range(4)).list() # optional - sage.combinat + sage: CyclicPermutations(range(4)).list() # needs sage.combinat [[0, 1, 2, 3], [0, 1, 3, 2], [0, 2, 1, 3], @@ -8884,7 +9145,7 @@ class CyclicPermutationsOfPartition(Permutations): EXAMPLES:: - sage: CyclicPermutationsOfPartition([[1,2,3,4],[5,6,7]]).list() # optional - sage.combinat + sage: CyclicPermutationsOfPartition([[1,2,3,4],[5,6,7]]).list() # needs sage.combinat [[[1, 2, 3, 4], [5, 6, 7]], [[1, 2, 4, 3], [5, 6, 7]], [[1, 3, 2, 4], [5, 6, 7]], @@ -8900,7 +9161,7 @@ class CyclicPermutationsOfPartition(Permutations): :: - sage: CyclicPermutationsOfPartition([[1,2,3,4],[4,4,4]]).list() # optional - sage.combinat + sage: CyclicPermutationsOfPartition([[1,2,3,4],[4,4,4]]).list() # needs sage.combinat [[[1, 2, 3, 4], [4, 4, 4]], [[1, 2, 4, 3], [4, 4, 4]], [[1, 3, 2, 4], [4, 4, 4]], @@ -8910,12 +9171,12 @@ class CyclicPermutationsOfPartition(Permutations): :: - sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list() # optional - sage.combinat + sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list() # needs sage.combinat [[[1, 2, 3], [4, 4, 4]], [[1, 3, 2], [4, 4, 4]]] :: - sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list(distinct=True) # optional - sage.combinat + sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list(distinct=True) # needs sage.combinat [[[1, 2, 3], [4, 4, 4]], [[1, 3, 2], [4, 4, 4]], [[1, 2, 3], [4, 4, 4]], @@ -8943,7 +9204,7 @@ def __init__(self, partition): sage: CP = CyclicPermutationsOfPartition([[1,2,3,4],[5,6,7]]) sage: CP Cyclic permutations of partition [[1, 2, 3, 4], [5, 6, 7]] - sage: TestSuite(CP).run() # optional - sage.combinat + sage: TestSuite(CP).run() # needs sage.combinat """ self.partition = partition Permutations.__init__(self, category=FiniteEnumeratedSets()) @@ -8960,8 +9221,8 @@ def check(self): EXAMPLES:: sage: CP = CyclicPermutationsOfPartition([[1,2,3,4],[5,6,7]]) - sage: elt = CP[0] # optional - sage.combinat - sage: elt.check() # optional - sage.combinat + sage: elt = CP[0] # needs sage.combinat + sage: elt.check() # needs sage.combinat """ if [sorted(_) for _ in self] != [sorted(_) for _ in self.parent().partition]: raise ValueError("Invalid cyclic permutation of the partition" % self.parent().partition) @@ -8984,7 +9245,7 @@ def __iter__(self, distinct=False): EXAMPLES:: - sage: CyclicPermutationsOfPartition([[1,2,3,4], # indirect doctest # optional - sage.combinat + sage: CyclicPermutationsOfPartition([[1,2,3,4], # indirect doctest # needs sage.combinat ....: [5,6,7]]).list() [[[1, 2, 3, 4], [5, 6, 7]], [[1, 2, 4, 3], [5, 6, 7]], @@ -9001,7 +9262,7 @@ def __iter__(self, distinct=False): :: - sage: CyclicPermutationsOfPartition([[1,2,3,4],[4,4,4]]).list() # optional - sage.combinat + sage: CyclicPermutationsOfPartition([[1,2,3,4],[4,4,4]]).list() # needs sage.combinat [[[1, 2, 3, 4], [4, 4, 4]], [[1, 2, 4, 3], [4, 4, 4]], [[1, 3, 2, 4], [4, 4, 4]], @@ -9011,12 +9272,12 @@ def __iter__(self, distinct=False): :: - sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list() # optional - sage.combinat + sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list() # needs sage.combinat [[[1, 2, 3], [4, 4, 4]], [[1, 3, 2], [4, 4, 4]]] :: - sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list(distinct=True) # optional - sage.combinat + sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list(distinct=True) # needs sage.combinat [[[1, 2, 3], [4, 4, 4]], [[1, 3, 2], [4, 4, 4]], [[1, 2, 3], [4, 4, 4]], @@ -9036,9 +9297,9 @@ def list(self, distinct=False): """ EXAMPLES:: - sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list() # optional - sage.combinat + sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list() # needs sage.combinat [[[1, 2, 3], [4, 4, 4]], [[1, 3, 2], [4, 4, 4]]] - sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list(distinct=True) # optional - sage.combinat + sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list(distinct=True) # needs sage.combinat [[[1, 2, 3], [4, 4, 4]], [[1, 3, 2], [4, 4, 4]], [[1, 2, 3], [4, 4, 4]], @@ -9074,7 +9335,7 @@ def __init__(self, a): TESTS:: sage: P = Permutations(avoiding=[[2,1,3],[1,2,3]]) - sage: TestSuite(P).run(max_runs=25) # optional - sage.combinat + sage: TestSuite(P).run(max_runs=25) # needs sage.combinat """ Permutations.__init__(self, category=InfiniteEnumeratedSets()) self._a = a @@ -9104,13 +9365,13 @@ def __contains__(self, x): """ TESTS:: - sage: [1,3,2] in Permutations(avoiding=[1,3,2]) # optional - sage.combinat + sage: [1,3,2] in Permutations(avoiding=[1,3,2]) # needs sage.combinat False - sage: [1,3,2] in Permutations(avoiding=[[1,3,2]]) # optional - sage.combinat + sage: [1,3,2] in Permutations(avoiding=[[1,3,2]]) # needs sage.combinat False - sage: [2,1,3] in Permutations(avoiding=[[1,3,2],[1,2,3]]) # optional - sage.combinat + sage: [2,1,3] in Permutations(avoiding=[[1,3,2],[1,2,3]]) # needs sage.combinat True - sage: [2,1,3] in Permutations(avoiding=[]) # optional - sage.combinat + sage: [2,1,3] in Permutations(avoiding=[]) True """ if not super().__contains__(x): @@ -9125,7 +9386,7 @@ def __iter__(self): TESTS:: sage: it = iter(Permutations(avoiding=[[2,1,3],[1,2,3]])) - sage: [next(it) for i in range(10)] # optional - sage.combinat + sage: [next(it) for i in range(10)] # needs sage.combinat [[], [1], [1, 2], @@ -9170,7 +9431,7 @@ def __init__(self, n, a): EXAMPLES:: sage: P = Permutations(3, avoiding=[[2,1,3],[1,2,3]]) - sage: TestSuite(P).run() # optional - sage.combinat + sage: TestSuite(P).run() # needs sage.combinat sage: type(P) """ @@ -9211,13 +9472,13 @@ def __contains__(self, x): """ TESTS:: - sage: [1,3,2] in Permutations(3, avoiding=[1,3,2]) # optional - sage.combinat + sage: [1,3,2] in Permutations(3, avoiding=[1,3,2]) # needs sage.combinat False - sage: [1,3,2] in Permutations(3, avoiding=[[1,3,2]]) # optional - sage.combinat + sage: [1,3,2] in Permutations(3, avoiding=[[1,3,2]]) # needs sage.combinat False - sage: [2,1,3] in Permutations(3, avoiding=[[1,3,2],[1,2,3]]) # optional - sage.combinat + sage: [2,1,3] in Permutations(3, avoiding=[[1,3,2],[1,2,3]]) # needs sage.combinat True - sage: [2,1,3] in Permutations(3, avoiding=[]) # optional - sage.combinat + sage: [2,1,3] in Permutations(3, avoiding=[]) True """ if not super().__contains__(x): @@ -9238,9 +9499,9 @@ def __iter__(self): """ EXAMPLES:: - sage: Permutations(3, avoiding=[[2, 1, 3],[1,2,3]]).list() # optional - sage.combinat + sage: Permutations(3, avoiding=[[2, 1, 3],[1,2,3]]).list() # needs sage.combinat [[1, 3, 2], [3, 1, 2], [2, 3, 1], [3, 2, 1]] - sage: Permutations(0, avoiding=[[2, 1, 3],[1,2,3]]).list() # optional - sage.combinat + sage: Permutations(0, avoiding=[[2, 1, 3],[1,2,3]]).list() [[]] """ if self.n > 0: @@ -9254,7 +9515,7 @@ def cardinality(self): EXAMPLES:: sage: P = Permutations(3, avoiding=[[2, 1, 3],[1,2,3]]) - sage: P.cardinality() # optional - sage.combinat + sage: P.cardinality() # needs sage.combinat 4 """ one = ZZ.one() @@ -9267,7 +9528,7 @@ def __init__(self, n): TESTS:: sage: P = Permutations(3, avoiding=[1, 2]) - sage: TestSuite(P).run() # optional - sage.combinat + sage: TestSuite(P).run() # needs sage.combinat """ super().__init__(n, (Permutations()([1, 2]),)) @@ -9275,7 +9536,7 @@ def __iter__(self): """ EXAMPLES:: - sage: Permutations(3, avoiding=[1,2]).list() # optional - sage.combinat + sage: Permutations(3, avoiding=[1,2]).list() [[3, 2, 1]] """ yield self.element_class(self, range(self.n, 0, -1), check=False) @@ -9287,7 +9548,7 @@ def cardinality(self): EXAMPLES:: sage: P = Permutations(3, avoiding=[1, 2]) - sage: P.cardinality() # optional - sage.combinat + sage: P.cardinality() 1 """ return ZZ.one() @@ -9299,7 +9560,7 @@ def __init__(self, n): TESTS:: sage: P = Permutations(3, avoiding=[2, 1]) - sage: TestSuite(P).run() # optional - sage.combinat + sage: TestSuite(P).run() # needs sage.combinat """ super().__init__(n, (Permutations()([2, 1]),)) @@ -9307,7 +9568,7 @@ def __iter__(self): """ EXAMPLES:: - sage: Permutations(3, avoiding=[2,1]).list() # optional - sage.combinat + sage: Permutations(3, avoiding=[2,1]).list() [[1, 2, 3]] """ yield self.element_class(self, range(1, self.n+1), check=False) @@ -9319,7 +9580,7 @@ def cardinality(self): EXAMPLES:: sage: P = Permutations(3, avoiding=[2, 1]) - sage: P.cardinality() # optional - sage.combinat + sage: P.cardinality() 1 """ return ZZ.one() @@ -9331,7 +9592,7 @@ def __init__(self, n): TESTS:: sage: P = Permutations(3, avoiding=[1, 3, 2]) - sage: TestSuite(P).run() # optional - sage.combinat + sage: TestSuite(P).run() # needs sage.combinat """ super().__init__(n, (Permutations()([1, 3, 2]),)) @@ -9341,7 +9602,7 @@ def cardinality(self): sage: Permutations(5, avoiding=[1, 3, 2]).cardinality() 42 - sage: len( Permutations(5, avoiding=[1, 3, 2]).list() ) # optional - sage.combinat + sage: len( Permutations(5, avoiding=[1, 3, 2]).list() ) 42 """ return catalan_number(self.n) @@ -9350,9 +9611,9 @@ def __iter__(self): """ EXAMPLES:: - sage: Permutations(3, avoiding=[1,3,2]).list() # indirect doctest # optional - sage.combinat + sage: Permutations(3, avoiding=[1,3,2]).list() # indirect doctest [[1, 2, 3], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] - sage: Permutations(4, avoiding=[1,3,2]).list() # optional - sage.combinat + sage: Permutations(4, avoiding=[1,3,2]).list() [[4, 1, 2, 3], [4, 2, 1, 3], [4, 2, 3, 1], @@ -9408,7 +9669,7 @@ def __init__(self, n): TESTS:: sage: P = Permutations(3, avoiding=[2, 1, 3]) - sage: TestSuite(P).run() # optional - sage.combinat + sage: TestSuite(P).run() # needs sage.combinat """ super().__init__(n, (Permutations()([1, 2, 3]),)) @@ -9416,9 +9677,9 @@ def cardinality(self) -> Integer: """ EXAMPLES:: - sage: Permutations(5, avoiding=[1, 2, 3]).cardinality() # optional - sage.combinat + sage: Permutations(5, avoiding=[1, 2, 3]).cardinality() 42 - sage: len( Permutations(5, avoiding=[1, 2, 3]).list() ) # optional - sage.combinat + sage: len( Permutations(5, avoiding=[1, 2, 3]).list() ) 42 """ return catalan_number(self.n) @@ -9427,11 +9688,11 @@ def __iter__(self): """ EXAMPLES:: - sage: Permutations(3, avoiding=[1, 2, 3]).list() # indirect doctest # optional - sage.combinat + sage: Permutations(3, avoiding=[1, 2, 3]).list() # indirect doctest [[1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] - sage: Permutations(2, avoiding=[1, 2, 3]).list() # optional - sage.combinat + sage: Permutations(2, avoiding=[1, 2, 3]).list() [[1, 2], [2, 1]] - sage: Permutations(3, avoiding=[1, 2, 3]).list() # optional - sage.combinat + sage: Permutations(3, avoiding=[1, 2, 3]).list() [[1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] """ if self.n == 0: @@ -9480,7 +9741,7 @@ def __init__(self, n): TESTS:: sage: P = Permutations(3, avoiding=[3, 2, 1]) - sage: TestSuite(P).run() # optional - sage.combinat + sage: TestSuite(P).run() # needs sage.combinat """ super().__init__(n, (Permutations()([3, 2, 1]),)) @@ -9488,9 +9749,9 @@ def cardinality(self): """ EXAMPLES:: - sage: Permutations(5, avoiding=[3, 2, 1]).cardinality() # optional - sage.combinat + sage: Permutations(5, avoiding=[3, 2, 1]).cardinality() 42 - sage: len( Permutations(5, avoiding=[3, 2, 1]).list() ) # optional - sage.combinat + sage: len( Permutations(5, avoiding=[3, 2, 1]).list() ) 42 """ return catalan_number(self.n) @@ -9499,7 +9760,7 @@ def __iter__(self): """ EXAMPLES:: - sage: Permutations(3, avoiding=[3, 2, 1]).list() # indirect doctest # optional - sage.combinat + sage: Permutations(3, avoiding=[3, 2, 1]).list() # indirect doctest [[2, 3, 1], [3, 1, 2], [1, 3, 2], [2, 1, 3], [1, 2, 3]] """ for p in StandardPermutations_avoiding_123(self.n): @@ -9512,7 +9773,7 @@ def __init__(self, n): TESTS:: sage: P = Permutations(3, avoiding=[2, 3, 1]) - sage: TestSuite(P).run() # optional - sage.combinat + sage: TestSuite(P).run() # needs sage.combinat """ super().__init__(n, (Permutations()([2, 3, 1]),)) @@ -9520,9 +9781,9 @@ def cardinality(self): """ EXAMPLES:: - sage: Permutations(5, avoiding=[2, 3, 1]).cardinality() # optional - sage.combinat + sage: Permutations(5, avoiding=[2, 3, 1]).cardinality() 42 - sage: len( Permutations(5, avoiding=[2, 3, 1]).list() ) # optional - sage.combinat + sage: len( Permutations(5, avoiding=[2, 3, 1]).list() ) 42 """ return catalan_number(self.n) @@ -9531,7 +9792,7 @@ def __iter__(self): """ EXAMPLES:: - sage: Permutations(3, avoiding=[2, 3, 1]).list() # optional - sage.combinat + sage: Permutations(3, avoiding=[2, 3, 1]).list() [[3, 2, 1], [3, 1, 2], [1, 3, 2], [2, 1, 3], [1, 2, 3]] """ for p in StandardPermutations_avoiding_132(self.n): @@ -9544,7 +9805,7 @@ def __init__(self, n): TESTS:: sage: P = Permutations(3, avoiding=[3, 1, 2]) - sage: TestSuite(P).run() # optional - sage.combinat + sage: TestSuite(P).run() # needs sage.combinat """ super().__init__(n, (Permutations()([3, 1, 2]),)) @@ -9554,7 +9815,7 @@ def cardinality(self): sage: Permutations(5, avoiding=[3, 1, 2]).cardinality() 42 - sage: len( Permutations(5, avoiding=[3, 1, 2]).list() ) # optional - sage.combinat + sage: len( Permutations(5, avoiding=[3, 1, 2]).list() ) 42 """ return catalan_number(self.n) @@ -9563,7 +9824,7 @@ def __iter__(self): """ EXAMPLES:: - sage: Permutations(3, avoiding=[3, 1, 2]).list() # optional - sage.combinat + sage: Permutations(3, avoiding=[3, 1, 2]).list() [[3, 2, 1], [2, 3, 1], [2, 1, 3], [1, 3, 2], [1, 2, 3]] """ for p in StandardPermutations_avoiding_132(self.n): @@ -9576,7 +9837,7 @@ def __init__(self, n): TESTS:: sage: P = Permutations(3, avoiding=[2, 1, 3]) - sage: TestSuite(P).run() # optional - sage.combinat + sage: TestSuite(P).run() # needs sage.combinat """ super().__init__(n, (Permutations()([2, 1, 3]),)) @@ -9586,7 +9847,7 @@ def cardinality(self): sage: Permutations(5, avoiding=[2, 1, 3]).cardinality() 42 - sage: len( Permutations(5, avoiding=[2, 1, 3]).list() ) # optional - sage.combinat + sage: len( Permutations(5, avoiding=[2, 1, 3]).list() ) 42 """ return catalan_number(self.n) @@ -9595,7 +9856,7 @@ def __iter__(self): """ EXAMPLES:: - sage: Permutations(3, avoiding=[2, 1, 3]).list() # optional - sage.combinat + sage: Permutations(3, avoiding=[2, 1, 3]).list() [[1, 2, 3], [1, 3, 2], [3, 1, 2], [2, 3, 1], [3, 2, 1]] """ for p in StandardPermutations_avoiding_132(self.n): @@ -9624,7 +9885,7 @@ def _rec(self, obj, state): sage: from sage.combinat.permutation import PatternAvoider sage: P = Permutations(4) sage: p = PatternAvoider(P, [[1,2]]) - sage: list(p._rec([1], 2)) # optional - sage.combinat + sage: list(p._rec([1], 2)) # needs sage.combinat [([2, 1], 3, False)] """ i = state diff --git a/src/sage/combinat/plane_partition.py b/src/sage/combinat/plane_partition.py index d18177aac00..21b8bb84334 100644 --- a/src/sage/combinat/plane_partition.py +++ b/src/sage/combinat/plane_partition.py @@ -544,7 +544,7 @@ def _repr_svg_(self) -> str: EXAMPLES:: sage: PP = PlanePartition([[2, 1, 1], [1, 1]]) - sage: PP._repr_svg_() + sage: PP._repr_svg_() # needs sage.modules '' """ colors = ["snow", "tomato", "steelblue"] @@ -621,7 +621,7 @@ def _latex_(self, show_box=False, EXAMPLES:: sage: PP = PlanePartition([[1]]) - sage: latex(PP) + sage: latex(PP) # needs sage.graphs \begin{tikzpicture} \draw[fill=white,shift={(210:0)},shift={(-30:0)},shift={(90:1)}] (0,0)--(-30:1)--(0,-1)--(210:1)--(0,0); @@ -669,7 +669,7 @@ def plot(self, show_box=False, colors=None): EXAMPLES:: sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) - sage: PP.plot() # optional - sage.plot + sage: PP.plot() # needs sage.plot Graphics object consisting of 27 graphics primitives """ from sage.functions.trig import cos, sin @@ -766,7 +766,7 @@ def plot3d(self, colors=None): EXAMPLES:: sage: PP = PlanePartition([[4,3,3,1],[2,1,1],[1,1]]) - sage: PP.plot3d() # optional - sage.plot + sage: PP.plot3d() # needs sage.plot Graphics3d Object """ if colors is None: @@ -1101,9 +1101,10 @@ def to_order_ideal(self): EXAMPLES:: - sage: PlanePartition([[3,2,1],[2,2],[2]]).to_order_ideal() - [(0, 0, 0), (0, 0, 1), (0, 0, 2), (0, 1, 0), (0, 1, 1), (0, 2, 0), (1, 0, 0), (1, 0, 1), (1, 1, 0), (1, 1, 1), (2, 0, 0), (2, 0, 1)] - sage: PlanePartition([[2,1],[1],[1]]).to_order_ideal() + sage: PlanePartition([[3,2,1],[2,2],[2]]).to_order_ideal() # needs sage.graphs sage.modules + [(0, 0, 0), (0, 0, 1), (0, 0, 2), (0, 1, 0), (0, 1, 1), (0, 2, 0), + (1, 0, 0), (1, 0, 1), (1, 1, 0), (1, 1, 1), (2, 0, 0), (2, 0, 1)] + sage: PlanePartition([[2,1],[1],[1]]).to_order_ideal() # needs sage.graphs sage.modules [(0, 0, 0), (0, 0, 1), (0, 1, 0), (1, 0, 0), (2, 0, 0)] """ from sage.combinat.posets.poset_examples import posets @@ -1160,6 +1161,8 @@ def cyclically_rotate(self, preserve_parent=False) -> PP: Plane partition [[3, 1, 1, 1], [1]] sage: PP == PP.cyclically_rotate().cyclically_rotate().cyclically_rotate() True + + sage: # needs sage.graphs sage.modules sage: PP = PlanePartitions([4,3,2]).random_element() sage: PP.cyclically_rotate().parent() Plane partitions inside a 2 x 4 x 3 box @@ -1400,7 +1403,7 @@ def __init__(self, box_size=None, symmetry=None, category=None): TESTS:: sage: PP = PlanePartitions(box_size=[2,2,1]) - sage: TestSuite(PP).run() + sage: TestSuite(PP).run() # needs sage.modules """ if box_size is not None and len(box_size) != 3: raise ValueError("invalid box size") @@ -1545,7 +1548,7 @@ def __init__(self, box_size): EXAMPLES:: sage: PP = PlanePartitions([4,3,2]) - sage: TestSuite(PP).run() # long time + sage: TestSuite(PP).run() # long time, needs sage.modules """ super().__init__(box_size, category=FiniteEnumeratedSets()) @@ -1585,7 +1588,7 @@ def to_poset(self): EXAMPLES:: - sage: PlanePartitions([2,2,2]).to_poset() + sage: PlanePartitions([2,2,2]).to_poset() # needs sage.graphs sage.modules Finite lattice containing 8 elements """ a = self._box[0] @@ -1601,8 +1604,9 @@ def from_order_ideal(self, I) -> PP: EXAMPLES:: - sage: I = [(1, 0, 0), (1, 0, 1), (1, 1, 0), (0, 1, 0), (0, 0, 0), (0, 0, 1), (0, 1, 1)] - sage: PlanePartitions([2,2,2]).from_order_ideal(I) + sage: I = [(1, 0, 0), (1, 0, 1), (1, 1, 0), (0, 1, 0), + ....: (0, 0, 0), (0, 0, 1), (0, 1, 1)] + sage: PlanePartitions([2,2,2]).from_order_ideal(I) # needs sage.graphs sage.modules Plane partition [[2, 2], [2, 1]] """ return self.from_antichain(self.to_poset().order_ideal_generators(I)) @@ -1654,7 +1658,7 @@ def __iter__(self) -> Iterator: EXAMPLES:: - sage: list(PlanePartitions([1,2,1])) + sage: list(PlanePartitions([1,2,1])) # needs sage.modules [Plane partition [], Plane partition [[1]], Plane partition [[1, 1]]] TESTS:: @@ -1721,7 +1725,7 @@ def random_element(self) -> PP: EXAMPLES:: sage: P = PlanePartitions([4,3,5]) - sage: P.random_element() # random + sage: P.random_element() # random # needs sage.graphs sage.modules Plane partition [[4, 3, 3], [4], [2]] """ Z = self.from_order_ideal(self.to_poset().random_order_ideal()) @@ -1871,7 +1875,7 @@ def __init__(self, box_size): TESTS:: sage: PP = PlanePartitions([3,3,2], symmetry='SPP') - sage: TestSuite(PP).run() + sage: TestSuite(PP).run() # needs sage.graphs sage.modules sage: PlanePartitions([4,3,2], symmetry='SPP') Traceback (most recent call last): ... @@ -1916,9 +1920,9 @@ def to_poset(self): EXAMPLES:: sage: PP = PlanePartitions([3,3,2], symmetry='SPP') - sage: PP.to_poset() + sage: PP.to_poset() # needs sage.graphs Finite poset containing 12 elements - sage: PP.to_poset().order_ideals_lattice().cardinality() == PP.cardinality() + sage: PP.to_poset().order_ideals_lattice().cardinality() == PP.cardinality() # needs sage.graphs sage.modules sage.rings.finite_rings True """ a = self._box[0] @@ -1941,7 +1945,7 @@ def from_order_ideal(self, I) -> PP: sage: PP = PlanePartitions([3,3,2], symmetry='SPP') sage: I = [(0, 0, 0), (1, 0, 0), (1, 1, 0), (2, 0, 0)] - sage: PP.from_order_ideal(I) + sage: PP.from_order_ideal(I) # needs sage.graphs Plane partition [[1, 1, 1], [1, 1], [1]] """ return self.from_antichain(self.to_poset().order_ideal_generators(I)) @@ -1993,7 +1997,7 @@ def __iter__(self) -> Iterator: EXAMPLES:: - sage: list(PlanePartitions([2,2,1], symmetry='SPP')) + sage: list(PlanePartitions([2,2,1], symmetry='SPP')) # needs sage.graphs sage.modules sage.rings.finite_rings [Plane partition [], Plane partition [[1, 1], [1, 1]], Plane partition [[1, 1], [1]], @@ -2053,7 +2057,7 @@ def random_element(self) -> PP: EXAMPLES:: sage: PP = PlanePartitions([3,3,2], symmetry='SPP') - sage: PP.random_element() # random + sage: PP.random_element() # random # needs sage.graphs Plane partition [[2, 2, 2], [2, 2], [2]] """ Z = self.from_order_ideal(self.to_poset().random_order_ideal()) @@ -2074,7 +2078,7 @@ def __init__(self, box_size): TESTS:: sage: PP = PlanePartitions([3,3,3], symmetry='CSPP') - sage: TestSuite(PP).run() + sage: TestSuite(PP).run() # needs sage.graphs sage.modules sage.rings.finite_rings sage: PlanePartitions([4,3,2], symmetry='CSPP') Traceback (most recent call last): ... @@ -2119,9 +2123,9 @@ def to_poset(self): EXAMPLES:: sage: PP = PlanePartitions([3,3,3], symmetry='CSPP') - sage: PP.to_poset() + sage: PP.to_poset() # needs sage.graphs Finite poset containing 11 elements - sage: PP.to_poset().order_ideals_lattice().cardinality() == PP.cardinality() + sage: PP.to_poset().order_ideals_lattice().cardinality() == PP.cardinality() # needs sage.graphs True """ a = self._box[0] @@ -2193,7 +2197,7 @@ def from_order_ideal(self, I) -> PP: sage: PP = PlanePartitions([3,3,3], symmetry='CSPP') sage: I = [(0, 0, 0), (0, 0, 1), (0, 0, 2), (0, 1, 1), (0, 1, 2), ....: (1, 0, 2), (0, 2, 2), (1, 1, 1), (1, 1, 2), (1, 2, 2)] - sage: PP.from_order_ideal(I) + sage: PP.from_order_ideal(I) # needs sage.graphs Plane partition [[3, 3, 3], [3, 3, 3], [3, 3, 2]] """ return self.from_antichain(self.to_poset().order_ideal_generators(I)) @@ -2212,7 +2216,7 @@ def random_element(self) -> PP: EXAMPLES:: sage: PP = PlanePartitions([3,3,3], symmetry='CSPP') - sage: PP.random_element() # random + sage: PP.random_element() # random # needs sage.graphs Plane partition [[3, 2, 2], [3, 1], [1, 1]] """ Z = self.from_order_ideal(self.to_poset().random_order_ideal()) @@ -2224,7 +2228,7 @@ def __iter__(self) -> Iterator: EXAMPLES:: - sage: list(PlanePartitions([2,2,2], symmetry='CSPP')) + sage: list(PlanePartitions([2,2,2], symmetry='CSPP')) # needs sage.graphs sage.modules [Plane partition [], Plane partition [[2, 2], [2, 2]], Plane partition [[2, 2], [2, 1]], @@ -2281,7 +2285,7 @@ def __init__(self, box_size): TESTS:: sage: PP = PlanePartitions([3,3,3], symmetry='TSPP') - sage: TestSuite(PP).run() + sage: TestSuite(PP).run() # needs sage.graphs sage.modules sage: PlanePartitions([4,3,2], symmetry='TSPP') Traceback (most recent call last): ... @@ -2325,9 +2329,10 @@ def to_poset(self): EXAMPLES:: sage: PP = PlanePartitions([3,3,3], symmetry='TSPP') - sage: PP.to_poset() + sage: PP.to_poset() # needs sage.graphs Finite poset containing 10 elements - sage: PP.to_poset().order_ideals_lattice().cardinality() == PP.cardinality() + sage: (PP.to_poset().order_ideals_lattice().cardinality() # needs sage.graphs sage.modules sage.rings.finite_rings + ....: == PP.cardinality()) True """ a = self._box[0] @@ -2396,7 +2401,7 @@ def from_order_ideal(self, I) -> PP: sage: PP = PlanePartitions([3,3,3], symmetry='TSPP') sage: I = [(0, 0, 0), (0, 0, 1), (0, 0, 2), (0, 1, 1)] - sage: PP.from_order_ideal(I) + sage: PP.from_order_ideal(I) # needs sage.graphs Plane partition [[3, 2, 1], [2, 1], [1]] """ return self.from_antichain(self.to_poset().order_ideal_generators(I)) @@ -2407,7 +2412,7 @@ def __iter__(self) -> Iterator: EXAMPLES:: - sage: list(PlanePartitions([2,2,2], symmetry='TSPP')) + sage: list(PlanePartitions([2,2,2], symmetry='TSPP')) # needs sage.graphs sage.modules [Plane partition [], Plane partition [[2, 2], [2, 2]], Plane partition [[2, 2], [2, 1]], @@ -2739,7 +2744,7 @@ def __init__(self, box_size): TESTS:: sage: PP = PlanePartitions([3,3,2], symmetry='TCPP') - sage: TestSuite(PP).run() + sage: TestSuite(PP).run() # needs sage.graphs sage.modules sage: PlanePartitions([3,3,3], symmetry='TCPP') Traceback (most recent call last): @@ -2773,7 +2778,7 @@ def __iter__(self) -> Iterator: EXAMPLES:: - sage: list(PlanePartitions([3,3,2], symmetry='TCPP')) + sage: list(PlanePartitions([3,3,2], symmetry='TCPP')) # needs sage.modules [Plane partition [[2, 2, 1], [2, 1], [1]], Plane partition [[2, 1, 1], [2, 1, 1], [1]], Plane partition [[2, 2, 1], [1, 1], [1, 1]], @@ -2825,10 +2830,10 @@ def __init__(self, box_size): TESTS:: sage: PP = PlanePartitions([2, 2, 4], symmetry='SSCPP') - sage: TestSuite(PP).run() + sage: TestSuite(PP).run() # needs sage.modules sage: PP = PlanePartitions([4, 4, 2], symmetry='SSCPP') - sage: TestSuite(PP).run() + sage: TestSuite(PP).run() # long time # needs sage.modules sage: PlanePartitions([4, 2, 2], symmetry='SSCPP') Traceback (most recent call last): @@ -2862,7 +2867,7 @@ def __iter__(self) -> Iterator: EXAMPLES:: - sage: list(PlanePartitions([4,4,2], symmetry='SSCPP')) + sage: list(PlanePartitions([4,4,2], symmetry='SSCPP')) # needs sage.modules [Plane partition [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]], Plane partition [[2, 2, 2, 1], [2, 1, 1], [2, 1, 1], [1]], Plane partition [[2, 2, 1, 1], [2, 2, 1, 1], [1, 1], [1, 1]], @@ -2934,7 +2939,7 @@ def __init__(self, box_size): TESTS:: sage: PP = PlanePartitions([2,2,2], symmetry='CSTCPP') - sage: TestSuite(PP).run() + sage: TestSuite(PP).run() # needs sage.modules sage: PlanePartitions([4,3,2], symmetry='CSTCPP') Traceback (most recent call last): @@ -2968,7 +2973,7 @@ def __iter__(self) -> Iterator: EXAMPLES:: - sage: list(PlanePartitions([2,2,2], symmetry='CSTCPP')) + sage: list(PlanePartitions([2,2,2], symmetry='CSTCPP')) # needs sage.modules [Plane partition [[2, 1], [1]]] TESTS:: @@ -3020,7 +3025,7 @@ def __init__(self, box_size): TESTS:: sage: PP = PlanePartitions([2,2,2], symmetry='CSSCPP') - sage: TestSuite(PP).run() + sage: TestSuite(PP).run() # needs sage.modules sage: PlanePartitions([4,3,2], symmetry='CSSCPP') Traceback (most recent call last): ... @@ -3052,7 +3057,7 @@ def __iter__(self) -> Iterator: EXAMPLES:: - sage: list(PlanePartitions([2,2,2], symmetry='CSSCPP')) + sage: list(PlanePartitions([2,2,2], symmetry='CSSCPP')) # needs sage.modules [Plane partition [[2, 1], [1]]] """ # any CSSCPP is a SCPP and an CSPP, there are much fewer CSPP @@ -3095,7 +3100,7 @@ def __init__(self, box_size): TESTS:: sage: PP = PlanePartitions([4,4,4], symmetry='TSSCPP') - sage: TestSuite(PP).run() + sage: TestSuite(PP).run() # needs sage.modules sage: PlanePartitions([4,3,2], symmetry='TSSCPP') Traceback (most recent call last): ... @@ -3129,9 +3134,9 @@ def to_poset(self): EXAMPLES:: sage: PP = PlanePartitions([6,6,6], symmetry='TSSCPP') - sage: PP.to_poset() + sage: PP.to_poset() # needs sage.graphs sage.modules Finite poset containing 4 elements - sage: PP.to_poset().order_ideals_lattice().cardinality() == PP.cardinality() + sage: PP.to_poset().order_ideals_lattice().cardinality() == PP.cardinality() # needs sage.graphs sage.modules True """ from sage.combinat.posets.posets import Poset @@ -3250,10 +3255,11 @@ def from_order_ideal(self, I) -> PP: EXAMPLES:: - sage: PP = PlanePartitions([6,6,6], symmetry='TSSCPP') + sage: PP = PlanePartitions([6,6,6], symmetry='TSSCPP') # needs sage.graphs sage: I = [(0, 0, 0), (0, 1, 0), (1, 1, 0)] - sage: PP.from_order_ideal(I) - Plane partition [[6, 6, 6, 5, 5, 3], [6, 5, 5, 3, 3, 1], [6, 5, 5, 3, 3, 1], [5, 3, 3, 1, 1], [5, 3, 3, 1, 1], [3, 1, 1]] + sage: PP.from_order_ideal(I) # needs sage.graphs + Plane partition [[6, 6, 6, 5, 5, 3], [6, 5, 5, 3, 3, 1], [6, 5, 5, 3, 3, 1], + [5, 3, 3, 1, 1], [5, 3, 3, 1, 1], [3, 1, 1]] """ return self.from_antichain(self.to_poset().order_ideal_generators(I)) @@ -3263,7 +3269,7 @@ def __iter__(self) -> Iterator: EXAMPLES:: - sage: list(PlanePartitions([4,4,4], symmetry='TSSCPP')) + sage: list(PlanePartitions([4,4,4], symmetry='TSSCPP')) # needs sage.graphs sage.modules [Plane partition [[4, 4, 2, 2], [4, 4, 2, 2], [2, 2], [2, 2]], Plane partition [[4, 4, 3, 2], [4, 3, 2, 1], [3, 2, 1], [2, 1]]] diff --git a/src/sage/combinat/q_analogues.py b/src/sage/combinat/q_analogues.py index ec4fb594470..358b60ff322 100644 --- a/src/sage/combinat/q_analogues.py +++ b/src/sage/combinat/q_analogues.py @@ -247,18 +247,18 @@ def q_binomial(n, k, q=None, algorithm='auto'): This also works for variables in the symbolic ring:: - sage: z = var('z') # optional - sage.symbolic - sage: factor(q_binomial(4, 2, z)) # optional - sage.symbolic + sage: z = var('z') # needs sage.symbolic + sage: factor(q_binomial(4, 2, z)) # needs sage.symbolic (z^2 + z + 1)*(z^2 + 1) This also works for complex roots of unity:: - sage: q_binomial(10, 4, QQbar(I)) # optional - sage.rings.number_field + sage: q_binomial(10, 4, QQbar(I)) # needs sage.rings.number_field 2 Note that the symbolic computation works (see :trac:`14982`):: - sage: q_binomial(10, 4, I) # optional - sage.rings.number_field + sage: q_binomial(10, 4, I) # needs sage.rings.number_field 2 Check that the algorithm does not matter:: @@ -589,7 +589,7 @@ def q_pochhammer(n, a, q=None): 1 sage: q_pochhammer(0, 1) 1 - sage: q_pochhammer(0, var('a')) # optional - sage.symbolic + sage: q_pochhammer(0, var('a')) # needs sage.symbolic 1 We check that :trac:`25715` is fixed:: @@ -648,7 +648,7 @@ def q_jordan(t, q=None): [615195, 40635, 5643, 2331, 1491, 515, 147, 87, 47, 11, 1] sage: q_jordan([3,2,1]) 16*q^4 + 24*q^3 + 14*q^2 + 5*q + 1 - sage: q_jordan([2,1], x) # optional - sage.symbolic + sage: q_jordan([2,1], x) # needs sage.symbolic 2*x + 1 If the partition is trivial (i.e. has only one part), we get @@ -876,13 +876,13 @@ def q_stirling_number1(n, k, q=None): sage: q_stirling_number1(4,2) q^3 + 3*q^2 + 4*q + 3 - sage: all(stirling_number1(6,k) == q_stirling_number1(6,k)(1) + sage: all(stirling_number1(6,k) == q_stirling_number1(6,k)(1) # needs sage.libs.gap ....: for k in range(1,6)) True sage: x = polygen(QQ['q'],'x') sage: S = sum(q_stirling_number1(5,k)*x**k for k in range(1, 6)) - sage: factor(S) + sage: factor(S) # needs sage.libs.singular x * (x + 1) * (x + q + 1) * (x + q^2 + q + 1) * (x + q^3 + q^2 + q + 1) TESTS:: diff --git a/src/sage/combinat/q_bernoulli.pyx b/src/sage/combinat/q_bernoulli.pyx index 6f899a4cf1e..271a04487fb 100644 --- a/src/sage/combinat/q_bernoulli.pyx +++ b/src/sage/combinat/q_bernoulli.pyx @@ -36,7 +36,7 @@ def q_bernoulli(m, p=None): -1/(q + 1) sage: q_bernoulli(2) q/(q^3 + 2*q^2 + 2*q + 1) - sage: all(q_bernoulli(i)(q=1) == bernoulli(i) for i in range(12)) + sage: all(q_bernoulli(i)(q=1) == bernoulli(i) for i in range(12)) # needs sage.libs.flint True One can evaluate the rational function by giving a second argument:: @@ -101,7 +101,8 @@ def q_bernoulli_polynomial(m): sage: q_bernoulli_polynomial(1) (2/(q + 1))*x - 1/(q + 1) sage: x = q_bernoulli_polynomial(1).parent().gen() - sage: all(q_bernoulli_polynomial(i)(q=1)==bernoulli_polynomial(x,i) for i in range(12)) + sage: all(q_bernoulli_polynomial(i)(q=1) == bernoulli_polynomial(x,i) # needs sage.libs.flint + ....: for i in range(12)) True sage: all(q_bernoulli_polynomial(i)(x=0)==q_bernoulli(i) for i in range(12)) True diff --git a/src/sage/combinat/quickref.py b/src/sage/combinat/quickref.py index 351563cec6c..ee7d9ca8ec1 100644 --- a/src/sage/combinat/quickref.py +++ b/src/sage/combinat/quickref.py @@ -3,9 +3,10 @@ Integer Sequences:: - sage: s = oeis([1,3,19,211]); s # optional - internet - 0: A000275: Coefficients of a Bessel function (reciprocal of J_0(z)); also pairs of permutations with rise/rise forbidden. - sage: s[0].programs() # optional - internet + sage: s = oeis([1,3,19,211]); s # optional - internet + 0: A000275: Coefficients of a Bessel function (reciprocal of J_0(z)); + also pairs of permutations with rise/rise forbidden. + sage: s[0].programs() # optional - internet [('maple', ...), ('mathematica', ...), ('pari', @@ -13,14 +14,14 @@ Combinatorial objects:: - sage: S = Subsets([1,2,3,4]); S.list(); S. # not tested - sage: P = Partitions(10000); P.cardinality() + sage: S = Subsets([1,2,3,4]); S.list(); S. # not tested + sage: P = Partitions(10000); P.cardinality() # needs sage.libs.flint 3616...315650422081868605887952568754066420592310556052906916435144 - sage: Combinations([1,3,7]).random_element() # random - sage: Compositions(5, max_part = 3).unrank(3) + sage: Combinations([1,3,7]).random_element() # random + sage: Compositions(5, max_part=3).unrank(3) [2, 2, 1] - sage: DyckWord([1,0,1,0,1,1,0,0]).to_binary_tree() + sage: DyckWord([1,0,1,0,1,1,0,0]).to_binary_tree() # needs sage.graphs [., [., [[., .], .]]] sage: Permutation([3,1,4,2]).robinson_schensted() [[[1, 2], [3, 4]], [[1, 3], [2, 4]]] @@ -30,7 +31,9 @@ Constructions and Species:: sage: for (p, s) in cartesian_product([P,S]): print((p, s)) # not tested - sage: DisjointUnionEnumeratedSets(Family(lambda n: IntegerVectors(n, 3), NonNegativeIntegers)) # not tested + sage: def IV_3(n): + ....: return IntegerVectors(n, 3) + sage: DisjointUnionEnumeratedSets(Family(IV_3, NonNegativeIntegers)) # not tested Words:: @@ -44,35 +47,35 @@ Polytopes:: - sage: points = random_matrix(ZZ, 6, 3, x=7).rows() - sage: L = LatticePolytope(points) - sage: L.npoints(); L.plot3d() # random # optional - sage.plot + sage: points = random_matrix(ZZ, 6, 3, x=7).rows() # needs sage.modules + sage: L = LatticePolytope(points) # needs sage.geometry.polyhedron sage.modules + sage: L.npoints(); L.plot3d() # random # needs sage.geometry.polyhedron sage.modules sage.plot :ref:`Root systems, Coxeter and Weyl groups `:: - sage: WeylGroup(["B",3]).bruhat_poset() + sage: WeylGroup(["B",3]).bruhat_poset() # needs sage.graphs sage.modules Finite poset containing 48 elements - sage: RootSystem(["A",2,1]).weight_lattice().plot() # not tested + sage: RootSystem(["A",2,1]).weight_lattice().plot() # not tested # needs sage.graphs sage.modules sage.plot :ref:`Crystals `:: - sage: CrystalOfTableaux(["A",3], shape = [3,2]).some_flashy_feature() # not tested + sage: CrystalOfTableaux(["A",3], shape=[3,2]).some_flashy_feature() # not tested :mod:`Symmetric functions and combinatorial Hopf algebras `:: - sage: Sym = SymmetricFunctions(QQ); Sym.inject_shorthands(verbose=False) - sage: m( ( h[2,1] * (1 + 3 * p[2,1]) ) + s[2](s[3]) ) + sage: Sym = SymmetricFunctions(QQ); Sym.inject_shorthands(verbose=False) # needs sage.sage.modules + sage: m( ( h[2,1] * (1 + 3 * p[2,1]) ) + s[2](s[3]) ) # needs sage.sage.modules 3*m[1, 1, 1] + ... + 10*m[5, 1] + 4*m[6] :ref:`Discrete groups, Permutation groups `:: - sage: S = SymmetricGroup(4) + sage: S = SymmetricGroup(4) # needs sage.groups sage: M = PolynomialRing(QQ, 'x0,x1,x2,x3') - sage: M.an_element() * S.an_element() + sage: M.an_element() * S.an_element() # needs sage.groups x0 Graph theory, posets, lattices (:ref:`sage.graphs`, :ref:`sage.combinat.posets.all`):: - sage: Poset({1: [2,3], 2: [4], 3: [4]}).linear_extensions().cardinality() + sage: Poset({1: [2,3], 2: [4], 3: [4]}).linear_extensions().cardinality() # needs sage.graphs sage.modules 2 """ diff --git a/src/sage/combinat/ranker.py b/src/sage/combinat/ranker.py index 68ae91baba3..c370800bf22 100644 --- a/src/sage/combinat/ranker.py +++ b/src/sage/combinat/ranker.py @@ -207,7 +207,7 @@ def unrank(L, i): Enumerated sets:: - sage: unrank(GF(7), 2) # optional - sage.rings.finite_rings + sage: unrank(GF(7), 2) 2 sage: unrank(IntegerModRing(29), 10) 10 diff --git a/src/sage/combinat/restricted_growth.py b/src/sage/combinat/restricted_growth.py index 98c1214b392..b638356e4db 100644 --- a/src/sage/combinat/restricted_growth.py +++ b/src/sage/combinat/restricted_growth.py @@ -33,7 +33,7 @@ def __init__(self, n): sage: R = RestrictedGrowthArrays(3) sage: R == loads(dumps(R)) True - sage: TestSuite(R).run(skip=['_test_an_element', + sage: TestSuite(R).run(skip=['_test_an_element', # needs sage.libs.flint ....: '_test_enumerated_set_contains', '_test_some_elements']) """ self._n = n @@ -74,7 +74,7 @@ def cardinality(self): sage: from sage.combinat.restricted_growth import RestrictedGrowthArrays sage: R = RestrictedGrowthArrays(6) - sage: R.cardinality() + sage: R.cardinality() # needs sage.libs.flint 203 """ return bell_number(self._n) diff --git a/src/sage/combinat/ribbon_shaped_tableau.py b/src/sage/combinat/ribbon_shaped_tableau.py index 4115a6a13aa..84458d104f3 100644 --- a/src/sage/combinat/ribbon_shaped_tableau.py +++ b/src/sage/combinat/ribbon_shaped_tableau.py @@ -199,8 +199,8 @@ def __init__(self, category=None): EXAMPLES:: - sage: S = RibbonShapedTableaux() - sage: TestSuite(S).run() + sage: S = RibbonShapedTableaux() # needs sage.graphs + sage: TestSuite(S).run() # needs sage.graphs """ if category is None: category = Sets() @@ -270,6 +270,7 @@ def __init__(self, category=None): EXAMPLES:: + sage: # needs sage.graphs sage.modules sage: S = StandardRibbonShapedTableaux() sage: TestSuite(S).run() """ @@ -293,6 +294,7 @@ def __iter__(self): EXAMPLES:: + sage: # needs sage.graphs sage.modules sage: it = StandardRibbonShapedTableaux().__iter__() sage: [next(it) for x in range(10)] [[], @@ -376,6 +378,8 @@ class StandardRibbonShapedTableaux_shape(StandardRibbonShapedTableaux): [[None, 2, 4], [1, 3]] sage: StandardRibbonShapedTableaux([2,2]).last() [[None, 1, 2], [3, 4]] + + sage: # needs sage.graphs sage.modules sage: StandardRibbonShapedTableaux([2,2]).cardinality() 5 sage: StandardRibbonShapedTableaux([2,2]).list() @@ -406,7 +410,7 @@ def __init__(self, shape): TESTS:: sage: S = StandardRibbonShapedTableaux([2,2]) - sage: TestSuite(S).run() + sage: TestSuite(S).run() # needs sage.graphs """ self.shape = shape StandardRibbonShapedTableaux.__init__(self, FiniteEnumeratedSets()) @@ -448,7 +452,7 @@ def __iter__(self): EXAMPLES:: - sage: [t for t in StandardRibbonShapedTableaux([2,2])] + sage: [t for t in StandardRibbonShapedTableaux([2,2])] # needs sage.graphs [[[None, 1, 3], [2, 4]], [[None, 1, 2], [3, 4]], [[None, 2, 3], [1, 4]], diff --git a/src/sage/combinat/ribbon_tableau.py b/src/sage/combinat/ribbon_tableau.py index 843626c4752..db82cbfd660 100644 --- a/src/sage/combinat/ribbon_tableau.py +++ b/src/sage/combinat/ribbon_tableau.py @@ -663,20 +663,21 @@ def spin_polynomial(part, weight, length): EXAMPLES:: + sage: # needs sage.symbolic sage: from sage.combinat.ribbon_tableau import spin_polynomial - sage: spin_polynomial([6,6,6],[4,2],3) # optional - sage.symbolic + sage: spin_polynomial([6,6,6],[4,2],3) t^6 + t^5 + 2*t^4 + t^3 + t^2 - sage: spin_polynomial([6,6,6],[4,1,1],3) # optional - sage.symbolic + sage: spin_polynomial([6,6,6],[4,1,1],3) t^6 + 2*t^5 + 3*t^4 + 2*t^3 + t^2 - sage: spin_polynomial([3,3,3,2,1], [2,2], 3) # optional - sage.symbolic + sage: spin_polynomial([3,3,3,2,1], [2,2], 3) t^(7/2) + t^(5/2) - sage: spin_polynomial([3,3,3,2,1], [2,1,1], 3) # optional - sage.symbolic + sage: spin_polynomial([3,3,3,2,1], [2,1,1], 3) 2*t^(7/2) + 2*t^(5/2) + t^(3/2) - sage: spin_polynomial([3,3,3,2,1], [1,1,1,1], 3) # optional - sage.symbolic + sage: spin_polynomial([3,3,3,2,1], [1,1,1,1], 3) 3*t^(7/2) + 5*t^(5/2) + 3*t^(3/2) + sqrt(t) - sage: spin_polynomial([5,4,3,2,1,1,1], [2,2,1], 3) # optional - sage.symbolic + sage: spin_polynomial([5,4,3,2,1,1,1], [2,2,1], 3) 2*t^(9/2) + 6*t^(7/2) + 2*t^(5/2) - sage: spin_polynomial([[6]*6, [3,3]], [4,4,2], 3) # optional - sage.symbolic + sage: spin_polynomial([[6]*6, [3,3]], [4,4,2], 3) 3*t^9 + 5*t^8 + 9*t^7 + 6*t^6 + 3*t^5 """ from sage.symbolic.ring import SR diff --git a/src/sage/combinat/rigged_configurations/kleber_tree.py b/src/sage/combinat/rigged_configurations/kleber_tree.py index b4a57e365f6..f6082658969 100644 --- a/src/sage/combinat/rigged_configurations/kleber_tree.py +++ b/src/sage/combinat/rigged_configurations/kleber_tree.py @@ -1044,7 +1044,7 @@ def plot(self, **options): sage: from sage.combinat.rigged_configurations.kleber_tree import KleberTree sage: KT = KleberTree(['D', 4, 1], [[2, 2]]) - sage: print(KT.plot()) # optional - sage.plot + sage: print(KT.plot()) # needs sage.plot Graphics object consisting of 8 graphics primitives """ return self.digraph().plot(edge_labels=True, vertex_size=0, **options) diff --git a/src/sage/combinat/root_system/coxeter_group.py b/src/sage/combinat/root_system/coxeter_group.py index f33003b35f6..83c1c0c7e9e 100644 --- a/src/sage/combinat/root_system/coxeter_group.py +++ b/src/sage/combinat/root_system/coxeter_group.py @@ -73,7 +73,7 @@ def CoxeterGroup(data, implementation="reflection", base_ring=None, index_set=No Permutation Group with generators [(1,4)(2,3)(5,6), (1,3)(2,5)(4,6)] sage: W.category() # optional - gap3 Join of Category of finite enumerated permutation groups - and Category of finite weyl groups + and Category of finite Weyl groups and Category of well generated finite irreducible complex reflection groups sage: W = CoxeterGroup(["A",2], implementation="matrix"); W # needs sage.libs.gap diff --git a/src/sage/combinat/root_system/weyl_group.py b/src/sage/combinat/root_system/weyl_group.py index c2e9b8dc59d..58711f85653 100644 --- a/src/sage/combinat/root_system/weyl_group.py +++ b/src/sage/combinat/root_system/weyl_group.py @@ -583,7 +583,7 @@ class ClassicalWeylSubgroup(WeylGroup_gens): sage: G Parabolic Subgroup of the Weyl Group of type ['A', 3, 1] (as a matrix group acting on the root space) sage: G.category() - Category of finite irreducible weyl groups + Category of finite irreducible Weyl groups sage: G.cardinality() 24 sage: G.index_set() diff --git a/src/sage/combinat/rooted_tree.py b/src/sage/combinat/rooted_tree.py index e8a44b1b163..9bb17754233 100644 --- a/src/sage/combinat/rooted_tree.py +++ b/src/sage/combinat/rooted_tree.py @@ -522,10 +522,10 @@ def __init__(self): """ TESTS:: - sage: sum(x**len(t) # optional - sage.symbolic + sage: sum(x**len(t) # needs sage.symbolic ....: for t in set(RootedTree(t) for t in OrderedTrees(6))) x^5 + x^4 + 3*x^3 + 6*x^2 + 9*x - sage: sum(x**len(t) for t in RootedTrees(6)) # optional - sage.symbolic + sage: sum(x**len(t) for t in RootedTrees(6)) # needs sage.symbolic x^5 + x^4 + 3*x^3 + 6*x^2 + 9*x sage: TestSuite(RootedTrees()).run() # long time @@ -625,14 +625,14 @@ class RootedTrees_size(RootedTrees): TESTS:: sage: from sage.combinat.rooted_tree import RootedTrees_size - sage: for i in range(1, 6): TestSuite(RootedTrees_size(i)).run() # optional - sage.combinat + sage: for i in range(1, 6): TestSuite(RootedTrees_size(i)).run() # needs sage.combinat """ def __init__(self, n): """ TESTS:: - sage: for i in range(1, 6): # optional - sage.combinat + sage: for i in range(1, 6): # needs sage.combinat ....: TestSuite(RootedTrees(i)).run() """ super().__init__(category=FiniteEnumeratedSets()) @@ -663,7 +663,7 @@ def _an_element_(self): """ TESTS:: - sage: RootedTrees(4).an_element() # indirect doctest # optional - sage.combinat + sage: RootedTrees(4).an_element() # indirect doctest # needs sage.combinat [[[[]]]] """ return self.first() @@ -681,11 +681,11 @@ def __iter__(self): sage: from sage.combinat.rooted_tree import * sage: RootedTrees(1).list() [[]] - sage: RootedTrees(2).list() # optional - sage.combinat + sage: RootedTrees(2).list() # needs sage.combinat [[[]]] - sage: RootedTrees(3).list() # optional - sage.combinat + sage: RootedTrees(3).list() # needs sage.combinat [[[[]]], [[], []]] - sage: RootedTrees(4).list() # optional - sage.combinat + sage: RootedTrees(4).list() # needs sage.combinat [[[[[]]]], [[[], []]], [[], [[]]], [[], [], []]] """ if self._n == 1: @@ -757,7 +757,7 @@ def element_class(self): sage: S = RootedTrees(3) sage: S.element_class - sage: S.first().__class__ == RootedTrees().first().__class__ # optional - sage.combinat + sage: S.first().__class__ == RootedTrees().first().__class__ # needs sage.combinat True """ return self._parent_for.element_class diff --git a/src/sage/combinat/set_partition.py b/src/sage/combinat/set_partition.py index 4fda6338b57..c7d5e98ea33 100644 --- a/src/sage/combinat/set_partition.py +++ b/src/sage/combinat/set_partition.py @@ -381,7 +381,7 @@ def standard_form(self): EXAMPLES:: - sage: [x.standard_form() for x in SetPartitions(4, [2,2])] + sage: [x.standard_form() for x in SetPartitions(4, [2,2])] # needs sage.graphs sage.rings.finite_rings [[[1, 2], [3, 4]], [[1, 4], [2, 3]], [[1, 3], [2, 4]]] TESTS:: @@ -466,6 +466,7 @@ def max_block_size(self): EXAMPLES:: + sage: # needs sage.modules sage: from sage.combinat.diagram_algebras import PartitionDiagram, PartitionDiagrams sage: pd = PartitionDiagram([[1,-3,-5],[2,4],[3,-1,-2],[5],[-4]]) sage: pd.max_block_size() @@ -562,18 +563,18 @@ class SetPartition(AbstractSetPartition, There are 5 set partitions of the set `\{1,2,3\}`:: - sage: SetPartitions(3).cardinality() + sage: SetPartitions(3).cardinality() # needs sage.libs.flint 5 Here is the list of them:: - sage: SetPartitions(3).list() + sage: SetPartitions(3).list() # needs sage.graphs [{{1, 2, 3}}, {{1, 2}, {3}}, {{1, 3}, {2}}, {{1}, {2, 3}}, {{1}, {2}, {3}}] There are 6 set partitions of `\{1,2,3,4\}` whose underlying partition is `[2, 1, 1]`:: - sage: SetPartitions(4, [2,1,1]).list() + sage: SetPartitions(4, [2,1,1]).list() # needs sage.graphs sage.rings.finite_rings [{{1}, {2, 4}, {3}}, {{1}, {2}, {3, 4}}, {{1, 4}, {2}, {3}}, @@ -1798,14 +1799,14 @@ def refinements(self): EXAMPLES:: - sage: SetPartition([[1,3],[2,4]]).refinements() + sage: SetPartition([[1,3],[2,4]]).refinements() # needs sage.graphs sage.libs.flint [{{1, 3}, {2, 4}}, {{1, 3}, {2}, {4}}, {{1}, {2, 4}, {3}}, {{1}, {2}, {3}, {4}}] - sage: SetPartition([[1],[2,4],[3]]).refinements() + sage: SetPartition([[1],[2,4],[3]]).refinements() # needs sage.graphs sage.libs.flint [{{1}, {2, 4}, {3}}, {{1}, {2}, {3}, {4}}] - sage: SetPartition([]).refinements() + sage: SetPartition([]).refinements() # needs sage.graphs sage.libs.flint [{}] """ L = [SetPartitions(part) for part in self] @@ -1893,7 +1894,7 @@ def plot(self, angle=None, color='black', base_set_dict=None): EXAMPLES:: sage: p = SetPartition([[1,10,11],[2,3,7],[4,5,6],[8,9]]) - sage: p.plot() # optional - sage.plot sage.symbolic + sage: p.plot() # needs sage.plot sage.symbolic Graphics object consisting of 29 graphics primitives .. PLOT:: @@ -1904,7 +1905,7 @@ def plot(self, angle=None, color='black', base_set_dict=None): :: sage: p = SetPartition([[1,3,4],[2,5]]) - sage: print(p.plot().description()) # optional - sage.plot sage.symbolic + sage: print(p.plot().description()) # needs sage.plot sage.symbolic Point set defined by 1 point(s): [(0.0, 0.0)] Point set defined by 1 point(s): [(1.0, 0.0)] Point set defined by 1 point(s): [(2.0, 0.0)] @@ -1922,7 +1923,7 @@ def plot(self, angle=None, color='black', base_set_dict=None): Arc with center (2.5,-1.5) radii (2.1213203435...,2.1213203435...) angle 0.0 inside the sector (0.785398163397...,2.35619449019...) sage: p = SetPartition([['a','c'],['b','d'],['e']]) - sage: print(p.plot().description()) # optional - sage.plot sage.symbolic + sage: print(p.plot().description()) # needs sage.plot sage.symbolic Point set defined by 1 point(s): [(0.0, 0.0)] Point set defined by 1 point(s): [(1.0, 0.0)] Point set defined by 1 point(s): [(2.0, 0.0)] @@ -1938,7 +1939,7 @@ def plot(self, angle=None, color='black', base_set_dict=None): Arc with center (2.0,-1.0) radii (1.41421356237...,1.41421356237...) angle 0.0 inside the sector (0.785398163397...,2.35619449019...) sage: p = SetPartition([['a','c'],['b','d'],['e']]) - sage: print(p.plot(base_set_dict={'a':0,'b':1,'c':2, # optional - sage.plot sage.symbolic + sage: print(p.plot(base_set_dict={'a':0,'b':1,'c':2, # needs sage.plot sage.symbolic ....: 'd':-2.3,'e':5.4}).description()) Point set defined by 1 point(s): [(-2.3, 0.0)] Point set defined by 1 point(s): [(0.0, 0.0)] @@ -2020,17 +2021,17 @@ class SetPartitions(UniqueRepresentation, Parent): sage: S = [1,2,3,4] sage: SetPartitions(S, 2) Set partitions of {1, 2, 3, 4} with 2 parts - sage: SetPartitions([1,2,3,4], [3,1]).list() + sage: SetPartitions([1,2,3,4], [3,1]).list() # needs sage.graphs sage.rings.finite_rings [{{1}, {2, 3, 4}}, {{1, 2, 3}, {4}}, {{1, 2, 4}, {3}}, {{1, 3, 4}, {2}}] - sage: SetPartitions(7, [3,3,1]).cardinality() + sage: SetPartitions(7, [3,3,1]).cardinality() # needs sage.libs.flint 70 In strings, repeated letters are not considered distinct as of :trac:`14140`:: - sage: SetPartitions('abcde').cardinality() + sage: SetPartitions('abcde').cardinality() # needs sage.libs.flint 52 - sage: SetPartitions('aabcd').cardinality() + sage: SetPartitions('aabcd').cardinality() # needs sage.libs.flint 15 REFERENCES: @@ -2080,13 +2081,13 @@ def __contains__(self, x): sage: S = SetPartitions(4, [2,2]) sage: SA = SetPartitions() - sage: all(sp in SA for sp in S) + sage: all(sp in SA for sp in S) # needs sage.graphs sage.modules sage.rings.finite_rings True - sage: Set([Set([1,2]),Set([3,7])]) in SA + sage: Set([Set([1,2]),Set([3,7])]) in SA # needs sage.graphs True - sage: Set([Set([1,2]),Set([2,3])]) in SA + sage: Set([Set([1,2]),Set([2,3])]) in SA # needs sage.graphs False - sage: Set([]) in SA + sage: Set([]) in SA # needs sage.graphs True """ # x must be a set @@ -2750,13 +2751,13 @@ def __contains__(self, x): TESTS:: sage: S = SetPartitions(4, [2,2]) - sage: all(sp in S for sp in S) + sage: all(sp in S for sp in S) # needs sage.graphs sage.rings.finite_rings True - sage: SetPartition([[1,3],[2,4]]) in SetPartitions(3) + sage: SetPartition([[1,3],[2,4]]) in SetPartitions(3) # needs sage.graphs False - sage: SetPartition([[1,3],[2,4]]) in SetPartitions(4, [3,1]) + sage: SetPartition([[1,3],[2,4]]) in SetPartitions(4, [3,1]) # needs sage.graphs False - sage: SetPartition([[2],[1,3,4]]) in SetPartitions(4, [3,1]) + sage: SetPartition([[2],[1,3,4]]) in SetPartitions(4, [3,1]) # needs sage.graphs True """ # Must pass the general check @@ -2780,16 +2781,16 @@ def random_element(self): EXAMPLES:: sage: S = SetPartitions(10) - sage: s = S.random_element() - sage: s.parent() is S + sage: s = S.random_element() # needs sage.symbolic + sage: s.parent() is S # needs sage.symbolic True - sage: assert s in S, s + sage: assert s in S, s # needs sage.symbolic sage: S = SetPartitions(["a", "b", "c"]) - sage: s = S.random_element() - sage: s.parent() is S + sage: s = S.random_element() # needs sage.symbolic + sage: s.parent() is S # needs sage.symbolic True - sage: assert s in S, s + sage: assert s in S, s # needs sage.symbolic """ base_set = list(self.base_set()) N = len(base_set) @@ -2818,6 +2819,7 @@ def cardinality(self): EXAMPLES:: + sage: # needs sage.libs.flint sage: SetPartitions([1,2,3,4]).cardinality() 15 sage: SetPartitions(3).cardinality() @@ -2905,7 +2907,7 @@ def __init__(self, s, parts): TESTS:: sage: S = SetPartitions(4, [2,2]) - sage: TestSuite(S).run() + sage: TestSuite(S).run() # needs sage.graphs sage.libs.flint """ SetPartitions_set.__init__(self, s) self._parts = parts @@ -2959,7 +2961,8 @@ def cardinality(self): sage: all((len(SetPartitions(size, part)) == SetPartitions(size, part).cardinality() for size in range(8) for part in Partitions(size))) True - sage: sum((SetPartitions(13, p).cardinality() for p in Partitions(13))) == SetPartitions(13).cardinality() + sage: sum((SetPartitions(13, p).cardinality() # needs sage.libs.flint + ....: for p in Partitions(13))) == SetPartitions(13).cardinality() True """ from sage.misc.misc_c import prod @@ -2983,12 +2986,13 @@ def _set_partition_poset(self): TESTS:: - sage: P = SetPartitions(["a", "b", "c", "d", "e"], [2,2,1])._set_partition_poset() - sage: P.cover_relations() + sage: P = SetPartitions(["a", "b", "c", "d", "e"], # needs sage.graphs + ....: [2,2,1])._set_partition_poset() + sage: P.cover_relations() # needs sage.graphs [(1, 2), (1, 3), (3, 4)] sage: n = 9 - sage: all(SetPartitions(n, mu).cardinality() == + sage: all(SetPartitions(n, mu).cardinality() == # needs sage.graphs sage.modules ....: len(list(SetPartitions(n, mu)._set_partition_poset().linear_extensions())) ....: for mu in Partitions(n)) True @@ -3023,16 +3027,17 @@ def __iter__(self): EXAMPLES:: - sage: SetPartitions(3, [2,1]).list() + sage: SetPartitions(3, [2,1]).list() # needs sage.graphs sage.rings.finite_rings [{{1}, {2, 3}}, {{1, 2}, {3}}, {{1, 3}, {2}}] - sage: SetPartitions(["a", "b", "c"], [2,1]).list() + sage: SetPartitions(["a", "b", "c"], [2,1]).list() # needs sage.graphs sage.rings.finite_rings [{{'a'}, {'b', 'c'}}, {{'a', 'b'}, {'c'}}, {{'a', 'c'}, {'b'}}] TESTS:: sage: n = 8 - sage: all(SetPartitions(n, mu).cardinality() == len(list(SetPartitions(n, mu))) for mu in Partitions(n)) + sage: all(SetPartitions(n, mu).cardinality() # needs sage.graphs sage.rings.finite_rings + ....: == len(list(SetPartitions(n, mu))) for mu in Partitions(n)) True """ # Ruskey, Combinatorial Generation, sec. 5.10.1 and Knuth TAOCP 4A 7.2.1.5, Exercise 6 diff --git a/src/sage/combinat/set_partition_iterator.pyx b/src/sage/combinat/set_partition_iterator.pyx index 47667561a71..7c9bc0eaaf5 100644 --- a/src/sage/combinat/set_partition_iterator.pyx +++ b/src/sage/combinat/set_partition_iterator.pyx @@ -31,7 +31,7 @@ def set_partition_iterator(base_set): EXAMPLES:: sage: from sage.combinat.set_partition_iterator import set_partition_iterator - sage: list(set_partition_iterator([1,-1,x])) # optional - sage.symbolic + sage: list(set_partition_iterator([1,-1,x])) # needs sage.symbolic [[[1, -1, x]], [[1, -1], [x]], [[1, x], [-1]], @@ -122,7 +122,7 @@ def set_partition_iterator_blocks(base_set, Py_ssize_t k): EXAMPLES:: sage: from sage.combinat.set_partition_iterator import set_partition_iterator_blocks - sage: list(set_partition_iterator_blocks([1,-1,x], 2)) # optional - sage.symbolic + sage: list(set_partition_iterator_blocks([1,-1,x], 2)) # needs sage.symbolic [[[1, x], [-1]], [[1], [-1, x]], [[1, -1], [x]]] """ cdef list base = list(base_set) diff --git a/src/sage/combinat/sf/elementary.py b/src/sage/combinat/sf/elementary.py index ce9cae6cdc8..f0942314323 100644 --- a/src/sage/combinat/sf/elementary.py +++ b/src/sage/combinat/sf/elementary.py @@ -371,7 +371,7 @@ def principal_specialization(self, n=infinity, q=None): By default, we return a rational functions in `q`. Sometimes it is better to obtain an element of the symbolic ring:: - sage: x.principal_specialization(q=var("q")) # optional - sage.symbolic + sage: x.principal_specialization(q=var("q")) # needs sage.symbolic -3*q/((q^2 - 1)*(q - 1)^2) - 5/(q - 1)^3 + 1 TESTS:: @@ -469,7 +469,7 @@ def exponential_specialization(self, t=None, q=1): sage: x.exponential_specialization() 1/12*t^5 sage: x = 5*e[2] + 3*e[1] + 1 - sage: x.exponential_specialization(t=var("t"), q=var("q")) # optional - sage.symbolic + sage: x.exponential_specialization(t=var("t"), q=var("q")) # needs sage.symbolic 5*q*t^2/(q + 1) + 3*t + 1 TESTS:: diff --git a/src/sage/combinat/sf/homogeneous.py b/src/sage/combinat/sf/homogeneous.py index e83dd16861e..29cf294ea80 100644 --- a/src/sage/combinat/sf/homogeneous.py +++ b/src/sage/combinat/sf/homogeneous.py @@ -281,7 +281,7 @@ def principal_specialization(self, n=infinity, q=None): sage: x.principal_specialization(3) q^6 + 2*q^5 + 4*q^4 + 4*q^3 + 4*q^2 + 2*q + 1 sage: x = 3*h[2] + 2*h[1] + 1 - sage: x.principal_specialization(3, q=var("q")) # optional - sage.symbolic + sage: x.principal_specialization(3, q=var("q")) # needs sage.symbolic 2*(q^3 - 1)/(q - 1) + 3*(q^4 - 1)*(q^3 - 1)/((q^2 - 1)*(q - 1)) + 1 TESTS:: @@ -385,7 +385,7 @@ def exponential_specialization(self, t=None, q=1): We also support the `q`-exponential_specialization:: - sage: factor(h[3].exponential_specialization(q=var("q"), t=var("t"))) # optional - sage.symbolic + sage: factor(h[3].exponential_specialization(q=var("q"), t=var("t"))) # needs sage.symbolic t^3/((q^2 + q + 1)*(q + 1)) TESTS:: diff --git a/src/sage/combinat/sf/monomial.py b/src/sage/combinat/sf/monomial.py index 6c910527fc9..583008830af 100644 --- a/src/sage/combinat/sf/monomial.py +++ b/src/sage/combinat/sf/monomial.py @@ -366,7 +366,7 @@ def principal_specialization(self, n=infinity, q=None): q^7 + q^6 + q^5 + q^3 + q^2 + q sage: x = 5*m[2] + 3*m[1] + 1 - sage: x.principal_specialization(3, q=var("q")) # optional - sage.symbolic + sage: x.principal_specialization(3, q=var("q")) # needs sage.symbolic -10*(q^3 - 1)*q/(q - 1) + 5*(q^3 - 1)^2/(q - 1)^2 + 3*(q^3 - 1)/(q - 1) + 1 TESTS:: @@ -452,7 +452,7 @@ def exponential_specialization(self, t=None, q=1): We also support the `q`-exponential_specialization:: - sage: factor(m[3].exponential_specialization(q=var("q"), t=var("t"))) # optional - sage.symbolic + sage: factor(m[3].exponential_specialization(q=var("q"), t=var("t"))) # needs sage.symbolic (q - 1)^2*t^3/(q^2 + q + 1) TESTS:: diff --git a/src/sage/combinat/sf/ns_macdonald.py b/src/sage/combinat/sf/ns_macdonald.py index 8807bd95b87..a2340ab5f68 100644 --- a/src/sage/combinat/sf/ns_macdonald.py +++ b/src/sage/combinat/sf/ns_macdonald.py @@ -534,8 +534,8 @@ def coeff(self, q, t): EXAMPLES:: sage: a = AugmentedLatticeDiagramFilling([[1,6],[2],[3,4,2],[],[],[5,5]]) - sage: q,t = var('q,t') # optional - sage.symbolic - sage: a.coeff(q,t) # optional - sage.symbolic + sage: q,t = var('q,t') # needs sage.symbolic + sage: a.coeff(q,t) # needs sage.symbolic (t - 1)^4/((q^2*t^3 - 1)^2*(q*t^2 - 1)^2) """ res = 1 @@ -555,8 +555,8 @@ def coeff_integral(self, q, t): EXAMPLES:: sage: a = AugmentedLatticeDiagramFilling([[1,6],[2],[3,4,2],[],[],[5,5]]) - sage: q,t = var('q,t') # optional - sage.symbolic - sage: a.coeff_integral(q,t) # optional - sage.symbolic + sage: q,t = var('q,t') # needs sage.symbolic + sage: a.coeff_integral(q,t) # needs sage.symbolic (q^2*t^3 - 1)^2*(q*t^2 - 1)^2*(t - 1)^4 """ res = 1 @@ -807,15 +807,15 @@ def _check_muqt(mu, q, t, pi=None): :: - sage: q,t = var('q,t') # optional - sage.symbolic - sage: P, q, t, n, R, x = _check_muqt([0,0,1],q,None) # optional - sage.symbolic + sage: q,t = var('q,t') # needs sage.symbolic + sage: P, q, t, n, R, x = _check_muqt([0,0,1],q,None) # needs sage.symbolic Traceback (most recent call last): ... ValueError: you must specify either both q and t or neither of them :: - sage: P, q, t, n, R, x = _check_muqt([0,0,1],q,2) # optional - sage.symbolic + sage: P, q, t, n, R, x = _check_muqt([0,0,1],q,2) # needs sage.symbolic Traceback (most recent call last): ... ValueError: the parents of q and t must be the same diff --git a/src/sage/combinat/sf/powersum.py b/src/sage/combinat/sf/powersum.py index bb20adf9941..8d7f744e75f 100644 --- a/src/sage/combinat/sf/powersum.py +++ b/src/sage/combinat/sf/powersum.py @@ -761,11 +761,11 @@ def principal_specialization(self, n=infinity, q=None): sage: p = SymmetricFunctions(QQ).p() sage: x = p[8,7,3,1] - sage: x.principal_specialization(3, q=var("q")) # optional - sage.symbolic + sage: x.principal_specialization(3, q=var("q")) # needs sage.symbolic (q^24 - 1)*(q^21 - 1)*(q^9 - 1)/((q^8 - 1)*(q^7 - 1)*(q - 1)) sage: x = 5*p[1,1,1] + 3*p[2,1] + 1 - sage: x.principal_specialization(3, q=var("q")) # optional - sage.symbolic + sage: x.principal_specialization(3, q=var("q")) # needs sage.symbolic 5*(q^3 - 1)^3/(q - 1)^3 + 3*(q^6 - 1)*(q^3 - 1)/((q^2 - 1)*(q - 1)) + 1 By default, we return a rational function in `q`:: @@ -775,7 +775,7 @@ def principal_specialization(self, n=infinity, q=None): If ``n`` is not given we return the stable principal specialization:: - sage: x.principal_specialization(q=var("q")) # optional - sage.symbolic + sage: x.principal_specialization(q=var("q")) # needs sage.symbolic 3/((q^2 - 1)*(q - 1)) - 5/(q - 1)^3 + 1 TESTS:: @@ -882,12 +882,12 @@ def exponential_specialization(self, t=None, q=1): sage: x.exponential_specialization() 0 sage: x = p[3] + 5*p[1,1] + 2*p[1] + 1 - sage: x.exponential_specialization(t=var("t")) # optional - sage.symbolic + sage: x.exponential_specialization(t=var("t")) # needs sage.symbolic 5*t^2 + 2*t + 1 We also support the `q`-exponential_specialization:: - sage: factor(p[3].exponential_specialization(q=var("q"), t=var("t"))) # optional - sage.symbolic + sage: factor(p[3].exponential_specialization(q=var("q"), t=var("t"))) # needs sage.symbolic (q - 1)^2*t^3/(q^2 + q + 1) TESTS:: diff --git a/src/sage/combinat/sf/schur.py b/src/sage/combinat/sf/schur.py index 283a43001a7..40e1de75812 100644 --- a/src/sage/combinat/sf/schur.py +++ b/src/sage/combinat/sf/schur.py @@ -19,14 +19,16 @@ # **************************************************************************** from . import classical -import sage.libs.lrcalc.lrcalc as lrcalc from sage.misc.misc_c import prod +from sage.misc.lazy_import import lazy_import from sage.data_structures.blas_dict import convert_remove_zeroes from sage.rings.infinity import infinity from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.arith.misc import factorial from sage.combinat.tableau import StandardTableaux +lazy_import('sage.libs.lrcalc', 'lrcalc') + class SymmetricFunctionAlgebra_schur(classical.SymmetricFunctionAlgebra_classical): def __init__(self, Sym): @@ -662,10 +664,10 @@ def principal_specialization(self, n=infinity, q=None): q^4 + q^3 + 2*q^2 + q + 1 sage: x = 3*s[2,2] + 2*s[1] + 1 - sage: x.principal_specialization(3, q=var("q")) # optional - sage.symbolic + sage: x.principal_specialization(3, q=var("q")) # needs sage.symbolic 3*(q^4 - 1)*(q^3 - 1)*q^2/((q^2 - 1)*(q - 1)) + 2*(q^3 - 1)/(q - 1) + 1 - sage: x.principal_specialization(q=var("q")) # optional - sage.symbolic + sage: x.principal_specialization(q=var("q")) # needs sage.symbolic -2/(q - 1) + 3*q^2/((q^3 - 1)*(q^2 - 1)^2*(q - 1)) + 1 TESTS:: @@ -806,7 +808,7 @@ def exponential_specialization(self, t=None, q=1): We also support the `q`-exponential_specialization:: - sage: factor(s[3].exponential_specialization(q=var("q"), t=var("t"))) # optional - sage.symbolic + sage: factor(s[3].exponential_specialization(q=var("q"), t=var("t"))) # needs sage.symbolic t^3/((q^2 + q + 1)*(q + 1)) TESTS:: diff --git a/src/sage/combinat/sf/sfa.py b/src/sage/combinat/sf/sfa.py index 3e9ac55bd70..9a5d8fb70a3 100644 --- a/src/sage/combinat/sf/sfa.py +++ b/src/sage/combinat/sf/sfa.py @@ -4916,8 +4916,8 @@ def scalar_qt(self, x, q=None, t=None): -q^3 + 2*q^2 - 2*q + 1 sage: a.scalar_qt(a,5,7) # q=5 and t=7 490/1539 - sage: (x,y) = var('x,y') # optional - sage.symbolic - sage: a.scalar_qt(a, q=x, t=y) # optional - sage.symbolic + sage: (x,y) = var('x,y') # needs sage.symbolic + sage: a.scalar_qt(a, q=x, t=y) # needs sage.symbolic 1/3*(x^3 - 1)/(y^3 - 1) + 2/3*(x - 1)^3/(y - 1)^3 sage: Rn = QQ['q','t','y','z'].fraction_field() sage: (q,t,y,z) = Rn.gens() @@ -6030,7 +6030,7 @@ def principal_specialization(self, n=infinity, q=None): it is better to obtain an element of the symbolic ring:: sage: h = SymmetricFunctions(QQ).h() - sage: (h[3]+h[2]).principal_specialization(q=var("q")) # optional - sage.symbolic + sage: (h[3]+h[2]).principal_specialization(q=var("q")) # needs sage.symbolic 1/((q^2 - 1)*(q - 1)) - 1/((q^3 - 1)*(q^2 - 1)*(q - 1)) In case ``q`` is in the base ring, it must be passed explicitly:: @@ -6291,11 +6291,11 @@ def exponential_specialization(self, t=None, q=1): sage: x = m[3]+m[2,1]+m[1,1,1] sage: d = x.homogeneous_degree() - sage: var("q t") # optional - sage.symbolic + sage: var("q t") # needs sage.symbolic (q, t) - sage: factor((x.principal_specialization()*(1-q)^d*t^d)) # optional - sage.symbolic + sage: factor((x.principal_specialization()*(1-q)^d*t^d)) # needs sage.symbolic t^3/((q^2 + q + 1)*(q + 1)) - sage: factor(x.exponential_specialization(q=q, t=t)) # optional - sage.symbolic + sage: factor(x.exponential_specialization(q=q, t=t)) # needs sage.symbolic t^3/((q^2 + q + 1)*(q + 1)) TESTS:: diff --git a/src/sage/combinat/shuffle.py b/src/sage/combinat/shuffle.py index 8bae3eda267..50618a6388f 100644 --- a/src/sage/combinat/shuffle.py +++ b/src/sage/combinat/shuffle.py @@ -254,7 +254,7 @@ def _ascii_art_(self): TESTS:: sage: from sage.combinat.shuffle import SetShuffleProduct - sage: ascii_art(SetShuffleProduct([[BinaryTree()], [BinaryTree([]), BinaryTree([[],[]])]], + sage: ascii_art(SetShuffleProduct([[BinaryTree()], [BinaryTree([]), BinaryTree([[],[]])]], # needs sage.graphs ....: [[1,4]])) Set shuffle product of: [ [ o, o ] ] @@ -376,8 +376,8 @@ def _repr_(self): sage: from sage.combinat.shuffle import ShuffleProduct sage: ShuffleProduct([1,2,3],[4,5]) Shuffle product of: [1, 2, 3] and [4, 5] - sage: B = BinaryTree - sage: ShuffleProduct([B(), B([[],[]])], []) + sage: B = BinaryTree # needs sage.graphs + sage: ShuffleProduct([B(), B([[],[]])], []) # needs sage.graphs Shuffle product of: [., [[., .], [., .]]] and [] """ return "Shuffle product of: %s and %s" % (self._l1, self._l2) @@ -390,8 +390,8 @@ def _ascii_art_(self): sage: ascii_art(ShuffleProduct([1,2,3],[4,5])) Shuffle product of: [ 1, 2, 3 ] and [ 4, 5 ] - sage: B = BinaryTree - sage: ascii_art(ShuffleProduct([B([]), B([[],[]])], + sage: B = BinaryTree # needs sage.graphs + sage: ascii_art(ShuffleProduct([B([]), B([[],[]])], # needs sage.graphs ....: [B([[[],[]],[[],None]])])) Shuffle product of: [ __o__ ] @@ -417,8 +417,8 @@ def __iter__(self): sage: list(ShuffleProduct([1,2,3],[4,5])) [[1, 2, 3, 4, 5], [1, 4, 2, 3, 5], [4, 1, 2, 3, 5], [1, 2, 4, 3, 5], [1, 4, 5, 2, 3], [4, 1, 5, 2, 3], [4, 5, 1, 2, 3], [1, 4, 2, 5, 3], [4, 1, 2, 5, 3], [1, 2, 4, 5, 3]] - sage: B = BinaryTree - sage: ascii_art(list(ShuffleProduct([B([]), B([[],[]])], + sage: B = BinaryTree # needs sage.graphs + sage: ascii_art(list(ShuffleProduct([B([]), B([[],[]])], # needs sage.graphs ....: [B([[[],[]],[[],None]])]))) [ [ o, o , __o__ ] [ __o__ , o, o ] [ [ / \ / \ ] [ / \ / \ ] diff --git a/src/sage/combinat/sine_gordon.py b/src/sage/combinat/sine_gordon.py index e98c393ea08..209acd4486e 100644 --- a/src/sage/combinat/sine_gordon.py +++ b/src/sage/combinat/sine_gordon.py @@ -463,7 +463,7 @@ def plot(self, **kwds): EXAMPLES:: sage: Y = SineGordonYsystem('A',(6,4,3)) - sage: Y.plot() # long time 2s + sage: Y.plot() # long time (2s) # needs sage.plot Graphics object consisting of 219 graphics primitives """ # Set up plotting options diff --git a/src/sage/combinat/six_vertex_model.py b/src/sage/combinat/six_vertex_model.py index cec485f23c7..11b3267eb61 100644 --- a/src/sage/combinat/six_vertex_model.py +++ b/src/sage/combinat/six_vertex_model.py @@ -111,7 +111,7 @@ def to_signed_matrix(self): EXAMPLES:: sage: M = SixVertexModel(3, boundary_conditions='ice') - sage: [x.to_signed_matrix() for x in M] + sage: [x.to_signed_matrix() for x in M] # needs sage.modules [ [1 0 0] [1 0 0] [ 0 1 0] [0 1 0] [0 1 0] [0 0 1] [0 0 1] [0 1 0] [0 0 1] [ 1 -1 1] [1 0 0] [0 0 1] [1 0 0] [0 1 0] @@ -149,7 +149,7 @@ def plot(self, color='sign'): EXAMPLES:: sage: M = SixVertexModel(2, boundary_conditions='ice') - sage: print(M[0].plot().description()) # optional - sage.plot + sage: print(M[0].plot().description()) # needs sage.plot Arrow from (-1.0,0.0) to (0.0,0.0) Arrow from (-1.0,1.0) to (0.0,1.0) Arrow from (0.0,0.0) to (0.0,-1.0) @@ -392,7 +392,7 @@ class SixVertexModel(UniqueRepresentation, Parent): sage: M = SixVertexModel(4, boundary_conditions='ice') sage: len(M) 42 - sage: all(len(SixVertexModel(n, boundary_conditions='ice')) + sage: all(len(SixVertexModel(n, boundary_conditions='ice')) # needs sage.modules ....: == AlternatingSignMatrices(n).cardinality() for n in range(1, 7)) True @@ -650,7 +650,7 @@ def partition_function(self, beta, epsilon): EXAMPLES:: sage: M = SixVertexModel(3, boundary_conditions='ice') - sage: M.partition_function(2, [1,2,1,2,1,2]) # optional - sage.symbolic + sage: M.partition_function(2, [1,2,1,2,1,2]) # needs sage.symbolic e^(-24) + 2*e^(-28) + e^(-30) + 2*e^(-32) + e^(-36) REFERENCES: @@ -693,8 +693,8 @@ def from_alternating_sign_matrix(self, asm): EXAMPLES:: sage: M = SixVertexModel(3, boundary_conditions='ice') - sage: asm = AlternatingSignMatrix([[0,1,0],[1,-1,1],[0,1,0]]) - sage: M.from_alternating_sign_matrix(asm) + sage: asm = AlternatingSignMatrix([[0,1,0],[1,-1,1],[0,1,0]]) # needs sage.modules + sage: M.from_alternating_sign_matrix(asm) # needs sage.modules ^ ^ ^ | | | --> # -> # <- # <-- @@ -710,11 +710,11 @@ def from_alternating_sign_matrix(self, asm): TESTS:: sage: M = SixVertexModel(5, boundary_conditions='ice') - sage: ASM = AlternatingSignMatrices(5) - sage: all(M.from_alternating_sign_matrix(x.to_alternating_sign_matrix()) == x + sage: ASM = AlternatingSignMatrices(5) # needs sage.modules + sage: all(M.from_alternating_sign_matrix(x.to_alternating_sign_matrix()) == x # needs sage.modules ....: for x in M) True - sage: all(M.from_alternating_sign_matrix(x).to_alternating_sign_matrix() == x + sage: all(M.from_alternating_sign_matrix(x).to_alternating_sign_matrix() == x # needs sage.modules ....: for x in ASM) True """ @@ -766,12 +766,12 @@ def to_alternating_sign_matrix(self): EXAMPLES:: sage: M = SixVertexModel(4, boundary_conditions='ice') - sage: M[6].to_alternating_sign_matrix() + sage: M[6].to_alternating_sign_matrix() # needs sage.modules [1 0 0 0] [0 0 0 1] [0 0 1 0] [0 1 0 0] - sage: M[7].to_alternating_sign_matrix() + sage: M[7].to_alternating_sign_matrix() # needs sage.modules [ 0 1 0 0] [ 1 -1 1 0] [ 0 1 -1 1] diff --git a/src/sage/combinat/skew_partition.py b/src/sage/combinat/skew_partition.py index 4c2239fd6a1..484b4ceb7f3 100644 --- a/src/sage/combinat/skew_partition.py +++ b/src/sage/combinat/skew_partition.py @@ -108,7 +108,7 @@ :: - sage: SkewPartition([[4,3,1],[2]]).jacobi_trudi() + sage: SkewPartition([[4,3,1],[2]]).jacobi_trudi() # needs sage.modules [h[2] h[] 0] [h[5] h[3] h[]] [h[6] h[4] h[1]] @@ -844,6 +844,7 @@ def cell_poset(self, orientation="SE"): EXAMPLES:: + sage: # needs sage.graphs sage: p = SkewPartition([[3,3,1], [2,1]]) sage: Q = p.cell_poset(); Q Finite poset containing 4 elements @@ -858,6 +859,7 @@ def cell_poset(self, orientation="SE"): sage: sorted(Q.upper_covers((0, 2))) [(1, 2)] + sage: # needs sage.graphs sage: P = p.cell_poset(orientation="NW"); P Finite poset containing 4 elements sage: sorted(P) @@ -869,6 +871,7 @@ def cell_poset(self, orientation="SE"): sage: sorted(P.upper_covers((1, 2))) [(0, 2), (1, 1)] + sage: # needs sage.graphs sage: R = p.cell_poset(orientation="NE"); R Finite poset containing 4 elements sage: sorted(R) @@ -896,7 +899,7 @@ def cell_poset(self, orientation="SE"): ....: and c[1] >= d[1]): ....: return False ....: return True - sage: all( check_NW(n) for n in range(7) ) + sage: all( check_NW(n) for n in range(7) ) # needs sage.graphs True sage: def check_NE(n): @@ -908,7 +911,7 @@ def cell_poset(self, orientation="SE"): ....: and c[1] <= d[1]): ....: return False ....: return True - sage: all( check_NE(n) for n in range(7) ) + sage: all( check_NE(n) for n in range(7) ) # needs sage.graphs True sage: def test_duality(n, ori1, ori2): @@ -920,11 +923,11 @@ def cell_poset(self, orientation="SE"): ....: if P.lt(c, d) != Q.lt(d, c): ....: return False ....: return True - sage: all( test_duality(n, "NW", "SE") for n in range(7) ) + sage: all( test_duality(n, "NW", "SE") for n in range(7) ) # needs sage.graphs True - sage: all( test_duality(n, "NE", "SW") for n in range(7) ) + sage: all( test_duality(n, "NE", "SW") for n in range(7) ) # needs sage.graphs True - sage: all( test_duality(n, "NE", "SE") for n in range(4) ) + sage: all( test_duality(n, "NE", "SE") for n in range(4) ) # needs sage.graphs False """ from sage.combinat.posets.posets import Poset @@ -1068,18 +1071,19 @@ def to_dag(self, format="string"): EXAMPLES:: - sage: dag = SkewPartition([[3, 3, 1], [1, 1]]).to_dag() # optional - sage.graphs - sage: dag.edges(sort=True) # optional - sage.graphs + sage: # needs sage.graphs + sage: dag = SkewPartition([[3, 3, 1], [1, 1]]).to_dag() + sage: dag.edges(sort=True) [('0,1', '0,2', None), ('0,1', '1,1', None), ('0,2', '1,2', None), ('1,1', '1,2', None)] - sage: dag.vertices(sort=True) # optional - sage.graphs + sage: dag.vertices(sort=True) ['0,1', '0,2', '1,1', '1,2', '2,0'] - sage: dag = SkewPartition([[3, 2, 1], [1, 1]]).to_dag(format="tuple") # optional - sage.graphs - sage: dag.edges(sort=True) # optional - sage.graphs + sage: dag = SkewPartition([[3, 2, 1], [1, 1]]).to_dag(format="tuple") + sage: dag.edges(sort=True) [((0, 1), (0, 2), None), ((0, 1), (1, 1), None)] - sage: dag.vertices(sort=True) # optional - sage.graphs + sage: dag.vertices(sort=True) [(0, 1), (0, 2), (1, 1), (2, 0)] """ outer = list(self.outer()) @@ -1216,11 +1220,11 @@ def jacobi_trudi(self): EXAMPLES:: - sage: SkewPartition([[3,2,1],[2,1]]).jacobi_trudi() + sage: SkewPartition([[3,2,1],[2,1]]).jacobi_trudi() # needs sage.modules [h[1] 0 0] [h[3] h[1] 0] [h[5] h[3] h[1]] - sage: SkewPartition([[4,3,2],[2,1]]).jacobi_trudi() + sage: SkewPartition([[4,3,2],[2,1]]).jacobi_trudi() # needs sage.modules [h[2] h[] 0] [h[4] h[2] h[]] [h[6] h[4] h[2]] @@ -1282,24 +1286,24 @@ def specht_module(self, base_ring=None): EXAMPLES:: sage: mu = SkewPartition([[3,2,1], [2]]) - sage: SM = mu.specht_module(QQ) - sage: s = SymmetricFunctions(QQ).s() - sage: s(SM.frobenius_image()) + sage: SM = mu.specht_module(QQ) # needs sage.modules + sage: s = SymmetricFunctions(QQ).s() # needs sage.modules + sage: s(SM.frobenius_image()) # needs sage.modules s[2, 1, 1] + s[2, 2] + s[3, 1] We verify that the Frobenius image is the corresponding skew Schur function:: - sage: s[3,2,1].skew_by(s[2]) + sage: s[3,2,1].skew_by(s[2]) # needs sage.modules s[2, 1, 1] + s[2, 2] + s[3, 1] :: sage: mu = SkewPartition([[4,2,1], [2,1]]) - sage: SM = mu.specht_module(QQ) - sage: s(SM.frobenius_image()) + sage: SM = mu.specht_module(QQ) # needs sage.modules + sage: s(SM.frobenius_image()) # needs sage.modules s[2, 1, 1] + s[2, 2] + 2*s[3, 1] + s[4] - sage: s(mu) + sage: s(mu) # needs sage.modules s[2, 1, 1] + s[2, 2] + 2*s[3, 1] + s[4] """ from sage.combinat.specht_module import SpechtModule @@ -1320,9 +1324,9 @@ def specht_module_dimension(self, base_ring=None): EXAMPLES:: sage: mu = SkewPartition([[3,2,1], [2]]) - sage: mu.specht_module_dimension() + sage: mu.specht_module_dimension() # needs sage.modules 8 - sage: mu.specht_module_dimension(GF(2)) + sage: mu.specht_module_dimension(GF(2)) # needs sage.modules sage.rings.finite_rings 8 """ from sage.categories.fields import Fields diff --git a/src/sage/combinat/skew_tableau.py b/src/sage/combinat/skew_tableau.py index 3c5282eae8e..4718f29f199 100644 --- a/src/sage/combinat/skew_tableau.py +++ b/src/sage/combinat/skew_tableau.py @@ -605,7 +605,7 @@ def weight(self): sage: by_word(t) == t.weight() True sage: SST = SemistandardTableaux(shape=[3,1,1]) - sage: all(by_word(t) == SkewTableau(t).weight() for t in SST) + sage: all(by_word(t) == SkewTableau(t).weight() for t in SST) # needs sage.modules True """ if (not self) or all(c is None for row in self for c in row): @@ -1288,8 +1288,9 @@ def standardization(self, check=True): Standard skew tableaux are fixed under standardization:: sage: p = Partition([4,3,3,2]) - sage: q = Partitions(3).random_element() - sage: all((t == t.standardization() for t in StandardSkewTableaux([p, q]))) + sage: q = Partitions(3).random_element() # needs sage.libs.flint + sage: all(t == t.standardization() # needs sage.libs.flint + ....: for t in StandardSkewTableaux([p, q])) True The reading word of the standardization is the @@ -1951,11 +1952,12 @@ class StandardSkewTableaux(SkewTableaux): sage: S = StandardSkewTableaux(2); S Standard skew tableaux of size 2 - sage: S.cardinality() # optional - sage.modules + sage: S.cardinality() # needs sage.modules 4 :: + sage: # needs sage.graphs sage.modules sage: StandardSkewTableaux([[3, 2, 1], [1, 1]]).list() [[[None, 2, 3], [None, 4], [1]], [[None, 1, 2], [None, 3], [4]], @@ -2016,7 +2018,7 @@ def __init__(self): EXAMPLES:: sage: s = StandardSkewTableaux() - sage: TestSuite(s).run() # optional - sage.graphs + sage: TestSuite(s).run() # needs sage.graphs """ StandardSkewTableaux.__init__(self, category=InfiniteEnumeratedSets()) @@ -2037,8 +2039,9 @@ def __iter__(self): EXAMPLES:: + sage: # needs sage.graphs sage.modules sage: it = StandardSkewTableaux().__iter__() - sage: [next(it) for x in range(10)] # optional - sage.graphs + sage: [next(it) for x in range(10)] [[], [[1]], [[1, 2]], [[1], [2]], [[None, 2], [1]], [[None, 1], [2]], @@ -2060,8 +2063,9 @@ def __init__(self, n): """ EXAMPLES:: + sage: # needs sage.graphs sage.modules sage: S = StandardSkewTableaux(3) - sage: TestSuite(S).run() # optional - sage.graphs + sage: TestSuite(S).run() """ self.n = n StandardSkewTableaux.__init__(self, category=FiniteEnumeratedSets()) @@ -2079,13 +2083,14 @@ def cardinality(self): """ EXAMPLES:: - sage: StandardSkewTableaux(1).cardinality() # optional - sage.modules + sage: # needs sage.modules + sage: StandardSkewTableaux(1).cardinality() 1 - sage: StandardSkewTableaux(2).cardinality() # optional - sage.modules + sage: StandardSkewTableaux(2).cardinality() 4 - sage: StandardSkewTableaux(3).cardinality() # optional - sage.modules + sage: StandardSkewTableaux(3).cardinality() 24 - sage: StandardSkewTableaux(4).cardinality() # optional - sage.modules + sage: StandardSkewTableaux(4).cardinality() 194 """ count = 0 @@ -2102,10 +2107,10 @@ def __iter__(self): EXAMPLES:: - sage: StandardSkewTableaux(2).list() # optional - sage.graphs + sage: # needs sage.graphs sage.modules + sage: StandardSkewTableaux(2).list() [[[1, 2]], [[1], [2]], [[None, 2], [1]], [[None, 1], [2]]] - - sage: StandardSkewTableaux(3).list() # optional - sage.graphs + sage: StandardSkewTableaux(3).list() [[[1, 2, 3]], [[1, 2], [3]], [[1, 3], [2]], [[None, 2, 3], [1]], [[None, 1, 2], [3]], [[None, 1, 3], [2]], @@ -2149,8 +2154,9 @@ def __init__(self, skp): """ TESTS:: + sage: # needs sage.graphs sage.modules sage: S = StandardSkewTableaux([[3, 2, 1], [1, 1]]) - sage: TestSuite(S).run() # optional - sage.graphs sage.modules + sage: TestSuite(S).run() """ self.skp = skp StandardSkewTableaux.__init__(self, category=FiniteEnumeratedSets()) @@ -2174,7 +2180,7 @@ def cardinality(self): EXAMPLES:: - sage: StandardSkewTableaux([[3, 2, 1], [1, 1]]).cardinality() # optional - sage.modules + sage: StandardSkewTableaux([[3, 2, 1], [1, 1]]).cardinality() # needs sage.modules 8 """ outer, inner = self.skp @@ -2201,7 +2207,8 @@ def __iter__(self): EXAMPLES:: - sage: StandardSkewTableaux([[3, 2, 1], [1, 1]]).list() # optional - sage.graphs + sage: # needs sage.graphs sage.modules + sage: StandardSkewTableaux([[3, 2, 1], [1, 1]]).list() [[[None, 2, 3], [None, 4], [1]], [[None, 1, 2], [None, 3], [4]], [[None, 1, 2], [None, 4], [3]], diff --git a/src/sage/combinat/specht_module.py b/src/sage/combinat/specht_module.py index 9db20d0b184..209890c1bd1 100644 --- a/src/sage/combinat/specht_module.py +++ b/src/sage/combinat/specht_module.py @@ -1,4 +1,4 @@ -# sage.doctest: needs sage.combinat sage.modules +# sage.doctest: needs sage.combinat sage.groups sage.modules r""" Specht Modules diff --git a/src/sage/combinat/subset.py b/src/sage/combinat/subset.py index add81ab8707..65dd76b8490 100644 --- a/src/sage/combinat/subset.py +++ b/src/sage/combinat/subset.py @@ -185,11 +185,11 @@ class Subsets_s(Parent): {1, 2, 3}, {1, 2, 4}, {1, 3, 4}, {2, 3, 4}, {1, 2, 3, 4}] - sage: S = Subsets(Subsets(Subsets(GF(3)))); S # optional - sage.rings.finite_rings + sage: S = Subsets(Subsets(Subsets(GF(3)))); S Subsets of Subsets of Subsets of Finite Field of size 3 - sage: S.cardinality() # optional - sage.rings.finite_rings + sage: S.cardinality() 115792089237316195423570985008687907853269984665640564039457584007913129639936 - sage: S.unrank(3149254230) # random # optional - sage.rings.finite_rings + sage: S.unrank(3149254230) # random {{{1}, {0, 2}}, {{0, 1, 2}, {0, 1}, {1}, {1, 2}}, {{2}, {1, 2}, {0, 1, 2}, {0, 2}, {1}, {}}, {{1, 2}, {0}}, @@ -247,7 +247,7 @@ def underlying_set(self): EXAMPLES:: - sage: Subsets(GF(13)).underlying_set() # optional - sage.rings.finite_rings + sage: Subsets(GF(13)).underlying_set() {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} """ return self.element_class(self._s) @@ -549,10 +549,10 @@ def lattice(self): EXAMPLES:: sage: X = Subsets([7,8,9]) - sage: X.lattice() # optional - sage.combinat sage.graphs + sage: X.lattice() # needs sage.combinat sage.graphs Finite lattice containing 8 elements sage: Y = Subsets(0) - sage: Y.lattice() # optional - sage.combinat sage.graphs + sage: Y.lattice() # needs sage.combinat sage.graphs Finite lattice containing 1 elements """ diff --git a/src/sage/combinat/subsets_hereditary.py b/src/sage/combinat/subsets_hereditary.py index 7a9e238679c..33b576e3cf1 100644 --- a/src/sage/combinat/subsets_hereditary.py +++ b/src/sage/combinat/subsets_hereditary.py @@ -72,23 +72,24 @@ def subsets_with_hereditary_property(f, X, max_obstruction_size=None, ncpus=1): have size 2. We can thus set ``max_obstruction_size=2``, which reduces the number of calls to `f` from 91 to 56:: + sage: # needs sage.graphs sage: num_calls = 0 - sage: g = graphs.PetersenGraph() # optional - sage.graphs + sage: g = graphs.PetersenGraph() sage: def is_independent_set(S): ....: global num_calls ....: num_calls += 1 ....: return g.subgraph(S).size() == 0 - sage: l1 = list(subsets_with_hereditary_property(is_independent_set, # optional - sage.graphs + sage: l1 = list(subsets_with_hereditary_property(is_independent_set, ....: g.vertices(sort=False))) - sage: num_calls # optional - sage.graphs + sage: num_calls 91 sage: num_calls = 0 - sage: l2 = list(subsets_with_hereditary_property(is_independent_set, # optional - sage.graphs + sage: l2 = list(subsets_with_hereditary_property(is_independent_set, ....: g.vertices(sort=False), ....: max_obstruction_size=2)) - sage: num_calls # optional - sage.graphs + sage: num_calls 56 - sage: l1 == l2 # optional - sage.graphs + sage: l1 == l2 True TESTS:: diff --git a/src/sage/combinat/subword_complex.py b/src/sage/combinat/subword_complex.py index 1a1b05dbf17..117f5599f70 100644 --- a/src/sage/combinat/subword_complex.py +++ b/src/sage/combinat/subword_complex.py @@ -84,13 +84,13 @@ sage: W = CoxeterGroup(['A',3]); I = list(W.index_set()) sage: Q = I + W.w0.coxeter_sorting_word(I) sage: S = SubwordComplex(Q,W.w0) - sage: S.brick_polytope() # optional - sage.geometry.polyhedron + sage: S.brick_polytope() # needs sage.geometry.polyhedron A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 14 vertices sage: W = CoxeterGroup(['H',3]); I = list(W.index_set()) sage: Q = I + W.w0.coxeter_sorting_word(I) sage: S = SubwordComplex(Q,W.w0) - sage: S.brick_polytope() # optional - sage.geometry.polyhedron + sage: S.brick_polytope() # needs sage.geometry.polyhedron doctest:...: RuntimeWarning: the polytope is built with rational vertices A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 32 vertices @@ -133,10 +133,11 @@ class SubwordComplexFacet(Simplex, Element): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1], w) # optional - gap3 - sage: F = SC[0]; F # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1], w) + sage: F = SC[0]; F (0, 1) sage: W = CoxeterGroup(['A',2]) @@ -210,12 +211,13 @@ def _extended_root_configuration_indices(self): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1], w) # optional - gap3 - sage: F = SC([1,2]); F # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1], w) + sage: F = SC([1,2]); F (1, 2) - sage: F._extended_root_configuration_indices() # optional - gap3 + sage: F._extended_root_configuration_indices() [0, 2, 3, 2, 1] sage: W = CoxeterGroup(['A',2]) @@ -250,12 +252,13 @@ def _root_configuration_indices(self): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1], w) # optional - gap3 - sage: F = SC([1,2]); F # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1], w) + sage: F = SC([1,2]); F (1, 2) - sage: F._root_configuration_indices() # optional - gap3 + sage: F._root_configuration_indices() [2, 3] sage: W = CoxeterGroup(['A',2]) @@ -289,12 +292,13 @@ def extended_root_configuration(self): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1],w) # optional - gap3 - sage: F = SC([1,2]); F # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1],w) + sage: F = SC([1,2]); F (1, 2) - sage: F.extended_root_configuration() # optional - gap3 + sage: F.extended_root_configuration() [(1, 0), (1, 1), (-1, 0), (1, 1), (0, 1)] sage: W = CoxeterGroup(['A',2]) @@ -323,12 +327,13 @@ def root_configuration(self): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1],w) # optional - gap3 - sage: F = SC([1,2]); F # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1],w) + sage: F = SC([1,2]); F (1, 2) - sage: F.root_configuration() # optional - gap3 + sage: F.root_configuration() [(1, 1), (-1, 0)] sage: W = CoxeterGroup(['A',2]) @@ -411,20 +416,22 @@ def is_vertex(self): EXAMPLES:: - sage: W = ReflectionGroup(['A',1]) # optional - gap3 - sage: w = W.from_reduced_word([1]) # optional - gap3 - sage: SC = SubwordComplex([1,1,1],w) # optional - gap3 - sage: F = SC([0,1]); F.is_vertex() # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',1]) + sage: w = W.from_reduced_word([1]) + sage: SC = SubwordComplex([1,1,1],w) + sage: F = SC([0,1]); F.is_vertex() True - sage: F = SC([0,2]); F.is_vertex() # optional - gap3 + sage: F = SC([0,2]); F.is_vertex() False - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1,2,1],w) # optional - gap3 - sage: F = SC([0,1,2,3]); F.is_vertex() # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1,2,1],w) + sage: F = SC([0,1,2,3]); F.is_vertex() True - sage: F = SC([0,1,2,6]); F.is_vertex() # optional - gap3 + sage: F = SC([0,1,2,6]); F.is_vertex() False sage: W = CoxeterGroup(['A',2]) @@ -452,10 +459,11 @@ def root_cone(self): EXAMPLES:: - sage: W = ReflectionGroup(['A',1]) # optional - gap3 - sage: w = W.from_reduced_word([1]) # optional - gap3 - sage: SC = SubwordComplex([1,1,1],w) # optional - gap3 - sage: F = SC([0,2]); F.root_cone() # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',1]) + sage: w = W.from_reduced_word([1]) + sage: SC = SubwordComplex([1,1,1],w) + sage: F = SC([0,2]); F.root_cone() 1-d cone in 1-d lattice N sage: W = CoxeterGroup(['A',1]) @@ -472,14 +480,15 @@ def upper_root_configuration(self): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1],w) # optional - gap3 - sage: F = SC([1,2]); F # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1],w) + sage: F = SC([1,2]); F (1, 2) - sage: F.root_configuration() # optional - gap3 + sage: F.root_configuration() [(1, 1), (-1, 0)] - sage: F.upper_root_configuration() # optional - gap3 + sage: F.upper_root_configuration() [(1, 0)] sage: W = CoxeterGroup(['A',2]) @@ -523,13 +532,14 @@ def extended_weight_configuration(self, coefficients=None): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1],w) # optional - gap3 - sage: F = SC([1,2]) # optional - gap3 - sage: F.extended_weight_configuration() # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1],w) + sage: F = SC([1,2]) + sage: F.extended_weight_configuration() [(2/3, 1/3), (1/3, 2/3), (-1/3, 1/3), (1/3, 2/3), (-1/3, 1/3)] - sage: F.extended_weight_configuration(coefficients=(1,2)) # optional - gap3 + sage: F.extended_weight_configuration(coefficients=(1,2)) [(2/3, 1/3), (2/3, 4/3), (-1/3, 1/3), (2/3, 4/3), (-1/3, 1/3)] sage: W = CoxeterGroup(['A',2]) @@ -578,12 +588,13 @@ def weight_configuration(self): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1],w) # optional - gap3 - sage: F = SC([1,2]); F # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1],w) + sage: F = SC([1,2]); F (1, 2) - sage: F.weight_configuration() # optional - gap3 + sage: F.weight_configuration() [(1/3, 2/3), (-1/3, 1/3)] sage: W = CoxeterGroup(['A',2]) @@ -609,14 +620,15 @@ def weight_cone(self): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1],w) # optional - gap3 - sage: F = SC([1,2]); F # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1],w) + sage: F = SC([1,2]); F (1, 2) - sage: WC = F.weight_cone(); WC # optional - gap3 + sage: WC = F.weight_cone(); WC 2-d cone in 2-d lattice N - sage: WC.rays() # optional - gap3 + sage: WC.rays() N( 1, 2), N(-1, 1) in 2-d lattice N @@ -649,16 +661,17 @@ def brick_vector(self, coefficients=None): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1],w) # optional - gap3 - sage: F = SC([1,2]); F # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1],w) + sage: F = SC([1,2]); F (1, 2) - sage: F.extended_weight_configuration() # optional - gap3 + sage: F.extended_weight_configuration() [(2/3, 1/3), (1/3, 2/3), (-1/3, 1/3), (1/3, 2/3), (-1/3, 1/3)] - sage: F.brick_vector() # optional - gap3 + sage: F.brick_vector() (2/3, 7/3) - sage: F.brick_vector(coefficients=[1,2]) # optional - gap3 + sage: F.brick_vector(coefficients=[1,2]) (4/3, 11/3) sage: W = CoxeterGroup(['A',2]) @@ -691,14 +704,15 @@ def flip(self, i, return_position=False): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1],w) # optional - gap3 - sage: F = SC([1,2]); F # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1],w) + sage: F = SC([1,2]); F (1, 2) - sage: F.flip(1) # optional - gap3 + sage: F.flip(1) (2, 3) - sage: F.flip(1, return_position=True) # optional - gap3 + sage: F.flip(1, return_position=True) ((2, 3), 3) sage: W = CoxeterGroup(['A',2]) @@ -752,32 +766,35 @@ def plot(self, list_colors=None, labels=[], thickness=3, fontsize=14, EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1],w) # optional - gap3 - sage: F = SC([1,2]); F.plot() # optional - gap3 sage.plot + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1],w) + sage: F = SC([1,2]); F.plot() # needs sage.plot Graphics object consisting of 26 graphics primitives sage: W = CoxeterGroup(['A',2]) sage: w = W.from_reduced_word([1,2,1]) sage: SC = SubwordComplex([1,2,1,2,1],w) - sage: F = SC([1,2]); F.plot() # optional - sage.plot + sage: F = SC([1,2]); F.plot() # needs sage.plot Graphics object consisting of 26 graphics primitives - sage: W = ReflectionGroup(['B',3]) # optional - gap3 - sage: c = W.from_reduced_word([1,2,3]) # optional - gap3 - sage: Q = c.reduced_word()*2 + W.w0.coxeter_sorting_word(c) # optional - gap3 - sage: SC = SubwordComplex(Q, W.w0) # optional - gap3 - sage: F = SC[15]; F.plot() # optional - gap3 sage.plot + sage: # optional - gap3 + sage: W = ReflectionGroup(['B',3]) + sage: c = W.from_reduced_word([1,2,3]) + sage: Q = c.reduced_word()*2 + W.w0.coxeter_sorting_word(c) + sage: SC = SubwordComplex(Q, W.w0) + sage: F = SC[15]; F.plot() # needs sage.plot Graphics object consisting of 53 graphics primitives TESTS:: - sage: W = ReflectionGroup(['D',4]) # optional - gap3 - sage: c = W.from_reduced_word([1,2,3,4]) # optional - gap3 - sage: Q = c.reduced_word() + W.w0.coxeter_sorting_word(c) # optional - gap3 - sage: SC = SubwordComplex(Q, W.w0) # optional - gap3 - sage: F = SC[1]; F.plot() # optional - gap3 sage.plot + sage: # optional - gap3 + sage: W = ReflectionGroup(['D',4]) + sage: c = W.from_reduced_word([1,2,3,4]) + sage: Q = c.reduced_word() + W.w0.coxeter_sorting_word(c) + sage: SC = SubwordComplex(Q, W.w0) + sage: F = SC[1]; F.plot() # needs sage.plot Traceback (most recent call last): ... ValueError: plotting is currently only implemented for irreducibles types A, B, and C. @@ -786,7 +803,7 @@ def plot(self, list_colors=None, labels=[], thickness=3, fontsize=14, sage: c = W.from_reduced_word([1,2,3,4]) sage: Q = c.reduced_word() + W.w0.coxeter_sorting_word(c) sage: SC = SubwordComplex(Q, W.w0) - sage: F = SC[1]; F.plot() # optional - sage.plot + sage: F = SC[1]; F.plot() # needs sage.plot Traceback (most recent call last): ... ValueError: plotting is currently only implemented for irreducibles types A, B, and C. @@ -971,10 +988,11 @@ def show(self, *kwds, **args): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1],w) # optional - gap3 - sage: F = SC([1,2]); F.show() # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1],w) + sage: F = SC([1,2]); F.show() """ return self.plot().show(*kwds, **args) @@ -1005,11 +1023,12 @@ class SubwordComplex(UniqueRepresentation, SimplicialComplex): :: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1], w); SC # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1], w); SC Subword complex of type ['A', 2] for Q = (1, 2, 1, 2, 1) and pi = [1, 2, 1] - sage: SC.facets() # optional - gap3 + sage: SC.facets() [(0, 1), (0, 4), (1, 2), (2, 3), (3, 4)] sage: W = CoxeterGroup(['A',2]) @@ -1023,11 +1042,12 @@ class SubwordComplex(UniqueRepresentation, SimplicialComplex): TESTS:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC1 = SubwordComplex([1,2,1,2,1], w) # optional - gap3 - sage: SC2 = SubwordComplex([1,2,1,2,1], w) # optional - gap3 - sage: SC1 == SC2 # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC1 = SubwordComplex([1,2,1,2,1], w) + sage: SC2 = SubwordComplex([1,2,1,2,1], w) + sage: SC1 == SC2 True sage: W = CoxeterGroup(['A',2]) @@ -1047,10 +1067,11 @@ def __classcall__(cls, Q, w, algorithm="inductive"): TESTS:: - sage: W = ReflectionGroup(['B',2]) # optional - gap3 - sage: S = SubwordComplex((1,2)*3,W.w0) # optional - gap3 - sage: T = SubwordComplex([1,2]*3,W.w0) # optional - gap3 - sage: S is T # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['B',2]) + sage: S = SubwordComplex((1,2)*3,W.w0) + sage: T = SubwordComplex([1,2]*3,W.w0) + sage: S is T True sage: W = CoxeterGroup(['B',2]) @@ -1077,11 +1098,12 @@ def __init__(self, Q, w, algorithm="inductive"): EXAMPLES:: - sage: W = ReflectionGroup(['A',3]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,3,1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,3,1,2,3,1,2,1], w); SC # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',3]) + sage: w = W.from_reduced_word([1,2,3,1,2,1]) + sage: SC = SubwordComplex([1,2,3,1,2,3,1,2,1], w); SC Subword complex of type ['A', 3] for Q = (1, 2, 3, 1, 2, 3, 1, 2, 1) and pi = [1, 2, 1, 3, 2, 1] - sage: len(SC) # optional - gap3 + sage: len(SC) 14 sage: W = CoxeterGroup(['A',3]) @@ -1095,10 +1117,11 @@ def __init__(self, Q, w, algorithm="inductive"): Check for methods from the enumerated sets category:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1], w) # optional - gap3 - sage: list(SC) # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1], w) + sage: list(SC) [(0, 1), (0, 4), (1, 2), (2, 3), (3, 4)] sage: W = CoxeterGroup(['A',2]) @@ -1208,20 +1231,21 @@ def __contains__(self, F): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1], w) # optional - gap3 - sage: SC.facets() # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1], w) + sage: SC.facets() [(0, 1), (0, 4), (1, 2), (2, 3), (3, 4)] - sage: [0,1] in SC # optional - gap3 + sage: [0,1] in SC True - sage: [0,2] in SC # optional - gap3 + sage: [0,2] in SC False - sage: [0,1,5] in SC # optional - gap3 + sage: [0,1,5] in SC False - sage: [0] in SC # optional - gap3 + sage: [0] in SC False - sage: ['a','b'] in SC # optional - gap3 + sage: ['a','b'] in SC False sage: W = CoxeterGroup(['A',2]) @@ -1255,10 +1279,11 @@ def group(self): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1], w) # optional - gap3 - sage: SC.group() # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1], w) + sage: SC.group() Irreducible real reflection group of rank 2 and type A2 sage: W = CoxeterGroup(['A',2]) @@ -1277,10 +1302,11 @@ def cartan_type(self): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1], w) # optional - gap3 - sage: SC.cartan_type() # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1], w) + sage: SC.cartan_type() ['A', 2] sage: W = CoxeterGroup(['A',2]) @@ -1300,10 +1326,11 @@ def word(self): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1], w) # optional - gap3 - sage: SC.word() # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1], w) + sage: SC.word() (1, 2, 1, 2, 1) sage: W = CoxeterGroup(['A',2]) @@ -1320,10 +1347,11 @@ def pi(self): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1], w) # optional - gap3 - sage: SC.pi().reduced_word() # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1], w) + sage: SC.pi().reduced_word() [1, 2, 1] sage: W = CoxeterGroup(['A',2]) @@ -1340,10 +1368,11 @@ def facets(self): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1], w) # optional - gap3 - sage: SC.facets() # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1], w) + sage: SC.facets() [(0, 1), (0, 4), (1, 2), (2, 3), (3, 4)] sage: W = CoxeterGroup(['A',2]) @@ -1363,10 +1392,11 @@ def __iter__(self): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1], w) # optional - gap3 - sage: for I in SC: print(I) # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1], w) + sage: for I in SC: print(I) (0, 1) (0, 4) (1, 2) @@ -1393,12 +1423,13 @@ def greedy_facet(self, side="positive"): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1], w) # optional - gap3 - sage: SC.greedy_facet(side="positive") # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1], w) + sage: SC.greedy_facet(side="positive") (0, 1) - sage: SC.greedy_facet(side="negative") # optional - gap3 + sage: SC.greedy_facet(side="negative") (3, 4) sage: W = CoxeterGroup(['A',2]) @@ -1420,10 +1451,11 @@ def is_sphere(self): EXAMPLES:: - sage: W = ReflectionGroup(['A',3]) # optional - gap3 - sage: w = W.from_reduced_word([2,3,2]) # optional - gap3 - sage: SC = SubwordComplex([3,2,3,2,3], w) # optional - gap3 - sage: SC.is_sphere() # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',3]) + sage: w = W.from_reduced_word([2,3,2]) + sage: SC = SubwordComplex([3,2,3,2,3], w) + sage: SC.is_sphere() True sage: SC = SubwordComplex([3,2,1,3,2,3], w) # optional - gap3 @@ -1448,10 +1480,11 @@ def is_ball(self): EXAMPLES:: - sage: W = ReflectionGroup(['A',3]) # optional - gap3 - sage: w = W.from_reduced_word([2,3,2]) # optional - gap3 - sage: SC = SubwordComplex([3,2,3,2,3], w) # optional - gap3 - sage: SC.is_ball() # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',3]) + sage: w = W.from_reduced_word([2,3,2]) + sage: SC = SubwordComplex([3,2,3,2,3], w) + sage: SC.is_ball() False sage: SC = SubwordComplex([3,2,1,3,2,3], w) # optional - gap3 @@ -1472,10 +1505,11 @@ def is_pure(self): EXAMPLES:: - sage: W = ReflectionGroup(['A',3]) # optional - gap3 - sage: w = W.from_reduced_word([2,3,2]) # optional - gap3 - sage: SC = SubwordComplex([3,2,3,2,3], w) # optional - gap3 - sage: SC.is_pure() # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',3]) + sage: w = W.from_reduced_word([2,3,2]) + sage: SC = SubwordComplex([3,2,3,2,3], w) + sage: SC.is_pure() True sage: W = CoxeterGroup(['A',3]) @@ -1544,10 +1578,11 @@ def is_double_root_free(self): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1], w) # optional - gap3 - sage: SC.is_double_root_free() # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1], w) + sage: SC.is_double_root_free() True sage: SC = SubwordComplex([1,1,2,2,1,1], w) # optional - gap3 @@ -1583,11 +1618,12 @@ def kappa_preimages(self): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1], w) # optional - gap3 - sage: kappa = SC.kappa_preimages() # optional - gap3 - sage: for F in SC: print("{} {}".format(F, [w.reduced_word() for w in kappa[F]])) # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1], w) + sage: kappa = SC.kappa_preimages() + sage: for F in SC: print("{} {}".format(F, [w.reduced_word() for w in kappa[F]])) (0, 1) [[]] (0, 4) [[2], [2, 1]] (1, 2) [[1]] @@ -1621,10 +1657,11 @@ def brick_fan(self): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1], w) # optional - gap3 - sage: SC.brick_fan() # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1], w) + sage: SC.brick_fan() Rational polyhedral fan in 2-d lattice N sage: W = CoxeterGroup(['A',2]) @@ -1653,11 +1690,12 @@ def brick_vectors(self, coefficients=None): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1], W.w0) # optional - gap3 - sage: SC.brick_vectors() # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: SC = SubwordComplex([1,2,1,2,1], W.w0) + sage: SC.brick_vectors() [(5/3, 7/3), (5/3, 1/3), (2/3, 7/3), (-1/3, 4/3), (-1/3, 1/3)] - sage: SC.brick_vectors(coefficients=(1,2)) # optional - gap3 + sage: SC.brick_vectors(coefficients=(1,2)) [(7/3, 11/3), (7/3, 2/3), (4/3, 11/3), (-2/3, 5/3), (-2/3, 2/3)] sage: W = CoxeterGroup(['A',2]) @@ -1733,10 +1771,11 @@ def brick_polytope(self, coefficients=None): sage: X = SC.brick_polytope(); X A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 5 vertices - sage: W = ReflectionGroup(['H',3]) # optional - gap3 - sage: c = W.index_set(); Q = c + tuple(W.w0.coxeter_sorting_word(c)) # optional - gap3 - sage: SC = SubwordComplex(Q,W.w0) # optional - gap3 - sage: SC.brick_polytope() # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['H',3]) + sage: c = W.index_set(); Q = c + tuple(W.w0.coxeter_sorting_word(c)) + sage: SC = SubwordComplex(Q,W.w0) + sage: SC.brick_polytope() doctest:...: RuntimeWarning: the polytope is built with rational vertices A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 32 vertices @@ -1870,10 +1909,11 @@ def interval(self, I, J): EXAMPLES:: - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1], W.w0) # optional - gap3 - sage: F = SC([1,2]) # optional - gap3 - sage: SC.interval(F, F) # optional - gap3 + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: SC = SubwordComplex([1,2,1,2,1], W.w0) + sage: F = SC([1,2]) + sage: SC.interval(F, F) {(1, 2)} sage: W = CoxeterGroup(['A',2]) @@ -1921,13 +1961,13 @@ def _greedy_facet(Q, w, side="negative", n=None, pos=0, l=None, elems=[]): INPUT: - - `Q` -- a word - - `w` -- an element in the Coxeter group - - side -- optional, either 'negative' (default) or 'positive' - - n -- an integer (optional, defaults to the length of Q) - - pos -- an integer (optional, default 0) - - l -- an integer (optional, defaults to the length of w) - - elems -- a list (optional) + - ``Q`` -- a word + - ``w`` -- an element in the Coxeter group + - ``side`` -- optional, either ``'negative'`` (default) or ``'positive'`` + - ``n`` -- an integer (optional, defaults to the length of `Q`) + - ``pos`` -- an integer (optional, default 0) + - ``l`` -- an integer (optional, defaults to the length of `w`) + - ``elems`` -- a list (optional) OUTPUT: @@ -1936,10 +1976,12 @@ def _greedy_facet(Q, w, side="negative", n=None, pos=0, l=None, elems=[]): EXAMPLES:: sage: from sage.combinat.subword_complex import _greedy_facet - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: Q = [1,2,1,2,1] # optional - gap3 - sage: w = W.from_reduced_word([1, 2, 1]) # optional - gap3 - sage: _greedy_facet(Q, w) # optional - gap3 + + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: Q = [1,2,1,2,1] + sage: w = W.from_reduced_word([1, 2, 1]) + sage: _greedy_facet(Q, w) {3, 4} sage: W = CoxeterGroup(['A',2]) @@ -1990,9 +2032,9 @@ def _extended_root_configuration_indices(W, Q, F): INPUT: - - `W` -- a Coxeter group - - `Q` -- a word representing an element of `W` - - `F` -- a facet of the subword complex + - ``W`` -- a Coxeter group + - ``Q`` -- a word representing an element of `W` + - ``F`` -- a facet of the subword complex OUTPUT: @@ -2001,12 +2043,14 @@ def _extended_root_configuration_indices(W, Q, F): EXAMPLES:: sage: from sage.combinat.subword_complex import _extended_root_configuration_indices - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: Q = [1,2,1,2,1] # optional - gap3 - sage: SC = SubwordComplex(Q, w) # optional - gap3 - sage: F = SC([1,2]) # optional - gap3 - sage: _extended_root_configuration_indices(W, Q, F) # optional - gap3 + + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: Q = [1,2,1,2,1] + sage: SC = SubwordComplex(Q, w) + sage: F = SC([1,2]) + sage: _extended_root_configuration_indices(W, Q, F) [0, 2, 3, 2, 1] sage: W = CoxeterGroup(['A',2]) @@ -2031,8 +2075,8 @@ def _greedy_flip_algorithm(Q, w): """ INPUT: - - Q -- a word in a Coxeter group W - - w -- an element of W + - ``Q`` -- a word in a Coxeter group `W` + - ``w`` -- an element of `W` OUTPUT: @@ -2041,10 +2085,12 @@ def _greedy_flip_algorithm(Q, w): EXAMPLES:: sage: from sage.combinat.subword_complex import _greedy_flip_algorithm - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: Q = [1,2,1,2,1] # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: _greedy_flip_algorithm(Q, w) # optional - gap3 + + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: Q = [1,2,1,2,1] + sage: w = W.from_reduced_word([1,2,1]) + sage: _greedy_flip_algorithm(Q, w) ([{0, 1}, [1, 2], [2, 3], [3, 4], [0, 4]], [[0, 1, 0, 2, 1], [0, 2, 3, 2, 1], diff --git a/src/sage/combinat/subword_complex_c.pyx b/src/sage/combinat/subword_complex_c.pyx index ec85790c133..31a985f8675 100644 --- a/src/sage/combinat/subword_complex_c.pyx +++ b/src/sage/combinat/subword_complex_c.pyx @@ -7,26 +7,28 @@ cpdef int _flip_c(W, set positions, list extended_root_conf_indices, INPUT: - - W -- a Coxeter group - - positions -- the positions of the elements of the facet - - extended_root_conf_indices -- also attached to the facet ? - - i -- the position where to flip - - side -- optional, can be 'positive', 'negative' or 'both' (default) + - ``W`` -- a Coxeter group + - ``positions`` -- the positions of the elements of the facet + - ``extended_root_conf_indices`` -- also attached to the facet ? + - ``i`` -- the position where to flip + - ``side`` -- optional, can be ``'positive'``, ``'negative'`` or ``'both'`` (default) OUTPUT: - the new position j that has replaced i + the new position `j` that has replaced `i` EXAMPLES:: sage: from sage.combinat.subword_complex_c import _flip_c - sage: W = ReflectionGroup(['A',2]) # optional - gap3 - sage: w = W.from_reduced_word([1,2,1]) # optional - gap3 - sage: SC = SubwordComplex([1,2,1,2,1], w) # optional - gap3 - sage: F = SC([0, 1]) # optional - gap3 - sage: _flip_c(W, set([0,1]), F._extended_root_configuration_indices(), 1) # optional - gap3 + + sage: # optional - gap3 + sage: W = ReflectionGroup(['A',2]) + sage: w = W.from_reduced_word([1,2,1]) + sage: SC = SubwordComplex([1,2,1,2,1], w) + sage: F = SC([0, 1]) + sage: _flip_c(W, set([0,1]), F._extended_root_configuration_indices(), 1) 4 - sage: _flip_c(W, set([0,1]), F._extended_root_configuration_indices(), 0) # optional - gap3 + sage: _flip_c(W, set([0,1]), F._extended_root_configuration_indices(), 0) 3 sage: W = CoxeterGroup(['A',2]) @@ -60,6 +62,7 @@ cpdef int _flip_c(W, set positions, list extended_root_conf_indices, extended_root_conf_indices[k] = t.action_on_root_indices(extended_root_conf_indices[k], side="left") return j + cpdef list _construct_facets_c(tuple Q, w, int n=-1, int pos=0, int l=-1) noexcept: r""" Return the list of facets of the subword complex associated to the diff --git a/src/sage/combinat/symmetric_group_algebra.py b/src/sage/combinat/symmetric_group_algebra.py index 3e8b27e9210..84b29a770b2 100644 --- a/src/sage/combinat/symmetric_group_algebra.py +++ b/src/sage/combinat/symmetric_group_algebra.py @@ -25,9 +25,12 @@ from sage.arith.misc import factorial from sage.matrix.constructor import matrix from sage.modules.free_module_element import vector -from sage.groups.perm_gps.permgroup_element import PermutationGroupElement +from sage.misc.lazy_import import lazy_import from sage.misc.persist import register_unpickle_override +lazy_import('sage.groups.perm_gps.permgroup_element', 'PermutationGroupElement') + + # TODO: Remove this function and replace it with the class # TODO: Create parents for other bases (such as the seminormal basis) diff --git a/src/sage/combinat/symmetric_group_representations.py b/src/sage/combinat/symmetric_group_representations.py index a684702119c..7c975919a75 100644 --- a/src/sage/combinat/symmetric_group_representations.py +++ b/src/sage/combinat/symmetric_group_representations.py @@ -76,28 +76,29 @@ def SymmetricGroupRepresentation(partition, implementation="specht", :: - sage: orth = SymmetricGroupRepresentation([2,1], "orthogonal"); orth # optional - sage.symbolic + sage: orth = SymmetricGroupRepresentation([2,1], "orthogonal"); orth # needs sage.symbolic Orthogonal representation of the symmetric group corresponding to [2, 1] - sage: all(a*a.transpose() == a.parent().identity_matrix() for a in orth) # optional - sage.symbolic + sage: all(a*a.transpose() == a.parent().identity_matrix() for a in orth) # needs sage.symbolic True :: - sage: orth = SymmetricGroupRepresentation([3,2], "orthogonal"); orth # optional - sage.symbolic + sage: # needs sage.symbolic + sage: orth = SymmetricGroupRepresentation([3,2], "orthogonal"); orth Orthogonal representation of the symmetric group corresponding to [3, 2] - sage: orth([2,1,3,4,5]) # optional - sage.symbolic + sage: orth([2,1,3,4,5]) [ 1 0 0 0 0] [ 0 1 0 0 0] [ 0 0 -1 0 0] [ 0 0 0 1 0] [ 0 0 0 0 -1] - sage: orth([1,3,2,4,5]) # optional - sage.symbolic + sage: orth([1,3,2,4,5]) [ 1 0 0 0 0] [ 0 -1/2 1/2*sqrt(3) 0 0] [ 0 1/2*sqrt(3) 1/2 0 0] [ 0 0 0 -1/2 1/2*sqrt(3)] [ 0 0 0 1/2*sqrt(3) 1/2] - sage: orth([1,2,4,3,5]) # optional - sage.symbolic + sage: orth([1,2,4,3,5]) [ -1/3 2/3*sqrt(2) 0 0 0] [2/3*sqrt(2) 1/3 0 0 0] [ 0 0 1 0 0] @@ -201,13 +202,13 @@ def SymmetricGroupRepresentations(n, implementation="specht", ring=None, :: - sage: orth = SymmetricGroupRepresentations(3, "orthogonal"); orth # optional - sage.symbolic + sage: orth = SymmetricGroupRepresentations(3, "orthogonal"); orth # needs sage.symbolic Orthogonal representations of the symmetric group of order 3! over Symbolic Ring - sage: orth.list() # optional - sage.symbolic + sage: orth.list() # needs sage.symbolic [Orthogonal representation of the symmetric group corresponding to [3], Orthogonal representation of the symmetric group corresponding to [2, 1], Orthogonal representation of the symmetric group corresponding to [1, 1, 1]] - sage: orth([2,1])([1,2,3]) # optional - sage.symbolic + sage: orth([2,1])([1,2,3]) # needs sage.symbolic [1 0] [0 1] @@ -517,8 +518,8 @@ def __iter__(self): EXAMPLES:: - sage: orth = SymmetricGroupRepresentations(3, "orthogonal") # optional - sage.symbolic - sage: for x in orth: print(x) # optional - sage.symbolic + sage: orth = SymmetricGroupRepresentations(3, "orthogonal") # needs sage.symbolic + sage: for x in orth: print(x) # needs sage.symbolic Orthogonal representation of the symmetric group corresponding to [3] Orthogonal representation of the symmetric group corresponding to [2, 1] Orthogonal representation of the symmetric group corresponding to [1, 1, 1] @@ -541,8 +542,8 @@ def _yang_baxter_graph(self): EXAMPLES:: - sage: orth = SymmetricGroupRepresentation([3,2], "orthogonal") # optional - sage.symbolic - sage: orth._yang_baxter_graph # optional - sage.symbolic + sage: orth = SymmetricGroupRepresentation([3,2], "orthogonal") # needs sage.symbolic + sage: orth._yang_baxter_graph # needs sage.symbolic Yang-Baxter graph of [3, 2], with top vertex (0, -1, 2, 1, 0) """ Y = YangBaxterGraph_partition(self._partition) @@ -566,8 +567,8 @@ def _tableau_dict(self): EXAMPLES:: - sage: orth = SymmetricGroupRepresentation([3,2], "orthogonal") # optional - sage.symbolic - sage: orth._tableau_dict # optional - sage.symbolic + sage: orth = SymmetricGroupRepresentation([3,2], "orthogonal") # needs sage.symbolic + sage: orth._tableau_dict # needs sage.symbolic {(0, -1, 2, 1, 0): [[1, 2, 3], [4, 5]], (0, 2, -1, 1, 0): [[1, 2, 4], [3, 5]], (0, 2, 1, -1, 0): [[1, 3, 4], [2, 5]], @@ -592,8 +593,8 @@ def _word_dict(self): EXAMPLES:: - sage: orth = SymmetricGroupRepresentation([3,2], "orthogonal") # optional - sage.symbolic - sage: orth._word_dict # optional - sage.symbolic + sage: orth = SymmetricGroupRepresentation([3,2], "orthogonal") # needs sage.symbolic + sage: orth._word_dict # needs sage.symbolic {(0, -1, 2, 1, 0): (4, 5, 1, 2, 3), (0, 2, -1, 1, 0): (3, 5, 1, 2, 4), (0, 2, 1, -1, 0): (2, 5, 1, 3, 4), @@ -611,11 +612,11 @@ def representation_matrix_for_simple_transposition(self, i): EXAMPLES:: - sage: orth = SymmetricGroupRepresentation([2,1], "orthogonal") # optional - sage.symbolic - sage: orth.representation_matrix_for_simple_transposition(1) # optional - sage.symbolic + sage: orth = SymmetricGroupRepresentation([2,1], "orthogonal") # needs sage.symbolic + sage: orth.representation_matrix_for_simple_transposition(1) # needs sage.symbolic [ 1 0] [ 0 -1] - sage: orth.representation_matrix_for_simple_transposition(2) # optional - sage.symbolic + sage: orth.representation_matrix_for_simple_transposition(2) # needs sage.symbolic [ -1/2 1/2*sqrt(3)] [1/2*sqrt(3) 1/2] @@ -664,11 +665,11 @@ def _representation_matrix_uncached(self, permutation): EXAMPLES:: - sage: orth = SymmetricGroupRepresentation([2,1], "orthogonal") # optional - sage.symbolic - sage: orth._representation_matrix_uncached(Permutation([2,1,3])) # optional - sage.symbolic + sage: orth = SymmetricGroupRepresentation([2,1], "orthogonal") # needs sage.symbolic + sage: orth._representation_matrix_uncached(Permutation([2,1,3])) # needs sage.symbolic [ 1 0] [ 0 -1] - sage: orth._representation_matrix_uncached(Permutation([1,3,2])) # optional - sage.symbolic + sage: orth._representation_matrix_uncached(Permutation([1,3,2])) # needs sage.symbolic [ -1/2 1/2*sqrt(3)] [1/2*sqrt(3) 1/2] @@ -697,11 +698,11 @@ def representation_matrix(self, permutation): EXAMPLES:: - sage: orth = SymmetricGroupRepresentation([2,1], "orthogonal") # optional - sage.symbolic - sage: orth.representation_matrix(Permutation([2,1,3])) # optional - sage.symbolic + sage: orth = SymmetricGroupRepresentation([2,1], "orthogonal") # needs sage.symbolic + sage: orth.representation_matrix(Permutation([2,1,3])) # needs sage.symbolic [ 1 0] [ 0 -1] - sage: orth.representation_matrix(Permutation([1,3,2])) # optional - sage.symbolic + sage: orth.representation_matrix(Permutation([1,3,2])) # needs sage.symbolic [ -1/2 1/2*sqrt(3)] [1/2*sqrt(3) 1/2] @@ -780,7 +781,7 @@ def _repr_(self): EXAMPLES:: - sage: SymmetricGroupRepresentation([2,1], "orthogonal") # optional - sage.symbolic + sage: SymmetricGroupRepresentation([2,1], "orthogonal") # needs sage.symbolic Orthogonal representation of the symmetric group corresponding to [2, 1] """ return "Orthogonal representation of the symmetric group corresponding to {}".format(self._partition) @@ -797,8 +798,8 @@ def _2x2_matrix_entries(self, beta): EXAMPLES:: - sage: orth = SymmetricGroupRepresentation([2,1], "orthogonal") # optional - sage.symbolic - sage: orth._2x2_matrix_entries(1/2) # optional - sage.symbolic + sage: orth = SymmetricGroupRepresentation([2,1], "orthogonal") # needs sage.symbolic + sage: orth._2x2_matrix_entries(1/2) # needs sage.symbolic (-1/2, 1/2*sqrt(3), 1/2*sqrt(3), 1/2) """ return (-beta, sqrt(1 - beta**2), sqrt(1 - beta**2), beta) @@ -816,7 +817,7 @@ def _repr_(self): EXAMPLES:: sage: from sage.combinat.symmetric_group_representations import YoungRepresentations_Orthogonal - sage: YoungRepresentations_Orthogonal(3) # optional - sage.symbolic + sage: YoungRepresentations_Orthogonal(3) # needs sage.symbolic Orthogonal representations of the symmetric group of order 3! over Symbolic Ring """ return "Orthogonal representations of the symmetric group of order %s! over %s" % (self._n, self._ring) diff --git a/src/sage/combinat/tableau.py b/src/sage/combinat/tableau.py index f7e58a15c20..cf44091d16d 100644 --- a/src/sage/combinat/tableau.py +++ b/src/sage/combinat/tableau.py @@ -1006,15 +1006,15 @@ def plot(self, descents=False): EXAMPLES:: sage: t = Tableau([[1,2,4],[3]]) - sage: t.plot() # optional - sage.plot + sage: t.plot() # needs sage.plot Graphics object consisting of 11 graphics primitives - sage: t.plot(descents=True) # optional - sage.plot + sage: t.plot(descents=True) # needs sage.plot Graphics object consisting of 12 graphics primitives sage: t = Tableau([[2,2,4],[3]]) - sage: t.plot() # optional - sage.plot + sage: t.plot() # needs sage.plot Graphics object consisting of 11 graphics primitives - sage: t.plot(descents=True) # optional - sage.plot + sage: t.plot(descents=True) # needs sage.plot Traceback (most recent call last): ... ValueError: the tableau must be standard for 'descents=True' @@ -1276,19 +1276,19 @@ def to_sign_matrix(self, max_entry=None): EXAMPLES:: sage: t = SemistandardTableau([[1,1,1,2,4],[3,3,4],[4,5],[6,6]]) - sage: t.to_sign_matrix(6) # optional - sage.modules + sage: t.to_sign_matrix(6) # needs sage.modules [ 0 0 0 1 0 0] [ 0 1 0 -1 0 0] [ 1 -1 0 1 0 0] [ 0 0 1 -1 1 1] [ 0 0 0 1 -1 0] sage: t = Tableau([[1,2,4],[3,5]]) - sage: t.to_sign_matrix(7) # optional - sage.modules + sage: t.to_sign_matrix(7) # needs sage.modules [ 0 0 0 1 0 0 0] [ 0 1 0 -1 1 0 0] [ 1 -1 1 0 -1 0 0] sage: t = Tableau([(4,5,4,3),(2,1,3)]) - sage: t.to_sign_matrix(5) # optional - sage.modules + sage: t.to_sign_matrix(5) # needs sage.modules [ 0 0 1 0 0] [ 0 0 0 1 0] [ 1 0 -1 -1 1] @@ -1558,24 +1558,29 @@ def bender_knuth_involution(self, k, rows=None, check=True): The Bender--Knuth involution is an involution:: sage: T = SemistandardTableaux(shape=[3,1,1], max_entry=4) - sage: all(all(t.bender_knuth_involution(k).bender_knuth_involution(k) == t for k in range(1,5)) for t in T) + sage: all(t.bender_knuth_involution(k).bender_knuth_involution(k) == t # needs sage.modules + ....: for k in range(1, 5) for t in T) True The same holds for the single switches:: - sage: all(all(t.bender_knuth_involution(k, j).bender_knuth_involution(k, j) == t for k in range(1,5) for j in range(1, 5)) for t in T) + sage: all(t.bender_knuth_involution(k, j).bender_knuth_involution(k, j) == t # needs sage.modules + ....: for k in range(1, 5) for j in range(1, 5) for t in T) True Locality of the Bender--Knuth involutions:: - sage: all(all(t.bender_knuth_involution(k).bender_knuth_involution(l) == t.bender_knuth_involution(l).bender_knuth_involution(k) for k in range(1,5) for l in range(1,5) if abs(k - l) > 1) for t in T) + sage: all(t.bender_knuth_involution(k).bender_knuth_involution(l) # needs sage.modules + ....: == t.bender_knuth_involution(l).bender_knuth_involution(k) + ....: for k in range(1, 5) for l in range(1, 5) if abs(k - l) > 1 + ....: for t in T) True Berenstein and Kirillov [KB1995]_ have shown that `(s_1 s_2)^6 = id` (for tableaux of straight shape):: sage: p = lambda t, k: t.bender_knuth_involution(k).bender_knuth_involution(k + 1) - sage: all(p(p(p(p(p(p(t,1),1),1),1),1),1) == t for t in T) + sage: all(p(p(p(p(p(p(t,1),1),1),1),1),1) == t for t in T) # needs sage.modules True However, `(s_2 s_3)^6 = id` is false:: @@ -1687,7 +1692,7 @@ def weight(self): sage: by_word(t) == t.weight() True sage: SST = SemistandardTableaux(shape=[3,1,1]) - sage: all(by_word(t) == t.weight() for t in SST) + sage: all(by_word(t) == t.weight() for t in SST) # needs sage.modules True """ if len(self) == 0: @@ -2943,26 +2948,27 @@ def row_stabilizer(self): EXAMPLES:: - sage: rs = Tableau([[1,2,3],[4,5]]).row_stabilizer() # optional - sage.groups - sage: rs.order() == factorial(3)*factorial(2) # optional - sage.groups + sage: # needs sage.groups + sage: rs = Tableau([[1,2,3],[4,5]]).row_stabilizer() + sage: rs.order() == factorial(3)*factorial(2) True - sage: PermutationGroupElement([(1,3,2),(4,5)]) in rs # optional - sage.groups + sage: PermutationGroupElement([(1,3,2),(4,5)]) in rs True - sage: PermutationGroupElement([(1,4)]) in rs # optional - sage.groups + sage: PermutationGroupElement([(1,4)]) in rs False - sage: rs = Tableau([[1, 2],[3]]).row_stabilizer() # optional - sage.groups - sage: PermutationGroupElement([(1,2),(3,)]) in rs # optional - sage.groups + sage: rs = Tableau([[1, 2],[3]]).row_stabilizer() + sage: PermutationGroupElement([(1,2),(3,)]) in rs True - sage: rs.one().domain() # optional - sage.groups + sage: rs.one().domain() [1, 2, 3] - sage: rs = Tableau([[1],[2],[3]]).row_stabilizer() # optional - sage.groups - sage: rs.order() # optional - sage.groups + sage: rs = Tableau([[1],[2],[3]]).row_stabilizer() + sage: rs.order() 1 - sage: rs = Tableau([[2,4,5],[1,3]]).row_stabilizer() # optional - sage.groups - sage: rs.order() # optional - sage.groups + sage: rs = Tableau([[2,4,5],[1,3]]).row_stabilizer() + sage: rs.order() 12 - sage: rs = Tableau([]).row_stabilizer() # optional - sage.groups - sage: rs.order() # optional - sage.groups + sage: rs = Tableau([]).row_stabilizer() + sage: rs.order() 1 """ # Ensure that the permutations involve all elements of the @@ -2984,12 +2990,13 @@ def column_stabilizer(self): EXAMPLES:: - sage: cs = Tableau([[1,2,3],[4,5]]).column_stabilizer() # optional - sage.groups - sage: cs.order() == factorial(2)*factorial(2) # optional - sage.groups + sage: # needs sage.groups + sage: cs = Tableau([[1,2,3],[4,5]]).column_stabilizer() + sage: cs.order() == factorial(2)*factorial(2) True - sage: PermutationGroupElement([(1,3,2),(4,5)]) in cs # optional - sage.groups + sage: PermutationGroupElement([(1,3,2),(4,5)]) in cs False - sage: PermutationGroupElement([(1,4)]) in cs # optional - sage.groups + sage: PermutationGroupElement([(1,4)]) in cs True """ return self.conjugate().row_stabilizer() @@ -3046,7 +3053,7 @@ def last_letter_lequal(self, tab2): sage: st = StandardTableaux([3,2]) sage: f = lambda b: 1 if b else 0 - sage: matrix([[f(t1.last_letter_lequal(t2)) for t2 in st] for t1 in st]) # optional - sage.modules + sage: matrix([[f(t1.last_letter_lequal(t2)) for t2 in st] for t1 in st]) # needs sage.modules [1 1 1 1 1] [0 1 1 1 1] [0 0 1 1 1] @@ -3807,9 +3814,9 @@ def _segments(self): sage: sorted(t._segments().items()) [((0, 2), 2), ((0, 3), 3), ((0, 5), 4), ((1, 3), 1), ((1, 5), 2), ((2, 4), 1)] - sage: B = crystals.Tableaux("A4", shape=[4,3,2,1]) # optional - sage.modules - sage: t = B[31].to_tableau() # optional - sage.modules - sage: sorted(t._segments().items()) # optional - sage.modules + sage: B = crystals.Tableaux("A4", shape=[4,3,2,1]) # needs sage.modules + sage: t = B[31].to_tableau() # needs sage.modules + sage: sorted(t._segments().items()) # needs sage.modules [((0, 5), 3), ((1, 4), 2), ((2, 4), 1)] """ segments = {} @@ -3839,9 +3846,9 @@ def seg(self): sage: t.seg() 6 - sage: B = crystals.Tableaux("A4", shape=[4,3,2,1]) # optional - sage.modules - sage: t = B[31].to_tableau() # optional - sage.modules - sage: t.seg() # optional - sage.modules + sage: B = crystals.Tableaux("A4", shape=[4,3,2,1]) # needs sage.modules + sage: t = B[31].to_tableau() # needs sage.modules + sage: t.seg() # needs sage.modules 3 """ return len(self._segments()) @@ -3867,9 +3874,9 @@ def flush(self): sage: t.flush() 3 - sage: B = crystals.Tableaux("A4", shape=[4,3,2,1]) # optional - sage.modules - sage: t = B[32].to_tableau() # optional - sage.modules - sage: t.flush() # optional - sage.modules + sage: B = crystals.Tableaux("A4", shape=[4,3,2,1]) # needs sage.modules + sage: t = B[32].to_tableau() # needs sage.modules + sage: t.flush() # needs sage.modules 4 """ for i in range(len(self)-1): @@ -3992,11 +3999,11 @@ def residue_sequence(self, e, multicharge=(0,)): EXAMPLES:: - sage: StandardTableauTuple([[1,2],[3,4]]).residue_sequence(2) # optional - sage.groups + sage: StandardTableauTuple([[1,2],[3,4]]).residue_sequence(2) # needs sage.groups 2-residue sequence (0,1,1,0) with multicharge (0) - sage: StandardTableauTuple([[1,2],[3,4]]).residue_sequence(3) # optional - sage.groups + sage: StandardTableauTuple([[1,2],[3,4]]).residue_sequence(3) # needs sage.groups 3-residue sequence (0,1,2,0) with multicharge (0) - sage: StandardTableauTuple([[1,2],[3,4]]).residue_sequence(4) # optional - sage.groups + sage: StandardTableauTuple([[1,2],[3,4]]).residue_sequence(4) # needs sage.groups 4-residue sequence (0,1,3,0) with multicharge (0) """ res = [0] * self.size() @@ -4030,9 +4037,9 @@ def degree(self, e, multicharge=(0,)): EXAMPLES:: - sage: StandardTableau([[1,2,5],[3,4]]).degree(3) # optional - sage.groups + sage: StandardTableau([[1,2,5],[3,4]]).degree(3) # needs sage.groups 0 - sage: StandardTableau([[1,2,5],[3,4]]).degree(4) # optional - sage.groups + sage: StandardTableau([[1,2,5],[3,4]]).degree(4) # needs sage.groups 1 """ n = self.size() @@ -4075,11 +4082,11 @@ def codegree(self, e, multicharge=(0,)): EXAMPLES:: - sage: StandardTableau([[1,3,5],[2,4]]).codegree(3) # optional - sage.groups + sage: StandardTableau([[1,3,5],[2,4]]).codegree(3) # needs sage.groups 0 - sage: StandardTableau([[1,2,5],[3,4]]).codegree(3) # optional - sage.groups + sage: StandardTableau([[1,2,5],[3,4]]).codegree(3) # needs sage.groups 1 - sage: StandardTableau([[1,2,5],[3,4]]).codegree(4) # optional - sage.groups + sage: StandardTableau([[1,2,5],[3,4]]).codegree(4) # needs sage.groups 0 """ if not self: # the trivial case @@ -5874,7 +5881,7 @@ class SemistandardTableaux(Tableaux): sage: SST = SemistandardTableaux([2,1]); SST Semistandard tableaux of shape [2, 1] and maximum entry 3 - sage: SST.list() + sage: SST.list() # needs sage.modules [[[1, 1], [2]], [[1, 1], [3]], [[1, 2], [2]], @@ -5886,7 +5893,7 @@ class SemistandardTableaux(Tableaux): sage: SST = SemistandardTableaux(3); SST Semistandard tableaux of size 3 and maximum entry 3 - sage: SST.list() + sage: SST.list() # needs sage.modules [[[1, 1, 1]], [[1, 1, 2]], [[1, 1, 3]], @@ -5909,7 +5916,7 @@ class SemistandardTableaux(Tableaux): sage: SST = SemistandardTableaux(3, max_entry=2); SST Semistandard tableaux of size 3 and maximum entry 2 - sage: SST.list() + sage: SST.list() # needs sage.modules [[[1, 1, 1]], [[1, 1, 2]], [[1, 2, 2]], @@ -5919,13 +5926,13 @@ class SemistandardTableaux(Tableaux): sage: SST = SemistandardTableaux(3, max_entry=oo); SST Semistandard tableaux of size 3 - sage: SST[123] + sage: SST[123] # needs sage.modules [[3, 4], [6]] - sage: SemistandardTableaux(max_entry=2)[11] + sage: SemistandardTableaux(max_entry=2)[11] # needs sage.modules [[1, 1], [2]] - sage: SemistandardTableaux()[0] + sage: SemistandardTableaux()[0] # needs sage.modules [] .. SEEALSO:: @@ -6007,6 +6014,7 @@ def __classcall_private__(cls, *args, **kwargs): ... ValueError: the maximum entry must match the weight + sage: # needs sage.modules sage: SemistandardTableaux([[1]]) Traceback (most recent call last): ... @@ -6124,7 +6132,7 @@ def __init__(self, **kwds): EXAMPLES:: sage: S = SemistandardTableaux() - sage: TestSuite(S).run() + sage: TestSuite(S).run() # needs sage.modules """ if 'max_entry' in kwds: self.max_entry = kwds['max_entry'] @@ -6152,51 +6160,51 @@ def __getitem__(self, r): [[1, 4, 8, 12], [2, 5, 10], [3, 7, 11], [6, 9]], [[1, 3, 8, 12], [2, 5, 10], [4, 7, 11], [6, 9]]] - sage: SemistandardTableaux(size=2, max_entry=oo)[5] + sage: SemistandardTableaux(size=2, max_entry=oo)[5] # needs sage.modules [[2, 3]] - sage: SemistandardTableaux([2,1], max_entry=oo)[3] + sage: SemistandardTableaux([2,1], max_entry=oo)[3] # needs sage.modules [[1, 2], [3]] - sage: SemistandardTableaux(3, max_entry=2)[0:5] # indirect doctest + sage: SemistandardTableaux(3, max_entry=2)[0:5] # indirect doctest # needs sage.modules [[[1, 1, 1]], [[1, 1, 2]], [[1, 2, 2]], [[2, 2, 2]], [[1, 1], [2]]] - sage: SemistandardTableaux([2,2], [2, 1, 1])[0] # indirect doctest + sage: SemistandardTableaux([2,2], [2, 1, 1])[0] # indirect doctest # needs sage.modules [[1, 1], [2, 3]] - sage: SemistandardTableaux([1,1,1], max_entry=4)[0:4] + sage: SemistandardTableaux([1,1,1], max_entry=4)[0:4] # needs sage.modules [[[1], [2], [3]], [[1], [2], [4]], [[1], [3], [4]], [[2], [3], [4]]] - sage: SemistandardTableaux(3, [2,1])[1] # indirect doctest + sage: SemistandardTableaux(3, [2,1])[1] # indirect doctest # needs sage.modules [[1, 1], [2]] - sage: StandardTableaux(3)[:] # indirect doctest + sage: StandardTableaux(3)[:] # indirect doctest # needs sage.modules [[[1, 2, 3]], [[1, 3], [2]], [[1, 2], [3]], [[1], [2], [3]]] - sage: StandardTableaux([2,2])[1] # indirect doctest + sage: StandardTableaux([2,2])[1] # indirect doctest # needs sage.modules [[1, 2], [3, 4]] TESTS:: - sage: SemistandardTableaux()[5] + sage: SemistandardTableaux()[5] # needs sage.modules [[1], [2]] - sage: SemistandardTableaux(max_entry=2)[5] + sage: SemistandardTableaux(max_entry=2)[5] # needs sage.modules [[2, 2]] - sage: SemistandardTableaux()[:] + sage: SemistandardTableaux()[:] # needs sage.modules Traceback (most recent call last): ... ValueError: infinite set - sage: SemistandardTableaux(size=2, max_entry=oo)[:] + sage: SemistandardTableaux(size=2, max_entry=oo)[:] # needs sage.modules Traceback (most recent call last): ... ValueError: infinite set @@ -6290,10 +6298,10 @@ def __init__(self, max_entry=None): TESTS:: sage: T = sage.combinat.tableau.SemistandardTableaux_all() - sage: TestSuite(T).run() + sage: TestSuite(T).run() # needs sage.modules sage: T = sage.combinat.tableau.SemistandardTableaux_all(max_entry=3) - sage: TestSuite(T).run() # long time + sage: TestSuite(T).run() # long time # needs sage.modules """ if max_entry is not PlusInfinity(): self.max_entry = max_entry @@ -6350,7 +6358,7 @@ def __init__(self, n): TESTS:: sage: T = sage.combinat.tableau.SemistandardTableaux_size_inf(3) - sage: TestSuite(T).run() + sage: TestSuite(T).run() # needs sage.modules """ super().__init__(category=InfiniteEnumeratedSets()) self.size = n @@ -6394,15 +6402,15 @@ def __iter__(self): EXAMPLES:: sage: sst = SemistandardTableaux(3, max_entry=oo) - sage: [sst[t] for t in range(5)] + sage: [sst[t] for t in range(5)] # needs sage.modules [[[1, 1, 1]], [[1, 1, 2]], [[1, 2, 2]], [[2, 2, 2]], [[1, 1], [2]]] - sage: sst[1000] + sage: sst[1000] # needs sage.modules [[2, 12], [7]] - sage: sst[0].parent() is sst + sage: sst[0].parent() is sst # needs sage.modules True """ from sage.combinat.partition import Partitions @@ -6453,7 +6461,7 @@ def __init__(self, p): sage: SST = SemistandardTableaux([2,1], max_entry=oo) sage: type(SST) - sage: TestSuite(SST).run() + sage: TestSuite(SST).run() # needs sage.modules """ super().__init__(category=InfiniteEnumeratedSets()) self.shape = p @@ -6494,15 +6502,15 @@ def __iter__(self): EXAMPLES:: sage: SST = SemistandardTableaux([3, 1], max_entry=oo) - sage: SST[1000] + sage: SST[1000] # needs sage.modules [[1, 1, 10], [6]] - sage: [ SST[t] for t in range(5) ] + sage: [ SST[t] for t in range(5) ] # needs sage.modules [[[1, 1, 1], [2]], [[1, 1, 2], [2]], [[1, 2, 2], [2]], [[1, 1, 1], [3]], [[1, 1, 2], [3]]] - sage: SST[0].parent() is SST + sage: SST[0].parent() is SST # needs sage.modules True """ # Iterates through with maximum entry as order @@ -6541,12 +6549,12 @@ def __init__(self, n, max_entry=None): Semistandard tableaux of size 3 and maximum entry 3 sage: type(SST) - sage: TestSuite(SST).run() + sage: TestSuite(SST).run() # needs sage.modules sage: SST = SemistandardTableaux(3, max_entry=6) sage: type(SST) - sage: TestSuite(SST).run() + sage: TestSuite(SST).run() # needs sage.modules """ if max_entry is None: @@ -6578,7 +6586,7 @@ def __contains__(self, x): sage: [[1,2],[3,3]] in SemistandardTableaux(4, max_entry=2) False sage: SST = SemistandardTableaux(4) - sage: all(sst in SST for sst in SST) + sage: all(sst in SST for sst in SST) # needs sage.modules True Check that :trac:`14145` is fixed:: @@ -6616,9 +6624,9 @@ def random_element(self): EXAMPLES:: - sage: SemistandardTableaux(6).random_element() # random # optional - sage.modules + sage: SemistandardTableaux(6).random_element() # random # needs sage.modules [[1, 1, 2], [3, 5, 5]] - sage: SemistandardTableaux(6, max_entry=7).random_element() # random # optional - sage.modules + sage: SemistandardTableaux(6, max_entry=7).random_element() # random # needs sage.modules [[2, 4, 4, 6, 6, 6]] """ from sage.rings.integer_ring import ZZ @@ -6662,7 +6670,7 @@ def cardinality(self): 4225 sage: ns = list(range(1, 6)) sage: ssts = [ SemistandardTableaux(n) for n in ns ] - sage: all(sst.cardinality() == len(sst.list()) for sst in ssts) + sage: all(sst.cardinality() == len(sst.list()) for sst in ssts) # needs sage.modules True """ from sage.combinat.partition import Partitions @@ -6675,9 +6683,9 @@ def __iter__(self): """ EXAMPLES:: - sage: [ t for t in SemistandardTableaux(2) ] + sage: [ t for t in SemistandardTableaux(2) ] # needs sage.modules [[[1, 1]], [[1, 2]], [[2, 2]], [[1], [2]]] - sage: [ t for t in SemistandardTableaux(3) ] + sage: [ t for t in SemistandardTableaux(3) ] # needs sage.modules [[[1, 1, 1]], [[1, 1, 2]], [[1, 1, 3]], @@ -6698,7 +6706,7 @@ def __iter__(self): [[2, 3], [3]], [[1], [2], [3]]] - sage: [ t for t in SemistandardTableaux(3, max_entry=2) ] + sage: [ t for t in SemistandardTableaux(3, max_entry=2) ] # needs sage.modules [[[1, 1, 1]], [[1, 1, 2]], [[1, 2, 2]], @@ -6707,7 +6715,7 @@ def __iter__(self): [[1, 2], [2]]] sage: sst = SemistandardTableaux(3) - sage: sst[0].parent() is sst + sage: sst[0].parent() is sst # needs sage.modules True """ from sage.combinat.partition import Partitions @@ -6743,10 +6751,10 @@ def __init__(self, p, max_entry=None): TESTS:: sage: SST = SemistandardTableaux([2,1]) - sage: TestSuite(SST).run() + sage: TestSuite(SST).run() # needs sage.modules sage: SST = SemistandardTableaux([2,1], max_entry=5) - sage: TestSuite(SST).run() + sage: TestSuite(SST).run() # needs sage.modules """ if max_entry is None: max_entry = sum(p) @@ -6761,7 +6769,7 @@ def __iter__(self): EXAMPLES:: - sage: [ t for t in SemistandardTableaux([3]) ] + sage: [ t for t in SemistandardTableaux([3]) ] # needs sage.modules [[[1, 1, 1]], [[1, 1, 2]], [[1, 1, 3]], @@ -6772,7 +6780,7 @@ def __iter__(self): [[2, 2, 3]], [[2, 3, 3]], [[3, 3, 3]]] - sage: [ t for t in SemistandardTableaux([2,1]) ] + sage: [ t for t in SemistandardTableaux([2,1]) ] # needs sage.modules [[[1, 1], [2]], [[1, 1], [3]], [[1, 2], [2]], @@ -6781,17 +6789,17 @@ def __iter__(self): [[1, 3], [3]], [[2, 2], [3]], [[2, 3], [3]]] - sage: [ t for t in SemistandardTableaux([1,1,1]) ] + sage: [ t for t in SemistandardTableaux([1,1,1]) ] # needs sage.modules [[[1], [2], [3]]] - sage: [ t for t in SemistandardTableaux([1,1,1], max_entry=4) ] + sage: [ t for t in SemistandardTableaux([1,1,1], max_entry=4) ] # needs sage.modules [[[1], [2], [3]], [[1], [2], [4]], [[1], [3], [4]], [[2], [3], [4]]] sage: sst = SemistandardTableaux([3]) - sage: sst[0].parent() is sst + sage: sst[0].parent() is sst # needs sage.modules True """ for c in integer_vectors_nk_fast_iter(sum(self.shape), self.max_entry): @@ -6803,15 +6811,15 @@ def __contains__(self, x): EXAMPLES:: sage: SST = SemistandardTableaux([2,1]) - sage: all(sst in SST for sst in SST) + sage: all(sst in SST for sst in SST) # needs sage.modules True - sage: len([x for x in SemistandardTableaux(3) if x in SST]) + sage: len([x for x in SemistandardTableaux(3) if x in SST]) # needs sage.modules 8 sage: SST.cardinality() 8 sage: SST = SemistandardTableaux([2,1], max_entry=4) - sage: all(sst in SST for sst in SST) + sage: all(sst in SST for sst in SST) # needs sage.modules True sage: SST.cardinality() 20 @@ -6905,7 +6913,7 @@ def cardinality(self, algorithm='hook'): 8 sage: SemistandardTableaux([2,2,1]).cardinality() 75 - sage: SymmetricFunctions(QQ).schur()([2,2,1]).expand(5)(1,1,1,1,1) # cross check + sage: SymmetricFunctions(QQ).schur()([2,2,1]).expand(5)(1,1,1,1,1) # cross check # needs sage.modules 75 sage: SemistandardTableaux([5]).cardinality() 126 @@ -6916,7 +6924,7 @@ def cardinality(self, algorithm='hook'): sage: SemistandardTableaux([6,5,4,3,2,1], max_entry=30).cardinality() 208361017592001331200 sage: ssts = [SemistandardTableaux(p, max_entry=6) for p in Partitions(5)] - sage: all(sst.cardinality() == sst.cardinality(algorithm='sum') + sage: all(sst.cardinality() == sst.cardinality(algorithm='sum') # needs sage.modules ....: for sst in ssts) True """ @@ -6955,7 +6963,7 @@ def __init__(self, p, mu): TESTS:: sage: SST = SemistandardTableaux([2,1], [2,1]) - sage: TestSuite(SST).run() + sage: TestSuite(SST).run() # needs sage.modules """ super().__init__(p, len(mu)) self.weight = mu @@ -6974,11 +6982,11 @@ def __contains__(self, x): EXAMPLES:: sage: SST = SemistandardTableaux([2,1], [2,1]) - sage: all(sst in SST for sst in SST) + sage: all(sst in SST for sst in SST) # needs sage.modules True - sage: len([x for x in SemistandardTableaux(3) if x in SST]) + sage: len([x for x in SemistandardTableaux(3) if x in SST]) # needs sage.modules 1 - sage: SST.cardinality() + sage: SST.cardinality() # needs sage.modules 1 """ if x not in SemistandardTableaux_shape(self.shape, self.max_entry): @@ -7009,6 +7017,7 @@ def cardinality(self): EXAMPLES:: + sage: # needs sage.modules sage: SemistandardTableaux([2,2], [2, 1, 1]).cardinality() 1 sage: SemistandardTableaux([2,2,2], [2, 2, 1,1]).cardinality() @@ -7025,9 +7034,9 @@ def __iter__(self): TESTS:: sage: sst = SemistandardTableaux([3,1],[2,1,1]) - sage: [sst[i] for i in range(2)] + sage: [sst[i] for i in range(2)] # needs sage.modules [[[1, 1, 2], [3]], [[1, 1, 3], [2]]] - sage: sst[0].parent() is sst + sage: sst[0].parent() is sst # needs sage.modules True """ for t in symmetrica.kostka_tab(self.shape, self.weight): @@ -7040,6 +7049,7 @@ def list(self): EXAMPLES:: + sage: # needs sage.modules sage: SemistandardTableaux([2,2], [2, 1, 1]).list() [[[1, 1], [2, 3]]] sage: SemistandardTableaux([2,2,2], [2, 2, 1,1]).list() @@ -7070,7 +7080,7 @@ def __init__(self, n, mu): TESTS:: sage: SST = SemistandardTableaux(3, [2,1]) - sage: TestSuite(SST).run() + sage: TestSuite(SST).run() # needs sage.modules """ super().__init__(max_entry=len(mu), category=FiniteEnumeratedSets()) @@ -7090,6 +7100,7 @@ def __iter__(self): """ EXAMPLES:: + sage: # needs sage.modules sage: [ t for t in SemistandardTableaux(3, [2,1]) ] [[[1, 1, 2]], [[1, 1], [2]]] sage: [ t for t in SemistandardTableaux(4, [2,2]) ] @@ -7109,9 +7120,9 @@ def cardinality(self): EXAMPLES:: - sage: SemistandardTableaux(3, [2,1]).cardinality() + sage: SemistandardTableaux(3, [2,1]).cardinality() # needs sage.modules 2 - sage: SemistandardTableaux(4, [2,2]).cardinality() + sage: SemistandardTableaux(4, [2,2]).cardinality() # needs sage.modules 3 """ from sage.combinat.partition import Partitions @@ -7125,9 +7136,9 @@ def __contains__(self, x): TESTS:: sage: SST = SemistandardTableaux(6, [2,2,2]) - sage: all(sst in SST for sst in SST) + sage: all(sst in SST for sst in SST) # needs sage.modules True - sage: all(sst in SST for sst in SemistandardTableaux([3,2,1],[2,2,2])) + sage: all(sst in SST for sst in SemistandardTableaux([3,2,1],[2,2,2])) # needs sage.modules True """ from sage.combinat.partition import Partition @@ -7167,13 +7178,13 @@ class RowStandardTableaux(Tableaux): sage: ST = RowStandardTableaux(3); ST Row standard tableaux of size 3 - sage: ST.first() # optional - sage.graphs + sage: ST.first() # needs sage.graphs [[1, 2, 3]] - sage: ST.last() # optional - sage.graphs + sage: ST.last() # needs sage.graphs sage.modules [[3], [1], [2]] - sage: ST.cardinality() # optional - sage.graphs + sage: ST.cardinality() # needs sage.graphs sage.modules 10 - sage: ST.list() # optional - sage.graphs + sage: ST.list() # needs sage.graphs sage.modules [[[1, 2, 3]], [[2, 3], [1]], [[1, 2], [3]], @@ -7200,13 +7211,13 @@ class RowStandardTableaux(Tableaux): [] sage: ST = RowStandardTableaux([2,2]); ST Row standard tableaux of shape [2, 2] - sage: ST.first() # optional - sage.graphs + sage: ST.first() # needs sage.graphs [[2, 4], [1, 3]] - sage: ST.last() # optional - sage.graphs + sage: ST.last() # needs sage.graphs sage.modules [[2, 3], [1, 4]] - sage: ST.cardinality() # optional - sage.graphs + sage: ST.cardinality() # needs sage.graphs sage.modules 6 - sage: ST.list() # optional - sage.graphs + sage: ST.list() # needs sage.graphs sage.modules [[[2, 4], [1, 3]], [[3, 4], [1, 2]], [[1, 4], [2, 3]], @@ -7318,7 +7329,7 @@ def __init__(self): TESTS:: sage: ST = RowStandardTableaux() - sage: TestSuite(ST).run() + sage: TestSuite(ST).run() # needs sage.graphs """ RowStandardTableaux.__init__(self) DisjointUnionEnumeratedSets.__init__(self, @@ -7341,11 +7352,11 @@ class RowStandardTableaux_size(RowStandardTableaux, DisjointUnionEnumeratedSets) EXAMPLES:: - sage: [t for t in RowStandardTableaux(1)] # optional - sage.graphs + sage: [t for t in RowStandardTableaux(1)] # needs sage.graphs [[[1]]] - sage: [t for t in RowStandardTableaux(2)] # optional - sage.graphs + sage: [t for t in RowStandardTableaux(2)] # needs sage.graphs [[[1, 2]], [[2], [1]], [[1], [2]]] - sage: list(RowStandardTableaux(3)) # optional - sage.graphs + sage: list(RowStandardTableaux(3)) # needs sage.graphs [[[1, 2, 3]], [[2, 3], [1]], [[1, 2], [3]], @@ -7359,13 +7370,13 @@ class RowStandardTableaux_size(RowStandardTableaux, DisjointUnionEnumeratedSets) TESTS:: - sage: TestSuite( RowStandardTableaux(4) ).run() + sage: TestSuite(RowStandardTableaux(4)).run() # needs sage.graphs - sage: RowStandardTableaux(3).cardinality() + sage: RowStandardTableaux(3).cardinality() # needs sage.libs.flint 10 sage: ns = [1,2,3,4,5,6] sage: sts = [RowStandardTableaux(n) for n in ns] - sage: all(st.cardinality() == len(st.list()) for st in sts) # optional - sage.graphs + sage: all(st.cardinality() == len(st.list()) for st in sts) # needs sage.graphs True sage: RowStandardTableaux(40).cardinality() # not tested, too long 2063837185739279909309355007659204891024472174278 @@ -7382,8 +7393,8 @@ def __init__(self, n): TESTS:: - sage: TestSuite(RowStandardTableaux(0)).run() # optional - sage.graphs - sage: TestSuite(RowStandardTableaux(3)).run() # optional - sage.graphs + sage: TestSuite(RowStandardTableaux(0)).run() # needs sage.graphs + sage: TestSuite(RowStandardTableaux(3)).run() # needs sage.graphs """ RowStandardTableaux.__init__(self) from sage.combinat.partition import Partitions_n @@ -7406,10 +7417,10 @@ def __contains__(self, x): TESTS:: sage: ST3 = RowStandardTableaux(3) - sage: all(st in ST3 for st in ST3) # optional - sage.graphs + sage: all(st in ST3 for st in ST3) # needs sage.graphs True sage: ST4 = RowStandardTableaux(4) - sage: [x for x in ST4 if x in ST3] # optional - sage.graphs + sage: [x for x in ST4 if x in ST3] # needs sage.graphs [] Check that :trac:`14145` is fixed:: @@ -7452,7 +7463,7 @@ def __init__(self, p): TESTS:: - sage: TestSuite( RowStandardTableaux([2,1,1]) ).run() # optional - sage.graphs + sage: TestSuite( RowStandardTableaux([2,1,1]) ).run() # needs sage.graphs """ super().__init__(category=FiniteEnumeratedSets()) self.shape = p @@ -7462,9 +7473,9 @@ def __contains__(self, x): EXAMPLES:: sage: ST = RowStandardTableaux([2,1,1]) - sage: all(st in ST for st in ST) # optional - sage.graphs + sage: all(st in ST for st in ST) # needs sage.graphs True - sage: len([x for x in RowStandardTableaux(4) if x in ST]) # optional - sage.graphs + sage: len([x for x in RowStandardTableaux(4) if x in ST]) # needs sage.graphs 12 sage: ST.cardinality() 12 @@ -7487,14 +7498,14 @@ def __iter__(self): EXAMPLES:: - sage: [t for t in RowStandardTableaux([2,2])] # optional - sage.graphs + sage: [t for t in RowStandardTableaux([2,2])] # needs sage.graphs [[[2, 4], [1, 3]], [[3, 4], [1, 2]], [[1, 4], [2, 3]], [[1, 3], [2, 4]], [[1, 2], [3, 4]], [[2, 3], [1, 4]]] - sage: [t for t in RowStandardTableaux([3,2])] # optional - sage.graphs + sage: [t for t in RowStandardTableaux([3,2])] # needs sage.graphs [[[2, 4, 5], [1, 3]], [[3, 4, 5], [1, 2]], [[1, 4, 5], [2, 3]], @@ -7506,7 +7517,7 @@ def __iter__(self): [[2, 3, 4], [1, 5]], [[2, 3, 5], [1, 4]]] sage: st = RowStandardTableaux([2,1]) - sage: st[0].parent() is st # optional - sage.graphs + sage: st[0].parent() is st # needs sage.graphs True """ partial_sums = [sum(self.shape[:i]) for i in range(len(self.shape)+1)] @@ -7613,7 +7624,7 @@ class StandardTableaux(SemistandardTableaux): 2 sage: ST.list() [[[1, 3], [2, 4]], [[1, 2], [3, 4]]] - sage: StandardTableau([[1,2,3],[4,5]]).residue_sequence(3).standard_tableaux() # optional - sage.groups + sage: StandardTableau([[1,2,3],[4,5]]).residue_sequence(3).standard_tableaux() # needs sage.groups Standard tableaux with 3-residue sequence (0,1,2,2,0) and multicharge (0) """ @staticmethod diff --git a/src/sage/combinat/tableau_tuple.py b/src/sage/combinat/tableau_tuple.py index 889f5ee9bc4..96fc0f0c51c 100644 --- a/src/sage/combinat/tableau_tuple.py +++ b/src/sage/combinat/tableau_tuple.py @@ -130,7 +130,7 @@ iterators must have the correct parents, so in this one case 1-tuples of tableaux are different from :class:`Tableaux`:: - sage: StandardTableauTuples()[:10] + sage: StandardTableauTuples()[:10] # needs sage.libs.flint [(), ([[1]]), ([], []), @@ -1072,7 +1072,9 @@ def row_stabilizer(self): EXAMPLES:: - sage: rs = TableauTuple([[[1,2,3],[4,5]],[[6,7]],[[8],[9]]]).row_stabilizer() + sage: # needs sage.groups + sage: t = TableauTuple([[[1,2,3],[4,5]],[[6,7]],[[8],[9]]]) + sage: rs = t.row_stabilizer() sage: rs.order() 24 sage: PermutationGroupElement([(1,3,2),(4,5)]) in rs @@ -1100,7 +1102,9 @@ def column_stabilizer(self): EXAMPLES:: - sage: cs = TableauTuple([[[1,2,3],[4,5]],[[6,7]],[[8],[9]]]).column_stabilizer() + sage: # needs sage.groups + sage: t = TableauTuple([[[1,2,3],[4,5]],[[6,7]],[[8],[9]]]) + sage: cs = t.column_stabilizer() sage: cs.order() 8 sage: PermutationGroupElement([(1,3,2),(4,5)]) in cs @@ -1507,7 +1511,7 @@ def __classcall_private__(self, t): sage: RowStandardTableauTuples(level=2)(t).parent() Row standard tableau tuples of level 2 - sage: RowStandardTableauTuples(level=2,size=6)(t).parent() + sage: RowStandardTableauTuples(level=2, size=6)(t).parent() # needs sage.libs.flint Row standard tableau tuples of level 2 and size 6 """ if isinstance(t, (RowStandardTableau, RowStandardTableauTuple)): @@ -1894,7 +1898,7 @@ def __classcall_private__(self, t): sage: StandardTableauTuples(level=2)(t).parent() Standard tableau tuples of level 2 - sage: StandardTableauTuples(level=2,size=6)(t).parent() + sage: StandardTableauTuples(level=2, size=6)(t).parent() # needs sage.libs.flint Standard tableau tuples of level 2 and size 6 """ if isinstance(t, (StandardTableau, StandardTableauTuple)): @@ -2712,7 +2716,7 @@ class RowStandardTableauTuples(TableauTuples): Row standard tableau tuples of shape ([2], [1, 1]) sage: tabs.cardinality() 12 - sage: tabs[:] + sage: tabs[:] # needs sage.graphs sage.rings.finite_rings [([[3, 4]], [[2], [1]]), ([[2, 4]], [[3], [1]]), ([[1, 4]], [[3], [2]]), @@ -2728,25 +2732,26 @@ class RowStandardTableauTuples(TableauTuples): sage: tabs = RowStandardTableauTuples(level=3); tabs Row standard tableau tuples of level 3 - sage: tabs[100] + sage: tabs[100] # needs sage.libs.flint ([], [], [[2, 3], [1]]) - sage: RowStandardTableauTuples()[0] + sage: RowStandardTableauTuples()[0] # needs sage.libs.flint ([]) TESTS:: + sage: # needs sage.libs.flint sage: TestSuite( RowStandardTableauTuples() ).run() sage: TestSuite( RowStandardTableauTuples(level=1) ).run() sage: TestSuite( RowStandardTableauTuples(level=4) ).run() - sage: TestSuite( RowStandardTableauTuples(size=0) ).run(max_runs=50) # recursion depth exceeded with default max_runs + sage: TestSuite( RowStandardTableauTuples(size=0) ).run(max_runs=50) # recursion depth exceeded with default max_runs sage: TestSuite( RowStandardTableauTuples(size=6) ).run() sage: TestSuite( RowStandardTableauTuples(level=1, size=0) ).run() sage: TestSuite( RowStandardTableauTuples(level=1, size=0) ).run() sage: TestSuite( RowStandardTableauTuples(level=1, size=10) ).run() sage: TestSuite( RowStandardTableauTuples(level=4, size=0) ).run() sage: TestSuite( RowStandardTableauTuples(level=4, size=0) ).run() - sage: TestSuite( RowStandardTableauTuples(level=4, size=10) ).run() # long time + sage: TestSuite( RowStandardTableauTuples(level=4, size=10) ).run() # long time sage: TestSuite( RowStandardTableauTuples(shape=[[1],[3,1],[],[2,1]]) ).run() .. SEEALSO:: @@ -2772,9 +2777,9 @@ def __classcall_private__(cls, *args, **kwargs): Row standard tableau tuples sage: RowStandardTableauTuples(4) Row standard tableau tuples of level 4 - sage: RowStandardTableauTuples(4,3) + sage: RowStandardTableauTuples(4,3) # needs sage.libs.flint Row standard tableau tuples of level 4 and size 3 - sage: RowStandardTableauTuples([ [2,1],[1],[1,1,1],[3,2] ]) + sage: RowStandardTableauTuples([ [2,1],[1],[1,1,1],[3,2] ]) # needs sage.libs.flint Row standard tableau tuples of shape ([2, 1], [1], [1, 1, 1], [3, 2]) TESTS:: @@ -2787,7 +2792,7 @@ def __classcall_private__(cls, *args, **kwargs): sage: P = PartitionTuples() sage: pt = P([[1]]); pt ([1]) - sage: RowStandardTableauTuples(pt) + sage: RowStandardTableauTuples(pt) # needs sage.libs.flint Row standard tableaux of shape [1] """ from sage.combinat.partition_tuple import PartitionTuple @@ -2874,7 +2879,7 @@ def __getitem__(self, r): EXAMPLES:: - sage: RowStandardTableauTuples()[10:20] + sage: RowStandardTableauTuples()[10:20] # needs sage.libs.flint [([[2, 3], [1]]), ([[1, 2], [3]]), ([[1, 3], [2]]), @@ -2993,7 +2998,7 @@ def __init__(self): EXAMPLES:: sage: RSTT = RowStandardTableauTuples() - sage: TestSuite(RSTT).run() + sage: TestSuite(RSTT).run() # needs sage.libs.flint """ RowStandardTableauTuples.__init__(self) from sage.combinat.partition_tuple import PartitionTuples @@ -3046,7 +3051,7 @@ def __init__(self, level): sage: RowStandardTableauTuples(3) Row standard tableau tuples of level 3 - sage: RowStandardTableauTuples(3)[:10] + sage: RowStandardTableauTuples(3)[:10] # needs sage.libs.flint [([], [], []), ([[1]], [], []), ([], [[1]], []), @@ -3144,7 +3149,7 @@ def __init__(self, size): sage: RowStandardTableauTuples(size=3) # indirect doctest Row standard tableau tuples of size 3 - sage: RowStandardTableauTuples(size=2)[:10] + sage: RowStandardTableauTuples(size=2)[:10] # needs sage.libs.flint [([[1, 2]]), ([[2], [1]]), ([[1], [2]]), @@ -3242,9 +3247,10 @@ def __init__(self, level, size): EXAMPLES:: - sage: RowStandardTableauTuples(size=4,level=3) + sage: # needs sage.libs.flint + sage: RSTT43 = RowStandardTableauTuples(size=4, level=3); RSTT43 Row standard tableau tuples of level 3 and size 4 - sage: RowStandardTableauTuples(size=4,level=3) is RowStandardTableauTuples(3,4) + sage: RSTT43 is RowStandardTableauTuples(3,4) True sage: RowStandardTableauTuples(level=3, size=2)[:] [([[1, 2]], [], []), @@ -3281,7 +3287,7 @@ def _repr_(self): EXAMPLES:: - sage: RowStandardTableauTuples(3, 4) + sage: RowStandardTableauTuples(3, 4) # needs sage.libs.flint Row standard tableau tuples of level 3 and size 4 """ return f"Row standard tableau tuples of level {self.level()} and size {self.size()}" @@ -3293,6 +3299,7 @@ def __contains__(self, t): EXAMPLES:: + sage: # needs sage.libs.flint sage: tabs = RowStandardTableauTuples(level=4, size=4); tabs Row standard tableau tuples of level 4 and size 4 sage: [[[2,4],[1]],[],[[3]],[]] in tabs @@ -3304,7 +3311,7 @@ def __contains__(self, t): Check that :trac:`14145` is fixed:: - sage: 1 in RowStandardTableauTuples(level=4, size=3) + sage: 1 in RowStandardTableauTuples(level=4, size=3) # needs sage.libs.flint False """ if isinstance(t, self.element_class): @@ -3323,9 +3330,9 @@ def an_element(self): EXAMPLES:: - sage: RowStandardTableauTuples(5,size=2).an_element() + sage: RowStandardTableauTuples(5, size=2).an_element() # needs sage.libs.flint ([], [], [], [], [[1], [2]]) - sage: RowStandardTableauTuples(2,size=4).an_element() + sage: RowStandardTableauTuples(2, size=4).an_element() # needs sage.libs.flint ([[1]], [[2, 3], [4]]) """ if self.size() == 0: @@ -3423,14 +3430,14 @@ def __iter__(self): EXAMPLES:: - sage: RowStandardTableauTuples([[1],[1],[1]]).list() + sage: RowStandardTableauTuples([[1],[1],[1]]).list() # needs sage.graphs sage.modules sage.rings.finite_rings [([[3]], [[2]], [[1]]), ([[2]], [[3]], [[1]]), ([[1]], [[3]], [[2]]), ([[1]], [[2]], [[3]]), ([[2]], [[1]], [[3]]), ([[3]], [[1]], [[2]])] - sage: RowStandardTableauTuples([[2,1],[2]]).list() + sage: RowStandardTableauTuples([[2,1],[2]]).list() # needs sage.graphs sage.modules sage.rings.finite_rings [([[4, 5], [2]], [[1, 3]]), ([[4, 5], [3]], [[1, 2]]), ([[3, 5], [4]], [[1, 2]]), @@ -3464,10 +3471,10 @@ def __iter__(self): TESTS:: - sage: def check(mu): + sage: def check(mu): # needs sage.graphs sage.modules sage.rings.finite_rings ....: return (RowStandardTableauTuples(mu).cardinality() ....: == len(RowStandardTableauTuples(mu).list())) - sage: all(check(mu) for mu in PartitionTuples(4,4)) + sage: all(check(mu) for mu in PartitionTuples(4,4)) # needs sage.graphs sage.modules sage.rings.finite_rings True """ mu = self.shape() @@ -3536,9 +3543,9 @@ def an_element(self): EXAMPLES:: - sage: RowStandardTableauTuples([[2],[2,1]]).an_element() + sage: RowStandardTableauTuples([[2],[2,1]]).an_element() # needs sage.graphs ([[4, 5]], [[1, 3], [2]]) - sage: RowStandardTableauTuples([[10],[],[]]).an_element() + sage: RowStandardTableauTuples([[10],[],[]]).an_element() # needs sage.graphs ([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [], []) """ c = self.cardinality() @@ -3641,7 +3648,7 @@ def __iter__(self): EXAMPLES:: sage: R = RowStandardTableauTuple([[[4, 5], [3]],[[1,2]]]).residue_sequence(3, (0,1)) - sage: R.row_standard_tableaux()[:] + sage: R.row_standard_tableaux()[:] # needs sage.libs.flint [([[4, 5], [3]], [[1, 2]]), ([[4, 5], [2]], [[1, 3]]), ([[4], [3], [5]], [[1, 2]]), @@ -3651,7 +3658,7 @@ def __iter__(self): ([], [[1, 3], [4], [2], [5]]), ([], [[1, 2], [4], [3], [5]])] sage: R = RowStandardTableauTuple([[[2,4],[1]],[[3]]]).residue_sequence(3,(0,1)) - sage: R.row_standard_tableaux()[:] + sage: R.row_standard_tableaux()[:] # needs sage.libs.flint [([[2, 4], [1], [3]], []), ([[2, 3], [1], [4]], []), ([[2, 4], [1]], [[3]]), @@ -3774,8 +3781,8 @@ def an_element(self): [[2, 3], [1]] sage: StandardTableau([[1,3],[2]]).residue_sequence(3).row_standard_tableaux().an_element() [[1, 3], [2]] - sage: RowStandardTableauTuple([[[4]],[[2,3],[1]]]).residue_sequence(3,(0,1)).row_standard_tableaux().an_element() - sage: StandardTableauTuple([[[4]],[[1,3],[2]]]).residue_sequence(3,(0,1)).row_standard_tableaux().an_element() + sage: RowStandardTableauTuple([[[4]],[[2,3],[1]]]).residue_sequence(3,(0,1)).row_standard_tableaux().an_element() # needs sage.libs.flint + sage: StandardTableauTuple([[[4]],[[1,3],[2]]]).residue_sequence(3,(0,1)).row_standard_tableaux().an_element() # needs sage.libs.flint ([[4], [3], [1], [2]], []) """ try: @@ -4017,14 +4024,15 @@ class StandardTableauTuples(RowStandardTableauTuples): sage: tabs=StandardTableauTuples(level=3); tabs Standard tableau tuples of level 3 - sage: tabs[100] + sage: tabs[100] # needs sage.libs.flint ([[1, 2], [3]], [], [[4]]) - sage: StandardTableauTuples()[0] + sage: StandardTableauTuples()[0] # needs sage.libs.flint () TESTS:: + sage: # needs sage.libs.flint sage: TestSuite( StandardTableauTuples() ).run() sage: TestSuite( StandardTableauTuples(level=1) ).run() sage: TestSuite( StandardTableauTuples(level=4) ).run() @@ -4061,14 +4069,14 @@ def __classcall_private__(cls, *args, **kwargs): Standard tableau tuples sage: StandardTableauTuples(4) Standard tableau tuples of level 4 - sage: StandardTableauTuples(4,3) + sage: StandardTableauTuples(4,3) # needs sage.libs.flint Standard tableau tuples of level 4 and size 3 - sage: StandardTableauTuples([ [2,1],[1],[1,1,1],[3,2] ]) + sage: StandardTableauTuples([ [2,1],[1],[1,1,1],[3,2] ]) # needs sage.libs.flint Standard tableau tuples of shape ([2, 1], [1], [1, 1, 1], [3, 2]) TESTS:: - sage: StandardTableauTuples([ [2,1],[1],[1,1,1],[3,2,3] ]) + sage: StandardTableauTuples([ [2,1],[1],[1,1,1],[3,2,3] ]) # needs sage.libs.flint Traceback (most recent call last): ... ValueError: the shape must be a partition tuple @@ -4076,7 +4084,7 @@ def __classcall_private__(cls, *args, **kwargs): sage: P = PartitionTuples() sage: pt = P([[1]]); pt ([1]) - sage: StandardTableauTuples(pt) + sage: StandardTableauTuples(pt) # needs sage.libs.flint Standard tableaux of shape [1] """ from sage.combinat.partition_tuple import PartitionTuple @@ -4162,7 +4170,7 @@ def __getitem__(self, r): EXAMPLES:: - sage: StandardTableauTuples()[10:20] + sage: StandardTableauTuples()[10:20] # needs sage.libs.flint [([[1, 2], [3]]), ([[1], [2], [3]]), ([[1, 2]], []), @@ -4316,6 +4324,7 @@ def __iter__(self): EXAMPLES:: + sage: # needs sage.libs.flint sage: stt = StandardTableauTuples() sage: stt[0:8] [(), @@ -4418,7 +4427,7 @@ def __iter__(self): EXAMPLES:: sage: stt = StandardTableauTuples(3) - sage: stt[0:8] + sage: stt[0:8] # needs sage.libs.flint [([], [], []), ([[1]], [], []), ([], [[1]], []), @@ -4427,9 +4436,9 @@ def __iter__(self): ([[1], [2]], [], []), ([[1]], [[2]], []), ([[2]], [[1]], [])] - sage: stt[50] + sage: stt[50] # needs sage.libs.flint ([], [[1, 2, 3]], []) - sage: stt[0].parent() is stt + sage: stt[0].parent() is stt # needs sage.libs.flint True """ # Iterate through the PartitionTuples and then the tableaux @@ -4540,7 +4549,7 @@ def __iter__(self): EXAMPLES:: sage: stt = StandardTableauTuples(size=3) - sage: stt[0:8] + sage: stt[0:8] # needs sage.libs.flint [([[1, 2, 3]]), ([[1, 3], [2]]), ([[1, 2], [3]]), @@ -4549,9 +4558,9 @@ def __iter__(self): ([[1, 2], [3]], []), ([[1, 3], [2]], []), ([[1], [2], [3]], [])] - sage: stt[50] + sage: stt[50] # needs sage.libs.flint ([[3]], [[1]], [[2]]) - sage: stt[0].parent() is stt + sage: stt[0].parent() is stt # needs sage.libs.flint True """ # Iterate through the PartitionTuples and then the tableaux @@ -4597,9 +4606,9 @@ def __init__(self, level, size): EXAMPLES:: - sage: StandardTableauTuples(size=4,level=3) + sage: StandardTableauTuples(size=4, level=3) # needs sage.libs.flint Standard tableau tuples of level 3 and size 4 - sage: StandardTableauTuples(size=4,level=3) is StandardTableauTuples(3,4) + sage: StandardTableauTuples(size=4, level=3) is StandardTableauTuples(3,4) # needs sage.libs.flint True """ StandardTableauTuples.__init__(self) @@ -4617,7 +4626,7 @@ def _repr_(self): EXAMPLES:: - sage: StandardTableauTuples(3, 4) # indirect doctest + sage: StandardTableauTuples(3, 4) # indirect doctest # needs sage.libs.flint Standard tableau tuples of level 3 and size 4 """ return f"Standard tableau tuples of level {self.level()} and size {self.size()}" @@ -4629,6 +4638,7 @@ def __contains__(self, t): EXAMPLES:: + sage: # needs sage.libs.flint sage: tabs = StandardTableauTuples(level=4, size=3); tabs Standard tableau tuples of level 4 and size 3 sage: [[[1,2]],[],[[3]],[]] in tabs @@ -4642,7 +4652,7 @@ def __contains__(self, t): Check that :trac:`14145` is fixed:: - sage: 1 in StandardTableauTuples(level=4, size=3) + sage: 1 in StandardTableauTuples(level=4, size=3) # needs sage.libs.flint False """ if isinstance(t, self.element_class): @@ -4661,9 +4671,9 @@ def cardinality(self): EXAMPLES:: - sage: StandardTableauTuples(3,2).cardinality() + sage: StandardTableauTuples(3,2).cardinality() # needs sage.libs.flint 12 - sage: StandardTableauTuples(4,6).cardinality() + sage: StandardTableauTuples(4,6).cardinality() # needs sage.libs.flint 31936 """ from sage.combinat.partition_tuple import PartitionTuples @@ -4680,7 +4690,8 @@ def __iter__(self): EXAMPLES:: - sage: stt = StandardTableauTuples(3,3) + sage: # needs sage.libs.flint + sage: stt = StandardTableauTuples(3, 3) sage: stt[0:8] [([[1, 2, 3]], [], []), ([[1, 2], [3]], [], []), @@ -4707,9 +4718,9 @@ def an_element(self): EXAMPLES:: - sage: StandardTableauTuples(5,size=2).an_element() + sage: StandardTableauTuples(5, size=2).an_element() # needs sage.libs.flint ([], [], [], [], [[1], [2]]) - sage: StandardTableauTuples(2,size=4).an_element() + sage: StandardTableauTuples(2, size=4).an_element() # needs sage.libs.flint ([[1]], [[2, 3], [4]]) """ if self.size() == 0: @@ -4823,8 +4834,8 @@ def __iter__(self): TESTS:: - sage: correct_number=lambda mu : StandardTableauTuples(mu).cardinality()==len(StandardTableauTuples(mu).list()) - sage: all(correct_number(mu) for mu in PartitionTuples(4,4)) + sage: correct_number = lambda mu: StandardTableauTuples(mu).cardinality()==len(StandardTableauTuples(mu).list()) + sage: all(correct_number(mu) for mu in PartitionTuples(4,4)) # needs sage.libs.flint True """ mu = self.shape() diff --git a/src/sage/combinat/tamari_lattices.py b/src/sage/combinat/tamari_lattices.py index e7ac12e1ca3..43191540d71 100644 --- a/src/sage/combinat/tamari_lattices.py +++ b/src/sage/combinat/tamari_lattices.py @@ -207,7 +207,7 @@ def GeneralizedTamariLattice(a, b, m=1, check=True): TESTS:: - sage: P.coxeter_transformation()**18 == 1 + sage: P.coxeter_transformation()**18 == 1 # needs sage.libs.flint True REFERENCES: diff --git a/src/sage/combinat/tiling.py b/src/sage/combinat/tiling.py index aaa9a7227b8..a543b50461d 100644 --- a/src/sage/combinat/tiling.py +++ b/src/sage/combinat/tiling.py @@ -108,9 +108,9 @@ Showing one solution:: - sage: solution = next(T.solve()) # long time - sage: G = sum([piece.show2d() for piece in solution], Graphics()) # long time # optional - sage.plot - sage: G.show(aspect_ratio=1, axes=False) # long time # optional - sage.plot + sage: solution = next(T.solve()) # long time + sage: G = sum([piece.show2d() for piece in solution], Graphics()) # long time, needs sage.plot + sage: G.show(aspect_ratio=1, axes=False) # long time, needs sage.plot 1d Easy Example --------------- @@ -154,20 +154,20 @@ there are no solution for tiling a `8 \times 8` rectangular box:: sage: T = TilingSolver(L, box=(8,8)) - sage: T.number_of_solutions() # long time (2.5 s) + sage: T.number_of_solutions() # long time (2.5s) 0 If reflections are allowed, there are solutions. Solve the puzzle and show one solution:: sage: T = TilingSolver(L, box=(8,8), reflection=True) - sage: solution = next(T.solve()) # long time (7s) - sage: G = sum([piece.show2d() for piece in solution], Graphics()) # long time (<1s) # optional - sage.plot - sage: G.show(aspect_ratio=1, axes=False) # long time (2s) # optional - sage.plot + sage: solution = next(T.solve()) # long time (7s) + sage: G = sum([piece.show2d() for piece in solution], Graphics()) # long time (<1s), needs sage.plot + sage: G.show(aspect_ratio=1, axes=False) # long time (2s), needs sage.plot Compute the number of solutions:: - sage: T.number_of_solutions() # long time (2.6s) + sage: T.number_of_solutions() # long time (2.6s) 328 Create a animation of all the solutions:: @@ -197,13 +197,13 @@ Solve the puzzle and show one solution:: sage: T = TilingSolver(L, box=(8,8,1)) - sage: solution = next(T.solve()) # long time (8s) - sage: G = sum([p.show3d(size=0.85) for p in solution], Graphics()) # long time (<1s) - sage: G.show(aspect_ratio=1, viewer='tachyon') # long time (2s) + sage: solution = next(T.solve()) # long time (8s) + sage: G = sum([p.show3d(size=0.85) for p in solution], Graphics()) # long time (<1s), needs sage.plot + sage: G.show(aspect_ratio=1, viewer='tachyon') # long time (2s), needs sage.plot Let us compute the number of solutions:: - sage: T.number_of_solutions() # long time (3s) + sage: T.number_of_solutions() # long time (3s) 328 Donald Knuth example : the Y pentamino @@ -218,8 +218,8 @@ sage: T.number_of_solutions() 10 sage: solution = next(T.solve()) - sage: G = sum([p.show2d() for p in solution], Graphics()) # optional - sage.plot - sage: G.show(aspect_ratio=1) # long time (2s) # optional - sage.plot + sage: G = sum([p.show2d() for p in solution], Graphics()) # needs sage.plot + sage: G.show(aspect_ratio=1) # long time (2s), needs sage.plot :: @@ -240,15 +240,14 @@ sage: from sage.combinat.tiling import Polyomino, TilingSolver sage: Y = Polyomino([(0,0),(1,0),(2,0),(3,0),(2,1)], color='yellow') sage: T = TilingSolver([Y], box=(15,15), reusable=True, reflection=True) - sage: a = T.animate(stop=40); a # long time # optional -- ImageMagick sage.plot + sage: a = T.animate(stop=40); a # long time, optional - imagemagick, needs sage.plot Animation with 40 frames Incremental animation of the solutions (one piece is removed/added at a time):: - sage: a = T.animate('incremental', stop=40) # long time # optional -- ImageMagick sage.plot - sage: a # long time # optional -- ImageMagick sage.plot + sage: a = T.animate('incremental', stop=40); a # long time, optional - imagemagick, needs sage.plot Animation with 40 frames - sage: a.show(delay=50, iterations=1) # long time # optional -- ImageMagick sage.plot + sage: a.show(delay=50, iterations=1) # long time, optional - imagemagick, needs sage.plot 5d Easy Example --------------- @@ -1387,7 +1386,7 @@ def show3d(self, size=1): sage: from sage.combinat.tiling import Polyomino sage: p = Polyomino([(0,0,0), (0,1,0), (1,1,0), (1,1,1)], color='blue') - sage: p.show3d() # long time (2s) # optional -- sage.plot + sage: p.show3d() # long time (2s) # needs sage.plot Graphics3d Object """ assert self._dimension == 3, "Dimension of the polyomino must be 3." @@ -1420,7 +1419,7 @@ def show2d(self, size=0.7, color='black', thickness=1): sage: from sage.combinat.tiling import Polyomino sage: p = Polyomino([(0,0),(1,0),(1,1),(1,2)], color='deeppink') - sage: p.show2d() # long time (0.5s) # optional -- sage.plot + sage: p.show2d() # long time (0.5s) # needs sage.plot Graphics object consisting of 17 graphics primitives """ assert self._dimension == 2, "Dimension of the polyomino must be 2." @@ -1471,12 +1470,12 @@ def self_surrounding(self, radius, remove_incomplete_copies=True, ....: (1, 3), (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (2, 0), (2, 2), ....: (2, 3), (2, 5), (2, 6), (2, 8)]) sage: solution = H.self_surrounding(8) - sage: G = sum([p.show2d() for p in solution], Graphics()) # optional - sage.plot + sage: G = sum([p.show2d() for p in solution], Graphics()) # needs sage.plot :: sage: solution = H.self_surrounding(8, remove_incomplete_copies=False) - sage: G = sum([p.show2d() for p in solution], Graphics()) # optional - sage.plot + sage: G = sum([p.show2d() for p in solution], Graphics()) # needs sage.plot """ # Define the box to tile @@ -2423,38 +2422,37 @@ def animate(self, partial=None, stop=None, size=0.75, axes=False): sage: from sage.combinat.tiling import Polyomino, TilingSolver sage: y = Polyomino([(0,0),(1,0),(2,0),(3,0),(2,1)], color='cyan') sage: T = TilingSolver([y], box=(5,10), reusable=True, reflection=True) - sage: a = T.animate() # optional - sage.plot - sage: a # optional -- ImageMagick # long time # optional - sage.plot + sage: a = T.animate() # needs sage.plot + sage: a # long time, optional - imagemagick, needs sage.plot Animation with 10 frames Include partial solutions (common prefix between two consecutive solutions):: - sage: a = T.animate('common_prefix') # optional - sage.plot - sage: a # optional -- ImageMagick # long time # optional - sage.plot + sage: a = T.animate('common_prefix') # needs sage.plot + sage: a # long time, optional - imagemagick, needs sage.plot Animation with 19 frames Incremental solutions (one piece removed or added at a time):: - sage: a = T.animate('incremental') # long time (2s) # optional - sage.plot - sage: a # long time (2s) # optional -- ImageMagick sage.plot + sage: a = T.animate('incremental') # long time (2s) # needs sage.plot + sage: a # long time (2s), optional - imagemagick, needs sage.plot Animation with 123 frames :: - sage: a.show() # optional -- ImageMagick # long time # optional - sage.plot + sage: a.show() # long time, optional - imagemagick, needs sage.plot The ``show`` function takes arguments to specify the delay between frames (measured in hundredths of a second, default value 20) and the number of iterations (default value 0, which means to iterate forever). To iterate 4 times with half a second between each frame:: - sage: a.show(delay=50, iterations=4) # optional -- ImageMagick # long time # optional - sage.plot + sage: a.show(delay=50, iterations=4) # long time, optional - imagemagick, needs sage.plot Limit the number of frames:: - sage: a = T.animate('incremental', stop=13) # not tested # optional - sage.plot - sage: a # not tested # optional - sage.plot + sage: a = T.animate('incremental', stop=13); a # not tested # needs sage.plot Animation with 13 frames """ dimension = self._box._dimension diff --git a/src/sage/combinat/triangles_FHM.py b/src/sage/combinat/triangles_FHM.py index 43f2947a51b..8e3399d4da4 100644 --- a/src/sage/combinat/triangles_FHM.py +++ b/src/sage/combinat/triangles_FHM.py @@ -12,11 +12,11 @@ The M-triangle class is motivated by the generating series of Möbius numbers for graded posets. A typical example is:: - sage: W = SymmetricGroup(4) # optional - sage.groups - sage: posets.NoncrossingPartitions(W).M_triangle() # optional - sage.graphs sage.groups + sage: W = SymmetricGroup(4) # needs sage.groups + sage: posets.NoncrossingPartitions(W).M_triangle() # needs sage.graphs sage.groups M: x^3*y^3 - 6*x^2*y^3 + 6*x^2*y^2 + 10*x*y^3 - 16*x*y^2 - 5*y^3 + 6*x*y + 10*y^2 - 6*y + 1 - sage: unicode_art(_) # optional - sage.graphs sage.modules sage.groups + sage: unicode_art(_) # needs sage.graphs sage.groups sage.modules ⎛ -5 10 -6 1⎞ ⎜ 10 -16 6 0⎟ ⎜ -6 6 0 0⎟ @@ -27,11 +27,12 @@ think about complete fans endowed with a distinguished maximal cone. A typical example is:: + sage: # needs sage.graphs sage.modules sage: C = ClusterComplex(['A',3]) sage: f = C.greedy_facet() sage: C.F_triangle(f) F: 5*x^3 + 5*x^2*y + 3*x*y^2 + y^3 + 10*x^2 + 8*x*y + 3*y^2 + 6*x + 3*y + 1 - sage: unicode_art(_) # optional - sage.modules + sage: unicode_art(_) ⎛ 1 0 0 0⎞ ⎜ 3 3 0 0⎟ ⎜ 3 8 5 0⎟ @@ -67,7 +68,7 @@ def _matrix_display(self, variables=None): sage: from sage.combinat.triangles_FHM import _matrix_display sage: x, y = PolynomialRing(QQ,['x', 'y']).gens() - sage: _matrix_display(x**2+x*y+y**3) # optional - sage.modules + sage: _matrix_display(x**2+x*y+y**3) # needs sage.modules [1 0 0] [0 0 0] [0 1 0] @@ -76,10 +77,10 @@ def _matrix_display(self, variables=None): With a specific choice of variables:: sage: x, y, z = PolynomialRing(QQ,['x','y','z']).gens() - sage: _matrix_display(x**2+z*x*y+z*y**3+z*x,[y,z]) # optional - sage.modules + sage: _matrix_display(x**2+z*x*y+z*y**3+z*x,[y,z]) # needs sage.modules [ x x 0 1] [x^2 0 0 0] - sage: _matrix_display(x**2+z*x*y+z*y**3+z*x,[x,z]) # optional - sage.modules + sage: _matrix_display(x**2+z*x*y+z*y**3+z*x,[x,z]) # needs sage.modules [ y^3 y + 1 0] [ 0 0 1] """ @@ -124,7 +125,7 @@ class Triangle(SageObject): sage: from sage.combinat.triangles_FHM import Triangle sage: x, y = polygens(ZZ, 'x,y') sage: ht = Triangle(1+4*x+2*x*y) - sage: unicode_art(ht) # optional - sage.modules + sage: unicode_art(ht) # needs sage.modules ⎛0 2⎞ ⎝1 4⎠ """ @@ -136,7 +137,7 @@ def __init__(self, poly, variables=None): sage: from sage.combinat.triangles_FHM import Triangle sage: x, y = polygens(ZZ, 'x,y') sage: ht = Triangle(1+2*x*y) - sage: unicode_art(ht) # optional - sage.modules + sage: unicode_art(ht) # needs sage.modules ⎛0 2⎞ ⎝1 0⎠ """ @@ -156,7 +157,7 @@ def _ascii_art_(self): sage: from sage.combinat.triangles_FHM import H_triangle sage: x, y = polygens(ZZ, 'x,y') sage: ht = H_triangle(1+2*x*y) - sage: ascii_art(ht) # optional - sage.modules + sage: ascii_art(ht) # needs sage.modules [0 2] [1 0] """ @@ -171,7 +172,7 @@ def _unicode_art_(self): sage: from sage.combinat.triangles_FHM import H_triangle sage: x, y = polygens(ZZ, 'x,y') sage: ht = H_triangle(1+2*x*y) - sage: unicode_art(ht) # optional - sage.modules + sage: unicode_art(ht) # needs sage.modules ⎛0 2⎞ ⎝1 0⎠ """ @@ -200,7 +201,7 @@ def _latex_(self): sage: from sage.combinat.triangles_FHM import H_triangle sage: x, y = polygens(ZZ, 'x,y') sage: ht = H_triangle(1+2*x*y) - sage: latex(ht) # optional - sage.modules + sage: latex(ht) # needs sage.modules \left(\begin{array}{rr} 0 & 2 \\ 1 & 0 @@ -296,7 +297,7 @@ def matrix(self): sage: from sage.combinat.triangles_FHM import H_triangle sage: x, y = polygens(ZZ, 'x,y') sage: h = H_triangle(1+2*x*y) - sage: h.matrix() # optional - sage.modules + sage: h.matrix() # needs sage.modules [0 2] [1 0] """ @@ -350,8 +351,8 @@ class M_triangle(Triangle): EXAMPLES:: sage: x, y = polygens(ZZ, 'x,y') - sage: P = Poset({2:[1]}) - sage: P.M_triangle() + sage: P = Poset({2: [1]}) # needs sage.graphs + sage: P.M_triangle() # needs sage.graphs M: x*y - y + 1 """ _prefix = 'M' @@ -398,9 +399,9 @@ def transmute(self): sage: x, y = polygens(ZZ, 'x,y') sage: nc3 = x^2*y^2 - 3*x*y^2 + 3*x*y + 2*y^2 - 3*y + 1 sage: m = M_triangle(nc3) - sage: m2 = m.transmute(); m2 + sage: m2 = m.transmute(); m2 # needs sage.libs.flint M: 2*x^2*y^2 - 3*x*y^2 + 2*x*y + y^2 - 2*y + 1 - sage: m2.transmute() == m + sage: m2.transmute() == m # needs sage.libs.flint True """ return self.h().transpose().m() @@ -557,9 +558,9 @@ def gamma(self): sage: H_triangle(ht).gamma() Γ: y^2 + x - sage: W = SymmetricGroup(5) # optional - sage.groups - sage: P = posets.NoncrossingPartitions(W) # optional - sage.graphs - sage: P.M_triangle().h().gamma() # optional - sage.graphs sage.groups + sage: W = SymmetricGroup(5) # needs sage.groups + sage: P = posets.NoncrossingPartitions(W) # needs sage.graphs sage.groups + sage: P.M_triangle().h().gamma() # needs sage.graphs sage.groups Γ: y^4 + 3*x*y^2 + 2*x^2 + 2*x*y + x """ x, y = self._vars diff --git a/src/sage/combinat/tuple.py b/src/sage/combinat/tuple.py index 8336fb4cbb6..54d1caf9181 100644 --- a/src/sage/combinat/tuple.py +++ b/src/sage/combinat/tuple.py @@ -48,11 +48,12 @@ class Tuples(Parent, UniqueRepresentation): :: - sage: K. = GF(4, 'a') # optional - sage.rings.finite_rings - sage: mset = [x for x in K if x != 0] # optional - sage.rings.finite_rings - sage: Tuples(mset,2).list() # optional - sage.rings.finite_rings - [(a, a), (a + 1, a), (1, a), (a, a + 1), (a + 1, a + 1), (1, a + 1), - (a, 1), (a + 1, 1), (1, 1)] + sage: K. = GF(4, 'a') # needs sage.rings.finite_rings + sage: mset = sorted((x for x in K if x != 0), key=str) # needs sage.rings.finite_rings + sage: Tuples(mset, 2).list() # needs sage.rings.finite_rings + [(1, 1), (a, 1), (a + 1, 1), + (1, a), (a, a), (a + 1, a), + (1, a + 1), (a, a + 1), (a + 1, a + 1)] """ @staticmethod def __classcall_private__(cls, S, k): @@ -116,10 +117,10 @@ def cardinality(self): EXAMPLES:: sage: S = [1,2,3,4,5] - sage: Tuples(S,2).cardinality() # optional - sage.libs.gap + sage: Tuples(S,2).cardinality() 25 sage: S = [1,1,2,3,4,5] - sage: Tuples(S,2).cardinality() # optional - sage.libs.gap + sage: Tuples(S,2).cardinality() 25 """ return ZZ(len(self._index_list)).__pow__(self.k) @@ -201,7 +202,7 @@ def cardinality(self): EXAMPLES:: sage: S = [1,2,3,4,5] - sage: UnorderedTuples(S,2).cardinality() # optional - sage.libs.gap + sage: UnorderedTuples(S,2).cardinality() 15 """ return binomial(len(self._index_list) + self.k - 1, self.k) diff --git a/src/sage/combinat/yang_baxter_graph.py b/src/sage/combinat/yang_baxter_graph.py index 306e8063f63..451bdc9e82e 100644 --- a/src/sage/combinat/yang_baxter_graph.py +++ b/src/sage/combinat/yang_baxter_graph.py @@ -68,7 +68,7 @@ def YangBaxterGraph(partition=None, root=None, operators=None): The ``partition`` keyword is a shorthand for the above construction:: - sage: Y = YangBaxterGraph(partition=[3,1]); Y # optional - sage.combinat + sage: Y = YangBaxterGraph(partition=[3,1]); Y # needs sage.combinat Yang-Baxter graph of [3, 1], with top vertex (0, 2, 1, 0) sage: Y.vertices(sort=True) [(0, 2, 1, 0), (2, 0, 1, 0), (2, 1, 0, 0)] @@ -79,25 +79,27 @@ def YangBaxterGraph(partition=None, root=None, operators=None): sage: swappers = [SwapIncreasingOperator(i) for i in range(3)] sage: Y = YangBaxterGraph(root=(1,2,3,4), operators=swappers); Y Yang-Baxter graph with root vertex (1, 2, 3, 4) - sage: Y.plot() # optional - sage.plot + sage: Y.plot() # needs sage.plot Graphics object consisting of 97 graphics primitives The Cayley graph of a finite group can be realized as a Yang-Baxter graph:: + sage: # needs sage.groups sage: def left_multiplication_by(g): ....: return lambda h: h*g - sage: G = CyclicPermutationGroup(4) # optional - sage.groups - sage: operators = [ left_multiplication_by(gen) for gen in G.gens() ] # optional - sage.groups - sage: Y = YangBaxterGraph(root=G.identity(), operators=operators); Y # optional - sage.groups + sage: G = CyclicPermutationGroup(4) + sage: operators = [ left_multiplication_by(gen) for gen in G.gens() ] + sage: Y = YangBaxterGraph(root=G.identity(), operators=operators); Y Yang-Baxter graph with root vertex () - sage: Y.plot(edge_labels=False) # optional - sage.groups sage.plot + sage: Y.plot(edge_labels=False) # needs sage.plot Graphics object consisting of 9 graphics primitives - sage: G = SymmetricGroup(4) # optional - sage.groups - sage: operators = [left_multiplication_by(gen) for gen in G.gens()] # optional - sage.groups - sage: Y = YangBaxterGraph(root=G.identity(), operators=operators); Y # optional - sage.groups + sage: # needs sage.groups + sage: G = SymmetricGroup(4) + sage: operators = [left_multiplication_by(gen) for gen in G.gens()] + sage: Y = YangBaxterGraph(root=G.identity(), operators=operators); Y Yang-Baxter graph with root vertex () - sage: Y.plot(edge_labels=False) # optional - sage.groups sage.plot + sage: Y.plot(edge_labels=False) # needs sage.plot Graphics object consisting of 96 graphics primitives AUTHORS: @@ -361,8 +363,8 @@ def root(self): sage: Y = YangBaxterGraph(root=(1,0,3,2,1,0), operators=ops) sage: Y.root() (1, 0, 3, 2, 1, 0) - sage: Y = YangBaxterGraph(partition=[3,2]) # optional - sage.combinat - sage: Y.root() + sage: Y = YangBaxterGraph(partition=[3,2]) # needs sage.combinat + sage: Y.root() # needs sage.combinat (1, 0, 2, 1, 0) """ return self._root @@ -392,9 +394,9 @@ def plot(self, *args, **kwds): sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator sage: ops = [SwapIncreasingOperator(i) for i in range(4)] sage: Y = YangBaxterGraph(root=(1,0,2,1,0), operators=ops) - sage: Y.plot() # optional - sage.plot + sage: Y.plot() # needs sage.plot Graphics object consisting of 16 graphics primitives - sage: Y.plot(edge_labels=False) # optional - sage.plot + sage: Y.plot(edge_labels=False) # needs sage.plot Graphics object consisting of 11 graphics primitives """ if "edge_labels" not in kwds: @@ -572,9 +574,9 @@ def __init__(self, partition): EXAMPLES:: - sage: Y = YangBaxterGraph(partition=[3,2,1]); Y # optional - sage.combinat + sage: Y = YangBaxterGraph(partition=[3,2,1]); Y # needs sage.combinat Yang-Baxter graph of [3, 2, 1], with top vertex (0, 1, 0, 2, 1, 0) - sage: loads(dumps(Y)) == Y # optional - sage.combinat + sage: loads(dumps(Y)) == Y # needs sage.combinat True AUTHORS: @@ -592,8 +594,8 @@ def __repr__(self): r""" EXAMPLES:: - sage: Y = YangBaxterGraph(partition=[3,2]) # optional - sage.combinat - sage: Y.__repr__() # optional - sage.combinat + sage: Y = YangBaxterGraph(partition=[3,2]) # needs sage.combinat + sage: Y.__repr__() # needs sage.combinat 'Yang-Baxter graph of [3, 2], with top vertex (1, 0, 2, 1, 0)' """ return "Yang-Baxter graph of %s, with top vertex %s" % (self._partition, self._root) @@ -604,13 +606,14 @@ def __copy__(self): EXAMPLES:: - sage: Y = YangBaxterGraph(partition=[3,2]); Y # optional - sage.combinat + sage: # needs sage.combinat + sage: Y = YangBaxterGraph(partition=[3,2]); Y Yang-Baxter graph of [3, 2], with top vertex (1, 0, 2, 1, 0) - sage: B = copy(Y); B # optional - sage.combinat + sage: B = copy(Y); B Yang-Baxter graph of [3, 2], with top vertex (1, 0, 2, 1, 0) - sage: Y is B # optional - sage.combinat + sage: Y is B False - sage: Y == B # optional - sage.combinat + sage: Y == B True """ from copy import copy @@ -626,10 +629,10 @@ def _digraph(self): EXAMPLES:: - sage: Y = YangBaxterGraph(partition=[2,1]) # optional - sage.combinat - sage: Y._digraph # optional - sage.combinat + sage: Y = YangBaxterGraph(partition=[2,1]) # needs sage.combinat + sage: Y._digraph # needs sage.combinat Digraph on 2 vertices - sage: Y.edges() # optional - sage.combinat + sage: Y.edges() # needs sage.combinat [((0, 1, 0), (1, 0, 0), Swap positions 0 and 1)] """ digraph = super()._digraph @@ -645,8 +648,8 @@ def _vertex_ordering(self): EXAMPLES:: - sage: Y = YangBaxterGraph(partition=[3,2]) # optional - sage.combinat - sage: Y._vertex_ordering # optional - sage.combinat + sage: Y = YangBaxterGraph(partition=[3,2]) # needs sage.combinat + sage: Y._vertex_ordering # needs sage.combinat [(1, 0, 2, 1, 0), (1, 2, 0, 1, 0), (1, 2, 1, 0, 0), (2, 1, 0, 1, 0), (2, 1, 1, 0, 0)] """ return self._digraph.vertices(sort=True) @@ -661,8 +664,8 @@ def __iter__(self): EXAMPLES:: - sage: Y = YangBaxterGraph(partition=[3,2]) # optional - sage.combinat - sage: list(Y.__iter__()) # optional - sage.combinat + sage: Y = YangBaxterGraph(partition=[3,2]) # needs sage.combinat + sage: list(Y.__iter__()) # needs sage.combinat [(1, 0, 2, 1, 0), (1, 2, 0, 1, 0), (1, 2, 1, 0, 0), (2, 1, 0, 1, 0), (2, 1, 1, 0, 0)] """ yield from self._vertex_ordering @@ -679,14 +682,15 @@ def _swap_operator(self, operator, u): EXAMPLES:: - sage: Y = YangBaxterGraph(partition=[3,1]) # optional - sage.combinat - sage: from sage.combinat.yang_baxter_graph import SwapOperator # optional - sage.combinat - sage: ops = [SwapOperator(i) for i in range(3)] # optional - sage.combinat - sage: [Y._swap_operator(op, (1,2,3,4)) for op in ops] # optional - sage.combinat + sage: # needs sage.combinat + sage: Y = YangBaxterGraph(partition=[3,1]) + sage: from sage.combinat.yang_baxter_graph import SwapOperator + sage: ops = [SwapOperator(i) for i in range(3)] + sage: [Y._swap_operator(op, (1,2,3,4)) for op in ops] [(2, 1, 3, 4), (1, 3, 2, 4), (1, 2, 4, 3)] - sage: [Y._swap_operator(op, [4,3,2,1]) for op in ops] # optional - sage.combinat + sage: [Y._swap_operator(op, [4,3,2,1]) for op in ops] [[3, 4, 2, 1], [4, 2, 3, 1], [4, 3, 1, 2]] - sage: [Y._swap_operator(op, Permutation([1,2,3,4])) for op in ops] # optional - sage.combinat + sage: [Y._swap_operator(op, Permutation([1,2,3,4])) for op in ops] [[2, 1, 3, 4], [1, 3, 2, 4], [1, 2, 4, 3]] """ return operator(u) @@ -709,12 +713,12 @@ def vertex_relabelling_dict(self, v): EXAMPLES:: - sage: Y = YangBaxterGraph(partition=[3,1]) # optional - sage.combinat - sage: Y.vertex_relabelling_dict((1,2,3,4)) # optional - sage.combinat + sage: Y = YangBaxterGraph(partition=[3,1]) # needs sage.combinat + sage: Y.vertex_relabelling_dict((1,2,3,4)) # needs sage.combinat {(0, 2, 1, 0): (1, 2, 3, 4), (2, 0, 1, 0): (2, 1, 3, 4), (2, 1, 0, 0): (2, 3, 1, 4)} - sage: Y.vertex_relabelling_dict((4,3,2,1)) # optional - sage.combinat + sage: Y.vertex_relabelling_dict((4,3,2,1)) # needs sage.combinat {(0, 2, 1, 0): (4, 3, 2, 1), (2, 0, 1, 0): (3, 4, 2, 1), (2, 1, 0, 0): (3, 2, 4, 1)} @@ -736,14 +740,15 @@ def relabel_vertices(self, v, inplace=True): EXAMPLES:: - sage: Y = YangBaxterGraph(partition=[3,1]); Y # optional - sage.combinat + sage: # needs sage.combinat + sage: Y = YangBaxterGraph(partition=[3,1]); Y Yang-Baxter graph of [3, 1], with top vertex (0, 2, 1, 0) - sage: d = Y.relabel_vertices((1,2,3,4), inplace=False); d # optional - sage.combinat + sage: d = Y.relabel_vertices((1,2,3,4), inplace=False); d Digraph on 3 vertices - sage: Y.vertices(sort=True) # optional - sage.combinat + sage: Y.vertices(sort=True) [(0, 2, 1, 0), (2, 0, 1, 0), (2, 1, 0, 0)] - sage: e = Y.relabel_vertices((1,2,3,4)); e # optional - sage.combinat - sage: Y.vertices(sort=True) # optional - sage.combinat + sage: e = Y.relabel_vertices((1,2,3,4)); e + sage: Y.vertices(sort=True) [(1, 2, 3, 4), (2, 1, 3, 4), (2, 3, 1, 4)] """ relabelling = self.vertex_relabelling_dict(v) @@ -910,7 +915,7 @@ def __call__(self, u): EXAMPLES:: - sage: Y = YangBaxterGraph(partition=[2,2]) # optional - sage.combinat + sage: Y = YangBaxterGraph(partition=[2,2]) # needs sage.combinat sage: from sage.combinat.yang_baxter_graph import SwapIncreasingOperator sage: operators = [SwapIncreasingOperator(i) for i in range(3)] sage: [op((1,2,3,4)) for op in operators] diff --git a/src/sage/cpython/__init__.py b/src/sage/cpython/__init__.py index 5deff221609..cb262984002 100644 --- a/src/sage/cpython/__init__.py +++ b/src/sage/cpython/__init__.py @@ -12,7 +12,8 @@ # Monkey-patch ExtensionFileLoader to allow IPython to find the sources # of Cython files. See https://github.com/sagemath/sage/issues/24681 from importlib.machinery import ExtensionFileLoader as _ExtensionFileLoader -del _ExtensionFileLoader.get_source +if hasattr(_ExtensionFileLoader, 'get_source'): + del _ExtensionFileLoader.get_source del _ExtensionFileLoader # Work around a Cygwin-specific bug caused by sqlite3; see diff --git a/src/sage/cpython/dict_del_by_value.pyx b/src/sage/cpython/dict_del_by_value.pyx index 19dd2bb2731..fdeb5fee8ff 100644 --- a/src/sage/cpython/dict_del_by_value.pyx +++ b/src/sage/cpython/dict_del_by_value.pyx @@ -46,31 +46,6 @@ cdef extern from "dict_internal.h": PyObject * me_key PyObject * me_value - -# dk_lookup was removed in python 3.11 -DEF HAS_DK_LOOKUP = PY_VERSION_HEX < 0x30b0000 - -IF HAS_DK_LOOKUP: - - cdef extern from *: - """ - #define DK_LOOKUP(dk) ((dk)->dk_lookup) - """ - ctypedef void * dict_lookup_func # Precise definition not needed - dict_lookup_func DK_LOOKUP(PyDictKeysObject *mp) - - cdef dict_lookup_func lookdict - - def init_lookdict(): - global lookdict - # A dict which a non-string key uses the generic "lookdict" - # as lookup function - cdef object D = {} - D[0] = 0 - lookdict = DK_LOOKUP((D).ma_keys) - - init_lookdict() - cdef int del_dictitem_by_exact_value(PyDictObject *mp, PyObject *value, Py_hash_t hash) except -1: """ This is used in callbacks for the weak values of :class:`WeakValueDictionary`. @@ -147,12 +122,6 @@ cdef int del_dictitem_by_exact_value(PyDictObject *mp, PyObject *value, Py_hash_ return 0 ep = &(entries[ix]) - # We need the lookup function to be the generic lookdict, otherwise - # deletions may not work correctly - IF HAS_DK_LOOKUP: - # Can this fail? In any case dk_lookup was removed in python 3.11 - assert DK_LOOKUP(keys) is lookdict - T = PyList_New(2) PyList_SetItem(T, 0, ep.me_key) PyList_SetItem(T, 1, ep.me_value) diff --git a/src/sage/crypto/lwe.py b/src/sage/crypto/lwe.py index db675ebafaa..25bb2a3fb47 100644 --- a/src/sage/crypto/lwe.py +++ b/src/sage/crypto/lwe.py @@ -312,10 +312,10 @@ def __init__(self, n, q, D, secret_dist='uniform', m=None): ... IndexError: Number of available samples exhausted. """ - self.n = ZZ(n) + self.n = ZZ(n) self.m = m self.__i = 0 - self.K = IntegerModRing(q) + self.K = IntegerModRing(q) self.FM = FreeModule(self.K, n) self.D = D @@ -443,7 +443,7 @@ def __init__(self, n, delta=0.01, m=None): s = sqrt(s_t_bound*floor(q/4)) # Transform s into stddev stddev = s/sqrt(2*pi.n()) - D = DiscreteGaussianDistributionIntegerSampler(stddev) + D = DiscreteGaussianDistributionIntegerSampler(stddev) LWE.__init__(self, n=n, q=q, D=D, secret_dist='noise', m=m) @@ -484,11 +484,11 @@ def __init__(self, n, instance='key', m=None): raise TypeError("Parameter too small") n2 = n - C = 4/sqrt(2*pi) + C = 4/sqrt(2*pi) kk = floor((n2-2*log(n2, 2)**2)/5) n1 = (3*n2-5*kk) // 2 ke = floor((n1-2*log(n1, 2)**2)/5) - l = (3*n1-5*ke) // 2 - n2 + l = (3*n1-5*ke) // 2 - n2 sk = ceil((C*(n1+n2))**(ZZ(3)/2)) se = ceil((C*(n1+n2+l))**(ZZ(3)/2)) q = next_prime(max(ceil((4*sk)**(ZZ(n1+n2)/n1)), @@ -499,12 +499,12 @@ def __init__(self, n, instance='key', m=None): raise TypeError("Parameter too small") if instance == 'key': - D = UniformSampler(0, sk-1) + D = UniformSampler(0, sk-1) if m is None: m = n1 LWE.__init__(self, n=n2, q=q, D=D, secret_dist='noise', m=m) elif instance == 'encrypt': - D = UniformSampler(0, se-1) + D = UniformSampler(0, se-1) if m is None: m = n2+l LWE.__init__(self, n=n1, q=q, D=D, secret_dist='noise', m=m) @@ -544,11 +544,11 @@ def __init__(self, N, q, D, poly=None, secret_dist='uniform', m=None): sage: RingLWE(N=20, q=next_prime(800), D=D) # needs sage.libs.pari RingLWE(20, 809, Discrete Gaussian sampler for polynomials of degree < 8 with σ=3.000000 in each component, x^8 - x^6 + x^4 - x^2 + 1, 'uniform', None) """ - self.N = ZZ(N) + self.N = ZZ(N) self.n = euler_phi(N) self.m = m self.__i = 0 - self.K = IntegerModRing(q) + self.K = IntegerModRing(q) if self.n != D.n: raise ValueError("Noise distribution has dimensions %d != %d" % (D.n, self.n)) diff --git a/src/sage/crypto/mq/sr.py b/src/sage/crypto/mq/sr.py index f4ddf5c1844..c4293c5a0e2 100644 --- a/src/sage/crypto/mq/sr.py +++ b/src/sage/crypto/mq/sr.py @@ -1947,7 +1947,7 @@ def key_schedule_polynomials(self, i): si = Matrix(R, r*e, 1, self.vars("s", i-1, r, e)) rc = Matrix(R, r*e, 1, self.phi([a**(i-1)] + [k(0)]*(r-1)) ) - d = Matrix(R, r*e, 1, self.phi([self.sbox_constant()]*r) ) + d = Matrix(R, r*e, 1, self.phi([self.sbox_constant()]*r) ) sbox = [] @@ -3123,8 +3123,8 @@ def _inversion_polynomials_single_sbox(self, x=None, w=None, biaffine_only=None, l.append( (Cw * x + o).list()[:-1] ) else: l.append( (Cw * x + o).list() ) - l.append( (Cw * S * x + x).list() ) - l.append( (Cx * S * w + w).list() ) + l.append( (Cw * S * x + x).list() ) + l.append( (Cx * S * w + w).list() ) if not biaffine_only: l.append( ((Cw * S**2 + Cx*S)*x).list() ) l.append( ((Cx * S**2 + Cw*S)*w).list() ) diff --git a/src/sage/crypto/sboxes.py b/src/sage/crypto/sboxes.py index 27ca13fbcc3..749593c401b 100644 --- a/src/sage/crypto/sboxes.py +++ b/src/sage/crypto/sboxes.py @@ -220,8 +220,8 @@ def carlet_tang_tang_liao(n, c=None, bf=None): if n < 6 or n % 2: raise TypeError("n >= 6 has to be even") - K = GF(2**(n-1)) - L = GF(2**n) + K = GF((2, n - 1)) + L = GF((2, n)) if c is None: c = K.random_element() @@ -392,7 +392,7 @@ def monomial_function(n, e): from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.finite_rings.finite_field_constructor import GF - base_ring = GF(2**n, name='x') + base_ring = GF((2, n), name='x') R = PolynomialRing(base_ring, name='X') X = R.gen() return SBox(X**e) @@ -516,18 +516,18 @@ def monomial_function(n, e): 112,130, 44,236,179, 39,192,229,228,133, 87, 53,234, 12,174, 65, 35,239,107,147, 69, 25,165, 33,237, 14, 79, 78, 29,101,146,189, 134,184,175,143,124,235, 31,206, 62, 48,220, 95, 94,197, 11, 26, - 166,225, 57,202,213, 71, 93, 61,217, 1, 90,214, 81, 86,108, 77, + 166,225, 57,202,213, 71, 93, 61,217, 1, 90,214, 81, 86,108, 77, 139, 13,154,102,251,204,176, 45,116, 18, 43, 32,240,177,132,153, - 223, 76,203,194, 52,126,118, 5,109,183,169, 49,209, 23, 4,215, + 223, 76,203,194, 52,126,118, 5,109,183,169, 49,209, 23, 4,215, 20, 88, 58, 97,222, 27, 17, 28, 50, 15,156, 22, 83, 24,242, 34, - 254, 68,207,178,195,181,122,145, 36, 8,232,168, 96,252,105, 80, + 254, 68,207,178,195,181,122,145, 36, 8,232,168, 96,252,105, 80, 170,208,160,125,161,137, 98,151, 84, 91, 30,149,224,255,100,210, - 16,196, 0, 72,163,247,117,219,138, 3,230,218, 9, 63,221,148, - 135, 92,131, 2,205, 74,144, 51,115,103,246,243,157,127,191,226, + 16,196, 0, 72,163,247,117,219,138, 3,230,218, 9, 63,221,148, + 135, 92,131, 2,205, 74,144, 51,115,103,246,243,157,127,191,226, 82,155,216, 38,200, 55,198, 59,129,150,111, 75, 19,190, 99, 46, 233,121,167,140,159,110,188,142, 41,245,249,182, 47,253,180, 89, - 120,152, 6,106,231, 70,113,186,212, 37,171, 66,136,162,141,250, - 114, 7,185, 85,248,238,172, 10, 54, 73, 42,104, 60, 56,241,164, + 120,152, 6,106,231, 70,113,186,212, 37,171, 66,136,162,141,250, + 114, 7,185, 85,248,238,172, 10, 54, 73, 42,104, 60, 56,241,164, 64, 40,211,123,187,201, 67,193, 21,227,173,244,119,199,128,158]) # source: https://www.schneier.com/academic/paperfiles/paper-cmea.pdf @@ -1063,20 +1063,20 @@ def monomial_function(n, e): newDES = SBox([ 32,137,239,188,102,125,221, 72,212, 68, 81, 37, 86,237,147,149, 70,229, 17,124,115,207, 33, 20,122,143, 25,215, 51,183,138,142, - 146,211,110,173, 1,228,189, 14,103, 78,162, 36,253,167,116,255, - 158, 45,185, 50, 98,168,250,235, 54,141,195,247,240, 63,148, 2, + 146,211,110,173, 1,228,189, 14,103, 78,162, 36,253,167,116,255, + 158, 45,185, 50, 98,168,250,235, 54,141,195,247,240, 63,148, 2, 224,169,214,180, 62, 22,117,108, 19,172,161,159,160, 47, 43,171, - 194,175,178, 56,196,112, 23,220, 89, 21,164,130,157, 8, 85,251, + 194,175,178, 56,196,112, 23,220, 89, 21,164,130,157, 8, 85,251, 216, 44, 94,179,226, 38, 90,119, 40,202, 34,206, 35, 69,231,246, - 29,109, 74, 71,176, 6, 60,145, 65, 13, 77,151, 12,127, 95,199, - 57,101, 5,232,150,210,129, 24,181, 10,121,187, 48,193,139,252, + 29,109, 74, 71,176, 6, 60,145, 65, 13, 77,151, 12,127, 95,199, + 57,101, 5,232,150,210,129, 24,181, 10,121,187, 48,193,139,252, 219, 64, 88,233, 96,128, 80, 53,191,144,218, 11,106,132,155,104, 91,136, 31, 42,243, 66,126,135, 30, 26, 87,186,182,154,242,123, 82,166,208, 39,152,190,113,205,114,105,225, 84, 73,163, 99,111, - 204, 61,200,217,170, 15,198, 28,192,254,134,234,222, 7,236,248, - 201, 41,177,156, 92,131, 67,249,245,184,203, 9,241, 0, 27, 46, - 133,174, 75, 18, 93,209,100,120, 76,213, 16, 83, 4,107,140, 52, - 58, 55, 3,244, 97,197,238,227,118, 49, 79,230,223,165,153, 59]) + 204, 61,200,217,170, 15,198, 28,192,254,134,234,222, 7,236,248, + 201, 41,177,156, 92,131, 67,249,245,184,203, 9,241, 0, 27, 46, + 133,174, 75, 18, 93,209,100,120, 76,213, 16, 83, 4,107,140, 52, + 58, 55, 3,244, 97,197,238,227,118, 49, 79,230,223,165,153, 59]) Picaro = SBox([ 0x08,0x0c,0x03,0x06,0x06,0x04,0x05,0x06,0x05,0x04,0x0c,0x0c,0x04,0x03,0x05,0x03, @@ -1097,22 +1097,22 @@ def monomial_function(n, e): 0x01,0xfd,0x75,0x8a,0xea,0x1c,0x9f,0x6a,0x5f,0xac,0x2d,0xdd,0xbc,0x45,0xcf,0x35]) Safer = SBox([ - 1, 45, 226, 147, 190, 69, 21, 174, 120, 3, 135, 164, 184, 56, 207, 63, - 8, 103, 9, 148, 235, 38, 168, 107, 189, 24, 52, 27, 187, 191, 114, 247, - 64, 53, 72, 156, 81, 47, 59, 85, 227, 192, 159, 216, 211, 243, 141, 177, - 255, 167, 62, 220, 134, 119, 215, 166, 17, 251, 244, 186, 146, 145, 100, 131, - 241, 51, 239, 218, 44, 181, 178, 43, 136, 209, 153, 203, 140, 132, 29, 20, - 129, 151, 113, 202, 95, 163, 139, 87, 60, 130, 196, 82, 92, 28, 232, 160, - 4, 180, 133, 74, 246, 19, 84, 182, 223, 12, 26, 142, 222, 224, 57, 252, - 32, 155, 36, 78, 169, 152, 158, 171, 242, 96, 208, 108, 234, 250, 199, 217, - 0, 212, 31, 110, 67, 188, 236, 83, 137, 254, 122, 93, 73, 201, 50, 194, - 249, 154, 248, 109, 22, 219, 89, 150, 68, 233, 205, 230, 70, 66, 143, 10, - 193, 204, 185, 101, 176, 210, 198, 172, 30, 65, 98, 41, 46, 14, 116, 80, - 2, 90, 195, 37, 123, 138, 42, 91, 240, 6, 13, 71, 111, 112, 157, 126, - 16, 206, 18, 39, 213, 76, 79, 214, 121, 48, 104, 54, 117, 125, 228, 237, - 128, 106, 144, 55, 162, 94, 118, 170, 197, 127, 61, 175, 165, 229, 25, 97, - 253, 77, 124, 183, 11, 238, 173, 75, 34, 245, 231, 115, 35, 33, 200, 5, - 225, 102, 221, 179, 88, 105, 99, 86, 15, 161, 49, 149, 23, 7, 58, 40]) + 1, 45, 226, 147, 190, 69, 21, 174, 120, 3, 135, 164, 184, 56, 207, 63, + 8, 103, 9, 148, 235, 38, 168, 107, 189, 24, 52, 27, 187, 191, 114, 247, + 64, 53, 72, 156, 81, 47, 59, 85, 227, 192, 159, 216, 211, 243, 141, 177, + 255, 167, 62, 220, 134, 119, 215, 166, 17, 251, 244, 186, 146, 145, 100, 131, + 241, 51, 239, 218, 44, 181, 178, 43, 136, 209, 153, 203, 140, 132, 29, 20, + 129, 151, 113, 202, 95, 163, 139, 87, 60, 130, 196, 82, 92, 28, 232, 160, + 4, 180, 133, 74, 246, 19, 84, 182, 223, 12, 26, 142, 222, 224, 57, 252, + 32, 155, 36, 78, 169, 152, 158, 171, 242, 96, 208, 108, 234, 250, 199, 217, + 0, 212, 31, 110, 67, 188, 236, 83, 137, 254, 122, 93, 73, 201, 50, 194, + 249, 154, 248, 109, 22, 219, 89, 150, 68, 233, 205, 230, 70, 66, 143, 10, + 193, 204, 185, 101, 176, 210, 198, 172, 30, 65, 98, 41, 46, 14, 116, 80, + 2, 90, 195, 37, 123, 138, 42, 91, 240, 6, 13, 71, 111, 112, 157, 126, + 16, 206, 18, 39, 213, 76, 79, 214, 121, 48, 104, 54, 117, 125, 228, 237, + 128, 106, 144, 55, 162, 94, 118, 170, 197, 127, 61, 175, 165, 229, 25, 97, + 253, 77, 124, 183, 11, 238, 173, 75, 34, 245, 231, 115, 35, 33, 200, 5, + 225, 102, 221, 179, 88, 105, 99, 86, 15, 161, 49, 149, 23, 7, 58, 40]) Scream = SBox([ 0x20,0x8D,0xB2,0xDA,0x33,0x35,0xA6,0xFF,0x7A,0x52,0x6A,0xC6,0xA4,0xA8,0x51,0x23, @@ -1433,8 +1433,8 @@ def monomial_function(n, e): 20,26,7,31,19,12,10,15,22,30,13,14,4,24,9, 18,27,11,1,21,6,16,2,28,23,5,8,3,0,17,29,25]) -Shamash = SBox([16, 14, 13, 2, 11, 17, 21, 30, 7, 24, 18, 28, 26, 1, 12, 6, - 31, 25, 0, 23, 20, 22, 8, 27, 4, 3, 19, 5, 9, 10, 29, 15]) +Shamash = SBox([16, 14, 13, 2, 11, 17, 21, 30, 7, 24, 18, 28, 26, 1, 12, 6, + 31, 25, 0, 23, 20, 22, 8, 27, 4, 3, 19, 5, 9, 10, 29, 15]) SYCON = SBox([8, 19, 30, 7, 6, 25, 16, 13, 22, 15, 3, 24, 17, 12, 4, 27, 11, 0, 29, 20, 1, 14, 23, 26, 28, 21, 9, 2, 31, 18, 10, 5]) @@ -1444,8 +1444,8 @@ def monomial_function(n, e): Elephant = SBox([0xE, 0xD, 0xB, 0x0, 0x2, 0x1, 0x4, 0xF, 0x7, 0xA, 0x8, 0x5, 0x9, 0xC, 0x3, 0x6]) -KNOT = SBox([0x4, 0x0, 0xA, 0x7, 0xB, 0xE, 0x1, 0xD, 0x9, 0xF, 0x6, 0x8, - 0x5, 0x2, 0xC, 0x3]) +KNOT = SBox([0x4, 0x0, 0xA, 0x7, 0xB, 0xE, 0x1, 0xD, 0x9, 0xF, 0x6, 0x8, + 0x5, 0x2, 0xC, 0x3]) Pyjamask_4 = SBox([0x2, 0xd, 0x3, 0x9, 0x7, 0xb, 0xa, 0x6, 0xe, 0x0, 0xf, 0x4, 0x8, 0x5, 0x1, 0xc]) SATURNIN_0 = SBox([0x0, 0x6, 0xE, 0x1, 0xF, 0x4, 0x7, 0xD, 0x9, 0x8, 0xC, 0x5, @@ -1457,9 +1457,9 @@ def monomial_function(n, e): Clyde = Spook Shadow = Spook TRIFLE = SBox([0x0, 0xC, 0x9, 0x7, 0x3, 0x5, 0xE, 0x4, 0x6, 0xB, 0xA, 0x2, - 0xD, 0x1, 0x8, 0xF]) + 0xD, 0x1, 0x8, 0xF]) Yarara = SBox([0x4, 0x7, 0x1, 0xC, 0x2, 0x8, 0xF, 0x3, 0xD, 0xA, 0xe, 0x9, 0xB, - 0x6, 0x5, 0x0]) + 0x6, 0x5, 0x0]) Coral = Yarara # DES @@ -1570,44 +1570,44 @@ def monomial_function(n, e): SERPENT_S7 = SBox([1,13,15,0,14,8,2,11,7,4,12,10,9,3,5,6]) # Other Block ciphers -KLEIN = SBox([0x7,0x4,0xA,0x9,0x1,0xF,0xB,0x0,0xC,0x3,0x2,0x6,0x8,0xE,0xD,0x5]) -MIBS = SBox([4,15,3,8,13,10,12,0,11,5,7,14,2,6,1,9]) -Midori_Sb0 = SBox([0xc,0xa,0xd,0x3,0xe,0xb,0xf,0x7,0x8,0x9,0x1,0x5,0x0,0x2,0x4,0x6]) +KLEIN = SBox([0x7,0x4,0xA,0x9,0x1,0xF,0xB,0x0,0xC,0x3,0x2,0x6,0x8,0xE,0xD,0x5]) +MIBS = SBox([4,15,3,8,13,10,12,0,11,5,7,14,2,6,1,9]) +Midori_Sb0 = SBox([0xc,0xa,0xd,0x3,0xe,0xb,0xf,0x7,0x8,0x9,0x1,0x5,0x0,0x2,0x4,0x6]) MANTIS = Midori_Sb0 CRAFT = Midori_Sb0 -Midori_Sb1 = SBox([0x1,0x0,0x5,0x3,0xe,0x2,0xf,0x7,0xd,0xa,0x9,0xb,0xc,0x8,0x4,0x6]) -Noekeon = SBox([0x7,0xA,0x2,0xC,0x4,0x8,0xF,0x0,0x5,0x9,0x1,0xE,0x3,0xD,0xB,0x6]) -Piccolo = SBox([0xe,0x4,0xb,0x2,0x3,0x8,0x0,0x9,0x1,0xa,0x7,0xf,0x6,0xc,0x5,0xd]) -Panda = SBox([0x0,0x1,0x3,0x2,0xf,0xc,0x9,0xb,0xa,0x6,0x8,0x7,0x5,0xe,0xd,0x4]) -PRESENT = SBox([0xC,0x5,0x6,0xB,0x9,0x0,0xA,0xD,0x3,0xE,0xF,0x8,0x4,0x7,0x1,0x2]) -CiliPadi = PRESENT -PHOTON = PRESENT -ORANGE = PHOTON -GIFT = SBox([0x1,0xa,0x4,0xc,0x6,0xf,0x3,0x9,0x2,0xd,0xb,0x7,0x5,0x0,0x8,0xe]) -HYENA = GIFT -Fountain_1 = GIFT -TGIF = GIFT -Fountain_2 = SBox([0x9, 0x5, 0x6, 0xD, 0x8, 0xA, 0x7, 0x2, 0xE, 0x4, 0xC, - 0x1, 0xF, 0x0, 0xB, 0x3]) -Fountain_3 = SBox([0x9, 0xD, 0xE, 0x5, 0x8, 0xA, 0xF, 0x2, 0x6, 0xC, 0x4, - 0x1, 0x7, 0x0, 0xB, 0x3]) -Fountain_4 = SBox([0xB, 0xF, 0xE, 0x8, 0x7, 0xA, 0x2, 0xD, 0x9, 0x3, 0x4, - 0xC, 0x5, 0x0, 0x6, 0x1]) -Pride = SBox([0x0,0x4,0x8,0xf,0x1,0x5,0xe,0x9,0x2,0x7,0xa,0xc,0xb,0xd,0x6,0x3]) -PRINCE = SBox([0xB,0xF,0x3,0x2,0xA,0xC,0x9,0x1,0x6,0x7,0x8,0x0,0xE,0x5,0xD,0x4]) -Prost = Pride +Midori_Sb1 = SBox([0x1,0x0,0x5,0x3,0xe,0x2,0xf,0x7,0xd,0xa,0x9,0xb,0xc,0x8,0x4,0x6]) +Noekeon = SBox([0x7,0xA,0x2,0xC,0x4,0x8,0xF,0x0,0x5,0x9,0x1,0xE,0x3,0xD,0xB,0x6]) +Piccolo = SBox([0xe,0x4,0xb,0x2,0x3,0x8,0x0,0x9,0x1,0xa,0x7,0xf,0x6,0xc,0x5,0xd]) +Panda = SBox([0x0,0x1,0x3,0x2,0xf,0xc,0x9,0xb,0xa,0x6,0x8,0x7,0x5,0xe,0xd,0x4]) +PRESENT = SBox([0xC,0x5,0x6,0xB,0x9,0x0,0xA,0xD,0x3,0xE,0xF,0x8,0x4,0x7,0x1,0x2]) +CiliPadi = PRESENT +PHOTON = PRESENT +ORANGE = PHOTON +GIFT = SBox([0x1,0xa,0x4,0xc,0x6,0xf,0x3,0x9,0x2,0xd,0xb,0x7,0x5,0x0,0x8,0xe]) +HYENA = GIFT +Fountain_1 = GIFT +TGIF = GIFT +Fountain_2 = SBox([0x9, 0x5, 0x6, 0xD, 0x8, 0xA, 0x7, 0x2, 0xE, 0x4, 0xC, + 0x1, 0xF, 0x0, 0xB, 0x3]) +Fountain_3 = SBox([0x9, 0xD, 0xE, 0x5, 0x8, 0xA, 0xF, 0x2, 0x6, 0xC, 0x4, + 0x1, 0x7, 0x0, 0xB, 0x3]) +Fountain_4 = SBox([0xB, 0xF, 0xE, 0x8, 0x7, 0xA, 0x2, 0xD, 0x9, 0x3, 0x4, + 0xC, 0x5, 0x0, 0x6, 0x1]) +Pride = SBox([0x0,0x4,0x8,0xf,0x1,0x5,0xe,0x9,0x2,0x7,0xa,0xc,0xb,0xd,0x6,0x3]) +PRINCE = SBox([0xB,0xF,0x3,0x2,0xA,0xC,0x9,0x1,0x6,0x7,0x8,0x0,0xE,0x5,0xD,0x4]) +Prost = Pride Qarma_sigma0 = SBox([0, 14, 2, 10, 9, 15, 8, 11, 6, 4, 3, 7, 13, 12, 1, 5]) Qarma_sigma1 = SBox([10, 13, 14, 6, 15, 7, 3, 5, 9, 8, 0, 12, 11, 1, 2, 4]) -Qameleon = Qarma_sigma1 +Qameleon = Qarma_sigma1 Qarma_sigma2 = SBox([11, 6, 8, 15, 12, 0, 9, 14, 3, 7, 4, 5, 13, 2, 1, 10]) -REC_0 = SBox([0x9,0x4,0xF,0xA,0xE,0x1,0x0,0x6,0xC,0x7,0x3,0x8,0x2,0xB,0x5,0xD]) -Rectangle = SBox([0x6,0x5,0xC,0xA,0x1,0xE,0x7,0x9,0xB,0x0,0x3,0xD,0x8,0xF,0x4,0x2]) -SC2000_4 = SBox([2,5,10,12,7,15,1,11,13,6,0,9,4,8,3,14]) -SKINNY_4 = SBox([0xc,0x6,0x9,0x0,0x1,0xa,0x2,0xb,0x3,0x8,0x5,0xd,0x4,0xe,0x7,0xf]) +REC_0 = SBox([0x9,0x4,0xF,0xA,0xE,0x1,0x0,0x6,0xC,0x7,0x3,0x8,0x2,0xB,0x5,0xD]) +Rectangle = SBox([0x6,0x5,0xC,0xA,0x1,0xE,0x7,0x9,0xB,0x0,0x3,0xD,0x8,0xF,0x4,0x2]) +SC2000_4 = SBox([2,5,10,12,7,15,1,11,13,6,0,9,4,8,3,14]) +SKINNY_4 = SBox([0xc,0x6,0x9,0x0,0x1,0xa,0x2,0xb,0x3,0x8,0x5,0xd,0x4,0xe,0x7,0xf]) ForkSkinny_4 = SKINNY_4 -Remus_4 = SKINNY_4 +Remus_4 = SKINNY_4 -TWINE = SBox([0xC,0x0,0xF,0xA,0x2,0xB,0x9,0x5,0x8,0x3,0xD,0x7,0x1,0xE,0x6,0x4]) +TWINE = SBox([0xC,0x0,0xF,0xA,0x2,0xB,0x9,0x5,0x8,0x3,0xD,0x7,0x1,0xE,0x6,0x4]) # Sub-components of hash functions Luffa_v1 = SBox([0x7,0xd,0xb,0xa,0xc,0x4,0x8,0x3,0x5,0xf,0x6,0x0,0x9,0x1,0x2,0xe]) @@ -1654,10 +1654,10 @@ def monomial_function(n, e): Twofish_Q1_T1 = SBox([0x1,0xE,0x2,0xB,0x4,0xC,0x3,0x7,0x6,0xD,0xA,0x5,0xF,0x9,0x0,0x8]) Twofish_Q1_T2 = SBox([0x4,0xC,0x7,0x5,0x1,0x6,0x9,0xA,0x0,0xE,0xD,0x8,0x2,0xB,0x3,0xF]) Twofish_Q1_T3 = SBox([0xB,0x9,0x5,0x1,0xC,0x3,0xD,0xE,0x6,0x4,0x7,0xF,0x2,0x0,0x8,0xA]) -Kuznyechik_nu0 = SBox([0x2,0x5,0x3,0xb,0x6,0x9,0xe,0xa,0x0,0x4,0xf,0x1,0x8,0xd,0xc,0x7]) -Kuznyechik_nu1 = SBox([0x7,0x6,0xc,0x9,0x0,0xf,0x8,0x1,0x4,0x5,0xb,0xe,0xd,0x2,0x3,0xa]) +Kuznyechik_nu0 = SBox([0x2,0x5,0x3,0xb,0x6,0x9,0xe,0xa,0x0,0x4,0xf,0x1,0x8,0xd,0xc,0x7]) +Kuznyechik_nu1 = SBox([0x7,0x6,0xc,0x9,0x0,0xf,0x8,0x1,0x4,0x5,0xb,0xe,0xd,0x2,0x3,0xa]) Kuznyechik_sigma = SBox([0xc,0xd,0x0,0x4,0x8,0xb,0xa,0xe,0x3,0x9,0x5,0x2,0xf,0x1,0x6,0x7]) -Kuznyechik_phi = SBox([0xb,0x2,0xb,0x8,0xc,0x4,0x1,0xc,0x6,0x3,0x5,0x8,0xe,0x3,0x6,0xb]) +Kuznyechik_phi = SBox([0xb,0x2,0xb,0x8,0xc,0x4,0x1,0xc,0x6,0x3,0x5,0x8,0xe,0x3,0x6,0xb]) Optimal_S0 = SBox([0, 1, 2, 13, 4, 7, 15, 6, 8, 11, 12, 9, 3, 14, 10, 5]) Optimal_S1 = SBox([0, 1, 2, 13, 4, 7, 15, 6, 8, 11, 14, 3, 5, 9, 10, 12]) Optimal_S2 = SBox([0, 1, 2, 13, 4, 7, 15, 6, 8, 11, 14, 3, 10, 12, 5, 9]) diff --git a/src/sage/databases/cremona.py b/src/sage/databases/cremona.py index a74eeac74d2..3e1615e5fd4 100644 --- a/src/sage/databases/cremona.py +++ b/src/sage/databases/cremona.py @@ -1623,7 +1623,7 @@ def _init_allbsd(self, ftpdata, largest_conductor=0): curve_data = [] class_data = [] for L in open(ftpdata + "/" + F).readlines(): - N, iso, num, eqn, rank, tor, cp, om, L, reg, sha = L.split() + N, iso, num, eqn, rank, tor, cp, om, L, reg, sha = L.split() if largest_conductor and int(N) > largest_conductor: break cls = N+iso diff --git a/src/sage/databases/findstat.py b/src/sage/databases/findstat.py index 86ab944744a..5b8455a49a2 100644 --- a/src/sage/databases/findstat.py +++ b/src/sage/databases/findstat.py @@ -263,20 +263,20 @@ def mapping(sigma): ###################################################################### # the FindStat URLs -FINDSTAT_URL = 'https://www.findstat.org/' -FINDSTAT_API = FINDSTAT_URL + "api/" -FINDSTAT_API_COLLECTIONS = FINDSTAT_API + 'CollectionsDatabase/' -FINDSTAT_API_STATISTICS = FINDSTAT_API + 'StatisticsDatabase/' -FINDSTAT_API_MAPS = FINDSTAT_API + 'MapsDatabase/' - -FINDSTAT_URL_LOGIN = FINDSTAT_URL + "?action=login" -FINDSTAT_URL_COLLECTIONS = FINDSTAT_URL + 'CollectionsDatabase/' -FINDSTAT_URL_STATISTICS = FINDSTAT_URL + 'StatisticsDatabase/' +FINDSTAT_URL = 'https://www.findstat.org/' +FINDSTAT_API = FINDSTAT_URL + "api/" +FINDSTAT_API_COLLECTIONS = FINDSTAT_API + 'CollectionsDatabase/' +FINDSTAT_API_STATISTICS = FINDSTAT_API + 'StatisticsDatabase/' +FINDSTAT_API_MAPS = FINDSTAT_API + 'MapsDatabase/' + +FINDSTAT_URL_LOGIN = FINDSTAT_URL + "?action=login" +FINDSTAT_URL_COLLECTIONS = FINDSTAT_URL + 'CollectionsDatabase/' +FINDSTAT_URL_STATISTICS = FINDSTAT_URL + 'StatisticsDatabase/' FINDSTAT_URL_EDIT_STATISTIC = FINDSTAT_URL + 'EditStatistic/' -FINDSTAT_URL_NEW_STATISTIC = FINDSTAT_URL + 'NewStatistic/' -FINDSTAT_URL_MAPS = FINDSTAT_URL + 'MapsDatabase/' -FINDSTAT_URL_EDIT_MAP = FINDSTAT_URL + 'EditMap/' -FINDSTAT_URL_NEW_MAP = FINDSTAT_URL + 'NewMap/' +FINDSTAT_URL_NEW_STATISTIC = FINDSTAT_URL + 'NewStatistic/' +FINDSTAT_URL_MAPS = FINDSTAT_URL + 'MapsDatabase/' +FINDSTAT_URL_EDIT_MAP = FINDSTAT_URL + 'EditMap/' +FINDSTAT_URL_NEW_MAP = FINDSTAT_URL + 'NewMap/' ###################################################################### # the number of values FindStat allows to search for at most @@ -297,9 +297,9 @@ def mapping(sigma): FINDSTAT_STATISTIC_REGEXP = '^St[0-9]{6}$' FINDSTAT_MAP_REGEXP = '^Mp[0-9]{5}$' FINDSTAT_COLLECTION_REGEXP = '^Cc[0-9]{4}$' -FINDSTAT_STATISTIC_PADDED_IDENTIFIER = "St%06d" -FINDSTAT_MAP_PADDED_IDENTIFIER = "Mp%05d" -FINDSTAT_COLLECTION_PADDED_IDENTIFIER = "Cc%04d" +FINDSTAT_STATISTIC_PADDED_IDENTIFIER = "St%06d" +FINDSTAT_MAP_PADDED_IDENTIFIER = "Mp%05d" +FINDSTAT_COLLECTION_PADDED_IDENTIFIER = "Cc%04d" ###################################################################### @@ -333,7 +333,7 @@ def __init__(self): The Combinatorial Statistic Finder (https://www.findstat.org/) """ # user credentials if provided - self._user_name = "" + self._user_name = "" self._user_email = "" self._allow_execution = False @@ -384,7 +384,7 @@ def set_user(self, name=None, email=None): raise ValueError("the given name (%s) should be a string" % name) if not isinstance(email, str): raise ValueError("the given email (%s) should be a string" % email) - self._user_name = name + self._user_name = name self._user_email = email def user_name(self): @@ -2375,14 +2375,14 @@ def submit(self, max_values=FINDSTAT_MAX_SUBMISSION_VALUES): """ args = {} args["OriginalStatistic"] = self.id_str() - args["Domain"] = self.domain().id_str() - args["Values"] = self.first_terms_str(max_values=max_values) - args["Description"] = self.description() - args["References"] = self.references_raw() - args["Code"] = self.code() - args["SageCode"] = self.sage_code() - args["CurrentAuthor"] = FindStat().user_name() - args["CurrentEmail"] = FindStat().user_email() + args["Domain"] = self.domain().id_str() + args["Values"] = self.first_terms_str(max_values=max_values) + args["Description"] = self.description() + args["References"] = self.references_raw() + args["Code"] = self.code() + args["SageCode"] = self.sage_code() + args["CurrentAuthor"] = FindStat().user_name() + args["CurrentEmail"] = FindStat().user_email() if not self.id(): url = FINDSTAT_NEWSTATISTIC_FORM_HEADER % FINDSTAT_URL_NEW_STATISTIC @@ -3212,16 +3212,16 @@ def submit(self): sage: s.reset() # optional -- internet """ args = dict() - args["OriginalMap"] = self.id_str() - args["Domain"] = self.domain().id_str() - args["Codomain"] = self.codomain().id_str() - args["Name"] = self.name() - args["Description"] = self.description() - args["References"] = self.references_raw() - args["Properties"] = self.properties_raw() - args["SageCode"] = self.sage_code() - args["CurrentAuthor"] = FindStat().user_name() - args["CurrentEmail"] = FindStat().user_email() + args["OriginalMap"] = self.id_str() + args["Domain"] = self.domain().id_str() + args["Codomain"] = self.codomain().id_str() + args["Name"] = self.name() + args["Description"] = self.description() + args["References"] = self.references_raw() + args["Properties"] = self.properties_raw() + args["SageCode"] = self.sage_code() + args["CurrentAuthor"] = FindStat().user_name() + args["CurrentEmail"] = FindStat().user_email() if not self.id(): url = FINDSTAT_NEWMAP_FORM_HEADER % FINDSTAT_URL_NEW_MAP @@ -3930,7 +3930,7 @@ def _finite_irreducible_cartan_types_by_rank(n): sage: _finite_irreducible_cartan_types_by_rank(2) [['A', 2], ['B', 2], ['G', 2]] """ - cartan_types = [CartanType(['A',n])] + cartan_types = [CartanType(['A',n])] if n >= 2: cartan_types += [CartanType(['B',n])] if n >= 3: diff --git a/src/sage/databases/knotinfo_db.py b/src/sage/databases/knotinfo_db.py index 2828c3ace45..df0b8310456 100644 --- a/src/sage/databases/knotinfo_db.py +++ b/src/sage/databases/knotinfo_db.py @@ -350,18 +350,18 @@ def __init__(self, install=False): 'linkinfo_data_complete']> """ # some constants - self._names_column = 'name' + self._names_column = 'name' self._components_column = 'components' - self._knot_prefix = 'K' + self._knot_prefix = 'K' self._knot_list = None self._link_list = None - self._demo = None + self._demo = None self._num_knots = None from sage.features.databases import DatabaseKnotInfo from sage.env import DOT_SAGE - self._feature = DatabaseKnotInfo() + self._feature = DatabaseKnotInfo() self._sobj_path = os.path.join(DOT_SAGE, 'knotinfo') def create_filecache(self, force=False): diff --git a/src/sage/doctest/control.py b/src/sage/doctest/control.py index 4a4e8a44737..8583d7a447d 100644 --- a/src/sage/doctest/control.py +++ b/src/sage/doctest/control.py @@ -36,7 +36,6 @@ import sys import time import json -import re import shlex import types import sage.misc.flatten @@ -66,6 +65,7 @@ except ImportError: pass + class DocTestDefaults(SageObject): """ This class is used for doctesting the Sage doctest module. @@ -145,7 +145,7 @@ def __init__(self, **kwds): # automatically anyway. However, this default is still used for # displaying user-defined optional tags and we don't want to see # the auto_optional_tags there. - self.optional = set(['sage']) | auto_optional_tags + self.optional = {'sage'} | auto_optional_tags self.hide = '' self.probe = '' @@ -224,6 +224,7 @@ def skipdir(dirname): return True return False + def skipfile(filename, tested_optional_tags=False, *, if_installed=False, log=None): """ @@ -317,8 +318,8 @@ def skipfile(filename, tested_optional_tags=False, *, return file_tag_string elif tested_optional_tags is not True: - extra = set(tag for tag in file_optional_tags - if tag not in tested_optional_tags) + extra = {tag for tag in file_optional_tags + if tag not in tested_optional_tags} if extra: file_tag_string = unparse_optional_tags(file_optional_tags, prefix='') if log: @@ -445,7 +446,7 @@ def __init__(self, options, args): options.hidden_features = set() if isinstance(options.hide, str): if not len(options.hide): - options.hide = set([]) + options.hide = set() else: s = options.hide.lower() options.hide = set(s.split(',')) @@ -455,12 +456,12 @@ def __init__(self, options, args): if 'all' in options.hide: options.hide.discard('all') from sage.features.all import all_features - feature_names = set([f.name for f in all_features() if not f.is_standard()]) + feature_names = {f.name for f in all_features() if not f.is_standard()} options.hide = options.hide.union(feature_names) if 'optional' in options.hide: options.hide.discard('optional') from sage.features.all import all_features - feature_names = set([f.name for f in all_features() if f.is_optional()]) + feature_names = {f.name for f in all_features() if f.is_optional()} options.hide = options.hide.union(feature_names) options.disabled_optional = set() @@ -1085,7 +1086,7 @@ def sort_sources(self): """ if self.options.nthreads > 1 and len(self.sources) > self.options.nthreads: self.log("Sorting sources by runtime so that slower doctests are run first....") - default = dict(walltime=0) + default = {'walltime': 0} def sort_key(source): basename = source.basename @@ -1153,7 +1154,7 @@ def run_doctests(self): self.cleanup(False) else: self.log("No files to doctest") - self.reporter = DictAsObject(dict(error_status=0, stats={})) + self.reporter = DictAsObject({'error_status': 0, 'stats': {}}) def cleanup(self, final=True): """ @@ -1315,9 +1316,9 @@ def run_val_gdb(self, testing=False): flags = os.getenv("SAGE_MEMCHECK_FLAGS") if flags is None: flags = "--leak-resolution=high --leak-check=full --num-callers=25 " - flags += '''--suppressions="%s" ''' % (os.path.join(SAGE_EXTCODE,"valgrind","pyalloc.supp")) - flags += '''--suppressions="%s" ''' % (os.path.join(SAGE_EXTCODE,"valgrind","sage.supp")) - flags += '''--suppressions="%s" ''' % (os.path.join(SAGE_EXTCODE,"valgrind","sage-additional.supp")) + flags += '''--suppressions="%s" ''' % (os.path.join(SAGE_EXTCODE,"valgrind", "pyalloc.supp")) + flags += '''--suppressions="%s" ''' % (os.path.join(SAGE_EXTCODE,"valgrind", "sage.supp")) + flags += '''--suppressions="%s" ''' % (os.path.join(SAGE_EXTCODE,"valgrind", "sage-additional.supp")) elif opt.massif: toolname = "massif" flags = os.getenv("SAGE_MASSIF_FLAGS", "--depth=6 ") diff --git a/src/sage/doctest/forker.py b/src/sage/doctest/forker.py index 6c3b0b225ac..05bd5d0fd8e 100644 --- a/src/sage/doctest/forker.py +++ b/src/sage/doctest/forker.py @@ -687,10 +687,10 @@ def compiler(example): # findlinestarts() returns pairs (index, lineno) where # "index" is the index in the bytecode where the line # number changes to "lineno". - linenumbers1 = set(lineno for (index, lineno) - in findlinestarts(code)) - linenumbers2 = set(lineno for (index, lineno) - in findlinestarts(execcode)) + linenumbers1 = {lineno for (index, lineno) + in findlinestarts(code)} + linenumbers2 = {lineno for (index, lineno) + in findlinestarts(execcode)} if linenumbers1 != linenumbers2: raise SyntaxError("doctest is not a single statement") @@ -1726,7 +1726,7 @@ def serial_dispatch(self): with tempfile.TemporaryFile() as outtmpfile: result = DocTestTask(source)(self.controller.options, - outtmpfile, self.controller.logger) + outtmpfile, self.controller.logger) outtmpfile.seek(0) output = bytes_to_str(outtmpfile.read()) @@ -2334,7 +2334,7 @@ def save_result_output(self): try: self.result = self.result_queue.get(block=False) except Empty: - self.result = (0, DictAsObject(dict(err='noresult'))) + self.result = (0, DictAsObject({'err': 'noresult'})) del self.result_queue self.outtmpfile.seek(0) @@ -2536,17 +2536,17 @@ def __call__(self, options, outtmpfile=None, msgfile=None, result_queue=None): result = None try: runner = SageDocTestRunner( - SageOutputChecker(), - verbose=options.verbose, - outtmpfile=outtmpfile, - msgfile=msgfile, - sage_options=options, - optionflags=doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS) + SageOutputChecker(), + verbose=options.verbose, + outtmpfile=outtmpfile, + msgfile=msgfile, + sage_options=options, + optionflags=doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS) runner.basename = self.source.basename runner.filename = self.source.path N = options.file_iterations - results = DictAsObject(dict(walltime=[], cputime=[], - err=None, walltime_skips=0)) + results = DictAsObject({'walltime': [], 'cputime': [], + 'err': None, 'walltime_skips': 0}) # multiprocessing.Process instances don't run exit # functions, so we run the functions added by doctests @@ -2571,7 +2571,7 @@ def __call__(self, options, outtmpfile=None, msgfile=None, result_queue=None): except BaseException: exc_info = sys.exc_info() tb = "".join(traceback.format_exception(*exc_info)) - result = (0, DictAsObject(dict(err=exc_info[0], tb=tb))) + result = (0, DictAsObject({'err': exc_info[0], 'tb': tb})) if result_queue is not None: result_queue.put(result, False) diff --git a/src/sage/doctest/parsing.py b/src/sage/doctest/parsing.py index 5c37ea1422b..32d15b4c720 100644 --- a/src/sage/doctest/parsing.py +++ b/src/sage/doctest/parsing.py @@ -94,7 +94,7 @@ def fake_RIFtol(*args): ansi_escape_sequence = re.compile(r'(\x1b[@-Z\\-~]|\x1b\[.*?[@-~]|\x9b.*?[@-~])') special_optional_regex = 'arb216|arb218|py2|long time|not implemented|not tested|known bug' -tag_with_explanation_regex = fr'((?:\w|[.])+)\s*(?:\((.*?)\))?' +tag_with_explanation_regex = r'((?:\w|[.])+)\s*(?:\((.*?)\))?' optional_regex = re.compile(fr'(?P{special_optional_regex})\s*(?:\((?P.*?)\))?|' fr'[^ a-z]\s*(optional|needs)(?:\s|[:-])*(?P(?:(?:{tag_with_explanation_regex})\s*)*)', re.IGNORECASE) @@ -470,7 +470,7 @@ def update_optional_tags(line, tags=None, *, add_tags=None, remove_tags=None, fo | V V V V V V v v v v | sage: # optional - magma, needs sage.symbolic """ - if not (m := re.match('( *sage: *)(.*)', line)): + if not re.match('( *sage: *)(.*)', line): raise ValueError(f'line must start with a sage: prompt, got: {line}') current_tags, line_sans_tags, is_persistent = parse_optional_tags(line.rstrip(), return_string_sans_tags=True) @@ -1140,8 +1140,8 @@ def update_tag_counts(optional_tags): def check_and_clear_tag_counts(): if (num_examples := tag_count_within_block['']) >= 4: - if overused_tags := set(tag for tag, count in tag_count_within_block.items() - if tag and count >= num_examples): + if overused_tags := {tag for tag, count in tag_count_within_block.items() + if tag and count >= num_examples}: overused_tags.update(persistent_optional_tags) overused_tags.difference_update(self.file_optional_tags) suggested = unparse_optional_tags(overused_tags, prefix='sage: # ') @@ -1210,10 +1210,10 @@ def check_and_clear_tag_counts(): continue if self.optional_tags is not True: - extra = set(tag - for tag in optional_tags - if (tag not in self.optional_tags - and tag not in available_software)) + extra = {tag + for tag in optional_tags + if (tag not in self.optional_tags + and tag not in available_software)} if extra: if any(tag in external_software for tag in extra): # never probe "external" software diff --git a/src/sage/doctest/reporting.py b/src/sage/doctest/reporting.py index 5ef3e29a0a6..a86153ce326 100644 --- a/src/sage/doctest/reporting.py +++ b/src/sage/doctest/reporting.py @@ -116,7 +116,7 @@ def __init__(self, controller): sage: DTR = DocTestReporter(DC) """ self.controller = controller - self.postscript = dict(lines=[], cputime=0, walltime=0) + self.postscript = {"lines": [], "cputime": 0, "walltime": 0} self.sources_completed = 0 self.stats = {} self.error_status = 0 @@ -408,7 +408,7 @@ def report(self, source, timeout, return_code, results, output, pid=None): ntests, result_dict = results except (TypeError, ValueError): ntests = 0 - result_dict = DictAsObject(dict(err='badresult')) + result_dict = DictAsObject({"err": 'badresult'}) if timeout: fail_msg = "Timed out" if ntests > 0: @@ -429,7 +429,7 @@ def report(self, source, timeout, return_code, results, output, pid=None): log(output) log("*"*70) postscript['lines'].append(cmd + " # %s" % fail_msg) - stats[basename] = dict(failed=True, walltime=1e6, ntests=ntests) + stats[basename] = {"failed": True, "walltime": 1e6, "ntests": ntests} if not the_baseline_stats.get('failed', False): self.error_status |= 4 elif return_code: @@ -445,7 +445,7 @@ def report(self, source, timeout, return_code, results, output, pid=None): log(output) log("*"*70) postscript['lines'].append(cmd + " # %s" % fail_msg) - stats[basename] = dict(failed=True, walltime=1e6, ntests=ntests) + stats[basename] = {"failed": True, "walltime": 1e6, "ntests": ntests} if not the_baseline_stats.get('failed', False): self.error_status |= (8 if return_code > 0 else 16) else: @@ -501,9 +501,9 @@ def report(self, source, timeout, return_code, results, output, pid=None): if hasattr(result_dict, 'tb'): log(result_dict.tb) if hasattr(result_dict, 'walltime'): - stats[basename] = dict(failed=True, walltime=wall, ntests=ntests) + stats[basename] = {"failed": True, "walltime": wall, "ntests": ntests} else: - stats[basename] = dict(failed=True, walltime=1e6, ntests=ntests) + stats[basename] = {"failed": True, "walltime": 1e6, "ntests": ntests} self.error_status |= 64 if result_dict.err is None or result_dict.err == 'tab': f = result_dict.failures @@ -515,16 +515,16 @@ def report(self, source, timeout, return_code, results, output, pid=None): if not the_baseline_stats.get('failed', False): self.error_status |= 1 if f or result_dict.err == 'tab': - stats[basename] = dict(failed=True, walltime=wall, ntests=ntests) + stats[basename] = {"failed": True, "walltime": wall, "ntests": ntests} else: - stats[basename] = dict(walltime=wall, ntests=ntests) + stats[basename] = {"walltime": wall, "ntests": ntests} postscript['cputime'] += cpu postscript['walltime'] += wall try: optionals = result_dict.optionals except AttributeError: - optionals = dict() + optionals = {} for tag in sorted(optionals): nskipped = optionals[tag] if tag == "long time": diff --git a/src/sage/doctest/sources.py b/src/sage/doctest/sources.py index 5064496052b..8c7b29bf1d4 100644 --- a/src/sage/doctest/sources.py +++ b/src/sage/doctest/sources.py @@ -233,7 +233,7 @@ def _process_doc(self, doctests, doc, namespace, start): new_doctests = self.parse_docstring(docstring, namespace, start) sig_on_count_doc_doctest = "sig_on_count() # check sig_on/off pairings (virtual doctest)\n" for dt in new_doctests: - if len(dt.examples) > 0 and not (hasattr(dt.examples[-1],'sage_source') + if len(dt.examples) > 0 and not (hasattr(dt.examples[-1], 'sage_source') and dt.examples[-1].sage_source == sig_on_count_doc_doctest): # Line number refers to the end of the docstring sigon = doctest.Example(sig_on_count_doc_doctest, "0\n", lineno=docstring.count("\n")) @@ -305,7 +305,7 @@ def _create_doctests(self, namespace, tab_okay=None): False """ if tab_okay is None: - tab_okay = isinstance(self,TexSource) + tab_okay = isinstance(self, TexSource) self._init() self.line_shift = 0 self.parser = SageDocTestParser(self.options.optional, @@ -371,9 +371,9 @@ def _create_doctests(self, namespace, tab_okay=None): if unparsed_doc: self._process_doc(doctests, doc, namespace, start) - extras = dict(tab=not tab_okay and tab_locations, - line_number=contains_line_number, - optionals=self.parser.optionals) + extras = {"tab": not tab_okay and tab_locations, + "line_number": contains_line_number, + "optionals": self.parser.optionals} if self.options.randorder is not None and self.options.randorder is not False: # we want to randomize even when self.randorder = 0 random.seed(self.options.randorder) @@ -569,13 +569,13 @@ def __init__(self, path, options): base, ext = os.path.splitext(path) valid_code_ext = ('.py', '.pyx', '.pxd', '.pxi', '.sage', '.spyx') if ext in valid_code_ext: - self.__class__ = dynamic_class('PythonFileSource',(FileDocTestSource,PythonSource)) + self.__class__ = dynamic_class('PythonFileSource', (FileDocTestSource, PythonSource)) self.encoding = "utf-8" elif ext == '.tex': - self.__class__ = dynamic_class('TexFileSource',(FileDocTestSource,TexSource)) + self.__class__ = dynamic_class('TexFileSource', (FileDocTestSource, TexSource)) self.encoding = "utf-8" elif ext == '.rst' or ext == '.rst.txt': - self.__class__ = dynamic_class('RestFileSource',(FileDocTestSource,RestSource)) + self.__class__ = dynamic_class('RestFileSource', (FileDocTestSource, RestSource)) self.encoding = "utf-8" else: valid_ext = ", ".join(valid_code_ext + ('.tex', '.rst', '.rst.txt')) @@ -955,6 +955,7 @@ def parse_docstring(self, docstring, namespace, start): return [self.parser.get_doctest(docstring, namespace, str(self.qualified_name), self.printpath, start + 1)] + class PythonSource(SourceLanguage): """ This class defines the functions needed for the extraction of doctests from python sources. @@ -1252,6 +1253,7 @@ def _neutralize_doctests(self, reindent): neutralized.append(" "*reindent + line) return "".join(neutralized) + class TexSource(SourceLanguage): """ This class defines the functions needed for the extraction of @@ -1628,6 +1630,7 @@ def parse_docstring(self, docstring, namespace, start): self.printpath, start + 1) return [outer_doctest] + inner_doctests + class DictAsObject(dict): """ A simple subclass of dict that inserts the items from the initializing dictionary into attributes. diff --git a/src/sage/doctest/util.py b/src/sage/doctest/util.py index c7774a6472b..b68068a0ce1 100644 --- a/src/sage/doctest/util.py +++ b/src/sage/doctest/util.py @@ -81,7 +81,7 @@ def dict_difference(self, other): sage: dict_difference(D2.__dict__, D1.__dict__) {'foobar': 'hello', 'timeout': 100} """ - D = dict() + D = {} for k, v in self.items(): try: if other[k] == v: @@ -275,8 +275,8 @@ def start(self): sage: D.start(); D.set set() """ - self.set = set([]) - self.got = set([]) + self.set = set() + self.got = set() def __getitem__(self, name): """ diff --git a/src/sage/dynamics/arithmetic_dynamics/projective_ds.py b/src/sage/dynamics/arithmetic_dynamics/projective_ds.py index 606d991b692..8ade7f9b31b 100644 --- a/src/sage/dynamics/arithmetic_dynamics/projective_ds.py +++ b/src/sage/dynamics/arithmetic_dynamics/projective_ds.py @@ -117,10 +117,7 @@ class initialization directly. lazy_import('sage.rings.padics.factory', 'Qp') lazy_import('sage.rings.qqbar', 'number_field_elements_from_algebraics') -try: - from sage.libs.pari.all import PariError -except ImportError: - PariError = () +from sage.libs.pari.all import PariError class DynamicalSystem_projective(SchemeMorphism_polynomial_projective_space, diff --git a/src/sage/env.py b/src/sage/env.py index b1fe9a89cd1..4515e90e912 100644 --- a/src/sage/env.py +++ b/src/sage/env.py @@ -417,8 +417,8 @@ def cython_aliases(required_modules=None, elif lib == 'ecl': try: # Determine ecl-specific compiler arguments using the ecl-config script - ecl_cflags = subprocess.run([ECL_CONFIG, "--cflags"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).stdout.split() - ecl_libs = subprocess.run([ECL_CONFIG, "--libs"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).stdout.split() + ecl_cflags = subprocess.run([ECL_CONFIG, "--cflags"], check=True, capture_output=True, text=True).stdout.split() + ecl_libs = subprocess.run([ECL_CONFIG, "--libs"], check=True, capture_output=True, text=True).stdout.split() except subprocess.CalledProcessError: if required: raise diff --git a/src/sage/ext/cplusplus.pxd b/src/sage/ext/cplusplus.pxd index e504f0c9fbb..d748bf2347a 100644 --- a/src/sage/ext/cplusplus.pxd +++ b/src/sage/ext/cplusplus.pxd @@ -8,7 +8,7 @@ # http://www.gnu.org/licenses/ #***************************************************************************** -cdef extern from "sage/ext/ccobject.h": +cdef extern from "ccobject.h": # Print representation of any C++ object str ccrepr[T](const T& x) diff --git a/src/sage/features/__init__.py b/src/sage/features/__init__.py index 89a7b184a4c..cabd63a1a24 100644 --- a/src/sage/features/__init__.py +++ b/src/sage/features/__init__.py @@ -572,7 +572,7 @@ def package_systems(): # Try to use scripts from SAGE_ROOT (or an installation of sage_bootstrap) # to obtain system package advice. try: - proc = run('sage-guess-package-system', shell=True, stdout=PIPE, stderr=PIPE, universal_newlines=True, check=True) + proc = run('sage-guess-package-system', shell=True, capture_output=True, text=True, check=True) system_name = proc.stdout.strip() if system_name != 'unknown': _cache_package_systems = [PackageSystem(system_name)] diff --git a/src/sage/features/latex.py b/src/sage/features/latex.py index 48b4576961c..874c5ca7bfb 100644 --- a/src/sage/features/latex.py +++ b/src/sage/features/latex.py @@ -243,8 +243,7 @@ def absolute_filename(self) -> str: from subprocess import run, CalledProcessError, PIPE try: proc = run(['kpsewhich', self.filename], - stdout=PIPE, stderr=PIPE, - universal_newlines=True, check=True) + capture_output=True, text=True, check=True) return proc.stdout.strip() except CalledProcessError: reason = "{filename!r} not found by kpsewhich".format(filename=self.filename) diff --git a/src/sage/features/pkg_systems.py b/src/sage/features/pkg_systems.py index 8485fab0c7d..72ecd494344 100644 --- a/src/sage/features/pkg_systems.py +++ b/src/sage/features/pkg_systems.py @@ -73,11 +73,11 @@ def _spkg_installation_hint(self, spkgs, prompt, feature): system = self.name try: proc = run(f'sage-get-system-packages {system} {spkgs}', - shell=True, stdout=PIPE, stderr=PIPE, universal_newlines=True, check=True) + shell=True, capture_output=True, text=True, check=True) system_packages = proc.stdout.strip() print_sys = f'sage-print-system-package-command {system} --verbose --sudo --prompt="{prompt}"' command = f'{print_sys} update && {print_sys} install {system_packages}' - proc = run(command, shell=True, stdout=PIPE, stderr=PIPE, universal_newlines=True, check=True) + proc = run(command, shell=True, capture_output=True, text=True, check=True) command = proc.stdout.strip() if command: lines.append(f'To install {feature} using the {system} package manager, you can try to run:') diff --git a/src/sage/features/sagemath.py b/src/sage/features/sagemath.py index 7404e6d0a8e..bc34d35dd1c 100644 --- a/src/sage/features/sagemath.py +++ b/src/sage/features/sagemath.py @@ -389,7 +389,19 @@ def __init__(self): """ JoinFeature.__init__(self, 'sage.libs.gap', [PythonModule('sage.libs.gap.libgap'), - PythonModule('sage.interfaces.gap')]) + PythonModule('sage.interfaces.gap'), + PythonModule('sage.groups.matrix_gps.finitely_generated_gap'), + PythonModule('sage.groups.matrix_gps.group_element_gap'), + PythonModule('sage.groups.matrix_gps.heisenberg'), + PythonModule('sage.groups.matrix_gps.isometries'), + PythonModule('sage.groups.matrix_gps.linear_gap'), + PythonModule('sage.groups.matrix_gps.matrix_group_gap'), + PythonModule('sage.groups.matrix_gps.named_group_gap'), + PythonModule('sage.groups.matrix_gps.orthogonal_gap'), + PythonModule('sage.groups.matrix_gps.symplectic_gap'), + PythonModule('sage.groups.matrix_gps.unitary_gap'), + PythonModule('sage.matrix.matrix_gap'), + PythonModule('sage.rings.universal_cyclotomic_field')]) class sage__libs__linbox(JoinFeature): @@ -397,8 +409,8 @@ class sage__libs__linbox(JoinFeature): A :class:`sage.features.Feature` describing the presence of :mod:`sage.libs.linbox` and other modules depending on Givaro, FFLAS-FFPACK, LinBox. - In addition to the modularization purposes that this tag serves, - it also provides attribution to the upstream project. + In addition to the modularization purposes that this tag serves, it also provides attribution + to the upstream project. TESTS:: @@ -415,7 +427,9 @@ def __init__(self): True """ JoinFeature.__init__(self, 'sage.libs.linbox', - [PythonModule('sage.rings.finite_rings.element_givaro')], + [PythonModule('sage.rings.finite_rings.element_givaro'), + PythonModule('sage.matrix.matrix_modn_dense_float'), + PythonModule('sage.matrix.matrix_modn_dense_double')], spkg='sagemath_linbox', type='standard') @@ -442,7 +456,8 @@ def __init__(self): True """ JoinFeature.__init__(self, 'sage.libs.m4ri', - [PythonModule('sage.matrix.matrix_gf2e_dense')], + [PythonModule('sage.matrix.matrix_gf2e_dense'), + PythonModule('sage.matrix.matrix_mod2_dense')], spkg='sagemath_m4ri', type='standard') @@ -708,7 +723,8 @@ def __init__(self): """ JoinFeature.__init__(self, 'sage.rings.finite_rings', [PythonModule('sage.rings.finite_rings.element_pari_ffelt'), - PythonModule('sage.rings.algebraic_closure_finite_field')], + PythonModule('sage.rings.algebraic_closure_finite_field'), + sage__libs__pari()], type='standard') @@ -784,8 +800,8 @@ class sage__rings__number_field(JoinFeature): sage: CC(zeta) 0.913545457642601 + 0.406736643075800*I - Doctests that make use of the algebraic field ``QQbar``, the algebraic real field ``AA``, - or the universal cyclotomic field should be marked likewise:: + Doctests that make use of the algebraic field ``QQbar`` or the algebraic real field ``AA`` + should be marked likewise:: sage: # needs sage.rings.number_field sage: AA(-1)^(1/3) @@ -793,7 +809,10 @@ class sage__rings__number_field(JoinFeature): sage: QQbar(-1)^(1/3) 0.500000000000000? + 0.866025403784439?*I - sage: # needs sage.rings.number_field + Use of the universal cyclotomic field should be marked + ``# needs sage.libs.gap sage.rings.number_field``. + + sage: # needs sage.libs.gap sage.rings.number_field sage: UCF = UniversalCyclotomicField(); UCF Universal Cyclotomic Field sage: E = UCF.gen diff --git a/src/sage/games/hexad.py b/src/sage/games/hexad.py index 7b3af6f49d7..ddc08530b08 100644 --- a/src/sage/games/hexad.py +++ b/src/sage/games/hexad.py @@ -1,5 +1,5 @@ r""" -Hexads in S(5,6,12) +Hexads in S(5, 6, 12) This module completes a 5-element subset of a 12-set `X` into a hexad in a Steiner system `S(5, 6, 12)` using Curtis @@ -34,13 +34,13 @@ The corresponding MINIMOG is:: - +-----+-----+-----+-----+ - | 6 | 3 | 0 | 9 | - +-----+-----+-----+-----+ - | 5 | 2 | 7 | 10 | - +-----+-----+-----+-----+ - | 4 | 1 | 8 | 11 | - +-----+-----+-----+-----+ + ┌─────┬─────┬─────┬─────┐ + │ 6 │ 3 │ 0 │ 9 │ + ├─────┼─────┼─────┼─────┤ + │ 5 │ 2 │ 7 │ 10 │ + ├─────┼─────┼─────┼─────┤ + │ 4 │ 1 │ 8 │ 11 │ + └─────┴─────┴─────┴─────┘ which is specified by the global variable ``minimog_shuffle``. @@ -61,7 +61,7 @@ - [KR2001]_ -Some details are also online at: http://www.permutationpuzzles.org/hexad/ +Some details are also online at: https://www.permutationpuzzles.org/hexad/ """ # **************************************************************************** # Copyright (C) 2005 David Joyner @@ -104,10 +104,10 @@ def view_list(L): [1 1 0] [1 1 0] """ - return matrix(GF(2), 3, 3, lambda x, y: 1 if (x,y) in L else 0) + return matrix(GF(2), 3, 3, lambda x, y: 1 if (x, y) in L else 0) -def picture_set(A, L): +def picture_set(A, L) -> set: """ This is needed in the :meth:`Minimog.find_hexad` function below. @@ -120,10 +120,10 @@ def picture_set(A, L): sage: picture_set(M.picture02, M.square[7]) {2, 3, 5, 8} """ - return set([A[x] for x in L]) + return {A[x] for x in L} -class Minimog(): +class Minimog: r""" This implements the Conway/Curtis minimog idea for describing the Steiner triple system `S(5, 6, 12)`. @@ -141,9 +141,9 @@ class Minimog(): """ def __init__(self, type="shuffle"): self.type = type - MS34 = MatrixSpace(SR,3,4) - minimog_modulo11 = MS34([[0,3,infinity,2],[5,9,8,10],[4,1,6,7]]) - minimog_shuffle = MS34([[6,3,0,9],[5,2,7,10],[4,1,8,11]]) + MS34 = MatrixSpace(SR, 3, 4) + minimog_modulo11 = MS34([[0, 3, infinity, 2], [5, 9, 8, 10], [4, 1, 6, 7]]) + minimog_shuffle = MS34([[6, 3, 0, 9], [5, 2, 7, 10], [4, 1, 8, 11]]) if type == "shuffle": self.minimog = minimog_shuffle elif type == "modulo11": @@ -151,75 +151,75 @@ def __init__(self, type="shuffle"): else: raise ValueError("that Minimog type is not implemented") # This initializes the variables in the game. - MS34 = MatrixSpace(SR,3,4) + MS34 = MatrixSpace(SR, 3, 4) A = self.minimog - MS33 = MatrixSpace(SR,3,3) - self.picture00 = MS33([[A[(1,0)],A[(2,3)],A[(0,1)]],[A[(2,2)],A[(1,1)],A[(2,0)]],[A[(0,3)],A[(1,3)],A[(1,2)]]]) - ####### self.picture00 is the "picture at 6" - self.picture02 = MS33([[A[(1,0)],A[(2,3)],A[(0,1)]],[A[(1,1)],A[(2,0)],A[(2,2)]],[A[(1,2)],A[(0,3)],A[(1,3)]]]) - ####### self.picture02 is the "picture at 1" - self.picture21 = MS33([[A[(2,2)],A[(1,3)],A[(0,1)]],[A[(0,3)],A[(2,3)],A[(2,0)]],[A[(1,0)],A[(1,1)],A[(1,2)]]]) - ####### self.picture21 is the "picture at 0" + MS33 = MatrixSpace(SR, 3, 3) + self.picture00 = MS33([[A[(1, 0)], A[(2, 3)], A[(0, 1)]], [A[(2, 2)], A[(1, 1)], A[(2, 0)]], [A[(0, 3)], A[(1, 3)], A[(1, 2)]]]) + # self.picture00 is the "picture at 6" + self.picture02 = MS33([[A[(1, 0)], A[(2, 3)], A[(0, 1)]], [A[(1, 1)], A[(2, 0)], A[(2, 2)]], [A[(1, 2)], A[(0, 3)], A[(1, 3)]]]) + # self.picture02 is the "picture at 1" + self.picture21 = MS33([[A[(2, 2)], A[(1, 3)], A[(0, 1)]], [A[(0, 3)], A[(2, 3)], A[(2, 0)]], [A[(1, 0)], A[(1, 1)], A[(1, 2)]]]) + # self.picture21 is the "picture at 0" self.line = list(range(12)) - self.line[0] = set([(0,0),(0,1),(0,2)]) - self.line[1] = set([(1,0),(1,1),(1,2)]) - self.line[2] = set([(2,0),(2,1),(2,2)]) - self.line[3] = set([(0,2),(1,2),(2,2)]) - self.line[4] = set([(0,1),(1,1),(2,1)]) - self.line[5] = set([(0,0),(1,0),(2,0)]) - self.line[6] = set([(0,0),(1,1),(2,2)]) - self.line[7] = set([(2,0),(0,1),(1,2)]) - self.line[8] = set([(0,2),(1,0),(2,1)]) - self.line[9] = set([(2,0),(1,1),(0,2)]) - self.line[10] = set([(0,0),(1,2),(2,1)]) - self.line[11] = set([(1,0),(0,1),(2,2)]) + self.line[0] = {(0, 0), (0, 1), (0, 2)} + self.line[1] = {(1, 0), (1, 1), (1, 2)} + self.line[2] = {(2, 0), (2, 1), (2, 2)} + self.line[3] = {(0, 2), (1, 2), (2, 2)} + self.line[4] = {(0, 1), (1, 1), (2, 1)} + self.line[5] = {(0, 0), (1, 0), (2, 0)} + self.line[6] = {(0, 0), (1, 1), (2, 2)} + self.line[7] = {(2, 0), (0, 1), (1, 2)} + self.line[8] = {(0, 2), (1, 0), (2, 1)} + self.line[9] = {(2, 0), (1, 1), (0, 2)} + self.line[10] = {(0, 0), (1, 2), (2, 1)} + self.line[11] = {(1, 0), (0, 1), (2, 2)} self.cross = list(range(18)) - self.cross[0] = set([(0,0),(0,1),(0,2),(1,0),(2,0)]) - self.cross[1] = set([(0,0),(0,1),(0,2),(1,2),(2,2)]) - self.cross[2] = set([(0,0),(1,0),(2,0),(2,1),(2,2)]) - self.cross[3] = set([(2,0),(2,1),(2,2),(0,2),(1,2)]) - self.cross[4] = set([(0,0),(0,1),(0,2),(1,1),(2,1)]) - self.cross[5] = set([(0,0),(1,0),(2,0),(1,1),(1,2)]) - self.cross[6] = set([(1,0),(1,1),(1,2),(0,2),(2,2)]) - self.cross[7] = set([(0,1),(1,1),(2,1),(2,0),(2,2)]) - self.cross[8] = set([(0,0),(0,1),(1,0),(1,1),(2,2)]) - self.cross[9] = set([(0,0),(1,1),(1,2),(2,1),(2,2)]) - self.cross[10] = set([(2,0),(2,1),(1,0),(1,1),(0,2)]) - self.cross[11] = set([(0,1),(0,2),(1,1),(1,2),(2,0)]) - self.cross[12] = set([(0,0),(1,0),(0,2),(1,2),(2,1)]) - self.cross[13] = set([(1,0),(0,1),(0,2),(2,1),(2,2)]) - self.cross[14] = set([(0,1),(1,0),(1,2),(2,0),(2,2)]) - self.cross[15] = set([(0,0),(0,1),(1,2),(2,0),(2,1)]) - self.cross[16] = set([(1,0),(1,1),(1,2),(0,1),(2,1)]) - self.cross[17] = set([(0,0),(0,2),(1,1),(2,0),(2,2)]) - self.box = set([(i,j) for i in range(3) for j in range(3)]) - self.square = [set([]) for i in range(18)] + self.cross[0] = {(0, 0), (0, 1), (0, 2), (1, 0), (2, 0)} + self.cross[1] = {(0, 0), (0, 1), (0, 2), (1, 2), (2, 2)} + self.cross[2] = {(0, 0), (1, 0), (2, 0), (2, 1), (2, 2)} + self.cross[3] = {(2, 0), (2, 1), (2, 2), (0, 2), (1, 2)} + self.cross[4] = {(0, 0), (0, 1), (0, 2), (1, 1), (2, 1)} + self.cross[5] = {(0, 0), (1, 0), (2, 0), (1, 1), (1, 2)} + self.cross[6] = {(1, 0), (1, 1), (1, 2), (0, 2), (2, 2)} + self.cross[7] = {(0, 1), (1, 1), (2, 1), (2, 0), (2, 2)} + self.cross[8] = {(0, 0), (0, 1), (1, 0), (1, 1), (2, 2)} + self.cross[9] = {(0, 0), (1, 1), (1, 2), (2, 1), (2, 2)} + self.cross[10] = {(2, 0), (2, 1), (1, 0), (1, 1), (0, 2)} + self.cross[11] = {(0, 1), (0, 2), (1, 1), (1, 2), (2, 0)} + self.cross[12] = {(0, 0), (1, 0), (0, 2), (1, 2), (2, 1)} + self.cross[13] = {(1, 0), (0, 1), (0, 2), (2, 1), (2, 2)} + self.cross[14] = {(0, 1), (1, 0), (1, 2), (2, 0), (2, 2)} + self.cross[15] = {(0, 0), (0, 1), (1, 2), (2, 0), (2, 1)} + self.cross[16] = {(1, 0), (1, 1), (1, 2), (0, 1), (2, 1)} + self.cross[17] = {(0, 0), (0, 2), (1, 1), (2, 0), (2, 2)} + self.box = {(i, j) for i in range(3) for j in range(3)} + self.square = [set() for i in range(18)] for i in range(18): self.square[i] = self.box - self.cross[i] MS34_GF3 = MatrixSpace(GF(2), 3, 4) cols = {} - cols[1] = MS34_GF3([[1,0,0,0],[1,0,0,0],[1,0,0,0]]) - cols[2] = MS34_GF3([[0,1,0,0],[0,1,0,0],[0,1,0,0]]) - cols[3] = MS34_GF3([[0,0,1,0],[0,0,1,0],[0,0,1,0]]) - cols[4] = MS34_GF3([[0,0,0,1],[0,0,0,1],[0,0,0,1]]) + cols[1] = MS34_GF3([[1, 0, 0, 0], [1, 0, 0, 0], [1, 0, 0, 0]]) + cols[2] = MS34_GF3([[0, 1, 0, 0], [0, 1, 0, 0], [0, 1, 0, 0]]) + cols[3] = MS34_GF3([[0, 0, 1, 0], [0, 0, 1, 0], [0, 0, 1, 0]]) + cols[4] = MS34_GF3([[0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1]]) self.col = cols tets = {} - tets[1] = MS34_GF3([[1,1,1,1],[0,0,0,0],[0,0,0,0]]) - tets[2] = MS34_GF3([[1,0,0,0],[0,1,1,1],[0,0,0,0]]) - tets[3] = MS34_GF3([[1,0,0,0],[0,0,0,0],[0,1,1,1]]) - tets[4] = MS34_GF3([[0,1,0,0],[1,0,1,0],[0,0,0,1]]) - tets[5] = MS34_GF3([[0,0,0,1],[1,1,0,0],[0,0,1,0]]) - tets[6] = MS34_GF3([[0,0,1,0],[1,0,0,1],[0,1,0,0]]) - tets[7] = MS34_GF3([[0,1,0,0],[0,0,0,1],[1,0,1,0]]) - tets[8] = MS34_GF3([[0,0,1,0],[0,1,0,0],[1,0,0,1]]) - tets[9] = MS34_GF3([[0,0,0,1],[0,0,1,0],[1,1,0,0]]) + tets[1] = MS34_GF3([[1, 1, 1, 1], [0, 0, 0, 0], [0, 0, 0, 0]]) + tets[2] = MS34_GF3([[1, 0, 0, 0], [0, 1, 1, 1], [0, 0, 0, 0]]) + tets[3] = MS34_GF3([[1, 0, 0, 0], [0, 0, 0, 0], [0, 1, 1, 1]]) + tets[4] = MS34_GF3([[0, 1, 0, 0], [1, 0, 1, 0], [0, 0, 0, 1]]) + tets[5] = MS34_GF3([[0, 0, 0, 1], [1, 1, 0, 0], [0, 0, 1, 0]]) + tets[6] = MS34_GF3([[0, 0, 1, 0], [1, 0, 0, 1], [0, 1, 0, 0]]) + tets[7] = MS34_GF3([[0, 1, 0, 0], [0, 0, 0, 1], [1, 0, 1, 0]]) + tets[8] = MS34_GF3([[0, 0, 1, 0], [0, 1, 0, 0], [1, 0, 0, 1]]) + tets[9] = MS34_GF3([[0, 0, 0, 1], [0, 0, 1, 0], [1, 1, 0, 0]]) self.tet = tets - def __repr__(self): + def __repr__(self) -> str: """ Return a string representation of ``self``. @@ -231,7 +231,7 @@ def __repr__(self): """ return "Minimog of type %s" % self.type - def __str__(self): + def __str__(self) -> str: """ EXAMPLES:: @@ -243,8 +243,7 @@ def __str__(self): [ 4 1 6 7] """ - return "Minimog of type %s associated to\n %s" % (self.type, - self.minimog) + return f"Minimog of type {self.type} associated to\n {self.minimog}" def _latex_(self): r""" @@ -262,8 +261,7 @@ def _latex_(self): \end{array}\right)$ """ from sage.misc.latex import latex - return "Minimog of type %s associated to\n $%s$" % (self.type, - latex(self.minimog)) + return f"Minimog of type {self.type} associated to\n ${latex(self.minimog)}$" def print_kitten(self): """ @@ -298,15 +296,15 @@ def print_kitten(self): """ MINIMOG = self.minimog - kitten = ' {}'.format(MINIMOG[0][2]) + kitten = f' {MINIMOG[0][2]}' kitten += '\n ' - kitten += '\n {}'.format(MINIMOG[2][2]) - kitten += '\n {} {}'.format(MINIMOG[0][3], MINIMOG[1][3]) - kitten += '\n {} {} {}'.format(MINIMOG[1][0], MINIMOG[2][3], MINIMOG[0][1]) + kitten += f'\n {MINIMOG[2][2]}' + kitten += f'\n {MINIMOG[0][3]} {MINIMOG[1][3]}' + kitten += f'\n {MINIMOG[1][0]} {MINIMOG[2][3]} {MINIMOG[0][1]}' kitten += '\n {0} {1} {2} {0}'.format(MINIMOG[2][2], MINIMOG[1][1], MINIMOG[2][0]) kitten += '\n {0} {1} {2} {0} {1}'.format(MINIMOG[0][3], MINIMOG[1][3], MINIMOG[1][2]) kitten += '\n \n' - kitten += '{} {}'.format(MINIMOG[0][0], MINIMOG[2][1]) + kitten += f'{MINIMOG[0][0]} {MINIMOG[2][1]}' print(kitten) def find_hexad0(self, pts): @@ -332,13 +330,13 @@ def find_hexad0(self, pts): sage: from sage.games.hexad import * sage: M = Minimog(type="shuffle") - sage: M.find_hexad0(set([2,4])) + sage: M.find_hexad0(set([2, 4])) ([0, 1, 2, 4, 6, 8], ['line 1', 'picture 1']) """ MINIMOG = self.minimog L = set(pts) - H = set([MINIMOG[0][2], MINIMOG[2][1], MINIMOG[0][0]]) + H = {MINIMOG[0][2], MINIMOG[2][1], MINIMOG[0][0]} for i in range(12): if L <= picture_set(self.picture02, self.line[i]): WHAT = ["line " + str(i), "picture " + str(1)] @@ -376,7 +374,7 @@ def find_hexad1(self, pts): sage: from sage.games.hexad import * sage: M = Minimog(type="shuffle") - sage: M.find_hexad1(set([2,3,4,5,8])) + sage: M.find_hexad1(set([2, 3, 4, 5, 8])) ([2, 3, 4, 5, 8, 11], ['lines (1, 2)', 'picture 1']) """ H = set(pts) @@ -386,19 +384,19 @@ def find_hexad1(self, pts): for x in linez: x1 = int(x[0] - 1) x2 = int(x[1] - 1) # (recall | is union) - if L <= (picture_set(self.picture02, self.line[x1]) | picture_set(self.picture02,self.line[x2])): + if L <= (picture_set(self.picture02, self.line[x1]) | picture_set(self.picture02, self.line[x2])): WHAT = ["lines " + str(x), "picture " + str(1)] - H = picture_set(self.picture02, self.line[x1]) | picture_set(self.picture02,self.line[x2]) + H = picture_set(self.picture02, self.line[x1]) | picture_set(self.picture02, self.line[x2]) return list(H), WHAT - if L <= (picture_set(self.picture21, self.line[x1]) | picture_set(self.picture21,self.line[x2])): + if L <= (picture_set(self.picture21, self.line[x1]) | picture_set(self.picture21, self.line[x2])): WHAT = ["lines " + str(x), "picture " + str(0)] - H = picture_set(self.picture21, self.line[x1]) | picture_set(self.picture21,self.line[x2]) + H = picture_set(self.picture21, self.line[x1]) | picture_set(self.picture21, self.line[x2]) return list(H), WHAT - if L <= (picture_set(self.picture00, self.line[x1]) | picture_set(self.picture00,self.line[x2])): + if L <= (picture_set(self.picture00, self.line[x1]) | picture_set(self.picture00, self.line[x2])): WHAT = ["lines " + str(x), "picture " + str(6)] - H = picture_set(self.picture00, self.line[x1]) | picture_set(self.picture00,self.line[x2]) + H = picture_set(self.picture00, self.line[x1]) | picture_set(self.picture00, self.line[x2]) return list(H), WHAT - return [],[] + return [], [] def find_hexad2(self, pts, x0): r""" @@ -418,33 +416,33 @@ def find_hexad2(self, pts, x0): sage: from sage.games.hexad import * sage: M = Minimog(type="shuffle") - sage: M.find_hexad2([2,3,4,5],1) + sage: M.find_hexad2([2, 3, 4, 5], 1) ([], []) The above output indicates that there is no hexad of type 2 - containing `\{2,3,4,5\}`. However, there is one containing - `\{2,3,4,8\}`:: + containing `\{2, 3, 4, 5\}`. However, there is one containing + `\{2, 3, 4, 8\}`:: - sage: M.find_hexad2([2,3,4,8],0) + sage: M.find_hexad2([2, 3, 4, 8], 0) ([0, 2, 3, 4, 8, 9], ['cross 12', 'picture 0']) """ MINIMOG = self.minimog L = set(pts) - H = set([x0]) + H = {x0} for i in range(18): - if (x0 == MINIMOG[2][1] and L <= picture_set(self.picture02,self.cross[i])): + if (x0 == MINIMOG[2][1] and L <= picture_set(self.picture02, self.cross[i])): WHAT = ["cross " + str(i), "picture " + str(1)] H = H | picture_set(self.picture02, self.cross[i]) return list(H), WHAT - if (x0 == MINIMOG[0][2] and L <= picture_set(self.picture21,self.cross[i])): + if (x0 == MINIMOG[0][2] and L <= picture_set(self.picture21, self.cross[i])): WHAT = ["cross " + str(i), "picture " + str(MINIMOG[0][2])] H = H | picture_set(self.picture21, self.cross[i]) return list(H), WHAT - if (x0 == MINIMOG[0][0] and L <= picture_set(self.picture00,self.cross[i])): + if (x0 == MINIMOG[0][0] and L <= picture_set(self.picture00, self.cross[i])): WHAT = ["cross " + str(i), "picture " + str(6)] H = H | picture_set(self.picture00, self.cross[i]) return list(H), WHAT - return [],[] + return [], [] def find_hexad3(self, pts, x0, x1): r""" @@ -459,20 +457,20 @@ def find_hexad3(self, pts, x0, x1): OUTPUT: - hexad containing pts union \{x0,x1\} of type 3 (square at + hexad containing pts union \{x0, x1\} of type 3 (square at picture of "omitted point at infinity") EXAMPLES:: sage: from sage.games.hexad import * sage: M = Minimog(type="shuffle") - sage: M.find_hexad3([2,3,4],0,1) + sage: M.find_hexad3([2, 3, 4], 0, 1) ([0, 1, 2, 3, 4, 11], ['square 2', 'picture 6']) """ MINIMOG = self.minimog L = set(pts) - H = set([x0, x1]) + H = {x0, x1} for i in range(18): if (not (MINIMOG[0][2] in H) and L <= picture_set(self.picture21, self.square[i])): WHAT = ["square " + str(i), "picture " + str(MINIMOG[0][2])] @@ -518,22 +516,22 @@ def find_hexad(self, pts): More precisely, there are 132 such hexads (12 of type 0, 12 of type 1, 54 of type 2, and 54 of type 3). - They form a Steiner system of type `(5,6,12)`. + They form a Steiner system of type `(5, 6, 12)`. EXAMPLES:: sage: from sage.games.hexad import * sage: M = Minimog(type="shuffle") - sage: M.find_hexad([0,1,2,3,4]) + sage: M.find_hexad([0, 1, 2, 3, 4]) ([0, 1, 2, 3, 4, 11], ['square 2', 'picture 6']) - sage: M.find_hexad([1,2,3,4,5]) + sage: M.find_hexad([1, 2, 3, 4, 5]) ([1, 2, 3, 4, 5, 6], ['square 8', 'picture 0']) - sage: M.find_hexad([2,3,4,5,8]) + sage: M.find_hexad([2, 3, 4, 5, 8]) ([2, 3, 4, 5, 8, 11], ['lines (1, 2)', 'picture 1']) - sage: M.find_hexad([0,1,2,4,6]) + sage: M.find_hexad([0, 1, 2, 4, 6]) ([0, 1, 2, 4, 6, 8], ['line 1', 'picture 1']) sage: M = Minimog(type="modulo11") - sage: M.find_hexad([1,2,3,4,SR(infinity)]) # random (machine dependent?) order + sage: M.find_hexad([1, 2, 3, 4, SR(infinity)]) # random (machine dependent?) order ([+Infinity, 2, 3, 4, 1, 10], ['square 8', 'picture 0']) AUTHOR: @@ -545,7 +543,7 @@ def find_hexad(self, pts): MINIMOG = self.minimog L = set(pts) LL = L.copy() - pts_at_infty = set([MINIMOG[0][2],MINIMOG[2][1],MINIMOG[0][0]]) + pts_at_infty = {MINIMOG[0][2], MINIMOG[2][1], MINIMOG[0][0]} # recall & means intersection L2 = LL & pts_at_infty if len(L2) == 3: # must be type 0 (line + pts at infty) @@ -553,69 +551,69 @@ def find_hexad(self, pts): return H, WHAT if len(L2) == 2: # type 0 or 3 if (MINIMOG[0][2] in LL and MINIMOG[2][1] in LL): - H, WHAT = self.find_hexad3(LL - set([MINIMOG[0][2],MINIMOG[2][1]]), + H, WHAT = self.find_hexad3(LL - {MINIMOG[0][2], MINIMOG[2][1]}, MINIMOG[0][2], MINIMOG[2][1]) - if H != []: # must be type 3 + if H: # must be type 3 + return list(H), WHAT + # could be type 0 + H, WHAT = self.find_hexad0(LL - L2) + if H: # must be type 0 return list(H), WHAT - if H == []: # could be type 0 - H, WHAT = self.find_hexad0(LL - L2) - if H != []: # must be type 0 - return list(H), WHAT if (MINIMOG[2][1] in LL and MINIMOG[0][0] in LL): - H, WHAT = self.find_hexad3(LL - set([MINIMOG[2][1],MINIMOG[0][0]]), + H, WHAT = self.find_hexad3(LL - {MINIMOG[2][1], MINIMOG[0][0]}, MINIMOG[2][1], MINIMOG[0][0]) - if H != []: # must be type 3 + if H: # must be type 3 + return list(H), WHAT + # could be type 0 + H, WHAT = self.find_hexad0(LL - L2) + if H: # must be type 0 return list(H), WHAT - if H == []: # could be type 0 - H, WHAT = self.find_hexad0(LL - L2) - if H != []: # must be type 0 - return list(H), WHAT if (MINIMOG[0][2] in LL and MINIMOG[0][0] in LL): - H, WHAT = self.find_hexad3(LL - set([MINIMOG[0][2],MINIMOG[0][0]]), + H, WHAT = self.find_hexad3(LL - {MINIMOG[0][2], MINIMOG[0][0]}, MINIMOG[0][2], MINIMOG[0][0]) - if H != []: # must be type 3 + if H: # must be type 3 + return list(H), WHAT + # could be type 0 + H, WHAT = self.find_hexad0(LL - L2) + if H: # must be type 0 return list(H), WHAT - if H == []: # could be type 0 - H, WHAT = self.find_hexad0(LL - L2) - if H != []: # must be type 0 - return list(H), WHAT if len(L2) == 1: H, WHAT = self.find_hexad2(LL - L2, list(L2)[0]) - if H == []: # not a cross in picture at infinity + if not H: # not a cross in picture at infinity if list(L2)[0] == MINIMOG[2][1]: L1 = LL - L2 H, WHAT = self.find_hexad3(L1, MINIMOG[0][0], MINIMOG[2][1]) - if H != []: + if H: return list(H), WHAT L1 = LL - L2 H, WHAT = self.find_hexad3(L1, MINIMOG[0][2], MINIMOG[2][1]) - if H != []: + if H: return list(H), WHAT if list(L2)[0] == MINIMOG[0][0]: L1 = (LL - L2) H, WHAT = self.find_hexad3(L1, MINIMOG[0][0], MINIMOG[2][1]) - if H != []: + if H: return list(H), WHAT L1 = (LL - L2) H, WHAT = self.find_hexad3(L1, MINIMOG[0][0], MINIMOG[0][2]) - if H != []: + if H: return list(H), WHAT if list(L2)[0] == MINIMOG[0][2]: L1 = (LL - L2) H, WHAT = self.find_hexad3(L1, MINIMOG[0][0], MINIMOG[0][2]) - if H != []: + if H: return list(H), WHAT L1 = (LL - L2) H, WHAT = self.find_hexad3(L1, MINIMOG[2][1], MINIMOG[0][2]) - if H != []: + if H: return list(H), WHAT return list(H), WHAT # a cross in a pic at infty if not L2: # L is either a union of 2 lines or a cross for i in LL: for j in pts_at_infty: - H, WHAT = self.find_hexad2(LL - set([i]),j) - if (H != [] and i in H): + H, WHAT = self.find_hexad2(LL - {i}, j) + if (H and i in H): return list(H), WHAT # L is in a cross H, WHAT = self.find_hexad1(LL) # L is a union of lines return H, WHAT @@ -650,7 +648,7 @@ def blackjack_move(self, L0): under 21 loses. The winning strategy (given below) for this game is due to - Conway and Ryba. There is a Steiner system `S(5,6,12)` of hexads + Conway and Ryba. There is a Steiner system `S(5, 6, 12)` of hexads in the set `\{0, 1, ..., 11\}`. This Steiner system is associated to the MINIMOG of in the "shuffle numbering" rather than the "modulo `11` labeling". @@ -662,32 +660,32 @@ def blackjack_move(self, L0): EXAMPLES:: sage: M = Minimog(type="modulo11") - sage: M.blackjack_move([0,2,3,6,1,10]) + sage: M.blackjack_move([0, 2, 3, 6, 1, 10]) '6 --> 5. The total went from 22 to 21.' sage: M = Minimog(type="shuffle") - sage: M.blackjack_move([0,2,4,6,7,11]) + sage: M.blackjack_move([0, 2, 4, 6, 7, 11]) '4 --> 3. The total went from 30 to 29.' Is this really a hexad? :: - sage: M.find_hexad([11,2,3,6,7]) + sage: M.find_hexad([11, 2, 3, 6, 7]) ([0, 2, 3, 6, 7, 11], ['square 9', 'picture 1']) So, yes it is, but here is further confirmation:: - sage: M.blackjack_move([0,2,3,6,7,11]) + sage: M.blackjack_move([0, 2, 3, 6, 7, 11]) This is a hexad. There is no winning move, so make a random legal move. [0, 2, 3, 6, 7, 11] Now, suppose player 2 replaced the 11 by a 9. Your next move:: - sage: M.blackjack_move([0,2,3,6,7,9]) + sage: M.blackjack_move([0, 2, 3, 6, 7, 9]) '7 --> 1. The total went from 27 to 21.' You have now won. Sage will even tell you so:: - sage: M.blackjack_move([0,2,3,6,1,9]) + sage: M.blackjack_move([0, 2, 3, 6, 1, 9]) 'No move possible. Shuffle the deck and redeal.' AUTHOR: @@ -701,11 +699,11 @@ def blackjack_move(self, L0): return "No move possible. Shuffle the deck and redeal." L = set(L0) for x in L: - h, WHAT = self.find_hexad(L - set([x])) + h, WHAT = self.find_hexad(L - {x}) if list(L0) == list(h): print(" This is a hexad. \n There is no winning move, so make a random legal move.") return L0 - y = list(set(h) - (L - set([x])))[0] + y = list(set(h) - (L - {x}))[0] if y < x: return str(x) + ' --> ' + str(y) + ". The total went from " + str(total) + " to " + str(total - x + y) + "." print("This is a hexad. \n There is no winning move, so make a random legal move.") diff --git a/src/sage/geometry/hyperbolic_space/hyperbolic_geodesic.py b/src/sage/geometry/hyperbolic_space/hyperbolic_geodesic.py index 9f6d5725f68..57354fad4d9 100644 --- a/src/sage/geometry/hyperbolic_space/hyperbolic_geodesic.py +++ b/src/sage/geometry/hyperbolic_space/hyperbolic_geodesic.py @@ -1110,7 +1110,7 @@ def reflection_involution(self): """ - x, y = [real(k.coordinates()) for k in self.ideal_endpoints()] + x, y = (real(k.coordinates()) for k in self.ideal_endpoints()) if x == infinity: M = matrix([[1, -2*y], [0, -1]]) elif y == infinity: @@ -1188,8 +1188,8 @@ def plot(self, boundary=True, **options): opts = {'axes': False, 'aspect_ratio': 1} opts.update(self.graphics_options()) opts.update(options) - end_1, end_2 = [CC(k.coordinates()) for k in self.endpoints()] - bd_1, bd_2 = [CC(k.coordinates()) for k in self.ideal_endpoints()] + end_1, end_2 = (CC(k.coordinates()) for k in self.endpoints()) + bd_1, bd_2 = (CC(k.coordinates()) for k in self.ideal_endpoints()) if (abs(real(end_1) - real(end_2)) < EPSILON) \ or CC(infinity) in [end_1, end_2]: # on same vertical line # If one of the endpoints is infinity, we replace it with a @@ -1224,7 +1224,7 @@ def plot(self, boundary=True, **options): # computations below compute the projection of the # geodesic to the real line, and then draw a little # to the left and right of the projection. - shadow_1, shadow_2 = [real(k) for k in [end_1, end_2]] + shadow_1, shadow_2 = (real(k) for k in [end_1, end_2]) midpoint = (shadow_1 + shadow_2)/2 length = abs(shadow_1 - shadow_2) bd_dict = {'bd_min': midpoint - length, 'bd_max': midpoint + @@ -1479,8 +1479,8 @@ def intersection(self, other): # Get endpoints and ideal endpoints i_start_1, i_end_1 = sorted(self.ideal_endpoints(), key=str) i_start_2, i_end_2 = sorted(other.ideal_endpoints(), key=str) - start_1, end_1 = [CC(x.coordinates()) for x in self.endpoints()] - start_2, end_2 = [CC(x.coordinates()) for x in other.endpoints()] + start_1, end_1 = (CC(x.coordinates()) for x in self.endpoints()) + start_2, end_2 = (CC(x.coordinates()) for x in other.endpoints()) # sort the geodesic endpoints according to start_1.real() < end_1.real() and if start_1.real() == end_1.real() # then start_1.imag() < end_1.imag() if start_1.real() > end_1.real(): # enforce @@ -1934,8 +1934,8 @@ def angle(self, other): # UHP if abs(a2 - a1) < EPSILON or abs(b2 - b1) < EPSILON: raise ValueError("intersecting geodesic is a point") - p1, p2 = [p.coordinates() for p in self.ideal_endpoints()] - q1, q2 = [p.coordinates() for p in other.ideal_endpoints()] + p1, p2 = (p.coordinates() for p in self.ideal_endpoints()) + q1, q2 = (p.coordinates() for p in other.ideal_endpoints()) # Check if both geodesics are lines. All lines intersect at # ``Infinity``, but the angle is always zero. @@ -1979,7 +1979,7 @@ def angle(self, other): # UHP # Transform into a line. t = HyperbolicGeodesicUHP._crossratio_matrix(p1, (p1 + p2) / 2, p2) - q1, q2 = [moebius_transform(t, q) for q in [q1, q2]] + q1, q2 = (moebius_transform(t, q) for q in [q1, q2]) # Calculate the angle. return arccos(abs(q1 + q2) / abs(q2 - q1)) @@ -2246,8 +2246,8 @@ def plot(self, boundary=True, **options): opts = {'axes': False, 'aspect_ratio': 1} opts.update(self.graphics_options()) opts.update(options) - end_1, end_2 = [CC(k.coordinates()) for k in self.endpoints()] - bd_1, bd_2 = [CC(k.coordinates()) for k in self.ideal_endpoints()] + end_1, end_2 = (CC(k.coordinates()) for k in self.endpoints()) + bd_1, bd_2 = (CC(k.coordinates()) for k in self.ideal_endpoints()) # Check to see if it's a line if abs(bd_1 + bd_2) < EPSILON: pic = bezier_path([[(real(end_1), imag(end_1)), (real(end_2), imag(end_2))]], **opts) @@ -2330,7 +2330,7 @@ def map_pt(pt): if pt in CC: return CC(pt) return CC(*pt) - end_1, end_2 = [map_pt(k.coordinates()) for k in self.endpoints()] + end_1, end_2 = (map_pt(k.coordinates()) for k in self.endpoints()) pic = bezier_path([[(real(end_1), imag(end_1)), (real(end_2), imag(end_2))]], **opts) if boundary: @@ -2392,7 +2392,7 @@ def _plot_vertices(self, points=75): from sage.arith.srange import xsrange x = SR.var('x') - v1, u2 = [vector(k.coordinates()) for k in self.endpoints()] + v1, u2 = (vector(k.coordinates()) for k in self.endpoints()) # Lorentzian Gram Shmidt. The original vectors will be # u1, u2 and the orthogonal ones will be v1, v2. Except # v1 = u1, and I don't want to declare another variable, @@ -2436,7 +2436,7 @@ def plot(self, show_hyperboloid=True, **graphics_options): x = SR.var('x') opts = self.graphics_options() opts.update(graphics_options) - v1, u2 = [vector(k.coordinates()) for k in self.endpoints()] + v1, u2 = (vector(k.coordinates()) for k in self.endpoints()) # Lorentzian Gram Shmidt. The original vectors will be # u1, u2 and the orthogonal ones will be v1, v2. Except # v1 = u1, and I don't want to declare another variable, diff --git a/src/sage/geometry/hyperbolic_space/hyperbolic_isometry.py b/src/sage/geometry/hyperbolic_space/hyperbolic_isometry.py index 2de12812ddc..08d68b2c518 100644 --- a/src/sage/geometry/hyperbolic_space/hyperbolic_isometry.py +++ b/src/sage/geometry/hyperbolic_space/hyperbolic_isometry.py @@ -820,10 +820,10 @@ def fixed_point_set(self): # UHP return self.domain().get_geodesic(pt(p_1), pt(p_2)) try: - p, q = [M.eigenvectors_right()[k][1][0] for k in range(2)] + p, q = (M.eigenvectors_right()[k][1][0] for k in range(2)) except IndexError: M = M.change_ring(RDF) - p, q = [M.eigenvectors_right()[k][1][0] for k in range(2)] + p, q = (M.eigenvectors_right()[k][1][0] for k in range(2)) pts = [] if p[1] == 0: diff --git a/src/sage/geometry/polyhedron/base5.py b/src/sage/geometry/polyhedron/base5.py index 89feb2d7b0f..72cb9f349ca 100644 --- a/src/sage/geometry/polyhedron/base5.py +++ b/src/sage/geometry/polyhedron/base5.py @@ -483,7 +483,7 @@ def _test_bipyramid(self, tester=None, **options): R = self.base_ring() a = (R(1),) + tuple(self.center()) b = (R(-1),) + tuple(self.center()) - c, d = [tuple(v) for v in cert] + c, d = (tuple(v) for v in cert) tester.assertEqual(sorted([a, b]), sorted([c, d])) def prism(self): diff --git a/src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pxd b/src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pxd index 85a020df78a..61814b4f538 100644 --- a/src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pxd +++ b/src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pxd @@ -1,10 +1,10 @@ cimport cython from sage.data_structures.list_of_pairs cimport ListOfPairs from sage.structure.sage_object cimport SageObject -from .face_iterator cimport FaceIterator, CombinatorialFace -from .list_of_faces cimport ListOfFaces -from .face_data_structure cimport face_t -from .polyhedron_face_lattice cimport PolyhedronFaceLattice +from sage.geometry.polyhedron.combinatorial_polyhedron.face_iterator cimport FaceIterator, CombinatorialFace +from sage.geometry.polyhedron.combinatorial_polyhedron.list_of_faces cimport ListOfFaces +from sage.geometry.polyhedron.combinatorial_polyhedron.face_data_structure cimport face_t +from sage.geometry.polyhedron.combinatorial_polyhedron.polyhedron_face_lattice cimport PolyhedronFaceLattice @cython.final cdef class CombinatorialPolyhedron(SageObject): diff --git a/src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx b/src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx index 8282fbbd1ca..11148d13a83 100644 --- a/src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx +++ b/src/sage/geometry/polyhedron/combinatorial_polyhedron/base.pyx @@ -98,14 +98,14 @@ from .conversions \ incidence_matrix_to_bit_rep_of_Vrep, \ facets_tuple_to_bit_rep_of_facets, \ facets_tuple_to_bit_rep_of_Vrep -from .conversions cimport Vrep_list_to_bit_rep +from sage.geometry.polyhedron.combinatorial_polyhedron.conversions cimport Vrep_list_to_bit_rep from sage.misc.cachefunc import cached_method from sage.rings.integer cimport smallInteger from cysignals.signals cimport sig_check -from .face_data_structure cimport face_len_atoms, face_init, face_free -from .face_iterator cimport iter_t, parallel_f_vector +from sage.geometry.polyhedron.combinatorial_polyhedron.face_data_structure cimport face_len_atoms, face_init, face_free +from sage.geometry.polyhedron.combinatorial_polyhedron.face_iterator cimport iter_t, parallel_f_vector cdef extern from "Python.h": diff --git a/src/sage/geometry/polyhedron/combinatorial_polyhedron/combinatorial_face.pxd b/src/sage/geometry/polyhedron/combinatorial_polyhedron/combinatorial_face.pxd index 2169fe539f6..e65f8eb678b 100644 --- a/src/sage/geometry/polyhedron/combinatorial_polyhedron/combinatorial_face.pxd +++ b/src/sage/geometry/polyhedron/combinatorial_polyhedron/combinatorial_face.pxd @@ -1,8 +1,8 @@ cimport cython from sage.structure.sage_object cimport SageObject -from .list_of_faces cimport ListOfFaces -from .face_data_structure cimport face_t -from .face_iterator cimport FaceIterator +from sage.geometry.polyhedron.combinatorial_polyhedron.list_of_faces cimport ListOfFaces +from sage.geometry.polyhedron.combinatorial_polyhedron.face_data_structure cimport face_t +from sage.geometry.polyhedron.combinatorial_polyhedron.face_iterator cimport FaceIterator @cython.final cdef class CombinatorialFace(SageObject): diff --git a/src/sage/geometry/polyhedron/combinatorial_polyhedron/combinatorial_face.pyx b/src/sage/geometry/polyhedron/combinatorial_polyhedron/combinatorial_face.pyx index 541927c6c11..5e5b2dfd992 100644 --- a/src/sage/geometry/polyhedron/combinatorial_polyhedron/combinatorial_face.pyx +++ b/src/sage/geometry/polyhedron/combinatorial_polyhedron/combinatorial_face.pyx @@ -68,13 +68,13 @@ from cysignals.memory cimport check_allocarray, sig_free import numbers from sage.rings.integer cimport smallInteger -from .conversions cimport bit_rep_to_Vrep_list -from .base cimport CombinatorialPolyhedron -from .face_iterator cimport FaceIterator_base, FaceStatus -from .polyhedron_face_lattice cimport PolyhedronFaceLattice -from .face_data_structure cimport face_len_atoms, face_init, face_free, face_copy, face_issubset -from .face_list_data_structure cimport bit_rep_to_coatom_rep -from .list_of_faces cimport face_as_combinatorial_polyhedron +from sage.geometry.polyhedron.combinatorial_polyhedron.conversions cimport bit_rep_to_Vrep_list +from sage.geometry.polyhedron.combinatorial_polyhedron.base cimport CombinatorialPolyhedron +from sage.geometry.polyhedron.combinatorial_polyhedron.face_iterator cimport FaceIterator_base, FaceStatus +from sage.geometry.polyhedron.combinatorial_polyhedron.polyhedron_face_lattice cimport PolyhedronFaceLattice +from sage.geometry.polyhedron.combinatorial_polyhedron.face_data_structure cimport face_len_atoms, face_init, face_free, face_copy, face_issubset +from sage.geometry.polyhedron.combinatorial_polyhedron.face_list_data_structure cimport bit_rep_to_coatom_rep +from sage.geometry.polyhedron.combinatorial_polyhedron.list_of_faces cimport face_as_combinatorial_polyhedron cdef extern from "Python.h": diff --git a/src/sage/geometry/polyhedron/combinatorial_polyhedron/conversions.pxd b/src/sage/geometry/polyhedron/combinatorial_polyhedron/conversions.pxd index 82ac7f6dcb8..2a0e950b469 100644 --- a/src/sage/geometry/polyhedron/combinatorial_polyhedron/conversions.pxd +++ b/src/sage/geometry/polyhedron/combinatorial_polyhedron/conversions.pxd @@ -1,4 +1,5 @@ -from .face_list_data_structure cimport face_t +from sage.geometry.polyhedron.combinatorial_polyhedron.face_list_data_structure cimport face_t + cdef int Vrep_list_to_bit_rep(tuple Vrep_list, face_t output) except -1 diff --git a/src/sage/geometry/polyhedron/combinatorial_polyhedron/conversions.pyx b/src/sage/geometry/polyhedron/combinatorial_polyhedron/conversions.pyx index baeb8fc4855..26aa92a6575 100644 --- a/src/sage/geometry/polyhedron/combinatorial_polyhedron/conversions.pyx +++ b/src/sage/geometry/polyhedron/combinatorial_polyhedron/conversions.pyx @@ -72,8 +72,8 @@ from memory_allocator cimport MemoryAllocator from sage.matrix.matrix_dense cimport Matrix_dense -from .list_of_faces cimport ListOfFaces -from .face_data_structure cimport face_next_atom, face_add_atom_safe, facet_set_coatom, face_clear +from sage.geometry.polyhedron.combinatorial_polyhedron.list_of_faces cimport ListOfFaces +from sage.geometry.polyhedron.combinatorial_polyhedron.face_data_structure cimport face_next_atom, face_add_atom_safe, facet_set_coatom, face_clear cdef extern from "Python.h": int unlikely(int) nogil # Defined by Cython diff --git a/src/sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pxd b/src/sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pxd index f148c81f7a9..c906ddb51cc 100644 --- a/src/sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pxd +++ b/src/sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pxd @@ -1,9 +1,9 @@ cimport cython from sage.structure.sage_object cimport SageObject -from .list_of_faces cimport ListOfFaces -from .face_data_structure cimport face_t -from .face_list_data_structure cimport face_list_t -from .combinatorial_face cimport CombinatorialFace +from sage.geometry.polyhedron.combinatorial_polyhedron.list_of_faces cimport ListOfFaces +from sage.geometry.polyhedron.combinatorial_polyhedron.face_data_structure cimport face_t +from sage.geometry.polyhedron.combinatorial_polyhedron.face_list_data_structure cimport face_list_t +from sage.geometry.polyhedron.combinatorial_polyhedron.combinatorial_face cimport CombinatorialFace cdef enum FaceStatus: NOT_INITIALIZED diff --git a/src/sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pyx b/src/sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pyx index d35033fc855..734745c6b8e 100644 --- a/src/sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pyx +++ b/src/sage/geometry/polyhedron/combinatorial_polyhedron/face_iterator.pyx @@ -176,14 +176,13 @@ AUTHOR: from cython.parallel cimport prange, threadid from cysignals.memory cimport check_allocarray, sig_free +from cysignals.signals cimport sig_check from memory_allocator cimport MemoryAllocator -from cysignals.signals cimport sig_check -from .conversions cimport bit_rep_to_Vrep_list -from .base cimport CombinatorialPolyhedron - +from sage.geometry.polyhedron.combinatorial_polyhedron.base cimport CombinatorialPolyhedron +from sage.geometry.polyhedron.combinatorial_polyhedron.conversions cimport bit_rep_to_Vrep_list +from sage.geometry.polyhedron.combinatorial_polyhedron.face_list_data_structure cimport * from sage.geometry.polyhedron.face import combinatorial_face_to_polyhedral_face, PolyhedronFace -from .face_list_data_structure cimport * cdef extern from "Python.h": diff --git a/src/sage/geometry/polyhedron/combinatorial_polyhedron/face_list_data_structure.pxd b/src/sage/geometry/polyhedron/combinatorial_polyhedron/face_list_data_structure.pxd index 105cc81b9a4..9867675fbec 100644 --- a/src/sage/geometry/polyhedron/combinatorial_polyhedron/face_list_data_structure.pxd +++ b/src/sage/geometry/polyhedron/combinatorial_polyhedron/face_list_data_structure.pxd @@ -14,7 +14,7 @@ Inline cython methods for lists of faces. cdef extern from "Python.h": int unlikely(int) nogil # Defined by Cython -from .face_data_structure cimport * +from sage.geometry.polyhedron.combinatorial_polyhedron.face_data_structure cimport * from libc.string cimport memset from cysignals.signals cimport sig_check from cysignals.memory cimport check_allocarray, check_calloc, sig_free diff --git a/src/sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.pxd b/src/sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.pxd index d50c8f85539..d994f78ebec 100644 --- a/src/sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.pxd +++ b/src/sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.pxd @@ -1,5 +1,5 @@ cimport cython -from .face_list_data_structure cimport face_list_t, face_t +from sage.geometry.polyhedron.combinatorial_polyhedron.face_list_data_structure cimport face_list_t, face_t @cython.final cdef class ListOfFaces: diff --git a/src/sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.pyx b/src/sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.pyx index 9b5f3dd4ada..59e72afad65 100644 --- a/src/sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.pyx +++ b/src/sage/geometry/polyhedron/combinatorial_polyhedron/list_of_faces.pyx @@ -92,7 +92,7 @@ AUTHOR: from sage.matrix.matrix_dense cimport Matrix_dense -from .face_list_data_structure cimport * +from sage.geometry.polyhedron.combinatorial_polyhedron.face_list_data_structure cimport * cdef extern from "Python.h": int unlikely(int) nogil # Defined by Cython diff --git a/src/sage/geometry/polyhedron/combinatorial_polyhedron/polyhedron_face_lattice.pxd b/src/sage/geometry/polyhedron/combinatorial_polyhedron/polyhedron_face_lattice.pxd index 438dc8de6f7..2cfd863835e 100644 --- a/src/sage/geometry/polyhedron/combinatorial_polyhedron/polyhedron_face_lattice.pxd +++ b/src/sage/geometry/polyhedron/combinatorial_polyhedron/polyhedron_face_lattice.pxd @@ -1,8 +1,8 @@ cimport cython -from .list_of_faces cimport ListOfFaces -from .face_data_structure cimport face_t -from .face_list_data_structure cimport face_list_t -from .combinatorial_face cimport CombinatorialFace +from sage.geometry.polyhedron.combinatorial_polyhedron.list_of_faces cimport ListOfFaces +from sage.geometry.polyhedron.combinatorial_polyhedron.face_data_structure cimport face_t +from sage.geometry.polyhedron.combinatorial_polyhedron.face_list_data_structure cimport face_list_t +from sage.geometry.polyhedron.combinatorial_polyhedron.combinatorial_face cimport CombinatorialFace @cython.final cdef class PolyhedronFaceLattice: diff --git a/src/sage/geometry/polyhedron/combinatorial_polyhedron/polyhedron_face_lattice.pyx b/src/sage/geometry/polyhedron/combinatorial_polyhedron/polyhedron_face_lattice.pyx index 9f5a98c7ece..8ba0b7edc1d 100644 --- a/src/sage/geometry/polyhedron/combinatorial_polyhedron/polyhedron_face_lattice.pyx +++ b/src/sage/geometry/polyhedron/combinatorial_polyhedron/polyhedron_face_lattice.pyx @@ -64,11 +64,11 @@ from .conversions \ import facets_tuple_to_bit_rep_of_facets, \ facets_tuple_to_bit_rep_of_Vrep -from .conversions cimport bit_rep_to_Vrep_list +from sage.geometry.polyhedron.combinatorial_polyhedron.conversions cimport bit_rep_to_Vrep_list -from .base cimport CombinatorialPolyhedron -from .face_iterator cimport FaceIterator -from .face_list_data_structure cimport * +from sage.geometry.polyhedron.combinatorial_polyhedron.base cimport CombinatorialPolyhedron +from sage.geometry.polyhedron.combinatorial_polyhedron.face_iterator cimport FaceIterator +from sage.geometry.polyhedron.combinatorial_polyhedron.face_list_data_structure cimport * cdef extern from "Python.h": diff --git a/src/sage/geometry/polyhedron/plot.py b/src/sage/geometry/polyhedron/plot.py index 03628f60e22..5c2362cfdda 100644 --- a/src/sage/geometry/polyhedron/plot.py +++ b/src/sage/geometry/polyhedron/plot.py @@ -852,7 +852,7 @@ def defining_equation(): # corresponding to a polygon face_inequalities.append(facet_equation) vertices = cyclic_sort_vertices_2d(vertices) if len(vertices) >= 3: - v0, v1, v2 = [vector(v) for v in vertices[:3]] + v0, v1, v2 = (vector(v) for v in vertices[:3]) normal = (v2 - v0).cross_product(v1 - v0) if normal.dot_product(facet_equation.A()) < 0: vertices.reverse() diff --git a/src/sage/geometry/triangulation/base.pyx b/src/sage/geometry/triangulation/base.pyx index cbb1673d0f2..61014429fdd 100644 --- a/src/sage/geometry/triangulation/base.pyx +++ b/src/sage/geometry/triangulation/base.pyx @@ -27,8 +27,8 @@ from sage.structure.parent cimport Parent from sage.categories.sets_cat import Sets from sage.matrix.constructor import matrix -from .functions cimport binomial -from .triangulations cimport \ +from sage.geometry.triangulation.functions cimport binomial +from sage.geometry.triangulation.triangulations cimport \ triangulations_ptr, init_triangulations, next_triangulation, delete_triangulations diff --git a/src/sage/graphs/base/c_graph.pxd b/src/sage/graphs/base/c_graph.pxd index 1d5fb583eb5..b29cc3c9527 100644 --- a/src/sage/graphs/base/c_graph.pxd +++ b/src/sage/graphs/base/c_graph.pxd @@ -6,7 +6,7 @@ #************************************************************************** from sage.data_structures.bitset cimport bitset_t -from .graph_backends cimport GenericGraphBackend +from sage.graphs.base.graph_backends cimport GenericGraphBackend from libc.stdint cimport uint32_t cdef class CGraph: diff --git a/src/sage/graphs/base/dense_graph.pxd b/src/sage/graphs/base/dense_graph.pxd index f5c194cec8a..6c4145694fe 100644 --- a/src/sage/graphs/base/dense_graph.pxd +++ b/src/sage/graphs/base/dense_graph.pxd @@ -8,7 +8,7 @@ # http://www.gnu.org/licenses/ #***************************************************************************** -from .c_graph cimport CGraph, CGraphBackend +from sage.graphs.base.c_graph cimport CGraph, CGraphBackend from sage.data_structures.binary_matrix cimport binary_matrix_t cdef class DenseGraph(CGraph): diff --git a/src/sage/graphs/base/graph_backends.pyx b/src/sage/graphs/base/graph_backends.pyx index c0ffc56533e..863f61be013 100644 --- a/src/sage/graphs/base/graph_backends.pyx +++ b/src/sage/graphs/base/graph_backends.pyx @@ -57,7 +57,7 @@ Classes and methods # (at your option) any later version. # https://www.gnu.org/licenses/ # **************************************************************************** -from .c_graph cimport CGraphBackend +from sage.graphs.base.c_graph cimport CGraphBackend cdef class GenericGraphBackend(SageObject): @@ -722,9 +722,9 @@ cdef class GenericGraphBackend(SageObject): sage: loads(dumps(gi)) == gi True """ - from .static_sparse_backend import StaticSparseBackend - from .sparse_graph import SparseGraphBackend - from .dense_graph import DenseGraphBackend + from sage.graphs.base.static_sparse_backend import StaticSparseBackend + from sage.graphs.base.sparse_graph import SparseGraphBackend + from sage.graphs.base.dense_graph import DenseGraphBackend # implementation, data_structure, multiedges, directed, loops if isinstance(self, CGraphBackend): diff --git a/src/sage/graphs/base/sparse_graph.pxd b/src/sage/graphs/base/sparse_graph.pxd index b925e9170ec..3795c8ff0f0 100644 --- a/src/sage/graphs/base/sparse_graph.pxd +++ b/src/sage/graphs/base/sparse_graph.pxd @@ -8,7 +8,7 @@ # https://www.gnu.org/licenses/ # **************************************************************************** -from .c_graph cimport CGraph, CGraphBackend +from sage.graphs.base.c_graph cimport CGraph, CGraphBackend cimport cython cdef struct SparseGraphLLNode: diff --git a/src/sage/graphs/base/static_sparse_backend.pxd b/src/sage/graphs/base/static_sparse_backend.pxd index db62534cb09..fb72a89180b 100644 --- a/src/sage/graphs/base/static_sparse_backend.pxd +++ b/src/sage/graphs/base/static_sparse_backend.pxd @@ -1,7 +1,9 @@ -from .c_graph cimport CGraph, CGraphBackend -from .static_sparse_graph cimport short_digraph, ushort from libc.stdint cimport uint64_t, uint32_t, INT32_MAX, UINT32_MAX + from sage.data_structures.bitset cimport * +from sage.graphs.base.c_graph cimport CGraph, CGraphBackend +from sage.graphs.base.static_sparse_graph cimport short_digraph, ushort + cdef class StaticSparseCGraph(CGraph): cdef short_digraph g @@ -12,6 +14,7 @@ cdef class StaticSparseCGraph(CGraph): cpdef int out_degree(self, int u) except -1 cpdef int in_degree(self, int u) except -1 + cdef class StaticSparseBackend(CGraphBackend): cdef int _order cdef bint _multiedges diff --git a/src/sage/graphs/base/static_sparse_backend.pyx b/src/sage/graphs/base/static_sparse_backend.pyx index ae76a399240..0d1361c940a 100644 --- a/src/sage/graphs/base/static_sparse_backend.pyx +++ b/src/sage/graphs/base/static_sparse_backend.pyx @@ -43,7 +43,7 @@ from sage.graphs.base.static_sparse_graph cimport (init_short_digraph, has_edge, free_short_digraph, edge_label) -from .c_graph cimport CGraphBackend +from sage.graphs.base.c_graph cimport CGraphBackend from sage.data_structures.bitset cimport FrozenBitset from libc.stdint cimport uint32_t from sage.data_structures.bitset_base cimport * diff --git a/src/sage/graphs/base/static_sparse_graph.pyx b/src/sage/graphs/base/static_sparse_graph.pyx index 90e47b6e069..ddb30927931 100644 --- a/src/sage/graphs/base/static_sparse_graph.pyx +++ b/src/sage/graphs/base/static_sparse_graph.pyx @@ -191,8 +191,8 @@ from memory_allocator cimport MemoryAllocator from sage.data_structures.bitset_base cimport * from sage.graphs.base.c_graph cimport CGraph -from .static_sparse_backend cimport StaticSparseCGraph -from .static_sparse_backend cimport StaticSparseBackend +from sage.graphs.base.static_sparse_backend cimport StaticSparseCGraph +from sage.graphs.base.static_sparse_backend cimport StaticSparseBackend cdef extern from "fenv.h": diff --git a/src/sage/graphs/bipartite_graph.py b/src/sage/graphs/bipartite_graph.py index 8cc866616ce..0a03affa422 100644 --- a/src/sage/graphs/bipartite_graph.py +++ b/src/sage/graphs/bipartite_graph.py @@ -1755,7 +1755,7 @@ def load_afile(self, fname): return None # read header information - num_cols, num_rows = [int(_) for _ in fi.readline().split()] + num_cols, num_rows = (int(_) for _ in fi.readline().split()) # next are max_col_degree, max_row_degree, not used _ = [int(_) for _ in fi.readline().split()] col_degrees = [int(_) for _ in fi.readline().split()] diff --git a/src/sage/graphs/convexity_properties.pyx b/src/sage/graphs/convexity_properties.pyx index 0c96c518e83..7024324f362 100644 --- a/src/sage/graphs/convexity_properties.pyx +++ b/src/sage/graphs/convexity_properties.pyx @@ -13,13 +13,10 @@ the following methods: :meth:`ConvexityProperties.hull` | Return the convex hull of a set of vertices :meth:`ConvexityProperties.hull_number` | Compute the hull number of a graph and a corresponding generating set :meth:`geodetic_closure`| Return the geodetic closure of a set of vertices + :meth:`is_geodetic` | Check whether the input (di)graph is geodetic -These methods can be used through the :class:`ConvexityProperties` object -returned by :meth:`Graph.convexity_properties`. - -AUTHORS: - - - Nathann Cohen +Some of these methods can be used through the :class:`ConvexityProperties` +object returned by :meth:`Graph.convexity_properties`. Methods ------- @@ -674,3 +671,156 @@ def geodetic_closure(G, S): free_short_digraph(sd) return ret + + +def is_geodetic(G): + r""" + Check whether the input (di)graph is geodetic. + + A graph `G` is *geodetic* if there exists only one shortest path between + every pair of its vertices. This can be checked in time `O(nm)` in + unweighted (di)graphs with `n` nodes and `m` edges. Examples of geodetic + graphs are trees, cliques and odd cycles. See the + :wikipedia:`Geodetic_graph` for more details. + + (Di)graphs with multiple edges are not considered geodetic. + + INPUT: + + - ``G`` -- a graph or a digraph + + EXAMPLES: + + Trees, cliques and odd cycles are geodetic:: + + sage: T = graphs.RandomTree(20) + sage: T.is_geodetic() + True + sage: all(graphs.CompleteGraph(n).is_geodetic() for n in range(8)) + True + sage: all(graphs.CycleGraph(n).is_geodetic() for n in range(3, 16, 2)) + True + + Even cycles of order at least 4 are not geodetic:: + + sage: all(graphs.CycleGraph(n).is_geodetic() for n in range(4, 17, 2)) + False + + The Petersen graph is geodetic:: + + sage: P = graphs.PetersenGraph() + sage: P.is_geodetic() + True + + Grid graphs are not geodetic:: + + sage: G = graphs.Grid2dGraph(2, 3) + sage: G.is_geodetic() + False + + This method is also valid for digraphs:: + + sage: G = DiGraph(graphs.PetersenGraph()) + sage: G.is_geodetic() + True + sage: G = digraphs.Path(5) + sage: G.add_path([0, 'a', 'b', 'c', 4]) + sage: G.is_geodetic() + False + + TESTS:: + + sage: all(g.is_geodetic() for g in graphs(3)) + True + sage: all((2*g).is_geodetic() for g in graphs(3)) + True + sage: G = graphs.CycleGraph(5) + sage: G.allow_loops(True) + sage: G.add_edges([(u, u) for u in G]) + sage: G.is_geodetic() + True + sage: G.allow_multiple_edges(True) + sage: G.is_geodetic() + True + sage: G.add_edge(G.random_edge()) + sage: G.is_geodetic() + False + """ + if G.has_multiple_edges(): + return False + + if G.order() < 4: + return True + + # Copy the graph as a short digraph + cdef int n = G.order() + cdef short_digraph sd + init_short_digraph(sd, G, edge_labelled=False, vertex_list=list(G)) + + # Allocate some data structures + cdef MemoryAllocator mem = MemoryAllocator() + cdef uint32_t * distances = mem.malloc(n * sizeof(uint32_t)) + cdef uint32_t * waiting_list = mem.malloc(n * sizeof(uint32_t)) + if not distances or not waiting_list: + free_short_digraph(sd) + raise MemoryError() + cdef bitset_t seen + bitset_init(seen, n) + + # We now explore geodesics between vertices in S, and we avoid visiting + # twice the geodesics between u and v + + cdef uint32_t source, u, v + cdef uint32_t waiting_beginning + cdef uint32_t waiting_end + cdef uint32_t * p_tmp + cdef uint32_t * end + cdef uint32_t ** p_vertices = sd.neighbors + + for source in range(n): + + # Compute distances from source using BFS + bitset_clear(seen) + bitset_add(seen, source) + distances[source] = 0 + waiting_beginning = 0 + waiting_end = 0 + waiting_list[waiting_beginning] = source + + # For as long as there are vertices left to explore + while waiting_beginning <= waiting_end: + + # We pick the first one + v = waiting_list[waiting_beginning] + p_tmp = p_vertices[v] + end = p_vertices[v + 1] + + # and we iterate over all the outneighbors u of v + while p_tmp < end: + u = p_tmp[0] + + # If we notice one of these neighbors is not seen yet, we set + # its parameters and add it to the queue to be explored later. + # Otherwise, we check whether we have detected a second shortest + # path between source and v. + if not bitset_in(seen, u): + distances[u] = distances[v] + 1 + bitset_add(seen, u) + waiting_end += 1 + waiting_list[waiting_end] = u + elif distances[u] == distances[v] + 1: + # G is not geodetic + bitset_free(seen) + free_short_digraph(sd) + return False + + p_tmp += 1 + + # We go to the next vertex in the queue + waiting_beginning += 1 + + bitset_free(seen) + free_short_digraph(sd) + + # The graph is geodetic + return True diff --git a/src/sage/graphs/domination.py b/src/sage/graphs/domination.py index 0dcab74e90c..7f631fcfe28 100644 --- a/src/sage/graphs/domination.py +++ b/src/sage/graphs/domination.py @@ -17,6 +17,7 @@ :meth:`~is_redundant` | Check whether a set of vertices has redundant vertices (with respect to domination). :meth:`~private_neighbors` | Return the private neighbors of a vertex with respect to other vertices. :meth:`~greedy_dominating_set` | Return a greedy distance-`k` dominating set of the graph. + :meth:`~maximum_leaf_number` | Return the maximum leaf number of the graph. EXAMPLES: @@ -1284,3 +1285,81 @@ def greedy_dominating_set(G, k=1, vertices=None, ordering=None, return_sets=Fals return dom else: return list(dom) + + +def maximum_leaf_number(G, solver=None, verbose=0, integrality_tolerance=1e-3): + r""" + Return the maximum leaf number of the graph. + + The maximum leaf number is the maximum possible number of leaves of a + spanning tree of `G`. This is also the cardinality of the complement of a + minimum connected dominating set. + See the :wikipedia:`Connected_dominating_set`. + + The MLN of a graph with less than 2 vertices is 0, while the MLN of a connected + graph with 2 or 3 vertices is 1 or 2 respectively. + + INPUT: + + - ``G`` -- a Graph + + - ``solver`` -- string (default: ``None``); specify a Mixed Integer Linear + Programming (MILP) solver to be used. If set to ``None``, the default one + is used. For more information on MILP solvers and which default solver is + used, see the method :meth:`solve + ` of the class + :class:`MixedIntegerLinearProgram + `. + + - ``verbose`` -- integer (default: ``0``); sets the level of verbosity. Set + to 0 by default, which means quiet. + + - ``integrality_tolerance`` -- float; parameter for use with MILP solvers + over an inexact base ring; see + :meth:`MixedIntegerLinearProgram.get_values`. + + EXAMPLES: + + Empty graph:: + + sage: G = Graph() + sage: G.maximum_leaf_number() + 0 + + Petersen graph:: + + sage: G = graphs.PetersenGraph() + sage: G.maximum_leaf_number() + 6 + + TESTS: + + One vertex:: + + sage: G = Graph(1) + sage: G.maximum_leaf_number() + 0 + + Two vertices:: + + sage: G = graphs.PathGraph(2) + sage: G.maximum_leaf_number() + 1 + + Unconnected graph:: + + sage: G = Graph(2) + sage: G.maximum_leaf_number() + Traceback (most recent call last): + ... + ValueError: the graph must be connected + """ + if G.order() <= 1: + return 0 + if not G.is_connected(): + raise ValueError('the graph must be connected') + if G.order() <= 3: + return G.order() - 1 + return G.order() - dominating_set(G, connected=True, value_only=True, + solver=solver, verbose=verbose, + integrality_tolerance=integrality_tolerance) diff --git a/src/sage/graphs/generators/classical_geometries.py b/src/sage/graphs/generators/classical_geometries.py index 1bfe55f0f54..e27f7e11b6d 100644 --- a/src/sage/graphs/generators/classical_geometries.py +++ b/src/sage/graphs/generators/classical_geometries.py @@ -535,12 +535,12 @@ def NonisotropicOrthogonalPolarGraph(m, q, sign="+", perp=None): deg = (q**n - e)*(q**(n - 1) + e) # k S = [libgap.Elements(libgap.Basis(x))[0] for x in libgap.Elements(libgap.Subspaces(W, 1))] - (V,) = [x for x in libgap.Orbits(g, S, libgap.OnLines) - if len(x) == nvert] + (V,) = (x for x in libgap.Orbits(g, S, libgap.OnLines) + if len(x) == nvert) gp = libgap.Action(g, V, libgap.OnLines) # make a permutation group h = libgap.Stabilizer(gp, 1) - (Vh,) = [x for x in libgap.Orbits(h, libgap.Orbit(gp, 1)) - if len(x) == deg] + (Vh,) = (x for x in libgap.Orbits(h, libgap.Orbit(gp, 1)) + if len(x) == deg) Vh = Vh[0] L = libgap.Orbit(gp, [1, Vh], libgap.OnSets) G = Graph() diff --git a/src/sage/graphs/generators/random.py b/src/sage/graphs/generators/random.py index d253633621c..22c1f583f6a 100644 --- a/src/sage/graphs/generators/random.py +++ b/src/sage/graphs/generators/random.py @@ -1957,7 +1957,7 @@ def rotate_word_to_next_occurrence(word): word2 = rotate_word_to_next_occurrence(word) if len(word2) >= 5: word = [word2[0]] + word2[4:] - in1, in2, in3 = [u[1] for u in word2[:3]] + in1, in2, in3 = (u[1] for u in word2[:3]) edges.append([in1, in3]) # edge 'in1,in3' idx = embedding[in1].index(in2) embedding[in1].insert(idx, in3) diff --git a/src/sage/graphs/generators/smallgraphs.py b/src/sage/graphs/generators/smallgraphs.py index a4f3e1c05ef..3b47f29f2ff 100644 --- a/src/sage/graphs/generators/smallgraphs.py +++ b/src/sage/graphs/generators/smallgraphs.py @@ -201,7 +201,7 @@ def HarriesGraph(embedding=1): # Vertices from o[1]. These are actually the "edges" of the copies of # Petersen. for v in o[1]: - p1, p2 = [gpos[x] for x in g.neighbors(v) if x in o[0]] + p1, p2 = (gpos[x] for x in g.neighbors(v) if x in o[0]) gpos[v] = ((p1[0] + p2[0])/2, (p1[1] + p2[1])/2) # 15 vertices from o[2] @@ -4816,8 +4816,8 @@ def JankoKharaghaniGraph(v): D = ("--1-11", "-11-1-", "11-1--", "--11-1", "11---1", "1--11-") E = ("-1--11", "1-1--1", "-11-1-", "---111", "1-11--", "11-1--") F = ("-1-1-1", "11--1-", "--111-", "1-11--", "-11--1", "1---11") - B, C, D, E, F = [matrix([map({'1': 1, '-': -1}.get, r) for r in m]) - for m in [B, C, D, E, F]] + B, C, D, E, F = (matrix([map({'1': 1, '-': -1}.get, r) for r in m]) + for m in [B, C, D, E, F]) H = [A, B, C, D, E, F] H = [[-x for x in H[6-i:]] + H[:6-i] for i in range(6)] diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py index a99aa1d5a64..c3039f68968 100644 --- a/src/sage/graphs/generic_graph.py +++ b/src/sage/graphs/generic_graph.py @@ -185,6 +185,7 @@ :meth:`~GenericGraph.is_gallai_tree` | Return whether the current graph is a Gallai tree. :meth:`~GenericGraph.is_clique` | Check whether a set of vertices is a clique :meth:`~GenericGraph.is_cycle` | Check whether ``self`` is a (directed) cycle graph. + :meth:`~GenericGraph.is_geodetic` | Check whether the input (di)graph is geodetic. :meth:`~GenericGraph.is_independent_set` | Check whether ``vertices`` is an independent set of ``self`` :meth:`~GenericGraph.is_transitively_reduced` | Test whether the digraph is transitively reduced. :meth:`~GenericGraph.is_equitable` | Check whether the given partition is equitable with respect to self. @@ -315,6 +316,7 @@ :meth:`~GenericGraph.disjoint_routed_paths` | Return a set of disjoint routed paths. :meth:`~GenericGraph.dominating_set` | Return a minimum dominating set of the graph :meth:`~GenericGraph.greedy_dominating_set` | Return a greedy distance-`k` dominating set of the graph. + :meth:`~GenericGraph.maximum_leaf_number` | Return the maximum leaf number of the graph. :meth:`~GenericGraph.subgraph_search` | Return a copy of ``G`` in ``self``. :meth:`~GenericGraph.subgraph_search_count` | Return the number of labelled occurrences of ``G`` in ``self``. :meth:`~GenericGraph.subgraph_search_iterator` | Return an iterator over the labelled copies of ``G`` in ``self``. @@ -5102,13 +5104,13 @@ def cycle_basis(self, output='vertex'): A cycle basis in Petersen's Graph :: sage: g = graphs.PetersenGraph() - sage: g.cycle_basis() # needs networkx + sage: g.cycle_basis() # needs networkx, random (changes in networkx 3.2) [[1, 6, 8, 5, 0], [4, 9, 6, 8, 5, 0], [7, 9, 6, 8, 5], [4, 3, 8, 5, 0], [1, 2, 3, 8, 5, 0], [7, 2, 3, 8, 5]] One can also get the result as a list of lists of edges:: - sage: g.cycle_basis(output='edge') # needs networkx + sage: g.cycle_basis(output='edge') # needs networkx, random (changes in networkx 3.2) [[(1, 6, None), (6, 8, None), (8, 5, None), (5, 0, None), (0, 1, None)], [(4, 9, None), (9, 6, None), (6, 8, None), (8, 5, None), (5, 0, None), (0, 4, None)], [(7, 9, None), @@ -5211,7 +5213,6 @@ def cycle_basis(self, output='vertex'): []) from sage.graphs.graph import Graph - from itertools import pairwise T = Graph(self.min_spanning_tree(), multiedges=True, format='list_of_edges') H = self.copy() H.delete_edges(T.edge_iterator()) @@ -5235,7 +5236,8 @@ def cycle_basis(self, output='vertex'): cycle = Q + P[-2::-1] if output == 'edge': - cycle = [e] + [(x, y, T.edge_label(x, y)[0]) for x, y in pairwise(cycle)] + cycle = [e] + [(x, y, T.edge_label(x, y)[0]) + for x, y in zip(cycle[:-1], cycle[1:])] L.append(cycle) return L @@ -5291,9 +5293,9 @@ def minimum_cycle_basis(self, algorithm=None, weight_function=None, by_weight=Fa [[1, 2, 3], [1, 2, 3, 4], [5, 6, 7]] sage: sorted(g.minimum_cycle_basis(by_weight=False)) [[1, 2, 3], [1, 3, 4], [5, 6, 7]] - sage: sorted(g.minimum_cycle_basis(by_weight=True, algorithm='NetworkX')) # needs networkx + sage: sorted(g.minimum_cycle_basis(by_weight=True, algorithm='NetworkX')) # needs networkx, random (changes in networkx 3.2) [[1, 2, 3], [1, 2, 3, 4], [5, 6, 7]] - sage: g.minimum_cycle_basis(by_weight=False, algorithm='NetworkX') # needs networkx + sage: g.minimum_cycle_basis(by_weight=False, algorithm='NetworkX') # needs networkx, random (changes in networkx 3.2) [[1, 2, 3], [1, 3, 4], [5, 6, 7]] :: @@ -5301,7 +5303,7 @@ def minimum_cycle_basis(self, algorithm=None, weight_function=None, by_weight=Fa sage: g = Graph([(1, 2), (2, 3), (3, 4), (4, 5), (5, 1), (5, 3)]) sage: sorted(g.minimum_cycle_basis(by_weight=False)) [[1, 2, 3, 5], [3, 4, 5]] - sage: sorted(g.minimum_cycle_basis(by_weight=False, algorithm='NetworkX')) # needs networkx + sage: sorted(g.minimum_cycle_basis(by_weight=False, algorithm='NetworkX')) # needs networkx, random (changes in networkx 3.2) [[1, 2, 3, 5], [3, 4, 5]] TESTS:: @@ -24407,6 +24409,7 @@ def is_self_complementary(self): from sage.graphs.domination import dominating_sets from sage.graphs.domination import dominating_set from sage.graphs.domination import greedy_dominating_set + from sage.graphs.domination import maximum_leaf_number from sage.graphs.base.static_dense_graph import connected_subgraph_iterator rooted_product = LazyImport('sage.graphs.graph_decompositions.graph_products', 'rooted_product') from sage.graphs.path_enumeration import shortest_simple_paths @@ -24415,6 +24418,7 @@ def is_self_complementary(self): from sage.graphs.traversals import lex_UP from sage.graphs.traversals import lex_DFS from sage.graphs.traversals import lex_DOWN + is_geodetic = LazyImport('sage.graphs.convexity_properties', 'is_geodetic') def katz_matrix(self, alpha, nonedgesonly=False, vertices=None): r""" diff --git a/src/sage/graphs/graph_generators.py b/src/sage/graphs/graph_generators.py index b029a9609b2..7e2a2341a46 100644 --- a/src/sage/graphs/graph_generators.py +++ b/src/sage/graphs/graph_generators.py @@ -1171,7 +1171,7 @@ def nauty_genbg(self, options="", debug=False): for s in msg.split(' '): if s.startswith('n='): from sage.rings.integer import Integer - n1, n2 = [Integer(t) for t in s[2:].split('+') if t.isdigit()] + n1, n2 = (Integer(t) for t in s[2:].split('+') if t.isdigit()) partition = [set(range(n1)), set(range(n1, n1 + n2))] break else: diff --git a/src/sage/groups/matrix_gps/group_element.pyx b/src/sage/groups/matrix_gps/group_element.pyx index d95fa0aa086..fa914a9499d 100644 --- a/src/sage/groups/matrix_gps/group_element.pyx +++ b/src/sage/groups/matrix_gps/group_element.pyx @@ -84,7 +84,7 @@ from sage.structure.richcmp cimport richcmp try: - from .group_element_gap import MatrixGroupElement_gap + from sage.groups.matrix_gps.group_element_gap import MatrixGroupElement_gap except ImportError: MatrixGroupElement_gap = () diff --git a/src/sage/groups/perm_gps/partn_ref/automorphism_group_canonical_label.pxd b/src/sage/groups/perm_gps/partn_ref/automorphism_group_canonical_label.pxd index 573eeb83f58..52f75a3df9c 100644 --- a/src/sage/groups/perm_gps/partn_ref/automorphism_group_canonical_label.pxd +++ b/src/sage/groups/perm_gps/partn_ref/automorphism_group_canonical_label.pxd @@ -8,7 +8,7 @@ # http://www.gnu.org/licenses/ #***************************************************************************** -from .data_structures cimport * +from sage.groups.perm_gps.partn_ref.data_structures cimport * from sage.data_structures.bitset cimport bitset_t from sage.rings.integer cimport Integer diff --git a/src/sage/groups/perm_gps/partn_ref/automorphism_group_canonical_label.pyx b/src/sage/groups/perm_gps/partn_ref/automorphism_group_canonical_label.pyx index 920ff69c3df..803f2533b7d 100644 --- a/src/sage/groups/perm_gps/partn_ref/automorphism_group_canonical_label.pyx +++ b/src/sage/groups/perm_gps/partn_ref/automorphism_group_canonical_label.pyx @@ -113,7 +113,7 @@ REFERENCE: from libc.string cimport memcmp, memcpy from cysignals.memory cimport sig_malloc, sig_realloc, sig_free -from .data_structures cimport * +from sage.groups.perm_gps.partn_ref.data_structures cimport * from sage.data_structures.bitset_base cimport * cdef inline int agcl_cmp(int a, int b) noexcept: diff --git a/src/sage/groups/perm_gps/partn_ref/canonical_augmentation.pxd b/src/sage/groups/perm_gps/partn_ref/canonical_augmentation.pxd index daa7a59b2b6..49e2f3cdbde 100644 --- a/src/sage/groups/perm_gps/partn_ref/canonical_augmentation.pxd +++ b/src/sage/groups/perm_gps/partn_ref/canonical_augmentation.pxd @@ -17,13 +17,13 @@ AUTHORS: # http://www.gnu.org/licenses/ #***************************************************************************** -from .data_structures cimport * +from sage.groups.perm_gps.partn_ref.data_structures cimport * -from .automorphism_group_canonical_label cimport ( +from sage.groups.perm_gps.partn_ref.automorphism_group_canonical_label cimport ( get_aut_gp_and_can_lab, aut_gp_and_can_lab, agcl_work_space, allocate_agcl_output, deallocate_agcl_output, allocate_agcl_work_space, deallocate_agcl_work_space) -from .double_coset cimport (double_coset, +from sage.groups.perm_gps.partn_ref.double_coset cimport (double_coset, dc_work_space, allocate_dc_work_space, deallocate_dc_work_space) diff --git a/src/sage/groups/perm_gps/partn_ref/canonical_augmentation.pyx b/src/sage/groups/perm_gps/partn_ref/canonical_augmentation.pyx index a8a25050413..6143e509caa 100644 --- a/src/sage/groups/perm_gps/partn_ref/canonical_augmentation.pyx +++ b/src/sage/groups/perm_gps/partn_ref/canonical_augmentation.pyx @@ -169,7 +169,7 @@ REFERENCE: from cysignals.memory cimport sig_malloc, sig_free -from .data_structures cimport* +from sage.groups.perm_gps.partn_ref.data_structures cimport* cdef void *canonical_generator_next(void *can_gen_data, int *degree, bint *mem_err) noexcept: diff --git a/src/sage/groups/perm_gps/partn_ref/double_coset.pxd b/src/sage/groups/perm_gps/partn_ref/double_coset.pxd index 1ca972a8e33..6c5d9e0f279 100644 --- a/src/sage/groups/perm_gps/partn_ref/double_coset.pxd +++ b/src/sage/groups/perm_gps/partn_ref/double_coset.pxd @@ -8,7 +8,7 @@ # http://www.gnu.org/licenses/ #***************************************************************************** -from .data_structures cimport * +from sage.groups.perm_gps.partn_ref.data_structures cimport * from sage.data_structures.bitset cimport bitset_t from sage.rings.integer cimport Integer diff --git a/src/sage/groups/perm_gps/partn_ref/double_coset.pyx b/src/sage/groups/perm_gps/partn_ref/double_coset.pyx index b29abddd20a..873199ce380 100644 --- a/src/sage/groups/perm_gps/partn_ref/double_coset.pyx +++ b/src/sage/groups/perm_gps/partn_ref/double_coset.pyx @@ -96,7 +96,7 @@ REFERENCE: from cysignals.memory cimport sig_calloc -from .data_structures cimport * +from sage.groups.perm_gps.partn_ref.data_structures cimport * from sage.data_structures.bitset_base cimport * # Functions diff --git a/src/sage/groups/perm_gps/partn_ref/refinement_binary.pxd b/src/sage/groups/perm_gps/partn_ref/refinement_binary.pxd index a06c9fc8532..4af69f4b5f5 100644 --- a/src/sage/groups/perm_gps/partn_ref/refinement_binary.pxd +++ b/src/sage/groups/perm_gps/partn_ref/refinement_binary.pxd @@ -8,9 +8,9 @@ # http://www.gnu.org/licenses/ #***************************************************************************** -from .data_structures cimport * +from sage.groups.perm_gps.partn_ref.data_structures cimport * -from .automorphism_group_canonical_label cimport ( +from sage.groups.perm_gps.partn_ref.automorphism_group_canonical_label cimport ( get_aut_gp_and_can_lab, aut_gp_and_can_lab, agcl_work_space, allocate_agcl_output, deallocate_agcl_output, allocate_agcl_work_space, deallocate_agcl_work_space) diff --git a/src/sage/groups/perm_gps/partn_ref/refinement_binary.pyx b/src/sage/groups/perm_gps/partn_ref/refinement_binary.pyx index 6339dbbd2e5..6a3c07ac75d 100644 --- a/src/sage/groups/perm_gps/partn_ref/refinement_binary.pyx +++ b/src/sage/groups/perm_gps/partn_ref/refinement_binary.pyx @@ -28,10 +28,10 @@ REFERENCE: #***************************************************************************** from sage.data_structures.bitset_base cimport * -from .data_structures cimport * +from sage.groups.perm_gps.partn_ref.data_structures cimport * from sage.rings.integer cimport Integer from sage.structure.element import is_Matrix -from .double_coset cimport double_coset +from sage.groups.perm_gps.partn_ref.double_coset cimport double_coset cdef class LinearBinaryCodeStruct(BinaryCodeStruct): diff --git a/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pxd b/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pxd index f26580d3010..464ddde015d 100644 --- a/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pxd +++ b/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pxd @@ -8,17 +8,17 @@ # http://www.gnu.org/licenses/ #***************************************************************************** -from .data_structures cimport * +from sage.groups.perm_gps.partn_ref.data_structures cimport * from sage.graphs.base.c_graph cimport CGraph -from .automorphism_group_canonical_label cimport ( +from sage.groups.perm_gps.partn_ref.automorphism_group_canonical_label cimport ( get_aut_gp_and_can_lab, aut_gp_and_can_lab, agcl_work_space, allocate_agcl_output, deallocate_agcl_output, allocate_agcl_work_space, deallocate_agcl_work_space) -from .canonical_augmentation cimport (iterator, +from sage.groups.perm_gps.partn_ref.canonical_augmentation cimport (iterator, canonical_generator_data, allocate_cgd, deallocate_cgd, canonical_generator_next, setup_canonical_generator, start_canonical_generator) -from .refinement_sets cimport (subset, free_subset, all_set_children_are_equivalent, +from sage.groups.perm_gps.partn_ref.refinement_sets cimport (subset, free_subset, all_set_children_are_equivalent, refine_set, compare_sets, generate_child_subsets, apply_subset_aug, canonical_set_parent, allocate_sgd, deallocate_sgd, allocate_subset_gen, free_subset_gen, setup_set_gen, subset_generator_next, subset_generator_data, allocate_subset_gen_2) diff --git a/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx b/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx index 83c91f3296d..1b588487d1c 100644 --- a/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx +++ b/src/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx @@ -20,12 +20,12 @@ REFERENCE: # https://www.gnu.org/licenses/ # **************************************************************************** -from .data_structures cimport * +from sage.groups.perm_gps.partn_ref.data_structures cimport * from sage.data_structures.bitset_base cimport * from sage.rings.integer cimport Integer from sage.graphs.base.sparse_graph cimport SparseGraph from sage.graphs.base.dense_graph cimport DenseGraph, copy_dense_graph -from .double_coset cimport double_coset +from sage.groups.perm_gps.partn_ref.double_coset cimport double_coset def isomorphic(G1, G2, partn, ordering2, dig, use_indicator_function, sparse=False): diff --git a/src/sage/groups/perm_gps/partn_ref/refinement_lists.pxd b/src/sage/groups/perm_gps/partn_ref/refinement_lists.pxd index faabab4024e..e7b6cf42f6d 100644 --- a/src/sage/groups/perm_gps/partn_ref/refinement_lists.pxd +++ b/src/sage/groups/perm_gps/partn_ref/refinement_lists.pxd @@ -9,7 +9,7 @@ # http://www.gnu.org/licenses/ #***************************************************************************** -from .data_structures cimport * +from sage.groups.perm_gps.partn_ref.data_structures cimport * # name of the three functions to customize diff --git a/src/sage/groups/perm_gps/partn_ref/refinement_lists.pyx b/src/sage/groups/perm_gps/partn_ref/refinement_lists.pyx index 462f96bef00..00365bcbd3c 100644 --- a/src/sage/groups/perm_gps/partn_ref/refinement_lists.pyx +++ b/src/sage/groups/perm_gps/partn_ref/refinement_lists.pyx @@ -20,8 +20,8 @@ EXAMPLES:: from cysignals.memory cimport sig_malloc, sig_free -from .data_structures cimport * -from .double_coset cimport double_coset, int_cmp +from sage.groups.perm_gps.partn_ref.data_structures cimport * +from sage.groups.perm_gps.partn_ref.double_coset cimport double_coset, int_cmp def is_isomorphic(self, other): diff --git a/src/sage/groups/perm_gps/partn_ref/refinement_matrices.pxd b/src/sage/groups/perm_gps/partn_ref/refinement_matrices.pxd index 7799111e457..2cf087e9915 100644 --- a/src/sage/groups/perm_gps/partn_ref/refinement_matrices.pxd +++ b/src/sage/groups/perm_gps/partn_ref/refinement_matrices.pxd @@ -8,9 +8,9 @@ # http://www.gnu.org/licenses/ #***************************************************************************** -from .data_structures cimport * +from sage.groups.perm_gps.partn_ref.data_structures cimport * -from .automorphism_group_canonical_label cimport ( +from sage.groups.perm_gps.partn_ref.automorphism_group_canonical_label cimport ( get_aut_gp_and_can_lab, aut_gp_and_can_lab, agcl_work_space, allocate_agcl_output, deallocate_agcl_output, allocate_agcl_work_space, deallocate_agcl_work_space) diff --git a/src/sage/groups/perm_gps/partn_ref/refinement_matrices.pyx b/src/sage/groups/perm_gps/partn_ref/refinement_matrices.pyx index 4d55e2a09a2..c8d4f86a8f1 100644 --- a/src/sage/groups/perm_gps/partn_ref/refinement_matrices.pyx +++ b/src/sage/groups/perm_gps/partn_ref/refinement_matrices.pyx @@ -28,12 +28,12 @@ REFERENCE: from libc.string cimport memcmp -from .data_structures cimport * +from sage.groups.perm_gps.partn_ref.data_structures cimport * from sage.data_structures.bitset_base cimport * from sage.rings.integer cimport Integer from sage.matrix.constructor import Matrix -from .refinement_binary cimport NonlinearBinaryCodeStruct, refine_by_bip_degree -from .double_coset cimport double_coset +from sage.groups.perm_gps.partn_ref.refinement_binary cimport NonlinearBinaryCodeStruct, refine_by_bip_degree +from sage.groups.perm_gps.partn_ref.double_coset cimport double_coset cdef class MatrixStruct: diff --git a/src/sage/groups/perm_gps/partn_ref/refinement_python.pxd b/src/sage/groups/perm_gps/partn_ref/refinement_python.pxd index 1c13cb9c337..9f46107a1c1 100644 --- a/src/sage/groups/perm_gps/partn_ref/refinement_python.pxd +++ b/src/sage/groups/perm_gps/partn_ref/refinement_python.pxd @@ -8,7 +8,7 @@ # http://www.gnu.org/licenses/ #***************************************************************************** -from .data_structures cimport * +from sage.groups.perm_gps.partn_ref.data_structures cimport * cdef class PythonPartitionStack: diff --git a/src/sage/groups/perm_gps/partn_ref/refinement_python.pyx b/src/sage/groups/perm_gps/partn_ref/refinement_python.pyx index 0a7de54bc4f..23d5e7576c7 100644 --- a/src/sage/groups/perm_gps/partn_ref/refinement_python.pyx +++ b/src/sage/groups/perm_gps/partn_ref/refinement_python.pyx @@ -32,11 +32,11 @@ debugger. from cysignals.memory cimport sig_malloc, sig_free -from .data_structures cimport * -from .automorphism_group_canonical_label cimport ( +from sage.groups.perm_gps.partn_ref.data_structures cimport * +from sage.groups.perm_gps.partn_ref.automorphism_group_canonical_label cimport ( get_aut_gp_and_can_lab, aut_gp_and_can_lab, deallocate_agcl_output) -from .double_coset cimport double_coset +from sage.groups.perm_gps.partn_ref.double_coset cimport double_coset from sage.rings.integer cimport Integer diff --git a/src/sage/groups/perm_gps/partn_ref/refinement_sets.pxd b/src/sage/groups/perm_gps/partn_ref/refinement_sets.pxd index 9a1d0da4bf2..94bcbe5bf95 100644 --- a/src/sage/groups/perm_gps/partn_ref/refinement_sets.pxd +++ b/src/sage/groups/perm_gps/partn_ref/refinement_sets.pxd @@ -17,12 +17,12 @@ AUTHORS: # http://www.gnu.org/licenses/ #***************************************************************************** -from .data_structures cimport * -from .automorphism_group_canonical_label cimport ( +from sage.groups.perm_gps.partn_ref.data_structures cimport * +from sage.groups.perm_gps.partn_ref.automorphism_group_canonical_label cimport ( get_aut_gp_and_can_lab, aut_gp_and_can_lab, agcl_work_space, allocate_agcl_output, deallocate_agcl_output, allocate_agcl_work_space, deallocate_agcl_work_space) -from .canonical_augmentation cimport (iterator, +from sage.groups.perm_gps.partn_ref.canonical_augmentation cimport (iterator, canonical_generator_data, allocate_cgd, deallocate_cgd, canonical_generator_next, setup_canonical_generator, start_canonical_generator) diff --git a/src/sage/groups/perm_gps/partn_ref/refinement_sets.pyx b/src/sage/groups/perm_gps/partn_ref/refinement_sets.pyx index cf8dd1b8c40..6ccc0b28c45 100644 --- a/src/sage/groups/perm_gps/partn_ref/refinement_sets.pyx +++ b/src/sage/groups/perm_gps/partn_ref/refinement_sets.pyx @@ -26,8 +26,8 @@ REFERENCE: # http://www.gnu.org/licenses/ #***************************************************************************** -from .data_structures cimport * -from .double_coset cimport double_coset +from sage.groups.perm_gps.partn_ref.data_structures cimport * +from sage.groups.perm_gps.partn_ref.double_coset cimport double_coset from sage.data_structures.bitset_base cimport * diff --git a/src/sage/groups/perm_gps/permgroup_named.py b/src/sage/groups/perm_gps/permgroup_named.py index 5052880e99e..f34ee9fcd21 100644 --- a/src/sage/groups/perm_gps/permgroup_named.py +++ b/src/sage/groups/perm_gps/permgroup_named.py @@ -236,7 +236,7 @@ class SymmetricGroup(PermutationGroup_symalt): {1, 2, 3, 4} sage: G.category() Join of Category of finite enumerated permutation groups and - Category of finite weyl groups and + Category of finite Weyl groups and Category of well generated finite irreducible complex reflection groups TESTS:: diff --git a/src/sage/groups/raag.py b/src/sage/groups/raag.py index 4bd3787d484..ff7aa0ae9c2 100644 --- a/src/sage/groups/raag.py +++ b/src/sage/groups/raag.py @@ -13,18 +13,15 @@ - Travis Scrimshaw (2018-02-05): Made compatible with :class:`~sage.groups.artin.ArtinGroup` """ - -#**************************************************************************** +# *************************************************************************** # Copyright (C) 2013,2018 Travis Scrimshaw # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** - - +# https://www.gnu.org/licenses/ +# **************************************************************************** from sage.libs.gap.element import GapElement from sage.misc.cachefunc import cached_method @@ -38,11 +35,13 @@ from sage.combinat.free_module import CombinatorialFreeModule from sage.categories.fields import Fields +from sage.categories.groups import Groups from sage.categories.algebras_with_basis import AlgebrasWithBasis from sage.algebras.clifford_algebra_element import CohomologyRAAGElement from sage.typeset.ascii_art import ascii_art from sage.typeset.unicode_art import unicode_art + class RightAngledArtinGroup(ArtinGroup): r""" The right-angled Artin group defined by a graph `G`. @@ -186,23 +185,26 @@ def __init__(self, G, names): sage: G = RightAngledArtinGroup(graphs.CycleGraph(5)) sage: TestSuite(G).run() + sage: G.category() + Category of infinite groups """ self._graph = G F = FreeGroup(names=names) CG = Graph(G).complement() # Make sure it's mutable CG.relabel() # Standardize the labels - cm = [[-1]*CG.num_verts() for _ in range(CG.num_verts())] + cm = [[-1] * CG.num_verts() for _ in range(CG.num_verts())] for i in range(CG.num_verts()): cm[i][i] = 1 - for u,v in CG.edge_iterator(labels=False): + for u, v in CG.edge_iterator(labels=False): cm[u][v] = 2 cm[v][u] = 2 self._coxeter_group = CoxeterGroup(CoxeterMatrix(cm, index_set=G.vertices(sort=True))) rels = tuple(F([i + 1, j + 1, -i - 1, -j - 1]) for i, j in CG.edge_iterator(labels=False)) # +/- 1 for indexing - FinitelyPresentedGroup.__init__(self, F, rels) + FinitelyPresentedGroup.__init__(self, F, rels, + category=Groups().Infinite()) - def _repr_(self): + def _repr_(self) -> str: """ Return a string representation of ``self``. @@ -226,7 +228,7 @@ def gen(self, i): """ return self.element_class(self, ([i, 1],)) - def gens(self): + def gens(self) -> tuple: """ Return the generators of ``self``. @@ -310,8 +312,9 @@ def _element_constructor_(self, x): def _normal_form(self, word): """ - Return the normal form of the word ``word``. Helper function for - creating elements. + Return the normal form of the word ``word``. + + Helper function for creating elements. EXAMPLES:: @@ -435,16 +438,16 @@ def __init__(self, parent, lst): mult += 1 else: if j < 0: - data.append([-j-1, -mult]) + data.append([-j - 1, -mult]) else: - data.append([j-1, mult]) + data.append([j - 1, mult]) j = i mult = 1 if j is not None: if j < 0: - data.append([-j-1, -mult]) + data.append([-j - 1, -mult]) else: - data.append([j-1, mult]) + data.append([j - 1, mult]) self._data = tuple(data) else: self._data = lst @@ -472,7 +475,7 @@ def __reduce__(self): V = P._graph.vertices(sort=True) return (P, ([[V[i], p] for i, p in self._data],)) - def _repr_(self): + def _repr_(self) -> str: """ Return a string representation of ``self``. @@ -499,12 +502,11 @@ def _repr_(self): def to_str(name, p): if p == 1: return "{}".format(name) - else: - return "{}^{}".format(name, p) + return "{}^{}".format(name, p) return '*'.join(to_str(v[i], p) for i, p in self._data) - def _latex_(self): + def _latex_(self) -> str: r""" Return a LaTeX representation of ``self``. @@ -603,7 +605,7 @@ def __invert__(self): lst = [[x[0], -x[1]] for x in reversed(self._data)] return self.__class__(P, P._normal_form(lst)) - def _richcmp_(self, other, op): + def _richcmp_(self, other, op) -> bool: """ Compare ``self`` and ``other``. @@ -627,6 +629,7 @@ def _richcmp_(self, other, op): """ return richcmp(self._data, other._data, op) + class CohomologyRAAG(CombinatorialFreeModule): r""" The cohomology ring of a right-angled Artin group. @@ -652,6 +655,11 @@ def __init__(self, R, A): sage: A = groups.misc.RightAngledArtin(C4) sage: H = A.cohomology() sage: TestSuite(H).run() + + sage: A.cohomology(ZZ) + Traceback (most recent call last): + ... + NotImplementedError: only implemented with coefficients in a field """ if R not in Fields(): raise NotImplementedError("only implemented with coefficients in a field") @@ -666,7 +674,7 @@ def __init__(self, R, A): CombinatorialFreeModule.__init__(self, R, indices, category=cat, prefix='H') self._assign_names(names) - def _repr_(self): + def _repr_(self) -> str: """ Return a string representation of ``self``. @@ -680,10 +688,9 @@ def _repr_(self): """ return "Cohomology ring of {} with coefficients in {}".format(self._group, self.base_ring()) - def _repr_term(self, m): + def _repr_term(self, m) -> str: """ - Return a string representation of the basis element indexed by - ``m``. + Return a string representation of the basis element indexed by ``m``. EXAMPLES:: @@ -743,8 +750,7 @@ def _unicode_art_term(self, m): def _latex_term(self, m): r""" - Return a `\LaTeX` representation of the basis element indexed - by ``m``. + Return a `\LaTeX` representation of the basis element indexed by ``m``. EXAMPLES:: @@ -807,7 +813,7 @@ def algebra_generators(self): Finite family {0: e0, 1: e1, 2: e2, 3: e3} """ V = self._group._graph.vertices(True) - d = {x: self.gen(i) for i,x in enumerate(V)} + d = {x: self.gen(i) for i, x in enumerate(V)} from sage.sets.family import Family return Family(V, lambda x: d[x]) diff --git a/src/sage/interacts/library.py b/src/sage/interacts/library.py index 83b5a93c006..16fadc5b594 100644 --- a/src/sage/interacts/library.py +++ b/src/sage/interacts/library.py @@ -218,11 +218,11 @@ def taylor_polynomial(title, f, order: int): f: EvalText(value='e^(-x)*sin(x)', description='$f(x)=$', layout=Layout(max_width='81em')) order: SelectionSlider(description='order', options=(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), value=1) """ - x0 = 0 - p = plot(f,(x,-1,5), thickness=2) - dot = point((x0,f(x=x0)),pointsize=80,rgbcolor=(1,0,0)) - ft = f.taylor(x,x0,order) - pt = plot(ft,(-1, 5), color='green', thickness=2) + x0 = 0 + p = plot(f, (x, -1, 5), thickness=2) + dot = point((x0, f(x=x0)), pointsize=80, rgbcolor=(1, 0, 0)) + ft = f.taylor(x, x0, order) + pt = plot(ft, (-1, 5), color='green', thickness=2) html(r'$f(x)\;=\;%s$' % latex(f)) html(r'$\hat{f}(x;%s)\;=\;%s+\mathcal{O}(x^{%s})$' % (x0, latex(ft), order + 1)) diff --git a/src/sage/interfaces/gap.py b/src/sage/interfaces/gap.py index 8c4ba93a25f..3a2ed434091 100644 --- a/src/sage/interfaces/gap.py +++ b/src/sage/interfaces/gap.py @@ -1699,7 +1699,7 @@ def gfq_gap_to_sage(x, F): return F(0) i1 = s.index("(") i2 = s.index(")") - q = eval(s[i1+1:i2].replace('^','**')) + q = eval(s[i1+1:i2].replace('^','**')) if not F.cardinality().is_power_of(q): raise ValueError('%r has no subfield of size %r' % (F, q)) if s.find(')^') == -1: diff --git a/src/sage/interfaces/octave.py b/src/sage/interfaces/octave.py index a1a9ba50582..d0f5694c8bc 100644 --- a/src/sage/interfaces/octave.py +++ b/src/sage/interfaces/octave.py @@ -511,7 +511,7 @@ def solve_linear_system(self, A, b): from sage.matrix.matrix_space import MatrixSpace from sage.rings.rational_field import QQ MS = MatrixSpace(QQ,m,1) - b = MS(list(b)) # converted b to a "column vector" + b = MS(list(b)) # converted b to a "column vector" sA = self.sage2octave_matrix_string(A) sb = self.sage2octave_matrix_string(b) self.eval("a = " + sA ) @@ -520,7 +520,7 @@ def solve_linear_system(self, A, b): soln = soln.replace("\n\n ","[") soln = soln.rstrip() + "]" soln = soln.replace("\n",",") - sol = soln[3:] + sol = soln[3:] return eval(sol) def sage2octave_matrix_string(self, A): diff --git a/src/sage/interfaces/singular.py b/src/sage/interfaces/singular.py index 331d698d3ab..c5a50438f03 100644 --- a/src/sage/interfaces/singular.py +++ b/src/sage/interfaces/singular.py @@ -410,7 +410,7 @@ def __init__(self, maxread=None, script_subdirectory=None, verbose_start=False, logfile=logfile, eval_using_file_cutoff=100 if os.uname()[0] == "SunOS" else 1000) - self.__libs = [] + self.__libs = [] self._prompt_wait = prompt self.__to_clear = [] # list of variable names that need to be cleared. self._seed = seed diff --git a/src/sage/interfaces/tides.py b/src/sage/interfaces/tides.py index 765b8bd3cb4..f70a2357cd3 100644 --- a/src/sage/interfaces/tides.py +++ b/src/sage/interfaces/tides.py @@ -532,13 +532,13 @@ def genfiles_mintides(integrator, driver, f, ics, initial, final, delta, elif el[0] == 'div_c': string += "inv_mc("+el[2]+","+el[1]+",XX[{}], i);".format(i+n) elif el[0] == 'log': - string += "log_mc("+el[1]+",XX[{}], i);".format(i+n) + string += "log_mc(" + el[1] + ",XX[{}], i);".format(i+n) elif el[0] == 'exp': - string += "exp_mc("+el[1]+",XX[{}], i);".format(i+n) + string += "exp_mc(" + el[1] + ",XX[{}], i);".format(i+n) elif el[0] == 'sin': - string += "sin_mc("+el[1]+",XX[{}], i);".format(i+n+1) + string += "sin_mc(" + el[1] + ",XX[{}], i);".format(i+n+1) elif el[0] == 'cos': - string += "cos_mc("+el[1]+",XX[{}], i);".format(i+n-1) + string += "cos_mc(" + el[1] + ",XX[{}], i);".format(i+n-1) res.append(string) @@ -583,7 +583,7 @@ def genfiles_mintides(integrator, driver, f, ics, initial, final, delta, for(i=0;i 11 and co > 1: @@ -3873,7 +3873,7 @@ def _knotinfo_matching_list(self): if cr > 12: cr = 12 - Hp = self.homfly_polynomial(normalization='vz') + Hp = self.homfly_polynomial(normalization='vz') det = None if cr > 6: @@ -3902,7 +3902,7 @@ def _knotinfo_matching_list(self): ln = Sn.lower_list(oriented=True, comp=co, det=det, homfly=Hp) l = sorted(list(set(la + ln))) - br = self.braid() + br = self.braid() br_ind = br.strands() res = [] diff --git a/src/sage/libs/arb/arith.pyx b/src/sage/libs/arb/arith.pyx index 3b32fe7e8ed..69281d916ce 100644 --- a/src/sage/libs/arb/arith.pyx +++ b/src/sage/libs/arb/arith.pyx @@ -12,10 +12,10 @@ Arithmetic functions using the arb library # http://www.gnu.org/licenses/ #***************************************************************************** -from ..flint.types cimport ulong -from ..flint.fmpq cimport fmpq_t, fmpq_init, fmpq_clear, fmpq_get_mpq -from .bernoulli cimport bernoulli_fmpq_ui -from .acb_modular cimport acb_modular_hilbert_class_poly +from sage.libs.flint.types cimport ulong +from sage.libs.flint.fmpq cimport fmpq_t, fmpq_init, fmpq_clear, fmpq_get_mpq +from sage.libs.arb.bernoulli cimport bernoulli_fmpq_ui +from sage.libs.arb.acb_modular cimport acb_modular_hilbert_class_poly from sage.rings.rational cimport Rational from sage.rings.polynomial.polynomial_integer_dense_flint cimport Polynomial_integer_dense_flint from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing diff --git a/src/sage/libs/arb/bernoulli.pxd b/src/sage/libs/arb/bernoulli.pxd index 375b2b9bbcf..f859ebfb8d7 100644 --- a/src/sage/libs/arb/bernoulli.pxd +++ b/src/sage/libs/arb/bernoulli.pxd @@ -1,7 +1,7 @@ # distutils: libraries = gmp flint ARB_LIBRARY # distutils: depends = bernoulli.h -from ..flint.types cimport fmpq_t, ulong +from sage.libs.flint.types cimport fmpq_t, ulong # bernoulli.h cdef extern from "arb_wrap.h": diff --git a/src/sage/libs/coxeter3/coxeter.pxd b/src/sage/libs/coxeter3/coxeter.pxd index c30ca1925b8..e8a89458e78 100644 --- a/src/sage/libs/coxeter3/coxeter.pxd +++ b/src/sage/libs/coxeter3/coxeter.pxd @@ -8,7 +8,7 @@ #***************************************************************************** from sage.structure.sage_object cimport SageObject -from .decl cimport * +from sage.libs.coxeter3.decl cimport * cdef class String: cdef c_String x diff --git a/src/sage/libs/coxeter3/coxeter.pyx b/src/sage/libs/coxeter3/coxeter.pyx index 1b21b010481..83cd1dccaee 100644 --- a/src/sage/libs/coxeter3/coxeter.pyx +++ b/src/sage/libs/coxeter3/coxeter.pyx @@ -17,7 +17,7 @@ Low level part of the interface to Fokko Ducloux's Coxeter 3 library # https://www.gnu.org/licenses/ # **************************************************************************** -from .decl cimport * +from sage.libs.coxeter3.decl cimport * from cpython.object cimport Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, Py_GE from sage.cpython.string cimport str_to_bytes, bytes_to_str diff --git a/src/sage/libs/eclib/homspace.pxd b/src/sage/libs/eclib/homspace.pxd index bf315f40ca9..d3600547f1e 100644 --- a/src/sage/libs/eclib/homspace.pxd +++ b/src/sage/libs/eclib/homspace.pxd @@ -1,4 +1,4 @@ -from ..eclib cimport homspace +from sage.libs.eclib cimport homspace cdef class ModularSymbols: cdef homspace* H diff --git a/src/sage/libs/eclib/homspace.pyx b/src/sage/libs/eclib/homspace.pyx index dc52b144328..735de8787e2 100644 --- a/src/sage/libs/eclib/homspace.pyx +++ b/src/sage/libs/eclib/homspace.pyx @@ -4,8 +4,8 @@ from cysignals.signals cimport sig_on, sig_off from cython.operator cimport dereference as deref from cython.operator cimport preincrement as inc -from ..eclib cimport svec, mat, smat -from .mat cimport MatrixFactory +from sage.libs.eclib cimport svec, mat, smat +from sage.libs.eclib.mat cimport MatrixFactory from sage.matrix.matrix_space import MatrixSpace from sage.rings.integer_ring import ZZ diff --git a/src/sage/libs/eclib/mat.pxd b/src/sage/libs/eclib/mat.pxd index 0bba3eb62d5..de8d9e81ad3 100644 --- a/src/sage/libs/eclib/mat.pxd +++ b/src/sage/libs/eclib/mat.pxd @@ -1,11 +1,7 @@ -from ..eclib cimport mat +from sage.libs.eclib cimport mat cdef class Matrix: cdef mat* M cdef class MatrixFactory: cdef new_matrix(self, mat M) noexcept - - - - diff --git a/src/sage/libs/eclib/mat.pyx b/src/sage/libs/eclib/mat.pyx index 24c5ce55fb2..b83cd76b5a5 100644 --- a/src/sage/libs/eclib/mat.pyx +++ b/src/sage/libs/eclib/mat.pyx @@ -2,7 +2,7 @@ Cremona matrices """ -from ..eclib cimport scalar, addscalar +from sage.libs.eclib cimport scalar, addscalar from sage.matrix.matrix_space import MatrixSpace from sage.rings.integer_ring import ZZ diff --git a/src/sage/libs/eclib/newforms.pxd b/src/sage/libs/eclib/newforms.pxd index 9cd1b23a034..7f78a4f9f63 100644 --- a/src/sage/libs/eclib/newforms.pxd +++ b/src/sage/libs/eclib/newforms.pxd @@ -1,4 +1,4 @@ -from ..eclib cimport newforms +from sage.libs.eclib cimport newforms cdef class ECModularSymbol: cdef newforms* nfs diff --git a/src/sage/libs/eclib/newforms.pyx b/src/sage/libs/eclib/newforms.pyx index 2d35716c4db..210c1d9e2c0 100644 --- a/src/sage/libs/eclib/newforms.pyx +++ b/src/sage/libs/eclib/newforms.pyx @@ -13,7 +13,7 @@ Modular symbols using eclib newforms from cysignals.signals cimport sig_on, sig_off -from ..eclib cimport * +from sage.libs.eclib cimport * from sage.libs.gmp.mpq cimport mpq_numref from sage.libs.ntl.convert cimport mpz_to_ZZ from sage.rings.rational_field import QQ diff --git a/src/sage/libs/flint/arith.pyx b/src/sage/libs/flint/arith.pyx index f24446b4ae4..fefe5f07efd 100644 --- a/src/sage/libs/flint/arith.pyx +++ b/src/sage/libs/flint/arith.pyx @@ -15,8 +15,8 @@ FLINT Arithmetic Functions from cysignals.signals cimport sig_on, sig_off -from .fmpz cimport * -from .fmpq cimport * +from sage.libs.flint.fmpz cimport * +from sage.libs.flint.fmpq cimport * from sage.rings.integer cimport Integer diff --git a/src/sage/libs/flint/ntl_interface.pxd b/src/sage/libs/flint/ntl_interface.pxd index d3ba446d8d3..d6112383330 100644 --- a/src/sage/libs/flint/ntl_interface.pxd +++ b/src/sage/libs/flint/ntl_interface.pxd @@ -2,7 +2,7 @@ # distutils: libraries = flint # distutils: depends = flint/NTL-interface.h -from .types cimport fmpz_t, fmpz_poly_t +from sage.libs.flint.types cimport fmpz_t, fmpz_poly_t from sage.libs.ntl.ZZ cimport ZZ_c from sage.libs.ntl.ZZX cimport ZZX_c diff --git a/src/sage/libs/gap/element.pxd b/src/sage/libs/gap/element.pxd index 7882414df20..329001e72f5 100644 --- a/src/sage/libs/gap/element.pxd +++ b/src/sage/libs/gap/element.pxd @@ -8,7 +8,7 @@ # http://www.gnu.org/licenses/ #***************************************************************************** -from .gap_includes cimport Obj, UInt +from sage.libs.gap.gap_includes cimport Obj, UInt from sage.structure.sage_object cimport SageObject from sage.structure.element cimport Element, ModuleElement, RingElement diff --git a/src/sage/libs/gap/element.pyx b/src/sage/libs/gap/element.pyx index a5f0dfcd24c..e522bf5bc03 100644 --- a/src/sage/libs/gap/element.pyx +++ b/src/sage/libs/gap/element.pyx @@ -18,10 +18,10 @@ elements. For general information about GAP, you should read the from cpython.object cimport Py_EQ, Py_NE, Py_LE, Py_GE, Py_LT, Py_GT from cysignals.signals cimport sig_on, sig_off -from .gap_includes cimport * -from .libgap import libgap -from .util cimport * -from .util import GAPError +from sage.libs.gap.gap_includes cimport * +from sage.libs.gap.libgap import libgap +from sage.libs.gap.util cimport * +from sage.libs.gap.util import GAPError from sage.cpython.string cimport str_to_bytes, char_to_str from sage.rings.integer_ring import ZZ from sage.rings.rational_field import QQ diff --git a/src/sage/libs/gap/libgap.pyx b/src/sage/libs/gap/libgap.pyx index 33a17cff528..3803f32b191 100644 --- a/src/sage/libs/gap/libgap.pyx +++ b/src/sage/libs/gap/libgap.pyx @@ -213,9 +213,9 @@ AUTHORS: from pathlib import Path -from .gap_includes cimport * -from .util cimport * -from .element cimport * +from sage.libs.gap.gap_includes cimport * +from sage.libs.gap.util cimport * +from sage.libs.gap.element cimport * from sage.cpython.string cimport str_to_bytes from sage.structure.parent cimport Parent diff --git a/src/sage/libs/gap/util.pxd b/src/sage/libs/gap/util.pxd index e7b499a7b5a..8b4a7aadce7 100644 --- a/src/sage/libs/gap/util.pxd +++ b/src/sage/libs/gap/util.pxd @@ -8,7 +8,7 @@ # http://www.gnu.org/licenses/ #***************************************************************************** -from .gap_includes cimport Obj +from sage.libs.gap.gap_includes cimport Obj ############################################################################ ### Hooking into the GAP memory management ################################# diff --git a/src/sage/libs/gap/util.pyx b/src/sage/libs/gap/util.pyx index f4f18589e14..d37fe84f029 100644 --- a/src/sage/libs/gap/util.pyx +++ b/src/sage/libs/gap/util.pyx @@ -24,8 +24,8 @@ import os import warnings import sage.env -from .gap_includes cimport * -from .element cimport * +from sage.libs.gap.gap_includes cimport * +from sage.libs.gap.element cimport * from sage.cpython.string import FS_ENCODING from sage.cpython.string cimport str_to_bytes, char_to_str from sage.interfaces.gap_workspace import prepare_workspace_dir @@ -240,7 +240,7 @@ cdef initialize() noexcept: argv[11] = s1 argv[4] = s1 - from .saved_workspace import workspace + from sage.libs.gap.saved_workspace import workspace workspace, workspace_is_up_to_date = workspace() ws = str_to_bytes(workspace, FS_ENCODING, "surrogateescape") if workspace_is_up_to_date: diff --git a/src/sage/libs/giac/__init__.py b/src/sage/libs/giac/__init__.py index 558cd894b13..e7d7bc67d14 100644 --- a/src/sage/libs/giac/__init__.py +++ b/src/sage/libs/giac/__init__.py @@ -172,9 +172,9 @@ def groebner_basis(gens, proba_epsilon=None, threads=None, prot=False, sage: from sage.libs.giac import groebner_basis as gb_giac sage: P = PolynomialRing(GF(previous_prime(2**31)), 6, 'x') sage: I = sage.rings.ideal.Cyclic(P) - sage: B=gb_giac(I.gens());B - - // Groebner basis computation time ... + sage: B = gb_giac(I.gens()) + ... + sage: B Polynomial Sequence with 45 Polynomials in 6 Variables sage: B.is_groebner() True @@ -184,8 +184,7 @@ def groebner_basis(gens, proba_epsilon=None, threads=None, prot=False, sage: P = PolynomialRing(GF(previous_prime(2**31)), 5, 'x') sage: I = sage.rings.ideal.Cyclic(P) sage: B = gb_giac(I.gens(), elim_variables=[P.gen(0), P.gen(2)]) - - // Groebner basis computation time ... + ... sage: B.is_groebner() True sage: B.ideal() == I.elimination_ideal([P.gen(0), P.gen(2)]) @@ -201,11 +200,10 @@ def groebner_basis(gens, proba_epsilon=None, threads=None, prot=False, ... sage: sage.structure.proof.all.polynomial(True) sage: B2 = gb_giac(I.gens()) # long time (4s) - - // Groebner basis computation time... + ... sage: B1 == B2 # long time True - sage: B1.is_groebner() # long time (20s) + sage: B1.is_groebner() # not tested, too long time (50s) True * multi threaded operations:: @@ -253,9 +251,7 @@ def groebner_basis(gens, proba_epsilon=None, threads=None, prot=False, sage: libgiac.purge('x2'),libgiac.purge('x4') (22, whywouldyoudothis) sage: gb_giac(I) # long time (3s) - - // Groebner basis computation time... - Polynomial Sequence with 74 Polynomials in 8 Variables + ...Polynomial Sequence with 74 Polynomials in 8 Variables sage: I = ideal(P(0),P(0)) sage: I.groebner_basis() == gb_giac(I) diff --git a/src/sage/libs/glpk/error.pyx b/src/sage/libs/glpk/error.pyx index 1d265f3ef65..da5595a7709 100644 --- a/src/sage/libs/glpk/error.pyx +++ b/src/sage/libs/glpk/error.pyx @@ -14,7 +14,7 @@ Error handler for the GLPK library from cysignals.signals cimport sig_error -from .env cimport * +from sage.libs.glpk.env cimport * from cpython.exc cimport PyErr_SetObject from sage.cpython.string cimport char_to_str from sage.numerical.mip import MIPSolverException diff --git a/src/sage/libs/gmp/all.pxd b/src/sage/libs/gmp/all.pxd index c9b26912094..cf1f3fa6417 100644 --- a/src/sage/libs/gmp/all.pxd +++ b/src/sage/libs/gmp/all.pxd @@ -1,5 +1,5 @@ -from .types cimport * -from .random cimport * -from .mpz cimport * -from .mpq cimport * -from .pylong cimport * +from sage.libs.gmp.types cimport * +from sage.libs.gmp.random cimport * +from sage.libs.gmp.mpz cimport * +from sage.libs.gmp.mpq cimport * +from sage.libs.gmp.pylong cimport * diff --git a/src/sage/libs/gmp/binop.pxd b/src/sage/libs/gmp/binop.pxd index 983e6de5214..6b56c24a1b5 100644 --- a/src/sage/libs/gmp/binop.pxd +++ b/src/sage/libs/gmp/binop.pxd @@ -2,9 +2,9 @@ r""" Fast binary operations for basic types """ -from .types cimport mpz_t, mpq_t -from .mpz cimport mpz_set, mpz_add, mpz_mul -from .mpq cimport mpq_canonicalize, mpq_numref, mpq_denref, mpq_add +from sage.libs.gmp.types cimport mpz_t, mpq_t +from sage.libs.gmp.mpz cimport mpz_set, mpz_add, mpz_mul +from sage.libs.gmp.mpq cimport mpq_canonicalize, mpq_numref, mpq_denref, mpq_add cdef inline void mpq_add_z(mpq_t res, mpq_t op1, mpz_t op2) noexcept: mpz_mul(mpq_numref(res), mpq_denref(op1), op2) diff --git a/src/sage/libs/gmp/mpf.pxd b/src/sage/libs/gmp/mpf.pxd index 7095c51073a..b63d84009c0 100644 --- a/src/sage/libs/gmp/mpf.pxd +++ b/src/sage/libs/gmp/mpf.pxd @@ -1,6 +1,6 @@ # distutils: libraries = gmp -from .types cimport * +from sage.libs.gmp.types cimport * cdef extern from "gmp.h": diff --git a/src/sage/libs/gmp/mpn.pxd b/src/sage/libs/gmp/mpn.pxd index 6bc40ff0150..890c5b63da7 100644 --- a/src/sage/libs/gmp/mpn.pxd +++ b/src/sage/libs/gmp/mpn.pxd @@ -1,6 +1,6 @@ # distutils: libraries = gmp -from .types cimport * +from sage.libs.gmp.types cimport * cdef extern from "gmp.h": diff --git a/src/sage/libs/gmp/mpq.pxd b/src/sage/libs/gmp/mpq.pxd index 6b7d9929620..d865630aee0 100644 --- a/src/sage/libs/gmp/mpq.pxd +++ b/src/sage/libs/gmp/mpq.pxd @@ -1,6 +1,6 @@ # distutils: libraries = gmp -from .types cimport * +from sage.libs.gmp.types cimport * cdef extern from "gmp.h": diff --git a/src/sage/libs/gmp/mpz.pxd b/src/sage/libs/gmp/mpz.pxd index 91e35963300..71d1e5e3069 100644 --- a/src/sage/libs/gmp/mpz.pxd +++ b/src/sage/libs/gmp/mpz.pxd @@ -1,6 +1,6 @@ # distutils: libraries = gmp -from .types cimport * +from sage.libs.gmp.types cimport * from libc.stdio cimport FILE from libc.stdint cimport intmax_t, uintmax_t diff --git a/src/sage/libs/gmp/pylong.pyx b/src/sage/libs/gmp/pylong.pyx index 833d44c9bc9..406f2703c1f 100644 --- a/src/sage/libs/gmp/pylong.pyx +++ b/src/sage/libs/gmp/pylong.pyx @@ -30,7 +30,7 @@ from cpython.long cimport PyLong_FromLong from cpython.longintrepr cimport _PyLong_New, py_long, digit, PyLong_SHIFT from sage.cpython.pycore_long cimport (ob_digit, _PyLong_IsNegative, _PyLong_DigitCount, _PyLong_SetSignAndDigitCount) -from .mpz cimport * +from sage.libs.gmp.mpz cimport * cdef extern from *: """ diff --git a/src/sage/libs/gmp/random.pxd b/src/sage/libs/gmp/random.pxd index 6c1a529dbd4..a50657454ca 100644 --- a/src/sage/libs/gmp/random.pxd +++ b/src/sage/libs/gmp/random.pxd @@ -1,6 +1,6 @@ # distutils: libraries = gmp -from .types cimport * +from sage.libs.gmp.types cimport * cdef extern from "gmp.h": diff --git a/src/sage/libs/gsl/airy.pxd b/src/sage/libs/gsl/airy.pxd index f9983ef0d79..7e996d5af81 100644 --- a/src/sage/libs/gsl/airy.pxd +++ b/src/sage/libs/gsl/airy.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_airy.h": diff --git a/src/sage/libs/gsl/all.pxd b/src/sage/libs/gsl/all.pxd index 34e93ea2535..099399d9f3f 100644 --- a/src/sage/libs/gsl/all.pxd +++ b/src/sage/libs/gsl/all.pxd @@ -1,65 +1,65 @@ -from .types cimport * +from sage.libs.gsl.types cimport * -from .math cimport * -from .complex cimport * -from .poly cimport * -from .airy cimport * -from .bessel cimport * -from .clausen cimport * -from .coulomb cimport * -from .coupling cimport * -from .dawson cimport * -from .debye cimport * -from .dilog cimport * -from .elementary cimport * -from .ellint cimport * -from .elljac cimport * -from .erf cimport * -from .exp cimport * -from .expint cimport * -from .fermi_dirac cimport * -from .gamma cimport * -from .gegenbauer cimport * -from .hyperg cimport * -from .laguerre cimport * -from .lambert cimport * -from .legendre cimport * -from .log cimport * -from .pow_int cimport * -from .psi cimport * -from .synchrotron cimport * -from .transport cimport * -from .trig cimport * -from .wavelet cimport * -from .zeta cimport * +from sage.libs.gsl.math cimport * +from sage.libs.gsl.complex cimport * +from sage.libs.gsl.poly cimport * +from sage.libs.gsl.airy cimport * +from sage.libs.gsl.bessel cimport * +from sage.libs.gsl.clausen cimport * +from sage.libs.gsl.coulomb cimport * +from sage.libs.gsl.coupling cimport * +from sage.libs.gsl.dawson cimport * +from sage.libs.gsl.debye cimport * +from sage.libs.gsl.dilog cimport * +from sage.libs.gsl.elementary cimport * +from sage.libs.gsl.ellint cimport * +from sage.libs.gsl.elljac cimport * +from sage.libs.gsl.erf cimport * +from sage.libs.gsl.exp cimport * +from sage.libs.gsl.expint cimport * +from sage.libs.gsl.fermi_dirac cimport * +from sage.libs.gsl.gamma cimport * +from sage.libs.gsl.gegenbauer cimport * +from sage.libs.gsl.hyperg cimport * +from sage.libs.gsl.laguerre cimport * +from sage.libs.gsl.lambert cimport * +from sage.libs.gsl.legendre cimport * +from sage.libs.gsl.log cimport * +from sage.libs.gsl.pow_int cimport * +from sage.libs.gsl.psi cimport * +from sage.libs.gsl.synchrotron cimport * +from sage.libs.gsl.transport cimport * +from sage.libs.gsl.trig cimport * +from sage.libs.gsl.wavelet cimport * +from sage.libs.gsl.zeta cimport * -from .block cimport * -from .vector cimport * -from .vector_complex cimport * -from .matrix cimport * -from .matrix_complex cimport * +from sage.libs.gsl.block cimport * +from sage.libs.gsl.vector cimport * +from sage.libs.gsl.vector_complex cimport * +from sage.libs.gsl.matrix cimport * +from sage.libs.gsl.matrix_complex cimport * -from .permutation cimport * -from .combination cimport * -from .sort cimport * +from sage.libs.gsl.permutation cimport * +from sage.libs.gsl.combination cimport * +from sage.libs.gsl.sort cimport * -from .blas cimport * -from .linalg cimport * -from .eigen cimport * -from .fft cimport * -from .integration cimport * -from .rng cimport * -from .qrng cimport * -from .random cimport * -from .statistics cimport * -from .histogram cimport * -from .ntuple cimport * -from .monte cimport * -from .odeiv cimport * -from .interp cimport * -from .chebyshev cimport * -from .sum cimport * -from .roots cimport * -from .min cimport * -from .fit cimport * -from .errno cimport * +from sage.libs.gsl.blas cimport * +from sage.libs.gsl.linalg cimport * +from sage.libs.gsl.eigen cimport * +from sage.libs.gsl.fft cimport * +from sage.libs.gsl.integration cimport * +from sage.libs.gsl.rng cimport * +from sage.libs.gsl.qrng cimport * +from sage.libs.gsl.random cimport * +from sage.libs.gsl.statistics cimport * +from sage.libs.gsl.histogram cimport * +from sage.libs.gsl.ntuple cimport * +from sage.libs.gsl.monte cimport * +from sage.libs.gsl.odeiv cimport * +from sage.libs.gsl.interp cimport * +from sage.libs.gsl.chebyshev cimport * +from sage.libs.gsl.sum cimport * +from sage.libs.gsl.roots cimport * +from sage.libs.gsl.min cimport * +from sage.libs.gsl.fit cimport * +from sage.libs.gsl.errno cimport * diff --git a/src/sage/libs/gsl/bessel.pxd b/src/sage/libs/gsl/bessel.pxd index e03a0e4866e..8a0a521aa3d 100644 --- a/src/sage/libs/gsl/bessel.pxd +++ b/src/sage/libs/gsl/bessel.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_bessel.h": diff --git a/src/sage/libs/gsl/blas.pxd b/src/sage/libs/gsl/blas.pxd index 509e9639594..7b195751993 100644 --- a/src/sage/libs/gsl/blas.pxd +++ b/src/sage/libs/gsl/blas.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_blas.h": diff --git a/src/sage/libs/gsl/block.pxd b/src/sage/libs/gsl/block.pxd index 76f928736a6..69ee5251dda 100644 --- a/src/sage/libs/gsl/block.pxd +++ b/src/sage/libs/gsl/block.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_block_double.h": diff --git a/src/sage/libs/gsl/chebyshev.pxd b/src/sage/libs/gsl/chebyshev.pxd index c713974b125..06d2da41732 100644 --- a/src/sage/libs/gsl/chebyshev.pxd +++ b/src/sage/libs/gsl/chebyshev.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_chebyshev.h": diff --git a/src/sage/libs/gsl/clausen.pxd b/src/sage/libs/gsl/clausen.pxd index bb34bc5000f..2f92518e171 100644 --- a/src/sage/libs/gsl/clausen.pxd +++ b/src/sage/libs/gsl/clausen.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_clausen.h": diff --git a/src/sage/libs/gsl/combination.pxd b/src/sage/libs/gsl/combination.pxd index a3a2851452d..6072fb2417a 100644 --- a/src/sage/libs/gsl/combination.pxd +++ b/src/sage/libs/gsl/combination.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_combination.h": diff --git a/src/sage/libs/gsl/complex.pxd b/src/sage/libs/gsl/complex.pxd index b6e0a16fbb1..87fd3957b62 100644 --- a/src/sage/libs/gsl/complex.pxd +++ b/src/sage/libs/gsl/complex.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_complex.h": double GSL_REAL(gsl_complex z) diff --git a/src/sage/libs/gsl/coulomb.pxd b/src/sage/libs/gsl/coulomb.pxd index 39fb4bdc54f..7941dff093d 100644 --- a/src/sage/libs/gsl/coulomb.pxd +++ b/src/sage/libs/gsl/coulomb.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_coulomb.h": diff --git a/src/sage/libs/gsl/coupling.pxd b/src/sage/libs/gsl/coupling.pxd index 72052d9db7f..cd5f4d301a6 100644 --- a/src/sage/libs/gsl/coupling.pxd +++ b/src/sage/libs/gsl/coupling.pxd @@ -2,7 +2,7 @@ # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR # distutils: extra_compile_args = -DGSL_DISABLE_DEPRECATED -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_coupling.h": diff --git a/src/sage/libs/gsl/dawson.pxd b/src/sage/libs/gsl/dawson.pxd index 8988a68df7f..9eccc6c4485 100644 --- a/src/sage/libs/gsl/dawson.pxd +++ b/src/sage/libs/gsl/dawson.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_dawson.h": diff --git a/src/sage/libs/gsl/debye.pxd b/src/sage/libs/gsl/debye.pxd index c6e5c86d2ab..ca6d5722e56 100644 --- a/src/sage/libs/gsl/debye.pxd +++ b/src/sage/libs/gsl/debye.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_debye.h": diff --git a/src/sage/libs/gsl/dilog.pxd b/src/sage/libs/gsl/dilog.pxd index 79adc6c28e9..30f633dd5d2 100644 --- a/src/sage/libs/gsl/dilog.pxd +++ b/src/sage/libs/gsl/dilog.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_dilog.h": diff --git a/src/sage/libs/gsl/eigen.pxd b/src/sage/libs/gsl/eigen.pxd index 0ad97189a56..a0568b1f464 100644 --- a/src/sage/libs/gsl/eigen.pxd +++ b/src/sage/libs/gsl/eigen.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_eigen.h": diff --git a/src/sage/libs/gsl/elementary.pxd b/src/sage/libs/gsl/elementary.pxd index f3a026c201f..66e3d39b1e9 100644 --- a/src/sage/libs/gsl/elementary.pxd +++ b/src/sage/libs/gsl/elementary.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_elementary.h": diff --git a/src/sage/libs/gsl/ellint.pxd b/src/sage/libs/gsl/ellint.pxd index d1156a3b285..2c6cdfb9662 100644 --- a/src/sage/libs/gsl/ellint.pxd +++ b/src/sage/libs/gsl/ellint.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_ellint.h": diff --git a/src/sage/libs/gsl/erf.pxd b/src/sage/libs/gsl/erf.pxd index 50cce929848..3035944ae47 100644 --- a/src/sage/libs/gsl/erf.pxd +++ b/src/sage/libs/gsl/erf.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_erf.h": diff --git a/src/sage/libs/gsl/exp.pxd b/src/sage/libs/gsl/exp.pxd index 61d253236f6..875f5564053 100644 --- a/src/sage/libs/gsl/exp.pxd +++ b/src/sage/libs/gsl/exp.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_exp.h": diff --git a/src/sage/libs/gsl/expint.pxd b/src/sage/libs/gsl/expint.pxd index f4155af974c..66e2e7b2091 100644 --- a/src/sage/libs/gsl/expint.pxd +++ b/src/sage/libs/gsl/expint.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_expint.h": diff --git a/src/sage/libs/gsl/fermi_dirac.pxd b/src/sage/libs/gsl/fermi_dirac.pxd index cf23826b800..367fe60f293 100644 --- a/src/sage/libs/gsl/fermi_dirac.pxd +++ b/src/sage/libs/gsl/fermi_dirac.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_fermi_dirac.h": diff --git a/src/sage/libs/gsl/fft.pxd b/src/sage/libs/gsl/fft.pxd index d45e866f82c..8d0bbff58c1 100644 --- a/src/sage/libs/gsl/fft.pxd +++ b/src/sage/libs/gsl/fft.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_fft.h": cdef enum gsl_fft_direction: diff --git a/src/sage/libs/gsl/gamma.pxd b/src/sage/libs/gsl/gamma.pxd index 43f297a08ad..59bcced37be 100644 --- a/src/sage/libs/gsl/gamma.pxd +++ b/src/sage/libs/gsl/gamma.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_gamma.h": diff --git a/src/sage/libs/gsl/gegenbauer.pxd b/src/sage/libs/gsl/gegenbauer.pxd index 4990ea7cd1c..8b3c802a9b9 100644 --- a/src/sage/libs/gsl/gegenbauer.pxd +++ b/src/sage/libs/gsl/gegenbauer.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_gegenbauer.h": diff --git a/src/sage/libs/gsl/histogram.pxd b/src/sage/libs/gsl/histogram.pxd index 794f60a9f89..6e83a5e48a8 100644 --- a/src/sage/libs/gsl/histogram.pxd +++ b/src/sage/libs/gsl/histogram.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_histogram.h": gsl_histogram * gsl_histogram_alloc (size_t n) diff --git a/src/sage/libs/gsl/hyperg.pxd b/src/sage/libs/gsl/hyperg.pxd index e1279e8bb28..3e85ebfb0e4 100644 --- a/src/sage/libs/gsl/hyperg.pxd +++ b/src/sage/libs/gsl/hyperg.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_hyperg.h": diff --git a/src/sage/libs/gsl/integration.pxd b/src/sage/libs/gsl/integration.pxd index 24b3e7d3e9f..0a584a90ecd 100644 --- a/src/sage/libs/gsl/integration.pxd +++ b/src/sage/libs/gsl/integration.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_integration.h": diff --git a/src/sage/libs/gsl/laguerre.pxd b/src/sage/libs/gsl/laguerre.pxd index f40b5907201..14a2bcbee83 100644 --- a/src/sage/libs/gsl/laguerre.pxd +++ b/src/sage/libs/gsl/laguerre.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_laguerre.h": diff --git a/src/sage/libs/gsl/lambert.pxd b/src/sage/libs/gsl/lambert.pxd index 03a511880db..e30e41f0bd9 100644 --- a/src/sage/libs/gsl/lambert.pxd +++ b/src/sage/libs/gsl/lambert.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_lambert.h": diff --git a/src/sage/libs/gsl/legendre.pxd b/src/sage/libs/gsl/legendre.pxd index 982c3a5aee7..f9a69910bc2 100644 --- a/src/sage/libs/gsl/legendre.pxd +++ b/src/sage/libs/gsl/legendre.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_legendre.h": diff --git a/src/sage/libs/gsl/linalg.pxd b/src/sage/libs/gsl/linalg.pxd index 6441b3a3bf8..389ec2e7997 100644 --- a/src/sage/libs/gsl/linalg.pxd +++ b/src/sage/libs/gsl/linalg.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_linalg.h": diff --git a/src/sage/libs/gsl/log.pxd b/src/sage/libs/gsl/log.pxd index 2077b7d2296..35798b2b150 100644 --- a/src/sage/libs/gsl/log.pxd +++ b/src/sage/libs/gsl/log.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_log.h": diff --git a/src/sage/libs/gsl/math.pxd b/src/sage/libs/gsl/math.pxd index 11087d78ca9..0f0a27a58e1 100644 --- a/src/sage/libs/gsl/math.pxd +++ b/src/sage/libs/gsl/math.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_math.h": bint gsl_isnan(double x) diff --git a/src/sage/libs/gsl/matrix.pxd b/src/sage/libs/gsl/matrix.pxd index bf6df93b29b..e1e2009b609 100644 --- a/src/sage/libs/gsl/matrix.pxd +++ b/src/sage/libs/gsl/matrix.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_matrix_double.h": # Allocation diff --git a/src/sage/libs/gsl/matrix_complex.pxd b/src/sage/libs/gsl/matrix_complex.pxd index 5a2366479a5..6cbc983a45e 100644 --- a/src/sage/libs/gsl/matrix_complex.pxd +++ b/src/sage/libs/gsl/matrix_complex.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_matrix_complex_double.h": # Allocation diff --git a/src/sage/libs/gsl/min.pxd b/src/sage/libs/gsl/min.pxd index 0843984a476..25a9770eba0 100644 --- a/src/sage/libs/gsl/min.pxd +++ b/src/sage/libs/gsl/min.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_min.h": diff --git a/src/sage/libs/gsl/monte.pxd b/src/sage/libs/gsl/monte.pxd index 05879875c20..92142abdbcc 100644 --- a/src/sage/libs/gsl/monte.pxd +++ b/src/sage/libs/gsl/monte.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_monte.h": ctypedef struct gsl_monte_function: diff --git a/src/sage/libs/gsl/ntuple.pxd b/src/sage/libs/gsl/ntuple.pxd index 13827e8903f..c47ab38d289 100644 --- a/src/sage/libs/gsl/ntuple.pxd +++ b/src/sage/libs/gsl/ntuple.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_ntuple.h": ctypedef struct gsl_ntuple diff --git a/src/sage/libs/gsl/permutation.pxd b/src/sage/libs/gsl/permutation.pxd index 5bf7cd6ba68..49b10e0611d 100644 --- a/src/sage/libs/gsl/permutation.pxd +++ b/src/sage/libs/gsl/permutation.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_permutation.h": # Allocation diff --git a/src/sage/libs/gsl/poly.pxd b/src/sage/libs/gsl/poly.pxd index 997ecd24eca..ae172cbf07f 100644 --- a/src/sage/libs/gsl/poly.pxd +++ b/src/sage/libs/gsl/poly.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_poly.h": diff --git a/src/sage/libs/gsl/pow_int.pxd b/src/sage/libs/gsl/pow_int.pxd index 0056cc9d402..af5de0263b8 100644 --- a/src/sage/libs/gsl/pow_int.pxd +++ b/src/sage/libs/gsl/pow_int.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_pow_int.h": diff --git a/src/sage/libs/gsl/psi.pxd b/src/sage/libs/gsl/psi.pxd index 4740ebd62a5..fd33ccd636c 100644 --- a/src/sage/libs/gsl/psi.pxd +++ b/src/sage/libs/gsl/psi.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_psi.h": diff --git a/src/sage/libs/gsl/random.pxd b/src/sage/libs/gsl/random.pxd index 80ac3c2016f..21f531265bc 100644 --- a/src/sage/libs/gsl/random.pxd +++ b/src/sage/libs/gsl/random.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_randist.h": unsigned int gsl_ran_bernoulli ( gsl_rng * r, double p) diff --git a/src/sage/libs/gsl/rng.pxd b/src/sage/libs/gsl/rng.pxd index 88ccf7d7a78..b1ab233715e 100644 --- a/src/sage/libs/gsl/rng.pxd +++ b/src/sage/libs/gsl/rng.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_rng.h": cdef gsl_rng_type *gsl_rng_borosh13 diff --git a/src/sage/libs/gsl/roots.pxd b/src/sage/libs/gsl/roots.pxd index 841f94dbc82..2bf1ccf9403 100644 --- a/src/sage/libs/gsl/roots.pxd +++ b/src/sage/libs/gsl/roots.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_roots.h": diff --git a/src/sage/libs/gsl/sort.pxd b/src/sage/libs/gsl/sort.pxd index 892e7a22304..68493a8a1a8 100644 --- a/src/sage/libs/gsl/sort.pxd +++ b/src/sage/libs/gsl/sort.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_heapsort.h": diff --git a/src/sage/libs/gsl/synchrotron.pxd b/src/sage/libs/gsl/synchrotron.pxd index 28581337097..a02c9964fc2 100644 --- a/src/sage/libs/gsl/synchrotron.pxd +++ b/src/sage/libs/gsl/synchrotron.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_synchrotron.h": diff --git a/src/sage/libs/gsl/transport.pxd b/src/sage/libs/gsl/transport.pxd index 389da93e607..6700511a9c9 100644 --- a/src/sage/libs/gsl/transport.pxd +++ b/src/sage/libs/gsl/transport.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_transport.h": diff --git a/src/sage/libs/gsl/trig.pxd b/src/sage/libs/gsl/trig.pxd index 71ae2be0199..c9da72206af 100644 --- a/src/sage/libs/gsl/trig.pxd +++ b/src/sage/libs/gsl/trig.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_trig.h": diff --git a/src/sage/libs/gsl/types.pxd b/src/sage/libs/gsl/types.pxd index 217738be893..7076e2f8861 100644 --- a/src/sage/libs/gsl/types.pxd +++ b/src/sage/libs/gsl/types.pxd @@ -4,7 +4,7 @@ from libc.stdio cimport FILE cdef enum: GSL_SUCCESS -from .blas_types cimport * +from sage.libs.gsl.blas_types cimport * cdef extern from "gsl/gsl_mode.h": ctypedef unsigned int gsl_mode_t diff --git a/src/sage/libs/gsl/vector.pxd b/src/sage/libs/gsl/vector.pxd index fdbdc7c10e5..30960a2d1ef 100644 --- a/src/sage/libs/gsl/vector.pxd +++ b/src/sage/libs/gsl/vector.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_vector.h": # Allocation diff --git a/src/sage/libs/gsl/vector_complex.pxd b/src/sage/libs/gsl/vector_complex.pxd index f712c493962..a784c32880a 100644 --- a/src/sage/libs/gsl/vector_complex.pxd +++ b/src/sage/libs/gsl/vector_complex.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_vector_complex_double.h": # Allocation diff --git a/src/sage/libs/gsl/wavelet.pxd b/src/sage/libs/gsl/wavelet.pxd index 43fcfd50c07..c74052e8bfc 100644 --- a/src/sage/libs/gsl/wavelet.pxd +++ b/src/sage/libs/gsl/wavelet.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_wavelet.h": diff --git a/src/sage/libs/gsl/zeta.pxd b/src/sage/libs/gsl/zeta.pxd index 58143b1d3ee..9b6edbd74b9 100644 --- a/src/sage/libs/gsl/zeta.pxd +++ b/src/sage/libs/gsl/zeta.pxd @@ -1,7 +1,7 @@ # distutils: libraries = GSL_LIBRARIES # distutils: library_dirs = GSL_LIBDIR # distutils: include_dirs = GSL_INCDIR -from .types cimport * +from sage.libs.gsl.types cimport * cdef extern from "gsl/gsl_sf_zeta.h": diff --git a/src/sage/libs/linbox/conversion.pxd b/src/sage/libs/linbox/conversion.pxd index f140a0fc321..a4cdd09711d 100644 --- a/src/sage/libs/linbox/conversion.pxd +++ b/src/sage/libs/linbox/conversion.pxd @@ -29,8 +29,8 @@ from libcpp.vector cimport vector as cppvector from sage.libs.gmp.mpz cimport mpz_set -from .givaro cimport Modular_uint64, ZRing, Integer -from .linbox cimport SparseMatrix_Modular_uint64, SparseMatrix_integer, DenseVector_integer +from sage.libs.linbox.givaro cimport Modular_uint64, ZRing, Integer +from sage.libs.linbox.linbox cimport SparseMatrix_Modular_uint64, SparseMatrix_integer, DenseVector_integer from sage.matrix.matrix_modn_sparse cimport Matrix_modn_sparse from sage.matrix.matrix_integer_sparse cimport Matrix_integer_sparse diff --git a/src/sage/libs/linbox/fflas.pxd b/src/sage/libs/linbox/fflas.pxd index f7ca98c614c..d5b077cf045 100644 --- a/src/sage/libs/linbox/fflas.pxd +++ b/src/sage/libs/linbox/fflas.pxd @@ -13,8 +13,8 @@ # distutils: extra_link_args = FFLASFFPACK_LIBEXTRA # distutils: language = c++ -from .givaro cimport Modular_double, Modular_float, Dense, Sparse -from .givaro cimport givvector, Poly1Dom +from sage.libs.linbox.givaro cimport Modular_double, Modular_float, Dense, Sparse +from sage.libs.linbox.givaro cimport givvector, Poly1Dom from libcpp.vector cimport vector from libcpp cimport bool ctypedef Poly1Dom[Modular_double, Dense] PolynomialRing_Modular_double diff --git a/src/sage/libs/linbox/linbox.pxd b/src/sage/libs/linbox/linbox.pxd index bfeda4b6042..6792e260a34 100644 --- a/src/sage/libs/linbox/linbox.pxd +++ b/src/sage/libs/linbox/linbox.pxd @@ -8,7 +8,7 @@ from libc.stdint cimport uint32_t, uint64_t from libcpp.vector cimport vector as cppvector -from .givaro cimport * +from sage.libs.linbox.givaro cimport * cdef extern from "linbox/matrix/dense-matrix.h": ## template ::Dense > diff --git a/src/sage/libs/linbox/linbox_flint_interface.pyx b/src/sage/libs/linbox/linbox_flint_interface.pyx index dabd375c2b8..1979ac0f0a4 100644 --- a/src/sage/libs/linbox/linbox_flint_interface.pyx +++ b/src/sage/libs/linbox/linbox_flint_interface.pyx @@ -40,7 +40,7 @@ from sage.libs.flint.fmpz_poly cimport fmpz_poly_set_coeff_mpz, fmpz_poly_fit_le cimport sage.libs.linbox.givaro as givaro cimport sage.libs.linbox.linbox as linbox -from .linbox cimport PolynomialRing_integer +from sage.libs.linbox.linbox cimport PolynomialRing_integer cdef void fmpz_mat_get_linbox(linbox.DenseMatrix_integer& A, fmpz_mat_t m) noexcept: diff --git a/src/sage/libs/mpmath/ext_libmp.pyx b/src/sage/libs/mpmath/ext_libmp.pyx index 5dccf596a91..10d1b32eb36 100644 --- a/src/sage/libs/mpmath/ext_libmp.pyx +++ b/src/sage/libs/mpmath/ext_libmp.pyx @@ -1,11 +1,11 @@ """ Faster versions of some key functions in mpmath.libmp """ -from .ext_impl cimport * +from sage.libs.mpmath.ext_impl cimport * from sage.libs.gmp.all cimport * # the next line is used by mpmath -from .ext_impl import exp_fixed, cos_sin_fixed, log_int_fixed +from sage.libs.mpmath.ext_impl import exp_fixed, cos_sin_fixed, log_int_fixed # Note: not thread-safe cdef MPF tmp1 diff --git a/src/sage/libs/mpmath/ext_main.pxd b/src/sage/libs/mpmath/ext_main.pxd index d810e75f544..8a3bf740b0e 100644 --- a/src/sage/libs/mpmath/ext_main.pxd +++ b/src/sage/libs/mpmath/ext_main.pxd @@ -1 +1 @@ -from .ext_impl cimport * +from sage.libs.mpmath.ext_impl cimport * diff --git a/src/sage/libs/mpmath/ext_main.pyx b/src/sage/libs/mpmath/ext_main.pyx index a00c5ee4831..4b717bb3860 100644 --- a/src/sage/libs/mpmath/ext_main.pyx +++ b/src/sage/libs/mpmath/ext_main.pyx @@ -38,7 +38,7 @@ DEF S_INF = 3 DEF S_NINF = 4 DEF S_NAN = 5 -from .ext_impl cimport * +from sage.libs.mpmath.ext_impl cimport * import mpmath.rational as rationallib import mpmath.libmp as libmp diff --git a/src/sage/libs/ntl/GF2.pxd b/src/sage/libs/ntl/GF2.pxd index 9443f143dcf..5be7f496766 100644 --- a/src/sage/libs/ntl/GF2.pxd +++ b/src/sage/libs/ntl/GF2.pxd @@ -1,4 +1,4 @@ -from .types cimport GF2_c +from sage.libs.ntl.types cimport GF2_c cdef extern from "ntlwrap.h": diff --git a/src/sage/libs/ntl/GF2E.pxd b/src/sage/libs/ntl/GF2E.pxd index 352e35330fc..5a72efec6a4 100644 --- a/src/sage/libs/ntl/GF2E.pxd +++ b/src/sage/libs/ntl/GF2E.pxd @@ -1,4 +1,4 @@ -from .types cimport GF2E_c, GF2X_c, GF2_c, GF2XModulus_c, ZZ_c +from sage.libs.ntl.types cimport GF2E_c, GF2X_c, GF2_c, GF2XModulus_c, ZZ_c cdef extern from "ntlwrap.h": diff --git a/src/sage/libs/ntl/GF2EX.pxd b/src/sage/libs/ntl/GF2EX.pxd index c9d272f1c5a..4a0df45c9f1 100644 --- a/src/sage/libs/ntl/GF2EX.pxd +++ b/src/sage/libs/ntl/GF2EX.pxd @@ -1,4 +1,4 @@ -from .types cimport GF2EX_c +from sage.libs.ntl.types cimport GF2EX_c cdef extern from "ntlwrap.h": diff --git a/src/sage/libs/ntl/GF2X.pxd b/src/sage/libs/ntl/GF2X.pxd index 1539a37c93c..9342f63244c 100644 --- a/src/sage/libs/ntl/GF2X.pxd +++ b/src/sage/libs/ntl/GF2X.pxd @@ -1,4 +1,4 @@ -from .types cimport GF2X_c, GF2_c, GF2XModulus_c, vec_GF2_c, ZZ_c +from sage.libs.ntl.types cimport GF2X_c, GF2_c, GF2XModulus_c, vec_GF2_c, ZZ_c cdef extern from "ntlwrap.h": diff --git a/src/sage/libs/ntl/ZZ.pxd b/src/sage/libs/ntl/ZZ.pxd index 2ac00565e78..fc8901fc31a 100644 --- a/src/sage/libs/ntl/ZZ.pxd +++ b/src/sage/libs/ntl/ZZ.pxd @@ -1,6 +1,6 @@ # distutils: depends = NTL/ZZ.h -from .types cimport ZZ_c +from sage.libs.ntl.types cimport ZZ_c cdef extern from "ntlwrap.h": diff --git a/src/sage/libs/ntl/ZZX.pxd b/src/sage/libs/ntl/ZZX.pxd index d46fce4bbb9..bc2780e3a83 100644 --- a/src/sage/libs/ntl/ZZX.pxd +++ b/src/sage/libs/ntl/ZZX.pxd @@ -1,7 +1,7 @@ # distutils: depends = NTL/ZZ.h from sage.libs.gmp.types cimport mpz_t -from .types cimport ZZ_c, vec_ZZ_c, ZZX_c +from sage.libs.ntl.types cimport ZZ_c, vec_ZZ_c, ZZX_c cdef extern from *: diff --git a/src/sage/libs/ntl/ZZ_p.pxd b/src/sage/libs/ntl/ZZ_p.pxd index 0bee7b282b9..1d7d95e4007 100644 --- a/src/sage/libs/ntl/ZZ_p.pxd +++ b/src/sage/libs/ntl/ZZ_p.pxd @@ -1,6 +1,6 @@ # distutils: depends = NTL/ZZ.h -from .types cimport ZZ_c, ZZ_p_c +from sage.libs.ntl.types cimport ZZ_c, ZZ_p_c cdef extern from "ntlwrap.h": diff --git a/src/sage/libs/ntl/ZZ_pE.pxd b/src/sage/libs/ntl/ZZ_pE.pxd index 7d92bae4479..bdfb04cb783 100644 --- a/src/sage/libs/ntl/ZZ_pE.pxd +++ b/src/sage/libs/ntl/ZZ_pE.pxd @@ -1,6 +1,6 @@ # distutils: depends = NTL/ZZ.h -from .types cimport ZZ_c, ZZ_p_c, ZZ_pX_c, ZZ_pE_c +from sage.libs.ntl.types cimport ZZ_c, ZZ_p_c, ZZ_pX_c, ZZ_pE_c cdef extern from "ntlwrap.h": diff --git a/src/sage/libs/ntl/ZZ_pEX.pxd b/src/sage/libs/ntl/ZZ_pEX.pxd index 7e2dc5626cd..78be3ee13ea 100644 --- a/src/sage/libs/ntl/ZZ_pEX.pxd +++ b/src/sage/libs/ntl/ZZ_pEX.pxd @@ -1,6 +1,6 @@ # distutils: depends = NTL/ZZ.h -from .types cimport (ZZ_c, ZZ_p_c, ZZ_pContext_c, ZZ_pE_c, vec_ZZ_p_c, +from sage.libs.ntl.types cimport (ZZ_c, ZZ_p_c, ZZ_pContext_c, ZZ_pE_c, vec_ZZ_p_c, vec_ZZ_pE_c, ZZ_pEX_c, ZZ_pEX_Modulus_c) diff --git a/src/sage/libs/ntl/ZZ_pX.pxd b/src/sage/libs/ntl/ZZ_pX.pxd index a48e815d018..8c9f609f1cd 100644 --- a/src/sage/libs/ntl/ZZ_pX.pxd +++ b/src/sage/libs/ntl/ZZ_pX.pxd @@ -1,6 +1,6 @@ # distutils: depends = NTL/ZZ.h -from .types cimport (ZZ_c, ZZX_c, ZZ_p_c, vec_ZZ_p_c, ZZ_pContext_c, +from sage.libs.ntl.types cimport (ZZ_c, ZZX_c, ZZ_p_c, vec_ZZ_p_c, ZZ_pContext_c, ZZ_pX_c, ZZ_pX_Modulus_c, ZZ_pX_Multiplier_c) diff --git a/src/sage/libs/ntl/__init__.py b/src/sage/libs/ntl/__init__.py index 5cdc57e0122..0ab0a2c43e7 100644 --- a/src/sage/libs/ntl/__init__.py +++ b/src/sage/libs/ntl/__init__.py @@ -1,2 +1,3 @@ -from .error import setup_NTL_error_callback +from sage.libs.ntl.error import setup_NTL_error_callback + setup_NTL_error_callback() diff --git a/src/sage/libs/ntl/conversion.pxd b/src/sage/libs/ntl/conversion.pxd index 840e3947ea3..e46cc66284e 100644 --- a/src/sage/libs/ntl/conversion.pxd +++ b/src/sage/libs/ntl/conversion.pxd @@ -23,7 +23,7 @@ conventions for conversion functions # http://www.gnu.org/licenses/ #***************************************************************************** -from .types cimport mat_ZZ_p_c +from sage.libs.ntl.types cimport mat_ZZ_p_c from sage.libs.ntl.ntl_ZZ_pContext cimport ntl_ZZ_pContext_class from sage.libs.ntl.ntl_ZZ_p cimport ntl_ZZ_p diff --git a/src/sage/libs/ntl/convert.pxd b/src/sage/libs/ntl/convert.pxd index 1a9532f0aba..58420abb94c 100644 --- a/src/sage/libs/ntl/convert.pxd +++ b/src/sage/libs/ntl/convert.pxd @@ -1,4 +1,4 @@ -from .types cimport ZZ_c +from sage.libs.ntl.types cimport ZZ_c from sage.libs.gmp.types cimport mpz_t, mpz_srcptr cdef void ZZ_to_mpz(mpz_t output, ZZ_c* x) noexcept diff --git a/src/sage/libs/ntl/convert.pyx b/src/sage/libs/ntl/convert.pyx index 975a3f3fced..5924c9f2e79 100644 --- a/src/sage/libs/ntl/convert.pyx +++ b/src/sage/libs/ntl/convert.pyx @@ -23,7 +23,7 @@ Conversion between NTL's ``ZZ`` and various other types from sage.libs.gmp.mpz cimport mpz_init, mpz_clear from sage.libs.gmp.pylong cimport mpz_set_pylong -cdef extern from "sage/libs/ntl/ntlwrap_impl.h": +cdef extern from "ntlwrap_impl.h": void ZZ_to_mpz(mpz_t output, ZZ_c* x) void mpz_to_ZZ(ZZ_c *output, mpz_srcptr x) diff --git a/src/sage/libs/ntl/error.pyx b/src/sage/libs/ntl/error.pyx index ac6cef82910..54443c13597 100644 --- a/src/sage/libs/ntl/error.pyx +++ b/src/sage/libs/ntl/error.pyx @@ -28,8 +28,8 @@ AUTHOR: #***************************************************************************** -from .ntl_tools cimport ErrorMsgCallback -from ...cpython.string cimport char_to_str +from sage.libs.ntl.ntl_tools cimport ErrorMsgCallback +from sage.cpython.string cimport char_to_str class NTLError(RuntimeError): diff --git a/src/sage/libs/ntl/lzz_p.pxd b/src/sage/libs/ntl/lzz_p.pxd index a7f8d5c52b6..14d81bc8ab0 100644 --- a/src/sage/libs/ntl/lzz_p.pxd +++ b/src/sage/libs/ntl/lzz_p.pxd @@ -1,6 +1,6 @@ # distutils: depends = NTL/ZZ.h -from .types cimport zz_p_c +from sage.libs.ntl.types cimport zz_p_c cdef extern from "ntlwrap.h": long zz_p_rep "rep"(zz_p_c x) diff --git a/src/sage/libs/ntl/lzz_pX.pxd b/src/sage/libs/ntl/lzz_pX.pxd index 65995a5c4d2..72905fd1d54 100644 --- a/src/sage/libs/ntl/lzz_pX.pxd +++ b/src/sage/libs/ntl/lzz_pX.pxd @@ -1,6 +1,6 @@ # distutils: depends = NTL/ZZ.h -from .types cimport ZZ_c, zz_p_c, zz_pX_c, zz_pX_Modulus_c +from sage.libs.ntl.types cimport ZZ_c, zz_p_c, zz_pX_c, zz_pX_Modulus_c cdef extern from "ntlwrap.h": diff --git a/src/sage/libs/ntl/mat_GF2.pxd b/src/sage/libs/ntl/mat_GF2.pxd index 89c8252c046..db535d800fc 100644 --- a/src/sage/libs/ntl/mat_GF2.pxd +++ b/src/sage/libs/ntl/mat_GF2.pxd @@ -1,4 +1,4 @@ -from .types cimport mat_GF2_c, vec_GF2_c, GF2_c +from sage.libs.ntl.types cimport mat_GF2_c, vec_GF2_c, GF2_c cdef extern from "ntlwrap.h": diff --git a/src/sage/libs/ntl/mat_GF2E.pxd b/src/sage/libs/ntl/mat_GF2E.pxd index 61250702247..e6c3b5fc622 100644 --- a/src/sage/libs/ntl/mat_GF2E.pxd +++ b/src/sage/libs/ntl/mat_GF2E.pxd @@ -1,4 +1,4 @@ -from .types cimport mat_GF2E_c, vec_GF2E_c, GF2E_c +from sage.libs.ntl.types cimport mat_GF2E_c, vec_GF2E_c, GF2E_c cdef extern from "ntlwrap.h": diff --git a/src/sage/libs/ntl/mat_ZZ.pxd b/src/sage/libs/ntl/mat_ZZ.pxd index b40e51d53de..a676c90fb1b 100644 --- a/src/sage/libs/ntl/mat_ZZ.pxd +++ b/src/sage/libs/ntl/mat_ZZ.pxd @@ -1,4 +1,4 @@ -from .types cimport mat_ZZ_c, ZZ_c, ZZX_c +from sage.libs.ntl.types cimport mat_ZZ_c, ZZ_c, ZZX_c cdef extern from "ntlwrap.h": diff --git a/src/sage/libs/ntl/ntl_GF2.pxd b/src/sage/libs/ntl/ntl_GF2.pxd index 0eff25dd32c..2be873c950c 100644 --- a/src/sage/libs/ntl/ntl_GF2.pxd +++ b/src/sage/libs/ntl/ntl_GF2.pxd @@ -1,4 +1,4 @@ -from .types cimport GF2_c +from sage.libs.ntl.types cimport GF2_c cdef class ntl_GF2(): cdef GF2_c x diff --git a/src/sage/libs/ntl/ntl_GF2E.pxd b/src/sage/libs/ntl/ntl_GF2E.pxd index f634042e7cb..93539cf8abf 100644 --- a/src/sage/libs/ntl/ntl_GF2E.pxd +++ b/src/sage/libs/ntl/ntl_GF2E.pxd @@ -1,5 +1,5 @@ -from .types cimport GF2E_c -from .ntl_GF2EContext cimport ntl_GF2EContext_class +from sage.libs.ntl.types cimport GF2E_c +from sage.libs.ntl.ntl_GF2EContext cimport ntl_GF2EContext_class cdef class ntl_GF2E(): cdef GF2E_c x diff --git a/src/sage/libs/ntl/ntl_GF2E.pyx b/src/sage/libs/ntl/ntl_GF2E.pyx index 078a3e2e6f7..2e4fec38020 100644 --- a/src/sage/libs/ntl/ntl_GF2E.pyx +++ b/src/sage/libs/ntl/ntl_GF2E.pyx @@ -27,11 +27,11 @@ include 'misc.pxi' include 'decl.pxi' from cpython.object cimport Py_EQ, Py_NE -from .ntl_ZZ cimport ntl_ZZ -from .ntl_GF2 cimport ntl_GF2 -from .ntl_GF2X cimport ntl_GF2X -from .ntl_GF2EContext cimport ntl_GF2EContext_class -from .ntl_GF2EContext import ntl_GF2EContext +from sage.libs.ntl.ntl_ZZ cimport ntl_ZZ +from sage.libs.ntl.ntl_GF2 cimport ntl_GF2 +from sage.libs.ntl.ntl_GF2X cimport ntl_GF2X +from sage.libs.ntl.ntl_GF2EContext cimport ntl_GF2EContext_class +from sage.libs.ntl.ntl_GF2EContext import ntl_GF2EContext from sage.libs.ntl.ntl_ZZ import unpickle_class_args from sage.misc.randstate cimport current_randstate diff --git a/src/sage/libs/ntl/ntl_GF2EContext.pxd b/src/sage/libs/ntl/ntl_GF2EContext.pxd index df1f44f87aa..01fc4676e58 100644 --- a/src/sage/libs/ntl/ntl_GF2EContext.pxd +++ b/src/sage/libs/ntl/ntl_GF2EContext.pxd @@ -1,5 +1,5 @@ -from .types cimport GF2EContext_c -from .ntl_GF2X cimport ntl_GF2X +from sage.libs.ntl.types cimport GF2EContext_c +from sage.libs.ntl.ntl_GF2X cimport ntl_GF2X cdef class ntl_GF2EContext_class(): cdef GF2EContext_c x diff --git a/src/sage/libs/ntl/ntl_GF2EX.pxd b/src/sage/libs/ntl/ntl_GF2EX.pxd index e9a98a3afd6..38c96a7fe52 100644 --- a/src/sage/libs/ntl/ntl_GF2EX.pxd +++ b/src/sage/libs/ntl/ntl_GF2EX.pxd @@ -1,6 +1,6 @@ -from .types cimport GF2EX_c -from .ntl_GF2EContext cimport ntl_GF2EContext_class -from .ntl_GF2E cimport ntl_GF2E +from sage.libs.ntl.types cimport GF2EX_c +from sage.libs.ntl.ntl_GF2EContext cimport ntl_GF2EContext_class +from sage.libs.ntl.ntl_GF2E cimport ntl_GF2E cdef class ntl_GF2EX(): cdef GF2EX_c x diff --git a/src/sage/libs/ntl/ntl_GF2EX.pyx b/src/sage/libs/ntl/ntl_GF2EX.pyx index 72d18cedd4a..4e1c4324915 100644 --- a/src/sage/libs/ntl/ntl_GF2EX.pyx +++ b/src/sage/libs/ntl/ntl_GF2EX.pyx @@ -27,10 +27,10 @@ include 'misc.pxi' include 'decl.pxi' from cpython.object cimport Py_EQ, Py_NE -from .ntl_ZZ import unpickle_class_args -from .ntl_GF2EContext import ntl_GF2EContext -from .ntl_GF2EContext cimport ntl_GF2EContext_class -from .ntl_GF2E cimport ntl_GF2E +from sage.libs.ntl.ntl_ZZ import unpickle_class_args +from sage.libs.ntl.ntl_GF2EContext import ntl_GF2EContext +from sage.libs.ntl.ntl_GF2EContext cimport ntl_GF2EContext_class +from sage.libs.ntl.ntl_GF2E cimport ntl_GF2E ############################################################################## # diff --git a/src/sage/libs/ntl/ntl_GF2X.pxd b/src/sage/libs/ntl/ntl_GF2X.pxd index 5af874d0b9e..8d50c9d17d8 100644 --- a/src/sage/libs/ntl/ntl_GF2X.pxd +++ b/src/sage/libs/ntl/ntl_GF2X.pxd @@ -1,4 +1,4 @@ -from .types cimport GF2X_c +from sage.libs.ntl.types cimport GF2X_c cdef class ntl_GF2X(): cdef GF2X_c x diff --git a/src/sage/libs/ntl/ntl_GF2X.pyx b/src/sage/libs/ntl/ntl_GF2X.pyx index 787169e6dc7..f6781a68c7b 100644 --- a/src/sage/libs/ntl/ntl_GF2X.pyx +++ b/src/sage/libs/ntl/ntl_GF2X.pyx @@ -29,8 +29,8 @@ include 'decl.pxi' from cpython.object cimport Py_EQ, Py_NE from sage.rings.integer cimport Integer -from .ntl_ZZ import unpickle_class_value -from .ntl_GF2 cimport ntl_GF2 +from sage.libs.ntl.ntl_ZZ import unpickle_class_value +from sage.libs.ntl.ntl_GF2 cimport ntl_GF2 ############################################################################## diff --git a/src/sage/libs/ntl/ntl_ZZX.pxd b/src/sage/libs/ntl/ntl_ZZX.pxd index 5f6238f73f1..63e588c1d42 100644 --- a/src/sage/libs/ntl/ntl_ZZX.pxd +++ b/src/sage/libs/ntl/ntl_ZZX.pxd @@ -1,4 +1,4 @@ -from .types cimport ZZX_c +from sage.libs.ntl.types cimport ZZX_c cdef class ntl_ZZX(): cdef ZZX_c x diff --git a/src/sage/libs/ntl/ntl_ZZ_p.pxd b/src/sage/libs/ntl/ntl_ZZ_p.pxd index 08a0a3beb84..a92c9766112 100644 --- a/src/sage/libs/ntl/ntl_ZZ_p.pxd +++ b/src/sage/libs/ntl/ntl_ZZ_p.pxd @@ -1,5 +1,5 @@ -from .types cimport ZZ_p_c -from .ntl_ZZ_pContext cimport ntl_ZZ_pContext_class +from sage.libs.ntl.types cimport ZZ_p_c +from sage.libs.ntl.ntl_ZZ_pContext cimport ntl_ZZ_pContext_class cdef class ntl_ZZ_p(): cdef ZZ_p_c x diff --git a/src/sage/libs/ntl/ntl_ZZ_pContext.pxd b/src/sage/libs/ntl/ntl_ZZ_pContext.pxd index 61269d95584..d60cab91d55 100644 --- a/src/sage/libs/ntl/ntl_ZZ_pContext.pxd +++ b/src/sage/libs/ntl/ntl_ZZ_pContext.pxd @@ -1,6 +1,6 @@ -from .types cimport ZZ_pContext_c -from .ntl_ZZ cimport ntl_ZZ -from .types cimport ZZ_c +from sage.libs.ntl.types cimport ZZ_pContext_c +from sage.libs.ntl.ntl_ZZ cimport ntl_ZZ +from sage.libs.ntl.types cimport ZZ_c cdef class ntl_ZZ_pContext_class(): diff --git a/src/sage/libs/ntl/ntl_ZZ_pE.pxd b/src/sage/libs/ntl/ntl_ZZ_pE.pxd index cb9efd2279f..b2a1aa70293 100644 --- a/src/sage/libs/ntl/ntl_ZZ_pE.pxd +++ b/src/sage/libs/ntl/ntl_ZZ_pE.pxd @@ -1,6 +1,6 @@ -from .types cimport ZZ_pE_c -from .ntl_ZZ_pEContext cimport ntl_ZZ_pEContext_class -from .ntl_ZZ_pX cimport ntl_ZZ_pX +from sage.libs.ntl.types cimport ZZ_pE_c +from sage.libs.ntl.ntl_ZZ_pEContext cimport ntl_ZZ_pEContext_class +from sage.libs.ntl.ntl_ZZ_pX cimport ntl_ZZ_pX cdef class ntl_ZZ_pE(): cdef ZZ_pE_c x diff --git a/src/sage/libs/ntl/ntl_ZZ_pEContext.pxd b/src/sage/libs/ntl/ntl_ZZ_pEContext.pxd index 027c59465a9..70041817a63 100644 --- a/src/sage/libs/ntl/ntl_ZZ_pEContext.pxd +++ b/src/sage/libs/ntl/ntl_ZZ_pEContext.pxd @@ -1,7 +1,7 @@ -from .types cimport ZZ_pContext_c, ZZ_pEContext_c -from .ntl_ZZ_pContext cimport ntl_ZZ_pContext_class -from .ntl_ZZ_pX cimport ntl_ZZ_pX -from .types cimport ZZ_pX_Modulus_c +from sage.libs.ntl.types cimport ZZ_pContext_c, ZZ_pEContext_c +from sage.libs.ntl.ntl_ZZ_pContext cimport ntl_ZZ_pContext_class +from sage.libs.ntl.ntl_ZZ_pX cimport ntl_ZZ_pX +from sage.libs.ntl.types cimport ZZ_pX_Modulus_c cdef struct ZZ_pEContext_ptrs: diff --git a/src/sage/libs/ntl/ntl_ZZ_pEContext.pyx b/src/sage/libs/ntl/ntl_ZZ_pEContext.pyx index affd31d299d..03ff00f21d4 100644 --- a/src/sage/libs/ntl/ntl_ZZ_pEContext.pyx +++ b/src/sage/libs/ntl/ntl_ZZ_pEContext.pyx @@ -148,7 +148,7 @@ cdef class ntl_ZZ_pEContext_class(): sage: c.ZZ_pE([4,3]) [4 3] """ - from .ntl_ZZ_pE import ntl_ZZ_pE + from sage.libs.ntl.ntl_ZZ_pE import ntl_ZZ_pE return ntl_ZZ_pE(v,modulus=self) def ZZ_pEX(self, v = None): @@ -161,7 +161,7 @@ cdef class ntl_ZZ_pEContext_class(): sage: c.ZZ_pEX([4,3]) [[4] [3]] """ - from .ntl_ZZ_pEX import ntl_ZZ_pEX + from sage.libs.ntl.ntl_ZZ_pEX import ntl_ZZ_pEX return ntl_ZZ_pEX(v, modulus=self) cpdef void _assert_is_current_modulus(self) except *: diff --git a/src/sage/libs/ntl/ntl_ZZ_pEX.pxd b/src/sage/libs/ntl/ntl_ZZ_pEX.pxd index de3e1e54fff..26ef2baf302 100644 --- a/src/sage/libs/ntl/ntl_ZZ_pEX.pxd +++ b/src/sage/libs/ntl/ntl_ZZ_pEX.pxd @@ -1,5 +1,5 @@ -from .types cimport ZZ_pEX_c -from .ntl_ZZ_pEContext cimport ntl_ZZ_pEContext_class +from sage.libs.ntl.types cimport ZZ_pEX_c +from sage.libs.ntl.ntl_ZZ_pEContext cimport ntl_ZZ_pEContext_class cdef class ntl_ZZ_pEX(): cdef ZZ_pEX_c x diff --git a/src/sage/libs/ntl/ntl_ZZ_pX.pxd b/src/sage/libs/ntl/ntl_ZZ_pX.pxd index e414fc5c272..38792bca2d1 100644 --- a/src/sage/libs/ntl/ntl_ZZ_pX.pxd +++ b/src/sage/libs/ntl/ntl_ZZ_pX.pxd @@ -1,4 +1,4 @@ -from .ZZ_pX cimport * +from sage.libs.ntl.ZZ_pX cimport * from sage.libs.ntl.ntl_ZZ_pContext cimport ntl_ZZ_pContext_class cdef class ntl_ZZ_pX(): diff --git a/src/sage/libs/ntl/ntl_lzz_p.pxd b/src/sage/libs/ntl/ntl_lzz_p.pxd index 6a1466b62d3..6b4a6b8d3f0 100644 --- a/src/sage/libs/ntl/ntl_lzz_p.pxd +++ b/src/sage/libs/ntl/ntl_lzz_p.pxd @@ -1,5 +1,5 @@ -from .lzz_p cimport * -from .ntl_lzz_pContext cimport ntl_zz_pContext_class +from sage.libs.ntl.lzz_p cimport * +from sage.libs.ntl.ntl_lzz_pContext cimport ntl_zz_pContext_class cdef class ntl_zz_p(): cdef zz_p_c x diff --git a/src/sage/libs/ntl/ntl_lzz_pContext.pxd b/src/sage/libs/ntl/ntl_lzz_pContext.pxd index cffc49f6b4c..3fd7452197d 100644 --- a/src/sage/libs/ntl/ntl_lzz_pContext.pxd +++ b/src/sage/libs/ntl/ntl_lzz_pContext.pxd @@ -1,4 +1,4 @@ -from .types cimport zz_pContext_c +from sage.libs.ntl.types cimport zz_pContext_c cdef class ntl_zz_pContext_class(): cdef zz_pContext_c x diff --git a/src/sage/libs/ntl/ntl_mat_GF2.pxd b/src/sage/libs/ntl/ntl_mat_GF2.pxd index 34176ca530e..4041f9f8f14 100644 --- a/src/sage/libs/ntl/ntl_mat_GF2.pxd +++ b/src/sage/libs/ntl/ntl_mat_GF2.pxd @@ -1,5 +1,5 @@ -from .types cimport mat_GF2_c -from .ntl_GF2 cimport ntl_GF2 +from sage.libs.ntl.types cimport mat_GF2_c +from sage.libs.ntl.ntl_GF2 cimport ntl_GF2 cdef class ntl_mat_GF2(): cdef mat_GF2_c x diff --git a/src/sage/libs/ntl/ntl_mat_GF2.pyx b/src/sage/libs/ntl/ntl_mat_GF2.pyx index 4c7b19a066b..71d4f8b7491 100644 --- a/src/sage/libs/ntl/ntl_mat_GF2.pyx +++ b/src/sage/libs/ntl/ntl_mat_GF2.pyx @@ -40,7 +40,7 @@ include 'misc.pxi' include 'decl.pxi' from cpython.object cimport Py_EQ, Py_NE -from .ntl_GF2 cimport ntl_GF2 +from sage.libs.ntl.ntl_GF2 cimport ntl_GF2 from sage.rings.integer cimport Integer from sage.libs.ntl.ntl_ZZ import unpickle_class_args diff --git a/src/sage/libs/ntl/ntl_mat_GF2E.pxd b/src/sage/libs/ntl/ntl_mat_GF2E.pxd index c01392b81db..15415965c66 100644 --- a/src/sage/libs/ntl/ntl_mat_GF2E.pxd +++ b/src/sage/libs/ntl/ntl_mat_GF2E.pxd @@ -1,6 +1,6 @@ -from .types cimport mat_GF2E_c -from .ntl_GF2EContext cimport ntl_GF2EContext_class -from .ntl_GF2E cimport ntl_GF2E +from sage.libs.ntl.types cimport mat_GF2E_c +from sage.libs.ntl.ntl_GF2EContext cimport ntl_GF2EContext_class +from sage.libs.ntl.ntl_GF2E cimport ntl_GF2E cdef class ntl_mat_GF2E(): cdef mat_GF2E_c x diff --git a/src/sage/libs/ntl/ntl_mat_GF2E.pyx b/src/sage/libs/ntl/ntl_mat_GF2E.pyx index 24f75c6c026..0588eaaa7a3 100644 --- a/src/sage/libs/ntl/ntl_mat_GF2E.pyx +++ b/src/sage/libs/ntl/ntl_mat_GF2E.pyx @@ -37,9 +37,9 @@ include 'misc.pxi' include 'decl.pxi' from cpython.object cimport Py_EQ, Py_NE -from .ntl_GF2E cimport ntl_GF2E -from .ntl_GF2EContext import ntl_GF2EContext -from .ntl_GF2EContext cimport ntl_GF2EContext_class +from sage.libs.ntl.ntl_GF2E cimport ntl_GF2E +from sage.libs.ntl.ntl_GF2EContext import ntl_GF2EContext +from sage.libs.ntl.ntl_GF2EContext cimport ntl_GF2EContext_class from sage.rings.integer cimport Integer from sage.misc.randstate cimport randstate, current_randstate diff --git a/src/sage/libs/ntl/ntl_mat_ZZ.pxd b/src/sage/libs/ntl/ntl_mat_ZZ.pxd index f766e82c187..472ef698704 100644 --- a/src/sage/libs/ntl/ntl_mat_ZZ.pxd +++ b/src/sage/libs/ntl/ntl_mat_ZZ.pxd @@ -1,4 +1,4 @@ -from .types cimport mat_ZZ_c +from sage.libs.ntl.types cimport mat_ZZ_c cdef class ntl_mat_ZZ(): cdef mat_ZZ_c x diff --git a/src/sage/libs/ntl/ntl_mat_ZZ.pyx b/src/sage/libs/ntl/ntl_mat_ZZ.pyx index 8df56b2632e..349055dc182 100644 --- a/src/sage/libs/ntl/ntl_mat_ZZ.pyx +++ b/src/sage/libs/ntl/ntl_mat_ZZ.pyx @@ -30,7 +30,7 @@ from sage.libs.ntl.ntl_ZZ cimport ntl_ZZ from sage.libs.ntl.ntl_ZZX cimport ntl_ZZX from cpython.object cimport PyObject_RichCompare -from .ntl_ZZ import unpickle_class_args +from sage.libs.ntl.ntl_ZZ import unpickle_class_args cdef inline ntl_ZZ make_ZZ(ZZ_c* x) noexcept: cdef ntl_ZZ y diff --git a/src/sage/libs/ntl/vec_GF2.pxd b/src/sage/libs/ntl/vec_GF2.pxd index fa606dc176a..81a3736b49f 100644 --- a/src/sage/libs/ntl/vec_GF2.pxd +++ b/src/sage/libs/ntl/vec_GF2.pxd @@ -1,4 +1,4 @@ -from .types cimport vec_GF2_c, GF2_c +from sage.libs.ntl.types cimport vec_GF2_c, GF2_c cdef extern from "ntlwrap.h": diff --git a/src/sage/libs/ntl/vec_GF2E.pxd b/src/sage/libs/ntl/vec_GF2E.pxd index 1cfdd7109fa..8e53bad0517 100644 --- a/src/sage/libs/ntl/vec_GF2E.pxd +++ b/src/sage/libs/ntl/vec_GF2E.pxd @@ -1 +1 @@ -from .types cimport vec_GF2E_c +from sage.libs.ntl.types cimport vec_GF2E_c diff --git a/src/sage/libs/pari/convert_flint.pyx b/src/sage/libs/pari/convert_flint.pyx index 340e72c13bb..c8e1ddb00cf 100644 --- a/src/sage/libs/pari/convert_flint.pyx +++ b/src/sage/libs/pari/convert_flint.pyx @@ -28,7 +28,7 @@ from sage.libs.flint.fmpq_mat cimport fmpq_mat_nrows, fmpq_mat_ncols, fmpq_mat_e from cypari2.paridecl cimport * from cypari2.stack cimport new_gen -from .convert_gmp cimport _new_GEN_from_mpz_t +from sage.libs.pari.convert_gmp cimport _new_GEN_from_mpz_t cdef inline GEN _new_GEN_from_fmpz_t(fmpz_t value) noexcept: diff --git a/src/sage/libs/pari/convert_sage.pyx b/src/sage/libs/pari/convert_sage.pyx index 500ed520312..7ee32b27b28 100644 --- a/src/sage/libs/pari/convert_sage.pyx +++ b/src/sage/libs/pari/convert_sage.pyx @@ -22,7 +22,7 @@ from cypari2.types cimport (GEN, typ, t_INT, t_FRAC, t_REAL, t_COMPLEX, lg, precp) from cypari2.paridecl cimport * from cypari2.stack cimport new_gen -from .convert_gmp cimport INT_to_mpz, new_gen_from_mpz_t, new_gen_from_mpq_t, INTFRAC_to_mpq +from sage.libs.pari.convert_gmp cimport INT_to_mpz, new_gen_from_mpz_t, new_gen_from_mpq_t, INTFRAC_to_mpq from sage.ext.stdsage cimport PY_NEW from sage.libs.gmp.mpz cimport mpz_fits_slong_p, mpz_sgn, mpz_get_ui, mpz_set, mpz_set_si, mpz_set_ui diff --git a/src/sage/manifolds/calculus_method.py b/src/sage/manifolds/calculus_method.py index 303dde6cd13..ddbad8a11ef 100644 --- a/src/sage/manifolds/calculus_method.py +++ b/src/sage/manifolds/calculus_method.py @@ -27,7 +27,12 @@ simplify_chain_real_sympy, simplify_chain_generic_sympy,) from sage.misc.latex import latex -import sympy + +try: + import sympy + from sympy import latex as sympy_latex +except ImportError: + sympy_latex = None # Conversion functions @@ -202,7 +207,7 @@ def __init__(self, current=None, base_field_type='real'): self._simplify_dict['SR'] = simplify_chain_generic # The default simplifying functions are saved: self._simplify_dict_default = self._simplify_dict.copy() - self._latex_dict = {'sympy': sympy.latex, 'SR': latex} + self._latex_dict = {'sympy': sympy_latex, 'SR': latex} def simplify(self, expression, method=None): r""" diff --git a/src/sage/manifolds/chart.py b/src/sage/manifolds/chart.py index 0705d4ecd88..e625299a6cc 100644 --- a/src/sage/manifolds/chart.py +++ b/src/sage/manifolds/chart.py @@ -1165,6 +1165,7 @@ def preimage(self, codomain_subset, name=None, latex_name=None): Pulling back a polytope under a chart:: + sage: # needs sage.geometry.polyhedron sage: P = Polyhedron(vertices=[[0, 0], [1, 2], [2, 1]]); P A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 3 vertices sage: McP = c_cart.preimage(P); McP @@ -1176,6 +1177,7 @@ def preimage(self, codomain_subset, name=None, latex_name=None): Pulling back the interior of a polytope under a chart:: + sage: # needs sage.geometry.polyhedron sage: int_P = P.interior(); int_P Relative interior of a 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 3 vertices @@ -1384,6 +1386,7 @@ def zero_function(self): Zero function on a p-adic manifold:: + sage: # needs sage.rings.padics sage: M = Manifold(2, 'M', structure='topological', field=Qp(5)); M 2-dimensional topological manifold M over the 5-adic Field with capped relative precision 20 @@ -1438,6 +1441,7 @@ def one_function(self): One function on a p-adic manifold:: + sage: # needs sage.rings.padics sage: M = Manifold(2, 'M', structure='topological', field=Qp(5)); M 2-dimensional topological manifold M over the 5-adic Field with capped relative precision 20 @@ -2754,10 +2758,9 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, A 2-dimensional chart plotted in terms of itself results in a rectangular grid:: - sage: R2 = Manifold(2, 'R^2', structure='topological') # the Euclidean plane - sage: c_cart. = R2.chart() # Cartesian coordinates - sage: g = c_cart.plot() # equivalent to c_cart.plot(c_cart) - sage: g + sage: R2 = Manifold(2, 'R^2', structure='topological') # the Euclidean plane + sage: c_cart. = R2.chart() # Cartesian coordinates + sage: g = c_cart.plot(); g # equivalent to c_cart.plot(c_cart) # needs sage.plot Graphics object consisting of 18 graphics primitives .. PLOT:: @@ -2770,11 +2773,10 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, Grid of polar coordinates in terms of Cartesian coordinates in the Euclidean plane:: - sage: U = R2.open_subset('U', coord_def={c_cart: (y!=0, x<0)}) # the complement of the segment y=0 and x>0 - sage: c_pol. = U.chart(r'r:(0,+oo) ph:(0,2*pi):\phi') # polar coordinates on U + sage: U = R2.open_subset('U', coord_def={c_cart: (y!=0, x<0)}) # the complement of the segment y=0 and x>0 + sage: c_pol. = U.chart(r'r:(0,+oo) ph:(0,2*pi):\phi') # polar coordinates on U sage: pol_to_cart = c_pol.transition_map(c_cart, [r*cos(ph), r*sin(ph)]) - sage: g = c_pol.plot(c_cart) - sage: g + sage: g = c_pol.plot(c_cart); g # needs sage.plot Graphics object consisting of 18 graphics primitives .. PLOT:: @@ -2789,7 +2791,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, Call with non-default values:: - sage: g = c_pol.plot(c_cart, ranges={ph:(pi/4,pi)}, + sage: g = c_pol.plot(c_cart, ranges={ph:(pi/4,pi)}, # needs sage.plot ....: number_values={r:7, ph:17}, ....: color={r:'red', ph:'green'}, ....: style={r:'-', ph:'--'}) @@ -2807,7 +2809,8 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, A single coordinate line can be drawn:: - sage: g = c_pol.plot(c_cart, fixed_coords={r: 2}) # draw a circle of radius r=2 + sage: g = c_pol.plot(c_cart, # draw a circle of radius r=2 # needs sage.plot + ....: fixed_coords={r: 2}) .. PLOT:: @@ -2821,7 +2824,8 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, :: - sage: g = c_pol.plot(c_cart, fixed_coords={ph: pi/4}) # draw a segment at phi=pi/4 + sage: g = c_pol.plot(c_cart, # draw a segment at phi=pi/4 # needs sage.plot + ....: fixed_coords={ph: pi/4}) .. PLOT:: @@ -2838,24 +2842,23 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, argument ``mapping``): 3D plot of the stereographic charts on the 2-sphere:: - sage: S2 = Manifold(2, 'S^2', structure='topological') # the 2-sphere - sage: U = S2.open_subset('U') ; V = S2.open_subset('V') # complement of the North and South pole, respectively + sage: S2 = Manifold(2, 'S^2', structure='topological') # the 2-sphere + sage: U = S2.open_subset('U'); V = S2.open_subset('V') # complement of the North and South pole, respectively sage: S2.declare_union(U,V) - sage: c_xy. = U.chart() # stereographic coordinates from the North pole - sage: c_uv. = V.chart() # stereographic coordinates from the South pole + sage: c_xy. = U.chart() # stereographic coordinates from the North pole + sage: c_uv. = V.chart() # stereographic coordinates from the South pole sage: xy_to_uv = c_xy.transition_map(c_uv, (x/(x^2+y^2), y/(x^2+y^2)), ....: intersection_name='W', restrictions1= x^2+y^2!=0, ....: restrictions2= u^2+v^2!=0) sage: uv_to_xy = xy_to_uv.inverse() - sage: R3 = Manifold(3, 'R^3', structure='topological') # the Euclidean space R^3 + sage: R3 = Manifold(3, 'R^3', structure='topological') # the Euclidean space R^3 sage: c_cart. = R3.chart() # Cartesian coordinates on R^3 sage: Phi = S2.continuous_map(R3, {(c_xy, c_cart): [2*x/(1+x^2+y^2), ....: 2*y/(1+x^2+y^2), (x^2+y^2-1)/(1+x^2+y^2)], ....: (c_uv, c_cart): [2*u/(1+u^2+v^2), ....: 2*v/(1+u^2+v^2), (1-u^2-v^2)/(1+u^2+v^2)]}, - ....: name='Phi', latex_name=r'\Phi') # Embedding of S^2 in R^3 - sage: g = c_xy.plot(c_cart, mapping=Phi) - sage: g + ....: name='Phi', latex_name=r'\Phi') # Embedding of S^2 in R^3 + sage: g = c_xy.plot(c_cart, mapping=Phi); g # needs sage.plot Graphics3d Object .. PLOT:: @@ -2885,12 +2888,12 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, The same plot without the ``(X,Y,Z)`` axes labels:: - sage: g = c_xy.plot(c_cart, mapping=Phi, label_axes=False) + sage: g = c_xy.plot(c_cart, mapping=Phi, label_axes=False) # needs sage.plot The North and South stereographic charts on the same plot:: - sage: g2 = c_uv.plot(c_cart, mapping=Phi, color='green') - sage: g + g2 + sage: g2 = c_uv.plot(c_cart, mapping=Phi, color='green') # needs sage.plot + sage: g + g2 # needs sage.plot Graphics3d Object .. PLOT:: @@ -2915,16 +2918,17 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, g2 = c_uv.plot(c_cart, mapping=Phi, color='green') sphinx_plot(g+g2) - South stereographic chart drawned in terms of the North one (we split + South stereographic chart drawn in terms of the North one (we split the plot in four parts to avoid the singularity at `(u,v)=(0,0)`):: + sage: # long time, needs sage.plot sage: W = U.intersection(V) # the subset common to both charts sage: c_uvW = c_uv.restrict(W) # chart (W,(u,v)) - sage: gSN1 = c_uvW.plot(c_xy, ranges={u:[-6.,-0.02], v:[-6.,-0.02]}) # long time - sage: gSN2 = c_uvW.plot(c_xy, ranges={u:[-6.,-0.02], v:[0.02,6.]}) # long time - sage: gSN3 = c_uvW.plot(c_xy, ranges={u:[0.02,6.], v:[-6.,-0.02]}) # long time - sage: gSN4 = c_uvW.plot(c_xy, ranges={u:[0.02,6.], v:[0.02,6.]}) # long time - sage: show(gSN1+gSN2+gSN3+gSN4, xmin=-1.5, xmax=1.5, ymin=-1.5, ymax=1.5) # long time + sage: gSN1 = c_uvW.plot(c_xy, ranges={u:[-6.,-0.02], v:[-6.,-0.02]}) + sage: gSN2 = c_uvW.plot(c_xy, ranges={u:[-6.,-0.02], v:[0.02,6.]}) + sage: gSN3 = c_uvW.plot(c_xy, ranges={u:[0.02,6.], v:[-6.,-0.02]}) + sage: gSN4 = c_uvW.plot(c_xy, ranges={u:[0.02,6.], v:[0.02,6.]}) + sage: show(gSN1+gSN2+gSN3+gSN4, xmin=-1.5, xmax=1.5, ymin=-1.5, ymax=1.5) .. PLOT:: @@ -2947,9 +2951,12 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, The coordinate line `u = 1` (red) and the coordinate line `v = 1` (green) on the same plot:: - sage: gu1 = c_uvW.plot(c_xy, fixed_coords={u: 1}, max_range=20, plot_points=300) # long time - sage: gv1 = c_uvW.plot(c_xy, fixed_coords={v: 1}, max_range=20, plot_points=300, color='green') # long time - sage: gu1 + gv1 # long time + sage: # long time, needs sage.plot + sage: gu1 = c_uvW.plot(c_xy, fixed_coords={u: 1}, max_range=20, + ....: plot_points=300) + sage: gv1 = c_uvW.plot(c_xy, fixed_coords={v: 1}, max_range=20, + ....: plot_points=300, color='green') + sage: gu1 + gv1 Graphics object consisting of 2 graphics primitives .. PLOT:: @@ -2975,8 +2982,9 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, A 3-dimensional chart plotted in terms of itself results in a 3D rectangular grid:: - sage: g = c_cart.plot() # equivalent to c_cart.plot(c_cart) # long time - sage: g # long time + sage: # long time, needs sage.plot + sage: g = c_cart.plot() # equivalent to c_cart.plot(c_cart) + sage: g Graphics3d Object .. PLOT:: @@ -2989,10 +2997,11 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, performed for at most 3 coordinates, which must be specified via the argument ``ambient_coords``):: + sage: # needs sage.plot sage: M = Manifold(4, 'M', structure='topological') sage: X. = M.chart() - sage: g = X.plot(ambient_coords=(t,x,y)) # the coordinate z is not depicted # long time - sage: g # long time + sage: g = X.plot(ambient_coords=(t,x,y)) # the coordinate z is not depicted # long time + sage: g # long time Graphics3d Object .. PLOT:: @@ -3004,7 +3013,8 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, :: - sage: g = X.plot(ambient_coords=(t,y)) # the coordinates x and z are not depicted + sage: # needs sage.plot + sage: g = X.plot(ambient_coords=(t,y)) # the coordinates x and z are not depicted sage: g Graphics object consisting of 18 graphics primitives diff --git a/src/sage/manifolds/chart_func.py b/src/sage/manifolds/chart_func.py index d7104cb7f0b..6363ed61841 100644 --- a/src/sage/manifolds/chart_func.py +++ b/src/sage/manifolds/chart_func.py @@ -40,9 +40,14 @@ from sage.categories.commutative_algebras import CommutativeAlgebras from sage.manifolds.utilities import ExpressionNice from sage.misc.cachefunc import cached_method +from sage.misc.lazy_import import lazy_import from sage.symbolic.ring import SR from sage.structure.mutability import Mutability -import sympy + +try: + import sympy +except ImportError: + pass class ChartFunction(AlgebraElement, ModuleElementWithMutability): diff --git a/src/sage/manifolds/differentiable/characteristic_cohomology_class.py b/src/sage/manifolds/differentiable/characteristic_cohomology_class.py index 7289f67b913..91ebbf00ccc 100644 --- a/src/sage/manifolds/differentiable/characteristic_cohomology_class.py +++ b/src/sage/manifolds/differentiable/characteristic_cohomology_class.py @@ -260,10 +260,11 @@ Let us check whether this form represents the Euler class correctly:: - sage: expr = e_class_form[2][[1,2]].expr() # long time - sage: expr = integrate(expr, x, -infinity, infinity) # long time - sage: expr = expr.simplify_full() # long time - sage: integrate(expr, y, -infinity, infinity) # long time + sage: # long time + sage: expr = e_class_form[2][[1,2]].expr() + sage: expr = integrate(expr, x, -infinity, infinity) + sage: expr = expr.simplify_full() + sage: integrate(expr, y, -infinity, infinity) 2 As we can see, the integral coincides with the Euler characteristic of `S^2` so diff --git a/src/sage/manifolds/differentiable/chart.py b/src/sage/manifolds/differentiable/chart.py index 6ea06b662ed..a40ebb8e5b2 100644 --- a/src/sage/manifolds/differentiable/chart.py +++ b/src/sage/manifolds/differentiable/chart.py @@ -1155,7 +1155,7 @@ def __init__(self, chart1, chart2, *transformations): """ CoordChange.__init__(self, chart1, chart2, *transformations) # Jacobian matrix: - self._jacobian = self._transf.jacobian() + self._jacobian = self._transf.jacobian() # If the two charts are on the same open subset, the Jacobian matrix is # added to the dictionary of changes of frame: if chart1.domain() == chart2.domain(): diff --git a/src/sage/manifolds/differentiable/curve.py b/src/sage/manifolds/differentiable/curve.py index fd77c39dfc4..7ea264565ae 100644 --- a/src/sage/manifolds/differentiable/curve.py +++ b/src/sage/manifolds/differentiable/curve.py @@ -94,7 +94,7 @@ class DifferentiableCurve(DiffMap): A graphical view of the curve is provided by the method :meth:`plot`:: - sage: c.plot(aspect_ratio=1) + sage: c.plot(aspect_ratio=1) # needs sage.plot Graphics object consisting of 1 graphics primitive .. PLOT:: diff --git a/src/sage/manifolds/differentiable/examples/euclidean.py b/src/sage/manifolds/differentiable/examples/euclidean.py index 97e3aa3d875..eb96b6da587 100644 --- a/src/sage/manifolds/differentiable/examples/euclidean.py +++ b/src/sage/manifolds/differentiable/examples/euclidean.py @@ -1879,14 +1879,15 @@ def _transition_spherical_cartesian(self): Tests of the change-of-frame formulas:: - sage: spher = E.spherical_coordinates() # long time - sage: spher_f = E.spherical_frame() # long time - sage: cart_f = E.cartesian_frame() # long time - sage: E.change_of_frame(cart_f, spher_f)[:,spher] # long time + sage: # long time + sage: spher = E.spherical_coordinates() + sage: spher_f = E.spherical_frame() + sage: cart_f = E.cartesian_frame() + sage: E.change_of_frame(cart_f, spher_f)[:,spher] [cos(ph)*sin(th) cos(ph)*cos(th) -sin(ph)] [sin(ph)*sin(th) cos(th)*sin(ph) cos(ph)] [ cos(th) -sin(th) 0] - sage: E.change_of_frame(spher_f, cart_f)[:,spher] # long time + sage: E.change_of_frame(spher_f, cart_f)[:,spher] [cos(ph)*sin(th) sin(ph)*sin(th) cos(th)] [cos(ph)*cos(th) cos(th)*sin(ph) -sin(th)] [ -sin(ph) cos(ph) 0] @@ -1958,14 +1959,15 @@ def _transition_cylindrical_cartesian(self): Tests of the change-of-frame formulas:: - sage: cylind = E.cylindrical_coordinates() # long time - sage: cylind_f = E.cylindrical_frame() # long time - sage: cart_f= E.cartesian_frame() # long time - sage: E.change_of_frame(cart_f, cylind_f)[:,cylind] # long time + sage: # long time + sage: cylind = E.cylindrical_coordinates() + sage: cylind_f = E.cylindrical_frame() + sage: cart_f= E.cartesian_frame() + sage: E.change_of_frame(cart_f, cylind_f)[:,cylind] [ cos(ph) -sin(ph) 0] [ sin(ph) cos(ph) 0] [ 0 0 1] - sage: E.change_of_frame(cylind_f, cart_f)[:,cylind] # long time + sage: E.change_of_frame(cylind_f, cart_f)[:,cylind] [ cos(ph) sin(ph) 0] [-sin(ph) cos(ph) 0] [ 0 0 1] @@ -2035,14 +2037,15 @@ def _transition_spherical_cylindrical(self): Tests of the change-of-frame formulas:: - sage: spher = E.spherical_coordinates() # long time - sage: spher_f = E.spherical_frame() # long time - sage: cylind_f = E.cylindrical_frame() # long time - sage: E.change_of_frame(cylind_f, spher_f)[:, spher] # long time + sage: # long time + sage: spher = E.spherical_coordinates() + sage: spher_f = E.spherical_frame() + sage: cylind_f = E.cylindrical_frame() + sage: E.change_of_frame(cylind_f, spher_f)[:, spher] [ sin(th) cos(th) 0] [ 0 0 1] [ cos(th) -sin(th) 0] - sage: E.change_of_frame(spher_f, cylind_f)[:, spher] # long time + sage: E.change_of_frame(spher_f, cylind_f)[:, spher] [ sin(th) 0 cos(th)] [ cos(th) 0 -sin(th)] [ 0 1 0] diff --git a/src/sage/manifolds/differentiable/integrated_curve.py b/src/sage/manifolds/differentiable/integrated_curve.py index 0d01a9afd70..fe2a6dcb3cc 100644 --- a/src/sage/manifolds/differentiable/integrated_curve.py +++ b/src/sage/manifolds/differentiable/integrated_curve.py @@ -41,11 +41,13 @@ Numerically integrate the geodesic (see :meth:`~IntegratedCurve.solve` for all possible options, including the choice of the numerical algorithm):: - sage: sol = c.solve() + sage: sol = c.solve() # needs scipy Plot the geodesic after interpolating the solution ``sol``:: sage: interp = c.interpolate() + + sage: # needs sage.plot sage: graph = c.plot_integrated() sage: p_plot = p.plot(size=30, label_offset=-0.07, fontsize=20) sage: v_plot = v.plot(label_offset=0.05, fontsize=20) @@ -116,12 +118,15 @@ from sage.calculus.interpolation import Spline from sage.misc.decorators import options from sage.misc.functional import numerical_approx +from sage.misc.lazy_import import lazy_import from sage.arith.srange import srange from sage.ext.fast_callable import fast_callable from sage.symbolic.ring import SR -from scipy.integrate import ode from random import shuffle +lazy_import('scipy.integrate', 'ode') + + class IntegratedCurve(DifferentiableCurve): r""" Given a chart with coordinates denoted `(x_{1}, \ldots, x_{n})`, @@ -227,7 +232,7 @@ class IntegratedCurve(DifferentiableCurve): Generate a solution of the system and an interpolation of this solution:: - sage: sol = c.solve(step=0.2, + sage: sol = c.solve(step=0.2, # needs scipy ....: parameters_values={B_0:1, m:1, q:1, L:10, T:1}, ....: solution_key='carac time 1', verbose=True) Performing numerical integration with method 'odeint'... @@ -239,7 +244,7 @@ class IntegratedCurve(DifferentiableCurve): The resulting list of points was associated with the key 'carac time 1' (if this key already referred to a former numerical solution, such a solution was erased). - sage: interp = c.interpolate(solution_key='carac time 1', + sage: interp = c.interpolate(solution_key='carac time 1', # needs scipy ....: interpolation_key='interp 1', verbose=True) Performing cubic spline interpolation by default... Interpolation completed and associated with the key 'interp 1' @@ -249,6 +254,7 @@ class IntegratedCurve(DifferentiableCurve): Such an interpolation is required to evaluate the curve and the vector tangent to the curve for any value of the curve parameter:: + sage: # needs scipy sage: p = c(1.9, verbose=True) Evaluating point coordinates from the interpolation associated with the key 'interp 1' by default... @@ -268,7 +274,7 @@ class IntegratedCurve(DifferentiableCurve): Plotting a numerical solution (with or without its tangent vector field) also requires the solution to be interpolated at least once:: - sage: c_plot_2d_1 = c.plot_integrated(ambient_coords=[x1, x2], + sage: c_plot_2d_1 = c.plot_integrated(ambient_coords=[x1, x2], # needs scipy ....: interpolation_key='interp 1', thickness=2.5, ....: display_tangent=True, plot_points=200, ....: plot_points_tangent=10, scale=0.5, @@ -277,7 +283,7 @@ class IntegratedCurve(DifferentiableCurve): A tiny final offset equal to 0.000251256281407035 was introduced for the last point in order to safely compute it from the interpolation. - sage: c_plot_2d_1 + sage: c_plot_2d_1 # needs scipy sage.plot Graphics object consisting of 11 graphics primitives .. PLOT:: @@ -307,22 +313,23 @@ class IntegratedCurve(DifferentiableCurve): An instance of :class:`IntegratedCurve` may store several numerical solutions and interpolations:: + sage: # needs scipy sage: sol = c.solve(step=0.2, ....: parameters_values={B_0:1, m:1, q:1, L:10, T:100}, ....: solution_key='carac time 100') sage: interp = c.interpolate(solution_key='carac time 100', ....: interpolation_key='interp 100') - sage: c_plot_3d_100 = c.plot_integrated(interpolation_key='interp 100', + sage: c_plot_3d_100 = c.plot_integrated(interpolation_key='interp 100', # needs sage.plot ....: thickness=2.5, display_tangent=True, ....: plot_points=200, plot_points_tangent=10, ....: scale=0.5, color='green', ....: color_tangent='orange') - sage: c_plot_3d_1 = c.plot_integrated(interpolation_key='interp 1', + sage: c_plot_3d_1 = c.plot_integrated(interpolation_key='interp 1', # needs sage.plot ....: thickness=2.5, display_tangent=True, ....: plot_points=200, plot_points_tangent=10, ....: scale=0.5, color='blue', ....: color_tangent='red') - sage: c_plot_3d_1 + c_plot_3d_100 + sage: c_plot_3d_1 + c_plot_3d_100 # needs sage.plot Graphics3d Object .. PLOT:: @@ -1001,7 +1008,7 @@ def solve(self, step=None, method='odeint', solution_key=None, sage: Tp = M.tangent_space(p) sage: v = Tp((1,0,1)) sage: c = M.integrated_curve(eqns, D, (t,0,5), v, name='c') - sage: sol = c.solve(parameters_values={B_0:1, m:1, q:1, L:10, T:1}, + sage: sol = c.solve(parameters_values={B_0:1, m:1, q:1, L:10, T:1}, # needs scipy ....: verbose=True) Performing numerical integration with method 'odeint'... Resulting list of points will be associated with the key @@ -1017,38 +1024,38 @@ def solve(self, step=None, method='odeint', solution_key=None, The first 3 points of the solution, in the form ``[t, x1, x2, x3]``:: - sage: sol[:3] # abs tol 1e-12 + sage: sol[:3] # abs tol 1e-12 # needs scipy [[0.0, 0.0, 0.0, 0.0], [0.05, 0.04999999218759271, -2.083327338392213e-05, 0.05], [0.1, 0.09999975001847655, -0.00016666146190783666, 0.1]] The default is ``verbose=False``:: - sage: sol_mute = c.solve(parameters_values={B_0:1, m:1, q:1, + sage: sol_mute = c.solve(parameters_values={B_0:1, m:1, q:1, # needs scipy ....: L:10, T:1}) - sage: sol_mute == sol + sage: sol_mute == sol # needs scipy True Specifying the relative and absolute error tolerance parameters to be used in :func:`~sage.calculus.desolvers.desolve_odeint`:: - sage: sol = c.solve(parameters_values={B_0:1, m:1, q:1, L:10, T:1}, + sage: sol = c.solve(parameters_values={B_0:1, m:1, q:1, L:10, T:1}, # needs scipy ....: rtol=1e-12, atol=1e-12) Using a numerical method different from the default one:: - sage: sol = c.solve(parameters_values={B_0:1, m:1, q:1, L:10, T:1}, + sage: sol = c.solve(parameters_values={B_0:1, m:1, q:1, L:10, T:1}, # needs scipy ....: method='rk8pd') TESTS:: - sage: sol = c.solve(parameters_values={m:1, q:1, L:10, T:1}) + sage: sol = c.solve(parameters_values={m:1, q:1, L:10, T:1}) # needs scipy Traceback (most recent call last): ... ValueError: numerical values should be provided for each of the parameters [B_0, L, T, m, q] - sage: sol = c.solve(method='my method', + sage: sol = c.solve(method='my method', # needs scipy ....: parameters_values={B_0:1, m:1, q:1, L:10, T:1}) Traceback (most recent call last): ... @@ -1489,9 +1496,9 @@ def solve_across_charts(self, charts=None, step=None, solution_key=None, mapping:: sage: phi = M.diff_map(M, {(C,C): [x, y], (P,C): [r*cos(th), r*sin(th)]}) - sage: fig = P.plot(number_values=9, chart=C, mapping=phi, + sage: fig = P.plot(number_values=9, chart=C, mapping=phi, # needs sage.plot ....: color='grey', ranges= {r:(2, 6), th:(0,2*pi)}) - sage: fig += C.plot(number_values=13, chart=C, mapping=phi, + sage: fig += C.plot(number_values=13, chart=C, mapping=phi, # needs sage.plot ....: color='grey', ranges= {x:(-3, 3), y:(-3, 3)}) There is a clear non-empty intersection between the two @@ -1559,9 +1566,9 @@ def solve_across_charts(self, charts=None, step=None, solution_key=None, :meth:`plot_integrated` again on each part. Finally, ``color`` can be a list, which will be cycled through:: - sage: fig += c.plot_integrated(mapping=phi, color=["green","red"], + sage: fig += c.plot_integrated(mapping=phi, color=["green","red"], # needs sage.plot ....: thickness=3, plot_points=100, across_charts=True) - sage: fig + sage: fig # needs sage.plot Graphics object consisting of 43 graphics primitives .. PLOT:: @@ -1856,6 +1863,8 @@ def solution(self, solution_key=None, verbose=False): sage: Tp = M.tangent_space(p) sage: v = Tp((1,0,1)) sage: c = M.integrated_curve(eqns, D, (t,0,5), v, name='c') + + sage: # needs scipy sage: sol = c.solve(solution_key='sol_T1', ....: parameters_values={B_0:1, m:1, q:1, L:10, T:1}) sage: sol_bis = c.solution(verbose=True) @@ -1928,6 +1937,8 @@ def interpolate(self, solution_key=None, method=None, sage: Tp = M.tangent_space(p) sage: v = Tp((1,0,1)) sage: c = M.integrated_curve(eqns, D, (t,0,5), v, name='c') + + sage: # needs scipy sage: sol = c.solve(method='odeint', ....: solution_key='sol_T1', ....: parameters_values={B_0:1, m:1, q:1, L:10, T:1}) @@ -2057,6 +2068,8 @@ def interpolation(self, interpolation_key=None, verbose=False): sage: Tp = M.tangent_space(p) sage: v = Tp((1,0,1)) sage: c = M.integrated_curve(eqns, D, (t,0,5), v, name='c') + + sage: # needs scipy sage: sol = c.solve(method='odeint', ....: solution_key='sol_T1', ....: parameters_values={B_0:1, m:1, q:1, L:10, T:1}) @@ -2131,6 +2144,8 @@ def __call__(self, t, interpolation_key=None, sage: Tp = M.tangent_space(p) sage: v = Tp((1,0,1)) sage: c = M.integrated_curve(eqns, D, (t,0,5), v, name='c') + + sage: # needs scipy sage: sol = c.solve(method='odeint', ....: solution_key='sol_T1', ....: parameters_values={B_0:1, m:1, q:1, L:10, T:1}) @@ -2213,6 +2228,8 @@ def tangent_vector_eval_at(self, t, sage: Tp = M.tangent_space(p) sage: v = Tp((1,0,1)) sage: c = M.integrated_curve(eqns, D, (t,0,5), v, name='c') + + sage: # needs scipy sage: sol = c.solve(method='odeint', ....: solution_key='sol_T1', ....: parameters_values={B_0:1, m:1, q:1, L:10, T:1}) @@ -2327,6 +2344,8 @@ def plot_integrated(self, chart=None, ambient_coords=None, sage: Tp = M.tangent_space(p) sage: v = Tp((1,0,1)) sage: c = M.integrated_curve(eqns, D, (t,0,6), v, name='c') + + sage: # needs scipy sage: sol = c.solve() sage: interp = c.interpolate() sage: c_plot_2d = c.plot_integrated(ambient_coords=[x1, x2], @@ -3756,6 +3775,7 @@ class IntegratedGeodesic(IntegratedAutoparallelCurve): Solve, interpolate and prepare the plot for the solutions corresponding to the three initial conditions previously set:: + sage: # needs scipy sage.plot sage: graph3D_embedded_geods = Graphics() sage: for key in dict_params: ....: sol = c.solve(solution_key='sol-'+key, @@ -3770,6 +3790,7 @@ class IntegratedGeodesic(IntegratedAutoparallelCurve): Plot the resulting geodesics on the grid of polar coordinates lines on `\mathbb{S}^{2}` and check that these are great circles:: + sage: # needs scipy sage.plot sage: graph3D_embedded_polar_coords = polar.plot(chart=cart, ....: mapping=euclid_embedding, ....: number_values=15, color='yellow') diff --git a/src/sage/manifolds/differentiable/multivectorfield.py b/src/sage/manifolds/differentiable/multivectorfield.py index 2590803b0fa..87f68f8b1f0 100644 --- a/src/sage/manifolds/differentiable/multivectorfield.py +++ b/src/sage/manifolds/differentiable/multivectorfield.py @@ -1404,18 +1404,20 @@ def bracket(self, other): Finally let us check the graded Jacobi identity for `p=1`, `q=1` and `r=2`:: - sage: a_bc = a.bracket(b.bracket(c)) # long time - sage: b_ca = b.bracket(c.bracket(a)) # long time - sage: c_ab = c.bracket(a.bracket(b)) # long time - sage: a_bc + b_ca + c_ab == 0 # long time + sage: # long time + sage: a_bc = a.bracket(b.bracket(c)) + sage: b_ca = b.bracket(c.bracket(a)) + sage: c_ab = c.bracket(a.bracket(b)) + sage: a_bc + b_ca + c_ab == 0 True as well as for `p=1`, `q=2` and `r=2`:: - sage: a_cd = a.bracket(c.bracket(d)) # long time - sage: c_da = c.bracket(d.bracket(a)) # long time - sage: d_ac = d.bracket(a.bracket(c)) # long time - sage: a_cd + c_da - d_ac == 0 # long time + sage: # long time + sage: a_cd = a.bracket(c.bracket(d)) + sage: c_da = c.bracket(d.bracket(a)) + sage: d_ac = d.bracket(a.bracket(c)) + sage: a_cd + c_da - d_ac == 0 True """ diff --git a/src/sage/manifolds/differentiable/pseudo_riemannian_submanifold.py b/src/sage/manifolds/differentiable/pseudo_riemannian_submanifold.py index 3aef31eb703..b41b8ba4ba8 100644 --- a/src/sage/manifolds/differentiable/pseudo_riemannian_submanifold.py +++ b/src/sage/manifolds/differentiable/pseudo_riemannian_submanifold.py @@ -115,13 +115,14 @@ Let us compute the induced metric (or first fundamental form):: - sage: gamma = N.induced_metric() # long time - sage: gamma.display() # long time + sage: # long time + sage: gamma = N.induced_metric() + sage: gamma.display() gamma = b^2 drh⊗drh + b^2*sinh(rh)^2 dth⊗dth - sage: gamma[:] # long time + sage: gamma[:] [ b^2 0] [ 0 b^2*sinh(rh)^2] - sage: gamma[1,1] # long time + sage: gamma[1,1] b^2 the normal vector:: diff --git a/src/sage/manifolds/differentiable/scalarfield_algebra.py b/src/sage/manifolds/differentiable/scalarfield_algebra.py index 7bbf5a39146..44e6e16bff4 100644 --- a/src/sage/manifolds/differentiable/scalarfield_algebra.py +++ b/src/sage/manifolds/differentiable/scalarfield_algebra.py @@ -465,12 +465,11 @@ def _latex_(self): 'C^{\\infty}\\left(M\\right)' sage: latex(CM) # indirect doctest C^{\infty}\left(M\right) - """ degree = self._domain.diff_degree() if degree == infinity: latex_degree = r"\infty" # to skip the "+" in latex(infinity) else: latex_degree = "{}".format(degree) - return r"C^{" + latex_degree + r"}\left(" + self._domain._latex_() + \ + return r"C^{" + latex_degree + r"}\left(" + self._domain._latex_() + \ r"\right)" diff --git a/src/sage/manifolds/differentiable/tangent_vector.py b/src/sage/manifolds/differentiable/tangent_vector.py index 5fc2506b1d0..97abcea54e1 100644 --- a/src/sage/manifolds/differentiable/tangent_vector.py +++ b/src/sage/manifolds/differentiable/tangent_vector.py @@ -261,12 +261,12 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, Plot of the vector alone (arrow + label):: - sage: v.plot() + sage: v.plot() # needs sage.plot Graphics object consisting of 2 graphics primitives Plot atop of the chart grid:: - sage: X.plot() + v.plot() + sage: X.plot() + v.plot() # needs sage.plot Graphics object consisting of 20 graphics primitives .. PLOT:: @@ -280,7 +280,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, Plots with various options:: - sage: X.plot() + v.plot(color='green', scale=2, label='V') + sage: X.plot() + v.plot(color='green', scale=2, label='V') # needs sage.plot Graphics object consisting of 20 graphics primitives .. PLOT:: @@ -294,7 +294,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, :: - sage: X.plot() + v.plot(print_label=False) + sage: X.plot() + v.plot(print_label=False) # needs sage.plot Graphics object consisting of 19 graphics primitives .. PLOT:: @@ -308,7 +308,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, :: - sage: X.plot() + v.plot(color='green', label_color='black', + sage: X.plot() + v.plot(color='green', label_color='black', # needs sage.plot ....: fontsize=20, label_offset=0.2) Graphics object consisting of 20 graphics primitives @@ -323,7 +323,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, :: - sage: X.plot() + v.plot(linestyle=':', width=4, arrowsize=8, + sage: X.plot() + v.plot(linestyle=':', width=4, arrowsize=8, # needs sage.plot ....: fontsize=20) Graphics object consisting of 20 graphics primitives @@ -342,7 +342,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, (a, b) sage: v = Tp((1+a, -b^2), name='v') ; v.display() v = (a + 1) ∂/∂x - b^2 ∂/∂y - sage: X.plot() + v.plot(parameters={a: -2, b: 3}) + sage: X.plot() + v.plot(parameters={a: -2, b: 3}) # needs sage.plot Graphics object consisting of 20 graphics primitives Special case of the zero vector:: @@ -350,7 +350,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, sage: v = Tp.zero() ; v Tangent vector zero at Point p on the 2-dimensional differentiable manifold M - sage: X.plot() + v.plot() + sage: X.plot() + v.plot() # needs sage.plot Graphics object consisting of 19 graphics primitives Vector tangent to a 4-dimensional manifold:: @@ -365,7 +365,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, We cannot make a 4D plot directly:: - sage: v.plot() + sage: v.plot() # needs sage.plot Traceback (most recent call last): ... ValueError: the number of coordinates involved in the plot must @@ -375,7 +375,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, the argument ``ambient_coords``. For instance, for a 2-dimensional plot in terms of the coordinates `(x, y)`:: - sage: v.plot(ambient_coords=(x,y)) + sage: v.plot(ambient_coords=(x,y)) # needs sage.plot Graphics object consisting of 2 graphics primitives .. PLOT:: @@ -391,14 +391,14 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, Similarly, for a 3-dimensional plot in terms of the coordinates `(t, x, y)`:: - sage: g = v.plot(ambient_coords=(t,x,z)) - sage: print(g) + sage: g = v.plot(ambient_coords=(t,x,z)) # needs sage.plot + sage: print(g) # needs sage.plot Graphics3d Object This plot involves only the components `v^t`, `v^x` and `v^z` of `v`. A nice 3D view atop the coordinate grid is obtained via:: - sage: (X.plot(ambient_coords=(t,x,z)) # long time + sage: (X.plot(ambient_coords=(t,x,z)) # long time # needs sage.plot ....: + v.plot(ambient_coords=(t,x,z), ....: label_offset=0.5, width=6)) Graphics3d Object @@ -431,9 +431,9 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, sage: v = XS.frame()[1].at(p) ; v # the coordinate vector ∂/∂phi at p Tangent vector ∂/∂ph at Point p on the 2-dimensional differentiable manifold S^2 - sage: graph_v = v.plot(mapping=F) - sage: graph_S2 = XS.plot(chart=X3, mapping=F, number_values=9) # long time - sage: graph_v + graph_S2 # long time + sage: graph_v = v.plot(mapping=F) # needs sage.plot + sage: graph_S2 = XS.plot(chart=X3, mapping=F, number_values=9) # long time, needs sage.plot + sage: graph_v + graph_S2 # long time, needs sage.plot Graphics3d Object .. PLOT:: diff --git a/src/sage/manifolds/differentiable/tensorfield.py b/src/sage/manifolds/differentiable/tensorfield.py index 9e302688024..a47bd364436 100644 --- a/src/sage/manifolds/differentiable/tensorfield.py +++ b/src/sage/manifolds/differentiable/tensorfield.py @@ -245,17 +245,18 @@ class TensorField(ModuleElementWithMutability): The vectors can be defined only on subsets of `S^2`, the domain of the result is then the common subset:: - sage: s = t(a.restrict(U), b) ; s # long time + sage: # long time + sage: s = t(a.restrict(U), b) ; s Scalar field t(a,b) on the Open subset U of the 2-dimensional differentiable manifold S^2 - sage: s.display() # long time + sage: s.display() t(a,b): U → ℝ (x, y) ↦ -2*x*y - y^2 - 3*x on W: (u, v) ↦ -(3*u^3 + (3*u + 1)*v^2 + 2*u*v)/(u^4 + 2*u^2*v^2 + v^4) - sage: s = t(a.restrict(U), b.restrict(W)) ; s # long time + sage: s = t(a.restrict(U), b.restrict(W)) ; s Scalar field t(a,b) on the Open subset W of the 2-dimensional differentiable manifold S^2 - sage: s.display() # long time + sage: s.display() t(a,b): W → ℝ (x, y) ↦ -2*x*y - y^2 - 3*x (u, v) ↦ -(3*u^3 + (3*u + 1)*v^2 + 2*u*v)/(u^4 + 2*u^2*v^2 + v^4) diff --git a/src/sage/manifolds/differentiable/vectorfield.py b/src/sage/manifolds/differentiable/vectorfield.py index 22b5df5717f..04018ba9916 100644 --- a/src/sage/manifolds/differentiable/vectorfield.py +++ b/src/sage/manifolds/differentiable/vectorfield.py @@ -465,7 +465,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, sage: v = M.vector_field(-y, x, name='v') sage: v.display() v = -y ∂/∂x + x ∂/∂y - sage: v.plot() + sage: v.plot() # needs sage.plot Graphics object consisting of 80 graphics primitives .. PLOT:: @@ -478,7 +478,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, Plot with various options:: - sage: v.plot(scale=0.5, color='green', linestyle='--', width=1, + sage: v.plot(scale=0.5, color='green', linestyle='--', width=1, # needs sage.plot ....: arrowsize=6) Graphics object consisting of 80 graphics primitives @@ -492,7 +492,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, :: - sage: v.plot(max_range=4, number_values=5, scale=0.5) + sage: v.plot(max_range=4, number_values=5, scale=0.5) # needs sage.plot Graphics object consisting of 24 graphics primitives .. PLOT:: @@ -506,7 +506,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, Plot using parallel computation:: sage: Parallelism().set(nproc=2) - sage: v.plot(scale=0.5, number_values=10, linestyle='--', width=1, + sage: v.plot(scale=0.5, number_values=10, linestyle='--', width=1, # needs sage.plot ....: arrowsize=6) Graphics object consisting of 100 graphics primitives @@ -524,7 +524,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, Plots along a line of fixed coordinate:: - sage: v.plot(fixed_coords={x: -2}) + sage: v.plot(fixed_coords={x: -2}) # needs sage.plot Graphics object consisting of 9 graphics primitives .. PLOT:: @@ -537,7 +537,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, :: - sage: v.plot(fixed_coords={y: 1}) + sage: v.plot(fixed_coords={y: 1}) # needs sage.plot Graphics object consisting of 9 graphics primitives .. PLOT:: @@ -566,7 +566,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, Rather, we have to select some coordinates for the plot, via the argument ``ambient_coords``. For instance, for a 3D plot:: - sage: v.plot(ambient_coords=(x, y, z), fixed_coords={t: 1}, # long time + sage: v.plot(ambient_coords=(x, y, z), fixed_coords={t: 1}, # long time, needs sage.plot ....: number_values=4) Graphics3d Object @@ -580,7 +580,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, :: - sage: v.plot(ambient_coords=(x, y, t), fixed_coords={z: 0}, # long time + sage: v.plot(ambient_coords=(x, y, t), fixed_coords={z: 0}, # long time, needs sage.plot ....: ranges={x: (-2,2), y: (-2,2), t: (-1, 4)}, ....: number_values=4) Graphics3d Object @@ -596,7 +596,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, or, for a 2D plot:: - sage: v.plot(ambient_coords=(x, y), fixed_coords={t: 1, z: 0}) # long time + sage: v.plot(ambient_coords=(x, y), fixed_coords={t: 1, z: 0}) # long time, needs sage.plot Graphics object consisting of 80 graphics primitives .. PLOT:: @@ -609,7 +609,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, :: - sage: v.plot(ambient_coords=(x, t), fixed_coords={y: 1, z: 0}) # long time + sage: v.plot(ambient_coords=(x, t), fixed_coords={y: 1, z: 0}) # long time, needs sage.plot Graphics object consisting of 72 graphics primitives .. PLOT:: @@ -636,9 +636,9 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, sage: v = XS.frame()[1] ; v # the coordinate vector ∂/∂phi Vector field ∂/∂ph on the Open subset U of the 2-dimensional differentiable manifold S^2 - sage: graph_v = v.plot(chart=X3, mapping=F, label_axes=False) - sage: graph_S2 = XS.plot(chart=X3, mapping=F, number_values=9) - sage: graph_v + graph_S2 + sage: graph_v = v.plot(chart=X3, mapping=F, label_axes=False) # needs sage.plot + sage: graph_S2 = XS.plot(chart=X3, mapping=F, number_values=9) # needs sage.plot + sage: graph_v + graph_S2 # needs sage.plot Graphics3d Object .. PLOT:: diff --git a/src/sage/manifolds/manifold.py b/src/sage/manifolds/manifold.py index b19177da9e5..0e09530ad54 100644 --- a/src/sage/manifolds/manifold.py +++ b/src/sage/manifolds/manifold.py @@ -455,7 +455,7 @@ class being :class:`~sage.manifolds.point.ManifoldPoint`. A manifold over `\QQ_5`, the field of 5-adic numbers:: - sage: N = Manifold(2, 'N', structure='topological', field=Qp(5)); N + sage: N = Manifold(2, 'N', structure='topological', field=Qp(5)); N # needs sage.rings.padics 2-dimensional topological manifold N over the 5-adic Field with capped relative precision 20 @@ -474,7 +474,7 @@ class being :class:`~sage.manifolds.point.ManifoldPoint`. True sage: M in Manifolds(RR) True - sage: N in Manifolds(Qp(5)) + sage: N in Manifolds(Qp(5)) # needs sage.rings.padics True The corresponding Sage *elements* are points:: diff --git a/src/sage/manifolds/point.py b/src/sage/manifolds/point.py index 728269ed5ea..ff0009db15b 100644 --- a/src/sage/manifolds/point.py +++ b/src/sage/manifolds/point.py @@ -803,6 +803,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, Drawing a point on a 2-dimensional manifold:: + sage: # needs sage.plot sage: M = Manifold(2, 'M', structure='topological') sage: X. = M.chart() sage: p = M.point((1,3), name='p') @@ -826,12 +827,14 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, ``p`` has been defined, it can be skipped in the arguments of ``plot``:: + sage: # needs sage.plot sage: g = p.plot() sage: g + gX Graphics object consisting of 20 graphics primitives Call with some options:: + sage: # needs sage.plot sage: g = p.plot(chart=X, size=40, color='green', label='$P$', ....: label_color='blue', fontsize=20, label_offset=0.3) sage: g + gX @@ -851,9 +854,9 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, symbolic variable:: sage: a = var('a') - sage: q = M.point((a,2*a), name='q') - sage: gq = q.plot(parameters={a:-2}, label_offset=0.2) - sage: g + gX + gq + sage: q = M.point((a,2*a), name='q') # needs sage.plot + sage: gq = q.plot(parameters={a:-2}, label_offset=0.2) # needs sage.plot + sage: g + gX + gq # needs sage.plot Graphics object consisting of 22 graphics primitives .. PLOT:: @@ -871,11 +874,12 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, The numerical value is used only for the plot:: - sage: q.coord() + sage: q.coord() # needs sage.plot (a, 2*a) Drawing a point on a 3-dimensional manifold:: + sage: # needs sage.plot sage: M = Manifold(3, 'M', structure='topological') sage: X. = M.chart() sage: p = M.point((2,1,3), name='p') @@ -888,16 +892,17 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, Call with some options:: - sage: g = p.plot(chart=X, size=40, color='green', label='P_1', + sage: g = p.plot(chart=X, size=40, color='green', label='P_1', # needs sage.plot ....: label_color='blue', fontsize=20, label_offset=0.3) - sage: g + gX + sage: g + gX # needs sage.plot Graphics3d Object An example of plot via a mapping: plot of a point on a 2-sphere viewed in the 3-dimensional space ``M``:: + sage: # needs sage.plot sage: S2 = Manifold(2, 'S^2', structure='topological') - sage: U = S2.open_subset('U') # the open set covered by spherical coord. + sage: U = S2.open_subset('U') # the open set covered by spherical coord. sage: XS. = U.chart(r'th:(0,pi):\theta ph:(0,2*pi):\phi') sage: p = U.point((pi/4, pi/8), name='p') sage: F = S2.continuous_map(M, {(XS, X): [sin(th)*cos(ph), @@ -913,6 +918,7 @@ def plot(self, chart=None, ambient_coords=None, mapping=None, Use of the option ``ambient_coords`` for plots on a 4-dimensional manifold:: + sage: # needs sage.plot sage: M = Manifold(4, 'M', structure='topological') sage: X. = M.chart() sage: p = M.point((1,2,3,4), name='p') diff --git a/src/sage/manifolds/scalarfield_algebra.py b/src/sage/manifolds/scalarfield_algebra.py index 52c89fd9959..d7941fad08c 100644 --- a/src/sage/manifolds/scalarfield_algebra.py +++ b/src/sage/manifolds/scalarfield_algebra.py @@ -568,7 +568,7 @@ def _latex_(self): C^0 \left(M\right) """ - return r"C^0 \left(" + self._domain._latex_() + r"\right)" + return r"C^0 \left(" + self._domain._latex_() + r"\right)" @cached_method def zero(self): diff --git a/src/sage/manifolds/subset.py b/src/sage/manifolds/subset.py index b92d8a25d82..cd98b143037 100644 --- a/src/sage/manifolds/subset.py +++ b/src/sage/manifolds/subset.py @@ -897,11 +897,12 @@ def subset_digraph(self, loops=False, quotient=False, open_covers=False, points= EXAMPLES:: + sage: # needs sage.graphs sage: M = Manifold(3, 'M') sage: U = M.open_subset('U'); V = M.open_subset('V'); W = M.open_subset('W') sage: D = M.subset_digraph(); D Digraph on 4 vertices - sage: D.edges(sort=True, key=lambda e: (e[0]._name, e[1]._name)) + sage: D.edges(sort=True, key=lambda e: (e[0]._name, e[1]._name)) # needs sage.graphs [(Set {U} of open subsets of the 3-dimensional differentiable manifold M, Set {M} of open subsets of the 3-dimensional differentiable manifold M, None), @@ -911,27 +912,26 @@ def subset_digraph(self, loops=False, quotient=False, open_covers=False, points= (Set {W} of open subsets of the 3-dimensional differentiable manifold M, Set {M} of open subsets of the 3-dimensional differentiable manifold M, None)] - sage: D.plot(layout='acyclic') + sage: D.plot(layout='acyclic') # needs sage.plot Graphics object consisting of 8 graphics primitives sage: def label(element): ....: try: ....: return element._name ....: except AttributeError: ....: return '[' + ', '.join(sorted(x._name for x in element)) + ']' - sage: D.relabel(label, inplace=False).plot(layout='acyclic') + sage: D.relabel(label, inplace=False).plot(layout='acyclic') # needs sage.plot Graphics object consisting of 8 graphics primitives - sage: VW = V.union(W) sage: D = M.subset_digraph(); D Digraph on 5 vertices - sage: D.relabel(label, inplace=False).plot(layout='acyclic') + sage: D.relabel(label, inplace=False).plot(layout='acyclic') # needs sage.plot Graphics object consisting of 12 graphics primitives If ``open_covers`` is ``True``, the digraph includes a special vertex for each nontrivial open cover of a subset:: - sage: D = M.subset_digraph(open_covers=True) - sage: D.relabel(label, inplace=False).plot(layout='acyclic') + sage: D = M.subset_digraph(open_covers=True) # needs sage.graphs + sage: D.relabel(label, inplace=False).plot(layout='acyclic') # needs sage.graphs sage.plot Graphics object consisting of 14 graphics primitives .. PLOT:: @@ -1057,11 +1057,12 @@ def subset_poset(self, open_covers=False, points=False, lower_bound=None): EXAMPLES:: + sage: # needs sage.graphs sage: M = Manifold(3, 'M') sage: U = M.open_subset('U'); V = M.open_subset('V'); W = M.open_subset('W') sage: P = M.subset_poset(); P Finite poset containing 4 elements - sage: P.plot(element_labels={element: element._name for element in P}) + sage: P.plot(element_labels={element: element._name for element in P}) # needs sage.plot Graphics object consisting of 8 graphics primitives sage: VW = V.union(W) sage: P = M.subset_poset(); P @@ -1076,12 +1077,13 @@ def subset_poset(self, open_covers=False, points=False, lower_bound=None): sage: sorted(P.lower_covers(ManifoldSubsetFiniteFamily([M])), key=str) [Set {U} of open subsets of the 3-dimensional differentiable manifold M, Set {V_union_W} of open subsets of the 3-dimensional differentiable manifold M] - sage: P.plot(element_labels={element: element._name for element in P}) + sage: P.plot(element_labels={element: element._name for element in P}) # needs sage.plot Graphics object consisting of 10 graphics primitives If ``open_covers`` is ``True``, the poset includes a special vertex for each nontrivial open cover of a subset:: + sage: # needs sage.graphs sage: P = M.subset_poset(open_covers=True); P Finite poset containing 6 elements sage: from sage.manifolds.subset import ManifoldSubsetFiniteFamily @@ -1094,7 +1096,7 @@ def subset_poset(self, open_covers=False, points=False, lower_bound=None): ....: return element._name ....: except AttributeError: ....: return '[' + ', '.join(sorted(x._name for x in element)) + ']' - sage: P.plot(element_labels={element: label(element) for element in P}) + sage: P.plot(element_labels={element: label(element) for element in P}) # needs sage.plot Graphics object consisting of 12 graphics primitives .. PLOT:: @@ -1236,7 +1238,7 @@ def superset_digraph(self, loops=False, quotient=False, open_covers=False, point sage: M = Manifold(3, 'M') sage: U = M.open_subset('U'); V = M.open_subset('V'); W = M.open_subset('W') sage: VW = V.union(W) - sage: P = V.superset_digraph(loops=False, upper_bound=VW); P + sage: P = V.superset_digraph(loops=False, upper_bound=VW); P # needs sage.graphs Digraph on 2 vertices """ @@ -1261,9 +1263,9 @@ def superset_poset(self, open_covers=False, points=False, upper_bound=None): sage: M = Manifold(3, 'M') sage: U = M.open_subset('U'); V = M.open_subset('V'); W = M.open_subset('W') sage: VW = V.union(W) - sage: P = V.superset_poset(); P + sage: P = V.superset_poset(); P # needs sage.graphs Finite poset containing 3 elements - sage: P.plot(element_labels={element: element._name for element in P}) + sage: P.plot(element_labels={element: element._name for element in P}) # needs sage.graphs sage.plot Graphics object consisting of 6 graphics primitives """ @@ -1369,25 +1371,25 @@ def declare_union(self, *subsets_or_families, disjoint=False): ....: return element._name ....: except AttributeError: ....: return '[' + ', '.join(sorted(x._name for x in element)) + ']' - sage: P = M.subset_poset(open_covers=True); P + sage: P = M.subset_poset(open_covers=True); P # needs sage.graphs Finite poset containing 4 elements - sage: P.plot(element_labels={element: label(element) for element in P}) + sage: P.plot(element_labels={element: label(element) for element in P}) # needs sage.graphs sage.plot Graphics object consisting of 8 graphics primitives sage: AB.declare_union(A, B) sage: A.union(B) Subset AB of the 2-dimensional topological manifold M - sage: P = M.subset_poset(open_covers=True); P + sage: P = M.subset_poset(open_covers=True); P # needs sage.graphs Finite poset containing 4 elements - sage: P.plot(element_labels={element: label(element) for element in P}) + sage: P.plot(element_labels={element: label(element) for element in P}) # needs sage.graphs sage.plot Graphics object consisting of 8 graphics primitives sage: B1 = B.subset('B1', is_open=True) sage: B2 = B.subset('B2', is_open=True) sage: B.declare_union(B1, B2, disjoint=True) - sage: P = M.subset_poset(open_covers=True); P + sage: P = M.subset_poset(open_covers=True); P # needs sage.graphs Finite poset containing 9 elements - sage: P.plot(element_labels={element: label(element) for element in P}) + sage: P.plot(element_labels={element: label(element) for element in P}) # needs sage.graphs sage.plot Graphics object consisting of 19 graphics primitives .. PLOT:: @@ -1495,18 +1497,18 @@ def declare_equal(self, *others): sage: Vs = [M.open_subset(f'V{i}') for i in range(2)] sage: UV = U.intersection(V) sage: W = UV.open_subset('W') - sage: P = M.subset_poset() + sage: P = M.subset_poset() # needs sage.graphs sage: def label(element): ....: return element._name - sage: P.plot(element_labels={element: label(element) for element in P}) + sage: P.plot(element_labels={element: label(element) for element in P}) # needs sage.graphs sage.plot Graphics object consisting of 15 graphics primitives sage: V.declare_equal(Vs) - sage: P = M.subset_poset() - sage: P.plot(element_labels={element: label(element) for element in P}) + sage: P = M.subset_poset() # needs sage.graphs + sage: P.plot(element_labels={element: label(element) for element in P}) # needs sage.graphs sage.plot Graphics object consisting of 11 graphics primitives sage: W.declare_equal(U) - sage: P = M.subset_poset() - sage: P.plot(element_labels={element: label(element) for element in P}) + sage: P = M.subset_poset() # needs sage.graphs + sage: P.plot(element_labels={element: label(element) for element in P}) # needs sage.graphs sage.plot Graphics object consisting of 6 graphics primitives .. PLOT:: @@ -1557,16 +1559,16 @@ def declare_subset(self, *supersets): Set {M, V} of open subsets of the 2-dimensional differentiable manifold M sage: U1.subset_family() Set {U1} of open subsets of the 2-dimensional differentiable manifold M - sage: P = M.subset_poset() + sage: P = M.subset_poset() # needs sage.graphs sage: def label(element): ....: return element._name - sage: P.plot(element_labels={element: label(element) for element in P}) + sage: P.plot(element_labels={element: label(element) for element in P}) # needs sage.graphs sage.plot Graphics object consisting of 8 graphics primitives sage: V.declare_subset(U1, U2) sage: V.superset_family() Set {M, U1, U2, V} of open subsets of the 2-dimensional differentiable manifold M - sage: P = M.subset_poset() - sage: P.plot(element_labels={element: label(element) for element in P}) + sage: P = M.subset_poset() # needs sage.graphs + sage: P.plot(element_labels={element: label(element) for element in P}) # needs sage.graphs sage.plot Graphics object consisting of 9 graphics primitives Subsets in a directed cycle of inclusions are equal:: @@ -1576,8 +1578,8 @@ def declare_subset(self, *supersets): Set {M, U1, U2, V} of open subsets of the 2-dimensional differentiable manifold M sage: M.equal_subset_family() Set {M, U1, U2, V} of open subsets of the 2-dimensional differentiable manifold M - sage: P = M.subset_poset() - sage: P.plot(element_labels={element: label(element) for element in P}) + sage: P = M.subset_poset() # needs sage.graphs + sage: P.plot(element_labels={element: label(element) for element in P}) # needs sage.graphs sage.plot Graphics object consisting of 2 graphics primitives .. PLOT:: @@ -1623,16 +1625,16 @@ def declare_superset(self, *subsets): sage: W = V1.intersection(V2) sage: U.subset_family() Set {U} of open subsets of the 2-dimensional differentiable manifold M - sage: P = M.subset_poset() + sage: P = M.subset_poset() # needs sage.graphs sage: def label(element): ....: return element._name - sage: P.plot(element_labels={element: label(element) for element in P}) + sage: P.plot(element_labels={element: label(element) for element in P}) # needs sage.graphs sage.plot Graphics object consisting of 11 graphics primitives sage: U.declare_superset(V1, V2) sage: U.subset_family() Set {U, V1, V1_inter_V2, V2} of open subsets of the 2-dimensional differentiable manifold M - sage: P = M.subset_poset() - sage: P.plot(element_labels={element: label(element) for element in P}) + sage: P = M.subset_poset() # needs sage.graphs + sage: P.plot(element_labels={element: label(element) for element in P}) # needs sage.graphs sage.plot Graphics object consisting of 11 graphics primitives Subsets in a directed cycle of inclusions are equal:: @@ -1642,8 +1644,8 @@ def declare_superset(self, *subsets): Set {U, V1, V1_inter_V2, V2} of open subsets of the 2-dimensional differentiable manifold M sage: W.equal_subset_family() Set {U, V1, V1_inter_V2, V2} of open subsets of the 2-dimensional differentiable manifold M - sage: P = M.subset_poset() - sage: P.plot(element_labels={element: label(element) for element in P}) + sage: P = M.subset_poset() # needs sage.graphs + sage: P.plot(element_labels={element: label(element) for element in P}) # needs sage.graphs sage.plot Graphics object consisting of 4 graphics primitives .. PLOT:: @@ -1726,7 +1728,7 @@ def declare_empty(self): Emptiness is recorded as empty open covers:: - sage: P = M.subset_poset(open_covers=True, points=[b]) + sage: P = M.subset_poset(open_covers=True, points=[b]) # needs sage.graphs sage: def label(element): ....: if isinstance(element, str): ....: return element @@ -1734,7 +1736,7 @@ def declare_empty(self): ....: return element._name ....: except AttributeError: ....: return '[' + ', '.join(sorted(x._name for x in element)) + ']' - sage: P.plot(element_labels={element: label(element) for element in P}) + sage: P.plot(element_labels={element: label(element) for element in P}) # needs sage.graphs sage.plot Graphics object consisting of 10 graphics primitives .. PLOT:: diff --git a/src/sage/manifolds/subsets/pullback.py b/src/sage/manifolds/subsets/pullback.py index b28365601f8..452b6a2e008 100644 --- a/src/sage/manifolds/subsets/pullback.py +++ b/src/sage/manifolds/subsets/pullback.py @@ -15,6 +15,7 @@ from sage.categories.sets_cat import Sets, EmptySetError from sage.categories.metric_spaces import MetricSpaces +from sage.misc.lazy_import import lazy_import from sage.modules.free_module import is_FreeModule from sage.rings.infinity import infinity, minus_infinity from sage.rings.integer_ring import ZZ @@ -29,7 +30,8 @@ from sage.manifolds.scalarfield import ScalarField from sage.sets.real_set import RealSet import sage.geometry.abc -from sage.geometry.relative_interior import RelativeInterior + +lazy_import('sage.geometry.relative_interior', 'RelativeInterior') class ManifoldSubsetPullback(ManifoldSubset): @@ -77,6 +79,7 @@ class ManifoldSubsetPullback(ManifoldSubset): Pulling back a polytope under a chart:: + sage: # needs sage.geometry.polyhedron sage: P = Polyhedron(vertices=[[0, 0], [1, 2], [2, 1]]); P A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 3 vertices sage: S = ManifoldSubsetPullback(c_cart, P); S @@ -88,8 +91,10 @@ class ManifoldSubsetPullback(ManifoldSubset): Pulling back the interior of a polytope under a chart:: + sage: # needs sage.geometry.polyhedron sage: int_P = P.interior(); int_P - Relative interior of a 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 3 vertices + Relative interior of a + 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 3 vertices sage: int_S = ManifoldSubsetPullback(c_cart, int_P, name='int_S'); int_S Open subset int_S of the 2-dimensional topological manifold R^2 sage: M((0, 0)) in int_S @@ -100,9 +105,9 @@ class ManifoldSubsetPullback(ManifoldSubset): Using the embedding map of a submanifold:: sage: M = Manifold(3, 'M', structure="topological") - sage: N = Manifold(2, 'N', ambient=M, structure="topological") - sage: N - 2-dimensional topological submanifold N immersed in the 3-dimensional topological manifold M + sage: N = Manifold(2, 'N', ambient=M, structure="topological"); N + 2-dimensional topological submanifold N + immersed in the 3-dimensional topological manifold M sage: CM. = M.chart() sage: CN. = N.chart() sage: t = var('t') @@ -115,7 +120,9 @@ class ManifoldSubsetPullback(ManifoldSubset): sage: from sage.manifolds.subsets.pullback import ManifoldSubsetPullback sage: S = M.open_subset('S', coord_def={CM: z<1}) - sage: phi_without_t = N.continuous_map(M, {(CN, CM): [expr.subs(t=0) for expr in phi.expr()]}); phi_without_t + sage: phi_without_t = N.continuous_map(M, {(CN, CM): [expr.subs(t=0) + ....: for expr in phi.expr()]}) + sage: phi_without_t Continuous map from the 2-dimensional topological submanifold N embedded in the 3-dimensional topological manifold M @@ -123,7 +130,8 @@ class ManifoldSubsetPullback(ManifoldSubset): sage: phi_without_t.expr() (u, v, u^2 + v^2) sage: D = ManifoldSubsetPullback(phi_without_t, S); D - Subset f_inv_S of the 2-dimensional topological submanifold N embedded in the 3-dimensional topological manifold M + Subset f_inv_S of the 2-dimensional topological submanifold N + embedded in the 3-dimensional topological manifold M sage: N.point((2,0)) in D False @@ -136,6 +144,7 @@ def __classcall_private__(cls, map, codomain_subset, inverse=None, TESTS:: + sage: # needs sage.geometry.polyhedron sage: from sage.manifolds.subsets.pullback import ManifoldSubsetPullback sage: M = Manifold(2, 'R^2', structure='topological') sage: c_cart. = M.chart() # Cartesian coordinates on R^2 @@ -243,6 +252,7 @@ def _is_open(codomain_subset): Polyhedra:: + sage: # needs sage.geometry.polyhedron sage: Empty = Polyhedron(ambient_dim=2); Empty The empty polyhedron in ZZ^2 sage: ManifoldSubsetPullback._is_open(Empty) @@ -254,30 +264,32 @@ def _is_open(codomain_subset): Interiors of polyhedra:: - sage: int_C = C.interior(); int_C - Relative interior of a 3-dimensional polyhedron in ZZ^3 defined as the convex hull of 8 vertices - sage: ManifoldSubsetPullback._is_open(int_C) + sage: int_C = C.interior(); int_C # needs sage.geometry.polyhedron + Relative interior of a + 3-dimensional polyhedron in ZZ^3 defined as the convex hull of 8 vertices + sage: ManifoldSubsetPullback._is_open(int_C) # needs sage.geometry.polyhedron True PPL polyhedra and not-necessarily-closed polyhedra:: - sage: from ppl import Variable, C_Polyhedron, NNC_Polyhedron, Constraint_System # optional - pplpy - sage: u = Variable(0) # optional - pplpy - sage: v = Variable(1) # optional - pplpy - sage: CS = Constraint_System() # optional - pplpy - sage: CS.insert(0 < u) # optional - pplpy - sage: CS.insert(u < 1) # optional - pplpy - sage: CS.insert(0 < v) # optional - pplpy - sage: CS.insert(v < 1) # optional - pplpy - sage: CS.insert(u + v <= 3) # redundant inequality # optional - pplpy - sage: P = NNC_Polyhedron(CS); P # optional - pplpy + sage: # needs pplpy + sage: from ppl import Variable, C_Polyhedron, NNC_Polyhedron, Constraint_System + sage: u = Variable(0) + sage: v = Variable(1) + sage: CS = Constraint_System() + sage: CS.insert(0 < u) + sage: CS.insert(u < 1) + sage: CS.insert(0 < v) + sage: CS.insert(v < 1) + sage: CS.insert(u + v <= 3) # redundant inequality + sage: P = NNC_Polyhedron(CS); P A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 1 point, 4 closure_points - sage: ManifoldSubsetPullback._is_open(P) # optional - pplpy + sage: ManifoldSubsetPullback._is_open(P) True - sage: CS.insert(u + v <= 1) # optional - pplpy - sage: T = NNC_Polyhedron(CS); T # optional - pplpy + sage: CS.insert(u + v <= 1) + sage: T = NNC_Polyhedron(CS); T A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 1 point, 3 closure_points - sage: ManifoldSubsetPullback._is_open(T) # optional - pplpy + sage: ManifoldSubsetPullback._is_open(T) False """ @@ -454,10 +466,10 @@ def _polyhedron_restriction(expr, polyhedron, relint=False): sage: _polyhedron_restriction = ManifoldSubsetPullback._polyhedron_restriction sage: var('x y z') (x, y, z) - sage: c = polytopes.cube() - sage: _polyhedron_restriction((x, y, z), c) + sage: c = polytopes.cube() # needs sage.geometry.polyhedron + sage: _polyhedron_restriction((x, y, z), c) # needs sage.geometry.polyhedron [-x + 1 >= 0, -y + 1 >= 0, -z + 1 >= 0, x + 1 >= 0, z + 1 >= 0, y + 1 >= 0] - sage: _polyhedron_restriction((x, y, z), c, relint=True) + sage: _polyhedron_restriction((x, y, z), c, relint=True) # needs sage.geometry.polyhedron [-x + 1 > 0, -y + 1 > 0, -z + 1 > 0, x + 1 > 0, z + 1 > 0, y + 1 > 0] """ conjunction = [] @@ -510,16 +522,16 @@ def _coord_def(map, codomain_subset): Coordinate definition of an open chart polyhedron:: sage: c_cart. = M.chart() # Cartesian coordinates on R^2 - sage: P = Polyhedron(vertices=[[0, 0], [1, 2], [3, 4]]); P + sage: P = Polyhedron(vertices=[[0, 0], [1, 2], [3, 4]]); P # needs sage.geometry.polyhedron A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 3 vertices - sage: ri_P = P.relative_interior(); ri_P + sage: ri_P = P.relative_interior(); ri_P # needs sage.geometry.polyhedron Relative interior of a 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 3 vertices - sage: _coord_def(c_cart, ri_P) + sage: _coord_def(c_cart, ri_P) # needs sage.geometry.polyhedron {Chart (R^2, (x, y)): [2*x - y > 0, -4*x + 3*y > 0, x - y + 1 > 0]} Coordinate definition of the pullback of an open interval under a scalar field:: - sage: r_squared = M.scalar_field(x^2+y^2) + sage: r_squared = M.scalar_field(x^2 + y^2) sage: I = RealSet((1, 4)); I (1, 4) sage: _coord_def(r_squared, I) @@ -594,6 +606,7 @@ def _an_element_(self): EXAMPLES:: + sage: # needs sage.geometry.polyhedron sage: from sage.manifolds.subsets.pullback import ManifoldSubsetPullback sage: M = Manifold(3, 'R^3', structure='topological') sage: c_cart. = M.chart() # Cartesian coordinates on R^3 @@ -606,8 +619,10 @@ def _an_element_(self): sage: p.coordinates(c_cart) (0, 0, 0) + sage: # needs sage.geometry.polyhedron sage: Empty = Polyhedron(ambient_dim=3) - sage: McEmpty = ManifoldSubsetPullback(c_cart, Empty, name='McEmpty'); McEmpty + sage: McEmpty = ManifoldSubsetPullback(c_cart, Empty, name='McEmpty') + sage: McEmpty Subset McEmpty of the 3-dimensional topological manifold R^3 sage: McEmpty.an_element() Traceback (most recent call last): @@ -625,6 +640,7 @@ def some_elements(self): EXAMPLES:: + sage: # needs sage.geometry.polyhedron sage: from sage.manifolds.subsets.pullback import ManifoldSubsetPullback sage: M = Manifold(3, 'R^3', structure='topological') sage: c_cart. = M.chart() # Cartesian coordinates on R^3 @@ -647,8 +663,10 @@ def some_elements(self): (1, -1/4, 1/2), (0, -5/8, 3/4)] + sage: # needs sage.geometry.polyhedron sage: Empty = Polyhedron(ambient_dim=3) - sage: McEmpty = ManifoldSubsetPullback(c_cart, Empty, name='McEmpty'); McEmpty + sage: McEmpty = ManifoldSubsetPullback(c_cart, Empty, name='McEmpty') + sage: McEmpty Subset McEmpty of the 3-dimensional topological manifold R^3 sage: list(McEmpty.some_elements()) [] @@ -670,6 +688,7 @@ def __contains__(self, point): EXAMPLES:: + sage: # needs sage.geometry.polyhedron sage: from sage.manifolds.subsets.pullback import ManifoldSubsetPullback sage: M = Manifold(3, 'R^3', structure='topological') sage: c_cart. = M.chart() # Cartesian coordinates on R^3 @@ -722,6 +741,7 @@ def is_open(self): sage: M = Manifold(2, 'R^2', structure='topological') sage: c_cart. = M.chart() # Cartesian coordinates on R^2 + sage: # needs sage.geometry.polyhedron sage: P = Polyhedron(vertices=[[0, 0], [1, 2], [3, 4]]); P A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 3 vertices sage: P.is_open() @@ -756,6 +776,7 @@ def is_closed(self): The pullback of a (closed convex) polyhedron under a chart is closed:: + sage: # needs sage.geometry.polyhedron sage: P = Polyhedron(vertices=[[0, 0], [1, 2], [3, 4]]); P A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 3 vertices sage: McP = ManifoldSubsetPullback(c_cart, P, name='McP'); McP diff --git a/src/sage/manifolds/utilities.py b/src/sage/manifolds/utilities.py index 4b7c21532aa..c15a98ebbce 100644 --- a/src/sage/manifolds/utilities.py +++ b/src/sage/manifolds/utilities.py @@ -1270,6 +1270,7 @@ def set_axes_labels(graph, xlabel, ylabel, zlabel, **kwds): EXAMPLES:: + sage: # needs sage.plot sage: g = sphere() sage: g.all [Graphics3d Object] diff --git a/src/sage/matrix/action.pyx b/src/sage/matrix/action.pyx index 849163a511f..11e70f977bb 100644 --- a/src/sage/matrix/action.pyx +++ b/src/sage/matrix/action.pyx @@ -62,7 +62,7 @@ AUTHOR: import operator -from .matrix_space import MatrixSpace, is_MatrixSpace +from sage.matrix.matrix_space import MatrixSpace, is_MatrixSpace from sage.modules.free_module import FreeModule, is_FreeModule from sage.structure.coerce cimport coercion_model from sage.categories.homset import Hom, End diff --git a/src/sage/matrix/args.pyx b/src/sage/matrix/args.pyx index bdb6eb796dd..c389feb1bc2 100644 --- a/src/sage/matrix/args.pyx +++ b/src/sage/matrix/args.pyx @@ -871,6 +871,7 @@ cdef class MatrixArgs: Check github issue #36065: + sage: # needs sage.rings.number_field sage: class MyAlgebraicNumber(sage.rings.qqbar.AlgebraicNumber): ....: def __bool__(self): ....: raise ValueError @@ -982,7 +983,7 @@ cdef class MatrixArgs: if self.space is None: global MatrixSpace if MatrixSpace is None: - from .matrix_space import MatrixSpace + from sage.matrix.matrix_space import MatrixSpace self.space = MatrixSpace(self.base, self.nrows, self.ncols, sparse=self.sparse, **self.kwds) @@ -1113,7 +1114,7 @@ cdef class MatrixArgs: if not (e.flags.c_contiguous is True or e.flags.f_contiguous is True): raise TypeError('numpy matrix must be either c_contiguous or f_contiguous') - from .constructor import matrix + from sage.matrix.constructor import matrix from sage.rings.real_double import RDF from sage.rings.complex_double import CDF diff --git a/src/sage/matrix/change_ring.pyx b/src/sage/matrix/change_ring.pyx index c14d6540849..f942b753275 100644 --- a/src/sage/matrix/change_ring.pyx +++ b/src/sage/matrix/change_ring.pyx @@ -2,9 +2,9 @@ Functions for changing the base ring of matrices quickly """ -from .matrix_space import MatrixSpace -from .matrix_real_double_dense cimport Matrix_real_double_dense -from .matrix_integer_dense cimport Matrix_integer_dense +from sage.matrix.matrix_space import MatrixSpace +from sage.matrix.matrix_real_double_dense cimport Matrix_real_double_dense +from sage.matrix.matrix_integer_dense cimport Matrix_integer_dense from sage.rings.real_double import RDF diff --git a/src/sage/matrix/constructor.pyx b/src/sage/matrix/constructor.pyx index a31543e0795..073b815d6ae 100644 --- a/src/sage/matrix/constructor.pyx +++ b/src/sage/matrix/constructor.pyx @@ -14,7 +14,7 @@ General matrix Constructor and display options # http://www.gnu.org/licenses/ #***************************************************************************** -from .args cimport MatrixArgs +from sage.matrix.args cimport MatrixArgs from sage.structure.global_options import GlobalOptions @@ -580,7 +580,7 @@ def matrix(*args, **kwds): Check :trac:`24459`:: - sage: # needs sage.libs.flint + sage: # needs sage.libs.linbox sage: Matrix(ZZ, sys.maxsize, sys.maxsize) Traceback (most recent call last): ... @@ -654,7 +654,7 @@ def matrix(*args, **kwds): Matrix = matrix -from .special import * +from sage.matrix.special import * @matrix_method diff --git a/src/sage/matrix/matrix.pxd b/src/sage/matrix/matrix.pxd index 72ba0b09531..b67ed5b4969 100644 --- a/src/sage/matrix/matrix.pxd +++ b/src/sage/matrix/matrix.pxd @@ -1 +1 @@ -from .matrix2 cimport Matrix +from sage.matrix.matrix2 cimport Matrix diff --git a/src/sage/matrix/matrix0.pyx b/src/sage/matrix/matrix0.pyx index d7a0487e6cd..eb015dac31e 100644 --- a/src/sage/matrix/matrix0.pyx +++ b/src/sage/matrix/matrix0.pyx @@ -47,7 +47,7 @@ from sage.rings.integer_ring import is_IntegerRing import sage.modules.free_module -from .matrix_misc import row_iterator +from sage.matrix.matrix_misc import row_iterator _Fields = Fields() _IntegralDomains = IntegralDomains() @@ -543,11 +543,11 @@ cdef class Matrix(sage.structure.element.Matrix): TESTS:: - sage: class MyAlgebraicNumber(sage.rings.qqbar.AlgebraicNumber): # needs sage.rings.number_fields + sage: class MyAlgebraicNumber(sage.rings.qqbar.AlgebraicNumber): # needs sage.rings.number_field ....: def __bool__(self): ....: raise ValueError - sage: mat = matrix(1, 1, MyAlgebraicNumber(1)) # needs sage.rings.number_fields - sage: bool(mat) # needs sage.rings.number_fields + sage: mat = matrix(1, 1, MyAlgebraicNumber(1)) # needs sage.rings.number_field + sage: bool(mat) # needs sage.rings.number_field Traceback (most recent call last): ... ValueError @@ -1750,7 +1750,7 @@ cdef class Matrix(sage.structure.element.Matrix): 100 x 100 dense matrix over Integer Ring] """ - from .constructor import options + from sage.matrix.constructor import options if self._nrows <= options.max_rows() and self._ncols <= options.max_cols(): return self.str() if self.is_sparse(): @@ -2051,7 +2051,7 @@ cdef class Matrix(sage.structure.element.Matrix): # only use floating point formatting for inexact types that have # custom implementation of __format__ - from .constructor import options + from sage.matrix.constructor import options prec = options.precision() if prec is None or callable(rep_mapping) or not entries \ or type(entries[0]).__format__ is Element.__format__ \ @@ -2135,7 +2135,7 @@ cdef class Matrix(sage.structure.element.Matrix): -0.35104242112828943 0.5084492941557279] -0.9541798283979341 -0.8948790563276592] """ - from .constructor import options + from sage.matrix.constructor import options if self._nrows <= options.max_rows() and self._ncols <= options.max_cols(): return self.str(character_art=True) else: @@ -2164,7 +2164,7 @@ cdef class Matrix(sage.structure.element.Matrix): sage: unicode_art(A) 100 x 100 dense matrix over Integer Ring """ - from .constructor import options + from sage.matrix.constructor import options if self._nrows <= options.max_rows() and self._ncols <= options.max_cols(): return self.str(unicode=True, character_art=True) else: @@ -2375,7 +2375,7 @@ cdef class Matrix(sage.structure.element.Matrix): [ 5 25] [125 625] """ - from .constructor import matrix + from sage.matrix.constructor import matrix return matrix(self.nrows(), self.ncols(), [e(*args, **kwargs) for e in self.list()]) ################################################### @@ -3850,7 +3850,7 @@ cdef class Matrix(sage.structure.element.Matrix): raise ValueError("length of v must be at most the number of rows of self") if not self._nrows: return self.parent().row_space().zero_vector() - from .constructor import matrix + from sage.matrix.constructor import matrix v = matrix(list(v)+[0]*(self._nrows-len(v))) return (v * self)[0] @@ -3927,7 +3927,7 @@ cdef class Matrix(sage.structure.element.Matrix): raise ValueError("length of v must be at most the number of columns of self") if not self._ncols: return self.parent().column_space().zero_vector() - from .constructor import matrix + from sage.matrix.constructor import matrix v = matrix(self._ncols, 1, list(v)+[0]*(self._ncols-len(v))) return (self * v).column(0) @@ -4898,7 +4898,7 @@ cdef class Matrix(sage.structure.element.Matrix): Over finite fields:: sage: A = matrix(GF(59), 3, [10,56,39,53,56,33,58,24,55]) - sage: A.multiplicative_order() # needs sage.groups + sage: A.multiplicative_order() # needs sage.libs.pari 580 sage: (A^580).is_one() True @@ -4918,7 +4918,7 @@ cdef class Matrix(sage.structure.element.Matrix): Over `\ZZ`:: sage: m = matrix(ZZ, 2, 2, [-1,1,-1,0]) - sage: m.multiplicative_order() # needs sage.groups + sage: m.multiplicative_order() # needs sage.libs.pari 3 sage: m = posets.ChainPoset(6).coxeter_transformation() # needs sage.combinat sage.graphs @@ -4930,10 +4930,10 @@ cdef class Matrix(sage.structure.element.Matrix): 10 sage: M = matrix(ZZ, 2, 2, [1, 1, 0, 1]) - sage: M.multiplicative_order() # needs sage.groups + sage: M.multiplicative_order() # needs sage.libs.pari +Infinity - sage: for k in range(600): # needs sage.groups + sage: for k in range(600): # needs sage.groups sage.modular ....: m = SL2Z.random_element() ....: o = m.multiplicative_order() ....: if o != Infinity and m**o != SL2Z.one(): @@ -4948,7 +4948,7 @@ cdef class Matrix(sage.structure.element.Matrix): ....: else: ....: return ZZ.random_element(-100,100) sage: rnd = matrix(ZZ, 8, 8, val) - sage: (rnd * m24 * rnd.inverse_of_unit()).multiplicative_order() # needs sage.groups + sage: (rnd * m24 * rnd.inverse_of_unit()).multiplicative_order() # needs sage.libs.pari 24 TESTS:: @@ -5827,9 +5827,9 @@ cdef class Matrix(sage.structure.element.Matrix): Tests for :trac:`28570`:: - sage: P = posets.TamariLattice(7) # needs sage.combinat sage.graphs - sage: M = P._hasse_diagram._leq_matrix # needs sage.combinat sage.graphs - sage: M.inverse_of_unit() # this was very slow, now 1s # needs sage.combinat sage.graphs + sage: P = posets.TamariLattice(7) # needs sage.graphs + sage: M = P._hasse_diagram._leq_matrix # needs sage.graphs + sage: M.inverse_of_unit() # this was very slow, now 1s # needs sage.graphs 429 x 429 sparse matrix over Integer Ring... sage: m = matrix(Zmod(2**2), 1, 1, [1], sparse=True) @@ -6178,7 +6178,7 @@ def set_max_rows(n): """ from sage.misc.superseded import deprecation deprecation(30552, "'set_max_rows' is replaced by 'matrix.options.max_rows'") - from .constructor import options + from sage.matrix.constructor import options options.max_rows = n-1 def set_max_cols(n): @@ -6195,5 +6195,5 @@ def set_max_cols(n): """ from sage.misc.superseded import deprecation deprecation(30552, "'set_max_cols' is replaced by 'matrix.options.max_cols'") - from .constructor import options + from sage.matrix.constructor import options options.max_cols = n-1 diff --git a/src/sage/matrix/matrix1.pxd b/src/sage/matrix/matrix1.pxd index 666cd4e6240..e3585f9caab 100644 --- a/src/sage/matrix/matrix1.pxd +++ b/src/sage/matrix/matrix1.pxd @@ -1,4 +1,4 @@ -from .matrix0 cimport Matrix as Matrix0 +from sage.matrix.matrix0 cimport Matrix as Matrix0 cdef class Matrix(Matrix0): cdef _stack_impl(self, bottom) noexcept diff --git a/src/sage/matrix/matrix1.pyx b/src/sage/matrix/matrix1.pyx index 14a8538a535..1193b0a6ca0 100644 --- a/src/sage/matrix/matrix1.pyx +++ b/src/sage/matrix/matrix1.pyx @@ -103,7 +103,7 @@ cdef class Matrix(Matrix0): [ [ 0, 1, 2 ], [ 3, 4, 5 ], [ 6, 7, 8 ] ] sage: g.CharacteristicPolynomial() x_1^3-12*x_1^2-18*x_1 - sage: A.characteristic_polynomial() + sage: A.characteristic_polynomial() # needs sage.libs.pari x^3 - 12*x^2 - 18*x sage: matrix(QQ, g) == A True diff --git a/src/sage/matrix/matrix2.pxd b/src/sage/matrix/matrix2.pxd index ad5bf85df04..1fd85c5f082 100644 --- a/src/sage/matrix/matrix2.pxd +++ b/src/sage/matrix/matrix2.pxd @@ -12,7 +12,7 @@ Generic matrices # http://www.gnu.org/licenses/ #***************************************************************************** -from .matrix1 cimport Matrix as Matrix1 +from sage.matrix.matrix1 cimport Matrix as Matrix1 cdef class Matrix(Matrix1): cdef _det_by_minors(self, Py_ssize_t level) noexcept diff --git a/src/sage/matrix/matrix2.pyx b/src/sage/matrix/matrix2.pyx index 8af0889927f..4acd46db4de 100644 --- a/src/sage/matrix/matrix2.pyx +++ b/src/sage/matrix/matrix2.pyx @@ -99,7 +99,7 @@ from sage.arith.numerical_approx cimport digits_to_bits from copy import copy import sage.modules.free_module -from . import berlekamp_massey +from sage.matrix import berlekamp_massey from sage.modules.free_module_element import is_FreeModuleElement from sage.matrix.matrix_misc import permanental_minor_polynomial @@ -304,32 +304,34 @@ cdef class Matrix(Matrix1): [ 7.6 2.3 1.0] [ 1.0 2.0 -1.0] sage: b = vector(RDF,[1,2,3]) - sage: x = A.solve_left(b); x.zero_at(2e-17) # fix noisy zeroes + sage: x = A.solve_left(b); x.zero_at(2e-17) # fix noisy zeroes # needs scipy (0.666666666..., 0.0, 0.333333333...) - sage: x.parent() + sage: x.parent() # needs scipy Vector space of dimension 3 over Real Double Field - sage: x*A # tol 1e-14 + sage: x*A # tol 1e-14 # needs scipy (0.9999999999999999, 1.9999999999999998, 3.0) Over the complex numbers:: + sage: # needs sage.rings.complex_double sage.symbolic sage: A = matrix(CDF, [[ 0, -1 + 2*I, 1 - 3*I, I], ....: [2 + 4*I, -2 + 3*I, -1 + 2*I, -1 - I], ....: [ 2 + I, 1 - I, -1, 5], ....: [ 3*I, -1 - I, -1 + I, -3 + I]]) sage: b = vector(CDF, [2 -3*I, 3, -2 + 3*I, 8]) - sage: x = A.solve_left(b); x - (-1.55765124... - 0.644483985...*I, 0.183274021... + 0.286476868...*I, 0.270818505... + 0.246619217...*I, -1.69003558... - 0.828113879...*I) - sage: x.parent() + sage: x = A.solve_left(b); x # needs scipy + (-1.55765124... - 0.644483985...*I, 0.183274021... + 0.286476868...*I, + 0.270818505... + 0.246619217...*I, -1.69003558... - 0.828113879...*I) + sage: x.parent() # needs scipy Vector space of dimension 4 over Complex Double Field - sage: abs(x*A - b) < 1e-14 + sage: abs(x*A - b) < 1e-14 # needs scipy True If ``b`` is given as a matrix, the result will be a matrix, as well:: sage: A = matrix(RDF, 3, 3, [2, 5, 0, 7, 7, -2, -4.3, 0, 1]) sage: b = matrix(RDF, 2, 3, [2, -4, -5, 1, 1, 0.1]) - sage: A.solve_left(b) # tol 1e-14 + sage: A.solve_left(b) # tol 1e-14 # needs scipy [ -6.495454545454545 4.068181818181818 3.1363636363636354] [ 0.5277272727272727 -0.2340909090909091 -0.36818181818181817] @@ -339,16 +341,16 @@ cdef class Matrix(Matrix1): sage: A = matrix(RDF, 3, 2, [1, 3, 4, 2, 0, -3]) sage: b = vector(RDF, [5, 6]) - sage: x = A.solve_left(b) - sage: (x * A - b).norm() < 1e-14 + sage: x = A.solve_left(b) # needs scipy + sage: (x * A - b).norm() < 1e-14 # needs scipy True For a wide matrix `A`, the error is usually not small:: sage: A = matrix(RDF, 2, 3, [1, 3, 4, 2, 0, -3]) sage: b = vector(RDF, [5, 6, 1]) - sage: x = A.solve_left(b) - sage: (x * A - b).norm() # tol 1e-14 + sage: x = A.solve_left(b) # needs scipy + sage: (x * A - b).norm() # tol 1e-14 # needs scipy 0.9723055853282466 TESTS:: @@ -380,7 +382,7 @@ cdef class Matrix(Matrix1): A degenerate case:: sage: A = matrix(RDF, 0, 0, []) - sage: A.solve_left(vector(RDF,[])) + sage: A.solve_left(vector(RDF,[])) # needs scipy () Over an inexact ring like ``RDF``, the coefficient matrix of a @@ -388,7 +390,7 @@ cdef class Matrix(Matrix1): sage: A = matrix(RDF, 5, range(25)) sage: b = vector(RDF, [1,2,3,4,5]) - sage: A.solve_left(b) + sage: A.solve_left(b) # needs scipy Traceback (most recent call last): ... LinAlgError: Matrix is singular. @@ -397,7 +399,7 @@ cdef class Matrix(Matrix1): sage: A = matrix(RDF, 5, range(25)) sage: b = vector(RDF, [1,2,3,4]) - sage: A.solve_left(b) + sage: A.solve_left(b) # needs scipy Traceback (most recent call last): ... ValueError: number of columns of self must equal degree of @@ -416,12 +418,13 @@ cdef class Matrix(Matrix1): Check that coercions work correctly (:trac:`17405`):: + sage: # needs sage.rings.complex_double sage.symbolic sage: A = matrix(RDF, 2, range(4)) sage: b = vector(CDF, [1+I, 2]) - sage: A.solve_left(b) + sage: A.solve_left(b) # needs scipy (0.5 - 1.5*I, 0.5 + 0.5*I) sage: b = vector(QQ[I], [1+I, 2]) - sage: x = A.solve_left(b) + sage: x = A.solve_left(b) # needs scipy Over the inexact ring ``SR``, we can still verify the solution if all of the elements involved were exact to begin with; if @@ -435,7 +438,6 @@ cdef class Matrix(Matrix1): ... ValueError: matrix equation has no solutions - In this case, turning off the ``check`` leads to a wrong result:: sage: A.solve_left(b, check=False) # needs sage.symbolic @@ -673,9 +675,9 @@ cdef class Matrix(Matrix1): sage: A = matrix(RDF, 3, 2, [1, 3, 4, 2, 0, -3]) sage: b = vector(RDF, [5, 6, 1]) - sage: A.solve_right(b) # tol 1e-14 + sage: A.solve_right(b) # tol 1e-14 # needs scipy (1.4782608695652177, 0.35177865612648235) - sage: ~(A.T * A) * A.T * b # closed form solution, tol 1e-14 + sage: ~(A.T * A) * A.T * b # closed form solution, tol 1e-14 # needs scipy (1.4782608695652177, 0.35177865612648235) Over the reals:: @@ -684,33 +686,35 @@ cdef class Matrix(Matrix1): [ 1.0 2.0 5.0] [ 7.6 2.3 1.0] [ 1.0 2.0 -1.0] - sage: b = vector(RDF,[1,2,3]) - sage: x = A.solve_right(b); x # tol 1e-14 + sage: b = vector(RDF, [1,2,3]) + sage: x = A.solve_right(b); x # tol 1e-14 # needs scipy (-0.1136950904392765, 1.3901808785529717, -0.33333333333333337) - sage: x.parent() + sage: x.parent() # needs scipy Vector space of dimension 3 over Real Double Field - sage: A*x # tol 1e-14 + sage: A*x # tol 1e-14 # needs scipy (1.0, 1.9999999999999996, 3.0000000000000004) Over the complex numbers:: + sage: # needs sage.rings.complex_double sage.symbolic sage: A = matrix(CDF, [[ 0, -1 + 2*I, 1 - 3*I, I], ....: [2 + 4*I, -2 + 3*I, -1 + 2*I, -1 - I], ....: [ 2 + I, 1 - I, -1, 5], ....: [ 3*I, -1 - I, -1 + I, -3 + I]]) - sage: b = vector(CDF, [2 -3*I, 3, -2 + 3*I, 8]) - sage: x = A.solve_right(b); x - (1.96841637... - 1.07606761...*I, -0.614323843... + 1.68416370...*I, 0.0733985765... + 1.73487544...*I, -1.6018683... + 0.524021352...*I) - sage: x.parent() + sage: b = vector(CDF, [2 - 3*I, 3, -2 + 3*I, 8]) + sage: x = A.solve_right(b); x # needs scipy + (1.96841637... - 1.07606761...*I, -0.614323843... + 1.68416370...*I, + 0.0733985765... + 1.73487544...*I, -1.6018683... + 0.524021352...*I) + sage: x.parent() # needs scipy Vector space of dimension 4 over Complex Double Field - sage: abs(A*x - b) < 1e-14 + sage: abs(A*x - b) < 1e-14 # needs scipy True If ``b`` is given as a matrix, the result will be a matrix, as well:: sage: A = matrix(RDF, 3, 3, [1, 2, 2, 3, 4, 5, 2, 2, 2]) sage: b = matrix(RDF, 3, 2, [3, 2, 3, 2, 3, 2]) - sage: A.solve_right(b) # tol 1e-14 + sage: A.solve_right(b) # tol 1e-14 # needs scipy [ 0.0 0.0] [ 4.5 3.0] [-3.0 -2.0] @@ -721,16 +725,16 @@ cdef class Matrix(Matrix1): sage: A = matrix(RDF, 2, 3, [1, 3, 4, 2, 0, -3]) sage: b = vector(RDF, [5, 6]) - sage: x = A.solve_right(b) - sage: (A * x - b).norm() < 1e-14 + sage: x = A.solve_right(b) # needs scipy + sage: (A * x - b).norm() < 1e-14 # needs scipy True For a tall matrix `A`, the error is usually not small:: sage: A = matrix(RDF, 3, 2, [1, 3, 4, 2, 0, -3]) sage: b = vector(RDF, [5, 6, 1]) - sage: x = A.solve_right(b) - sage: (A * x - b).norm() # tol 1e-14 + sage: x = A.solve_right(b) # needs scipy + sage: (A * x - b).norm() # tol 1e-14 # needs scipy 3.2692119900020438 TESTS: @@ -740,8 +744,9 @@ cdef class Matrix(Matrix1): sage: A = matrix(QQ, 2, [1, 2, 3, 4]) sage: b = vector(RDF, [pi, e]) # needs sage.symbolic - sage: A.solve_right(b) # tol 1e-15 # needs sage.symbolic + sage: A.solve_right(b) # tol 1e-15 # needs scipy sage.symbolic (-3.564903478720541, 3.353248066155167) + sage: R. = ZZ[] sage: b = vector(R, [1, t]) sage: x = A.solve_right(b); x @@ -805,6 +810,7 @@ cdef class Matrix(Matrix1): Check that coercions work correctly (:trac:`17405`):: + sage: # needs sage.rings.complex_double sage.symbolic sage: A = matrix(RDF, 2, range(4)) sage: b = vector(CDF, [1+I, 2]) sage: A.solve_right(b) @@ -1542,8 +1548,8 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: M = diagonal_matrix(CDF, [0, I, 1+I]) - sage: M + sage: # needs sage.rings.complex_double sage.symbolic + sage: M = diagonal_matrix(CDF, [0, I, 1+I]); M [ 0.0 0.0 0.0] [ 0.0 1.0*I 0.0] [ 0.0 0.0 1.0 + 1.0*I] @@ -1569,11 +1575,11 @@ cdef class Matrix(Matrix1): Beware that the ``exact`` algorithm is not numerically stable, but the default ``numpy`` algorithm is:: - sage: M = matrix.hilbert(12,ring=RR) - sage: (~M*M).norm() # a considerable error + sage: M = matrix.hilbert(12, ring=RR) + sage: (~M * M).norm() # a considerable error # needs scipy 1.3... sage: Mx = M.pseudoinverse(algorithm="exact") - sage: (Mx*M).norm() # huge error + sage: (Mx * M).norm() # huge error # needs scipy 11.5... sage: Mx = M.pseudoinverse(algorithm="numpy") # needs numpy sage: (Mx * M).norm() # still OK @@ -1765,7 +1771,7 @@ cdef class Matrix(Matrix1): [1, 8, 20, 16, 4] sage: A.rook_vector(algorithm="Ryser") [1, 8, 20, 16, 4] - sage: A.rook_vector(algorithm="Godsil") # needs sage.graphs + sage: A.rook_vector(algorithm="Godsil") # needs sage.graphs sage.libs.flint [1, 8, 20, 16, 4] When the matrix `A` has more ones then zeroes it is usually faster @@ -1805,17 +1811,17 @@ cdef class Matrix(Matrix1): [1, 0, 0] sage: matrix([[0,0],[0,0]]).rook_vector(algorithm="Ryser") [1, 0, 0] - sage: matrix([[0,0],[0,0]]).rook_vector(algorithm="Godsil") # needs sage.graphs + sage: matrix([[0,0],[0,0]]).rook_vector(algorithm="Godsil") # needs sage.graphs sage.libs.flint [1, 0, 0] sage: matrix.ones(4, 2).rook_vector("Ryser") [1, 8, 12] - sage: matrix.ones(4, 2).rook_vector("Godsil") # needs sage.graphs + sage: matrix.ones(4, 2).rook_vector("Godsil") # needs sage.graphs sage.libs.flint [1, 8, 12] sage: m = matrix(ZZ,4,5) sage: m[:4,:4] = identity_matrix(4) sage: algos = ["Ryser", "ButeraPernici"] sage: algos += ["Godsil"] - sage: for algorithm in algos: # needs sage.graphs + sage: for algorithm in algos: # needs sage.graphs sage.libs.flint ....: v = m.rook_vector(complement=True, use_complement=True, algorithm=algorithm) ....: if v != [1, 16, 78, 128, 53]: ....: print("ERROR with algorithm={} use_complement=True".format(algorithm)) @@ -2062,17 +2068,18 @@ cdef class Matrix(Matrix1): We verify that :trac:`10063` is resolved:: + sage: # needs sage.libs.singular sage: A = GF(2)['x,y,z'] sage: A.inject_variables() Defining x, y, z - sage: R = A.quotient(x^2 + 1).quotient(y^2 + 1).quotient(z^2 + 1) # needs sage.rings.finite_rings - sage: R.inject_variables() # needs sage.rings.finite_rings + sage: R = A.quotient(x^2 + 1).quotient(y^2 + 1).quotient(z^2 + 1) + sage: R.inject_variables() Defining xbarbarbar, ybarbarbar, zbarbarbar - sage: M = matrix([[1, 1, 1, 1], # needs sage.rings.finite_rings + sage: M = matrix([[1, 1, 1, 1], ....: [xbarbarbar, ybarbarbar, 1, 1], ....: [0, 1, zbarbarbar, 1], ....: [xbarbarbar, zbarbarbar, 1, 1]]) - sage: M.determinant() # needs sage.rings.finite_rings + sage: M.determinant() xbarbarbar*ybarbarbar*zbarbarbar + xbarbarbar*ybarbarbar + xbarbarbar*zbarbarbar + ybarbarbar*zbarbarbar + xbarbarbar + ybarbarbar + zbarbarbar + 1 @@ -2137,10 +2144,15 @@ cdef class Matrix(Matrix1): # word, use PARI. ch = R.characteristic() if ch.is_prime() and ch < (2*sys.maxsize): - d = R(self.__pari__().matdet()) - else: - # Lift to ZZ and compute there. - d = R(self.apply_map(lambda x : x.lift_centered()).det()) + try: + d = R(self.__pari__().matdet()) + except ImportError: + pass + else: + self.cache('det', d) + return d + # Lift to ZZ and compute there. + d = R(self.apply_map(lambda x: x.lift_centered()).det()) self.cache('det', d) return d @@ -2448,7 +2460,7 @@ cdef class Matrix(Matrix1): In that case, the definition by perfect matchings is used instead:: - sage: A.pfaffian() # needs sage.combinat sage.rings.finite_rings + sage: A.pfaffian() # needs sage.combinat 2 """ @@ -3014,10 +3026,10 @@ cdef class Matrix(Matrix1): ``S`` in the following example is an integral domain. But the computation of the characteristic polynomial succeeds as follows:: + sage: # needs sage.libs.singular sage: R. = QQ[] sage: S. = R.quo((b^3)) - sage: A = matrix(S, [[x*y^2, 2*x], [2, x^10*y]]) - sage: A + sage: A = matrix(S, [[x*y^2, 2*x], [2, x^10*y]]); A [ x*y^2 2*x] [ 2 x^10*y] sage: A.charpoly('T') @@ -4197,7 +4209,7 @@ cdef class Matrix(Matrix1): [1 0 0 0 0 1] sage: A*DP.transpose() == zero_matrix(GF(2), 3, 4) True - sage: A.right_kernel_matrix(algorithm='pluq', basis='echelon') + sage: A.right_kernel_matrix(algorithm='pluq', basis='echelon') # needs sage.libs.m4ri [1 0 0 0 0 1] [0 1 1 0 0 0] [0 0 0 1 0 0] @@ -4455,7 +4467,8 @@ cdef class Matrix(Matrix1): sage: A.right_kernel_matrix() Traceback (most recent call last): ... - NotImplementedError: Cannot compute a matrix kernel over Quaternion Algebra (-1, -1) with base ring Rational Field + NotImplementedError: Cannot compute a matrix kernel over + Quaternion Algebra (-1, -1) with base ring Rational Field We test error messages for improper choices of the 'algorithm' keyword. :: @@ -4467,15 +4480,18 @@ cdef class Matrix(Matrix1): sage: matrix(GF(2), 2, 2).right_kernel_matrix(algorithm='padic') Traceback (most recent call last): ... - ValueError: 'padic' matrix kernel algorithm only available over the rationals and the integers, not over Finite Field of size 2 + ValueError: 'padic' matrix kernel algorithm only available over + the rationals and the integers, not over Finite Field of size 2 sage: matrix(QQ, 2, 2).right_kernel_matrix(algorithm='pari') Traceback (most recent call last): ... - ValueError: 'pari' matrix kernel algorithm only available over non-trivial number fields and the integers, not over Rational Field - sage: matrix(QQ, 2, 2).right_kernel_matrix(algorithm='pluq') + ValueError: 'pari' matrix kernel algorithm only available over + non-trivial number fields and the integers, not over Rational Field + sage: matrix(QQ, 2, 2).right_kernel_matrix(algorithm='pluq') # needs sage.libs.m4ri Traceback (most recent call last): ... - ValueError: 'pluq' matrix kernel algorithm only available over integers mod 2, not over Rational Field + ValueError: 'pluq' matrix kernel algorithm only available over + integers mod 2, not over Rational Field We test error messages for improper basis format requests. :: @@ -4490,7 +4506,8 @@ cdef class Matrix(Matrix1): sage: matrix(QQ, 2, 2).right_kernel_matrix(basis='LLL') Traceback (most recent call last): ... - ValueError: LLL-reduced basis only available over the integers, not over Rational Field + ValueError: LLL-reduced basis only available over the integers, + not over Rational Field Finally, error messages for the 'proof' keyword. :: @@ -5435,8 +5452,10 @@ cdef class Matrix(Matrix1): [1 0 0] [0 1 0] [0 0 1] - sage: W = MatrixSpace(CC,2,2) - sage: B = W([1, 2+3*I,4+5*I,9]); B + + sage: # needs sage.rings.real_mpfr sage.symbolic + sage: W = MatrixSpace(CC, 2, 2) + sage: B = W([1, 2 + 3*I, 4 + 5*I, 9]); B [ 1.00000000000000 2.00000000000000 + 3.00000000000000*I] [4.00000000000000 + 5.00000000000000*I 9.00000000000000] sage: B.column_space() @@ -6092,7 +6111,7 @@ cdef class Matrix(Matrix1): sage: A._eigenspace_format(None) == 'all' # needs sage.rings.number_field True sage: B = matrix(GF(13), 2, range(4)) - sage: B._eigenspace_format(None) # needs sage.rings.finite_rings + sage: B._eigenspace_format(None) 'all' Subrings are promoted to fraction fields and then checked for the @@ -6345,6 +6364,7 @@ cdef class Matrix(Matrix1): NotImplementedError: eigenspaces cannot be computed reliably for inexact rings such as Real Field with 53 bits of precision, consult numerical or symbolic matrix classes for other options + sage: # needs scipy sage: em = A.change_ring(RDF).eigenmatrix_left() sage: eigenvalues = em[0]; eigenvalues.dense_matrix() # abs tol 1e-13 [13.348469228349522 0.0 0.0] @@ -6373,12 +6393,12 @@ cdef class Matrix(Matrix1): sage: # needs sage.rings.finite_rings sage: F. = FiniteField(11^2) sage: A = matrix(F, [[b + 1, b + 1], [10*b + 4, 5*b + 4]]) - sage: A.eigenspaces_left(format='all') + sage: A.eigenspaces_left(format='all') # needs sage.rings.number_field Traceback (most recent call last): ... NotImplementedError: unable to construct eigenspaces for eigenvalues outside the base field, try the keyword option: format='galois' - sage: A.eigenspaces_left(format='galois') + sage: A.eigenspaces_left(format='galois') # needs sage.rings.number_field [ (a0, Vector space of degree 2 and dimension 1 over Univariate Quotient Polynomial Ring in a0 over @@ -6626,6 +6646,7 @@ cdef class Matrix(Matrix1): for inexact rings such as Real Field with 53 bits of precision, consult numerical or symbolic matrix classes for other options + sage: # needs scipy sage: em = B.change_ring(RDF).eigenmatrix_right() sage: eigenvalues = em[0]; eigenvalues.dense_matrix() # abs tol 1e-13 [13.348469228349522 0.0 0.0] @@ -6771,7 +6792,7 @@ cdef class Matrix(Matrix1): sage: M = matrix(QQ, [[0,-1,0], [1,0,0], [0,0,2]]) sage: M.eigenvalues() # needs sage.rings.number_field [2, -1*I, 1*I] - sage: M.eigenvalues(extend=False) # needs sage.rings.number_field + sage: M.eigenvalues(extend=False) # needs sage.libs.pari [2] The method also works for matrices over finite fields:: @@ -7111,6 +7132,7 @@ cdef class Matrix(Matrix1): A generalized eigenvector decomposition:: + sage: # needs scipy sage: A = matrix(RDF, [[1, -2], [3, 4]]) sage: B = matrix(RDF, [[0, 7], [2, -3]]) sage: D, P = A.eigenmatrix_left(B) @@ -7119,23 +7141,25 @@ cdef class Matrix(Matrix1): The matrix `B` in a generalized eigenvalue problem may be singular:: + sage: # needs scipy sage.rings.complex_double sage.symbolic sage: A = matrix.identity(CDF, 2) sage: B = matrix(CDF, [[2, 1+I], [4, 2+2*I]]) sage: D, P = A.eigenmatrix_left(B) - sage: D.diagonal() # tol 1e-14 # needs sage.symbolic + sage: D.diagonal() # tol 1e-14 [0.2 - 0.1*I, +infinity] In this case, we can still verify the eigenvector equation for the first eigenvalue and first eigenvector:: - sage: l = D[0, 0] # needs sage.symbolic + sage: # needs scipy sage.rings.complex_double sage.symbolic + sage: l = D[0, 0] sage: v = P[0, :] - sage: (v * A - l * v * B).norm() < 1e-14 # needs sage.symbolic + sage: (v * A - l * v * B).norm() < 1e-14 True The second eigenvector is contained in the left kernel of `B`:: - sage: (P[1, :] * B).norm() < 1e-14 + sage: (P[1, :] * B).norm() < 1e-14 # needs scipy sage.rings.complex_double sage.symbolic True .. SEEALSO:: @@ -7170,6 +7194,7 @@ cdef class Matrix(Matrix1): The following example shows that :trac:`20439` has been resolved:: + sage: # needs sage.rings.complex_double sage.symbolic sage: A = matrix(CDF, [[-2.53634347567, 2.04801738686, -0.0, -62.166145304], ....: [ 0.7, -0.6, 0.0, 0.0], ....: [0.547271128842, 0.0, -0.3015, -21.7532081652], @@ -7181,6 +7206,7 @@ cdef class Matrix(Matrix1): The following example shows that the fix for :trac:`20439` (conjugating eigenvectors rather than eigenvalues) is the correct one:: + sage: # needs sage.rings.complex_double sage.symbolic sage: A = Matrix(CDF,[[I,0],[0,1]]) sage: D, P = A.eigenmatrix_left() sage: (P*A - D*P).norm() < 10^(-2) @@ -7212,6 +7238,7 @@ cdef class Matrix(Matrix1): The following example shows that :trac:`12595` has been resolved:: + sage: # needs sage.rings.complex_double sage: m = Matrix(CDF, 8, [[-1, -1, -1, -1, 1, -3, -1, -1], ....: [1, 1, 1, 1, -1, -1, 1, -3], ....: [-1, 3, -1, -1, 1, 1, -1, -1], @@ -7332,6 +7359,7 @@ cdef class Matrix(Matrix1): A generalized eigenvector decomposition:: + sage: # needs scipy sage: A = matrix(RDF, [[1, -2], [3, 4]]) sage: B = matrix(RDF, [[0, 7], [2, -3]]) sage: D, P = A.eigenmatrix_right(B) @@ -7340,6 +7368,7 @@ cdef class Matrix(Matrix1): The matrix `B` in a generalized eigenvalue problem may be singular:: + sage: # needs scipy sage: A = matrix.identity(RDF, 2) sage: B = matrix(RDF, [[3, 5], [6, 10]]) sage: D, P = A.eigenmatrix_right(B); D # tol 1e-14 @@ -7349,14 +7378,15 @@ cdef class Matrix(Matrix1): In this case, we can still verify the eigenvector equation for the first eigenvalue and first eigenvector:: - sage: l = D[0, 0] # needs sage.symbolic + sage: # needs scipy + sage: l = D[0, 0] sage: v = P[:, 0] - sage: (A * v - B * v * l).norm() < 1e-14 # needs sage.symbolic + sage: (A * v - B * v * l).norm() < 1e-14 True The second eigenvector is contained in the right kernel of `B`:: - sage: (B * P[:, 1]).norm() < 1e-14 + sage: (B * P[:, 1]).norm() < 1e-14 # needs scipy True .. SEEALSO:: @@ -7374,6 +7404,7 @@ cdef class Matrix(Matrix1): Running this test independently, without adjusting the eigenvectors could indicate this situation on your hardware. :: + sage: # needs scipy sage: B = matrix(QQ, 3, 3, range(9)) sage: em = B.change_ring(RDF).eigenmatrix_right() sage: evalues = em[0]; evalues.dense_matrix() # abs tol 1e-13 @@ -7391,6 +7422,7 @@ cdef class Matrix(Matrix1): The following example shows that :trac:`20439` has been resolved:: + sage: # needs scipy sage.rings.complex_double sage: A = matrix(CDF, [[-2.53634347567, 2.04801738686, -0.0, -62.166145304], ....: [ 0.7, -0.6, 0.0, 0.0], ....: [0.547271128842, 0.0, -0.3015, -21.7532081652], @@ -7402,6 +7434,7 @@ cdef class Matrix(Matrix1): The following example shows that the fix for :trac:`20439` (conjugating eigenvectors rather than eigenvalues) is the correct one:: + sage: # needs scipy sage.rings.complex_double sage.symbolic sage: A = Matrix(CDF,[[I,0],[0,1]]) sage: D, P = A.eigenmatrix_right() sage: (A*P - P*D).norm() < 10^(-2) @@ -7427,8 +7460,8 @@ cdef class Matrix(Matrix1): sage: M.eigenvalue_multiplicity(1) 0 - sage: M = posets.DiamondPoset(5).coxeter_transformation() # needs sage.graphs - sage: [M.eigenvalue_multiplicity(x) for x in [-1, 1]] # needs sage.graphs + sage: M = posets.DiamondPoset(5).coxeter_transformation() # needs sage.graphs sage.libs.flint + sage: [M.eigenvalue_multiplicity(x) for x in [-1, 1]] # needs sage.graphs sage.libs.flint [3, 2] TESTS:: @@ -8449,7 +8482,7 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: # needs sage.groups + sage: # needs sage.graphs sage.groups sage: M = matrix(ZZ,[[1,0],[1,0],[0,1]]); M [1 0] [1 0] @@ -8464,7 +8497,7 @@ cdef class Matrix(Matrix1): One can now apply these automorphisms to ``M`` to show that it leaves it invariant:: - sage: all(M.with_permuted_rows_and_columns(*i) == M for i in A) # needs sage.groups + sage: all(M.with_permuted_rows_and_columns(*i) == M for i in A) # needs sage.graphs sage.groups True Check that :trac:`25426` is fixed:: @@ -8474,7 +8507,7 @@ cdef class Matrix(Matrix1): ....: (1, 0, 3, 0, 2), ....: (0, 1, 0, 2, 1), ....: (0, 0, 2, 1, 2)]) - sage: j.automorphisms_of_rows_and_columns() # needs sage.groups + sage: j.automorphisms_of_rows_and_columns() # needs sage.graphs sage.groups [((), ()), ((1,3)(2,5), (1,3)(2,5))] """ from sage.groups.perm_gps.constructor import \ @@ -8542,15 +8575,27 @@ cdef class Matrix(Matrix1): TESTS:: + sage: # needs sage.graphs sage: M = matrix(ZZ, [[3, 4, 5], [3, 4, 5], [3, 5, 4], [2, 0,1]]) - sage: M.permutation_normal_form() # needs sage.graphs + sage: M.permutation_normal_form() [5 4 3] [5 4 3] [4 5 3] [1 0 2] + sage: M = matrix(ZZ, 0, 0, []) + sage: M.permutation_normal_form() + [] + sage: M.permutation_normal_form(check=True) + ([], ((), ())) """ nrows = self.nrows() ncols = self.ncols() + if not nrows or not ncols: + if not check: + return self + from sage.groups.perm_gps.permgroup_named import SymmetricGroup + return (self, (SymmetricGroup(nrows).one(), + SymmetricGroup(ncols).one())) # A helper def new_sorted_matrix(m): @@ -8699,15 +8744,13 @@ cdef class Matrix(Matrix1): Some examples that are not permutations of each other:: - sage: N = matrix(ZZ, [[1,2,3], [4,5,6], [7,8,9]]) - sage: N + sage: N = matrix(ZZ, [[1,2,3], [4,5,6], [7,8,9]]); N [1 2 3] [4 5 6] [7 8 9] sage: M.is_permutation_of(N) # needs sage.graphs False - sage: N = matrix(ZZ, [[1,2], [3,4]]) - sage: N + sage: N = matrix(ZZ, [[1,2], [3,4]]); N [1 2] [3 4] sage: M.is_permutation_of(N) @@ -8715,9 +8758,8 @@ cdef class Matrix(Matrix1): And for when ``check`` is True:: - sage: # needs sage.graphs - sage: N = matrix(ZZ, [[3,5,3], [2,6,4], [1,2,3]]) - sage: N + sage: # needs sage.graphs sage.groups + sage: N = matrix(ZZ, [[3,5,3], [2,6,4], [1,2,3]]); N [3 5 3] [2 6 4] [1 2 3] @@ -8802,7 +8844,7 @@ cdef class Matrix(Matrix1): output_window = output.matrix_window() - from . import strassen + from sage.matrix import strassen strassen.strassen_window_multiply(output_window, self_window, right_window, cutoff) return output @@ -8840,7 +8882,7 @@ cdef class Matrix(Matrix1): self._echelon_in_place_classical() return - from . import strassen + from sage.matrix import strassen pivots = strassen.strassen_echelon(self.matrix_window(), cutoff) self.cache('pivots', pivots) verbose('done with strassen', tm) @@ -8879,7 +8921,7 @@ cdef class Matrix(Matrix1): ... IndexError: matrix window index out of range """ - from . import matrix_window + from sage.matrix import matrix_window if nrows == -1: nrows = self._nrows - row if ncols == -1: @@ -9331,7 +9373,7 @@ cdef class Matrix(Matrix1): sage: D = A.tensor_product(B) sage: D.parent() Full MatrixSpace of 6 by 12 dense matrices over Finite Field of size 23 - sage: E = C.tensor_product(B) # needs sage.rings.finite_rings + sage: E = C.tensor_product(B) Traceback (most recent call last): ... TypeError: unsupported operand parent(s) for *: @@ -9667,9 +9709,9 @@ cdef class Matrix(Matrix1): [0 0 0 1 0] sage: P.is_unitary() True - sage: P.change_ring(GF(3)).is_unitary() # needs sage.rings.finite_rings + sage: P.change_ring(GF(3)).is_unitary() True - sage: P.change_ring(GF(3)).is_unitary() # needs sage.rings.finite_rings + sage: P.change_ring(GF(3)).is_unitary() True A square matrix far from unitary. :: @@ -9902,14 +9944,14 @@ cdef class Matrix(Matrix1): sage: L.append((2, Permutation([1, 4, 2, 3, 5]))) sage: M = sum([c * p.to_matrix() for c, p in L]) sage: from sage.combinat.permutation import bistochastic_as_sum_of_permutations - sage: decomp = bistochastic_as_sum_of_permutations(M) # needs sage.combinat - sage: print(decomp) # needs sage.combinat + sage: decomp = bistochastic_as_sum_of_permutations(M) # needs sage.combinat sage.graphs + sage: print(decomp) # needs sage.combinat sage.graphs 2*B[[1, 4, 2, 3, 5]] + 3*B[[3, 1, 4, 2, 5]] + 9*B[[4, 1, 3, 5, 2]] + 6*B[[5, 3, 4, 1, 2]] An exception is raised when the matrix is not bistochastic:: sage: M = Matrix([[2,3],[2,2]]) - sage: decomp = bistochastic_as_sum_of_permutations(M) # needs sage.combinat + sage: decomp = bistochastic_as_sum_of_permutations(M) # needs sage.graphs Traceback (most recent call last): ... ValueError: The matrix is not bistochastic @@ -10766,6 +10808,7 @@ cdef class Matrix(Matrix1): First, the inexact rings, ``CDF`` and ``RDF``. :: + sage: # needs scipy sage.rings.complex_double sage.symbolic sage: A = matrix(CDF, [[ 0.6454 + 0.7491*I, -0.8662 + 0.1489*I, 0.7656 - 0.00344*I], ....: [-0.2913 + 0.8057*I, 0.8321 + 0.8170*I, -0.6744 + 0.9248*I], ....: [ 0.2554 + 0.3517*I, -0.4454 - 0.1715*I, 0.8325 - 0.6282*I]]) @@ -10790,6 +10833,7 @@ cdef class Matrix(Matrix1): A rectangular matrix. Note that the ``orthonormal`` keyword is ignored in these cases. :: + sage: # needs scipy sage: A = matrix(RDF, [[-0.978325, -0.751994, 0.925305, -0.200512, 0.420458], ....: [-0.474877, -0.983403, 0.089836, 0.132218, 0.672965]]) sage: G, M = A.gram_schmidt(orthonormal=False) @@ -10799,7 +10843,7 @@ cdef class Matrix(Matrix1): sage: M.round(6).zero_at(10^-6) [1.611147 0.0] [0.958116 0.867778] - sage: (A-M*G).zero_at(10^-12) + sage: (A - M*G).zero_at(10^-12) [0.0 0.0 0.0 0.0 0.0] [0.0 0.0 0.0 0.0 0.0] sage: (G*G.transpose()).round(6).zero_at(10^-6) @@ -10812,6 +10856,7 @@ cdef class Matrix(Matrix1): are treated as being of full rank. Try one of the base rings that provide exact results if you need exact results. :: + sage: # needs scipy sage: entries = [[1,1,2], [2,1,3], [3,1,4]] sage: A = matrix(QQ, entries) sage: A.rank() @@ -11110,7 +11155,7 @@ cdef class Matrix(Matrix1): EXAMPLES:: - sage: # needs sage.combinat + sage: # needs sage.combinat sage.libs.pari sage: a = matrix(ZZ,4,[1, 0, 0, 0, 0, 1, 0, 0, ....: 1, -1, 1, 0, 1, -1, 1, 2]); a [ 1 0 0 0] @@ -11156,20 +11201,21 @@ cdef class Matrix(Matrix1): If you need the transformation matrix as well as the Jordan form of ``self``, then pass the option ``transformation=True``. For example:: + sage: # needs sage.combinat sage.libs.pari sage: m = matrix([[5,4,2,1], [0,1,-1,-1], [-1,-1,3,0], [1,1,-1,2]]); m [ 5 4 2 1] [ 0 1 -1 -1] [-1 -1 3 0] [ 1 1 -1 2] - sage: jf, p = m.jordan_form(transformation=True) # needs sage.combinat - sage: jf # needs sage.combinat + sage: jf, p = m.jordan_form(transformation=True) + sage: jf [2|0|0 0] [-+-+---] [0|1|0 0] [-+-+---] [0|0|4 1] [0|0|0 4] - sage: ~p * m * p # needs sage.combinat + sage: ~p * m * p [2 0 0 0] [0 1 0 0] [0 0 4 1] @@ -11191,14 +11237,14 @@ cdef class Matrix(Matrix1): [1 1 1] [1 1 1] [1 1 1] - sage: c.jordan_form(subdivide=False) # needs sage.combinat + sage: c.jordan_form(subdivide=False) # needs sage.combinat sage.libs.pari [3 0 0] [0 0 0] [0 0 0] :: - sage: # needs sage.combinat + sage: # needs sage.combinat sage.libs.pari sage: evals = [(i,i) for i in range(1,6)] sage: n = sum(range(1,6)) sage: jf = block_diagonal_matrix([jordan_block(ev,size) for ev,size in evals]) @@ -11215,10 +11261,10 @@ cdef class Matrix(Matrix1): We verify that the bug from :trac:`6942` is fixed:: - sage: # needs sage.combinat - sage: M = Matrix(GF(2),[[1,0,1,0,0,0,1], [1,0,0,1,1,1,0], [1,1,0,1,1,1,1], - ....: [1,1,1,0,1,1,1], [1,1,1,0,0,1,0], [1,1,1,0,1,0,0], - ....: [1,1,1,1,1,1,0]]) + sage: # needs sage.combinat sage.libs.pari + sage: M = Matrix(GF(2), [[1,0,1,0,0,0,1], [1,0,0,1,1,1,0], [1,1,0,1,1,1,1], + ....: [1,1,1,0,1,1,1], [1,1,1,0,0,1,0], [1,1,1,0,1,0,0], + ....: [1,1,1,1,1,1,0]]) sage: J, T = M.jordan_form(transformation=True) sage: J [1 1|0 0|0 0|0] @@ -11247,6 +11293,7 @@ cdef class Matrix(Matrix1): We now go through three `10 \times 10` matrices to exhibit cases where there are multiple blocks of the same size:: + sage: # needs sage.combinat sage.libs.pari sage: A = matrix(QQ, [[15, 37/3, -16, -104/3, -29, -7/3, 0, 2/3, -29/3, -1/3], [2, 9, -1, -6, -6, 0, 0, 0, -2, 0], [24, 74/3, -41, -208/3, -58, -23/3, 0, 4/3, -58/3, -2/3], [-6, -19, 3, 21, 19, 0, 0, 0, 6, 0], [2, 6, 3, -6, -3, 1, 0, 0, -2, 0], [-96, -296/3, 176, 832/3, 232, 101/3, 0, -16/3, 232/3, 8/3], [-4, -2/3, 21, 16/3, 4, 14/3, 3, -1/3, 4/3, -25/3], [20, 26/3, -66, -199/3, -42, -41/3, 0, 13/3, -55/3, -2/3], [18, 57, -9, -54, -57, 0, 0, 0, -15, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 3]]); A [ 15 37/3 -16 -104/3 -29 -7/3 0 2/3 -29/3 -1/3] [ 2 9 -1 -6 -6 0 0 0 -2 0] @@ -11258,7 +11305,7 @@ cdef class Matrix(Matrix1): [ 20 26/3 -66 -199/3 -42 -41/3 0 13/3 -55/3 -2/3] [ 18 57 -9 -54 -57 0 0 0 -15 0] [ 0 0 0 0 0 0 0 0 0 3] - sage: J, T = A.jordan_form(transformation=True); J # needs sage.combinat + sage: J, T = A.jordan_form(transformation=True); J [3 1 0|0 0 0|0 0 0|0] [0 3 1|0 0 0|0 0 0|0] [0 0 3|0 0 0|0 0 0|0] @@ -11272,13 +11319,14 @@ cdef class Matrix(Matrix1): [0 0 0|0 0 0|0 0 3|0] [-----+-----+-----+-] [0 0 0|0 0 0|0 0 0|3] - sage: T * J * T**(-1) == A # needs sage.combinat + sage: T * J * T**(-1) == A True - sage: T.rank() # needs sage.combinat + sage: T.rank() 10 :: + sage: # needs sage.combinat sage.libs.pari sage: A = matrix(QQ, [[15, 37/3, -16, -14/3, -29, -7/3, 0, 2/3, 1/3, 44/3], [2, 9, -1, 0, -6, 0, 0, 0, 0, 3], [24, 74/3, -41, -28/3, -58, -23/3, 0, 4/3, 2/3, 88/3], [-6, -19, 3, 3, 19, 0, 0, 0, 0, -9], [2, 6, 3, 0, -3, 1, 0, 0, 0, 3], [-96, -296/3, 176, 112/3, 232, 101/3, 0, -16/3, -8/3, -352/3], [-4, -2/3, 21, 16/3, 4, 14/3, 3, -1/3, 4/3, -25/3], [20, 26/3, -66, -28/3, -42, -41/3, 0, 13/3, 2/3, 82/3], [18, 57, -9, 0, -57, 0, 0, 0, 3, 28], [0, 0, 0, 0, 0, 0, 0, 0, 0, 3]]); A [ 15 37/3 -16 -14/3 -29 -7/3 0 2/3 1/3 44/3] [ 2 9 -1 0 -6 0 0 0 0 3] @@ -11290,7 +11338,7 @@ cdef class Matrix(Matrix1): [ 20 26/3 -66 -28/3 -42 -41/3 0 13/3 2/3 82/3] [ 18 57 -9 0 -57 0 0 0 3 28] [ 0 0 0 0 0 0 0 0 0 3] - sage: J, T = A.jordan_form(transformation=True); J # needs sage.combinat + sage: J, T = A.jordan_form(transformation=True); J [3 1 0|0 0 0|0 0|0 0] [0 3 1|0 0 0|0 0|0 0] [0 0 3|0 0 0|0 0|0 0] @@ -11304,13 +11352,14 @@ cdef class Matrix(Matrix1): [-----+-----+---+---] [0 0 0|0 0 0|0 0|3 1] [0 0 0|0 0 0|0 0|0 3] - sage: T * J * T**(-1) == A # needs sage.combinat + sage: T * J * T**(-1) == A True - sage: T.rank() # needs sage.combinat + sage: T.rank() 10 :: + sage: # needs sage.combinat sage.libs.pari sage: A = matrix(QQ, [[15, 37/3, -16, -104/3, -29, -7/3, 35, 2/3, -29/3, -1/3], [2, 9, -1, -6, -6, 0, 7, 0, -2, 0], [24, 74/3, -29, -208/3, -58, -14/3, 70, 4/3, -58/3, -2/3], [-6, -19, 3, 21, 19, 0, -21, 0, 6, 0], [2, 6, -1, -6, -3, 0, 7, 0, -2, 0], [-96, -296/3, 128, 832/3, 232, 65/3, -279, -16/3, 232/3, 8/3], [0, 0, 0, 0, 0, 0, 3, 0, 0, 0], [20, 26/3, -30, -199/3, -42, -14/3, 70, 13/3, -55/3, -2/3], [18, 57, -9, -54, -57, 0, 63, 0, -15, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 3]]); A [ 15 37/3 -16 -104/3 -29 -7/3 35 2/3 -29/3 -1/3] [ 2 9 -1 -6 -6 0 7 0 -2 0] @@ -11322,7 +11371,7 @@ cdef class Matrix(Matrix1): [ 20 26/3 -30 -199/3 -42 -14/3 70 13/3 -55/3 -2/3] [ 18 57 -9 -54 -57 0 63 0 -15 0] [ 0 0 0 0 0 0 0 0 0 3] - sage: J, T = A.jordan_form(transformation=True); J # needs sage.combinat + sage: J, T = A.jordan_form(transformation=True); J [3 1 0|0 0|0 0|0 0|0] [0 3 1|0 0|0 0|0 0|0] [0 0 3|0 0|0 0|0 0|0] @@ -11337,15 +11386,15 @@ cdef class Matrix(Matrix1): [0 0 0|0 0|0 0|0 3|0] [-----+---+---+---+-] [0 0 0|0 0|0 0|0 0|3] - sage: T * J * T**(-1) == A # needs sage.combinat + sage: T * J * T**(-1) == A True - sage: T.rank() # needs sage.combinat + sage: T.rank() 10 Verify that we smoothly move to QQ from ZZ (:trac:`12693`), i.e. we work in the vector space over the field:: - sage: # needs sage.combinat + sage: # needs sage.combinat sage.libs.pari sage: M = matrix(((2,2,2), (0,0,0), (-2,-2,-2))) sage: J, P = M.jordan_form(transformation=True) sage: J; P @@ -11603,8 +11652,7 @@ cdef class Matrix(Matrix1): Matrices may fail to be diagonalizable for various reasons:: - sage: A = matrix(QQ, 2, [1,2,3, 4,5,6]) - sage: A + sage: A = matrix(QQ, 2, [1,2,3, 4,5,6]); A [1 2 3] [4 5 6] sage: A.diagonalization() @@ -11612,8 +11660,7 @@ cdef class Matrix(Matrix1): ... TypeError: not a square matrix - sage: B = matrix(ZZ, 2, [1, 2, 3, 4]) - sage: B + sage: B = matrix(ZZ, 2, [1, 2, 3, 4]); B [1 2] [3 4] sage: B.diagonalization() @@ -11621,17 +11668,16 @@ cdef class Matrix(Matrix1): ... ValueError: matrix entries must be from a field - sage: C = matrix(RR, 2, [1., 2., 3., 4.]) - sage: C + sage: C = matrix(RR, 2, [1., 2., 3., 4.]); C [1.00000000000000 2.00000000000000] [3.00000000000000 4.00000000000000] sage: C.diagonalization() Traceback (most recent call last): ... - ValueError: base field must be exact, but Real Field with 53 bits of precision is not + ValueError: base field must be exact, + but Real Field with 53 bits of precision is not - sage: D = matrix(QQ, 2, [0, 2, 1, 0]) - sage: D + sage: D = matrix(QQ, 2, [0, 2, 1, 0]); D [0 2] [1 0] sage: D.diagonalization() # needs sage.libs.pari @@ -11639,15 +11685,14 @@ cdef class Matrix(Matrix1): ... ValueError: not diagonalizable over Rational Field - sage: E = matrix(QQ, 2, [3, 1, 0, 3]) - sage: E + sage: E = matrix(QQ, 2, [3, 1, 0, 3]); E [3 1] [0 3] sage: E.diagonalization() # needs sage.libs.pari Traceback (most recent call last): ... ValueError: not diagonalizable - sage: E.jordan_form() # needs sage.combinat + sage: E.jordan_form() # needs sage.combinat sage.libs.pari [3 1] [0 3] """ @@ -11751,7 +11796,7 @@ cdef class Matrix(Matrix1): ....: [-1, 6, 1, -3, 1]]) sage: A.is_diagonalizable() # needs sage.libs.pari False - sage: A.jordan_form(subdivide=False) # needs sage.libs.pari + sage: A.jordan_form(subdivide=False) # needs sage.combinat sage.libs.pari [-1 1 0 0 0] [ 0 -1 0 0 0] [ 0 0 2 1 0] @@ -11794,7 +11839,7 @@ cdef class Matrix(Matrix1): ....: [ 2*b, 3*b, 4*b + 4, 3*b + 3]]) sage: A.is_diagonalizable() False - sage: A.jordan_form() + sage: A.jordan_form() # needs sage.combinat [ 4 1| 0 0] [ 0 4| 0 0] [---------------+---------------] @@ -11974,7 +12019,7 @@ cdef class Matrix(Matrix1): sage: A.is_similar(B) True - sage: # needs sage.libs.pari + sage: # needs sage.combinat sage.libs.pari sage: _, T = A.is_similar(B, transformation=True) sage: T [ 1.00000000000000? + 0.?e-14*I 0.?e-14 + 0.?e-14*I 0.?e-14 + 0.?e-14*I] @@ -12074,11 +12119,11 @@ cdef class Matrix(Matrix1): sage: D = S.inverse()*C*S sage: C.is_similar(D) True - sage: C.is_similar(D, transformation=True) + sage: C.is_similar(D, transformation=True) # needs sage.combinat Traceback (most recent call last): ... RuntimeError: unable to compute transformation for similar matrices - sage: C.jordan_form() + sage: C.jordan_form() # needs sage.combinat Traceback (most recent call last): ... RuntimeError: Some eigenvalue does not exist in @@ -12126,7 +12171,7 @@ cdef class Matrix(Matrix1): sage: A = matrix(GF(3), 2, 2, range(4)) sage: B = matrix(GF(2), 2, 2, range(4)) - sage: A.is_similar(B, transformation=True) # needs sage.rings.finite_rings + sage: A.is_similar(B, transformation=True) Traceback (most recent call last): ... TypeError: no common canonical parent for objects with parents: @@ -12815,7 +12860,7 @@ cdef class Matrix(Matrix1): sage: L = A.cholesky(); L [ 1.000... 0.000...] [ 2.000... 1.414...] - sage: (L*L.transpose() - A).norm() < 1e-10 + sage: (L*L.transpose() - A).norm() < 1e-10 # needs scipy True Even symbolic matrices can sometimes be factored:: @@ -13420,7 +13465,7 @@ cdef class Matrix(Matrix1): [ 0 0 0 0] sage: L.base_ring() # needs sage.combinat Finite Field in a of size 5^2 - sage: C == P*L*U + sage: C == P*L*U # needs sage.combinat True With no pivoting strategy given (i.e. ``pivot=None``) @@ -14462,7 +14507,7 @@ cdef class Matrix(Matrix1): sage: L*D*L.T [1e-10 1.0] [ 1.0 0.0] - sage: A.block_ldlt() + sage: A.block_ldlt() # needs scipy ( [1.0 0.0] [1.0 0.0] [1e-10 1.0] [0.0 1.0], [0.0 1.0], [ 1.0 2e-10] @@ -14472,6 +14517,7 @@ cdef class Matrix(Matrix1): but `P^{T}AP` will ideally be close to `LDL^{*}` in the metric induced by the norm:: + sage: # needs scipy sage.rings.complex_double sage.symbolic sage: A = matrix(CDF, 2, 2, [ [-1.1933, -0.3185 - 1.3553*I], ....: [-0.3185 + 1.3553*I, 1.5729 ] ]) sage: P,L,D = A.block_ldlt() @@ -14759,21 +14805,19 @@ cdef class Matrix(Matrix1): Any of the preceding examples are valid over inexact rings and with complex numbers as well:: + sage: # needs sage.rings.complex_double sage.symbolic sage: A = matrix(CDF, [ [ 2, I], ....: [-I, 2] ] ) sage: A.is_positive_semidefinite() True - sage: A = matrix(CDF, [ [ 1, I], ....: [-I, 1] ] ) sage: A.is_positive_semidefinite() True - sage: A = matrix(CDF, [ [0,I], ....: [I,0] ] ) sage: A.is_positive_semidefinite() False - sage: A = matrix(CDF, [ [2,I], ....: [0,0] ]) sage: A.is_positive_semidefinite() @@ -14792,7 +14836,8 @@ cdef class Matrix(Matrix1): a Hermitian matrix (for a non-Hermitian matrix, both "obviously" return ``False``):: - sage: rings = [ZZ, QQ, RDF, CDF] + sage: rings = [ZZ, QQ, RDF] + sage: rings.append(CDF) # needs sage.rings.complex_double sage: rings.append(QuadraticField(-1, 'I')) # needs sage.rings.number_field sage: from sage.misc.prandom import choice sage: ring = choice(rings) @@ -14802,9 +14847,9 @@ cdef class Matrix(Matrix1): ....: return True ....: return ( A.is_hermitian() and ....: all(v >= 0 for v in A.eigenvalues()) ) - sage: expected = is_positive_semidefinite_naive(A) # needs numpy - sage: actual = A.is_positive_semidefinite() - sage: actual == expected # needs numpy + sage: expected = is_positive_semidefinite_naive(A) # needs scipy + sage: actual = A.is_positive_semidefinite() # needs scipy + sage: actual == expected # needs scipy True We reject matrices whose base fields cannot be coerced to @@ -15084,7 +15129,7 @@ cdef class Matrix(Matrix1): except (OverflowError, TypeError): from sage.rings.real_mpfr import RealField # Try using MPFR, which handles large numbers much better, but is slower. - from .misc_mpfr import hadamard_row_bound_mpfr + from sage.matrix.misc_mpfr import hadamard_row_bound_mpfr R = RealField(53, rnd='RNDU') A = self.change_ring(R) m1 = hadamard_row_bound_mpfr(A) @@ -15191,6 +15236,7 @@ cdef class Matrix(Matrix1): EXAMPLES:: + sage: # needs sage.rings.complex_double sage.symbolic sage: A = matrix(CDF, [[1+I,1],[0,2*I]]) sage: A.conjugate() [1.0 - 1.0*I 1.0] @@ -15368,10 +15414,10 @@ cdef class Matrix(Matrix1): :: sage: Id = identity_matrix(12) - sage: Id.norm(2) + sage: Id.norm(2) # needs scipy 1.0 - sage: # needs sage.rings.real_mpfr + sage: # needs scipy sage.rings.real_mpfr sage: A = matrix(RR, 2, 2, [13,-4,-4,7]) sage: A.norm() # rel tol 2e-16 14.999999999999998 @@ -15380,7 +15426,7 @@ cdef class Matrix(Matrix1): Faster routines for double precision entries from `RDF` or `CDF` are provided by the :class:`~sage.matrix.matrix_double_dense.Matrix_double_dense` class. :: - sage: # needs sage.rings.real_mpfr + sage: # needs sage.rings.real_mpfr sage.symbolic sage: A = matrix(CC, 2, 3, [3*I,4,1-I,1,2,0]) sage: A.norm('frob') 5.656854249492381 @@ -15390,6 +15436,7 @@ cdef class Matrix(Matrix1): 6.0 sage: A.norm(Infinity) 8.414213562373096 + sage: a = matrix([[],[],[],[]]) sage: a.norm() 0.0 @@ -15404,13 +15451,14 @@ cdef class Matrix(Matrix1): 0.0 """ from sage.rings.real_double import RDF - from sage.rings.complex_double import CDF if self._nrows == 0 or self._ncols == 0: return RDF(0) # 2-norm: if p == 2: + from sage.rings.complex_double import CDF + A = self.change_ring(CDF) A = A.conjugate().transpose() * A S = A.SVD()[1] @@ -16738,7 +16786,7 @@ cdef class Matrix(Matrix1): sage: U.inverse()*B*U == Z True - sage: A.jordan_form() == B.jordan_form() # needs sage.combinat + sage: A.jordan_form() == B.jordan_form() # needs sage.combinat sage.libs.pari True Two more examples, illustrating the two extremes of the zig-zag @@ -16799,7 +16847,7 @@ cdef class Matrix(Matrix1): sage: U.inverse()*D*U == Z True - sage: C.jordan_form() == D.jordan_form() # needs sage.combinat + sage: C.jordan_form() == D.jordan_form() # needs sage.combinat sage.libs.pari True ZigZag form is achieved entirely with the operations of the field, so @@ -17117,7 +17165,7 @@ cdef class Matrix(Matrix1): ....: [-155, -3, -55, 45, 50, -245, -27, 65, -328, 77, 365, 583]]) sage: A.characteristic_polynomial().factor() # needs sage.libs.pari (x^2 - 2)^2 * (x^2 + 2*x + 5)^4 - sage: A.eigenvalues(extend=False) # needs sage.rings.number_field + sage: A.eigenvalues(extend=False) # needs sage.libs.pari [] sage: A.rational_form() [ 0 -5| 0 0 0 0| 0 0 0 0 0 0] @@ -17389,7 +17437,7 @@ cdef class Matrix(Matrix1): sage: L = matrix(SR, [ [0, e, 0 ], # needs sage.symbolic ....: [0, 2, pi], ....: [sqrt(2), 0, 0 ] ]) - sage: L.is_positive_operator_on(K) # needs sage.geometry.polyhedron sage.symbolic + sage: L.is_positive_operator_on(K) # needs sage.geometry.polyhedron True Your matrix can be over any exact ring, for example the ring of @@ -17816,7 +17864,7 @@ cdef class Matrix(Matrix1): sage: L = matrix(SR, [ [e, 0, 0 ], # needs sage.symbolic ....: [0, pi, 0 ], ....: [0, 0, sqrt(2)] ]) - sage: L.is_lyapunov_like_on(K) # needs sage.geometry.polyhedron sage.symbolic + sage: L.is_lyapunov_like_on(K) # needs sage.geometry.polyhedron True TESTS: diff --git a/src/sage/matrix/matrix_complex_ball_dense.pxd b/src/sage/matrix/matrix_complex_ball_dense.pxd index 622925a0ee9..9a17089a1c7 100644 --- a/src/sage/matrix/matrix_complex_ball_dense.pxd +++ b/src/sage/matrix/matrix_complex_ball_dense.pxd @@ -1,5 +1,5 @@ from sage.libs.arb.types cimport acb_mat_t -from .matrix_dense cimport Matrix_dense +from sage.matrix.matrix_dense cimport Matrix_dense from sage.matrix.matrix_generic_dense cimport Matrix_generic_dense from sage.structure.parent cimport Parent diff --git a/src/sage/matrix/matrix_complex_ball_dense.pyx b/src/sage/matrix/matrix_complex_ball_dense.pyx index 22366b5f1f2..e5414abdd9e 100644 --- a/src/sage/matrix/matrix_complex_ball_dense.pyx +++ b/src/sage/matrix/matrix_complex_ball_dense.pyx @@ -19,8 +19,8 @@ TESTS:: [8.000000000000000 11.00000000000000] [22.00000000000000 41.00000000000000] - sage: mat = matrix(ComplexBallField(20), 2, 2, list(range(4)))*i/3 - sage: loads(dumps(mat)).identical(mat) + sage: mat = matrix(ComplexBallField(20), 2, 2, list(range(4)))*i/3 # needs sage.symbolic + sage: loads(dumps(mat)).identical(mat) # needs sage.symbolic True """ # **************************************************************************** @@ -40,7 +40,7 @@ from sage.libs.arb.acb cimport * from sage.libs.arb.acb_mat cimport * from sage.libs.gmp.mpz cimport mpz_fits_ulong_p, mpz_get_ui from sage.matrix.constructor import matrix -from .args cimport SparseEntry, MatrixArgs_init +from sage.matrix.args cimport SparseEntry, MatrixArgs_init from sage.rings.complex_interval cimport ComplexIntervalFieldElement from sage.rings.complex_arb cimport ( ComplexBall, diff --git a/src/sage/matrix/matrix_complex_double_dense.pxd b/src/sage/matrix/matrix_complex_double_dense.pxd index 0ad83958941..a9041564e43 100644 --- a/src/sage/matrix/matrix_complex_double_dense.pxd +++ b/src/sage/matrix/matrix_complex_double_dense.pxd @@ -1,4 +1,4 @@ -from .matrix_double_dense cimport Matrix_double_dense +from sage.matrix.matrix_double_dense cimport Matrix_double_dense cdef class Matrix_complex_double_dense(Matrix_double_dense): pass diff --git a/src/sage/matrix/matrix_complex_double_dense.pyx b/src/sage/matrix/matrix_complex_double_dense.pyx index 162332eb44e..b86516fd121 100644 --- a/src/sage/matrix/matrix_complex_double_dense.pyx +++ b/src/sage/matrix/matrix_complex_double_dense.pyx @@ -17,6 +17,7 @@ We deal with the case of zero rows or zero columns:: TESTS:: + sage: # needs sage.symbolic sage: a = matrix(CDF,2,[i+(4-i)*I for i in range(4)], sparse=False) sage: TestSuite(a).run() sage: Mat(CDF,0,0).zero_matrix().inverse() @@ -53,6 +54,7 @@ cdef class Matrix_complex_double_dense(Matrix_double_dense): EXAMPLES:: + sage: # needs sage.symbolic sage: m = Matrix(CDF, [[1,2*I],[3+I,4]]) sage: m**2 [-1.0 + 6.0*I 10.0*I] @@ -65,7 +67,7 @@ cdef class Matrix_complex_double_dense(Matrix_double_dense): :meth:`~.Matrix_double_dense.left_eigenvectors` or :meth:`~.Matrix_double_dense.right_eigenvectors`:: - sage: p,e = m.right_eigenvectors() + sage: p,e = m.right_eigenvectors() # needs sage.symbolic The result is a pair ``(p,e)``, where ``p`` is a diagonal matrix of eigenvalues and ``e`` is a matrix whose columns are the @@ -74,8 +76,8 @@ cdef class Matrix_complex_double_dense(Matrix_double_dense): To solve a linear system `Ax = b` where ``A = [[1,2*I],[3+I,4]]`` and ``b = [5,6]``:: - sage: b = vector(CDF,[5,6]) - sage: m.solve_right(b) # abs tol 1e-14 + sage: b = vector(CDF,[5,6]) # needs sage.symbolic + sage: m.solve_right(b) # abs tol 1e-14 # needs sage.symbolic (2.6666666666666665 + 0.6666666666666669*I, -0.3333333333333333 - 1.1666666666666667*I) See the methods :meth:`~.Matrix_double_dense.QR`, diff --git a/src/sage/matrix/matrix_cyclo_dense.pxd b/src/sage/matrix/matrix_cyclo_dense.pxd index 1ce4e1e1cfd..d6c8711f862 100644 --- a/src/sage/matrix/matrix_cyclo_dense.pxd +++ b/src/sage/matrix/matrix_cyclo_dense.pxd @@ -1,6 +1,6 @@ from sage.libs.gmp.types cimport mpz_t -from .matrix_dense cimport Matrix_dense -from .matrix_rational_dense cimport Matrix_rational_dense +from sage.matrix.matrix_dense cimport Matrix_dense +from sage.matrix.matrix_rational_dense cimport Matrix_rational_dense cdef class Matrix_cyclo_dense(Matrix_dense): diff --git a/src/sage/matrix/matrix_cyclo_dense.pyx b/src/sage/matrix/matrix_cyclo_dense.pyx index c3ec3ebf81a..cb83823c576 100644 --- a/src/sage/matrix/matrix_cyclo_dense.pyx +++ b/src/sage/matrix/matrix_cyclo_dense.pyx @@ -56,14 +56,14 @@ from sage.libs.flint.fmpz cimport fmpz_init, fmpz_clear, fmpz_set_mpz, fmpz_one, from sage.libs.flint.fmpq cimport fmpq_is_zero, fmpq_set_mpq, fmpq_canonicalise from sage.libs.flint.fmpq_mat cimport fmpq_mat_entry_num, fmpq_mat_entry_den, fmpq_mat_entry -from .args cimport MatrixArgs_init -from .constructor import matrix -from .matrix_space import MatrixSpace -from .matrix cimport Matrix -from . import matrix_dense -from .matrix_integer_dense cimport _lift_crt +from sage.matrix.args cimport MatrixArgs_init +from sage.matrix.constructor import matrix +from sage.matrix.matrix_space import MatrixSpace +from sage.matrix.matrix cimport Matrix +from sage.matrix import matrix_dense +from sage.matrix.matrix_integer_dense cimport _lift_crt from sage.structure.element cimport Matrix as baseMatrix -from .misc_flint import matrix_integer_dense_rational_reconstruction +from sage.matrix.misc_flint import matrix_integer_dense_rational_reconstruction from sage.arith.misc import binomial, previous_prime from sage.rings.rational_field import QQ @@ -1535,7 +1535,7 @@ cdef class Matrix_cyclo_dense(Matrix_dense): K = self.base_ring() phi = K.defining_polynomial() from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF - from .constructor import matrix + from sage.matrix.constructor import matrix F = GF(p) aa = [a for a, _ in phi.change_ring(F).roots()] n = K.degree() diff --git a/src/sage/matrix/matrix_dense.pxd b/src/sage/matrix/matrix_dense.pxd index 3343438682b..30c3effe02a 100644 --- a/src/sage/matrix/matrix_dense.pxd +++ b/src/sage/matrix/matrix_dense.pxd @@ -1,4 +1,4 @@ -from .matrix cimport Matrix +from sage.matrix.matrix cimport Matrix cdef class Matrix_dense(Matrix): cdef void set_unsafe_int(self, Py_ssize_t i, Py_ssize_t j, int value) noexcept diff --git a/src/sage/matrix/matrix_domain_dense.pxd b/src/sage/matrix/matrix_domain_dense.pxd index 92e37e22afb..8a6e487c493 100644 --- a/src/sage/matrix/matrix_domain_dense.pxd +++ b/src/sage/matrix/matrix_domain_dense.pxd @@ -1,4 +1,4 @@ -from .matrix cimport Matrix +from sage.matrix.matrix cimport Matrix cdef class Matrix_domain_dense(Matrix): pass diff --git a/src/sage/matrix/matrix_domain_sparse.pxd b/src/sage/matrix/matrix_domain_sparse.pxd index 42eab458643..c5882238632 100644 --- a/src/sage/matrix/matrix_domain_sparse.pxd +++ b/src/sage/matrix/matrix_domain_sparse.pxd @@ -1,4 +1,4 @@ -from .matrix cimport Matrix +from sage.matrix.matrix cimport Matrix cdef class Matrix_domain_sparse(Matrix): pass diff --git a/src/sage/matrix/matrix_double_dense.pxd b/src/sage/matrix/matrix_double_dense.pxd index db1feffa053..3f2cb525b10 100644 --- a/src/sage/matrix/matrix_double_dense.pxd +++ b/src/sage/matrix/matrix_double_dense.pxd @@ -1,4 +1,4 @@ -from .matrix_numpy_dense cimport Matrix_numpy_dense +from sage.matrix.matrix_numpy_dense cimport Matrix_numpy_dense cdef class Matrix_double_dense(Matrix_numpy_dense): diff --git a/src/sage/matrix/matrix_double_dense.pyx b/src/sage/matrix/matrix_double_dense.pyx index f4312a479e5..5d19067f2ed 100644 --- a/src/sage/matrix/matrix_double_dense.pyx +++ b/src/sage/matrix/matrix_double_dense.pyx @@ -70,7 +70,7 @@ import sage.rings.real_double import sage.rings.complex_double from sage.structure.element cimport Vector -from .constructor import matrix +from sage.matrix.constructor import matrix cimport sage.structure.element cimport numpy as cnumpy @@ -99,7 +99,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): sage: m**2 [ 7.0 10.0] [15.0 22.0] - sage: m^(-1) # rel tol 1e-15 + sage: m^(-1) # rel tol 1e-15 # needs scipy [-1.9999999999999996 0.9999999999999998] [ 1.4999999999999998 -0.4999999999999999] @@ -624,6 +624,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): And over the complex numbers. :: + sage: # needs sage.symbolic sage: B = matrix(CDF, 2, [[1+I, 2+3*I],[3+4*I,3*I]]); B [1.0 + 1.0*I 2.0 + 3.0*I] [3.0 + 4.0*I 3.0*I] @@ -1144,13 +1145,14 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): sage: m.eigenvalues(algorithm='default') [1.0*I, -1.0*I] - sage: m = matrix(CDF, 2, 2, [I,1,-I,0]) - sage: m.eigenvalues() + sage: m = matrix(CDF, 2, 2, [I,1,-I,0]) # needs sage.symbolic + sage: m.eigenvalues() # needs sage.symbolic [-0.624810533... + 1.30024259...*I, 0.624810533... - 0.30024259...*I] The adjacency matrix of a graph will be symmetric, and the eigenvalues will be real. :: + sage: # needs sage.graphs sage: A = graphs.PetersenGraph().adjacency_matrix() sage: A = A.change_ring(RDF) sage: ev = A.eigenvalues(algorithm='symmetric'); ev # tol 1e-14 @@ -1163,6 +1165,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): the eigenvalues of a Hermitian matrix are real, and the eigenvalues of a positive-definite matrix will be positive. :: + sage: # needs sage.symbolic sage: A = matrix([[ 4*I + 5, 8*I + 1, 7*I + 5, 3*I + 5], ....: [ 7*I - 2, -4*I + 7, -2*I + 4, 8*I + 8], ....: [-2*I + 1, 6*I + 6, 5*I + 5, -I - 4], @@ -1178,19 +1181,19 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): it might split too finely. Too large, and it can go wrong very badly. Use with care. :: + sage: # needs sage.graphs sage: G = graphs.PetersenGraph() sage: G.spectrum() [3, 1, 1, 1, 1, 1, -2, -2, -2, -2] - sage: A = G.adjacency_matrix().change_ring(RDF) sage: A.eigenvalues(algorithm='symmetric', tol=1.0e-5) # tol 1e-15 [(-2.0, 4), (1.0, 5), (3.0, 1)] - sage: A.eigenvalues(algorithm='symmetric', tol=2.5) # tol 1e-15 [(-2.0, 4), (1.3333333333333333, 6)] An (extreme) example of properly grouping similar eigenvalues. :: + sage: # needs sage.graphs sage: G = graphs.HigmanSimsGraph() sage: A = G.adjacency_matrix().change_ring(RDF) sage: A.eigenvalues(algorithm='symmetric', tol=1.0e-5) # tol 2e-15 @@ -1268,6 +1271,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): Test the deprecation:: + sage: # needs sage.graphs sage: A = graphs.PetersenGraph().adjacency_matrix().change_ring(RDF) sage: ev = A.eigenvalues('symmetric', 1e-13) doctest:...: DeprecationWarning: "algorithm" and "tol" should be used @@ -1705,6 +1709,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): TESTS:: + sage: # needs sage.symbolic sage: A = matrix(CDF, [[1, 2], [3, 3+I]]) sage: b = matrix(CDF, [[1, 0], [2, 1]]) sage: x = A._solve_right_nonsingular_square(b) @@ -1830,6 +1835,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): EXAMPLES:: + sage: # needs sage.symbolic sage: A = matrix(CDF, [[1+I, 3-I], [0, 2*I]]) sage: A.conjugate() [1.0 - 1.0*I 3.0 + 1.0*I] @@ -1837,7 +1843,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): There is a shorthand notation:: - sage: A.conjugate() == A.C + sage: A.conjugate() == A.C # needs sage.symbolic True Conjugates work (trivially) for real matrices:: @@ -2265,6 +2271,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): The QR decomposition will produce a unitary matrix as Q and the SVD decomposition will create two unitary matrices, U and V. :: + sage: # needs sage.symbolic sage: A = matrix(CDF, [[ 1 - I, -3*I, -2 + I, 1, -2 + 3*I], ....: [ 1 - I, -2 + I, 1 + 4*I, 0, 2 + I], ....: [ -1, -5 + I, -2 + I, 1 + I, -5 - 4*I], @@ -2427,6 +2434,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): EXAMPLES:: + sage: # needs sage.symbolic sage: A = matrix(CDF, [[ 1 + I, 1 - 6*I, -1 - I], ....: [-3 - I, -4*I, -2], ....: [-1 + I, -2 - 8*I, 2 + I]]) @@ -2439,6 +2447,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): A matrix that is nearly Hermitian, but for one non-real diagonal entry:: + sage: # needs sage.symbolic sage: A = matrix(CDF, [[ 2, 2-I, 1+4*I], ....: [ 2+I, 3+I, 2-6*I], ....: [1-4*I, 2+6*I, 5]]) @@ -2461,6 +2470,8 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): False A matrix that is skew-Hermitian:: + + sage: # needs sage.symbolic sage: A = matrix(CDF, [[-I, 2.0+I], [-2.0+I, 0.0]]) sage: A._is_hermitian_orthonormal() False @@ -2549,6 +2560,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): EXAMPLES:: + sage: # needs sage.symbolic sage: A = matrix(CDF, [[ 1 + I, 1 - 6*I, -1 - I], ....: [-3 - I, -4*I, -2], ....: [-1 + I, -2 - 8*I, 2 + I]]) @@ -2565,6 +2577,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): A matrix that is nearly Hermitian, but for one non-real diagonal entry. :: + sage: # needs sage.symbolic sage: A = matrix(CDF, [[ 2, 2-I, 1+4*I], ....: [ 2+I, 3+I, 2-6*I], ....: [1-4*I, 2+6*I, 5]]) @@ -2582,11 +2595,12 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): of entries and may achieve the wrong result (depending on the system):: + sage: # needs sage.symbolic sage: A = matrix(CDF, [[ 1 + I, 1 - 6*I, -1 - I], ....: [-3 - I, -4*I, -2], ....: [-1 + I, -2 - 8*I, 2 + I]]) sage: U, _, _ = A.SVD() - sage: B=U*U.conjugate_transpose() + sage: B = U*U.conjugate_transpose() sage: B.is_hermitian(algorithm='naive') True sage: B.is_hermitian(algorithm='naive', tol=1.0e-17) # random @@ -2685,6 +2699,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): A matrix that is nearly skew-Hermitian, but for a non-real diagonal entry. :: + sage: # needs sage.symbolic sage: A = matrix(CDF, [[ -I, -1, 1-I], ....: [ 1, 1, -1], ....: [-1-I, 1, -I]]) @@ -2702,11 +2717,12 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): be too strict about the equality of entries and may achieve the wrong result (depending on the system):: + sage: # needs sage.symbolic sage: A = matrix(CDF, [[ 1 + I, 1 - 6*I, -1 - I], ....: [-3 - I, -4*I, -2], ....: [-1 + I, -2 - 8*I, 2 + I]]) sage: U, _, _ = A.SVD() - sage: B=1j*U*U.conjugate_transpose() + sage: B = 1j*U*U.conjugate_transpose() sage: B.is_skew_hermitian(algorithm='naive') True sage: B.is_skew_hermitian(algorithm='naive', tol=1.0e-17) # random @@ -2798,6 +2814,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): First over the complexes. ``B`` is Hermitian, hence normal. :: + sage: # needs sage.symbolic sage: A = matrix(CDF, [[ 1 + I, 1 - 6*I, -1 - I], ....: [-3 - I, -4*I, -2], ....: [-1 + I, -2 - 8*I, 2 + I]]) @@ -2816,22 +2833,24 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): Now over the reals. Circulant matrices are normal. :: + sage: # needs sage.graphs sage: G = graphs.CirculantGraph(20, [3, 7]) sage: D = digraphs.Circuit(20) sage: A = 3*D.adjacency_matrix() - 5*G.adjacency_matrix() sage: A = A.change_ring(RDF) sage: A.is_normal() True - sage: A.is_normal(algorithm = 'naive') + sage: A.is_normal(algorithm='naive') True sage: A[19,0] = 4.0 sage: A.is_normal() False - sage: A.is_normal(algorithm = 'naive') + sage: A.is_normal(algorithm='naive') False Skew-Hermitian matrices are normal. :: + sage: # needs sage.symbolic sage: A = matrix(CDF, [[ 1 + I, 1 - 6*I, -1 - I], ....: [-3 - I, -4*I, -2], ....: [-1 + I, -2 - 8*I, 2 + I]]) @@ -2856,6 +2875,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): Sage has several fields besides the entire complex numbers where conjugation is non-trivial. :: + sage: # needs sage.rings.number_field sage: F. = QuadraticField(-7) sage: C = matrix(F, [[-2*b - 3, 7*b - 6, -b + 3], ....: [-2*b - 3, -3*b + 2, -2*b], @@ -2991,7 +3011,9 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): First over the complexes. The similar matrix is always upper-triangular in this case. :: - sage: A = matrix(CDF, 4, 4, range(16)) + matrix(CDF, 4, 4, [x^3*I for x in range(0, 16)]) + sage: # needs sage.symbolic + sage: A = matrix(CDF, 4, 4, range(16)) + matrix(CDF, 4, 4, + ....: [x^3*I for x in range(0, 16)]) sage: Q, T = A.schur() sage: (Q*Q.conjugate().transpose()).zero_at(1e-12) # tol 1e-12 [ 0.999999999999999 0.0 0.0 0.0] @@ -3000,7 +3022,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): [ 0.0 0.0 0.0 0.9999999999999999] sage: all(T.zero_at(1.0e-12)[i,j] == 0 for i in range(4) for j in range(i)) True - sage: (Q*T*Q.conjugate().transpose()-A).zero_at(1.0e-11) + sage: (Q*T*Q.conjugate().transpose() - A).zero_at(1.0e-11) [0.0 0.0 0.0 0.0] [0.0 0.0 0.0 0.0] [0.0 0.0 0.0 0.0] @@ -3027,7 +3049,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): Full MatrixSpace of 4 by 4 dense matrices over Complex Double Field sage: all(T.zero_at(1.0e-12)[i,j] == 0 for i in range(4) for j in range(i)) True - sage: (Q*T*Q.conjugate().transpose()-A).zero_at(1.0e-11) + sage: (Q*T*Q.conjugate().transpose() - A).zero_at(1.0e-11) [0.0 0.0 0.0 0.0] [0.0 0.0 0.0 0.0] [0.0 0.0 0.0 0.0] @@ -3054,7 +3076,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): False sage: all(T.zero_at(1.0e-12)[i,j] == 0 for i in range(4) for j in range(i-1)) True - sage: (Q*T*Q.conjugate().transpose()-A).zero_at(1.0e-11) + sage: (Q*T*Q.conjugate().transpose() - A).zero_at(1.0e-11) [0.0 0.0 0.0 0.0] [0.0 0.0 0.0 0.0] [0.0 0.0 0.0 0.0] @@ -3069,6 +3091,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): Starting with complex numbers and requesting a result over the reals will never happen. :: + sage: # needs sage.symbolic sage: A = matrix(CDF, 2, 2, [[2+I, -1+3*I], [5-4*I, 2-7*I]]) sage: A.schur(base_ring=RDF) Traceback (most recent call last): @@ -3095,7 +3118,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): sage: T.round(6) [ 0.5 1.5] [-0.5 0.5] - sage: (Q*T*Q.conjugate().transpose()-B).zero_at(1.0e-11) + sage: (Q*T*Q.conjugate().transpose() - B).zero_at(1.0e-11) [0.0 0.0] [0.0 0.0] @@ -3105,6 +3128,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): of eigenvectors of the matrix. Here that basis is the set of columns of the unitary matrix. :: + sage: # needs sage.symbolic sage: A = matrix(CDF, [[ 52, -9*I - 8, 6*I - 187, -188*I + 2], ....: [ 9*I - 8, 12, -58*I + 59, 30*I + 42], ....: [-6*I - 187, 58*I + 59, 2677, 2264*I + 65], @@ -3121,7 +3145,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): [ 0.0 0.9999999999999989 0.0 0.0] [ 0.0 0.0 1.0000000000000002 0.0] [ 0.0 0.0 0.0 0.9999999999999992] - sage: (Q*T*Q.conjugate().transpose()-A).zero_at(1.0e-11) + sage: (Q*T*Q.conjugate().transpose() - A).zero_at(1.0e-11) [0.0 0.0 0.0 0.0] [0.0 0.0 0.0 0.0] [0.0 0.0 0.0 0.0] @@ -3142,14 +3166,15 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): [ 0.4361 0.359 0.7599 0.3217] [ -0.836 0.3945 0.1438 0.3533] sage: T = T.zero_at(10^-12) - sage: all(abs(e) < 10^-4 for e in (T - diagonal_matrix(RDF, [-13.5698, -0.8508, 7.7664, 11.6542])).list()) + sage: all(abs(e) < 10^-4 + ....: for e in (T - diagonal_matrix(RDF, [-13.5698, -0.8508, 7.7664, 11.6542])).list()) True sage: (Q*Q.transpose()) # tol 1e-12 [0.9999999999999998 0.0 0.0 0.0] [ 0.0 1.0 0.0 0.0] [ 0.0 0.0 0.9999999999999998 0.0] [ 0.0 0.0 0.0 0.9999999999999996] - sage: (Q*T*Q.transpose()-A).zero_at(1.0e-11) + sage: (Q*T*Q.transpose() - A).zero_at(1.0e-11) [0.0 0.0 0.0 0.0] [0.0 0.0 0.0 0.0] [0.0 0.0 0.0 0.0] @@ -3294,6 +3319,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): A complex matrix that is Hermitian and positive definite. :: + sage: # needs sage.symbolic sage: A = matrix(CDF, [[ 23, 17*I + 3, 24*I + 25, 21*I], ....: [ -17*I + 3, 38, -69*I + 89, 7*I + 15], ....: [-24*I + 25, 69*I + 89, 976, 24*I + 6], @@ -3332,6 +3358,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): ... ValueError: matrix is not positive definite + sage: # needs sage.symbolic sage: B = matrix(CDF, [[ 2, 4 - 2*I, 2 + 2*I], ....: [4 + 2*I, 8, 10*I], ....: [2 - 2*I, -10*I, -3]]) @@ -3363,6 +3390,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): :: + sage: # needs sage.symbolic sage: A = matrix(CDF, [[1+I]]) sage: A.cholesky() Traceback (most recent call last): @@ -3464,6 +3492,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): A matrix over ``CDF`` that is positive definite. :: + sage: # needs sage.symbolic sage: C = matrix(CDF, [[ 23, 17*I + 3, 24*I + 25, 21*I], ....: [ -17*I + 3, 38, -69*I + 89, 7*I + 15], ....: [-24*I + 25, 69*I + 89, 976, 24*I + 6], @@ -3495,6 +3524,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): A matrix over ``CDF`` that is not positive definite. :: + sage: # needs sage.symbolic sage: B = matrix(CDF, [[ 2, 4 - 2*I, 2 + 2*I], ....: [4 + 2*I, 8, 10*I], ....: [2 - 2*I, -10*I, -3]]) @@ -3539,6 +3569,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): :: + sage: # needs sage.symbolic sage: A = matrix(CDF, [[1+I]]) sage: A.is_positive_definite() False @@ -3641,10 +3672,10 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): sage: A.exp() # tol 1e-14 [51.968956198705044 74.73656456700327] [112.10484685050491 164.07380304920997] - sage: A = matrix(CDF, 2, [1,2+I,3*I,4]); A + sage: A = matrix(CDF, 2, [1,2+I,3*I,4]); A # needs sage.symbolic [ 1.0 2.0 + 1.0*I] [ 3.0*I 4.0] - sage: A.exp() # tol 1.1e-14 + sage: A.exp() # tol 1.1e-14 # needs sage.symbolic [-19.614602953804912 + 12.517743846762578*I 3.7949636449582176 + 28.88379930658099*I] [ -32.383580980922254 + 21.88423595789845*I 2.269633004093535 + 44.901324827684824*I] @@ -3655,8 +3686,8 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): [51.968956198705044 74.73656456700327] [112.10484685050491 164.07380304920997] - sage: A = matrix(CDF, 2, [1,2+I,3*I,4]) - sage: A.exp() # tol 3e-14 + sage: A = matrix(CDF, 2, [1,2+I,3*I,4]) # needs sage.symbolic + sage: A.exp() # tol 3e-14 # needs sage.symbolic [-19.614602953804923 + 12.51774384676257*I 3.7949636449582016 + 28.883799306580997*I] [-32.38358098092227 + 21.884235957898433*I 2.2696330040935084 + 44.90132482768484*I] """ @@ -3690,6 +3721,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): EXAMPLES:: + sage: # needs sage.symbolic sage: a = matrix(CDF, [[1, 1e-4r, 1+1e-100jr], [1e-8+3j, 0, 1e-58r]]) sage: a [ 1.0 0.0001 1.0 + 1e-100*I] @@ -3765,6 +3797,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): EXAMPLES:: + sage: # needs sage.symbolic sage: a = matrix(CDF, [[1, -2+I, 0, -3*I], [2, 2, -2, 2], [-3, -3, -3, -2]]) sage: a [ 1.0 -2.0 + 1.0*I 0.0 -3.0*I] @@ -3803,6 +3836,7 @@ cdef class Matrix_double_dense(Matrix_numpy_dense): EXAMPLES:: + sage: # needs sage.symbolic sage: a = matrix(CDF, [[1, 2, -3], [-2+I, 2, -3], [0, -2, -3], [-3*I, 2, -2]]) sage: a [ 1.0 2.0 -3.0] diff --git a/src/sage/matrix/matrix_double_sparse.pxd b/src/sage/matrix/matrix_double_sparse.pxd index ba8b303878b..0a292404338 100644 --- a/src/sage/matrix/matrix_double_sparse.pxd +++ b/src/sage/matrix/matrix_double_sparse.pxd @@ -1,4 +1,5 @@ -from .matrix_generic_sparse cimport Matrix_generic_sparse +from sage.matrix.matrix_generic_sparse cimport Matrix_generic_sparse + cdef class Matrix_double_sparse(Matrix_generic_sparse): pass diff --git a/src/sage/matrix/matrix_double_sparse.pyx b/src/sage/matrix/matrix_double_sparse.pyx index adf285a311c..cac826d7777 100644 --- a/src/sage/matrix/matrix_double_sparse.pyx +++ b/src/sage/matrix/matrix_double_sparse.pyx @@ -1,5 +1,6 @@ -from .matrix2 cimport Matrix -from .matrix_generic_sparse cimport Matrix_generic_sparse +from sage.matrix.matrix2 cimport Matrix +from sage.matrix.matrix_generic_sparse cimport Matrix_generic_sparse + cdef class Matrix_double_sparse(Matrix_generic_sparse): r""" @@ -143,6 +144,7 @@ cdef class Matrix_double_sparse(Matrix_generic_sparse): :: + sage: # needs sage.rings.complex_double sage.symbolic sage: A = matrix(CDF, [[ 2, 4 + 2*I, 6 - 4*I], ....: [ -2*I + 4, 11, 10 - 12*I], ....: [ 4*I + 6, 10 + 12*I, 37]]) @@ -168,11 +170,12 @@ cdef class Matrix_double_sparse(Matrix_generic_sparse): sage: (A - L*L.T).norm(1) < 1e-10 True sage: B = A.dense_matrix() - sage: (B.cholesky() - L).norm(1) < 1e-10 + sage: (B.cholesky() - L).norm(1) < 1e-10 # needs scipy True :: + sage: # needs sage.rings.complex_double sage.symbolic sage: n = ZZ.random_element(1,5) sage: A = matrix.random(CDF, n, sparse=True) sage: I = matrix.identity(CDF, n, sparse=True) @@ -181,7 +184,7 @@ cdef class Matrix_double_sparse(Matrix_generic_sparse): sage: (A - L*L.H).norm(1) < 1e-10 True sage: B = A.dense_matrix() - sage: (B.cholesky() - L).norm(1) < 1e-10 + sage: (B.cholesky() - L).norm(1) < 1e-10 # needs scipy True """ cdef Matrix L # output matrix diff --git a/src/sage/matrix/matrix_gap.pxd b/src/sage/matrix/matrix_gap.pxd index bb4801258cf..da8fe7e1277 100644 --- a/src/sage/matrix/matrix_gap.pxd +++ b/src/sage/matrix/matrix_gap.pxd @@ -1,9 +1,9 @@ -from .matrix_dense cimport Matrix_dense +from sage.matrix.matrix_dense cimport Matrix_dense from sage.libs.gap.element cimport GapElement + cdef class Matrix_gap(Matrix_dense): cdef GapElement _libgap cpdef GapElement gap(self) noexcept cdef Matrix_gap _new(self, Py_ssize_t nrows, Py_ssize_t ncols) noexcept - diff --git a/src/sage/matrix/matrix_gap.pyx b/src/sage/matrix/matrix_gap.pyx index 853cb0626a1..9e1d1066a48 100644 --- a/src/sage/matrix/matrix_gap.pyx +++ b/src/sage/matrix/matrix_gap.pyx @@ -13,7 +13,7 @@ Wrappers on GAP matrices from sage.libs.gap.libgap import libgap from sage.structure.element cimport Matrix -from .args cimport MatrixArgs_init +from sage.matrix.args cimport MatrixArgs_init cdef class Matrix_gap(Matrix_dense): @@ -48,6 +48,7 @@ cdef class Matrix_gap(Matrix_dense): sage: m.transpose().parent() is M True + sage: # needs sage.rings.number_field sage: UCF = UniversalCyclotomicField() sage: M = MatrixSpace(UCF, 3, implementation='gap') sage: m = M([UCF.zeta(i) for i in range(1,10)]) @@ -60,7 +61,9 @@ cdef class Matrix_gap(Matrix_dense): TESTS:: - sage: for ring in [ZZ, QQ, UniversalCyclotomicField(), GF(2), GF(3)]: + sage: rings = [ZZ, QQ, UniversalCyclotomicField(), GF(2), GF(3)] + sage: rings += [UniversalCyclotomicField()] # needs sage.rings.number_field + sage: for ring in rings: ....: M = MatrixSpace(ring, 2, implementation='gap') ....: TestSuite(M).run(skip=['_test_construction']) ....: M = MatrixSpace(ring, 2, 3, implementation='gap') @@ -233,6 +236,7 @@ cdef class Matrix_gap(Matrix_dense): sage: m1 != m3 True + sage: # needs sage.rings.number_field sage: UCF = UniversalCyclotomicField() sage: M = MatrixSpace(UCF, 2, implementation='gap') sage: m1 = M([E(2), E(3), 0, E(4)]) @@ -367,6 +371,7 @@ cdef class Matrix_gap(Matrix_dense): sage: parent(M(1).determinant()) Rational Field + sage: # needs sage.rings.number_field sage: M = MatrixSpace(UniversalCyclotomicField(), 1, implementation='gap') sage: parent(M(1).determinant()) Universal Cyclotomic Field @@ -395,6 +400,7 @@ cdef class Matrix_gap(Matrix_dense): sage: parent(M(1).trace()) Rational Field + sage: # needs sage.rings.number_field sage: M = MatrixSpace(UniversalCyclotomicField(), 1, implementation='gap') sage: parent(M(1).trace()) Universal Cyclotomic Field diff --git a/src/sage/matrix/matrix_generic_dense.pxd b/src/sage/matrix/matrix_generic_dense.pxd index 86963fe05df..839efd22159 100644 --- a/src/sage/matrix/matrix_generic_dense.pxd +++ b/src/sage/matrix/matrix_generic_dense.pxd @@ -1,4 +1,5 @@ -from .matrix_dense cimport Matrix_dense +from sage.matrix.matrix_dense cimport Matrix_dense + cdef class Matrix_generic_dense(Matrix_dense): cdef list _entries diff --git a/src/sage/matrix/matrix_generic_dense.pyx b/src/sage/matrix/matrix_generic_dense.pyx index 3e51e0d1703..a4d0615971d 100644 --- a/src/sage/matrix/matrix_generic_dense.pyx +++ b/src/sage/matrix/matrix_generic_dense.pyx @@ -8,8 +8,8 @@ from cpython.number cimport * from cpython.ref cimport * cimport sage.matrix.matrix_dense as matrix_dense -from . import matrix_dense -from .args cimport MatrixArgs_init +from sage.matrix import matrix_dense +from sage.matrix.args cimport MatrixArgs_init cimport sage.matrix.matrix as matrix diff --git a/src/sage/matrix/matrix_generic_sparse.pxd b/src/sage/matrix/matrix_generic_sparse.pxd index f4d1465318f..461fb38e18b 100644 --- a/src/sage/matrix/matrix_generic_sparse.pxd +++ b/src/sage/matrix/matrix_generic_sparse.pxd @@ -1,4 +1,5 @@ -from .matrix_sparse cimport Matrix_sparse +from sage.matrix.matrix_sparse cimport Matrix_sparse + cdef class Matrix_generic_sparse(Matrix_sparse): cdef dict _entries diff --git a/src/sage/matrix/matrix_generic_sparse.pyx b/src/sage/matrix/matrix_generic_sparse.pyx index 2570d08b55d..bd1f860c167 100644 --- a/src/sage/matrix/matrix_generic_sparse.pyx +++ b/src/sage/matrix/matrix_generic_sparse.pyx @@ -55,7 +55,7 @@ EXAMPLES:: """ cimport sage.matrix.matrix_sparse as matrix_sparse cimport sage.structure.element -from .args cimport MatrixArgs_init +from sage.matrix.args cimport MatrixArgs_init cdef class Matrix_generic_sparse(matrix_sparse.Matrix_sparse): @@ -451,7 +451,7 @@ def Matrix_sparse_from_rows(X): if not X: raise ArithmeticError("X must be nonempty") - from . import matrix_space + from sage.matrix import matrix_space entries = {} R = X[0].base_ring() ncols = X[0].degree() diff --git a/src/sage/matrix/matrix_gf2e_dense.pxd b/src/sage/matrix/matrix_gf2e_dense.pxd index 70391868740..485266e517b 100644 --- a/src/sage/matrix/matrix_gf2e_dense.pxd +++ b/src/sage/matrix/matrix_gf2e_dense.pxd @@ -1,6 +1,6 @@ from sage.libs.m4rie cimport mzed_t from sage.libs.m4ri cimport m4ri_word -from .matrix_dense cimport Matrix_dense +from sage.matrix.matrix_dense cimport Matrix_dense cdef class Matrix_gf2e_dense(Matrix_dense): diff --git a/src/sage/matrix/matrix_gf2e_dense.pyx b/src/sage/matrix/matrix_gf2e_dense.pyx index 25db5315598..c1c3ee3a0c4 100644 --- a/src/sage/matrix/matrix_gf2e_dense.pyx +++ b/src/sage/matrix/matrix_gf2e_dense.pyx @@ -95,7 +95,7 @@ from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF from sage.misc.randstate cimport randstate, current_randstate from sage.matrix.matrix_mod2_dense cimport Matrix_mod2_dense -from .args cimport SparseEntry, MatrixArgs_init +from sage.matrix.args cimport SparseEntry, MatrixArgs_init from sage.libs.m4ri cimport m4ri_word, mzd_copy from sage.libs.m4rie cimport * diff --git a/src/sage/matrix/matrix_integer_dense.pxd b/src/sage/matrix/matrix_integer_dense.pxd index d606deacc45..dcc69db5d72 100644 --- a/src/sage/matrix/matrix_integer_dense.pxd +++ b/src/sage/matrix/matrix_integer_dense.pxd @@ -1,7 +1,7 @@ from sage.libs.gmp.types cimport * from sage.libs.flint.types cimport fmpz_mat_t -from .matrix_dense cimport Matrix_dense +from sage.matrix.matrix_dense cimport Matrix_dense from sage.rings.integer cimport Integer from sage.ext.mod_int cimport * diff --git a/src/sage/matrix/matrix_integer_dense.pyx b/src/sage/matrix/matrix_integer_dense.pyx index 207aa73a592..5488177dae1 100644 --- a/src/sage/matrix/matrix_integer_dense.pyx +++ b/src/sage/matrix/matrix_integer_dense.pyx @@ -86,7 +86,7 @@ from sage.structure.proof.proof import get_flag as get_proof_flag from sage.structure.richcmp cimport rich_to_bool from sage.misc.randstate cimport randstate, current_randstate -from .args cimport SparseEntry, MatrixArgs_init +from sage.matrix.args cimport SparseEntry, MatrixArgs_init ######################################################### # PARI C library @@ -114,18 +114,18 @@ from sage.rings.polynomial.polynomial_integer_dense_flint cimport Polynomial_int from sage.structure.element cimport Element, Vector from sage.structure.element import is_Vector -from .matrix_modn_dense_float cimport Matrix_modn_dense_template -from .matrix_modn_dense_float cimport Matrix_modn_dense_float -from .matrix_modn_dense_double cimport Matrix_modn_dense_double +from sage.matrix.matrix_modn_dense_float cimport Matrix_modn_dense_template +from sage.matrix.matrix_modn_dense_float cimport Matrix_modn_dense_float +from sage.matrix.matrix_modn_dense_double cimport Matrix_modn_dense_double -from .matrix_mod2_dense import Matrix_mod2_dense -from .matrix_mod2_dense cimport Matrix_mod2_dense +from sage.matrix.matrix_mod2_dense import Matrix_mod2_dense +from sage.matrix.matrix_mod2_dense cimport Matrix_mod2_dense from sage.rings.finite_rings.finite_field_constructor import GF -from .matrix2 import decomp_seq +from sage.matrix.matrix2 import decomp_seq -from .matrix cimport Matrix +from sage.matrix.matrix cimport Matrix cimport sage.structure.element @@ -1592,8 +1592,8 @@ cdef class Matrix_integer_dense(Matrix_dense): return Matrix_mod2_dense(MS, self, True, True) cdef _mod_int_c(self, mod_int p) noexcept: - from .matrix_modn_dense_float import MAX_MODULUS as MAX_MODULUS_FLOAT - from .matrix_modn_dense_double import MAX_MODULUS as MAX_MODULUS_DOUBLE + from sage.matrix.matrix_modn_dense_float import MAX_MODULUS as MAX_MODULUS_FLOAT + from sage.matrix.matrix_modn_dense_double import MAX_MODULUS as MAX_MODULUS_DOUBLE cdef Py_ssize_t i, j @@ -1626,8 +1626,8 @@ cdef class Matrix_integer_dense(Matrix_dense): raise ValueError("p to big.") def _reduce(self, moduli): - from .matrix_modn_dense_float import MAX_MODULUS as MAX_MODULUS_FLOAT - from .matrix_modn_dense_double import MAX_MODULUS as MAX_MODULUS_DOUBLE + from sage.matrix.matrix_modn_dense_float import MAX_MODULUS as MAX_MODULUS_FLOAT + from sage.matrix.matrix_modn_dense_double import MAX_MODULUS as MAX_MODULUS_DOUBLE if isinstance(moduli, (int, Integer)): return self._mod_int(moduli) @@ -2051,7 +2051,7 @@ cdef class Matrix_integer_dense(Matrix_dense): if transformation: U = U[:r] elif algorithm == "padic": - from . import matrix_integer_dense_hnf + from sage.matrix import matrix_integer_dense_hnf if transformation: H_m, U = matrix_integer_dense_hnf.hnf_with_transformation(self, proof=proof) if not include_zero_rows: @@ -2098,7 +2098,7 @@ cdef class Matrix_integer_dense(Matrix_dense): H_m.set_immutable() if pivots is None: - from .matrix_integer_dense_hnf import pivots_of_hnf_matrix + from sage.matrix.matrix_integer_dense_hnf import pivots_of_hnf_matrix pivots = pivots_of_hnf_matrix(H_m) pivots = tuple(pivots) rank = len(pivots) @@ -2197,7 +2197,7 @@ cdef class Matrix_integer_dense(Matrix_dense): sage: S = A.saturation(max_dets=2) """ proof = get_proof_flag(proof, "linear_algebra") - from .matrix_integer_dense_saturation import saturation + from sage.matrix.matrix_integer_dense_saturation import saturation return saturation(self, p=p, proof=proof, max_dets=max_dets) def index_in_saturation(self, proof=None): @@ -2235,7 +2235,7 @@ cdef class Matrix_integer_dense(Matrix_dense): [1 1 1] """ proof = get_proof_flag(proof, "linear_algebra") - from .matrix_integer_dense_saturation import index_in_saturation + from sage.matrix.matrix_integer_dense_saturation import index_in_saturation return index_in_saturation(self, proof=proof) def pivots(self): @@ -3402,7 +3402,7 @@ cdef class Matrix_integer_dense(Matrix_dense): ... ZeroDivisionError: The modulus cannot be zero """ - from .misc_flint import matrix_integer_dense_rational_reconstruction + from sage.matrix.misc_flint import matrix_integer_dense_rational_reconstruction return matrix_integer_dense_rational_reconstruction(self, N) def randomize(self, density=1, x=None, y=None, distribution=None, @@ -3766,7 +3766,7 @@ cdef class Matrix_integer_dense(Matrix_dense): fmpz_clear(e) d = det elif algorithm == 'padic': - from . import matrix_integer_dense_hnf + from sage.matrix import matrix_integer_dense_hnf d = matrix_integer_dense_hnf.det_padic(self, proof=proof, stabilize=stabilize) elif algorithm == 'linbox': if proof: @@ -4233,7 +4233,7 @@ cdef class Matrix_integer_dense(Matrix_dense): # in the non-full rank case. In any case, we do this for now, # since rank is very fast and infinite loops are evil. if check_rank and self.rank() < self.nrows(): - from .matrix2 import NotFullRankError + from sage.matrix.matrix2 import NotFullRankError raise NotFullRankError if not self.is_square(): @@ -4680,7 +4680,7 @@ cdef class Matrix_integer_dense(Matrix_dense): d = Integer(1) return pivots, nonpivots, X, d - from .matrix_modn_dense_double import MAX_MODULUS + from sage.matrix.matrix_modn_dense_double import MAX_MODULUS A = self # Step 1: Compute the rank @@ -4879,7 +4879,7 @@ cdef class Matrix_integer_dense(Matrix_dense): """ cdef Py_ssize_t i, j, n = self._nrows, m = self._ncols - from .constructor import matrix + from sage.matrix.constructor import matrix # 0. Base case if self.nrows() == 0: @@ -5584,7 +5584,7 @@ cdef class Matrix_integer_dense(Matrix_dense): [ 3.0 5.0] """ if ring == RDF: - from .change_ring import integer_to_real_double_dense + from sage.matrix.change_ring import integer_to_real_double_dense return integer_to_real_double_dense(self) else: raise NotImplementedError diff --git a/src/sage/matrix/matrix_integer_sparse.pxd b/src/sage/matrix/matrix_integer_sparse.pxd index d69b4879dc5..fa130f9e680 100644 --- a/src/sage/matrix/matrix_integer_sparse.pxd +++ b/src/sage/matrix/matrix_integer_sparse.pxd @@ -1,6 +1,6 @@ from sage.modules.vector_integer_sparse cimport mpz_vector from sage.ext.mod_int cimport mod_int -from .matrix_sparse cimport Matrix_sparse +from sage.matrix.matrix_sparse cimport Matrix_sparse cdef class Matrix_integer_sparse(Matrix_sparse): cdef mpz_vector* _matrix diff --git a/src/sage/matrix/matrix_integer_sparse.pyx b/src/sage/matrix/matrix_integer_sparse.pyx index 0712500e67d..27f5cdfac0f 100644 --- a/src/sage/matrix/matrix_integer_sparse.pyx +++ b/src/sage/matrix/matrix_integer_sparse.pyx @@ -53,15 +53,15 @@ from sage.libs.gmp.mpz cimport * from sage.rings.integer cimport Integer from sage.rings.polynomial.polynomial_integer_dense_flint cimport Polynomial_integer_dense_flint -from .matrix cimport Matrix +from sage.matrix.matrix cimport Matrix -from .args cimport SparseEntry, MatrixArgs_init -from .matrix_integer_dense cimport Matrix_integer_dense +from sage.matrix.args cimport SparseEntry, MatrixArgs_init +from sage.matrix.matrix_integer_dense cimport Matrix_integer_dense from sage.libs.flint.fmpz cimport fmpz_set_mpz, fmpz_get_mpz from sage.libs.flint.fmpz_poly cimport fmpz_poly_fit_length, fmpz_poly_set_coeff_mpz, _fmpz_poly_set_length from sage.libs.flint.fmpz_mat cimport fmpz_mat_entry -from .matrix_modn_sparse cimport Matrix_modn_sparse +from sage.matrix.matrix_modn_sparse cimport Matrix_modn_sparse from sage.structure.element cimport Element import sage.matrix.matrix_space as matrix_space @@ -421,7 +421,7 @@ cdef class Matrix_integer_sparse(Matrix_sparse): ... ZeroDivisionError: The modulus cannot be zero """ - from .misc import matrix_integer_sparse_rational_reconstruction + from sage.matrix.misc import matrix_integer_sparse_rational_reconstruction return matrix_integer_sparse_rational_reconstruction(self, N) def _right_kernel_matrix(self, **kwds): @@ -1037,7 +1037,7 @@ cdef class Matrix_integer_sparse(Matrix_sparse): [0 2] """ if check_rank and self.rank() < self.nrows(): - from .matrix2 import NotFullRankError + from sage.matrix.matrix2 import NotFullRankError raise NotFullRankError if self.base_ring() != B.base_ring(): @@ -1230,7 +1230,7 @@ cdef class Matrix_integer_sparse(Matrix_sparse): if self._nrows == 0 or self._ncols == 0: raise ValueError("not implemented for nrows=0 or ncols=0") - from .constructor import matrix + from sage.matrix.constructor import matrix from sage.modules.free_module_element import vector cdef Matrix_integer_dense B diff --git a/src/sage/matrix/matrix_mod2_dense.pyx b/src/sage/matrix/matrix_mod2_dense.pyx index 98708b4e9fb..1db7e22aa1a 100644 --- a/src/sage/matrix/matrix_mod2_dense.pyx +++ b/src/sage/matrix/matrix_mod2_dense.pyx @@ -109,7 +109,7 @@ from cysignals.memory cimport check_malloc, sig_free from cysignals.signals cimport sig_on, sig_str, sig_off cimport sage.matrix.matrix_dense as matrix_dense -from .args cimport SparseEntry, MatrixArgs_init +from sage.matrix.args cimport SparseEntry, MatrixArgs_init from libc.stdio cimport * from sage.structure.element cimport (Matrix, Vector) from sage.modules.free_module_element cimport FreeModuleElement diff --git a/src/sage/matrix/matrix_modn_dense_template.pxi b/src/sage/matrix/matrix_modn_dense_template.pxi index 55cff5b9ac7..14df7a38884 100644 --- a/src/sage/matrix/matrix_modn_dense_template.pxi +++ b/src/sage/matrix/matrix_modn_dense_template.pxi @@ -123,7 +123,7 @@ from sage.structure.proof.proof import get_flag as get_proof_flag from sage.structure.richcmp cimport rich_to_bool from sage.misc.randstate cimport randstate, current_randstate import sage.matrix.matrix_space as matrix_space -from .args cimport SparseEntry, MatrixArgs_init +from sage.matrix.args cimport SparseEntry, MatrixArgs_init from sage.cpython.string cimport char_to_str @@ -465,7 +465,7 @@ cdef class Matrix_modn_dense_template(Matrix_dense): TESTS:: sage: import gc - sage: for i in range(10): # needs sage.rings.finite_rings + sage: for i in range(10): # needs sage.libs.linbox sage.rings.finite_rings ....: A = random_matrix(GF(7),1000,1000) ....: B = random_matrix(Integers(10),1000,1000) ....: C = random_matrix(GF(16007),1000,1000) diff --git a/src/sage/matrix/matrix_modn_sparse.pyx b/src/sage/matrix/matrix_modn_sparse.pyx index 235fc4e7b81..2a399790ca3 100644 --- a/src/sage/matrix/matrix_modn_sparse.pyx +++ b/src/sage/matrix/matrix_modn_sparse.pyx @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Sparse matrices over `\ZZ/n\ZZ` for `n` small @@ -109,6 +108,7 @@ from sage.matrix.args cimport SparseEntry, MatrixArgs_init from sage.matrix.matrix2 import Matrix as Matrix2 from sage.matrix.matrix_dense cimport Matrix_dense from sage.matrix.matrix_integer_dense cimport Matrix_integer_dense +from sage.matrix.matrix_sparse cimport Matrix_sparse from sage.misc.verbose import verbose, get_verbose from sage.modules.vector_integer_dense cimport Vector_integer_dense from sage.modules.vector_integer_sparse cimport * @@ -932,7 +932,7 @@ cdef class Matrix_modn_sparse(Matrix_sparse): [0 2] """ if check_rank and self.rank() < self.nrows(): - from .matrix2 import NotFullRankError + from sage.matrix.matrix2 import NotFullRankError raise NotFullRankError if self.base_ring() != B.base_ring(): @@ -1111,7 +1111,7 @@ cdef class Matrix_modn_sparse(Matrix_sparse): if self._nrows == 0 or self._ncols == 0: raise ValueError("not implemented for nrows=0 or ncols=0") - from .constructor import matrix + from sage.matrix.constructor import matrix from sage.modules.free_module_element import vector cdef Matrix_integer_dense B diff --git a/src/sage/matrix/matrix_numpy_dense.pxd b/src/sage/matrix/matrix_numpy_dense.pxd index fafc6fda5f7..150f9d59551 100644 --- a/src/sage/matrix/matrix_numpy_dense.pxd +++ b/src/sage/matrix/matrix_numpy_dense.pxd @@ -1,6 +1,7 @@ -from .matrix_dense cimport Matrix_dense cimport numpy as cnumpy +from sage.matrix.matrix_dense cimport Matrix_dense + cdef class Matrix_numpy_dense(Matrix_dense): cdef object _numpy_dtype diff --git a/src/sage/matrix/matrix_numpy_dense.pyx b/src/sage/matrix/matrix_numpy_dense.pyx index d0e55fa927a..78cf21022f3 100644 --- a/src/sage/matrix/matrix_numpy_dense.pyx +++ b/src/sage/matrix/matrix_numpy_dense.pyx @@ -40,7 +40,7 @@ AUTHORS: # https://www.gnu.org/licenses/ # **************************************************************************** -from .args cimport MatrixArgs_init +from sage.matrix.args cimport MatrixArgs_init cimport sage.structure.element cimport numpy as cnumpy @@ -134,7 +134,7 @@ cdef class Matrix_numpy_dense(Matrix_dense): [0.0 1.0 2.0] [3.0 4.0 5.0] [6.0 7.0 8.0] - sage: matrix(CDF,2,2,[CDF(1+I)*j for j in range(4)]) + sage: matrix(CDF,2,2,[CDF(1+I)*j for j in range(4)]) # needs sage.symbolic [ 0.0 1.0 + 1.0*I] [2.0 + 2.0*I 3.0 + 3.0*I] """ @@ -308,8 +308,8 @@ cdef class Matrix_numpy_dense(Matrix_dense): Complex entries are supported (:trac:`27831`). :: - sage: a = matrix(CDF, [(21, 0.6 + 18.5*i), (0.6 - 18.5*i, 21)]) - sage: a.is_symmetric() + sage: a = matrix(CDF, [(21, 0.6 + 18.5*i), (0.6 - 18.5*i, 21)]) # needs sage.symbolic + sage: a.is_symmetric() # needs sage.symbolic False """ cdef Py_ssize_t i, j diff --git a/src/sage/matrix/matrix_numpy_integer_dense.pxd b/src/sage/matrix/matrix_numpy_integer_dense.pxd index c74a2c7511c..3116f89d8e2 100644 --- a/src/sage/matrix/matrix_numpy_integer_dense.pxd +++ b/src/sage/matrix/matrix_numpy_integer_dense.pxd @@ -1,4 +1,4 @@ -from .matrix_numpy_dense cimport Matrix_numpy_dense +from sage.matrix.matrix_numpy_dense cimport Matrix_numpy_dense cdef class Matrix_numpy_integer_dense(Matrix_numpy_dense): diff --git a/src/sage/matrix/matrix_polynomial_dense.pyx b/src/sage/matrix/matrix_polynomial_dense.pyx index 10d9a9248b6..31a13cd83d6 100644 --- a/src/sage/matrix/matrix_polynomial_dense.pyx +++ b/src/sage/matrix/matrix_polynomial_dense.pyx @@ -998,7 +998,6 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): (2*x^3 + x^2, 5*x^3 + x^2 + 5*x + 6, 4*x^3 + 6*x^2 + 4*x) sage: B == A*X % x**4 True - sage: B = Matrix(pR, 3, 2, ....: [[5*x^2 + 6*x + 3, 4*x^2 + 6*x + 4], ....: [ x^2 + 4*x + 2, 5*x + 2], @@ -2010,7 +2009,7 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): Demonstrating the ``ordered`` option:: - sage: P.leading_positions() # needs sage.combinat + sage: P.leading_positions() [2, 1] sage: PP = M.weak_popov_form(ordered=True); PP [ 2 4*x^2 + 2*x + 4 5] @@ -2129,12 +2128,12 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): sage: A = matrix(PF,[[1, a*x^17 + 1 ], ....: [0, a*x^11 + a^2*x^7 + 1 ]]) sage: M = A.__copy__() - sage: U = M._weak_popov_form(transformation=True) # needs sage.combinat - sage: U * A == M # needs sage.combinat + sage: U = M._weak_popov_form(transformation=True) + sage: U * A == M True - sage: M.is_weak_popov() # needs sage.combinat + sage: M.is_weak_popov() True - sage: U.is_invertible() # needs sage.combinat + sage: U.is_invertible() True sage: PF. = QQ[] @@ -2826,7 +2825,7 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): [ 6*x + 3 5*x^2 + 6 3] ) - sage: A.right_quo_rem(B[:2,:]) # matrix 2 x 3, full row rank + sage: A.right_quo_rem(B[:2,:]) # matrix 2 x 3, full row rank # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: division of these matrices does not admit a remainder @@ -3316,7 +3315,7 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): ....: [ 17, 86, x^2+77*x+16, 76*x+29, 90*x+78], ....: [ 44, 36, 3*x+42, x^2+50*x+26, 85*x+44], ....: [ 2, 22, 54*x+94, 73*x+24, x^2+2*x+25]]) - sage: appbas.is_minimal_approximant_basis( + sage: appbas.is_minimal_approximant_basis( # needs sage.libs.pari ....: pmat, order, shifts, row_wise=True, normal_form=True) True @@ -3326,7 +3325,7 @@ cdef class Matrix_polynomial_dense(Matrix_generic_dense): contained in the set of approximants for ``pmat`` at order 8:: sage: M = x^8 * Matrix.identity(pR, 5) - sage: M.is_minimal_approximant_basis(pmat, 8) + sage: M.is_minimal_approximant_basis(pmat, 8) # needs sage.libs.pari False Since ``pmat`` is a single column, with nonzero constant coefficient, diff --git a/src/sage/matrix/matrix_rational_dense.pxd b/src/sage/matrix/matrix_rational_dense.pxd index 64d2c646e51..6a6347f4926 100644 --- a/src/sage/matrix/matrix_rational_dense.pxd +++ b/src/sage/matrix/matrix_rational_dense.pxd @@ -1,5 +1,5 @@ from sage.libs.flint.types cimport fmpz_t, fmpq_mat_t -from .matrix_dense cimport Matrix_dense +from sage.matrix.matrix_dense cimport Matrix_dense cdef class Matrix_rational_dense(Matrix_dense): cdef fmpq_mat_t _matrix diff --git a/src/sage/matrix/matrix_rational_dense.pyx b/src/sage/matrix/matrix_rational_dense.pyx index 4f1e5e415e1..8b72c9c56f2 100644 --- a/src/sage/matrix/matrix_rational_dense.pyx +++ b/src/sage/matrix/matrix_rational_dense.pyx @@ -104,9 +104,9 @@ cimport sage.structure.element from sage.structure.richcmp cimport rich_to_bool from sage.rings.rational cimport Rational -from .matrix cimport Matrix -from .args cimport SparseEntry, MatrixArgs_init -from .matrix_integer_dense cimport Matrix_integer_dense, _lift_crt +from sage.matrix.matrix cimport Matrix +from sage.matrix.args cimport SparseEntry, MatrixArgs_init +from sage.matrix.matrix_integer_dense cimport Matrix_integer_dense, _lift_crt from sage.structure.element cimport Element, Vector from sage.rings.integer cimport Integer from sage.rings.ring import is_Ring @@ -114,7 +114,7 @@ from sage.rings.integer_ring import ZZ, is_IntegerRing import sage.rings.abc from sage.rings.rational_field import QQ -from .matrix2 import decomp_seq +from sage.matrix.matrix2 import decomp_seq from sage.misc.verbose import verbose # ######################################################## @@ -1406,7 +1406,7 @@ cdef class Matrix_rational_dense(Matrix_dense): tm = verbose("computing right kernel matrix over the rationals for %sx%s matrix" % (self.nrows(), self.ncols()),level=1) # _rational_kernel_flint() gets the zero-row case wrong, fix it there if self.nrows()==0: - from .constructor import identity_matrix + from sage.matrix.constructor import identity_matrix K = identity_matrix(QQ, self.ncols()) else: A, _ = self._clear_denom() @@ -1473,7 +1473,7 @@ cdef class Matrix_rational_dense(Matrix_dense): A.subdivide(self.subdivisions()) return A - from .matrix_modn_dense_double import MAX_MODULUS + from sage.matrix.matrix_modn_dense_double import MAX_MODULUS if isinstance(R, sage.rings.abc.IntegerModRing) and R.order() < MAX_MODULUS: b = R.order() A, d = self._clear_denom() @@ -1803,7 +1803,7 @@ cdef class Matrix_rational_dense(Matrix_dense): [ 0 0 1 1 3 0] [ 0 0 0 0 0 1] """ - from .misc import matrix_rational_echelon_form_multimodular + from sage.matrix.misc import matrix_rational_echelon_form_multimodular E, pivots = matrix_rational_echelon_form_multimodular(self, height_guess, proof=proof) self.clear_cache() fmpq_mat_swap(self._matrix, (E)._matrix) diff --git a/src/sage/matrix/matrix_rational_sparse.pxd b/src/sage/matrix/matrix_rational_sparse.pxd index 56ff6ff26a3..c754850bee9 100644 --- a/src/sage/matrix/matrix_rational_sparse.pxd +++ b/src/sage/matrix/matrix_rational_sparse.pxd @@ -1,6 +1,6 @@ from sage.libs.gmp.types cimport mpz_t from sage.modules.vector_rational_sparse cimport mpq_vector -from .matrix_sparse cimport Matrix_sparse +from sage.matrix.matrix_sparse cimport Matrix_sparse cdef class Matrix_rational_sparse(Matrix_sparse): diff --git a/src/sage/matrix/matrix_rational_sparse.pyx b/src/sage/matrix/matrix_rational_sparse.pyx index 497c58408b7..fcdc75b43d1 100644 --- a/src/sage/matrix/matrix_rational_sparse.pyx +++ b/src/sage/matrix/matrix_rational_sparse.pyx @@ -35,8 +35,8 @@ from cpython.sequence cimport * from sage.rings.rational cimport Rational from sage.rings.integer cimport Integer -from .matrix cimport Matrix -from .args cimport SparseEntry, MatrixArgs_init +from sage.matrix.matrix cimport Matrix +from sage.matrix.args cimport SparseEntry, MatrixArgs_init from sage.libs.gmp.mpz cimport * from sage.libs.gmp.mpq cimport * @@ -51,8 +51,8 @@ cimport sage.structure.element import sage.matrix.matrix_space -from .matrix_integer_sparse cimport Matrix_integer_sparse -from .matrix_rational_dense cimport Matrix_rational_dense +from sage.matrix.matrix_integer_sparse cimport Matrix_integer_sparse +from sage.matrix.matrix_rational_dense cimport Matrix_rational_dense cdef class Matrix_rational_sparse(Matrix_sparse): @@ -583,7 +583,7 @@ cdef class Matrix_rational_sparse(Matrix_sparse): - height_guess -- integer or None - proof -- boolean (default: True) """ - from .misc import matrix_rational_echelon_form_multimodular + from sage.matrix.misc import matrix_rational_echelon_form_multimodular cdef Matrix E E, pivots = matrix_rational_echelon_form_multimodular(self, height_guess=height_guess, proof=proof) diff --git a/src/sage/matrix/matrix_real_double_dense.pxd b/src/sage/matrix/matrix_real_double_dense.pxd index 3be163114c5..d0badf48240 100644 --- a/src/sage/matrix/matrix_real_double_dense.pxd +++ b/src/sage/matrix/matrix_real_double_dense.pxd @@ -1,4 +1,5 @@ -from .matrix_double_dense cimport Matrix_double_dense +from sage.matrix.matrix_double_dense cimport Matrix_double_dense + cdef class Matrix_real_double_dense(Matrix_double_dense): cdef set_unsafe_double(self, Py_ssize_t i, Py_ssize_t j, double value) noexcept diff --git a/src/sage/matrix/matrix_real_double_dense.pyx b/src/sage/matrix/matrix_real_double_dense.pyx index 542638ed17d..1337641bb24 100644 --- a/src/sage/matrix/matrix_real_double_dense.pyx +++ b/src/sage/matrix/matrix_real_double_dense.pyx @@ -60,7 +60,7 @@ cdef class Matrix_real_double_dense(Matrix_double_dense): sage: m**2 [ 7.0 10.0] [15.0 22.0] - sage: n = m^(-1); n # rel tol 1e-15 + sage: n = m^(-1); n # rel tol 1e-15 # needs scipy [-1.9999999999999996 0.9999999999999998] [ 1.4999999999999998 -0.4999999999999999] @@ -70,7 +70,7 @@ cdef class Matrix_real_double_dense(Matrix_double_dense): :: - sage: p,e = m.right_eigenvectors() + sage: p,e = m.right_eigenvectors() # needs scipy The result is a pair ``(p,e)``, where ``p`` is a diagonal matrix of eigenvalues and ``e`` is a matrix whose columns are the @@ -80,7 +80,7 @@ cdef class Matrix_real_double_dense(Matrix_double_dense): `b = [5,6]`:: sage: b = vector(RDF,[5,6]) - sage: m.solve_right(b) # rel tol 1e-15 + sage: m.solve_right(b) # rel tol 1e-15 # needs scipy (-3.9999999999999987, 4.499999999999999) See the methods :meth:`~.Matrix_double_dense.QR`, diff --git a/src/sage/matrix/matrix_space.py b/src/sage/matrix/matrix_space.py index 279eba44511..3795ff4b0fa 100644 --- a/src/sage/matrix/matrix_space.py +++ b/src/sage/matrix/matrix_space.py @@ -107,14 +107,14 @@ def get_matrix_class(R, nrows, ncols, sparse, implementation): sage: from sage.matrix.matrix_space import get_matrix_class - sage: get_matrix_class(ZZ, 4, 5, False, None) + sage: get_matrix_class(ZZ, 4, 5, False, None) # needs sage.libs.linbox - sage: get_matrix_class(ZZ, 4, 5, True, None) + sage: get_matrix_class(ZZ, 4, 5, True, None) # needs sage.libs.linbox - sage: get_matrix_class(ZZ, 3, 3, False, 'flint') + sage: get_matrix_class(ZZ, 3, 3, False, 'flint') # needs sage.libs.linbox - sage: get_matrix_class(ZZ, 3, 3, False, 'gap') # needs sage.modules + sage: get_matrix_class(ZZ, 3, 3, False, 'gap') # needs sage.libs.gap sage: get_matrix_class(ZZ, 3, 3, False, 'generic') @@ -124,24 +124,23 @@ def get_matrix_class(R, nrows, ncols, sparse, implementation): sage: get_matrix_class(GF(2^17), 3, 3, False, None) # needs sage.rings.finite_rings - sage: # needs sage.rings.finite_rings - sage: get_matrix_class(GF(2), 2, 2, False, 'm4ri') + sage: get_matrix_class(GF(2), 2, 2, False, 'm4ri') # needs sage.libs.m4ri - sage: get_matrix_class(GF(4), 2, 2, False, 'm4ri') + sage: get_matrix_class(GF(4), 2, 2, False, 'm4ri') # needs sage.libs.m4ri sage.rings.finite_rings - sage: get_matrix_class(GF(7), 2, 2, False, 'linbox-float') + sage: get_matrix_class(GF(7), 2, 2, False, 'linbox-float') # needs sage.libs.linbox - sage: get_matrix_class(GF(7), 2, 2, False, 'linbox-double') + sage: get_matrix_class(GF(7), 2, 2, False, 'linbox-double') # needs sage.libs.linbox sage: get_matrix_class(RDF, 2, 2, False, 'numpy') # needs numpy - sage: get_matrix_class(CDF, 2, 3, False, 'numpy') # needs numpy + sage: get_matrix_class(CDF, 2, 3, False, 'numpy') # needs numpy sage.rings.complex_double - sage: get_matrix_class(GF(25,'x'), 4, 4, False, 'meataxe') # optional - meataxe, needs sage.rings.finite_rings + sage: get_matrix_class(GF(25,'x'), 4, 4, False, 'meataxe') # optional - meataxe, needs sage.rings.finite_rings - sage: get_matrix_class(IntegerModRing(3), 4, 4, False, 'meataxe') # optional - meataxe + sage: get_matrix_class(IntegerModRing(3), 4, 4, False, 'meataxe') # optional - meataxe sage: get_matrix_class(IntegerModRing(4), 4, 4, False, 'meataxe') Traceback (most recent call last): @@ -159,12 +158,13 @@ def get_matrix_class(R, nrows, ncols, sparse, implementation): sage: get_matrix_class(GF(3), 2, 2, False, 'm4ri') Traceback (most recent call last): ... - ValueError: 'm4ri' matrices are only available for fields of characteristic 2 and order <= 65536 - sage: get_matrix_class(Zmod(2**30), 2, 2, False, 'linbox-float') + ValueError: 'm4ri' matrices are only available for fields of characteristic 2 + and order <= 65536 + sage: get_matrix_class(Zmod(2**30), 2, 2, False, 'linbox-float') # needs sage.libs.linbox Traceback (most recent call last): ... ValueError: 'linbox-float' matrices can only deal with order < 256 - sage: get_matrix_class(Zmod(2**30), 2, 2, False, 'linbox-double') + sage: get_matrix_class(Zmod(2**30), 2, 2, False, 'linbox-double') # needs sage.libs.linbox Traceback (most recent call last): ... ValueError: 'linbox-double' matrices can only deal with order < 94906266 @@ -173,17 +173,17 @@ def get_matrix_class(R, nrows, ncols, sparse, implementation): sage: type(matrix(SR, 2, 2, 0, sparse=True)) # needs sage.symbolic - sage: type(matrix(GF(7), 2, range(4))) # needs sage.rings.finite_rings + sage: type(matrix(GF(7), 2, range(4))) # needs sage.libs.linbox - sage: type(matrix(GF(16007), 2, range(4))) # needs sage.rings.finite_rings + sage: type(matrix(GF(16007), 2, range(4))) # needs sage.libs.linbox sage: type(matrix(CBF, 2, range(4))) # needs sage.libs.flint - sage: type(matrix(GF(2), 2, range(4))) # needs sage.rings.finite_rings + sage: type(matrix(GF(2), 2, range(4))) # needs sage.libs.m4ri - sage: type(matrix(GF(64, 'z'), 2, range(4))) # needs sage.rings.finite_rings + sage: type(matrix(GF(64, 'z'), 2, range(4))) # needs sage.libs.m4ri sage.rings.finite_rings - sage: type(matrix(GF(125, 'z'), 2, range(4))) # optional - meataxe # needs sage.rings.finite_rings + sage: type(matrix(GF(125, 'z'), 2, range(4))) # optional - meataxe, needs sage.rings.finite_rings """ @@ -496,29 +496,28 @@ class MatrixSpace(UniqueRepresentation, Parent): Check that different implementations play together as expected:: - sage: M1 = MatrixSpace(ZZ, 2, implementation='flint') # needs sage.libs.flint + sage: # needs sage.libs.linbox + sage: M1 = MatrixSpace(ZZ, 2, implementation='flint') sage: M2 = MatrixSpace(ZZ, 2, implementation='generic') - - sage: type(M1(range(4))) # needs sage.libs.flint + sage: type(M1(range(4))) sage: type(M2(range(4))) - - sage: M1(M2.an_element()) # needs sage.libs.flint + sage: M1(M2.an_element()) [ 0 1] [-1 2] - sage: M2(M1.an_element()) # needs sage.libs.flint + sage: M2(M1.an_element()) [ 0 1] [-1 2] - - sage: all((A.get_action(B) is not None) == (A is B) # needs sage.libs.flint + sage: all((A.get_action(B) is not None) == (A is B) ....: for A in [M1, M2] for B in [M1, M2]) True Check that libgap matrices over finite fields are working properly:: - sage: M2 = MatrixSpace(GF(2), 5, implementation='gap') # needs sage.libs.gap sage.rings.finite_rings - sage: M2.one() # needs sage.libs.gap sage.rings.finite_rings + sage: # needs sage.libs.gap + sage: M2 = MatrixSpace(GF(2), 5, implementation='gap') + sage: M2.one() [1 0 0 0 0] [0 1 0 0 0] [0 0 1 0 0] @@ -526,7 +525,7 @@ class MatrixSpace(UniqueRepresentation, Parent): [0 0 0 0 1] sage: m = M2.random_element() sage: M1 = MatrixSpace(GF(2), 5) - sage: M1(m * m) == M1(m) * M1(m) # needs sage.libs.gap sage.rings.finite_rings + sage: M1(m * m) == M1(m) * M1(m) True """ @@ -648,7 +647,8 @@ def __init__(self, base_ring, nrows, ncols, sparse, implementation): Category of infinite enumerated finite dimensional algebras with basis over (euclidean domains and infinite enumerated sets and metric spaces) sage: MatrixSpace(QQ,10).category() - Category of infinite finite dimensional algebras with basis over (number fields and quotient fields and metric spaces) + Category of infinite finite dimensional algebras with basis over + (number fields and quotient fields and metric spaces) TESTS: @@ -769,7 +769,7 @@ def _has_default_implementation(self): sage: MatrixSpace(ZZ, 2, implementation='generic')._has_default_implementation() False - sage: MatrixSpace(ZZ, 2, implementation='flint')._has_default_implementation() + sage: MatrixSpace(ZZ, 2, implementation='flint')._has_default_implementation() # needs sage.libs.linbox True """ default = get_matrix_class(self.base_ring(), self.nrows(), self.ncols(), self.is_sparse(), None) @@ -806,14 +806,14 @@ def _copy_zero(self): EXAMPLES:: sage: MS = MatrixSpace(GF(2), 20, 20) - sage: MS._copy_zero # needs sage.rings.finite_rings + sage: MS._copy_zero False sage: MS = MatrixSpace(GF(3), 20, 20) - sage: MS._copy_zero # needs sage.rings.finite_rings + sage: MS._copy_zero True sage: MS = MatrixSpace(GF(3), 200, 200) - sage: MS._copy_zero # needs sage.rings.finite_rings + sage: MS._copy_zero False sage: MS = MatrixSpace(ZZ,200,200) @@ -880,8 +880,9 @@ def _element_constructor_(self, entries, **kwds): [1 2] [3 4] + sage: # needs sage.modular sage: MS = MatrixSpace(ZZ, 2) - sage: g = Gamma0(5)([1,1,0,1]) # needs sage.modular + sage: g = Gamma0(5)([1,1,0,1]) sage: MS(g) [1 1] [0 1] @@ -901,11 +902,14 @@ def _element_constructor_(self, entries, **kwds): Ensure that :trac:`12020` is fixed:: - sage: rings = [ZZ, QQ, RealField(100), ComplexField(100), RDF, CDF] + sage: rings = [ZZ, QQ, RDF] + sage: rings.extend([RealField(100), ComplexField(100)]) # needs sage.rings.real_mpfr + sage: rings.append(CDF) # needs sage.rings.complex_double sage: rings.append(PolynomialRing(QQ, 'x')) - sage: rings.append(PolynomialRing(CC, 2, 'x')) + sage: rings.append(PolynomialRing(CC, 2, 'x')) # needs sage.rings.real_mpfr sage: rings.append(SR) # needs sage.symbolic - sage: rings.extend([GF(2), GF(11), GF(2^8,'a'), GF(3^19,'a')]) # needs sage.rings.finite_rings + sage: rings.extend([GF(2), GF(11)]) + sage: rings.extend([GF(2^8,'a'), GF(3^19,'a')]) # needs sage.rings.finite_rings sage: x = polygen(QQ) sage: rings.extend([NumberField(x^3 + 2, 'a'), CyclotomicField(4)]) # needs sage.rings.number_field sage: for R in rings: @@ -1017,7 +1021,8 @@ def construction(self): sage: A.parent().construction() (MatrixFunctor, Integer Ring) sage: A.parent().construction()[0](QQ['x']) - Full MatrixSpace of 2 by 2 sparse matrices over Univariate Polynomial Ring in x over Rational Field + Full MatrixSpace of 2 by 2 sparse matrices over + Univariate Polynomial Ring in x over Rational Field sage: parent(A/2) Full MatrixSpace of 2 by 2 sparse matrices over Rational Field """ @@ -1159,8 +1164,8 @@ def _coerce_map_from_(self, S): Coercion map: From: General Linear Group of degree 2 over Finite Field of size 3 To: Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 3 - sage: MS.coerce_map_from(GL(2, 2)) # needs sage.rings.finite_rings - sage: MS.coerce_map_from(Gamma1(5)) # needs sage.rings.finite_rings + sage: MS.coerce_map_from(GL(2, 2)) + sage: MS.coerce_map_from(Gamma1(5)) # needs sage.modular Coercion map: From: Congruence Subgroup Gamma1(5) To: Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 3 @@ -1202,7 +1207,7 @@ def _coerce_map_from_(self, S): poset):: sage: S = [] - sage: S += [MatrixSpace(ZZ, 3, implementation='flint')] # needs sage.libs.flint + sage: S += [MatrixSpace(ZZ, 3, implementation='flint')] # needs sage.libs.linbox sage: S += [MatrixSpace(ZZ, 3, implementation='generic')] sage: S += [MatrixSpace(ZZ, 3, implementation='gap')] # needs sage.libs.gap sage: S += [MatrixSpace(ZZ, 3, sparse=True)] @@ -1214,7 +1219,7 @@ def _coerce_map_from_(self, S): ....: else: ....: mult += ' ' ....: mult += '\n' - sage: print(mult) # needs sage.libs.flint sage.libs.gap + sage: print(mult) # needs sage.libs.linbox sage.libs.gap XXXX X X XX @@ -1294,7 +1299,7 @@ def _repr_(self): sage: MS Full MatrixSpace of 2 by 4 sparse matrices over Integer Ring - sage: MatrixSpace(ZZ, 2, implementation='flint') # needs sage.libs.flint + sage: MatrixSpace(ZZ, 2, implementation='flint') # needs sage.libs.linbox Full MatrixSpace of 2 by 2 dense matrices over Integer Ring sage: MatrixSpace(ZZ, 2, implementation='generic') Full MatrixSpace of 2 by 2 dense matrices over Integer Ring (using Matrix_generic_dense) @@ -1810,10 +1815,10 @@ def identity_matrix(self): Check different implementations:: - sage: M1 = MatrixSpace(ZZ, 2, implementation='flint') # needs sage.libs.flint + sage: M1 = MatrixSpace(ZZ, 2, implementation='flint') # needs sage.libs.linbox sage: M2 = MatrixSpace(ZZ, 2, implementation='generic') - sage: type(M1.identity_matrix()) # needs sage.libs.flint + sage: type(M1.identity_matrix()) # needs sage.libs.linbox sage: type(M2.identity_matrix()) @@ -1868,10 +1873,10 @@ def diagonal_matrix(self, entries): Check different implementations:: - sage: M1 = MatrixSpace(ZZ, 2, implementation='flint') # needs sage.libs.flint + sage: M1 = MatrixSpace(ZZ, 2, implementation='flint') # needs sage.libs.linbox sage: M2 = MatrixSpace(ZZ, 2, implementation='generic') - sage: type(M1.diagonal_matrix([1, 2])) # needs sage.libs.flint + sage: type(M1.diagonal_matrix([1, 2])) # needs sage.libs.linbox sage: type(M2.diagonal_matrix([1, 2])) @@ -2063,6 +2068,8 @@ def matrix(self, x=None, **kwds): sage: MS([[1],[2]]) [1] [2] + + sage: # needs sage.rings.real_mpfr sage: MS = MatrixSpace(CC, 2, 1) sage: x = polygen(ZZ, 'x') sage: F = NumberField(x^2 + 1, name='x') # needs sage.rings.number_field @@ -2489,10 +2496,10 @@ def _test_trivial_matrices_inverse(ring, sparse=True, implementation=None, check sage: from sage.matrix.matrix_space import _test_trivial_matrices_inverse as tinv sage: tinv(ZZ, sparse=True) - sage: tinv(ZZ, sparse=False, implementation='flint') + sage: tinv(ZZ, sparse=False, implementation='flint') # needs sage.libs.linbox sage: tinv(ZZ, sparse=False, implementation='generic') sage: tinv(QQ, sparse=True) - sage: tinv(QQ, sparse=False, implementation='flint') + sage: tinv(QQ, sparse=False, implementation='flint') # needs sage.libs.linbox sage: tinv(QQ, sparse=False, implementation='generic') sage: tinv(GF(11), sparse=True) sage: tinv(GF(11), sparse=False) @@ -2500,10 +2507,12 @@ def _test_trivial_matrices_inverse(ring, sparse=True, implementation=None, check sage: tinv(GF(2), sparse=False) sage: tinv(SR, sparse=True) # needs sage.symbolic sage: tinv(SR, sparse=False) # needs sage.symbolic + + sage: # needs scipy sage: tinv(RDF, sparse=True) sage: tinv(RDF, sparse=False) - sage: tinv(CDF, sparse=True) - sage: tinv(CDF, sparse=False) + sage: tinv(CDF, sparse=True) # needs sage.rings.complex_double + sage: tinv(CDF, sparse=False) # needs sage.rings.complex_double sage: tinv(CyclotomicField(7), sparse=True) # needs sage.rings.number_field sage: tinv(CyclotomicField(7), sparse=False) # needs sage.rings.number_field sage: tinv(QQ['x,y'], sparse=True) diff --git a/src/sage/matrix/matrix_sparse.pyx b/src/sage/matrix/matrix_sparse.pyx index a98c6bfe64c..ef707ebe3f8 100644 --- a/src/sage/matrix/matrix_sparse.pyx +++ b/src/sage/matrix/matrix_sparse.pyx @@ -1178,7 +1178,7 @@ cdef class Matrix_sparse(matrix.Matrix): Check that the bug in :trac:`13854` has been fixed:: - sage: # needs sage.combinat + sage: # needs sage.combinat sage.libs.singular sage: A. = FreeAlgebra(QQ, 2) sage: P. = A.g_algebra(relations={y*x: -x*y}, order='lex') sage: M = Matrix([[x]], sparse=True) diff --git a/src/sage/matrix/matrix_symbolic_dense.pxd b/src/sage/matrix/matrix_symbolic_dense.pxd index 9ae644a8815..aa85e4c6a21 100644 --- a/src/sage/matrix/matrix_symbolic_dense.pxd +++ b/src/sage/matrix/matrix_symbolic_dense.pxd @@ -1,4 +1,5 @@ -from .matrix_generic_dense cimport Matrix_generic_dense +from sage.matrix.matrix_generic_dense cimport Matrix_generic_dense + cdef class Matrix_symbolic_dense(Matrix_generic_dense): pass diff --git a/src/sage/matrix/matrix_symbolic_dense.pyx b/src/sage/matrix/matrix_symbolic_dense.pyx index b4f6f4f748f..e69d977a117 100644 --- a/src/sage/matrix/matrix_symbolic_dense.pyx +++ b/src/sage/matrix/matrix_symbolic_dense.pyx @@ -157,8 +157,8 @@ Check that :trac:`12778` is fixed:: from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.structure.factorization import Factorization -from .matrix_generic_dense cimport Matrix_generic_dense -from .constructor import matrix +from sage.matrix.matrix_generic_dense cimport Matrix_generic_dense +from sage.matrix.constructor import matrix cdef maxima diff --git a/src/sage/matrix/matrix_symbolic_sparse.pxd b/src/sage/matrix/matrix_symbolic_sparse.pxd index 897754c837d..c90e0161119 100644 --- a/src/sage/matrix/matrix_symbolic_sparse.pxd +++ b/src/sage/matrix/matrix_symbolic_sparse.pxd @@ -1,4 +1,5 @@ -from .matrix_generic_sparse cimport Matrix_generic_sparse +from sage.matrix.matrix_generic_sparse cimport Matrix_generic_sparse + cdef class Matrix_symbolic_sparse(Matrix_generic_sparse): pass diff --git a/src/sage/matrix/matrix_symbolic_sparse.pyx b/src/sage/matrix/matrix_symbolic_sparse.pyx index 29f29a04dd1..69c36e764fb 100644 --- a/src/sage/matrix/matrix_symbolic_sparse.pyx +++ b/src/sage/matrix/matrix_symbolic_sparse.pyx @@ -165,8 +165,8 @@ Check that :issue:`35653` is fixed:: from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.structure.factorization import Factorization -from .matrix_generic_sparse cimport Matrix_generic_sparse -from .constructor import matrix +from sage.matrix.matrix_generic_sparse cimport Matrix_generic_sparse +from sage.matrix.constructor import matrix cdef maxima diff --git a/src/sage/matrix/matrix_window.pxd b/src/sage/matrix/matrix_window.pxd index 523f0d2b235..c33d5d16806 100644 --- a/src/sage/matrix/matrix_window.pxd +++ b/src/sage/matrix/matrix_window.pxd @@ -1,4 +1,5 @@ -from .matrix cimport Matrix +from sage.matrix.matrix cimport Matrix + cdef class MatrixWindow: cdef Py_ssize_t _row, _col, _nrows, _ncols diff --git a/src/sage/matrix/misc.pyx b/src/sage/matrix/misc.pyx index 1819d45591e..9a51efc1038 100644 --- a/src/sage/matrix/misc.pyx +++ b/src/sage/matrix/misc.pyx @@ -18,9 +18,9 @@ from sage.modules.vector_rational_sparse cimport * from sage.rings.integer cimport Integer from sage.rings.rational_field import QQ -from .matrix0 cimport Matrix -from .matrix_integer_sparse cimport Matrix_integer_sparse -from .matrix_rational_sparse cimport Matrix_rational_sparse +from sage.matrix.matrix0 cimport Matrix +from sage.matrix.matrix_integer_sparse cimport Matrix_integer_sparse +from sage.matrix.matrix_rational_sparse cimport Matrix_rational_sparse matrix_integer_dense_rational_reconstruction = \ LazyImport('sage.matrix.misc_flint', 'matrix_integer_dense_rational_reconstruction', diff --git a/src/sage/matrix/misc_flint.pyx b/src/sage/matrix/misc_flint.pyx index 37d326c9a74..d5ca017f73a 100644 --- a/src/sage/matrix/misc_flint.pyx +++ b/src/sage/matrix/misc_flint.pyx @@ -13,8 +13,8 @@ from sage.libs.flint.fmpz cimport fmpz_set_mpz, fmpz_one from sage.rings.integer cimport Integer from sage.rings.rational_field import QQ -from .matrix_integer_dense cimport Matrix_integer_dense -from .matrix_rational_dense cimport Matrix_rational_dense +from sage.matrix.matrix_integer_dense cimport Matrix_integer_dense +from sage.matrix.matrix_rational_dense cimport Matrix_rational_dense def matrix_integer_dense_rational_reconstruction(Matrix_integer_dense A, Integer N): diff --git a/src/sage/matrix/misc_mpfr.pyx b/src/sage/matrix/misc_mpfr.pyx index 48b6ade6379..91613b16492 100644 --- a/src/sage/matrix/misc_mpfr.pyx +++ b/src/sage/matrix/misc_mpfr.pyx @@ -9,7 +9,7 @@ cimport sage.rings.abc from sage.libs.mpfr cimport * from sage.rings.real_mpfr cimport RealNumber -from .matrix0 cimport Matrix +from sage.matrix.matrix0 cimport Matrix def hadamard_row_bound_mpfr(Matrix A): diff --git a/src/sage/matrix/operation_table.py b/src/sage/matrix/operation_table.py index 4b3f1dc905c..50fe4f257dd 100644 --- a/src/sage/matrix/operation_table.py +++ b/src/sage/matrix/operation_table.py @@ -977,7 +977,7 @@ def color_table(self, element_names=True, cmap=None, **options): EXAMPLES:: sage: from sage.matrix.operation_table import OperationTable - sage: OTa = OperationTable(SymmetricGroup(3), operation=operator.mul) # needs sage.groups sage.plot + sage: OTa = OperationTable(SymmetricGroup(3), operation=operator.mul) # needs sage.groups sage: OTa.color_table() # needs sage.groups sage.plot Graphics object consisting of 37 graphics primitives @@ -1036,7 +1036,7 @@ def gray_table(self, **options): EXAMPLES:: sage: from sage.matrix.operation_table import OperationTable - sage: OTa = OperationTable(SymmetricGroup(3), operation=operator.mul) # needs sage.groups sage.plot + sage: OTa = OperationTable(SymmetricGroup(3), operation=operator.mul) # needs sage.groups sage: OTa.gray_table() # needs sage.groups sage.plot Graphics object consisting of 37 graphics primitives diff --git a/src/sage/matrix/special.py b/src/sage/matrix/special.py index 0b23f80123a..7233892ce2f 100644 --- a/src/sage/matrix/special.py +++ b/src/sage/matrix/special.py @@ -356,7 +356,7 @@ def random_matrix(ring, nrows, ncols=None, algorithm='randomize', implementation ....: A = random_matrix(*args, **kwds) ....: density_sum += float(A.density()) - sage: # needs sage.libs.flint (otherwise timeout) + sage: # needs sage.libs.linbox (otherwise timeout) sage: density_sum = 0.0 sage: total_count = 0.0 sage: add_sample(ZZ, 5, x=-10, y=10, density=0.75) @@ -366,14 +366,14 @@ def random_matrix(ring, nrows, ncols=None, algorithm='randomize', implementation sage: while abs(density_sum/total_count - expected_density) > 0.001: ....: add_sample(ZZ, 5, x=-10, y=10, density=0.75) - sage: # needs sage.libs.flint (otherwise timeout) + sage: # needs sage.libs.linbox (otherwise timeout) sage: density_sum = 0.0 sage: total_count = 0.0 sage: add_sample(ZZ, 5, x=20, y=30, density=0.75) sage: while abs(density_sum/total_count - expected_density) > 0.001: ....: add_sample(ZZ, 5, x=20, y=30, density=0.75) - sage: # needs sage.libs.flint (otherwise timeout) + sage: # needs sage.libs.linbox (otherwise timeout) sage: density_sum = 0.0 sage: total_count = 0.0 sage: add_sample(ZZ, 100, x=20, y=30, density=0.75) @@ -396,7 +396,7 @@ def random_matrix(ring, nrows, ncols=None, algorithm='randomize', implementation For algorithm testing you might want to control the number of bits, say 10,000 entries, each limited to 16 bits. :: - sage: # needs sage.libs.flint (otherwise timeout) + sage: # needs sage.libs.linbox (otherwise timeout) sage: A = random_matrix(ZZ, 100, 100, x=2^16); A 100 x 100 dense matrix over Integer Ring (use the '.str()' method to see the entries) @@ -556,7 +556,7 @@ def random_matrix(ring, nrows, ncols=None, algorithm='randomize', implementation True sage: all(x in ZZ for x in (A - (-1)*identity_matrix(5)).rref().list()) True - sage: A.jordan_form() # needs sage.combinat + sage: A.jordan_form() # needs sage.combinat sage.libs.pari [ 2| 0| 0| 0| 0] [--+--+--+--+--] [ 0| 3| 0| 0| 0] diff --git a/src/sage/matrix/strassen.pyx b/src/sage/matrix/strassen.pyx index 9e2797c9925..3d083fa6859 100644 --- a/src/sage/matrix/strassen.pyx +++ b/src/sage/matrix/strassen.pyx @@ -15,7 +15,7 @@ multiplication algorithms. # http://www.gnu.org/licenses/ #***************************************************************************** -from .matrix_window cimport MatrixWindow +from sage.matrix.matrix_window cimport MatrixWindow from cysignals.signals cimport sig_on, sig_off diff --git a/src/sage/matrix/template.pxd b/src/sage/matrix/template.pxd index 8c473730dd2..69123a38f2d 100644 --- a/src/sage/matrix/template.pxd +++ b/src/sage/matrix/template.pxd @@ -1,4 +1,5 @@ -from .matrix_dense cimport Matrix_dense +from sage.matrix.matrix_dense cimport Matrix_dense + cdef class Matrix_generic_dense(Matrix_dense): pass diff --git a/src/sage/matrix/tests.py b/src/sage/matrix/tests.py index 9208a5d4d72..b4747bff5c9 100644 --- a/src/sage/matrix/tests.py +++ b/src/sage/matrix/tests.py @@ -48,10 +48,10 @@ sage: matrix(QQ['x,y'], 2, 2, [1, 1, 1, 1]) / x # needs sage.symbolic [1/x 1/x] [1/x 1/x] - sage: A = matrix(CC, 2, 2, [1, 1, 1, 1]) / I; A + sage: A = matrix(CC, 2, 2, [1, 1, 1, 1]) / I; A # needs sage.rings.real_mpfr sage.symbolic [-1.00000000000000*I -1.00000000000000*I] [-1.00000000000000*I -1.00000000000000*I] - sage: A.parent() + sage: A.parent() # needs sage.rings.real_mpfr sage.symbolic Full MatrixSpace of 2 by 2 dense matrices over Complex Field with 53 bits of precision We test an example determinant computation where LinBox gave an incorrect @@ -64,8 +64,8 @@ Test that a certain bug in GP's mathnf was fixed:: - sage: a = gp('Mat([-15,18,-23,-20,-32,11,-19,2,-1,15,22,29,-29,3,-31,25,11,-6,32,7; -31,0,30,-27,-15,13,-21,6,-27,6,3,-4,-4,-28,-30,-16,29,-4,29,-20; -15,-19,-30,9,-18,-31,23,-15,15,-9,20,10,-29,9,18,-6,-1,-20,19,-29; 2,-32,4,-13,17,21,12,-32,12,0,27,-10,-31,-33,-8,-31,-23,25,-18,6; -10,33,4,27,1,25,1,6,31,-7,3,30,23,-4,18,16,-12,21,0,4; -19,20,31,-34,-24,20,-13,-2,18,12,-18,33,22,0,0,10,-25,-29,6,-23; -15,-33,27,-9,-21,-20,5,-20,-31,-11,20,19,31,25,16,20,5,23,-32,-2; 20,18,12,-10,-3,-29,-14,4,-9,21,7,-34,6,16,7,10,11,-21,8,28; 10,-4,-11,-8,-29,33,-23,21,-3,-17,21,7,-28,-10,-16,-1,-29,32,12,16; 13,33,-7,15,-31,20,22,33,21,8,-24,20,27,30,24,20,-29,31,-20,-16; -24,-16,24,-8,7,-22,3,12,-1,-4,-9,10,13,-2,-14,-4,-3,-26,28,-25; 7,-7,19,-26,25,-27,33,12,6,3,31,-30,-14,6,-17,11,-6,5,15,0; 9,-32,-14,9,12,-8,-19,22,20,-23,14,29,-17,-28,-34,-10,4,26,-3,-14; 7,-13,-16,32,-2,11,-2,3,33,-22,-7,-3,12,-24,-7,-7,-1,31,26,22; 8,7,30,29,26,-12,13,21,-18,-5,-27,-33,1,16,-34,-10,-1,8,6,20; 32,-30,27,-21,33,5,14,30,13,24,10,-23,30,-18,13,25,0,-22,18,-19; -4,-6,7,28,-4,9,32,21,29,2,-7,7,-24,-10,2,-9,-23,-18,6,5; 3,19,0,23,-24,-16,-33,-15,-2,16,2,19,28,33,-16,32,-20,-15,28,-18])') - sage: a.mathnf(1)[1][1,] == gp('[4, 2, 1, 0, 3, 1, 1, 0, 1, 1, 2, 2, 3, 3, 0, 0, 1, 3]') + sage: a = gp('Mat([-15,18,-23,-20,-32,11,-19,2,-1,15,22,29,-29,3,-31,25,11,-6,32,7; -31,0,30,-27,-15,13,-21,6,-27,6,3,-4,-4,-28,-30,-16,29,-4,29,-20; -15,-19,-30,9,-18,-31,23,-15,15,-9,20,10,-29,9,18,-6,-1,-20,19,-29; 2,-32,4,-13,17,21,12,-32,12,0,27,-10,-31,-33,-8,-31,-23,25,-18,6; -10,33,4,27,1,25,1,6,31,-7,3,30,23,-4,18,16,-12,21,0,4; -19,20,31,-34,-24,20,-13,-2,18,12,-18,33,22,0,0,10,-25,-29,6,-23; -15,-33,27,-9,-21,-20,5,-20,-31,-11,20,19,31,25,16,20,5,23,-32,-2; 20,18,12,-10,-3,-29,-14,4,-9,21,7,-34,6,16,7,10,11,-21,8,28; 10,-4,-11,-8,-29,33,-23,21,-3,-17,21,7,-28,-10,-16,-1,-29,32,12,16; 13,33,-7,15,-31,20,22,33,21,8,-24,20,27,30,24,20,-29,31,-20,-16; -24,-16,24,-8,7,-22,3,12,-1,-4,-9,10,13,-2,-14,-4,-3,-26,28,-25; 7,-7,19,-26,25,-27,33,12,6,3,31,-30,-14,6,-17,11,-6,5,15,0; 9,-32,-14,9,12,-8,-19,22,20,-23,14,29,-17,-28,-34,-10,4,26,-3,-14; 7,-13,-16,32,-2,11,-2,3,33,-22,-7,-3,12,-24,-7,-7,-1,31,26,22; 8,7,30,29,26,-12,13,21,-18,-5,-27,-33,1,16,-34,-10,-1,8,6,20; 32,-30,27,-21,33,5,14,30,13,24,10,-23,30,-18,13,25,0,-22,18,-19; -4,-6,7,28,-4,9,32,21,29,2,-7,7,-24,-10,2,-9,-23,-18,6,5; 3,19,0,23,-24,-16,-33,-15,-2,16,2,19,28,33,-16,32,-20,-15,28,-18])') # needs sage.libs.pari + sage: a.mathnf(1)[1][1,] == gp('[4, 2, 1, 0, 3, 1, 1, 0, 1, 1, 2, 2, 3, 3, 0, 0, 1, 3]') # needs sage.libs.pari True """ diff --git a/src/sage/matroids/basis_exchange_matroid.pxd b/src/sage/matroids/basis_exchange_matroid.pxd index b762fd9ed9d..5877f62fc09 100644 --- a/src/sage/matroids/basis_exchange_matroid.pxd +++ b/src/sage/matroids/basis_exchange_matroid.pxd @@ -1,8 +1,8 @@ from sage.data_structures.bitset cimport * from sage.data_structures.bitset_base cimport bitset_t, bitset_s -from .matroid cimport Matroid -from .set_system cimport SetSystem +from sage.matroids.matroid cimport Matroid +from sage.matroids.set_system cimport SetSystem cdef class BasisExchangeMatroid(Matroid): cdef long _groundset_size, _matroid_rank, _bitset_size diff --git a/src/sage/matroids/basis_exchange_matroid.pyx b/src/sage/matroids/basis_exchange_matroid.pyx index c27a8cba33d..e5c18e0185b 100644 --- a/src/sage/matroids/basis_exchange_matroid.pyx +++ b/src/sage/matroids/basis_exchange_matroid.pyx @@ -38,8 +38,8 @@ Methods # https://www.gnu.org/licenses/ # **************************************************************************** -from .matroid cimport Matroid -from .set_system cimport SetSystem +from sage.matroids.matroid cimport Matroid +from sage.matroids.set_system cimport SetSystem from sage.data_structures.bitset_base cimport * @@ -2151,7 +2151,7 @@ cdef class BasisExchangeMatroid(Matroid): True """ if not isinstance(other, BasisExchangeMatroid): - from .basis_matroid import BasisMatroid + from sage.matroids.basis_matroid import BasisMatroid ot = BasisMatroid(other) else: ot = other @@ -2217,7 +2217,7 @@ cdef class BasisExchangeMatroid(Matroid): True """ if not isinstance(other, BasisExchangeMatroid): - from .basis_matroid import BasisMatroid + from sage.matroids.basis_matroid import BasisMatroid other = BasisMatroid(other) if self is other: return {e:e for e in self.groundset()} diff --git a/src/sage/matroids/basis_matroid.pxd b/src/sage/matroids/basis_matroid.pxd index a4202bfedac..aeb59fdb66f 100644 --- a/src/sage/matroids/basis_matroid.pxd +++ b/src/sage/matroids/basis_matroid.pxd @@ -1,7 +1,7 @@ from sage.data_structures.bitset cimport bitset_t -from .matroid cimport Matroid -from .basis_exchange_matroid cimport BasisExchangeMatroid -from .set_system cimport SetSystem +from sage.matroids.matroid cimport Matroid +from sage.matroids.basis_exchange_matroid cimport BasisExchangeMatroid +from sage.matroids.set_system cimport SetSystem cdef class BasisMatroid(BasisExchangeMatroid): cdef bitset_t _bb diff --git a/src/sage/matroids/basis_matroid.pyx b/src/sage/matroids/basis_matroid.pyx index 93cf56ec60c..0610c9a1149 100644 --- a/src/sage/matroids/basis_matroid.pyx +++ b/src/sage/matroids/basis_matroid.pyx @@ -74,9 +74,9 @@ Methods from sage.data_structures.bitset_base cimport * from sage.structure.richcmp cimport rich_to_bool -from .matroid cimport Matroid -from .basis_exchange_matroid cimport BasisExchangeMatroid -from .set_system cimport SetSystem +from sage.matroids.matroid cimport Matroid +from sage.matroids.basis_exchange_matroid cimport BasisExchangeMatroid +from sage.matroids.set_system cimport SetSystem from cpython.object cimport Py_EQ, Py_NE from itertools import combinations diff --git a/src/sage/matroids/circuit_closures_matroid.pxd b/src/sage/matroids/circuit_closures_matroid.pxd index 1ec965db0fe..5f4edf109b7 100644 --- a/src/sage/matroids/circuit_closures_matroid.pxd +++ b/src/sage/matroids/circuit_closures_matroid.pxd @@ -1,4 +1,5 @@ -from .matroid cimport Matroid +from sage.matroids.matroid cimport Matroid + cdef class CircuitClosuresMatroid(Matroid): cdef frozenset _groundset # _E diff --git a/src/sage/matroids/circuit_closures_matroid.pyx b/src/sage/matroids/circuit_closures_matroid.pyx index 1fc11f0c344..0a25aee80cb 100644 --- a/src/sage/matroids/circuit_closures_matroid.pyx +++ b/src/sage/matroids/circuit_closures_matroid.pyx @@ -67,9 +67,9 @@ Methods # **************************************************************************** from sage.structure.richcmp cimport rich_to_bool, richcmp -from .matroid cimport Matroid -from .set_system cimport SetSystem -from .utilities import setprint_s +from sage.matroids.matroid cimport Matroid +from sage.matroids.set_system cimport SetSystem +from sage.matroids.utilities import setprint_s from cpython.object cimport Py_EQ, Py_NE diff --git a/src/sage/matroids/extension.pxd b/src/sage/matroids/extension.pxd index 34d813eeb7c..6b6d7949794 100644 --- a/src/sage/matroids/extension.pxd +++ b/src/sage/matroids/extension.pxd @@ -1,5 +1,5 @@ from sage.data_structures.bitset cimport bitset_t -from .basis_matroid cimport BasisMatroid +from sage.matroids.basis_matroid cimport BasisMatroid cdef class CutNode: cdef LinearSubclasses _MC diff --git a/src/sage/matroids/extension.pyx b/src/sage/matroids/extension.pyx index 061ba37089e..553869fcf66 100644 --- a/src/sage/matroids/extension.pyx +++ b/src/sage/matroids/extension.pyx @@ -30,7 +30,7 @@ Methods # **************************************************************************** from sage.data_structures.bitset_base cimport * -from .basis_matroid cimport BasisMatroid +from sage.matroids.basis_matroid cimport BasisMatroid cdef class CutNode: diff --git a/src/sage/matroids/linear_matroid.pxd b/src/sage/matroids/linear_matroid.pxd index 663886fa58e..c7e6a402494 100644 --- a/src/sage/matroids/linear_matroid.pxd +++ b/src/sage/matroids/linear_matroid.pxd @@ -1,8 +1,8 @@ from sage.data_structures.bitset cimport bitset_t -from .matroid cimport Matroid -from .basis_exchange_matroid cimport BasisExchangeMatroid -from .lean_matrix cimport LeanMatrix, GenericMatrix, BinaryMatrix, TernaryMatrix, QuaternaryMatrix +from sage.matroids.matroid cimport Matroid +from sage.matroids.basis_exchange_matroid cimport BasisExchangeMatroid +from sage.matroids.lean_matrix cimport LeanMatrix, GenericMatrix, BinaryMatrix, TernaryMatrix, QuaternaryMatrix cdef class LinearMatroid(BasisExchangeMatroid): diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index 51692e8f1c1..ed971cb8349 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -344,9 +344,9 @@ from sage.structure.sage_object cimport SageObject MixedIntegerLinearProgram = LazyImport('sage.numerical.mip', 'MixedIntegerLinearProgram') -from .lean_matrix cimport BinaryMatrix, TernaryMatrix -from .set_system cimport SetSystem -from .utilities import newlabel, sanitize_contractions_deletions, spanning_forest, spanning_stars +from sage.matroids.lean_matrix cimport BinaryMatrix, TernaryMatrix +from sage.matroids.set_system cimport SetSystem +from sage.matroids.utilities import newlabel, sanitize_contractions_deletions, spanning_forest, spanning_stars # On some systems, macros "minor()" and "major()" are defined in system header @@ -1113,7 +1113,7 @@ cdef class Matroid(SageObject): {'e', 'f', 'g', 'h'}}, 4: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'}}} """ - from . import minor_matroid + from sage.matroids import minor_matroid return minor_matroid.MinorMatroid(self, contractions, deletions) cpdef _has_minor(self, N, bint certificate=False) noexcept: @@ -1226,7 +1226,7 @@ cdef class Matroid(SageObject): sage: [sorted(C) for C in N.circuits() if len(C) == 3] [[0, 1, 6]] """ - from . import basis_matroid + from sage.matroids import basis_matroid return basis_matroid.BasisMatroid(self)._extension(element, hyperplanes) # ** user-facing methods ** @@ -3610,8 +3610,8 @@ cdef class Matroid(SageObject): sage: M._is_isomorphism(N, morphism) True """ - from . import basis_exchange_matroid - from . import basis_matroid + from sage.matroids import basis_exchange_matroid + from sage.matroids import basis_matroid sf = basis_matroid.BasisMatroid(self) if not isinstance(other, basis_exchange_matroid.BasisExchangeMatroid): ot = basis_matroid.BasisMatroid(other) @@ -3694,7 +3694,7 @@ cdef class Matroid(SageObject): return rich_to_bool(op, 1) # Default implementation: use BasisMatroid - from .basis_matroid import BasisMatroid + from sage.matroids.basis_matroid import BasisMatroid return richcmp(BasisMatroid(left), BasisMatroid(right), op) # Minors and duality @@ -4009,7 +4009,7 @@ cdef class Matroid(SageObject): {'c', 'e', 'g'}, {'d', 'e', 'f'}, {'g', 'h', 'i'}}, 3: {{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'}}}' """ - from . import dual_matroid + from sage.matroids import dual_matroid return dual_matroid.DualMatroid(self) cpdef truncation(self) noexcept: @@ -4505,7 +4505,7 @@ cdef class Matroid(SageObject): sage: len(list(M.linear_subclasses(line_length=5))) 44 """ - from . import extension + from sage.matroids import extension return extension.LinearSubclasses(self, line_length=line_length, subsets=subsets) cpdef extensions(self, element=None, line_length=None, subsets=None) noexcept: @@ -4564,7 +4564,7 @@ cdef class Matroid(SageObject): 5 """ - from . import extension + from sage.matroids import extension if element is None: element = newlabel(self.groundset()) else: @@ -7773,7 +7773,7 @@ cdef class Matroid(SageObject): sage: G.show() # needs sage.plot sage.rings.finite_rings """ - from . import matroids_plot_helpers + from sage.matroids import matroids_plot_helpers if pos_method == 1 and pos_dict is not None: # check sanity of pos_dict and add it to cached info if sane if matroids_plot_helpers.posdict_is_sane(self, pos_dict): @@ -7882,7 +7882,7 @@ cdef class Matroid(SageObject): raise NotImplementedError # check sanity of pos_dict and add it to cached info if sane if pos_dict is not None: - from . import matroids_plot_helpers + from sage.matroids import matroids_plot_helpers if matroids_plot_helpers.posdict_is_sane(self,pos_dict): self._cached_info = {'plot_positions': pos_dict, 'lineorders': lineorders} return @@ -8066,7 +8066,7 @@ cdef class Matroid(SageObject): Binary matroid of rank 3 on 7 elements, type (3, 0) Ternary matroid of rank 3 on 7 elements, type 0- """ - from . import union_matroid + from sage.matroids import union_matroid if isinstance(matroids, Matroid): matroids = [matroids] else: @@ -8116,7 +8116,7 @@ cdef class Matroid(SageObject): sage: len(N.bases()) 2100 """ - from . import union_matroid + from sage.matroids import union_matroid if isinstance(matroids, Matroid): matroids = [matroids] else: diff --git a/src/sage/matroids/union_matroid.pxd b/src/sage/matroids/union_matroid.pxd index 6e3a6e8d96e..a378cfe910d 100644 --- a/src/sage/matroids/union_matroid.pxd +++ b/src/sage/matroids/union_matroid.pxd @@ -1,4 +1,5 @@ -from .matroid cimport Matroid +from sage.matroids.matroid cimport Matroid + cdef class MatroidUnion(Matroid): cdef list matroids diff --git a/src/sage/matroids/union_matroid.pyx b/src/sage/matroids/union_matroid.pyx index 802b8d609f4..bb3dd03a082 100644 --- a/src/sage/matroids/union_matroid.pyx +++ b/src/sage/matroids/union_matroid.pyx @@ -1,5 +1,5 @@ -from .matroid cimport Matroid +from sage.matroids.matroid cimport Matroid cdef class MatroidUnion(Matroid): diff --git a/src/sage/matroids/unpickling.pyx b/src/sage/matroids/unpickling.pyx index 94464ecb9f0..77b3f12265c 100644 --- a/src/sage/matroids/unpickling.pyx +++ b/src/sage/matroids/unpickling.pyx @@ -28,13 +28,13 @@ AUTHORS: from sage.data_structures.bitset_base cimport * import sage.matroids.matroid import sage.matroids.basis_exchange_matroid -from .minor_matroid import MinorMatroid -from .dual_matroid import DualMatroid -from .circuit_closures_matroid cimport CircuitClosuresMatroid -from .basis_matroid cimport BasisMatroid -from .linear_matroid cimport LinearMatroid, RegularMatroid, BinaryMatroid, TernaryMatroid, QuaternaryMatroid -from .lean_matrix cimport GenericMatrix, BinaryMatrix, TernaryMatrix, QuaternaryMatrix, PlusMinusOneMatrix, RationalMatrix -from .graphic_matroid import GraphicMatroid +from sage.matroids.minor_matroid import MinorMatroid +from sage.matroids.dual_matroid import DualMatroid +from sage.matroids.circuit_closures_matroid cimport CircuitClosuresMatroid +from sage.matroids.basis_matroid cimport BasisMatroid +from sage.matroids.linear_matroid cimport LinearMatroid, RegularMatroid, BinaryMatroid, TernaryMatroid, QuaternaryMatroid +from sage.matroids.lean_matrix cimport GenericMatrix, BinaryMatrix, TernaryMatrix, QuaternaryMatrix, PlusMinusOneMatrix, RationalMatrix +from sage.matroids.graphic_matroid import GraphicMatroid from sage.rings.rational cimport Rational from sage.libs.gmp.mpq cimport mpq_set diff --git a/src/sage/misc/c3_controlled.pyx b/src/sage/misc/c3_controlled.pyx index 6e34f0a4ba8..4a4c51cbfe7 100644 --- a/src/sage/misc/c3_controlled.pyx +++ b/src/sage/misc/c3_controlled.pyx @@ -343,12 +343,12 @@ doctest:: sage: sorted([C for C in category_sample() # needs sage.combinat sage.graphs sage.modules sage.rings.number_field ....: if len(C._super_categories_for_classes) != len(C.super_categories())], ....: key=str) - [Category of affine weyl groups, + [Category of affine Weyl groups, Category of fields, + Category of finite Weyl groups, Category of finite dimensional algebras with basis over Rational Field, Category of finite dimensional hopf algebras with basis over Rational Field, Category of finite enumerated permutation groups, - Category of finite weyl groups, Category of number fields] AUTHOR: diff --git a/src/sage/misc/lazy_attribute.pyi b/src/sage/misc/lazy_attribute.pyi new file mode 100644 index 00000000000..6a174a37aa2 --- /dev/null +++ b/src/sage/misc/lazy_attribute.pyi @@ -0,0 +1,9 @@ +# This type-stub file helps pyright understand the decorator @lazy_attribute. + +# Adapted from https://github.com/python/typeshed/blob/b9640005eb586afdbe0a57bac2b88a7a12465069/stdlib/builtins.pyi#L1237-L1254 +class lazy_attribute: + def __init__( + self, + f: Callable[[Any], Any] | None = ... + ) -> None: ... + def __get__(self, a: Any, cls: type) -> Any: ... diff --git a/src/sage/misc/package_dir.py b/src/sage/misc/package_dir.py index 218949ca11e..9f075b16c31 100644 --- a/src/sage/misc/package_dir.py +++ b/src/sage/misc/package_dir.py @@ -124,7 +124,7 @@ def read_distribution(src_file): line = line[1:].lstrip() kind = "sage_setup:" if line.startswith(kind): - key, _, value = [s.strip() for s in line[len(kind):].partition('=')] + key, _, value = (s.strip() for s in line[len(kind):].partition('=')) if key == "distribution": return value return '' diff --git a/src/sage/misc/sageinspect.py b/src/sage/misc/sageinspect.py index bbd03bcb24c..8c734ecd36d 100644 --- a/src/sage/misc/sageinspect.py +++ b/src/sage/misc/sageinspect.py @@ -1806,6 +1806,7 @@ def formatannotation(annotation, base_module=None): return annotation.__module__ + '.' + annotation.__qualname__ return repr(annotation) +_formatannotation = formatannotation def sage_formatargspec(args, varargs=None, varkw=None, defaults=None, kwonlyargs=(), kwonlydefaults=None, annotations={}, @@ -1814,7 +1815,7 @@ def sage_formatargspec(args, varargs=None, varkw=None, defaults=None, formatvarkw=None, formatvalue=None, formatreturns=None, - formatannotation=formatannotation): + formatannotation=None): """ Format an argument spec from the values returned by getfullargspec. @@ -1851,6 +1852,8 @@ def sage_formatargspec(args, varargs=None, varkw=None, defaults=None, formatvalue = lambda value: '=' + repr(value) if formatreturns is None: formatreturns = lambda text: ' -> ' + text + if formatannotation is None: + formatannotation = _formatannotation def formatargandannotation(arg): result = formatarg(arg) diff --git a/src/sage/modular/abvar/abvar.py b/src/sage/modular/abvar/abvar.py index 818e7cf1a85..4f23ab768fd 100644 --- a/src/sage/modular/abvar/abvar.py +++ b/src/sage/modular/abvar/abvar.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.libs.flint sage.libs.pari """ Base class for modular abelian varieties @@ -317,7 +317,7 @@ def base_extend(self, K): sage: A = J0(37); A Abelian variety J0(37) of dimension 2 - sage: A.base_extend(QQbar) + sage: A.base_extend(QQbar) # needs sage.rings.number_field Abelian variety J0(37) over Algebraic Field of dimension 2 sage: A.base_extend(GF(7)) Abelian variety J0(37) over Finite Field of size 7 of dimension 2 diff --git a/src/sage/modular/abvar/abvar_newform.py b/src/sage/modular/abvar/abvar_newform.py index 67c478511f3..5d4976d5d54 100644 --- a/src/sage/modular/abvar/abvar_newform.py +++ b/src/sage/modular/abvar/abvar_newform.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.pari """ Abelian varieties attached to newforms diff --git a/src/sage/modular/abvar/finite_subgroup.py b/src/sage/modular/abvar/finite_subgroup.py index 74f7dd6389b..2725e11a387 100644 --- a/src/sage/modular/abvar/finite_subgroup.py +++ b/src/sage/modular/abvar/finite_subgroup.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.pari r""" Finite subgroups of modular abelian varieties @@ -178,7 +179,8 @@ def lattice(self): EXAMPLES:: sage: J = J0(33); C = J[0].cuspidal_subgroup(); C - Finite subgroup with invariants [5] over QQ of Simple abelian subvariety 11a(1,33) of dimension 1 of J0(33) + Finite subgroup with invariants [5] over QQ of + Simple abelian subvariety 11a(1,33) of dimension 1 of J0(33) sage: C.lattice() Free module of degree 6 and rank 2 over Integer Ring Echelon basis matrix: @@ -197,7 +199,8 @@ def _relative_basis_matrix(self): sage: A = J0(43)[1]; A Simple abelian subvariety 43b(1,43) of dimension 2 of J0(43) sage: C = A.cuspidal_subgroup(); C - Finite subgroup with invariants [7] over QQ of Simple abelian subvariety 43b(1,43) of dimension 2 of J0(43) + Finite subgroup with invariants [7] over QQ of + Simple abelian subvariety 43b(1,43) of dimension 2 of J0(43) sage: C._relative_basis_matrix() [ 1 0 0 0] [ 0 1/7 6/7 5/7] @@ -262,7 +265,7 @@ def __richcmp__(self, other, op): def is_subgroup(self, other): """ - Return True exactly if self is a subgroup of other, and both are + Return ``True`` exactly if ``self`` is a subgroup of ``other``, and both are defined as subgroups of the same ambient abelian variety. EXAMPLES:: @@ -302,8 +305,9 @@ def __add__(self, other): An example where the parent abelian varieties are different:: - A = J0(48); A[0].cuspidal_subgroup() + A[1].cuspidal_subgroup() - Finite subgroup with invariants [2, 4, 4] over QQ of Abelian subvariety of dimension 2 of J0(48) + sage: A = J0(48); A[0].cuspidal_subgroup() + A[1].cuspidal_subgroup() + Finite subgroup with invariants [2, 4, 4] over QQ of + Abelian subvariety of dimension 2 of J0(48) """ if not isinstance(other, FiniteSubgroup): raise TypeError("only addition of two finite subgroups is defined") @@ -330,7 +334,8 @@ def exponent(self): sage: t = J0(33).hecke_operator(7) sage: G = t.kernel()[0]; G - Finite subgroup with invariants [2, 2, 2, 2, 4, 4] over QQ of Abelian variety J0(33) of dimension 3 + Finite subgroup with invariants [2, 2, 2, 2, 4, 4] over QQ of + Abelian variety J0(33) of dimension 3 sage: G.exponent() 4 """ @@ -343,7 +348,7 @@ def exponent(self): def intersection(self, other): """ - Return the intersection of the finite subgroups self and other. + Return the intersection of the finite subgroups ``self`` and ``other``. INPUT: @@ -358,12 +363,15 @@ def intersection(self, other): sage: E11a0, E11a1, B = J0(33) sage: G = E11a0.torsion_subgroup(6); H = E11a0.torsion_subgroup(9) sage: G.intersection(H) - Finite subgroup with invariants [3, 3] over QQ of Simple abelian subvariety 11a(1,33) of dimension 1 of J0(33) + Finite subgroup with invariants [3, 3] over QQ of + Simple abelian subvariety 11a(1,33) of dimension 1 of J0(33) sage: W = E11a1.torsion_subgroup(15) sage: G.intersection(W) - Finite subgroup with invariants [] over QQ of Simple abelian subvariety 11a(1,33) of dimension 1 of J0(33) + Finite subgroup with invariants [] over QQ of + Simple abelian subvariety 11a(1,33) of dimension 1 of J0(33) sage: E11a0.intersection(E11a1)[0] - Finite subgroup with invariants [5] over QQ of Simple abelian subvariety 11a(1,33) of dimension 1 of J0(33) + Finite subgroup with invariants [5] over QQ of + Simple abelian subvariety 11a(1,33) of dimension 1 of J0(33) We intersect subgroups of different abelian varieties. @@ -372,27 +380,35 @@ def intersection(self, other): sage: E11a0, E11a1, B = J0(33) sage: G = E11a0.torsion_subgroup(5); H = E11a1.torsion_subgroup(5) sage: G.intersection(H) - Finite subgroup with invariants [5] over QQ of Simple abelian subvariety 11a(1,33) of dimension 1 of J0(33) + Finite subgroup with invariants [5] over QQ of + Simple abelian subvariety 11a(1,33) of dimension 1 of J0(33) sage: E11a0.intersection(E11a1)[0] - Finite subgroup with invariants [5] over QQ of Simple abelian subvariety 11a(1,33) of dimension 1 of J0(33) + Finite subgroup with invariants [5] over QQ of + Simple abelian subvariety 11a(1,33) of dimension 1 of J0(33) We intersect abelian varieties with subgroups:: sage: t = J0(33).hecke_operator(7) sage: G = t.kernel()[0]; G - Finite subgroup with invariants [2, 2, 2, 2, 4, 4] over QQ of Abelian variety J0(33) of dimension 3 + Finite subgroup with invariants [2, 2, 2, 2, 4, 4] over QQ of + Abelian variety J0(33) of dimension 3 sage: A = J0(33).old_subvariety() sage: A.intersection(G) - Finite subgroup with invariants [2, 2, 2, 2] over QQ of Abelian subvariety of dimension 2 of J0(33) + Finite subgroup with invariants [2, 2, 2, 2] over QQ of + Abelian subvariety of dimension 2 of J0(33) sage: A.hecke_operator(7).kernel()[0] - Finite subgroup with invariants [2, 2, 2, 2] over QQ of Abelian subvariety of dimension 2 of J0(33) + Finite subgroup with invariants [2, 2, 2, 2] over QQ of + Abelian subvariety of dimension 2 of J0(33) sage: B = J0(33).new_subvariety() sage: B.intersection(G) - Finite subgroup with invariants [4, 4] over QQ of Abelian subvariety of dimension 1 of J0(33) + Finite subgroup with invariants [4, 4] over QQ of + Abelian subvariety of dimension 1 of J0(33) sage: B.hecke_operator(7).kernel()[0] - Finite subgroup with invariants [4, 4] over QQ of Abelian subvariety of dimension 1 of J0(33) + Finite subgroup with invariants [4, 4] over QQ of + Abelian subvariety of dimension 1 of J0(33) sage: A.intersection(B)[0] - Finite subgroup with invariants [3, 3] over QQ of Abelian subvariety of dimension 2 of J0(33) + Finite subgroup with invariants [3, 3] over QQ of + Abelian subvariety of dimension 2 of J0(33) """ from .abvar import is_ModularAbelianVariety A = self.abelian_variety() @@ -736,13 +752,15 @@ def subgroup(self, gens): sage: J = J0(23) sage: G = J.torsion_subgroup(11); G - Finite subgroup with invariants [11, 11, 11, 11] over QQ of Abelian variety J0(23) of dimension 2 + Finite subgroup with invariants [11, 11, 11, 11] over QQ of + Abelian variety J0(23) of dimension 2 We create the subgroup of the 11-torsion subgroup of `J_0(23)` generated by the first `11`-torsion point:: sage: H = G.subgroup([G.0]); H - Finite subgroup with invariants [11] over QQbar of Abelian variety J0(23) of dimension 2 + Finite subgroup with invariants [11] over QQbar of + Abelian variety J0(23) of dimension 2 sage: H.invariants() [11] @@ -773,7 +791,8 @@ def invariants(self): sage: J = J0(38) sage: C = J.cuspidal_subgroup(); C - Finite subgroup with invariants [3, 45] over QQ of Abelian variety J0(38) of dimension 4 + Finite subgroup with invariants [3, 45] over QQ of + Abelian variety J0(38) of dimension 4 sage: v = C.invariants(); v [3, 45] sage: v[0] = 5 @@ -786,12 +805,14 @@ def invariants(self): :: sage: C * 3 - Finite subgroup with invariants [15] over QQ of Abelian variety J0(38) of dimension 4 + Finite subgroup with invariants [15] over QQ of + Abelian variety J0(38) of dimension 4 An example involving another cuspidal subgroup:: sage: C = J0(22).cuspidal_subgroup(); C - Finite subgroup with invariants [5, 5] over QQ of Abelian variety J0(22) of dimension 2 + Finite subgroup with invariants [5, 5] over QQ of + Abelian variety J0(22) of dimension 2 sage: C.lattice() Free module of degree 4 and rank 4 over Integer Ring Echelon basis matrix: @@ -843,7 +864,8 @@ def __init__(self, abvar, lattice, field_of_definition=None, check=True): sage: J = J0(11) sage: G = J.finite_subgroup([[1/3,0], [0,1/5]]); G - Finite subgroup with invariants [15] over QQbar of Abelian variety J0(11) of dimension 1 + Finite subgroup with invariants [15] over QQbar of + Abelian variety J0(11) of dimension 1 """ if field_of_definition is None: from sage.rings.qqbar import QQbar as field_of_definition @@ -868,7 +890,8 @@ def lattice(self): sage: J = J0(11) sage: G = J.finite_subgroup([[1/3,0], [0,1/5]]); G - Finite subgroup with invariants [15] over QQbar of Abelian variety J0(11) of dimension 1 + Finite subgroup with invariants [15] over QQbar of + Abelian variety J0(11) of dimension 1 sage: G.lattice() Free module of degree 2 and rank 2 over Integer Ring Echelon basis matrix: diff --git a/src/sage/modular/abvar/homology.py b/src/sage/modular/abvar/homology.py index 735bb48fb7f..59cc17a77e7 100644 --- a/src/sage/modular/abvar/homology.py +++ b/src/sage/modular/abvar/homology.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint sage.libs.pari r""" Homology of modular abelian varieties @@ -37,7 +38,8 @@ [-4 0] [ 0 -4] sage: a.T(7) - Hecke operator T_7 on Submodule of rank 2 of Integral Homology of Abelian variety J0(43) of dimension 3 + Hecke operator T_7 on + Submodule of rank 2 of Integral Homology of Abelian variety J0(43) of dimension 3 """ # **************************************************************************** @@ -272,7 +274,8 @@ def hecke_matrix(self, n): sage: J = J0(23) sage: J.homology(QQ[I]).hecke_matrix(3).parent() - Full MatrixSpace of 4 by 4 dense matrices over Number Field in I with defining polynomial x^2 + 1 with I = 1*I + Full MatrixSpace of 4 by 4 dense matrices over + Number Field in I with defining polynomial x^2 + 1 with I = 1*I """ raise NotImplementedError @@ -694,16 +697,19 @@ def hecke_bound(self): def hecke_matrix(self, n): """ - Return the matrix of the n-th Hecke operator acting on this + Return the matrix of the `n`-th Hecke operator acting on this homology group. EXAMPLES:: sage: d = J0(125).homology(GF(17)).decomposition(2); d [ - Submodule of rank 4 of Homology with coefficients in Finite Field of size 17 of Abelian variety J0(125) of dimension 8, - Submodule of rank 4 of Homology with coefficients in Finite Field of size 17 of Abelian variety J0(125) of dimension 8, - Submodule of rank 8 of Homology with coefficients in Finite Field of size 17 of Abelian variety J0(125) of dimension 8 + Submodule of rank 4 of Homology with coefficients in Finite Field of size 17 + of Abelian variety J0(125) of dimension 8, + Submodule of rank 4 of Homology with coefficients in Finite Field of size 17 + of Abelian variety J0(125) of dimension 8, + Submodule of rank 8 of Homology with coefficients in Finite Field of size 17 + of Abelian variety J0(125) of dimension 8 ] sage: t = d[0].hecke_matrix(17); t [16 15 15 0] diff --git a/src/sage/modular/abvar/homspace.py b/src/sage/modular/abvar/homspace.py index 06ec268e2ec..964df397a93 100644 --- a/src/sage/modular/abvar/homspace.py +++ b/src/sage/modular/abvar/homspace.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint sage.libs.pari """ Spaces of homomorphisms between modular abelian varieties @@ -16,7 +17,8 @@ Simple abelian subvariety 37b(1,37) of dimension 1 of J0(37) ] sage: D[0].intersection(D[1]) - (Finite subgroup with invariants [2, 2] over QQ of Simple abelian subvariety 37a(1,37) of dimension 1 of J0(37), + (Finite subgroup with invariants [2, 2] over QQ of + Simple abelian subvariety 37a(1,37) of dimension 1 of J0(37), Simple abelian subvariety of dimension 0 of J0(37)) As an abstract product, since these newforms are distinct, the @@ -218,7 +220,8 @@ def __init__(self, domain, codomain, cat): EXAMPLES:: sage: H = Hom(J0(11), J0(22)); H - Space of homomorphisms from Abelian variety J0(11) of dimension 1 to Abelian variety J0(22) of dimension 2 + Space of homomorphisms from Abelian variety J0(11) of dimension 1 + to Abelian variety J0(22) of dimension 2 sage: Hom(J0(11), J0(11)) Endomorphism ring of Abelian variety J0(11) of dimension 1 sage: type(H) diff --git a/src/sage/modular/abvar/lseries.py b/src/sage/modular/abvar/lseries.py index 84823684f03..4d67f7b2dfd 100644 --- a/src/sage/modular/abvar/lseries.py +++ b/src/sage/modular/abvar/lseries.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint """ `L`-series of modular abelian varieties @@ -99,29 +100,29 @@ def __call__(self, s, prec=53): EXAMPLES:: sage: L = J0(23).lseries() - sage: L(1) + sage: L(1) # needs sage.symbolic 0.248431866590600 - sage: L(1, prec=100) + sage: L(1, prec=100) # needs sage.symbolic 0.24843186659059968120725033931 sage: L = J0(389)[0].lseries() - sage: L(1) # long time (2s) abstol 1e-10 + sage: L(1) # abstol 1e-10 # long time (2s), needs sage.symbolic -1.33139759782370e-19 - sage: L(1, prec=100) # long time (2s) abstol 1e-20 + sage: L(1, prec=100) # abstol 1e-20 # long time (2s), needs sage.symbolic 6.0129758648142797032650287762e-39 sage: L.rational_part() 0 sage: L = J1(23)[0].lseries() - sage: L(1) + sage: L(1) # needs sage.symbolic 0.248431866590600 sage: J = J0(11) * J1(11) - sage: J.lseries()(1) + sage: J.lseries()(1) # needs sage.symbolic 0.0644356903227915 sage: L = JH(17,[2]).lseries() - sage: L(1) + sage: L(1) # needs sage.symbolic 0.386769938387780 """ diff --git a/src/sage/modular/abvar/morphism.py b/src/sage/modular/abvar/morphism.py index f0f3c065577..cc7e5a22ab2 100644 --- a/src/sage/modular/abvar/morphism.py +++ b/src/sage/modular/abvar/morphism.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint r""" Hecke operators and morphisms between modular abelian varieties diff --git a/src/sage/modular/abvar/torsion_point.py b/src/sage/modular/abvar/torsion_point.py index a7cdd54ff3a..6702a231cbb 100644 --- a/src/sage/modular/abvar/torsion_point.py +++ b/src/sage/modular/abvar/torsion_point.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.rings.number_field """ Torsion points on modular abelian varieties @@ -30,10 +31,10 @@ class TorsionPoint(ModuleElement): - ``parent`` -- a finite subgroup of a modular abelian variety - ``element`` -- a `\QQ`-vector space element that represents - this element in terms of the ambient rational homology + this element in terms of the ambient rational homology - ``check`` -- bool (default: ``True``): whether to check that - element is in the appropriate vector space + element is in the appropriate vector space EXAMPLES: @@ -78,7 +79,8 @@ def element(self): sage: J = J0(11) sage: G = J.finite_subgroup([[1/3,0], [0,1/5]]); G - Finite subgroup with invariants [15] over QQbar of Abelian variety J0(11) of dimension 1 + Finite subgroup with invariants [15] over QQbar of + Abelian variety J0(11) of dimension 1 sage: G.0.element() (1/3, 0) @@ -194,7 +196,7 @@ def _richcmp_(self, right, op): INPUT: - ``self, right`` -- elements of the same finite abelian - variety subgroup. + variety subgroup. - ``op`` -- comparison operator (see :mod:`sage.structure.richcmp`) @@ -255,10 +257,12 @@ def _relative_element(self): EXAMPLES:: + sage: # needs sage.libs.flint sage: A = J0(43)[1]; A Simple abelian subvariety 43b(1,43) of dimension 2 of J0(43) sage: C = A.cuspidal_subgroup(); C - Finite subgroup with invariants [7] over QQ of Simple abelian subvariety 43b(1,43) of dimension 2 of J0(43) + Finite subgroup with invariants [7] over QQ of + Simple abelian subvariety 43b(1,43) of dimension 2 of J0(43) sage: x = C.0; x [(0, 1/7, 0, 6/7, 0, 5/7)] sage: x._relative_element() diff --git a/src/sage/modular/abvar/torsion_subgroup.py b/src/sage/modular/abvar/torsion_subgroup.py index 14a52ba0284..5993a611355 100644 --- a/src/sage/modular/abvar/torsion_subgroup.py +++ b/src/sage/modular/abvar/torsion_subgroup.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint sage.libs.pari """ Torsion subgroups of modular abelian varieties @@ -176,11 +177,11 @@ def order(self, proof=True): subgroup. The computation of the rational torsion order of J1(p) is conjectural - and will only be used if proof=False. See Section 6.2.3 of [CES2003]_. + and will only be used if ``proof=False``. See Section 6.2.3 of [CES2003]_. INPUT: - - ``proof`` -- a boolean (default: True) + - ``proof`` -- a boolean (default: ``True``) OUTPUT: @@ -202,13 +203,14 @@ def order(self, proof=True): sage: J.rational_torsion_subgroup().order() 19 - Sometimes the order can only be computed with proof=False. :: + Sometimes the order can only be computed with ``proof=False``. :: sage: J = J1(23) sage: J.rational_torsion_subgroup().order() Traceback (most recent call last): ... - RuntimeError: Unable to compute order of torsion subgroup (it is in [408991, 9406793]) + RuntimeError: Unable to compute order of torsion subgroup + (it is in [408991, 9406793]) sage: J.rational_torsion_subgroup().order(proof=False) 408991 @@ -249,7 +251,8 @@ def lattice(self): sage: T.lattice() Traceback (most recent call last): ... - NotImplementedError: unable to compute the rational torsion subgroup in this case (there is no known general algorithm yet) + NotImplementedError: unable to compute the rational torsion subgroup + in this case (there is no known general algorithm yet) The problem is that the multiple of the order obtained by counting points over finite fields is twice the divisor of the order got @@ -278,14 +281,14 @@ def possible_orders(self, proof=True): INPUT: - - ``proof`` -- a boolean (default: True) + - ``proof`` -- a boolean (default: ``True``) OUTPUT: - an array of positive integers The computation of the rational torsion order of J1(p) is conjectural - and will only be used if proof=False. See Section 6.2.3 of [CES2003]_. + and will only be used if ``proof=False``. See Section 6.2.3 of [CES2003]_. EXAMPLES:: @@ -431,7 +434,7 @@ def multiple_of_order(self, maxp=None, proof=True): performance. :: sage: J = J1(23) - sage: J.rational_torsion_subgroup().multiple_of_order() # long time (2s) + sage: J.rational_torsion_subgroup().multiple_of_order() # long time (2s) 9406793 sage: J.rational_torsion_subgroup().multiple_of_order(proof=False) 408991 @@ -680,7 +683,7 @@ def __init__(self, abvar): EXAMPLES:: sage: A = J0(23) - sage: A.qbar_torsion_subgroup() + sage: A.qbar_torsion_subgroup() # needs sage.rings.number_field Group of all torsion points in QQbar on Abelian variety J0(23) of dimension 2 """ self.__abvar = abvar @@ -694,7 +697,7 @@ def _repr_(self): EXAMPLES:: - sage: J0(23).qbar_torsion_subgroup()._repr_() + sage: J0(23).qbar_torsion_subgroup()._repr_() # needs sage.rings.number_field 'Group of all torsion points in QQbar on Abelian variety J0(23) of dimension 2' """ return 'Group of all torsion points in QQbar on %s' % self.__abvar @@ -709,7 +712,7 @@ def field_of_definition(self): EXAMPLES:: - sage: J0(23).qbar_torsion_subgroup().field_of_definition() + sage: J0(23).qbar_torsion_subgroup().field_of_definition() # needs sage.rings.number_field Rational Field """ return self.__abvar.base_field() @@ -726,9 +729,9 @@ def _element_constructor_(self, x): EXAMPLES:: - sage: P = J0(23).qbar_torsion_subgroup()([1,1/2,3/4,2]); P + sage: P = J0(23).qbar_torsion_subgroup()([1,1/2,3/4,2]); P # needs sage.rings.number_field [(1, 1/2, 3/4, 2)] - sage: P.order() + sage: P.order() # needs sage.rings.number_field 4 """ v = self.__abvar.vector_space()(x) @@ -743,7 +746,7 @@ def abelian_variety(self): EXAMPLES:: - sage: J0(23).qbar_torsion_subgroup().abelian_variety() + sage: J0(23).qbar_torsion_subgroup().abelian_variety() # needs sage.rings.number_field Abelian variety J0(23) of dimension 2 """ return self.__abvar diff --git a/src/sage/modular/arithgroup/arithgroup_element.pyx b/src/sage/modular/arithgroup/arithgroup_element.pyx index 41b268ea4ef..86f2e550d18 100644 --- a/src/sage/modular/arithgroup/arithgroup_element.pyx +++ b/src/sage/modular/arithgroup/arithgroup_element.pyx @@ -334,12 +334,13 @@ cdef class ArithmeticSubgroupElement(MultiplicativeGroupElement): An example of g acting on a symbolic variable:: - sage: z = var('z') - sage: g.acton(z) + sage: z = var('z') # needs sage.symbolic + sage: g.acton(z) # needs sage.symbolic (z + 2)/(15*z + 31) An example involving the Gaussian numbers:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + 1) sage: g.acton(i) diff --git a/src/sage/modular/arithgroup/arithgroup_generic.py b/src/sage/modular/arithgroup/arithgroup_generic.py index 093541b9b06..0547901b1f1 100644 --- a/src/sage/modular/arithgroup/arithgroup_generic.py +++ b/src/sage/modular/arithgroup/arithgroup_generic.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.pari r""" Arithmetic subgroups, finite index subgroups of `\SL_2(\ZZ)` """ @@ -683,24 +684,24 @@ def reduce_cusp(self, c): def cusps(self, algorithm='default'): r""" - Return a sorted list of inequivalent cusps for self, i.e. a set of + Return a sorted list of inequivalent cusps for ``self``, i.e. a set of representatives for the orbits of self on `\mathbb{P}^1(\QQ)`. These should be returned in a reduced form where this makes sense. INPUT: - - ``algorithm`` -- which algorithm to use to compute the cusps of self. + - ``algorithm`` -- which algorithm to use to compute the cusps of ``self``. ``'default'`` finds representatives for a known complete set of cusps. ``'modsym'`` computes the boundary map on the space of weight - two modular symbols associated to self, which finds the cusps for - self in the process. + two modular symbols associated to ``self``, which finds the cusps for + ``self`` in the process. EXAMPLES:: sage: Gamma0(36).cusps() [0, 1/18, 1/12, 1/9, 1/6, 1/4, 1/3, 5/12, 1/2, 2/3, 5/6, Infinity] - sage: Gamma0(36).cusps(algorithm='modsym') == Gamma0(36).cusps() + sage: Gamma0(36).cusps(algorithm='modsym') == Gamma0(36).cusps() # needs sage.libs.flint True sage: GammaH(36, [19,29]).cusps() == Gamma0(36).cusps() True @@ -898,8 +899,8 @@ def generalised_level(self): sage: Gamma0(18).generalised_level() 18 - sage: from sage.modular.arithgroup.arithgroup_perm import HsuExample18 - sage: HsuExample18().generalised_level() + sage: from sage.modular.arithgroup.arithgroup_perm import HsuExample18 # needs sage.groups + sage: HsuExample18().generalised_level() # needs sage.groups 24 In the following example, the actual level is twice the generalised @@ -1256,7 +1257,7 @@ def dimension_eis(self, k=2): def as_permutation_group(self): r""" - Return self as an arithmetic subgroup defined in terms of the + Return ``self`` as an arithmetic subgroup defined in terms of the permutation action of `SL(2,\ZZ)` on its right cosets. This method uses Todd-Coxeter enumeration (via the method @@ -1265,6 +1266,7 @@ def as_permutation_group(self): EXAMPLES:: + sage: # needs sage.groups sage: G = Gamma(3) sage: P = G.as_permutation_group(); P Arithmetic subgroup of index 24 diff --git a/src/sage/modular/arithgroup/arithgroup_perm.py b/src/sage/modular/arithgroup/arithgroup_perm.py index 9f7371c1702..eb0e645559a 100644 --- a/src/sage/modular/arithgroup/arithgroup_perm.py +++ b/src/sage/modular/arithgroup/arithgroup_perm.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.groups r""" Arithmetic subgroups defined by permutations of cosets diff --git a/src/sage/modular/arithgroup/congroup_gamma.py b/src/sage/modular/arithgroup/congroup_gamma.py index a9eeb2a5769..47d5390b8f4 100644 --- a/src/sage/modular/arithgroup/congroup_gamma.py +++ b/src/sage/modular/arithgroup/congroup_gamma.py @@ -105,7 +105,7 @@ def __richcmp__(self, other, op): EXAMPLES:: - sage: Gamma(3) == SymmetricGroup(8) + sage: Gamma(3) == SymmetricGroup(8) # needs sage.groups False sage: Gamma(3) == Gamma1(3) False @@ -113,7 +113,7 @@ def __richcmp__(self, other, op): True sage: Gamma(5) == Gamma(5) True - sage: Gamma(3) == Gamma(3).as_permutation_group() + sage: Gamma(3) == Gamma(3).as_permutation_group() # needs sage.groups True """ if is_Gamma(other): diff --git a/src/sage/modular/arithgroup/congroup_gamma0.py b/src/sage/modular/arithgroup/congroup_gamma0.py index 70d263ebc45..5c57f12a511 100644 --- a/src/sage/modular/arithgroup/congroup_gamma0.py +++ b/src/sage/modular/arithgroup/congroup_gamma0.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.pari r""" Congruence subgroup `\Gamma_0(N)` """ @@ -99,9 +100,11 @@ class Gamma0_class(GammaH_class): Independently compute the dimension 5 above:: - sage: m = ModularSymbols(100, 2,sign=1).cuspidal_subspace() + sage: m = ModularSymbols(100, 2, sign=1).cuspidal_subspace() sage: m.new_subspace(5) - Modular Symbols subspace of dimension 5 of Modular Symbols space of dimension 18 for Gamma_0(100) of weight 2 with sign 1 over Rational Field + Modular Symbols subspace of dimension 5 of + Modular Symbols space of dimension 18 for Gamma_0(100) + of weight 2 with sign 1 over Rational Field """ @@ -225,13 +228,13 @@ def divisor_subgroups(self): sage: Gamma0(24).divisor_subgroups() [Modular Group SL(2,Z), - Congruence Subgroup Gamma0(2), - Congruence Subgroup Gamma0(3), - Congruence Subgroup Gamma0(4), - Congruence Subgroup Gamma0(6), - Congruence Subgroup Gamma0(8), - Congruence Subgroup Gamma0(12), - Congruence Subgroup Gamma0(24)] + Congruence Subgroup Gamma0(2), + Congruence Subgroup Gamma0(3), + Congruence Subgroup Gamma0(4), + Congruence Subgroup Gamma0(6), + Congruence Subgroup Gamma0(8), + Congruence Subgroup Gamma0(12), + Congruence Subgroup Gamma0(24)] """ return [Gamma0_constructor(M) for M in self.level().divisors()] @@ -329,8 +332,8 @@ def generators(self, algorithm="farey"): INPUT: - - ``algorithm`` (string): either ``farey`` (default) or - ``todd-coxeter``. + - ``algorithm`` (string): either ``"farey"`` (default) or + ``"todd-coxeter"``. If ``algorithm`` is set to ``"farey"``, then the generators will be calculated using Farey symbols, which will always return a *minimal* @@ -388,10 +391,17 @@ def gamma_h_subgroups(self): sage: G = Gamma0(11) sage: G.gamma_h_subgroups() - [Congruence Subgroup Gamma0(11), Congruence Subgroup Gamma_H(11) with H generated by [3], Congruence Subgroup Gamma_H(11) with H generated by [10], Congruence Subgroup Gamma1(11)] + [Congruence Subgroup Gamma0(11), + Congruence Subgroup Gamma_H(11) with H generated by [3], + Congruence Subgroup Gamma_H(11) with H generated by [10], + Congruence Subgroup Gamma1(11)] sage: G = Gamma0(12) sage: G.gamma_h_subgroups() - [Congruence Subgroup Gamma0(12), Congruence Subgroup Gamma_H(12) with H generated by [7], Congruence Subgroup Gamma_H(12) with H generated by [11], Congruence Subgroup Gamma_H(12) with H generated by [5], Congruence Subgroup Gamma1(12)] + [Congruence Subgroup Gamma0(12), + Congruence Subgroup Gamma_H(12) with H generated by [7], + Congruence Subgroup Gamma_H(12) with H generated by [11], + Congruence Subgroup Gamma_H(12) with H generated by [5], + Congruence Subgroup Gamma1(12)] """ from .all import GammaH N = self.level() diff --git a/src/sage/modular/arithgroup/congroup_gamma1.py b/src/sage/modular/arithgroup/congroup_gamma1.py index 00dc9e8c0a5..c8bc6fb0320 100644 --- a/src/sage/modular/arithgroup/congroup_gamma1.py +++ b/src/sage/modular/arithgroup/congroup_gamma1.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.libs.pari r""" Congruence subgroup `\Gamma_1(N)` """ @@ -357,10 +357,10 @@ def dimension_modular_forms(self, k=2, eps=None, algorithm="CohenOesterle"): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K = CyclotomicField(3) sage: eps = DirichletGroup(7*43,K).0^2 sage: G = Gamma1(7*43) - sage: G.dimension_modular_forms(2, eps) 32 sage: G.dimension_modular_forms(2, eps, algorithm="Quer") @@ -370,6 +370,7 @@ def dimension_modular_forms(self, k=2, eps=None, algorithm="CohenOesterle"): Check that :trac:`18436` is fixed:: + sage: # needs sage.rings.number_field sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^2 + x + 1) sage: G = DirichletGroup(13, base_ring=K) @@ -386,7 +387,7 @@ def dimension_modular_forms(self, k=2, eps=None, algorithm="CohenOesterle"): def dimension_cusp_forms(self, k=2, eps=None, algorithm="CohenOesterle"): r""" - Return the dimension of the space of cusp forms for self, or the + Return the dimension of the space of cusp forms for ``self``, or the dimension of the subspace corresponding to the given character if one is supplied. @@ -409,18 +410,19 @@ def dimension_cusp_forms(self, k=2, eps=None, algorithm="CohenOesterle"): We compute the same dimension in two different ways :: + sage: # needs sage.rings.number_field sage: K = CyclotomicField(3) sage: eps = DirichletGroup(7*43,K).0^2 sage: G = Gamma1(7*43) Via Cohen--Oesterle:: - sage: Gamma1(7*43).dimension_cusp_forms(2, eps) + sage: Gamma1(7*43).dimension_cusp_forms(2, eps) # needs sage.rings.number_field 28 Via Quer's method:: - sage: Gamma1(7*43).dimension_cusp_forms(2, eps, algorithm="Quer") + sage: Gamma1(7*43).dimension_cusp_forms(2, eps, algorithm="Quer") # needs sage.rings.number_field 28 Some more examples:: diff --git a/src/sage/modular/arithgroup/congroup_gammaH.py b/src/sage/modular/arithgroup/congroup_gammaH.py index 20da4f05b3e..c9e53fdf3a8 100644 --- a/src/sage/modular/arithgroup/congroup_gammaH.py +++ b/src/sage/modular/arithgroup/congroup_gammaH.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.libs.pari r""" Congruence subgroup `\Gamma_H(N)` diff --git a/src/sage/modular/arithgroup/congroup_generic.py b/src/sage/modular/arithgroup/congroup_generic.py index edf056784e6..3fd60c06165 100644 --- a/src/sage/modular/arithgroup/congroup_generic.py +++ b/src/sage/modular/arithgroup/congroup_generic.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint sage.libs.gap sage.libs.pari r""" Congruence arithmetic subgroups of `\SL_2(\ZZ)` diff --git a/src/sage/modular/arithgroup/farey_symbol.pyx b/src/sage/modular/arithgroup/farey_symbol.pyx index cd80cb32f3e..27cbeafd9fc 100644 --- a/src/sage/modular/arithgroup/farey_symbol.pyx +++ b/src/sage/modular/arithgroup/farey_symbol.pyx @@ -1,5 +1,5 @@ # distutils: sources = sage/modular/arithgroup/sl2z.cpp sage/modular/arithgroup/farey.cpp - +# sage.doctest: needs sage.libs.pari r""" Farey symbol for arithmetic subgroups of `\PSL_2(\ZZ)` @@ -43,7 +43,7 @@ from sage.misc.cachefunc import cached_method from sage.structure.richcmp cimport richcmp_not_equal -cdef extern from "sage/modular/arithgroup/sl2z.hpp": +cdef extern from "sl2z.hpp": cppclass cpp_SL2Z "SL2Z": mpz_class a, b, c, d cpp_SL2Z(int, int, int, int) @@ -53,7 +53,7 @@ cdef extern from "sage/modular/arithgroup/sl2z.hpp": mpz_class c() mpz_class d() -cdef extern from "sage/modular/arithgroup/farey.hpp": +cdef extern from "farey.hpp": cppclass is_element_Gamma0: is_element_Gamma0(int) cppclass is_element_Gamma1: @@ -731,6 +731,7 @@ cdef class Farey: The unique index 2 even subgroup and index 4 odd subgroup each get handled correctly:: + sage: # needs sage.groups sage: FareySymbol(ArithmeticSubgroup_Permutation(S2="(1,2)", S3="()")).generators() [ [ 0 1] [-1 1] @@ -876,6 +877,7 @@ cdef class Farey: Reduce 11/17 to a cusp of for HsuExample10():: + sage: # needs sage.groups sage: from sage.modular.arithgroup.arithgroup_perm import HsuExample10 sage: f = FareySymbol(HsuExample10()) sage: f.reduce_to_cusp(11/17) @@ -932,7 +934,7 @@ cdef class Farey: For example, to plot the fundamental domain of `\Gamma_0(11)` with pairings use the following command:: - sage: FareySymbol(Gamma0(11)).fundamental_domain() + sage: FareySymbol(Gamma0(11)).fundamental_domain() # needs sage.plot sage.symbolic Graphics object consisting of 54 graphics primitives indicating that side 1 is paired with side 3 and side 2 is @@ -941,18 +943,20 @@ cdef class Farey: To plot the fundamental domain of `\Gamma(3)` without pairings use the following command:: - sage: FareySymbol(Gamma(3)).fundamental_domain(show_pairing=False) + sage: FareySymbol(Gamma(3)).fundamental_domain(show_pairing=False) # needs sage.plot sage.symbolic Graphics object consisting of 48 graphics primitives Plot the fundamental domain of `\Gamma_0(23)` showing the left coset representatives:: - sage: FareySymbol(Gamma0(23)).fundamental_domain(tesselation='coset') + sage: FareySymbol(Gamma0(23)).fundamental_domain(tesselation='coset') # needs sage.plot sage.symbolic Graphics object consisting of 58 graphics primitives The same as above but with a custom linestyle:: - sage: FareySymbol(Gamma0(23)).fundamental_domain(tesselation='coset', linestyle=':', thickness='2') + sage: FareySymbol(Gamma0(23)).fundamental_domain(tesselation='coset', # needs sage.plot sage.symbolic + ....: linestyle=':', + ....: thickness='2') Graphics object consisting of 58 graphics primitives """ from sage.plot.all import Graphics diff --git a/src/sage/modular/arithgroup/tests.py b/src/sage/modular/arithgroup/tests.py index be49c7d41d2..d30ead3ac4c 100644 --- a/src/sage/modular/arithgroup/tests.py +++ b/src/sage/modular/arithgroup/tests.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.groups r""" Testing arithmetic subgroup """ diff --git a/src/sage/modular/btquotients/btquotient.py b/src/sage/modular/btquotients/btquotient.py index 1bf60ecbefb..3c7bceb0aa3 100644 --- a/src/sage/modular/btquotients/btquotient.py +++ b/src/sage/modular/btquotients/btquotient.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.libs.pari r""" Quotients of the Bruhat-Tits tree @@ -539,8 +539,8 @@ def lift(a): EXAMPLES:: - sage: x = Zp(3)(-17) - sage: lift(x) + sage: x = Zp(3)(-17) # needs sage.rings.padics + sage: lift(x) # needs sage.rings.padics 3486784384 """ try: @@ -600,6 +600,7 @@ def vertex(self, M): EXAMPLES:: + sage: # needs sage.rings.padics sage: from sage.modular.btquotients.btquotient import BruhatTitsTree sage: p = 5 sage: T = BruhatTitsTree(p) @@ -961,6 +962,7 @@ def find_containing_affinoid(self, z): EXAMPLES:: + sage: # needs sage.rings.padics sage: from sage.modular.btquotients.btquotient import BruhatTitsTree sage: T = BruhatTitsTree(5) sage: K. = Qq(5^2,20) @@ -976,9 +978,9 @@ def find_containing_affinoid(self, z): affinoid. That is, it is a `p`-adic unit and its reduction modulo `p` is not in `\GF{p}`:: - sage: gz = (v[0,0]*z+v[0,1])/(v[1,0]*z+v[1,1]); gz + sage: gz = (v[0,0]*z+v[0,1])/(v[1,0]*z+v[1,1]); gz # needs sage.rings.padics (a + 1) + O(5^19) - sage: gz.valuation() == 0 + sage: gz.valuation() == 0 # needs sage.rings.padics True """ # Assume z belongs to some extension of QQp. @@ -1062,6 +1064,7 @@ def find_covering(self, z1, z2, level=0): EXAMPLES:: + sage: # needs sage.rings.padics sage: from sage.modular.btquotients.btquotient import BruhatTitsTree sage: p = 3 sage: K. = Qq(p^2) @@ -2127,7 +2130,7 @@ def plot(self, *args, **kwargs): EXAMPLES:: sage: X = BruhatTitsQuotient(7,23) - sage: X.plot() + sage: X.plot() # needs sage.plot Graphics object consisting of 17 graphics primitives """ S = self.get_graph() @@ -2160,7 +2163,7 @@ def plot_fundom(self, *args, **kwargs): EXAMPLES:: sage: X = BruhatTitsQuotient(7,23) - sage: X.plot_fundom() + sage: X.plot_fundom() # needs sage.plot Graphics object consisting of 88 graphics primitives """ S = self.get_fundom_graph() diff --git a/src/sage/modular/btquotients/pautomorphicform.py b/src/sage/modular/btquotients/pautomorphicform.py index 6428c7357da..656c1f42d89 100644 --- a/src/sage/modular/btquotients/pautomorphicform.py +++ b/src/sage/modular/btquotients/pautomorphicform.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.libs.pari ######################################################################### # Copyright (C) 2011 Cameron Franc and Marc Masdeu # @@ -20,23 +20,23 @@ Create a quotient of the Bruhat-Tits tree:: - sage: X = BruhatTitsQuotient(13,11) + sage: X = BruhatTitsQuotient(13, 11) Declare the corresponding space of harmonic cocycles:: - sage: H = X.harmonic_cocycles(2,prec=5) + sage: H = X.harmonic_cocycles(2, prec=5) And the space of `p`-adic automorphic forms:: - sage: A = X.padic_automorphic_forms(2,prec=5,overconvergent=True) + sage: A = X.padic_automorphic_forms(2, prec=5, overconvergent=True) # needs sage.rings.padics Harmonic cocycles, unlike `p`-adic automorphic forms, can be used to compute a basis:: - sage: a = H.gen(0) + sage: a = H.gen(0) # needs sage.rings.padics This can then be lifted to an overconvergent `p`-adic modular form:: - sage: A.lift(a) # long time + sage: A.lift(a) # long time # needs sage.rings.padics p-adic automorphic form of cohomological weight 0 """ @@ -135,9 +135,9 @@ def eval_dist_at_powseries(phi, f): sage: R. = PowerSeriesRing(ZZ,10) sage: f = (1 - 7*X)^(-1) - sage: D = OverconvergentDistributions(0,7,10) - sage: phi = D(list(range(1,11))) - sage: eval_dist_at_powseries(phi,f) + sage: D = OverconvergentDistributions(0,7,10) # needs sage.rings.padics + sage: phi = D(list(range(1,11))) # needs sage.rings.padics + sage: eval_dist_at_powseries(phi,f) # needs sage.rings.padics 1 + 2*7 + 3*7^2 + 4*7^3 + 5*7^4 + 6*7^5 + 2*7^7 + 3*7^8 + 4*7^9 + O(7^10) """ nmoments = phi.parent().precision_cap() diff --git a/src/sage/modular/buzzard.py b/src/sage/modular/buzzard.py index 99ee6673d2a..72e72e745cc 100644 --- a/src/sage/modular/buzzard.py +++ b/src/sage/modular/buzzard.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.pari """ Conjectural slopes of Hecke polynomials diff --git a/src/sage/modular/cusps.py b/src/sage/modular/cusps.py index 098c7e52a24..fd8a6d7bc58 100644 --- a/src/sage/modular/cusps.py +++ b/src/sage/modular/cusps.py @@ -742,6 +742,7 @@ def is_gamma_h_equiv(self, other, G): EXAMPLES:: + sage: # needs sage.libs.pari sage: x = Cusp(2,3) sage: y = Cusp(4,5) sage: x.is_gamma_h_equiv(y,GammaH(13,[2])) @@ -758,8 +759,10 @@ def is_gamma_h_equiv(self, other, G): :: - sage: G = GammaH(25,[6]) ; M = G.modular_symbols() ; M - Modular Symbols space of dimension 11 for Congruence Subgroup Gamma_H(25) with H generated by [6] of weight 2 with sign 0 over Rational Field + sage: # needs sage.libs.pari + sage: G = GammaH(25,[6]); M = G.modular_symbols(); M + Modular Symbols space of dimension 11 for Congruence Subgroup Gamma_H(25) + with H generated by [6] of weight 2 with sign 0 over Rational Field sage: M.cusps() [8/25, 1/3, 6/25, 1/4, 1/15, -7/15, 7/15, 4/15, 1/20, 3/20, 7/20, 9/20] sage: len(M.cusps()) @@ -770,10 +773,13 @@ def is_gamma_h_equiv(self, other, G): :: + sage: # needs sage.libs.pari sage: G.dimension_eis(2) 11 sage: M.cuspidal_subspace() - Modular Symbols subspace of dimension 0 of Modular Symbols space of dimension 11 for Congruence Subgroup Gamma_H(25) with H generated by [6] of weight 2 with sign 0 over Rational Field + Modular Symbols subspace of dimension 0 of + Modular Symbols space of dimension 11 for Congruence Subgroup Gamma_H(25) + with H generated by [6] of weight 2 with sign 0 over Rational Field sage: G.dimension_cusp_forms(2) 0 """ @@ -934,6 +940,7 @@ def galois_action(self, t, N): Here we check that the Galois action is indeed a permutation on the cusps of Gamma1(48) and check that :trac:`13253` is fixed. :: + sage: # needs sage.libs.pari sage: G = Gamma1(48) sage: C = G.cusps() sage: for i in Integers(48).unit_gens(): @@ -943,6 +950,7 @@ def galois_action(self, t, N): We test that Gamma1(19) has 9 rational cusps and check that :trac:`8998` is fixed. :: + sage: # needs sage.libs.pari sage: G = Gamma1(19) sage: [c for c in G.cusps() if c.galois_action(2,19).is_gamma1_equiv(c,19)[0]] [2/19, 3/19, 4/19, 5/19, 6/19, 7/19, 8/19, 9/19, Infinity] @@ -1003,9 +1011,9 @@ def __pari__(self): EXAMPLES:: - sage: Cusp(1, 0).__pari__() + sage: Cusp(1, 0).__pari__() # needs sage.libs.pari +oo - sage: pari(Cusp(3, 2)) + sage: pari(Cusp(3, 2)) # needs sage.libs.pari 3/2 """ b = self.__b diff --git a/src/sage/modular/dims.py b/src/sage/modular/dims.py index f2f63b3433c..ab1f9cbc268 100644 --- a/src/sage/modular/dims.py +++ b/src/sage/modular/dims.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.libs.pari r""" Dimensions of spaces of modular forms @@ -227,6 +227,7 @@ def _lambda(r, s, p): :: + sage: # needs sage.rings.number_field sage: K = CyclotomicField(3) sage: eps = DirichletGroup(7*43, K).0^2 sage: sage.modular.dims.CohenOesterle(eps, 2) diff --git a/src/sage/modular/dirichlet.py b/src/sage/modular/dirichlet.py index 9785c18963f..e752cc36b59 100644 --- a/src/sage/modular/dirichlet.py +++ b/src/sage/modular/dirichlet.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.libs.pari r""" Dirichlet characters @@ -400,6 +400,7 @@ def _richcmp_(self, other, op): EXAMPLES:: + sage: # needs sage.rings.number_field sage: e = DirichletGroup(16)([-1, 1]) sage: f = e.restrict(8) sage: e == e @@ -420,6 +421,7 @@ def __hash__(self): EXAMPLES:: + sage: # needs sage.rings.number_field sage: e = DirichletGroup(16)([-1, 1]) sage: hash(e) == hash((-1,1)) True @@ -560,6 +562,7 @@ def _latex_(self): EXAMPLES:: + sage: # needs sage.rings.number_field sage: G. = DirichletGroup(16) sage: latex(b) # indirect doctest \hbox{Dirichlet character modulo } 16 \hbox{ of conductor } 16 \hbox{ mapping } 15 \mapsto 1,\ 5 \mapsto \zeta_{4} @@ -1124,6 +1127,7 @@ def _pari_init_(self): EXAMPLES:: + sage: # needs sage.rings.number_field sage: chi4 = DirichletGroup(4).gen() sage: pari(chi4) [[[4, [0]], [2, [2], [3]], [[2]~, Vecsmall([2])], @@ -1178,6 +1182,7 @@ def conrey_number(self): EXAMPLES:: + sage: # needs sage.rings.number_field sage: chi4 = DirichletGroup(4).gen() sage: chi4.conrey_number() 3 @@ -1218,6 +1223,7 @@ def lmfdb_page(self): EXAMPLES:: + sage: # needs sage.rings.number_field sage: E = DirichletGroup(4).gen() sage: E.lmfdb_page() # optional -- webbrowser """ @@ -2106,6 +2112,7 @@ def values_on_gens(self): EXAMPLES:: + sage: # needs sage.rings.number_field sage: e = DirichletGroup(16)([-1, 1]) sage: e.values_on_gens () (-1, 1) @@ -2162,6 +2169,7 @@ def __setstate__(self, state): TESTS:: + sage: # needs sage.rings.number_field sage: e = DirichletGroup(16)([-1, 1]) sage: loads(dumps(e)) == e True @@ -2361,13 +2369,15 @@ class DirichletGroupFactory(UniqueFactory): If the order of ``zeta`` cannot be determined automatically, we can specify it using ``zeta_order``:: - sage: DirichletGroup(7, CC, zeta=exp(2*pi*I/6)) + sage: DirichletGroup(7, CC, zeta=exp(2*pi*I/6)) # needs sage.symbolic Traceback (most recent call last): ... NotImplementedError: order of element not known - sage: DirichletGroup(7, CC, zeta=exp(2*pi*I/6), zeta_order=6) - Group of Dirichlet characters modulo 7 with values in the group of order 6 generated by 0.500000000000000 + 0.866025403784439*I in Complex Field with 53 bits of precision + sage: DirichletGroup(7, CC, zeta=exp(2*pi*I/6), zeta_order=6) # needs sage.symbolic + Group of Dirichlet characters modulo 7 with values in the group of order 6 + generated by 0.500000000000000 + 0.866025403784439*I + in Complex Field with 53 bits of precision If the base ring is not a domain (in which case the group of roots of unity is not necessarily cyclic), some operations still work, @@ -2495,9 +2505,11 @@ def create_object(self, version, key, **extra_args): TESTS:: + sage: # needs sage.rings.number_field sage: K = CyclotomicField(4) sage: DirichletGroup.create_object(None, (K, 60, K.gen(), 4)) - Group of Dirichlet characters modulo 60 with values in the group of order 4 generated by zeta4 in Cyclotomic Field of order 4 and degree 2 + Group of Dirichlet characters modulo 60 with values in the group of order 4 + generated by zeta4 in Cyclotomic Field of order 4 and degree 2 """ base_ring, modulus, zeta, zeta_order = key @@ -2656,18 +2668,21 @@ def change_ring(self, R, zeta=None, zeta_order=None): sage: G = DirichletGroup(7,QQ); G Group of Dirichlet characters modulo 7 with values in Rational Field - sage: G.change_ring(CyclotomicField(6)) - Group of Dirichlet characters modulo 7 with values in Cyclotomic Field of order 6 and degree 2 + sage: G.change_ring(CyclotomicField(6)) # needs sage.rings.number_field + Group of Dirichlet characters modulo 7 with values in + Cyclotomic Field of order 6 and degree 2 TESTS: We test the case where `R` is a map (:trac:`18072`):: + sage: # needs sage.rings.number_field sage: K. = QuadraticField(-1) sage: f = K.complex_embeddings()[0] sage: D = DirichletGroup(5, K) sage: D.change_ring(f) - Group of Dirichlet characters modulo 5 with values in Complex Field with 53 bits of precision + Group of Dirichlet characters modulo 5 with values in + Complex Field with 53 bits of precision """ if zeta is None and self._zeta is not None: diff --git a/src/sage/modular/hecke/algebra.py b/src/sage/modular/hecke/algebra.py index 0f6f5536a70..4ccc6d0b1bf 100644 --- a/src/sage/modular/hecke/algebra.py +++ b/src/sage/modular/hecke/algebra.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint sage.libs.pari """ Hecke algebras diff --git a/src/sage/modular/hecke/ambient_module.py b/src/sage/modular/hecke/ambient_module.py index e5ed6158cb5..4d0b4c583ea 100644 --- a/src/sage/modular/hecke/ambient_module.py +++ b/src/sage/modular/hecke/ambient_module.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint sage.libs.pari """ Ambient Hecke modules """ diff --git a/src/sage/modular/hecke/degenmap.py b/src/sage/modular/hecke/degenmap.py index fad128c0c3c..887506e7559 100644 --- a/src/sage/modular/hecke/degenmap.py +++ b/src/sage/modular/hecke/degenmap.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint """ Degeneracy maps """ @@ -32,7 +33,8 @@ class DegeneracyMap(morphism.HeckeModuleMorphism_matrix): sage: M = ModularSymbols(33) sage: d = M.degeneracy_map(11) sage: d - Hecke module morphism degeneracy map corresponding to f(q) |--> f(q) defined by the matrix + Hecke module morphism degeneracy map corresponding to f(q) |--> f(q) + defined by the matrix [ 1 0 0] [ 0 0 1] [ 0 0 -1] @@ -55,12 +57,14 @@ class DegeneracyMap(morphism.HeckeModuleMorphism_matrix): sage: d = M.degeneracy_map(11,2) Traceback (most recent call last): ... - ValueError: the level of self (=33) must be a divisor or multiple of level (=11) and t (=2) must be a divisor of the quotient + ValueError: the level of self (=33) must be a divisor or multiple + of level (=11) and t (=2) must be a divisor of the quotient Degeneracy maps can also go from lower level to higher level:: sage: M.degeneracy_map(66,2) - Hecke module morphism degeneracy map corresponding to f(q) |--> f(q^2) defined by the matrix + Hecke module morphism degeneracy map corresponding to f(q) |--> f(q^2) + defined by the matrix [ 2 0 0 0 0 0 1 0 0 0 1 -1 0 0 0 -1 1 0 0 0 0 0 0 0 -1] [ 0 0 1 -1 0 -1 1 0 -1 2 0 0 0 -1 0 0 -1 1 2 -2 0 0 0 -1 1] [ 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 -1 1 0 0 -1 1 0 0 0] diff --git a/src/sage/modular/hecke/element.py b/src/sage/modular/hecke/element.py index b91d33b6b8d..d4ecd4b380a 100644 --- a/src/sage/modular/hecke/element.py +++ b/src/sage/modular/hecke/element.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint sage.libs.pari """ Elements of Hecke modules diff --git a/src/sage/modular/hecke/hecke_operator.py b/src/sage/modular/hecke/hecke_operator.py index e0401936daa..a6b3faf2ffc 100644 --- a/src/sage/modular/hecke/hecke_operator.py +++ b/src/sage/modular/hecke/hecke_operator.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint sage.libs.pari """ Hecke operators """ diff --git a/src/sage/modular/hecke/homspace.py b/src/sage/modular/hecke/homspace.py index 2245067bf99..1e6f55e0838 100644 --- a/src/sage/modular/hecke/homspace.py +++ b/src/sage/modular/hecke/homspace.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.pari r""" Hom spaces between Hecke modules """ @@ -181,6 +182,7 @@ def _an_element_(self): EXAMPLES:: + sage: # needs sage.libs.flint sage: M = ModularSymbols(Gamma0(2), weight=12, sign=1) sage: S = M.cuspidal_subspace() sage: S.Hom(S).an_element() diff --git a/src/sage/modular/hecke/module.py b/src/sage/modular/hecke/module.py index 8e1b699658c..d0d8d5e49d7 100644 --- a/src/sage/modular/hecke/module.py +++ b/src/sage/modular/hecke/module.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint sage.libs.pari """ Hecke modules """ diff --git a/src/sage/modular/hecke/morphism.py b/src/sage/modular/hecke/morphism.py index 373d2b67298..ac9cfbf4e84 100644 --- a/src/sage/modular/hecke/morphism.py +++ b/src/sage/modular/hecke/morphism.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint """ Morphisms of Hecke modules diff --git a/src/sage/modular/hecke/submodule.py b/src/sage/modular/hecke/submodule.py index c1112d685b6..379daa00f7a 100644 --- a/src/sage/modular/hecke/submodule.py +++ b/src/sage/modular/hecke/submodule.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint sage.libs.pari """ Submodules of Hecke modules """ diff --git a/src/sage/modular/local_comp/liftings.py b/src/sage/modular/local_comp/liftings.py index dbe80b59b14..dcb901cc3a1 100644 --- a/src/sage/modular/local_comp/liftings.py +++ b/src/sage/modular/local_comp/liftings.py @@ -64,13 +64,13 @@ def lift_to_gamma1(g, m, n): """ if m == 1: return [ZZ.one(), ZZ.zero(), ZZ.zero(), ZZ.one()] - a, b, c, d = [ZZ(x) for x in g] + a, b, c, d = (ZZ(x) for x in g) det = (a * d - b * c) % m if det != 1: raise ValueError("Determinant is {0} mod {1}, should be 1".format(det, m)) c2 = crt(c, 0, m, n) d2 = crt(d, 1, m, n) - a3,b3,c3,d3 = [ZZ(_) for _ in lift_to_sl2z(c2, d2, m * n)] + a3,b3,c3,d3 = (ZZ(_) for _ in lift_to_sl2z(c2, d2, m * n)) r = (a3*b - b3*a) % m return [a3 + r * c3, b3 + r * d3, c3, d3] diff --git a/src/sage/modular/local_comp/local_comp.py b/src/sage/modular/local_comp/local_comp.py index 765ce805ed9..0fb990c17de 100644 --- a/src/sage/modular/local_comp/local_comp.py +++ b/src/sage/modular/local_comp/local_comp.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.pari r""" Local components of modular forms @@ -81,8 +82,10 @@ def LocalComponent(f, p, twist_factor=None): 'Supercuspidal' sage: Pi.characters() [ - Character of unramified extension Q_7(s)* (s^2 + 6*s + 3 = 0), of level 1, mapping s |--> -d, 7 |--> 1, - Character of unramified extension Q_7(s)* (s^2 + 6*s + 3 = 0), of level 1, mapping s |--> d, 7 |--> 1 + Character of unramified extension Q_7(s)* (s^2 + 6*s + 3 = 0), + of level 1, mapping s |--> -d, 7 |--> 1, + Character of unramified extension Q_7(s)* (s^2 + 6*s + 3 = 0), + of level 1, mapping s |--> d, 7 |--> 1 ] """ p = ZZ(p) @@ -643,8 +646,10 @@ def characters(self): sage: Pi = LocalComponent(f, 5) sage: chars = Pi.characters(); chars [ - Character of unramified extension Q_5(s)* (s^2 + 4*s + 2 = 0), of level 1, mapping s |--> -d - 1, 5 |--> 1, - Character of unramified extension Q_5(s)* (s^2 + 4*s + 2 = 0), of level 1, mapping s |--> d, 5 |--> 1 + Character of unramified extension Q_5(s)* (s^2 + 4*s + 2 = 0), + of level 1, mapping s |--> -d - 1, 5 |--> 1, + Character of unramified extension Q_5(s)* (s^2 + 4*s + 2 = 0), + of level 1, mapping s |--> d, 5 |--> 1 ] sage: chars[0].base_ring() Number Field in d with defining polynomial x^2 + x + 1 @@ -661,8 +666,10 @@ def characters(self): sage: Pi = LocalComponent(f, 5) sage: Pi.characters() [ - Character of unramified extension Q_5(s)* (s^2 + 4*s + 2 = 0), of level 1, mapping s |--> 1/3*j0^2*d - 1/3*j0^3, 5 |--> 5, - Character of unramified extension Q_5(s)* (s^2 + 4*s + 2 = 0), of level 1, mapping s |--> -1/3*j0^2*d, 5 |--> 5 + Character of unramified extension Q_5(s)* (s^2 + 4*s + 2 = 0), + of level 1, mapping s |--> 1/3*j0^2*d - 1/3*j0^3, 5 |--> 5, + Character of unramified extension Q_5(s)* (s^2 + 4*s + 2 = 0), + of level 1, mapping s |--> -1/3*j0^2*d, 5 |--> 5 ] sage: Pi.characters()[0].base_ring() Number Field in d with defining polynomial x^2 - j0*x + 1/3*j0^2 over its base field @@ -680,21 +687,27 @@ def characters(self): q + j0*q^2 + q^4 - j0*q^5 + O(q^6) sage: LocalComponent(f, 3).characters() # long time (12s on sage.math, 2012) [ - Character of unramified extension Q_3(s)* (s^2 + 2*s + 2 = 0), of level 2, mapping -2*s |--> -2*d + j0, 4 |--> 1, 3*s + 1 |--> -j0*d + 1, 3 |--> 1, - Character of unramified extension Q_3(s)* (s^2 + 2*s + 2 = 0), of level 2, mapping -2*s |--> 2*d - j0, 4 |--> 1, 3*s + 1 |--> j0*d - 2, 3 |--> 1 + Character of unramified extension Q_3(s)* (s^2 + 2*s + 2 = 0), + of level 2, mapping -2*s |--> -2*d + j0, 4 |--> 1, 3*s + 1 |--> -j0*d + 1, 3 |--> 1, + Character of unramified extension Q_3(s)* (s^2 + 2*s + 2 = 0), + of level 2, mapping -2*s |--> 2*d - j0, 4 |--> 1, 3*s + 1 |--> j0*d - 2, 3 |--> 1 ] Some ramified examples:: sage: Newform('27a').local_component(3).characters() [ - Character of ramified extension Q_3(s)* (s^2 - 6 = 0), of level 2, mapping 2 |--> 1, s + 1 |--> -d, s |--> -1, - Character of ramified extension Q_3(s)* (s^2 - 6 = 0), of level 2, mapping 2 |--> 1, s + 1 |--> d - 1, s |--> -1 + Character of ramified extension Q_3(s)* (s^2 - 6 = 0), + of level 2, mapping 2 |--> 1, s + 1 |--> -d, s |--> -1, + Character of ramified extension Q_3(s)* (s^2 - 6 = 0), + of level 2, mapping 2 |--> 1, s + 1 |--> d - 1, s |--> -1 ] sage: LocalComponent(Newform('54a'), 3, twist_factor=4).characters() [ - Character of ramified extension Q_3(s)* (s^2 - 3 = 0), of level 2, mapping 2 |--> 1, s + 1 |--> -1/9*d, s |--> -9, - Character of ramified extension Q_3(s)* (s^2 - 3 = 0), of level 2, mapping 2 |--> 1, s + 1 |--> 1/9*d - 1, s |--> -9 + Character of ramified extension Q_3(s)* (s^2 - 3 = 0), + of level 2, mapping 2 |--> 1, s + 1 |--> -1/9*d, s |--> -9, + Character of ramified extension Q_3(s)* (s^2 - 3 = 0), + of level 2, mapping 2 |--> 1, s + 1 |--> 1/9*d - 1, s |--> -9 ] A 2-adic non-example:: @@ -709,13 +722,17 @@ def characters(self): sage: Newforms(DirichletGroup(64, QQ).1, 2, names='a')[0].local_component(2).characters() # long time, random [ - Character of unramified extension Q_2(s)* (s^2 + s + 1 = 0), of level 3, mapping s |--> 1, 2*s + 1 |--> 1/2*a0, 4*s + 1 |--> 1, -1 |--> 1, 2 |--> 1, - Character of unramified extension Q_2(s)* (s^2 + s + 1 = 0), of level 3, mapping s |--> 1, 2*s + 1 |--> 1/2*a0, 4*s + 1 |--> -1, -1 |--> 1, 2 |--> 1 + Character of unramified extension Q_2(s)* (s^2 + s + 1 = 0), of level 3, + mapping s |--> 1, 2*s + 1 |--> 1/2*a0, 4*s + 1 |--> 1, -1 |--> 1, 2 |--> 1, + Character of unramified extension Q_2(s)* (s^2 + s + 1 = 0), of level 3, + mapping s |--> 1, 2*s + 1 |--> 1/2*a0, 4*s + 1 |--> -1, -1 |--> 1, 2 |--> 1 ] sage: Newform('243a',names='a').local_component(3).characters() # long time [ - Character of ramified extension Q_3(s)* (s^2 - 6 = 0), of level 4, mapping -2*s - 1 |--> -d - 1, 4 |--> 1, 3*s + 1 |--> -d - 1, s |--> 1, - Character of ramified extension Q_3(s)* (s^2 - 6 = 0), of level 4, mapping -2*s - 1 |--> d, 4 |--> 1, 3*s + 1 |--> d, s |--> 1 + Character of ramified extension Q_3(s)* (s^2 - 6 = 0), of level 4, + mapping -2*s - 1 |--> -d - 1, 4 |--> 1, 3*s + 1 |--> -d - 1, s |--> 1, + Character of ramified extension Q_3(s)* (s^2 - 6 = 0), of level 4, + mapping -2*s - 1 |--> d, 4 |--> 1, 3*s + 1 |--> d, s |--> 1 ] """ T = self.type_space() @@ -747,7 +764,7 @@ def characters(self): if len(gs) == 1: # This is always the case if p != 2 - chi1, chi2 = [G.extend_character(n, self.central_character(), [x]) for x in gvals] + chi1, chi2 = (G.extend_character(n, self.central_character(), [x]) for x in gvals) else: # 2-adic cases, conductor >= 64. Here life is complicated # because the quotient (O_K* / p^n)^* / (image of Z_2^*) is not @@ -871,7 +888,7 @@ def characters(self): c1q, c2q = flatten([[x]*e for x,e in theta_poly.roots(G.base_ring())]) if len(qs) == 1: - chi1, chi2 = [G.extend_character(n, self.central_character(), [x]) for x in [c1q, c2q]] + chi1, chi2 = (G.extend_character(n, self.central_character(), [x]) for x in [c1q, c2q]) else: assert p == 3 diff --git a/src/sage/modular/local_comp/smoothchar.py b/src/sage/modular/local_comp/smoothchar.py index c81677589a9..62d80dc560a 100644 --- a/src/sage/modular/local_comp/smoothchar.py +++ b/src/sage/modular/local_comp/smoothchar.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.pari sage.rings.number_field r""" Smooth characters of `p`-adic fields diff --git a/src/sage/modular/local_comp/type_space.py b/src/sage/modular/local_comp/type_space.py index e27e4b27137..e3bf9c3bf1b 100644 --- a/src/sage/modular/local_comp/type_space.py +++ b/src/sage/modular/local_comp/type_space.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.pari r""" Type spaces of newforms diff --git a/src/sage/modular/modform/ambient.py b/src/sage/modular/modform/ambient.py index b7a963f354d..825b572688d 100644 --- a/src/sage/modular/modform/ambient.py +++ b/src/sage/modular/modform/ambient.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.libs.pari r""" Ambient spaces of modular forms diff --git a/src/sage/modular/modform/ambient_R.py b/src/sage/modular/modform/ambient_R.py index 95c69eea5be..64188bb3892 100644 --- a/src/sage/modular/modform/ambient_R.py +++ b/src/sage/modular/modform/ambient_R.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.pari """ Modular forms over a non-minimal base ring """ @@ -24,7 +25,8 @@ def __init__(self, M, base_ring): sage: M = ModularForms(23,2,base_ring=GF(7)) # indirect doctest sage: M - Modular Forms space of dimension 3 for Congruence Subgroup Gamma0(23) of weight 2 over Finite Field of size 7 + Modular Forms space of dimension 3 for Congruence Subgroup Gamma0(23) + of weight 2 over Finite Field of size 7 sage: M == loads(dumps(M)) True """ @@ -42,6 +44,7 @@ def modular_symbols(self,sign=0): TESTS:: + sage: # needs sage.rings.number_field sage: K. = QuadraticField(-1) sage: chi = DirichletGroup(5, base_ring = K).0 sage: L. = K.extension(x^2 - 402*i) @@ -65,6 +68,7 @@ def _repr_(self): sage: M._repr_() 'Modular Forms space of dimension 3 for Congruence Subgroup Gamma0(23) of weight 2 over Finite Field of size 7' + sage: # needs sage.rings.number_field sage: chi = DirichletGroup(109).0 ** 36 sage: ModularForms(chi, 2, base_ring = chi.base_ring()) Modular Forms space of dimension 9, character [zeta3] and weight 2 over Cyclotomic Field of order 108 and degree 36 @@ -84,8 +88,8 @@ def _compute_q_expansion_basis(self, prec=None): sage: M = ModularForms(23,2,base_ring=GF(7)) sage: M._compute_q_expansion_basis(10) [q + 6*q^3 + 6*q^4 + 5*q^6 + 2*q^7 + 6*q^8 + 2*q^9 + O(q^10), - q^2 + 5*q^3 + 6*q^4 + 2*q^5 + q^6 + 2*q^7 + 5*q^8 + O(q^10), - 1 + 5*q^3 + 5*q^4 + 5*q^6 + 3*q^8 + 5*q^9 + O(q^10)] + q^2 + 5*q^3 + 6*q^4 + 2*q^5 + q^6 + 2*q^7 + 5*q^8 + O(q^10), + 1 + 5*q^3 + 5*q^4 + 5*q^6 + 3*q^8 + 5*q^9 + O(q^10)] TESTS: @@ -141,7 +145,8 @@ def cuspidal_submodule(self): EXAMPLES:: - sage: C = CuspForms(7, 4, base_ring=CyclotomicField(5)) # indirect doctest + sage: # needs sage.rings.number_field + sage: C = CuspForms(7, 4, base_ring=CyclotomicField(5)) # indirect doctest sage: type(C) """ @@ -153,10 +158,12 @@ def change_ring(self, R): EXAMPLES:: + sage: # needs sage.rings.number_field sage: chi = DirichletGroup(109, CyclotomicField(3)).0 sage: M9 = ModularForms(chi, 2, base_ring = CyclotomicField(9)) sage: M9.change_ring(CyclotomicField(15)) - Modular Forms space of dimension 10, character [zeta3 + 1] and weight 2 over Cyclotomic Field of order 15 and degree 8 + Modular Forms space of dimension 10, character [zeta3 + 1] and weight 2 + over Cyclotomic Field of order 15 and degree 8 sage: M9.change_ring(QQ) Traceback (most recent call last): ... diff --git a/src/sage/modular/modform/ambient_eps.py b/src/sage/modular/modform/ambient_eps.py index 71502963bb8..57bad5752eb 100644 --- a/src/sage/modular/modform/ambient_eps.py +++ b/src/sage/modular/modform/ambient_eps.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.libs.pari sage.rings.number_field r""" Modular forms with character @@ -6,12 +6,16 @@ sage: eps = DirichletGroup(13).0 sage: M = ModularForms(eps^2, 2); M - Modular Forms space of dimension 3, character [zeta6] and weight 2 over Cyclotomic Field of order 6 and degree 2 + Modular Forms space of dimension 3, character [zeta6] and weight 2 over + Cyclotomic Field of order 6 and degree 2 sage: S = M.cuspidal_submodule(); S - Cuspidal subspace of dimension 1 of Modular Forms space of dimension 3, character [zeta6] and weight 2 over Cyclotomic Field of order 6 and degree 2 + Cuspidal subspace of dimension 1 of Modular Forms space of dimension 3, + character [zeta6] and weight 2 over Cyclotomic Field of order 6 and degree 2 sage: S.modular_symbols() - Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 4 and level 13, weight 2, character [zeta6], sign 0, over Cyclotomic Field of order 6 and degree 2 + Modular Symbols subspace of dimension 2 of + Modular Symbols space of dimension 4 and level 13, weight 2, character [zeta6], + sign 0, over Cyclotomic Field of order 6 and degree 2 We create a spaces associated to Dirichlet characters of modulus 225:: @@ -53,10 +57,12 @@ sage: M.eisenstein_submodule() Eisenstein subspace of dimension 8 of Modular Forms space of - dimension 484, character [1, zeta20] and weight 17 over Cyclotomic Field of order 20 and degree 8 + dimension 484, character [1, zeta20] and weight 17 over + Cyclotomic Field of order 20 and degree 8 sage: M.cuspidal_submodule() - Cuspidal subspace of dimension 476 of Modular Forms space of dimension 484, character [1, zeta20] and weight 17 over Cyclotomic Field of order 20 and degree 8 + Cuspidal subspace of dimension 476 of Modular Forms space of dimension 484, + character [1, zeta20] and weight 17 over Cyclotomic Field of order 20 and degree 8 TESTS:: @@ -113,7 +119,8 @@ def __init__(self, character, weight=2, base_ring=None, eis_only=False): EXAMPLES:: sage: m = ModularForms(DirichletGroup(11).0,3); m - Modular Forms space of dimension 3, character [zeta10] and weight 3 over Cyclotomic Field of order 10 and degree 4 + Modular Forms space of dimension 3, character [zeta10] and weight 3 over + Cyclotomic Field of order 10 and degree 4 sage: type(m) """ @@ -167,9 +174,11 @@ def cuspidal_submodule(self): sage: eps = DirichletGroup(4).0 sage: M = ModularForms(eps, 5); M - Modular Forms space of dimension 3, character [-1] and weight 5 over Rational Field + Modular Forms space of dimension 3, character [-1] and weight 5 + over Rational Field sage: M.cuspidal_submodule() - Cuspidal subspace of dimension 1 of Modular Forms space of dimension 3, character [-1] and weight 5 over Rational Field + Cuspidal subspace of dimension 1 of Modular Forms space of dimension 3, + character [-1] and weight 5 over Rational Field """ if self.weight() > 1: return cuspidal_submodule.CuspidalSubmodule_eps(self) @@ -185,9 +194,11 @@ def change_ring(self, base_ring): EXAMPLES:: sage: m = ModularForms(DirichletGroup(13).0^2,2); m - Modular Forms space of dimension 3, character [zeta6] and weight 2 over Cyclotomic Field of order 6 and degree 2 + Modular Forms space of dimension 3, character [zeta6] and weight 2 over + Cyclotomic Field of order 6 and degree 2 sage: m.change_ring(CyclotomicField(12)) - Modular Forms space of dimension 3, character [zeta6] and weight 2 over Cyclotomic Field of order 12 and degree 4 + Modular Forms space of dimension 3, character [zeta6] and weight 2 over + Cyclotomic Field of order 12 and degree 4 It must be possible to change the ring of the underlying Dirichlet character:: @@ -210,11 +221,14 @@ def modular_symbols(self, sign=0): sage: eps = DirichletGroup(13).0 sage: M = ModularForms(eps^2, 2) sage: M.modular_symbols() - Modular Symbols space of dimension 4 and level 13, weight 2, character [zeta6], sign 0, over Cyclotomic Field of order 6 and degree 2 + Modular Symbols space of dimension 4 and level 13, weight 2, + character [zeta6], sign 0, over Cyclotomic Field of order 6 and degree 2 sage: M.modular_symbols(1) - Modular Symbols space of dimension 3 and level 13, weight 2, character [zeta6], sign 1, over Cyclotomic Field of order 6 and degree 2 + Modular Symbols space of dimension 3 and level 13, weight 2, + character [zeta6], sign 1, over Cyclotomic Field of order 6 and degree 2 sage: M.modular_symbols(-1) - Modular Symbols space of dimension 1 and level 13, weight 2, character [zeta6], sign -1, over Cyclotomic Field of order 6 and degree 2 + Modular Symbols space of dimension 1 and level 13, weight 2, + character [zeta6], sign -1, over Cyclotomic Field of order 6 and degree 2 sage: M.modular_symbols(2) Traceback (most recent call last): ... @@ -236,9 +250,11 @@ def eisenstein_submodule(self): EXAMPLES:: sage: m = ModularForms(DirichletGroup(13).0^2,2); m - Modular Forms space of dimension 3, character [zeta6] and weight 2 over Cyclotomic Field of order 6 and degree 2 + Modular Forms space of dimension 3, character [zeta6] and weight 2 over + Cyclotomic Field of order 6 and degree 2 sage: m.eisenstein_submodule() - Eisenstein subspace of dimension 2 of Modular Forms space of dimension 3, character [zeta6] and weight 2 over Cyclotomic Field of order 6 and degree 2 + Eisenstein subspace of dimension 2 of Modular Forms space of dimension 3, + character [zeta6] and weight 2 over Cyclotomic Field of order 6 and degree 2 """ return eisenstein_submodule.EisensteinSubmodule_eps(self) @@ -254,13 +270,15 @@ def hecke_module_of_level(self, N): sage: M = ModularForms(DirichletGroup(15).0, 3); M.character().conductor() 3 sage: M.hecke_module_of_level(3) - Modular Forms space of dimension 2, character [-1] and weight 3 over Rational Field + Modular Forms space of dimension 2, character [-1] and weight 3 + over Rational Field sage: M.hecke_module_of_level(5) Traceback (most recent call last): ... ValueError: conductor(=3) must divide M(=5) sage: M.hecke_module_of_level(30) - Modular Forms space of dimension 16, character [-1, 1] and weight 3 over Rational Field + Modular Forms space of dimension 16, character [-1, 1] and weight 3 + over Rational Field """ from . import constructor if N % self.level() == 0: diff --git a/src/sage/modular/modform/ambient_g0.py b/src/sage/modular/modform/ambient_g0.py index 114718b68b9..0b2ffb8fb83 100644 --- a/src/sage/modular/modform/ambient_g0.py +++ b/src/sage/modular/modform/ambient_g0.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.pari r""" Modular forms for `\Gamma_0(N)` over `\QQ` @@ -39,7 +40,8 @@ def __init__(self, level, weight): EXAMPLES:: sage: m = ModularForms(Gamma0(11),4); m - Modular Forms space of dimension 4 for Congruence Subgroup Gamma0(11) of weight 4 over Rational Field + Modular Forms space of dimension 4 for Congruence Subgroup Gamma0(11) + of weight 4 over Rational Field sage: type(m) """ @@ -73,7 +75,8 @@ def cuspidal_submodule(self): sage: m = ModularForms(Gamma0(33),4) sage: s = m.cuspidal_submodule(); s - Cuspidal subspace of dimension 10 of Modular Forms space of dimension 14 for Congruence Subgroup Gamma0(33) of weight 4 over Rational Field + Cuspidal subspace of dimension 10 of Modular Forms space of dimension 14 + for Congruence Subgroup Gamma0(33) of weight 4 over Rational Field sage: type(s) """ @@ -92,7 +95,8 @@ def eisenstein_submodule(self): sage: m = ModularForms(Gamma0(389),6) sage: m.eisenstein_submodule() - Eisenstein subspace of dimension 2 of Modular Forms space of dimension 163 for Congruence Subgroup Gamma0(389) of weight 6 over Rational Field + Eisenstein subspace of dimension 2 of Modular Forms space of dimension 163 + for Congruence Subgroup Gamma0(389) of weight 6 over Rational Field """ return eisenstein_submodule.EisensteinSubmodule_g0_Q(self) diff --git a/src/sage/modular/modform/constructor.py b/src/sage/modular/modform/constructor.py index b632f6d398c..2adde8bafc3 100644 --- a/src/sage/modular/modform/constructor.py +++ b/src/sage/modular/modform/constructor.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.libs.pari """ Creating spaces of modular forms @@ -6,7 +6,8 @@ sage: m = ModularForms(Gamma1(4),11) sage: m - Modular Forms space of dimension 6 for Congruence Subgroup Gamma1(4) of weight 11 over Rational Field + Modular Forms space of dimension 6 for + Congruence Subgroup Gamma1(4) of weight 11 over Rational Field sage: m.basis() [ q - 134*q^5 + O(q^6), @@ -195,14 +196,16 @@ def ModularForms(group=1, sage: ModularForms(1,12).dimension() 2 sage: ModularForms(11,4) - Modular Forms space of dimension 4 for Congruence Subgroup Gamma0(11) of weight 4 over Rational Field + Modular Forms space of dimension 4 for Congruence Subgroup Gamma0(11) + of weight 4 over Rational Field We create some spaces for `\Gamma_1(N)`. :: sage: ModularForms(Gamma1(13),2) - Modular Forms space of dimension 13 for Congruence Subgroup Gamma1(13) of weight 2 over Rational Field + Modular Forms space of dimension 13 for Congruence Subgroup Gamma1(13) + of weight 2 over Rational Field sage: ModularForms(Gamma1(13),2).dimension() 13 sage: [ModularForms(Gamma1(7),k).dimension() for k in [2,3,4,5]] @@ -212,11 +215,13 @@ def ModularForms(group=1, We create a space with character:: + sage: # needs sage.rings.number_field sage: e = (DirichletGroup(13).0)^2 sage: e.order() 6 sage: M = ModularForms(e, 2); M - Modular Forms space of dimension 3, character [zeta6] and weight 2 over Cyclotomic Field of order 6 and degree 2 + Modular Forms space of dimension 3, character [zeta6] and weight 2 + over Cyclotomic Field of order 6 and degree 2 sage: f = M.T(2).charpoly('x'); f x^3 + (-2*zeta6 - 2)*x^2 - 2*zeta6*x + 14*zeta6 - 7 sage: f.factor() @@ -227,7 +232,8 @@ def ModularForms(group=1, sage: G = GammaH(30, [11]) sage: M = ModularForms(G, 2); M - Modular Forms space of dimension 20 for Congruence Subgroup Gamma_H(30) with H generated by [11] of weight 2 over Rational Field + Modular Forms space of dimension 20 for Congruence Subgroup Gamma_H(30) + with H generated by [11] of weight 2 over Rational Field sage: M.T(7).charpoly().factor() # long time (7s on sage.math, 2011) (x + 4) * x^2 * (x - 6)^4 * (x + 6)^4 * (x - 8)^7 * (x^2 + 4) @@ -237,7 +243,8 @@ def ModularForms(group=1, Dirichlet character modulo 5 of conductor 5 mapping 2 |--> -1 sage: m = ModularForms(e, 2); m - Modular Forms space of dimension 2, character [-1] and weight 2 over Rational Field + Modular Forms space of dimension 2, character [-1] and weight 2 + over Rational Field sage: m == loads(dumps(m)) True sage: m.T(2).charpoly('x') @@ -250,20 +257,23 @@ def ModularForms(group=1, This came up in a subtle bug (:trac:`5923`):: sage: ModularForms(gp(1), gap(12)) - Modular Forms space of dimension 2 for Modular Group SL(2,Z) of weight 12 over Rational Field + Modular Forms space of dimension 2 for Modular Group SL(2,Z) + of weight 12 over Rational Field This came up in another bug (related to :trac:`8630`):: sage: chi = DirichletGroup(109, CyclotomicField(3)).0 sage: ModularForms(chi, 2, base_ring = CyclotomicField(15)) - Modular Forms space of dimension 10, character [zeta3 + 1] and weight 2 over Cyclotomic Field of order 15 and degree 8 + Modular Forms space of dimension 10, character [zeta3 + 1] and weight 2 + over Cyclotomic Field of order 15 and degree 8 We create some weight 1 spaces. Here modular symbol algorithms do not work. In some small examples we can prove using Riemann--Roch that there are no cusp forms anyway, so the entire space is Eisenstein:: sage: M = ModularForms(Gamma1(11), 1); M - Modular Forms space of dimension 5 for Congruence Subgroup Gamma1(11) of weight 1 over Rational Field + Modular Forms space of dimension 5 for Congruence Subgroup Gamma1(11) + of weight 1 over Rational Field sage: M.basis() [ 1 + 22*q^5 + O(q^6), @@ -281,9 +291,10 @@ def ModularForms(group=1, When this does not work (which happens as soon as the level is more than about 30), we use the Hecke stability algorithm of George Schaeffer:: - sage: M = ModularForms(Gamma1(57), 1); M # long time - Modular Forms space of dimension 38 for Congruence Subgroup Gamma1(57) of weight 1 over Rational Field - sage: M.cuspidal_submodule().basis() # long time + sage: M = ModularForms(Gamma1(57), 1); M # long time + Modular Forms space of dimension 38 for Congruence Subgroup Gamma1(57) + of weight 1 over Rational Field + sage: M.cuspidal_submodule().basis() # long time [ q - q^4 + O(q^6), q^3 - q^4 + O(q^6) @@ -292,8 +303,9 @@ def ModularForms(group=1, The Eisenstein subspace in weight 1 can be computed quickly, without triggering the expensive computation of the cuspidal part:: - sage: E = EisensteinForms(Gamma1(59), 1); E # indirect doctest - Eisenstein subspace of dimension 29 of Modular Forms space for Congruence Subgroup Gamma1(59) of weight 1 over Rational Field + sage: E = EisensteinForms(Gamma1(59), 1); E # indirect doctest + Eisenstein subspace of dimension 29 of Modular Forms space for + Congruence Subgroup Gamma1(59) of weight 1 over Rational Field sage: (E.0 + E.2).q_expansion(40) 1 + q^2 + 196*q^29 - 197*q^30 - q^31 + q^33 + q^34 + q^37 + q^38 - q^39 + O(q^40) @@ -378,7 +390,8 @@ def CuspForms(group=1, EXAMPLES:: sage: CuspForms(11,2) - Cuspidal subspace of dimension 1 of Modular Forms space of dimension 2 for Congruence Subgroup Gamma0(11) of weight 2 over Rational Field + Cuspidal subspace of dimension 1 of Modular Forms space of dimension 2 + for Congruence Subgroup Gamma0(11) of weight 2 over Rational Field """ return ModularForms(group, weight, base_ring, use_cache=use_cache, prec=prec).cuspidal_submodule() @@ -398,7 +411,8 @@ def EisensteinForms(group=1, EXAMPLES:: sage: EisensteinForms(11,2) - Eisenstein subspace of dimension 1 of Modular Forms space of dimension 2 for Congruence Subgroup Gamma0(11) of weight 2 over Rational Field + Eisenstein subspace of dimension 1 of Modular Forms space of dimension 2 + for Congruence Subgroup Gamma0(11) of weight 2 over Rational Field """ if weight == 1: return ModularForms(group, weight, base_ring, @@ -458,7 +472,8 @@ def Newforms(group, weight=2, base_ring=None, names=None): sage: chi = DirichletGroup(109, CyclotomicField(3)).0 sage: CuspForms(chi, 2, base_ring = CyclotomicField(9)) - Cuspidal subspace of dimension 8 of Modular Forms space of dimension 10, character [zeta3 + 1] and weight 2 over Cyclotomic Field of order 9 and degree 6 + Cuspidal subspace of dimension 8 of Modular Forms space of dimension 10, + character [zeta3 + 1] and weight 2 over Cyclotomic Field of order 9 and degree 6 Check that :trac:`15486` is fixed (this used to take over a day):: diff --git a/src/sage/modular/modform/cuspidal_submodule.py b/src/sage/modular/modform/cuspidal_submodule.py index 954542073dc..19cb7c65d9d 100644 --- a/src/sage/modular/modform/cuspidal_submodule.py +++ b/src/sage/modular/modform/cuspidal_submodule.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.pari """ The cuspidal subspace @@ -161,17 +162,21 @@ def modular_symbols(self, sign=0): Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 3 for Gamma_0(1) of weight 12 with sign 0 over Rational Field + sage: # needs sage.rings.number_field sage: eps = DirichletGroup(13).0 sage: S = CuspForms(eps^2, 2) - sage: S.modular_symbols(sign=0) - Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 4 and level 13, weight 2, character [zeta6], sign 0, over Cyclotomic Field of order 6 and degree 2 - + Modular Symbols subspace of dimension 2 of Modular Symbols space + of dimension 4 and level 13, weight 2, character [zeta6], sign 0, + over Cyclotomic Field of order 6 and degree 2 sage: S.modular_symbols(sign=1) - Modular Symbols subspace of dimension 1 of Modular Symbols space of dimension 3 and level 13, weight 2, character [zeta6], sign 1, over Cyclotomic Field of order 6 and degree 2 - + Modular Symbols subspace of dimension 1 of Modular Symbols space + of dimension 3 and level 13, weight 2, character [zeta6], sign 1, + over Cyclotomic Field of order 6 and degree 2 sage: S.modular_symbols(sign=-1) - Modular Symbols subspace of dimension 1 of Modular Symbols space of dimension 1 and level 13, weight 2, character [zeta6], sign -1, over Cyclotomic Field of order 6 and degree 2 + Modular Symbols subspace of dimension 1 of Modular Symbols space + of dimension 1 and level 13, weight 2, character [zeta6], sign -1, + over Cyclotomic Field of order 6 and degree 2 """ A = self.ambient_module() return A.modular_symbols(sign).cuspidal_submodule() @@ -189,11 +194,16 @@ def change_ring(self, R): EXAMPLES:: + sage: # needs sage.rings.number_field sage: chi = DirichletGroup(109, CyclotomicField(3)).0 sage: S9 = CuspForms(chi, 2, base_ring = CyclotomicField(9)); S9 - Cuspidal subspace of dimension 8 of Modular Forms space of dimension 10, character [zeta3 + 1] and weight 2 over Cyclotomic Field of order 9 and degree 6 + Cuspidal subspace of dimension 8 of + Modular Forms space of dimension 10, character [zeta3 + 1] and weight 2 + over Cyclotomic Field of order 9 and degree 6 sage: S9.change_ring(CyclotomicField(3)) - Cuspidal subspace of dimension 8 of Modular Forms space of dimension 10, character [zeta3 + 1] and weight 2 over Cyclotomic Field of order 3 and degree 2 + Cuspidal subspace of dimension 8 of + Modular Forms space of dimension 10, character [zeta3 + 1] and weight 2 + over Cyclotomic Field of order 3 and degree 2 sage: S9.change_ring(QQ) Traceback (most recent call last): ... @@ -209,6 +219,7 @@ def _compute_q_expansion_basis(self, prec): r""" EXAMPLES:: + sage: # needs sage.rings.number_field sage: CuspForms(Gamma1(13), 2, base_ring=QuadraticField(-7, 'a')).q_expansion_basis() # indirect doctest [ q - 4*q^3 - q^4 + 3*q^5 + O(q^6), @@ -268,12 +279,14 @@ def hecke_polynomial(self, n, var='x'): EXAMPLES:: sage: CuspForms(105, 2).hecke_polynomial(2, 'y') - y^13 + 5*y^12 - 4*y^11 - 52*y^10 - 34*y^9 + 174*y^8 + 212*y^7 - 196*y^6 - 375*y^5 - 11*y^4 + 200*y^3 + 80*y^2 + y^13 + 5*y^12 - 4*y^11 - 52*y^10 - 34*y^9 + 174*y^8 + 212*y^7 + - 196*y^6 - 375*y^5 - 11*y^4 + 200*y^3 + 80*y^2 Check that this gives the same answer as computing the Hecke matrix:: sage: CuspForms(105, 2).hecke_matrix(2).charpoly(var='y') - y^13 + 5*y^12 - 4*y^11 - 52*y^10 - 34*y^9 + 174*y^8 + 212*y^7 - 196*y^6 - 375*y^5 - 11*y^4 + 200*y^3 + 80*y^2 + y^13 + 5*y^12 - 4*y^11 - 52*y^10 - 34*y^9 + 174*y^8 + 212*y^7 + - 196*y^6 - 375*y^5 - 11*y^4 + 200*y^3 + 80*y^2 Check that :trac:`21546` is fixed (this example used to take about 5 hours):: @@ -290,7 +303,9 @@ def new_submodule(self, p=None): EXAMPLES:: sage: CuspForms(55).new_submodule() - Modular Forms subspace of dimension 3 of Modular Forms space of dimension 8 for Congruence Subgroup Gamma0(55) of weight 2 over Rational Field + Modular Forms subspace of dimension 3 of + Modular Forms space of dimension 8 for + Congruence Subgroup Gamma0(55) of weight 2 over Rational Field """ symbs = self.modular_symbols(sign=1).new_subspace(p) bas = [] @@ -347,7 +362,7 @@ def _compute_q_expansion_basis(self, prec=None): EXAMPLES:: - sage: CuspForms(DirichletGroup(23, QQ).0, 1).q_echelon_basis() # indirect doctest + sage: CuspForms(DirichletGroup(23, QQ).0, 1).q_echelon_basis() # indirect doctest [ q - q^2 - q^3 + O(q^6) ] @@ -372,7 +387,7 @@ def _compute_q_expansion_basis(self, prec=None): EXAMPLES:: - sage: CuspForms(GammaH(31, [7]), 1).q_expansion_basis() # indirect doctest + sage: CuspForms(GammaH(31, [7]), 1).q_expansion_basis() # indirect doctest [ q - q^2 - q^5 + O(q^6) ] @@ -447,7 +462,7 @@ def _transformation_matrix(self): sage: CuspForms(GammaH(31, [7]), 1)._transformation_matrix() [1] - sage: CuspForms(GammaH(124, [33]), 1)._transformation_matrix() # long time + sage: CuspForms(GammaH(124, [33]), 1)._transformation_matrix() # long time [ 1 1 0 0 0 0 1] [ 0 0 0 0 0 1 0] [ 1 0 1 1 -1 -1 1] @@ -504,8 +519,10 @@ def _compute_hecke_matrix(self, n): sage: CuspForms(GammaH(31, [7]), 1).hecke_matrix(7) [-1] - sage: C = CuspForms(GammaH(124, [33]), 1) # long time - sage: C.hecke_matrix(2) # long time + + sage: # long time + sage: C = CuspForms(GammaH(124, [33]), 1) + sage: C.hecke_matrix(2) [ 0 0 -1 -1 0 1 0] [ 1 0 0 -1 -1 -1 0] [ 0 0 0 -1 1 1 -1] @@ -513,7 +530,7 @@ def _compute_hecke_matrix(self, n): [ 0 0 -1 0 0 1 1] [ 0 0 0 -1 0 0 -1] [ 0 0 0 0 0 1 0] - sage: C.hecke_matrix(7) # long time + sage: C.hecke_matrix(7) [ 0 1 0 -1 0 0 1] [ 0 -1 0 0 0 0 0] [ 0 1 -1 0 0 0 1] @@ -521,7 +538,7 @@ def _compute_hecke_matrix(self, n): [ 0 1 1 0 0 -1 0] [ 1 0 -1 -1 -1 0 1] [ 0 1 0 0 1 0 0] - sage: C.hecke_matrix(23) == 0 # long time + sage: C.hecke_matrix(23) == 0 True """ @@ -597,7 +614,7 @@ def _compute_diamond_matrix(self, d): r""" EXAMPLES:: - sage: CuspForms(Gamma1(5), 6).diamond_bracket_matrix(3) # indirect doctest + sage: CuspForms(Gamma1(5), 6).diamond_bracket_matrix(3) # indirect doctest [ -1 0 0] [ 3 5 -12] [ 1 2 -5] @@ -622,7 +639,8 @@ class CuspidalSubmodule_eps(CuspidalSubmodule_modsym_qexp): EXAMPLES:: sage: S = CuspForms(DirichletGroup(5).0,5); S - Cuspidal subspace of dimension 1 of Modular Forms space of dimension 3, character [zeta4] and weight 5 over Cyclotomic Field of order 4 and degree 2 + Cuspidal subspace of dimension 1 of Modular Forms space of dimension 3, + character [zeta4] and weight 5 over Cyclotomic Field of order 4 and degree 2 sage: S.basis() [ @@ -658,7 +676,7 @@ def _convert_matrix_from_modsyms(symbs, T): EXAMPLES:: - sage: CuspForms(Gamma1(5), 6).diamond_bracket_matrix(3) # indirect doctest + sage: CuspForms(Gamma1(5), 6).diamond_bracket_matrix(3) # indirect doctest [ -1 0 0] [ 3 5 -12] [ 1 2 -5] diff --git a/src/sage/modular/modform/eis_series.py b/src/sage/modular/modform/eis_series.py index 39d78cdc0ea..19bf574dec8 100644 --- a/src/sage/modular/modform/eis_series.py +++ b/src/sage/modular/modform/eis_series.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.libs.flint sage.libs.pari """ Eisenstein series """ @@ -177,14 +177,16 @@ def __common_minimal_basering(chi, psi): EXAMPLES:: + sage: # needs sage.rings.number_field sage: sage.modular.modform.eis_series.__common_minimal_basering(DirichletGroup(1)[0], DirichletGroup(1)[0]) - (Dirichlet character modulo 1 of conductor 1, Dirichlet character modulo 1 of conductor 1) - + (Dirichlet character modulo 1 of conductor 1, + Dirichlet character modulo 1 of conductor 1) sage: sage.modular.modform.eis_series.__common_minimal_basering(DirichletGroup(3).0, DirichletGroup(5).0) - (Dirichlet character modulo 3 of conductor 3 mapping 2 |--> -1, Dirichlet character modulo 5 of conductor 5 mapping 2 |--> zeta4) - + (Dirichlet character modulo 3 of conductor 3 mapping 2 |--> -1, + Dirichlet character modulo 5 of conductor 5 mapping 2 |--> zeta4) sage: sage.modular.modform.eis_series.__common_minimal_basering(DirichletGroup(12).0, DirichletGroup(36).0) - (Dirichlet character modulo 12 of conductor 4 mapping 7 |--> -1, 5 |--> 1, Dirichlet character modulo 36 of conductor 4 mapping 19 |--> -1, 29 |--> 1) + (Dirichlet character modulo 12 of conductor 4 mapping 7 |--> -1, 5 |--> 1, + Dirichlet character modulo 36 of conductor 4 mapping 19 |--> -1, 29 |--> 1) """ chi = chi.minimize_base_ring() psi = psi.minimize_base_ring() diff --git a/src/sage/modular/modform/eisenstein_submodule.py b/src/sage/modular/modform/eisenstein_submodule.py index 90370ecf78d..66e3dcca72f 100644 --- a/src/sage/modular/modform/eisenstein_submodule.py +++ b/src/sage/modular/modform/eisenstein_submodule.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.libs.pari """ The Eisenstein subspace """ @@ -29,7 +29,7 @@ def __init__(self, ambient_space): EXAMPLES:: - sage: E = ModularForms(23,4).eisenstein_subspace() # indirect doctest + sage: E = ModularForms(23,4).eisenstein_subspace() # indirect doctest sage: E Eisenstein subspace of dimension 2 of Modular Forms space of dimension 7 for Congruence Subgroup Gamma0(23) of weight 4 over Rational Field diff --git a/src/sage/modular/modform/element.py b/src/sage/modular/modform/element.py index e71c014569f..2c8c1c79616 100644 --- a/src/sage/modular/modform/element.py +++ b/src/sage/modular/modform/element.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.libs.flint sage.libs.pari """ Elements of modular forms spaces @@ -3237,7 +3237,7 @@ def __init__(self, parent, forms_datum): Traceback (most recent call last): ... TypeError: no canonical coercion from Modular Forms space of dimension 1 for Modular Group SL(2,Z) of weight 4 over Rational Field to Rational Field - sage: M([E4, x]) + sage: M([E4, x]) # needs sage.symbolic Traceback (most recent call last): ... TypeError: no canonical coercion from Symbolic Ring to Rational Field diff --git a/src/sage/modular/modform/find_generators.py b/src/sage/modular/modform/find_generators.py index 63b4397e3cd..72080237d56 100644 --- a/src/sage/modular/modform/find_generators.py +++ b/src/sage/modular/modform/find_generators.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint r""" This module is now called ``ring.py`` (see :trac:`31559`). Do not import from here as it will generate a deprecation warning. diff --git a/src/sage/modular/modform/hecke_operator_on_qexp.py b/src/sage/modular/modform/hecke_operator_on_qexp.py index 48590ba7d23..52de2f5c54b 100644 --- a/src/sage/modular/modform/hecke_operator_on_qexp.py +++ b/src/sage/modular/modform/hecke_operator_on_qexp.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint """ Hecke operators on `q`-expansions """ @@ -40,14 +41,18 @@ def hecke_operator_on_qexp(f, n, k, eps=None, sage: hecke_operator_on_qexp(M.basis()[0], 1, 12, prec=7) q - 24*q^2 + 252*q^3 - 1472*q^4 + 4830*q^5 - 6048*q^6 + O(q^7) sage: hecke_operator_on_qexp(M.basis()[0], 1, 12) - q - 24*q^2 + 252*q^3 - 1472*q^4 + 4830*q^5 - 6048*q^6 - 16744*q^7 + 84480*q^8 - 113643*q^9 - 115920*q^10 + 534612*q^11 - 370944*q^12 - 577738*q^13 + O(q^14) + q - 24*q^2 + 252*q^3 - 1472*q^4 + 4830*q^5 - 6048*q^6 - 16744*q^7 + 84480*q^8 + - 113643*q^9 - 115920*q^10 + 534612*q^11 - 370944*q^12 - 577738*q^13 + O(q^14) sage: M.prec(20) 20 sage: hecke_operator_on_qexp(M.basis()[0], 3, 12) 252*q - 6048*q^2 + 63504*q^3 - 370944*q^4 + 1217160*q^5 - 1524096*q^6 + O(q^7) sage: hecke_operator_on_qexp(M.basis()[0], 1, 12) - q - 24*q^2 + 252*q^3 - 1472*q^4 + 4830*q^5 - 6048*q^6 - 16744*q^7 + 84480*q^8 - 113643*q^9 - 115920*q^10 + 534612*q^11 - 370944*q^12 - 577738*q^13 + 401856*q^14 + 1217160*q^15 + 987136*q^16 - 6905934*q^17 + 2727432*q^18 + 10661420*q^19 - 7109760*q^20 + O(q^21) + q - 24*q^2 + 252*q^3 - 1472*q^4 + 4830*q^5 - 6048*q^6 - 16744*q^7 + 84480*q^8 + - 113643*q^9 - 115920*q^10 + 534612*q^11 - 370944*q^12 - 577738*q^13 + + 401856*q^14 + 1217160*q^15 + 987136*q^16 - 6905934*q^17 + 2727432*q^18 + + 10661420*q^19 - 7109760*q^20 + O(q^21) sage: (hecke_operator_on_qexp(M.basis()[0], 1, 12)*252).add_bigoh(7) 252*q - 6048*q^2 + 63504*q^3 - 370944*q^4 + 1217160*q^5 - 1524096*q^6 + O(q^7) @@ -183,7 +188,8 @@ def hecke_operator_on_basis(B, n, k, eps=None, already_echelonized=False): sage: ModularForms(1,12).q_expansion_basis() [ q - 24*q^2 + 252*q^3 - 1472*q^4 + 4830*q^5 + O(q^6), - 1 + 65520/691*q + 134250480/691*q^2 + 11606736960/691*q^3 + 274945048560/691*q^4 + 3199218815520/691*q^5 + O(q^6) + 1 + 65520/691*q + 134250480/691*q^2 + 11606736960/691*q^3 + + 274945048560/691*q^4 + 3199218815520/691*q^5 + O(q^6) ] sage: hecke_operator_on_basis(ModularForms(1,12).q_expansion_basis(), 3, 12) Traceback (most recent call last): @@ -205,6 +211,7 @@ def hecke_operator_on_basis(B, n, k, eps=None, already_echelonized=False): This shows that empty input is handled sensibly (:trac:`12202`):: + sage: # needs sage.rings.number_field sage: x = hecke_operator_on_basis([], 3, 12); x [] sage: x.parent() diff --git a/src/sage/modular/modform/j_invariant.py b/src/sage/modular/modform/j_invariant.py index 9d53d44d909..48b7c91fcb0 100644 --- a/src/sage/modular/modform/j_invariant.py +++ b/src/sage/modular/modform/j_invariant.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint r""" `q`-expansion of `j`-invariant """ diff --git a/src/sage/modular/modform/numerical.py b/src/sage/modular/modform/numerical.py index f811939ca5f..e5444b25c22 100644 --- a/src/sage/modular/modform/numerical.py +++ b/src/sage/modular/modform/numerical.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint """ Numerical computation of newforms """ diff --git a/src/sage/modular/modform/ring.py b/src/sage/modular/modform/ring.py index 2e98067413e..d7008429b5f 100644 --- a/src/sage/modular/modform/ring.py +++ b/src/sage/modular/modform/ring.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint sage.libs.pari """ Graded rings of modular forms diff --git a/src/sage/modular/modform/space.py b/src/sage/modular/modform/space.py index 36daef1d17b..de2b0e74cda 100644 --- a/src/sage/modular/modform/space.py +++ b/src/sage/modular/modform/space.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.pari r""" Generic spaces of modular forms @@ -732,6 +733,7 @@ def _compute_q_expansion_basis(self, prec): """ EXAMPLES:: + sage: # needs sage.rings.number_field sage: sage.modular.modform.space.ModularFormsSpace(Gamma0(11), 2, DirichletGroup(1)[0], QQ)._compute_q_expansion_basis(5) Traceback (most recent call last): ... @@ -1617,10 +1619,11 @@ def new_submodule(self, p=None): EXAMPLES:: - sage: M = sage.modular.modform.space.ModularFormsSpace(Gamma0(11), 2, DirichletGroup(1)[0], base_ring=QQ); M.new_submodule() - Traceback (most recent call last): - ... - NotImplementedError: computation of new submodule not yet implemented + sage: # needs sage.rings.number_field + sage: M = sage.modular.modform.space.ModularFormsSpace(Gamma0(11), 2, DirichletGroup(1)[0], base_ring=QQ); M.new_submodule() + Traceback (most recent call last): + ... + NotImplementedError: computation of new submodule not yet implemented """ raise NotImplementedError("computation of new submodule not yet implemented") @@ -1630,6 +1633,7 @@ def new_subspace(self, p=None): EXAMPLES:: + sage: # needs sage.rings.number_field sage: M = sage.modular.modform.space.ModularFormsSpace(Gamma0(11), 2, DirichletGroup(1)[0], base_ring=QQ); M.new_subspace() Traceback (most recent call last): ... @@ -1647,6 +1651,7 @@ def eisenstein_series(self): EXAMPLES:: + sage: # needs sage.rings.number_field sage: M = sage.modular.modform.space.ModularFormsSpace(Gamma0(11), 2, DirichletGroup(1)[0], base_ring=QQ); M.eisenstein_series() Traceback (most recent call last): ... @@ -1833,6 +1838,7 @@ def modular_symbols(self, sign=0): EXAMPLES:: + sage: # needs sage.rings.number_field sage: M = sage.modular.modform.space.ModularFormsSpace(Gamma0(11), 2, DirichletGroup(1)[0], base_ring=QQ); M.modular_symbols() Traceback (most recent call last): ... diff --git a/src/sage/modular/modform/submodule.py b/src/sage/modular/modform/submodule.py index 441f6d9dd05..f2bc33f5782 100644 --- a/src/sage/modular/modform/submodule.py +++ b/src/sage/modular/modform/submodule.py @@ -1,16 +1,20 @@ +# sage.doctest: needs sage.libs.pari """ Submodules of spaces of modular forms EXAMPLES:: sage: M = ModularForms(Gamma1(13),2); M - Modular Forms space of dimension 13 for Congruence Subgroup Gamma1(13) of weight 2 over Rational Field + Modular Forms space of dimension 13 for + Congruence Subgroup Gamma1(13) of weight 2 over Rational Field sage: M.eisenstein_subspace() - Eisenstein subspace of dimension 11 of Modular Forms space of dimension 13 for Congruence Subgroup Gamma1(13) of weight 2 over Rational Field + Eisenstein subspace of dimension 11 of Modular Forms space of dimension 13 for + Congruence Subgroup Gamma1(13) of weight 2 over Rational Field sage: M == loads(dumps(M)) True sage: M.cuspidal_subspace() - Cuspidal subspace of dimension 2 of Modular Forms space of dimension 13 for Congruence Subgroup Gamma1(13) of weight 2 over Rational Field + Cuspidal subspace of dimension 2 of Modular Forms space of dimension 13 for + Congruence Subgroup Gamma1(13) of weight 2 over Rational Field """ ######################################################################### diff --git a/src/sage/modular/modform/tests.py b/src/sage/modular/modform/tests.py index 87dcf84d1a7..ec831dcc84e 100644 --- a/src/sage/modular/modform/tests.py +++ b/src/sage/modular/modform/tests.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.pari """ TESTS: diff --git a/src/sage/modular/modform/vm_basis.py b/src/sage/modular/modform/vm_basis.py index f83c6bbcc1f..e79408d6f93 100644 --- a/src/sage/modular/modform/vm_basis.py +++ b/src/sage/modular/modform/vm_basis.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint r""" The Victor Miller basis diff --git a/src/sage/modular/modform/weight1.py b/src/sage/modular/modform/weight1.py index 4cb34df7513..c2ce006decb 100644 --- a/src/sage/modular/modform/weight1.py +++ b/src/sage/modular/modform/weight1.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.pari r""" Weight 1 modular forms diff --git a/src/sage/modular/modform_hecketriangle/abstract_space.py b/src/sage/modular/modform_hecketriangle/abstract_space.py index d1e23066aff..e0c4506122d 100644 --- a/src/sage/modular/modform_hecketriangle/abstract_space.py +++ b/src/sage/modular/modform_hecketriangle/abstract_space.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.combinat sage.graphs r""" Modular forms for Hecke triangle groups diff --git a/src/sage/modular/modform_hecketriangle/analytic_type.py b/src/sage/modular/modform_hecketriangle/analytic_type.py index 0c809b3328c..bdbc34a778a 100644 --- a/src/sage/modular/modform_hecketriangle/analytic_type.py +++ b/src/sage/modular/modform_hecketriangle/analytic_type.py @@ -326,9 +326,9 @@ class AnalyticType(FiniteLatticePoset): EXAMPLES:: sage: from sage.modular.modform_hecketriangle.space import QuasiModularForms - sage: x,y,z,d = var("x,y,z,d") - sage: el = QuasiModularForms(n=3, k=6, ep=-1)(y-z^3) - sage: el.analytic_type() + sage: x,y,z,d = var("x,y,z,d") # needs sage.symbolic + sage: el = QuasiModularForms(n=3, k=6, ep=-1)(y-z^3) # needs sage.symbolic + sage: el.analytic_type() # needs sage.symbolic quasi modular Similarly the type of the ring element ``el2 = E4/Delta - E6/Delta`` is @@ -336,9 +336,9 @@ class AnalyticType(FiniteLatticePoset): a function which is holomorphic at infinity:: sage: from sage.modular.modform_hecketriangle.graded_ring import WeakModularFormsRing - sage: x,y,z,d = var("x,y,z,d") - sage: el2 = WeakModularFormsRing(n=3)(x/(x^3-y^2)-y/(x^3-y^2)) - sage: el2.analytic_type() + sage: x,y,z,d = var("x,y,z,d") # needs sage.symbolic + sage: el2 = WeakModularFormsRing(n=3)(x/(x^3-y^2)-y/(x^3-y^2)) # needs sage.symbolic + sage: el2.analytic_type() # needs sage.symbolic weakly holomorphic modular """ diff --git a/src/sage/modular/modform_hecketriangle/constructor.py b/src/sage/modular/modform_hecketriangle/constructor.py index 845098fe862..3a9e21fa852 100644 --- a/src/sage/modular/modform_hecketriangle/constructor.py +++ b/src/sage/modular/modform_hecketriangle/constructor.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.combinat sage.graphs r""" Constructor for spaces of modular forms for Hecke triangle groups based on a type @@ -42,33 +43,30 @@ def rational_type(f, n=ZZ(3), base_ring=ZZ): INPUT: - - ``f`` -- A rational function in ``x,y,z,d`` over ``base_ring``. + - ``f`` -- A rational function in ``x,y,z,d`` over ``base_ring``. - - ``n`` -- An integer greater or equal to `3` corresponding - to the ``HeckeTriangleGroup`` with that parameter - (default: `3`). + - ``n`` -- An integer greater or equal to `3` corresponding + to the ``HeckeTriangleGroup`` with that parameter (default: `3`). - - ``base_ring`` -- The base ring of the corresponding forms ring, resp. - polynomial ring (default: ``ZZ``). + - ``base_ring`` -- The base ring of the corresponding forms ring, resp. + polynomial ring (default: ``ZZ``). OUTPUT: A tuple ``(elem, homo, k, ep, analytic_type)`` describing the basic analytic properties of `f` (with the interpretation indicated above). - - ``elem`` -- ``True`` if `f` has a homogeneous denominator. + - ``elem`` -- ``True`` if `f` has a homogeneous denominator. - - ``homo`` -- ``True`` if `f` also has a homogeneous numerator. + - ``homo`` -- ``True`` if `f` also has a homogeneous numerator. - - ``k`` -- ``None`` if `f` is not homogeneous, otherwise - the weight of `f` (which is the first component - of its degree). + - ``k`` -- ``None`` if `f` is not homogeneous, otherwise + the weight of `f` (which is the first component of its degree). - - ``ep`` -- ``None`` if `f` is not homogeneous, otherwise - the multiplier of `f` (which is the second component - of its degree) + - ``ep`` -- ``None`` if `f` is not homogeneous, otherwise + the multiplier of `f` (which is the second component of its degree) - - ``analytic_type`` -- The ``AnalyticType`` of `f`. + - ``analytic_type`` -- The :class:`AnalyticType` of `f`. For the zero function the degree `(0, 1)` is choosen. @@ -79,44 +77,34 @@ def rational_type(f, n=ZZ(3), base_ring=ZZ): EXAMPLES:: sage: from sage.modular.modform_hecketriangle.constructor import rational_type - sage: (x,y,z,d) = var("x,y,z,d") sage: rational_type(0, n=4) (True, True, 0, 1, zero) - sage: rational_type(1, n=12) (True, True, 0, 1, modular) + sage: # needs sage.symbolic + sage: (x,y,z,d) = var("x,y,z,d") sage: rational_type(x^3 - y^2) (True, True, 12, 1, cuspidal) - sage: rational_type(x * z, n=7) (True, True, 14/5, -1, quasi modular) - sage: rational_type(1/(x^3 - y^2) + z/d) (True, False, None, None, quasi weakly holomorphic modular) - sage: rational_type(x^3/(x^3 - y^2)) (True, True, 0, 1, weakly holomorphic modular) - sage: rational_type(1/(x + z)) (False, False, None, None, None) - sage: rational_type(1/x + 1/z) (True, False, None, None, quasi meromorphic modular) - sage: rational_type(d/x, n=10) (True, True, -1/2, 1, meromorphic modular) - sage: rational_type(1.1 * z * (x^8-y^2), n=8, base_ring=CC) (True, True, 22/3, -1, quasi cuspidal) - sage: rational_type(x-y^2, n=infinity) (True, True, 4, 1, modular) - sage: rational_type(x*(x-y^2), n=infinity) (True, True, 8, 1, cuspidal) - sage: rational_type(1/x, n=infinity) (True, True, -4, 1, weakly holomorphic modular) """ @@ -222,21 +210,17 @@ def FormsSpace(analytic_type, group=3, base_ring=ZZ, k=QQ(0), ep=None): INPUT: - - ``analytic_type`` -- An element of ``AnalyticType()`` describing - the analytic type of the space. + - ``analytic_type`` -- An element of ``AnalyticType()`` describing + the analytic type of the space. - - ``group`` -- The index of the (Hecke triangle) group of the - space (default: `3`). + - ``group`` -- The index of the (Hecke triangle) group of the space (default: `3`). - - ``base_ring`` -- The base ring of the space - (default: ``ZZ``). + - ``base_ring`` -- The base ring of the space (default: ``ZZ``). - - ``k`` -- The weight of the space, a rational number - (default: ``0``). + - ``k`` -- The weight of the space, a rational number (default: ``0``). - - ``ep`` -- The multiplier of the space, `1`, `-1` - or ``None`` (in case ``ep`` should be - determined from ``k``). Default: ``None``. + - ``ep`` -- The multiplier of the space, `1`, `-1` or ``None`` + (in which case ``ep`` should be determined from ``k``). Default: ``None``. For the variables ``group``, ``base_ring``, ``k``, ``ep`` the same arguments as for the class ``FormsSpace_abstract`` can be used. @@ -340,20 +324,19 @@ def FormsRing(analytic_type, group=3, base_ring=ZZ, red_hom=False): INPUT: - - ``analytic_type`` -- An element of ``AnalyticType()`` describing - the analytic type of the space. + - ``analytic_type`` -- An element of ``AnalyticType()`` describing + the analytic type of the space. - - ``group`` -- The index of the (Hecke triangle) group of the space - (default: 3`). + - ``group`` -- The index of the (Hecke triangle) group of the space + (default: 3`). - - ``base_ring`` -- The base ring of the space - (default: ``ZZ``). + - ``base_ring`` -- The base ring of the space (default: ``ZZ``). - - ``red_hom`` -- The (boolean= variable ``red_hom`` of the space - (default: ``False``). + - ``red_hom`` -- The (boolean) variable ``red_hom`` of the space + (default: ``False``). For the variables ``group``, ``base_ring``, ``red_hom`` - the same arguments as for the class ``FormsRing_abstract`` can be used. + the same arguments as for the class :class:`FormsRing_abstract` can be used. The variables will then be put in canonical form. OUTPUT: diff --git a/src/sage/modular/modform_hecketriangle/element.py b/src/sage/modular/modform_hecketriangle/element.py index 9cb02cb7cde..b8cac1e9f52 100644 --- a/src/sage/modular/modform_hecketriangle/element.py +++ b/src/sage/modular/modform_hecketriangle/element.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.combinat sage.graphs r""" Elements of Hecke modular forms spaces @@ -30,10 +31,10 @@ def __init__(self, parent, rat): INPUT: - - ``parent`` -- a modular form space + - ``parent`` -- a modular form space - - ``rat`` -- a rational function which corresponds to a - modular form in the modular form space + - ``rat`` -- a rational function which corresponds to a + modular form in the modular form space OUTPUT: @@ -188,14 +189,14 @@ def lseries(self, num_prec=None, max_imaginary_part=0, max_asymp_coeffs=40): INPUT: - - ``num_prec`` -- An integer denoting the to-be-used numerical precision. - If integer ``num_prec=None`` (default) the default - numerical precision of the parent of ``self`` is used. + - ``num_prec`` -- An integer denoting the to-be-used numerical precision. + If integer ``num_prec=None`` (default) the default + numerical precision of the parent of ``self`` is used. - ``max_imaginary_part`` -- A real number (default: 0), indicating up to which - imaginary part the L-series is going to be studied. + imaginary part the L-series is going to be studied. - - ``max_asymp_coeffs`` -- An integer (default: 40). + - ``max_asymp_coeffs`` -- An integer (default: 40). OUTPUT: @@ -260,16 +261,17 @@ def lseries(self, num_prec=None, max_imaginary_part=0, max_asymp_coeffs=40): sage: L(10).n(53) -13.0290184579... - sage: f = (ModularForms(n=17, k=24).Delta()^2) # long time - sage: L = f.lseries() # long time - sage: L.check_functional_equation() < 2^(-50) # long time + sage: # long time + sage: f = (ModularForms(n=17, k=24).Delta()^2) + sage: L = f.lseries() + sage: L.check_functional_equation() < 2^(-50) True - sage: L.taylor_series(12, 3) # long time + sage: L.taylor_series(12, 3) 0.000683924755280... - 0.000875942285963...*z + 0.000647618966023...*z^2 + O(z^3) - sage: coeffs = f.q_expansion_vector(min_exp=0, max_exp=20, fix_d=True) # long time - sage: sum([coeffs[k]*k^(-30) for k in range(1,len(coeffs))]).n(53) # long time + sage: coeffs = f.q_expansion_vector(min_exp=0, max_exp=20, fix_d=True) + sage: sum([coeffs[k]*k^(-30) for k in range(1,len(coeffs))]).n(53) 9.31562890589...e-10 - sage: L(30).n(53) # long time + sage: L(30).n(53) 9.31562890589...e-10 sage: f = ModularForms(n=infinity, k=2, ep=-1).f_i() diff --git a/src/sage/modular/modform_hecketriangle/functors.py b/src/sage/modular/modform_hecketriangle/functors.py index f06615c823f..3ba9c865231 100644 --- a/src/sage/modular/modform_hecketriangle/functors.py +++ b/src/sage/modular/modform_hecketriangle/functors.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.combinat sage.graphs r""" Functor construction for all spaces diff --git a/src/sage/modular/modform_hecketriangle/graded_ring.py b/src/sage/modular/modform_hecketriangle/graded_ring.py index f7153493aac..624341c8dc7 100644 --- a/src/sage/modular/modform_hecketriangle/graded_ring.py +++ b/src/sage/modular/modform_hecketriangle/graded_ring.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.combinat sage.graphs r""" Graded rings of modular forms for Hecke triangle groups diff --git a/src/sage/modular/modform_hecketriangle/graded_ring_element.py b/src/sage/modular/modform_hecketriangle/graded_ring_element.py index a2ef2a03b04..0de1562677b 100644 --- a/src/sage/modular/modform_hecketriangle/graded_ring_element.py +++ b/src/sage/modular/modform_hecketriangle/graded_ring_element.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.combinat sage.graphs r""" Elements of graded rings of modular forms for Hecke triangle groups @@ -57,9 +58,10 @@ def __classcall__(cls, parent, rat): EXAMPLES:: + sage: # needs sage.symbolic sage: from sage.modular.modform_hecketriangle.graded_ring_element import FormsRingElement sage: from sage.modular.modform_hecketriangle.graded_ring import ModularFormsRing - sage: (x,d) = var("x","d") + sage: x, d = var("x","d") sage: el = FormsRingElement(ModularFormsRing(), x*d) sage: el.rat() x*d @@ -100,11 +102,11 @@ def __init__(self, parent, rat): EXAMPLES:: + sage: # needs sage.symbolic sage: from sage.modular.modform_hecketriangle.graded_ring import QuasiModularFormsRing - sage: (x,y,z,d)=var("x,y,z,d") + sage: x, y, z, d = var("x,y,z,d") sage: MR = QuasiModularFormsRing(n=5) - sage: el = MR(x^3*d + y*z) - sage: el + sage: el = MR(x^3*d + y*z); el f_rho^3*d + f_i*E2 sage: el.rat() x^3*d + y*z @@ -112,10 +114,8 @@ def __init__(self, parent, rat): QuasiModularFormsRing(n=5) over Integer Ring sage: el.rat().parent() Fraction Field of Multivariate Polynomial Ring in x, y, z, d over Integer Ring - sage: MR = QuasiModularFormsRing(n=infinity) - sage: el = MR(d*x*(x-y^2)) - sage: el + sage: el = MR(d*x*(x-y^2)); el -E4*f_i^2*d + E4^2*d sage: el.rat() -x*y^2*d + x^2*d @@ -172,11 +172,11 @@ def _repr_(self): EXAMPLES:: sage: from sage.modular.modform_hecketriangle.graded_ring import QuasiModularFormsRing - sage: (x,y,z,d)=var("x,y,z,d") - sage: QuasiModularFormsRing(n=5)(x^3*z-d*y) + sage: x, y, z, d = var("x,y,z,d") # needs sage.symbolic + sage: QuasiModularFormsRing(n=5)(x^3*z - d*y) # needs sage.symbolic f_rho^3*E2 - f_i*d - sage: QuasiModularFormsRing(n=infinity)(x) + sage: QuasiModularFormsRing(n=infinity)(x) # needs sage.symbolic E4 """ @@ -189,11 +189,11 @@ def _rat_repr(self): EXAMPLES:: sage: from sage.modular.modform_hecketriangle.space import QuasiModularForms - sage: (x,y,z,d)=var("x,y,z,d") - sage: QuasiModularForms(n=5, k=6, ep=-1)(x^3*z)._rat_repr() + sage: x, y, z, d = var("x,y,z,d") # needs sage.symbolic + sage: QuasiModularForms(n=5, k=6, ep=-1)(x^3*z)._rat_repr() # needs sage.symbolic 'f_rho^3*E2' - sage: QuasiModularForms(n=infinity, k=10)(x*(x-y^2)*z)._rat_repr() + sage: QuasiModularForms(n=infinity, k=10)(x*(x-y^2)*z)._rat_repr() # needs sage.symbolic '-E4*f_i^2*E2 + E4^2*E2' """ if self.hecke_n() == infinity: @@ -212,13 +212,13 @@ def _qexp_repr(self): EXAMPLES:: sage: from sage.modular.modform_hecketriangle.graded_ring import QuasiModularFormsRing - sage: (x,y,z,d)=var("x,y,z,d") + sage: x, y, z, d = var("x,y,z,d") # needs sage.symbolic sage: MR = QuasiModularFormsRing(n=5) sage: MR.disp_prec(3) - sage: MR(x^3*z-d*y)._qexp_repr() + sage: MR(x^3*z-d*y)._qexp_repr() # needs sage.symbolic '-d + 1 + ((65*d + 33)/(200*d))*q + ((1755*d + 1437)/(320000*d^2))*q^2 + O(q^3)' - sage: QuasiModularFormsRing(n=infinity)(x*(x-y^2)*z)._qexp_repr() + sage: QuasiModularFormsRing(n=infinity)(x*(x-y^2)*z)._qexp_repr() # needs sage.symbolic '64*q - 3840*q^3 - 16384*q^4 + O(q^5)' """ @@ -235,15 +235,15 @@ def _latex_(self): EXAMPLES:: sage: from sage.modular.modform_hecketriangle.graded_ring import QuasiModularFormsRing - sage: (x,y,z,d)=var("x,y,z,d") - sage: latex(QuasiModularFormsRing(n=5)(x^3*z-d*y)) + sage: x, y, z, d = var("x,y,z,d") # needs sage.symbolic + sage: latex(QuasiModularFormsRing(n=5)(x^3*z - d*y)) # needs sage.symbolic f_{\rho}^{3} E_{2} - f_{i} d sage: from sage.modular.modform_hecketriangle.space import CuspForms - sage: latex(CuspForms(k=12)(x^3-y^2)) + sage: latex(CuspForms(k=12)(x^3 - y^2)) # needs sage.symbolic f_{\rho}^{3} - f_{i}^{2} - sage: latex(QuasiModularFormsRing(n=infinity)(x*(x-y^2)*z)) + sage: latex(QuasiModularFormsRing(n=infinity)(x*(x-y^2)*z)) # needs sage.symbolic -E_{4} f_{i}^{2} E_{2} + E_{4}^{2} E_{2} """ @@ -361,11 +361,11 @@ def is_homogeneous(self): True sage: QuasiModularFormsRing(n=12).Delta().parent().is_homogeneous() False - sage: x,y,z,d=var("x,y,z,d") - sage: QuasiModularFormsRing(n=12)(x^3+y^2+z+d).is_homogeneous() + sage: x, y, z, d = var("x,y,z,d") # needs sage.symbolic + sage: QuasiModularFormsRing(n=12)(x^3+y^2+z+d).is_homogeneous() # needs sage.symbolic False - sage: QuasiModularFormsRing(n=infinity)(x*(x-y^2)+y^4).is_homogeneous() + sage: QuasiModularFormsRing(n=infinity)(x*(x-y^2)+y^4).is_homogeneous() # needs sage.symbolic True """ @@ -379,8 +379,8 @@ def weight(self): sage: from sage.modular.modform_hecketriangle.graded_ring import QuasiModularFormsRing sage: from sage.modular.modform_hecketriangle.space import ModularForms - sage: x,y,z,d = var("x,y,z,d") - sage: QuasiModularFormsRing()(x+y).weight() is None + sage: x, y, z, d = var("x,y,z,d") # needs sage.symbolic + sage: QuasiModularFormsRing()(x+y).weight() is None # needs sage.symbolic True sage: ModularForms(n=18).f_i().weight() 9/4 @@ -398,8 +398,8 @@ def ep(self): sage: from sage.modular.modform_hecketriangle.graded_ring import QuasiModularFormsRing sage: from sage.modular.modform_hecketriangle.space import ModularForms - sage: x,y,z,d = var("x,y,z,d") - sage: QuasiModularFormsRing()(x+y).ep() is None + sage: x, y, z, d = var("x,y,z,d") # needs sage.symbolic + sage: QuasiModularFormsRing()(x+y).ep() is None # needs sage.symbolic True sage: ModularForms(n=18).f_i().ep() -1 @@ -419,8 +419,8 @@ def degree(self): sage: from sage.modular.modform_hecketriangle.graded_ring import QuasiModularFormsRing sage: from sage.modular.modform_hecketriangle.space import ModularForms - sage: x,y,z,d = var("x,y,z,d") - sage: QuasiModularFormsRing()(x+y).degree() == (None, None) + sage: x, y, z, d = var("x,y,z,d") # needs sage.symbolic + sage: QuasiModularFormsRing()(x+y).degree() == (None, None) # needs sage.symbolic True sage: ModularForms(n=18).f_i().degree() (9/4, -1) @@ -438,10 +438,10 @@ def is_modular(self) -> bool: sage: from sage.modular.modform_hecketriangle.graded_ring import QuasiModularFormsRing sage: from sage.modular.modform_hecketriangle.space import QuasiModularForms - sage: x,y,z,d = var("x,y,z,d") - sage: QuasiModularFormsRing(n=5)(x^2+y-d).is_modular() + sage: x, y, z, d = var("x,y,z,d") # needs sage.symbolic + sage: QuasiModularFormsRing(n=5)(x^2+y-d).is_modular() # needs sage.symbolic True - sage: QuasiModularFormsRing(n=5)(x^2+y-d+z).is_modular() + sage: QuasiModularFormsRing(n=5)(x^2+y-d+z).is_modular() # needs sage.symbolic False sage: QuasiModularForms(n=18).f_i().is_modular() True @@ -460,9 +460,10 @@ def is_weakly_holomorphic(self): EXAMPLES:: + sage: # needs sage.symbolic sage: from sage.modular.modform_hecketriangle.graded_ring import QuasiMeromorphicModularFormsRing sage: from sage.modular.modform_hecketriangle.space import QuasiMeromorphicModularForms - sage: x,y,z,d = var("x,y,z,d") + sage: x, y, z, d = var("x,y,z,d") sage: QuasiMeromorphicModularFormsRing(n=5)(x/(x^5-y^2)+z).is_weakly_holomorphic() True sage: QuasiMeromorphicModularFormsRing(n=5)(x^2+y/x-d).is_weakly_holomorphic() @@ -487,10 +488,10 @@ def is_holomorphic(self): sage: from sage.modular.modform_hecketriangle.graded_ring import QuasiMeromorphicModularFormsRing sage: from sage.modular.modform_hecketriangle.space import QuasiMeromorphicModularForms - sage: x,y,z,d = var("x,y,z,d") - sage: QuasiMeromorphicModularFormsRing(n=5)((y^3-z^5)/(x^5-y^2)+y-d).is_holomorphic() + sage: x, y, z, d = var("x,y,z,d") # needs sage.symbolic + sage: QuasiMeromorphicModularFormsRing(n=5)((y^3-z^5)/(x^5-y^2)+y-d).is_holomorphic() # needs sage.symbolic False - sage: QuasiMeromorphicModularFormsRing(n=5)(x^2+y-d+z).is_holomorphic() + sage: QuasiMeromorphicModularFormsRing(n=5)(x^2+y-d+z).is_holomorphic() # needs sage.symbolic True sage: QuasiMeromorphicModularForms(n=18).J_inv().is_holomorphic() False @@ -512,10 +513,10 @@ def is_cuspidal(self): sage: from sage.modular.modform_hecketriangle.graded_ring import QuasiModularFormsRing sage: from sage.modular.modform_hecketriangle.space import QuasiModularForms - sage: x,y,z,d = var("x,y,z,d") - sage: QuasiModularFormsRing(n=5)(y^3-z^5).is_cuspidal() + sage: x, y, z, d = var("x,y,z,d") # needs sage.symbolic + sage: QuasiModularFormsRing(n=5)(y^3-z^5).is_cuspidal() # needs sage.symbolic False - sage: QuasiModularFormsRing(n=5)(z*x^5-z*y^2).is_cuspidal() + sage: QuasiModularFormsRing(n=5)(z*x^5-z*y^2).is_cuspidal() # needs sage.symbolic True sage: QuasiModularForms(n=18).Delta().is_cuspidal() True @@ -536,7 +537,6 @@ def is_zero(self): sage: from sage.modular.modform_hecketriangle.graded_ring import QuasiModularFormsRing sage: from sage.modular.modform_hecketriangle.space import QuasiModularForms - sage: x,y,z,d = var("x,y,z,d") sage: QuasiModularFormsRing(n=5)(1).is_zero() False sage: QuasiModularFormsRing(n=5)(0).is_zero() @@ -558,13 +558,16 @@ def analytic_type(self): sage: from sage.modular.modform_hecketriangle.graded_ring import QuasiMeromorphicModularFormsRing sage: from sage.modular.modform_hecketriangle.space import QuasiMeromorphicModularForms - sage: x,y,z,d = var("x,y,z,d") + + sage: # needs sage.symbolic + sage: x, y, z, d = var("x,y,z,d") sage: QuasiMeromorphicModularFormsRing(n=5)(x/z+d).analytic_type() quasi meromorphic modular sage: QuasiMeromorphicModularFormsRing(n=5)((y^3-z^5)/(x^5-y^2)+y-d).analytic_type() quasi weakly holomorphic modular sage: QuasiMeromorphicModularFormsRing(n=5)(x^2+y-d).analytic_type() modular + sage: QuasiMeromorphicModularForms(n=18).J_inv().analytic_type() weakly holomorphic modular sage: QuasiMeromorphicModularForms(n=18).f_inf().analytic_type() @@ -585,9 +588,10 @@ def numerator(self): EXAMPLES:: + sage: # needs sage.symbolic sage: from sage.modular.modform_hecketriangle.graded_ring import QuasiMeromorphicModularFormsRing sage: from sage.modular.modform_hecketriangle.space import QuasiMeromorphicModularForms - sage: x,y,z,d = var("x,y,z,d") + sage: x, y, z, d = var("x,y,z,d") sage: QuasiMeromorphicModularFormsRing(n=5)((y^3-z^5)/(x^5-y^2)+y-d).numerator() f_rho^5*f_i - f_rho^5*d - E2^5 + f_i^2*d sage: QuasiMeromorphicModularFormsRing(n=5)((y^3-z^5)/(x^5-y^2)+y-d).numerator().parent() @@ -617,9 +621,10 @@ def denominator(self): EXAMPLES:: + sage: # needs sage.symbolic sage: from sage.modular.modform_hecketriangle.graded_ring import QuasiMeromorphicModularFormsRing sage: from sage.modular.modform_hecketriangle.space import QuasiMeromorphicModularForms - sage: x,y,z,d = var("x,y,z,d") + sage: x, y, z, d = var("x,y,z,d") sage: QuasiMeromorphicModularFormsRing(n=5).Delta().full_reduce().denominator() 1 + O(q^5) sage: QuasiMeromorphicModularFormsRing(n=5)((y^3-z^5)/(x^5-y^2)+y-d).denominator() @@ -1010,22 +1015,21 @@ def diff_op(self, op, new_parent=None): INPUT: - - ``op`` -- An element of ``self.parent().diff_alg()``. - I.e. an element of the algebra over ``QQ`` - of differential operators generated - by ``X, Y, Z, dX, dY, DZ``, where e.g. ``X`` - corresponds to the multiplication by ``x`` - (resp. ``f_rho``) and ``dX`` corresponds to ``d/dx``. + - ``op`` -- An element of ``self.parent().diff_alg()``. + I.e. an element of the algebra over ``QQ`` + of differential operators generated + by ``X, Y, Z, dX, dY, DZ``, where e.g. ``X`` + corresponds to the multiplication by ``x`` + (resp. ``f_rho``) and ``dX`` corresponds to ``d/dx``. - To expect a homogeneous result after applying - the operator to a homogeneous element it should - should be homogeneous operator (with respect - to the usual, special grading). + To expect a homogeneous result after applying + the operator to a homogeneous element it should + should be homogeneous operator (with respect + to the usual, special grading). - ``new_parent`` -- Try to convert the result to the specified - ``new_parent``. If ``new_parent == None`` (default) - then the parent is extended to a - "quasi meromorphic" ring. + ``new_parent``. If ``new_parent == None`` (default) + then the parent is extended to a "quasi meromorphic" ring. OUTPUT: @@ -1323,10 +1327,10 @@ def order_at(self, tau=infinity): sage: (1/MR.f_inf()^2).order_at(-1) 0 - sage: p = HyperbolicPlane().PD().get_point(I) - sage: MR((x-y)^10).order_at(p) + sage: p = HyperbolicPlane().PD().get_point(I) # needs sage.symbolic + sage: MR((x-y)^10).order_at(p) # needs sage.symbolic 10 - sage: MR.zero().order_at(p) + sage: MR.zero().order_at(p) # needs sage.symbolic +Infinity """ @@ -1586,31 +1590,31 @@ def _q_expansion_cached(self, prec, fix_d, subs_d, d_num_prec, fix_prec=False): def q_expansion(self, prec=None, fix_d=False, d_num_prec=None, fix_prec=False): """ - Returns the Fourier expansion of self. + Return the Fourier expansion of ``self``. INPUT: - - ``prec`` -- An integer, the desired output precision O(q^prec). - Default: ``None`` in which case the default precision - of ``self.parent()`` is used. + - ``prec`` -- An integer, the desired output precision O(q^prec). + Default: ``None`` in which case the default precision + of ``self.parent()`` is used. - - ``fix_d`` -- If ``False`` (default) a formal parameter is used for ``d``. - If ``True`` then the numerical value of ``d`` is used - (resp. an exact value if the group is arithmetic). - Otherwise the given value is used for ``d``. + - ``fix_d`` -- If ``False`` (default) a formal parameter is used for ``d``. + If ``True`` then the numerical value of ``d`` is used + (resp. an exact value if the group is arithmetic). + Otherwise the given value is used for ``d``. - ``d_num_prec`` -- The precision to be used if a numerical value for ``d`` is substituted. - Default: ``None`` in which case the default - numerical precision of ``self.parent()`` is used. + Default: ``None`` in which case the default + numerical precision of ``self.parent()`` is used. - - ``fix_prec`` -- If ``fix_prec`` is not ``False`` (default) - then the precision of the ``MFSeriesConstructor`` is - increased such that the output has exactly the specified - precision O(q^prec). + - ``fix_prec`` -- If ``fix_prec`` is not ``False`` (default) + then the precision of the ``MFSeriesConstructor`` is + increased such that the output has exactly the specified + precision O(q^prec). OUTPUT: - The Fourier expansion of self as a ``FormalPowerSeries`` or ``FormalLaurentSeries``. + The Fourier expansion of ``self`` as a ``FormalPowerSeries`` or ``FormalLaurentSeries``. EXAMPLES:: @@ -1690,24 +1694,24 @@ def q_expansion(self, prec=None, fix_d=False, d_num_prec=None, fix_prec=False): def q_expansion_fixed_d(self, prec=None, d_num_prec=None, fix_prec=False): """ - Returns the Fourier expansion of self. + Return the Fourier expansion of ``self``. + The numerical (or exact) value for ``d`` is substituted. INPUT: - - ``prec`` -- An integer, the desired output precision O(q^prec). - Default: ``None`` in which case the default precision - of ``self.parent()`` is used. + - ``prec`` -- An integer, the desired output precision O(q^prec). + Default: ``None`` in which case the default precision of ``self.parent()`` is used. - ``d_num_prec`` -- The precision to be used if a numerical value for ``d`` is substituted. - Default: ``None`` in which case the default - numerical precision of ``self.parent()`` is used. + Default: ``None`` in which case the default + numerical precision of ``self.parent()`` is used. - - ``fix_prec`` -- If ``fix_prec`` is not ``False`` (default) - then the precision of the ``MFSeriesConstructor`` is - increased such that the output has exactly the specified - precision O(q^prec). + - ``fix_prec`` -- If ``fix_prec`` is not ``False`` (default) + then the precision of the ``MFSeriesConstructor`` is + increased such that the output has exactly the specified + precision O(q^prec). OUTPUT: @@ -1757,20 +1761,19 @@ def q_expansion_vector(self, min_exp=None, max_exp=None, prec=None, **kwargs): INPUT: - ``min_exp`` -- An integer, specifying the first coefficient to be - used for the vector. Default: ``None``, meaning that - the first non-trivial coefficient is used. + used for the vector. Default: ``None``, meaning that + the first non-trivial coefficient is used. - - ``max_exp`` -- An integer, specifying the last coefficient to be - used for the vector. Default: ``None``, meaning that - the default precision + 1 is used. + - ``max_exp`` -- An integer, specifying the last coefficient to be + used for the vector. Default: ``None``, meaning that + the default precision + 1 is used. - - ``prec`` -- An integer, specifying the precision of the underlying - Laurent series. Default: ``None``, meaning that - ``max_exp + 1`` is used. + - ``prec`` -- An integer, specifying the precision of the underlying + Laurent series. Default: ``None``, meaning that ``max_exp + 1`` is used. OUTPUT: - A vector of size ``max_exp - min_exp`` over the coefficient ring of self, + A vector of size ``max_exp - min_exp`` over the coefficient ring of ``self``, determined by the corresponding Laurent series coefficients. EXAMPLES:: @@ -1840,22 +1843,21 @@ def evaluate(self, tau, prec=None, num_prec=None, check=False): INPUT: - - ``tau`` -- ``infinity`` or an element of the upper - half plane. E.g. with parent ``AA`` or ``CC``. + - ``tau`` -- ``infinity`` or an element of the upper + half plane. E.g. with parent ``AA`` or ``CC``. - - ``prec`` -- An integer, namely the precision used for the - Fourier expansion. If ``prec == None`` (default) - then the default precision of ``self.parent()`` - is used. + - ``prec`` -- An integer, namely the precision used for the + Fourier expansion. If ``prec == None`` (default) + then the default precision of ``self.parent()`` is used. - - ``num_prec`` -- An integer, namely the minimal numerical precision - used for ``tau`` and ``d``. If ``num_prec == None`` - (default) then the default numerical precision of - ``self.parent()`` is used. + - ``num_prec`` -- An integer, namely the minimal numerical precision + used for ``tau`` and ``d``. If ``num_prec == None`` + (default) then the default numerical precision of + ``self.parent()`` is used. - - ``check`` -- If ``True`` then the order of ``tau`` is checked. - Otherwise the order is only considered for - ``tau = infinity, i, rho, -1/rho``. Default: ``False``. + - ``check`` -- If ``True`` then the order of ``tau`` is checked. + Otherwise the order is only considered for + ``tau = infinity, i, rho, -1/rho``. Default: ``False``. OUTPUT: @@ -2123,6 +2125,7 @@ def evaluate(self, tau, prec=None, num_prec=None, check=False): It is possible to evaluate at points of ``HyperbolicPlane()``:: + sage: # needs sage.symbolic sage: p = HyperbolicPlane().PD().get_point(-I/2) sage: bool(p.to_model('UHP').coordinates() == I/3) True diff --git a/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py b/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py index b0241196107..7fa7b698d14 100644 --- a/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py +++ b/src/sage/modular/modform_hecketriangle/hecke_triangle_group_element.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.gap r""" Hecke triangle group elements @@ -40,12 +41,14 @@ def coerce_AA(p): EXAMPLES:: + sage: # needs sage.rings.number_field sage.symbolic sage: from sage.modular.modform_hecketriangle.hecke_triangle_group_element import coerce_AA sage: p = (791264*AA(2*cos(pi/8))^2 - 463492).sqrt() sage: AA(p)._exact_field() Number Field in a with defining polynomial y^8 ... with a in ... sage: coerce_AA(p)._exact_field() - Number Field in a with defining polynomial y^4 - 1910*y^2 - 3924*y + 681058 with a in ...? + Number Field in a with defining polynomial y^4 - 1910*y^2 - 3924*y + 681058 + with a in ...? """ el = AA(p) el.simplify() @@ -103,17 +106,18 @@ def __init__(self, parent, M, check=True, **kwargs): - ``parent`` -- A ``HeckeTriangleGroup``. - - ``M`` -- A matrix which coerces into the matrix space - of ``parent``. For example with entries in a - polynomial ring over ``ZZ`` with parameter ``lam``. + - ``M`` -- A matrix which coerces into the matrix space + of ``parent``. For example with entries in a + polynomial ring over ``ZZ`` with parameter ``lam``. - ``check`` -- ``True`` (default) or ``False``. If ``True`` - then a (possibly long) check is performed - to see whether ``M`` really corresponds to a - group element of ``parent``. + then a (possibly long) check is performed + to see whether ``M`` really corresponds to a + group element of ``parent``. EXAMPLES:: + sage: sage: from sage.modular.modform_hecketriangle.hecke_triangle_groups import HeckeTriangleGroup, HeckeTriangleGroupElement sage: lam = PolynomialRing(ZZ, 'lam').gen() sage: M = matrix([[-1, 0], [-lam^4 + 5*lam^2 + lam - 5, -1]]) @@ -121,7 +125,8 @@ def __init__(self, parent, M, check=True, **kwargs): sage: G(M) Traceback (most recent call last): ... - TypeError: The matrix is not an element of Hecke triangle group for n = 4, up to equivalence it identifies two nonequivalent points. + TypeError: The matrix is not an element of Hecke triangle group for n = 4, + up to equivalence it identifies two nonequivalent points. sage: G = HeckeTriangleGroup(10) sage: el = G(M) @@ -139,13 +144,16 @@ def __init__(self, parent, M, check=True, **kwargs): [ -1 0] [lam -1] sage: el.matrix().parent() - Full MatrixSpace of 2 by 2 dense matrices over Maximal Order in Number Field in lam with defining polynomial x^4 - 5*x^2 + 5 with lam = 1.902113032590308? + Full MatrixSpace of 2 by 2 dense matrices over + Maximal Order in Number Field in lam with defining polynomial x^4 - 5*x^2 + 5 + with lam = 1.902113032590308? sage: M = matrix([[-1, lam], [0, 1]]) sage: G(M) Traceback (most recent call last): ... - TypeError: The matrix is not an element of Hecke triangle group for n = 10, it has determinant -1 != 1. + TypeError: The matrix is not an element of Hecke triangle group for n = 10, + it has determinant -1 != 1. sage: G.T().inverse() [ 1 -lam] @@ -339,19 +347,21 @@ def string_repr(self, method="default"): INPUT: - - ``method`` -- ``default``: Use the usual representation method for matrix group elements. + - ``method`` -- one of - ``basic``: The representation is given as a word in ``S`` and powers of ``T``. - Note: If ``S, T`` are defined accordingly the output can - be used/evaluated directly to recover ``self``. + - ``default``: Use the usual representation method for matrix group elements. - ``conj``: The conjugacy representative of the element is represented - as a word in powers of the basic blocks, together with - an unspecified conjugation matrix. + - ``basic``: The representation is given as a word in ``S`` and powers of ``T``. + Note: If ``S, T`` are defined accordingly the output can + be used/evaluated directly to recover ``self``. - ``block``: Same as ``conj`` but the conjugation matrix is specified as well. - Note: Assuming ``S, T, U, V`` are defined accordingly the output - can directly be used/evaluated to recover ``self``. + - ``conj``: The conjugacy representative of the element is represented + as a word in powers of the basic blocks, together with + an unspecified conjugation matrix. + + - ``block``: Same as ``conj`` but the conjugation matrix is specified as well. + Note: Assuming ``S, T, U, V`` are defined accordingly the output + can directly be used/evaluated to recover ``self``. Warning: For ``n=infinity`` the methods ``conj`` and ``block`` are not verified at all and are probably wrong! @@ -893,19 +903,19 @@ def primitive_representative(self, method="block"): INPUT: - ``method`` -- ``block`` (default) or ``cf``. The method - used to determine ``P`` and ``R``. If - ``self`` is elliptic this parameter is - ignored and if ``self`` is +- the identity - then the ``block`` method is used. + used to determine ``P`` and ``R``. If + ``self`` is elliptic, this parameter is + ignored, and if ``self`` is +- the identity + then the ``block`` method is used. - With ``block`` the decomposition described - in :meth:`_primitive_block_decomposition_data` is used. + With ``block`` the decomposition described + in :meth:`_primitive_block_decomposition_data` is used. - With ``cf`` a reduced representative from - the lambda-CF of ``self`` is used (see - :meth:`continued_fraction`). In that case - ``P`` corresponds to the period and ``R`` - to the preperiod. + With ``cf`` a reduced representative from + the lambda-CF of ``self`` is used (see + :meth:`continued_fraction`). In that case + ``P`` corresponds to the period and ``R`` + to the preperiod. OUTPUT: @@ -1079,11 +1089,11 @@ def primitive_part(self, method="cf"): INPUT: - ``method`` -- The method used to determine the primitive - part (see :meth:`primitive_representative`), - default: "cf". The parameter is ignored - for elliptic elements or +- the identity. + part (see :meth:`primitive_representative`), + default: "cf". The parameter is ignored + for elliptic elements or +- the identity. - The result should not depend on the method. + The result should not depend on the method. OUTPUT: @@ -1166,7 +1176,7 @@ def reduce(self, primitive=True): INPUT: - ``primitive`` -- If ``True`` (default) then a primitive - representative for ``self`` is returned. + representative for ``self`` is returned. EXAMPLES:: @@ -1278,9 +1288,9 @@ def primitive_power(self, method="cf"): INPUT: - ``method`` -- The method used to determine the primitive - power (see :meth:`primitive_representative`), - default: "cf". The parameter is ignored - for elliptic elements or +- the identity. + power (see :meth:`primitive_representative`), + default: "cf". The parameter is ignored + for elliptic elements or +- the identity. OUTPUT: @@ -1416,8 +1426,8 @@ def block_length(self, primitive=False): INPUT: - ``primitive`` -- If ``True`` then the conjugacy - representative of the primitive part is - used instead, default: ``False``. + representative of the primitive part is + used instead, default: ``False``. OUTPUT: @@ -1778,11 +1788,11 @@ def conjugacy_type(self, ignore_sign=True, primitive=False): INPUT: - ``ignore_sign`` -- If ``True`` (default) then the conjugacy - classes are only considered up to a sign. + classes are only considered up to a sign. - - ``primitive`` -- If ``True`` then the conjugacy class of - the primitive part is considered instead - and the sign is ignored, default: ``False``. + - ``primitive`` -- If ``True`` then the conjugacy class of + the primitive part is considered instead + and the sign is ignored, default: ``False``. OUTPUT: @@ -2379,10 +2389,10 @@ def is_reduced(self, require_primitive=True, require_hyperbolic=True): INPUT: - ``require_primitive`` -- If ``True`` (default) then non-primitive elements - are not considered reduced. + are not considered reduced. - ``require_hyperbolic`` -- If ``True`` (default) then non-hyperbolic elements - are not considered reduced. + are not considered reduced. EXAMPLES:: @@ -2721,7 +2731,8 @@ def linking_number(self): ....: t_const = (2*pi*i/G.lam()).n(num_prec) ....: d = MF.get_d(fix_d=True, d_num_prec=num_prec) ....: q = exp(t_const * z) - ....: return t_const*z + sum([(int_series.coefficients()[m]).subs(d=d) * q**int_series.exponents()[m] for m in range(len(int_series.coefficients()))]) + ....: return t_const*z + sum((int_series.coefficients()[m]).subs(d=d) * q**int_series.exponents()[m] + ....: for m in range(len(int_series.coefficients()))) sage: def M(gamma, z, num_prec=53): ....: a = ComplexField(num_prec)(gamma.a()) @@ -2738,7 +2749,9 @@ def linking_number(self): sage: def num_linking_number(A, z, n=3, prec=10, num_prec=53): ....: z = z.n(num_prec) ....: k = 4 * n / (n - 2) - ....: return (n-2) / (2*pi*i).n(num_prec) * (E2_primitive(A.acton(z), n=n, prec=prec, num_prec=num_prec) - E2_primitive(z, n=n, prec=prec, num_prec=num_prec) - k*M(A, z, num_prec=num_prec)) + ....: return (n-2) / (2*pi*i).n(num_prec) * (E2_primitive(A.acton(z), n=n, prec=prec, num_prec=num_prec) + ....: - E2_primitive(z, n=n, prec=prec, num_prec=num_prec) + ....: - k*M(A, z, num_prec=num_prec)) sage: G = HeckeTriangleGroup(8) sage: z = i diff --git a/src/sage/modular/modform_hecketriangle/hecke_triangle_groups.py b/src/sage/modular/modform_hecketriangle/hecke_triangle_groups.py index 917ebb0cf02..6c73cc50d40 100644 --- a/src/sage/modular/modform_hecketriangle/hecke_triangle_groups.py +++ b/src/sage/modular/modform_hecketriangle/hecke_triangle_groups.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.gap r""" Hecke triangle groups diff --git a/src/sage/modular/modform_hecketriangle/readme.py b/src/sage/modular/modform_hecketriangle/readme.py index b0059725904..ff8a725c15c 100644 --- a/src/sage/modular/modform_hecketriangle/readme.py +++ b/src/sage/modular/modform_hecketriangle/readme.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.gap r""" Overview of Hecke triangle groups and modular forms for Hecke triangle groups diff --git a/src/sage/modular/modform_hecketriangle/series_constructor.py b/src/sage/modular/modform_hecketriangle/series_constructor.py index dc2cd792a6b..b44f41a09a0 100644 --- a/src/sage/modular/modform_hecketriangle/series_constructor.py +++ b/src/sage/modular/modform_hecketriangle/series_constructor.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.gap r""" Series constructor for modular forms for Hecke triangle groups diff --git a/src/sage/modular/modform_hecketriangle/space.py b/src/sage/modular/modform_hecketriangle/space.py index 662f1035794..9df1e2d60ba 100644 --- a/src/sage/modular/modform_hecketriangle/space.py +++ b/src/sage/modular/modform_hecketriangle/space.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.combinat sage.graphs r""" Modular forms for Hecke triangle groups diff --git a/src/sage/modular/modform_hecketriangle/subspace.py b/src/sage/modular/modform_hecketriangle/subspace.py index f89d42affd8..4475f71530a 100644 --- a/src/sage/modular/modform_hecketriangle/subspace.py +++ b/src/sage/modular/modform_hecketriangle/subspace.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.combinat sage.graphs r""" Subspaces of modular forms for Hecke triangle groups diff --git a/src/sage/modular/modsym/ambient.py b/src/sage/modular/modsym/ambient.py index 9c1876493f1..a0e40c27785 100644 --- a/src/sage/modular/modsym/ambient.py +++ b/src/sage/modular/modsym/ambient.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.libs.flint sage.libs.pari r""" Ambient spaces of modular symbols diff --git a/src/sage/modular/modsym/boundary.py b/src/sage/modular/modsym/boundary.py index 208371b9deb..e90a5d165f6 100644 --- a/src/sage/modular/modsym/boundary.py +++ b/src/sage/modular/modsym/boundary.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.libs.flint sage.libs.pari r""" Space of boundary modular symbols diff --git a/src/sage/modular/modsym/element.py b/src/sage/modular/modsym/element.py index df08763459d..80ccb3c4242 100644 --- a/src/sage/modular/modsym/element.py +++ b/src/sage/modular/modsym/element.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint """ A single element of an ambient space of modular symbols """ diff --git a/src/sage/modular/modsym/ghlist.py b/src/sage/modular/modsym/ghlist.py index bd15cc505b5..5df29f52af9 100644 --- a/src/sage/modular/modsym/ghlist.py +++ b/src/sage/modular/modsym/ghlist.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.pari r""" List of coset representatives for `\Gamma_H(N)` in `\SL_2(\ZZ)` """ diff --git a/src/sage/modular/modsym/hecke_operator.py b/src/sage/modular/modsym/hecke_operator.py index 6d416eca8e3..43e34b57a49 100644 --- a/src/sage/modular/modsym/hecke_operator.py +++ b/src/sage/modular/modsym/hecke_operator.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint """ Sparse action of Hecke operators """ diff --git a/src/sage/modular/modsym/manin_symbol.pyx b/src/sage/modular/modsym/manin_symbol.pyx index 52026160b38..a71533e1b73 100644 --- a/src/sage/modular/modsym/manin_symbol.pyx +++ b/src/sage/modular/modsym/manin_symbol.pyx @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.libs.flint r""" Manin symbols diff --git a/src/sage/modular/modsym/manin_symbol_list.py b/src/sage/modular/modsym/manin_symbol_list.py index 858fa4a9feb..93fa3f1365b 100644 --- a/src/sage/modular/modsym/manin_symbol_list.py +++ b/src/sage/modular/modsym/manin_symbol_list.py @@ -901,6 +901,7 @@ class ManinSymbolList_character(ManinSymbolList): EXAMPLES:: + sage: # needs sage.rings.number_field sage: eps = DirichletGroup(4).gen(0) sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_character sage: m = ManinSymbolList_character(eps,2); m @@ -922,6 +923,7 @@ def __init__(self, character, weight): EXAMPLES:: + sage: # needs sage.rings.number_field sage: eps = DirichletGroup(4).gen(0) sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_character sage: m = ManinSymbolList_character(eps,2); m @@ -955,6 +957,7 @@ def __repr__(self): EXAMPLES:: + sage: # needs sage.rings.number_field sage: eps = DirichletGroup(4).gen(0) sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_character sage: m = ManinSymbolList_character(eps,2); m @@ -975,6 +978,7 @@ def level(self): EXAMPLES:: + sage: # needs sage.rings.number_field sage: eps = DirichletGroup(4).gen(0) sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_character sage: ManinSymbolList_character(eps,4).level() @@ -1005,6 +1009,7 @@ def apply(self, j, m): EXAMPLES:: + sage: # needs sage.rings.number_field sage: eps = DirichletGroup(4).gen(0) sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_character sage: m = ManinSymbolList_character(eps,4) @@ -1041,6 +1046,7 @@ def apply_S(self, j): EXAMPLES:: + sage: # needs sage.rings.number_field sage: eps = DirichletGroup(4).gen(0) sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_character sage: m = ManinSymbolList_character(eps,2); m @@ -1065,6 +1071,7 @@ def _apply_S_only_0pm1(self): EXAMPLES:: + sage: # needs sage.rings.number_field sage: eps = DirichletGroup(4).gen(0) sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_character sage: ManinSymbolList_character(eps,2)._apply_S_only_0pm1() @@ -1090,6 +1097,7 @@ def apply_I(self, j): EXAMPLES:: + sage: # needs sage.rings.number_field sage: eps = DirichletGroup(4).gen(0) sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_character sage: m = ManinSymbolList_character(eps,2); m @@ -1123,6 +1131,7 @@ def apply_T(self, j): EXAMPLES:: + sage: # needs sage.rings.number_field sage: eps = DirichletGroup(4).gen(0) sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_character sage: m = ManinSymbolList_character(eps,2); m @@ -1165,6 +1174,7 @@ def apply_TT(self, j): EXAMPLES:: + sage: # needs sage.rings.number_field sage: eps = DirichletGroup(4).gen(0) sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_character sage: m = ManinSymbolList_character(eps,2); m @@ -1200,6 +1210,7 @@ def character(self): EXAMPLES:: + sage: # needs sage.rings.number_field sage: eps = DirichletGroup(4).gen(0) sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_character sage: m = ManinSymbolList_character(eps,2); m @@ -1229,6 +1240,7 @@ def index(self, x): EXAMPLES:: + sage: # needs sage.rings.number_field sage: eps = DirichletGroup(4).gen(0) sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_character sage: m = ManinSymbolList_character(eps,4); m @@ -1267,6 +1279,7 @@ def normalize(self, x): EXAMPLES:: + sage: # needs sage.rings.number_field sage: eps = DirichletGroup(4).gen(0) sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_character sage: m = ManinSymbolList_character(eps,4); m diff --git a/src/sage/modular/modsym/modsym.py b/src/sage/modular/modsym/modsym.py index d33f61cd928..962e3c168ed 100644 --- a/src/sage/modular/modsym/modsym.py +++ b/src/sage/modular/modsym/modsym.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.libs.flint sage.libs.pari r""" Creation of modular symbols spaces @@ -20,25 +20,34 @@ :: - sage: M = ModularSymbols(23,2,base_ring=QQ) + sage: M = ModularSymbols(23,2, base_ring=QQ) sage: M.T(2).charpoly('x').factor() (x - 3) * (x^2 + x - 1)^2 sage: M.decomposition(2) [ - Modular Symbols subspace of dimension 1 of Modular Symbols space of dimension 5 for Gamma_0(23) of weight 2 with sign 0 over Rational Field, - Modular Symbols subspace of dimension 4 of Modular Symbols space of dimension 5 for Gamma_0(23) of weight 2 with sign 0 over Rational Field + Modular Symbols subspace of dimension 1 of Modular Symbols space of dimension 5 + for Gamma_0(23) of weight 2 with sign 0 over Rational Field, + Modular Symbols subspace of dimension 4 of Modular Symbols space of dimension 5 + for Gamma_0(23) of weight 2 with sign 0 over Rational Field ] :: - sage: M = ModularSymbols(23,2,base_ring=QuadraticField(5, 'sqrt5')) + sage: # needs sage.rings.number_field + sage: M = ModularSymbols(23,2, base_ring=QuadraticField(5, 'sqrt5')) sage: M.T(2).charpoly('x').factor() (x - 3) * (x - 1/2*sqrt5 + 1/2)^2 * (x + 1/2*sqrt5 + 1/2)^2 sage: M.decomposition(2) [ - Modular Symbols subspace of dimension 1 of Modular Symbols space of dimension 5 for Gamma_0(23) of weight 2 with sign 0 over Number Field in sqrt5 with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790?, - Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 5 for Gamma_0(23) of weight 2 with sign 0 over Number Field in sqrt5 with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790?, - Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 5 for Gamma_0(23) of weight 2 with sign 0 over Number Field in sqrt5 with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790? + Modular Symbols subspace of dimension 1 of Modular Symbols space of dimension 5 + for Gamma_0(23) of weight 2 with sign 0 over Number Field in sqrt5 + with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790?, + Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 5 + for Gamma_0(23) of weight 2 with sign 0 over Number Field in sqrt5 + with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790?, + Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 5 + for Gamma_0(23) of weight 2 with sign 0 over Number Field in sqrt5 + with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790? ] We compute some Hecke operators and do a consistency check:: @@ -52,23 +61,30 @@ sage: G = GammaH(36, [13, 19]) sage: G.modular_symbols() - Modular Symbols space of dimension 13 for Congruence Subgroup Gamma_H(36) with H generated by [13, 19] of weight 2 with sign 0 over Rational Field + Modular Symbols space of dimension 13 for Congruence Subgroup Gamma_H(36) + with H generated by [13, 19] of weight 2 with sign 0 over Rational Field sage: G.modular_symbols().cuspidal_subspace() - Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 13 for Congruence Subgroup Gamma_H(36) with H generated by [13, 19] of weight 2 with sign 0 over Rational Field + Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 13 for + Congruence Subgroup Gamma_H(36) with H generated by [13, 19] of weight 2 with sign 0 + over Rational Field This test catches a tricky corner case for spaces with character:: sage: ModularSymbols(DirichletGroup(20).1**3, weight=3, sign=1).cuspidal_subspace() - Modular Symbols subspace of dimension 3 of Modular Symbols space of dimension 6 and level 20, weight 3, character [1, -zeta4], sign 1, over Cyclotomic Field of order 4 and degree 2 + Modular Symbols subspace of dimension 3 of Modular Symbols space of dimension 6 + and level 20, weight 3, character [1, -zeta4], sign 1, + over Cyclotomic Field of order 4 and degree 2 This tests the bugs reported in :trac:`20932`:: sage: chi = kronecker_character(3*34603) - sage: ModularSymbols(chi, 2, sign=1, base_ring=GF(3)) # not tested # long time (600 seconds) - Modular Symbols space of dimension 11535 and level 103809, weight 2, character [2, 2], sign 1, over Finite Field of size 3 + sage: ModularSymbols(chi, 2, sign=1, base_ring=GF(3)) # not tested # long time (600 seconds) + Modular Symbols space of dimension 11535 and level 103809, weight 2, + character [2, 2], sign 1, over Finite Field of size 3 sage: chi = kronecker_character(3*61379) - sage: ModularSymbols(chi, 2, sign=1, base_ring=GF(3)) # not tested # long time (1800 seconds) - Modular Symbols space of dimension 20460 and level 184137, weight 2, character [2, 2], sign 1, over Finite Field of size 3 + sage: ModularSymbols(chi, 2, sign=1, base_ring=GF(3)) # not tested # long time (1800 seconds) + Modular Symbols space of dimension 20460 and level 184137, weight 2, + character [2, 2], sign 1, over Finite Field of size 3 """ # **************************************************************************** @@ -175,7 +191,8 @@ def ModularSymbols_clear_cache(): sage: ModularSymbols_clear_cache() sage: gc.collect() # random 3422 - sage: a = [x for x in gc.get_objects() if isinstance(x,sage.modular.modsym.ambient.ModularSymbolsAmbient_wtk_g1)] + sage: a = [x for x in gc.get_objects() + ....: if isinstance(x,sage.modular.modsym.ambient.ModularSymbolsAmbient_wtk_g1)] sage: a [] """ @@ -221,14 +238,16 @@ def ModularSymbols(group=1, sage: ModularSymbols(1,12,-1).dimension() 1 sage: ModularSymbols(11,4, sign=1) - Modular Symbols space of dimension 4 for Gamma_0(11) of weight 4 with sign 1 over Rational Field + Modular Symbols space of dimension 4 for Gamma_0(11) of weight 4 + with sign 1 over Rational Field We create some spaces for `\Gamma_1(N)`. :: sage: ModularSymbols(Gamma1(13),2) - Modular Symbols space of dimension 15 for Gamma_1(13) of weight 2 with sign 0 over Rational Field + Modular Symbols space of dimension 15 for Gamma_1(13) of weight 2 + with sign 0 over Rational Field sage: ModularSymbols(Gamma1(13),2, sign=1).dimension() 13 sage: ModularSymbols(Gamma1(13),2, sign=-1).dimension() @@ -244,8 +263,12 @@ def ModularSymbols(group=1, sage: M = ModularSymbols(G,2) sage: M.decomposition() [ - Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 5 for Congruence Subgroup Gamma_H(15) with H generated by [4, 7] of weight 2 with sign 0 over Rational Field, - Modular Symbols subspace of dimension 3 of Modular Symbols space of dimension 5 for Congruence Subgroup Gamma_H(15) with H generated by [4, 7] of weight 2 with sign 0 over Rational Field + Modular Symbols subspace of dimension 2 of Modular Symbols space of dimension 5 + for Congruence Subgroup Gamma_H(15) with H generated by [4, 7] + of weight 2 with sign 0 over Rational Field, + Modular Symbols subspace of dimension 3 of Modular Symbols space of dimension 5 + for Congruence Subgroup Gamma_H(15) with H generated by [4, 7] + of weight 2 with sign 0 over Rational Field ] We create a space with character:: @@ -254,7 +277,8 @@ def ModularSymbols(group=1, sage: e.order() 6 sage: M = ModularSymbols(e, 2); M - Modular Symbols space of dimension 4 and level 13, weight 2, character [zeta6], sign 0, over Cyclotomic Field of order 6 and degree 2 + Modular Symbols space of dimension 4 and level 13, weight 2, character [zeta6], + sign 0, over Cyclotomic Field of order 6 and degree 2 sage: f = M.T(2).charpoly('x'); f x^4 + (-zeta6 - 1)*x^3 - 8*zeta6*x^2 + (10*zeta6 - 5)*x + 21*zeta6 - 21 sage: f.factor() @@ -262,8 +286,10 @@ def ModularSymbols(group=1, We create a space with character over a larger base ring than the values of the character:: - sage: ModularSymbols(e, 2, base_ring = CyclotomicField(24)) - Modular Symbols space of dimension 4 and level 13, weight 2, character [zeta24^4], sign 0, over Cyclotomic Field of order 24 and degree 8 + sage: # needs sage.rings.number_field + sage: ModularSymbols(e, 2, base_ring=CyclotomicField(24)) + Modular Symbols space of dimension 4 and level 13, weight 2, character [zeta24^4], + sign 0, over Cyclotomic Field of order 24 and degree 8 More examples of spaces with character:: @@ -271,7 +297,8 @@ def ModularSymbols(group=1, Dirichlet character modulo 5 of conductor 5 mapping 2 |--> -1 sage: m = ModularSymbols(e, 2); m - Modular Symbols space of dimension 2 and level 5, weight 2, character [-1], sign 0, over Rational Field + Modular Symbols space of dimension 2 and level 5, weight 2, character [-1], + sign 0, over Rational Field :: @@ -287,14 +314,18 @@ def ModularSymbols(group=1, :: - sage: G = DirichletGroup(13,GF(4,'a')); G - Group of Dirichlet characters modulo 13 with values in Finite Field in a of size 2^2 + sage: # needs sage.rings.finite_rings + sage: G = DirichletGroup(13, GF(4,'a')); G + Group of Dirichlet characters modulo 13 + with values in Finite Field in a of size 2^2 sage: e = G.list()[2]; e Dirichlet character modulo 13 of conductor 13 mapping 2 |--> a + 1 sage: M = ModularSymbols(e,4); M - Modular Symbols space of dimension 8 and level 13, weight 4, character [a + 1], sign 0, over Finite Field in a of size 2^2 + Modular Symbols space of dimension 8 and level 13, weight 4, + character [a + 1], sign 0, over Finite Field in a of size 2^2 sage: M.basis() - ([X*Y,(1,0)], [X*Y,(1,5)], [X*Y,(1,10)], [X*Y,(1,11)], [X^2,(0,1)], [X^2,(1,10)], [X^2,(1,11)], [X^2,(1,12)]) + ([X*Y,(1,0)], [X*Y,(1,5)], [X*Y,(1,10)], [X*Y,(1,11)], + [X^2,(0,1)], [X^2,(1,10)], [X^2,(1,11)], [X^2,(1,12)]) sage: M.T(2).matrix() [ 0 0 0 0 0 0 1 1] [ 0 0 0 0 0 0 0 0] diff --git a/src/sage/modular/modsym/modular_symbols.py b/src/sage/modular/modsym/modular_symbols.py index e76694d54e2..57dc8f23a2b 100644 --- a/src/sage/modular/modsym/modular_symbols.py +++ b/src/sage/modular/modsym/modular_symbols.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint r""" Modular symbols `\{\alpha`, `\beta\}` diff --git a/src/sage/modular/modsym/p1list_nf.py b/src/sage/modular/modsym/p1list_nf.py index 69986c1b8c8..25c68137e0c 100644 --- a/src/sage/modular/modsym/p1list_nf.py +++ b/src/sage/modular/modsym/p1list_nf.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.rings.number_field r""" Lists of Manin symbols over number fields, elements of `\mathbb{P}^1(R/N)` diff --git a/src/sage/modular/modsym/relation_matrix.py b/src/sage/modular/modsym/relation_matrix.py index 99b3ebfd7b6..5885812d36c 100644 --- a/src/sage/modular/modsym/relation_matrix.py +++ b/src/sage/modular/modsym/relation_matrix.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint """ Relation matrices for ambient modular symbols spaces diff --git a/src/sage/modular/modsym/space.py b/src/sage/modular/modsym/space.py index 9cf4bf0796f..b8b7197bced 100644 --- a/src/sage/modular/modsym/space.py +++ b/src/sage/modular/modsym/space.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.libs.flint sage.libs.pari """ Base class of the space of modular symbols diff --git a/src/sage/modular/modsym/subspace.py b/src/sage/modular/modsym/subspace.py index d1d2a393127..fdc69b18b9a 100644 --- a/src/sage/modular/modsym/subspace.py +++ b/src/sage/modular/modsym/subspace.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint """ Subspace of ambient spaces of modular symbols """ @@ -53,7 +54,8 @@ def __init__(self, ambient_hecke_module, submodule, sage: M = ModularSymbols(15,4) ; S = M.cuspidal_submodule() # indirect doctest sage: S - Modular Symbols subspace of dimension 8 of Modular Symbols space of dimension 12 for Gamma_0(15) of weight 4 with sign 0 over Rational Field + Modular Symbols subspace of dimension 8 of Modular Symbols space of dimension 12 + for Gamma_0(15) of weight 4 with sign 0 over Rational Field sage: S == loads(dumps(S)) True sage: M = ModularSymbols(1,24) @@ -61,7 +63,8 @@ def __init__(self, ambient_hecke_module, submodule, sage: B = A.submodule([ x.element() for x in M.cuspidal_submodule().gens() ]) sage: S = sage.modular.modsym.subspace.ModularSymbolsSubspace(A, B.free_module()) sage: S - Modular Symbols subspace of dimension 4 of Modular Symbols space of dimension 5 for Gamma_0(1) of weight 24 with sign 0 over Rational Field + Modular Symbols subspace of dimension 4 of Modular Symbols space of dimension 5 + for Gamma_0(1) of weight 24 with sign 0 over Rational Field sage: S == loads(dumps(S)) True """ @@ -96,7 +99,8 @@ def boundary_map(self): EXAMPLES:: sage: M = ModularSymbols(1, 24, sign=1) ; M - Modular Symbols space of dimension 3 for Gamma_0(1) of weight 24 with sign 1 over Rational Field + Modular Symbols space of dimension 3 for Gamma_0(1) of weight 24 + with sign 1 over Rational Field sage: M.basis() ([X^18*Y^4,(0,0)], [X^20*Y^2,(0,0)], [X^22,(0,0)]) sage: M.cuspidal_submodule().basis() @@ -137,11 +141,13 @@ def cuspidal_submodule(self): EXAMPLES:: sage: S = ModularSymbols(42,4).cuspidal_submodule() ; S - Modular Symbols subspace of dimension 40 of Modular Symbols space of dimension 48 for Gamma_0(42) of weight 4 with sign 0 over Rational Field + Modular Symbols subspace of dimension 40 of Modular Symbols space of dimension 48 + for Gamma_0(42) of weight 4 with sign 0 over Rational Field sage: S.is_cuspidal() True sage: S.cuspidal_submodule() - Modular Symbols subspace of dimension 40 of Modular Symbols space of dimension 48 for Gamma_0(42) of weight 4 with sign 0 over Rational Field + Modular Symbols subspace of dimension 40 of Modular Symbols space of dimension 48 + for Gamma_0(42) of weight 4 with sign 0 over Rational Field The cuspidal submodule of the cuspidal submodule is just itself:: @@ -156,7 +162,8 @@ def cuspidal_submodule(self): sage: S = M.eisenstein_submodule() sage: S._set_is_cuspidal(True) sage: S.cuspidal_submodule() - Modular Symbols subspace of dimension 1 of Modular Symbols space of dimension 65 for Gamma_0(389) of weight 2 with sign 0 over Rational Field + Modular Symbols subspace of dimension 1 of Modular Symbols space of dimension 65 + for Gamma_0(389) of weight 2 with sign 0 over Rational Field """ try: return self.__cuspidal_submodule @@ -205,9 +212,11 @@ def eisenstein_subspace(self): EXAMPLES:: sage: ModularSymbols(24,4).eisenstein_subspace() - Modular Symbols subspace of dimension 8 of Modular Symbols space of dimension 24 for Gamma_0(24) of weight 4 with sign 0 over Rational Field + Modular Symbols subspace of dimension 8 of Modular Symbols space of dimension 24 + for Gamma_0(24) of weight 4 with sign 0 over Rational Field sage: ModularSymbols(20,2).cuspidal_subspace().eisenstein_subspace() - Modular Symbols subspace of dimension 0 of Modular Symbols space of dimension 7 for Gamma_0(20) of weight 2 with sign 0 over Rational Field + Modular Symbols subspace of dimension 0 of Modular Symbols space of dimension 7 + for Gamma_0(20) of weight 2 with sign 0 over Rational Field """ try: return self.__eisenstein_subspace @@ -238,9 +247,12 @@ def factorization(self): sage: M = ModularSymbols(11) sage: D = M.factorization(); D - (Modular Symbols subspace of dimension 1 of Modular Symbols space of dimension 3 for Gamma_0(11) of weight 2 with sign 0 over Rational Field) * - (Modular Symbols subspace of dimension 1 of Modular Symbols space of dimension 3 for Gamma_0(11) of weight 2 with sign 0 over Rational Field) * - (Modular Symbols subspace of dimension 1 of Modular Symbols space of dimension 3 for Gamma_0(11) of weight 2 with sign 0 over Rational Field) + (Modular Symbols subspace of dimension 1 of Modular Symbols space of dimension 3 + for Gamma_0(11) of weight 2 with sign 0 over Rational Field) * + (Modular Symbols subspace of dimension 1 of Modular Symbols space of dimension 3 + for Gamma_0(11) of weight 2 with sign 0 over Rational Field) * + (Modular Symbols subspace of dimension 1 of Modular Symbols space of dimension 3 + for Gamma_0(11) of weight 2 with sign 0 over Rational Field) sage: [A.T(2).matrix() for A, _ in D] [[-2], [3], [-2]] sage: [A.star_eigenvalues() for A, _ in D] @@ -253,14 +265,16 @@ def factorization(self): sage: M = ModularSymbols(22,sign=1) sage: S = M.cuspidal_submodule() sage: S.factorization() - (Modular Symbols subspace of dimension 1 of Modular Symbols space of dimension 2 for Gamma_0(11) of weight 2 with sign 1 over Rational Field)^2 + (Modular Symbols subspace of dimension 1 of Modular Symbols space of dimension 2 + for Gamma_0(11) of weight 2 with sign 1 over Rational Field)^2 :: sage: M = ModularSymbols(Gamma0(22), 2, sign=1) sage: M1 = M.decomposition()[1] sage: M1.factorization() - Modular Symbols subspace of dimension 3 of Modular Symbols space of dimension 5 for Gamma_0(22) of weight 2 with sign 1 over Rational Field + Modular Symbols subspace of dimension 3 of Modular Symbols space of dimension 5 + for Gamma_0(22) of weight 2 with sign 1 over Rational Field """ try: return self._factorization @@ -404,7 +418,8 @@ def star_involution(self): sage: M = ModularSymbols(1,24) sage: M.star_involution() - Hecke module morphism Star involution on Modular Symbols space of dimension 5 for Gamma_0(1) of weight 24 with sign 0 over Rational Field defined by the matrix + Hecke module morphism Star involution on Modular Symbols space of dimension 5 + for Gamma_0(1) of weight 24 with sign 0 over Rational Field defined by the matrix [ 1 0 0 0 0] [ 0 -1 0 0 0] [ 0 0 1 0 0] diff --git a/src/sage/modular/modsym/tests.py b/src/sage/modular/modsym/tests.py index 737bb66ba62..3af2ffb1d87 100644 --- a/src/sage/modular/modsym/tests.py +++ b/src/sage/modular/modsym/tests.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint sage.libs.pari """ Testing modular symbols spaces @@ -187,10 +188,13 @@ def _modular_symbols_space_character(self): EXAMPLES:: + sage: # needs sage.rings.number_field sage: from sage.modular.modsym.tests import Test sage: Test()._modular_symbols_space_character() # random level = 18, weight = 3, sign = 0 - Modular Symbols space of dimension 0 and level 18, weight 3, character [1, zeta6 - 1], sign 0, over Cyclotomic Field of order 6 and degree 2 + Modular Symbols space of dimension 0 + and level 18, weight 3, character [1, zeta6 - 1], sign 0, + over Cyclotomic Field of order 6 and degree 2 """ level, weight, sign = self._level_weight_sign() G = dirichlet.DirichletGroup(level) @@ -270,7 +274,8 @@ def test_cs_dimension(self): sage: Test().test_cs_dimension() # random gamma0 level = 16, weight = 3, sign = -1 - Modular Symbols space of dimension 0 for Gamma_0(16) of weight 3 with sign -1 over Rational Field + Modular Symbols space of dimension 0 for Gamma_0(16) of weight 3 + with sign -1 over Rational Field """ self._modular_symbols_space().cuspidal_submodule() @@ -285,7 +290,8 @@ def test_csnew_dimension(self): sage: Test().test_csnew_dimension() # random gamma0 level = 3, weight = 3, sign = 1 - Modular Symbols space of dimension 0 for Gamma_0(3) of weight 3 with sign 1 over Rational Field + Modular Symbols space of dimension 0 for Gamma_0(3) of weight 3 + with sign 1 over Rational Field """ M = self._modular_symbols_space() V = M.cuspidal_submodule().new_submodule() diff --git a/src/sage/modular/multiple_zeta.py b/src/sage/modular/multiple_zeta.py index 22cabe23344..494d183e805 100644 --- a/src/sage/modular/multiple_zeta.py +++ b/src/sage/modular/multiple_zeta.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.combinat r""" Algebra of motivic multiple zeta values diff --git a/src/sage/modular/multiple_zeta_F_algebra.py b/src/sage/modular/multiple_zeta_F_algebra.py index f8875d4bc51..251310de6b8 100644 --- a/src/sage/modular/multiple_zeta_F_algebra.py +++ b/src/sage/modular/multiple_zeta_F_algebra.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.combinat r""" F-algebra for motivic multiple zeta values. diff --git a/src/sage/modular/overconvergent/genus0.py b/src/sage/modular/overconvergent/genus0.py index 62d189e49d5..9cfbcb3a39b 100644 --- a/src/sage/modular/overconvergent/genus0.py +++ b/src/sage/modular/overconvergent/genus0.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.libs.pari sage.rings.padics r""" Overconvergent `p`-adic modular forms for small primes @@ -1657,7 +1657,7 @@ def valuation_plot(self, rmax=None): sage: o = OverconvergentModularForms(3, 0, 1/2) sage: f = o.eigenfunctions(4)[1] - sage: f.valuation_plot() + sage: f.valuation_plot() # needs sage.plot Graphics object consisting of 1 graphics primitive """ from sage.plot.plot import plot diff --git a/src/sage/modular/overconvergent/hecke_series.py b/src/sage/modular/overconvergent/hecke_series.py index 5183106e458..1e10c6386a9 100644 --- a/src/sage/modular/overconvergent/hecke_series.py +++ b/src/sage/modular/overconvergent/hecke_series.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint sage.libs.pari r""" Atkin/Hecke series for overconvergent modular forms diff --git a/src/sage/modular/pollack_stevens/distributions.py b/src/sage/modular/pollack_stevens/distributions.py index 7aaad3c6f0e..a83121db4fa 100644 --- a/src/sage/modular/pollack_stevens/distributions.py +++ b/src/sage/modular/pollack_stevens/distributions.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.rings.padics r""" Spaces of distributions for Pollack-Stevens modular symbols diff --git a/src/sage/modular/pollack_stevens/manin_map.py b/src/sage/modular/pollack_stevens/manin_map.py index 4acbecf038b..06aa3496e10 100644 --- a/src/sage/modular/pollack_stevens/manin_map.py +++ b/src/sage/modular/pollack_stevens/manin_map.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.rings.padics r""" Manin map diff --git a/src/sage/modular/pollack_stevens/space.py b/src/sage/modular/pollack_stevens/space.py index 88b7be6d2cd..6fe7c12b95b 100644 --- a/src/sage/modular/pollack_stevens/space.py +++ b/src/sage/modular/pollack_stevens/space.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.rings.padics r""" Pollack-Stevens' modular symbols spaces diff --git a/src/sage/modular/quasimodform/element.py b/src/sage/modular/quasimodform/element.py index b92c31722ac..c096973fadc 100644 --- a/src/sage/modular/quasimodform/element.py +++ b/src/sage/modular/quasimodform/element.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint """ Elements of quasimodular forms rings @@ -605,7 +606,7 @@ def __getitem__(self, weight): TESTS:: - sage: F[x] + sage: F[x] # needs sage.symbolic Traceback (most recent call last): ... KeyError: 'the weight must be an integer' diff --git a/src/sage/modular/ssmod/ssmod.py b/src/sage/modular/ssmod/ssmod.py index a23320cecb0..13b6d11fbb6 100644 --- a/src/sage/modular/ssmod/ssmod.py +++ b/src/sage/modular/ssmod/ssmod.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.pari """ Module of supersingular points diff --git a/src/sage/modules/filtered_vector_space.py b/src/sage/modules/filtered_vector_space.py index f34c0abfe71..c5e4b7058bf 100644 --- a/src/sage/modules/filtered_vector_space.py +++ b/src/sage/modules/filtered_vector_space.py @@ -1002,7 +1002,7 @@ def direct_sum(self, other): sage: v = [(1,0), (0,1)] sage: F1 = FilteredVectorSpace(v, {0:[0], 1:[1]}, base_ring=QQ) sage: F2 = FilteredVectorSpace(v, {0:[0], 1:[1]}, base_ring=RDF) - sage: F1 + F2 + sage: F1 + F2 # needs scipy RDF^4 >= RDF^2 >= 0 """ from sage.structure.element import get_coercion_model @@ -1067,7 +1067,7 @@ def tensor_product(self, other): sage: v = [(1,0), (0,1)] sage: F1 = FilteredVectorSpace(v, {0:[0], 1:[1]}, base_ring=QQ) sage: F2 = FilteredVectorSpace(v, {0:[0], 1:[1]}, base_ring=RDF) - sage: F1 * F2 + sage: F1 * F2 # needs scipy RDF^4 >= RDF^3 >= RDF^1 >= 0 """ V = self diff --git a/src/sage/modules/free_module_element.pyx b/src/sage/modules/free_module_element.pyx index a2c077cc8c8..2c28616dbf4 100644 --- a/src/sage/modules/free_module_element.pyx +++ b/src/sage/modules/free_module_element.pyx @@ -416,8 +416,8 @@ def vector(arg0, arg1=None, arg2=None, sparse=None, immutable=False): Complex numbers can be converted naturally to a sequence of length 2. And then to a vector. :: - sage: c = CDF(2 + 3*I) - sage: v = vector(c); v + sage: c = CDF(2 + 3*I) # needs sage.rings.complex_double sage.symbolic + sage: v = vector(c); v # needs sage.rings.complex_double sage.symbolic (2.0, 3.0) A generator, or other iterable, may also be supplied as input. Anything @@ -457,9 +457,9 @@ def vector(arg0, arg1=None, arg2=None, sparse=None, immutable=False): sage: v.is_immutable() True - sage: # needs numpy + sage: # needs numpy sage.symbolic sage: import numpy as np - sage: w = np.array([1, 2, pi], float) # needs sage.symbolic + sage: w = np.array([1, 2, pi], float) sage: v = vector(w, immutable=True) sage: v.is_immutable() True @@ -554,11 +554,11 @@ def vector(arg0, arg1=None, arg2=None, sparse=None, immutable=False): if isinstance(v, ndarray): if len(v.shape) != 1: raise TypeError("cannot convert %r-dimensional array to a vector" % len(v.shape)) - from .free_module import VectorSpace + from sage.modules.free_module import VectorSpace if (R is None or isinstance(R, RealDoubleField)) and v.dtype.kind == 'f': from sage.rings.real_double import RDF V = VectorSpace(RDF, v.shape[0]) - from .vector_real_double_dense import Vector_real_double_dense + from sage.modules.vector_real_double_dense import Vector_real_double_dense v = Vector_real_double_dense(V, v) if immutable: v.set_immutable() @@ -566,7 +566,7 @@ def vector(arg0, arg1=None, arg2=None, sparse=None, immutable=False): if (R is None or isinstance(R, ComplexDoubleField)) and v.dtype.kind == 'c': from sage.rings.complex_double import CDF V = VectorSpace(CDF, v.shape[0]) - from .vector_complex_double_dense import Vector_complex_double_dense + from sage.modules.vector_complex_double_dense import Vector_complex_double_dense v = Vector_complex_double_dense(V, v) if immutable: v.set_immutable() @@ -1831,7 +1831,7 @@ cdef class FreeModuleElement(Vector): # abstract base class values = [] for n in range(slicelength): values.append(self.get_unsafe(start + n*step)) - from .free_module import FreeModule + from sage.modules.free_module import FreeModule M = FreeModule(self.coordinate_ring(), slicelength, sparse=self.is_sparse()) return M(values, coerce=False, copy=False) else: @@ -3225,6 +3225,7 @@ cdef class FreeModuleElement(Vector): # abstract base class We test this by building a specialized vector space with a non-standard inner product, and constructing a test vector in this space. :: + sage: # needs sage.rings.complex_double sage.symbolic sage: V = VectorSpace(CDF, 2, inner_product_matrix=[[2,1],[1,5]]) sage: v = vector(CDF, [2-3*I, 4+5*I]) sage: w = V(v) @@ -3435,8 +3436,7 @@ cdef class FreeModuleElement(Vector): # abstract base class sage: R. = ZZ[] sage: v = vector(R, [12, 24*t]) sage: w = vector(QQ, [1/2, 1/3, 1/4]) - sage: op = v.outer_product(w) - sage: op + sage: op = v.outer_product(w); op [ 6 4 3] [12*t 8*t 6*t] sage: op.base_ring() @@ -3451,7 +3451,7 @@ cdef class FreeModuleElement(Vector): # abstract base class sage: w = vector(GF(5), [1,2]) sage: v = vector(GF(7), [1,2,3,4]) - sage: z = w.outer_product(v) # needs sage.rings.finite_rings + sage: z = w.outer_product(v) Traceback (most recent call last): ... TypeError: unsupported operand parent(s) for *: @@ -3460,8 +3460,8 @@ cdef class FreeModuleElement(Vector): # abstract base class And some inputs don't make any sense at all. :: - sage: w=vector(QQ, [5,10]) - sage: z=w.outer_product(6) + sage: w = vector(QQ, [5,10]) + sage: z = w.outer_product(6) Traceback (most recent call last): ... TypeError: right operand in an outer product must be a vector, @@ -3531,7 +3531,7 @@ cdef class FreeModuleElement(Vector): # abstract base class in each argument (with conjugation on the first scalar), and anti-commutative. :: - sage: # needs sage.symbolic + sage: # needs sage.rings.complex_double sage.symbolic sage: alpha = CDF(5.0 + 3.0*I) sage: u = vector(CDF, [2+4*I, -3+5*I, 2-7*I]) sage: v = vector(CDF, [-1+3*I, 5+4*I, 9-2*I]) @@ -3550,6 +3550,7 @@ cdef class FreeModuleElement(Vector): # abstract base class default for the :meth:`norm` method). The norm squared equals the Hermitian inner product of the vector with itself. :: + sage: # needs sage.rings.complex_double sage.symbolic sage: v = vector(CDF, [-0.66+0.47*I, -0.60+0.91*I, -0.62-0.87*I, 0.53+0.32*I]) sage: abs(v.norm()^2 - v.hermitian_inner_product(v)) < 1.0e-10 True @@ -3560,6 +3561,7 @@ cdef class FreeModuleElement(Vector): # abstract base class which allows for a wide variety of inputs. Any error handling happens there. :: + sage: # needs sage.rings.complex_double sage.symbolic sage: v = vector(CDF, [2+3*I]) sage: w = vector(CDF, [5+2*I, 3+9*I]) sage: v.hermitian_inner_product(w) @@ -5093,7 +5095,7 @@ cdef class FreeModuleElement_generic_sparse(FreeModuleElement): if min <= n <= max and n % step == mod: k = (n - start) // step newentries[k] = x - from .free_module import FreeModule + from sage.modules.free_module import FreeModule M = FreeModule(self.coordinate_ring(), slicelength, sparse=True) return M(newentries, coerce=False, copy=False) diff --git a/src/sage/modules/free_module_integer.py b/src/sage/modules/free_module_integer.py index c16e747a53f..5f20d55a89c 100644 --- a/src/sage/modules/free_module_integer.py +++ b/src/sage/modules/free_module_integer.py @@ -407,7 +407,7 @@ def BKZ(self, *args, **kwds): EXAMPLES:: - sage: # needs sage.libs.flint (o/w timeout) + sage: # needs sage.libs.linbox (o/w timeout) sage: from sage.modules.free_module_integer import IntegerLattice sage: A = sage.crypto.gen_lattice(type='random', n=1, m=60, q=2^60, seed=42) sage: L = IntegerLattice(A, lll_reduce=False) diff --git a/src/sage/modules/free_quadratic_module_integer_symmetric.py b/src/sage/modules/free_quadratic_module_integer_symmetric.py index e4959cc7a55..60f3cc131f6 100644 --- a/src/sage/modules/free_quadratic_module_integer_symmetric.py +++ b/src/sage/modules/free_quadratic_module_integer_symmetric.py @@ -1037,7 +1037,7 @@ def maximal_overlattice(self, p=None): EXAMPLES:: - sage: # needs sage.graphs + sage: # needs sage.graphs sage.libs.pari sage: L = IntegralLattice("A4").twist(25*89) sage: L.maximal_overlattice().determinant() 5 @@ -1048,7 +1048,7 @@ def maximal_overlattice(self, p=None): TESTS:: - sage: # needs sage.libs.flint (otherwise timeout) + sage: # needs sage.libs.flint (otherwise timeout) sage.libs.pari sage: L = IntegralLattice(matrix.diagonal([2,4,4,8])) sage: L.maximal_overlattice().is_even() True @@ -1441,7 +1441,7 @@ def maximum(self): sage: L = IntegralLattice('A2') # needs sage.graphs sage: L.maximum() # needs sage.graphs +Infinity - sage: L.twist(-1).maximum() # needs sage.graphs + sage: L.twist(-1).maximum() # needs sage.graphs sage.libs.pari -2 """ if self.rank() == 0: @@ -1463,7 +1463,7 @@ def LLL(self): EXAMPLES:: sage: L = IntegralLattice('A2') # needs sage.graphs - sage: L.lll() == L # needs sage.graphs + sage: L.lll() == L # needs sage.graphs sage.libs.pari True sage: G = matrix(ZZ, 3, [0,1,0, 1,0,0, 0,0,7]) @@ -1511,9 +1511,9 @@ def short_vectors(self, n, **kwargs): EXAMPLES:: sage: A2 = IntegralLattice('A2') # needs sage.graphs - sage: A2.short_vectors(3) # needs sage.graphs + sage: A2.short_vectors(3) # needs sage.graphs sage.libs.pari [[(0, 0)], [], [(1, 1), (-1, -1), (0, 1), (0, -1), (1, 0), (-1, 0)]] - sage: A2.short_vectors(3,up_to_sign_flag=True) # needs sage.graphs + sage: A2.short_vectors(3, up_to_sign_flag=True) # needs sage.graphs sage.libs.pari [[(0, 0)], [], [(1, 1), (0, 1), (1, 0)]] """ p, m = self.signature_pair() @@ -1602,7 +1602,7 @@ def local_modification(M, G, p, check=True): EXAMPLES:: - sage: # needs sage.graphs + sage: # needs sage.graphs sage.libs.pari sage: from sage.modules.free_quadratic_module_integer_symmetric import local_modification sage: L = IntegralLattice("A3").twist(15) sage: M = L.maximal_overlattice() diff --git a/src/sage/modules/matrix_morphism.py b/src/sage/modules/matrix_morphism.py index b9d45e9755f..d342dc00237 100644 --- a/src/sage/modules/matrix_morphism.py +++ b/src/sage/modules/matrix_morphism.py @@ -212,13 +212,15 @@ def _call_with_args(self, x, args=(), kwds={}): EXAMPLES:: + sage: # needs sage.rings.real_mpfr sage.symbolic sage: V = RR^2 sage: f = V.hom(V.gens()) sage: f._matrix *= I # f is now invalid sage: f((1, 0)) Traceback (most recent call last): ... - TypeError: Unable to coerce entries (=[1.00000000000000*I, 0.000000000000000]) to coefficients in Real Field with 53 bits of precision + TypeError: Unable to coerce entries (=[1.00000000000000*I, 0.000000000000000]) + to coefficients in Real Field with 53 bits of precision sage: f((1, 0), coerce=False) (1.00000000000000*I, 0.000000000000000) diff --git a/src/sage/modules/vector_complex_double_dense.pxd b/src/sage/modules/vector_complex_double_dense.pxd index f26526a1669..955c0a414d2 100644 --- a/src/sage/modules/vector_complex_double_dense.pxd +++ b/src/sage/modules/vector_complex_double_dense.pxd @@ -1,4 +1,5 @@ -from .vector_double_dense cimport Vector_double_dense +from sage.modules.vector_double_dense cimport Vector_double_dense + cdef class Vector_complex_double_dense(Vector_double_dense): pass diff --git a/src/sage/modules/vector_double_dense.pxd b/src/sage/modules/vector_double_dense.pxd index f29b4597d15..f4f1f47cbce 100644 --- a/src/sage/modules/vector_double_dense.pxd +++ b/src/sage/modules/vector_double_dense.pxd @@ -1,4 +1,5 @@ -from .vector_numpy_dense cimport Vector_numpy_dense +from sage.modules.vector_numpy_dense cimport Vector_numpy_dense + cdef class Vector_double_dense(Vector_numpy_dense): pass diff --git a/src/sage/modules/vector_double_dense.pyx b/src/sage/modules/vector_double_dense.pyx index a47d91a7fdd..74c73270ffc 100644 --- a/src/sage/modules/vector_double_dense.pyx +++ b/src/sage/modules/vector_double_dense.pyx @@ -212,6 +212,7 @@ cdef class Vector_double_dense(Vector_numpy_dense): EXAMPLES:: + sage: # needs scipy sage: v = vector(CDF,[1,2,3,4]) sage: w = v.fft() sage: max(v - w.inv_fft()) < 1e-12 @@ -233,6 +234,7 @@ cdef class Vector_double_dense(Vector_numpy_dense): EXAMPLES:: + sage: # needs scipy sage: v = vector(CDF,[1+2*I,2,3*I,4]) sage: v.fft() (7.0 + 5.0*I, 1.0 + 1.0*I, -5.0 + 5.0*I, 1.0 - 3.0*I) @@ -246,6 +248,7 @@ cdef class Vector_double_dense(Vector_numpy_dense): sage: v (7.0 + 5.0*I, 1.0 + 1.0*I, -5.0 + 5.0*I, 1.0 - 3.0*I) + sage: # needs scipy sage: v = vector(RDF,4,range(4)); v (0.0, 1.0, 2.0, 3.0) sage: v.fft() @@ -284,7 +287,7 @@ cdef class Vector_double_dense(Vector_numpy_dense): fft = scipy.fft ifft = scipy.ifft V = CDF ** self._degree - from .vector_complex_double_dense import Vector_complex_double_dense + from sage.modules.vector_complex_double_dense import Vector_complex_double_dense if direction == 'forward': return Vector_complex_double_dense(V, fft(self._vector_numpy)) else: @@ -555,6 +558,7 @@ cdef class Vector_double_dense(Vector_numpy_dense): EXAMPLES:: + sage: # needs scipy sage: v = vector(RDF, range(9)) sage: w = vector(CDF, [k+(9-k)*I for k in range(9)]) sage: v.stats_kurtosis() # rel tol 5e-15 diff --git a/src/sage/modules/vector_integer_dense.pxd b/src/sage/modules/vector_integer_dense.pxd index 322a10c369b..0db4808be63 100644 --- a/src/sage/modules/vector_integer_dense.pxd +++ b/src/sage/modules/vector_integer_dense.pxd @@ -1,7 +1,8 @@ -from .free_module_element cimport FreeModuleElement from sage.libs.gmp.types cimport mpz_t +from sage.modules.free_module_element cimport FreeModuleElement from sage.structure.parent cimport Parent + cdef class Vector_integer_dense(FreeModuleElement): cdef mpz_t* _entries cdef int _init(self, Py_ssize_t degree, Parent parent) except -1 diff --git a/src/sage/modules/vector_modn_dense.pxd b/src/sage/modules/vector_modn_dense.pxd index 2482f999d37..6e726651ea1 100644 --- a/src/sage/modules/vector_modn_dense.pxd +++ b/src/sage/modules/vector_modn_dense.pxd @@ -1,5 +1,6 @@ -from .free_module_element cimport FreeModuleElement from sage.ext.mod_int cimport mod_int +from sage.modules.free_module_element cimport FreeModuleElement + cdef class Vector_modn_dense(FreeModuleElement): cdef mod_int* _entries @@ -8,4 +9,3 @@ cdef class Vector_modn_dense(FreeModuleElement): cdef _new_c(self) noexcept cdef _init(self, Py_ssize_t degree, parent, mod_int p) noexcept - diff --git a/src/sage/modules/vector_numpy_dense.pxd b/src/sage/modules/vector_numpy_dense.pxd index 6af57a997c5..0cb384222c2 100644 --- a/src/sage/modules/vector_numpy_dense.pxd +++ b/src/sage/modules/vector_numpy_dense.pxd @@ -1,6 +1,8 @@ -from .free_module_element cimport FreeModuleElement cimport numpy +from sage.modules.free_module_element cimport FreeModuleElement + + cdef class Vector_numpy_dense(FreeModuleElement): cdef object _numpy_dtype cdef int _numpy_dtypeint diff --git a/src/sage/modules/vector_numpy_dense.pyx b/src/sage/modules/vector_numpy_dense.pyx index fc14cc4829a..2739e36d442 100644 --- a/src/sage/modules/vector_numpy_dense.pyx +++ b/src/sage/modules/vector_numpy_dense.pyx @@ -29,7 +29,7 @@ AUTHORS: cimport numpy import numpy -from .free_module_element import FreeModuleElement +from sage.modules.free_module_element import FreeModuleElement # This is for the NumPy C API (the PyArray... functions) to work numpy.import_array() @@ -151,7 +151,7 @@ cdef class Vector_numpy_dense(FreeModuleElement): (0.0, 0.0, 0.0, 0.0) sage: vector(RDF, 4) (0.0, 0.0, 0.0, 0.0) - sage: vector(CDF, [CDF(1+I)*j for j in range(4)]) + sage: vector(CDF, [CDF(1+I)*j for j in range(4)]) # needs sage.symbolic (0.0, 1.0 + 1.0*I, 2.0 + 2.0*I, 3.0 + 3.0*I) sage: vector(RDF, 4, range(4)) (0.0, 1.0, 2.0, 3.0) @@ -211,13 +211,13 @@ cdef class Vector_numpy_dense(FreeModuleElement): """ EXAMPLES:: - sage: v = vector(CDF, [1,CDF(3,2), -1]); v + sage: v = vector(CDF, [1, CDF(3,2), -1]); v (1.0, 3.0 + 2.0*I, -1.0) sage: v[1] = 2 - sage: v[-1] = I - sage: v + sage: v[-1] = I # needs sage.symbolic + sage: v # needs sage.symbolic (1.0, 2.0, 1.0*I) - sage: v[1:3] = [1, 1]; v + sage: v[1:3] = [1, 1]; v # needs sage.symbolic (1.0, 1.0, 1.0) """ # We assume that Py_ssize_t is the same as npy_intp diff --git a/src/sage/modules/vector_numpy_integer_dense.pxd b/src/sage/modules/vector_numpy_integer_dense.pxd index e39b90bbcb9..31bc1cf8f6b 100644 --- a/src/sage/modules/vector_numpy_integer_dense.pxd +++ b/src/sage/modules/vector_numpy_integer_dense.pxd @@ -1,4 +1,5 @@ -from .vector_numpy_dense cimport Vector_numpy_dense +from sage.modules.vector_numpy_dense cimport Vector_numpy_dense + cdef class Vector_numpy_integer_dense(Vector_numpy_dense): diff --git a/src/sage/modules/vector_rational_dense.pxd b/src/sage/modules/vector_rational_dense.pxd index 1bcde479153..4820936580a 100644 --- a/src/sage/modules/vector_rational_dense.pxd +++ b/src/sage/modules/vector_rational_dense.pxd @@ -1,7 +1,8 @@ -from .free_module_element cimport FreeModuleElement from sage.libs.gmp.types cimport mpq_t +from sage.modules.free_module_element cimport FreeModuleElement from sage.structure.parent cimport Parent + cdef class Vector_rational_dense(FreeModuleElement): cdef mpq_t* _entries cdef int _init(self, Py_ssize_t degree, Parent parent) except -1 diff --git a/src/sage/modules/vector_real_double_dense.pxd b/src/sage/modules/vector_real_double_dense.pxd index 6f75ec0c4dd..4dd3b43ab25 100644 --- a/src/sage/modules/vector_real_double_dense.pxd +++ b/src/sage/modules/vector_real_double_dense.pxd @@ -1,5 +1,5 @@ -from .vector_double_dense cimport Vector_double_dense +from sage.modules.vector_double_dense cimport Vector_double_dense + cdef class Vector_real_double_dense(Vector_double_dense): pass - diff --git a/src/sage/modules/vector_real_double_dense.pyx b/src/sage/modules/vector_real_double_dense.pyx index bf7c75f1605..e05895f0011 100644 --- a/src/sage/modules/vector_real_double_dense.pyx +++ b/src/sage/modules/vector_real_double_dense.pyx @@ -72,7 +72,7 @@ cdef class Vector_real_double_dense(Vector_double_dense): EXAMPLES:: sage: v = vector(RDF, range(9)) - sage: v.stats_skew() + sage: v.stats_skew() # needs scipy 0.0 """ import scipy.stats diff --git a/src/sage/modules/vector_space_morphism.py b/src/sage/modules/vector_space_morphism.py index 2685462a74e..91f8f6f64b2 100644 --- a/src/sage/modules/vector_space_morphism.py +++ b/src/sage/modules/vector_space_morphism.py @@ -224,7 +224,7 @@ sage: A = graphs.PetersenGraph().adjacency_matrix() sage: V = QQ^10 sage: phi = linear_transformation(V, V, A) - sage: phi.eigenvalues() + sage: phi.eigenvalues() # needs sage.rings.number_field [3, -2, -2, -2, -2, 1, 1, 1, 1, 1] sage: B1 = [V.gen(i) + V.gen(i+1) for i in range(9)] + [V.gen(9)] sage: C = V.subspace_with_basis(B1) @@ -265,7 +265,7 @@ [0 0 0 0 0 0 0 1 1 0] [0 0 0 0 0 0 0 0 1 1] [0 0 0 0 0 0 0 0 0 1] - sage: zeta.eigenvalues() + sage: zeta.eigenvalues() # needs sage.rings.number_field [3, -2, -2, -2, -2, 1, 1, 1, 1, 1] Equality diff --git a/src/sage/numerical/all.py b/src/sage/numerical/all.py index 06ca1dd1a60..8b69da18652 100644 --- a/src/sage/numerical/all.py +++ b/src/sage/numerical/all.py @@ -1,7 +1,7 @@ from sage.misc.lazy_import import lazy_import lazy_import("sage.numerical.optimize", ["find_fit", "find_local_maximum", "find_local_minimum", - "find_root", "linear_program", "minimize", "minimize_constrained"]) + "find_root", "minimize", "minimize_constrained"]) lazy_import("sage.numerical.mip", ["MixedIntegerLinearProgram"]) lazy_import("sage.numerical.sdp", ["SemidefiniteProgram"]) lazy_import("sage.numerical.backends.generic_backend", ["default_mip_solver"]) diff --git a/src/sage/numerical/backends/cvxopt_backend.pyx b/src/sage/numerical/backends/cvxopt_backend.pyx index 4100fb71b76..0e2f3b82896 100644 --- a/src/sage/numerical/backends/cvxopt_backend.pyx +++ b/src/sage/numerical/backends/cvxopt_backend.pyx @@ -1,10 +1,11 @@ +# sage.doctest: needs cvxopt r""" CVXOPT Backend AUTHORS: -- Ingolfur Edvardsson (2014-05) : initial implementation +- Ingolfur Edvardsson (2014-05): initial implementation """ #***************************************************************************** @@ -18,7 +19,7 @@ AUTHORS: #***************************************************************************** from sage.numerical.mip import MIPSolverException -from .generic_backend cimport GenericBackend +from sage.numerical.backends.generic_backend cimport GenericBackend from copy import copy @@ -30,13 +31,13 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: - sage: p = MixedIntegerLinearProgram(solver="CVXOPT") # optional - cvxopt + sage: p = MixedIntegerLinearProgram(solver="CVXOPT") TESTS: :trac:`20332`:: - sage: p # optional - cvxopt + sage: p Mixed Integer Program (no objective, 0 variables, 0 constraints) """ @@ -62,7 +63,7 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") """ @@ -101,15 +102,15 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = MixedIntegerLinearProgram(solver = "CVXOPT") # optional - cvxopt - sage: b = p.new_variable() # optional - cvxopt - sage: p.add_constraint(b[1] + b[2] <= 6) # optional - cvxopt - sage: p.add_constraint(b[2] <= 5) # optional - cvxopt - sage: p.set_objective(b[1] + b[2]) # optional - cvxopt - sage: cp = copy(p.get_backend()) # optional - cvxopt - sage: cp.solve() # optional - cvxopt + sage: p = MixedIntegerLinearProgram(solver="CVXOPT") + sage: b = p.new_variable() + sage: p.add_constraint(b[1] + b[2] <= 6) + sage: p.add_constraint(b[2] <= 5) + sage: p.set_objective(b[1] + b[2]) + sage: cp = copy(p.get_backend()) + sage: cp.solve() 0 - sage: cp.get_objective_value() # optional - cvxopt + sage: cp.get_objective_value() 6.0 """ cdef CVXOPTBackend cp = type(self)() @@ -160,35 +161,35 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt - sage: p.ncols() # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") + sage: p.ncols() 0 - sage: p.add_variable() # optional - cvxopt + sage: p.add_variable() 0 - sage: p.ncols() # optional - cvxopt + sage: p.ncols() 1 - sage: p.add_variable() # optional - cvxopt + sage: p.add_variable() 1 - sage: p.add_variable(lower_bound=-2.0) # optional - cvxopt + sage: p.add_variable(lower_bound=-2.0) 2 - sage: p.add_variable(continuous=True) # optional - cvxopt + sage: p.add_variable(continuous=True) 3 - sage: p.add_variable(name='x',obj=1.0) # optional - cvxopt + sage: p.add_variable(name='x',obj=1.0) 4 - sage: p.col_name(3) # optional - cvxopt + sage: p.col_name(3) 'x_3' - sage: p.col_name(4) # optional - cvxopt + sage: p.col_name(4) 'x' - sage: p.objective_coefficient(4) # optional - cvxopt + sage: p.objective_coefficient(4) 1.00000000000000 TESTS:: - sage: p.add_variable(integer=True) # optional - cvxopt + sage: p.add_variable(integer=True) Traceback (most recent call last): ... RuntimeError: CVXOPT only supports continuous variables - sage: p.add_variable(binary=True) # optional - cvxopt + sage: p.add_variable(binary=True) Traceback (most recent call last): ... RuntimeError: CVXOPT only supports continuous variables @@ -211,11 +212,11 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "cvxopt") # optional - cvxopt - sage: p.add_variables(5) # optional - cvxopt + sage: p = get_solver(solver="cvxopt") + sage: p.add_variables(5) 4 - sage: p.set_variable_type(3, -1) # optional - cvxopt - sage: p.set_variable_type(3, -2) # optional - cvxopt + sage: p.set_variable_type(3, -1) + sage: p.set_variable_type(3, -2) Traceback (most recent call last): ... ValueError: ... @@ -229,19 +230,19 @@ cdef class CVXOPTBackend(GenericBackend): INPUT: - - ``sense`` (integer) : + - ``sense`` (integer): - * +1 => Maximization - * -1 => Minimization + * `+1` => Maximization + * `-1` => Minimization EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt - sage: p.is_maximization() # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") + sage: p.is_maximization() True - sage: p.set_sense(-1) # optional - cvxopt - sage: p.is_maximization() # optional - cvxopt + sage: p.set_sense(-1) + sage: p.is_maximization() False """ if sense == 1: @@ -263,13 +264,13 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt - sage: p.add_variable() # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") + sage: p.add_variable() 0 - sage: p.objective_coefficient(0) # optional - cvxopt + sage: p.objective_coefficient(0) 0.0 - sage: p.objective_coefficient(0,2) # optional - cvxopt - sage: p.objective_coefficient(0) # optional - cvxopt + sage: p.objective_coefficient(0,2) + sage: p.objective_coefficient(0) 2.0 """ if coeff is not None: @@ -290,12 +291,12 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: - sage: from sage.numerical.backends.generic_backend import get_solver # optional - cvxopt - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt - sage: p.add_variables(5) # optional - cvxopt + sage: from sage.numerical.backends.generic_backend import get_solver + sage: p = get_solver(solver="CVXOPT") + sage: p.add_variables(5) 4 - sage: p.set_objective([1, 1, 2, 1, 3]) # optional - cvxopt - sage: [p.objective_coefficient(x) for x in range(5)] # optional - cvxopt + sage: p.set_objective([1, 1, 2, 1, 3]) + sage: [p.objective_coefficient(x) for x in range(5)] [1, 1, 2, 1, 3] """ for i in range(len(coeff)): @@ -332,14 +333,14 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt - sage: p.ncols() # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") + sage: p.ncols() 0 - sage: p.nrows() # optional - cvxopt + sage: p.nrows() 0 - sage: p.add_linear_constraints(5, 0, None) # optional - cvxopt - sage: p.add_col(range(5), range(5)) # optional - cvxopt - sage: p.nrows() # optional - cvxopt + sage: p.add_linear_constraints(5, 0, None) + sage: p.add_col(range(5), range(5)) + sage: p.nrows() 5 """ column = [] @@ -375,16 +376,16 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt - sage: p.add_variables(5) # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") + sage: p.add_variables(5) 4 - sage: p.add_linear_constraint(zip(range(5), range(5)), 2.0, 2.0) # optional - cvxopt - sage: p.row(0) # optional - cvxopt + sage: p.add_linear_constraint(zip(range(5), range(5)), 2.0, 2.0) + sage: p.row(0) ([1, 2, 3, 4], [1, 2, 3, 4]) - sage: p.row_bounds(0) # optional - cvxopt + sage: p.row_bounds(0) (2.00000000000000, 2.00000000000000) - sage: p.add_linear_constraint(zip(range(5), range(5)), 1.0, 1.0, name='foo') # optional - cvxopt - sage: p.row_name(-1) # optional - cvxopt + sage: p.add_linear_constraint(zip(range(5), range(5)), 1.0, 1.0, name='foo') + sage: p.row_name(-1) 'foo' """ coefficients = list(coefficients) @@ -412,76 +413,85 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: - sage: p = MixedIntegerLinearProgram(solver = "cvxopt", maximization=False) # optional - cvxopt - sage: x=p.new_variable(nonnegative=True) # optional - cvxopt - sage: p.set_objective(-4*x[0] - 5*x[1]) # optional - cvxopt - sage: p.add_constraint(2*x[0] + x[1] <= 3) # optional - cvxopt - sage: p.add_constraint(2*x[1] + x[0] <= 3) # optional - cvxopt - sage: N(p.solve(), digits=2) # optional - cvxopt + sage: p = MixedIntegerLinearProgram(solver="cvxopt", maximization=False) + sage: x = p.new_variable(nonnegative=True) + sage: p.set_objective(-4*x[0] - 5*x[1]) + sage: p.add_constraint(2*x[0] + x[1] <= 3) + sage: p.add_constraint(2*x[1] + x[0] <= 3) + sage: N(p.solve(), digits=2) -9.0 - sage: p = MixedIntegerLinearProgram(solver = "cvxopt", maximization=False) # optional - cvxopt - sage: x=p.new_variable(nonnegative=True) # optional - cvxopt - sage: p.set_objective(x[0] + 2*x[1]) # optional - cvxopt - sage: p.add_constraint(-5*x[0] + x[1] <= 7) # optional - cvxopt - sage: p.add_constraint(-5*x[0] + x[1] >= 7) # optional - cvxopt - sage: p.add_constraint(x[0] + x[1] >= 26 ) # optional - cvxopt - sage: p.add_constraint( x[0] >= 3) # optional - cvxopt - sage: p.add_constraint( x[1] >= 4) # optional - cvxopt - sage: N(p.solve(),digits=4) # optional - cvxopt + + sage: p = MixedIntegerLinearProgram(solver="cvxopt", maximization=False) + sage: x = p.new_variable(nonnegative=True) + sage: p.set_objective(x[0] + 2*x[1]) + sage: p.add_constraint(-5*x[0] + x[1] <= 7) + sage: p.add_constraint(-5*x[0] + x[1] >= 7) + sage: p.add_constraint(x[0] + x[1] >= 26) + sage: p.add_constraint(x[0] >= 3) + sage: p.add_constraint(x[1] >= 4) + sage: N(p.solve(), digits=4) 48.83 - sage: p = MixedIntegerLinearProgram(solver = "cvxopt") # optional - cvxopt - sage: x=p.new_variable(nonnegative=True) # optional - cvxopt - sage: p.set_objective(x[0] + x[1] + 3*x[2]) # optional - cvxopt - sage: p.solver_parameter("show_progress",True) # optional - cvxopt - sage: p.add_constraint(x[0] + 2*x[1] <= 4) # optional - cvxopt - sage: p.add_constraint(5*x[2] - x[1] <= 8) # optional - cvxopt - sage: N(p.solve(), digits=2) # optional - cvxopt + + sage: p = MixedIntegerLinearProgram(solver="cvxopt") + sage: x = p.new_variable(nonnegative=True) + sage: p.set_objective(x[0] + x[1] + 3*x[2]) + sage: p.solver_parameter("show_progress",True) + sage: p.add_constraint(x[0] + 2*x[1] <= 4) + sage: p.add_constraint(5*x[2] - x[1] <= 8) + sage: N(p.solve(), digits=2) pcost dcost gap pres dres k/t ... 8.8 - sage: #CVXOPT gives different values for variables compared to the other solvers. - sage: c = MixedIntegerLinearProgram(solver = "cvxopt") # optional - cvxopt - sage: p = MixedIntegerLinearProgram(solver = "ppl") # optional - cvxopt - sage: g = MixedIntegerLinearProgram() # optional - cvxopt - sage: xc=c.new_variable(nonnegative=True) # optional - cvxopt - sage: xp=p.new_variable(nonnegative=True) # optional - cvxopt - sage: xg=g.new_variable(nonnegative=True) # optional - cvxopt - sage: c.set_objective(xc[2]) # optional - cvxopt - sage: p.set_objective(xp[2]) # optional - cvxopt - sage: g.set_objective(xg[2]) # optional - cvxopt - sage: #we create a cube for all three solvers - sage: c.add_constraint(xc[0] <= 100) # optional - cvxopt - sage: c.add_constraint(xc[1] <= 100) # optional - cvxopt - sage: c.add_constraint(xc[2] <= 100) # optional - cvxopt - sage: p.add_constraint(xp[0] <= 100) # optional - cvxopt - sage: p.add_constraint(xp[1] <= 100) # optional - cvxopt - sage: p.add_constraint(xp[2] <= 100) # optional - cvxopt - sage: g.add_constraint(xg[0] <= 100) # optional - cvxopt - sage: g.add_constraint(xg[1] <= 100) # optional - cvxopt - sage: g.add_constraint(xg[2] <= 100) # optional - cvxopt - sage: N(c.solve(),digits=4) # optional - cvxopt + + When the optimal solution is not unique, CVXOPT as an interior point solver + gives a different type of solution compared to the solvers that use the + simplex method. + + In the following example, the top face of the cube is optimal, and CVXOPT + gives the center point of the top face, whereas the other tested solvers + return a vertex:: + + sage: c = MixedIntegerLinearProgram(solver="cvxopt") + sage: p = MixedIntegerLinearProgram(solver="ppl") + sage: g = MixedIntegerLinearProgram() + sage: xc = c.new_variable(nonnegative=True) + sage: xp = p.new_variable(nonnegative=True) + sage: xg = g.new_variable(nonnegative=True) + sage: c.set_objective(xc[2]) + sage: p.set_objective(xp[2]) + sage: g.set_objective(xg[2]) + sage: c.add_constraint(xc[0] <= 100) + sage: c.add_constraint(xc[1] <= 100) + sage: c.add_constraint(xc[2] <= 100) + sage: p.add_constraint(xp[0] <= 100) + sage: p.add_constraint(xp[1] <= 100) + sage: p.add_constraint(xp[2] <= 100) + sage: g.add_constraint(xg[0] <= 100) + sage: g.add_constraint(xg[1] <= 100) + sage: g.add_constraint(xg[2] <= 100) + sage: N(c.solve(), digits=4) 100.0 - sage: N(c.get_values(xc[0]),digits=3) # optional - cvxopt + sage: N(c.get_values(xc[0]), digits=3) 50.0 - sage: N(c.get_values(xc[1]),digits=3) # optional - cvxopt + sage: N(c.get_values(xc[1]), digits=3) 50.0 - sage: N(c.get_values(xc[2]),digits=4) # optional - cvxopt + sage: N(c.get_values(xc[2]), digits=4) 100.0 - sage: N(p.solve(),digits=4) # optional - cvxopt + sage: N(p.solve(), digits=4) 100.0 - sage: N(p.get_values(xp[0]),2) # optional - cvxopt + sage: N(p.get_values(xp[0]), 2) 0.00 - sage: N(p.get_values(xp[1]),2) # optional - cvxopt + sage: N(p.get_values(xp[1]), 2) 0.00 - sage: N(p.get_values(xp[2]),digits=4) # optional - cvxopt + sage: N(p.get_values(xp[2]), digits=4) 100.0 - sage: N(g.solve(),digits=4) # optional - cvxopt + sage: N(g.solve(), digits=4) 100.0 - sage: N(g.get_values(xg[0]),2) # optional - cvxopt + sage: N(g.get_values(xg[0]), 2) 0.00 - sage: N(g.get_values(xg[1]),2) # optional - cvxopt + sage: N(g.get_values(xg[1]), 2) 0.00 - sage: N(g.get_values(xg[2]),digits=4) # optional - cvxopt + sage: N(g.get_values(xg[2]), digits=4) 100.0 """ from cvxopt import matrix, solvers @@ -565,18 +575,18 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "cvxopt") # optional - cvxopt - sage: p.add_variables(2) # optional - cvxopt + sage: p = get_solver(solver="cvxopt") + sage: p.add_variables(2) 1 - sage: p.add_linear_constraint([(0,1), (1,2)], None, 3) # optional - cvxopt - sage: p.set_objective([2, 5]) # optional - cvxopt - sage: p.solve() # optional - cvxopt + sage: p.add_linear_constraint([(0,1), (1,2)], None, 3) + sage: p.set_objective([2, 5]) + sage: p.solve() 0 - sage: N(p.get_objective_value(),4) # optional - cvxopt + sage: N(p.get_objective_value(),4) 7.5 - sage: N(p.get_variable_value(0),4) # optional - cvxopt + sage: N(p.get_variable_value(0),4) 3.6e-7 - sage: N(p.get_variable_value(1),4) # optional - cvxopt + sage: N(p.get_variable_value(1),4) 1.5 """ sum = self.obj_constant_term @@ -597,18 +607,18 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt - sage: p.add_variables(2) # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") + sage: p.add_variables(2) 1 - sage: p.add_linear_constraint([(0,1), (1, 2)], None, 3) # optional - cvxopt - sage: p.set_objective([2, 5]) # optional - cvxopt - sage: p.solve() # optional - cvxopt + sage: p.add_linear_constraint([(0,1), (1, 2)], None, 3) + sage: p.set_objective([2, 5]) + sage: p.solve() 0 - sage: N(p.get_objective_value(),4) # optional - cvxopt + sage: N(p.get_objective_value(),4) 7.5 - sage: N(p.get_variable_value(0),4) # optional - cvxopt + sage: N(p.get_variable_value(0),4) 3.6e-7 - sage: N(p.get_variable_value(1),4) # optional - cvxopt + sage: N(p.get_variable_value(1),4) 1.5 """ return self.answer['x'][variable] @@ -620,12 +630,12 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt - sage: p.ncols() # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") + sage: p.ncols() 0 - sage: p.add_variables(2) # optional - cvxopt + sage: p.add_variables(2) 1 - sage: p.ncols() # optional - cvxopt + sage: p.ncols() 2 """ @@ -638,13 +648,13 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt - sage: p.nrows() # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") + sage: p.nrows() 0 - sage: p.add_variables(5) # optional - cvxopt + sage: p.add_variables(5) 4 - sage: p.add_linear_constraints(2, 2.0, None) # optional - cvxopt - sage: p.nrows() # optional - cvxopt + sage: p.add_linear_constraints(2, 2.0, None) + sage: p.nrows() 2 """ return len(self.row_upper_bound) @@ -657,11 +667,11 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt - sage: p.is_maximization() # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") + sage: p.is_maximization() True - sage: p.set_sense(-1) # optional - cvxopt - sage: p.is_maximization() # optional - cvxopt + sage: p.set_sense(-1) + sage: p.is_maximization() False """ if self.is_maximize == 1: @@ -681,11 +691,11 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt - sage: p.problem_name() # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") + sage: p.problem_name() '' - sage: p.problem_name("There once was a french fry") # optional - cvxopt - sage: print(p.problem_name()) # optional - cvxopt + sage: p.problem_name("There once was a french fry") + sage: print(p.problem_name()) There once was a french fry """ if name is None: @@ -711,13 +721,13 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt - sage: p.add_variables(5) # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") + sage: p.add_variables(5) 4 - sage: p.add_linear_constraint(list(zip(range(5), range(5))), 2, 2) # optional - cvxopt - sage: p.row(0) # optional - cvxopt + sage: p.add_linear_constraint(list(zip(range(5), range(5))), 2, 2) + sage: p.row(0) ([1, 2, 3, 4], [1, 2, 3, 4]) - sage: p.row_bounds(0) # optional - cvxopt + sage: p.row_bounds(0) (2, 2) """ coeff = [] @@ -748,13 +758,13 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt - sage: p.add_variables(5) # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") + sage: p.add_variables(5) 4 - sage: p.add_linear_constraint(list(zip(range(5), range(5))), 2, 2) # optional - cvxopt - sage: p.row(0) # optional - cvxopt + sage: p.add_linear_constraint(list(zip(range(5), range(5))), 2, 2) + sage: p.row(0) ([1, 2, 3, 4], [1, 2, 3, 4]) - sage: p.row_bounds(0) # optional - cvxopt + sage: p.row_bounds(0) (2, 2) """ return (self.row_lower_bound[index], self.row_upper_bound[index]) @@ -776,13 +786,13 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt - sage: p.add_variable() # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") + sage: p.add_variable() 0 - sage: p.col_bounds(0) # optional - cvxopt + sage: p.col_bounds(0) (0.0, None) - sage: p.variable_upper_bound(0, 5) # optional - cvxopt - sage: p.col_bounds(0) # optional - cvxopt + sage: p.variable_upper_bound(0, 5) + sage: p.col_bounds(0) (0.0, 5) """ return (self.col_lower_bound[index], self.col_upper_bound[index]) @@ -799,16 +809,16 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt - sage: p.ncols() # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") + sage: p.ncols() 0 - sage: p.add_variable() # optional - cvxopt + sage: p.add_variable() 0 - sage: p.set_variable_type(0,0) # optional - cvxopt + sage: p.set_variable_type(0,0) Traceback (most recent call last): ... ValueError: ... - sage: p.is_variable_binary(0) # optional - cvxopt + sage: p.is_variable_binary(0) False """ @@ -826,17 +836,17 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt - sage: p.ncols() # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") + sage: p.ncols() 0 - sage: p.add_variable() # optional - cvxopt + sage: p.add_variable() 0 - sage: p.set_variable_type(0,-1) # optional - cvxopt - sage: p.set_variable_type(0,1) # optional - cvxopt + sage: p.set_variable_type(0,-1) + sage: p.set_variable_type(0,1) Traceback (most recent call last): ... ValueError: ... - sage: p.is_variable_integer(0) # optional - cvxopt + sage: p.is_variable_integer(0) False """ return False @@ -853,18 +863,18 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt - sage: p.ncols() # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") + sage: p.ncols() 0 - sage: p.add_variable() # optional - cvxopt + sage: p.add_variable() 0 - sage: p.is_variable_continuous(0) # optional - cvxopt + sage: p.is_variable_continuous(0) True - sage: p.set_variable_type(0,1) # optional - cvxopt + sage: p.set_variable_type(0,1) Traceback (most recent call last): ... ValueError: ... - sage: p.is_variable_continuous(0) # optional - cvxopt + sage: p.is_variable_continuous(0) True """ @@ -881,9 +891,9 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt - sage: p.add_linear_constraints(1, 2, None, names=["Empty constraint 1"]) # optional - cvxopt - sage: p.row_name(0) # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") + sage: p.add_linear_constraints(1, 2, None, names=["Empty constraint 1"]) + sage: p.row_name(0) 'Empty constraint 1' """ if self.row_name_var[index] is not None: @@ -904,10 +914,10 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt - sage: p.add_variable(name="I am a variable") # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") + sage: p.add_variable(name="I am a variable") 0 - sage: p.col_name(0) # optional - cvxopt + sage: p.col_name(0) 'I am a variable' """ if self.col_name_var[index] is not None: @@ -929,13 +939,13 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt - sage: p.add_variable() # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") + sage: p.add_variable() 0 - sage: p.col_bounds(0) # optional - cvxopt + sage: p.col_bounds(0) (0.0, None) - sage: p.variable_upper_bound(0, 5) # optional - cvxopt - sage: p.col_bounds(0) # optional - cvxopt + sage: p.variable_upper_bound(0, 5) + sage: p.col_bounds(0) (0.0, 5) """ if value is not False: @@ -958,13 +968,13 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt - sage: p.add_variable() # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") + sage: p.add_variable() 0 - sage: p.col_bounds(0) # optional - cvxopt + sage: p.col_bounds(0) (0.0, None) - sage: p.variable_lower_bound(0, 5) # optional - cvxopt - sage: p.col_bounds(0) # optional - cvxopt + sage: p.variable_lower_bound(0, 5) + sage: p.col_bounds(0) (5, None) """ if value is not False: @@ -991,11 +1001,11 @@ cdef class CVXOPTBackend(GenericBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver="CVXOPT") # optional - cvxopt - sage: p.solver_parameter("show_progress") # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") + sage: p.solver_parameter("show_progress") False - sage: p.solver_parameter("show_progress", True) # optional - cvxopt - sage: p.solver_parameter("show_progress") # optional - cvxopt + sage: p.solver_parameter("show_progress", True) + sage: p.solver_parameter("show_progress") True """ if value is None: diff --git a/src/sage/numerical/backends/cvxopt_sdp_backend.pyx b/src/sage/numerical/backends/cvxopt_sdp_backend.pyx index aefa91439bf..7aa91de6158 100644 --- a/src/sage/numerical/backends/cvxopt_sdp_backend.pyx +++ b/src/sage/numerical/backends/cvxopt_sdp_backend.pyx @@ -1,12 +1,13 @@ +# sage.doctest: needs cvxopt r""" CVXOPT SDP Backend AUTHORS: -- Ingolfur Edvardsson (2014-05) : initial implementation +- Ingolfur Edvardsson (2014-05): initial implementation -- Dima Pasechnik (2015-12) : minor fixes +- Dima Pasechnik (2015-12): minor fixes """ #***************************************************************************** @@ -21,7 +22,7 @@ AUTHORS: from sage.numerical.sdp import SDPSolverException from sage.matrix.constructor import Matrix -from .matrix_sdp_backend cimport MatrixSDPBackend +from sage.numerical.backends.matrix_sdp_backend cimport MatrixSDPBackend cdef class CVXOPTSDPBackend(MatrixSDPBackend): @@ -36,7 +37,7 @@ cdef class CVXOPTSDPBackend(MatrixSDPBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_sdp_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") """ @@ -62,15 +63,15 @@ cdef class CVXOPTSDPBackend(MatrixSDPBackend): .. NOTE:: - This method raises ``SDPSolverException`` exceptions when + This method raises :class:`SDPSolverException` exceptions when the solution cannot be computed for any reason (none exists, or the LP solver was not able to find it, etc...) EXAMPLES:: - sage: p = SemidefiniteProgram(solver = "cvxopt", maximization=False) # optional - cvxopt - sage: x = p.new_variable() # optional - cvxopt - sage: p.set_objective(x[0] - x[1] + x[2]) # optional - cvxopt + sage: p = SemidefiniteProgram(solver="cvxopt", maximization=False) + sage: x = p.new_variable() + sage: p.set_objective(x[0] - x[1] + x[2]) sage: a1 = matrix([[-7., -11.], [-11., 3.]]) sage: a2 = matrix([[7., -18.], [-18., 8.]]) sage: a3 = matrix([[-2., -8.], [-8., 1.]]) @@ -79,13 +80,13 @@ cdef class CVXOPTSDPBackend(MatrixSDPBackend): sage: b2 = matrix([[0., 10., 16.], [10., -10., -10.], [16., -10., 3.]]) sage: b3 = matrix([[-5., 2., -17.], [2., -6., 8.], [-17., 8., 6.]]) sage: b4 = matrix([[14., 9., 40.], [9., 91., 10.], [40., 10., 15.]]) - sage: p.add_constraint(a1*x[0] + a3*x[2] <= a4) # optional - cvxopt - sage: p.add_constraint(b1*x[0] + b2*x[1] + b3*x[2] <= b4) # optional - cvxopt - sage: N(p.solve(), digits=4) # optional - cvxopt + sage: p.add_constraint(a1*x[0] + a3*x[2] <= a4) + sage: p.add_constraint(b1*x[0] + b2*x[1] + b3*x[2] <= b4) + sage: N(p.solve(), digits=4) -3.225 - sage: p = SemidefiniteProgram(solver = "cvxopt", maximization=False) # optional - cvxopt - sage: x = p.new_variable() # optional - cvxopt - sage: p.set_objective(x[0] - x[1] + x[2]) # optional - cvxopt + sage: p = SemidefiniteProgram(solver="cvxopt", maximization=False) + sage: x = p.new_variable() + sage: p.set_objective(x[0] - x[1] + x[2]) sage: a1 = matrix([[-7., -11.], [-11., 3.]]) sage: a2 = matrix([[7., -18.], [-18., 8.]]) sage: a3 = matrix([[-2., -8.], [-8., 1.]]) @@ -94,9 +95,9 @@ cdef class CVXOPTSDPBackend(MatrixSDPBackend): sage: b2 = matrix([[0., 10., 16.], [10., -10., -10.], [16., -10., 3.]]) sage: b3 = matrix([[-5., 2., -17.], [2., -6., 8.], [-17., 8., 6.]]) sage: b4 = matrix([[14., 9., 40.], [9., 91., 10.], [40., 10., 15.]]) - sage: p.add_constraint(a1*x[0] + a2*x[1] + a3*x[2] <= a4) # optional - cvxopt - sage: p.add_constraint(b1*x[0] + b2*x[1] + b3*x[2] <= b4) # optional - cvxopt - sage: N(p.solve(), digits=4) # optional - cvxopt + sage: p.add_constraint(a1*x[0] + a2*x[1] + a3*x[2] <= a4) + sage: p.add_constraint(b1*x[0] + b2*x[1] + b3*x[2] <= b4) + sage: N(p.solve(), digits=4) -3.154 """ @@ -171,9 +172,9 @@ cdef class CVXOPTSDPBackend(MatrixSDPBackend): EXAMPLES:: - sage: p = SemidefiniteProgram(solver = "cvxopt", maximization=False) # optional - cvxopt - sage: x = p.new_variable() # optional - cvxopt - sage: p.set_objective(x[0] - x[1] + x[2]) # optional - cvxopt + sage: p = SemidefiniteProgram(solver="cvxopt", maximization=False) + sage: x = p.new_variable() + sage: p.set_objective(x[0] - x[1] + x[2]) sage: a1 = matrix([[-7., -11.], [-11., 3.]]) sage: a2 = matrix([[7., -18.], [-18., 8.]]) sage: a3 = matrix([[-2., -8.], [-8., 1.]]) @@ -182,11 +183,11 @@ cdef class CVXOPTSDPBackend(MatrixSDPBackend): sage: b2 = matrix([[0., 10., 16.], [10., -10., -10.], [16., -10., 3.]]) sage: b3 = matrix([[-5., 2., -17.], [2., -6., 8.], [-17., 8., 6.]]) sage: b4 = matrix([[14., 9., 40.], [9., 91., 10.], [40., 10., 15.]]) - sage: p.add_constraint(a1*x[0] + a2*x[1] + a3*x[2] <= a4) # optional - cvxopt - sage: p.add_constraint(b1*x[0] + b2*x[1] + b3*x[2] <= b4) # optional - cvxopt - sage: N(p.solve(), digits=4) # optional - cvxopt + sage: p.add_constraint(a1*x[0] + a2*x[1] + a3*x[2] <= a4) + sage: p.add_constraint(b1*x[0] + b2*x[1] + b3*x[2] <= b4) + sage: N(p.solve(), digits=4) -3.154 - sage: N(p.get_backend().get_objective_value(), digits=4) # optional - cvxopt + sage: N(p.get_backend().get_objective_value(), digits=4) -3.154 """ sum = self.obj_constant_term @@ -204,20 +205,20 @@ cdef class CVXOPTSDPBackend(MatrixSDPBackend): TESTS:: - sage: p = SemidefiniteProgram(maximization = False, solver='cvxopt') # optional - cvxopt - sage: x = p.new_variable() # optional - cvxopt - sage: p.set_objective(x[0] - x[1]) # optional - cvxopt + sage: p = SemidefiniteProgram(maximization=False, solver='cvxopt') + sage: x = p.new_variable() + sage: p.set_objective(x[0] - x[1]) sage: a1 = matrix([[1, 2.], [2., 3.]]) sage: a2 = matrix([[3, 4.], [4., 5.]]) sage: a3 = matrix([[5, 6.], [6., 7.]]) sage: b1 = matrix([[1, 1.], [1., 1.]]) sage: b2 = matrix([[2, 2.], [2., 2.]]) sage: b3 = matrix([[3, 3.], [3., 3.]]) - sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) # optional - cvxopt - sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) # optional - cvxopt - sage: p.solve(); # tol 1e-08 # optional - cvxopt + sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) + sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) + sage: p.solve(); # tol 1e-08 -3.0 - sage: p.get_backend()._get_answer() # optional - cvxopt + sage: p.get_backend()._get_answer() {...} """ return self.answer @@ -232,9 +233,9 @@ cdef class CVXOPTSDPBackend(MatrixSDPBackend): EXAMPLES:: - sage: p = SemidefiniteProgram(solver = "cvxopt", maximization=False) # optional - cvxopt - sage: x = p.new_variable() # optional - cvxopt - sage: p.set_objective(x[0] - x[1] + x[2]) # optional - cvxopt + sage: p = SemidefiniteProgram(solver="cvxopt", maximization=False) + sage: x = p.new_variable() + sage: p.set_objective(x[0] - x[1] + x[2]) sage: a1 = matrix([[-7., -11.], [-11., 3.]]) sage: a2 = matrix([[7., -18.], [-18., 8.]]) sage: a3 = matrix([[-2., -8.], [-8., 1.]]) @@ -243,15 +244,15 @@ cdef class CVXOPTSDPBackend(MatrixSDPBackend): sage: b2 = matrix([[0., 10., 16.], [10., -10., -10.], [16., -10., 3.]]) sage: b3 = matrix([[-5., 2., -17.], [2., -6., 8.], [-17., 8., 6.]]) sage: b4 = matrix([[14., 9., 40.], [9., 91., 10.], [40., 10., 15.]]) - sage: p.add_constraint(a1*x[0] + a2*x[1] + a3*x[2] <= a4) # optional - cvxopt - sage: p.add_constraint(b1*x[0] + b2*x[1] + b3*x[2] <= b4) # optional - cvxopt - sage: N(p.solve(), digits=4) # optional - cvxopt + sage: p.add_constraint(a1*x[0] + a2*x[1] + a3*x[2] <= a4) + sage: p.add_constraint(b1*x[0] + b2*x[1] + b3*x[2] <= b4) + sage: N(p.solve(), digits=4) -3.154 - sage: N(p.get_backend().get_variable_value(0), digits=3) # optional - cvxopt + sage: N(p.get_backend().get_variable_value(0), digits=3) -0.368 - sage: N(p.get_backend().get_variable_value(1), digits=4) # optional - cvxopt + sage: N(p.get_backend().get_variable_value(1), digits=4) 1.898 - sage: N(p.get_backend().get_variable_value(2), digits=3) # optional - cvxopt + sage: N(p.get_backend().get_variable_value(2), digits=3) -0.888 """ return self.answer['x'][variable] @@ -270,34 +271,34 @@ cdef class CVXOPTSDPBackend(MatrixSDPBackend): EXAMPLES:: - sage: p = SemidefiniteProgram(maximization = False, solver='cvxopt') # optional - cvxopt - sage: x = p.new_variable() # optional - cvxopt - sage: p.set_objective(x[0] - x[1]) # optional - cvxopt + sage: p = SemidefiniteProgram(maximization=False, solver='cvxopt') + sage: x = p.new_variable() + sage: p.set_objective(x[0] - x[1]) sage: a1 = matrix([[1, 2.], [2., 3.]]) sage: a2 = matrix([[3, 4.], [4., 5.]]) sage: a3 = matrix([[5, 6.], [6., 7.]]) sage: b1 = matrix([[1, 1.], [1., 1.]]) sage: b2 = matrix([[2, 2.], [2., 2.]]) sage: b3 = matrix([[3, 3.], [3., 3.]]) - sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) # optional - cvxopt - sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) # optional - cvxopt - sage: p.solve() # tol 1e-08 # optional - cvxopt + sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) + sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) + sage: p.solve() # tol 1e-08 -3.0 - sage: B=p.get_backend() # optional - cvxopt - sage: x=p.get_values(x).values() # optional - cvxopt - sage: -(a3*B.dual_variable(0)).trace()-(b3*B.dual_variable(1)).trace() # tol 1e-07 # optional - cvxopt + sage: B = p.get_backend() + sage: x = p.get_values(x).values() + sage: -(a3*B.dual_variable(0)).trace() - (b3*B.dual_variable(1)).trace() # tol 1e-07 -3.0 - sage: g = sum((B.slack(j)*B.dual_variable(j)).trace() for j in range(2)); g # tol 1.5e-08 # optional - cvxopt + sage: g = sum((B.slack(j)*B.dual_variable(j)).trace() for j in range(2)); g # tol 1.5e-08 0.0 TESTS:: - sage: B.dual_variable(7) # optional - cvxopt + sage: B.dual_variable(7) Traceback (most recent call last): ... IndexError: list index out of range - sage: abs(g - B._get_answer()['gap']) # tol 1e-22 # optional - cvxopt + sage: abs(g - B._get_answer()['gap']) # tol 1e-22 0.0 """ @@ -320,33 +321,33 @@ cdef class CVXOPTSDPBackend(MatrixSDPBackend): EXAMPLES:: - sage: p = SemidefiniteProgram(maximization = False, solver='cvxopt') # optional - cvxopt - sage: x = p.new_variable() # optional - cvxopt - sage: p.set_objective(x[0] - x[1]) # optional - cvxopt + sage: p = SemidefiniteProgram(maximization = False, solver='cvxopt') + sage: x = p.new_variable() + sage: p.set_objective(x[0] - x[1]) sage: a1 = matrix([[1, 2.], [2., 3.]]) sage: a2 = matrix([[3, 4.], [4., 5.]]) sage: a3 = matrix([[5, 6.], [6., 7.]]) sage: b1 = matrix([[1, 1.], [1., 1.]]) sage: b2 = matrix([[2, 2.], [2., 2.]]) sage: b3 = matrix([[3, 3.], [3., 3.]]) - sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) # optional - cvxopt - sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) # optional - cvxopt - sage: p.solve() # tol 1e-08 # optional - cvxopt + sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) + sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) + sage: p.solve() # tol 1e-08 -3.0 - sage: B = p.get_backend() # optional - cvxopt - sage: B1 = B.slack(1); B1 # tol 1e-08 # optional - cvxopt + sage: B = p.get_backend() + sage: B1 = B.slack(1); B1 # tol 1e-08 [0.0 0.0] [0.0 0.0] - sage: B1.is_positive_definite() # optional - cvxopt + sage: B1.is_positive_definite() True - sage: x = sorted(p.get_values(x).values()) # optional - cvxopt - sage: x[0]*b1 + x[1]*b2 - b3 + B1 # tol 1e-09 # optional - cvxopt + sage: x = sorted(p.get_values(x).values()) + sage: x[0]*b1 + x[1]*b2 - b3 + B1 # tol 1e-09 [0.0 0.0] [0.0 0.0] TESTS:: - sage: B.slack(7) # optional - cvxopt + sage: B.slack(7) Traceback (most recent call last): ... IndexError: list index out of range @@ -358,7 +359,7 @@ cdef class CVXOPTSDPBackend(MatrixSDPBackend): return Matrix(n, n, list(self.answer['ss'][i]), sparse=sparse) - cpdef solver_parameter(self, name, value = None) noexcept: + cpdef solver_parameter(self, name, value=None) noexcept: """ Return or define a solver parameter @@ -377,11 +378,11 @@ cdef class CVXOPTSDPBackend(MatrixSDPBackend): EXAMPLES:: sage: from sage.numerical.backends.generic_sdp_backend import get_solver - sage: p = get_solver(solver = "CVXOPT") # optional - cvxopt - sage: p.solver_parameter("show_progress") # optional - cvxopt + sage: p = get_solver(solver="CVXOPT") + sage: p.solver_parameter("show_progress") False - sage: p.solver_parameter("show_progress", True) # optional - cvxopt - sage: p.solver_parameter("show_progress") # optional - cvxopt + sage: p.solver_parameter("show_progress", True) + sage: p.solver_parameter("show_progress") True """ if value is None: diff --git a/src/sage/numerical/backends/cvxpy_backend.pyx b/src/sage/numerical/backends/cvxpy_backend.pyx index 7cf5ccc8fb6..1cbba9f6375 100644 --- a/src/sage/numerical/backends/cvxpy_backend.pyx +++ b/src/sage/numerical/backends/cvxpy_backend.pyx @@ -58,11 +58,11 @@ cdef class CVXPYBackend: Open-source solvers provided by optional packages:: - sage: p = MixedIntegerLinearProgram(solver="CVXPY/GLPK"); p.solve() # optional - cvxopt + sage: p = MixedIntegerLinearProgram(solver="CVXPY/GLPK"); p.solve() # needs cvxopt 0.0 - sage: p = MixedIntegerLinearProgram(solver="CVXPY/GLPK_MI"); p.solve() # optional - cvxopt + sage: p = MixedIntegerLinearProgram(solver="CVXPY/GLPK_MI"); p.solve() # needs cvxopt 0.0 - sage: p = MixedIntegerLinearProgram(solver="CVXPY/CVXOPT"); p.solve() # optional - cvxopt + sage: p = MixedIntegerLinearProgram(solver="CVXPY/CVXOPT"); p.solve() # needs cvxopt 0.0 sage: p = MixedIntegerLinearProgram(solver="CVXPY/GLOP"); p.solve() # optional - ortools 0.0 diff --git a/src/sage/numerical/backends/generic_backend.pyx b/src/sage/numerical/backends/generic_backend.pyx index 6d43a6ba958..c5c7dadc4c1 100644 --- a/src/sage/numerical/backends/generic_backend.pyx +++ b/src/sage/numerical/backends/generic_backend.pyx @@ -3,7 +3,7 @@ Generic Backend for LP solvers This class only lists the methods that should be defined by any interface with a LP Solver. All these methods immediately raise -``NotImplementedError`` exceptions when called, and are obviously +:class:`NotImplementedError` exceptions when called, and are obviously meant to be replaced by the solver-specific method. This file can also be used as a template to create a new interface : one would only need to replace the occurrences of ``"Nonexistent_LP_solver"`` by the @@ -69,27 +69,28 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.ncols() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.ncols() 0 - sage: p.add_variable() # optional - Nonexistent_LP_solver + sage: p.add_variable() 0 - sage: p.ncols() # optional - Nonexistent_LP_solver + sage: p.ncols() 1 - sage: p.add_variable(binary=True) # optional - Nonexistent_LP_solver + sage: p.add_variable(binary=True) 1 - sage: p.add_variable(lower_bound=-2.0, integer=True) # optional - Nonexistent_LP_solver + sage: p.add_variable(lower_bound=-2.0, integer=True) 2 - sage: p.add_variable(continuous=True, integer=True) # optional - Nonexistent_LP_solver + sage: p.add_variable(continuous=True, integer=True) Traceback (most recent call last): ... ValueError: ... - sage: p.add_variable(name='x',obj=1.0) # optional - Nonexistent_LP_solver + sage: p.add_variable(name='x', obj=1.0) 3 - sage: p.col_name(3) # optional - Nonexistent_LP_solver + sage: p.col_name(3) 'x' - sage: p.objective_coefficient(3) # optional - Nonexistent_LP_solver + sage: p.objective_coefficient(3) 1.0 """ raise NotImplementedError() @@ -123,28 +124,30 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.ncols() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.ncols() 0 - sage: p.add_variables(5) # optional - Nonexistent_LP_solver + sage: p.add_variables(5) 4 - sage: p.ncols() # optional - Nonexistent_LP_solver + sage: p.ncols() 5 - sage: p.add_variables(2, lower_bound=-2.0, integer=True, names=['a','b']) # optional - Nonexistent_LP_solver + sage: p.add_variables(2, lower_bound=-2.0, integer=True, names=['a','b']) 6 TESTS: Check that arguments are used:: - sage: p.col_bounds(5) # tol 1e-8, optional - Nonexistent_LP_solver + sage: # optional - nonexistent_lp_solver + sage: p.col_bounds(5) # tol 1e-8 (-2.0, None) - sage: p.is_variable_integer(5) # optional - Nonexistent_LP_solver + sage: p.is_variable_integer(5) True - sage: p.col_name(5) # optional - Nonexistent_LP_solver + sage: p.col_name(5) 'a' - sage: p.objective_coefficient(5) # tol 1e-8, optional - Nonexistent_LP_solver + sage: p.objective_coefficient(5) # tol 1e-8 42.0 """ cdef int i @@ -215,22 +218,23 @@ cdef class GenericBackend: - ``variable`` (integer) -- the variable's id - - ``vtype`` (integer) : + - ``vtype`` (integer): - * 1 Integer - * 0 Binary - * -1 Continuous + * `1` Integer + * `0` Binary + * `-1` Continuous EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.ncols() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.ncols() 0 - sage: p.add_variable() # optional - Nonexistent_LP_solver + sage: p.add_variable() 0 - sage: p.set_variable_type(0,1) # optional - Nonexistent_LP_solver - sage: p.is_variable_integer(0) # optional - Nonexistent_LP_solver + sage: p.set_variable_type(0,1) + sage: p.is_variable_integer(0) True """ raise NotImplementedError() @@ -248,12 +252,13 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.is_maximization() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.is_maximization() True - sage: p.set_sense(-1) # optional - Nonexistent_LP_solver - sage: p.is_maximization() # optional - Nonexistent_LP_solver + sage: p.set_sense(-1) + sage: p.is_maximization() False """ raise NotImplementedError() @@ -293,14 +298,15 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variable() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variable() 0 - sage: p.objective_coefficient(0) # optional - Nonexistent_LP_solver + sage: p.objective_coefficient(0) 0.0 - sage: p.objective_coefficient(0,2) # optional - Nonexistent_LP_solver - sage: p.objective_coefficient(0) # optional - Nonexistent_LP_solver + sage: p.objective_coefficient(0,2) + sage: p.objective_coefficient(0) 2.0 """ raise NotImplementedError() @@ -315,12 +321,13 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.objective_constant_term() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.objective_constant_term() 0.0 - sage: p.objective_constant_term(42) # optional - Nonexistent_LP_solver - sage: p.objective_constant_term() # optional - Nonexistent_LP_solver + sage: p.objective_constant_term(42) + sage: p.objective_constant_term() 42.0 """ if d is None: @@ -341,23 +348,25 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variables(5) # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variables(5) 4 - sage: p.set_objective([1, 1, 2, 1, 3]) # optional - Nonexistent_LP_solver - sage: [p.objective_coefficient(x) for x in range(5)] # optional - Nonexistent_LP_solver + sage: p.set_objective([1, 1, 2, 1, 3]) + sage: [p.objective_coefficient(x) for x in range(5)] [1.0, 1.0, 2.0, 1.0, 3.0] Constants in the objective function are respected:: - sage: p = MixedIntegerLinearProgram(solver='Nonexistent_LP_solver') # optional - Nonexistent_LP_solver - sage: x,y = p[0], p[1] # optional - Nonexistent_LP_solver - sage: p.add_constraint(2*x + 3*y, max = 6) # optional - Nonexistent_LP_solver - sage: p.add_constraint(3*x + 2*y, max = 6) # optional - Nonexistent_LP_solver - sage: p.set_objective(x + y + 7) # optional - Nonexistent_LP_solver - sage: p.set_integer(x); p.set_integer(y) # optional - Nonexistent_LP_solver - sage: p.solve() # optional - Nonexistent_LP_solver + sage: # optional - nonexistent_lp_solver + sage: p = MixedIntegerLinearProgram(solver='Nonexistent_LP_solver') + sage: x,y = p[0], p[1] + sage: p.add_constraint(2*x + 3*y, max=6) + sage: p.add_constraint(3*x + 2*y, max=6) + sage: p.set_objective(x + y + 7) + sage: p.set_integer(x); p.set_integer(y) + sage: p.solve() 9.0 """ raise NotImplementedError() @@ -373,7 +382,7 @@ cdef class GenericBackend: EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") # optional - Nonexistent_LP_solver sage: p.set_verbosity(2) # optional - Nonexistent_LP_solver """ raise NotImplementedError() @@ -388,19 +397,20 @@ cdef class GenericBackend: EXAMPLES:: - sage: p = MixedIntegerLinearProgram(solver="Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: v = p.new_variable(nonnegative=True) # optional - Nonexistent_LP_solver - sage: x,y = v[0], v[1] # optional - Nonexistent_LP_solver - sage: p.add_constraint(2*x + 3*y, max = 6) # optional - Nonexistent_LP_solver - sage: p.add_constraint(3*x + 2*y, max = 6) # optional - Nonexistent_LP_solver - sage: p.set_objective(x + y + 7) # optional - Nonexistent_LP_solver - sage: p.set_integer(x); p.set_integer(y) # optional - Nonexistent_LP_solver - sage: p.solve() # optional - Nonexistent_LP_solver + sage: # optional - nonexistent_lp_solver + sage: p = MixedIntegerLinearProgram(solver="Nonexistent_LP_solver") + sage: v = p.new_variable(nonnegative=True) + sage: x,y = v[0], v[1] + sage: p.add_constraint(2*x + 3*y, max=6) + sage: p.add_constraint(3*x + 2*y, max=6) + sage: p.set_objective(x + y + 7) + sage: p.set_integer(x); p.set_integer(y) + sage: p.solve() 9.0 - sage: p.remove_constraint(0) # optional - Nonexistent_LP_solver - sage: p.solve() # optional - Nonexistent_LP_solver + sage: p.remove_constraint(0) + sage: p.solve() 10.0 - sage: p.get_values([x,y]) # optional - Nonexistent_LP_solver + sage: p.get_values([x,y]) [0.0, 3.0] """ raise NotImplementedError() @@ -415,13 +425,14 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variables(2) # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variables(2) 1 - sage: p.add_linear_constraint([(0, 2), (1, 3)], None, 6) # optional - Nonexistent_LP_solver - sage: p.add_linear_constraint([(0, 3), (1, 2)], None, 6) # optional - Nonexistent_LP_solver - sage: p.remove_constraints([0, 1]) # optional - Nonexistent_LP_solver + sage: p.add_linear_constraint([(0, 2), (1, 3)], None, 6) + sage: p.add_linear_constraint([(0, 3), (1, 2)], None, 6) + sage: p.remove_constraints([0, 1]) """ if isinstance(constraints, int): self.remove_constraint(constraints) @@ -452,17 +463,18 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variables(5) # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variables(5) 4 - sage: p.add_linear_constraint( zip(range(5), range(5)), 2.0, 2.0) # optional - Nonexistent_LP_solver - sage: p.row(0) # optional - Nonexistent_LP_solver + sage: p.add_linear_constraint( zip(range(5), range(5)), 2.0, 2.0) + sage: p.row(0) ([0, 1, 2, 3, 4], [0.0, 1.0, 2.0, 3.0, 4.0]) - sage: p.row_bounds(0) # optional - Nonexistent_LP_solver + sage: p.row_bounds(0) (2.0, 2.0) - sage: p.add_linear_constraint( zip(range(5), range(5)), 1.0, 1.0, name='foo') # optional - Nonexistent_LP_solver - sage: p.row_name(1) # optional - Nonexistent_LP_solver + sage: p.add_linear_constraint( zip(range(5), range(5)), 1.0, 1.0, name='foo') + sage: p.row_name(1) 'foo' """ raise NotImplementedError('add_linear_constraint') @@ -498,14 +510,15 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") sage: coeffs = ([0, vector([1, 2])], [1, vector([2, 3])]) sage: upper = vector([5, 5]) sage: lower = vector([0, 0]) - sage: p.add_variables(2) # optional - Nonexistent_LP_solver + sage: p.add_variables(2) 1 - sage: p.add_linear_constraint_vector(2, coeffs, lower, upper, 'foo') # optional - Nonexistent_LP_solver + sage: p.add_linear_constraint_vector(2, coeffs, lower, upper, 'foo') """ for d in range(degree): coefficients_d = [] @@ -569,15 +582,16 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.ncols() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.ncols() 0 - sage: p.nrows() # optional - Nonexistent_LP_solver + sage: p.nrows() 0 - sage: p.add_linear_constraints(5, 0, None) # optional - Nonexistent_LP_solver - sage: p.add_col(list(range(5)), list(range(5))) # optional - Nonexistent_LP_solver - sage: p.nrows() # optional - Nonexistent_LP_solver + sage: p.add_linear_constraints(5, 0, None) + sage: p.add_col(list(range(5)), list(range(5))) + sage: p.nrows() 5 """ raise NotImplementedError() @@ -622,14 +636,15 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variables(5) # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variables(5) 5 - sage: p.add_linear_constraints(5, None, 2) # optional - Nonexistent_LP_solver - sage: p.row(4) # optional - Nonexistent_LP_solver + sage: p.add_linear_constraints(5, None, 2) + sage: p.row(4) ([], []) - sage: p.row_bounds(4) # optional - Nonexistent_LP_solver + sage: p.row_bounds(4) (None, 2.0) """ cdef int i @@ -686,14 +701,15 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_linear_constraints(5, 0, None) # optional - Nonexistent_LP_solver - sage: p.add_col(list(range(5)), list(range(5))) # optional - Nonexistent_LP_solver - sage: p.solve() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_linear_constraints(5, 0, None) + sage: p.add_col(list(range(5)), list(range(5))) + sage: p.solve() 0 - sage: p.objective_coefficient(0,1) # optional - Nonexistent_LP_solver - sage: p.solve() # optional - Nonexistent_LP_solver + sage: p.objective_coefficient(0,1) + sage: p.solve() Traceback (most recent call last): ... MIPSolverException: ... @@ -739,19 +755,20 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variables(2) # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variables(2) 1 - sage: p.add_linear_constraint([(0,1), (1,2)], None, 3) # optional - Nonexistent_LP_solver - sage: p.set_objective([2, 5]) # optional - Nonexistent_LP_solver - sage: p.solve() # optional - Nonexistent_LP_solver + sage: p.add_linear_constraint([(0,1), (1,2)], None, 3) + sage: p.set_objective([2, 5]) + sage: p.solve() 0 - sage: p.get_objective_value() # optional - Nonexistent_LP_solver + sage: p.get_objective_value() 7.5 - sage: p.get_variable_value(0) # optional - Nonexistent_LP_solver + sage: p.get_variable_value(0) 0.0 - sage: p.get_variable_value(1) # optional - Nonexistent_LP_solver + sage: p.get_variable_value(1) 1.5 """ @@ -774,17 +791,18 @@ cdef class GenericBackend: EXAMPLES:: - sage: p = MixedIntegerLinearProgram(solver="Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: b = p.new_variable(binary=True) # optional - Nonexistent_LP_solver - sage: for u,v in graphs.CycleGraph(5).edges(labels=False): # optional - Nonexistent_LP_solver + sage: # optional - nonexistent_lp_solver + sage: p = MixedIntegerLinearProgram(solver="Nonexistent_LP_solver") + sage: b = p.new_variable(binary=True) + sage: for u,v in graphs.CycleGraph(5).edges(labels=False): ....: p.add_constraint(b[u]+b[v]<=1) - sage: p.set_objective(p.sum(b[x] for x in range(5))) # optional - Nonexistent_LP_solver - sage: p.solve() # optional - Nonexistent_LP_solver + sage: p.set_objective(p.sum(b[x] for x in range(5))) + sage: p.solve() 2.0 - sage: pb = p.get_backend() # optional - Nonexistent_LP_solver - sage: pb.get_objective_value() # optional - Nonexistent_LP_solver + sage: pb = p.get_backend() + sage: pb.get_objective_value() 2.0 - sage: pb.best_known_objective_bound() # optional - Nonexistent_LP_solver + sage: pb.best_known_objective_bound() 2.0 """ raise NotImplementedError() @@ -809,17 +827,18 @@ cdef class GenericBackend: EXAMPLES:: - sage: p = MixedIntegerLinearProgram(solver="Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: b = p.new_variable(binary=True) # optional - Nonexistent_LP_solver - sage: for u,v in graphs.CycleGraph(5).edges(labels=False): # optional - Nonexistent_LP_solver + sage: # optional - nonexistent_lp_solver + sage: p = MixedIntegerLinearProgram(solver="Nonexistent_LP_solver") + sage: b = p.new_variable(binary=True) + sage: for u,v in graphs.CycleGraph(5).edges(labels=False): ....: p.add_constraint(b[u]+b[v]<=1) - sage: p.set_objective(p.sum(b[x] for x in range(5))) # optional - Nonexistent_LP_solver - sage: p.solve() # optional - Nonexistent_LP_solver + sage: p.set_objective(p.sum(b[x] for x in range(5))) + sage: p.solve() 2.0 - sage: pb = p.get_backend() # optional - Nonexistent_LP_solver - sage: pb.get_objective_value() # optional - Nonexistent_LP_solver + sage: pb = p.get_backend() + sage: pb.get_objective_value() 2.0 - sage: pb.get_relative_objective_gap() # optional - Nonexistent_LP_solver + sage: pb.get_relative_objective_gap() 0.0 """ raise NotImplementedError() @@ -835,19 +854,20 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variables(2) # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variables(2) 1 - sage: p.add_linear_constraint([(0,1), (1, 2)], None, 3) # optional - Nonexistent_LP_solver - sage: p.set_objective([2, 5]) # optional - Nonexistent_LP_solver - sage: p.solve() # optional - Nonexistent_LP_solver + sage: p.add_linear_constraint([(0,1), (1, 2)], None, 3) + sage: p.set_objective([2, 5]) + sage: p.solve() 0 - sage: p.get_objective_value() # optional - Nonexistent_LP_solver + sage: p.get_objective_value() 7.5 - sage: p.get_variable_value(0) # optional - Nonexistent_LP_solver + sage: p.get_variable_value(0) 0.0 - sage: p.get_variable_value(1) # optional - Nonexistent_LP_solver + sage: p.get_variable_value(1) 1.5 """ @@ -859,13 +879,14 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.ncols() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.ncols() 0 - sage: p.add_variables(2) # optional - Nonexistent_LP_solver + sage: p.add_variables(2) 1 - sage: p.ncols() # optional - Nonexistent_LP_solver + sage: p.ncols() 2 """ @@ -885,12 +906,13 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.nrows() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.nrows() 0 - sage: p.add_linear_constraints(2, 2.0, None) # optional - Nonexistent_LP_solver - sage: p.nrows() # optional - Nonexistent_LP_solver + sage: p.add_linear_constraints(2, 2.0, None) + sage: p.nrows() 2 """ @@ -902,12 +924,13 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.is_maximization() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.is_maximization() True - sage: p.set_sense(-1) # optional - Nonexistent_LP_solver - sage: p.is_maximization() # optional - Nonexistent_LP_solver + sage: p.set_sense(-1) + sage: p.is_maximization() False """ raise NotImplementedError() @@ -924,7 +947,7 @@ cdef class GenericBackend: EXAMPLES:: sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") # optional - Nonexistent_LP_solver sage: p.problem_name("There once was a french fry") # optional - Nonexistent_LP_solver sage: print(p.problem_name()) # optional - Nonexistent_LP_solver There once was a french fry @@ -942,14 +965,15 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variables(2) # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variables(2) 2 - sage: p.add_linear_constraint([(0, 1], (1, 2)], None, 3) # optional - Nonexistent_LP_solver - sage: p.set_objective([2, 5]) # optional - Nonexistent_LP_solver - sage: from tempfile import NamedTemporaryFile # optional - Nonexistent_LP_solver - sage: with NamedTemporaryFile(suffix=".lp") as f: # optional - Nonexistent_LP_solver + sage: p.add_linear_constraint([(0, 1], (1, 2)], None, 3) + sage: p.set_objective([2, 5]) + sage: from tempfile import NamedTemporaryFile + sage: with NamedTemporaryFile(suffix=".lp") as f: ....: p.write_lp(f.name) """ raise NotImplementedError() @@ -964,14 +988,15 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variables(2) # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variables(2) 2 - sage: p.add_linear_constraint([(0, 1), (1, 2)], None, 3) # optional - Nonexistent_LP_solver - sage: p.set_objective([2, 5]) # optional - Nonexistent_LP_solver - sage: from tempfile import NamedTemporaryFile # optional - Nonexistent_LP_solver - sage: with NamedTemporaryFile(suffix=".lp") as f: # optional - Nonexistent_LP_solver + sage: p.add_linear_constraint([(0, 1), (1, 2)], None, 3) + sage: p.set_objective([2, 5]) + sage: from tempfile import NamedTemporaryFile + sage: with NamedTemporaryFile(suffix=".lp") as f: ....: p.write_lp(f.name) """ @@ -983,12 +1008,13 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = MixedIntegerLinearProgram(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: b = p.new_variable() # optional - Nonexistent_LP_solver - sage: p.add_constraint(b[1] + b[2] <= 6) # optional - Nonexistent_LP_solver - sage: p.set_objective(b[1] + b[2]) # optional - Nonexistent_LP_solver - sage: copy(p).solve() # optional - Nonexistent_LP_solver + sage: p = MixedIntegerLinearProgram(solver="Nonexistent_LP_solver") + sage: b = p.new_variable() + sage: p.add_constraint(b[1] + b[2] <= 6) + sage: p.set_objective(b[1] + b[2]) + sage: copy(p).solve() 6.0 """ return self.__copy__() @@ -1000,15 +1026,16 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = MixedIntegerLinearProgram(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: b = p.new_variable() # optional - Nonexistent_LP_solver - sage: p.add_constraint(b[1] + b[2] <= 6) # optional - Nonexistent_LP_solver - sage: p.set_objective(b[1] + b[2]) # optional - Nonexistent_LP_solver - sage: cp = copy(p.get_backend()) # optional - Nonexistent_LP_solver - sage: cp.solve() # optional - Nonexistent_LP_solver + sage: p = MixedIntegerLinearProgram(solver="Nonexistent_LP_solver") + sage: b = p.new_variable() + sage: p.add_constraint(b[1] + b[2] <= 6) + sage: p.set_objective(b[1] + b[2]) + sage: cp = copy(p.get_backend()) + sage: cp.solve() 0 - sage: cp.get_objective_value() # optional - Nonexistent_LP_solver + sage: cp.get_objective_value() 6.0 """ raise NotImplementedError() @@ -1019,15 +1046,16 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = MixedIntegerLinearProgram(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: b = p.new_variable() # optional - Nonexistent_LP_solver - sage: p.add_constraint(b[1] + b[2] <= 6) # optional - Nonexistent_LP_solver - sage: p.set_objective(b[1] + b[2]) # optional - Nonexistent_LP_solver - sage: cp = deepcopy(p.get_backend()) # optional - Nonexistent_LP_solver - sage: cp.solve() # optional - Nonexistent_LP_solver + sage: p = MixedIntegerLinearProgram(solver="Nonexistent_LP_solver") + sage: b = p.new_variable() + sage: p.add_constraint(b[1] + b[2] <= 6) + sage: p.set_objective(b[1] + b[2]) + sage: cp = deepcopy(p.get_backend()) + sage: cp.solve() 0 - sage: cp.get_objective_value() # optional - Nonexistent_LP_solver + sage: cp.get_objective_value() 6.0 """ return self.__copy__() @@ -1049,14 +1077,15 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variables(5) # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variables(5) 4 - sage: p.add_linear_constraint(zip(range(5), range(5)), 2, 2) # optional - Nonexistent_LP_solver - sage: p.row(0) # optional - Nonexistent_LP_solver + sage: p.add_linear_constraint(zip(range(5), range(5)), 2, 2) + sage: p.row(0) ([4, 3, 2, 1], [4.0, 3.0, 2.0, 1.0]) ## FIXME: Why backwards? - sage: p.row_bounds(0) # optional - Nonexistent_LP_solver + sage: p.row_bounds(0) (2.0, 2.0) """ raise NotImplementedError() @@ -1077,14 +1106,15 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variables(5) # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variables(5) 4 - sage: p.add_linear_constraint(list(range(5)), list(range(5)), 2, 2) # optional - Nonexistent_LP_solver - sage: p.row(0) # optional - Nonexistent_LP_solver + sage: p.add_linear_constraint(list(range(5)), list(range(5)), 2, 2) + sage: p.row(0) ([4, 3, 2, 1], [4.0, 3.0, 2.0, 1.0]) ## FIXME: Why backwards? - sage: p.row_bounds(0) # optional - Nonexistent_LP_solver + sage: p.row_bounds(0) (2.0, 2.0) """ raise NotImplementedError() @@ -1105,14 +1135,15 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variable() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variable() 0 - sage: p.col_bounds(0) # optional - Nonexistent_LP_solver + sage: p.col_bounds(0) (0.0, None) - sage: p.variable_upper_bound(0, 5) # optional - Nonexistent_LP_solver - sage: p.col_bounds(0) # optional - Nonexistent_LP_solver + sage: p.variable_upper_bound(0, 5) + sage: p.col_bounds(0) (0.0, 5.0) """ raise NotImplementedError() @@ -1127,14 +1158,15 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.ncols() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.ncols() 0 - sage: p.add_variable() # optional - Nonexistent_LP_solver + sage: p.add_variable() 0 - sage: p.set_variable_type(0,0) # optional - Nonexistent_LP_solver - sage: p.is_variable_binary(0) # optional - Nonexistent_LP_solver + sage: p.set_variable_type(0,0) + sage: p.is_variable_binary(0) True """ @@ -1150,14 +1182,15 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.ncols() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.ncols() 0 - sage: p.add_variable() # optional - Nonexistent_LP_solver + sage: p.add_variable() 0 - sage: p.set_variable_type(0,1) # optional - Nonexistent_LP_solver - sage: p.is_variable_integer(0) # optional - Nonexistent_LP_solver + sage: p.set_variable_type(0,1) + sage: p.is_variable_integer(0) True """ raise NotImplementedError() @@ -1172,16 +1205,17 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.ncols() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.ncols() 0 - sage: p.add_variable() # optional - Nonexistent_LP_solver + sage: p.add_variable() 0 - sage: p.is_variable_continuous(0) # optional - Nonexistent_LP_solver + sage: p.is_variable_continuous(0) True - sage: p.set_variable_type(0,1) # optional - Nonexistent_LP_solver - sage: p.is_variable_continuous(0) # optional - Nonexistent_LP_solver + sage: p.set_variable_type(0,1) + sage: p.is_variable_continuous(0) False """ @@ -1197,10 +1231,11 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_linear_constraints(1, 2, None, names=['Empty constraint 1']) # optional - Nonexistent_LP_solver - sage: p.row_name(0) # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_linear_constraints(1, 2, None, names=['Empty constraint 1']) + sage: p.row_name(0) 'Empty constraint 1' """ @@ -1219,11 +1254,12 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variable(name="I am a variable") # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variable(name="I am a variable") 1 - sage: p.col_name(0) # optional - Nonexistent_LP_solver + sage: p.col_name(0) 'I am a variable' """ raise NotImplementedError() @@ -1323,14 +1359,15 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variable() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variable() 0 - sage: p.col_bounds(0) # optional - Nonexistent_LP_solver + sage: p.col_bounds(0) (0.0, None) - sage: p.variable_upper_bound(0, 5) # optional - Nonexistent_LP_solver - sage: p.col_bounds(0) # optional - Nonexistent_LP_solver + sage: p.variable_upper_bound(0, 5) + sage: p.col_bounds(0) (0.0, 5.0) """ raise NotImplementedError() @@ -1349,14 +1386,15 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variable() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variable() 0 - sage: p.col_bounds(0) # optional - Nonexistent_LP_solver + sage: p.col_bounds(0) (0.0, None) - sage: p.variable_lower_bound(0, 5) # optional - Nonexistent_LP_solver - sage: p.col_bounds(0) # optional - Nonexistent_LP_solver + sage: p.variable_lower_bound(0, 5) + sage: p.col_bounds(0) (5.0, None) """ raise NotImplementedError() @@ -1379,11 +1417,12 @@ cdef class GenericBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.solver_parameter("timelimit") # optional - Nonexistent_LP_solver - sage: p.solver_parameter("timelimit", 60) # optional - Nonexistent_LP_solver - sage: p.solver_parameter("timelimit") # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.solver_parameter("timelimit") + sage: p.solver_parameter("timelimit", 60) + sage: p.solver_parameter("timelimit") """ raise NotImplementedError() @@ -1400,19 +1439,20 @@ cdef class GenericBackend: EXAMPLES:: - sage: p = MixedIntegerLinearProgram(maximization=True,\ - solver="Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: x = p.new_variable(nonnegative=True) # optional - Nonexistent_LP_solver - sage: p.add_constraint(-x[0] + x[1] <= 2) # optional - Nonexistent_LP_solver - sage: p.add_constraint(8 * x[0] + 2 * x[1] <= 17) # optional - Nonexistent_LP_solver - sage: p.set_objective(5.5 * x[0] - 3 * x[1]) # optional - Nonexistent_LP_solver - sage: b = p.get_backend() # optional - Nonexistent_LP_solver + sage: # optional - nonexistent_lp_solver + sage: p = MixedIntegerLinearProgram(maximization=True, + ....: solver="Nonexistent_LP_solver") + sage: x = p.new_variable(nonnegative=True) + sage: p.add_constraint(-x[0] + x[1] <= 2) + sage: p.add_constraint(8 * x[0] + 2 * x[1] <= 17) + sage: p.set_objective(5.5 * x[0] - 3 * x[1]) + sage: b = p.get_backend() sage: # Backend-specific commands to instruct solver to use simplex method here - sage: b.solve() # optional - Nonexistent_LP_solver + sage: b.solve() 0 - sage: b.is_variable_basic(0) # optional - Nonexistent_LP_solver + sage: b.is_variable_basic(0) True - sage: b.is_variable_basic(1) # optional - Nonexistent_LP_solver + sage: b.is_variable_basic(1) False """ raise NotImplementedError() @@ -1430,19 +1470,20 @@ cdef class GenericBackend: EXAMPLES:: - sage: p = MixedIntegerLinearProgram(maximization=True,\ - solver="Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: x = p.new_variable(nonnegative=True) # optional - Nonexistent_LP_solver - sage: p.add_constraint(-x[0] + x[1] <= 2) # optional - Nonexistent_LP_solver - sage: p.add_constraint(8 * x[0] + 2 * x[1] <= 17) # optional - Nonexistent_LP_solver - sage: p.set_objective(5.5 * x[0] - 3 * x[1]) # optional - Nonexistent_LP_solver - sage: b = p.get_backend() # optional - Nonexistent_LP_solver + sage: # optional - nonexistent_lp_solver + sage: p = MixedIntegerLinearProgram(maximization=True, + ....: solver="Nonexistent_LP_solver") + sage: x = p.new_variable(nonnegative=True) + sage: p.add_constraint(-x[0] + x[1] <= 2) + sage: p.add_constraint(8 * x[0] + 2 * x[1] <= 17) + sage: p.set_objective(5.5 * x[0] - 3 * x[1]) + sage: b = p.get_backend() sage: # Backend-specific commands to instruct solver to use simplex method here - sage: b.solve() # optional - Nonexistent_LP_solver + sage: b.solve() 0 - sage: b.is_variable_nonbasic_at_lower_bound(0) # optional - Nonexistent_LP_solver + sage: b.is_variable_nonbasic_at_lower_bound(0) False - sage: b.is_variable_nonbasic_at_lower_bound(1) # optional - Nonexistent_LP_solver + sage: b.is_variable_nonbasic_at_lower_bound(1) True """ raise NotImplementedError() @@ -1460,19 +1501,20 @@ cdef class GenericBackend: EXAMPLES:: - sage: p = MixedIntegerLinearProgram(maximization=True,\ - solver="Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: x = p.new_variable(nonnegative=True) # optional - Nonexistent_LP_solver - sage: p.add_constraint(-x[0] + x[1] <= 2) # optional - Nonexistent_LP_solver - sage: p.add_constraint(8 * x[0] + 2 * x[1] <= 17) # optional - Nonexistent_LP_solver - sage: p.set_objective(5.5 * x[0] - 3 * x[1]) # optional - Nonexistent_LP_solver - sage: b = p.get_backend() # optional - Nonexistent_LP_solver + sage: # optional - nonexistent_lp_solver + sage: p = MixedIntegerLinearProgram(maximization=True, + ....: solver="Nonexistent_LP_solver") + sage: x = p.new_variable(nonnegative=True) + sage: p.add_constraint(-x[0] + x[1] <= 2) + sage: p.add_constraint(8 * x[0] + 2 * x[1] <= 17) + sage: p.set_objective(5.5 * x[0] - 3 * x[1]) + sage: b = p.get_backend() sage: # Backend-specific commands to instruct solver to use simplex method here - sage: b.solve() # optional - Nonexistent_LP_solver + sage: b.solve() 0 - sage: b.is_slack_variable_basic(0) # optional - Nonexistent_LP_solver + sage: b.is_slack_variable_basic(0) True - sage: b.is_slack_variable_basic(1) # optional - Nonexistent_LP_solver + sage: b.is_slack_variable_basic(1) False """ raise NotImplementedError() @@ -1490,19 +1532,20 @@ cdef class GenericBackend: EXAMPLES:: - sage: p = MixedIntegerLinearProgram(maximization=True,\ - solver="Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: x = p.new_variable(nonnegative=True) # optional - Nonexistent_LP_solver - sage: p.add_constraint(-x[0] + x[1] <= 2) # optional - Nonexistent_LP_solver - sage: p.add_constraint(8 * x[0] + 2 * x[1] <= 17) # optional - Nonexistent_LP_solver - sage: p.set_objective(5.5 * x[0] - 3 * x[1]) # optional - Nonexistent_LP_solver - sage: b = p.get_backend() # optional - Nonexistent_LP_solver + sage: # optional - nonexistent_lp_solver + sage: p = MixedIntegerLinearProgram(maximization=True, + ....: solver="Nonexistent_LP_solver") + sage: x = p.new_variable(nonnegative=True) + sage: p.add_constraint(-x[0] + x[1] <= 2) + sage: p.add_constraint(8 * x[0] + 2 * x[1] <= 17) + sage: p.set_objective(5.5 * x[0] - 3 * x[1]) + sage: b = p.get_backend() sage: # Backend-specific commands to instruct solver to use simplex method here - sage: b.solve() # optional - Nonexistent_LP_solver + sage: b.solve() 0 - sage: b.is_slack_variable_nonbasic_at_lower_bound(0) # optional - Nonexistent_LP_solver + sage: b.is_slack_variable_nonbasic_at_lower_bound(0) False - sage: b.is_slack_variable_nonbasic_at_lower_bound(1) # optional - Nonexistent_LP_solver + sage: b.is_slack_variable_nonbasic_at_lower_bound(1) True """ raise NotImplementedError() @@ -1552,20 +1595,20 @@ def default_mip_solver(solver=None): - ``solver`` -- one of the following: - - a string indicating one of the available solvers - (see :class:`MixedIntegerLinearProgram`); + - a string indicating one of the available solvers + (see :class:`MixedIntegerLinearProgram`); - - a callable (typically a subclass of - :class:`sage.numerical.backends.generic_backend.GenericBackend`); + - a callable (typically a subclass of + :class:`sage.numerical.backends.generic_backend.GenericBackend`); - - ``None`` (default), in which case the current default solver - is returned; this is either a string or a callable. + - ``None`` (default), in which case the current default solver + is returned; this is either a string or a callable. OUTPUT: This function returns the current default solver's name if ``solver = None`` (default). Otherwise, it sets the default solver to the one given. If this - solver does not exist, or is not available, a ``ValueError`` exception is + solver does not exist, or is not available, a :class:`ValueError` exception is raised. EXAMPLES:: @@ -1677,7 +1720,8 @@ def default_mip_solver(solver=None): else: raise ValueError("'solver' should be set to 'GLPK', 'Coin', 'CPLEX', 'CVXOPT', 'CVXPY', 'Gurobi', 'PPL', 'SCIP', 'InteractiveLP', a callable, or None.") -cpdef GenericBackend get_solver(constraint_generation = False, solver = None, base_ring = None) noexcept: + +cpdef GenericBackend get_solver(constraint_generation=False, solver=None, base_ring=None) noexcept: """ Return a solver according to the given preferences @@ -1685,22 +1729,22 @@ cpdef GenericBackend get_solver(constraint_generation = False, solver = None, ba - ``solver`` -- one of the following: - - a string indicating one of the available solvers - (see :class:`MixedIntegerLinearProgram`); + - a string indicating one of the available solvers + (see :class:`MixedIntegerLinearProgram`); - - ``None`` (default), in which case the default solver is used - (see :func:`default_mip_solver`); + - ``None`` (default), in which case the default solver is used + (see :func:`default_mip_solver`); - - or a callable (such as a class), in which case it is called, - and its result is returned. + - or a callable (such as a class), in which case it is called, + and its result is returned. - ``base_ring`` -- If not ``None``, request a solver that works over this - (ordered) field. If ``base_ring`` is not a field, its fraction field - is used. + (ordered) field. If ``base_ring`` is not a field, its fraction field + is used. - For example, is ``base_ring=ZZ`` is provided, the solver will work over - the rational numbers. This is unrelated to whether variables are - constrained to be integers or not. + For example, is ``base_ring=ZZ`` is provided, the solver will work over + the rational numbers. This is unrelated to whether variables are + constrained to be integers or not. - ``constraint_generation`` -- Only used when ``solver=None``. @@ -1728,21 +1772,23 @@ cpdef GenericBackend get_solver(constraint_generation = False, solver = None, ba <...sage.numerical.backends.ppl_backend.PPLBackend...> sage: p.base_ring() Rational Field - sage: p = get_solver(base_ring=AA); p # optional - sage.rings.number_field + sage: p = get_solver(base_ring=AA); p # needs sage.rings.number_field <...sage.numerical.backends.interactivelp_backend.InteractiveLPBackend...> - sage: p.base_ring() # optional - sage.rings.number_field + sage: p.base_ring() # needs sage.rings.number_field Algebraic Real Field - sage: d = polytopes.dodecahedron() # optional - sage.rings.number_field - sage: p = get_solver(base_ring=d.base_ring()); p # optional - sage.rings.number_field + + sage: # needs sage.groups sage.rings.number_field + sage: d = polytopes.dodecahedron() + sage: p = get_solver(base_ring=d.base_ring()); p <...sage.numerical.backends.interactivelp_backend.InteractiveLPBackend...> - sage: p.base_ring() # optional - sage.rings.number_field + sage: p.base_ring() Number Field in sqrt5 with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790? - sage: p = get_solver(solver='InteractiveLP', base_ring=QQ); p # optional - sage.rings.number_field + sage: p = get_solver(solver='InteractiveLP', base_ring=QQ); p <...sage.numerical.backends.interactivelp_backend.InteractiveLPBackend...> - sage: p.base_ring() # optional - sage.rings.number_field + sage: p.base_ring() Rational Field - Passing a callable as the 'solver':: + Passing a callable as the ``solver``:: sage: from sage.numerical.backends.glpk_backend import GLPKBackend sage: p = get_solver(solver=GLPKBackend); p diff --git a/src/sage/numerical/backends/generic_sdp_backend.pyx b/src/sage/numerical/backends/generic_sdp_backend.pyx index bad0e3511e2..45bfde5f89b 100644 --- a/src/sage/numerical/backends/generic_sdp_backend.pyx +++ b/src/sage/numerical/backends/generic_sdp_backend.pyx @@ -71,19 +71,20 @@ cdef class GenericSDPBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_sdp_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.ncols() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.ncols() 0 - sage: p.add_variable() # optional - Nonexistent_LP_solver + sage: p.add_variable() 0 - sage: p.ncols() # optional - Nonexistent_LP_solver + sage: p.ncols() 1 - sage: p.add_variable(name='x',obj=1.0) # optional - Nonexistent_LP_solver + sage: p.add_variable(name='x', obj=1.0) 3 - sage: p.col_name(3) # optional - Nonexistent_LP_solver + sage: p.col_name(3) 'x' - sage: p.objective_coefficient(3) # optional - Nonexistent_LP_solver + sage: p.objective_coefficient(3) 1.0 """ raise NotImplementedError() @@ -107,15 +108,16 @@ cdef class GenericSDPBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_sdp_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.ncols() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.ncols() 0 - sage: p.add_variables(5) # optional - Nonexistent_LP_solver + sage: p.add_variables(5) 4 - sage: p.ncols() # optional - Nonexistent_LP_solver + sage: p.ncols() 5 - sage: p.add_variables(2, lower_bound=-2.0, integer=True, names=['a','b']) # optional - Nonexistent_LP_solver + sage: p.add_variables(2, lower_bound=-2.0, integer=True, names=['a','b']) 6 """ raise NotImplementedError() @@ -126,19 +128,20 @@ cdef class GenericSDPBackend: INPUT: - - ``sense`` (integer) : + - ``sense`` (integer): - * +1 => Maximization - * -1 => Minimization + * `+1` => Maximization + * `-1` => Minimization EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_sdp_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.is_maximization() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.is_maximization() True - sage: p.set_sense(-1) # optional - Nonexistent_LP_solver - sage: p.is_maximization() # optional - Nonexistent_LP_solver + sage: p.set_sense(-1) + sage: p.is_maximization() False """ raise NotImplementedError() @@ -156,14 +159,15 @@ cdef class GenericSDPBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_sdp_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variable() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variable() 1 - sage: p.objective_coefficient(0) # optional - Nonexistent_LP_solver + sage: p.objective_coefficient(0) 0.0 - sage: p.objective_coefficient(0,2) # optional - Nonexistent_LP_solver - sage: p.objective_coefficient(0) # optional - Nonexistent_LP_solver + sage: p.objective_coefficient(0,2) + sage: p.objective_coefficient(0) 2.0 """ raise NotImplementedError() @@ -181,12 +185,13 @@ cdef class GenericSDPBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_sdp_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variables(5) # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variables(5) 5 - sage: p.set_objective([1, 1, 2, 1, 3]) # optional - Nonexistent_LP_solver - sage: [p.objective_coefficient(x) for x in range(5)] # optional - Nonexistent_LP_solver + sage: p.set_objective([1, 1, 2, 1, 3]) + sage: [p.objective_coefficient(x) for x in range(5)] [1.0, 1.0, 2.0, 1.0, 3.0] Constants in the objective function are respected. @@ -212,17 +217,18 @@ cdef class GenericSDPBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_sdp_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variables(5) # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variables(5) 4 - sage: p.add_linear_constraint(zip(range(5), range(5)), 2.0, 2.0) # optional - Nonexistent_LP_solver - sage: p.row(0) # optional - Nonexistent_LP_solver + sage: p.add_linear_constraint(zip(range(5), range(5)), 2.0, 2.0) + sage: p.row(0) ([4, 3, 2, 1], [4.0, 3.0, 2.0, 1.0]) # optional - Nonexistent_LP_solver - sage: p.row_bounds(0) # optional - Nonexistent_LP_solver + sage: p.row_bounds(0) (2.0, 2.0) - sage: p.add_linear_constraint( zip(range(5), range(5)), 1.0, 1.0, name='foo') # optional - Nonexistent_LP_solver - sage: p.row_name(-1) # optional - Nonexistent_LP_solver + sage: p.add_linear_constraint( zip(range(5), range(5)), 1.0, 1.0, name='foo') + sage: p.row_name(-1) "foo" """ raise NotImplementedError() @@ -244,14 +250,15 @@ cdef class GenericSDPBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_sdp_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variables(5) # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variables(5) 5 - sage: p.add_linear_constraints(5, None, 2) # optional - Nonexistent_LP_solver - sage: p.row(4) # optional - Nonexistent_LP_solver + sage: p.add_linear_constraints(5, None, 2) + sage: p.row(4) ([], []) - sage: p.row_bounds(4) # optional - Nonexistent_LP_solver + sage: p.row_bounds(4) (None, 2.0) """ raise NotImplementedError() @@ -262,20 +269,21 @@ cdef class GenericSDPBackend: .. NOTE:: - This method raises ``SDPSolverException`` exceptions when + This method raises :class:`SDPSolverException` exceptions when the solution cannot be computed for any reason (none exists, or the LP solver was not able to find it, etc...) EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_sdp_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_linear_constraints(5, 0, None) # optional - Nonexistent_LP_solver - sage: p.add_col(range(5), range(5)) # optional - Nonexistent_LP_solver - sage: p.solve() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_linear_constraints(5, 0, None) + sage: p.add_col(range(5), range(5)) + sage: p.solve() 0 - sage: p.objective_coefficient(0,1) # optional - Nonexistent_LP_solver - sage: p.solve() # optional - Nonexistent_LP_solver + sage: p.objective_coefficient(0,1) + sage: p.solve() Traceback (most recent call last): ... SDPSolverException: ... @@ -292,22 +300,22 @@ cdef class GenericSDPBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_sdp_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variables(2) # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variables(2) 2 - sage: p.add_linear_constraint([(0,1), (1,2)], None, 3) # optional - Nonexistent_LP_solver - sage: p.set_objective([2, 5]) # optional - Nonexistent_LP_solver - sage: p.solve() # optional - Nonexistent_LP_solver + sage: p.add_linear_constraint([(0,1), (1,2)], None, 3) + sage: p.set_objective([2, 5]) + sage: p.solve() 0 - sage: p.get_objective_value() # optional - Nonexistent_LP_solver + sage: p.get_objective_value() 7.5 - sage: p.get_variable_value(0) # optional - Nonexistent_LP_solver + sage: p.get_variable_value(0) 0.0 - sage: p.get_variable_value(1) # optional - Nonexistent_LP_solver + sage: p.get_variable_value(1) 1.5 """ - raise NotImplementedError() cpdef get_variable_value(self, int variable) noexcept: @@ -320,19 +328,20 @@ cdef class GenericSDPBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_sdp_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variables(2) # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variables(2) 2 - sage: p.add_linear_constraint([(0,1), (1, 2)], None, 3) # optional - Nonexistent_LP_solver - sage: p.set_objective([2, 5]) # optional - Nonexistent_LP_solver - sage: p.solve() # optional - Nonexistent_LP_solver + sage: p.add_linear_constraint([(0,1), (1, 2)], None, 3) + sage: p.set_objective([2, 5]) + sage: p.solve() 0 - sage: p.get_objective_value() # optional - Nonexistent_LP_solver + sage: p.get_objective_value() 7.5 - sage: p.get_variable_value(0) # optional - Nonexistent_LP_solver + sage: p.get_variable_value(0) 0.0 - sage: p.get_variable_value(1) # optional - Nonexistent_LP_solver + sage: p.get_variable_value(1) 1.5 """ @@ -344,13 +353,14 @@ cdef class GenericSDPBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_sdp_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.ncols() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.ncols() 0 - sage: p.add_variables(2) # optional - Nonexistent_LP_solver + sage: p.add_variables(2) 2 - sage: p.ncols() # optional - Nonexistent_LP_solver + sage: p.ncols() 2 """ @@ -362,15 +372,15 @@ cdef class GenericSDPBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_sdp_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.nrows() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.nrows() 0 - sage: p.add_linear_constraints(2, 2.0, None) # optional - Nonexistent_LP_solver - sage: p.nrows() # optional - Nonexistent_LP_solver + sage: p.add_linear_constraints(2, 2.0, None) + sage: p.nrows() 2 """ - raise NotImplementedError() cpdef bint is_maximization(self) noexcept: @@ -379,12 +389,13 @@ cdef class GenericSDPBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_sdp_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.is_maximization() # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.is_maximization() True - sage: p.set_sense(-1) # optional - Nonexistent_LP_solver - sage: p.is_maximization() # optional - Nonexistent_LP_solver + sage: p.set_sense(-1) + sage: p.is_maximization() False """ raise NotImplementedError() @@ -400,10 +411,11 @@ cdef class GenericSDPBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_sdp_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.problem_name("There once was a french fry") # optional - Nonexistent_LP_solver - sage: print(p.problem_name()) # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.problem_name("There once was a french fry") + sage: print(p.problem_name()) There once was a french fry """ @@ -426,20 +438,19 @@ cdef class GenericSDPBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_sdp_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variables(5) # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variables(5) 5 - sage: p.add_linear_constraint(zip(range(5), range(5)), 2, 2) # optional - Nonexistent_LP_solver - sage: p.row(0) # optional - Nonexistent_LP_solver + sage: p.add_linear_constraint(zip(range(5), range(5)), 2, 2) + sage: p.row(0) ([4, 3, 2, 1], [4.0, 3.0, 2.0, 1.0]) - sage: p.row_bounds(0) # optional - Nonexistent_LP_solver + sage: p.row_bounds(0) (2.0, 2.0) """ raise NotImplementedError() - - cpdef row_name(self, int index) noexcept: """ Return the ``index`` th row name @@ -450,10 +461,11 @@ cdef class GenericSDPBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_sdp_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_linear_constraints(1, 2, None, name="Empty constraint 1") # optional - Nonexistent_LP_solver - sage: p.row_name(0) # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_linear_constraints(1, 2, None, name="Empty constraint 1") + sage: p.row_name(0) 'Empty constraint 1' """ @@ -472,11 +484,12 @@ cdef class GenericSDPBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_sdp_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.add_variable(name="I am a variable") # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.add_variable(name="I am a variable") 1 - sage: p.col_name(0) # optional - Nonexistent_LP_solver + sage: p.col_name(0) 'I am a variable' """ raise NotImplementedError() @@ -495,24 +508,25 @@ cdef class GenericSDPBackend: EXAMPLES:: - sage: p = SemidefiniteProgram(maximization = False,solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: x = p.new_variable() # optional - Nonexistent_LP_solver - sage: p.set_objective(x[0] - x[1]) # optional - Nonexistent_LP_solver - sage: a1 = matrix([[1, 2.], [2., 3.]]) # optional - Nonexistent_LP_solver - sage: a2 = matrix([[3, 4.], [4., 5.]]) # optional - Nonexistent_LP_solver - sage: a3 = matrix([[5, 6.], [6., 7.]]) # optional - Nonexistent_LP_solver - sage: b1 = matrix([[1, 1.], [1., 1.]]) # optional - Nonexistent_LP_solver - sage: b2 = matrix([[2, 2.], [2., 2.]]) # optional - Nonexistent_LP_solver - sage: b3 = matrix([[3, 3.], [3., 3.]]) # optional - Nonexistent_LP_solver - sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) # optional - Nonexistent_LP_solver - sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) # optional - Nonexistent_LP_solver - sage: p.solve() # optional - Nonexistent_LP_solver # tol ??? + sage: # optional - nonexistent_lp_solver + sage: p = SemidefiniteProgram(maximization=False, solver="Nonexistent_LP_solver") + sage: x = p.new_variable() + sage: p.set_objective(x[0] - x[1]) + sage: a1 = matrix([[1, 2.], [2., 3.]]) + sage: a2 = matrix([[3, 4.], [4., 5.]]) + sage: a3 = matrix([[5, 6.], [6., 7.]]) + sage: b1 = matrix([[1, 1.], [1., 1.]]) + sage: b2 = matrix([[2, 2.], [2., 2.]]) + sage: b3 = matrix([[3, 3.], [3., 3.]]) + sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) + sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) + sage: p.solve() -3.0 - sage: B=p.get_backend() # optional - Nonexistent_LP_solver - sage: x=p.get_values(x).values() # optional - Nonexistent_LP_solver - sage: -(a3*B.dual_variable(0)).trace()-(b3*B.dual_variable(1)).trace() # optional - Nonexistent_LP_solver # tol ??? + sage: B = p.get_backend() + sage: x = p.get_values(x).values() + sage: -(a3*B.dual_variable(0)).trace()-(b3*B.dual_variable(1)).trace() -3.0 - sage: g = sum((B.slack(j)*B.dual_variable(j)).trace() for j in range(2)); g # optional - Nonexistent_LP_solver # tol ??? + sage: g = sum((B.slack(j)*B.dual_variable(j)).trace() for j in range(2)); g 0.0 TESTS:: @@ -541,27 +555,28 @@ cdef class GenericSDPBackend: EXAMPLES:: - sage: p = SemidefiniteProgram(maximization = False,solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: x = p.new_variable() # optional - Nonexistent_LP_solver - sage: p.set_objective(x[0] - x[1]) # optional - Nonexistent_LP_solver - sage: a1 = matrix([[1, 2.], [2., 3.]]) # optional - Nonexistent_LP_solver - sage: a2 = matrix([[3, 4.], [4., 5.]]) # optional - Nonexistent_LP_solver - sage: a3 = matrix([[5, 6.], [6., 7.]]) # optional - Nonexistent_LP_solver - sage: b1 = matrix([[1, 1.], [1., 1.]]) # optional - Nonexistent_LP_solver - sage: b2 = matrix([[2, 2.], [2., 2.]]) # optional - Nonexistent_LP_solver - sage: b3 = matrix([[3, 3.], [3., 3.]]) # optional - Nonexistent_LP_solver - sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) # optional - Nonexistent_LP_solver - sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) # optional - Nonexistent_LP_solver - sage: p.solve() # optional - Nonexistent_LP_solver # tol ??? + sage: # optional - nonexistent_lp_solver + sage: p = SemidefiniteProgram(maximization=False, solver="Nonexistent_LP_solver") + sage: x = p.new_variable() + sage: p.set_objective(x[0] - x[1]) + sage: a1 = matrix([[1, 2.], [2., 3.]]) + sage: a2 = matrix([[3, 4.], [4., 5.]]) + sage: a3 = matrix([[5, 6.], [6., 7.]]) + sage: b1 = matrix([[1, 1.], [1., 1.]]) + sage: b2 = matrix([[2, 2.], [2., 2.]]) + sage: b3 = matrix([[3, 3.], [3., 3.]]) + sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) + sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) + sage: p.solve() -3.0 - sage: B=p.get_backend() # optional - Nonexistent_LP_solver - sage: B1 = B.slack(1); B1 # optional - Nonexistent_LP_solver # tol ??? + sage: B = p.get_backend() + sage: B1 = B.slack(1); B1 [0.0 0.0] [0.0 0.0] - sage: B1.is_positive_definite() # optional - Nonexistent_LP_solver + sage: B1.is_positive_definite() True - sage: x = p.get_values(x).values() # optional - Nonexistent_LP_solver - sage: x[0]*b1 + x[1]*b2 - b3 + B1 # optional - Nonexistent_LP_solver # tol ??? + sage: x = p.get_values(x).values() + sage: x[0]*b1 + x[1]*b2 - b3 + B1 [0.0 0.0] [0.0 0.0] @@ -593,11 +608,12 @@ cdef class GenericSDPBackend: EXAMPLES:: + sage: # optional - nonexistent_lp_solver sage: from sage.numerical.backends.generic_sdp_backend import get_solver - sage: p = get_solver(solver = "Nonexistent_LP_solver") # optional - Nonexistent_LP_solver - sage: p.solver_parameter("timelimit") # optional - Nonexistent_LP_solver - sage: p.solver_parameter("timelimit", 60) # optional - Nonexistent_LP_solver - sage: p.solver_parameter("timelimit") # optional - Nonexistent_LP_solver + sage: p = get_solver(solver="Nonexistent_LP_solver") + sage: p.solver_parameter("timelimit") + sage: p.solver_parameter("timelimit", 60) + sage: p.solver_parameter("timelimit") """ raise NotImplementedError() @@ -613,15 +629,15 @@ def default_sdp_solver(solver=None): - ``solver`` -- one of the following: - - the string ``"CVXOPT"``, to make the use of the CVXOPT solver - (see the `CVXOPT `_ web site) the default; + - the string ``"CVXOPT"``, to make the use of the CVXOPT solver + (see the `CVXOPT `_ web site) the default; - - a subclass of - :class:`sage.numerical.backends.generic_sdp_backend.GenericSDPBackend`, - to make it the default; or + - a subclass of + :class:`sage.numerical.backends.generic_sdp_backend.GenericSDPBackend`, + to make it the default; or - - ``None`` (default), in which case the current default solver - (a string or a class) is returned. + - ``None`` (default), in which case the current default solver + (a string or a class) is returned. OUTPUT: @@ -694,14 +710,14 @@ cpdef GenericSDPBackend get_solver(solver=None, base_ring=None) noexcept: - ``solver`` -- one of the following: - - the string ``"CVXOPT"``, designating the use of the CVXOPT solver - (see the `CVXOPT `_ web site); + - the string ``"CVXOPT"``, designating the use of the CVXOPT solver + (see the `CVXOPT `_ web site); - - a subclass of - :class:`sage.numerical.backends.generic_sdp_backend.GenericSDPBackend`; + - a subclass of + :class:`sage.numerical.backends.generic_sdp_backend.GenericSDPBackend`; - - ``None`` (default), in which case the default solver is used (see - :func:`default_sdp_solver`); + - ``None`` (default), in which case the default solver is used (see + :func:`default_sdp_solver`); .. SEEALSO:: diff --git a/src/sage/numerical/backends/glpk_backend.pxd b/src/sage/numerical/backends/glpk_backend.pxd index 064c69cac18..4ff1d4a8d76 100644 --- a/src/sage/numerical/backends/glpk_backend.pxd +++ b/src/sage/numerical/backends/glpk_backend.pxd @@ -9,7 +9,7 @@ #***************************************************************************** from sage.libs.glpk.types cimport glp_prob, glp_iocp, glp_smcp -from .generic_backend cimport GenericBackend +from sage.numerical.backends.generic_backend cimport GenericBackend # search_tree_data_t: diff --git a/src/sage/numerical/backends/glpk_backend.pyx b/src/sage/numerical/backends/glpk_backend.pyx index 0fa5c2d3b98..77cab0ff1b5 100644 --- a/src/sage/numerical/backends/glpk_backend.pyx +++ b/src/sage/numerical/backends/glpk_backend.pyx @@ -1097,6 +1097,7 @@ cdef class GLPKBackend(GenericBackend): the result is not optimal. To do this, we try to compute the maximum number of disjoint balls (of diameter 1) in a hypercube:: + sage: # needs sage.graphs sage: g = graphs.CubeGraph(9) sage: p = MixedIntegerLinearProgram(solver="GLPK") sage: p.solver_parameter("mip_gap_tolerance",100) @@ -1110,6 +1111,7 @@ cdef class GLPKBackend(GenericBackend): Same, now with a time limit:: + sage: # needs sage.graphs sage: p.solver_parameter("mip_gap_tolerance",1) sage: p.solver_parameter("timelimit",3.0) sage: p.solve() # rel tol 100 @@ -1197,6 +1199,7 @@ cdef class GLPKBackend(GenericBackend): EXAMPLES:: + sage: # needs sage.graphs sage: g = graphs.CubeGraph(9) sage: p = MixedIntegerLinearProgram(solver="GLPK") sage: p.solver_parameter("mip_gap_tolerance",100) @@ -1231,6 +1234,7 @@ cdef class GLPKBackend(GenericBackend): EXAMPLES:: + sage: # needs sage.graphs sage: g = graphs.CubeGraph(9) sage: p = MixedIntegerLinearProgram(solver="GLPK") sage: p.solver_parameter("mip_gap_tolerance",100) @@ -1250,7 +1254,7 @@ cdef class GLPKBackend(GenericBackend): Just make sure that the variable *has* been defined, and is not just undefined:: - sage: backend.get_relative_objective_gap() > 1 + sage: backend.get_relative_objective_gap() > 1 # needs sage.graphs True """ return self.search_tree_data.mip_gap diff --git a/src/sage/numerical/backends/glpk_exact_backend.pxd b/src/sage/numerical/backends/glpk_exact_backend.pxd index 40489d2ac94..89326bf3604 100644 --- a/src/sage/numerical/backends/glpk_exact_backend.pxd +++ b/src/sage/numerical/backends/glpk_exact_backend.pxd @@ -8,7 +8,7 @@ # http://www.gnu.org/licenses/ #***************************************************************************** -from .glpk_backend cimport GLPKBackend +from sage.numerical.backends.glpk_backend cimport GLPKBackend cdef class GLPKExactBackend(GLPKBackend): cpdef int add_variable(self, lower_bound=*, upper_bound=*, binary=*, continuous=*, integer=*, obj=*, name=*) except -1 diff --git a/src/sage/numerical/backends/glpk_graph_backend.pyx b/src/sage/numerical/backends/glpk_graph_backend.pyx index dcc6425d8de..90431f8a481 100644 --- a/src/sage/numerical/backends/glpk_graph_backend.pyx +++ b/src/sage/numerical/backends/glpk_graph_backend.pyx @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.graphs """ GLPK Backend for access to GLPK graph functions diff --git a/src/sage/numerical/backends/interactivelp_backend.pyx b/src/sage/numerical/backends/interactivelp_backend.pyx index 665631f19de..3062a29eb1f 100644 --- a/src/sage/numerical/backends/interactivelp_backend.pyx +++ b/src/sage/numerical/backends/interactivelp_backend.pyx @@ -53,17 +53,18 @@ cdef class InteractiveLPBackend: This backend can work with irrational algebraic numbers:: - sage: poly = polytopes.dodecahedron(base_ring=AA) # optional - sage.rings.number_field - sage: lp, x = poly.to_linear_program(solver='InteractiveLP', return_variable=True) # optional - sage.rings.number_field - sage: lp.set_objective(x[0] + x[1] + x[2]) # optional - sage.rings.number_field - sage: lp.solve() # optional - sage.rings.number_field + sage: # needs sage.rings.number_field + sage: poly = polytopes.dodecahedron(base_ring=AA) + sage: lp, x = poly.to_linear_program(solver='InteractiveLP', return_variable=True) + sage: lp.set_objective(x[0] + x[1] + x[2]) + sage: lp.solve() 2.291796067500631? - sage: lp.get_values(x[0], x[1], x[2]) # optional - sage.rings.number_field + sage: lp.get_values(x[0], x[1], x[2]) [0.763932022500211?, 0.763932022500211?, 0.763932022500211?] - sage: lp.set_objective(x[0] - x[1] - x[2]) # optional - sage.rings.number_field - sage: lp.solve() # optional - sage.rings.number_field + sage: lp.set_objective(x[0] - x[1] - x[2]) + sage: lp.solve() 2.291796067500631? - sage: lp.get_values(x[0], x[1], x[2]) # optional - sage.rings.number_field + sage: lp.get_values(x[0], x[1], x[2]) [0.763932022500211?, -0.763932022500211?, -0.763932022500211?] """ diff --git a/src/sage/numerical/backends/matrix_sdp_backend.pxd b/src/sage/numerical/backends/matrix_sdp_backend.pxd index 4ebbf01a16d..9038955f83a 100644 --- a/src/sage/numerical/backends/matrix_sdp_backend.pxd +++ b/src/sage/numerical/backends/matrix_sdp_backend.pxd @@ -1,4 +1,5 @@ -from .generic_sdp_backend cimport GenericSDPBackend +from sage.numerical.backends.generic_sdp_backend cimport GenericSDPBackend + cdef class MatrixSDPBackend(GenericSDPBackend): diff --git a/src/sage/numerical/backends/matrix_sdp_backend.pyx b/src/sage/numerical/backends/matrix_sdp_backend.pyx index 7704ff91c90..631a7bd6dde 100644 --- a/src/sage/numerical/backends/matrix_sdp_backend.pyx +++ b/src/sage/numerical/backends/matrix_sdp_backend.pyx @@ -21,7 +21,7 @@ other classes implementing solvers. #***************************************************************************** from sage.matrix.constructor import Matrix -from .generic_sdp_backend cimport GenericSDPBackend +from sage.numerical.backends.generic_sdp_backend cimport GenericSDPBackend cdef class MatrixSDPBackend(GenericSDPBackend): diff --git a/src/sage/numerical/backends/ppl_backend.pyx b/src/sage/numerical/backends/ppl_backend.pyx index f437527e42c..0de85409c94 100644 --- a/src/sage/numerical/backends/ppl_backend.pyx +++ b/src/sage/numerical/backends/ppl_backend.pyx @@ -1,3 +1,4 @@ +# sage.doctest: optional - pplpy """ PPL Backend @@ -23,7 +24,7 @@ from sage.numerical.mip import MIPSolverException from ppl import MIP_Problem, Variable, Variables_Set, Linear_Expression from sage.rings.integer cimport Integer from sage.rings.rational cimport Rational -from .generic_backend cimport GenericBackend +from sage.numerical.backends.generic_backend cimport GenericBackend from copy import copy @@ -61,7 +62,7 @@ cdef class PPLBackend(GenericBackend): Raise an error if a ``base_ring`` is requested that is not supported:: - sage: p = MixedIntegerLinearProgram(solver = "PPL", base_ring=AA) + sage: p = MixedIntegerLinearProgram(solver="PPL", base_ring=AA) # needs sage.rings.number_field Traceback (most recent call last): ... TypeError: The PPL backend only supports rational data. diff --git a/src/sage/numerical/backends/scip_backend.pxd b/src/sage/numerical/backends/scip_backend.pxd index c7a7c4d780c..93f1b81ab96 100644 --- a/src/sage/numerical/backends/scip_backend.pxd +++ b/src/sage/numerical/backends/scip_backend.pxd @@ -8,7 +8,7 @@ # http://www.gnu.org/licenses/ #***************************************************************************** -from .generic_backend cimport GenericBackend +from sage.numerical.backends.generic_backend cimport GenericBackend cdef class SCIPBackend(GenericBackend): diff --git a/src/sage/numerical/gauss_legendre.pyx b/src/sage/numerical/gauss_legendre.pyx index 269727c1fdd..81bb5f36af5 100644 --- a/src/sage/numerical/gauss_legendre.pyx +++ b/src/sage/numerical/gauss_legendre.pyx @@ -79,11 +79,11 @@ def nodes_uncached(degree, prec): sage: from sage.numerical.gauss_legendre import nodes_uncached sage: L1 = nodes_uncached(24, 53) - sage: P = RR['x'](sage.functions.orthogonal_polys.legendre_P(24, x)) - sage: Pdif = P.diff() - sage: L2 = [((r + 1)/2, 1/(1 - r^2)/Pdif(r)^2) + sage: P = RR['x'](sage.functions.orthogonal_polys.legendre_P(24, x)) # needs sage.symbolic + sage: Pdif = P.diff() # needs sage.symbolic + sage: L2 = [((r + 1)/2, 1/(1 - r^2)/Pdif(r)^2) # needs sage.symbolic ....: for r, _ in RR['x'](P).roots()] - sage: all((a[0] - b[0]).abs() < 1e-15 and (a[1] - b[1]).abs() < 1e-9 + sage: all((a[0] - b[0]).abs() < 1e-15 and (a[1] - b[1]).abs() < 1e-9 # needs sage.symbolic ....: for a, b in zip(L1, L2)) True @@ -188,11 +188,11 @@ def nodes(degree, prec): sage: from sage.numerical.gauss_legendre import nodes sage: L1 = nodes(24, 53) - sage: P = RR['x'](sage.functions.orthogonal_polys.legendre_P(24, x)) - sage: Pdif = P.diff() - sage: L2 = [((r + 1)/2, 1/(1 - r^2)/Pdif(r)^2) + sage: P = RR['x'](sage.functions.orthogonal_polys.legendre_P(24, x)) # needs sage.symbolic + sage: Pdif = P.diff() # needs sage.symbolic + sage: L2 = [((r + 1)/2, 1/(1 - r^2)/Pdif(r)^2) # needs sage.symbolic ....: for r, _ in RR['x'](P).roots()] - sage: all((a[0] - b[0]).abs() < 1e-15 and (a[1] - b[1]).abs() < 1e-9 + sage: all((a[0] - b[0]).abs() < 1e-15 and (a[1] - b[1]).abs() < 1e-9 # needs sage.symbolic ....: for a, b in zip(L1, L2)) True @@ -343,8 +343,8 @@ def integrate_vector(f, prec, epsilon=None): sage: epsilon = K(2^(-prec + 4)) sage: f = lambda t:V((1 + t^2, 1/(1 + t^2))) sage: I = integrate_vector(f, prec, epsilon=epsilon) - sage: J = V((4/3, pi/4)) - sage: max(c.abs() for c in (I - J)) < epsilon + sage: J = V((4/3, pi/4)) # needs sage.symbolic + sage: max(c.abs() for c in (I - J)) < epsilon # needs sage.symbolic True We can also use complex-valued integrands:: @@ -354,10 +354,10 @@ def integrate_vector(f, prec, epsilon=None): sage: K = ComplexField(prec) sage: V = VectorSpace(K, 2) sage: epsilon = Kreal(2^(-prec + 4)) - sage: f = lambda t: V((t, K(exp(2*pi*t*K.0)))) - sage: I = integrate_vector(f, prec, epsilon=epsilon) + sage: f = lambda t: V((t, K(exp(2*pi*t*K.0)))) # needs sage.symbolic + sage: I = integrate_vector(f, prec, epsilon=epsilon) # needs sage.symbolic sage: J = V((1/2, 0)) - sage: max(c.abs() for c in (I - J)) < epsilon + sage: max(c.abs() for c in (I - J)) < epsilon # needs sage.symbolic True """ results = [] diff --git a/src/sage/numerical/interactive_simplex_method.py b/src/sage/numerical/interactive_simplex_method.py index 184a2c8a434..c2a10d6a4f6 100644 --- a/src/sage/numerical/interactive_simplex_method.py +++ b/src/sage/numerical/interactive_simplex_method.py @@ -64,7 +64,7 @@ Since it has only two variables, we can solve it graphically:: - sage: P.plot() # optional - sage.plot + sage: P.plot() # needs sage.plot Graphics object consisting of 19 graphics primitives @@ -298,9 +298,9 @@ def _latex_product(coefficients, variables, sage: from sage.numerical.interactive_simplex_method import \ ....: _latex_product - sage: var("x, y") + sage: var("x, y") # needs sage.symbolic (x, y) - sage: print(_latex_product([-1, 3], [x, y])) + sage: print(_latex_product([-1, 3], [x, y])) # needs sage.symbolic - \mspace{-6mu}&\mspace{-6mu} x \mspace{-6mu}&\mspace{-6mu} + \mspace{-6mu}&\mspace{-6mu} 3 y """ entries = [] @@ -1534,19 +1534,19 @@ def plot(self, *args, **kwds): sage: b = (1000, 1500) sage: c = (10, 5) sage: P = InteractiveLPProblem(A, b, c, ["C", "B"], variable_type=">=") - sage: p = P.plot() # optional - sage.plot - sage: p.show() # optional - sage.plot + sage: p = P.plot() # needs sage.plot + sage: p.show() # needs sage.plot In this case the plot works better with the following axes ranges:: - sage: p = P.plot(0, 1000, 0, 1500) # optional - sage.plot - sage: p.show() # optional - sage.plot + sage: p = P.plot(0, 1000, 0, 1500) # needs sage.plot + sage: p.show() # needs sage.plot TESTS: We check that zero objective can be dealt with:: - sage: InteractiveLPProblem(A, b, (0, 0), ["C", "B"], variable_type=">=").plot() # optional - sage.plot + sage: InteractiveLPProblem(A, b, (0, 0), ["C", "B"], variable_type=">=").plot() # needs sage.plot Graphics object consisting of 8 graphics primitives """ FP = self.plot_feasible_set(*args, **kwds) @@ -1611,13 +1611,13 @@ def plot_feasible_set(self, xmin=None, xmax=None, ymin=None, ymax=None, sage: b = (1000, 1500) sage: c = (10, 5) sage: P = InteractiveLPProblem(A, b, c, ["C", "B"], variable_type=">=") - sage: p = P.plot_feasible_set() # optional - sage.plot - sage: p.show() # optional - sage.plot + sage: p = P.plot_feasible_set() # needs sage.plot + sage: p.show() # needs sage.plot In this case the plot works better with the following axes ranges:: - sage: p = P.plot_feasible_set(0, 1000, 0, 1500) # optional - sage.plot - sage: p.show() # optional - sage.plot + sage: p = P.plot_feasible_set(0, 1000, 0, 1500) # needs sage.plot + sage: p.show() # needs sage.plot """ if self.n() != 2: raise ValueError("only problems with 2 variables can be plotted") diff --git a/src/sage/numerical/knapsack.py b/src/sage/numerical/knapsack.py index 3a5c14474e8..3f80f517998 100644 --- a/src/sage/numerical/knapsack.py +++ b/src/sage/numerical/knapsack.py @@ -408,6 +408,7 @@ def is_superincreasing(self, seq=None): The sequence must contain only integers:: + sage: # needs sage.symbolic sage: from sage.numerical.knapsack import Superincreasing sage: L = [1.0, 2.1, pi, 21, 69, 189, 376, 919] sage: Superincreasing(L).is_superincreasing() diff --git a/src/sage/numerical/mip.pyx b/src/sage/numerical/mip.pyx index 71dc66360da..1e6e6caa7bd 100644 --- a/src/sage/numerical/mip.pyx +++ b/src/sage/numerical/mip.pyx @@ -315,6 +315,7 @@ cdef class MixedIntegerLinearProgram(SageObject): Computation of a maximum stable set in Petersen's graph:: + sage: # needs sage.graphs sage: g = graphs.PetersenGraph() sage: p = MixedIntegerLinearProgram(maximization=True, solver='GLPK') sage: b = p.new_variable(binary=True) @@ -659,13 +660,15 @@ cdef class MixedIntegerLinearProgram(SageObject): sage: p = MixedIntegerLinearProgram(solver='ppl') sage: p.base_ring() Rational Field - sage: from sage.rings.qqbar import AA # optional - sage.rings.number_field - sage: p = MixedIntegerLinearProgram(solver='InteractiveLP', base_ring=AA) # optional - sage.rings.number_field - sage: p.base_ring() # optional - sage.rings.number_field + sage: from sage.rings.qqbar import AA # needs sage.rings.number_field + sage: p = MixedIntegerLinearProgram(solver='InteractiveLP', base_ring=AA) # needs sage.rings.number_field + sage: p.base_ring() # needs sage.rings.number_field Algebraic Real Field - sage: d = polytopes.dodecahedron() # optional - sage.rings.number_field - sage: p = MixedIntegerLinearProgram(base_ring=d.base_ring()) # optional - sage.rings.number_field - sage: p.base_ring() # optional - sage.rings.number_field + + sage: # needs sage.groups sage.rings.number_field + sage: d = polytopes.dodecahedron() + sage: p = MixedIntegerLinearProgram(base_ring=d.base_ring()) + sage: p.base_ring() Number Field in sqrt5 with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790? """ return self._backend.base_ring() @@ -2629,6 +2632,7 @@ cdef class MixedIntegerLinearProgram(SageObject): Computation of a maximum stable set in Petersen's graph:: + sage: # needs sage.graphs sage: g = graphs.PetersenGraph() sage: p = MixedIntegerLinearProgram(maximization=True, solver='GLPK') sage: b = p.new_variable(nonnegative=True) @@ -2823,14 +2827,15 @@ cdef class MixedIntegerLinearProgram(SageObject): are not recorded, and we can disable this feature providing an empty filename. This is currently working with CPLEX and Gurobi:: - sage: p = MixedIntegerLinearProgram(solver="CPLEX") # optional - CPLEX - sage: p.solver_parameter("logfile") # optional - CPLEX + sage: # optional - cplex + sage: p = MixedIntegerLinearProgram(solver="CPLEX") + sage: p.solver_parameter("logfile") '' - sage: p.solver_parameter("logfile", "/dev/null") # optional - CPLEX - sage: p.solver_parameter("logfile") # optional - CPLEX + sage: p.solver_parameter("logfile", "/dev/null") + sage: p.solver_parameter("logfile") '/dev/null' - sage: p.solver_parameter("logfile", '') # optional - CPLEX - sage: p.solver_parameter("logfile") # optional - CPLEX + sage: p.solver_parameter("logfile", '') + sage: p.solver_parameter("logfile") '' Solver-specific parameters: @@ -2983,6 +2988,7 @@ cdef class MixedIntegerLinearProgram(SageObject): EXAMPLES:: + sage: # needs sage.graphs sage: g = graphs.CubeGraph(9) sage: p = MixedIntegerLinearProgram(solver="GLPK") sage: p.solver_parameter("mip_gap_tolerance",100) @@ -3017,6 +3023,7 @@ cdef class MixedIntegerLinearProgram(SageObject): EXAMPLES:: + sage: # needs sage.graphs sage: g = graphs.CubeGraph(9) sage: p = MixedIntegerLinearProgram(solver="GLPK") sage: p.solver_parameter("mip_gap_tolerance",100) @@ -3035,7 +3042,7 @@ cdef class MixedIntegerLinearProgram(SageObject): Just make sure that the variable *has* been defined, and is not just undefined:: - sage: p.get_relative_objective_gap() > 1 + sage: p.get_relative_objective_gap() > 1 # needs sage.graphs True """ return self._backend.get_relative_objective_gap() diff --git a/src/sage/numerical/optimize.py b/src/sage/numerical/optimize.py index f728b2ad89f..708d440a205 100644 --- a/src/sage/numerical/optimize.py +++ b/src/sage/numerical/optimize.py @@ -1,17 +1,17 @@ +# sage.doctest: optional - scipy """ Numerical Root Finding and Optimization AUTHOR: - William Stein (2007): initial version -- Nathann Cohen (2008) : Bin Packing +- Nathann Cohen (2008): Bin Packing Functions and Methods ---------------------- """ -from sage.misc.superseded import deprecation from sage.modules.free_module_element import vector from sage.rings.real_double import RDF @@ -171,6 +171,7 @@ def find_root(f, a, b, xtol=10e-13, rtol=2.0**-50, maxiter=100, full_output=Fals raise NotImplementedError("Brent's method failed to find a zero for f on the interval") return brentqRes + def find_local_maximum(f, a, b, tol=1.48e-08, maxfun=500): """ Numerically find a local maximum of the expression `f` on the interval @@ -191,7 +192,7 @@ def find_local_maximum(f, a, b, tol=1.48e-08, maxfun=500): (0.561096338191..., 0.8603335890...) sage: find_local_maximum(f, 0, 5, tol=0.1, maxfun=10) (0.561090323458..., 0.857926501456...) - sage: find_local_maximum(8*e^(-x)*sin(x) - 1, 0, 7) + sage: find_local_maximum(8*e^(-x)*sin(x) - 1, 0, 7) # needs sage.symbolic (1.579175535558..., 0.7853981...) """ try: @@ -201,6 +202,7 @@ def find_local_maximum(f, a, b, tol=1.48e-08, maxfun=500): minval, x = find_local_minimum(lambda z: -f(z), a=a, b=b, tol=tol, maxfun=maxfun) return -minval, x + def find_local_minimum(f, a, b, tol=1.48e-08, maxfun=500): """ Numerically find a local minimum of the expression ``f`` on the @@ -215,7 +217,7 @@ def find_local_minimum(f, a, b, tol=1.48e-08, maxfun=500): - ``f`` -- a function of at most one variable. - - ``a``, ``b`` -- endpoints of interval on which to minimize self. + - ``a``, ``b`` -- endpoints of interval on which to minimize `f`. - ``tol`` -- the convergence tolerance @@ -224,10 +226,10 @@ def find_local_minimum(f, a, b, tol=1.48e-08, maxfun=500): OUTPUT: - - ``minval`` -- (float) the minimum value that self takes on in the + - ``minval`` -- (float) the minimum value that `f` takes on in the interval `[a,b]` - - ``x`` -- (float) the point at which self takes on the minimum value + - ``x`` -- (float) the point at which `f` takes on the minimum value EXAMPLES:: @@ -239,7 +241,7 @@ def find_local_minimum(f, a, b, tol=1.48e-08, maxfun=500): (-3.28837136189098..., 3.42575079030572...) sage: find_local_minimum(f, 1, 5, tol=1e-2, maxfun=10) (-3.28837084598..., 3.4250840220...) - sage: show(plot(f, 0, 20)) + sage: show(plot(f, 0, 20)) # needs sage.plot sage: find_local_minimum(f, 1, 15) (-9.4772942594..., 9.5293344109...) @@ -248,12 +250,14 @@ def find_local_minimum(f, a, b, tol=1.48e-08, maxfun=500): :: + sage: # needs sage.symbolic sage: f(x) = -x*sin(x^2) sage: find_local_minimum(f, -2.5, -1) (-2.182769784677722, -2.1945027498534686) Enlarging the interval returns a larger minimum:: + sage: # needs sage.symbolic sage: find_local_minimum(f, -2.5, 2) (-1.3076194129914434, 1.3552111405712108) @@ -262,9 +266,10 @@ def find_local_minimum(f, a, b, tol=1.48e-08, maxfun=500): numerics (observe the small number of decimal places that we actually test):: - sage: plot(f, (x,-2.5, -1)).ymin() + sage: # needs sage.plot sage.symbolic + sage: plot(f, (x, -2.5, -1)).ymin() -2.182... - sage: plot(f, (x,-2.5, 2)).ymin() + sage: plot(f, (x, -2.5, 2)).ymin() -2.182... ALGORITHM: @@ -318,15 +323,15 @@ def minimize(func, x0, gradient=None, hessian=None, algorithm="default", ``'default'`` (for Python functions, the simplex method is the default) (for symbolic functions bfgs is the default): - - ``'simplex'`` -- using the downhill simplex algorithm + - ``'simplex'`` -- using the downhill simplex algorithm - - ``'powell'`` -- use the modified Powell algorithm + - ``'powell'`` -- use the modified Powell algorithm - - ``'bfgs'`` -- (Broyden-Fletcher-Goldfarb-Shanno) requires gradient + - ``'bfgs'`` -- (Broyden-Fletcher-Goldfarb-Shanno) requires gradient - - ``'cg'`` -- (conjugate-gradient) requires gradient + - ``'cg'`` -- (conjugate-gradient) requires gradient - - ``'ncg'`` -- (newton-conjugate gradient) requires gradient and hessian + - ``'ncg'`` -- (newton-conjugate gradient) requires gradient and hessian - ``verbose`` -- (optional, default: False) print convergence message @@ -341,27 +346,27 @@ def minimize(func, x0, gradient=None, hessian=None, algorithm="default", Minimize a fourth order polynomial in three variables (see the :wikipedia:`Rosenbrock_function`):: - sage: vars = var('x y z') - sage: f = 100*(y-x^2)^2+(1-x)^2+100*(z-y^2)^2+(1-y)^2 - sage: minimize(f, [.1,.3,.4]) # abs tol 1e-6 + sage: vars = var('x y z') # needs sage.symbolic + sage: f = 100*(y-x^2)^2 + (1-x)^2 + 100*(z-y^2)^2 + (1-y)^2 # needs sage.symbolic + sage: minimize(f, [.1,.3,.4]) # abs tol 1e-6 # needs sage.symbolic (1.0, 1.0, 1.0) Try the newton-conjugate gradient method; the gradient and hessian are computed automatically:: - sage: minimize(f, [.1, .3, .4], algorithm="ncg") # abs tol 1e-6 + sage: minimize(f, [.1, .3, .4], algorithm="ncg") # abs tol 1e-6 # needs sage.symbolic (1.0, 1.0, 1.0) We get additional convergence information with the `verbose` option:: - sage: minimize(f, [.1, .3, .4], algorithm="ncg", verbose=True) + sage: minimize(f, [.1, .3, .4], algorithm="ncg", verbose=True) # needs sage.symbolic Optimization terminated successfully. ... (0.9999999..., 0.999999..., 0.999999...) Same example with just Python functions:: - sage: def rosen(x): # The Rosenbrock function + sage: def rosen(x): # The Rosenbrock function ....: return sum(100.0r*(x[1r:]-x[:-1r]**2.0r)**2.0r + (1r-x[:-1r])**2.0r) sage: minimize(rosen, [.1,.3,.4]) # abs tol 3e-5 (1.0, 1.0, 1.0) @@ -369,7 +374,8 @@ def minimize(func, x0, gradient=None, hessian=None, algorithm="default", Same example with a pure Python function and a Python function to compute the gradient:: - sage: def rosen(x): # The Rosenbrock function + sage: # needs numpy + sage: def rosen(x): # The Rosenbrock function ....: return sum(100.0r*(x[1r:]-x[:-1r]**2.0r)**2.0r + (1r-x[:-1r])**2.0r) sage: import numpy sage: from numpy import zeros @@ -382,7 +388,8 @@ def minimize(func, x0, gradient=None, hessian=None, algorithm="default", ....: der[0] = -400r*x[0r]*(x[1r]-x[0r]**2r) - 2r*(1r-x[0]) ....: der[-1] = 200r*(x[-1r]-x[-2r]**2r) ....: return der - sage: minimize(rosen, [.1,.3,.4], gradient=rosen_der, algorithm="bfgs") # abs tol 1e-6 + sage: minimize(rosen, [.1,.3,.4], gradient=rosen_der, # abs tol 1e-6 + ....: algorithm="bfgs") (1.0, 1.0, 1.0) """ from sage.structure.element import Expression @@ -434,7 +441,7 @@ def minimize_constrained(func,cons,x0,gradient=None,algorithm='default', **args) INPUT: - ``func`` -- Either a symbolic function, or a Python function whose - argument is a tuple with n components + argument is a tuple with `n` components - ``cons`` -- constraints. This should be either a function or list of functions that must be positive. Alternatively, the constraints can @@ -465,7 +472,6 @@ def minimize_constrained(func,cons,x0,gradient=None,algorithm='default', **args) `50x + 24y \leq 2400`, `30x + 33y \leq 2100`, `x \geq 45`, and `y \geq 5`:: - sage: y = var('y') sage: f = lambda p: -p[0]-p[1]+50 sage: c_1 = lambda p: p[0]-45 sage: c_2 = lambda p: p[1]-5 @@ -477,31 +483,35 @@ def minimize_constrained(func,cons,x0,gradient=None,algorithm='default', **args) Let's find a minimum of `\sin(xy)`:: - sage: x,y = var('x y') - sage: f(x,y) = sin(x*y) - sage: minimize_constrained(f, [(None,None),(4,10)],[5,5]) + sage: x,y = var('x y') # needs sage.symbolic + sage: f(x,y) = sin(x*y) # needs sage.symbolic + sage: minimize_constrained(f, [(None,None),(4,10)],[5,5]) # needs sage.symbolic (4.8..., 4.8...) Check if L-BFGS-B finds the same minimum:: - sage: minimize_constrained(f, [(None,None),(4,10)],[5,5], algorithm='l-bfgs-b') + sage: minimize_constrained(f, [(None,None),(4,10)],[5,5], # needs sage.symbolic + ....: algorithm='l-bfgs-b') (4.7..., 4.9...) Rosenbrock function (see the :wikipedia:`Rosenbrock_function`):: sage: from scipy.optimize import rosen, rosen_der - sage: minimize_constrained(rosen, [(-50,-10),(5,10)],[1,1],gradient=rosen_der,algorithm='l-bfgs-b') + sage: minimize_constrained(rosen, [(-50,-10),(5,10)],[1,1], + ....: gradient=rosen_der, algorithm='l-bfgs-b') (-10.0, 10.0) - sage: minimize_constrained(rosen, [(-50,-10),(5,10)],[1,1],algorithm='l-bfgs-b') + sage: minimize_constrained(rosen, [(-50,-10),(5,10)],[1,1], + ....: algorithm='l-bfgs-b') (-10.0, 10.0) TESTS: Check if :trac:`6592` is fixed:: + sage: # needs sage.symbolic sage: x, y = var('x y') sage: f(x,y) = (100 - x) + (1000 - y) - sage: c(x,y) = x + y - 479 # > 0 + sage: c(x,y) = x + y - 479 # > 0 sage: minimize_constrained(f, [c], [100, 300]) (805.985..., 1005.985...) sage: minimize_constrained(f, c, [100, 300]) @@ -510,6 +520,7 @@ def minimize_constrained(func,cons,x0,gradient=None,algorithm='default', **args) If ``func`` is symbolic, its minimizer should be in the same order as its arguments (:trac:`32511`):: + sage: # needs sage.symbolic sage: x,y = SR.var('x,y') sage: f(y,x) = x - y sage: c1(y,x) = x @@ -563,119 +574,6 @@ def minimize_constrained(func,cons,x0,gradient=None,algorithm='default', **args) return vector(RDF, min) -def linear_program(c, G, h, A=None, b=None, solver=None): - r""" - Solve the dual linear programs: - - - Minimize `c'x` subject to `Gx + s = h`, `Ax = b`, and `s \geq 0` where - `'` denotes transpose. - - - Maximize `-h'z - b'y` subject to `G'z + A'y + c = 0` and `z \geq 0`. - - This function is deprecated. Use :class:`MixedIntegerLinearProgram` instead. - - This function depends on the optional package ``cvxopt``. - - INPUT: - - - ``c`` -- a vector - - - ``G`` -- a matrix - - - ``h`` -- a vector - - - ``A`` -- a matrix - - - ``b`` --- a vector - - - ``solver`` (optional) --- solver to use. If None, the cvxopt's lp-solver - is used. If it is 'glpk', then glpk's solver - is used. - - These can be over any field that can be turned into a floating point - number. - - - OUTPUT: - - A dictionary ``sol`` with keys ``x``, ``s``, ``y``, ``z`` corresponding - to the variables above: - - - ``sol['x']`` -- the solution to the linear program - - - ``sol['s']`` -- the slack variables for the solution - - - ``sol['z']``, ``sol['y']`` -- solutions to the dual program - - - EXAMPLES: - - First, we minimize `-4x_1 - 5x_2` subject to `2x_1 + x_2 \leq 3`, - `x_1 + 2x_2 \leq 3`, `x_1 \geq 0`, and `x_2 \geq 0`:: - - sage: c=vector(RDF,[-4,-5]) - sage: G=matrix(RDF,[[2,1],[1,2],[-1,0],[0,-1]]) - sage: h=vector(RDF,[3,3,0,0]) - sage: sol=linear_program(c,G,h) # optional - cvxopt - doctest:warning... - DeprecationWarning: linear_program is deprecated; use MixedIntegerLinearProgram instead - See https://github.com/sagemath/sage/issues/32226 for details. - sage: sol['x'] # optional - cvxopt - (0.999..., 1.000...) - - Here we solve the same problem with 'glpk' interface to 'cvxopt':: - - sage: sol=linear_program(c,G,h,solver='glpk') # optional - cvxopt - GLPK Simplex Optimizer... - ... - OPTIMAL LP SOLUTION FOUND - sage: sol['x'] # optional - cvxopt - (1.0, 1.0) - - Next, we maximize `x+y-50` subject to `50x + 24y \leq 2400`, - `30x + 33y \leq 2100`, `x \geq 45`, and `y \geq 5`:: - - sage: v=vector([-1.0,-1.0,-1.0]) - sage: m=matrix([[50.0,24.0,0.0],[30.0,33.0,0.0],[-1.0,0.0,0.0],[0.0,-1.0,0.0],[0.0,0.0,1.0],[0.0,0.0,-1.0]]) - sage: h=vector([2400.0,2100.0,-45.0,-5.0,1.0,-1.0]) - sage: sol=linear_program(v,m,h) # optional - cvxopt - sage: sol['x'] # optional - cvxopt - (45.000000..., 6.2499999..., 1.00000000...) - sage: sol=linear_program(v,m,h,solver='glpk') # optional - cvxopt - GLPK Simplex Optimizer... - OPTIMAL LP SOLUTION FOUND - sage: sol['x'] # optional - cvxopt - (45.0..., 6.25..., 1.0...) - """ - deprecation(32226, 'linear_program is deprecated; use MixedIntegerLinearProgram instead') - - from cvxopt.base import matrix as m - from cvxopt import solvers - solvers.options['show_progress'] = False - if solver == 'glpk': - from cvxopt import glpk - glpk.options['LPX_K_MSGLEV'] = 0 - c_ = m(c.base_extend(RDF).numpy()) - G_ = m(G.base_extend(RDF).numpy()) - h_ = m(h.base_extend(RDF).numpy()) - if A is not None and b is not None: - A_ = m(A.base_extend(RDF).numpy()) - b_ = m(b.base_extend(RDF).numpy()) - sol = solvers.lp(c_,G_,h_,A_,b_,solver=solver) - else: - sol = solvers.lp(c_,G_,h_,solver=solver) - status = sol['status'] - if status != 'optimal': - return {'primal objective': None, 'x': None, 's': None, 'y': None, - 'z': None, 'status': status} - x = vector(RDF, list(sol['x'])) - s = vector(RDF, list(sol['s'])) - y = vector(RDF, list(sol['y'])) - z = vector(RDF, list(sol['z'])) - return {'primal objective': sol['primal objective'], - 'x': x, 's': s, 'y': y, 'z': z, 'status': status} - - def find_fit(data, model, initial_guess=None, parameters=None, variables=None, solution_dict=False): r""" Finds numerical estimates for the parameters of the function model to @@ -719,30 +617,34 @@ def find_fit(data, model, initial_guess=None, parameters=None, variables=None, s perturbations:: sage: set_random_seed(0) - sage: data = [(i, 1.2 * sin(0.5*i-0.2) + 0.1 * normalvariate(0, 1)) for i in xsrange(0, 4*pi, 0.2)] - sage: var('a, b, c, x') + sage: data = [(i, 1.2 * sin(0.5*i-0.2) + 0.1 * normalvariate(0, 1)) # needs sage.symbolic + ....: for i in xsrange(0, 4*pi, 0.2)] + sage: var('a, b, c, x') # needs sage.symbolic (a, b, c, x) We define a function with free parameters `a`, `b` and `c`:: - sage: model(x) = a * sin(b * x - c) + sage: model(x) = a * sin(b * x - c) # needs sage.symbolic We search for the parameters that give the best fit to the data:: - sage: find_fit(data, model) + sage: find_fit(data, model) # needs sage.symbolic [a == 1.21..., b == 0.49..., c == 0.19...] We can also use a Python function for the model:: sage: def f(x, a, b, c): return a * sin(b * x - c) - sage: fit = find_fit(data, f, parameters = [a, b, c], variables = [x], solution_dict = True) - sage: fit[a], fit[b], fit[c] + sage: fit = find_fit(data, f, parameters=[a, b, c], variables=[x], # needs sage.symbolic + ....: solution_dict = True) + sage: fit[a], fit[b], fit[c] # needs sage.symbolic (1.21..., 0.49..., 0.19...) We search for a formula for the `n`-th prime number:: + sage: # needs sage.libs.pari sage: dataprime = [(i, nth_prime(i)) for i in range(1, 5000, 100)] - sage: find_fit(dataprime, a * x * log(b * x), parameters = [a, b], variables = [x]) + sage: find_fit(dataprime, a * x * log(b * x), # needs sage.symbolic + ....: parameters=[a, b], variables=[x]) [a == 1.11..., b == 1.24...] @@ -898,24 +800,24 @@ def binpacking(items, maximum=1, k=None, solver=None, verbose=0, sage: from sage.numerical.optimize import binpacking sage: values = [1/5, 1/3, 2/3, 3/4, 5/7] - sage: bins = binpacking(values) - sage: len(bins) + sage: bins = binpacking(values) # needs sage.numerical.mip + sage: len(bins) # needs sage.numerical.mip 3 Checking the bins are of correct size :: - sage: all(sum(b) <= 1 for b in bins) + sage: all(sum(b) <= 1 for b in bins) # needs sage.numerical.mip True Checking every item is in a bin :: - sage: b1, b2, b3 = bins - sage: all((v in b1 or v in b2 or v in b3) for v in values) + sage: b1, b2, b3 = bins # needs sage.numerical.mip + sage: all((v in b1 or v in b2 or v in b3) for v in values) # needs sage.numerical.mip True And only in one bin :: - sage: sum(len(b) for b in bins) == len(values) + sage: sum(len(b) for b in bins) == len(values) # needs sage.numerical.mip True One way to use only three boxes (which is best possible) is to put @@ -925,7 +827,7 @@ def binpacking(items, maximum=1, k=None, solver=None, verbose=0, Of course, we can also check that there is no solution using only two boxes :: sage: from sage.numerical.optimize import binpacking - sage: binpacking([0.2,0.3,0.8,0.9], k=2) + sage: binpacking([0.2,0.3,0.8,0.9], k=2) # needs sage.numerical.mip Traceback (most recent call last): ... ValueError: this problem has no solution @@ -934,8 +836,8 @@ def binpacking(items, maximum=1, k=None, solver=None, verbose=0, its weight. Then, the bins contain the name of the items inside it :: sage: values = {'a':1/5, 'b':1/3, 'c':2/3, 'd':3/4, 'e':5/7} - sage: bins = binpacking(values) - sage: set(flatten(bins)) == set(values.keys()) + sage: bins = binpacking(values) # needs sage.numerical.mip + sage: set(flatten(bins)) == set(values.keys()) # needs sage.numerical.mip True TESTS: diff --git a/src/sage/numerical/sdp.pyx b/src/sage/numerical/sdp.pyx index e7b96a2abef..3f5f8a47cfb 100644 --- a/src/sage/numerical/sdp.pyx +++ b/src/sage/numerical/sdp.pyx @@ -72,17 +72,19 @@ The following example shows all these steps:: sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) sage: p.add_constraint(c1*x[0] + c2*x[1] >= matrix.zero(2,2,sparse=True)) - sage: p.solver_parameter("show_progress", True) # optional - cvxopt - sage: opt = p.solve() # optional - cvxopt + + sage: # needs cvxopt + sage: p.solver_parameter("show_progress", True) + sage: opt = p.solve() pcost dcost gap pres dres k/t 0: ... ... Optimal solution found. - sage: print('Objective Value: {}'.format(N(opt,3))) # optional - cvxopt + sage: print('Objective Value: {}'.format(N(opt,3))) Objective Value: 1.0 - sage: [N(x, 3) for x in sorted(p.get_values(x).values())] # optional - cvxopt + sage: [N(x, 3) for x in sorted(p.get_values(x).values())] [3.0e-8, 1.0] - sage: p.show() # optional - cvxopt + sage: p.show() Maximization: x_0 - x_1 Constraints: @@ -97,46 +99,49 @@ of primal and dual problems. Thus we can get the optimizer `X` of the dual probl as follows, as diagonal blocks, one per each constraint, via :meth:`~SemidefiniteProgram.dual_variable`. E.g.:: - sage: p.dual_variable(1) # rel tol 2e-03 # optional - cvxopt + sage: p.dual_variable(1) # rel tol 2e-03 # needs cvxopt [ 85555.0 -85555.0] [-85555.0 85555.0] We can see that the optimal value of the dual is equal (up to numerical noise) to `opt`.:: - sage: opt-((p.dual_variable(0)*a3).trace()+(p.dual_variable(1)*b3).trace()) # tol 8e-08 # optional - cvxopt + sage: opt - ((p.dual_variable(0)*a3).trace() # tol 8e-08 # needs cvxopt + ....: + (p.dual_variable(1)*b3).trace()) 0.0 Dual variable blocks at optimality are orthogonal to "slack variables", that is, matrices `C-\sum_k x_k A_k`, cf. (Primal problem) above, available via :meth:`~SemidefiniteProgram.slack`. E.g.:: - sage: (p.slack(0)*p.dual_variable(0)).trace() # tol 2e-07 # optional - cvxopt + sage: (p.slack(0)*p.dual_variable(0)).trace() # tol 2e-07 # needs cvxopt 0.0 More interesting example, the :func:`Lovasz theta ` of the 7-gon:: - sage: c=graphs.CycleGraph(7) - sage: c2=c.distance_graph(2).adjacency_matrix() - sage: c3=c.distance_graph(3).adjacency_matrix() - sage: p.=SemidefiniteProgram() + sage: # needs sage.graphs + sage: c = graphs.CycleGraph(7) + sage: c2 = c.distance_graph(2).adjacency_matrix() + sage: c3 = c.distance_graph(3).adjacency_matrix() + sage: p. = SemidefiniteProgram() sage: p.add_constraint((1/7)*matrix.identity(7)>=-y[0]*c2-y[1]*c3) sage: p.set_objective(y[0]*(c2**2).trace()+y[1]*(c3**2).trace()) - sage: x=p.solve(); x+1 # optional - cvxopt + sage: x = p.solve(); x + 1 # needs cvxopt 3.31766... Unlike in the previous example, the slack variable is very far from 0:: - sage: p.slack(0).trace() # tol 1e-14 # optional - cvxopt + sage: p.slack(0).trace() # tol 1e-14 # needs cvxopt sage.graphs 1.0 The default CVXOPT backend computes with the Real Double Field, for example:: - sage: p = SemidefiniteProgram(solver='cvxopt') # optional - cvxopt - sage: p.base_ring() # optional - cvxopt + sage: # needs cvxopt + sage: p = SemidefiniteProgram(solver='cvxopt') + sage: p.base_ring() Real Double Field - sage: x = p.new_variable() # optional - cvxopt - sage: 0.5 + 3/2*x[1] # optional - cvxopt + sage: x = p.new_variable() + sage: 0.5 + 3/2*x[1] 0.5 + 1.5*x_0 For representing an SDP with exact data, there is another backend:: @@ -285,7 +290,7 @@ cdef class SemidefiniteProgram(SageObject): sage: b3 = matrix([[3, 3.], [3., 3.]]) sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) - sage: N(p.solve(), 2) # optional - cvxopt + sage: N(p.solve(), 2) # needs cvxopt -3.0 """ @@ -301,7 +306,7 @@ cdef class SemidefiniteProgram(SageObject): - CVXOPT (``solver="CVXOPT"``). See the `CVXOPT `_ web site. - -If ``solver=None`` (default), the default solver is used (see + - If ``solver=None`` (default), the default solver is used (see ``default_sdp_solver`` method. - ``maximization`` @@ -335,7 +340,6 @@ cdef class SemidefiniteProgram(SageObject): # Associates an index to the variables self._variables = {} - def linear_functions_parent(self): """ Return the parent for all linear functions. @@ -479,8 +483,8 @@ cdef class SemidefiniteProgram(SageObject): def new_variable(self, name=""): r""" - Returns an instance of ``SDPVariable`` associated - to the current instance of ``SemidefiniteProgram``. + Returns an instance of :class:`SDPVariable` associated + to the current instance of :class:`SemidefiniteProgram`. A new variable ``x`` is defined by:: @@ -504,7 +508,7 @@ cdef class SemidefiniteProgram(SageObject): sage: p = SemidefiniteProgram() sage: x = p.new_variable() sage: a1 = matrix([[1, 2.], [2., 3.]]) - sage: p.add_constraint(a1*x[0]+a1*x[3] <= 0) + sage: p.add_constraint(a1*x[0] + a1*x[3] <= 0) sage: p.show() Maximization: @@ -567,7 +571,7 @@ cdef class SemidefiniteProgram(SageObject): cpdef int number_of_constraints(self) noexcept: r""" - Returns the number of constraints assigned so far. + Return the number of constraints assigned so far. EXAMPLES:: @@ -589,7 +593,7 @@ cdef class SemidefiniteProgram(SageObject): cpdef int number_of_variables(self) noexcept: r""" - Returns the number of variables used so far. + Return the number of variables used so far. EXAMPLES:: @@ -602,11 +606,9 @@ cdef class SemidefiniteProgram(SageObject): """ return self._backend.ncols() - - def show(self): r""" - Displays the ``SemidefiniteProgram`` in a human-readable way. + Display the :class:`SemidefiniteProgram` in a human-readable way. EXAMPLES: @@ -618,7 +620,7 @@ cdef class SemidefiniteProgram(SageObject): sage: a2 = matrix([[2,3],[3,4]]) sage: a3 = matrix([[3,4],[4,5]]) sage: p.set_objective(x[0] - x[1]) - sage: p.add_constraint(a1*x[0]+a2*x[1]<= a3) + sage: p.add_constraint(a1*x[0] + a2*x[1]<= a3) sage: p.show() Maximization: hihi[0] - hihi[1] @@ -692,25 +694,23 @@ cdef class SemidefiniteProgram(SageObject): print(str(varid_name[i]) + ", ", end=" ") print(str(varid_name[b.ncols()-1])) - def get_values(self, *lists): r""" Return values found by the previous call to ``solve()``. INPUT: - - Any instance of ``SDPVariable`` (or one of its elements), + - Any instance of :class:`SDPVariable` (or one of its elements), or lists of them. OUTPUT: - - Each instance of ``SDPVariable`` is replaced by a dictionary + - Each instance of :class:`SDPVariable` is replaced by a dictionary containing the numerical values found for each corresponding variable in the instance. - - Each element of an instance of a ``SDPVariable`` is replaced + - Each element of an instance of a :class:`SDPVariable` is replaced by its corresponding numerical value. - EXAMPLES:: sage: p = SemidefiniteProgram(solver = "cvxopt", maximization = False) @@ -724,19 +724,19 @@ cdef class SemidefiniteProgram(SageObject): sage: b3 = matrix([[3, 3.], [3., 3.]]) sage: p.add_constraint(a1*x[3] + a2*x[5] <= a3) sage: p.add_constraint(b1*x[3] + b2*x[5] <= b3) - sage: N(p.solve(),3) # optional - cvxopt + sage: N(p.solve(), 3) # needs cvxopt -3.0 To return the optimal value of ``x[3]``:: - sage: N(p.get_values(x[3]),3) # optional - cvxopt + sage: N(p.get_values(x[3]),3) # needs cvxopt -1.0 To get a dictionary identical to ``x`` containing optimal values for the corresponding variables :: - sage: x_sol = p.get_values(x) # optional - cvxopt - sage: sorted(x_sol) # optional - cvxopt + sage: x_sol = p.get_values(x) # needs cvxopt + sage: sorted(x_sol) # needs cvxopt [3, 5] """ @@ -765,13 +765,13 @@ cdef class SemidefiniteProgram(SageObject): def set_objective(self, obj): r""" - Sets the objective of the ``SemidefiniteProgram``. + Sets the objective of the :class:`SemidefiniteProgram`. INPUT: - ``obj`` -- A semidefinite function to be optimized. - ( can also be set to ``None`` or ``0`` when just - looking for a feasible solution ) + (can also be set to ``None`` or ``0`` when just + looking for a feasible solution) EXAMPLES: @@ -794,11 +794,11 @@ cdef class SemidefiniteProgram(SageObject): sage: a1 = matrix([[1,2],[2,3]]) sage: a2 = matrix([[1,1],[1,1]]) sage: a3 = matrix([[1,-1],[-1,1]]) - sage: p.add_constraint(a1*x[1]+a2*x[2] <= a3) - sage: N(p.solve(),digits=3) # optional - cvxopt + sage: p.add_constraint(a1*x[1] + a2*x[2] <= a3) + sage: N(p.solve(), digits=3) # needs cvxopt 16.2 sage: p.set_objective(None) - sage: _ = p.solve() # optional - cvxopt + sage: _ = p.solve() # needs cvxopt """ cdef list values = [] @@ -825,11 +825,13 @@ cdef class SemidefiniteProgram(SageObject): INPUT: - ``linear_function`` -- Two different types of arguments are possible: - - A linear function. In this case, arguments ``min`` or ``max`` - have to be specified. - - A linear constraint of the form ``A <= B``, ``A >= B``, - ``A <= B <= C``, ``A >= B >= C`` or ``A == B``. In this - case, arguments ``min`` and ``max`` will be ignored. + + - A linear function. In this case, arguments ``min`` or ``max`` + have to be specified. + - A linear constraint of the form ``A <= B``, ``A >= B``, + ``A <= B <= C``, ``A >= B >= C`` or ``A == B``. In this + case, arguments ``min`` and ``max`` will be ignored. + - ``name`` -- A name for the constraint. EXAMPLES: @@ -853,8 +855,8 @@ cdef class SemidefiniteProgram(SageObject): sage: a1 = matrix([[1,2],[2,3]]) sage: a2 = matrix([[1,1],[1,1]]) sage: a3 = matrix([[1,-1],[-1,1]]) - sage: p.add_constraint(a1*x[1]+a2*x[2] <= a3) - sage: N(p.solve(),digits=3) # optional - cvxopt + sage: p.add_constraint(a1*x[1] + a2*x[2] <= a3) + sage: N(p.solve(), digits=3) # needs cvxopt 16.2 One can also define double-bounds or equality using the symbol @@ -867,7 +869,7 @@ cdef class SemidefiniteProgram(SageObject): sage: a2 = matrix([[1,1],[1,1]]) sage: a3 = matrix([[1,-1],[-1,1]]) sage: p.add_constraint(a3 >= a1*x[1] + a2*x[2]) - sage: N(p.solve(),digits=3) # optional - cvxopt + sage: N(p.solve(), digits=3) # needs cvxopt 16.2 TESTS: @@ -892,7 +894,6 @@ cdef class SemidefiniteProgram(SageObject): sage: p = SemidefiniteProgram() sage: p.add_constraint(sum([])) - """ if linear_function is 0: return @@ -918,7 +919,7 @@ cdef class SemidefiniteProgram(SageObject): def solve(self, objective_only=False): r""" - Solves the ``SemidefiniteProgram``. + Solve the :class:`SemidefiniteProgram`. INPUT: @@ -947,12 +948,14 @@ cdef class SemidefiniteProgram(SageObject): sage: b3 = matrix([[3, 3.], [3., 3.]]) sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) - sage: N(p.solve(),4) # optional - cvxopt + + sage: # needs cvxopt + sage: N(p.solve(), 4) -11. - sage: x = p.get_values(x) # optional - cvxopt - sage: N(x[0],4) # optional - cvxopt + sage: x = p.get_values(x) + sage: N(x[0],4) -8.0 - sage: N(x[1],4) # optional - cvxopt + sage: N(x[1],4) 3.0 """ self._backend.solve() @@ -977,7 +980,7 @@ cdef class SemidefiniteProgram(SageObject): Dual objective value is the same as the primal one:: - sage: p = SemidefiniteProgram(maximization = False) + sage: p = SemidefiniteProgram(maximization=False) sage: x = p.new_variable() sage: p.set_objective(x[0] - x[1]) sage: a1 = matrix([[1, 2.], [2., 3.]]) @@ -988,20 +991,23 @@ cdef class SemidefiniteProgram(SageObject): sage: b3 = matrix([[3, 3.], [3., 3.]]) sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) - sage: p.solve() # tol 1e-08 # optional - cvxopt + + sage: # needs cvxopt + sage: p.solve() # tol 1e-08 -3.0 - sage: x = p.get_values(x).values() # optional - cvxopt - sage: -(a3*p.dual_variable(0)).trace()-(b3*p.dual_variable(1)).trace() # tol 1e-07 # optional - cvxopt + sage: x = p.get_values(x).values() + sage: -(a3*p.dual_variable(0)).trace() - (b3*p.dual_variable(1)).trace() # tol 1e-07 -3.0 Dual variable is orthogonal to the slack :: - sage: g = sum((p.slack(j)*p.dual_variable(j)).trace() for j in range(2)); g # tol 1.2e-08 # optional - cvxopt + sage: # needs cvxopt + sage: g = sum((p.slack(j)*p.dual_variable(j)).trace() for j in range(2)); g # tol 1.2e-08 0.0 TESTS:: - sage: p.dual_variable(7) # optional - cvxopt + sage: p.dual_variable(7) # needs cvxopt Traceback (most recent call last): ... IndexError: list index out of range @@ -1035,21 +1041,23 @@ cdef class SemidefiniteProgram(SageObject): sage: b3 = matrix([[3, 3.], [3., 3.]]) sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) - sage: p.solve() # tol 1e-08 # optional - cvxopt + + sage: # needs cvxopt + sage: p.solve() # tol 1e-08 -3.0 - sage: B1 = p.slack(1); B1 # tol 1e-08 # optional - cvxopt + sage: B1 = p.slack(1); B1 # tol 1e-08 [0.0 0.0] [0.0 0.0] - sage: B1.is_positive_definite() # optional - cvxopt + sage: B1.is_positive_definite() True - sage: x = sorted(p.get_values(x).values()) # optional - cvxopt - sage: x[0]*b1 + x[1]*b2 - b3 + B1 # tol 1e-09 # optional - cvxopt + sage: x = sorted(p.get_values(x).values()) + sage: x[0]*b1 + x[1]*b2 - b3 + B1 # tol 1e-09 [0.0 0.0] [0.0 0.0] TESTS:: - sage: p.slack(7) # optional - cvxopt + sage: p.slack(7) # needs cvxopt Traceback (most recent call last): ... IndexError: list index out of range @@ -1066,7 +1074,6 @@ cdef class SemidefiniteProgram(SageObject): (If you do not know which solver you are using, then you are using CVXOPT). - INPUT: - ``name`` (string) -- the parameter @@ -1076,20 +1083,22 @@ cdef class SemidefiniteProgram(SageObject): EXAMPLES:: - sage: p. = SemidefiniteProgram(solver = "cvxopt", maximization = False) # optional - cvxopt - sage: p.solver_parameter("show_progress", True) # optional - cvxopt - sage: p.solver_parameter("show_progress") # optional - cvxopt + sage: # needs cvxopt + sage: p. = SemidefiniteProgram(solver="cvxopt", + ....: maximization=False) + sage: p.solver_parameter("show_progress", True) + sage: p.solver_parameter("show_progress") True - sage: p.set_objective(x[0] - x[1]) # optional - cvxopt + sage: p.set_objective(x[0] - x[1]) sage: a1 = matrix([[1, 2.], [2., 3.]]) sage: a2 = matrix([[3, 4.], [4., 2.]]) sage: a3 = matrix([[5, 6.], [6., 7.]]) sage: b1 = matrix([[1, 1.], [1., 1.]]) sage: b2 = matrix([[2, 2.], [2., 1.]]) sage: b3 = matrix([[3, 3.], [3., 3.]]) - sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) # optional - cvxopt - sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) # optional - cvxopt - sage: N(p.solve(),4) # optional - cvxopt + sage: p.add_constraint(a1*x[0] + a2*x[1] <= a3) + sage: p.add_constraint(b1*x[0] + b2*x[1] <= b3) + sage: N(p.solve(), 4) pcost dcost gap pres dres k/t 0: 1... ... @@ -1177,13 +1186,14 @@ class SDPSolverException(RuntimeError): No solution:: - sage: p = SemidefiniteProgram(solver="cvxopt") # optional - cvxopt - sage: x = p.new_variable() # optional - cvxopt - sage: p.set_objective(x[0]) # optional - cvxopt + sage: # needs cvxopt + sage: p = SemidefiniteProgram(solver="cvxopt") + sage: x = p.new_variable() + sage: p.set_objective(x[0]) sage: a = matrix([[1,2],[2,4]]) sage: b = matrix([[1,9],[9,4]]) - sage: p.add_constraint( a*x[0] == b ) # optional - cvxopt - sage: p.solve() # optional - cvxopt + sage: p.add_constraint(a*x[0] == b) + sage: p.solve() Traceback (most recent call last): ... SDPSolverException: ... @@ -1220,7 +1230,6 @@ cdef class SDPVariable(Element): - ``sdp`` -- :class:`SemidefiniteProgram`. The underlying linear program. - - ``name`` -- A name for the ``SDPVariable``. - ``lower_bound``, ``upper_bound`` -- lower bound and upper @@ -1244,7 +1253,7 @@ cdef class SDPVariable(Element): def __getitem__(self, i): r""" - Returns the symbolic variable corresponding to the key. + Return the symbolic variable corresponding to the key. Returns the element asked, otherwise creates it. @@ -1275,8 +1284,8 @@ cdef class SDPVariable(Element): EXAMPLES:: - sage: p=SemidefiniteProgram() - sage: v=p.new_variable() + sage: p = SemidefiniteProgram() + sage: v = p.new_variable() sage: v SDPVariable """ diff --git a/src/sage/plot/contour_plot.py b/src/sage/plot/contour_plot.py index 9c70ebd3e49..fd175d5eceb 100644 --- a/src/sage/plot/contour_plot.py +++ b/src/sage/plot/contour_plot.py @@ -891,7 +891,7 @@ def f(x,y): return cos(x) + sin(y) F, ranges = setup_for_eval_on_grid(ev, [xrange, yrange], options['plot_points']) h = F[0] - xrange, yrange = [r[:2] for r in ranges] + xrange, yrange = (r[:2] for r in ranges) xy_data_array = [[h(x, y) for x in xsrange(*ranges[0], include_endpoint=True)] @@ -1000,7 +1000,7 @@ def f(x,y): return cos(x) + sin(y) F, ranges = setup_for_eval_on_grid(ev, [xrange, yrange], options['plot_points']) h = F[0] - xrange, yrange = [r[:2] for r in ranges] + xrange, yrange = (r[:2] for r in ranges) # ...and a function whose values are shifted towards # z0 by "tol". @@ -1690,7 +1690,7 @@ def region_plot(f, xrange, yrange, **options): f_all, ranges = setup_for_eval_on_grid(feqs + f, [xrange, yrange], plot_points) - xrange, yrange = [r[:2] for r in ranges] + xrange, yrange = (r[:2] for r in ranges) xy_data_arrays = numpy.asarray([[[func(x, y) for x in xsrange(*ranges[0], diff --git a/src/sage/plot/density_plot.py b/src/sage/plot/density_plot.py index 8d6123ff226..e2ffbb6d453 100644 --- a/src/sage/plot/density_plot.py +++ b/src/sage/plot/density_plot.py @@ -307,7 +307,7 @@ def f(x,y): return x**2 * cos(x*y) from sage.rings.real_double import RDF g, ranges = setup_for_eval_on_grid([f], [xrange, yrange], options['plot_points']) g = g[0] - xrange, yrange = [r[:2] for r in ranges] + xrange, yrange = (r[:2] for r in ranges) xy_data_array = [[RDF(g(x,y)) for x in xsrange(*ranges[0], include_endpoint=True)] for y in xsrange(*ranges[1], include_endpoint=True)] diff --git a/src/sage/plot/plot3d/base.pyx b/src/sage/plot/plot3d/base.pyx index 85510d0c33a..253f152130c 100644 --- a/src/sage/plot/plot3d/base.pyx +++ b/src/sage/plot/plot3d/base.pyx @@ -63,8 +63,8 @@ from sage.misc.temporary_file import tmp_filename from sage.misc.fast_methods cimport hash_by_id from sage.modules.free_module_element import vector from sage.rings.real_double import RDF -from .texture import Texture -from .transform cimport Transformation, point_c, face_c +from sage.plot.plot3d.texture import Texture +from sage.plot.plot3d.transform cimport Transformation, point_c, face_c include "point_c.pxi" from sage.interfaces.tachyon import tachyon_rt @@ -502,7 +502,7 @@ cdef class Graphics3d(SageObject): js_options['axesLabelsStyle'] = None if js_options['axesLabelsStyle'] is not None: - from .shapes import _validate_threejs_text_style + from sage.plot.plot3d.shapes import _validate_threejs_text_style style = js_options['axesLabelsStyle'] if isinstance(style, dict): style = _validate_threejs_text_style(style) @@ -1552,7 +1552,7 @@ end_scene""".format( T = [xyz_min[i] - a_min[i] for i in range(3)] X = X.translate(T) if frame: - from .shapes2 import frame3d, frame_labels + from sage.plot.plot3d.shapes2 import frame3d, frame_labels F = frame3d(xyz_min, xyz_max, opacity=0.5, color=(0,0,0), thickness=thickness) if labels: F += frame_labels(xyz_min, xyz_max, a_min_orig, a_max_orig) @@ -1561,7 +1561,7 @@ end_scene""".format( if axes: # draw axes - from .shapes import arrow3d + from sage.plot.plot3d.shapes import arrow3d A = (arrow3d((min(0,a_min[0]),0, 0), (max(0,a_max[0]), 0,0), thickness, color="blue"), arrow3d((0,min(0,a_min[1]), 0), (0, max(0,a_max[1]), 0), diff --git a/src/sage/plot/plot3d/index_face_set.pxd b/src/sage/plot/plot3d/index_face_set.pxd index 3b42507ff62..5a81bd32de1 100644 --- a/src/sage/plot/plot3d/index_face_set.pxd +++ b/src/sage/plot/plot3d/index_face_set.pxd @@ -1,5 +1,6 @@ -from .base cimport PrimitiveObject -from .transform cimport point_c, face_c, color_c +from sage.plot.plot3d.base cimport PrimitiveObject +from sage.plot.plot3d.transform cimport point_c, face_c, color_c + cdef class IndexFaceSet(PrimitiveObject): cdef bint enclosed @@ -13,15 +14,18 @@ cdef class IndexFaceSet(PrimitiveObject): # array used as storage for _faces[i].vertices cdef int* face_indices + cdef class FaceIter: cdef Py_ssize_t i cdef IndexFaceSet set + cdef class EdgeIter: cdef Py_ssize_t i, j cdef object seen cdef IndexFaceSet set + cdef class VertexIter: cdef Py_ssize_t i cdef IndexFaceSet set diff --git a/src/sage/plot/plot3d/index_face_set.pyx b/src/sage/plot/plot3d/index_face_set.pyx index af5a9cfd32b..265bfc01513 100644 --- a/src/sage/plot/plot3d/index_face_set.pyx +++ b/src/sage/plot/plot3d/index_face_set.pyx @@ -62,7 +62,7 @@ from sage.plot.colors import Color, float_to_integer from sage.plot.plot3d.base import Graphics3dGroup from sage.plot.plot3d.texture import Texture -from .transform cimport Transformation +from sage.plot.plot3d.transform cimport Transformation # -------------------------------------------------------------------- @@ -1550,7 +1550,7 @@ cdef class IndexFaceSet(PrimitiveObject): str(self.fcount + extra_faces), faces] - from .base import flatten_list + from sage.plot.plot3d.base import flatten_list name = render_params.unique_name('obj') all = flatten_list(all) if render_params.output_archive: diff --git a/src/sage/plot/plot3d/parametric_surface.pxd b/src/sage/plot/plot3d/parametric_surface.pxd index 47265921622..82ac1164f8a 100644 --- a/src/sage/plot/plot3d/parametric_surface.pxd +++ b/src/sage/plot/plot3d/parametric_surface.pxd @@ -1,5 +1,6 @@ -from .index_face_set cimport IndexFaceSet -from .transform cimport point_c +from sage.plot.plot3d.index_face_set cimport IndexFaceSet +from sage.plot.plot3d.transform cimport point_c + cdef class ParametricSurface(IndexFaceSet): cdef object f diff --git a/src/sage/plot/plot3d/parametric_surface.pyx b/src/sage/plot/plot3d/parametric_surface.pyx index f62bc08b1a7..7399314961d 100644 --- a/src/sage/plot/plot3d/parametric_surface.pyx +++ b/src/sage/plot/plot3d/parametric_surface.pyx @@ -122,8 +122,8 @@ from math import cos, sin from sage.rings.real_double import RDF from sage.plot.colors import check_color_data -from .base import RenderParams -from .transform cimport point_c, face_c +from sage.plot.plot3d.base import RenderParams +from sage.plot.plot3d.transform cimport point_c, face_c from sage.ext.interpreters.wrapper_rdf cimport Wrapper_rdf include "point_c.pxi" diff --git a/src/sage/plot/plot3d/plot_field3d.py b/src/sage/plot/plot3d/plot_field3d.py index d93d95cba57..a2c04f137a3 100644 --- a/src/sage/plot/plot3d/plot_field3d.py +++ b/src/sage/plot/plot3d/plot_field3d.py @@ -129,7 +129,7 @@ def plot_vector_field3d(functions, xrange, yrange, zrange, Graphics3d Object """ (ff, gg, hh), ranges = setup_for_eval_on_grid(functions, [xrange, yrange, zrange], plot_points) - xpoints, ypoints, zpoints = [srange(*r, include_endpoint=True) for r in ranges] + xpoints, ypoints, zpoints = (srange(*r, include_endpoint=True) for r in ranges) points = [vector((i, j, k)) for i in xpoints for j in ypoints for k in zpoints] vectors = [vector((ff(*point), gg(*point), hh(*point))) for point in points] diff --git a/src/sage/plot/plot3d/shapes.pxd b/src/sage/plot/plot3d/shapes.pxd index 37a85c19223..d01e2a7460d 100644 --- a/src/sage/plot/plot3d/shapes.pxd +++ b/src/sage/plot/plot3d/shapes.pxd @@ -1,4 +1,4 @@ -from .parametric_surface cimport ParametricSurface +from sage.plot.plot3d.parametric_surface cimport ParametricSurface cdef class Cone(ParametricSurface): @@ -6,13 +6,16 @@ cdef class Cone(ParametricSurface): cdef double height cdef bint closed + cdef class Cylinder(ParametricSurface): cdef double radius cdef double height cdef bint closed + cdef class Sphere(ParametricSurface): cdef double radius + cdef class Torus(ParametricSurface): cdef double R, r diff --git a/src/sage/plot/plot3d/shapes.pyx b/src/sage/plot/plot3d/shapes.pyx index f5c98fe3929..e184075b23b 100644 --- a/src/sage/plot/plot3d/shapes.pyx +++ b/src/sage/plot/plot3d/shapes.pyx @@ -56,9 +56,9 @@ from libc.math cimport sqrt, sin, cos, acos, M_PI from sage.rings.real_double import RDF from sage.modules.free_module_element import vector from sage.misc.decorators import rename_keyword -from .base import Graphics3dGroup -from .index_face_set cimport IndexFaceSet, PrimitiveObject -from .transform cimport point_c +from sage.plot.plot3d.base import Graphics3dGroup +from sage.plot.plot3d.index_face_set cimport IndexFaceSet, PrimitiveObject +from sage.plot.plot3d.transform cimport point_c # Helper function to check that Box input is right @@ -245,7 +245,7 @@ def ColorCube(size, colors, opacity=1, **kwds): all = [] kwds['opacity'] = opacity - from .texture import Texture + from sage.plot.plot3d.texture import Texture for k in range(6): all.append(IndexFaceSet([faces[k]], enclosed=True, texture=Texture(colors[k], opacity=opacity), @@ -1330,7 +1330,7 @@ def _validate_threejs_text_style(style): """ default_color = '#000000' # black color = style.get('color', default_color) - from .texture import Texture + from sage.plot.plot3d.texture import Texture try: texture = Texture(color=color) except ValueError: diff --git a/src/sage/quadratic_forms/binary_qf.py b/src/sage/quadratic_forms/binary_qf.py index 6516888e3ac..0f32bba92ba 100755 --- a/src/sage/quadratic_forms/binary_qf.py +++ b/src/sage/quadratic_forms/binary_qf.py @@ -144,7 +144,7 @@ def __init__(self, a, b=None, c=None): elif (isinstance(a, MPolynomial) and a.is_homogeneous() and a.base_ring() == ZZ and a.degree() == 2 and a.parent().ngens() == 2): x, y = a.parent().gens() - a, b, c = [a.monomial_coefficient(mon) for mon in [x**2, x*y, y**2]] + a, b, c = (a.monomial_coefficient(mon) for mon in [x**2, x*y, y**2]) elif isinstance(a, pari_gen) and a.type() in ('t_QFI', 't_QFR', 't_QFB'): # a has 3 or 4 components a, b, c = a[0], a[1], a[2] diff --git a/src/sage/quadratic_forms/ternary_qf.py b/src/sage/quadratic_forms/ternary_qf.py index 4184c839528..fa4499566a9 100644 --- a/src/sage/quadratic_forms/ternary_qf.py +++ b/src/sage/quadratic_forms/ternary_qf.py @@ -97,7 +97,7 @@ def __init__(self, v): if len(v) != 6: # Check we have six coefficients raise ValueError("Ternary quadratic form must be given by a list of six coefficients") - self._a, self._b, self._c, self._r, self._s, self._t = [ZZ(x) for x in v] + self._a, self._b, self._c, self._r, self._s, self._t = (ZZ(x) for x in v) self._automorphisms = None self._number_of_automorphisms = None diff --git a/src/sage/rings/abc.pyx b/src/sage/rings/abc.pyx index 6ad9dd8d6f0..028cade2bba 100644 --- a/src/sage/rings/abc.pyx +++ b/src/sage/rings/abc.pyx @@ -66,13 +66,13 @@ class UniversalCyclotomicField(Field): EXAMPLES:: sage: import sage.rings.abc - sage: K = UniversalCyclotomicField() # needs sage.rings.number_field - sage: isinstance(K, sage.rings.abc.UniversalCyclotomicField) # needs sage.rings.number_field + sage: K = UniversalCyclotomicField() # needs sage.libs.gap sage.rings.number_field + sage: isinstance(K, sage.rings.abc.UniversalCyclotomicField) # needs sage.libs.gap sage.rings.number_field True By design, there is a unique direct subclass:: - sage: sage.rings.abc.UniversalCyclotomicField.__subclasses__() # needs sage.rings.number_field + sage: sage.rings.abc.UniversalCyclotomicField.__subclasses__() # needs sage.libs.gap sage.rings.number_field [] sage: len(sage.rings.abc.NumberField_cyclotomic.__subclasses__()) <= 1 diff --git a/src/sage/rings/complex_arb.pyx b/src/sage/rings/complex_arb.pyx index f36a89bb229..1e3085c9215 100644 --- a/src/sage/rings/complex_arb.pyx +++ b/src/sage/rings/complex_arb.pyx @@ -4014,7 +4014,7 @@ cdef class ComplexBall(RingElement): [2.2882956833435e+50 +/- ...e+36], [1.2807602335816e+51 +/- ...e+37]) sage: ai, aip, bi, bip = CBF(1,2).airy() - sage: (ai * bip - bi * aip) * CBF(pi) + sage: (ai * bip - bi * aip) * CBF(pi) # needs sage.symbolic [1.0000000000000 +/- ...e-15] + [+/- ...e-16]*I """ diff --git a/src/sage/rings/complex_double.pyx b/src/sage/rings/complex_double.pyx index ed46913433f..8f1e8205817 100644 --- a/src/sage/rings/complex_double.pyx +++ b/src/sage/rings/complex_double.pyx @@ -796,11 +796,11 @@ cdef class ComplexDoubleElement(FieldElement): EXAMPLES:: - sage: CDF(1.2) > CDF(i) + sage: CDF(1.2) > CDF(i) # needs sage.symbolic True sage: CDF(1) < CDF(2) True - sage: CDF(1 + i) > CDF(-1 - i) + sage: CDF(1 + i) > CDF(-1 - i) # needs sage.symbolic True :: @@ -2551,11 +2551,12 @@ cdef class ComplexToCDF(Morphism): EXAMPLES:: - sage: import numpy # needs numpy - sage: f = CDF.coerce_map_from(numpy.complex_) # needs numpy - sage: f(numpy.complex_(I)) # needs numpy + sage: # needs numpy + sage: import numpy + sage: f = CDF.coerce_map_from(numpy.complex_) + sage: f(numpy.complex_(I)) 1.0*I - sage: f(numpy.complex_(I)).parent() # needs numpy + sage: f(numpy.complex_(I)).parent() Complex Double Field """ def __init__(self, R): diff --git a/src/sage/rings/complex_interval_field.py b/src/sage/rings/complex_interval_field.py index 5c5e6bbb906..7903ab42bae 100644 --- a/src/sage/rings/complex_interval_field.py +++ b/src/sage/rings/complex_interval_field.py @@ -484,19 +484,19 @@ def _coerce_map_from_(self, S): Coercion map: From: Set of Python objects of class 'int' To: Complex Interval Field with 53 bits of precision - sage: CIF.coerce_map_from(GaussianIntegers()) + sage: CIF.coerce_map_from(GaussianIntegers()) # needs sage.rings.number_field Conversion via _complex_mpfi_ method map: From: Gaussian Integers in Number Field in I with defining polynomial x^2 + 1 with I = 1*I To: Complex Interval Field with 53 bits of precision - sage: CIF.coerce_map_from(QQbar) + sage: CIF.coerce_map_from(QQbar) # needs sage.rings.number_field Conversion via _complex_mpfi_ method map: From: Algebraic Field To: Complex Interval Field with 53 bits of precision - sage: CIF.coerce_map_from(AA) + sage: CIF.coerce_map_from(AA) # needs sage.rings.number_field Conversion via _complex_mpfi_ method map: From: Algebraic Real Field To: Complex Interval Field with 53 bits of precision - sage: CIF.coerce_map_from(UniversalCyclotomicField()) + sage: CIF.coerce_map_from(UniversalCyclotomicField()) # needs sage.libs.gap sage.rings.number_field Conversion via _complex_mpfi_ method map: From: Universal Cyclotomic Field To: Complex Interval Field with 53 bits of precision @@ -532,9 +532,9 @@ def _repr_(self): EXAMPLES:: - sage: ComplexIntervalField() # indirect doctest + sage: ComplexIntervalField() # indirect doctest Complex Interval Field with 53 bits of precision - sage: ComplexIntervalField(100) # indirect doctest + sage: ComplexIntervalField(100) # indirect doctest Complex Interval Field with 100 bits of precision """ return "Complex Interval Field with %s bits of precision" % self._prec diff --git a/src/sage/rings/continued_fraction.py b/src/sage/rings/continued_fraction.py index e701c917062..1980d55b27c 100644 --- a/src/sage/rings/continued_fraction.py +++ b/src/sage/rings/continued_fraction.py @@ -157,7 +157,7 @@ Nevertheless, the tail is preserved under invertible integer homographies:: - sage: # needs sage.rings.number_field + sage: # needs sage.modular sage.rings.number_field sage: apply_homography = lambda m,z: (m[0,0]*z + m[0,1]) / (m[1,0]*z + m[1,1]) sage: m1 = SL2Z([60,13,83,18]) sage: m2 = SL2Z([27,80,28,83]) diff --git a/src/sage/rings/derivation.py b/src/sage/rings/derivation.py index 26b6f2d5905..44182627cfc 100644 --- a/src/sage/rings/derivation.py +++ b/src/sage/rings/derivation.py @@ -1580,7 +1580,7 @@ def __init__(self, parent, arg=None): TESTS:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.singular sage: from sage.rings.derivation import RingDerivationWithoutTwist_wrapper sage: R. = GF(5)[] sage: S = R.quo([x^5, y^5]) @@ -1588,8 +1588,7 @@ def __init__(self, parent, arg=None): sage: der = M.random_element() sage: isinstance(der, RingDerivationWithoutTwist_wrapper) True - - sage: TestSuite(der).run() # needs sage.rings.finite_rings + sage: TestSuite(der).run() """ if isinstance(arg, list) and len(arg) == 1 and isinstance(arg[0], RingDerivation): @@ -1620,7 +1619,7 @@ def _add_(self, other): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.singular sage: R. = GF(5)[] sage: S. = R.quo([X^5, Y^5]) sage: Dx = S.derivation(x) @@ -1637,7 +1636,7 @@ def _sub_(self, other): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.singular sage: R. = GF(5)[] sage: S. = R.quo([X^5, Y^5]) sage: Dx = S.derivation(x) @@ -1654,7 +1653,7 @@ def _neg_(self): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.singular sage: R. = GF(5)[] sage: S. = R.quo([X^5, Y^5]) sage: Dx = S.derivation(x) @@ -1670,7 +1669,7 @@ def _lmul_(self, factor): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.singular sage: R. = GF(5)[] sage: S. = R.quo([X^5, Y^5]) sage: Dx = S.derivation(x) @@ -1688,7 +1687,7 @@ def _rmul_(self, factor): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.singular sage: R. = GF(5)[] sage: S. = R.quo([X^5, Y^5]) sage: Dx = S.derivation(x) @@ -1707,21 +1706,19 @@ def list(self): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.singular sage: R. = GF(5)[] sage: S. = R.quo([X^5, Y^5]) sage: M = S.derivation_module() sage: M.basis() Family (d/dx, d/dy) - - sage: S.derivation(x).list() # needs sage.rings.finite_rings + sage: S.derivation(x).list() [1, 0] - sage: S.derivation(y).list() # needs sage.rings.finite_rings + sage: S.derivation(y).list() [0, 1] - - sage: f = x*S.derivation(x) + y*S.derivation(y); f # needs sage.rings.finite_rings + sage: f = x*S.derivation(x) + y*S.derivation(y); f x*d/dx + y*d/dy - sage: f.list() # needs sage.rings.finite_rings + sage: f.list() [x, y] """ @@ -2000,7 +1997,7 @@ def _call_(self, x): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.singular sage: R. = GF(5)[] sage: S. = R.quo([X^5, Y^5]) sage: f = x^3*S.derivation(); f diff --git a/src/sage/rings/factorint.pyx b/src/sage/rings/factorint.pyx index ad0b735eaaa..e3b0e9f034f 100644 --- a/src/sage/rings/factorint.pyx +++ b/src/sage/rings/factorint.pyx @@ -50,6 +50,8 @@ cpdef aurifeuillian(n, m, F=None, bint check=True) noexcept: EXAMPLES:: sage: from sage.rings.factorint import aurifeuillian + + sage: # needs sage.libs.pari sage.rings.real_interval_field sage: aurifeuillian(2, 2) [5, 13] sage: aurifeuillian(2, 2^5) @@ -58,6 +60,8 @@ cpdef aurifeuillian(n, m, F=None, bint check=True) noexcept: [1471, 2851] sage: aurifeuillian(15, 1) [19231, 142111] + + sage: # needs sage.libs.pari sage: aurifeuillian(12, 3) Traceback (most recent call last): ... @@ -76,8 +80,6 @@ cpdef aurifeuillian(n, m, F=None, bint check=True) noexcept: There is no need to set `F`. It's only for increasing speed of :meth:`factor_aurifeuillian()`. """ - from sage.arith.misc import euler_phi - from sage.rings.real_mpfi import RealIntervalField if check: if not n.is_squarefree(): raise ValueError("n has to be square-free") @@ -85,6 +87,10 @@ cpdef aurifeuillian(n, m, F=None, bint check=True) noexcept: raise ValueError("n has to be greater than 1") if m < 1: raise ValueError("m has to be positive") + + from sage.arith.misc import euler_phi + from sage.rings.real_mpfi import RealIntervalField + x = m**2*n cdef Py_ssize_t y = euler_phi(2*n)//2 if F is None: @@ -129,7 +135,7 @@ cpdef factor_aurifeuillian(n, check=True) noexcept: EXAMPLES:: - sage: # needs sage.libs.pari + sage: # needs sage.libs.pari sage.rings.real_interval_field sage: from sage.rings.factorint import factor_aurifeuillian as fa sage: fa(2^6 + 1) [5, 13] @@ -148,7 +154,8 @@ cpdef factor_aurifeuillian(n, check=True) noexcept: TESTS:: - sage: for n in [2,3,5,6,30,31,33]: # needs sage.libs.pari + sage: # needs sage.libs.pari sage.rings.real_interval_field + sage: for n in [2,3,5,6,30,31,33]: ....: for m in [8,96,109201283]: ....: s = -1 if n % 4 == 1 else 1 ....: y = (m^2*n)^n + s diff --git a/src/sage/rings/fast_arith.pyx b/src/sage/rings/fast_arith.pyx index 5d43ed41c6f..d3695ebb69f 100644 --- a/src/sage/rings/fast_arith.pyx +++ b/src/sage/rings/fast_arith.pyx @@ -148,8 +148,8 @@ cpdef prime_range(start, stop=None, algorithm=None, bint py_ints=False) noexcept """ # input to pari.init_primes cannot be greater than 436273290 (hardcoded bound) DEF init_primes_max = 436273290 - DEF small_prime_max = 436273009 # a prime < init_primes_max (preferably the largest) - DEF prime_gap_bound = 250 # upper bound for gap between primes <= small_prime_max + DEF small_prime_max = 436273009 # a prime < init_primes_max (preferably the largest) + DEF prime_gap_bound = 250 # upper bound for gap between primes <= small_prime_max # make sure that start and stop are integers # First try coercing them. If that does not work, then try rounding them. @@ -160,7 +160,8 @@ cpdef prime_range(start, stop=None, algorithm=None, bint py_ints=False) noexcept start = Integer(round(float(start))) except (ValueError, TypeError) as real_error: raise TypeError(str(integer_error) - + "\nand argument is also not real: " + str(real_error)) + + "\nand argument is also not real: " + + str(real_error)) if stop is not None: try: stop = Integer(stop) @@ -169,7 +170,8 @@ cpdef prime_range(start, stop=None, algorithm=None, bint py_ints=False) noexcept stop = Integer(round(float(stop))) except (ValueError, TypeError) as real_error: raise ValueError(str(integer_error) - + "\nand argument is also not real: " + str(real_error)) + + "\nand argument is also not real: " + + str(real_error)) if algorithm is None: # if 'stop' is 'None', need to change it to an integer before comparing with 'start' @@ -183,8 +185,8 @@ cpdef prime_range(start, stop=None, algorithm=None, bint py_ints=False) noexcept from sage.libs.pari import pari if max(start, stop or 0) > small_prime_max: - raise ValueError('algorithm "pari_primes" is limited to primes larger than' - + ' {}'.format(small_prime_max - 1)) + raise ValueError('algorithm "pari_primes" is limited to primes ' + f'larger than {small_prime_max - 1}') if stop is None: # In this case, "start" is really stop @@ -206,7 +208,7 @@ cpdef prime_range(start, stop=None, algorithm=None, bint py_ints=False) noexcept res = pari_prime_range(start, stop, py_ints) - elif (algorithm == "pari_isprime") or (algorithm == "pari_primes"): + elif algorithm == "pari_isprime" or algorithm == "pari_primes": from sage.arith.misc import primes res = list(primes(start, stop)) else: @@ -227,12 +229,14 @@ cdef class arith_int: cdef int c_gcd_int(self, int a, int b) except -1: cdef int c - if a==0: + if a == 0: return self.abs_int(b) - if b==0: + if b == 0: return self.abs_int(a) - if a<0: a=-a - if b<0: b=-b + if a < 0: + a = -a + if b < 0: + b = -b while b: c = a % b a = b @@ -240,7 +244,7 @@ cdef class arith_int: return a def gcd_int(self, int a, int b): - return self.c_gcd_int(a,b) + return self.c_gcd_int(a, b) cdef int c_xgcd_int(self, int a, int b, int* ss, int* tt) except -1: cdef int psign, qsign, p, q, r, s, c, quot, new_r, new_s @@ -255,34 +259,47 @@ cdef class arith_int: tt[0] = 0 return self.abs_int(a) - psign = 1; qsign = 1 + psign = 1 + qsign = 1 - if a<0: a = -a; psign = -1 - if b<0: b = -b; qsign = -1 + if a < 0: + a = -a + psign = -1 + if b < 0: + b = -b + qsign = -1 - p = 1; q = 0; r = 0; s = 1 + p = 1 + q = 0 + r = 0 + s = 1 while b: - c = a % b; quot = a/b - a = b; b = c - new_r = p - quot*r - new_s = q - quot*s - p = r; q = s - r = new_r; s = new_s + c = a % b + quot = a / b + a = b + b = c + new_r = p - quot * r + new_s = q - quot * s + p = r + q = s + r = new_r + s = new_s - ss[0] = p*psign - tt[0] = q*qsign + ss[0] = p * psign + tt[0] = q * qsign return a def xgcd_int(self, int a, int b): cdef int g, s, t - g = self.c_xgcd_int(a,b, &s, &t) - return (g,s,t) + g = self.c_xgcd_int(a, b, &s, &t) + return (g, s, t) cdef int c_inverse_mod_int(self, int a, int m) except -1: - if a == 1 or m<=1: return a%m # common special case + if a == 1 or m <= 1: + return a % m # common special case cdef int g, s, t - g = self.c_xgcd_int(a,m, &s, &t) + g = self.c_xgcd_int(a, m, &s, &t) if g != 1: raise ArithmeticError("The inverse of %s modulo %s is not defined." % (a, m)) s = s % m @@ -297,19 +314,21 @@ cdef class arith_int: cdef int u, v, u0, u1, u2, v0, v1, v2, q, t0, t1, t2, x, y cdef float bnd - if m>46340: - raise OverflowError("The modulus m(=%s) should be at most 46340"%m) + if m > 46340: + raise OverflowError(f"The modulus m(={m}) should be at most 46340") a = a % m - if a==0 or m == 0: + if a == 0 or m == 0: n[0] = 0 d[0] = 1 return 0 - if m<0: m = -m - if a<0: a = m - a - if a==1: + if m < 0: + m = -m + if a < 0: + a = m - a + if a == 1: n[0] = 1 d[0] = 1 return 0 @@ -317,17 +336,29 @@ cdef class arith_int: u = m v = a bnd = sqrt(m/2.0) - u0=1; u1=0; u2=u - v0=0; v1=1; v2=v + u0 = 1 + u1 = 0 + u2 = u + v0 = 0 + v1 = 1 + v2 = v while self.abs_int(v2) > bnd: - q = u2/v2 # floor is implicit - t0=u0-q*v0; t1=u1-q*v1; t2=u2-q*v2 - u0=v0; u1=v1; u2=v2 - v0=t0; v1=t1; v2=t2 - - x = self.abs_int(v1); y = v2 - if v1<0: y = -1*y - if x<=bnd and self.c_gcd_int(x,y)==1: + q = u2 / v2 # floor is implicit + t0 = u0 - q * v0 + t1 = u1 - q * v1 + t2 = u2 - q * v2 + u0 = v0 + u1 = v1 + u2 = v2 + v0 = t0 + v1 = t1 + v2 = t2 + + x = self.abs_int(v1) + y = v2 + if v1 < 0: + y = -1*y + if x <= bnd and self.c_gcd_int(x, y) == 1: n[0] = y d[0] = x return 0 @@ -342,7 +373,7 @@ cdef class arith_int: """ cdef int n, d self.c_rational_recon_int(a, m, &n, &d) - return (n,d) + return (n, d) # The long long versions are next. @@ -375,7 +406,7 @@ cdef class arith_llong: return a def gcd_longlong(self, long long a, long long b): - return self.c_gcd_longlong(a,b) + return self.c_gcd_longlong(a, b) cdef long long c_xgcd_longlong(self, long long a, long long b, long long *ss, @@ -392,30 +423,42 @@ cdef class arith_llong: tt[0] = 0 return self.abs_longlong(a) - psign = 1; qsign = 1 + psign = 1 + qsign = 1 - if a<0: a = -a; psign = -1 - if b<0: b = -b; qsign = -1 + if a < 0: + a = -a + psign = -1 + if b < 0: + b = -b + qsign = -1 - p = 1; q = 0; r = 0; s = 1 + p = 1 + q = 0 + r = 0 + s = 1 while b: - c = a % b; quot = a/b - a = b; b = c - new_r = p - quot*r - new_s = q - quot*s - p = r; q = s - r = new_r; s = new_s + c = a % b + quot = a / b + a = b + b = c + new_r = p - quot * r + new_s = q - quot * s + p = r + q = s + r = new_r + s = new_s - ss[0] = p*psign - tt[0] = q*qsign + ss[0] = p * psign + tt[0] = q * qsign return a cdef long long c_inverse_mod_longlong(self, long long a, long long m) except -1: cdef long long g, s, t - g = self.c_xgcd_longlong(a,m, &s, &t) + g = self.c_xgcd_longlong(a, m, &s, &t) if g != 1: - raise ArithmeticError("The inverse of %s modulo %s is not defined."%(a,m)) + raise ArithmeticError("The inverse of %s modulo %s is not defined." % (a, m)) s = s % m if s < 0: s = s + m @@ -430,18 +473,20 @@ cdef class arith_llong: cdef float bnd if m > 2147483647: - raise OverflowError("The modulus m(=%s) must be at most 2147483647"%m) + raise OverflowError(f"The modulus m(={m}) must be at most 2147483647") a = a % m - if a==0 or m == 0: + if a == 0 or m == 0: n[0] = 0 d[0] = 1 return 0 - if m<0: m = -m - if a<0: a = m - a - if a==1: + if m < 0: + m = -m + if a < 0: + a = m - a + if a == 1: n[0] = 1 d[0] = 1 return 0 @@ -449,17 +494,29 @@ cdef class arith_llong: u = m v = a bnd = sqrt(m/2.0) - u0=1; u1=0; u2=u - v0=0; v1=1; v2=v + u0 = 1 + u1 = 0 + u2 = u + v0 = 0 + v1 = 1 + v2 = v while self.abs_longlong(v2) > bnd: - q = u2/v2 # floor is implicit - t0=u0-q*v0; t1=u1-q*v1; t2=u2-q*v2 - u0=v0; u1=v1; u2=v2 - v0=t0; v1=t1; v2=t2 - - x = self.abs_longlong(v1); y = v2 - if v1<0: y = -1*y - if x<=bnd and self.gcd_longlong(x,y)==1: + q = u2 / v2 # floor is implicit + t0 = u0 - q * v0 + t1 = u1 - q * v1 + t2 = u2 - q * v2 + u0 = v0 + u1 = v1 + u2 = v2 + v0 = t0 + v1 = t1 + v2 = t2 + + x = self.abs_longlong(v1) + y = v2 + if v1 < 0: + y = -1*y + if x <= bnd and self.gcd_longlong(x, y) == 1: n[0] = y d[0] = x return 0 @@ -474,4 +531,4 @@ cdef class arith_llong: """ cdef long long n, d self.c_rational_recon_longlong(a, m, &n, &d) - return (n,d) + return (n, d) diff --git a/src/sage/rings/finite_rings/element_base.pyx b/src/sage/rings/finite_rings/element_base.pyx index beeae9fa4c9..8af0867a9f5 100755 --- a/src/sage/rings/finite_rings/element_base.pyx +++ b/src/sage/rings/finite_rings/element_base.pyx @@ -268,6 +268,7 @@ cdef class FinitePolyExtElement(FiniteRingElement): TESTS:: + sage: # needs sage.modules sage: F,t = GF(random_prime(99)^randrange(2,99), 't').objgen() sage: a = F.random_element() sage: all(a[i] == a.polynomial()[i] for i in range(F.degree())) @@ -290,7 +291,7 @@ cdef class FinitePolyExtElement(FiniteRingElement): EXAMPLES:: sage: x = polygen(GF(71)) - sage: F. = GF(71^7, modulus=x^7+x+1) + sage: F. = GF(71^7, modulus=x^7 + x + 1) sage: a = 3 + u + 3*u^2 + 3*u^3 + 7*u^4 sage: a.list() [3, 1, 3, 3, 7, 0, 0] @@ -308,6 +309,7 @@ cdef class FinitePolyExtElement(FiniteRingElement): TESTS:: + sage: # needs sage.modules sage: R. = GF(17)[] sage: F. = GF(17^60) sage: a = F.random_element() @@ -351,6 +353,7 @@ cdef class FinitePolyExtElement(FiniteRingElement): TESTS:: + sage: # needs sage.modules sage: F = GF(random_prime(333)^randrange(111,999),'t') sage: a = F.random_element() sage: list(a) == a.list() # implicit doctest @@ -358,6 +361,7 @@ cdef class FinitePolyExtElement(FiniteRingElement): :: + sage: # needs sage.modules sage: F. = GF(17^60) sage: a = F.random_element() sage: a == sum(c*t^i for i,c in enumerate(a)) # implicit doctest @@ -365,7 +369,8 @@ cdef class FinitePolyExtElement(FiniteRingElement): :: - sage: F. = GF((2^127-1)^10, 't') + sage: # needs sage.modules + sage: F. = GF((2^127 - 1)^10, 't') sage: a = F.random_element() sage: a == sum(c*t^i for i,c in enumerate(a)) # implicit doctest True @@ -431,6 +436,7 @@ cdef class FinitePolyExtElement(FiniteRingElement): EXAMPLES:: + sage: # needs sage.modules sage: k. = GF(2^4) sage: b = k.random_element() sage: vector(a*b) == a.matrix() * vector(b) @@ -557,18 +563,18 @@ cdef class FinitePolyExtElement(FiniteRingElement): def charpoly(self, var='x', algorithm='pari'): """ - Return the characteristic polynomial of self as a polynomial with given variable. + Return the characteristic polynomial of ``self`` as a polynomial with given variable. INPUT: - ``var`` -- string (default: 'x') - - ``algorithm`` -- string (default: 'pari') + - ``algorithm`` -- string (default: ``'pari'``) - - 'pari' -- use pari's charpoly + - ``'pari'`` -- use pari's charpoly - - 'matrix' -- return the charpoly computed from the matrix of - left multiplication by self + - ``'matrix'`` -- return the charpoly computed from the matrix of + left multiplication by ``self`` The result is not cached. @@ -578,10 +584,10 @@ cdef class FinitePolyExtElement(FiniteRingElement): sage: k. = FiniteField(19^2) sage: parent(a) Finite Field in a of size 19^2 - sage: b=a**20 - sage: p=FinitePolyExtElement.charpoly(b,"x", algorithm="pari") - sage: q=FinitePolyExtElement.charpoly(b,"x", algorithm="matrix") - sage: q == p + sage: b = a**20 + sage: p = FinitePolyExtElement.charpoly(b, "x", algorithm="pari") + sage: q = FinitePolyExtElement.charpoly(b, "x", algorithm="matrix") # needs sage.modules + sage: q == p # needs sage.modules True sage: p x^2 + 15*x + 4 @@ -998,6 +1004,7 @@ cdef class FinitePolyExtElement(FiniteRingElement): Check that :trac:`26761` is fixed:: + sage: # needs sage.libs.gap sage: G32 = GU(3,2) sage: g1, g2 = G32.gens() sage: m1 = g1.matrix() diff --git a/src/sage/rings/finite_rings/element_ntl_gf2e.pyx b/src/sage/rings/finite_rings/element_ntl_gf2e.pyx index ef41e6d8dc1..61e7b05048c 100644 --- a/src/sage/rings/finite_rings/element_ntl_gf2e.pyx +++ b/src/sage/rings/finite_rings/element_ntl_gf2e.pyx @@ -1152,9 +1152,9 @@ cdef class FiniteField_ntl_gf2eElement(FinitePolyExtElement): sage: k. = GF(2^16) sage: b._gap_init_() 'Z(65536)^1' - sage: k(gap('Z(2^16)^3+Z(2^16)^5')) + sage: k(gap('Z(2^16)^3+Z(2^16)^5')) # needs sage.libs.gap b^5 + b^3 - sage: k(libgap.Z(2^16)^3+libgap.Z(2^16)^5) + sage: k(libgap.Z(2^16)^3+libgap.Z(2^16)^5) # needs sage.libs.gap b^5 + b^3 """ F = self._parent diff --git a/src/sage/rings/finite_rings/element_pari_ffelt.pyx b/src/sage/rings/finite_rings/element_pari_ffelt.pyx index 792aa9ce257..9beb505cae3 100644 --- a/src/sage/rings/finite_rings/element_pari_ffelt.pyx +++ b/src/sage/rings/finite_rings/element_pari_ffelt.pyx @@ -202,22 +202,22 @@ cdef class FiniteFieldElement_pari_ffelt(FinitePolyExtElement): sage: F = FiniteField(2^3, 'a', impl='pari_ffelt') sage: a = F.multiplicative_generator(); a a - sage: b = gap(a^3); b + sage: b = gap(a^3); b # needs sage.libs.gap Z(2^3)^3 sage: F(b) a + 1 sage: a^3 a + 1 - sage: a = GF(13)(gap('0*Z(13)')); a + sage: a = GF(13)(gap('0*Z(13)')); a # needs sage.libs.gap 0 sage: a.parent() Finite Field of size 13 sage: F = FiniteField(2^4, 'a', impl='pari_ffelt') - sage: F(gap('Z(16)^3')) + sage: F(gap('Z(16)^3')) # needs sage.libs.gap a^3 - sage: F(gap('Z(16)^2')) + sage: F(gap('Z(16)^2')) # needs sage.libs.gap a^2 You can also call a finite extension field with a string @@ -873,6 +873,7 @@ cdef class FiniteFieldElement_pari_ffelt(FinitePolyExtElement): TESTS:: + sage: # needs sage.modules sage: F. = GF(13^64, impl='pari_ffelt'); F Finite Field in a of size 13^64 sage: x = F.random_element() @@ -885,6 +886,7 @@ cdef class FiniteFieldElement_pari_ffelt(FinitePolyExtElement): sage: x.pth_power(-1)**13 == x True + sage: # needs sage.modules sage: F. = GF(127^16, impl='pari_ffelt'); F Finite Field in a of size 127^16 sage: x = F.random_element() @@ -1386,6 +1388,7 @@ def unpickle_FiniteFieldElement_pari_ffelt(parent, elem): """ EXAMPLES:: + sage: # needs sage.modules sage: k. = GF(2^20, impl='pari_ffelt') sage: e = k.random_element() sage: f = loads(dumps(e)) # indirect doctest diff --git a/src/sage/rings/finite_rings/finite_field_base.pyx b/src/sage/rings/finite_rings/finite_field_base.pyx index c60f3d2ec07..cc2d1b65dd0 100644 --- a/src/sage/rings/finite_rings/finite_field_base.pyx +++ b/src/sage/rings/finite_rings/finite_field_base.pyx @@ -4,6 +4,7 @@ Base class for finite fields TESTS:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 1) # needs sage.rings.number_field sage: F = K.factor(3)[0][0].residue_field() # needs sage.rings.number_field sage: loads(dumps(F)) == F # needs sage.rings.number_field @@ -1238,6 +1239,7 @@ cdef class FiniteField(Field): (0, 1) sage: # needs sage.modules + sage: x = polygen(ZZ) sage: F = GF(9, 't', modulus=x^2 + x - 1) sage: E = GF(81) sage: h = Hom(F,E).an_element() diff --git a/src/sage/rings/finite_rings/finite_field_prime_modn.py b/src/sage/rings/finite_rings/finite_field_prime_modn.py index 95c1803abf4..2c52681e822 100644 --- a/src/sage/rings/finite_rings/finite_field_prime_modn.py +++ b/src/sage/rings/finite_rings/finite_field_prime_modn.py @@ -105,7 +105,7 @@ def _coerce_map_from_(self, S): sage: 12 % 7 5 - sage: ZZ.residue_field(7).hom(GF(7))(1) # See trac 11319 # needs sage.rings.finite_rings + sage: ZZ.residue_field(7).hom(GF(7))(1) # See trac 11319 1 sage: # needs sage.rings.finite_rings sage.rings.number_field @@ -120,12 +120,12 @@ def _coerce_map_from_(self, S): Check that :trac:`19573` is resolved:: - sage: Integers(9).hom(GF(3)) # needs sage.rings.finite_rings + sage: Integers(9).hom(GF(3)) Natural morphism: From: Ring of integers modulo 9 To: Finite Field of size 3 - sage: Integers(9).hom(GF(5)) # needs sage.rings.finite_rings + sage: Integers(9).hom(GF(5)) Traceback (most recent call last): ... TypeError: natural coercion morphism from Ring of integers modulo 9 to Finite Field of size 5 not defined diff --git a/src/sage/rings/finite_rings/integer_mod.pyx b/src/sage/rings/finite_rings/integer_mod.pyx index b2cd1a1fa24..d715cec1493 100644 --- a/src/sage/rings/finite_rings/integer_mod.pyx +++ b/src/sage/rings/finite_rings/integer_mod.pyx @@ -659,7 +659,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: # needs sage.libs.pari + sage: # needs sage.libs.pari sage.modules sage: r = Integers(125) sage: b = r.multiplicative_generator()^3 sage: a = b^17 @@ -823,10 +823,11 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: + sage: m = Mod(3, 1568) - sage: v = m.generalised_log(); v # needs sage.libs.pari + sage: v = m.generalised_log(); v # needs sage.libs.pari sage.modules [1, 3, 1] - sage: prod([Zmod(1568).unit_gens()[i] ** v[i] for i in [0..2]]) # needs sage.libs.pari + sage: prod([Zmod(1568).unit_gens()[i] ** v[i] for i in [0..2]]) # needs sage.libs.pari sage.modules 3 .. SEEALSO:: @@ -922,7 +923,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): 1 sage: a.polynomial() 1 - sage: type(a.polynomial()) # needs sage.rings.finite_rings + sage: type(a.polynomial()) # needs sage.libs.flint """ R = self.parent()[var] diff --git a/src/sage/rings/finite_rings/integer_mod_ring.py b/src/sage/rings/finite_rings/integer_mod_ring.py index 92b99d050ba..a448046f137 100644 --- a/src/sage/rings/finite_rings/integer_mod_ring.py +++ b/src/sage/rings/finite_rings/integer_mod_ring.py @@ -19,13 +19,13 @@ sage: s = GF(7) sage: r.has_coerce_map_from(s) False - sage: s.has_coerce_map_from(r) # needs sage.rings.finite_rings + sage: s.has_coerce_map_from(r) True - sage: s(1) + r(1) # needs sage.rings.finite_rings + sage: s(1) + r(1) 2 - sage: parent(s(1) + r(1)) # needs sage.rings.finite_rings + sage: parent(s(1) + r(1)) Finite Field of size 7 - sage: parent(r(1) + s(1)) # needs sage.rings.finite_rings + sage: parent(r(1) + s(1)) Finite Field of size 7 We list the elements of `\ZZ/3\ZZ`:: diff --git a/src/sage/rings/finite_rings/residue_field.pyx b/src/sage/rings/finite_rings/residue_field.pyx index 17a431f3496..9845266870a 100644 --- a/src/sage/rings/finite_rings/residue_field.pyx +++ b/src/sage/rings/finite_rings/residue_field.pyx @@ -89,7 +89,7 @@ Verify that :trac:`7475` is fixed:: Reducing a curve modulo a prime:: - sage: # needs sage.rings.number_field + sage: # needs sage.rings.number_field sage.schemes sage: K. = NumberField(x^2 + 23) sage: OK = K.ring_of_integers() sage: E = EllipticCurve([0,0,0,K(1),K(5)]) @@ -99,12 +99,12 @@ Reducing a curve modulo a prime:: Elliptic Curve defined by y^2 = x^3 + x + 5 over Residue field of Fractional ideal (13, 1/2*s + 9/2) - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.pari sage.schemes sage: R. = GF(11)[] sage: P = R.ideal(t^3 + t + 4) sage: ff. = R.residue_field(P) - sage: E = EllipticCurve([0,0,0,R(1),R(t)]) # needs sage.schemes - sage: E.base_extend(ff) # needs sage.schemes + sage: E = EllipticCurve([0,0,0,R(1),R(t)]) + sage: E.base_extend(ff) Elliptic Curve defined by y^2 = x^3 + x + a over Residue field in a of Principal ideal (t^3 + t + 4) of Univariate Polynomial Ring in t over Finite Field of size 11 @@ -1293,7 +1293,7 @@ cdef class ResidueFieldHomomorphism_global(RingHomomorphism): sage: # needs sage.rings.finite_rings sage: R. = GF(2)[]; P = R.ideal(t^7 + t^6 + t^5 + t^4 + 1) sage: k = P.residue_field(); f = k.coerce_map_from(R) - sage: f(t^10) + sage: f(t^10) # needs sage.modules tbar^6 + tbar^3 + tbar^2 """ self._K = K @@ -1482,7 +1482,7 @@ cdef class ResidueFieldHomomorphism_global(RingHomomorphism): sage: k. = P.residue_field(); f = k.coerce_map_from(R) sage: f.lift(a^2 + 5*a + 1) t^2 + 5*t + 1 - sage: f(f.lift(a^2 + 5*a + 1)) == a^2 + 5*a + 1 + sage: f(f.lift(a^2 + 5*a + 1)) == a^2 + 5*a + 1 # needs sage.modules True """ if self.domain() is ZZ: @@ -1780,12 +1780,11 @@ class ResidueFiniteField_prime_modn(ResidueField_generic, FiniteField_prime_modn EXAMPLES:: - sage: # needs sage.rings.number_field + sage: # needs sage.modules sage.rings.number_field sage: R. = QQ[] sage: K. = NumberField(x^3 - 7) sage: P = K.ideal(29).factor()[1][0] - sage: k = ResidueField(P) - sage: k + sage: k = ResidueField(P); k Residue field of Fractional ideal (-a^2 - 2*a - 2) sage: OK = K.maximal_order() sage: c = OK(a) @@ -1799,7 +1798,7 @@ class ResidueFiniteField_prime_modn(ResidueField_generic, FiniteField_prime_modn sage: k(v) # indirect doctest 3 - sage: # needs sage.rings.finite_rings + sage: # needs sage.modules sage.rings.finite_rings sage: R. = GF(2)[]; P = R.ideal(t + 1); k. = P.residue_field() sage: V = k.vector_space(map=False); v = V([1]) sage: k(v) diff --git a/src/sage/rings/finite_rings/residue_field_ntl_gf2e.pyx b/src/sage/rings/finite_rings/residue_field_ntl_gf2e.pyx index ed6af655258..5071bc87137 100644 --- a/src/sage/rings/finite_rings/residue_field_ntl_gf2e.pyx +++ b/src/sage/rings/finite_rings/residue_field_ntl_gf2e.pyx @@ -85,7 +85,8 @@ class ResidueFiniteField_ntl_gf2e(ResidueField_generic, FiniteField_ntl_gf2e): sage: P = K.ideal(61).factor()[0][0] # needs sage.rings.number_field sage: k = K.residue_field(P) # needs sage.rings.number_field - sage: R. = GF(3)[]; P = R.ideal(t^4 - t^3 + t + 1); k. = P.residue_field(); type(k) + sage: R. = GF(3)[]; P = R.ideal(t^4 - t^3 + t + 1); k. = P.residue_field() + sage: type(k) # needs sage.libs.linbox sage: a^5 a^3 + 2*a^2 + a + 2 diff --git a/src/sage/rings/finite_rings/residue_field_pari_ffelt.pyx b/src/sage/rings/finite_rings/residue_field_pari_ffelt.pyx index 375b3b4cdfc..f21a3b8d9bb 100644 --- a/src/sage/rings/finite_rings/residue_field_pari_ffelt.pyx +++ b/src/sage/rings/finite_rings/residue_field_pari_ffelt.pyx @@ -110,15 +110,15 @@ class ResidueFiniteField_pari_ffelt(ResidueField_generic, FiniteField_pari_ffelt 7521*alpha + 4131 sage: ff(17/3) 6677 - sage: V = ff.vector_space(map=False); v = V([3,-2]) - sage: type(ff.convert_map_from(V)) + sage: V = ff.vector_space(map=False); v = V([3,-2]) # needs sage.modules + sage: type(ff.convert_map_from(V)) # needs sage.modules - sage: ff(v) # indirect doctest + sage: ff(v) # indirect doctest # needs sage.modules 10005*alpha + 3 sage: R. = GF(5)[]; P = R.ideal(4*t^12 + 3*t^11 + 4*t^10 + t^9 + t^8 + 3*t^7 + 2*t^6 + 3*t^4 + t^3 + 3*t^2 + 2) sage: k. = P.residue_field() - sage: V = k.vector_space(map=False); v = V([1,2,3,4,5,6,7,8,9,0,1,2]); k(v) # indirect doctest + sage: V = k.vector_space(map=False); v = V([1,2,3,4,5,6,7,8,9,0,1,2]); k(v) # indirect doctest # needs sage.modules 2*a^11 + a^10 + 4*a^8 + 3*a^7 + 2*a^6 + a^5 + 4*a^3 + 3*a^2 + 2*a + 1 """ try: diff --git a/src/sage/rings/function_field/drinfeld_modules/finite_drinfeld_module.py b/src/sage/rings/function_field/drinfeld_modules/finite_drinfeld_module.py index 03fbf08ae3f..a6d64d46fa5 100644 --- a/src/sage/rings/function_field/drinfeld_modules/finite_drinfeld_module.py +++ b/src/sage/rings/function_field/drinfeld_modules/finite_drinfeld_module.py @@ -10,6 +10,7 @@ AUTHORS: - Antoine Leudière (2022-04) +- Yossef Musleh (2023-02): added characteristic polynomial methods """ # ***************************************************************************** @@ -22,10 +23,15 @@ # http://www.gnu.org/licenses/ # ***************************************************************************** +from sage.functions.log import logb +from sage.functions.other import ceil, sqrt from sage.matrix.constructor import Matrix +from sage.matrix.matrix_space import MatrixSpace +from sage.matrix.special import companion_matrix +from sage.misc.misc_c import prod from sage.modules.free_module_element import vector -from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing from sage.rings.function_field.drinfeld_modules.drinfeld_module import DrinfeldModule +from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing class DrinfeldModule_finite(DrinfeldModule): @@ -151,8 +157,76 @@ def __init__(self, gen, category): # added one to ensure that DrinfeldModule_finite would always # have _frobenius_norm and _frobenius_trace attributes. super().__init__(gen, category) + self._base_degree_over_constants = self.base_over_constants_field().degree(self._Fq) self._frobenius_norm = None self._frobenius_trace = None + self._frobenius_charpoly = None + + def _frobenius_crystalline_matrix(self): + r""" + Return the matrix representing the Frobenius endomorphism on the + crystalline cohomology of the Drinfeld module. This is done up to + precision [K:Fq] + 1, which is enough to ensure the characteristic + polynomial can be recovered. + + For the formal construction of the crystalline cohomology, see + [Ang1997]_. It is a free module of rank r over the ring of Witt + vectors in `T - \mathfrak{p}`. + + EXAMPLES:: + + sage: Fq = GF(25) + sage: A. = Fq[] + sage: K. = Fq.extension(6) + sage: p_root = 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 + sage: phi = DrinfeldModule(A, [p_root, z12^3, z12^5]) + sage: phi._frobenius_crystalline_matrix() + [...((z2 + 3) + z12 + (4*z2 + 1)*z12^2 + (z2 + 4)*z12^3 + (z2 + 4)*z12^4 + (2*z2 + 3)*z12^5)*T^3 + (2*z2 + 2*z2*z12 + (2*z2 + 3)*z12^2 + ... + (3*z2 + 4)*z12^3 + (2*z2 + 3)*z12^4 + 3*z2*z12^5] + + ALGORITHM: + + Compute the action of the Frobenius on an explicit basis for the + cohomology using a recurrence relation, and return the resulting + matrix. + """ + Fq = self._Fq + K = self.base_over_constants_field() + A = self.function_ring() + char, q = Fq.characteristic(), Fq.cardinality() + qdeg = logb(q, char) + r, n = self.rank(), self._base_degree_over_constants + nstar = ceil(sqrt(n)) + nquo, nrem = divmod(n, nstar) + drin_coeffs = self.coefficients(sparse=False) + poly_K = PolynomialRing(K, name=str(A.gen())) + matrix_poly_K = MatrixSpace(poly_K, r, r) + mu_coeffs = ((poly_K.gen() - drin_coeffs[0])**(n+1)) \ + .coefficients(sparse=False) + + def companion(order): + # + [1] is required to satisfy formatting for companion matrix + M = matrix_poly_K(companion_matrix([(drin_coeffs[i]/drin_coeffs[r]) + .frobenius(qdeg*order) + for i in range(r)] + [1], format='top')) + M[0, r-1] += poly_K.gen() / drin_coeffs[r].frobenius(qdeg*order) + return M + + companion_initial = prod([companion(i) for i in range(nrem, 0, -1)]) + companion_step = prod([companion(i) + for i in range(nstar + nrem, nrem, -1)]) + reduced_companions = [] + for k in range(nquo - 1, 0, -1): + M = Matrix(poly_K, r, r) + modulus = poly_K([c.frobenius(qdeg*(-k*nstar % n)) + for c in mu_coeffs]) + for i, row in enumerate(companion_step): + for j, entry in enumerate(row): + reduction = entry % modulus + M[i, j] = poly_K([c.frobenius(qdeg*(k*nstar)) + for c in reduction + .coefficients(sparse=False)]) + reduced_companions.append(M) + return (prod(reduced_companions) * companion_step * companion_initial) def frobenius_endomorphism(self): r""" @@ -183,46 +257,62 @@ def frobenius_endomorphism(self): deg = self.base_over_constants_field().degree_over() return self._Hom_(self, category=self.category())(t**deg) - def frobenius_charpoly(self, var='X'): + def frobenius_charpoly(self, var='X', algorithm='crystalline'): r""" Return the characteristic polynomial of the Frobenius - endomorphism if the rank is two. Raise a NotImplementedError - otherwise. + endomorphism. Let `\mathbb{F}_q` be the base field of the function ring. The - *characteristic polynomial `\chi` of the Frobenius endomorphism* + *characteristic polynomial* `\chi` *of the Frobenius endomorphism* is defined in [Gek1991]_. An important feature of this - polynomial is that it is a monic univariate polynomial with - coefficients in the function ring. As in our case the function + polynomial is that it is monic, univariate, and has coefficients + in the function ring. As in our case the function ring is a univariate polynomial ring, it is customary to see the characteristic polynomial of the Frobenius endomorphism as a bivariate polynomial. - Let `\chi = X^2 - A(T)X + B(T)` be the characteristic polynomial - of the Frobenius endomorphism, and let `t^n` be the Ore polynomial - that defines the Frobenius endomorphism of `\phi`; by - definition, `n` is the degree over of the base field over - `\mathbb{F}_q`. We have `\chi(t^n)(\phi(T)) = t^{2n} - \phi_A - t^n + \phi_B = 0`, with `\deg(A) \leq \frac{n}{2}` and `\deg(B) - = n`. + Let `\chi = X^r + \sum_{i=0}^{r-1} A_{i}(T)X^{i}` be the + characteristic polynomial of the Frobenius endomorphism, and + let `t^n` be the Ore polynomial that defines the Frobenius + endomorphism of `\phi`; by definition, `n` is the degree of `K` + over the base field `\mathbb{F}_q`. Then we have + + .. MATH:: + + \chi(t^n)(\phi(T)) + = t^{nr} + \sum_{i=1}^{r} \phi_{A_{i}}t^{n(i)} + = 0, - Note that the *Frobenius trace* is defined as `A(T)` and the - *Frobenius norm* is defined as `B(T)`. + with `\deg(A_i) \leq \frac{n(r-i)}{r}`. + + Note that the *Frobenius trace* is defined as `A_{r-1}(T)` and the + *Frobenius norm* is defined as `A_0(T)`. INPUT: - ``var`` (default: ``'X'``) -- the name of the second variable + - ``algorithm`` (default: ``'crystalline'``) -- the algorithm + used to compute the characteristic polynomial EXAMPLES:: + sage: Fq = GF(25) + sage: A. = Fq[] + sage: K. = Fq.extension(6) + sage: p_root = 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 + sage: phi = DrinfeldModule(A, [p_root, z12^3, z12^5]) + sage: phi.frobenius_charpoly() + X^2 + ((4*z2 + 4)*T^3 + (z2 + 3)*T^2 + 3*T + 2*z2 + 3)*X + 3*z2*T^6 + (4*z2 + 3)*T^5 + (4*z2 + 4)*T^4 + 2*T^3 + (3*z2 + 3)*T^2 + (z2 + 2)*T + 4*z2 + + :: + sage: Fq = GF(343) sage: A. = Fq[] sage: K. = Fq.extension(2) sage: phi = DrinfeldModule(A, [1, 0, z6]) sage: chi = phi.frobenius_charpoly() sage: chi - X^2 + ((3*z3^2 + z3 + 4)*T + 4*z3^2 + 6*z3 + 3)*X - + (5*z3^2 + 2*z3)*T^2 + (4*z3^2 + 3*z3)*T + 5*z3^2 + 2*z3 + X^2 + ((3*z3^2 + z3 + 4)*T + 4*z3^2 + 6*z3 + 3)*X + (5*z3^2 + 2*z3)*T^2 + (4*z3^2 + 3*z3)*T + 5*z3^2 + 2*z3 :: @@ -232,51 +322,165 @@ def frobenius_charpoly(self, var='X'): :: - sage: trace = phi.frobenius_trace() - sage: trace - (4*z3^2 + 6*z3 + 3)*T + 3*z3^2 + z3 + 4 - sage: norm = phi.frobenius_norm() - sage: norm - (5*z3^2 + 2*z3)*T^2 + (4*z3^2 + 3*z3)*T + 5*z3^2 + 2*z3 + sage: phi.frobenius_charpoly(algorithm="NotImplemented") + Traceback (most recent call last): + ... + NotImplementedError: algorithm "NotImplemented" not implemented + + ALGORITHM: + + By default, this method uses the so-called *crystalline* + algorithm which computes the characteristic polynomial of the + Frobenius acting on the crystalline cohomology of the Drinfeld + module. For further details, see [Ang1997]_. + + The available options for 'algorithm' are: + + - ``'crystalline'`` -- Computes the characteristic polynomial of the + Frobenius endomorphism on the crystalline cohomology of a Drinfeld + module. + + - ``'motive'`` -- Based on computing the characteristic polynomial of + the Frobenius endomorphism on the motive of a Drinfeld module. This + instantiates the Frobenius as a morphism object and calls its + ``'characteristic_polynomial'`` method. + """ + # Throw an error if the user asks for an unimplemented algorithm + # even if the char poly has already been computed + method_name = f'_frobenius_charpoly_{algorithm}' + if hasattr(self, method_name): + if self._frobenius_charpoly is not None: + return self._frobenius_charpoly + self._frobenius_charpoly = getattr(self, method_name)(var) + return self._frobenius_charpoly + raise NotImplementedError(f'algorithm \"{algorithm}\" not implemented') + + def _frobenius_charpoly_crystalline(self, var): + r""" + Return the characteristic polynomial of the Frobenius + endomorphism using Crystalline cohomology. + + The algorithm works for Drinfeld `\mathbb{F}_q[T]`-modules of + any rank. + + This method is private and should not be directly called. + Instead, use :meth:`frobenius_charpoly` with the option + `algorithm='crystalline'`. + + INPUT: + + - ``var`` -- the name of the second variable + + OUTPUT: a univariate polynomial with coefficients in the + function ring + + EXAMPLES:: + + sage: Fq = GF(25) + sage: A. = Fq[] + sage: K. = Fq.extension(6) + sage: p_root = 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 + sage: phi = DrinfeldModule(A, [p_root, z12^3, z12^5]) + sage: phi.frobenius_charpoly(algorithm='crystalline') # indirect doctest + X^2 + ((4*z2 + 4)*T^3 + (z2 + 3)*T^2 + 3*T + 2*z2 + 3)*X + 3*z2*T^6 + (4*z2 + 3)*T^5 + (4*z2 + 4)*T^4 + 2*T^3 + (3*z2 + 3)*T^2 + (z2 + 2)*T + 4*z2 :: - sage: n = 2 # Degree of the base field over Fq - sage: trace.degree() <= n/2 - True - sage: norm.degree() == n - True + sage: Fq = GF(25) + sage: A. = Fq[] + sage: K. = Fq.extension(8) + sage: phi = DrinfeldModule(A, [z, 4, 1, z, z+1, 2, z+2, 1, 1, 3, 1]) + sage: phi.frobenius_charpoly(algorithm='crystalline') # indirect doctest + X^10 + X^9 + (3*T + z2 + 1)*X^8 + (4*T^2 + z2*T + 2*z2 + 1)*X^7 + ... + (4*z2 + 4)*T^4 + 4*z2*T^2 + (z2 + 2)*T + z2 + + :: + + sage: Fq = GF(27) + sage: A. = Fq[] + sage: K. = Fq.extension(10) + sage: phi = DrinfeldModule(A, [z, z^2 + z, 2, 1, z, z+1, 2, z+2, 0, 1, 1, z^2 + z]) + sage: phi.frobenius_charpoly(algorithm='crystalline') # indirect doctest + X^11 + (z3^2 + 2*z3)*X^10 + ((z3 + 1)*T + z3)*X^9 + ((2*z3^2 + z3 + 2)*T^2 + ... + (2*z3^2 + 2*z3 + 2)*T + z3^2 ALGORITHM: - We compute the Frobenius norm, and with it the Frobenius - trace. This gives the Frobenius characteristic polynomial. - See [MS2019]_, Section 4. + Compute the characteristic polynomial of the Frobenius endomorphism + acting on the crystalline cohomology of a Drinfeld module, which + is equal to that of the Frobenius endomorphism on the Drinfeld + module. A recurrence on elements of the cohomology allows us to + compute a matrix representation of the Frobenius endomorphism + efficiently using a companion matrix method. Based on the algorithm + of section 6.3 in [MS2023]_. + """ + A = self.function_ring() + K = self.base_over_constants_field() + charpoly_K = self._frobenius_crystalline_matrix() \ + .charpoly(var).coefficients(sparse=False) + + # The above line obtains the char poly with coefficients in K[T] + # This maps them into A = Fq[T] + + coeffs_A = [A([x.in_base() for x in coeff]) for coeff in charpoly_K] + return PolynomialRing(A, name=var)(coeffs_A) + + def _frobenius_charpoly_motive(self, var): + r""" + Return the characteristic polynomial of the Frobenius + endomorphism using Motivic cohomology. + + The algorithm works for Drinfeld `\mathbb{F}_q[T]`-modules of + any rank. + + This method is private and should not be directly called. + Instead, use :meth:`frobenius_charpoly` with the option + `algorithm='motive'`. + + INPUT: + + - ``var`` -- the name of the second variable - See docstrings of methods :meth:`frobenius_norm` and - :meth:`frobenius_trace` for further details on the - computation of the norm and of the trace. + OUTPUT: a univariate polynomial with coefficients in the + function ring + + EXAMPLES:: + + sage: Fq = GF(25) + sage: A. = Fq[] + sage: K. = Fq.extension(6) + sage: p_root = 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 + sage: phi = DrinfeldModule(A, [p_root, z12^3, z12^5]) + sage: phi.frobenius_charpoly(algorithm='motive') # indirect doctest + X^2 + ((4*z2 + 4)*T^3 + (z2 + 3)*T^2 + 3*T + 2*z2 + 3)*X + 3*z2*T^6 + (4*z2 + 3)*T^5 + (4*z2 + 4)*T^4 + 2*T^3 + (3*z2 + 3)*T^2 + (z2 + 2)*T + 4*z2 + + :: + + sage: Fq = GF(25) + sage: A. = Fq[] + sage: K. = Fq.extension(8) + sage: phi = DrinfeldModule(A, [z, 4, 1, z, z+1, 2, z+2, 1, 1, 3, 1]) + sage: phi.frobenius_charpoly(algorithm='motive') # indirect doctest + X^10 + X^9 + (3*T + z2 + 1)*X^8 + (4*T^2 + z2*T + 2*z2 + 1)*X^7 + ... + (4*z2 + 4)*T^4 + 4*z2*T^2 + (z2 + 2)*T + z2 + + :: + + sage: Fq = GF(27) + sage: A. = Fq[] + sage: K. = Fq.extension(10) + sage: phi = DrinfeldModule(A, [z, z^2 + z, 2, 1, z, z+1, 2, z+2, 0, 1, 1, z^2 + z]) + sage: phi.frobenius_charpoly(algorithm='motive') # indirect doctest + X^11 + (z3^2 + 2*z3)*X^10 + ((z3 + 1)*T + z3)*X^9 + ((2*z3^2 + z3 + 2)*T^2 + ... + (2*z3^2 + 2*z3 + 2)*T + z3^2 """ - self._check_rank_two() - A = self._function_ring # Fq[T] - S = PolynomialRing(A, name=var) # Fq[T][X] - # Does not work when Fq is not a prime field... - # chi = self._gen.reduced_charpoly() - # return -chi(A.gen(), S.gen()) - return S([self.frobenius_norm(), -self.frobenius_trace(), 1]) + return self.frobenius_endomorphism().characteristic_polynomial(var) def frobenius_norm(self): r""" - Return Frobenius norm of the Drinfeld module, if the rank is - two, raise a NotImplementedError otherwise. + Return the Frobenius norm of the Drinfeld module. - Let `\mathbb{F}_q[T]` be the function ring, write `\chi = X^2 - - A(T)X + B(T) \in \mathbb{F}_q[T][X]` for the characteristic - polynomial of the Frobenius endomorphism. The *Frobenius norm* - is defined as the polynomial `B(T) \in \mathbb{F}_q[T]`. - - Let `n` be the degree of the base field over `\mathbb{F}_q` Then the - Frobenius norm has degree `n`. + Let `C(X) = \sum_{i=0}^r a_iX^{i}` denote the characteristic + polynomial of the Frobenius endomorphism. The Frobenius norm + is `(-1)^r a_{0}`. This is an element of the regular function ring + and if `n` is the degree of the base field over `\mathbb{F}_q`, + then the Frobenius norm has degree `n`. EXAMPLES:: @@ -304,31 +508,24 @@ def frobenius_norm(self): The Frobenius norm is computed using the formula, by Gekeler, given in [MS2019]_, Section 4, Proposition 3. """ - self._check_rank_two() - L = self._base.over(self._Fq) - # Notations from Schost-Musleh: - if self._frobenius_norm is None: - n = L.degree_over(self._Fq) - d = self.characteristic().degree() - m = n // d - delta = self._gen[2] - norm = L(delta).norm() - char = self.characteristic() - self._frobenius_norm = ((-1)**n) * (char**m) / norm + if self._frobenius_norm is not None: + return self._frobenius_norm + K = self.base_over_constants_field() + n = K.degree(self._Fq) + char = self.characteristic() + norm = K(self.coefficients()[-1]).norm() + self._frobenius_norm = ((-1)**n)*(char**(n/char.degree())) / norm return self._frobenius_norm def frobenius_trace(self): r""" - Return Frobenius norm of the Drinfeld module, if the rank is - two; raise a NotImplementedError otherwise. + Return the Frobenius trace of the Drinfeld module. - Let `\mathbb{F}_q[T]` be the function ring, write `\chi = T^2 - - A(X)T + B(X) \in \mathbb{F}_q[T][X]` for the characteristic - polynomial of the Frobenius endomorphism. The *Frobenius trace* - is defined as the polynomial `A(T) \in \mathbb{F}_q[T]`. - - Let `n` be the degree over `\mathbb{F}_q` of the base codomain. - Then the Frobenius trace has degree at most `\frac{n}{2}`. + Let `C(X) = \sum_{i=0}^r a_iX^{i}` denote the characteristic + polynomial of the Frobenius endomorphism. The Frobenius trace + is `-a_{r-1}`. This is an element of the regular function ring + and if `n` is the degree of the base field over `\mathbb{F}_q`, + then the Frobenius trace has degree at most `\frac{n}{r}`. EXAMPLES:: @@ -353,24 +550,20 @@ def frobenius_trace(self): ALGORITHM: - Let `A(T)` denote the Frobenius trace and `B(T)` denote the - Frobenius norm. We begin by computing `B(T)`, see docstring - of method :meth:`frobenius_norm` for details. The - characteristic polynomial of the Frobenius yields `t^{2n} - - \phi_A t^n + \phi_B = 0`, where `t^n` is the Frobenius - endomorphism. As `\phi_B` is now known, we can compute - `\phi_A = (t^{2n} + \phi_B) / t^n`. We get `A(T)` by - inverting this quantity, using the method - :meth:`sage.rings.function_fields.drinfeld_module.drinfeld_module.DrinfeldModule.invert`, - see its docstring for details. + We extract the coefficient of `X^{r-1}` from the characteristic + polynomial if it has been previously computed, otherwise we compute + the trace of the matrix of the Frobenius acting on the crystalline + cohomology. """ - self._check_rank_two() - # Notations from Schost-Musleh: - if self._frobenius_trace is None: - n = self._base.over(self._Fq).degree_over(self._Fq) - B = self.frobenius_norm() - t = self.ore_polring().gen() - self._frobenius_trace = self.invert(t**n + (self(B) // t**n)) + K = self.base_over_constants_field() + A = self.function_ring() + if self._frobenius_trace is not None: + return self._frobenius_trace + if self._frobenius_charpoly is not None: + self._frobenius_trace = -self._frobenius_charpoly \ + .coefficients(sparse=False)[-2] + self._frobenius_trace = self._frobenius_crystalline_matrix().trace() + self._frobenius_trace = A([x.in_base() for x in self._frobenius_trace]) return self._frobenius_trace def invert(self, ore_pol): @@ -487,6 +680,62 @@ def invert(self, ore_pol): pass raise ValueError('input must be in the image of the Drinfeld module') + def is_isogenous(self, psi): + r""" + Return ``True`` when ``self`` is isogenous to the other + Drinfeld module. + + If the Drinfeld modules do not belong to the same category, an + exception is raised. + + EXAMPLES:: + + sage: Fq = GF(2) + sage: A. = Fq[] + sage: K. = Fq.extension(3) + sage: psi = DrinfeldModule(A, [z, z + 1, z^2 + z + 1]) + sage: phi = DrinfeldModule(A, [z, z^2 + z + 1, z^2 + z]) + sage: phi.is_isogenous(psi) + True + + :: + + sage: chi = DrinfeldModule(A, [z, z + 1, z^2 + z]) + sage: phi.is_isogenous(chi) + False + + :: + + sage: mu = DrinfeldModule(A, [z + 1, z^2 + z + 1, z^2 + z]) + sage: phi.is_isogenous(mu) + Traceback (most recent call last): + ... + TypeError: Drinfeld modules are not in the same category + + :: + + sage: mu = 1 + sage: phi.is_isogenous(mu) + Traceback (most recent call last): + ... + TypeError: input must be a Drinfeld module + + ALGORITHM: + + Two Drinfeld A-modules of equal characteristic are isogenous + if and only if: + + - they have the same rank + - the characteristic polynomial of the Frobenius endomorphism + for both Drinfeld modules are equal. + """ + if not isinstance(psi, DrinfeldModule): + raise TypeError("input must be a Drinfeld module") + if self.category() != psi.category(): + raise TypeError("Drinfeld modules are not in the same category") + return self.rank() == psi.rank() \ + and self.frobenius_charpoly() == psi.frobenius_charpoly() + def is_supersingular(self): r""" Return ``True`` if this Drinfeld module is supersingular. diff --git a/src/sage/rings/function_field/element_rational.pyx b/src/sage/rings/function_field/element_rational.pyx index faa70ee7aee..0b36c50f5f7 100644 --- a/src/sage/rings/function_field/element_rational.pyx +++ b/src/sage/rings/function_field/element_rational.pyx @@ -390,7 +390,7 @@ cdef class FunctionFieldElement_rational(FunctionFieldElement): sage: f = (x+1)/(x-1) sage: f.is_nth_power(1) True - sage: f.is_nth_power(3) + sage: f.is_nth_power(3) # needs sage.modules False sage: (f^3).is_nth_power(3) True diff --git a/src/sage/rings/function_field/function_field.py b/src/sage/rings/function_field/function_field.py index 26975773a88..af5b6c4d924 100644 --- a/src/sage/rings/function_field/function_field.py +++ b/src/sage/rings/function_field/function_field.py @@ -125,13 +125,15 @@ TESTS:: sage: TestSuite(J).run() - sage: TestSuite(K).run(max_runs=256) # long time (10s) # needs sage.rings.number_field + sage: TestSuite(K).run(max_runs=256) # long time (10s) # needs sage.rings.function_field sage.rings.number_field sage: TestSuite(L).run(max_runs=8) # long time (25s) # needs sage.rings.function_field sage.rings.number_field - sage: TestSuite(M).run(max_runs=8) # long time (35s) # needs sage.rings.finite_rings sage.rings.function_field - sage: TestSuite(N).run(max_runs=8, skip='_test_derivation') # long time (15s), needs sage.rings.finite_rings - sage: TestSuite(O).run() # needs sage.rings.function_field - sage: TestSuite(R).run() # needs sage.rings.finite_rings sage.rings.function_field - sage: TestSuite(S).run() # long time (4s) # needs sage.rings.finite_rings sage.rings.function_field + + sage: # needs sage.rings.finite_rings sage.rings.function_field + sage: TestSuite(M).run(max_runs=8) # long time (35s) + sage: TestSuite(N).run(max_runs=8, skip='_test_derivation') # long time (15s) + sage: TestSuite(O).run() + sage: TestSuite(R).run() + sage: TestSuite(S).run() # long time (4s) Global function fields ---------------------- diff --git a/src/sage/rings/function_field/function_field_rational.py b/src/sage/rings/function_field/function_field_rational.py index 1b169275da4..e763a673a15 100644 --- a/src/sage/rings/function_field/function_field_rational.py +++ b/src/sage/rings/function_field/function_field_rational.py @@ -135,9 +135,10 @@ def __init__(self, constant_field, names, category=None): EXAMPLES:: + sage: K. = FunctionField(CC); K # needs sage.rings.real_mpfr Rational function field in t over Complex Field with 53 bits of precision - sage: TestSuite(K).run() # long time (5s) + sage: TestSuite(K).run() # long time (5s) # needs sage.rings.real_mpfr sage: FunctionField(QQ[I], 'alpha') # needs sage.rings.number_field Rational function field in alpha over diff --git a/src/sage/rings/function_field/valuation.py b/src/sage/rings/function_field/valuation.py index 3c92f8cf212..b7c7536bca9 100644 --- a/src/sage/rings/function_field/valuation.py +++ b/src/sage/rings/function_field/valuation.py @@ -654,7 +654,7 @@ def _test_classical_residue_field(self, **options): sage: K. = FunctionField(QQ) sage: v = K.valuation(x^2 + 1) - sage: v._test_classical_residue_field() + sage: v._test_classical_residue_field() # needs sage.rings.number_field """ tester = self._tester(**options) @@ -774,7 +774,7 @@ def reduce(self, f): sage: K. = FunctionField(QQ) sage: v = K.valuation(x^2 + 1) - sage: v.reduce(x) + sage: v.reduce(x) # needs sage.rings.number_field u1 """ @@ -805,7 +805,7 @@ def _repr_(self): EXAMPLES:: sage: K. = FunctionField(QQ) - sage: K.valuation(x^2 + 1) # indirect doctest + sage: K.valuation(x^2 + 1) # indirect doctest (x^2 + 1)-adic valuation """ @@ -827,6 +827,7 @@ def extensions(self, L): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K. = FunctionField(QQ) sage: v = K.valuation(x^2 + 1) sage: L. = FunctionField(GaussianIntegers().fraction_field()) diff --git a/src/sage/rings/infinity.py b/src/sage/rings/infinity.py index 3c4a960c037..119f48a9f65 100644 --- a/src/sage/rings/infinity.py +++ b/src/sage/rings/infinity.py @@ -943,12 +943,13 @@ def _sympy_(self): EXAMPLES:: - sage: import sympy # needs sympy - sage: SR(unsigned_infinity)._sympy_() # needs sympy + sage: # needs sympy + sage: import sympy + sage: SR(unsigned_infinity)._sympy_() zoo - sage: gamma(-3)._sympy_() is sympy.factorial(-2) # needs sympy + sage: gamma(-3)._sympy_() is sympy.factorial(-2) True - sage: gamma(-3) is sympy.factorial(-2)._sage_() # needs sympy + sage: gamma(-3) is sympy.factorial(-2)._sage_() True """ import sympy @@ -1626,12 +1627,13 @@ def _sympy_(self): EXAMPLES:: - sage: import sympy # needs sympy - sage: bool(-oo == -sympy.oo) # needs sympy + sage: # needs sympy + sage: import sympy + sage: bool(-oo == -sympy.oo) True - sage: bool(SR(-oo) == -sympy.oo) # needs sympy + sage: bool(SR(-oo) == -sympy.oo) True - sage: bool((-oo)._sympy_() == -sympy.oo) # needs sympy + sage: bool((-oo)._sympy_() == -sympy.oo) True """ @@ -1773,17 +1775,15 @@ def test_comparison(ring): EXAMPLES:: sage: from sage.rings.infinity import test_comparison - sage: rings = [ZZ, QQ, RR, RealField(200), RDF, RLF, RIF] # needs sage.rings.real_mpfr - sage: for R in rings: # needs sage.rings.real_mpfr + sage: rings = [ZZ, QQ, RDF] + sage: rings += [RR, RealField(200)] # needs sage.rings.real_mpfr + sage: rings += [RLF, RIF] # needs sage.rings.real_interval_field + sage: for R in rings: ....: print('testing {}'.format(R)) ....: test_comparison(R) testing Integer Ring testing Rational Field - testing Real Field with 53 bits of precision - testing Real Field with 200 bits of precision - testing Real Double Field - testing Real Lazy Field - testing Real Interval Field with 53 bits of precision + testing Real Double Field... sage: test_comparison(AA) # needs sage.rings.number_field Comparison with number fields does not work:: @@ -1857,7 +1857,7 @@ def test_signed_infinity(pos_inf): sage: from sage.rings.infinity import test_signed_infinity sage: test_signed_infinity(oo) sage: test_signed_infinity(float('+inf')) - sage: test_signed_infinity(RLF(oo)) + sage: test_signed_infinity(RLF(oo)) # needs sage.rings.real_interval_field sage: test_signed_infinity(RIF(oo)) # needs sage.rings.real_interval_field sage: test_signed_infinity(SR(oo)) # needs sage.symbolic """ diff --git a/src/sage/rings/integer.pyx b/src/sage/rings/integer.pyx index 5ce9df2fc3c..3ecd0bd986d 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -14,7 +14,7 @@ Add 2 integers:: Add an integer and a real number:: - sage: a + 4.0 + sage: a + 4.0 # needs sage.rings.real_mpfr 7.00000000000000 Add an integer and a rational number:: @@ -24,7 +24,8 @@ Add an integer and a rational number:: Add an integer and a complex number:: - sage: b = ComplexField().0 + 1.5 # needs sage.rings.real_mpfr + sage: # needs sage.rings.real_mpfr + sage: b = ComplexField().0 + 1.5 sage: loads((a + b).dumps()) == a + b True @@ -1468,10 +1469,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): :: sage: n=3^100000 - sage: n.digits(base=10)[-1] # slightly slower than str + sage: n.digits(base=10)[-1] # slightly slower than str # needs sage.rings.real_interval_field 1 sage: n=10^10000 - sage: n.digits(base=10)[-1] # slightly faster than str + sage: n.digits(base=10)[-1] # slightly faster than str # needs sage.rings.real_interval_field 1 AUTHORS: @@ -1710,13 +1711,13 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: n.ndigits(2) 4 sage: n = 1000**1000000+1 - sage: n.ndigits() + sage: n.ndigits() # needs sage.rings.real_interval_field 3000001 sage: n = 1000**1000000-1 - sage: n.ndigits() + sage: n.ndigits() # needs sage.rings.real_interval_field 3000000 sage: n = 10**10000000-10**9999990 - sage: n.ndigits() + sage: n.ndigits() # needs sage.rings.real_interval_field 10000000 """ cdef Integer temp @@ -2139,7 +2140,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: 2^x # symbolic x # needs sage.symbolic 2^x - sage: 2^1.5 # real number + sage: 2^1.5 # real number # needs sage.rings.real_mpfr 2.82842712474619 sage: 2^float(1.5) # python float abs tol 3e-16 2.8284271247461903 @@ -2525,9 +2526,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: Integer(125)._exact_log_mpfi_log(3) + sage: Integer(125)._exact_log_mpfi_log(3) # needs sage.rings.real_interval_field 4 - sage: Integer(5^150)._exact_log_mpfi_log(5) + sage: Integer(5^150)._exact_log_mpfi_log(5) # needs sage.rings.real_interval_field 150 """ cdef int i @@ -2637,7 +2638,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: Integer(178^1700+1).exact_log(178) 1700 sage: # we need to exercise the large base code path too - sage: Integer(1780^1700-1).exact_log(1780) + sage: Integer(1780^1700-1).exact_log(1780) # needs sage.rings.real_interval_field 1699 sage: # The following are very very fast. @@ -2784,7 +2785,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): For extremely large numbers, this works:: sage: x = 3^100000 - sage: log(x, 3) + sage: log(x, 3) # needs sage.rings.real_interval_field 100000 Also ``log(x)``, giving a symbolic output, @@ -3447,10 +3448,11 @@ 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: mpmath.mp.prec = 1000 # needs mpmath - sage: root = mpmath.findroot(lambda x: x^2 - 3, 2) # needs mpmath - sage: len(str(root)) # needs mpmath + sage: # needs mpmath + sage: import mpmath + sage: mpmath.mp.prec = 1000 + sage: root = mpmath.findroot(lambda x: x^2 - 3, 2) + sage: len(str(root)) 301 """ cdef Integer q = PY_NEW(Integer) @@ -6229,6 +6231,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: numpy.array([1, 2, 3]).dtype dtype('int32') # 32-bit dtype('int64') # 64-bit + + sage: # needs numpy (this has to be repeated until #36099 is fixed) + sage: import numpy sage: numpy.array(2**40).dtype dtype('int64') sage: numpy.array(2**400).dtype @@ -6733,7 +6738,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): 128 sage: int(32) << 2 128 - sage: 1 << 2.5 + sage: 1 << 2.5 # needs sage.rings.real_mpfr Traceback (most recent call last): ... TypeError: unsupported operands for <<: 1, 2.5000... @@ -6766,7 +6771,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): 8 sage: int(32) >> 2 8 - sage: 1 >> 2.5 + sage: 1 >> 2.5 # needs sage.rings.real_mpfr Traceback (most recent call last): ... TypeError: unsupported operands for >>: 1, 2.5000... diff --git a/src/sage/rings/invariants/reconstruction.py b/src/sage/rings/invariants/reconstruction.py index 4619bf777f1..2fff473d090 100644 --- a/src/sage/rings/invariants/reconstruction.py +++ b/src/sage/rings/invariants/reconstruction.py @@ -86,7 +86,7 @@ def binary_cubic_coefficients_from_invariants(discriminant, invariant_choice='de sage: coeffs (0, 1, -1, 0) sage: R. = QQ[] - sage: R(coeffs).discriminant() + sage: R(coeffs).discriminant() # needs sage.libs.pari 1 The two non-equivalent cubics `x^3` and `x^2*z` with discriminant 0 can't diff --git a/src/sage/rings/morphism.pyx b/src/sage/rings/morphism.pyx index 04fca55cd60..9901eff95a3 100644 --- a/src/sage/rings/morphism.pyx +++ b/src/sage/rings/morphism.pyx @@ -45,8 +45,7 @@ Reduction to finite field:: Map from single variable polynomial ring:: sage: R. = ZZ[] - sage: phi = R.hom([2], GF(5)) - sage: phi + sage: phi = R.hom([2], GF(5)); phi Ring morphism: From: Univariate Polynomial Ring in x over Integer Ring To: Finite Field of size 5 @@ -56,12 +55,13 @@ Map from single variable polynomial ring:: Identity map on the real numbers:: + sage: # needs sage.rings.real_mpfr sage: f = RR.hom([RR(1)]); f Ring endomorphism of Real Field with 53 bits of precision Defn: 1.00000000000000 |--> 1.00000000000000 sage: f(2.5) 2.50000000000000 - sage: f = RR.hom( [2.0] ) + sage: f = RR.hom([2.0]) Traceback (most recent call last): ... ValueError: relations do not all (canonically) map to 0 @@ -80,14 +80,15 @@ From smaller to bigger doesn't make sense:: From bigger to small does:: - sage: f = RR.hom( RealField(15) ) # needs sage.rings.real_mpfr - sage: f(2.5) + sage: f = RR.hom(RealField(15)) # needs sage.rings.real_mpfr + sage: f(2.5) # needs sage.rings.real_mpfr 2.500 - sage: f(RR.pi()) + sage: f(RR.pi()) # needs sage.rings.real_mpfr 3.142 Inclusion map from the reals to the complexes:: + sage: # needs sage.rings.real_mpfr sage: i = RR.hom([CC(1)]); i Ring morphism: From: Real Field with 53 bits of precision @@ -98,7 +99,7 @@ Inclusion map from the reals to the complexes:: A map from a multivariate polynomial ring to itself:: - sage: R. = PolynomialRing(QQ,3) + sage: R. = PolynomialRing(QQ, 3) sage: phi = R.hom([y, z, x^2]); phi Ring endomorphism of Multivariate Polynomial Ring in x, y, z over Rational Field Defn: x |--> y @@ -112,8 +113,7 @@ An endomorphism of a quotient of a multi-variate polynomial ring:: sage: # needs sage.libs.singular sage: R. = PolynomialRing(QQ) sage: S. = quo(R, ideal(1 + y^2)) - sage: phi = S.hom([a^2, -b]) - sage: phi + sage: phi = S.hom([a^2, -b]); phi Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (y^2 + 1) Defn: a |--> a^2 @@ -165,13 +165,11 @@ We next compose the inclusion with reduction from the integers to ``GF(2)``:: sage: # needs sage.rings.finite_rings - sage: pi = ZZ.hom(k) - sage: pi + sage: pi = ZZ.hom(k); pi Natural morphism: From: Integer Ring To: Finite Field of size 2 - sage: f = i * pi - sage: f + sage: f = i * pi; f Composite map: From: Integer Ring To: Finite Field in a of size 2^2 @@ -347,8 +345,9 @@ TESTS:: :: - sage: K. = CyclotomicField(7) # needs sage.rings.number_field - sage: c = K.hom([1/zeta7]) # needs sage.rings.number_field + sage: # needs sage.rings.number_field + sage: K. = CyclotomicField(7) + sage: c = K.hom([1/zeta7]) sage: c == loads(dumps(c)) True @@ -365,7 +364,7 @@ compare equal:: sage: # needs sage.rings.finite_rings sage: k = GF(2) sage: R. = k[] - sage: F4. = R.quo(x^2+x+1) + sage: F4. = R.quo(x^2 + x + 1) sage: H = End(F4) sage: from sage.rings.morphism import * sage: phi1 = H.identity(); phi1 @@ -963,13 +962,13 @@ cdef class RingHomomorphism(RingMap): sage: K. = NumberField(QQ['x']('x^2+2')) sage: f = K.hom([-a], K) sage: I = K.ideal([a + 1]) - sage: f.inverse_image(I) + sage: f.inverse_image(I) # needs sage.libs.singular Traceback (most recent call last): ... NotImplementedError: inverse image not implemented... - sage: f.inverse_image(K.ideal(0)).is_zero() + sage: f.inverse_image(K.ideal(0)).is_zero() # needs sage.libs.singular True - sage: f.inverse()(I) + sage: f.inverse()(I) # needs sage.rings.padics Fractional ideal (-a + 1) ALGORITHM: @@ -1011,7 +1010,7 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: - sage: # needs sage.rings.number_field + sage: # needs sage.rings.number_field sage.symbolic sage: R. = QQbar[] sage: f = R.hom([x, QQbar(i) * x + y^2], R) sage: I = R.ideal(y^3) @@ -1170,7 +1169,7 @@ cdef class RingHomomorphism(RingMap): :: sage: K. = QuadraticField(2) # needs sage.rings.number_field - sage: K.hom([-sqrt2], K).kernel().is_zero() # needs sage.rings.number_field + sage: K.hom([-sqrt2], K).kernel().is_zero() # needs sage.libs.singular sage.rings.number_field True :: @@ -1179,7 +1178,7 @@ cdef class RingHomomorphism(RingMap): sage: A. = QuadraticField(2) sage: B. = A.extension(A['b']('b^2-3')) sage: C. = B.absolute_field() - sage: A.hom([B(a)], C).kernel().is_zero() + sage: A.hom([B(a)], C).kernel().is_zero() # needs sage.libs.singular True sage: A.hom([a], B).kernel() Traceback (most recent call last): @@ -1422,7 +1421,7 @@ cdef class RingHomomorphism(RingMap): x1^3 + 3*x1*x2 + x3, x1^4 + 6*x1^2*x2 + 3*x2^2 + 4*x1*x3 + x4, x1^5 + 10*x1^3*x2 + 15*x1*x2^2 + 10*x1^2*x3 + 10*x2*x3 + 5*x1*x4 + x5] - sage: all(p.is_homogeneous() for p in phi.im_gens()) + sage: all(p.is_homogeneous() for p in phi.im_gens()) # needs sage.libs.singular True sage: phi.inverse().im_gens()[:5] # needs sage.libs.singular [x1, @@ -1437,11 +1436,12 @@ cdef class RingHomomorphism(RingMap): sage: K. = CyclotomicField(7) # needs sage.rings.number_field sage: c = K.hom([1/zeta7]) # needs sage.rings.number_field - sage: (c.inverse() * c).is_identity() # needs sage.rings.number_field + sage: (c.inverse() * c).is_identity() # needs sage.libs.singular sage.rings.number_field True + sage: F. = GF(7^3) # needs sage.rings.finite_rings sage: f = F.hom(t^7, F) # needs sage.rings.finite_rings - sage: (f.inverse() * f).is_identity() # needs sage.rings.finite_rings + sage: (f.inverse() * f).is_identity() # needs sage.libs.singular sage.rings.finite_rings True An isomorphism between the algebraic torus and the circle over a number @@ -1494,7 +1494,7 @@ cdef class RingHomomorphism(RingMap): sage: A. = GF(7^3) sage: R = A.polynomial_ring().quotient(A.polynomial()) sage: g = A.hom(R.gens(), R) - sage: (g.inverse() * g).is_identity() + sage: (g.inverse() * g).is_identity() # needs sage.libs.singular True sage: B., f = A.extension(3, map=True) sage: f.inverse() @@ -1549,8 +1549,8 @@ cdef class RingHomomorphism(RingMap): Check that results are cached:: sage: R. = GF(823)[] - sage: f = R.hom([x, y+x^2], R) - sage: f.inverse() is f.inverse() # needs sage.rings.finite_rings + sage: f = R.hom([x, y + x^2], R) + sage: f.inverse() is f.inverse() # needs sage.libs.singular True Some subclasses of ring homomorphisms are not supported:: @@ -1564,8 +1564,8 @@ cdef class RingHomomorphism(RingMap): :: - sage: R. = LaurentPolynomialRing(QQ) - sage: R.hom([y, x], R).inverse() + sage: R. = LaurentPolynomialRing(QQ) # needs sage.modules + sage: R.hom([y, x], R).inverse() # needs sage.libs.singular sage.modules Traceback (most recent call last): ... NotImplementedError @@ -1610,7 +1610,7 @@ cdef class RingHomomorphism(RingMap): sage: R. = GF(17)[] sage: f = R.hom([3*x, y + x^2 + x^3], R) - sage: (f * ~f).is_identity() # needs sage.rings.finite_rings + sage: (f * ~f).is_identity() # needs sage.libs.singular True """ return self.inverse() @@ -1885,6 +1885,7 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): A multivariate quotient over a finite field:: + sage: # needs sage.libs.singular sage: R. = GF(7)[] sage: Q. = R.quotient([x^2 + x + 1, y^2 + y + 1]) sage: f1 = R.hom([a, b]) @@ -1902,7 +1903,7 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): TESTS:: - sage: loads(dumps(f2)) == f2 # needs sage.rings.finite_rings + sage: loads(dumps(f2)) == f2 # needs sage.libs.pari True This was fixed in :trac:`24277`:: @@ -2216,7 +2217,7 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): A matrix ring over a multivariate quotient over a finite field:: - sage: # needs sage.modules + sage: # needs sage.libs.singular sage.modules sage: R. = GF(7)[] sage: Q. = R.quotient([x^2 + x + 1, y^2 + y + 1]) sage: f1 = R.hom([a, b]) @@ -2230,7 +2231,7 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): TESTS:: - sage: f1M == loads(dumps(f1M)) # needs sage.modules + sage: f1M == loads(dumps(f1M)) # needs sage.libs.singular sage.modules True """ if not isinstance(other, RingHomomorphism_from_base): @@ -2784,7 +2785,7 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.singular sage: R. = PolynomialRing(GF(19), 3) sage: S. = R.quo(x^3 + y^3 + z^3) sage: phi = S.hom([b, c, a]) @@ -2809,7 +2810,7 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.singular sage: R. = PolynomialRing(GF(19), 3) sage: S. = R.quo(x^3 + y^3 + z^3) sage: phi = S.hom([b, c, a]) @@ -3110,13 +3111,14 @@ def _tensor_product_ring(B, A): EXAMPLES:: + sage: # needs sage.libs.singular sage: from sage.rings.morphism import _tensor_product_ring sage: R. = QQ[] - sage: S. = R.quotient(x^2 + y^2) # needs sage.libs.singular - sage: Q = _tensor_product_ring(S, R); Q # needs sage.libs.singular + sage: S. = R.quotient(x^2 + y^2) + sage: Q = _tensor_product_ring(S, R); Q Quotient of Multivariate Polynomial Ring in u, v, x, y over Rational Field by the ideal (u^2 + v^2) - sage: Q.term_order() # needs sage.libs.singular + sage: Q.term_order() Block term order with blocks: (Degree reverse lexicographic term order of length 2, Degree reverse lexicographic term order of length 2) @@ -3128,7 +3130,7 @@ def _tensor_product_ring(B, A): Local orderings are not supported:: sage: R = PolynomialRing(QQ, 'x,y', order='negdeglex') - sage: _tensor_product_ring(R, R) + sage: _tensor_product_ring(R, R) # needs sage.libs.singular Traceback (most recent call last): ... ValueError: term ordering must be global diff --git a/src/sage/rings/number_field/S_unit_solver.py b/src/sage/rings/number_field/S_unit_solver.py index 92f7af1bf19..b7e40d9893d 100644 --- a/src/sage/rings/number_field/S_unit_solver.py +++ b/src/sage/rings/number_field/S_unit_solver.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.rings.number_field sage.rings.padics r""" Solve S-unit equation x + y = 1 @@ -104,7 +105,7 @@ def column_Log(SUK, iota, U, prec=106): sage: phi_complex = K.places()[1] sage: v_fin = S[0] sage: U = [phi_complex, v_fin] - sage: column_Log(SUK, xi^2, U) # abs tol 1e-29 + sage: column_Log(SUK, xi^2, U) # abs tol 1e-29 [1.464816384890812968648768625966, -2.197224577336219382790490473845] REFERENCES: @@ -787,10 +788,10 @@ def c11_func(SUK, v, A, prec=106): sage: phi_complex = K.places()[1] sage: A = K.roots_of_unity() - sage: c11_func(SUK, phi_real, A) # abs tol 1e-29 + sage: c11_func(SUK, phi_real, A) # abs tol 1e-29 3.255848343572896153455615423662 - sage: c11_func(SUK, phi_complex, A) # abs tol 1e-29 + sage: c11_func(SUK, phi_complex, A) # abs tol 1e-29 6.511696687145792306911230847323 REFERENCES: @@ -827,10 +828,10 @@ def c13_func(SUK, v, prec=106): sage: phi_real = K.places()[0] sage: phi_complex = K.places()[1] - sage: c13_func(SUK, phi_real) # abs tol 1e-29 + sage: c13_func(SUK, phi_real) # abs tol 1e-29 0.4257859134798034746197327286726 - sage: c13_func(SUK, phi_complex) # abs tol 1e-29 + sage: c13_func(SUK, phi_complex) # abs tol 1e-29 0.2128929567399017373098663643363 It is an error to input a finite place. :: @@ -968,7 +969,7 @@ def minimal_vector(A, y, prec=106): [ 1 1 -2] [ 6 1 -1] sage: y = vector([1, 2, 100]) - sage: minimal_vector(B, y) # random + sage: minimal_vector(B, y) # random 15/28 """ if A.is_singular(): diff --git a/src/sage/rings/number_field/bdd_height.py b/src/sage/rings/number_field/bdd_height.py index e467ee9df0e..ee2080c3bd7 100644 --- a/src/sage/rings/number_field/bdd_height.py +++ b/src/sage/rings/number_field/bdd_height.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.geometry.polyhedron r""" Elements of bounded height in number fields diff --git a/src/sage/rings/number_field/galois_group.py b/src/sage/rings/number_field/galois_group.py index 07b58b7b2a2..6e159f9e3fa 100644 --- a/src/sage/rings/number_field/galois_group.py +++ b/src/sage/rings/number_field/galois_group.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.groups sage.rings.number_field """ Galois Groups of Number Fields diff --git a/src/sage/rings/number_field/morphism.py b/src/sage/rings/number_field/morphism.py index 14ad5772d3b..a16ccd2bbc6 100644 --- a/src/sage/rings/number_field/morphism.py +++ b/src/sage/rings/number_field/morphism.py @@ -114,6 +114,7 @@ def preimage(self, y): :: + sage: # needs sage.libs.linbox sage: F. = QuadraticField(23) sage: G. = F.extension(x^3 + 5) sage: f = F.embeddings(G)[0] diff --git a/src/sage/rings/number_field/number_field.py b/src/sage/rings/number_field/number_field.py index 7ffeeca710b..f4c3948e9e5 100644 --- a/src/sage/rings/number_field/number_field.py +++ b/src/sage/rings/number_field/number_field.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.libs.linbox r""" Number Fields @@ -127,7 +127,7 @@ from sage.misc.fast_methods import WithEqualityById from sage.misc.functional import is_odd, lift - +from sage.misc.lazy_import import lazy_import from sage.misc.misc_c import prod from sage.rings.infinity import Infinity from sage.categories.number_fields import NumberFields @@ -162,6 +162,10 @@ from sage.interfaces.abc import GapElement +lazy_import('sage.libs.gap.element', 'GapElement', as_='LibGapElement') +lazy_import('sage.rings.universal_cyclotomic_field', 'UniversalCyclotomicFieldElement') + + _NumberFields = NumberFields() @@ -199,7 +203,7 @@ def is_NumberFieldHomsetCodomain(codomain): Caveat: Gap objects are not (yet) in :class:`Fields`, and therefore not accepted as number field homset codomains:: - sage: is_NumberFieldHomsetCodomain(gap.Rationals) + sage: is_NumberFieldHomsetCodomain(gap.Rationals) # needs sage.libs.gap False """ from sage.categories.fields import Fields @@ -400,7 +404,7 @@ def NumberField(polynomial, name=None, check=True, names=None, embedding=None, sage: K. = NumberField(x^3-2, embedding=CC.gen()-0.6) sage: CC(a) -0.629960524947436 + 1.09112363597172*I - sage: L = Qp(5) + sage: L = Qp(5) # needs sage.rings.padics sage: f = polygen(L)^3 - 2 sage: K. = NumberField(x^3-2, embedding=f.roots()[0][0]) sage: a + L(1) @@ -781,7 +785,7 @@ def NumberFieldTower(polynomials, names, check=True, embeddings=None, latex_name The Galois group is a product of 3 groups of order 2:: - sage: k.absolute_field(names='c').galois_group() + sage: k.absolute_field(names='c').galois_group() # needs sage.groups Galois group 8T3 (2[x]2[x]2) with order 8 of x^8 + 36*x^6 + 302*x^4 + 564*x^2 + 121 Repeatedly calling base_field allows us to descend the internally @@ -1204,7 +1208,7 @@ def create_object(self, version, key, **extra_args): TESTS:: - sage: CyclotomicField.create_object(None, (0, None, True)) + sage: CyclotomicField.create_object(None, (0, None, True)) # needs sage.libs.gap Universal Cyclotomic Field """ n, names, embedding = key @@ -1329,8 +1333,8 @@ class NumberField_generic(WithEqualityById, number_field_base.NumberField): This example was suggested on sage-nt; see :trac:`18942`:: - sage: G = DirichletGroup(80) - sage: for chi in G: # long time + sage: G = DirichletGroup(80) # needs sage.modular + sage: for chi in G: # long time # needs sage.modular ....: D = ModularSymbols(chi, 2, -1).cuspidal_subspace().new_subspace().decomposition() ....: for f in D: ....: elt = f.q_eigenform(10, 'alpha')[3] @@ -1716,13 +1720,13 @@ def _element_constructor_(self, x, check=True): Check that :trac:`30961` is fixed:: + sage: # needs sage.symbolic sage: QQi = i.parent() - sage: x = SR.var('x') # needs sage.symbolic - sage: QQi((x, x)) # needs sage.symbolic + sage: x = SR.var('x') + sage: QQi((x, x)) Traceback (most recent call last): ... TypeError: unable to convert x to a rational - sage: QQi(("1", "2")) 2*I + 1 sage: QQi((RR(1), RR(2))) @@ -9334,6 +9338,7 @@ def embeddings(self, K): We embed a cubic field in the complex numbers:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^3 - 2) sage: K.embeddings(CC) [ @@ -11349,14 +11354,11 @@ def _element_constructor_(self, x, check=True): return NumberField_absolute._element_constructor_(self, x) elif isinstance(x, pari_gen): return NumberField_absolute._element_constructor_(self, x, check=check) - elif isinstance(x, (sage.libs.gap.element.GapElement, GapElement)): + elif isinstance(x, (LibGapElement, GapElement)): return self._coerce_from_gap(x) elif isinstance(x, str): return self._convert_from_str(x) - - # late import because of speed - from sage.rings.universal_cyclotomic_field import UniversalCyclotomicFieldElement - if isinstance(x, UniversalCyclotomicFieldElement): + elif isinstance(x, UniversalCyclotomicFieldElement): return x.to_cyclotomic_field(self) else: return self._convert_non_number_field_element(x) @@ -12055,7 +12057,7 @@ def __init__(self, polynomial, name=None, latex_name=None, check=True, embedding self._standard_embedding = True # set the generator and element class - c, b, a = [QQ(t) for t in self.defining_polynomial().list()] + c, b, a = (QQ(t) for t in self.defining_polynomial().list()) Dpoly = b*b - 4*a*c D = (Dpoly.numer() * Dpoly.denom()).squarefree_part(bound=10000) self._D = D @@ -12724,12 +12726,12 @@ def _splitting_classes_gens_(K, m, d): sage: L = K.subfields(20)[0][0] sage: L.conductor() 101 - sage: _splitting_classes_gens_(L,101,20) + sage: _splitting_classes_gens_(L,101,20) # needs sage.libs.gap [95] sage: K = CyclotomicField(44) sage: L = K.subfields(4)[0][0] - sage: _splitting_classes_gens_(L,44,4) + sage: _splitting_classes_gens_(L,44,4) # needs sage.libs.gap [37] sage: K = CyclotomicField(44) @@ -12741,7 +12743,7 @@ def _splitting_classes_gens_(K, m, d): with zeta44_0 = 3.837971894457990? sage: L.conductor() 11 - sage: _splitting_classes_gens_(L,11,5) + sage: _splitting_classes_gens_(L,11,5) # needs sage.libs.gap [10] """ diff --git a/src/sage/rings/number_field/number_field_base.pyx b/src/sage/rings/number_field/number_field_base.pyx index 538dc8b0579..40961d24d41 100644 --- a/src/sage/rings/number_field/number_field_base.pyx +++ b/src/sage/rings/number_field/number_field_base.pyx @@ -5,6 +5,7 @@ Base class for all number fields TESTS:: + sage: x = polygen(ZZ) sage: k = NumberField(x^2 + 1, 'i'); k == loads(dumps(k)) True """ @@ -19,6 +20,7 @@ def is_NumberField(x): EXAMPLES:: sage: from sage.rings.number_field.number_field_base import is_NumberField + sage: x = polygen(ZZ) sage: is_NumberField(NumberField(x^2 + 1, 'a')) doctest:...: DeprecationWarning: the function is_NumberField is deprecated; use isinstance(x, sage.rings.number_field.number_field_base.NumberField) instead @@ -74,6 +76,7 @@ cdef class NumberField(Field): Pushout is implemented for number field embedded in ``AA``:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 - 3, embedding=AA(3)**(1/2)) sage: L. = NumberField(x^2 - 2, embedding=AA(2)**(1/2)) sage: cm = sage.structure.element.get_coercion_model() @@ -151,6 +154,7 @@ cdef class NumberField(Field): EXAMPLES:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^2 + 1) sage: K.ring_of_integers() Gaussian Integers in Number Field in a with defining polynomial x^2 + 1 @@ -163,6 +167,7 @@ cdef class NumberField(Field): EXAMPLES:: + sage: x = polygen(ZZ) sage: NumberField(x^3 - 2,'a').OK() Maximal Order in Number Field in a with defining polynomial x^3 - 2 """ @@ -175,6 +180,7 @@ cdef class NumberField(Field): EXAMPLES:: + sage: x = polygen(ZZ) sage: NumberField(x^3 - 2,'b').maximal_order() Maximal Order in Number Field in b with defining polynomial x^3 - 2 """ @@ -186,11 +192,12 @@ cdef class NumberField(Field): EXAMPLES:: - sage: K. = NumberField(x^3+2) + sage: x = polygen(ZZ) + sage: K. = NumberField(x^3 + 2) sage: K.is_absolute() True sage: y = polygen(K) - sage: L. = NumberField(y^2+1) + sage: L. = NumberField(y^2 + 1) sage: L.is_absolute() False sage: QQ.is_absolute() @@ -205,6 +212,7 @@ cdef class NumberField(Field): EXAMPLES:: + sage: x = polygen(ZZ) sage: NumberField(x^3 - 2, 'a').signature() (1, 1) """ @@ -216,6 +224,7 @@ cdef class NumberField(Field): EXAMPLES:: + sage: x = polygen(ZZ) sage: NumberField(x^3 + 9, 'a').degree() 3 """ @@ -227,6 +236,7 @@ cdef class NumberField(Field): EXAMPLES:: + sage: x = polygen(ZZ) sage: NumberField(x^3 + 9, 'a').discriminant() -243 """ @@ -253,6 +263,7 @@ cdef class NumberField(Field): The Minkowski bound for `\QQ[i]` tells us that the class number is 1:: + sage: # needs sage.symbolic sage: K = QQ[I] sage: B = K.minkowski_bound(); B 4/pi @@ -261,6 +272,7 @@ cdef class NumberField(Field): We compute the Minkowski bound for `\QQ[\sqrt[3]{2}]`:: + sage: # needs sage.symbolic sage: K = QQ[2^(1/3)] sage: B = K.minkowski_bound(); B 16/3*sqrt(3)/pi @@ -272,6 +284,7 @@ cdef class NumberField(Field): We compute the Minkowski bound for `\QQ[\sqrt{10}]`, which has class number 2:: + sage: # needs sage.symbolic sage: K = QQ[sqrt(10)] sage: B = K.minkowski_bound(); B sqrt(10) @@ -282,7 +295,9 @@ cdef class NumberField(Field): We compute the Minkowski bound for `\QQ[\sqrt{2}+\sqrt{3}]`:: - sage: K. = NumberField([x^2-2, x^2-3]) + sage: # needs sage.symbolic + sage: x = polygen(ZZ) + sage: K. = NumberField([x^2 - 2, x^2 - 3]) sage: L. = QQ[sqrt(2) + sqrt(3)] sage: B = K.minkowski_bound(); B 9/2 @@ -328,6 +343,7 @@ cdef class NumberField(Field): We compute both the Minkowski and Bach bounds for a quadratic field, where the Minkowski bound is much better:: + sage: # needs sage.symbolic sage: K = QQ[sqrt(5)] sage: K.minkowski_bound() 1/2*sqrt(5) @@ -341,6 +357,7 @@ cdef class NumberField(Field): We compute both the Minkowski and Bach bounds for a bigger degree field, where the Bach bound is much better:: + sage: # needs sage.symbolic sage: K = CyclotomicField(37) sage: K.minkowski_bound().n() 7.50857335698544e14 @@ -349,7 +366,7 @@ cdef class NumberField(Field): The bound of course also works for the rational numbers:: - sage: QQ.minkowski_bound() + sage: QQ.bach_bound() # needs sage.symbolic 1 """ ans = 12 * abs(self.discriminant()).log()**2 @@ -369,6 +386,7 @@ cdef class NumberField(Field): TESTS:: + sage: x = polygen(ZZ) sage: K. = NumberField(x^3 - x^2 - x - 1, embedding=1) sage: K._get_embedding_approx(0) # indirect doctest 1.839286755214161? @@ -413,7 +431,6 @@ cdef class NumberField(Field): sage: K._get_embedding_approx(1).str(style='brackets') '[0.334734141943352687075098962473280 .. 0.334734141943352687075098962473287]' - sage: K._get_embedding_approx(2).prec() 212 sage: K._get_embedding_approx(1).prec() diff --git a/src/sage/rings/number_field/number_field_element.pxd b/src/sage/rings/number_field/number_field_element.pxd index 612e5cce09c..c73d1806fc7 100644 --- a/src/sage/rings/number_field/number_field_element.pxd +++ b/src/sage/rings/number_field/number_field_element.pxd @@ -4,7 +4,6 @@ from sage.rings.integer cimport Integer from sage.rings.number_field.number_field_element_base cimport NumberFieldElement_base from sage.rings.polynomial.polynomial_element cimport Polynomial from sage.structure.parent cimport Parent -from sage.structure.parent_base cimport ParentWithBase from sage.libs.ntl.types cimport ZZ_c, ZZX_c from sage.libs.ntl.ntl_ZZX cimport ntl_ZZX from sage.libs.ntl.ntl_ZZ cimport ntl_ZZ diff --git a/src/sage/rings/number_field/number_field_element.pyx b/src/sage/rings/number_field/number_field_element.pyx index e141c38ba79..a0553fc31d9 100644 --- a/src/sage/rings/number_field/number_field_element.pyx +++ b/src/sage/rings/number_field/number_field_element.pyx @@ -4,6 +4,7 @@ # distutils: library_dirs = NTL_LIBDIR # distutils: extra_link_args = NTL_LIBEXTRA # distutils: language = c++ +# sage.doctest: needs sage.libs.linbox """ Number field elements (implementation using NTL) @@ -54,7 +55,6 @@ from sage.libs.gmp.pylong cimport mpz_pythonhash from cpython.object cimport Py_EQ, Py_NE, Py_LT, Py_GT, Py_LE, Py_GE from sage.structure.richcmp cimport rich_to_bool -import sage.rings.infinity import sage.rings.polynomial.polynomial_element from sage.rings.polynomial.evaluation_ntl cimport ZZX_evaluation_mpfi import sage.rings.rational_field @@ -97,6 +97,7 @@ from sage.rings.cc import CC # issue 5213 TUNE_CHARPOLY_NF = 25 + def is_NumberFieldElement(x): """ Return ``True`` if `x` is of type :class:`NumberFieldElement`, i.e., an element of @@ -212,12 +213,10 @@ cdef class NumberFieldElement(NumberFieldElement_base): """ INPUT: - - ``parent`` -- a number field - ``f`` -- defines an element of a number field. - EXAMPLES: The following examples illustrate creation of elements of @@ -286,8 +285,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): # set it up and exit immediately # fast pathway mpz_to_ZZ(&coeff, (ZZ(f)).value) - ZZX_SetCoeff( self._numerator, 0, coeff ) - ZZ_conv_from_int( self._denominator, 1 ) + ZZX_SetCoeff(self._numerator, 0, coeff) + ZZ_conv_from_int(self._denominator, 1) return elif isinstance(f, NumberFieldElement): if type(self) is type(f): @@ -308,7 +307,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): num = f * den for i from 0 <= i <= num.degree(): mpz_to_ZZ(&coeff, (ZZ(num[i])).value) - ZZX_SetCoeff( self._numerator, i, coeff ) + ZZX_SetCoeff(self._numerator, i, coeff) def _lift_cyclotomic_element(self, new_parent, bint check=True, int rel=0): """ @@ -356,7 +355,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): if check: from .number_field import NumberField_cyclotomic if not isinstance(self.number_field(), NumberField_cyclotomic) \ - or not isinstance(new_parent, NumberField_cyclotomic): + or not isinstance(new_parent, NumberField_cyclotomic): raise TypeError("The field and the new parent field must both be cyclotomic fields.") if rel == 0: @@ -368,8 +367,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): except TypeError: raise TypeError("The zeta_order of the new field must be a multiple of the zeta_order of the original.") - ## degree 2 is handled differently, because elements are - ## represented differently + # degree 2 is handled differently, because elements are + # represented differently if new_parent.degree() == 2: if rel == 1: return new_parent._element_class(new_parent, self) @@ -378,7 +377,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef type t = type(self) cdef NumberFieldElement x = t.__new__(t) - x._parent = new_parent + x._parent = new_parent x._fld_numerator, x._fld_denominator = new_parent.polynomial_ntl() x._denominator = self._denominator cdef ZZX_c result @@ -488,13 +487,13 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: # needs sage.libs.gap sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: (a**2 - a + 1)._gap_init_() '\\$sage4^2 - \\$sage4 + 1' sage: gap(_) a^2-a+1 - sage: F = CyclotomicField(8) sage: F.gen() zeta8 @@ -512,7 +511,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): Check that :trac:`15276` is fixed:: - sage: for n in range(2,20): + sage: for n in range(2,20): # needs sage.libs.gap ....: K = CyclotomicField(n) ....: assert K(gap(K.gen())) == K.gen(), "n = {}".format(n) ....: assert K(gap(K.one())) == K.one(), "n = {}".format(n) @@ -527,12 +526,12 @@ cdef class NumberFieldElement(NumberFieldElement_base): from .number_field import NumberField_cyclotomic if isinstance(P, NumberField_cyclotomic): n = P._n() - if n != 2 and n%4 == 2: + if n != 2 and n % 4 == 2: x = p.variables()[0] p = p(-x**((n//2+1)//2)) - E = 'E(%d)'%(n//2) + E = 'E(%d)' % (n//2) else: - E = 'E(%d)'%n + E = 'E(%d)' % n else: E = self.parent()._gap_().GeneratorsOfField()[1].name() return str(p).replace(p.variable_name(), E) @@ -543,15 +542,16 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: # needs sage.libs.gap sage: F = CyclotomicField(8) - sage: F.gen()._libgap_() # needs sage.libs.gap + sage: F.gen()._libgap_() E(8) - sage: libgap(F.gen()) # syntactic sugar # needs sage.libs.gap + sage: libgap(F.gen()) # syntactic sugar E(8) - sage: E8 = F.gen() # needs sage.libs.gap - sage: libgap(E8 + 3/2*E8^2 + 100*E8^7) # needs sage.libs.gap + sage: E8 = F.gen() + sage: libgap(E8 + 3/2*E8^2 + 100*E8^7) E(8)+3/2*E(8)^2-100*E(8)^3 - sage: type(_) # needs sage.libs.gap + sage: type(_) Check that :trac:`15276` is fixed:: @@ -572,8 +572,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): from sage.libs.gap.libgap import libgap E = libgap(P).GeneratorsOfField()[0] n = P._n() - if n%4 == 2: - E = -E**((n//2+1)//2) + if n % 4 == 2: + E = -E**((n//2 + 1)//2) return self.polynomial()(E) def _pari_polynomial(self, name='y'): @@ -582,15 +582,16 @@ cdef class NumberFieldElement(NumberFieldElement_base): TESTS: + sage: # needs sage.libs.pari sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) - sage: K.zero()._pari_polynomial('x') # needs sage.libs.pari + sage: K.zero()._pari_polynomial('x') 0 - sage: K.one()._pari_polynomial() # needs sage.libs.pari + sage: K.one()._pari_polynomial() 1 - sage: (a + 1)._pari_polynomial() # needs sage.libs.pari + sage: (a + 1)._pari_polynomial() y + 1 - sage: a._pari_polynomial('c') # needs sage.libs.pari + sage: a._pari_polynomial('c') c """ f = pari(self._coefficients()).Polrev() @@ -613,14 +614,15 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: + sage: # needs sage.libs.pari sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 + 2) - sage: K(1).__pari__() # needs sage.libs.pari + sage: K(1).__pari__() Mod(1, y^3 + 2) - sage: (a + 2).__pari__() # needs sage.libs.pari + sage: (a + 2).__pari__() Mod(y + 2, y^3 + 2) sage: L. = K.extension(x^2 + 2) - sage: (b + a).__pari__() # needs sage.libs.pari + sage: (b + a).__pari__() Mod(24/101*y^5 - 9/101*y^4 + 160/101*y^3 - 156/101*y^2 + 397/101*y + 364/101, y^6 + 6*y^4 - 4*y^3 + 12*y^2 + 24*y + 12) :: @@ -856,7 +858,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): ZZX_evaluation_mpfi(ra, _right._numerator, v.value) mpfi_div_z(ra, ra, rd) while mpfr_greaterequal_p(&la.right, &ra.left) \ - and mpfr_greaterequal_p(&ra.right, &la.left): + and mpfr_greaterequal_p(&ra.right, &la.left): i += 1 v = P._get_embedding_approx(i) mpfi_set_prec(la, mpfi_get_prec(v.value)) @@ -906,7 +908,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef int _randomize(self, num_bound, den_bound, distribution) except -1: cdef int i cdef Integer denom_temp = Integer.__new__(Integer) - cdef Integer tmp_integer = Integer.__new__(Integer) + cdef Integer tmp_int = Integer.__new__(Integer) cdef ZZ_c ntl_temp cdef list coeff_list cdef Rational tmp_rational @@ -928,16 +930,16 @@ cdef class NumberFieldElement(NumberFieldElement_base): # set the denominator mpz_set_si(denom_temp.value, 1) mpz_to_ZZ(&self._denominator, (denom_temp).value) - for i from 0 <= i < ZZX_deg(self._fld_numerator.x): - tmp_integer = (ZZ.random_element(x=num_bound, - distribution=distribution)) - mpz_to_ZZ(&ntl_temp, (tmp_integer).value) + for i in range(ZZX_deg(self._fld_numerator.x)): + tmp_int = (ZZ.random_element(x=num_bound, + distribution=distribution)) + mpz_to_ZZ(&ntl_temp, (tmp_int).value) ZZX_SetCoeff(self._numerator, i, ntl_temp) else: coeff_list = [] mpz_set_si(denom_temp.value, 1) - tmp_integer = Integer.__new__(Integer) + tmp_int = Integer.__new__(Integer) for i from 0 <= i < ZZX_deg(self._fld_numerator.x): tmp_rational = (QQ.random_element(num_bound=num_bound, @@ -960,19 +962,18 @@ cdef class NumberFieldElement(NumberFieldElement_base): # also know is integral -- so we can use mpz_divexact # below tmp_rational = (coeff_list[i]) - mpz_mul(tmp_integer.value, mpq_numref(tmp_rational.value), + mpz_mul(tmp_int.value, mpq_numref(tmp_rational.value), denom_temp.value) - mpz_divexact(tmp_integer.value, tmp_integer.value, + mpz_divexact(tmp_int.value, tmp_int.value, mpq_denref(tmp_rational.value)) # now set the coefficient of self - mpz_to_ZZ(&ntl_temp, (tmp_integer).value) + mpz_to_ZZ(&ntl_temp, (tmp_int).value) ZZX_SetCoeff(self._numerator, i, ntl_temp) return 0 # No error - def __abs__(self): r""" Return the absolute value of this number field element. @@ -983,9 +984,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): Otherwise, it is the numerical absolute value with respect to the first archimedean embedding, to double precision. - This is the ``abs( )`` Python function. If you want a - different embedding or precision, use - ``self.abs(...)``. + This is the :func:`abs` Python function. If you want a + different embedding or precision, use ``self.abs(...)``. EXAMPLES:: @@ -1114,7 +1114,6 @@ cdef class NumberFieldElement(NumberFieldElement_base): cdef size_t i cdef RealIntervalFieldElement v - if ZZX_deg(self._numerator) <= 0: mpz_init(num) mpz_init(den) @@ -1133,7 +1132,6 @@ cdef class NumberFieldElement(NumberFieldElement_base): if not ( self._parent)._embedded_real: raise TypeError("floor not uniquely defined since no real embedding is specified") - cdef number_field_base.NumberField P try: P = self._parent @@ -1365,18 +1363,18 @@ cdef class NumberFieldElement(NumberFieldElement_base): """ if (i is None and prec is None - and ( self._parent)._embedded_real): + and ( self._parent)._embedded_real): return self.sign() * self - else: - if prec is None: - prec = 53 - CCprec = ComplexField(prec) - if i is None and CCprec.has_coerce_map_from(self.parent()): - return CCprec(self).abs() - else: - i = 0 if i is None else i - P = self.number_field().complex_embeddings(prec)[i] - return P(self).abs() + + if prec is None: + prec = 53 + CCprec = ComplexField(prec) + if i is None and CCprec.has_coerce_map_from(self.parent()): + return CCprec(self).abs() + + i = 0 if i is None else i + P = self.number_field().complex_embeddings(prec)[i] + return P(self).abs() def abs_non_arch(self, P, prec=None): r""" @@ -1624,12 +1622,12 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: L. = NumberField(X^4 + a + 2) sage: (a/4).is_norm(L) True - sage: (a/2).is_norm(L) + sage: (a/2).is_norm(L) # needs sage.groups Traceback (most recent call last): ... NotImplementedError: is_norm is not implemented unconditionally for norms from non-Galois number fields - sage: (a/2).is_norm(L, proof=False) + sage: (a/2).is_norm(L, proof=False) # needs sage.groups False sage: K. = NumberField(x^3 + x + 1) @@ -2106,11 +2104,10 @@ cdef class NumberFieldElement(NumberFieldElement_base): K = R.number_field() g = K.fractional_ideal(self, other).gens_reduced() if len(g) > 1: - raise ArithmeticError("ideal (%r, %r) is not principal, gcd is not defined" % (self, other) ) + raise ArithmeticError("ideal (%r, %r) is not principal, gcd is not defined" % (self, other)) return R(g[0]) - def is_totally_positive(self): """ Return ``True`` if ``self`` is positive for all real embeddings of its @@ -2228,7 +2225,6 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: K(5).is_padic_square(p) False """ - infinity = sage.rings.infinity.infinity return self.parent().quadratic_defect(self, P, check=check) == infinity def sqrt(self, all=False, extend=True): @@ -2308,7 +2304,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): root = sqrt(SR(self)) roots = [[root, 1], [-root, 1]] except TypeError: - raise ValueError("%s not a square in %s"%(self, self._parent)) + raise ValueError("%s not a square in %s" % (self, self._parent)) if all: return [r[0] for r in roots] elif roots: @@ -2339,10 +2335,9 @@ cdef class NumberFieldElement(NumberFieldElement_base): roots = f.roots() if all: return [r[0] for r in roots] - elif roots: + if roots: return roots[0][0] - else: - raise ValueError("%s not a %s-th root in %s"%(self, n, self._parent)) + raise ValueError("%s not a %s-th root in %s" % (self, n, self._parent)) def is_nth_power(self, n): r""" @@ -2412,7 +2407,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): TypeError: no canonical coercion from Number Field in a with defining polynomial x^2 + 1 to Symbolic Ring """ if (isinstance(base, NumberFieldElement) and - (isinstance(exp, Integer) or type(exp) is int or exp in ZZ)): + (isinstance(exp, Integer) or type(exp) is int or exp in ZZ)): return generic_power(base, exp) else: cbase, cexp = canonical_coercion(base, exp) @@ -2539,8 +2534,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): else: ZZX_mul(x._numerator, self._numerator, _right._numerator) if ZZX_deg(x._numerator) >= ZZX_deg(self._fld_numerator.x): - ZZX_mul_ZZ( x._numerator, x._numerator, self._fld_denominator.x ) - ZZX_mul_ZZ( temp, self._fld_numerator.x, x._denominator ) + ZZX_mul_ZZ(x._numerator, x._numerator, self._fld_denominator.x) + ZZX_mul_ZZ(temp, self._fld_numerator.x, x._denominator) ZZ_power(temp1,ZZX_LeadCoeff(temp),ZZX_deg(x._numerator)-ZZX_deg(self._fld_numerator.x)+1) ZZX_PseudoRem(x._numerator, x._numerator, temp) ZZ_mul(x._denominator, x._denominator, self._fld_denominator.x) @@ -2840,7 +2835,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): -1/2 """ if ZZX_deg(self._numerator) >= 1: - raise TypeError("Unable to coerce %s to a rational"%self) + raise TypeError("Unable to coerce %s to a rational" % self) cdef Integer num = Integer.__new__(Integer) ZZX_getitem_as_mpz(num.value, &self._numerator, 0) cdef Integer den = Integer.__new__(Integer) @@ -3011,9 +3006,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): from sage.rings.complex_mpfr import ComplexField from sage.rings.imaginary_unit import I from sage.symbolic.constants import pi - CC = ComplexField(53) two_pi_i = 2 * pi * I - k = ( K._n()*CC(K.gen()).log() / CC(two_pi_i) ).real().round() # n ln z / (2 pi i) + k = (K._n()*CC(K.gen()).log() / CC(two_pi_i)).real().round() # n ln z / (2 pi i) gen_image = exp(k*two_pi_i/K._n()) return self.polynomial()(gen_image) else: @@ -3055,13 +3049,13 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: c = a.galois_conjugates(K); c [a] sage: K. = NumberField(x^3 - 2) - sage: c = a.galois_conjugates(K.galois_closure('a1')); c + sage: c = a.galois_conjugates(K.galois_closure('a1')); c # needs sage.groups [1/18*a1^4, -1/36*a1^4 + 1/2*a1, -1/36*a1^4 - 1/2*a1] sage: c[0]^3 2 sage: parent(c[0]) Number Field in a1 with defining polynomial x^6 + 108 - sage: parent(c[0]).is_galois() + sage: parent(c[0]).is_galois() # needs sage.groups True There is only one Galois conjugate of `\sqrt[3]{2}` in @@ -3378,21 +3372,21 @@ cdef class NumberFieldElement(NumberFieldElement_base): elif (-self).is_one(): self.__multiplicative_order = ZZ(2) else: - self.__multiplicative_order = sage.rings.infinity.infinity + self.__multiplicative_order = infinity elif not (self.is_integral() and self.norm().is_one()): - self.__multiplicative_order = sage.rings.infinity.infinity + self.__multiplicative_order = infinity elif isinstance(self.number_field(), NumberField_cyclotomic): t = self.number_field()._multiplicative_order_table() f = self.polynomial() if f in t: self.__multiplicative_order = t[f] else: - self.__multiplicative_order = sage.rings.infinity.infinity + self.__multiplicative_order = infinity else: # Now we have a unit of norm 1, and check if it is a root of unity n = self.number_field().zeta_order() if not self**n ==1: - self.__multiplicative_order = sage.rings.infinity.infinity + self.__multiplicative_order = infinity else: from sage.groups.generic import order_from_multiple self.__multiplicative_order = order_from_multiple(self,n,operation='*') @@ -3415,8 +3409,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: K.ring_of_integers().characteristic() # implicit doctest 0 """ - if not self: return ZZ.one() - else: return sage.rings.infinity.infinity + return ZZ.one() if not self else infinity cpdef bint is_one(self) noexcept: r""" @@ -3438,7 +3431,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): False """ return ZZX_IsOne(self._numerator) == 1 and \ - ZZ_IsOne(self._denominator) == 1 + ZZ_IsOne(self._denominator) == 1 cpdef bint is_rational(self) noexcept: r""" @@ -3706,7 +3699,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: b^2 - (22+a) 0 """ - return self.charpoly(var).radical() # square free part of charpoly + return self.charpoly(var).radical() # square free part of charpoly def is_integral(self): r""" @@ -3991,13 +3984,13 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: L(1/4).local_height(L.ideal(2, c - a + 1)) 1.38629436111989 """ - if self.valuation(P) >= 0: ## includes the case self=0 + if self.valuation(P) >= 0: # includes the case self=0 from sage.rings.real_mpfr import RealField if prec is None: return RealField().zero() else: return RealField(prec).zero() - ht = self.abs_non_arch(P,prec).log() + ht = self.abs_non_arch(P, prec).log() if not weighted: return ht nP = P.residue_class_degree()*P.absolute_ramification_index() @@ -4332,15 +4325,14 @@ cdef class NumberFieldElement(NumberFieldElement_base): """ L = phi.domain() - ## the code below doesn't work if the morphism is - ## over QQ, since QQ.primitive_element() doesn't - ## make sense + # the code below doesn't work if the morphism is + # over QQ, since QQ.primitive_element() doesn't make sense if L is QQ: K = phi.codomain() if K != self.number_field(): raise ValueError("codomain of phi must be parent of self") - ## the variable name is irrelevant below, because the - ## matrix is over QQ + # the variable name is irrelevant below, because the + # matrix is over QQ F = K.absolute_field('alpha') _, to_F = F.structure() return to_F(self).matrix() @@ -4352,7 +4344,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): raise ValueError("codomain of phi must be parent of self") # Construct a relative extension over L (= QQ(beta)) - M = K.relativize(beta, (K.variable_name()+'0', L.variable_name()+'0') ) + M = K.relativize(beta, (K.variable_name()+'0', L.variable_name()+'0')) # Carry self over to M. _, to_M = M.structure() @@ -4368,7 +4360,6 @@ cdef class NumberFieldElement(NumberFieldElement_base): psi = M.base_field().hom([alpha]) return R.apply_morphism(psi) - def list(self): """ Return the list of coefficients of ``self`` written in terms of a power @@ -4427,10 +4418,9 @@ cdef class NumberFieldElement(NumberFieldElement_base): R = self.number_field().ring_of_integers() try: return _inverse_mod_generic(R(self), I) - except TypeError: # raised by failure of R(self) + except TypeError: # raised by failure of R(self) raise NotImplementedError("inverse_mod is not implemented for non-integral elements") - def residue_symbol(self, P, m, check=True): r""" The `m`-th power residue symbol for an element ``self`` and proper ideal `P`. @@ -4475,7 +4465,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: L. = K.extension(x^2 + 1) sage: K(7).residue_symbol(K.ideal(11),2) -1 - sage: K(7).residue_symbol(L.ideal(11),2) + sage: K(7).residue_symbol(L.ideal(11),2) # needs sage.libs.gap 1 Cubic Residue:: @@ -4551,7 +4541,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): from sage.sets.set import Set - if K is QQ: # simpler special case avoids relativizing + if K is QQ: # simpler special case avoids relativizing # First set of primes: those which ramify in L/K: S1 = L.absolute_discriminant().prime_factors() # Second set of primes: those where self has nonzero valuation mod d: @@ -4706,7 +4696,7 @@ cdef class NumberFieldElement_absolute(NumberFieldElement): zeta9 """ K = magma(self.parent()) - return '(%s!%s)'%(K.name(), self.list()) + return '(%s!%s)' % (K.name(), self.list()) def absolute_charpoly(self, var='x', algorithm=None): r""" @@ -4848,9 +4838,8 @@ cdef class NumberFieldElement_absolute(NumberFieldElement): sage: R(a).minpoly(algorithm='pari') == R(a).minpoly(algorithm='sage') True - """ - return self.charpoly(var, algorithm).radical() # square free part of charpoly + return self.charpoly(var, algorithm).radical() # square free part of charpoly def list(self): r""" @@ -5571,7 +5560,6 @@ cdef class OrderElement_relative(NumberFieldElement_relative): return R(K(self).absolute_minpoly(var)) - class CoordinateFunction(): r""" This class provides a callable object which expresses @@ -5613,7 +5601,7 @@ class CoordinateFunction(): sage: f = (a + 1).coordinates_in_terms_of_powers(); repr(f) # indirect doctest 'Coordinate function that writes elements in terms of the powers of a + 1' """ - return "Coordinate function that writes elements in terms of the powers of %s"%self.__alpha + return "Coordinate function that writes elements in terms of the powers of %s" % self.__alpha def alpha(self): r""" @@ -5676,7 +5664,7 @@ class CoordinateFunction(): if not isinstance(other, CoordinateFunction): return False - return self.__K == other.__K and self.__alpha == other.__alpha + return self.__K == other.__K and self.__alpha == other.__alpha def __ne__(self, other): """ @@ -5707,4 +5695,4 @@ cdef void _ntl_poly(f, ZZX_c *num, ZZ_c *den) noexcept: __num = f * __den for i from 0 <= i <= __num.degree(): mpz_to_ZZ(&coeff, (ZZ(__num[i])).value) - ZZX_SetCoeff( num[0], i, coeff ) + ZZX_SetCoeff(num[0], i, coeff) diff --git a/src/sage/rings/number_field/number_field_element_quadratic.pyx b/src/sage/rings/number_field/number_field_element_quadratic.pyx index 57c2df2cb43..3cdaabb3140 100644 --- a/src/sage/rings/number_field/number_field_element_quadratic.pyx +++ b/src/sage/rings/number_field/number_field_element_quadratic.pyx @@ -4,6 +4,7 @@ # distutils: library_dirs = NTL_LIBDIR # distutils: extra_link_args = NTL_LIBEXTRA # distutils: language = c++ +# sage.doctest: needs sage.rings.number_field r""" Optimized Quadratic Number Field Elements diff --git a/src/sage/rings/number_field/number_field_ideal.py b/src/sage/rings/number_field/number_field_ideal.py index 161ef40a842..de95aa69369 100644 --- a/src/sage/rings/number_field/number_field_ideal.py +++ b/src/sage/rings/number_field/number_field_ideal.py @@ -273,6 +273,7 @@ def _mul_(self, other): EXAMPLES:: + sage: # needs sage.symbolic sage: K.=QQ[i] sage: A = K.ideal([5, 2 + I]) sage: B = K.ideal([13, 5 + 12*I]) @@ -804,11 +805,11 @@ def gens_reduced(self, proof=None): sage: R. = QQ['x'] sage: L. = NumberField(x^10 - 10*x^8 - 20*x^7 + 165*x^6 - 12*x^5 - 760*x^3 + 2220*x^2 + 5280*x + 7744) sage: z_x = -96698852571685/2145672615243325696*b^9 + 2472249905907/195061146840302336*b^8 + 916693155514421/2145672615243325696*b^7 + 1348520950997779/2145672615243325696*b^6 - 82344497086595/12191321677518896*b^5 + 2627122040194919/536418153810831424*b^4 - 452199105143745/48765286710075584*b^3 + 4317002771457621/536418153810831424*b^2 + 2050725777454935/67052269226353928*b + 3711967683469209/3047830419379724 - sage: P = EllipticCurve(L, '57a1').lift_x(z_x) * 3 - sage: ideal = L.fractional_ideal(P[0], P[1]) - sage: ideal.is_principal(proof=False) + sage: P = EllipticCurve(L, '57a1').lift_x(z_x) * 3 # needs sage.schemes + sage: ideal = L.fractional_ideal(P[0], P[1]) # needs sage.schemes + sage: ideal.is_principal(proof=False) # needs sage.schemes True - sage: len(ideal.gens_reduced(proof=False)) + sage: len(ideal.gens_reduced(proof=False)) # needs sage.schemes 1 """ if len(self.gens()) <= 1: diff --git a/src/sage/rings/number_field/number_field_morphisms.pyx b/src/sage/rings/number_field/number_field_morphisms.pyx index 18c2c54d2f2..1f6e12ce2c5 100644 --- a/src/sage/rings/number_field/number_field_morphisms.pyx +++ b/src/sage/rings/number_field/number_field_morphisms.pyx @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.rings.number_field r""" Embeddings into ambient fields diff --git a/src/sage/rings/number_field/number_field_rel.py b/src/sage/rings/number_field/number_field_rel.py index 26ab82bc54f..9e1e22dccd4 100644 --- a/src/sage/rings/number_field/number_field_rel.py +++ b/src/sage/rings/number_field/number_field_rel.py @@ -579,7 +579,7 @@ def galois_closure(self, names=None): sage: x = polygen(ZZ, 'x') sage: K. = NumberField([x^4 + 3, x^2 + 2]); K Number Field in a with defining polynomial x^4 + 3 over its base field - sage: K.galois_closure('c') + sage: K.galois_closure('c') # needs sage.groups Number Field in c with defining polynomial x^16 + 16*x^14 + 28*x^12 + 784*x^10 + 19846*x^8 - 595280*x^6 + 2744476*x^4 + 3212848*x^2 + 29953729 """ @@ -1234,7 +1234,7 @@ def is_galois_absolute(self): sage: x = polygen(ZZ, 'x') sage: K. = NumberField(x^3 - 2) sage: y = polygen(K); L. = K.extension(y^2 - a) - sage: L.is_galois_absolute() + sage: L.is_galois_absolute() # needs sage.groups False """ @@ -1255,6 +1255,8 @@ def is_isomorphic_relative(self, other, base_isom=None): sage: R. = PolynomialRing(K) sage: m1 = 3*z9^4 - 4*z9^3 - 4*z9^2 + 3*z9 - 8 sage: L1 = K.extension(z^2 - m1, 'b1') + + sage: # needs sage.groups sage: G = K.galois_group(); gamma = G.gen() sage: m2 = (gamma^2)(m1) sage: L2 = K.extension(z^2 - m2, 'b2') @@ -1262,6 +1264,7 @@ def is_isomorphic_relative(self, other, base_isom=None): False sage: L1.is_isomorphic(L2) True + sage: L3 = K.extension(z^4 - m1, 'b3') sage: L1.is_isomorphic_relative(L3) False @@ -1276,6 +1279,8 @@ def is_isomorphic_relative(self, other, base_isom=None): sage: L1cyc = Kcyc.extension(zcyc^2 - m1cyc, 'b1cyc') sage: L1.is_isomorphic_relative(L1cyc, base_isom=phi1) True + + sage: # needs sage.groups sage: L2.is_isomorphic_relative(L1cyc, base_isom=phi1) False sage: phi2 = K.hom([phi1((gamma^(-2))(z9))]) @@ -1296,7 +1301,7 @@ def is_isomorphic_relative(self, other, base_isom=None): The parameter ``base_isom`` can also be used to check if the relative extensions are Galois conjugate:: - sage: for g in G: + sage: for g in G: # needs sage.groups ....: if L1.is_isomorphic_relative(L2, g.as_hom()): ....: print(g.as_hom()) Ring endomorphism of Number Field in z9 with defining polynomial x^6 + x^3 + 1 @@ -2252,7 +2257,7 @@ def places(self, all_complex=False, prec=None): sage: x = polygen(ZZ, 'x') sage: L. = NumberFieldTower([x^2 - 5, x^3 + x + 3]) - sage: L.places() + sage: L.places() # needs sage.libs.linbox [Relative number field morphism: From: Number Field in b with defining polynomial x^2 - 5 over its base field To: Real Field with 106 bits of precision diff --git a/src/sage/rings/number_field/order.py b/src/sage/rings/number_field/order.py index f0b24b74630..896132b4e56 100644 --- a/src/sage/rings/number_field/order.py +++ b/src/sage/rings/number_field/order.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.linbox """ Orders in Number Fields diff --git a/src/sage/rings/number_field/splitting_field.py b/src/sage/rings/number_field/splitting_field.py index 927ecb3b5fb..46c535d2a5e 100644 --- a/src/sage/rings/number_field/splitting_field.py +++ b/src/sage/rings/number_field/splitting_field.py @@ -283,8 +283,8 @@ def splitting_field(poly, name, map=False, degree_multiple=None, abort_degree=No Some bigger examples:: sage: R. = PolynomialRing(QQ) - sage: pol15 = chebyshev_T(31, x) - 1 # 2^30*(x-1)*minpoly(cos(2*pi/31))^2 # needs sage.symbolic - sage: pol15.splitting_field('a') # needs sage.symbolic + sage: pol15 = chebyshev_T(31, x) - 1 # 2^30*(x-1)*minpoly(cos(2*pi/31))^2 + sage: pol15.splitting_field('a') Number Field in a with defining polynomial x^15 - x^14 - 14*x^13 + 13*x^12 + 78*x^11 - 66*x^10 - 220*x^9 + 165*x^8 + 330*x^7 - 210*x^6 - 252*x^5 + 126*x^4 + 84*x^3 - 28*x^2 - 8*x + 1 @@ -297,7 +297,7 @@ def splitting_field(poly, name, map=False, degree_multiple=None, abort_degree=No computation, in particular for polynomials of degree >= 12 or for relative extensions:: - sage: pol15.splitting_field('a', degree_multiple=15) # needs sage.symbolic + sage: pol15.splitting_field('a', degree_multiple=15) Number Field in a with defining polynomial x^15 + x^14 - 14*x^13 - 13*x^12 + 78*x^11 + 66*x^10 - 220*x^9 - 165*x^8 + 330*x^7 + 210*x^6 - 252*x^5 - 126*x^4 + 84*x^3 + 28*x^2 - 8*x - 1 diff --git a/src/sage/rings/number_field/structure.py b/src/sage/rings/number_field/structure.py index ee699716638..64d7d688e35 100644 --- a/src/sage/rings/number_field/structure.py +++ b/src/sage/rings/number_field/structure.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.rings.number_field r""" Helper classes for structural embeddings and isomorphisms of number fields diff --git a/src/sage/rings/number_field/unit_group.py b/src/sage/rings/number_field/unit_group.py index 5f9d5c0654c..63bd1f7cbfc 100644 --- a/src/sage/rings/number_field/unit_group.py +++ b/src/sage/rings/number_field/unit_group.py @@ -296,6 +296,7 @@ def __init__(self, number_field, proof=True, S=None): Conversion from unit group to a number field and back gives the right results (:trac:`25874`):: + sage: # needs sage.libs.linbox sage: K = QuadraticField(-3).composite_fields(QuadraticField(2))[0] sage: U = K.unit_group() sage: tuple(U(K(u)) for u in U.gens()) == U.gens() diff --git a/src/sage/rings/padics/CA_template.pxi b/src/sage/rings/padics/CA_template.pxi index cf4eb55a327..f8493fabd44 100644 --- a/src/sage/rings/padics/CA_template.pxi +++ b/src/sage/rings/padics/CA_template.pxi @@ -69,13 +69,13 @@ cdef class CAElement(pAdicTemplateElement): TESTS:: sage: R = ZpCA(5) - sage: a = R(17,5); a #indirect doctest + sage: a = R(17,5); a # indirect doctest 2 + 3*5 + O(5^5) - sage: a = R(75, absprec = 5, relprec = 4); a #indirect doctest + sage: a = R(75, absprec = 5, relprec = 4); a # indirect doctest 3*5^2 + O(5^5) - sage: a = R(25/9, absprec = 5); a #indirect doctest + sage: a = R(25/9, absprec = 5); a # indirect doctest 4*5^2 + 2*5^3 + O(5^5) - sage: a = R(25/9, absprec = 5, relprec = 4); a #indirect doctest + sage: a = R(25/9, absprec = 5, relprec = 4); a # indirect doctest 4*5^2 + 2*5^3 + O(5^5) """ IF CELEMENT_IS_PY_OBJECT: @@ -100,13 +100,14 @@ cdef class CAElement(pAdicTemplateElement): TESTS:: - sage: R = ZpCA(5); R(6,5) * R(7,8) #indirect doctest + sage: R = ZpCA(5); R(6,5) * R(7,8) # indirect doctest 2 + 3*5 + 5^2 + O(5^5) + sage: # needs sage.libs.flint sage: R. = ZqCA(25) sage: S. = ZZ[] sage: W. = R.ext(x^2 - 5) - sage: w * (w+1) #indirect doctest + sage: w * (w+1) # indirect doctest w + w^2 + O(w^40) """ cdef type t = type(self) @@ -144,7 +145,7 @@ cdef class CAElement(pAdicTemplateElement): TESTS:: - sage: ZpCA(5)(1).lift_to_precision(30) # indirect doctest + sage: ZpCA(5)(1).lift_to_precision(30) # indirect doctest Traceback (most recent call last): ... PrecisionError: precision higher than allowed by the precision cap @@ -204,7 +205,7 @@ cdef class CAElement(pAdicTemplateElement): sage: R = Zp(5, prec=10, type='capped-abs') sage: a = R(1) - sage: -a #indirect doctest + sage: -a # indirect doctest 4 + 4*5 + 4*5^2 + 4*5^3 + 4*5^4 + 4*5^5 + 4*5^6 + 4*5^7 + 4*5^8 + 4*5^9 + O(5^10) """ cdef CAElement ans = self._new_c() @@ -220,7 +221,7 @@ cdef class CAElement(pAdicTemplateElement): EXAMPLES:: sage: R = ZpCA(13, 4) - sage: R(2) + R(3) #indirect doctest + sage: R(2) + R(3) # indirect doctest 5 + O(13^4) sage: R(12) + R(1) 13 + O(13^4) @@ -244,7 +245,7 @@ cdef class CAElement(pAdicTemplateElement): EXAMPLES:: sage: R = ZpCA(13, 4) - sage: R(10) - R(10) #indirect doctest + sage: R(10) - R(10) # indirect doctest O(13^4) sage: R(10) - R(11) 12 + 12*13 + 12*13^2 + 12*13^3 + O(13^4) @@ -276,7 +277,7 @@ cdef class CAElement(pAdicTemplateElement): 7 + 3*17 + 10*17^2 + 13*17^3 + 6*17^4 + 3*17^5 + 10*17^6 + 13*17^7 + 6*17^8 + 3*17^9 + 10*17^10 + 13*17^11 + 6*17^12 + 3*17^13 + 10*17^14 + 13*17^15 + 6*17^16 + 3*17^17 + 10*17^18 + 13*17^19 + O(17^20) - sage: ~R(-1) == R(-1) #indirect doctest + sage: ~R(-1) == R(-1) # indirect doctest True """ return ~self.parent().fraction_field()(self) @@ -288,7 +289,7 @@ cdef class CAElement(pAdicTemplateElement): EXAMPLES:: sage: R = ZpCA(5) - sage: a = R(20,5); b = R(75, 4); a * b #indirect doctest + sage: a = R(20,5); b = R(75, 4); a * b # indirect doctest 2*5^3 + 2*5^4 + O(5^5) """ cdef CAElement right = _right @@ -316,7 +317,7 @@ cdef class CAElement(pAdicTemplateElement): EXAMPLES:: sage: R = ZpCA(13, 4) - sage: R(2) / R(3) # indirect doctest + sage: R(2) / R(3) # indirect doctest 5 + 4*13 + 4*13^2 + 4*13^3 + O(13^4) sage: a = R(169 * 2) / R(13); a 2*13 + O(13^3) @@ -337,9 +338,9 @@ cdef class CAElement(pAdicTemplateElement): EXAMPLES:: sage: R = ZpCA(3, 5) - sage: R(12).quo_rem(R(2)) # indirect doctest + sage: R(12).quo_rem(R(2)) # indirect doctest (2*3 + O(3^5), O(3^5)) - sage: R(2).quo_rem(R(12)) # indirect doctest + sage: R(2).quo_rem(R(12)) # indirect doctest (O(3^4), 2 + O(3^5)) sage: q, r = R(4).quo_rem(R(12)); q, r (1 + 2*3 + 2*3^3 + O(3^4), 1 + O(3^5)) @@ -458,6 +459,8 @@ cdef class CAElement(pAdicTemplateElement): sage: R(1)^R(0) 1 + O(19^5) + + sage: # needs sage.libs.flint sage: S. = ZqCA(4) sage: S(1)^S(0) 1 + O(2^20) @@ -803,7 +806,7 @@ cdef class CAElement(pAdicTemplateElement): EXAMPLES:: sage: R = ZpCA(37) - sage: R(17) == R(17+37^6) # indirect doctest + sage: R(17) == R(17+37^6) # indirect doctest False """ cdef CAElement right = _right @@ -829,7 +832,7 @@ cdef class CAElement(pAdicTemplateElement): sage: R = ZpCA(19) sage: a = R(19, 7); a 19 + O(19^7) - sage: a.lift_to_precision(12) # indirect doctest + sage: a.lift_to_precision(12) # indirect doctest 19 + O(19^12) sage: a.lift_to_precision(4) is a True @@ -850,6 +853,7 @@ cdef class CAElement(pAdicTemplateElement): TESTS:: + sage: # needs sage.libs.flint sage: R. = ZqCA(9) sage: (9*a)._cache_key() (..., ((), (), (0, 1)), 20) @@ -912,9 +916,10 @@ cdef class CAElement(pAdicTemplateElement): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZZ[] sage: K. = ZqCA(25) - sage: W. = K.extension(x^3-5) + sage: W. = K.extension(x^3 - 5) sage: (1 + w + O(w^11))._polynomial_list() [1 + O(5^4), 1 + O(5^4)] sage: (1 + w + O(w^11))._polynomial_list(pad=True) @@ -951,6 +956,7 @@ cdef class CAElement(pAdicTemplateElement): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCA(5^3) sage: a.polynomial() (1 + O(5^20))*x + O(5^20) @@ -1119,7 +1125,7 @@ cdef class pAdicCoercion_ZZ_CA(RingHomomorphism): EXAMPLES:: sage: f = ZpCA(5).coerce_map_from(ZZ) - sage: g = copy(f) # indirect doctest + sage: g = copy(f) # indirect doctest sage: g == f True sage: g(6) @@ -1139,7 +1145,7 @@ cdef class pAdicCoercion_ZZ_CA(RingHomomorphism): EXAMPLES:: sage: f = ZpCA(5).coerce_map_from(ZZ) - sage: g = copy(f) # indirect doctest + sage: g = copy(f) # indirect doctest sage: g == f True sage: g(6) @@ -1183,7 +1189,7 @@ cdef class pAdicCoercion_ZZ_CA(RingHomomorphism): sage: R = ZpCA(5,4) sage: type(R(10,2)) - sage: R(10,2) # indirect doctest + sage: R(10,2) # indirect doctest 2*5 + O(5^2) sage: R(10,3,1) 2*5 + O(5^2) @@ -1313,7 +1319,7 @@ cdef class pAdicConvert_QQ_CA(Morphism): EXAMPLES:: sage: f = ZpCA(5).convert_map_from(QQ) - sage: g = copy(f) # indirect doctest + sage: g = copy(f) # indirect doctest sage: g == f # todo: comparison not implemented True sage: g(1/6) @@ -1332,7 +1338,7 @@ cdef class pAdicConvert_QQ_CA(Morphism): EXAMPLES:: sage: f = ZpCA(5).convert_map_from(QQ) - sage: g = copy(f) # indirect doctest + sage: g = copy(f) # indirect doctest sage: g == f # todo: comparison not implemented True sage: g(1/6) @@ -1373,7 +1379,7 @@ cdef class pAdicConvert_QQ_CA(Morphism): sage: R = ZpCA(5,4) sage: type(R(10/3,2)) - sage: R(10/3,2) # indirect doctest + sage: R(10/3,2) # indirect doctest 4*5 + O(5^2) sage: R(10/3,3,1) 4*5 + O(5^2) @@ -1416,6 +1422,7 @@ cdef class pAdicCoercion_CA_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCA(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R); f @@ -1425,7 +1432,7 @@ cdef class pAdicCoercion_CA_frac_field(RingHomomorphism): TESTS:: - sage: TestSuite(f).run() + sage: TestSuite(f).run() # needs sage.libs.flint """ def __init__(self, R, K): @@ -1434,6 +1441,7 @@ cdef class pAdicCoercion_CA_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCA(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R); type(f) @@ -1449,6 +1457,7 @@ cdef class pAdicCoercion_CA_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCA(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -1477,10 +1486,11 @@ cdef class pAdicCoercion_CA_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCA(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) - sage: f(a, 3) # indirect doctest + sage: f(a, 3) # indirect doctest a + O(3^3) sage: b = 9*a sage: f(b, 3) @@ -1527,6 +1537,7 @@ cdef class pAdicCoercion_CA_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCA(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -1549,6 +1560,7 @@ cdef class pAdicCoercion_CA_frac_field(RingHomomorphism): TESTS:: + sage: # needs sage.libs.flint sage: R. = ZqCA(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -1578,6 +1590,7 @@ cdef class pAdicCoercion_CA_frac_field(RingHomomorphism): TESTS:: + sage: # needs sage.libs.flint sage: R. = ZqCA(9, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -1606,6 +1619,7 @@ cdef class pAdicCoercion_CA_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCA(9, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -1621,6 +1635,7 @@ cdef class pAdicCoercion_CA_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCA(9, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -1637,6 +1652,7 @@ cdef class pAdicConvert_CA_frac_field(Morphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCA(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = R.convert_map_from(K); f @@ -1650,6 +1666,7 @@ cdef class pAdicConvert_CA_frac_field(Morphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCA(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = R.convert_map_from(K); type(f) @@ -1664,10 +1681,11 @@ cdef class pAdicConvert_CA_frac_field(Morphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCA(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = R.convert_map_from(K) - sage: f(K.gen()) # indirect doctest + sage: f(K.gen()) # indirect doctest a + O(3^20) """ cdef CRElement x = _x @@ -1699,10 +1717,11 @@ cdef class pAdicConvert_CA_frac_field(Morphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCA(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = R.convert_map_from(K); a = K(a) - sage: f(a, 3) # indirect doctest + sage: f(a, 3) # indirect doctest a + O(3^3) sage: b = 9*a sage: f(b, 3) @@ -1750,6 +1769,7 @@ cdef class pAdicConvert_CA_frac_field(Morphism): TESTS:: + sage: # needs sage.libs.flint sage: R. = ZqCA(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = R.convert_map_from(K) @@ -1778,6 +1798,7 @@ cdef class pAdicConvert_CA_frac_field(Morphism): TESTS:: + sage: # needs sage.libs.flint sage: R. = ZqCA(9, implementation='FLINT') sage: K = R.fraction_field() sage: f = R.convert_map_from(K) diff --git a/src/sage/rings/padics/CR_template.pxi b/src/sage/rings/padics/CR_template.pxi index 7c74f5ecc61..14a2f1686c0 100644 --- a/src/sage/rings/padics/CR_template.pxi +++ b/src/sage/rings/padics/CR_template.pxi @@ -94,21 +94,21 @@ cdef class CRElement(pAdicTemplateElement): TESTS:: sage: R = Zp(5) - sage: R(15) #indirect doctest + sage: R(15) # indirect doctest 3*5 + O(5^21) sage: R(15, absprec=5) 3*5 + O(5^5) sage: R(15, relprec=5) 3*5 + O(5^6) - sage: R(75, absprec = 10, relprec = 9) #indirect doctest + sage: R(75, absprec = 10, relprec = 9) # indirect doctest 3*5^2 + O(5^10) - sage: R(25/9, relprec = 5) #indirect doctest + sage: R(25/9, relprec = 5) # indirect doctest 4*5^2 + 2*5^3 + 5^5 + 2*5^6 + O(5^7) - sage: R(25/9, relprec = 4, absprec = 5) #indirect doctest + sage: R(25/9, relprec = 4, absprec = 5) # indirect doctest 4*5^2 + 2*5^3 + O(5^5) sage: R = Zp(5,5) - sage: R(25/9) #indirect doctest + sage: R(25/9) # indirect doctest 4*5^2 + 2*5^3 + 5^5 + 2*5^6 + O(5^7) sage: R(25/9, absprec = 5) 4*5^2 + 2*5^3 + O(5^5) @@ -116,9 +116,9 @@ cdef class CRElement(pAdicTemplateElement): 4*5^2 + 2*5^3 + 5^5 + O(5^6) sage: R = Zp(5); S = Zp(5, 6) - sage: S(R(17)) # indirect doctest + sage: S(R(17)) # indirect doctest 2 + 3*5 + O(5^6) - sage: S(R(17),4) # indirect doctest + sage: S(R(17),4) # indirect doctest 2 + 3*5 + O(5^4) sage: T = Qp(5); a = T(1/5) - T(1/5) sage: R(a) @@ -129,7 +129,7 @@ cdef class CRElement(pAdicTemplateElement): O(5^17) sage: R = Zp(5); S = ZpCA(5) - sage: R(S(17, 5)) #indirect doctest + sage: R(S(17, 5)) # indirect doctest 2 + 3*5 + O(5^5) """ IF CELEMENT_IS_PY_OBJECT: @@ -156,7 +156,7 @@ cdef class CRElement(pAdicTemplateElement): TESTS:: - sage: R = Zp(5); R(0) #indirect doctest + sage: R = Zp(5); R(0) # indirect doctest 0 """ csetzero(self.unit, self.prime_pow) @@ -169,7 +169,7 @@ cdef class CRElement(pAdicTemplateElement): TESTS:: - sage: R = Zp(5); R(0, 5) #indirect doctest + sage: R = Zp(5); R(0, 5) # indirect doctest O(5^5) """ csetzero(self.unit, self.prime_pow) @@ -183,13 +183,14 @@ cdef class CRElement(pAdicTemplateElement): TESTS:: sage: R = Zp(5) - sage: R(6,5) * R(7,8) #indirect doctest + sage: R(6,5) * R(7,8) # indirect doctest 2 + 3*5 + 5^2 + O(5^5) + sage: # needs sage.libs.ntl sage: R. = ZqCR(25) sage: S. = ZZ[] sage: W. = R.ext(x^2 - 5) - sage: w * (w+1) #indirect doctest + sage: w * (w+1) # indirect doctest w + w^2 + O(w^41) """ cdef type t = type(self) @@ -262,7 +263,7 @@ cdef class CRElement(pAdicTemplateElement): TESTS:: sage: R = Zp(5) - sage: R(6) + R(4) #indirect doctest + sage: R(6) + R(4) # indirect doctest 2*5 + O(5^20) """ cdef long diff @@ -312,7 +313,7 @@ cdef class CRElement(pAdicTemplateElement): EXAMPLES:: sage: R = Zp(5, 20, 'capped-rel', 'val-unit') - sage: R(5) + (-R(5)) # indirect doctest + sage: R(5) + (-R(5)) # indirect doctest O(5^21) sage: -R(1) 95367431640624 + O(5^20) @@ -340,7 +341,7 @@ cdef class CRElement(pAdicTemplateElement): 18 + 18*19 + 18*19^2 + 18*19^3 + 18*19^4 + O(19^5) sage: b=R(-5/2); b 7 + 9*19 + 9*19^2 + 9*19^3 + 9*19^4 + O(19^5) - sage: a+b #indirect doctest + sage: a+b # indirect doctest 6 + 9*19 + 9*19^2 + 9*19^3 + 9*19^4 + O(19^5) """ cdef CRElement ans @@ -380,7 +381,7 @@ cdef class CRElement(pAdicTemplateElement): EXAMPLES:: sage: R = Zp(13, 4) - sage: R(10) - R(10) #indirect doctest + sage: R(10) - R(10) # indirect doctest O(13^4) sage: R(10) - R(11) 12 + 12*13 + 12*13^2 + 12*13^3 + O(13^4) @@ -458,7 +459,7 @@ cdef class CRElement(pAdicTemplateElement): 2*5 + 4*5^3 + 3*5^4 + O(5^11) sage: b = R(2387625, 16); b 5^3 + 4*5^5 + 2*5^6 + 5^8 + 5^9 + O(5^16) - sage: a * b # indirect doctest + sage: a * b # indirect doctest 2*5^4 + 2*5^6 + 4*5^7 + 2*5^8 + 3*5^10 + 5^11 + 3*5^12 + 4*5^13 + O(5^14) """ cdef CRElement ans @@ -490,7 +491,7 @@ cdef class CRElement(pAdicTemplateElement): EXAMPLES:: sage: R = Zp(5,6) - sage: R(17) / R(21) #indirect doctest + sage: R(17) / R(21) # indirect doctest 2 + 4*5^2 + 3*5^3 + 4*5^4 + O(5^6) sage: a = R(50) / R(5); a 2*5 + O(5^7) @@ -643,7 +644,7 @@ cdef class CRElement(pAdicTemplateElement): 18 + 18*19 + 18*19^2 + 18*19^3 + 18*19^4 + O(19^5) sage: K(5)^30 11 + 14*19 + 19^2 + 7*19^3 + O(19^5) - sage: K(5, 3)^19 #indirect doctest + sage: K(5, 3)^19 # indirect doctest 5 + 3*19 + 11*19^3 + O(19^4) `p`-adic exponents are also supported:: @@ -663,6 +664,8 @@ cdef class CRElement(pAdicTemplateElement): sage: R(1)^R(0) 1 + O(19^5) + + sage: # needs sage.libs.ntl sage: S. = ZqCR(4) sage: S(1)^S(0) 1 + O(2^20) @@ -742,7 +745,7 @@ cdef class CRElement(pAdicTemplateElement): sage: a = Zp(5)(17); a 2 + 3*5 + O(5^20) - sage: a << 2 #indirect doctest + sage: a << 2 # indirect doctest 2*5^2 + 3*5^3 + O(5^22) sage: a << -2 O(5^18) @@ -811,7 +814,7 @@ cdef class CRElement(pAdicTemplateElement): EXAMPLES:: sage: R = Zp(3, 5) - sage: R(12).quo_rem(R(2)) # indirect doctest + sage: R(12).quo_rem(R(2)) # indirect doctest (2*3 + O(3^6), 0) sage: R(2).quo_rem(R(12)) (O(3^4), 2 + O(3^5)) @@ -1242,6 +1245,7 @@ cdef class CRElement(pAdicTemplateElement): TESTS:: + sage: # needs sage.libs.ntl sage: K. = Qq(9) sage: (9*a)._cache_key() (..., ((0, 1),), 2, 20) @@ -1305,9 +1309,10 @@ cdef class CRElement(pAdicTemplateElement): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = ZZ[] sage: K. = Qq(25) - sage: W. = K.extension(x^3-5) + sage: W. = K.extension(x^3 - 5) sage: (1 + w + O(w^11))._polynomial_list() [1 + O(5^4), 1 + O(5^4)] sage: (1 + w + O(w^11))._polynomial_list(pad=True) @@ -1349,6 +1354,7 @@ cdef class CRElement(pAdicTemplateElement): EXAMPLES:: + sage: # needs sage.libs.ntl sage: K. = Qq(5^3) sage: a.polynomial() (1 + O(5^20))*x + O(5^20) @@ -1469,7 +1475,7 @@ cdef class CRElement(pAdicTemplateElement): EXAMPLES:: sage: R = Qp(5); a = R(1) - sage: a.valuation() #indirect doctest + sage: a.valuation() # indirect doctest 0 sage: b = (a << 4); b.valuation() 4 @@ -1528,7 +1534,7 @@ cdef class CRElement(pAdicTemplateElement): EXAMPLES:: sage: R = Zp(5) - sage: hash(R(17)) #indirect doctest + sage: hash(R(17)) # indirect doctest 17 sage: hash(R(-1)) @@ -1653,7 +1659,7 @@ cdef class pAdicCoercion_ZZ_CR(RingHomomorphism): sage: R = Zp(5,4) sage: type(R(10,2)) - sage: R(10,2) # indirect doctest + sage: R(10,2) # indirect doctest 2*5 + O(5^2) sage: R(10,3,1) 2*5 + O(5^2) @@ -1873,7 +1879,7 @@ cdef class pAdicCoercion_QQ_CR(RingHomomorphism): sage: R = Qp(5,4) sage: type(R(10/3,2)) - sage: R(10/3,2) # indirect doctest + sage: R(10/3,2) # indirect doctest 4*5 + O(5^2) sage: R(10/3,3,1) 4*5 + O(5^2) @@ -2074,7 +2080,7 @@ cdef class pAdicConvert_QQ_CR(Morphism): sage: R = Zp(5,4) sage: type(R(10/3,2)) - sage: R(10/3,2) # indirect doctest + sage: R(10/3,2) # indirect doctest 4*5 + O(5^2) sage: R(10/3,3,1) 4*5 + O(5^2) @@ -2135,6 +2141,7 @@ cdef class pAdicCoercion_CR_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCR(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R); f @@ -2144,7 +2151,7 @@ cdef class pAdicCoercion_CR_frac_field(RingHomomorphism): TESTS:: - sage: TestSuite(f).run() + sage: TestSuite(f).run() # needs sage.libs.flint """ def __init__(self, R, K): @@ -2153,6 +2160,7 @@ cdef class pAdicCoercion_CR_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCR(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R); type(f) @@ -2168,6 +2176,7 @@ cdef class pAdicCoercion_CR_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCR(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -2197,13 +2206,14 @@ cdef class pAdicCoercion_CR_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCR(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) sage: f(a, 3) a + O(3^3) sage: b = 9*a - sage: f(b, 3) # indirect doctest + sage: f(b, 3) # indirect doctest a*3^2 + O(3^3) sage: f(b, 4, 1) a*3^2 + O(3^3) @@ -2251,6 +2261,7 @@ cdef class pAdicCoercion_CR_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCR(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -2273,6 +2284,7 @@ cdef class pAdicCoercion_CR_frac_field(RingHomomorphism): TESTS:: + sage: # needs sage.libs.flint sage: R. = ZqCR(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -2302,6 +2314,7 @@ cdef class pAdicCoercion_CR_frac_field(RingHomomorphism): TESTS:: + sage: # needs sage.libs.flint sage: R. = ZqCR(9, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -2330,6 +2343,7 @@ cdef class pAdicCoercion_CR_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCR(9, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -2345,6 +2359,7 @@ cdef class pAdicCoercion_CR_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCR(9, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -2361,6 +2376,7 @@ cdef class pAdicConvert_CR_frac_field(Morphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCR(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = R.convert_map_from(K); f @@ -2374,6 +2390,7 @@ cdef class pAdicConvert_CR_frac_field(Morphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCR(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = R.convert_map_from(K); type(f) @@ -2388,6 +2405,7 @@ cdef class pAdicConvert_CR_frac_field(Morphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCR(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = R.convert_map_from(K) @@ -2417,13 +2435,14 @@ cdef class pAdicConvert_CR_frac_field(Morphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqCR(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = R.convert_map_from(K); a = K(a) sage: f(a, 3) a + O(3^3) sage: b = 9*a - sage: f(b, 3) # indirect doctest + sage: f(b, 3) # indirect doctest a*3^2 + O(3^3) sage: f(b, 4, 1) a*3^2 + O(3^3) @@ -2472,6 +2491,7 @@ cdef class pAdicConvert_CR_frac_field(Morphism): TESTS:: + sage: # needs sage.libs.flint sage: R. = ZqCR(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = R.convert_map_from(K) @@ -2500,6 +2520,7 @@ cdef class pAdicConvert_CR_frac_field(Morphism): TESTS:: + sage: # needs sage.libs.flint sage: R. = ZqCR(9, implementation='FLINT') sage: K = R.fraction_field() sage: f = R.convert_map_from(K) diff --git a/src/sage/rings/padics/FM_template.pxi b/src/sage/rings/padics/FM_template.pxi index 3e4a9fdc4cb..3e6abe53a7f 100644 --- a/src/sage/rings/padics/FM_template.pxi +++ b/src/sage/rings/padics/FM_template.pxi @@ -74,10 +74,10 @@ cdef class FMElement(pAdicTemplateElement): TESTS:: sage: R = ZpFM(5) - sage: a = R(17,5); a #indirect doctest + sage: a = R(17,5); a # indirect doctest 2 + 3*5 sage: R = ZpFM(5,5) - sage: a = R(25/9); a #indirect doctest + sage: a = R(25/9); a # indirect doctest 4*5^2 + 2*5^3 """ IF CELEMENT_IS_PY_OBJECT: @@ -95,7 +95,7 @@ cdef class FMElement(pAdicTemplateElement): TESTS:: - sage: R = ZpFM(5); R(6) * R(7) #indirect doctest + sage: R = ZpFM(5); R(6) * R(7) # indirect doctest 2 + 3*5 + 5^2 """ cdef type t = type(self) @@ -131,7 +131,7 @@ cdef class FMElement(pAdicTemplateElement): TESTS:: - sage: ZpFM(5)(1).lift_to_precision(30) # indirect doctest + sage: ZpFM(5)(1).lift_to_precision(30) # indirect doctest 1 """ pass @@ -186,7 +186,7 @@ cdef class FMElement(pAdicTemplateElement): EXAMPLES:: sage: R = Zp(7, 4, 'fixed-mod', 'series') - sage: -R(7) #indirect doctest + sage: -R(7) # indirect doctest 6*7 + 6*7^2 + 6*7^3 """ cdef FMElement ans = self._new_c() @@ -205,7 +205,7 @@ cdef class FMElement(pAdicTemplateElement): 6 + 5*7^3 sage: y = R(1373); y 1 + 4*7^3 - sage: x + y #indirect doctest + sage: x + y # indirect doctest 7 + 2*7^3 """ cdef FMElement right = _right @@ -225,7 +225,7 @@ cdef class FMElement(pAdicTemplateElement): 6 + 5*7^3 sage: y = R(1373); y 1 + 4*7^3 - sage: x - y #indirect doctest + sage: x - y # indirect doctest 5 + 7^3 """ cdef FMElement right = _right @@ -266,7 +266,7 @@ cdef class FMElement(pAdicTemplateElement): EXAMPLES:: sage: R = Zp(7, 4, 'fixed-mod', 'series') - sage: R(3) * R(2) #indirect doctest + sage: R(3) * R(2) # indirect doctest 6 sage: R(1/2) * R(2) 1 @@ -285,7 +285,7 @@ cdef class FMElement(pAdicTemplateElement): EXAMPLES:: sage: R = Zp(7, 4, 'fixed-mod', 'series') - sage: R(3) / R(2) #indirect doctest + sage: R(3) / R(2) # indirect doctest 5 + 3*7 + 3*7^2 + 3*7^3 sage: R(5) / R(0) Traceback (most recent call last): @@ -311,7 +311,7 @@ cdef class FMElement(pAdicTemplateElement): EXAMPLES:: sage: R = ZpFM(3, 5) - sage: R(12).quo_rem(R(2)) # indirect doctest + sage: R(12).quo_rem(R(2)) # indirect doctest (2*3, 0) sage: R(2).quo_rem(R(12)) (0, 2) @@ -359,7 +359,7 @@ cdef class FMElement(pAdicTemplateElement): 10 + 7*11 + 11^2 + 5*11^3 + 4*11^4 sage: R(1/2)^5 == R(1/32) True - sage: R(3)^1000 #indirect doctest + sage: R(3)^1000 # indirect doctest 1 + 4*11^2 + 3*11^3 + 7*11^4 TESTS: @@ -574,7 +574,7 @@ cdef class FMElement(pAdicTemplateElement): EXAMPLES:: sage: R = ZpFM(5); a = R(0); b = R(75) - sage: bool(a), bool(b) # indirect doctest + sage: bool(a), bool(b) # indirect doctest (False, True) """ return not ciszero(self.value, self.prime_pow) @@ -639,7 +639,7 @@ cdef class FMElement(pAdicTemplateElement): sage: R = ZpFM(5) sage: a = R(17); b = R(0,3); c = R(85,7); d = R(2, 1) - sage: any([a == b, a == c, b == c, b == d, c == d, a == d]) # indirect doctest + sage: any([a == b, a == c, b == c, b == d, c == d, a == d]) # indirect doctest False sage: all([a == a, b == b, c == c, d == d]) True @@ -659,7 +659,7 @@ cdef class FMElement(pAdicTemplateElement): sage: R = ZpFM(5) sage: a = R(77, 2); a 2 + 3*5^2 - sage: a.lift_to_precision(17) # indirect doctest + sage: a.lift_to_precision(17) # indirect doctest 2 + 3*5^2 """ return self @@ -710,9 +710,10 @@ cdef class FMElement(pAdicTemplateElement): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZZ[] sage: K. = ZqFM(25) - sage: W. = K.extension(x^3-5) + sage: W. = K.extension(x^3 - 5) sage: (1 + w)._polynomial_list() [1, 1] sage: (1 + w)._polynomial_list(pad=True) @@ -737,6 +738,7 @@ cdef class FMElement(pAdicTemplateElement): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqFM(5^3) sage: a.polynomial() x @@ -808,7 +810,7 @@ cdef class FMElement(pAdicTemplateElement): TESTS:: - sage: R = ZpFM(5, 5); R(0).valuation() #indirect doctest + sage: R = ZpFM(5, 5); R(0).valuation() # indirect doctest 5 sage: R = Zp(17, 4,'fixed-mod') sage: a = R(2*17^2) @@ -902,7 +904,7 @@ cdef class pAdicCoercion_ZZ_FM(RingHomomorphism): EXAMPLES:: sage: f = ZpFM(5).coerce_map_from(ZZ) - sage: g = copy(f) # indirect doctest + sage: g = copy(f) # indirect doctest sage: g == f True sage: g(6) @@ -922,7 +924,7 @@ cdef class pAdicCoercion_ZZ_FM(RingHomomorphism): EXAMPLES:: sage: f = ZpFM(5).coerce_map_from(ZZ) - sage: g = copy(f) # indirect doctest + sage: g = copy(f) # indirect doctest sage: g == f True sage: g(6) @@ -1086,7 +1088,7 @@ cdef class pAdicConvert_QQ_FM(Morphism): EXAMPLES:: sage: f = ZpFM(5).convert_map_from(QQ) - sage: g = copy(f) # indirect doctest + sage: g = copy(f) # indirect doctest sage: g == f # todo: comparison not implemented True sage: g(1/6) @@ -1105,7 +1107,7 @@ cdef class pAdicConvert_QQ_FM(Morphism): EXAMPLES:: sage: f = ZpFM(5).convert_map_from(QQ) - sage: g = copy(f) # indirect doctest + sage: g = copy(f) # indirect doctest sage: g == f # todo: comparison not implemented True sage: g(1/6) @@ -1179,6 +1181,7 @@ cdef class pAdicCoercion_FM_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqFM(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R); f @@ -1188,7 +1191,7 @@ cdef class pAdicCoercion_FM_frac_field(RingHomomorphism): TESTS:: - sage: TestSuite(f).run() + sage: TestSuite(f).run() # needs sage.libs.flint """ def __init__(self, R, K): @@ -1197,6 +1200,7 @@ cdef class pAdicCoercion_FM_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqFM(27) sage: K = R.fraction_field() sage: f = K.coerce_map_from(R); type(f) @@ -1212,6 +1216,7 @@ cdef class pAdicCoercion_FM_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqFM(27) sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -1239,6 +1244,7 @@ cdef class pAdicCoercion_FM_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqFM(27) sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -1286,6 +1292,7 @@ cdef class pAdicCoercion_FM_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqFM(27) sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -1304,6 +1311,7 @@ cdef class pAdicCoercion_FM_frac_field(RingHomomorphism): TESTS:: + sage: # needs sage.libs.flint sage: R. = ZqFM(27) sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -1332,6 +1340,7 @@ cdef class pAdicCoercion_FM_frac_field(RingHomomorphism): TESTS:: + sage: # needs sage.libs.flint sage: R. = ZqFM(9) sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -1360,6 +1369,7 @@ cdef class pAdicCoercion_FM_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqFM(9) sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -1375,6 +1385,7 @@ cdef class pAdicCoercion_FM_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqFM(9) sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -1391,6 +1402,7 @@ cdef class pAdicConvert_FM_frac_field(Morphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqFM(27) sage: K = R.fraction_field() sage: f = R.convert_map_from(K); f @@ -1404,6 +1416,7 @@ cdef class pAdicConvert_FM_frac_field(Morphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqFM(27) sage: K = R.fraction_field() sage: f = R.convert_map_from(K); type(f) @@ -1418,6 +1431,7 @@ cdef class pAdicConvert_FM_frac_field(Morphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqFM(27) sage: K = R.fraction_field() sage: f = R.convert_map_from(K) @@ -1447,6 +1461,7 @@ cdef class pAdicConvert_FM_frac_field(Morphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqFM(27) sage: K = R.fraction_field() sage: f = R.convert_map_from(K); a = K(a) @@ -1491,6 +1506,7 @@ cdef class pAdicConvert_FM_frac_field(Morphism): TESTS:: + sage: # needs sage.libs.flint sage: R. = ZqFM(27) sage: K = R.fraction_field() sage: f = R.convert_map_from(K) @@ -1519,6 +1535,7 @@ cdef class pAdicConvert_FM_frac_field(Morphism): TESTS:: + sage: # needs sage.libs.flint sage: R. = ZqFM(9) sage: K = R.fraction_field() sage: f = R.convert_map_from(K) diff --git a/src/sage/rings/padics/FP_template.pxi b/src/sage/rings/padics/FP_template.pxi index e4950778756..254d627630b 100644 --- a/src/sage/rings/padics/FP_template.pxi +++ b/src/sage/rings/padics/FP_template.pxi @@ -112,13 +112,13 @@ cdef class FPElement(pAdicTemplateElement): TESTS:: sage: R = ZpFP(5) - sage: a = R(17,5); a #indirect doctest + sage: a = R(17,5); a # indirect doctest 2 + 3*5 - sage: R(15) #indirect doctest + sage: R(15) # indirect doctest 3*5 sage: R = ZpFP(5,5) - sage: a = R(25/9); a #indirect doctest + sage: a = R(25/9); a # indirect doctest 4*5^2 + 2*5^3 + 5^5 + 2*5^6 sage: R(ZpCR(5)(25/9)) == a True @@ -153,7 +153,7 @@ cdef class FPElement(pAdicTemplateElement): TESTS:: - sage: R = Zp(5); R(0) #indirect doctest + sage: R = Zp(5); R(0) # indirect doctest 0 """ csetzero(self.unit, self.prime_pow) @@ -165,7 +165,7 @@ cdef class FPElement(pAdicTemplateElement): TESTS:: - sage: R = Zp(5); R(0) #indirect doctest + sage: R = Zp(5); R(0) # indirect doctest 0 """ csetone(self.unit, self.prime_pow) @@ -177,13 +177,14 @@ cdef class FPElement(pAdicTemplateElement): TESTS:: - sage: R = ZpFP(5); R(6) * R(7) #indirect doctest + sage: R = ZpFP(5); R(6) * R(7) # indirect doctest 2 + 3*5 + 5^2 + sage: # needs sage.libs.flint sage: R. = ZqFP(25) sage: S. = ZZ[] sage: W. = R.ext(x^2 - 5) - sage: w * (w+1) #indirect doctest + sage: w * (w+1) # indirect doctest w + w^2 """ cdef type t = type(self) @@ -221,7 +222,7 @@ cdef class FPElement(pAdicTemplateElement): TESTS:: - sage: ZpFP(5)(1).lift_to_precision(30) # indirect doctest + sage: ZpFP(5)(1).lift_to_precision(30) # indirect doctest 1 """ pass @@ -250,7 +251,7 @@ cdef class FPElement(pAdicTemplateElement): TESTS:: sage: R = ZpFP(5) - sage: R(6) + R(4) #indirect doctest + sage: R(6) + R(4) # indirect doctest 2*5 """ cdef long diff @@ -319,7 +320,7 @@ cdef class FPElement(pAdicTemplateElement): EXAMPLES:: sage: R = Zp(7, 4, 'floating-point', 'series') - sage: -R(7) #indirect doctest + sage: -R(7) # indirect doctest 6*7 + 6*7^2 + 6*7^3 + 6*7^4 """ cdef FPElement ans = self._new_c() @@ -342,7 +343,7 @@ cdef class FPElement(pAdicTemplateElement): 6 + 5*7^3 sage: y = R(1373); y 1 + 4*7^3 - sage: x + y #indirect doctest + sage: x + y # indirect doctest 7 + 2*7^3 """ cdef FPElement ans @@ -386,7 +387,7 @@ cdef class FPElement(pAdicTemplateElement): 6 + 5*7^3 sage: y = R(1373); y 1 + 4*7^3 - sage: x - y #indirect doctest + sage: x - y # indirect doctest 5 + 7^3 """ cdef FPElement ans @@ -461,7 +462,7 @@ cdef class FPElement(pAdicTemplateElement): EXAMPLES:: sage: R = Zp(7, 4, 'floating-point', 'series') - sage: R(3) * R(2) #indirect doctest + sage: R(3) * R(2) # indirect doctest 6 sage: R(1/2) * R(2) 1 @@ -494,7 +495,7 @@ cdef class FPElement(pAdicTemplateElement): EXAMPLES:: sage: R = Zp(7, 4, 'floating-point', 'series') - sage: R(3) / R(2) #indirect doctest + sage: R(3) / R(2) # indirect doctest 5 + 3*7 + 3*7^2 + 3*7^3 sage: R(5) / R(0) infinity @@ -535,7 +536,7 @@ cdef class FPElement(pAdicTemplateElement): EXAMPLES:: sage: R = ZpFP(3, 5) - sage: R(12).quo_rem(R(2)) # indirect doctest + sage: R(12).quo_rem(R(2)) # indirect doctest (2*3, 0) sage: R(2).quo_rem(R(12)) (0, 2) @@ -597,7 +598,7 @@ cdef class FPElement(pAdicTemplateElement): 10 + 7*11 + 11^2 + 5*11^3 + 4*11^4 sage: R(1/2)^5 == R(1/32) True - sage: R(3)^1000 #indirect doctest + sage: R(3)^1000 # indirect doctest 1 + 4*11^2 + 3*11^3 + 7*11^4 sage: R(11)^-1 11^-1 @@ -608,8 +609,9 @@ cdef class FPElement(pAdicTemplateElement): sage: R(1)^R(0) 1 - sage: S. = ZqFP(4) - sage: S(1)^S(0) + + sage: S. = ZqFP(4) # needs sage.libs.flint + sage: S(1)^S(0) # needs sage.libs.flint 1 """ cdef long dummyL @@ -783,7 +785,7 @@ cdef class FPElement(pAdicTemplateElement): EXAMPLES:: - sage: ZpFP(5,5)(1/3) # indirect doctest + sage: ZpFP(5,5)(1/3) # indirect doctest 2 + 3*5 + 5^2 + 3*5^3 + 5^4 sage: ~QpFP(5,5)(0) infinity @@ -902,7 +904,7 @@ cdef class FPElement(pAdicTemplateElement): EXAMPLES:: sage: R = ZpFP(5); a = R(0); b = R(75) - sage: bool(a), bool(b) # indirect doctest + sage: bool(a), bool(b) # indirect doctest (False, True) """ return not very_pos_val(self.ordp) @@ -977,7 +979,7 @@ cdef class FPElement(pAdicTemplateElement): sage: R = ZpFP(5) sage: a = R(17); b = R(0,3); c = R(85,7); d = R(2, 1) - sage: any([a == b, a == c, b == c, b == d, c == d, a == d]) # indirect doctest + sage: any([a == b, a == c, b == c, b == d, c == d, a == d]) # indirect doctest False sage: all([a == a, b == b, c == c, d == d]) True @@ -997,7 +999,7 @@ cdef class FPElement(pAdicTemplateElement): sage: R = ZpFP(5) sage: a = R(77, 2); a 2 - sage: a.lift_to_precision(17) # indirect doctest + sage: a.lift_to_precision(17) # indirect doctest 2 """ return self @@ -1050,9 +1052,10 @@ cdef class FPElement(pAdicTemplateElement): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZZ[] sage: K. = QqFP(5^3) - sage: W. = K.extension(x^3-5) + sage: W. = K.extension(x^3 - 5) sage: (1 + w)._polynomial_list() [1, 1] sage: (1 + w)._polynomial_list(pad=True) @@ -1081,6 +1084,7 @@ cdef class FPElement(pAdicTemplateElement): EXAMPLES:: + sage: # needs sage.libs.flint sage: K. = QqFP(5^3) sage: a.polynomial() x @@ -1175,7 +1179,7 @@ cdef class FPElement(pAdicTemplateElement): TESTS:: - sage: R = ZpFP(5, 5); R(1).valuation() #indirect doctest + sage: R = ZpFP(5, 5); R(1).valuation() # indirect doctest 0 sage: R = Zp(17, 4,'floating-point') sage: a = R(2*17^2) @@ -1282,7 +1286,7 @@ cdef class pAdicCoercion_ZZ_FP(RingHomomorphism): EXAMPLES:: sage: f = ZpFP(5).coerce_map_from(ZZ) - sage: g = copy(f) # indirect doctest + sage: g = copy(f) # indirect doctest sage: g == f True sage: g(6) @@ -1302,7 +1306,7 @@ cdef class pAdicCoercion_ZZ_FP(RingHomomorphism): EXAMPLES:: sage: f = ZpFP(5).coerce_map_from(ZZ) - sage: g = copy(f) # indirect doctest + sage: g = copy(f) # indirect doctest sage: g == f True sage: g(6) @@ -1697,7 +1701,7 @@ cdef class pAdicConvert_QQ_FP(Morphism): EXAMPLES:: sage: f = ZpFP(5).convert_map_from(QQ) - sage: g = copy(f) # indirect doctest + sage: g = copy(f) # indirect doctest sage: g == f # todo: comparison not implemented True sage: g(1/6) @@ -1716,7 +1720,7 @@ cdef class pAdicConvert_QQ_FP(Morphism): EXAMPLES:: sage: f = ZpFP(5).convert_map_from(QQ) - sage: g = copy(f) # indirect doctest + sage: g = copy(f) # indirect doctest sage: g == f # todo: comparison not implemented True sage: g(1/6) @@ -1800,6 +1804,7 @@ cdef class pAdicCoercion_FP_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqFP(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R); f @@ -1809,7 +1814,7 @@ cdef class pAdicCoercion_FP_frac_field(RingHomomorphism): TESTS:: - sage: TestSuite(f).run() + sage: TestSuite(f).run() # needs sage.libs.flint """ def __init__(self, R, K): @@ -1818,6 +1823,7 @@ cdef class pAdicCoercion_FP_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqFP(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R); type(f) @@ -1833,6 +1839,7 @@ cdef class pAdicCoercion_FP_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqFP(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -1861,6 +1868,7 @@ cdef class pAdicCoercion_FP_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqFP(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -1912,6 +1920,7 @@ cdef class pAdicCoercion_FP_frac_field(RingHomomorphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqFP(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -1926,6 +1935,7 @@ cdef class pAdicCoercion_FP_frac_field(RingHomomorphism): TESTS:: + sage: # needs sage.libs.flint sage: R. = ZqFP(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -1954,6 +1964,7 @@ cdef class pAdicCoercion_FP_frac_field(RingHomomorphism): TESTS:: + sage: # needs sage.libs.flint sage: R. = ZqFP(9, implementation='FLINT') sage: K = R.fraction_field() sage: f = K.coerce_map_from(R) @@ -1982,6 +1993,7 @@ cdef class pAdicConvert_FP_frac_field(Morphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqFP(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = R.convert_map_from(K); f @@ -1995,6 +2007,7 @@ cdef class pAdicConvert_FP_frac_field(Morphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqFP(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = R.convert_map_from(K); type(f) @@ -2009,6 +2022,7 @@ cdef class pAdicConvert_FP_frac_field(Morphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqFP(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = R.convert_map_from(K) @@ -2037,6 +2051,7 @@ cdef class pAdicConvert_FP_frac_field(Morphism): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqFP(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = R.convert_map_from(K); a = K(a) @@ -2089,6 +2104,7 @@ cdef class pAdicConvert_FP_frac_field(Morphism): TESTS:: + sage: # needs sage.libs.flint sage: R. = ZqFP(27, implementation='FLINT') sage: K = R.fraction_field() sage: f = R.convert_map_from(K) @@ -2117,6 +2133,7 @@ cdef class pAdicConvert_FP_frac_field(Morphism): TESTS:: + sage: # needs sage.libs.flint sage: R. = ZqFP(9, implementation='FLINT') sage: K = R.fraction_field() sage: f = R.convert_map_from(K) diff --git a/src/sage/rings/padics/eisenstein_extension_generic.py b/src/sage/rings/padics/eisenstein_extension_generic.py index bf9a3d96158..10e198abfb9 100644 --- a/src/sage/rings/padics/eisenstein_extension_generic.py +++ b/src/sage/rings/padics/eisenstein_extension_generic.py @@ -31,8 +31,8 @@ def __init__(self, poly, prec, print_mode, names, element_class): EXAMPLES:: sage: A = Zp(7,10) - sage: S. = A[] - sage: B. = A.ext(x^2+7) #indirect doctest + sage: S. = A[] # needs sage.libs.ntl + sage: B. = A.ext(x^2+7) # indirect doctest # needs sage.libs.ntl sage.rings.padics """ pAdicExtensionGeneric.__init__(self, poly, prec, print_mode, names, element_class) #self._precompute() @@ -46,13 +46,13 @@ def _extension_type(self): EXAMPLES:: - sage: K. = Qq(5^3) - sage: K._extension_type() + sage: K. = Qq(5^3) # needs sage.libs.ntl + sage: K._extension_type() # needs sage.libs.ntl 'Unramified' sage: x = polygen(ZZ, 'x') - sage: L. = Qp(5).extension(x^2 - 5) - sage: L._extension_type() + sage: L. = Qp(5).extension(x^2 - 5) # needs sage.libs.ntl + sage: L._extension_type() # needs sage.libs.ntl 'Eisenstein' """ return "Eisenstein" @@ -63,13 +63,13 @@ def absolute_e(self): EXAMPLES:: - sage: K. = Qq(3^5) - sage: K.absolute_e() + sage: K. = Qq(3^5) # needs sage.libs.ntl + sage: K.absolute_e() # needs sage.libs.ntl 1 sage: x = polygen(ZZ, 'x') - sage: L. = Qp(3).extension(x^2 - 3) - sage: L.absolute_e() + sage: L. = Qp(3).extension(x^2 - 3) # needs sage.libs.ntl + sage: L.absolute_e() # needs sage.libs.ntl 2 """ return self.modulus().degree() * self.base_ring().absolute_e() @@ -84,9 +84,9 @@ def inertia_subring(self): EXAMPLES:: sage: A = Zp(7,10) - sage: S. = A[] - sage: B. = A.ext(x^2 + 7) - sage: B.inertia_subring() + sage: S. = A[] # needs sage.libs.ntl + sage: B. = A.ext(x^2 + 7) # needs sage.libs.ntl + sage: B.inertia_subring() # needs sage.libs.ntl 7-adic Ring with capped relative precision 10 """ return self.ground_ring() @@ -106,9 +106,9 @@ def residue_class_field(self): EXAMPLES:: sage: A = Zp(7,10) - sage: S. = A[] - sage: B. = A.ext(x^2 + 7) - sage: B.residue_class_field() + sage: S. = A[] # needs sage.libs.ntl + sage: B. = A.ext(x^2 + 7) # needs sage.libs.ntl + sage: B.residue_class_field() # needs sage.libs.ntl Finite Field of size 7 """ return self.ground_ring().residue_class_field() @@ -120,13 +120,13 @@ def residue_ring(self, n): EXAMPLES:: sage: S. = ZZ[] - sage: W. = Zp(5).extension(x^2 - 5) - sage: W.residue_ring(1) + sage: W. = Zp(5).extension(x^2 - 5) # needs sage.libs.ntl + sage: W.residue_ring(1) # needs sage.libs.ntl Ring of integers modulo 5 The following requires implementing more general Artinian rings:: - sage: W.residue_ring(2) + sage: W.residue_ring(2) # needs sage.libs.ntl Traceback (most recent call last): ... NotImplementedError @@ -169,9 +169,9 @@ def gen(self, n=0): EXAMPLES:: sage: A = Zp(7,10) - sage: S. = A[] - sage: B. = A.ext(x^2 + 7) - sage: B.gen() + sage: S. = A[] # needs sage.libs.ntl + sage: B. = A.ext(x^2 + 7) # needs sage.libs.ntl + sage: B.gen() # needs sage.libs.ntl t + O(t^21) """ if n != 0: @@ -186,9 +186,9 @@ def uniformizer_pow(self, n): EXAMPLES:: sage: A = Zp(7,10) - sage: S. = A[] - sage: B. = A.ext(x^2 + 7) - sage: B.uniformizer_pow(5) + sage: S. = A[] # needs sage.libs.ntl + sage: B. = A.ext(x^2 + 7) # needs sage.libs.ntl + sage: B.uniformizer_pow(5) # needs sage.libs.ntl t^5 + O(t^25) """ if n is infinity: @@ -204,9 +204,9 @@ def uniformizer(self): EXAMPLES:: sage: A = Zp(7,10) - sage: S. = A[] - sage: B. = A.ext(x^2 + 7) - sage: B.uniformizer() + sage: S. = A[] # needs sage.libs.ntl + sage: B. = A.ext(x^2 + 7) # needs sage.libs.ntl + sage: B.uniformizer() # needs sage.libs.ntl t + O(t^21) """ return self.gen() @@ -219,9 +219,9 @@ def _uniformizer_print(self): EXAMPLES:: sage: A = Zp(7,10) - sage: S. = A[] - sage: B. = A.ext(x^2+7) - sage: B._uniformizer_print() + sage: S. = A[] # needs sage.libs.ntl + sage: B. = A.ext(x^2+7) # needs sage.libs.ntl + sage: B._uniformizer_print() # needs sage.libs.ntl 't' """ return self.variable_name() diff --git a/src/sage/rings/padics/factory.py b/src/sage/rings/padics/factory.py index cea226d80c9..ea9681919ea 100644 --- a/src/sage/rings/padics/factory.py +++ b/src/sage/rings/padics/factory.py @@ -897,15 +897,15 @@ def Qq(q, prec=None, type='capped-rel', modulus=None, names=None, is relative precision, which gives the number of known `p`-adic digits:: - sage: R. = Qq(25, 20, 'capped-rel', print_mode='series'); b = 25*a; b + sage: R. = Qq(25, 20, 'capped-rel', print_mode='series'); b = 25*a; b # needs sage.libs.ntl a*5^2 + O(5^22) - sage: b.precision_relative() + sage: b.precision_relative() # needs sage.libs.ntl 20 The second type of precision is absolute precision, which gives the power of `p` that this element is defined modulo:: - sage: b.precision_absolute() + sage: b.precision_absolute() # needs sage.libs.ntl 22 There are two types of unramified `p`-adic fields: capped relative @@ -919,11 +919,11 @@ def Qq(q, prec=None, type='capped-rel', modulus=None, names=None, capped relative field, it truncates it to the precision cap of the field. :: - sage: R. = Qq(9, 5, 'capped-rel', print_mode='series'); b = (1+2*a)^4; b + sage: R. = Qq(9, 5, 'capped-rel', print_mode='series'); b = (1+2*a)^4; b # needs sage.libs.ntl 2 + (2*a + 2)*3 + (2*a + 1)*3^2 + O(3^5) - sage: c = R(3249); c + sage: c = R(3249); c # needs sage.libs.ntl 3^2 + 3^4 + 3^5 + 3^6 + O(3^7) - sage: b + c + sage: b + c # needs sage.libs.ntl 2 + (2*a + 2)*3 + (2*a + 2)*3^2 + 3^4 + O(3^5) In the floating point case, elements do not track their @@ -941,6 +941,7 @@ def Qq(q, prec=None, type='capped-rel', modulus=None, names=None, The base ring can be `\ZZ`, `\QQ`, `\ZZ_p`, `\QQ_p`, `\GF{p}`. :: + sage: # needs sage.libs.ntl sage: P. = ZZ[] sage: R. = Qq(27, modulus = x^3 + 2*x + 1); R.modulus() (1 + O(3^20))*x^3 + O(3^20)*x^2 + (2 + O(3^20))*x + 1 + O(3^20) @@ -950,19 +951,20 @@ def Qq(q, prec=None, type='capped-rel', modulus=None, names=None, sage: T. = Qq(27, modulus = x^3 + 2*x + 1) sage: P. = Qp(3)[] sage: U. = Qq(27, modulus = x^3 + 2*x + 1) - sage: P. = GF(3)[] + sage: P. = GF(3)[] # needs sage.rings.finite_rings sage: V. = Qq(27, modulus = x^3 + 2*x + 1) Which form the modulus is given in has no effect on the unramified extension produced:: - sage: R == S, S == T, T == U, U == V + sage: R == S, S == T, T == U, U == V # needs sage.libs.ntl (True, True, True, False) unless the precision of the modulus differs. In the case of V, the modulus is only given to precision 1, so the resulting field has a precision cap of 1. :: + sage: # needs sage.libs.ntl sage: V.precision_cap() 1 sage: U.precision_cap() @@ -979,24 +981,24 @@ def Qq(q, prec=None, type='capped-rel', modulus=None, names=None, sage: x = var('x') # needs sage.symbolic sage: X. = Qq(27, modulus = x^3 + 2*x + 1); X.modulus() # needs sage.symbolic (1 + O(3^20))*x^3 + O(3^20)*x^2 + (2 + O(3^20))*x + 1 + O(3^20) - sage: X == R # needs sage.symbolic + sage: X == R # needs sage.libs.ntl sage.symbolic True By default, the polynomial chosen is the standard lift of the generator chosen for `\GF{q}`. :: - sage: GF(125, 'a').modulus() + sage: GF(125, 'a').modulus() # needs sage.rings.finite_rings x^3 + 3*x + 3 - sage: Y. = Qq(125); Y.modulus() + sage: Y. = Qq(125); Y.modulus() # needs sage.libs.ntl (1 + O(5^20))*x^3 + O(5^20)*x^2 + (3 + O(5^20))*x + 3 + O(5^20) However, you can choose another polynomial if desired (as long as the reduction to `\GF{p}[x]` is irreducible). :: sage: P. = ZZ[] - sage: Z. = Qq(125, modulus = x^3 + 3*x^2 + x + 1); Z.modulus() + sage: Z. = Qq(125, modulus = x^3 + 3*x^2 + x + 1); Z.modulus() # needs sage.libs.ntl (1 + O(5^20))*x^3 + (3 + O(5^20))*x^2 + (1 + O(5^20))*x + 1 + O(5^20) - sage: Y == Z + sage: Y == Z # needs sage.libs.ntl False PRINTING: @@ -1012,15 +1014,15 @@ def Qq(q, prec=None, type='capped-rel', modulus=None, names=None, 1. **series**: elements are displayed as series in `p`. :: - sage: R. = Qq(9, 20, 'capped-rel', print_mode='series'); (1+2*a)^4 + sage: R. = Qq(9, 20, 'capped-rel', print_mode='series'); (1+2*a)^4 # needs sage.libs.ntl 2 + (2*a + 2)*3 + (2*a + 1)*3^2 + O(3^20) - sage: -3*(1+2*a)^4 + sage: -3*(1+2*a)^4 # needs sage.libs.ntl 3 + a*3^2 + 3^3 + (2*a + 2)*3^4 + (2*a + 2)*3^5 + (2*a + 2)*3^6 + (2*a + 2)*3^7 + (2*a + 2)*3^8 + (2*a + 2)*3^9 + (2*a + 2)*3^10 + (2*a + 2)*3^11 + (2*a + 2)*3^12 + (2*a + 2)*3^13 + (2*a + 2)*3^14 + (2*a + 2)*3^15 + (2*a + 2)*3^16 + (2*a + 2)*3^17 + (2*a + 2)*3^18 + (2*a + 2)*3^19 + (2*a + 2)*3^20 + O(3^21) - sage: ~(3*a+18) + sage: ~(3*a+18) # needs sage.libs.ntl (a + 2)*3^-1 + 1 + 2*3 + (a + 1)*3^2 + 3^3 + 2*3^4 + (a + 1)*3^5 + 3^6 + 2*3^7 + (a + 1)*3^8 + 3^9 + 2*3^10 + (a + 1)*3^11 + 3^12 + 2*3^13 + (a + 1)*3^14 + 3^15 + 2*3^16 + (a + 1)*3^17 + 3^18 + O(3^19) @@ -1028,24 +1030,25 @@ def Qq(q, prec=None, type='capped-rel', modulus=None, names=None, *print_pos* controls whether negatives can be used in the coefficients of powers of `p`. :: - sage: S. = Qq(9, print_mode='series', print_pos=False); (1+2*b)^4 + sage: S. = Qq(9, print_mode='series', print_pos=False); (1+2*b)^4 # needs sage.libs.ntl -1 - b*3 - 3^2 + (b + 1)*3^3 + O(3^20) - sage: -3*(1+2*b)^4 + sage: -3*(1+2*b)^4 # needs sage.libs.ntl 3 + b*3^2 + 3^3 + (-b - 1)*3^4 + O(3^21) *ram_name* controls how the prime is printed. :: - sage: T. = Qq(9, print_mode='series', ram_name='p'); 3*(1+2*d)^4 + sage: T. = Qq(9, print_mode='series', ram_name='p'); 3*(1+2*d)^4 # needs sage.libs.ntl 2*p + (2*d + 2)*p^2 + (2*d + 1)*p^3 + O(p^21) *print_max_ram_terms* limits the number of powers of `p` that appear. :: - sage: U. = Qq(9, print_mode='series', print_max_ram_terms=4); repr(-3*(1+2*e)^4) + sage: U. = Qq(9, print_mode='series', print_max_ram_terms=4); repr(-3*(1+2*e)^4) # needs sage.libs.ntl '3 + e*3^2 + 3^3 + (2*e + 2)*3^4 + ... + O(3^21)' *print_max_unram_terms* limits the number of terms that appear in a coefficient of a power of `p`. :: + sage: # needs sage.libs.ntl sage: V. = Qq(128, prec = 8, print_mode='series'); repr((1+f)^9) '(f^3 + 1) + (f^5 + f^4 + f^3 + f^2)*2 + (f^6 + f^5 + f^4 + f + 1)*2^2 + (f^5 + f^4 + f^2 + f + 1)*2^3 + (f^6 + f^5 + f^4 + f^3 + f^2 + f + 1)*2^4 + (f^5 + f^4)*2^5 + (f^6 + f^5 + f^4 + f^3 + f + 1)*2^6 + (f + 1)*2^7 + O(2^8)' sage: V. = Qq(128, prec = 8, print_mode='series', print_max_unram_terms = 3); repr((1+f)^9) @@ -1063,34 +1066,35 @@ def Qq(q, prec=None, type='capped-rel', modulus=None, names=None, The default is ``False`` for the ``'floating-point'`` type and ``True`` for all other types. :: - sage: U. = Qq(9, 2, show_prec=False); repr(-3*(1+2*e)^4) + sage: U. = Qq(9, 2, show_prec=False); repr(-3*(1+2*e)^4) # needs sage.libs.ntl '3 + e*3^2' *print_sep* and *print_max_terse_terms* have no effect. Note that print options affect equality:: - sage: R == S, R == T, R == U, R == V, S == T, S == U, S == V, T == U, T == V, U == V + sage: R == S, R == T, R == U, R == V, S == T, S == U, S == V, T == U, T == V, U == V # needs sage.libs.ntl (False, False, False, False, False, False, False, False, False, False) 2. **val-unit**: elements are displayed as `p^k u`:: - sage: R. = Qq(9, 7, print_mode='val-unit'); b = (1+3*a)^9 - 1; b + sage: R. = Qq(9, 7, print_mode='val-unit'); b = (1+3*a)^9 - 1; b # needs sage.libs.ntl 3^3 * (15 + 64*a) + O(3^7) - sage: ~b + sage: ~b # needs sage.libs.ntl 3^-3 * (41 + a) + O(3) *print_pos* controls whether to use a balanced representation or not. :: - sage: S. = Qq(9, 7, print_mode='val-unit', print_pos=False) - sage: b = (1+3*a)^9 - 1; b + sage: S. = Qq(9, 7, print_mode='val-unit', print_pos=False) # needs sage.libs.ntl + sage: b = (1+3*a)^9 - 1; b # needs sage.libs.ntl 3^3 * (15 - 17*a) + O(3^7) - sage: ~b + sage: ~b # needs sage.libs.ntl 3^-3 * (-40 + a) + O(3) *ram_name* affects how the prime is printed. :: + sage: # needs sage.libs.ntl sage: A. = Qp(next_prime(10^6), print_mode='val-unit')[] sage: T. = Qq(next_prime(10^6)^3, 4, print_mode='val-unit', ram_name='p', ....: modulus=x^3+385831*x^2+106556*x+321036) @@ -1103,10 +1107,10 @@ def Qq(q, prec=None, type='capped-rel', modulus=None, names=None, *print_max_terse_terms* controls how many terms of the polynomial appear in the unit part. :: - sage: U. = Qq(17^4, 6, print_mode='val-unit', print_max_terse_terms=3) - sage: b = ~(17*(a^3-a+14)); b + sage: U. = Qq(17^4, 6, print_mode='val-unit', print_max_terse_terms=3) # needs sage.libs.ntl + sage: b = ~(17*(a^3-a+14)); b # needs sage.libs.ntl 17^-1 * (22110411 + 11317400*a + 20656972*a^2 + ...) + O(17^5) - sage: b*17*(a^3-a+14) + sage: b*17*(a^3-a+14) # needs sage.libs.ntl 1 + O(17^6) *show_prec* determines how the precision is printed. @@ -1115,7 +1119,7 @@ def Qq(q, prec=None, type='capped-rel', modulus=None, names=None, The default is ``False`` for the ``'floating-point'`` type and ``True`` for all other types. :: - sage: U. = Qq(9, 2, print_mode='val-unit', show_prec=False); repr(-3*(1+2*e)^4) + sage: U. = Qq(9, 2, print_mode='val-unit', show_prec=False); repr(-3*(1+2*e)^4) # needs sage.libs.ntl '3 * (1 + 3*e)' *print_sep*, *print_max_ram_terms* and *print_max_unram_terms* have no @@ -1123,44 +1127,44 @@ def Qq(q, prec=None, type='capped-rel', modulus=None, names=None, Equality again depends on the printing options:: - sage: R == S, R == T, R == U, S == T, S == U, T == U + sage: R == S, R == T, R == U, S == T, S == U, T == U # needs sage.libs.ntl (False, False, False, False, False, False) 3. **terse**: elements are displayed as a polynomial of degree less than the degree of the extension. :: - sage: R. = Qq(125, print_mode='terse') - sage: (a+5)^177 + sage: R. = Qq(125, print_mode='terse') # needs sage.libs.ntl + sage: (a+5)^177 # needs sage.libs.ntl 68210977979428 + 90313850704069*a + 73948093055069*a^2 + O(5^20) - sage: (a/5+1)^177 + sage: (a/5+1)^177 # needs sage.libs.ntl 68210977979428/5^177 + 90313850704069/5^177*a + 73948093055069/5^177*a^2 + O(5^-157) As of version 3.3, if coefficients of the polynomial are non-integral, they are always printed with an explicit power of `p` in the denominator. :: - sage: 5*a + a^2/25 + sage: 5*a + a^2/25 # needs sage.libs.ntl 5*a + 1/5^2*a^2 + O(5^18) *print_pos* controls whether to use a balanced representation or not. :: - sage: (a-5)^6 + sage: (a-5)^6 # needs sage.libs.ntl 22864 + 95367431627998*a + 8349*a^2 + O(5^20) - sage: S. = Qq(125, print_mode='terse', print_pos=False); b = (a-5)^6; b + sage: S. = Qq(125, print_mode='terse', print_pos=False); b = (a-5)^6; b # needs sage.libs.ntl 22864 - 12627*a + 8349*a^2 + O(5^20) - sage: (a - 1/5)^6 + sage: (a - 1/5)^6 # needs sage.libs.ntl -20624/5^6 + 18369/5^5*a + 1353/5^3*a^2 + O(5^14) *ram_name* affects how the prime is printed. :: - sage: T. = Qq(125, print_mode='terse', ram_name='p'); (a - 1/5)^6 + sage: T. = Qq(125, print_mode='terse', ram_name='p'); (a - 1/5)^6 # needs sage.libs.ntl 95367431620001/p^6 + 18369/p^5*a + 1353/p^3*a^2 + O(p^14) *print_max_terse_terms* controls how many terms of the polynomial are shown. :: - sage: U. = Qq(625, print_mode='terse', print_max_terse_terms=2); (a-1/5)^6 + sage: U. = Qq(625, print_mode='terse', print_max_terse_terms=2); (a-1/5)^6 # needs sage.libs.ntl 106251/5^6 + 49994/5^5*a + ... + O(5^14) *show_prec* determines how the precision is printed. @@ -1169,7 +1173,7 @@ def Qq(q, prec=None, type='capped-rel', modulus=None, names=None, The default is ``False`` for the ``'floating-point'`` type and ``True`` for all other types. :: - sage: U. = Qq(9, 2, print_mode='terse', show_prec=False); repr(-3*(1+2*e)^4) + sage: U. = Qq(9, 2, print_mode='terse', show_prec=False); repr(-3*(1+2*e)^4) # needs sage.libs.ntl '3 + 9*e' *print_sep*, *print_max_ram_terms* and *print_max_unram_terms* have no @@ -1177,7 +1181,7 @@ def Qq(q, prec=None, type='capped-rel', modulus=None, names=None, Equality again depends on the printing options:: - sage: R == S, R == T, R == U, S == T, S == U, T == U + sage: R == S, R == T, R == U, S == T, S == U, T == U # needs sage.libs.ntl (False, False, False, False, False, False) 4. **digits**: This print mode is not available when the residue @@ -1189,30 +1193,31 @@ def Qq(q, prec=None, type='capped-rel', modulus=None, names=None, 5. **bars**: elements are displayed in a similar fashion to series, but more compactly. :: - sage: R. = Qq(125); (a+5)^6 + sage: R. = Qq(125); (a+5)^6 # needs sage.libs.ntl (4*a^2 + 3*a + 4) + (3*a^2 + 2*a)*5 + (a^2 + a + 1)*5^2 + (3*a + 2)*5^3 + (3*a^2 + a + 3)*5^4 + (2*a^2 + 3*a + 2)*5^5 + O(5^20) - sage: R. = Qq(125, print_mode='bars', prec=8); repr((a+5)^6) + sage: R. = Qq(125, print_mode='bars', prec=8); repr((a+5)^6) # needs sage.libs.ntl '...[2, 3, 2]|[3, 1, 3]|[2, 3]|[1, 1, 1]|[0, 2, 3]|[4, 3, 4]' - sage: repr((a-5)^6) + sage: repr((a-5)^6) # needs sage.libs.ntl '...[0, 4]|[1, 4]|[2, 0, 2]|[1, 4, 3]|[2, 3, 1]|[4, 4, 3]|[2, 4, 4]|[4, 3, 4]' Note that elements with negative valuation are shown with a decimal point at valuation 0. :: - sage: repr((a+1/5)^6) + sage: repr((a+1/5)^6) # needs sage.libs.ntl '...[3]|[4, 1, 3]|.|[1, 2, 3]|[3, 3]|[0, 0, 3]|[0, 1]|[0, 1]|[1]' - sage: repr((a+1/5)^2) + sage: repr((a+1/5)^2) # needs sage.libs.ntl '...[0, 0, 1]|.|[0, 2]|[1]' If not enough precision is known, ``'?'`` is used instead. :: - sage: repr((a+R(1/5,relprec=3))^7) + sage: repr((a+R(1/5,relprec=3))^7) # needs sage.libs.ntl '...|.|?|?|?|?|[0, 1, 1]|[0, 2]|[1]' Note that it's not possible to read off the precision from the representation in this mode. :: + sage: # needs sage.libs.ntl sage: b = a + 3; repr(b) '...[3, 1]' sage: c = a + R(3, 4); repr(c) @@ -1224,28 +1229,29 @@ def Qq(q, prec=None, type='capped-rel', modulus=None, names=None, *print_pos* controls whether the digits can be negative. :: - sage: S. = Qq(125, print_mode='bars', print_pos=False); repr((a-5)^6) + sage: S. = Qq(125, print_mode='bars', print_pos=False); repr((a-5)^6) # needs sage.libs.ntl '...[1, -1, 1]|[2, 1, -2]|[2, 0, -2]|[-2, -1, 2]|[0, 0, -1]|[-2]|[-1, -2, -1]' - sage: repr((a-1/5)^6) + sage: repr((a-1/5)^6) # needs sage.libs.ntl '...[0, 1, 2]|[-1, 1, 1]|.|[-2, -1, -1]|[2, 2, 1]|[0, 0, -2]|[0, -1]|[0, -1]|[1]' *print_max_ram_terms* controls the maximum number of "digits" shown. Note that this puts a cap on the relative precision, not the absolute precision. :: - sage: T. = Qq(125, print_max_ram_terms=3, print_pos=False); (a-5)^6 + sage: T. = Qq(125, print_max_ram_terms=3, print_pos=False); (a-5)^6 # needs sage.libs.ntl (-a^2 - 2*a - 1) - 2*5 - a^2*5^2 + ... + O(5^20) - sage: 5*(a-5)^6 + 50 + sage: 5*(a-5)^6 + 50 # needs sage.libs.ntl (-a^2 - 2*a - 1)*5 - a^2*5^3 + (2*a^2 - a - 2)*5^4 + ... + O(5^21) *print_sep* controls the separating character (``'|'`` by default). :: - sage: U. = Qq(625, print_mode='bars', print_sep=''); b = (a+5)^6; repr(b) + sage: U. = Qq(625, print_mode='bars', print_sep=''); b = (a+5)^6; repr(b) # needs sage.libs.ntl '...[0, 1][4, 0, 2][3, 2, 2, 3][4, 2, 2, 4][0, 3][1, 1, 3][3, 1, 4, 1]' *print_max_unram_terms* controls how many terms are shown in each "digit":: + sage: # needs sage.libs.ntl sage: with local_print_mode(U, {'max_unram_terms': 3}): repr(b) '...[0, 1][4,..., 0, 2][3,..., 2, 3][4,..., 2, 4][0, 3][1,..., 1, 3][3,..., 4, 1]' sage: with local_print_mode(U, {'max_unram_terms': 2}): repr(b) @@ -1261,14 +1267,14 @@ def Qq(q, prec=None, type='capped-rel', modulus=None, names=None, The default is ``False`` for the ``'floating-point'`` type and ``True`` for all other types. :: - sage: U. = Qq(9, 2, print_mode='bars', show_prec=True); repr(-3*(1+2*e)^4) + sage: U. = Qq(9, 2, print_mode='bars', show_prec=True); repr(-3*(1+2*e)^4) # needs sage.libs.ntl '...[0, 1]|[1]|[]' *ram_name* and *print_max_terse_terms* have no effect. Equality depends on printing options:: - sage: R == S, R == T, R == U, S == T, S == U, T == U + sage: R == S, R == T, R == U, S == T, S == U, T == U # needs sage.libs.ntl (False, False, False, False, False, False) EXAMPLES: @@ -1281,16 +1287,16 @@ def Qq(q, prec=None, type='capped-rel', modulus=None, names=None, sage: p = next_prime(2^123) sage: k = Qp(p) - sage: R. = k[] - sage: K = Qq([(p, 5)], modulus=x^5+x+4, names='a', ram_name='p', + sage: R. = k[] # needs sage.libs.ntl + sage: K = Qq([(p, 5)], modulus=x^5+x+4, names='a', ram_name='p', # needs sage.libs.ntl ....: print_pos=False, check=False) - sage: K.0^5 + sage: K.0^5 # needs sage.libs.ntl (-a - 4) + O(p^20) In tests on ``sage.math.washington.edu``, the creation of ``K`` as above took an average of 1.58ms, while:: - sage: K = Qq(p^5, modulus=x^5+x+4, names='a', ram_name='p', + sage: K = Qq(p^5, modulus=x^5+x+4, names='a', ram_name='p', # needs sage.libs.ntl ....: print_pos=False, check=True) took an average of 24.5ms. Of course, with smaller primes these @@ -1300,11 +1306,11 @@ def Qq(q, prec=None, type='capped-rel', modulus=None, names=None, Check that :trac:`8162` is resolved:: - sage: R = Qq([(5,3)], names="alpha", check=False); R + sage: R = Qq([(5,3)], names="alpha", check=False); R # needs sage.libs.ntl 5-adic Unramified Extension Field in alpha defined by x^3 + 3*x + 3 - sage: Qq((5, 3), names="alpha") is R + sage: Qq((5, 3), names="alpha") is R # needs sage.libs.ntl True - sage: Qq(125.factor(), names="alpha") is R + sage: Qq(125.factor(), names="alpha") is R # needs sage.libs.ntl True Check that :trac:`18606` is resolved:: @@ -1312,8 +1318,8 @@ def Qq(q, prec=None, type='capped-rel', modulus=None, names=None, sage: x = QQ['x'].gen() sage: F = Qp(5,20) sage: K0 = F.extension(x^2-F(13),names = 'g') - sage: K1 = F.extension(x^2-13,names = 'g') - sage: K0 is K1 + sage: K1 = F.extension(x^2-13,names = 'g') # needs sage.libs.ntl + sage: K0 is K1 # needs sage.libs.ntl True """ if is_Element(q): @@ -1419,7 +1425,7 @@ def QqCR(q, prec=None, *args, **kwds): EXAMPLES:: - sage: R. = QqCR(25, 40); R + sage: R. = QqCR(25, 40); R # needs sage.libs.ntl 5-adic Unramified Extension Field in a defined by x^2 + 4*x + 2 """ return Qq(q, prec, 'capped-rel', *args, **kwds) @@ -1434,7 +1440,7 @@ def QqFP(q, prec=None, *args, **kwds): EXAMPLES:: - sage: R. = QqFP(25, 40); R + sage: R. = QqFP(25, 40); R # needs sage.libs.flint 5-adic Unramified Extension Field in a defined by x^2 + 4*x + 2 """ return Qq(q, prec, 'floating-point', *args, **kwds) @@ -1477,8 +1483,7 @@ def QpER(p, prec=None, halt=None, secure=False, *args, **kwds): EXAMPLES:: - sage: R = QpER(2) - sage: R + sage: R = QpER(2); R # needs sage.libs.flint 2-adic Field handled with relaxed arithmetics """ return Qp(p, (prec, halt, secure), 'relaxed', *args, **kwds) @@ -2113,15 +2118,15 @@ def Zq(q, prec=None, type='capped-rel', modulus=None, names=None, is relative precision (default), which gives the number of known `p`-adic digits:: - sage: R. = Zq(25, 20, 'capped-rel', print_mode='series'); b = 25*a; b + sage: R. = Zq(25, 20, 'capped-rel', print_mode='series'); b = 25*a; b # needs sage.libs.ntl a*5^2 + O(5^22) - sage: b.precision_relative() + sage: b.precision_relative() # needs sage.libs.ntl 20 The second type of precision is absolute precision, which gives the power of `p` that this element is defined modulo:: - sage: b.precision_absolute() + sage: b.precision_absolute() # needs sage.libs.ntl 22 There are many types of `p`-adic rings: capped relative rings @@ -2137,43 +2142,45 @@ def Zq(q, prec=None, type='capped-rel', modulus=None, names=None, capped relative field, it truncates it to the precision cap of the field. :: - sage: R. = Zq(9, 5, 'capped-rel', print_mode='series'); b = (1+2*a)^4; b + sage: R. = Zq(9, 5, 'capped-rel', print_mode='series'); b = (1+2*a)^4; b # needs sage.libs.ntl 2 + (2*a + 2)*3 + (2*a + 1)*3^2 + O(3^5) - sage: c = R(3249); c + sage: c = R(3249); c # needs sage.libs.ntl 3^2 + 3^4 + 3^5 + 3^6 + O(3^7) - sage: b + c + sage: b + c # needs sage.libs.ntl 2 + (2*a + 2)*3 + (2*a + 2)*3^2 + 3^4 + O(3^5) One can invert non-units: the result is in the fraction field. :: - sage: d = ~(3*b+c); d + sage: d = ~(3*b+c); d # needs sage.libs.ntl 2*3^-1 + (a + 1) + (a + 1)*3 + a*3^3 + O(3^4) - sage: d.parent() + sage: d.parent() # needs sage.libs.ntl 3-adic Unramified Extension Field in a defined by x^2 + 2*x + 2 The capped absolute case is the same as the capped relative case, except that the cap is on the absolute precision rather than the relative precision. :: + sage: # needs sage.libs.flint sage: R. = Zq(9, 5, 'capped-abs', print_mode='series'); b = 3*(1+2*a)^4; b 2*3 + (2*a + 2)*3^2 + (2*a + 1)*3^3 + O(3^5) - sage: c = R(3249); c + sage: c = R(3249); c # needs sage.libs.ntl 3^2 + 3^4 + O(3^5) - sage: b*c + sage: b*c # needs sage.libs.ntl 2*3^3 + (2*a + 2)*3^4 + O(3^5) - sage: b*c >> 1 + sage: b*c >> 1 # needs sage.libs.ntl 2*3^2 + (2*a + 2)*3^3 + O(3^4) The fixed modulus case is like the capped absolute, except that individual elements don't track their precision. :: + sage: # needs sage.libs.flint sage: R. = Zq(9, 5, 'fixed-mod', print_mode='series'); b = 3*(1+2*a)^4; b 2*3 + (2*a + 2)*3^2 + (2*a + 1)*3^3 - sage: c = R(3249); c + sage: c = R(3249); c # needs sage.libs.ntl 3^2 + 3^4 - sage: b*c + sage: b*c # needs sage.libs.ntl 2*3^3 + (2*a + 2)*3^4 - sage: b*c >> 1 + sage: b*c >> 1 # needs sage.libs.ntl 2*3^2 + (2*a + 2)*3^3 The floating point case is similar to the fixed modulus type @@ -2192,6 +2199,7 @@ def Zq(q, prec=None, type='capped-rel', modulus=None, names=None, The base ring can be `\ZZ`, `\QQ`, `\ZZ_p`, `\GF{p}`, or anything that can be converted to `\ZZ_p`. :: + sage: # needs sage.libs.ntl sage: P. = ZZ[] sage: R. = Zq(27, modulus = x^3 + 2*x + 1); R.modulus() (1 + O(3^20))*x^3 + O(3^20)*x^2 + (2 + O(3^20))*x + 1 + O(3^20) @@ -2201,19 +2209,20 @@ def Zq(q, prec=None, type='capped-rel', modulus=None, names=None, sage: T. = Zq(27, modulus = x^3 + 2*x + 1) sage: P. = Qp(3)[] sage: U. = Zq(27, modulus = x^3 + 2*x + 1) - sage: P. = GF(3)[] + sage: P. = GF(3)[] # needs sage.rings.finite_rings sage: V. = Zq(27, modulus = x^3 + 2*x + 1) Which form the modulus is given in has no effect on the unramified extension produced:: - sage: R == S, R == T, T == U, U == V + sage: R == S, R == T, T == U, U == V # needs sage.libs.ntl (False, True, True, False) unless the modulus is different, or the precision of the modulus differs. In the case of ``V``, the modulus is only given to precision ``1``, so the resulting field has a precision cap of ``1``. :: + sage: # needs sage.libs.ntl sage: V.precision_cap() 1 sage: U.precision_cap() @@ -2230,24 +2239,24 @@ def Zq(q, prec=None, type='capped-rel', modulus=None, names=None, sage: x = var('x') # needs sage.symbolic sage: X. = Zq(27, modulus = x^3 + 2*x + 1); X.modulus() # needs sage.symbolic (1 + O(3^20))*x^3 + O(3^20)*x^2 + (2 + O(3^20))*x + 1 + O(3^20) - sage: X == R # needs sage.symbolic + sage: X == R # needs sage.libs.ntl sage.symbolic True By default, the polynomial chosen is the standard lift of the generator chosen for `\GF{q}`. :: - sage: GF(125, 'a').modulus() + sage: GF(125, 'a').modulus() # needs sage.rings.finite_rings x^3 + 3*x + 3 - sage: Y. = Zq(125); Y.modulus() + sage: Y. = Zq(125); Y.modulus() # needs sage.libs.ntl (1 + O(5^20))*x^3 + O(5^20)*x^2 + (3 + O(5^20))*x + 3 + O(5^20) However, you can choose another polynomial if desired (as long as the reduction to `\GF{p}[x]` is irreducible). :: sage: P. = ZZ[] - sage: Z. = Zq(125, modulus = x^3 + 3*x^2 + x + 1); Z.modulus() + sage: Z. = Zq(125, modulus = x^3 + 3*x^2 + x + 1); Z.modulus() # needs sage.libs.ntl (1 + O(5^20))*x^3 + (3 + O(5^20))*x^2 + (1 + O(5^20))*x + 1 + O(5^20) - sage: Y == Z + sage: Y == Z # needs sage.libs.ntl False PRINTING: @@ -2263,37 +2272,44 @@ def Zq(q, prec=None, type='capped-rel', modulus=None, names=None, 1. **series**: elements are displayed as series in `p`. :: + sage: # needs sage.libs.ntl sage: R. = Zq(9, 20, 'capped-rel', print_mode='series'); (1+2*a)^4 2 + (2*a + 2)*3 + (2*a + 1)*3^2 + O(3^20) sage: -3*(1+2*a)^4 - 3 + a*3^2 + 3^3 + (2*a + 2)*3^4 + (2*a + 2)*3^5 + (2*a + 2)*3^6 + (2*a + 2)*3^7 + (2*a + 2)*3^8 + (2*a + 2)*3^9 + (2*a + 2)*3^10 + (2*a + 2)*3^11 + (2*a + 2)*3^12 + (2*a + 2)*3^13 + (2*a + 2)*3^14 + (2*a + 2)*3^15 + (2*a + 2)*3^16 + (2*a + 2)*3^17 + (2*a + 2)*3^18 + (2*a + 2)*3^19 + (2*a + 2)*3^20 + O(3^21) + 3 + a*3^2 + 3^3 + (2*a + 2)*3^4 + (2*a + 2)*3^5 + (2*a + 2)*3^6 + (2*a + 2)*3^7 + + (2*a + 2)*3^8 + (2*a + 2)*3^9 + (2*a + 2)*3^10 + (2*a + 2)*3^11 + (2*a + 2)*3^12 + + (2*a + 2)*3^13 + (2*a + 2)*3^14 + (2*a + 2)*3^15 + (2*a + 2)*3^16 + + (2*a + 2)*3^17 + (2*a + 2)*3^18 + (2*a + 2)*3^19 + (2*a + 2)*3^20 + O(3^21) sage: b = ~(3*a+18); b - (a + 2)*3^-1 + 1 + 2*3 + (a + 1)*3^2 + 3^3 + 2*3^4 + (a + 1)*3^5 + 3^6 + 2*3^7 + (a + 1)*3^8 + 3^9 + 2*3^10 + (a + 1)*3^11 + 3^12 + 2*3^13 + (a + 1)*3^14 + 3^15 + 2*3^16 + (a + 1)*3^17 + 3^18 + O(3^19) + (a + 2)*3^-1 + 1 + 2*3 + (a + 1)*3^2 + 3^3 + 2*3^4 + (a + 1)*3^5 + 3^6 + 2*3^7 + + (a + 1)*3^8 + 3^9 + 2*3^10 + (a + 1)*3^11 + 3^12 + 2*3^13 + (a + 1)*3^14 + + 3^15 + 2*3^16 + (a + 1)*3^17 + 3^18 + O(3^19) sage: b.parent() is R.fraction_field() True *print_pos* controls whether negatives can be used in the coefficients of powers of `p`. :: - sage: S. = Zq(9, print_mode='series', print_pos=False); (1+2*b)^4 + sage: S. = Zq(9, print_mode='series', print_pos=False); (1+2*b)^4 # needs sage.libs.ntl -1 - b*3 - 3^2 + (b + 1)*3^3 + O(3^20) - sage: -3*(1+2*b)^4 + sage: -3*(1+2*b)^4 # needs sage.libs.ntl 3 + b*3^2 + 3^3 + (-b - 1)*3^4 + O(3^21) *ram_name* controls how the prime is printed. :: - sage: T. = Zq(9, print_mode='series', ram_name='p'); 3*(1+2*d)^4 + sage: T. = Zq(9, print_mode='series', ram_name='p'); 3*(1+2*d)^4 # needs sage.libs.ntl 2*p + (2*d + 2)*p^2 + (2*d + 1)*p^3 + O(p^21) *print_max_ram_terms* limits the number of powers of `p` that appear. :: - sage: U. = Zq(9, print_mode='series', print_max_ram_terms=4); repr(-3*(1+2*e)^4) + sage: U. = Zq(9, print_mode='series', print_max_ram_terms=4); repr(-3*(1+2*e)^4) # needs sage.libs.ntl '3 + e*3^2 + 3^3 + (2*e + 2)*3^4 + ... + O(3^21)' *print_max_unram_terms* limits the number of terms that appear in a coefficient of a power of `p`. :: + sage: # needs sage.libs.ntl sage: V. = Zq(128, prec = 8, print_mode='series'); repr((1+f)^9) '(f^3 + 1) + (f^5 + f^4 + f^3 + f^2)*2 + (f^6 + f^5 + f^4 + f + 1)*2^2 + (f^5 + f^4 + f^2 + f + 1)*2^3 + (f^6 + f^5 + f^4 + f^3 + f^2 + f + 1)*2^4 + (f^5 + f^4)*2^5 + (f^6 + f^5 + f^4 + f^3 + f + 1)*2^6 + (f + 1)*2^7 + O(2^8)' sage: V. = Zq(128, prec = 8, print_mode='series', print_max_unram_terms = 3); repr((1+f)^9) @@ -2311,33 +2327,34 @@ def Zq(q, prec=None, type='capped-rel', modulus=None, names=None, The default is ``False`` for the ``'floating-point'`` and ``'fixed-mod'`` types and ``True`` for all other types. :: - sage: U. = Zq(9, 2, show_prec=False); repr(-3*(1+2*e)^4) + sage: U. = Zq(9, 2, show_prec=False); repr(-3*(1+2*e)^4) # needs sage.libs.ntl '3 + e*3^2' *print_sep* and *print_max_terse_terms* have no effect. Note that print options affect equality:: - sage: R == S, R == T, R == U, R == V, S == T, S == U, S == V, T == U, T == V, U == V + sage: R == S, R == T, R == U, R == V, S == T, S == U, S == V, T == U, T == V, U == V # needs sage.libs.ntl (False, False, False, False, False, False, False, False, False, False) 2. **val-unit**: elements are displayed as `p^k u`:: - sage: R. = Zq(9, 7, print_mode='val-unit'); b = (1+3*a)^9 - 1; b + sage: R. = Zq(9, 7, print_mode='val-unit'); b = (1+3*a)^9 - 1; b # needs sage.libs.ntl 3^3 * (15 + 64*a) + O(3^7) - sage: ~b + sage: ~b # needs sage.libs.ntl 3^-3 * (41 + a) + O(3) *print_pos* controls whether to use a balanced representation or not. :: - sage: S. = Zq(9, 7, print_mode='val-unit', print_pos=False); b = (1+3*a)^9 - 1; b + sage: S. = Zq(9, 7, print_mode='val-unit', print_pos=False); b = (1+3*a)^9 - 1; b # needs sage.libs.ntl 3^3 * (15 - 17*a) + O(3^7) - sage: ~b + sage: ~b # needs sage.libs.ntl 3^-3 * (-40 + a) + O(3) *ram_name* affects how the prime is printed. :: + sage: # needs sage.libs.ntl sage: A. = Zp(next_prime(10^6), print_mode='val-unit')[] sage: T. = Zq(next_prime(10^6)^3, 4, print_mode='val-unit', ram_name='p', ....: modulus=x^3+385831*x^2+106556*x+321036) @@ -2350,6 +2367,7 @@ def Zq(q, prec=None, type='capped-rel', modulus=None, names=None, *print_max_terse_terms* controls how many terms of the polynomial appear in the unit part. :: + sage: # needs sage.libs.ntl sage: U. = Zq(17^4, 6, print_mode='val-unit', print_max_terse_terms=3) sage: b = 17*(a^3-a+14)^6; b 17 * (12131797 + 12076378*a + 10809706*a^2 + ...) + O(17^7) @@ -2360,19 +2378,20 @@ def Zq(q, prec=None, type='capped-rel', modulus=None, names=None, The default is ``False`` for the ``'floating-point'`` and ``'fixed-mod'`` types and ``True`` for all other types. :: - sage: U. = Zq(9, 2, print_mode='val-unit', show_prec=False); repr(-3*(1+2*e)^4) + sage: U. = Zq(9, 2, print_mode='val-unit', show_prec=False); repr(-3*(1+2*e)^4) # needs sage.libs.ntl '3 * (1 + 3*e)' *print_sep*, *print_max_ram_terms* and *print_max_unram_terms* have no effect. Equality again depends on the printing options:: - sage: R == S, R == T, R == U, S == T, S == U, T == U + sage: R == S, R == T, R == U, S == T, S == U, T == U # needs sage.libs.ntl (False, False, False, False, False, False) 3. **terse**: elements are displayed as a polynomial of degree less than the degree of the extension. :: + sage: # needs sage.libs.ntl sage: R. = Zq(125, print_mode='terse') sage: (a+5)^177 68210977979428 + 90313850704069*a + 73948093055069*a^2 + O(5^20) @@ -2387,12 +2406,14 @@ def Zq(q, prec=None, type='capped-rel', modulus=None, names=None, non-integral, they are always printed with an explicit power of `p` in the denominator. :: + sage: # needs sage.libs.ntl sage: 5*a + a^2/25 5*a + 1/5^2*a^2 + O(5^18) *print_pos* controls whether to use a balanced representation or not. :: + sage: # needs sage.libs.ntl sage: (a-5)^6 22864 + 95367431627998*a + 8349*a^2 + O(5^20) sage: S. = Zq(125, print_mode='terse', print_pos=False); b = (a-5)^6; b @@ -2402,13 +2423,13 @@ def Zq(q, prec=None, type='capped-rel', modulus=None, names=None, *ram_name* affects how the prime is printed. :: - sage: T. = Zq(125, print_mode='terse', ram_name='p'); (a - 1/5)^6 + sage: T. = Zq(125, print_mode='terse', ram_name='p'); (a - 1/5)^6 # needs sage.libs.ntl 95367431620001/p^6 + 18369/p^5*a + 1353/p^3*a^2 + O(p^14) *print_max_terse_terms* controls how many terms of the polynomial are shown. :: - sage: U. = Zq(625, print_mode='terse', print_max_terse_terms=2); (a-1/5)^6 + sage: U. = Zq(625, print_mode='terse', print_max_terse_terms=2); (a-1/5)^6 # needs sage.libs.ntl 106251/5^6 + 49994/5^5*a + ... + O(5^14) *show_prec* determines how the precision is printed. @@ -2417,7 +2438,7 @@ def Zq(q, prec=None, type='capped-rel', modulus=None, names=None, The default is ``False`` for the ``'floating-point'`` and ``'fixed-mod'`` types and ``True`` for all other types. :: - sage: U. = Zq(9, 2, print_mode='terse', show_prec=False); repr(-3*(1+2*e)^4) + sage: U. = Zq(9, 2, print_mode='terse', show_prec=False); repr(-3*(1+2*e)^4) # needs sage.libs.ntl '3 + 9*e' *print_sep*, *print_max_ram_terms* and *print_max_unram_terms* have no @@ -2425,7 +2446,7 @@ def Zq(q, prec=None, type='capped-rel', modulus=None, names=None, Equality again depends on the printing options:: - sage: R == S, R == T, R == U, S == T, S == U, T == U + sage: R == S, R == T, R == U, S == T, S == U, T == U # needs sage.libs.ntl (False, False, False, False, False, False) 4. **digits**: This print mode is not available when the residue @@ -2435,6 +2456,7 @@ def Zq(q, prec=None, type='capped-rel', modulus=None, names=None, 5. **bars**: elements are displayed in a similar fashion to series, but more compactly. :: + sage: # needs sage.libs.ntl sage: R. = Zq(125); (a+5)^6 (4*a^2 + 3*a + 4) + (3*a^2 + 2*a)*5 + (a^2 + a + 1)*5^2 + (3*a + 2)*5^3 + (3*a^2 + a + 3)*5^4 + (2*a^2 + 3*a + 2)*5^5 + O(5^20) @@ -2446,6 +2468,7 @@ def Zq(q, prec=None, type='capped-rel', modulus=None, names=None, Note that it's not possible to read off the precision from the representation in this mode. :: + sage: # needs sage.libs.ntl sage: b = a + 3; repr(b) '...[3, 1]' sage: c = a + R(3, 4); repr(c) @@ -2457,6 +2480,7 @@ def Zq(q, prec=None, type='capped-rel', modulus=None, names=None, *print_pos* controls whether the digits can be negative. :: + sage: # needs sage.libs.ntl sage: S. = Zq(125, print_mode='bars', print_pos=False); repr((a-5)^6) '...[1, -1, 1]|[2, 1, -2]|[2, 0, -2]|[-2, -1, 2]|[0, 0, -1]|[-2]|[-1, -2, -1]' sage: repr((a-1/5)^6) @@ -2466,6 +2490,7 @@ def Zq(q, prec=None, type='capped-rel', modulus=None, names=None, Note that this puts a cap on the relative precision, not the absolute precision. :: + sage: # needs sage.libs.ntl sage: T. = Zq(125, print_max_ram_terms=3, print_pos=False); (a-5)^6 (-a^2 - 2*a - 1) - 2*5 - a^2*5^2 + ... + O(5^20) sage: 5*(a-5)^6 + 50 @@ -2475,12 +2500,13 @@ def Zq(q, prec=None, type='capped-rel', modulus=None, names=None, *print_sep* controls the separating character (``'|'`` by default). :: - sage: U. = Zq(625, print_mode='bars', print_sep=''); b = (a+5)^6; repr(b) + sage: U. = Zq(625, print_mode='bars', print_sep=''); b = (a+5)^6; repr(b) # needs sage.libs.ntl '...[0, 1][4, 0, 2][3, 2, 2, 3][4, 2, 2, 4][0, 3][1, 1, 3][3, 1, 4, 1]' *print_max_unram_terms* controls how many terms are shown in each ``'digit'``:: + sage: # needs sage.libs.ntl sage: with local_print_mode(U, {'max_unram_terms': 3}): repr(b) '...[0, 1][4,..., 0, 2][3,..., 2, 3][4,..., 2, 4][0, 3][1,..., 1, 3][3,..., 4, 1]' sage: with local_print_mode(U, {'max_unram_terms': 2}): repr(b) @@ -2496,14 +2522,14 @@ def Zq(q, prec=None, type='capped-rel', modulus=None, names=None, The default is ``False`` for the ``'floating-point'`` and ``'fixed-mod'`` types and ``True`` for all other types. :: - sage: U. = Zq(9, 2, print_mode='bars', show_prec='bigoh'); repr(-3*(1+2*e)^4) + sage: U. = Zq(9, 2, print_mode='bars', show_prec='bigoh'); repr(-3*(1+2*e)^4) # needs sage.libs.ntl '[0, 1]|[1]|[] + O(3^3)' *ram_name* and *print_max_terse_terms* have no effect. Equality depends on printing options:: - sage: R == S, R == T, R == U, S == T, S == U, T == U + sage: R == S, R == T, R == U, S == T, S == U, T == U # needs sage.libs.ntl (False, False, False, False, False, False) EXAMPLES: @@ -2514,6 +2540,7 @@ def Zq(q, prec=None, type='capped-rel', modulus=None, names=None, have to factor. If you do so, you need to use names explicitly rather than the ``R.`` syntax. :: + sage: # needs sage.libs.ntl sage: p = next_prime(2^123) sage: k = Zp(p) sage: R. = k[] @@ -2525,7 +2552,7 @@ def Zq(q, prec=None, type='capped-rel', modulus=None, names=None, In tests on sage.math, the creation of ``K`` as above took an average of 1.58ms, while:: - sage: K = Zq(p^5, modulus=x^5+x+4, names='a', ram_name='p', + sage: K = Zq(p^5, modulus=x^5+x+4, names='a', ram_name='p', # needs sage.libs.ntl ....: print_pos=False, check=True) took an average of 24.5ms. Of course, with smaller primes these @@ -2533,6 +2560,7 @@ def Zq(q, prec=None, type='capped-rel', modulus=None, names=None, TESTS:: + sage: # needs sage.libs.ntl sage: R = Zq([(5,3)], names="alpha"); R 5-adic Unramified Extension Ring in alpha defined by x^3 + 3*x + 3 sage: Zq((5, 3), names="alpha") is R @@ -2664,7 +2692,7 @@ def ZqCR(q, prec=None, *args, **kwds): EXAMPLES:: - sage: R. = ZqCR(25, 40); R + sage: R. = ZqCR(25, 40); R # needs sage.libs.ntl 5-adic Unramified Extension Ring in a defined by x^2 + 4*x + 2 """ return Zq(q, prec, 'capped-rel', *args, **kwds) @@ -2677,7 +2705,7 @@ def ZqCA(q, prec=None, *args, **kwds): EXAMPLES:: - sage: R. = ZqCA(25, 40); R + sage: R. = ZqCA(25, 40); R # needs sage.libs.flint 5-adic Unramified Extension Ring in a defined by x^2 + 4*x + 2 """ return Zq(q, prec, 'capped-abs', *args, **kwds) @@ -2690,7 +2718,7 @@ def ZqFM(q, prec=None, *args, **kwds): EXAMPLES:: - sage: R. = ZqFM(25, 40); R + sage: R. = ZqFM(25, 40); R # needs sage.libs.flint 5-adic Unramified Extension Ring in a defined by x^2 + 4*x + 2 """ return Zq(q, prec, 'fixed-mod', *args, **kwds) @@ -2704,7 +2732,7 @@ def ZqFP(q, prec=None, *args, **kwds): EXAMPLES:: - sage: R. = ZqFP(25, 40); R + sage: R. = ZqFP(25, 40); R # needs sage.libs.flint 5-adic Unramified Extension Ring in a defined by x^2 + 4*x + 2 """ return Zq(q, prec, 'floating-point', *args, **kwds) @@ -2902,7 +2930,7 @@ def ZpLC(p, prec=None, *args, **kwds): might be delayed. We can force it with the method :meth:`del_elements`:: sage: z = 0 - sage: prec # random output, could be 2 objects if the garbage collector is fast + sage: prec # random output, could be 2 objects if the garbage collector is fast Precision lattice on 3 objects sage: prec.del_elements() sage: prec @@ -2911,7 +2939,7 @@ def ZpLC(p, prec=None, *args, **kwds): The method :meth:`precision_lattice` returns (a matrix defining) the lattice that models the precision. Here we have:: - sage: prec.precision_lattice() + sage: prec.precision_lattice() # needs sage.geometry.polyhedron [9765625 0] [ 0 3125] @@ -2923,7 +2951,7 @@ def ZpLC(p, prec=None, *args, **kwds): sage: x, y = 3*x+2*y, 2*(x-y) sage: prec.del_elements() - sage: prec.precision_lattice() + sage: prec.precision_lattice() # needs sage.geometry.polyhedron [ 3125 48825000] [ 0 48828125] @@ -3025,44 +3053,42 @@ def ZpER(p, prec=None, halt=None, secure=False, *args, **kwds): Relaxed `p`-adic rings are created by the constructor :func:`ZpER`:: - sage: R = ZpER(5, print_mode="digits") - sage: R + sage: R = ZpER(5, print_mode="digits"); R # needs sage.libs.flint 5-adic Ring handled with relaxed arithmetics The precision is not capped in `R`:: - sage: R.precision_cap() + sage: R.precision_cap() # needs sage.libs.flint +Infinity However, a default precision is fixed. This is the precision at which the elements will be printed:: - sage: R.default_prec() + sage: R.default_prec() # needs sage.libs.flint 20 A default halting precision is also set. It is the default absolute precision at which the elements will be compared. By default, it is twice the default precision:: - sage: R.halting_prec() + sage: R.halting_prec() # needs sage.libs.flint 40 However, both the default precision and the halting precision can be customized at the creation of the parent as follows:: - sage: S = ZpER(5, prec=10, halt=100) - sage: S.default_prec() + sage: S = ZpER(5, prec=10, halt=100) # needs sage.libs.flint + sage: S.default_prec() # needs sage.libs.flint 10 - sage: S.halting_prec() + sage: S.halting_prec() # needs sage.libs.flint 100 One creates elements as usual:: - sage: a = R(17/42) - sage: a + sage: a = R(17/42); a # needs sage.libs.flint ...00244200244200244201 - sage: R.random_element() # random + sage: R.random_element() # random # needs sage.libs.flint ...21013213133412431402 Here we notice that 20 digits (that is the default precision) are printed. @@ -3071,22 +3097,23 @@ def ZpER(p, prec=None, halt=None, secure=False, *args, **kwds): This feature is reflected by the fact that, when we ask for the precision of `a`, the software answers `+\infty`:: - sage: a.precision_absolute() + sage: a.precision_absolute() # needs sage.libs.flint +Infinity Asking for more digits is achieved by the methods :meth:`at_precision_absolute` and :meth:`at_precision_relative`:: - sage: a.at_precision_absolute(30) + sage: a.at_precision_absolute(30) # needs sage.libs.flint ...?244200244200244200244200244201 As a shortcut, one can use the bracket operator:: - sage: a[:30] + sage: a[:30] # needs sage.libs.flint ...?244200244200244200244200244201 Of course, standard operations are supported:: + sage: # needs sage.libs.flint sage: b = R(42/17) sage: a + b ...03232011214322140002 @@ -3102,7 +3129,7 @@ def ZpER(p, prec=None, halt=None, secure=False, *args, **kwds): We observe again that only 20 digits are printed but, as before, more digits are available on demand:: - sage: sqrt(a)[:30] + sage: sqrt(a)[:30] # needs sage.libs.flint ...?142443342120042333114021142101 .. RUBRIC:: Equality tests @@ -3114,12 +3141,12 @@ def ZpER(p, prec=None, halt=None, secure=False, *args, **kwds): default), elements are compared at the current precision, or at the default halting precision if it is higher:: - sage: a == b + sage: a == b # needs sage.libs.flint False - sage: a == sqrt(a)^2 + sage: a == sqrt(a)^2 # needs sage.libs.flint True - sage: a == sqrt(a)^2 + 5^50 + sage: a == sqrt(a)^2 + 5^50 # needs sage.libs.flint True In the above example, the halting precision is `40`; it is the @@ -3129,6 +3156,7 @@ def ZpER(p, prec=None, halt=None, secure=False, *args, **kwds): Hence comparing two elements at different times can produce different results:: + sage: # needs sage.libs.flint sage: aa = sqrt(a)^2 + 5^50 sage: a == aa True @@ -3145,6 +3173,7 @@ def ZpER(p, prec=None, halt=None, secure=False, *args, **kwds): Indeed, in this case, if the equality cannot be decided, an error is raised:: + sage: # needs sage.libs.flint sage: S = ZpER(5, secure=True) sage: u = S.random_element() sage: uu = u + 5^50 @@ -3153,7 +3182,7 @@ def ZpER(p, prec=None, halt=None, secure=False, *args, **kwds): ... PrecisionError: unable to decide equality; try to bound precision - sage: u[:60] == uu + sage: u[:60] == uu # needs sage.libs.flint False .. RUBRIC:: Self-referent numbers @@ -3162,20 +3191,19 @@ def ZpER(p, prec=None, halt=None, secure=False, *args, **kwds): create (in some cases) self-referent numbers. Here is an example. We first declare a new variable as follows:: - sage: x = R.unknown() - sage: x + sage: x = R.unknown(); x # needs sage.libs.flint ...?.0 We then use the method :meth:`set` to define `x` by writing down an equation it satisfies:: - sage: x.set(1 + 5*x^2) + sage: x.set(1 + 5*x^2) # needs sage.libs.flint True The variable `x` now contains the unique solution of the equation `x = 1 + 5 x^2`:: - sage: x + sage: x # needs sage.libs.flint ...04222412141121000211 This works because the `n`-th digit of the right hand size of the @@ -3184,6 +3212,7 @@ def ZpER(p, prec=None, halt=None, secure=False, *args, **kwds): As a comparison, the following does not work:: + sage: # needs sage.libs.flint sage: y = R.unknown() sage: y.set(1 + 3*y^2) True @@ -3196,17 +3225,16 @@ def ZpER(p, prec=None, halt=None, secure=False, *args, **kwds): Self-referent definitions also work with systems of equations:: + sage: # needs sage.libs.flint sage: u = R.unknown() sage: v = R.unknown() sage: w = R.unknown() - sage: u.set(1 + 2*v + 3*w^2 + 5*u*v*w) True sage: v.set(2 + 4*w + sqrt(1 + 5*u + 10*v + 15*w)) True sage: w.set(3 + 25*(u*v + v*w + u*w)) True - sage: u ...31203130103131131433 sage: v @@ -3251,7 +3279,7 @@ def create_key_and_extra_args(self, base, modulus, prec=None, print_mode=None, sage: R = Zp(5,3) sage: S. = ZZ[] - sage: pAdicExtension.create_key_and_extra_args(R, x^4-15,names='w') + sage: pAdicExtension.create_key_and_extra_args(R, x^4-15,names='w') # needs sage.libs.ntl (('e', 5-adic Ring with capped relative precision 3, x^4 - 15, @@ -3268,6 +3296,7 @@ def create_key_and_extra_args(self, base, modulus, prec=None, print_mode=None, 'NTL'), {'approx_modulus': (1 + O(5^3))*x^4 + O(5^4)*x^3 + O(5^4)*x^2 + O(5^4)*x + 2*5 + 4*5^2 + 4*5^3 + O(5^4)}) + sage: # needs sage.libs.ntl sage: A = Qp(3,5) sage: Po. = A[] sage: f = Po([3,0,-1]) @@ -3277,6 +3306,7 @@ def create_key_and_extra_args(self, base, modulus, prec=None, print_mode=None, sage: K.defining_polynomial() == f/f.leading_coefficient() True + sage: # needs sage.libs.ntl sage: g = Po([6,3,2]) sage: H. = A.ext(g) sage: 2*b^2+3*b+6 @@ -3395,8 +3425,8 @@ def create_object(self, version, key, approx_modulus=None, shift_seed=None): TESTS:: sage: R = Zp(5,3) - sage: S. = R[] - sage: pAdicExtension.create_object(version = (6,4,2), key = ('e', R, x^4 - 15, x^4 - 15, ('w', None, None, 'w'), 12, None, 'series', True, '|', (),-1,-1,-1,'NTL'), shift_seed = S(3 + O(5^3))) + sage: S. = R[] # needs sage.libs.ntl + sage: pAdicExtension.create_object(version = (6,4,2), key = ('e', R, x^4 - 15, x^4 - 15, ('w', None, None, 'w'), 12, None, 'series', True, '|', (),-1,-1,-1,'NTL'), shift_seed = S(3 + O(5^3))) # needs sage.libs.ntl 5-adic Eisenstein Extension Ring in w defined by x^4 - 15 """ polytype = key[0] @@ -3454,9 +3484,9 @@ def split(poly, prec): EXAMPLES:: sage: k = Qp(13) - sage: x = polygen(k) - sage: f = x^2 + 1 - sage: sage.rings.padics.factory.split(f, 10) + sage: x = polygen(k) # needs sage.libs.ntl + sage: f = x^2 + 1 # needs sage.libs.ntl + sage: sage.rings.padics.factory.split(f, 10) # needs sage.libs.ntl sage.rings.real_double Traceback (most recent call last): ... NotImplementedError: Extensions by general polynomials not yet supported. @@ -3467,9 +3497,9 @@ def split(poly, prec): This checks that :trac:`6186` is still fixed:: sage: k = Qp(13) - sage: x = polygen(k) - sage: f = x^2+1 - sage: L. = k.extension(f) + sage: x = polygen(k) # needs sage.libs.ntl + sage: f = x^2+1 # needs sage.libs.ntl + sage: L. = k.extension(f) # needs sage.libs.ntl Traceback (most recent call last): ... NotImplementedError: Extensions by general polynomials not yet supported. Please use an unramified or Eisenstein polynomial. @@ -3484,10 +3514,10 @@ def truncate_to_prec(poly, R, absprec): EXAMPLES:: sage: R = Zp(5) - sage: S. = R[] + sage: S. = R[] # needs sage.libs.ntl sage: from sage.rings.padics.factory import truncate_to_prec - sage: f = x^4 + (3+O(5^6))*x^3 + O(5^4) - sage: truncate_to_prec(f, R, 5) + sage: f = x^4 + (3+O(5^6))*x^3 + O(5^4) # needs sage.libs.ntl + sage: truncate_to_prec(f, R, 5) # needs sage.libs.ntl (1 + O(5^5))*x^4 + (3 + O(5^5))*x^3 + O(5^5)*x^2 + O(5^5)*x + O(5^4) """ return R[poly.variable_name()]([R(a, absprec=absprec) for a in poly.list()]) # Is this quite right? We don't want flat necessarily... @@ -3518,6 +3548,7 @@ def is_eisenstein(poly): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R = Zp(5) sage: S. = R[] sage: from sage.rings.padics.factory import is_eisenstein @@ -3546,6 +3577,7 @@ def is_unramified(poly): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R = Zp(5) sage: S. = R[] sage: from sage.rings.padics.factory import is_unramified diff --git a/src/sage/rings/padics/generic_nodes.py b/src/sage/rings/padics/generic_nodes.py index b6b514d4005..3a135548a32 100644 --- a/src/sage/rings/padics/generic_nodes.py +++ b/src/sage/rings/padics/generic_nodes.py @@ -523,8 +523,8 @@ def label(self): with matrices:: sage: R = ZpLC(5, label='matrices') - sage: M = random_matrix(R, 4, 4) - sage: d = M.determinant() + sage: M = random_matrix(R, 4, 4) # needs sage.geometry.polyhedron + sage: d = M.determinant() # needs sage.geometry.polyhedron Now, if we want to do another unrelated computation, we can use a different label:: @@ -612,7 +612,7 @@ def convert_multiple(self, *elts): sage: x + y 2 + O(2^11) - sage: R.precision().diffused_digits([x,y]) + sage: R.precision().diffused_digits([x,y]) # needs sage.geometry.polyhedron 6 As a consequence, if we convert ``x`` and ``y`` separately, we @@ -627,17 +627,17 @@ def convert_multiple(self, *elts): sage: x2 + y2 2 + O(2^5) - sage: R2.precision().diffused_digits([x2,y2]) + sage: R2.precision().diffused_digits([x2,y2]) # needs sage.geometry.polyhedron 0 On the other hand, this issue disappears when we use multiple conversion:: - sage: x2,y2 = R2.convert_multiple(x,y) - sage: x2 + y2 + sage: x2,y2 = R2.convert_multiple(x,y) # needs sage.geometry.polyhedron + sage: x2 + y2 # needs sage.rings.padics 2 + O(2^11) - sage: R2.precision().diffused_digits([x2,y2]) + sage: R2.precision().diffused_digits([x2,y2]) # needs sage.geometry.polyhedron 6 """ p = self.prime() @@ -712,8 +712,8 @@ class pAdicRelaxedGeneric(pAdicGeneric): TESTS:: - sage: R = ZpER(17) # indirect doctest - sage: R._prec_type() + sage: R = ZpER(17) # indirect doctest # needs sage.libs.flint + sage: R._prec_type() # needs sage.libs.flint 'relaxed' """ def _get_element_class(self, name=None): @@ -727,16 +727,14 @@ def _get_element_class(self, name=None): TESTS:: + sage: # needs sage.libs.flint sage: R = ZpER(5) sage: R._get_element_class() - sage: R._get_element_class("add") - sage: R._get_element_class("unknown") - sage: R._get_element_class("foobar") Traceback (most recent call last): ... @@ -754,7 +752,7 @@ def _prec_type(self): EXAMPLES:: - sage: ZpER(5)._prec_type() + sage: ZpER(5)._prec_type() # needs sage.libs.flint 'relaxed' """ return 'relaxed' @@ -768,8 +766,8 @@ def is_relaxed(self): sage: R = Zp(5) sage: R.is_relaxed() False - sage: S = ZpER(5) - sage: S.is_relaxed() + sage: S = ZpER(5) # needs sage.libs.flint + sage: S.is_relaxed() # needs sage.libs.flint True """ return True @@ -783,6 +781,7 @@ def is_secure(self): EXAMPLES:: + sage: # needs sage.libs.flint sage: R = ZpER(5) sage: R.is_secure() False @@ -791,6 +790,7 @@ def is_secure(self): sage: x == y True + sage: # needs sage.libs.flint sage: S = ZpER(5, secure=True) sage: S.is_secure() True @@ -813,12 +813,12 @@ def default_prec(self): EXAMPLES:: + sage: # needs sage.libs.flint sage: R = ZpER(5, print_mode="digits") sage: R.default_prec() 20 sage: R(1/17) ...34024323104201213403 - sage: S = ZpER(5, prec=10, print_mode="digits") sage: S.default_prec() 10 @@ -838,8 +838,8 @@ def halting_prec(self): EXAMPLES:: - sage: R = ZpER(5, print_mode="digits") - sage: R.halting_prec() + sage: R = ZpER(5, print_mode="digits") # needs sage.libs.flint + sage: R.halting_prec() # needs sage.libs.flint 40 """ return self._halting_prec @@ -851,8 +851,8 @@ def precision_cap(self): EXAMPLES:: - sage: R = ZpER(5) - sage: R.precision_cap() + sage: R = ZpER(5) # needs sage.libs.flint + sage: R.precision_cap() # needs sage.libs.flint +Infinity """ return infinity @@ -863,6 +863,7 @@ def _coerce_map_from_(self, R): EXAMPLES:: + sage: # needs sage.libs.flint sage: R = ZpER(5) sage: K = R.fraction_field() sage: K.has_coerce_map_from(R) # indirect doctest @@ -886,23 +887,20 @@ def _element_constructor_(self, x, prec=None): EXAMPLES:: + sage: # needs sage.libs.flint sage: R = ZpER(7, prec=5) - - sage: a = R(17/71) - sage: a + sage: a = R(17/71); a 3 + 3*7^2 + 4*7^3 + 4*7^4 + ... sage: a.precision_absolute() +Infinity - - sage: b = R(17/71, prec=10) - sage: b + sage: b = R(17/71, prec=10); b 3 + 3*7^2 + 4*7^3 + 4*7^4 + 2*7^5 + 7^6 + 5*7^8 + 5*7^9 + O(7^10) sage: b.precision_absolute() 10 TESTS:: - sage: R(1/7) + sage: R(1/7) # needs sage.libs.flint Traceback (most recent call last): ... ValueError: negative valuation @@ -913,7 +911,7 @@ def _element_constructor_(self, x, prec=None): sage: c = S(7^5) sage: c 7^5 + O(7^25) - sage: R(c) + sage: R(c) # needs sage.libs.flint 7^5 + O(7^25) """ parent = x.parent() @@ -963,10 +961,10 @@ def an_element(self, unbounded=False): EXAMPLES:: - sage: R = ZpER(7, prec=5) - sage: R.an_element() + sage: R = ZpER(7, prec=5) # needs sage.libs.flint + sage: R.an_element() # needs sage.libs.flint 7 + O(7^5) - sage: R.an_element(unbounded=True) + sage: R.an_element(unbounded=True) # needs sage.libs.flint 7 + ... """ p = self(self.prime()) @@ -982,8 +980,8 @@ def some_elements(self, unbounded=False): EXAMPLES:: - sage: R = ZpER(7, prec=5) - sage: R.some_elements() + sage: R = ZpER(7, prec=5) # needs sage.libs.flint + sage: R.some_elements() # needs sage.libs.flint [O(7^5), 1 + O(7^5), 7 + O(7^5), @@ -991,7 +989,7 @@ def some_elements(self, unbounded=False): 1 + 5*7 + 3*7^2 + 6*7^3 + O(7^5), 7 + 6*7^2 + 6*7^3 + 6*7^4 + O(7^5)] - sage: R.some_elements(unbounded=True) + sage: R.some_elements(unbounded=True) # needs sage.libs.flint [0, 1 + ..., 7 + ..., @@ -1032,16 +1030,16 @@ def unknown(self, start_val=0, digits=None): EXAMPLES: - sage: R = ZpER(5, prec=10) + sage: R = ZpER(5, prec=10) # needs sage.libs.flint We declare a self-referent number:: - sage: a = R.unknown() + sage: a = R.unknown() # needs sage.libs.flint So far, we do not know anything on `a` (except that it has nonnegative valuation):: - sage: a + sage: a # needs sage.libs.flint O(5^0) We can now use the method :meth:`sage.rings.padics.relaxed_template.RelaxedElement_unknown.set` @@ -1049,17 +1047,18 @@ def unknown(self, start_val=0, digits=None): agree with the digits of `1 + 5 a`. Note that the factor `5` shifts the digits; the `n`-th digit of `a` is then defined by the previous ones:: - sage: a.set(1 + 5*a) + sage: a.set(1 + 5*a) # needs sage.libs.flint True After this, `a` contains the solution of the equation `a = 1 + 5 a`, that is `a = -1/4`:: - sage: a + sage: a # needs sage.libs.flint 1 + 5 + 5^2 + 5^3 + 5^4 + 5^5 + 5^6 + 5^7 + 5^8 + 5^9 + ... Here is another example with an equation of degree `2`:: + sage: # needs sage.libs.flint sage: b = R.unknown() sage: b.set(1 - 5*b^2) True @@ -1070,17 +1069,16 @@ def unknown(self, start_val=0, digits=None): Cross self-referent definitions are also allowed:: + sage: # needs sage.libs.flint sage: u = R.unknown() sage: v = R.unknown() sage: w = R.unknown() - sage: u.set(1 + 2*v + 3*w^2 + 5*u*v*w) True sage: v.set(2 + 4*w + sqrt(1 + 5*u + 10*v + 15*w)) True sage: w.set(3 + 25*(u*v + v*w + u*w)) True - sage: u 3 + 3*5 + 4*5^2 + 5^3 + 3*5^4 + 5^5 + 5^6 + 3*5^7 + 5^8 + 3*5^9 + ... sage: v @@ -1090,6 +1088,7 @@ def unknown(self, start_val=0, digits=None): TESTS:: + sage: # needs sage.libs.flint sage: a = R.unknown() sage: a.set(1 + 3*a) True @@ -1121,23 +1120,23 @@ def random_element(self, integral=False, prec=None): EXAMPLES:: - sage: R = ZpER(5, prec=10) + sage: R = ZpER(5, prec=10) # needs sage.libs.flint By default, this method returns a unbounded element:: - sage: a = R.random_element() - sage: a # random + sage: a = R.random_element() # needs sage.libs.flint + sage: a # random # needs sage.libs.flint 4 + 3*5 + 3*5^2 + 5^3 + 3*5^4 + 2*5^5 + 2*5^6 + 5^7 + 5^9 + ... - sage: a.precision_absolute() + sage: a.precision_absolute() # needs sage.libs.flint +Infinity The precision can be bounded by passing in a precision:: - sage: b = R.random_element(prec=15) - sage: b # random + sage: b = R.random_element(prec=15) # needs sage.libs.flint + sage: b # random # needs sage.libs.flint 2 + 3*5^2 + 5^3 + 3*5^4 + 5^5 + 3*5^6 + 3*5^8 + 3*5^9 + 4*5^10 + 5^11 + 4*5^12 + 5^13 + 2*5^14 + O(5^15) - sage: b.precision_absolute() + sage: b.precision_absolute() # needs sage.libs.flint 15 """ if integral or (not self.is_field()): @@ -1151,8 +1150,8 @@ def teichmuller(self, x): EXAMPLES:: - sage: R = ZpER(5, print_mode="digits") - sage: R.teichmuller(2) + sage: R = ZpER(5, print_mode="digits") # needs sage.libs.flint + sage: R.teichmuller(2) # needs sage.libs.flint ...40423140223032431212 """ x = self(x) @@ -1167,8 +1166,8 @@ def teichmuller_system(self): EXAMPLES:: - sage: R = ZpER(7, print_mode="digits") - sage: R.teichmuller_system() + sage: R = ZpER(7, print_mode="digits") # needs sage.libs.flint + sage: R.teichmuller_system() # needs sage.libs.flint [...00000000000000000001, ...16412125443426203642, ...16412125443426203643, @@ -1235,19 +1234,21 @@ def _xgcd_univariate_polynomial(self, f, g): EXAMPLES:: - sage: R. = Zp(3,3)[] - sage: f = x + 1 - sage: f.xgcd(f^2) + sage: R. = Zp(3,3)[] # needs sage.libs.ntl + sage: f = x + 1 # needs sage.libs.ntl + sage: f.xgcd(f^2) # needs sage.libs.ntl ((1 + O(3^3))*x + 1 + O(3^3), 1 + O(3^3), 0) We check that :trac:`13439` has been fixed:: + sage: # needs sage.libs.ntl sage: R. = Zp(3,3)[] sage: f = 3*x + 7 sage: g = 5*x + 9 sage: f.xgcd(f*g) ((3 + O(3^4))*x + 1 + 2*3 + O(3^3), 1 + O(3^3), 0) + sage: # needs sage.libs.ntl sage: R. = Zp(3)[] sage: f = 357555295953*x + 257392844 sage: g = 225227399*x - 511940255230575 @@ -1260,6 +1261,7 @@ def _xgcd_univariate_polynomial(self, f, g): We check low precision computations:: + sage: # needs sage.libs.ntl sage: R. = Zp(3,1)[] sage: h = 3*x + 7 sage: i = 4*x + 9 @@ -1296,6 +1298,7 @@ def _gcd_univariate_polynomial(self, f, g): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Zq(27) sage: K. = R[] sage: h = 3*x + a @@ -1387,8 +1390,8 @@ def construction(self, forbid_frac_field=False): The `secure` attribute for relaxed type is included in the functor:: - sage: R = ZpER(5, secure=True) - sage: R.construction() + sage: R = ZpER(5, secure=True) # needs sage.libs.flint + sage: R.construction() # needs sage.libs.flint (Completion[5, prec=(20, 40, True)], Integer Ring) """ from sage.categories.pushout import CompletionFunctor @@ -1565,8 +1568,8 @@ def construction(self, forbid_frac_field=False): The `secure` attribute for relaxed type is included in the functor:: - sage: K = QpER(5, secure=True) - sage: K.construction(forbid_frac_field=True) + sage: K = QpER(5, secure=True) # needs sage.libs.flint + sage: K.construction(forbid_frac_field=True) # needs sage.libs.flint (Completion[5, prec=(20, 40, True)], Rational Field) """ from sage.categories.pushout import FractionField, CompletionFunctor diff --git a/src/sage/rings/padics/lattice_precision.py b/src/sage/rings/padics/lattice_precision.py index 9c76ff88362..51a510a4360 100644 --- a/src/sage/rings/padics/lattice_precision.py +++ b/src/sage/rings/padics/lattice_precision.py @@ -847,7 +847,7 @@ def _new_element(self, *args, **kwargs): sage: R = ZpLC(2) sage: x = R.random_element() sage: y = R.random_element() - sage: z = x*y # indirect doctest + sage: z = x*y # indirect doctest """ pass @@ -897,19 +897,19 @@ def del_elements(self, threshold=None): sage: x = R(1, 10) sage: prec Precision lattice on 1 object (label: del_elements) - sage: prec.precision_lattice() + sage: prec.precision_lattice() # needs sage.geometry.polyhedron [1024] sage: del x sage: prec Precision lattice on 1 object (label: del_elements) - sage: prec.precision_lattice() + sage: prec.precision_lattice() # needs sage.geometry.polyhedron [1024] sage: prec.del_elements() sage: prec Precision lattice on 0 objects (label: del_elements) - sage: prec.precision_lattice() + sage: prec.precision_lattice() # needs sage.geometry.polyhedron [] """ pass @@ -963,12 +963,12 @@ def precision_lattice(self, elements=None): sage: x = R(1, 10); y = R(1, 5) sage: u = x + y sage: v = x - y - sage: prec.precision_lattice() + sage: prec.precision_lattice() # needs sage.geometry.polyhedron [ 1024 0 1024 1024] [ 0 32 32 1099511627744] [ 0 0 2097152 0] [ 0 0 0 1099511627776] - sage: prec.precision_lattice([u, v]) + sage: prec.precision_lattice([u, v]) # needs sage.geometry.polyhedron [ 32 2016] [ 0 2048] @@ -980,7 +980,7 @@ def precision_lattice(self, elements=None): sage: x = R(1, 10); y = R(1, 5) sage: u = x + y sage: v = x - y - sage: prec.precision_lattice([x,y,u,v]) + sage: prec.precision_lattice([x,y,u,v]) # needs sage.geometry.polyhedron Traceback (most recent call last): ... PrecisionError: the differential is not surjective @@ -1012,9 +1012,9 @@ def diffused_digits(self, elements=None): sage: u = x + y sage: v = x - y - sage: prec.diffused_digits([x, y]) + sage: prec.diffused_digits([x, y]) # needs sage.geometry.polyhedron 0 - sage: prec.diffused_digits([u, v]) + sage: prec.diffused_digits([u, v]) # needs sage.geometry.polyhedron 6 The elements `u` and `v` are known at absolute precision `O(2^5)`. @@ -1024,14 +1024,14 @@ def diffused_digits(self, elements=None): Here is another example with matrices:: - sage: M = matrix(R, 2, 2, [R(3, 5), R(7, 5), R(1, 5), R(11, 1)]) - sage: N = M^10 + sage: M = matrix(R, 2, 2, [R(3, 5), R(7, 5), R(1, 5), R(11, 1)]) # needs sage.modules + sage: N = M^10 # needs sage.modules The next syntax provides as easy way to select an interesting subset of variables (the selected subset consists of the four entries of the matrix ``N``):: - sage: prec.diffused_digits(N) + sage: prec.diffused_digits(N) # needs sage.geometry.polyhedron sage.modules 17 Note that, in some cases, the number of diffused digits can be @@ -1041,7 +1041,7 @@ def diffused_digits(self, elements=None): sage: prec = R.precision() sage: x = R(1, 10) sage: y = x - sage: prec.diffused_digits([x, y]) + sage: prec.diffused_digits([x, y]) # needs sage.geometry.polyhedron +Infinity """ try: @@ -1081,6 +1081,7 @@ def tracked_elements(self, values=True, dead=True): [WeakProxy#..., WeakProxy#...] + sage: # needs sage.rings.padics sage: u = x + y sage: v = x - y sage: prec.tracked_elements() @@ -1091,7 +1092,6 @@ def tracked_elements(self, values=True, dead=True): WeakProxy#..., WeakProxy#..., WeakProxy#...] - sage: del x; del y sage: prec.tracked_elements() [None, None, 2 + O(2^5), O(2^5), None] @@ -1378,8 +1378,8 @@ def history(self, compact=True, separate_reduce=False, timings=True, output_type sage: R = ZpLC(3) sage: prec = R.precision() sage: prec.history_enable() - sage: M = random_matrix(R, 5) - sage: d = M.determinant() + sage: M = random_matrix(R, 5) # needs sage.geometry.polyhedron + sage: d = M.determinant() # needs sage.geometry.polyhedron sage: print(prec.history()) # somewhat random --- 0.004212s oooooooooooooooooooooooooooooooooooo @@ -1503,8 +1503,8 @@ def timings(self, action=None): sage: R = ZpLC(2, label='timings') sage: prec = R.precision() sage: prec.history_enable() - sage: M = random_matrix(R, 5, 5) - sage: N = M^10 + sage: M = random_matrix(R, 5, 5) # needs sage.geometry.polyhedron + sage: N = M^10 # needs sage.geometry.polyhedron sage: prec.timings() # somewhat random {'add': 1.0530245304107666, 'del': 0.24358701705932617, @@ -1808,19 +1808,19 @@ def del_elements(self, threshold=None): sage: x = R(1, 10) sage: prec Precision lattice on 1 object (label: delelts) - sage: prec.precision_lattice() + sage: prec.precision_lattice() # needs sage.geometry.polyhedron [1024] sage: del x sage: prec Precision lattice on 1 object (label: delelts) - sage: prec.precision_lattice() + sage: prec.precision_lattice() # needs sage.geometry.polyhedron [1024] sage: prec.del_elements() sage: prec Precision lattice on 0 objects (label: delelts) - sage: prec.precision_lattice() + sage: prec.precision_lattice() # needs sage.geometry.polyhedron [] """ n = len(self._elements) @@ -2076,27 +2076,27 @@ def precision_lattice(self, elements=None): sage: x = R(1, 10); y = R(1, 5) sage: u = x + y sage: v = x - y - sage: prec.precision_lattice() + sage: prec.precision_lattice() # needs sage.geometry.polyhedron [ 1024 0 1024 1024] [ 0 32 32 1099511627744] [ 0 0 2097152 0] [ 0 0 0 1099511627776] - sage: prec.precision_lattice([u, v]) + sage: prec.precision_lattice([u, v]) # needs sage.geometry.polyhedron [ 32 2016] [ 0 2048] Here is another example with matrices:: - sage: M = matrix(R, 2, 2, [R(3, 5), R(7, 5), R(1, 5), R(11, 1)]) - sage: N = M^10 - sage: prec.precision_lattice() + sage: M = matrix(R, 2, 2, [R(3, 5), R(7, 5), R(1, 5), R(11, 1)]) # needs sage.modules + sage: N = M^10 # needs sage.modules + sage: prec.precision_lattice() # needs sage.geometry.polyhedron sage.modules 23 x 23 dense matrix over Integer Ring (use the '.str()' method to see the entries) The next syntax provides as easy way to select an interesting subset of variables (the selected subset consists of the four entries of the matrix ``N``):: - sage: prec.precision_lattice(N) + sage: prec.precision_lattice(N) # needs sage.modules [ 2048 512 28160 230400] [ 0 2048 14336 258048] [ 0 0 65536 65536] @@ -2104,7 +2104,7 @@ def precision_lattice(self, elements=None): We can give a list of matrices as well:: - sage: prec.precision_lattice([M, N]) + sage: prec.precision_lattice([M, N]) # needs sage.modules [ 32 0 0 0 226115584 96788480 52174848 82804736] [ 0 32 0 0 52174848 121765888 11829248 28516352] [ 0 0 32 0 96788480 42762240 121765888 199614464] @@ -2408,19 +2408,19 @@ def del_elements(self, threshold=None): sage: x = R(1, 10) sage: prec Precision module on 1 object (label: delelts) - sage: prec.precision_lattice() + sage: prec.precision_lattice() # needs sage.geometry.polyhedron [1024] sage: del x sage: prec Precision module on 1 object (label: delelts) - sage: prec.precision_lattice() + sage: prec.precision_lattice() # needs sage.geometry.polyhedron [1024] sage: prec.del_elements() sage: prec Precision module on 0 objects (label: delelts) - sage: prec.precision_lattice() + sage: prec.precision_lattice() # needs sage.geometry.polyhedron [] """ # We mark new collected elements for deletion @@ -2676,34 +2676,34 @@ def precision_lattice(self, elements=None): sage: R = ZpLF(2, label='preclattice') sage: prec = R.precision() sage: x = R(1, 10); y = R(1, 5) - sage: prec.precision_lattice() + sage: prec.precision_lattice() # needs sage.geometry.polyhedron [1024 0] [ 0 32] sage: u = x + y sage: v = x - y - sage: prec.precision_lattice([u, v]) + sage: prec.precision_lattice([u, v]) # needs sage.geometry.polyhedron [ 32 2016] [ 0 2048] If the precision module does not project to a lattice, an error is raised. :: - sage: prec.precision_lattice([x, y, u, v]) + sage: prec.precision_lattice([x, y, u, v]) # needs sage.geometry.polyhedron Traceback (most recent call last): ... PrecisionError: the differential is not surjective Here is another example with matrices:: - sage: M = matrix(R, 2, 2, [R(3, 5), R(7, 5), R(1, 5), R(11, 1)]) - sage: N = M^10 + sage: M = matrix(R, 2, 2, [R(3, 5), R(7, 5), R(1, 5), R(11, 1)]) # needs sage.modules + sage: N = M^10 # needs sage.modules The next syntax provides as easy way to select an interesting subset of variables (the selected subset consists of the four entries of the matrix ``N``):: - sage: prec.precision_lattice(N) + sage: prec.precision_lattice(N) # needs sage.geometry.polyhedron sage.modules [ 2048 512 28160 230400] [ 0 2048 14336 258048] [ 0 0 65536 65536] @@ -2852,7 +2852,7 @@ def __repr__(self): sage: from sage.rings.padics.lattice_precision import pAdicLatticeElementWeakProxy sage: R = ZpLF(2, label='proxy_repr') sage: p = R(2) - sage: R.precision()._elements # indirect doctest + sage: R.precision()._elements # indirect doctest [WeakProxy#...] """ @@ -2869,8 +2869,8 @@ def list_of_padics(elements): sage: from sage.rings.padics.lattice_precision import list_of_padics sage: R = ZpLC(2) - sage: M = random_matrix(R, 2, 2) - sage: list_of_padics(M) + sage: M = random_matrix(R, 2, 2) # needs sage.geometry.polyhedron + sage: list_of_padics(M) # needs sage.geometry.polyhedron [WeakProxy#..., WeakProxy#..., WeakProxy#..., diff --git a/src/sage/rings/padics/local_generic.py b/src/sage/rings/padics/local_generic.py index 5726055d2be..a88d74f605f 100644 --- a/src/sage/rings/padics/local_generic.py +++ b/src/sage/rings/padics/local_generic.py @@ -36,15 +36,15 @@ def __init__(self, base, prec, names, element_class, category=None): EXAMPLES:: - sage: R = Zp(5) #indirect doctest + sage: R = Zp(5) # indirect doctest sage: R.precision_cap() 20 In :trac:`14084`, the category framework has been implemented for p-adic rings:: - sage: TestSuite(R).run() + sage: TestSuite(R).run() # needs sage.geometry.polyhedron sage: K = Qp(7) - sage: TestSuite(K).run() + sage: TestSuite(K).run() # needs sage.geometry.polyhedron TESTS:: @@ -228,7 +228,7 @@ def _latex_(self): EXAMPLES:: - sage: latex(Zq(27,names='a')) #indirect doctest + sage: latex(Zq(27,names='a')) # indirect doctest # needs sage.libs.ntl \Bold{Z}_{3^{3}} """ return self._repr_(do_latex=True) @@ -264,18 +264,18 @@ def change(self, **kwds): The following arguments have special behavior: - ``prec`` -- integer. If the precision is increased on an extension ring, - the precision on the base is increased as necessary (respecting ramification). - If the precision is decreased, the precision of the base is unchanged. + the precision on the base is increased as necessary (respecting ramification). + If the precision is decreased, the precision of the base is unchanged. - ``field`` -- bool. If ``True``, switch to a tower of fields via the fraction field. - If False, switch to a tower of rings of integers. + If False, switch to a tower of rings of integers. - ``q`` -- prime power. Replace the initial unramified extension of `\QQ_p` or `\ZZ_p` - with an unramified extension of residue cardinality `q`. - If the initial extension is ramified, add in an unramified extension. + with an unramified extension of residue cardinality `q`. + If the initial extension is ramified, add in an unramified extension. - ``base`` -- ring or field. Use a specific base ring instead of recursively - calling :meth:`change` down the tower. + calling :meth:`change` down the tower. See the :mod:`constructors ` for more details on the meaning of these arguments. @@ -310,6 +310,7 @@ def change(self, **kwds): Changing print mode to 'digits' works for Eisenstein extensions:: + sage: # needs sage.libs.ntl sage: S. = ZZ[] sage: W. = Zp(3).extension(x^4 + 9*x^2 + 3*x - 3) sage: W.print_mode() @@ -319,6 +320,7 @@ def change(self, **kwds): You can change extensions:: + sage: # needs sage.libs.flint sage: K. = QqFP(125, prec=4) sage: K.change(q=64) 2-adic Unramified Extension Field in a defined by x^6 + x^4 + x^3 + x + 1 @@ -328,11 +330,12 @@ def change(self, **kwds): and variable names:: - sage: K.change(names='b') + sage: K.change(names='b') # needs sage.libs.flint 5-adic Unramified Extension Field in b defined by x^3 + 3*x + 3 and precision:: + sage: # needs sage.libs.flint sage: Kup = K.change(prec=8); Kup 5-adic Unramified Extension Field in a defined by x^3 + 3*x + 3 sage: Kup.precision_cap() @@ -342,6 +345,7 @@ def change(self, **kwds): If you decrease the precision, the precision of the base stays the same:: + sage: # needs sage.libs.flint sage: Kdown = K.change(prec=2); Kdown 5-adic Unramified Extension Field in a defined by x^3 + 3*x + 3 sage: Kdown.precision_cap() @@ -351,6 +355,7 @@ def change(self, **kwds): Changing the prime works for extensions:: + sage: # needs sage.libs.ntl sage: x = polygen(ZZ) sage: R. = Zp(5).extension(x^2 + 2) sage: S = R.change(p=7) @@ -364,6 +369,7 @@ def change(self, **kwds): :: + sage: # needs sage.libs.ntl sage: R. = Zq(5^3) sage: S = R.change(prec=50) sage: S.defining_polynomial(exact=True) @@ -382,6 +388,7 @@ def change(self, **kwds): The `secure` attribute for relaxed type is copied:: + sage: # needs sage.libs.flint sage: R = ZpER(5, secure=True); R 5-adic Ring handled with relaxed arithmetics sage: K = R.change(field=True); K @@ -391,6 +398,7 @@ def change(self, **kwds): The `check=False` option works for relaxed type:: + sage: # needs sage.libs.flint sage: R = ZpER(5) ; R 5-adic Ring handled with relaxed arithmetics sage: K = R.change(field=True, check=False) ; K @@ -708,12 +716,13 @@ def absolute_degree(self): EXAMPLES:: - sage: K. = Qq(3^5) - sage: K.absolute_degree() + sage: K. = Qq(3^5) # needs sage.libs.ntl + sage: K.absolute_degree() # needs sage.libs.ntl 5 - sage: L. = Qp(3).extension(x^2 - 3) - sage: L.absolute_degree() + sage: R. = QQ[] + sage: L. = Qp(3).extension(x^2 - 3) # needs sage.libs.ntl + sage: L.absolute_degree() # needs sage.libs.ntl 2 """ return self.absolute_e() * self.absolute_f() @@ -724,12 +733,13 @@ def relative_degree(self): EXAMPLES:: - sage: K. = Qq(3^5) - sage: K.relative_degree() + sage: K. = Qq(3^5) # needs sage.libs.ntl + sage: K.relative_degree() # needs sage.libs.ntl 5 - sage: L. = Qp(3).extension(x^2 - 3) - sage: L.relative_degree() + sage: R. = QQ[] + sage: L. = Qp(3).extension(x^2 - 3) # needs sage.libs.ntl + sage: L.relative_degree() # needs sage.libs.ntl 2 """ return self.absolute_degree() // self.base_ring().absolute_degree() @@ -742,12 +752,13 @@ def degree(self): EXAMPLES:: - sage: K. = Qq(3^5) - sage: K.degree() + sage: K. = Qq(3^5) # needs sage.libs.ntl + sage: K.degree() # needs sage.libs.ntl 5 - sage: L. = Qp(3).extension(x^2 - 3) - sage: L.degree() + sage: R. = QQ[] + sage: L. = Qp(3).extension(x^2 - 3) # needs sage.libs.ntl + sage: L.degree() # needs sage.libs.ntl 2 """ if self.base_ring().absolute_degree() == 1: @@ -761,12 +772,13 @@ def absolute_e(self): EXAMPLES:: - sage: K. = Qq(3^5) - sage: K.absolute_e() + sage: K. = Qq(3^5) # needs sage.libs.ntl + sage: K.absolute_e() # needs sage.libs.ntl 1 - sage: L. = Qp(3).extension(x^2 - 3) - sage: L.absolute_e() + sage: R. = QQ[] + sage: L. = Qp(3).extension(x^2 - 3) # needs sage.libs.ntl + sage: L.absolute_e() # needs sage.libs.ntl 2 """ # Override this in subclasses (if appropriate) @@ -781,12 +793,13 @@ def absolute_ramification_index(self): EXAMPLES:: - sage: K. = Qq(3^5) - sage: K.absolute_ramification_index() + sage: K. = Qq(3^5) # needs sage.libs.ntl + sage: K.absolute_ramification_index() # needs sage.libs.ntl 1 - sage: L. = Qp(3).extension(x^2 - 3) - sage: L.absolute_ramification_index() + sage: R. = QQ[] + sage: L. = Qp(3).extension(x^2 - 3) # needs sage.libs.ntl + sage: L.absolute_ramification_index() # needs sage.libs.ntl 2 """ return self.absolute_e() @@ -797,12 +810,13 @@ def relative_e(self): EXAMPLES:: - sage: K. = Qq(3^5) - sage: K.relative_e() + sage: K. = Qq(3^5) # needs sage.libs.ntl + sage: K.relative_e() # needs sage.libs.ntl 1 - sage: L. = Qp(3).extension(x^2 - 3) - sage: L.relative_e() + sage: R. = QQ[] + sage: L. = Qp(3).extension(x^2 - 3) # needs sage.libs.ntl + sage: L.relative_e() # needs sage.libs.ntl 2 """ return self.absolute_e() // self.base_ring().absolute_e() @@ -813,12 +827,13 @@ def relative_ramification_index(self): EXAMPLES:: - sage: K. = Qq(3^5) - sage: K.relative_ramification_index() + sage: K. = Qq(3^5) # needs sage.libs.ntl + sage: K.relative_ramification_index() # needs sage.libs.ntl 1 - sage: L. = Qp(3).extension(x^2 - 3) - sage: L.relative_ramification_index() + sage: R. = QQ[] + sage: L. = Qp(3).extension(x^2 - 3) # needs sage.libs.ntl + sage: L.relative_ramification_index() # needs sage.libs.ntl 2 """ return self.relative_e() @@ -831,12 +846,13 @@ def e(self): EXAMPLES:: - sage: K. = Qq(3^5) - sage: K.e() + sage: K. = Qq(3^5) # needs sage.libs.ntl + sage: K.e() # needs sage.libs.ntl 1 - sage: L. = Qp(3).extension(x^2 - 3) - sage: L.e() + sage: R. = QQ[] + sage: L. = Qp(3).extension(x^2 - 3) # needs sage.libs.ntl + sage: L.e() # needs sage.libs.ntl 2 """ if self.base_ring().absolute_degree() == 1: @@ -852,12 +868,13 @@ def ramification_index(self): EXAMPLES:: - sage: K. = Qq(3^5) - sage: K.ramification_index() + sage: K. = Qq(3^5) # needs sage.libs.ntl + sage: K.ramification_index() # needs sage.libs.ntl 1 - sage: L. = Qp(3).extension(x^2 - 3) - sage: L.ramification_index() + sage: R. = QQ[] + sage: L. = Qp(3).extension(x^2 - 3) # needs sage.libs.ntl + sage: L.ramification_index() # needs sage.libs.ntl 2 """ return self.e() @@ -869,12 +886,13 @@ def absolute_f(self): EXAMPLES:: - sage: K. = Qq(3^5) - sage: K.absolute_f() + sage: K. = Qq(3^5) # needs sage.libs.ntl + sage: K.absolute_f() # needs sage.libs.ntl 5 - sage: L. = Qp(3).extension(x^2 - 3) - sage: L.absolute_f() + sage: R. = QQ[] + sage: L. = Qp(3).extension(x^2 - 3) # needs sage.libs.ntl + sage: L.absolute_f() # needs sage.libs.ntl 1 """ # Override this in subclasses (if appropriate) @@ -890,12 +908,13 @@ def absolute_inertia_degree(self): EXAMPLES:: - sage: K. = Qq(3^5) - sage: K.absolute_inertia_degree() + sage: K. = Qq(3^5) # needs sage.libs.ntl + sage: K.absolute_inertia_degree() # needs sage.libs.ntl 5 - sage: L. = Qp(3).extension(x^2 - 3) - sage: L.absolute_inertia_degree() + sage: R. = QQ[] + sage: L. = Qp(3).extension(x^2 - 3) # needs sage.libs.ntl + sage: L.absolute_inertia_degree() # needs sage.libs.ntl 1 """ return self.absolute_f() @@ -906,12 +925,13 @@ def relative_f(self): EXAMPLES:: - sage: K. = Qq(3^5) - sage: K.relative_f() + sage: K. = Qq(3^5) # needs sage.libs.ntl + sage: K.relative_f() # needs sage.libs.ntl 5 - sage: L. = Qp(3).extension(x^2 - 3) - sage: L.relative_f() + sage: R. = QQ[] + sage: L. = Qp(3).extension(x^2 - 3) # needs sage.libs.ntl + sage: L.relative_f() # needs sage.libs.ntl 1 """ return self.absolute_f() // self.base_ring().absolute_f() @@ -922,12 +942,13 @@ def relative_inertia_degree(self): EXAMPLES:: - sage: K. = Qq(3^5) - sage: K.relative_inertia_degree() + sage: K. = Qq(3^5) # needs sage.libs.ntl + sage: K.relative_inertia_degree() # needs sage.libs.ntl 5 - sage: L. = Qp(3).extension(x^2 - 3) - sage: L.relative_inertia_degree() + sage: R. = QQ[] + sage: L. = Qp(3).extension(x^2 - 3) # needs sage.libs.ntl + sage: L.relative_inertia_degree() # needs sage.libs.ntl 1 """ return self.relative_f() @@ -940,12 +961,13 @@ def f(self): EXAMPLES:: - sage: K. = Qq(3^5) - sage: K.f() + sage: K. = Qq(3^5) # needs sage.libs.ntl + sage: K.f() # needs sage.libs.ntl 5 - sage: L. = Qp(3).extension(x^2 - 3) - sage: L.f() + sage: R. = QQ[] + sage: L. = Qp(3).extension(x^2 - 3) # needs sage.libs.ntl + sage: L.f() # needs sage.libs.ntl 1 """ if self.base_ring().absolute_degree() == 1: @@ -961,12 +983,13 @@ def inertia_degree(self): EXAMPLES:: - sage: K. = Qq(3^5) - sage: K.inertia_degree() + sage: K. = Qq(3^5) # needs sage.libs.ntl + sage: K.inertia_degree() # needs sage.libs.ntl 5 - sage: L. = Qp(3).extension(x^2 - 3) - sage: L.inertia_degree() + sage: R. = QQ[] + sage: L. = Qp(3).extension(x^2 - 3) # needs sage.libs.ntl + sage: L.inertia_degree() # needs sage.libs.ntl 1 """ return self.f() @@ -1027,9 +1050,9 @@ def uniformiser(self): sage: R.uniformiser() 5 + O(5^21) sage: A = Zp(7,10) - sage: S. = A[] - sage: B. = A.ext(x^2+7) - sage: B.uniformiser() + sage: S. = A[] # needs sage.libs.ntl + sage: B. = A.ext(x^2+7) # needs sage.libs.ntl + sage: B.uniformiser() # needs sage.libs.ntl t + O(t^21) """ return self.uniformizer() @@ -1048,14 +1071,14 @@ def uniformiser_pow(self, n): def ext(self, *args, **kwds): r""" - Construct an extension of self. See :meth:`extension` for more details. + Construct an extension of ``self``. See :meth:`extension` for more details. EXAMPLES:: sage: A = Zp(7,10) - sage: S. = A[] - sage: B. = A.ext(x^2+7) - sage: B.uniformiser() + sage: S. = A[] # needs sage.libs.ntl + sage: B. = A.ext(x^2 + 7) # needs sage.libs.ntl + sage: B.uniformiser() # needs sage.libs.ntl t + O(t^21) """ return self.extension(*args, **kwds) @@ -1279,7 +1302,7 @@ def _matrix_smith_form(self, M, transformation, integral, exact): TESTS:: sage: A = ZpCR(5, prec=10) - sage: M = zero_matrix(A, 2) + sage: M = zero_matrix(A, 2) # needs sage.geometry.polyhedron sage: M.smith_form(transformation=False) # indirect doctest [0 0] [0 0] @@ -1468,7 +1491,7 @@ def _test_matrix_smith(self, **options): EXAMPLES:: - sage: ZpCA(5, 15)._test_matrix_smith() + sage: ZpCA(5, 15)._test_matrix_smith() # needs sage.geometry.polyhedron """ tester = self._tester(**options) @@ -1562,12 +1585,14 @@ def _matrix_determinant(self, M): O(5^70) O(5^80) + sage: # needs sage.geometry.polyhedron sage: A = random_matrix(Qp(5),4) sage: B = random_matrix(Qp(5),4) sage: (A*B).det() == A.det()*B.det() True sage: A.change_ring(QQ).det() == A.det() True + sage: matrix(Qp(37),[0]).determinant() 0 sage: matrix(Qp(37),[O(37)]).determinant() diff --git a/src/sage/rings/padics/local_generic_element.pyx b/src/sage/rings/padics/local_generic_element.pyx index 6177f74c047..df5c454e865 100644 --- a/src/sage/rings/padics/local_generic_element.pyx +++ b/src/sage/rings/padics/local_generic_element.pyx @@ -47,7 +47,7 @@ cdef class LocalGenericElement(CommutativeRingElement): sage: R = Zp(7, 4, 'capped-rel', 'series'); R(3)/R(5) 2 + 4*7 + 5*7^2 + 2*7^3 + O(7^4) - sage: R(2/3) / R(1/3) #indirect doctest + sage: R(2/3) / R(1/3) # indirect doctest 2 + O(7^4) sage: R(49) / R(7) 7 + O(7^5) @@ -127,40 +127,39 @@ cdef class LocalGenericElement(CommutativeRingElement): Over unramified extensions:: - sage: R = ZpCA(3,5); S. = R[]; W. = R.extension( t^2 + 1 ) - sage: t.inverse_of_unit() - 2*t + 2*t*3 + 2*t*3^2 + 2*t*3^3 + 2*t*3^4 + O(3^5) + sage: # needs sage.libs.ntl sage: R = ZpCR(3,5); S. = R[]; W. = R.extension( t^2 + 1 ) sage: t.inverse_of_unit() 2*t + 2*t*3 + 2*t*3^2 + 2*t*3^3 + 2*t*3^4 + O(3^5) + sage: R = QpCR(3,5); S. = R[]; W. = R.extension( t^2 + 1 ) + sage: t.inverse_of_unit() + 2*t + 2*t*3 + 2*t*3^2 + 2*t*3^3 + 2*t*3^4 + O(3^5) + sage: # needs sage.libs.flint + sage: R = ZpCA(3,5); S. = R[]; W. = R.extension( t^2 + 1 ) + sage: t.inverse_of_unit() + 2*t + 2*t*3 + 2*t*3^2 + 2*t*3^3 + 2*t*3^4 + O(3^5) sage: R = ZpFM(3,5); S. = R[]; W. = R.extension( t^2 + 1 ) sage: t.inverse_of_unit() 2*t + 2*t*3 + 2*t*3^2 + 2*t*3^3 + 2*t*3^4 - sage: R = ZpFP(3,5); S. = R[]; W. = R.extension( t^2 + 1 ) sage: t.inverse_of_unit() 2*t + 2*t*3 + 2*t*3^2 + 2*t*3^3 + 2*t*3^4 - sage: R = QpCR(3,5); S. = R[]; W. = R.extension( t^2 + 1 ) - sage: t.inverse_of_unit() - 2*t + 2*t*3 + 2*t*3^2 + 2*t*3^3 + 2*t*3^4 + O(3^5) Over Eisenstein extensions:: + sage: # needs sage.libs.ntl sage: R = ZpCA(3,5); S. = R[]; W. = R.extension( t^2 - 3 ) sage: (t - 1).inverse_of_unit() 2 + 2*t + t^2 + t^3 + t^4 + t^5 + t^6 + t^7 + t^8 + t^9 + O(t^10) - sage: R = ZpCR(3,5); S. = R[]; W. = R.extension( t^2 - 3 ) sage: (t - 1).inverse_of_unit() 2 + 2*t + t^2 + t^3 + t^4 + t^5 + t^6 + t^7 + t^8 + t^9 + O(t^10) - sage: R = ZpFM(3,5); S. = R[]; W. = R.extension( t^2 - 3 ) sage: (t - 1).inverse_of_unit() 2 + 2*t + t^2 + t^3 + t^4 + t^5 + t^6 + t^7 + t^8 + t^9 - sage: R = QpCR(3,5); S. = R[]; W. = R.extension( t^2 - 3 ) sage: (t - 1).inverse_of_unit() 2 + 2*t + t^2 + t^3 + t^4 + t^5 + t^6 + t^7 + t^8 + t^9 + O(t^10) @@ -301,9 +300,10 @@ cdef class LocalGenericElement(CommutativeRingElement): Test that slices also work over eisenstein extensions:: + sage: # needs sage.libs.ntl sage: F = Qp(5) sage: H. = F[] - sage: T. = F.extension(x^2-5) + sage: T. = F.extension(x^2 - 5) sage: a = T(3*t^-2 + 1 + 4*t + 2*t^2) sage: a.slice(0, 1) 1 + O(t) @@ -314,9 +314,10 @@ cdef class LocalGenericElement(CommutativeRingElement): Test that slices also work over unramified extensions:: + sage: # needs sage.libs.ntl sage: F = Qp(5) sage: H. = F[] - sage: T. = F.extension(x^2-2) + sage: T. = F.extension(x^2 - 2) sage: a = T(3*5^-1 + 1 + (3*t + 4)*5^2) sage: a.slice(0, 1) 1 + O(5) @@ -327,9 +328,10 @@ cdef class LocalGenericElement(CommutativeRingElement): Test that slices also work over 2-step extensions (unramified followed by eisenstein):: + sage: # needs sage.libs.ntl sage: F = Qp(5) sage: H. = F[] - sage: T. = F.extension(x^2-3) + sage: T. = F.extension(x^2 - 3) sage: D. = T[] sage: W. = T.extension((4*5^-2 + 2*5^-1 + 4 + (2*t + 2)*5 + 3*t*5^3 + 4*5^4 + 3*5^5 + (2*t + 2)*5^8 + (4*t + 3)*5^9 + 2*t*5^10 + (3*t + 3)*5^11 + (3*t + 1)*5^12 + (3*t + 2)*5^13 + 4*5^14 + (2*t + 4)*5^15 + (4*t + 1)*5^16 + (t + 1)*5^17 + O(5^18))*y^2 + (t + 2*t*5 + t*5^2 + 4*t*5^3 + (2*t + 4)*5^4 + (3*t + 4)*5^5 + (t + 1)*5^6 + t*5^7 + (2*t + 4)*5^8 + 3*5^9 + 2*5^10 + 5^12 + (4*t + 2)*5^13 + 5^14 + 5^15 + 3*t*5^16 + (t + 2)*5^17 + 4*5^18 + (3*t + 1)*5^19 + O(5^20))*y + (2*t + 2)*5^-1 + 3 + 5 + t*5^2 + (4*t + 2)*5^3 + (4*t + 1)*5^4 + (3*t + 4)*5^5 + (4*t + 4)*5^6 + (3*t + 2)*5^7 + (4*t + 4)*5^8 + 3*5^9 + (t + 3)*5^10 + (4*t + 3)*5^11 + 5^12 + (2*t + 2)*5^14 + 4*t*5^15 + (2*t + 2)*5^16 + (4*t + 4)*5^17 + O(5^18)) sage: a = W(3*w^-36 + (2*t + 2)*w^-23) @@ -351,8 +353,8 @@ cdef class LocalGenericElement(CommutativeRingElement): Verify that :trac:`30695` has been fixed:: - sage: F=Qp(3) - sage: a=F(0) + sage: F = Qp(3) + sage: a = F(0) sage: a.slice(0,None) 0 @@ -415,7 +417,7 @@ cdef class LocalGenericElement(CommutativeRingElement): EXAMPLES:: sage: R = Zp(5); a = R(17) - sage: latex(a) #indirect doctest + sage: latex(a) # indirect doctest 2 + 3 \cdot 5 + O(5^{20}) """ # TODO: add a bunch more documentation of latexing elements @@ -441,7 +443,7 @@ cdef class LocalGenericElement(CommutativeRingElement): sage: R = Zp(7, 4, 'capped-rel', 'series'); a = R(12); b = R(5); a - b 7 + O(7^4) - sage: R(4/3) - R(1/3) #indirect doctest + sage: R(4/3) - R(1/3) # indirect doctest 1 + O(7^4) """ # this doctest doesn't actually test this function, since _sub_ is overridden. @@ -508,8 +510,9 @@ cdef class LocalGenericElement(CommutativeRingElement): Check that :trac:`23464` has been resolved:: - sage: R. = Qp(7).extension(x^3 - 7) - sage: (pi^93).add_bigoh(-10) + sage: x = polygen(QQ) + sage: R. = Qp(7).extension(x^3 - 7) # needs sage.libs.ntl + sage: (pi^93).add_bigoh(-10) # needs sage.libs.ntl sage.symbolic O(pi^-10) """ @@ -603,7 +606,7 @@ cdef class LocalGenericElement(CommutativeRingElement): False sage: K(1/9).is_padic_unit() False - sage: Qq(3^2,5,names='a')(3).is_padic_unit() + sage: Qq(3^2,5,names='a')(3).is_padic_unit() # needs sage.libs.ntl False """ return self.valuation() == 0 @@ -639,7 +642,7 @@ cdef class LocalGenericElement(CommutativeRingElement): True sage: R(3).is_unit() False - sage: Qp(5,5)(5).is_unit() # Note that 5 is invertible in `QQ_5`, even if it has positive valuation! + sage: Qp(5,5)(5).is_unit() # Note that 5 is invertible in `QQ_5`, even if it has positive valuation! True sage: Qp(5,5)(5).is_padic_unit() False @@ -670,7 +673,7 @@ cdef class LocalGenericElement(CommutativeRingElement): True sage: K(1/9).is_unit() True - sage: Qq(3^2,5,names='a')(3).is_unit() + sage: Qq(3^2,5,names='a')(3).is_unit() # needs sage.libs.ntl True sage: R(0,0).is_unit() False @@ -772,21 +775,22 @@ cdef class LocalGenericElement(CommutativeRingElement): sage: sqrt(R2(4)) 2 + O(2^20) - sage: R. = Zq(2^10, 10) - sage: u = 1 + 8*t - sage: sqrt(u) - 1 + t*2^2 + t^2*2^3 + t^2*2^4 + (t^4 + t^3 + t^2)*2^5 + (t^4 + t^2)*2^6 + (t^5 + t^2)*2^7 + (t^6 + t^5 + t^4 + t^2)*2^8 + O(2^9) + sage: R. = Zq(2^10, 10) # needs sage.libs.ntl + sage: u = 1 + 8*t # needs sage.libs.ntl + sage: sqrt(u) # needs sage.libs.ntl + 1 + t*2^2 + t^2*2^3 + t^2*2^4 + (t^4 + t^3 + t^2)*2^5 + (t^4 + t^2)*2^6 + + (t^5 + t^2)*2^7 + (t^6 + t^5 + t^4 + t^2)*2^8 + O(2^9) sage: R. = Zp(2).extension(x^3 - 2) sage: u = R(1 + a^4 + a^5 + a^7 + a^8, 10); u 1 + a^4 + a^5 + a^7 + a^8 + O(a^10) - sage: v = sqrt(u); v + sage: v = sqrt(u); v # needs sage.libs.ntl 1 + a^2 + a^4 + a^6 + O(a^7) However, observe that the precision increases to its original value when we recompute the square of the square root:: - sage: v^2 + sage: v^2 # needs sage.libs.ntl 1 + a^4 + a^5 + a^7 + a^8 + O(a^10) If the input does not have enough precision in order to determine if @@ -849,9 +853,9 @@ cdef class LocalGenericElement(CommutativeRingElement): EXAMPLES:: sage: Q7 = Qp(7) - sage: R. = Q7[] - sage: F. = Q7.ext(x^3+7*x+7) - sage: z.normalized_valuation() + sage: R. = Q7[] # needs sage.libs.ntl + sage: F. = Q7.ext(x^3+7*x+7) # needs sage.libs.ntl + sage: z.normalized_valuation() # needs sage.libs.ntl 1/3 """ F = self.parent() diff --git a/src/sage/rings/padics/misc.py b/src/sage/rings/padics/misc.py index b535dbb07c5..984482bc39c 100644 --- a/src/sage/rings/padics/misc.py +++ b/src/sage/rings/padics/misc.py @@ -91,21 +91,21 @@ def gauss_sum(a, p, f, prec=20, factored=False, algorithm='pari', parent=None): In this example, we verify that `g_3(0) = -1`:: sage: from sage.rings.padics.misc import gauss_sum - sage: -gauss_sum(0, 3, 1) # needs sage.rings.padics + sage: -gauss_sum(0, 3, 1) # needs sage.libs.ntl sage.rings.padics 1 + O(pi^40) Next, we verify that `g_5(a) g_5(-a) = 5 (-1)^a`:: sage: from sage.rings.padics.misc import gauss_sum - sage: gauss_sum(2,5,1)^2 - 5 # needs sage.rings.padics + sage: gauss_sum(2,5,1)^2 - 5 # needs sage.libs.ntl O(pi^84) - sage: gauss_sum(1,5,1)*gauss_sum(3,5,1) + 5 # needs sage.rings.padics + sage: gauss_sum(1,5,1)*gauss_sum(3,5,1) + 5 # needs sage.libs.ntl O(pi^84) Finally, we compute a non-trivial value:: sage: from sage.rings.padics.misc import gauss_sum - sage: gauss_sum(2,13,2) # needs sage.rings.padics + sage: gauss_sum(2,13,2) # needs sage.libs.ntl 6*pi^2 + 7*pi^14 + 11*pi^26 + 3*pi^62 + 6*pi^74 + 3*pi^86 + 5*pi^98 + pi^110 + 7*pi^134 + 9*pi^146 + 4*pi^158 + 6*pi^170 + 4*pi^194 + pi^206 + 6*pi^218 + 9*pi^230 + O(pi^242) diff --git a/src/sage/rings/padics/morphism.pyx b/src/sage/rings/padics/morphism.pyx index 87aa8fef1a7..3dbae06bc51 100644 --- a/src/sage/rings/padics/morphism.pyx +++ b/src/sage/rings/padics/morphism.pyx @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.ntl """ Frobenius endomorphisms on p-adic fields """ diff --git a/src/sage/rings/padics/padic_ZZ_pX_CA_element.pyx b/src/sage/rings/padics/padic_ZZ_pX_CA_element.pyx index b13f79ea6f2..fb62a0695f9 100644 --- a/src/sage/rings/padics/padic_ZZ_pX_CA_element.pyx +++ b/src/sage/rings/padics/padic_ZZ_pX_CA_element.pyx @@ -4,6 +4,7 @@ # distutils: library_dirs = NTL_LIBDIR # distutils: extra_link_args = NTL_LIBEXTRA # distutils: language = c++ +# sage.doctest: needs sage.rings.padics r""" `p`-adic ``ZZ_pX`` CA Element @@ -73,13 +74,15 @@ An Eisenstein extension:: sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f); W 5-adic Eisenstein Extension Ring in w defined by x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: z = (1+w)^5; z - 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 + O(w^25) + 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 + O(w^25) sage: y = z >> 1; y - w^4 + w^5 + 2*w^6 + 4*w^7 + 3*w^9 + w^11 + 4*w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^19 + w^20 + 4*w^23 + O(w^24) + w^4 + w^5 + 2*w^6 + 4*w^7 + 3*w^9 + w^11 + 4*w^12 + 4*w^13 + 4*w^14 + 4*w^15 + + 4*w^16 + 4*w^19 + w^20 + 4*w^23 + O(w^24) sage: y.valuation() 4 sage: y.precision_relative() @@ -95,14 +98,17 @@ An Eisenstein extension:: An unramified extension:: + sage: # needs sage.libs.flint sage: g = x^3 + 3*x + 3 sage: A. = R.ext(g) sage: z = (1+a)^5; z - (2*a^2 + 4*a) + (3*a^2 + 3*a + 1)*5 + (4*a^2 + 3*a + 4)*5^2 + (4*a^2 + 4*a + 4)*5^3 + (4*a^2 + 4*a + 4)*5^4 + O(5^5) + (2*a^2 + 4*a) + (3*a^2 + 3*a + 1)*5 + (4*a^2 + 3*a + 4)*5^2 + + (4*a^2 + 4*a + 4)*5^3 + (4*a^2 + 4*a + 4)*5^4 + O(5^5) sage: z - 1 - 5*a - 10*a^2 - 10*a^3 - 5*a^4 - a^5 O(5^5) sage: y = z >> 1; y - (3*a^2 + 3*a + 1) + (4*a^2 + 3*a + 4)*5 + (4*a^2 + 4*a + 4)*5^2 + (4*a^2 + 4*a + 4)*5^3 + O(5^4) + (3*a^2 + 3*a + 1) + (4*a^2 + 3*a + 4)*5 + (4*a^2 + 4*a + 4)*5^2 + + (4*a^2 + 4*a + 4)*5^3 + O(5^4) sage: 1/a (3*a^2 + 4) + (a^2 + 4)*5 + (3*a^2 + 4)*5^2 + (a^2 + 4)*5^3 + (3*a^2 + 4)*5^4 + O(5^5) sage: FFA = A.residue_field() @@ -111,6 +117,7 @@ An unramified extension:: Different printing modes:: + sage: # needs sage.libs.flint sage: R = ZpCA(5, print_mode='digits'); S. = ZZ[]; f = x^5 + 75*x^3 - 15*x^2 + 125*x -5; W. = R.ext(f) sage: z = (1+w)^5; repr(z) '...4110403113210310442221311242000111011201102002023303214332011214403232013144001400444441030421100001' @@ -126,6 +133,7 @@ Different printing modes:: You can get at the underlying ntl representation:: + sage: # needs sage.libs.flint sage: z._ntl_rep() [6 95367431640505 25 95367431640560 5] sage: y._ntl_rep() @@ -215,10 +223,11 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = (1+w)^5; z # indirect doctest - 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 + O(w^25) + sage: z = (1+w)^5; z # indirect doctest + 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 + O(w^25) sage: W(R(3,3)) 3 + O(w^15) sage: W(pari('3 + O(5^3)')) @@ -245,9 +254,10 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): Check that :trac:`13612` has been fixed:: + sage: # needs sage.libs.flint sage: R = ZpCA(3) sage: S. = R[] - sage: W. = R.extension(a^2+1) + sage: W. = R.extension(a^2 + 1) sage: W(W.residue_field().zero()) O(3) @@ -436,9 +446,9 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(0,6); z # indirect doctest + sage: z = W(0,6); z # indirect doctest O(w^6) sage: z.valuation() 6 @@ -460,10 +470,10 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = W(0) - sage: z._is_inexact_zero() #indirect doctest + sage: z._is_inexact_zero() # indirect doctest True sage: z = W(0,6) sage: z._is_inexact_zero() @@ -479,10 +489,10 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: F = W.fraction_field() - sage: z = F(1+w); z # indirect doctest + sage: z = F(1+w); z # indirect doctest 1 + w + O(w^25) sage: W.precision_cap() 25 @@ -502,9 +512,9 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: W(70, absprec = 13) # indirect doctest + sage: W(70, absprec = 13) # indirect doctest 4*w^5 + 3*w^7 + w^9 + 2*w^10 + 2*w^11 + O(w^13) sage: W(70, absprec = 4) O(w^4) @@ -530,9 +540,9 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: W(70, relprec = 3) # indirect doctest + sage: W(70, relprec = 3) # indirect doctest 4*w^5 + 3*w^7 + O(w^8) sage: W(70, absprec = 4, relprec = 2) O(w^4) @@ -565,9 +575,9 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(70/3, 14); z # indirect doctest + sage: z = W(70/3, 14); z # indirect doctest 3*w^5 + w^7 + 2*w^9 + 2*w^10 + 4*w^11 + w^12 + 2*w^13 + O(w^14) sage: z * 3 4*w^5 + 3*w^7 + w^9 + 2*w^10 + 2*w^11 + w^13 + O(w^14) @@ -595,9 +605,9 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(70/3, 14); z # indirect doctest + sage: z = W(70/3, 14); z # indirect doctest 3*w^5 + w^7 + 2*w^9 + 2*w^10 + 4*w^11 + w^12 + 2*w^13 + O(w^14) sage: z * 3 4*w^5 + 3*w^7 + w^9 + 2*w^10 + 2*w^11 + w^13 + O(w^14) @@ -630,9 +640,9 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: W(QQ(4), 23) # indirect doctest + sage: W(QQ(4), 23) # indirect doctest 4 + O(w^23) """ cdef mpz_t tmp_m @@ -656,9 +666,9 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(ntl.ZZX([4,1,16]), absprec = 14); z # indirect doctest + sage: z = W(ntl.ZZX([4,1,16]), absprec = 14); z # indirect doctest 4 + w + w^2 + 3*w^7 + w^9 + 2*w^11 + 4*w^13 + O(w^14) sage: z._ntl_rep() [4 1 16] @@ -680,9 +690,9 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(ntl.ZZX([4,1,16]), relprec = 12); z # indirect doctest + sage: z = W(ntl.ZZX([4,1,16]), relprec = 12); z # indirect doctest 4 + w + w^2 + 3*w^7 + w^9 + 2*w^11 + O(w^12) sage: z._ntl_rep() [4 1 16] @@ -703,9 +713,9 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(ntl.ZZ_pX([4,1,16],5^2)); z # indirect doctest + sage: z = W(ntl.ZZ_pX([4,1,16],5^2)); z # indirect doctest 4 + w + w^2 + 3*w^7 + w^9 + O(w^10) sage: z._ntl_rep() [4 1 16] @@ -733,9 +743,9 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(ntl.ZZ_pX([4,1,16],5^2), absprec = 8, relprec = 12); z # indirect doctest + sage: z = W(ntl.ZZ_pX([4,1,16],5^2), absprec = 8, relprec = 12); z # indirect doctest 4 + w + w^2 + 3*w^7 + O(w^8) sage: z._ntl_rep() [4 1 16] @@ -785,9 +795,9 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: W(70, 13) # indirect doctest + sage: W(70, 13) # indirect doctest 4*w^5 + 3*w^7 + w^9 + 2*w^10 + 2*w^11 + O(w^13) """ if absprec < 0: @@ -826,9 +836,9 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: W(70, relprec = 3) # indirect doctest + sage: W(70, relprec=3) # indirect doctest 4*w^5 + 3*w^7 + O(w^8) """ if absprec <= ordp + relprec: @@ -845,9 +855,9 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: w^5 + 1 # indirect doctest + sage: w^5 + 1 # indirect doctest 1 + w^5 + O(w^25) """ cdef pAdicZZpXCAElement ans = pAdicZZpXCAElement.__new__(pAdicZZpXCAElement) @@ -868,7 +878,7 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = Qp(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5 - 1 sage: loads(dumps(z)) == z @@ -894,9 +904,9 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: w == 1 # indirect doctest + sage: w == 1 # indirect doctest False sage: y = 1 + w + O(w^7) sage: z = 1 + w + w^10 + O(w^13) @@ -921,10 +931,10 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5 - sage: y = ~z; y # indirect doctest + sage: y = ~z; y # indirect doctest 1 + 4*w^5 + 4*w^6 + 3*w^7 + w^8 + 2*w^10 + w^11 + w^12 + 2*w^14 + 3*w^16 + 3*w^17 + 4*w^18 + 4*w^19 + 2*w^20 + 2*w^21 + 4*w^22 + 3*w^23 + 3*w^24 + O(w^25) sage: y.parent() 5-adic Eisenstein Extension Field in w defined by x^5 + 75*x^3 - 15*x^2 + 125*x - 5 @@ -942,11 +952,11 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5; z 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 + O(w^25) - sage: y = z.to_fraction_field(); y #indirect doctest + sage: y = z.to_fraction_field(); y # indirect doctest 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 + O(w^25) sage: y.parent() 5-adic Eisenstein Extension Field in w defined by x^5 + 75*x^3 - 15*x^2 + 125*x - 5 @@ -970,12 +980,12 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5 sage: z 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 + O(w^25) - sage: z << 17 # indirect doctest + sage: z << 17 # indirect doctest w^17 + w^22 + w^23 + 2*w^24 + O(w^25) sage: z << (-1) w^4 + w^5 + 2*w^6 + 4*w^7 + 3*w^9 + w^11 + 4*w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^19 + w^20 + 4*w^23 + O(w^24) @@ -991,12 +1001,12 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5 sage: z 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 + O(w^25) - sage: z << 17 # indirect doctest + sage: z << 17 # indirect doctest w^17 + w^22 + w^23 + 2*w^24 + O(w^25) sage: z << (-1) w^4 + w^5 + 2*w^6 + 4*w^7 + 3*w^9 + w^11 + 4*w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^19 + w^20 + 4*w^23 + O(w^24) @@ -1022,10 +1032,10 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5,print_mode='digits') sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5 - sage: for m in range(26): repr(z >> m) # indirect doctest + sage: for m in range(26): repr(z >> m) # indirect doctest '...4001400444441030421100001' '...400140044444103042110000' '...40014004444410304211000' @@ -1089,12 +1099,12 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5 sage: z 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 + O(w^25) - sage: z >> (6) # indirect doctest + sage: z >> (6) # indirect doctest 1 + 2*w + 4*w^2 + 3*w^4 + w^6 + 4*w^7 + 4*w^8 + 4*w^9 + 4*w^10 + 4*w^11 + 4*w^14 + w^15 + 4*w^18 + O(w^19) sage: z >> (-4) w^4 + w^9 + w^10 + 2*w^11 + 4*w^12 + 3*w^14 + w^16 + 4*w^17 + 4*w^18 + 4*w^19 + 4*w^20 + 4*w^21 + 4*w^24 + O(w^25) @@ -1118,11 +1128,11 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5; z 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 + O(w^25) - sage: -z # indirect doctest + sage: -z # indirect doctest 4 + 3*w^5 + 4*w^6 + w^7 + w^8 + w^9 + w^10 + w^11 + 2*w^12 + 4*w^13 + 4*w^15 + 3*w^16 + w^17 + 2*w^18 + 3*w^19 + 2*w^21 + 4*w^23 + 4*w^24 + O(w^25) sage: y = z + (-z); y O(w^25) @@ -1196,9 +1206,9 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: (1 + w)^5 # indirect doctest + sage: (1 + w)^5 # indirect doctest 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 + O(w^25) sage: (1 + w + O(w^19))^5 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + O(w^24) @@ -1384,9 +1394,9 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: (4*w^5 + 3*w^7 + w^9 + 2*w^10 + 2*w^11 + O(w^13)) - 69 # indirect doctest + sage: (4*w^5 + 3*w^7 + w^9 + 2*w^10 + 2*w^11 + O(w^13)) - 69 # indirect doctest 1 + O(w^13) sage: -69 + (4*w^5 + 3*w^7 + w^9 + 2*w^10 + 2*w^11 + O(w^13)) 1 + O(w^13) @@ -1422,11 +1432,11 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(329) sage: b = W(111) - sage: a - b #indirect doctest + sage: a - b # indirect doctest 3 + 3*w^5 + w^7 + 2*w^9 + 3*w^10 + 4*w^11 + 2*w^13 + 2*w^14 + w^15 + 4*w^16 + 2*w^18 + 3*w^19 + 2*w^20 + 3*w^21 + w^22 + w^24 + O(w^25) sage: W(218) 3 + 3*w^5 + w^7 + 2*w^9 + 3*w^10 + 4*w^11 + 2*w^13 + 2*w^14 + w^15 + 4*w^16 + 2*w^18 + 3*w^19 + 2*w^20 + 3*w^21 + w^22 + w^24 + O(w^25) @@ -1463,11 +1473,11 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(329) sage: b = W(111) - sage: a*b #indirect doctest + sage: a*b # indirect doctest 4 + 3*w^5 + w^7 + 2*w^9 + 4*w^11 + 3*w^12 + 2*w^13 + w^14 + 2*w^15 + 3*w^16 + 4*w^17 + 4*w^18 + 2*w^19 + 2*w^21 + 4*w^22 + 2*w^23 + w^24 + O(w^25) sage: a * 0 O(w^25) @@ -1516,9 +1526,9 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: W(14) / W(125) #indirect doctest + sage: W(14) / W(125) # indirect doctest 4*w^-15 + w^-13 + 3*w^-11 + 2*w^-10 + 3*w^-9 + 4*w^-8 + 4*w^-7 + 3*w^-6 + O(w^-5) sage: 1 / w w^-1 + O(w^23) @@ -1544,7 +1554,8 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): EXAMPLES:: - sage: ZZ(ZqCA(125,names='a')(-1)) #indirect doctest + sage: # needs sage.libs.flint + sage: ZZ(ZqCA(125,names='a')(-1)) # indirect doctest 95367431640624 sage: R = ZpCA(5); S. = ZZ[]; f = x^5 + 25*x^3 - 5; W. = R.ext(f) sage: ZZ(W(-1)) @@ -1577,7 +1588,7 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: b = W(45, 17); b 4*w^5 + 3*w^7 + w^9 + w^10 + 2*w^11 + w^12 + w^13 + 3*w^14 + w^16 + O(w^17) @@ -1604,7 +1615,7 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: O(w^189).is_zero() True @@ -1648,10 +1659,10 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(566); b = W(209) - sage: c = a + b; c._ntl_rep() # indirect doctest + sage: c = a + b; c._ntl_rep() # indirect doctest [775] """ if self.absprec == 0: @@ -1670,7 +1681,7 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(566); b = W(209) sage: c = a + b; c._ntl_rep_abs() @@ -1694,7 +1705,7 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): EXAMPLES:: sage: R. = ZZ[] - sage: W. = ZpCA(5).extension(x^3-5) + sage: W. = ZpCA(5).extension(x^3 - 5) sage: (1 + w + O(w^11))._polynomial_list() [1 + O(5^4), 1 + O(5^4)] sage: (1 + w + O(w^11))._polynomial_list(pad=True) @@ -1750,10 +1761,10 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(566) - sage: a._const_term_test() #indirect doctest + sage: a._const_term_test() # indirect doctest 566 """ return ZZ_pX_ConstTerm(self.value) @@ -1770,7 +1781,7 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(47); b = W(47 + 25) sage: a.is_equal_to(b) @@ -1803,11 +1814,11 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(345, 17); a 4*w^5 + 3*w^7 + w^9 + 3*w^10 + 2*w^11 + 4*w^12 + w^13 + 2*w^14 + 2*w^15 + O(w^17) - sage: b = a.lift_to_precision(19); b # indirect doctest + sage: b = a.lift_to_precision(19); b # indirect doctest 4*w^5 + 3*w^7 + w^9 + 3*w^10 + 2*w^11 + 4*w^12 + w^13 + 2*w^14 + 2*w^15 + w^17 + 2*w^18 + O(w^19) sage: c = a.lift_to_precision(24); c 4*w^5 + 3*w^7 + w^9 + 3*w^10 + 2*w^11 + 4*w^12 + w^13 + 2*w^14 + 2*w^15 + w^17 + 2*w^18 + 4*w^19 + 4*w^20 + 2*w^21 + 4*w^23 + O(w^24) @@ -1873,7 +1884,7 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: y = W(775, 19); y w^10 + 4*w^12 + 2*w^14 + w^15 + 2*w^16 + 4*w^17 + w^18 + O(w^19) @@ -1884,6 +1895,8 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: w^10 - w^12 + 2*w^14 + w^15 + 2*w^16 + w^18 + O(w^19) w^10 + 4*w^12 + 2*w^14 + w^15 + 2*w^16 + 4*w^17 + w^18 + O(w^19) sage: g = x^3 + 3*x + 3 + + sage: # needs sage.libs.flint sage: A. = R.ext(g) sage: y = 75 + 45*a + 1200*a^2; y 4*a*5 + (3*a^2 + a + 3)*5^2 + 4*a^2*5^3 + a^2*5^4 + O(5^5) @@ -1954,10 +1967,10 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = (3+w)^7 - sage: a.matrix_mod_pn() + sage: a.matrix_mod_pn() # needs sage.geometry.polyhedron [2757 333 1068 725 2510] [ 50 1507 483 318 725] [ 500 50 3007 2358 318] @@ -2044,7 +2057,10 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: E = a.teichmuller_expansion(); E 5-adic expansion of a + O(5^4) (teichmuller) sage: list(E) - [a + (2*a^3 + 2*a^2 + 3*a + 4)*5 + (4*a^3 + 3*a^2 + 3*a + 2)*5^2 + (4*a^2 + 2*a + 2)*5^3 + O(5^4), (3*a^3 + 3*a^2 + 2*a + 1) + (a^3 + 4*a^2 + 1)*5 + (a^2 + 4*a + 4)*5^2 + O(5^3), (4*a^3 + 2*a^2 + a + 1) + (2*a^3 + 2*a^2 + 2*a + 4)*5 + O(5^2), (a^3 + a^2 + a + 4) + O(5)] + [a + (2*a^3 + 2*a^2 + 3*a + 4)*5 + (4*a^3 + 3*a^2 + 3*a + 2)*5^2 + (4*a^2 + 2*a + 2)*5^3 + O(5^4), + (3*a^3 + 3*a^2 + 2*a + 1) + (a^3 + 4*a^2 + 1)*5 + (a^2 + 4*a + 4)*5^2 + O(5^3), + (4*a^3 + 2*a^2 + a + 1) + (2*a^3 + 2*a^2 + 2*a + 4)*5 + O(5^2), + (a^3 + a^2 + a + 4) + O(5)] sage: sum([c * 5^i for i, c in enumerate(E)]) a + O(5^4) sage: all(c^625 == c for c in E) @@ -2054,14 +2070,16 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: f = x^3 - 98*x + 7 sage: W. = ZpCA(7,3).ext(f) sage: b = (1+w)^5; L = b.teichmuller_expansion(); L - [1 + O(w^9), 5 + 5*w^3 + w^6 + 4*w^7 + O(w^8), 3 + 3*w^3 + O(w^7), 3 + 3*w^3 + O(w^6), O(w^5), 4 + 5*w^3 + O(w^4), 3 + O(w^3), 6 + O(w^2), 6 + O(w)] + [1 + O(w^9), 5 + 5*w^3 + w^6 + 4*w^7 + O(w^8), 3 + 3*w^3 + O(w^7), + 3 + 3*w^3 + O(w^6), O(w^5), 4 + 5*w^3 + O(w^4), 3 + O(w^3), 6 + O(w^2), 6 + O(w)] sage: sum([w^i*L[i] for i in range(9)]) == b True sage: all(L[i]^(7^3) == L[i] for i in range(9)) True sage: L = W(3).teichmuller_expansion(); L - [3 + 3*w^3 + w^7 + O(w^9), O(w^8), O(w^7), 4 + 5*w^3 + O(w^6), O(w^5), O(w^4), 3 + O(w^3), 6 + O(w^2)] + [3 + 3*w^3 + w^7 + O(w^9), O(w^8), O(w^7), 4 + 5*w^3 + O(w^6), O(w^5), + O(w^4), 3 + O(w^3), 6 + O(w^2)] sage: sum([w^i*L[i] for i in range(len(L))]) 3 + O(w^9) """ @@ -2120,12 +2138,13 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: S. = ZZ[] sage: f = x^5 + 33*x^3 - 121*x^2 - 77 sage: W. = R.ext(f) - sage: y = W.teichmuller(3, 19); y #indirect doctest + sage: y = W.teichmuller(3, 19); y # indirect doctest 3 + 9*w^10 + 3*w^13 + 3*w^15 + 9*w^16 + 3*w^17 + w^18 + O(w^19) - sage: y^11 == y True sage: g = x^3 + 9*x^2 + 7 + + sage: # needs sage.libs.flint sage: A. = R.ext(g) sage: b = A.teichmuller(1 + 2*a - a^2); b (10*a^2 + 2*a + 1) + (4*a^2 + 7)*11 + (5*a^2 + a + 3)*11^2 + (a^2 + 9*a + 6)*11^3 + (7*a^2 + 2*a + 3)*11^4 + O(11^5) @@ -2165,7 +2184,7 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(75, 19); a 3*w^10 + 2*w^12 + w^14 + w^16 + w^17 + 3*w^18 + O(w^19) @@ -2192,7 +2211,7 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(75, 19); a 3*w^10 + 2*w^12 + w^14 + w^16 + w^17 + 3*w^18 + O(w^19) @@ -2223,11 +2242,11 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(75, 19); a 3*w^10 + 2*w^12 + w^14 + w^16 + w^17 + 3*w^18 + O(w^19) - sage: a.valuation() # indirect doctest + sage: a.valuation() # indirect doctest 10 sage: a.precision_absolute() 19 @@ -2260,7 +2279,7 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(75, 19); a 3*w^10 + 2*w^12 + w^14 + w^16 + w^17 + 3*w^18 + O(w^19) @@ -2296,7 +2315,7 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: y = W(775, 19); y w^10 + 4*w^12 + 2*w^14 + w^15 + 2*w^16 + 4*w^17 + w^18 + O(w^19) @@ -2307,6 +2326,8 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement): sage: w^10 - w^12 + 2*w^14 + w^15 + 2*w^16 + w^18 + O(w^19) w^10 + 4*w^12 + 2*w^14 + w^15 + 2*w^16 + 4*w^17 + w^18 + O(w^19) sage: g = x^3 + 3*x + 3 + + sage: # needs sage.libs.flint sage: A. = R.ext(g) sage: y = 75 + 45*a + 1200*a^2; y 4*a*5 + (3*a^2 + a + 3)*5^2 + 4*a^2*5^3 + a^2*5^4 + O(5^5) @@ -2329,7 +2350,7 @@ def make_ZZpXCAElement(parent, value, absprec, version): sage: from sage.rings.padics.padic_ZZ_pX_CA_element import make_ZZpXCAElement sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: make_ZZpXCAElement(W, ntl.ZZ_pX([3,2,4],5^3),13,0) 3 + 2*w + 4*w^2 + O(w^13) diff --git a/src/sage/rings/padics/padic_ZZ_pX_CR_element.pyx b/src/sage/rings/padics/padic_ZZ_pX_CR_element.pyx index f0406955abe..f4f8bce971f 100644 --- a/src/sage/rings/padics/padic_ZZ_pX_CR_element.pyx +++ b/src/sage/rings/padics/padic_ZZ_pX_CR_element.pyx @@ -4,6 +4,7 @@ # distutils: library_dirs = NTL_LIBDIR # distutils: extra_link_args = NTL_LIBEXTRA # distutils: language = c++ +# sage.doctest: needs sage.rings.padics r""" `p`-adic ``ZZ_pX`` CR Element @@ -91,7 +92,7 @@ An Eisenstein extension:: sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f); W 5-adic Eisenstein Extension Ring in w defined by x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: z = (1+w)^5; z @@ -251,9 +252,9 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = (1+w)^5; z # indirect doctest + sage: z = (1+w)^5; z # indirect doctest 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 + O(w^25) sage: W(pari('3 + O(5^3)')) 3 + O(w^15) @@ -277,13 +278,13 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(3) sage: S. = R[] - sage: W. = R.extension(a^2+1) + sage: W. = R.extension(a^2 + 1) sage: W(W.residue_field().zero()) O(3) sage: K = Qp(3) sage: S. = K[] - sage: L. = K.extension(a^2+1) + sage: L. = K.extension(a^2 + 1) sage: L(L.residue_field().zero()) O(3) @@ -553,9 +554,9 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(0,6); z # indirect doctest + sage: z = W(0,6); z # indirect doctest O(w^6) sage: z.valuation() 6 @@ -589,9 +590,9 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = R(0); z # indirect doctest + sage: z = R(0); z # indirect doctest 0 sage: z.valuation() +Infinity @@ -605,7 +606,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(89, 3) sage: S. = R[] sage: W. = R.ext(x^34 - 2*89*x^5 + 89) - sage: z = R(0); z # indirect doctest + sage: z = R(0); z # indirect doctest 0 sage: z.valuation() +Infinity @@ -625,7 +626,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Qp(3,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = W(0) sage: z._is_exact_zero() @@ -660,7 +661,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(7,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = W(0) sage: z._is_inexact_zero() @@ -695,10 +696,10 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: F = W.fraction_field() - sage: z = F(1+w); z # indirect doctest + sage: z = F(1 + w); z # indirect doctest 1 + w + O(w^25) TESTS:: @@ -708,9 +709,9 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: f = x^51 - 34 sage: W. = R.ext(f) sage: F = W.fraction_field() - sage: z = F(1+w); z # indirect doctest + sage: z = F(1 + w); z # indirect doctest 1 + w + O(w^1530) - sage: z = F(w+w^2,relprec=0); z + sage: z = F(w + w^2, relprec=0); z O(w) """ self.ordp = ordp @@ -726,11 +727,11 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: W(70, relprec = 8) # indirect doctest + sage: W(70, relprec=8) # indirect doctest 4*w^5 + 3*w^7 + w^9 + 2*w^10 + 2*w^11 + O(w^13) - sage: W(70, relprec = 0) + sage: W(70, relprec=0) O(w^5) TESTS:: @@ -739,9 +740,9 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: S. = R[] sage: f = x^169 - 13 sage: W. = R.ext(f) - sage: a = W(65, relprec = 8); a.valuation() # indirect doctest + sage: a = W(65, relprec=8); a.valuation() # indirect doctest 169 - sage: W(65, relprec = 0) + sage: W(65, relprec=0) O(w^169) """ if mpz_sgn(x) == 0: @@ -773,11 +774,11 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: W(70, 8) # indirect doctest + sage: W(70, 8) # indirect doctest 4*w^5 + 3*w^7 + O(w^8) - sage: W(70, absprec = 4) + sage: W(70, absprec=4) O(w^4) TESTS:: @@ -786,9 +787,9 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: S. = R[] sage: f = x^49 + 7*x^21 - 14 sage: W. = R.ext(f) - sage: W(70, 100) # indirect doctest + sage: W(70, 100) # indirect doctest 5*w^49 + 6*w^70 + 3*w^91 + O(w^100) - sage: W(70, absprec = 4) + sage: W(70, absprec=4) O(w^4) """ if mpz_sgn(x) == 0: @@ -822,9 +823,9 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(70/3, relprec = 9); z # indirect doctest + sage: z = W(70/3, relprec=9); z # indirect doctest 3*w^5 + w^7 + 2*w^9 + 2*w^10 + 4*w^11 + w^12 + 2*w^13 + O(w^14) sage: z * 3 4*w^5 + 3*w^7 + w^9 + 2*w^10 + 2*w^11 + w^13 + O(w^14) @@ -835,7 +836,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): w^-10 + w^-8 + 4*w^-6 + w^-3 + 4*w^-2 + 3*w^-1 + 3 + 4*w + w^3 + 4*w^4 + w^5 + 4*w^6 + 2*w^7 + 3*w^8 + 4*w^9 + 3*w^10 + 4*w^11 + w^12 + O(w^15) sage: y * 700 3 + O(w^25) - sage: W(70/3, relprec = 0) + sage: W(70/3, relprec=0) O(w^5) sage: c = F(5^-1 + O(5^2)); c w^-5 + 3*w^-3 + 2*w^3 + 4*w^5 + 4*w^6 + 3*w^7 + w^9 + O(w^10) @@ -848,7 +849,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: S. = R[] sage: f = x^3 + 1331 * x^2 - 11 * x + 11 sage: W. = R.ext(f) - sage: z = W(77/3, relprec = 11); repr(z)[3:] + sage: z = W(77/3, relprec=11); repr(z)[3:] '304107A2555000' sage: repr(z*3)[3:] '56698765444000' @@ -884,9 +885,9 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(70/3, 14); z # indirect doctest + sage: z = W(70/3, 14); z # indirect doctest 3*w^5 + w^7 + 2*w^9 + 2*w^10 + 4*w^11 + w^12 + 2*w^13 + O(w^14) sage: z * 3 4*w^5 + 3*w^7 + w^9 + 2*w^10 + 2*w^11 + w^13 + O(w^14) @@ -897,7 +898,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): w^-10 + w^-8 + 4*w^-6 + w^-3 + O(w^-2) sage: y * 700 3 + O(w^8) - sage: W(70/3, absprec = 4) + sage: W(70/3, absprec=4) O(w^4) """ if mpq_sgn(x) == 0: @@ -920,9 +921,9 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(7000/3, 23); z # indirect doctest + sage: z = W(7000/3, 23); z # indirect doctest 2*w^15 + 2*w^17 + 3*w^19 + w^22 + O(w^23) """ cdef long num_ordp, den_ordp @@ -947,9 +948,9 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: W(QQ(0), 23) # indirect doctest + sage: W(QQ(0), 23) # indirect doctest O(w^23) sage: W(QQ(0)) 0 @@ -980,17 +981,17 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(ntl.ZZX([4,1,16]), relprec = 14); z # indirect doctest + sage: z = W(ntl.ZZX([4,1,16]), relprec=14); z # indirect doctest 4 + w + w^2 + 3*w^7 + w^9 + 2*w^11 + 4*w^13 + O(w^14) sage: z._ntl_rep() [4 1 16] - sage: z = W(ntl.ZZX([5^40,5^42,3*5^41]), relprec = 14); z + sage: z = W(ntl.ZZX([5^40,5^42,3*5^41]), relprec=14); z w^200 + 4*w^207 + 4*w^209 + w^210 + 2*w^211 + 2*w^213 + O(w^214) sage: W(5)^40 + w*W(5)^42 + w^2 * W(3) * W(5)^41 w^200 + 4*w^207 + 4*w^209 + w^210 + 2*w^211 + 2*w^213 + 2*w^215 + w^217 + 2*w^218 + w^220 + w^221 + w^222 + 3*w^224 + O(w^225) - sage: z = W(ntl.ZZX([5^40,5^42,3*5^41]), relprec = 0); z + sage: z = W(ntl.ZZX([5^40,5^42,3*5^41]), relprec=0); z O(w^200) """ if ZZX_IsZero(poly): @@ -1018,9 +1019,9 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(ntl.ZZX([4,1,16]), 12); z # indirect doctest + sage: z = W(ntl.ZZX([4,1,16]), 12); z # indirect doctest 4 + w + w^2 + 3*w^7 + w^9 + 2*w^11 + O(w^12) sage: z._ntl_rep() [4 1 16] @@ -1052,9 +1053,9 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(ntl.ZZX([4,1,16]), 12); z # indirect doctest + sage: z = W(ntl.ZZX([4,1,16]), 12); z # indirect doctest 4 + w + w^2 + 3*w^7 + w^9 + 2*w^11 + O(w^12) """ cdef long i = 0 @@ -1099,15 +1100,15 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(ntl.ZZ_pX([4,1,16],5^2)); z # indirect doctest + sage: z = W(ntl.ZZ_pX([4,1,16],5^2)); z # indirect doctest 4 + w + w^2 + 3*w^7 + w^9 + O(w^10) sage: z._ntl_rep() [4 1 16] sage: z = W(ntl.ZZ_pX([5^40,5^42,3*5^41], 5^44)); z w^200 + 4*w^207 + 4*w^209 + w^210 + 2*w^211 + 2*w^213 + 2*w^215 + w^217 + 2*w^218 + O(w^220) - sage: z = W(ntl.ZZ_pX([5^40,5^42,3*5^41], 5^44), relprec = 0); z + sage: z = W(ntl.ZZ_pX([5^40,5^42,3*5^41], 5^44), relprec=0); z O(w^200) """ cdef long ctx_prec = -1 @@ -1138,15 +1139,15 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(ntl.ZZ_pX([4,1,16],5^2), absprec = 8, relprec = 12); z # indirect doctest + sage: z = W(ntl.ZZ_pX([4,1,16],5^2), absprec=8, relprec=12); z # indirect doctest 4 + w + w^2 + 3*w^7 + O(w^8) sage: z._ntl_rep() [4 1 16] sage: z = W(ntl.ZZ_pX([5^40,5^42,3*5^41], 5^50), 220); z w^200 + 4*w^207 + 4*w^209 + w^210 + 2*w^211 + 2*w^213 + 2*w^215 + w^217 + 2*w^218 + O(w^220) - sage: z = W(ntl.ZZ_pX([5^40,5^42,3*5^41], 5^44), absprec = 77); z + sage: z = W(ntl.ZZ_pX([5^40,5^42,3*5^41], 5^44), absprec=77); z O(w^77) """ cdef long ctx_prec @@ -1172,9 +1173,9 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(ntl.ZZ_pX([4,1,16],5^2), absprec = 8, relprec = 12); z # indirect doctest + sage: z = W(ntl.ZZ_pX([4,1,16],5^2), absprec=8, relprec=12); z # indirect doctest 4 + w + w^2 + 3*w^7 + O(w^8) """ cdef long val = 0, index = 0 @@ -1193,9 +1194,9 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(ntl.ZZ_pX([4,1,16],5^2), absprec = 8, relprec = 12); z # indirect doctest + sage: z = W(ntl.ZZ_pX([4,1,16],5^2), absprec=8, relprec=12); z # indirect doctest 4 + w + w^2 + 3*w^7 + O(w^8) """ # We've set self.relprec to what is actually the absolute precision. @@ -1229,9 +1230,9 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: W(70, relprec = 8) # indirect doctest + sage: W(70, relprec=8) # indirect doctest 4*w^5 + 3*w^7 + w^9 + 2*w^10 + 2*w^11 + O(w^13) """ if self.relprec == relprec: @@ -1271,9 +1272,9 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: W(70, 8) # indirect doctest + sage: W(70, 8) # indirect doctest 4*w^5 + 3*w^7 + O(w^8) """ self.relprec = absprec - self.ordp @@ -1303,13 +1304,13 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1+w)^5 sage: y = z - 1 sage: y._ntl_rep_unnormalized() [5 3005 25 3060 5] - sage: y # indirect doctest + sage: y # indirect doctest w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 + O(w^25) sage: y._ntl_rep_unnormalized() [41 26 152 49 535] @@ -1370,11 +1371,11 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1+w)^5 sage: y = z - 1 - sage: y # indirect doctest + sage: y # indirect doctest w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 + O(w^25) """ if self.relprec == 0: @@ -1408,9 +1409,9 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Qp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(3/25, relprec = 6); z + sage: z = W(3/25, relprec=6); z 3*w^-10 + 3*w^-8 + 2*w^-6 + O(w^-4) sage: z * 25 3 + O(w^6) @@ -1481,9 +1482,9 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Qp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: w^5 + 1 # indirect doctest + sage: w^5 + 1 # indirect doctest 1 + w^5 + O(w^25) """ cdef pAdicZZpXCRElement ans = pAdicZZpXCRElement.__new__(pAdicZZpXCRElement) @@ -1507,7 +1508,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Qp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5 - 1 sage: loads(dumps(z)) == z @@ -1535,9 +1536,9 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Qp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: w == 1 # indirect doctest + sage: w == 1 # indirect doctest False sage: y = 1 + w + O(w^7) sage: z = 1 + w + w^10 + O(w^13) @@ -1563,10 +1564,10 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5 - sage: y = ~z; y # indirect doctest + sage: y = ~z; y # indirect doctest 1 + 4*w^5 + 4*w^6 + 3*w^7 + w^8 + 2*w^10 + w^11 + w^12 + 2*w^14 + 3*w^16 + 3*w^17 + 4*w^18 + 4*w^19 + 2*w^20 + 2*w^21 + 4*w^22 + 3*w^23 + 3*w^24 + O(w^25) sage: y.parent() 5-adic Eisenstein Extension Field in w defined by x^5 + 75*x^3 - 15*x^2 + 125*x - 5 @@ -1602,12 +1603,12 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5 sage: z 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 + O(w^25) - sage: z << 17 # indirect doctest + sage: z << 17 # indirect doctest w^17 + w^22 + w^23 + 2*w^24 + 4*w^25 + 3*w^27 + w^29 + 4*w^30 + 4*w^31 + 4*w^32 + 4*w^33 + 4*w^34 + 4*w^37 + w^38 + 4*w^41 + O(w^42) sage: z << (-1) w^4 + w^5 + 2*w^6 + 4*w^7 + 3*w^9 + w^11 + 4*w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^19 + w^20 + 4*w^23 + O(w^24) @@ -1636,12 +1637,12 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5 sage: z 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 + O(w^25) - sage: z << 17 # indirect doctest + sage: z << 17 # indirect doctest w^17 + w^22 + w^23 + 2*w^24 + 4*w^25 + 3*w^27 + w^29 + 4*w^30 + 4*w^31 + 4*w^32 + 4*w^33 + 4*w^34 + 4*w^37 + w^38 + 4*w^41 + O(w^42) sage: z << (-1) w^4 + w^5 + 2*w^6 + 4*w^7 + 3*w^9 + w^11 + 4*w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^19 + w^20 + 4*w^23 + O(w^24) @@ -1670,10 +1671,10 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5,print_mode='digits') sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5 - sage: for m in range(26): repr(z >> m) # indirect doctest + sage: for m in range(26): repr(z >> m) # indirect doctest '...4001400444441030421100001' '...400140044444103042110000' '...40014004444410304211000' @@ -1735,12 +1736,12 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5 sage: z 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 + O(w^25) - sage: z >> (6) # indirect doctest + sage: z >> (6) # indirect doctest 1 + 2*w + 4*w^2 + 3*w^4 + w^6 + 4*w^7 + 4*w^8 + 4*w^9 + 4*w^10 + 4*w^11 + 4*w^14 + w^15 + 4*w^18 + O(w^19) sage: z >> (-4) w^4 + w^9 + w^10 + 2*w^11 + 4*w^12 + 3*w^14 + w^16 + 4*w^17 + 4*w^18 + 4*w^19 + 4*w^20 + 4*w^21 + 4*w^24 + w^25 + 4*w^28 + O(w^29) @@ -1771,11 +1772,11 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5; z 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 + O(w^25) - sage: -z # indirect doctest + sage: -z # indirect doctest 4 + 3*w^5 + 4*w^6 + w^7 + w^8 + w^9 + w^10 + w^11 + 2*w^12 + 4*w^13 + 4*w^15 + 3*w^16 + w^17 + 2*w^18 + 3*w^19 + 2*w^21 + 4*w^23 + 4*w^24 + O(w^25) sage: y = z + (-z); y O(w^25) @@ -1855,9 +1856,9 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: (1 + w)^5 # indirect doctest + sage: (1 + w)^5 # indirect doctest 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 + O(w^25) sage: (1 + w)^-5 1 + 4*w^5 + 4*w^6 + 3*w^7 + w^8 + 2*w^10 + w^11 + w^12 + 2*w^14 + 3*w^16 + 3*w^17 + 4*w^18 + 4*w^19 + 2*w^20 + 2*w^21 + 4*w^22 + 3*w^23 + 3*w^24 + O(w^25) @@ -1892,7 +1893,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: type(W(0)) @@ -1905,7 +1906,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: type(W(0)^0) == type(W(0)) True @@ -2051,9 +2052,9 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: (4*w^5 + 3*w^7 + w^9 + 2*w^10 + 2*w^11 + O(w^13)) - 69 # indirect doctest + sage: (4*w^5 + 3*w^7 + w^9 + 2*w^10 + 2*w^11 + O(w^13)) - 69 # indirect doctest 1 + O(w^13) sage: -69 + (4*w^5 + 3*w^7 + w^9 + 2*w^10 + 2*w^11 + O(w^13)) 1 + O(w^13) @@ -2168,11 +2169,11 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(329) sage: b = W(111) - sage: a - b #indirect doctest + sage: a - b # indirect doctest 3 + 3*w^5 + w^7 + 2*w^9 + 3*w^10 + 4*w^11 + 2*w^13 + 2*w^14 + w^15 + 4*w^16 + 2*w^18 + 3*w^19 + 2*w^20 + 3*w^21 + w^22 + w^24 + O(w^25) sage: W(218) 3 + 3*w^5 + w^7 + 2*w^9 + 3*w^10 + 4*w^11 + 2*w^13 + 2*w^14 + w^15 + 4*w^16 + 2*w^18 + 3*w^19 + 2*w^20 + 3*w^21 + w^22 + w^24 + O(w^25) @@ -2194,11 +2195,11 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(329) sage: b = W(111) - sage: a*b #indirect doctest + sage: a*b # indirect doctest 4 + 3*w^5 + w^7 + 2*w^9 + 4*w^11 + 3*w^12 + 2*w^13 + w^14 + 2*w^15 + 3*w^16 + 4*w^17 + 4*w^18 + 2*w^19 + 2*w^21 + 4*w^22 + 2*w^23 + w^24 + O(w^25) sage: a * 0 0 @@ -2247,9 +2248,9 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: W(14) / W(125) #indirect doctest + sage: W(14) / W(125) # indirect doctest 4*w^-15 + w^-13 + 3*w^-11 + 2*w^-10 + 3*w^-9 + 4*w^-8 + 4*w^-7 + 3*w^-6 + 2*w^-5 + 4*w^-4 + 3*w^-3 + 2*w^-2 + 4*w^-1 + 2 + w^2 + w^4 + 4*w^5 + w^6 + w^7 + 3*w^9 + O(w^10) sage: 1 / w w^-1 + O(w^24) @@ -2277,7 +2278,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: b = W(45, 17); b 4*w^5 + 3*w^7 + w^9 + w^10 + 2*w^11 + w^12 + w^13 + 3*w^14 + w^16 + O(w^17) @@ -2298,7 +2299,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): EXAMPLES:: - sage: ZZ(ZqCR(125,names='a')(-1)) #indirect doctest + sage: ZZ(ZqCR(125,names='a')(-1)) # indirect doctest 95367431640624 sage: R = Zp(5); S. = ZZ[]; f = x^5 + 25*x^3 - 5; W. = R.ext(f) sage: ZZ(W(-1)) @@ -2311,7 +2312,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): Traceback (most recent call last): ... ValueError: this element not well approximated by an integer - sage: ZZ(W(5)) # todo: this should be different... + sage: ZZ(W(5)) # todo: this should be different... 381469726562505 """ cdef Integer ans @@ -2344,7 +2345,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: O(w^189).is_zero() True @@ -2394,7 +2395,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(566); b = W(209) sage: c = a + b; c._ntl_rep_unnormalized() @@ -2420,7 +2421,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(566); b = W(209) sage: c = a + b; c._ntl_rep() @@ -2442,7 +2443,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(566); b = W(209) sage: c = a + b; c._ntl_rep_abs() @@ -2511,7 +2512,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): EXAMPLES:: sage: R. = ZZ[] - sage: W. = Qp(5).extension(x^3-5) + sage: W. = Qp(5).extension(x^3 - 5) sage: (1 + w + O(w^11))._polynomial_list() [1 + O(5^4), 1 + O(5^4)] sage: (1 + w + O(w^11))._polynomial_list(pad=True) @@ -2524,7 +2525,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): [] sage: W(O(w^7))._polynomial_list(pad=True) [O(5^3), O(5^2), O(5^2)] - sage: T. = Qp(5).extension(x^2-5) + sage: T. = Qp(5).extension(x^2 - 5) sage: T(1/5)._polynomial_list() [5^-1 + O(5^19)] sage: T(a^-800)._polynomial_list() @@ -2581,10 +2582,10 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(566) - sage: a._const_term_test() #indirect doctest + sage: a._const_term_test() # indirect doctest 566 """ return ZZ_pX_ConstTerm((self).unit) @@ -2600,7 +2601,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(47); b = W(47 + 25) sage: a.is_equal_to(b) @@ -2643,7 +2644,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(345, 17); a 4*w^5 + 3*w^7 + w^9 + 3*w^10 + 2*w^11 + 4*w^12 + w^13 + 2*w^14 + 2*w^15 + O(w^17) @@ -2742,7 +2743,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: y = W(775, 19); y w^10 + 4*w^12 + 2*w^14 + w^15 + 2*w^16 + 4*w^17 + w^18 + O(w^19) @@ -2838,7 +2839,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = ZpCR(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = (3+w)^7 sage: a.matrix_mod_pn() @@ -3084,7 +3085,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(75, 19); a 3*w^10 + 2*w^12 + w^14 + w^16 + w^17 + 3*w^18 + O(w^19) @@ -3119,7 +3120,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(75, 19); a 3*w^10 + 2*w^12 + w^14 + w^16 + w^17 + 3*w^18 + O(w^19) @@ -3151,11 +3152,11 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(75, 19); a 3*w^10 + 2*w^12 + w^14 + w^16 + w^17 + 3*w^18 + O(w^19) - sage: a.valuation() # indirect doctest + sage: a.valuation() # indirect doctest 10 sage: a.precision_absolute() 19 @@ -3175,7 +3176,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(75, 19); a 3*w^10 + 2*w^12 + w^14 + w^16 + w^17 + 3*w^18 + O(w^19) @@ -3194,7 +3195,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: z = (1+w)^5 sage: y = z - 1 - sage: t=y-y + sage: t = y - y sage: t.unit_part() O(w^0) """ @@ -3224,7 +3225,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: y = W(775, 19); y w^10 + 4*w^12 + 2*w^14 + w^15 + 2*w^16 + 4*w^17 + w^18 + O(w^19) @@ -3256,11 +3257,11 @@ def make_ZZpXCRElement(parent, unit, ordp, relprec, version): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: y = W(775, 19); y w^10 + 4*w^12 + 2*w^14 + w^15 + 2*w^16 + 4*w^17 + w^18 + O(w^19) - sage: loads(dumps(y)) #indirect doctest + sage: loads(dumps(y)) # indirect doctest w^10 + 4*w^12 + 2*w^14 + w^15 + 2*w^16 + 4*w^17 + w^18 + O(w^19) sage: from sage.rings.padics.padic_ZZ_pX_CR_element import make_ZZpXCRElement diff --git a/src/sage/rings/padics/padic_ZZ_pX_FM_element.pyx b/src/sage/rings/padics/padic_ZZ_pX_FM_element.pyx index 70d09266445..e3785c4adff 100644 --- a/src/sage/rings/padics/padic_ZZ_pX_FM_element.pyx +++ b/src/sage/rings/padics/padic_ZZ_pX_FM_element.pyx @@ -4,6 +4,7 @@ # distutils: library_dirs = NTL_LIBDIR # distutils: extra_link_args = NTL_LIBEXTRA # distutils: language = c++ +# sage.doctest: needs sage.rings.padics r""" `p`-adic ``ZZ_pX`` FM Element @@ -65,7 +66,7 @@ An Eisenstein extension:: sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f); W 5-adic Eisenstein Extension Ring in w defined by x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: z = (1+w)^5; z @@ -83,6 +84,7 @@ An Eisenstein extension:: An unramified extension:: + sage: # needs sage.libs.flint sage: g = x^3 + 3*x + 3 sage: A. = R.ext(g) sage: z = (1+a)^5; z @@ -96,6 +98,7 @@ An unramified extension:: Different printing modes:: + sage: # needs sage.libs.flint sage: R = ZpFM(5, print_mode='digits'); S. = R[]; f = x^5 + 75*x^3 - 15*x^2 + 125*x -5; W. = R.ext(f) sage: z = (1+w)^5; repr(z) '...4110403113210310442221311242000111011201102002023303214332011214403232013144001400444441030421100001' @@ -173,9 +176,9 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = (1+w)^5; z # indirect doctest + sage: z = (1+w)^5; z # indirect doctest 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 TESTS: @@ -187,9 +190,10 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): Check that :trac:`13612` has been fixed:: + sage: # needs sage.libs.flint sage: R = ZpFM(3) sage: S. = R[] - sage: W. = R.extension(a^2+1) + sage: W. = R.extension(a^2 + 1) sage: W(W.residue_field().zero()) 0 @@ -285,9 +289,9 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: W(70) # indirect doctest + sage: W(70) # indirect doctest 4*w^5 + 3*w^7 + w^9 + 2*w^10 + 2*w^11 + w^13 + 3*w^16 + w^17 + w^18 + 4*w^20 + 4*w^21 + w^22 + 2*w^23 """ self.prime_pow.restore_top_context() @@ -309,9 +313,9 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(70/3); z # indirect doctest + sage: z = W(70/3); z # indirect doctest 3*w^5 + w^7 + 2*w^9 + 2*w^10 + 4*w^11 + w^12 + 2*w^13 + 3*w^15 + 2*w^16 + 3*w^17 + w^18 + 3*w^19 + 3*w^20 + 2*w^21 + 2*w^22 + 3*w^23 + 4*w^24 sage: z * 3 @@ -343,9 +347,9 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(ntl.ZZ_pX([4,1,16],5^2)); z # indirect doctest + sage: z = W(ntl.ZZ_pX([4,1,16],5^2)); z # indirect doctest 4 + w + w^2 + 3*w^7 + w^9 + 2*w^11 + 4*w^13 + 3*w^14 + 2*w^15 + w^16 + 3*w^18 + 2*w^19 + 4*w^20 + 4*w^21 + 2*w^22 + 2*w^23 + 4*w^24 sage: z._ntl_rep() @@ -364,9 +368,9 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(ntl.ZZX([4,1,16])); z # indirect doctest + sage: z = W(ntl.ZZX([4,1,16])); z # indirect doctest 4 + w + w^2 + 3*w^7 + w^9 + 2*w^11 + 4*w^13 + 3*w^14 + 2*w^15 + w^16 + 3*w^18 + 2*w^19 + 4*w^20 + 4*w^21 + 2*w^22 + 2*w^23 + 4*w^24 sage: z._ntl_rep() @@ -383,7 +387,7 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = W(0) sage: z._is_inexact_zero() @@ -403,10 +407,10 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5 - 1 - sage: loads(dumps(z)) == z #indirect doctest + sage: loads(dumps(z)) == z # indirect doctest True """ self.prime_pow.restore_top_context() @@ -423,9 +427,9 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: w^5 + 1 # indirect doctest + sage: w^5 + 1 # indirect doctest 1 + w^5 """ self.prime_pow.restore_top_context() @@ -442,9 +446,9 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: w == 1 # indirect doctest + sage: w == 1 # indirect doctest False sage: y = 1 + w sage: z = 1 + w + w^27 @@ -479,10 +483,10 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5 - sage: y = ~z; y # indirect doctest + sage: y = ~z; y # indirect doctest 1 + 4*w^5 + 4*w^6 + 3*w^7 + w^8 + 2*w^10 + w^11 + w^12 + 2*w^14 + 3*w^16 + 3*w^17 + 4*w^18 + 4*w^19 + 2*w^20 + 2*w^21 + 4*w^22 + 3*w^23 + 3*w^24 sage: y.parent() @@ -514,12 +518,12 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5 sage: z 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 - sage: z << 17 # indirect doctest + sage: z << 17 # indirect doctest w^17 + w^22 + w^23 + 2*w^24 sage: z << (-1) w^4 + w^5 + 2*w^6 + 4*w^7 + 3*w^9 + w^11 + 4*w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^19 + w^20 + 4*w^23 + 4*w^24 @@ -546,12 +550,12 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5 sage: z 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 - sage: z << 17 # indirect doctest + sage: z << 17 # indirect doctest w^17 + w^22 + w^23 + 2*w^24 sage: z << (-1) w^4 + w^5 + 2*w^6 + 4*w^7 + 3*w^9 + w^11 + 4*w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^19 + w^20 + 4*w^23 + 4*w^24 @@ -577,10 +581,10 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5,print_mode='digits') sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5 - sage: for m in range(26): '...' + repr(z >> m)[len(repr(z >> m)) - 25 + m:] # indirect doctest + sage: for m in range(26): '...' + repr(z >> m)[len(repr(z >> m)) - 25 + m:] # indirect doctest '...4001400444441030421100001' '...400140044444103042110000' '...40014004444410304211000' @@ -635,13 +639,13 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5 sage: z 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 - sage: z >> (6) # indirect doctest + sage: z >> (6) # indirect doctest 1 + 2*w + 4*w^2 + 3*w^4 + w^6 + 4*w^7 + 4*w^8 + 4*w^9 + 4*w^10 + 4*w^11 + 4*w^14 + w^15 + 4*w^18 + 4*w^19 + 2*w^20 + 3*w^21 + 2*w^22 + 3*w^24 sage: z >> (-4) @@ -664,12 +668,12 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5; z 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 - sage: -z # indirect doctest + sage: -z # indirect doctest 4 + 3*w^5 + 4*w^6 + w^7 + w^8 + w^9 + w^10 + w^11 + 2*w^12 + 4*w^13 + 4*w^15 + 3*w^16 + w^17 + 2*w^18 + 3*w^19 + 2*w^21 + 4*w^23 + 4*w^24 sage: y = z + (-z); y @@ -689,9 +693,9 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: (1 + w)^5 # indirect doctest + sage: (1 + w)^5 # indirect doctest 1 + w^5 + w^6 + 2*w^7 + 4*w^8 + 3*w^10 + w^12 + 4*w^13 + 4*w^14 + 4*w^15 + 4*w^16 + 4*w^17 + 4*w^20 + w^21 + 4*w^24 sage: (1 + w)^-5 @@ -704,7 +708,7 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: type(W(0)) @@ -717,7 +721,7 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: type(W(0)^0) == type(W(0)) True @@ -755,9 +759,9 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: (4*w^5 + 3*w^7 + w^9 + 2*w^10 + 2*w^11) - 69 # indirect doctest + sage: (4*w^5 + 3*w^7 + w^9 + 2*w^10 + 2*w^11) - 69 # indirect doctest 1 + 4*w^13 + 2*w^16 + 4*w^17 + 3*w^18 + 4*w^20 + 4*w^22 sage: -69 + (4*w^5 + 3*w^7 + w^9 + 2*w^10 + 2*w^11) 1 + 4*w^13 + 2*w^16 + 4*w^17 + 3*w^18 + 4*w^20 + 4*w^22 @@ -774,11 +778,11 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(329) sage: b = W(111) - sage: a*b #indirect doctest + sage: a*b # indirect doctest 4 + 3*w^5 + w^7 + 2*w^9 + 4*w^11 + 3*w^12 + 2*w^13 + w^14 + 2*w^15 + 3*w^16 + 4*w^17 + 4*w^18 + 2*w^19 + 2*w^21 + 4*w^22 + 2*w^23 + w^24 sage: a * 0 @@ -798,11 +802,11 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(329) sage: b = W(111) - sage: a - b #indirect doctest + sage: a - b # indirect doctest 3 + 3*w^5 + w^7 + 2*w^9 + 3*w^10 + 4*w^11 + 2*w^13 + 2*w^14 + w^15 + 4*w^16 + 2*w^18 + 3*w^19 + 2*w^20 + 3*w^21 + w^22 + w^24 sage: W(218) @@ -823,9 +827,9 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: W(125) / W(14) #indirect doctest + sage: W(125) / W(14) # indirect doctest 4*w^15 + 4*w^17 + w^19 + w^20 + w^23 + 2*w^24 sage: 1 / W(14) == ~W(14) True @@ -863,7 +867,7 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: b = W(45); b 4*w^5 + 3*w^7 + w^9 + w^10 + 2*w^11 + w^12 + w^13 + 3*w^14 + w^16 @@ -888,7 +892,7 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: O(w^189).is_zero() True @@ -934,8 +938,8 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): EXAMPLES:: - sage: R=Zp(7,4,'fixed-mod') - sage: a = R(1+7+7^2) + sage: R = Zp(7,4,'fixed-mod') + sage: a = R(1 + 7 + 7^2) sage: a.add_bigoh(1) 1 """ @@ -971,7 +975,8 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): EXAMPLES:: - sage: ZZ(ZqFM(125,names='a')(-1)) #indirect doctest + sage: # needs sage.libs.flint + sage: ZZ(ZqFM(125,names='a')(-1)) # indirect doctest 95367431640624 sage: R = ZpFM(5); S. = ZZ[]; f = x^5 + 25*x^3 - 5; W. = R.ext(f) sage: ZZ(W(-1)) @@ -1011,10 +1016,10 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = (3+w)^7 - sage: a.matrix_mod_pn() + sage: a.matrix_mod_pn() # needs sage.geometry.polyhedron [2757 333 1068 725 2510] [ 50 1507 483 318 725] [ 500 50 3007 2358 318] @@ -1078,7 +1083,7 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpCR(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: ((1+2*w)^5).norm() 1 + 5^2 + O(5^5) @@ -1110,7 +1115,7 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpCR(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = (2+3*w)^7 sage: b = (6+w^3)^5 @@ -1144,7 +1149,7 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = 72 + 4*w^2; b = 17 + 9*w + w^3; c = a + b sage: c._ntl_rep() @@ -1169,7 +1174,7 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): EXAMPLES:: sage: R. = ZZ[] - sage: W. = ZpFM(5).extension(x^3-5) + sage: W. = ZpFM(5).extension(x^3 - 5) sage: (1 + w)._polynomial_list() [1, 1] sage: (1 + w + O(w^11))._polynomial_list(pad=True) @@ -1217,10 +1222,10 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(566) - sage: a._const_term_test() #indirect doctest + sage: a._const_term_test() # indirect doctest 566 """ return ZZ_pX_ConstTerm(self.value) @@ -1237,7 +1242,7 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(47); b = W(47 + 25) sage: a.is_equal_to(b) @@ -1264,7 +1269,7 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: w.lift_to_precision(10000) w @@ -1310,7 +1315,7 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: y = W(775); y w^10 + 4*w^12 + 2*w^14 + w^15 + 2*w^16 + 4*w^17 + w^18 + w^20 + 2*w^21 + 3*w^22 + w^23 + w^24 @@ -1321,6 +1326,8 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: w^10 - w^12 + 2*w^14 + w^15 + 2*w^16 + w^18 + 2*w^19 + w^20 + w^21 - w^22 - w^23 + 2*w^24 w^10 + 4*w^12 + 2*w^14 + w^15 + 2*w^16 + 4*w^17 + w^18 + w^20 + 2*w^21 + 3*w^22 + w^23 + w^24 sage: g = x^3 + 3*x + 3 + + sage: # needs sage.libs.flint sage: A. = R.ext(g) sage: y = 75 + 45*a + 1200*a^2; y 4*a*5 + (3*a^2 + a + 3)*5^2 + 4*a^2*5^3 + a^2*5^4 @@ -1393,6 +1400,7 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): EXAMPLES:: + sage: # needs sage.libs.flint sage: R. = ZqFM(5^4,4) sage: E = a.teichmuller_expansion(); E 5-adic expansion of a (teichmuller) @@ -1488,13 +1496,15 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: y = W.teichmuller(3); y #indirect doctest + sage: y = W.teichmuller(3); y # indirect doctest 3 + 3*w^5 + w^7 + 2*w^9 + 2*w^10 + 4*w^11 + w^12 + 2*w^13 + 3*w^15 + 2*w^16 + 3*w^17 + w^18 + 3*w^19 + 3*w^20 + 2*w^21 + 2*w^22 + 3*w^23 + 4*w^24 sage: y^5 == y True + + sage: # needs sage.libs.flint sage: g = x^3 + 3*x + 3 sage: A. = R.ext(g) sage: b = A.teichmuller(1 + 2*a - a^2); b @@ -1546,7 +1556,7 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(75); a 3*w^10 + 2*w^12 + w^14 + w^16 + w^17 + 3*w^18 + 3*w^19 + 2*w^21 + 3*w^22 + 3*w^23 @@ -1573,7 +1583,7 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(75); a 3*w^10 + 2*w^12 + w^14 + w^16 + w^17 + 3*w^18 + 3*w^19 + 2*w^21 + 3*w^22 + 3*w^23 @@ -1607,7 +1617,7 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(75); a 3*w^10 + 2*w^12 + w^14 + w^16 + w^17 + 3*w^18 + 3*w^19 + 2*w^21 + 3*w^22 + 3*w^23 @@ -1637,7 +1647,7 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(75); a 3*w^10 + 2*w^12 + w^14 + w^16 + w^17 + 3*w^18 + 3*w^19 + 2*w^21 + 3*w^22 + 3*w^23 @@ -1691,23 +1701,25 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: y = W(775); y w^10 + 4*w^12 + 2*w^14 + w^15 + 2*w^16 + 4*w^17 + w^18 + w^20 + 2*w^21 + 3*w^22 + w^23 + w^24 - sage: (y>>9).expansion() #indirect doctest + sage: (y>>9).expansion() # indirect doctest [0, 1, 0, 4, 0, 2, 1, 2, 4, 1, 0, 1, 2, 3, 1, 1, 4, 1, 2, 4, 1, 0, 0, 3] - sage: (y>>9).expansion(lift_mode='smallest') #indirect doctest + sage: (y>>9).expansion(lift_mode='smallest') # indirect doctest [0, 1, 0, -1, 0, 2, 1, 2, 0, 1, 2, 1, 1, -1, -1, 2, -2, 0, -2, -2, -2, 0, -2, -2, 2] sage: w^10 - w^12 + 2*w^14 + w^15 + 2*w^16 + w^18 + 2*w^19 + w^20 + w^21 - w^22 - w^23 + 2*w^24 w^10 + 4*w^12 + 2*w^14 + w^15 + 2*w^16 + 4*w^17 + w^18 + w^20 + 2*w^21 + 3*w^22 + w^23 + w^24 sage: g = x^3 + 3*x + 3 + + sage: # needs sage.libs.flint sage: A. = R.ext(g) sage: y = 75 + 45*a + 1200*a^2; y 4*a*5 + (3*a^2 + a + 3)*5^2 + 4*a^2*5^3 + a^2*5^4 - sage: list(y.expansion()) #indirect doctest + sage: list(y.expansion()) # indirect doctest [[], [0, 4], [3, 1, 3], [0, 0, 4], [0, 0, 1]] - sage: list(y.expansion(lift_mode='smallest')) #indirect doctest + sage: list(y.expansion(lift_mode='smallest')) # indirect doctest [[], [0, -1], [-2, 2, -2], [1], [0, 0, 2]] sage: 5*((-2*5 + 25) + (-1 + 2*5)*a + (-2*5 + 2*125)*a^2) 4*a*5 + (3*a^2 + a + 3)*5^2 + 4*a^2*5^3 + a^2*5^4 @@ -1724,10 +1736,10 @@ def make_ZZpXFMElement(parent, f): sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: z = (1 + w)^5 - 1 - sage: loads(dumps(z)) == z # indirect doctest + sage: loads(dumps(z)) == z # indirect doctest True """ return pAdicZZpXFMElement(parent, f) diff --git a/src/sage/rings/padics/padic_ZZ_pX_element.pyx b/src/sage/rings/padics/padic_ZZ_pX_element.pyx index 81a6cd1e28c..b3f57329e8f 100644 --- a/src/sage/rings/padics/padic_ZZ_pX_element.pyx +++ b/src/sage/rings/padics/padic_ZZ_pX_element.pyx @@ -4,6 +4,7 @@ # distutils: library_dirs = NTL_LIBDIR # distutils: extra_link_args = NTL_LIBEXTRA # distutils: language = c++ +# sage.doctest: needs sage.rings.padics r""" `p`-adic ``ZZ_pX Element`` @@ -60,7 +61,7 @@ cdef class pAdicZZpXElement(pAdicExtElement): sage: A = Zp(next_prime(50000),10) sage: S. = A[] - sage: B. = A.ext(x^2+next_prime(50000)) #indirect doctest + sage: B. = A.ext(x^2 + next_prime(50000)) # indirect doctest """ self.prime_pow = parent.prime_pow pAdicExtElement.__init__(self, parent) @@ -81,7 +82,7 @@ cdef class pAdicZZpXElement(pAdicExtElement): sage: R = ZpFM(5,5) sage: S. = ZZ[] sage: W. = R.ext(x^5 + 25*x^3 - 15*x - 5) - sage: W([1,2,3,4]) #indirect doctest + sage: W([1,2,3,4]) # indirect doctest 1 + 2*w + 3*w^2 + 4*w^3 sage: W([5,10,15,20]) w^5 + 4*w^6 + w^7 + w^8 + 2*w^9 + 4*w^10 + 2*w^11 + 3*w^13 + 2*w^15 + w^16 + 2*w^17 + 2*w^18 + w^19 + 4*w^20 + w^21 + 4*w^22 + 4*w^23 + 2*w^24 @@ -113,7 +114,7 @@ cdef class pAdicZZpXElement(pAdicExtElement): sage: R = Zp(5,5) sage: S. = ZZ[] sage: W. = R.ext(x^5 + 25*x^3 - 15*x - 5) - sage: W([1,2,3,4]) #indirect doctest + sage: W([1,2,3,4]) # indirect doctest 1 + 2*w + 3*w^2 + 4*w^3 + O(w^25) sage: W([5,10,15,20], relprec=16) w^5 + 4*w^6 + w^7 + w^8 + 2*w^9 + 4*w^10 + 2*w^11 + 3*w^13 + 2*w^15 + w^16 + 2*w^17 + 2*w^18 + w^19 + 4*w^20 + O(w^21) @@ -145,7 +146,7 @@ cdef class pAdicZZpXElement(pAdicExtElement): sage: W. = R.ext(x^5 + 25*x^3 - 15*x - 5) sage: W([1,2,3,4]) 1 + 2*w + 3*w^2 + 4*w^3 + O(w^25) - sage: W([5,10,15,20], absprec=16) #indirect doctest + sage: W([5,10,15,20], absprec=16) # indirect doctest w^5 + 4*w^6 + w^7 + w^8 + 2*w^9 + 4*w^10 + 2*w^11 + 3*w^13 + 2*w^15 + O(w^16) """ @@ -180,12 +181,12 @@ cdef class pAdicZZpXElement(pAdicExtElement): sage: W. = R.ext(x^5 + 25*x^3 - 15*x - 5) sage: W([1,2,3,4]) 1 + 2*w + 3*w^2 + 4*w^3 + O(w^25) - sage: W([5,10,15,20], absprec=16) #indirect doctest + sage: W([5,10,15,20], absprec=16) # indirect doctest w^5 + 4*w^6 + w^7 + w^8 + 2*w^9 + 4*w^10 + 2*w^11 + 3*w^13 + 2*w^15 + O(w^16) - sage: T. = Qp(5).extension(x^2-5) + sage: T. = Qp(5).extension(x^2 - 5) sage: T([5^-2], absprec=-1) a^-4 + O(a^-1) - sage: G. = Qp(5).extension(x^2-5) + sage: G. = Qp(5).extension(x^2 - 5) sage: G(a^-41) g^-41 + O(g^-2) """ @@ -215,9 +216,9 @@ cdef class pAdicZZpXElement(pAdicExtElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: z = W(ntl.ZZ_pX([4,1,16],5^2)); z # indirect doctest + sage: z = W(ntl.ZZ_pX([4,1,16],5^2)); z # indirect doctest 4 + w + w^2 + 3*w^7 + w^9 + O(w^10) """ cdef ZZ_c leftover @@ -268,11 +269,11 @@ cdef class pAdicZZpXElement(pAdicExtElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: y = W(775, 19); y w^10 + 4*w^12 + 2*w^14 + w^15 + 2*w^16 + 4*w^17 + w^18 + O(w^19) - sage: y._ext_p_list(True) #indirect doctest + sage: y._ext_p_list(True) # indirect doctest [1, 0, 4, 0, 2, 1, 2, 4, 1] sage: y._ext_p_list(False) [1, 0, -1, 0, 2, 1, 2, 0, 1] @@ -373,7 +374,7 @@ cdef class pAdicZZpXElement(pAdicExtElement): sage: R = ZpCR(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: ((1+2*w)^5).norm() 1 + 5^2 + O(5^5) @@ -384,19 +385,19 @@ cdef class pAdicZZpXElement(pAdicExtElement): sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: ((1+2*w)^5).norm() + sage: ((1+2*w)^5).norm() # needs sage.geometry.polyhedron 1 + 5^2 + O(5^5) - sage: ((1+2*w)).norm()^5 + sage: ((1+2*w)).norm()^5 # needs sage.geometry.polyhedron 1 + 5^2 + O(5^5) sage: R = ZpFM(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) - sage: ((1+2*w)^5).norm() + sage: ((1+2*w)^5).norm() # needs sage.geometry.polyhedron 1 + 5^2 - sage: ((1+2*w)).norm()^5 + sage: ((1+2*w)).norm()^5 # needs sage.geometry.polyhedron 1 + 5^2 Check that :trac:`11586` has been resolved:: @@ -445,7 +446,7 @@ cdef class pAdicZZpXElement(pAdicExtElement): sage: R = ZpCR(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = (2+3*w)^7 sage: b = (6+w^3)^5 @@ -458,9 +459,10 @@ cdef class pAdicZZpXElement(pAdicExtElement): TESTS:: + sage: # needs sage.geometry.polyhedron sage: R = ZpCA(5,5) sage: S. = ZZ[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = (2+3*w)^7 sage: b = (6+w^3)^5 @@ -472,7 +474,7 @@ cdef class pAdicZZpXElement(pAdicExtElement): 4*5 + 5^2 + 5^3 + 2*5^4 + O(5^5) sage: R = ZpFM(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = (2+3*w)^7 sage: b = (6+w^3)^5 @@ -518,7 +520,7 @@ cdef class pAdicZZpXElement(pAdicExtElement): EXAMPLES:: - sage: QQ(Qq(125,names='a')(-1/5)) #indirect doctest + sage: QQ(Qq(125,names='a')(-1/5)) # indirect doctest -1/5 """ if self.valuation() < 0: @@ -535,7 +537,7 @@ cdef class pAdicZZpXElement(pAdicExtElement): sage: R = ZpCR(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: w._prime_pow() PowComputer_ext for 5, with polynomial [3120 125 3110 75 0 1] @@ -550,12 +552,12 @@ cdef class pAdicZZpXElement(pAdicExtElement): Check that :trac:`13647` has been fixed:: + sage: # needs sage.libs.flint sage: K = ZpCA(3) sage: R. = K[] sage: L. = K.extension(u^2 + 1) sage: L(R.gen()) u + O(3^20) - sage: K = ZpFM(3) sage: R. = K[] sage: L. = K.extension(u^2 + 1) @@ -820,7 +822,7 @@ def _test_get_val_prec(R, a): TESTS:: - sage: _test_get_val_prec(Zq(25,names='a',implementation="NTL"), 0) #indirect doctest + sage: _test_get_val_prec(Zq(25,names='a',implementation="NTL"), 0) # indirect doctest (340282366920938463463374607431768211457, 340282366920938463463374607431768211457, 2) sage: _test_get_val_prec(Zq(25,names='a',implementation="NTL"), ntl_ZZ(0)) (340282366920938463463374607431768211457, 340282366920938463463374607431768211457, 2) diff --git a/src/sage/rings/padics/padic_base_generic.py b/src/sage/rings/padics/padic_base_generic.py index 6fb5f464a7f..792e99996c5 100644 --- a/src/sage/rings/padics/padic_base_generic.py +++ b/src/sage/rings/padics/padic_base_generic.py @@ -40,7 +40,7 @@ def __init__(self, p, prec, print_mode, names, element_class): TESTS:: - sage: R = Zp(5) #indirect doctest + sage: R = Zp(5) # indirect doctest """ if self.is_relaxed(): from sage.rings.padics.pow_computer_flint import PowComputer_flint @@ -92,21 +92,21 @@ def _repr_(self, do_latex=False): EXAMPLES:: - sage: K = Zp(17); K #indirect doctest + sage: K = Zp(17); K # indirect doctest 17-adic Ring with capped relative precision 20 sage: latex(K) \Bold{Z}_{17} - sage: K = ZpCA(17); K #indirect doctest + sage: K = ZpCA(17); K # indirect doctest 17-adic Ring with capped absolute precision 20 sage: latex(K) \Bold{Z}_{17} - sage: K = ZpFP(17); K #indirect doctest + sage: K = ZpFP(17); K # indirect doctest 17-adic Ring with floating precision 20 sage: latex(K) \Bold{Z}_{17} sage: K = ZpFM(7); K 7-adic Ring of fixed modulus 7^20 - sage: latex(K) #indirect doctest + sage: latex(K) # indirect doctest \Bold{Z}_{7} sage: K = ZpLF(2); K # indirect doctest doctest:...: FutureWarning: This class/method/function is marked as experimental. It, its functionality or its interface might change without a formal deprecation. @@ -114,11 +114,11 @@ def _repr_(self, do_latex=False): 2-adic Ring with lattice-float precision sage: latex(K) \Bold{Z}_{2} - sage: K = Qp(17); K #indirect doctest + sage: K = Qp(17); K # indirect doctest 17-adic Field with capped relative precision 20 sage: latex(K) \Bold{Q}_{17} - sage: K = QpFP(17); K #indirect doctest + sage: K = QpFP(17); K # indirect doctest 17-adic Field with floating precision 20 sage: latex(K) \Bold{Q}_{17} diff --git a/src/sage/rings/padics/padic_base_leaves.py b/src/sage/rings/padics/padic_base_leaves.py index 1c47b0083c2..4f48c187efc 100644 --- a/src/sage/rings/padics/padic_base_leaves.py +++ b/src/sage/rings/padics/padic_base_leaves.py @@ -163,17 +163,17 @@ class names.:: sage: R = Qp(5, 15, print_mode='bars', print_sep='&') sage: repr(R(2777))[3:] '0&0&0&0&0&0&0&0&0&0&4&2&1&0&2' - sage: TestSuite(R).run() + sage: TestSuite(R).run() # needs sage.geometry.polyhedron sage: R = Zp(5, 15, print_mode='bars', print_sep='&') sage: repr(R(2777))[3:] '0&0&0&0&0&0&0&0&0&0&4&2&1&0&2' - sage: TestSuite(R).run() + sage: TestSuite(R).run() # needs sage.geometry.polyhedron sage: R = ZpCA(5, 15, print_mode='bars', print_sep='&') sage: repr(R(2777))[3:] '0&0&0&0&0&0&0&0&0&0&4&2&1&0&2' - sage: TestSuite(R).run() + sage: TestSuite(R).run() # needs sage.geometry.polyhedron """ @@ -225,27 +225,28 @@ def __init__(self, p, prec, print_mode, names): EXAMPLES:: - sage: R = ZpCR(next_prime(10^60)) #indirect doctest + sage: R = ZpCR(next_prime(10^60)) # indirect doctest sage: type(R) TESTS:: + sage: # needs sage.geometry.polyhedron sage: R = ZpCR(2) sage: TestSuite(R).run() - sage: TestSuite(R).run(elements = [R.random_element() for i in range(2^10)], max_runs = 2^12, skip='_test_metric_function') # long time - sage: R._test_metric_function(elements = [R.random_element() for i in range(2^3)]) # long time - + sage: TestSuite(R).run(elements=[R.random_element() for i in range(2^10)], # long time + ....: max_runs=2^12, skip='_test_metric_function') + sage: R._test_metric_function(elements=[R.random_element() for i in range(2^3)]) # long time sage: R = ZpCR(3, 1) - sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^3)]) - + sage: TestSuite(R).run(elements=[R.random_element() for i in range(3^3)]) sage: R = ZpCR(3, 2) - sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^6)], skip='_test_metric_function') # long time - sage: R._test_metric_function(elements = [R.random_element() for i in range(2^3)]) # long time - + sage: TestSuite(R).run(elements=[R.random_element() for i in range(3^6)], # long time + ....: skip='_test_metric_function') + sage: R._test_metric_function(elements=[R.random_element() for i in range(2^3)]) # long time sage: R = ZpCR(next_prime(10^60)) - sage: TestSuite(R).run(elements = [R.random_element() for i in range(2^3)], max_runs = 2^5, skip='_test_log') # long time - sage: R._test_log(max_runs=2, elements=[R.random_element() for i in range(4)]) # long time + sage: TestSuite(R).run(elements=[R.random_element() for i in range(2^3)], # long time + ....: max_runs=2^5, skip='_test_log') + sage: R._test_log(max_runs=2, elements=[R.random_element() for i in range(4)]) # long time """ pAdicRingBaseGeneric.__init__(self, p, prec, print_mode, names, pAdicCappedRelativeElement) @@ -256,7 +257,7 @@ def _coerce_map_from_(self, R): EXAMPLES:: sage: K = Zp(17) - sage: K(1) + 1 #indirect doctest + sage: K(1) + 1 # indirect doctest 2 + O(17^20) sage: K.has_coerce_map_from(ZZ) True @@ -304,6 +305,7 @@ def _convert_map_from_(self, R): from sage.rings.padics.padic_generic import ResidueLiftingMap return ResidueLiftingMap._create_(R, self) + class pAdicRingCappedAbsolute(pAdicRingBaseGeneric, pAdicCappedAbsoluteRingGeneric): r""" An implementation of the `p`-adic integers with capped absolute precision. @@ -321,26 +323,27 @@ def __init__(self, p, prec, print_mode, names): EXAMPLES:: - sage: R = ZpCA(next_prime(10^60)) #indirect doctest + sage: R = ZpCA(next_prime(10^60)) # indirect doctest sage: type(R) TESTS:: + sage: # needs sage.geometry.polyhedron sage: R = ZpCA(2) sage: TestSuite(R).run() - sage: TestSuite(R).run(elements = [R.random_element() for i in range(2^10)], max_runs = 2^12, skip='_test_metric_function') # long time - sage: R._test_metric_function(elements = [R.random_element() for i in range(2^3)]) # long time - + sage: TestSuite(R).run(elements=[R.random_element() for i in range(2^10)], # long time + ....: max_runs=2^12, skip='_test_metric_function') + sage: R._test_metric_function(elements=[R.random_element() for i in range(2^3)]) # long time sage: R = ZpCA(3, 1) - sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^3)]) - + sage: TestSuite(R).run(elements=[R.random_element() for i in range(3^3)]) sage: R = ZpCA(3, 2) - sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^6)], skip='_test_metric_function') # long time - sage: R._test_metric_function(elements = [R.random_element() for i in range(2^3)]) # long time - + sage: TestSuite(R).run(elements=[R.random_element() for i in range(3^6)], # long time + ....: skip='_test_metric_function') + sage: R._test_metric_function(elements=[R.random_element() for i in range(2^3)]) # long time sage: R = ZpCA(next_prime(10^60)) - sage: TestSuite(R).run(elements = [R.random_element() for i in range(2^3)], max_runs = 2^5, skip='_test_log') # long time + sage: TestSuite(R).run(elements=[R.random_element() for i in range(2^3)], # long time + ....: max_runs=2^5, skip='_test_log') sage: R._test_log(max_runs=2, elements=[R.random_element() for i in range(4)]) """ pAdicRingBaseGeneric.__init__(self, p, prec, print_mode, names, pAdicCappedAbsoluteElement) @@ -352,7 +355,7 @@ def _coerce_map_from_(self, R): EXAMPLES:: sage: K = ZpCA(17) - sage: K(1) + 1 #indirect doctest + sage: K(1) + 1 # indirect doctest 2 + O(17^20) sage: K.has_coerce_map_from(ZZ) True @@ -420,26 +423,27 @@ def __init__(self, p, prec, print_mode, names): EXAMPLES:: - sage: R = ZpFP(next_prime(10^60)) #indirect doctest + sage: R = ZpFP(next_prime(10^60)) # indirect doctest sage: type(R) TESTS:: + sage: # needs sage.geometry.polyhedron sage: R = ZpFP(2) sage: TestSuite(R).run() - sage: TestSuite(R).run(elements = [R.random_element() for i in range(2^10)], max_runs = 2^12, skip='_test_metric_function') # long time - sage: R._test_metric_function(elements = [R.random_element() for i in range(2^3)]) # long time - + sage: TestSuite(R).run(elements=[R.random_element() for i in range(2^10)], # long time + ....: max_runs=2^12, skip='_test_metric_function') + sage: R._test_metric_function(elements=[R.random_element() for i in range(2^3)]) # long time sage: R = ZpFP(3, 1) - sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^3)]) - + sage: TestSuite(R).run(elements=[R.random_element() for i in range(3^3)]) sage: R = ZpFP(3, 2) - sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^6)], skip='_test_metric_function') # long time - sage: R._test_metric_function(elements = [R.random_element() for i in range(2^3)]) # long time - + sage: TestSuite(R).run(elements=[R.random_element() for i in range(3^6)], # long time + ....: skip='_test_metric_function') + sage: R._test_metric_function(elements=[R.random_element() for i in range(2^3)]) # long time sage: R = ZpFP(next_prime(10^60)) - sage: TestSuite(R).run(elements = [R.random_element() for i in range(2^3)], max_runs = 2^5, skip='_test_log') # long time + sage: TestSuite(R).run(elements=[R.random_element() for i in range(2^3)], # long time + ....: max_runs=2^5, skip='_test_log') sage: R._test_log(max_runs=2, elements=[R.random_element() for i in range(4)]) """ pAdicRingBaseGeneric.__init__(self, p, prec, print_mode, names, pAdicFloatingPointElement) @@ -451,7 +455,7 @@ def _coerce_map_from_(self, R): EXAMPLES:: sage: K = ZpFP(17) - sage: K(1) + 1 #indirect doctest + sage: K(1) + 1 # indirect doctest 2 sage: K.has_coerce_map_from(ZZ) True @@ -513,27 +517,28 @@ def __init__(self, p, prec, print_mode, names): EXAMPLES:: - sage: R = ZpFM(next_prime(10^60)) #indirect doctest + sage: R = ZpFM(next_prime(10^60)) # indirect doctest sage: type(R) TESTS:: + sage: # needs sage.geometry.polyhedron sage: R = ZpFM(2) sage: TestSuite(R).run() - sage: TestSuite(R).run(elements = [R.random_element() for i in range(2^10)], max_runs = 2^12, skip='_test_metric_function') # long time - sage: R._test_metric_function(elements = [R.random_element() for i in range(2^3)]) # long time - + sage: TestSuite(R).run(elements=[R.random_element() for i in range(2^10)], # long time + ....: max_runs=2^12, skip='_test_metric_function') + sage: R._test_metric_function(elements=[R.random_element() for i in range(2^3)]) # long time sage: R = ZpFM(3, 1) - sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^3)]) - + sage: TestSuite(R).run(elements=[R.random_element() for i in range(3^3)]) sage: R = ZpFM(3, 2) - sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^6)], skip='_test_metric_function') # long time - sage: R._test_metric_function(elements = [R.random_element() for i in range(2^3)]) # long time - + sage: TestSuite(R).run(elements=[R.random_element() for i in range(3^6)], # long time + ....: skip='_test_metric_function') + sage: R._test_metric_function(elements=[R.random_element() for i in range(2^3)]) # long time sage: R = ZpFM(next_prime(10^60)) sage: TestSuite(R).run(skip='_test_log') - sage: TestSuite(R).run(elements = [R.random_element() for i in range(2^4)], max_runs = 2^6, skip='_test_log') # long time + sage: TestSuite(R).run(elements=[R.random_element() for i in range(2^4)], # long time + ....: max_runs=2^6, skip='_test_log') sage: R._test_log(max_runs=2, elements=[R.random_element() for i in range(4)]) Fraction fields work after :trac:`23510`:: @@ -553,7 +558,7 @@ def _coerce_map_from_(self, R): EXAMPLES:: sage: K = ZpFM(17) - sage: K(1) + 1 #indirect doctest + sage: K(1) + 1 # indirect doctest 2 sage: K.has_coerce_map_from(ZZ) True @@ -607,8 +612,8 @@ class pAdicFieldCappedRelative(pAdicFieldBaseGeneric, pAdicCappedRelativeFieldGe EXAMPLES:: - sage: K = Qp(17, 1000000) #indirect doctest - sage: K = Qp(101) #indirect doctest + sage: K = Qp(17, 1000000) # indirect doctest + sage: K = Qp(101) # indirect doctest """ @@ -625,28 +630,33 @@ def __init__(self, p, prec, print_mode, names): EXAMPLES:: - sage: K = Qp(next_prime(10^60)) # indirect doctest + sage: K = Qp(next_prime(10^60)) # indirect doctest sage: type(K) TESTS:: + sage: # needs sage.geometry.polyhedron sage: R = Qp(2) sage: TestSuite(R).run() - sage: TestSuite(R).run(elements = [R.random_element() for i in range(2^10)], max_runs = 2^12, skip='_test_metric_function') # long time - sage: R._test_metric_function(elements = [R.random_element() for i in range(2^3)]) # long time + sage: TestSuite(R).run(elements=[R.random_element() for i in range(2^10)], # long time + ....: max_runs=2^12, skip='_test_metric_function') + sage: R._test_metric_function(elements=[R.random_element() for i in range(2^3)]) # long time sage: R = Qp(3, 1) - sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^6)], skip='_test_metric_function') # long time - sage: R._test_metric_function(elements = [R.random_element() for i in range(2^3)]) # long time + sage: TestSuite(R).run(elements=[R.random_element() for i in range(3^6)], # long time, needs sage.geometry.polyhedron + ....: skip='_test_metric_function') + sage: R._test_metric_function(elements=[R.random_element() for i in range(2^3)]) # long time sage: R = Qp(3, 2) - sage: TestSuite(R).run(elements=[R.random_element() for i in range(3^9)], skip="_test_metric_function") # long time + sage: TestSuite(R).run(elements=[R.random_element() for i in range(3^9)], # long time, needs sage.geometry.polyhedron + ....: skip="_test_metric_function") sage: R._test_metric_function(elements=[R.random_element() for i in range(3^3)]) sage: R = Qp(next_prime(10^60)) - sage: TestSuite(R).run(skip='_test_log') - sage: TestSuite(R).run(elements = [R.random_element() for i in range(2^3)], max_runs = 2^5, skip='_test_log') # long time + sage: TestSuite(R).run(skip='_test_log') # needs sage.geometry.polyhedron + sage: TestSuite(R).run(elements=[R.random_element() for i in range(2^3)], # long time, needs sage.geometry.polyhedron + ....: max_runs=2^5, skip='_test_log') sage: R._test_log(max_runs=2, elements=[R.random_element() for i in range(4)]) """ pAdicFieldBaseGeneric.__init__(self, p, prec, print_mode, names, pAdicCappedRelativeElement) @@ -658,7 +668,7 @@ def _coerce_map_from_(self, R): EXAMPLES:: sage: K = Qp(17) - sage: K(1) + 1 #indirect doctest + sage: K(1) + 1 # indirect doctest 2 + O(17^20) sage: K.has_coerce_map_from(ZZ) True @@ -751,27 +761,28 @@ def __init__(self, p, prec, print_mode, names): EXAMPLES:: - sage: R = QpFP(next_prime(10^60)) #indirect doctest + sage: R = QpFP(next_prime(10^60)) # indirect doctest sage: type(R) TESTS:: + sage: # needs sage.geometry.polyhedron sage: R = QpFP(2) sage: TestSuite(R).run() - sage: TestSuite(R).run(elements = [R.random_element() for i in range(2^10)], max_runs = 2^12, skip='_test_metric_function') # long time - sage: R._test_metric_function(elements = [R.random_element() for i in range(2^3)]) # long time - + sage: TestSuite(R).run(elements=[R.random_element() for i in range(2^10)], # long time + ....: max_runs=2^12, skip='_test_metric_function') + sage: R._test_metric_function(elements=[R.random_element() for i in range(2^3)]) # long time sage: R = QpFP(3, 1) - sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^3)]) - + sage: TestSuite(R).run(elements=[R.random_element() for i in range(3^3)]) sage: R = QpFP(3, 2) - sage: TestSuite(R).run(elements = [R.random_element() for i in range(3^6)], skip='_test_metric_function') # long time - sage: R._test_metric_function(elements = [R.random_element() for i in range(2^3)]) # long time - + sage: TestSuite(R).run(elements=[R.random_element() for i in range(3^6)], # long time + ....: skip='_test_metric_function') + sage: R._test_metric_function(elements=[R.random_element() for i in range(2^3)]) # long time sage: R = QpFP(next_prime(10^60)) sage: TestSuite(R).run(skip='_test_log') - sage: TestSuite(R).run(elements = [R.random_element() for i in range(2^3)], max_runs = 2^5, skip='_test_log') # long time + sage: TestSuite(R).run(elements=[R.random_element() for i in range(2^3)], # long time + ....: max_runs=2^5, skip='_test_log') sage: R._test_log(max_runs=2, elements=[R.random_element() for i in range(4)]) """ pAdicFieldBaseGeneric.__init__(self, p, prec, print_mode, names, pAdicFloatingPointElement) @@ -783,7 +794,7 @@ def _coerce_map_from_(self, R): EXAMPLES:: sage: K = QpFP(17) - sage: K(1) + 1 #indirect doctest + sage: K(1) + 1 # indirect doctest 2 sage: K.has_coerce_map_from(ZZ) True @@ -857,14 +868,14 @@ class pAdicRingLattice(pAdicLatticeGeneric, pAdicRingBaseGeneric): EXAMPLES:: - sage: R = ZpLC(next_prime(10^60)) # indirect doctest + sage: R = ZpLC(next_prime(10^60)) # indirect doctest doctest:...: FutureWarning: This class/method/function is marked as experimental. It, its functionality or its interface might change without a formal deprecation. See https://github.com/sagemath/sage/issues/23505 for details. sage: type(R) - sage: R = ZpLC(2, label='init') # indirect doctest + sage: R = ZpLC(2, label='init') # indirect doctest sage: R 2-adic Ring with lattice-cap precision (label: init) """ @@ -875,7 +886,7 @@ def __init__(self, p, prec, subtype, print_mode, names, label=None): TESTS: sage: R = ZpLC(7, label='init') - sage: TestSuite(R).run(skip=['_test_teichmuller', '_test_matrix_smith']) # long time + sage: TestSuite(R).run(skip=['_test_teichmuller', '_test_matrix_smith']) # long time """ # We need to set the subtype first, so that # pAdicRingBaseGeneric.__init__ can work @@ -988,14 +999,14 @@ class pAdicFieldLattice(pAdicLatticeGeneric, pAdicFieldBaseGeneric): EXAMPLES:: - sage: R = QpLC(next_prime(10^60)) # indirect doctest + sage: R = QpLC(next_prime(10^60)) # indirect doctest doctest:...: FutureWarning: This class/method/function is marked as experimental. It, its functionality or its interface might change without a formal deprecation. See https://github.com/sagemath/sage/issues/23505 for details. sage: type(R) - sage: R = QpLC(2,label='init') # indirect doctest + sage: R = QpLC(2,label='init') # indirect doctest sage: R 2-adic Field with lattice-cap precision (label: init) """ @@ -1006,7 +1017,7 @@ def __init__(self, p, prec, subtype, print_mode, names, label=None): TESTS:: sage: R = QpLC(7, label='init') - sage: TestSuite(R).run(skip=['_test_teichmuller', '_test_matrix_smith']) # long time + sage: TestSuite(R).run(skip=['_test_teichmuller', '_test_matrix_smith']) # long time """ # We need to set the subtype first, so that # pAdicFieldBaseGeneric.__init__ can work @@ -1120,8 +1131,8 @@ class pAdicRingRelaxed(pAdicRelaxedGeneric, pAdicRingBaseGeneric): EXAMPLES:: - sage: R = ZpER(5) # indirect doctest - sage: type(R) + sage: R = ZpER(5) # indirect doctest # needs sage.libs.flint + sage: type(R) # needs sage.libs.flint """ def __init__(self, p, prec, print_mode, names): @@ -1130,6 +1141,7 @@ def __init__(self, p, prec, print_mode, names): TESTS:: + sage: # needs sage.libs.flint sage: R = ZpER(7) sage: TestSuite(R).run(skip=['_test_log', '_test_matrix_smith']) sage: R = ZpER(7, secure=True) @@ -1157,8 +1169,8 @@ class pAdicFieldRelaxed(pAdicRelaxedGeneric, pAdicFieldBaseGeneric): EXAMPLES:: - sage: R = QpER(5) # indirect doctest - sage: type(R) + sage: R = QpER(5) # indirect doctest # needs sage.libs.flint + sage: type(R) # needs sage.libs.flint """ def __init__(self, p, prec, print_mode, names): @@ -1167,6 +1179,7 @@ def __init__(self, p, prec, print_mode, names): TESTS:: + sage: # needs sage.libs.flint sage: K = QpER(7) sage: TestSuite(K).run(skip=['_test_log', '_test_matrix_smith']) sage: K = QpER(7, secure=True) diff --git a/src/sage/rings/padics/padic_capped_absolute_element.pyx b/src/sage/rings/padics/padic_capped_absolute_element.pyx index 061d36fd309..d4f76f08efe 100644 --- a/src/sage/rings/padics/padic_capped_absolute_element.pyx +++ b/src/sage/rings/padics/padic_capped_absolute_element.pyx @@ -25,7 +25,7 @@ include "CA_template.pxi" from sage.libs.pari.convert_gmp cimport new_gen_from_padic from sage.rings.finite_rings.integer_mod import Mod -cdef extern from "sage/rings/padics/transcendantal.c": +cdef extern from "transcendantal.c": cdef void padiclog(mpz_t ans, const mpz_t a, unsigned long p, unsigned long prec, const mpz_t modulo) cdef void padicexp(mpz_t ans, const mpz_t a, unsigned long p, unsigned long prec, const mpz_t modulo) cdef void padicexp_Newton(mpz_t ans, const mpz_t a, unsigned long p, unsigned long prec, unsigned long precinit, const mpz_t modulo) @@ -103,7 +103,7 @@ cdef class pAdicCappedAbsoluteElement(CAElement): TESTS:: - sage: ZpCA(3,3)(1/4).lift() # indirect doctest + sage: ZpCA(3,3)(1/4).lift() # indirect doctest 7 """ cdef Integer ans = Integer.__new__(Integer) @@ -117,9 +117,9 @@ cdef class pAdicCappedAbsoluteElement(CAElement): EXAMPLES:: sage: R = ZpCA(5) - sage: pari(R(1777)) #indirect doctest + sage: pari(R(1777)) # indirect doctest # needs sage.libs.pari 2 + 5^2 + 4*5^3 + 2*5^4 + O(5^20) - sage: pari(R(0,0)) + sage: pari(R(0,0)) # needs sage.libs.pari O(5^0) """ return self._to_gen() @@ -130,11 +130,11 @@ cdef class pAdicCappedAbsoluteElement(CAElement): EXAMPLES:: - sage: R = ZpCA(5, 10); a = R(17); pari(a) #indirect doctest + sage: R = ZpCA(5, 10); a = R(17); pari(a) # indirect doctest 2 + 3*5 + O(5^10) - sage: pari(R(0,5)) + sage: pari(R(0,5)) # needs sage.libs.pari O(5^5) - sage: pari(R(0,5)).debug() + sage: pari(R(0,5)).debug() # needs sage.libs.pari [&=...] PADIC(lg=5):... (precp=0,valp=5):... ... ... ... p : [&=...] INT(lg=3):... (+,lgefint=3):... ... p^l : [&=...] INT(lg=3):... (+,lgefint=3):... ... @@ -477,6 +477,7 @@ cdef class pAdicCappedAbsoluteElement(CAElement): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Zq(7^2,5) sage: x = R(7*w) sage: x.exp(algorithm="newton") # indirect doctest diff --git a/src/sage/rings/padics/padic_capped_relative_element.pyx b/src/sage/rings/padics/padic_capped_relative_element.pyx index c32b882ff8e..e2e652798fe 100644 --- a/src/sage/rings/padics/padic_capped_relative_element.pyx +++ b/src/sage/rings/padics/padic_capped_relative_element.pyx @@ -29,7 +29,7 @@ from sage.libs.pari.convert_gmp cimport new_gen_from_padic from sage.rings.finite_rings.integer_mod import Mod from sage.rings.padics.pow_computer cimport PowComputer_class -cdef extern from "sage/rings/padics/transcendantal.c": +cdef extern from "transcendantal.c": cdef void padiclog(mpz_t ans, const mpz_t a, unsigned long p, unsigned long prec, const mpz_t modulo) cdef void padicexp(mpz_t ans, const mpz_t a, unsigned long p, unsigned long prec, const mpz_t modulo) cdef void padicexp_Newton(mpz_t ans, const mpz_t a, unsigned long p, unsigned long prec, unsigned long precinit, const mpz_t modulo) @@ -126,16 +126,16 @@ cdef class pAdicCappedRelativeElement(CRElement): Construct from Pari objects:: sage: R = Zp(5) - sage: x = pari(123123) ; R(x) + sage: x = pari(123123) ; R(x) # needs sage.libs.pari 3 + 4*5 + 4*5^2 + 4*5^3 + 5^4 + 4*5^5 + 2*5^6 + 5^7 + O(5^20) sage: R(pari(R(5252))) 2 + 2*5^3 + 3*5^4 + 5^5 + O(5^20) sage: R = Zp(5,prec=5) sage: R(pari(-1)) 4 + 4*5 + 4*5^2 + 4*5^3 + 4*5^4 + O(5^5) - sage: pari(R(-1)) + sage: pari(R(-1)) # needs sage.libs.pari 4 + 4*5 + 4*5^2 + 4*5^3 + 4*5^4 + O(5^5) - sage: pari(R(0)) + sage: pari(R(0)) # needs sage.libs.pari 0 sage: R(pari(R(0,5))) O(5^5) @@ -201,11 +201,11 @@ cdef class pAdicCappedRelativeElement(CRElement): EXAMPLES:: - sage: R = Zp(17, 10); a = ~R(14); pari(a) #indirect doctest + sage: R = Zp(17, 10); a = ~R(14); pari(a) # indirect doctest 11 + 3*17 + 17^2 + 6*17^3 + 13*17^4 + 15*17^5 + 10*17^6 + 3*17^7 + 17^8 + 6*17^9 + O(17^10) - sage: pari(R(0)) + sage: pari(R(0)) # needs sage.libs.pari 0 - sage: pari(R(0,5)) + sage: pari(R(0,5)) # needs sage.libs.pari O(17^5) """ return self._to_gen() @@ -216,13 +216,13 @@ cdef class pAdicCappedRelativeElement(CRElement): EXAMPLES:: - sage: R = Zp(5, 10); a = R(17); pari(a) #indirect doctest + sage: R = Zp(5, 10); a = R(17); pari(a) # indirect doctest 2 + 3*5 + O(5^10) - sage: pari(R(0)) + sage: pari(R(0)) # needs sage.libs.pari 0 - sage: pari(R(0,5)) + sage: pari(R(0,5)) # needs sage.libs.pari O(5^5) - sage: pari(R(0,5)).debug() + sage: pari(R(0,5)).debug() # needs sage.libs.pari [&=...] PADIC(lg=5):... (precp=0,valp=5):... ... ... ... p : [&=...] INT(lg=3):... (+,lgefint=3):... ... p^l : [&=...] INT(lg=3):... (+,lgefint=3):... ... @@ -535,6 +535,7 @@ cdef class pAdicCappedRelativeElement(CRElement): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Zq(7^2,5) sage: x = R(7*w) sage: x.exp(algorithm="newton") # indirect doctest diff --git a/src/sage/rings/padics/padic_ext_element.pyx b/src/sage/rings/padics/padic_ext_element.pyx index 0b5bc0f1249..a79dc1a4a97 100644 --- a/src/sage/rings/padics/padic_ext_element.pyx +++ b/src/sage/rings/padics/padic_ext_element.pyx @@ -4,6 +4,7 @@ # distutils: library_dirs = NTL_LIBDIR # distutils: extra_link_args = NTL_LIBEXTRA # distutils: language = c++ +# sage.doctest: needs sage.rings.padics r""" `p`-adic Extension Element @@ -280,7 +281,7 @@ cdef class pAdicExtElement(pAdicGenericElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: a = W(566) sage: a._const_term_test() @@ -320,7 +321,7 @@ cdef class pAdicExtElement(pAdicGenericElement): sage: R = Zp(5,5) sage: S. = R[] - sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 + sage: f = x^5 + 75*x^3 - 15*x^2 + 125*x - 5 sage: W. = R.ext(f) sage: y = W(775, 19); y w^10 + 4*w^12 + 2*w^14 + w^15 + 2*w^16 + 4*w^17 + w^18 + O(w^19) @@ -442,6 +443,7 @@ cdef class pAdicExtElement(pAdicGenericElement): Unramified case:: + sage: # needs sage.libs.flint sage: R = ZpCA(3,5) sage: S. = R[] sage: W. = R.extension(a^2 + 9*a + 1) @@ -466,6 +468,7 @@ cdef class pAdicExtElement(pAdicGenericElement): TESTS:: + sage: # needs sage.libs.flint sage: K = Qp(3,5) sage: S. = R[] sage: W. = R.extension(a^2 + 9*a + 1) @@ -474,6 +477,7 @@ cdef class pAdicExtElement(pAdicGenericElement): ... ValueError: element must have non-negative valuation in order to compute residue + sage: # needs sage.libs.flint sage: R = ZpFM(3,5) sage: S. = R[] sage: W. = R.extension(a^2 + 3) diff --git a/src/sage/rings/padics/padic_extension_generic.py b/src/sage/rings/padics/padic_extension_generic.py index 59264f4f0f4..accb68ccfc4 100644 --- a/src/sage/rings/padics/padic_extension_generic.py +++ b/src/sage/rings/padics/padic_extension_generic.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.ntl """ `p`-adic Extension Generic @@ -50,7 +51,7 @@ def __init__(self, poly, prec, print_mode, names, element_class): sage: R = Zp(5,5) sage: S. = R[] sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 - sage: W. = R.ext(f) #indirect doctest + sage: W. = R.ext(f) # indirect doctest """ #type checking done in factory self._given_poly = poly @@ -73,7 +74,7 @@ def _coerce_map_from_(self, R): sage: R = Zp(5); S. = ZZ[]; f = x^5 + 25*x - 5; W. = R.ext(f) sage: L = W.fraction_field() - sage: w + L(w) #indirect doctest + sage: w + L(w) # indirect doctest 2*w + O(w^101) sage: w + R(5,2) w + w^5 + O(w^10) @@ -142,7 +143,7 @@ def _repr_(self, do_latex=False): '\\Bold{Z}_{7^{3}}' sage: x = polygen(ZZ, 'x') sage: R2. = R.ext(x^2 + 7) - sage: R2 #indirect doctest + sage: R2 # indirect doctest 7-adic Eisenstein Extension Ring in t defined by x^2 + 7 sage: R2._latex_() '\\Bold{Z}_{7}[t]' @@ -156,7 +157,7 @@ def _repr_(self, do_latex=False): sage: K1._latex_() '\\Bold{Q}_{7^{3}}' sage: K2. = K.ext(x^2+7) - sage: K2 #indirect doctest + sage: K2 # indirect doctest 7-adic Eisenstein Extension Field in t defined by x^2 + 7 sage: K2._latex_() '\\Bold{Q}_{7}[t]' @@ -736,7 +737,7 @@ class MapFreeModuleToOneStep(pAdicModuleIsomorphism): sage: K. = Qq(125) sage: V, fr, to = K.free_module() - sage: TestSuite(fr).run(skip=['_test_nonzero_equal']) # skipped since Qq(125) doesn't have dimension() + sage: TestSuite(fr).run(skip=['_test_nonzero_equal']) # skipped since Qq(125) doesn't have dimension() """ def _call_(self, x): """ @@ -797,7 +798,7 @@ class MapFreeModuleToTwoStep(pAdicModuleIsomorphism): sage: R. = ZZ[] sage: L. = K.extension(x^2 - 5*x + 5) sage: V, fr, to = L.free_module(base=Qp(5)) - sage: TestSuite(fr).run(skip=['_test_nonzero_equal']) # skipped since L doesn't have dimension() + sage: TestSuite(fr).run(skip=['_test_nonzero_equal']) # skipped since L doesn't have dimension() """ def _call_(self, x): """ @@ -941,7 +942,7 @@ def _call_with_args(self, x, args=(), kwds={}): sage: S. = ZZ[] sage: W. = Zp(3).extension(x^4 + 9*x^2 + 3*x - 3) sage: z = W.random_element() - sage: r = repr(W.change(print_mode='digits')(z, absprec=8)) # indirect doctest + sage: r = repr(W.change(print_mode='digits')(z, absprec=8)) # indirect doctest sage: r[:3] == '...' True sage: all(l in ['0', '1', '2'] for l in r[3:]) diff --git a/src/sage/rings/padics/padic_extension_leaves.py b/src/sage/rings/padics/padic_extension_leaves.py index 44156a85075..ef0ed071a2c 100644 --- a/src/sage/rings/padics/padic_extension_leaves.py +++ b/src/sage/rings/padics/padic_extension_leaves.py @@ -99,8 +99,8 @@ class UnramifiedExtensionRingCappedRelative(UnramifiedExtensionGeneric, pAdicCap """ TESTS:: - sage: R. = ZqCR(27,1000) - sage: TestSuite(R).run(skip='_test_log',max_runs=4) + sage: R. = ZqCR(27,1000) # needs sage.libs.ntl + sage: TestSuite(R).run(skip='_test_log',max_runs=4) # needs sage.libs.ntl """ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, implementation='FLINT'): r""" @@ -126,10 +126,10 @@ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, imp EXAMPLES:: - sage: R. = ZqCR(27,10000); R #indirect doctest + sage: R. = ZqCR(27,10000); R # indirect doctest # needs sage.libs.ntl 3-adic Unramified Extension Ring in a defined by x^3 + 2*x + 1 - sage: R. = ZqCR(next_prime(10^30)^3, 3); R.prime() + sage: R. = ZqCR(next_prime(10^30)^3, 3); R.prime() # needs sage.libs.ntl 1000000000000000000000000000057 """ self._shift_seed = None @@ -157,8 +157,8 @@ class UnramifiedExtensionFieldCappedRelative(UnramifiedExtensionGeneric, pAdicCa """ TESTS:: - sage: R. = QqCR(27,1000) - sage: TestSuite(R).run(skip='_test_log',max_runs=4) + sage: R. = QqCR(27,1000) # needs sage.libs.ntl + sage: TestSuite(R).run(skip='_test_log',max_runs=4) # needs sage.libs.ntl """ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, implementation='FLINT'): r""" @@ -184,10 +184,10 @@ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, imp EXAMPLES:: - sage: R. = Qq(27,10000); R #indirect doctest + sage: R. = Qq(27,10000); R # indirect doctest # needs sage.libs.ntl 3-adic Unramified Extension Field in a defined by x^3 + 2*x + 1 - sage: R. = Qq(next_prime(10^30)^3, 3); R.prime() + sage: R. = Qq(next_prime(10^30)^3, 3); R.prime() # needs sage.libs.ntl 1000000000000000000000000000057 """ # Currently doesn't support polynomials with non-integral coefficients @@ -219,12 +219,12 @@ def _coerce_map_from_(self, R): EXAMPLES:: - sage: R. = QqCR(27) - sage: R.coerce_map_from(ZqCR(27,names='a')) # indirect doctest + sage: R. = QqCR(27) # needs sage.libs.ntl + sage: R.coerce_map_from(ZqCR(27,names='a')) # indirect doctest # needs sage.libs.ntl Ring morphism: From: 3-adic Unramified Extension Ring in a defined by x^3 + 2*x + 1 To: 3-adic Unramified Extension Field in a defined by x^3 + 2*x + 1 - sage: R.coerce_map_from(ZqCA(27,names='a')) # indirect doctest + sage: R.coerce_map_from(ZqCA(27,names='a')) # indirect doctest # needs sage.libs.ntl Ring morphism: From: 3-adic Unramified Extension Ring in a defined by x^3 + 2*x + 1 To: 3-adic Unramified Extension Field in a defined by x^3 + 2*x + 1 @@ -243,8 +243,8 @@ class UnramifiedExtensionRingCappedAbsolute(UnramifiedExtensionGeneric, pAdicCap """ TESTS:: - sage: R. = ZqCA(27,1000) - sage: TestSuite(R).run(skip='_test_log',max_runs=4) + sage: R. = ZqCA(27,1000) # needs sage.libs.flint + sage: TestSuite(R).run(skip='_test_log',max_runs=4) # needs sage.libs.flint """ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, implementation='FLINT'): r""" @@ -270,10 +270,10 @@ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, imp EXAMPLES:: - sage: R. = ZqCA(27,10000); R #indirect doctest + sage: R. = ZqCA(27,10000); R # indirect doctest # needs sage.libs.flint 3-adic Unramified Extension Ring in a defined by x^3 + 2*x + 1 - sage: R. = ZqCA(next_prime(10^30)^3, 3); R.prime() + sage: R. = ZqCA(next_prime(10^30)^3, 3); R.prime() # needs sage.libs.flint 1000000000000000000000000000057 """ # Currently doesn't support polynomials with non-integral coefficients @@ -302,8 +302,8 @@ class UnramifiedExtensionRingFixedMod(UnramifiedExtensionGeneric, pAdicFixedModR """ TESTS:: - sage: R. = ZqFM(27,1000) - sage: TestSuite(R).run(skip='_test_log',max_runs=4) # long time + sage: R. = ZqFM(27,1000) # needs sage.libs.flint + sage: TestSuite(R).run(skip='_test_log',max_runs=4) # long time # needs sage.libs.flint """ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, implementation='FLINT'): """ @@ -328,10 +328,10 @@ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, imp EXAMPLES:: - sage: R. = ZqFM(27,10000); R #indirect doctest + sage: R. = ZqFM(27,10000); R # indirect doctest # needs sage.libs.flint 3-adic Unramified Extension Ring in a defined by x^3 + 2*x + 1 - sage: R. = ZqFM(next_prime(10^30)^3, 3); R.prime() + sage: R. = ZqFM(next_prime(10^30)^3, 3); R.prime() # needs sage.libs.flint 1000000000000000000000000000057 """ self._shift_seed = None @@ -364,7 +364,7 @@ class UnramifiedExtensionRingFloatingPoint(UnramifiedExtensionGeneric, pAdicFloa """ TESTS:: - sage: R. = ZqFP(27,10000); R == loads(dumps(R)) + sage: R. = ZqFP(27,10000); R == loads(dumps(R)) # needs sage.libs.flint True """ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, implementation='FLINT'): @@ -390,16 +390,16 @@ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, imp EXAMPLES:: - sage: R. = ZqFP(27,10000); R #indirect doctest + sage: R. = ZqFP(27,10000); R # indirect doctest # needs sage.libs.flint 3-adic Unramified Extension Ring in a defined by x^3 + 2*x + 1 - sage: R. = ZqFP(next_prime(10^30)^3, 3); R.prime() + sage: R. = ZqFP(next_prime(10^30)^3, 3); R.prime() # needs sage.libs.flint 1000000000000000000000000000057 TESTS: Check that :trac:`23228` has been resolved:: - sage: a % R.prime() + sage: a % R.prime() # needs sage.libs.flint a """ @@ -421,7 +421,7 @@ class UnramifiedExtensionFieldFloatingPoint(UnramifiedExtensionGeneric, pAdicFlo """ TESTS:: - sage: R. = QqFP(27,10000); R == loads(dumps(R)) + sage: R. = QqFP(27,10000); R == loads(dumps(R)) # needs sage.libs.flint True """ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, implementation='FLINT'): @@ -447,9 +447,9 @@ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, imp EXAMPLES:: - sage: R. = QqFP(27,10000); R #indirect doctest + sage: R. = QqFP(27,10000); R # indirect doctest # needs sage.libs.flint 3-adic Unramified Extension Field in a defined by x^3 + 2*x + 1 - sage: R. = Qq(next_prime(10^30)^3, 3); R.prime() + sage: R. = Qq(next_prime(10^30)^3, 3); R.prime() # needs sage.libs.ntl 1000000000000000000000000000057 """ # Currently doesn't support polynomials with non-integral coefficients @@ -473,8 +473,8 @@ def _coerce_map_from_(self, R): EXAMPLES:: - sage: R. = QqFP(27) - sage: R.coerce_map_from(ZqFP(27,names='a')) # indirect doctest + sage: R. = QqFP(27) # needs sage.libs.flint + sage: R.coerce_map_from(ZqFP(27,names='a')) # indirect doctest # needs sage.libs.flint Ring morphism: From: 3-adic Unramified Extension Ring in a defined by x^3 + 2*x + 1 To: 3-adic Unramified Extension Field in a defined by x^3 + 2*x + 1 @@ -490,8 +490,8 @@ class EisensteinExtensionRingCappedRelative(EisensteinExtensionGeneric, pAdicCap TESTS:: sage: R = Zp(3, 1000, print_pos=False); S. = ZZ[]; f = x^3 + 9*x - 3 - sage: W. = R.ext(f) - sage: TestSuite(R).run(skip='_test_log',max_runs=4) + sage: W. = R.ext(f) # needs sage.libs.ntl sage.rings.padics + sage: TestSuite(R).run(skip='_test_log',max_runs=4) # needs sage.geometry.polyhedron """ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, implementation='NTL'): r""" @@ -517,15 +517,15 @@ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, imp EXAMPLES:: sage: R = Zp(3, 10000, print_pos=False); S. = ZZ[]; f = x^3 + 9*x - 3 - sage: W. = R.ext(f); W #indirect doctest + sage: W. = R.ext(f); W # indirect doctest # needs sage.libs.ntl 3-adic Eisenstein Extension Ring in w defined by x^3 + 9*x - 3 - sage: W.precision_cap() + sage: W.precision_cap() # needs sage.libs.ntl 30000 - sage: R.

= Zp(next_prime(10^30), 3, print_pos=False); S. = ZZ[]; f = x^3 + p^2*x - p - sage: W. = R.ext(f); W.prime() + sage: R.

= Zp(next_prime(10^30), 3, print_pos=False); S. = ZZ[]; f = x^3 + p^2*x - p # needs sage.libs.ntl + sage: W. = R.ext(f); W.prime() # needs sage.libs.ntl 1000000000000000000000000000057 - sage: W.precision_cap() + sage: W.precision_cap() # needs sage.libs.ntl 9 """ unram_prec = (prec + poly.degree() - 1) // poly.degree() @@ -545,8 +545,8 @@ class EisensteinExtensionFieldCappedRelative(EisensteinExtensionGeneric, pAdicCa TESTS:: sage: R = Qp(3, 1000, print_pos=False); S. = ZZ[]; f = x^3 + 9*x - 3 - sage: W. = R.ext(f) - sage: TestSuite(R).run(skip='_test_log',max_runs=4) + sage: W. = R.ext(f) # needs sage.libs.ntl + sage: TestSuite(R).run(skip='_test_log',max_runs=4) # needs sage.geometry.polyhedron """ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, implementation='NTL'): r""" @@ -572,15 +572,15 @@ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, imp EXAMPLES:: sage: R = Qp(3, 10000, print_pos=False); S. = ZZ[]; f = x^3 + 9*x - 3 - sage: W. = R.ext(f); W #indirect doctest + sage: W. = R.ext(f); W # indirect doctest # needs sage.libs.ntl 3-adic Eisenstein Extension Field in w defined by x^3 + 9*x - 3 - sage: W.precision_cap() + sage: W.precision_cap() # needs sage.libs.ntl 30000 - sage: R.

= Qp(next_prime(10^30), 3, print_pos=False); S. = ZZ[]; f = x^3 + p^2*x - p - sage: W. = R.ext(f); W.prime() + sage: R.

= Qp(next_prime(10^30), 3, print_pos=False); S. = ZZ[]; f = x^3 + p^2*x - p # needs sage.libs.ntl + sage: W. = R.ext(f); W.prime() # needs sage.libs.ntl 1000000000000000000000000000057 - sage: W.precision_cap() + sage: W.precision_cap() # needs sage.libs.ntl 9 """ # Currently doesn't support polynomials with non-integral coefficients @@ -601,8 +601,8 @@ class EisensteinExtensionRingCappedAbsolute(EisensteinExtensionGeneric, pAdicCap TESTS:: sage: R = ZpCA(3, 1000, print_pos=False); S. = ZZ[]; f = x^3 + 9*x - 3 - sage: W. = R.ext(f) - sage: TestSuite(R).run(skip='_test_log',max_runs=4) + sage: W. = R.ext(f) # needs sage.libs.ntl sage.rings.padics + sage: TestSuite(R).run(skip='_test_log',max_runs=4) # needs sage.geometry.polyhedron """ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, implementation): r""" @@ -628,15 +628,15 @@ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, imp EXAMPLES:: sage: R = ZpCA(3, 10000, print_pos=False); S. = ZZ[]; f = x^3 + 9*x - 3 - sage: W. = R.ext(f); W + sage: W. = R.ext(f); W # needs sage.libs.ntl 3-adic Eisenstein Extension Ring in w defined by x^3 + 9*x - 3 - sage: W.precision_cap() + sage: W.precision_cap() # needs sage.libs.ntl 30000 sage: R.

= ZpCA(next_prime(10^30), 3, print_pos=False); S. = ZZ[]; f = x^3 + p^2*x - p - sage: W. = R.ext(f); W.prime() + sage: W. = R.ext(f); W.prime() # needs sage.libs.ntl 1000000000000000000000000000057 - sage: W.precision_cap() + sage: W.precision_cap() # needs sage.libs.ntl 9 """ unram_prec = (prec + poly.degree() - 1) // poly.degree() @@ -656,8 +656,8 @@ class EisensteinExtensionRingFixedMod(EisensteinExtensionGeneric, pAdicFixedModR TESTS:: sage: R = ZpFM(3, 1000, print_pos=False); S. = ZZ[]; f = x^3 + 9*x - 3 - sage: W. = R.ext(f) - sage: TestSuite(R).run(skip='_test_log',max_runs=4) + sage: W. = R.ext(f) # needs sage.libs.ntl sage.rings.padics + sage: TestSuite(R).run(skip='_test_log',max_runs=4) # needs sage.geometry.polyhedron """ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, implementation='NTL'): r""" @@ -683,15 +683,15 @@ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, imp EXAMPLES:: sage: R = ZpFM(3, 10000, print_pos=False); S. = ZZ[]; f = x^3 + 9*x - 3 - sage: W. = R.ext(f); W #indirect doctest + sage: W. = R.ext(f); W # indirect doctest # needs sage.libs.ntl 3-adic Eisenstein Extension Ring in w defined by x^3 + 9*x - 3 - sage: W.precision_cap() + sage: W.precision_cap() # needs sage.libs.ntl 30000 sage: R.

= ZpFM(next_prime(10^30), 3, print_pos=False); S. = ZZ[]; f = x^3 + p^2*x - p - sage: W. = R.ext(f); W.prime() + sage: W. = R.ext(f); W.prime() # needs sage.libs.ntl 1000000000000000000000000000057 - sage: W.precision_cap() + sage: W.precision_cap() # needs sage.libs.ntl 9 """ unram_prec = (prec + poly.degree() - 1) // poly.degree() @@ -712,8 +712,8 @@ def fraction_field(self): EXAMPLES:: sage: S. = ZZ[] - sage: R. = ZpFM(5).extension(x^2 - 5) - sage: R.fraction_field() + sage: R. = ZpFM(5).extension(x^2 - 5) # needs sage.libs.ntl + sage: R.fraction_field() # needs sage.libs.ntl Traceback (most recent call last): ... TypeError: This implementation of the p-adic ring diff --git a/src/sage/rings/padics/padic_fixed_mod_element.pyx b/src/sage/rings/padics/padic_fixed_mod_element.pyx index d538b10475d..21cbbded8f4 100644 --- a/src/sage/rings/padics/padic_fixed_mod_element.pyx +++ b/src/sage/rings/padics/padic_fixed_mod_element.pyx @@ -27,7 +27,7 @@ include "FM_template.pxi" from sage.libs.pari.convert_gmp cimport new_gen_from_padic from sage.rings.finite_rings.integer_mod import Mod -cdef extern from "sage/rings/padics/transcendantal.c": +cdef extern from "transcendantal.c": cdef void padiclog(mpz_t ans, const mpz_t a, unsigned long p, unsigned long prec, const mpz_t modulo) cdef void padicexp(mpz_t ans, const mpz_t a, unsigned long p, unsigned long prec, const mpz_t modulo) cdef void padicexp_Newton(mpz_t ans, const mpz_t a, unsigned long p, unsigned long prec, unsigned long precinit, const mpz_t modulo) @@ -169,7 +169,7 @@ cdef class pAdicFixedModElement(FMElement): EXAMPLES:: - sage: R = ZpFM(7,4); a = R(8); a.lift() # indirect doctest + sage: R = ZpFM(7,4); a = R(8); a.lift() # indirect doctest 8 """ cdef Integer ans = PY_NEW(Integer) @@ -183,7 +183,7 @@ cdef class pAdicFixedModElement(FMElement): EXAMPLES:: sage: R = ZpCA(5) - sage: pari(R(1777)) #indirect doctest + sage: pari(R(1777)) # indirect doctest # needs sage.libs.pari 2 + 5^2 + 4*5^3 + 2*5^4 + O(5^20) """ return self._to_gen() @@ -194,13 +194,13 @@ cdef class pAdicFixedModElement(FMElement): EXAMPLES:: - sage: R = ZpFM(5, 10); a = R(17); pari(a) # indirect doctest + sage: R = ZpFM(5, 10); a = R(17); pari(a) # indirect doctest 2 + 3*5 + O(5^10) - sage: pari(R(0)) + sage: pari(R(0)) # needs sage.libs.pari O(5^10) - sage: pari(R(0,5)) + sage: pari(R(0,5)) # needs sage.libs.pari O(5^10) - sage: pari(R(0)).debug() + sage: pari(R(0)).debug() # needs sage.libs.pari [&=...] PADIC(lg=5):... (precp=0,valp=10):... ... ... ... p : [&=...] INT(lg=3):... (+,lgefint=3):... ... p^l : [&=...] INT(lg=3):... (+,lgefint=3):... ... @@ -542,6 +542,7 @@ cdef class pAdicFixedModElement(FMElement): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Zq(7^2,5) sage: x = R(7*w) sage: x.exp(algorithm="newton") # indirect doctest diff --git a/src/sage/rings/padics/padic_floating_point_element.pyx b/src/sage/rings/padics/padic_floating_point_element.pyx index 70f5ce806af..22529fffc6f 100644 --- a/src/sage/rings/padics/padic_floating_point_element.pyx +++ b/src/sage/rings/padics/padic_floating_point_element.pyx @@ -25,7 +25,7 @@ from sage.libs.pari.all import pari from sage.libs.pari.convert_gmp cimport new_gen_from_padic from sage.rings.finite_rings.integer_mod import Mod -cdef extern from "sage/rings/padics/transcendantal.c": +cdef extern from "transcendantal.c": cdef void padicexp(mpz_t ans, const mpz_t a, unsigned long p, unsigned long prec, const mpz_t modulo) cdef void padicexp_Newton(mpz_t ans, const mpz_t a, unsigned long p, unsigned long prec, unsigned long precinit, const mpz_t modulo) @@ -121,16 +121,16 @@ cdef class pAdicFloatingPointElement(FPElement): Construct from Pari objects:: sage: R = ZpFP(5) - sage: x = pari(123123) ; R(x) + sage: x = pari(123123) ; R(x) # needs sage.libs.pari 3 + 4*5 + 4*5^2 + 4*5^3 + 5^4 + 4*5^5 + 2*5^6 + 5^7 sage: R(pari(R(5252))) 2 + 2*5^3 + 3*5^4 + 5^5 sage: R = ZpFP(5,prec=5) sage: R(pari(-1)) 4 + 4*5 + 4*5^2 + 4*5^3 + 4*5^4 - sage: pari(R(-1)) + sage: pari(R(-1)) # needs sage.libs.pari 4 + 4*5 + 4*5^2 + 4*5^3 + 4*5^4 + O(5^5) - sage: pari(R(0)) + sage: pari(R(0)) # needs sage.libs.pari 0 sage: R(pari(R(0,5))) 0 @@ -164,7 +164,7 @@ cdef class pAdicFloatingPointElement(FPElement): TESTS:: - sage: ZpFP(5)(0).lift() #indirect doctest + sage: ZpFP(5)(0).lift() # indirect doctest 0 sage: R = QpFP(5); R(0).lift() 0 @@ -197,9 +197,9 @@ cdef class pAdicFloatingPointElement(FPElement): EXAMPLES:: - sage: R = ZpFP(17, 10); a = ~R(14); pari(a) #indirect doctest + sage: R = ZpFP(17, 10); a = ~R(14); pari(a) # indirect doctest 11 + 3*17 + 17^2 + 6*17^3 + 13*17^4 + 15*17^5 + 10*17^6 + 3*17^7 + 17^8 + 6*17^9 + O(17^10) - sage: pari(R(0)) + sage: pari(R(0)) # needs sage.libs.pari 0 """ return self._to_gen() @@ -210,9 +210,9 @@ cdef class pAdicFloatingPointElement(FPElement): EXAMPLES:: - sage: R = ZpFP(5, 10); a = R(17); pari(a) #indirect doctest + sage: R = ZpFP(5, 10); a = R(17); pari(a) # indirect doctest 2 + 3*5 + O(5^10) - sage: pari(R(0)) + sage: pari(R(0)) # needs sage.libs.pari 0 """ if very_pos_val(self.ordp): @@ -419,6 +419,7 @@ cdef class pAdicFloatingPointElement(FPElement): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Zq(7^2,5) sage: x = R(7*w) sage: x.exp(algorithm="newton") # indirect doctest diff --git a/src/sage/rings/padics/padic_generic.py b/src/sage/rings/padics/padic_generic.py index a929ee60a75..8abc87020fe 100644 --- a/src/sage/rings/padics/padic_generic.py +++ b/src/sage/rings/padics/padic_generic.py @@ -141,7 +141,7 @@ def ngens(self): sage: Zp(5).ngens() 1 - sage: Zq(25,names='a').ngens() + sage: Zq(25,names='a').ngens() # needs sage.libs.ntl 1 """ return 1 @@ -154,9 +154,9 @@ def gens(self): sage: R = Zp(5); R.gens() [5 + O(5^21)] - sage: Zq(25,names='a').gens() + sage: Zq(25,names='a').gens() # needs sage.libs.ntl [a + O(5^20)] - sage: S. = ZZ[]; f = x^5 + 25*x -5; W. = R.ext(f); W.gens() + sage: S. = ZZ[]; f = x^5 + 25*x -5; W. = R.ext(f); W.gens() # needs sage.libs.ntl [w + O(w^101)] """ return [self.gen()] @@ -393,10 +393,10 @@ def fraction_field(self, print_mode=None): DeprecationWarning: Use the change method if you want to change print options in fraction_field() See https://github.com/sagemath/sage/issues/23227 for details. 3132 - sage: U. = Zq(17^4, 6, print_mode='val-unit', print_max_terse_terms=3) - sage: U.fraction_field() + sage: U. = Zq(17^4, 6, print_mode='val-unit', print_max_terse_terms=3) # needs sage.libs.ntl + sage: U.fraction_field() # needs sage.libs.ntl 17-adic Unramified Extension Field in a defined by x^4 + 7*x^2 + 10*x + 3 - sage: U.fraction_field({"pos":False}) == U.fraction_field() + sage: U.fraction_field({"pos":False}) == U.fraction_field() # needs sage.libs.ntl False TESTS:: @@ -453,10 +453,10 @@ def integer_ring(self, print_mode=None): DeprecationWarning: Use the change method if you want to change print options in integer_ring() See https://github.com/sagemath/sage/issues/23227 for details. 3132 - sage: U. = Qq(17^4, 6, print_mode='val-unit', print_max_terse_terms=3) - sage: U.integer_ring() + sage: U. = Qq(17^4, 6, print_mode='val-unit', print_max_terse_terms=3) # needs sage.libs.ntl + sage: U.integer_ring() # needs sage.libs.ntl 17-adic Unramified Extension Ring in a defined by x^4 + 7*x^2 + 10*x + 3 - sage: U.fraction_field({"print_mode":"terse"}) == U.fraction_field() + sage: U.fraction_field({"print_mode":"terse"}) == U.fraction_field() # needs sage.libs.ntl doctest:warning ... DeprecationWarning: Use the change method if you want to change print options in fraction_field() @@ -482,7 +482,7 @@ def integer_ring(self, print_mode=None): The `secure` attribute for relaxed type is preserved:: - sage: K = QpER(5, secure=True) + sage: K = QpER(5, secure=True) # needs sage.libs.flint sage: K.integer_ring().is_secure() True """ @@ -522,6 +522,8 @@ def teichmuller(self, x, prec=None): sage: R = Zp(5, 10, 'fixed-mod', 'series') sage: R.teichmuller(2) 2 + 5 + 2*5^2 + 5^3 + 3*5^4 + 4*5^5 + 2*5^6 + 3*5^7 + 3*5^9 + + sage: # needs sage.libs.ntl sage: R = Zp(5,5) sage: S. = R[] sage: f = x^5 + 75*x^3 - 15*x^2 +125*x - 5 @@ -542,6 +544,7 @@ def teichmuller(self, x, prec=None): We check that :trac:`23736` is resolved:: + sage: # needs sage.libs.ntl sage: R.teichmuller(GF(5)(2)) 2 + 5 + 2*5^2 + 5^3 + 3*5^4 + O(5^5) @@ -581,8 +584,8 @@ def teichmuller_system(self): Check that :trac:`20457` is fixed:: - sage: F. = Qq(5^2,6) - sage: F.teichmuller_system()[3] + sage: F. = Qq(5^2,6) # needs sage.libs.ntl + sage: F.teichmuller_system()[3] # needs sage.libs.ntl (2*a + 2) + (4*a + 1)*5 + 4*5^2 + (2*a + 1)*5^3 + (4*a + 1)*5^4 + (2*a + 3)*5^5 + O(5^6) .. NOTE:: @@ -621,14 +624,13 @@ def extension(self, modulus, prec=None, names=None, print_mode=None, implementat EXAMPLES:: + sage: # needs sage.libs.ntl sage: k = Qp(5) sage: R. = k[] - sage: l. = k.extension(x^2-5); l + sage: l. = k.extension(x^2 - 5); l 5-adic Eisenstein Extension Field in w defined by x^2 - 5 - sage: F = list(Qp(19)['x'](cyclotomic_polynomial(5)).factor())[0][0] - sage: L = Qp(19).extension(F, names='a') - sage: L + sage: L = Qp(19).extension(F, names='a'); L 19-adic Unramified Extension Field in a defined by x^2 + 8751674996211859573806383*x + 1 """ if isinstance(modulus, list): @@ -675,6 +677,7 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = ZZ[] sage: K. = Qq(25, modulus=x^2-2) sage: L. = Qq(625, modulus=x^4-2) @@ -687,7 +690,6 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): True sage: L._is_valid_homomorphism_(L, [-b]) True - sage: W. = K.extension(x^2 - 5) sage: cc = K.hom([-a]) sage: W._is_valid_homomorphism_(W, [w], base_map=cc) @@ -1102,12 +1104,12 @@ def _log_unit_part_p(self): O(3^5) sage: S. = ZZ[] - sage: W. = R.extension(x^3-3) - sage: W._log_unit_part_p() + sage: W. = R.extension(x^3-3) # needs sage.libs.ntl + sage: W._log_unit_part_p() # needs sage.libs.ntl O(pi^15) - sage: W. = R.extension(x^3-3*x-3) - sage: W._log_unit_part_p() + sage: W. = R.extension(x^3-3*x-3) # needs sage.libs.ntl + sage: W._log_unit_part_p() # needs sage.libs.ntl 2 + pi + 2*pi^2 + pi^4 + pi^5 + 2*pi^7 + 2*pi^8 + pi^9 + 2*pi^10 + pi^11 + pi^12 + 2*pi^14 + O(pi^15) """ return self(self.prime()).unit_part().log() @@ -1123,30 +1125,30 @@ def frobenius_endomorphism(self, n=1): EXAMPLES:: - sage: K. = Qq(3^5) - sage: Frob = K.frobenius_endomorphism(); Frob + sage: K. = Qq(3^5) # needs sage.libs.ntl + sage: Frob = K.frobenius_endomorphism(); Frob # needs sage.libs.ntl Frobenius endomorphism on 3-adic Unramified Extension ... lifting a |--> a^3 on the residue field - sage: Frob(a) == a.frobenius() + sage: Frob(a) == a.frobenius() # needs sage.libs.ntl True We can specify a power:: - sage: K.frobenius_endomorphism(2) + sage: K.frobenius_endomorphism(2) # needs sage.libs.ntl Frobenius endomorphism on 3-adic Unramified Extension ... lifting a |--> a^(3^2) on the residue field The result is simplified if possible:: - sage: K.frobenius_endomorphism(6) + sage: K.frobenius_endomorphism(6) # needs sage.libs.ntl Frobenius endomorphism on 3-adic Unramified Extension ... lifting a |--> a^3 on the residue field - sage: K.frobenius_endomorphism(5) + sage: K.frobenius_endomorphism(5) # needs sage.libs.ntl Identity endomorphism of 3-adic Unramified Extension ... Comparisons work:: - sage: K.frobenius_endomorphism(6) == Frob + sage: K.frobenius_endomorphism(6) == Frob # needs sage.libs.ntl True """ from .morphism import FrobeniusEndomorphism_padics @@ -1183,6 +1185,7 @@ def valuation(self): EXAMPLES:: + sage: # needs sage.libs.ntl sage: K = Qp(3) sage: R. = K[] sage: L. = K.extension(a^3 - 3) @@ -1196,9 +1199,9 @@ def valuation(self): The normalization is chosen such that the valuation restricts to the valuation on the base ring:: - sage: v(3) == K.valuation()(3) + sage: v(3) == K.valuation()(3) # needs sage.libs.ntl True - sage: v.restriction(K) == K.valuation() + sage: v.restriction(K) == K.valuation() # needs sage.libs.ntl True .. SEEALSO:: @@ -1229,10 +1232,11 @@ def _primitive_qth_root_of_unity(self, exponent): TESTS:: + sage: # needs sage.libs.ntl sage: K. = Qq(2^3, 5) sage: S. = K[] sage: L. = K.extension(x^2 + 2*x + 2) - sage: zeta = L.primitive_root_of_unity(); zeta # indirect doctest + sage: zeta = L.primitive_root_of_unity(); zeta # indirect doctest a + a*pi + pi^2 + a*pi^4 + a*pi^5 + a^2*pi^8 + a^2*pi^9 + O(pi^10) sage: zeta.parent() is L True @@ -1312,10 +1316,10 @@ def primitive_root_of_unity(self, n=None, order=False): Now we consider an example with non trivial ``p``-th roots of unity:: + sage: # needs sage.libs.ntl sage: W = Zp(3, 2) sage: S. = W[] sage: R. = W.extension((x+1)^6 + (x+1)^3 + 1) - sage: zeta, order = R.primitive_root_of_unity(order=True) sage: zeta 2 + 2*pi + 2*pi^3 + 2*pi^7 + 2*pi^8 + 2*pi^9 + pi^11 + O(pi^12) @@ -1323,7 +1327,6 @@ def primitive_root_of_unity(self, n=None, order=False): 18 sage: zeta.multiplicative_order() 18 - sage: zeta, order = R.primitive_root_of_unity(24, order=True) sage: zeta 2 + pi^3 + 2*pi^7 + 2*pi^8 + 2*pi^10 + 2*pi^11 + O(pi^12) @@ -1397,10 +1400,10 @@ def roots_of_unity(self, n=None): In general, there might be more roots of unity (it happens when the ring has non trivial ``p``-th roots of unity):: + sage: # needs sage.libs.ntl sage: W. = Zq(3^2, 2) sage: S. = W[] sage: R. = W.extension((x+1)^2 + (x+1) + 1) - sage: roots = R.roots_of_unity(); roots [1 + O(pi^4), a + 2*a*pi + 2*a*pi^2 + a*pi^3 + O(pi^4), @@ -1416,6 +1419,7 @@ def roots_of_unity(self, n=None): We check that the logarithm of each root of unity vanishes:: + sage: # needs sage.libs.ntl sage: for root in roots: ....: if root.log() != 0: ....: raise ValueError @@ -1473,6 +1477,7 @@ def _roots_univariate_polynomial(self, P, ring, multiplicities, algorithm, secur EXAMPLES:: + sage: # needs sage.libs.ntl sage: A = Zp(3, prec=10, print_mode='terse') sage: S. = A[] sage: P = x^2 - 7 @@ -1484,13 +1489,13 @@ def _roots_univariate_polynomial(self, P, ring, multiplicities, algorithm, secur We compare with the result given by the method :meth:`sage.rings.padics.padic_generic_element.square_root`:: - sage: A(7).square_root(all=True) + sage: A(7).square_root(all=True) # needs sage.libs.ntl [30793 + O(3^10), 28256 + O(3^10)] Here is another example:: - sage: P = x * (x-1) * (x-2) * (x-3) * (x-4) - sage: P.roots(multiplicities=False) + sage: P = x * (x-1) * (x-2) * (x-3) * (x-4) # needs sage.libs.ntl + sage: P.roots(multiplicities=False) # needs sage.libs.ntl [39370 + O(3^10), 19684 + O(3^10), 2 + O(3^10), @@ -1500,7 +1505,7 @@ def _roots_univariate_polynomial(self, P, ring, multiplicities, algorithm, secur The result is not quite what we expected. In fact, the roots are correct but the precision is not:: - sage: [ root.add_bigoh(9) for root in P.roots(multiplicities=False) ] + sage: [ root.add_bigoh(9) for root in P.roots(multiplicities=False) ] # needs sage.libs.ntl [4 + O(3^9), 1 + O(3^9), 2 + O(3^9), @@ -1512,7 +1517,7 @@ def _roots_univariate_polynomial(self, P, ring, multiplicities, algorithm, secur If we are switching to ``"sage"`` then the precision on the result becomes correct (but the computation is much slower):: - sage: P.roots(multiplicities=False, algorithm="sage") + sage: P.roots(multiplicities=False, algorithm="sage") # needs sage.geometry.polyhedron sage.libs.ntl [0, 3 + O(3^11), 1 + O(3^9), @@ -1521,27 +1526,27 @@ def _roots_univariate_polynomial(self, P, ring, multiplicities, algorithm, secur We check that the keyword ``secure`` works as explained above:: - sage: P = x^2 + O(3^10)*x + O(3^10) - sage: P.roots(algorithm="sage") + sage: P = x^2 + O(3^10)*x + O(3^10) # needs sage.libs.ntl + sage: P.roots(algorithm="sage") # needs sage.geometry.polyhedron sage.libs.ntl [(O(3^5), 2)] - sage: P.roots(algorithm="sage", secure=True) + sage: P.roots(algorithm="sage", secure=True) # needs sage.libs.ntl Traceback (most recent call last): ... PrecisionError: not enough precision to determine the number of roots An example over an extension:: - sage: B. = Zq(3^3, prec=10, print_mode='terse') - sage: P = B.modulus() + sage: B. = Zq(3^3, prec=10, print_mode='terse') # needs sage.libs.ntl + sage: P = B.modulus() # needs sage.libs.ntl We check that `P` has no root in `A`:: - sage: P.roots() + sage: P.roots() # needs sage.libs.ntl [] but that it has roots in `B`:: - sage: P.roots(B) + sage: P.roots(B) # needs sage.geometry.polyhedron sage.libs.ntl [(35149 + 57730*b + 41124*b^2 + O(3^10), 1), (23900 + 1318*b + 17925*b^2 + O(3^10), 1), (b + O(3^10), 1)] @@ -1549,21 +1554,21 @@ def _roots_univariate_polynomial(self, P, ring, multiplicities, algorithm, secur We check further that the other roots are the conjugates of ``b`` under Frobenius:: - sage: b.frobenius() + sage: b.frobenius() # needs sage.libs.ntl 23900 + 1318*b + 17925*b^2 + O(3^10) - sage: b.frobenius().frobenius() + sage: b.frobenius().frobenius() # needs sage.libs.ntl 35149 + 57730*b + 41124*b^2 + O(3^10) Root finding works over ramified extensions also:: + sage: # needs sage.libs.ntl sage: E = x^3 - 3*x + 3*b sage: C. = B.extension(E) - sage: E.roots(C) + sage: E.roots(C) # needs sage.geometry.polyhedron [(pi + O(pi^30), 1)] - sage: S. = C[] sage: P = prod(x - (pi+i) for i in range(5)) - sage: P.roots() + sage: P.roots() # needs sage.geometry.polyhedron [(pi + O(pi^29), 1), (3 + pi + O(pi^29), 1), (1 + pi + O(pi^27), 1), @@ -1572,7 +1577,7 @@ def _roots_univariate_polynomial(self, P, ring, multiplicities, algorithm, secur TESTS:: - sage: S(0).roots() + sage: S(0).roots() # needs sage.libs.ntl Traceback (most recent call last): ... ArithmeticError: factorization of 0 is not defined @@ -1615,8 +1620,8 @@ class ResidueReductionMap(Morphism): EXAMPLES:: sage: from sage.rings.padics.padic_generic import ResidueReductionMap - sage: R. = Zq(125); k = R.residue_field() - sage: f = ResidueReductionMap._create_(R, k); f + sage: R. = Zq(125); k = R.residue_field() # needs sage.libs.ntl + sage: f = ResidueReductionMap._create_(R, k); f # needs sage.libs.ntl Reduction morphism: From: 5-adic Unramified Extension Ring in a defined by x^3 + 3*x + 3 To: Finite Field in a0 of size 5^3 @@ -1634,10 +1639,10 @@ def _create_(R, k): EXAMPLES:: - sage: f = Zmod(49).convert_map_from(Zp(7)) - sage: TestSuite(f).run() - sage: K. = Qq(125); k = K.residue_field(); f = k.convert_map_from(K) - sage: TestSuite(f).run() + sage: f = Zmod(49).convert_map_from(Zp(7)) # needs sage.rings.finite_rings + sage: TestSuite(f).run() # needs sage.rings.finite_rings + sage: K. = Qq(125); k = K.residue_field(); f = k.convert_map_from(K) # needs sage.libs.ntl + sage: TestSuite(f).run() # needs sage.rings.finite_rings """ if R.is_field(): from sage.categories.sets_with_partial_maps import SetsWithPartialMaps @@ -1667,7 +1672,7 @@ def is_surjective(self): EXAMPLES:: - sage: GF(7).convert_map_from(Qp(7)).is_surjective() + sage: GF(7).convert_map_from(Qp(7)).is_surjective() # needs sage.rings.finite_rings True """ return True @@ -1678,7 +1683,7 @@ def is_injective(self): EXAMPLES:: - sage: GF(5).convert_map_from(ZpCA(5)).is_injective() + sage: GF(5).convert_map_from(ZpCA(5)).is_injective() # needs sage.rings.finite_rings False """ return False @@ -1689,6 +1694,7 @@ def _call_(self, x): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Zq(125); k = R.residue_field() sage: f = k.convert_map_from(R) sage: f(15) @@ -1696,7 +1702,7 @@ def _call_(self, x): sage: f(1/(1+a)) a0^2 + 4*a0 + 4 - sage: Zmod(121).convert_map_from(Qp(11))(3/11) + sage: Zmod(121).convert_map_from(Qp(11))(3/11) # needs sage.rings.finite_rings Traceback (most recent call last): ... ValueError: element must have non-negative valuation in order to compute residue @@ -1710,7 +1716,7 @@ def section(self): EXAMPLES:: - sage: GF(3).convert_map_from(Zp(3)).section() + sage: GF(3).convert_map_from(Zp(3)).section() # needs sage.rings.finite_rings Lifting morphism: From: Finite Field of size 3 To: 3-adic Ring with capped relative precision 20 @@ -1723,7 +1729,7 @@ def _repr_type(self): EXAMPLES:: - sage: GF(3).convert_map_from(Zp(3))._repr_type() + sage: GF(3).convert_map_from(Zp(3))._repr_type() # needs sage.rings.finite_rings 'Reduction' """ return "Reduction" @@ -1758,8 +1764,8 @@ class ResidueLiftingMap(Morphism): EXAMPLES:: sage: from sage.rings.padics.padic_generic import ResidueLiftingMap - sage: R. = Zq(125); k = R.residue_field() - sage: f = ResidueLiftingMap._create_(k, R); f + sage: R. = Zq(125); k = R.residue_field() # needs sage.libs.ntl + sage: f = ResidueLiftingMap._create_(k, R); f # needs sage.libs.ntl Lifting morphism: From: Finite Field in a0 of size 5^3 To: 5-adic Unramified Extension Ring in a defined by x^3 + 3*x + 3 @@ -1799,12 +1805,12 @@ def _call_(self, x): EXAMPLES:: - sage: R. = Zq(27); k = R.residue_field(); a0 = k.gen() - sage: f = R.convert_map_from(k); f + sage: R. = Zq(27); k = R.residue_field(); a0 = k.gen() # needs sage.libs.ntl + sage: f = R.convert_map_from(k); f # needs sage.libs.ntl Lifting morphism: From: Finite Field in a0 of size 3^3 To: 3-adic Unramified Extension Ring in a defined by x^3 + 2*x + 1 - sage: f(a0 + 1) + sage: f(a0 + 1) # needs sage.libs.ntl (a + 1) + O(3) sage: Zp(3)(Zmod(81)(0)) @@ -1830,7 +1836,7 @@ def _call_with_args(self, x, args=(), kwds={}): EXAMPLES:: sage: f = Zp(2).convert_map_from(Zmod(128)) - sage: f(7, 5) # indirect doctest + sage: f(7, 5) # indirect doctest 1 + 2 + 2^2 + O(2^5) """ R = self.codomain() @@ -1867,6 +1873,7 @@ def _richcmp_(self, other, op): EXAMPLES:: + sage: # needs sage.rings.finite_rings sage: from sage.rings.padics.padic_generic import ResidueLiftingMap sage: f = ResidueLiftingMap._create_(GF(3), Zp(3)) sage: g = ResidueLiftingMap._create_(GF(3), Zp(3)) diff --git a/src/sage/rings/padics/padic_generic_element.pyx b/src/sage/rings/padics/padic_generic_element.pyx index c54005de2f7..88797ddf4ed 100644 --- a/src/sage/rings/padics/padic_generic_element.pyx +++ b/src/sage/rings/padics/padic_generic_element.pyx @@ -67,7 +67,7 @@ cdef class pAdicGenericElement(LocalGenericElement): :: sage: R = Zp(5); a = R(5, 6); b = R(5 + 5^6, 8) - sage: a == b #indirect doctest + sage: a == b # indirect doctest True :: @@ -329,7 +329,7 @@ cdef class pAdicGenericElement(LocalGenericElement): EXAMPLES:: sage: R = ZpCA(5); a = R(129378); b = R(2398125) - sage: a // b #indirect doctest + sage: a // b # indirect doctest 1 + 2*5 + 2*5^3 + 4*5^4 + 5^6 + 5^7 + 5^8 + 4*5^9 + 2*5^10 + 4*5^11 + 4*5^12 + 2*5^13 + 3*5^14 + O(5^16) sage: a / b 4*5^-4 + 3*5^-3 + 2*5^-2 + 5^-1 + 3 + 3*5 + 4*5^2 + 2*5^4 + 2*5^6 + 4*5^7 + 5^9 + 5^10 + 5^11 + O(5^12) @@ -361,7 +361,7 @@ cdef class pAdicGenericElement(LocalGenericElement): EXAMPLES:: sage: R = Zp(5, 5); a = R(77) - sage: a // 15 # indirect doctest + sage: a // 15 # indirect doctest 5 + O(5^4) """ return self.quo_rem(right, integral=True)[0] @@ -375,7 +375,7 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: R = Zp(7,4,'capped-rel','series'); a = R(1/3); a 5 + 4*7 + 4*7^2 + 4*7^3 + O(7^4) - sage: a[0] #indirect doctest + sage: a[0] # indirect doctest doctest:warning ... DeprecationWarning: __getitem__ is changing to match the behavior of number fields. Please use expansion instead. @@ -435,8 +435,9 @@ cdef class pAdicGenericElement(LocalGenericElement): For extension elements, "zeros" match the behavior of ``list``:: + sage: # needs sage.libs.ntl sage: S. = Qq(125) - sage: a[-2] + sage: a[-2] # needs sage.rings.padics [] .. SEEALSO:: @@ -455,7 +456,7 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: R = Zp(7,4,'capped-rel','series'); a = R(3); a 3 + O(7^4) - sage: ~a #indirect doctest + sage: ~a # indirect doctest 5 + 4*7 + 4*7^2 + 4*7^3 + O(7^4) .. NOTE:: @@ -555,14 +556,15 @@ cdef class pAdicGenericElement(LocalGenericElement): EXAMPLES:: - sage: Zp(5,5)(1/3) # indirect doctest + sage: Zp(5,5)(1/3) # indirect doctest 2 + 3*5 + 5^2 + 3*5^3 + 5^4 + O(5^5) We check that :trac:`26479` is fixed:: + sage: # needs sage.libs.ntl sage: x = polygen(ZZ, 'x') sage: K. = Qp(2).extension(x^3 - 2) - sage: latex(pi) + sage: latex(pi) # needs sage.symbolic \pi + O(\pi^{61}) """ return self.parent()._printer.repr_gen(self, do_latex, mode=mode) @@ -695,10 +697,10 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: x = PowerSeriesRing(QQ, 'x', default_prec=82).gen() sage: AH = sum(x**(3**i)/(3**i) for i in range(5)).O(82).exp() sage: z = Zp(3)(33/7) - sage: ahz = AH(z); ahz + sage: ahz = AH(z); ahz # needs sage.libs.ntl 1 + 2*3 + 3^2 + 3^3 + 2*3^5 + 3^6 + 2*3^7 + 3^9 + 3^11 + 3^12 + 3^13 + 3^14 + 2*3^15 + 3^16 + 2*3^18 + 2*3^19 + O(3^20) - sage: ahz - z.artin_hasse_exp() + sage: ahz - z.artin_hasse_exp() # needs sage.libs.ntl O(3^20) Out of convergence domain:: @@ -772,9 +774,10 @@ cdef class pAdicGenericElement(LocalGenericElement): When `x^{p^i}/p^i` is not in the domain of convergence of the exponential for some nonnegative integer `i`, an error is raised:: + sage: # needs sage.libs.ntl sage: S. = W[] sage: R. = W.extension(x^2 + 3) - sage: pi.artin_hasse_exp(algorithm='direct') # indirect doctest + sage: pi.artin_hasse_exp(algorithm='direct') # indirect doctest # needs sage.symbolic Traceback (most recent call last): ... NotImplementedError: one factor of the Artin-Hasse exponential does not converge @@ -801,7 +804,7 @@ cdef class pAdicGenericElement(LocalGenericElement): 1 + 2^3 + 2^4 + 2^5 + 2^7 + O(2^8) sage: y1 == -y2 True - sage: y1 == x.artin_hasse_exp(algorithm='series') + sage: y1 == x.artin_hasse_exp(algorithm='series') # needs sage.symbolic True .. SEEALSO:: @@ -858,12 +861,13 @@ cdef class pAdicGenericElement(LocalGenericElement): EXAMPLES:: sage: W = Zp(3,10) - sage: W(123456).artin_hasse_exp(algorithm='series') # indirect doctest + sage: W(123456).artin_hasse_exp(algorithm='series') # indirect doctest # needs sage.symbolic 1 + 3 + 2*3^3 + 2*3^4 + 3^5 + 2*3^6 + 2*3^7 + 3^8 + O(3^10) + sage: # needs sage.libs.ntl sage: S. = W[] sage: R. = W.extension(x^2 + 3) - sage: pi.artin_hasse_exp(algorithm='series') # indirect doctest + sage: pi.artin_hasse_exp(algorithm='series') # indirect doctest # needs sage.symbolic 1 + pi + 2*pi^2 + 2*pi^3 + 2*pi^4 + 2*pi^10 + 2*pi^11 + pi^13 + pi^18 + pi^19 + O(pi^20) .. SEEALSO:: @@ -911,9 +915,10 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: W(123456).artin_hasse_exp(algorithm='newton') # indirect doctest 1 + 3 + 2*3^3 + 2*3^4 + 3^5 + 2*3^6 + 2*3^7 + 3^8 + O(3^10) + sage: # needs sage.libs.ntl sage: S. = W[] sage: R. = W.extension(x^2 + 3) - sage: pi.artin_hasse_exp(algorithm='newton') # indirect doctest + sage: pi.artin_hasse_exp(algorithm='newton') # indirect doctest # needs sage.symbolic 1 + pi + 2*pi^2 + 2*pi^3 + 2*pi^4 + 2*pi^10 + 2*pi^11 + pi^13 + pi^18 + pi^19 + O(pi^20) .. SEEALSO:: @@ -978,25 +983,24 @@ cdef class pAdicGenericElement(LocalGenericElement): EXAMPLES:: - sage: Zp(5,5)(1/3).minimal_polynomial('x') + sage: Zp(5,5)(1/3).minimal_polynomial('x') # needs sage.libs.ntl (1 + O(5^5))*x + 3 + 5 + 3*5^2 + 5^3 + 3*5^4 + O(5^5) - sage: Zp(5,5)(1/3).minimal_polynomial('foo') + sage: Zp(5,5)(1/3).minimal_polynomial('foo') # needs sage.libs.ntl (1 + O(5^5))*foo + 3 + 5 + 3*5^2 + 5^3 + 3*5^4 + O(5^5) :: + sage: # needs sage.libs.ntl sage: K. = QqCR(2^3,5) sage: S. = K[] sage: L. = K.extension(x^4 - 2*a) - - sage: pi.minimal_polynomial() + sage: pi.minimal_polynomial() # needs sage.symbolic (1 + O(2^5))*x^4 + a*2 + a*2^2 + a*2^3 + a*2^4 + a*2^5 + O(2^6) - sage: (pi^2).minimal_polynomial() + sage: (pi^2).minimal_polynomial() # needs sage.symbolic (1 + O(2^5))*x^2 + a*2 + a*2^2 + a*2^3 + a*2^4 + a*2^5 + O(2^6) - sage: (1/pi).minimal_polynomial() + sage: (1/pi).minimal_polynomial() # needs sage.symbolic (1 + O(2^5))*x^4 + (a^2 + 1)*2^-1 + O(2^4) - sage: elt = L.random_element() sage: P = elt.minimal_polynomial() # not tested, known bug (see :trac:`32111`) sage: P(elt) == 0 # not tested @@ -1053,26 +1057,26 @@ cdef class pAdicGenericElement(LocalGenericElement): EXAMPLES:: - sage: Zp(5)(5).norm() + sage: Zp(5)(5).norm() # needs sage.libs.ntl 5 + O(5^21) :: + sage: # needs sage.libs.ntl sage: K. = QqCR(2^3,5) sage: S. = K[] sage: L. = K.extension(x^4 - 2*a) - - sage: pi.norm() # norm over K + sage: pi.norm() # norm over K # needs sage.symbolic a*2 + a*2^2 + a*2^3 + a*2^4 + a*2^5 + O(2^6) - sage: (pi^2).norm() + sage: (pi^2).norm() # needs sage.symbolic a^2*2^2 + O(2^7) - sage: pi.norm()^2 + sage: pi.norm()^2 # needs sage.symbolic a^2*2^2 + O(2^7) TESTS:: - sage: x = L.random_element() - sage: y = L.random_element() + sage: x = L.random_element() # needs sage.libs.ntl + sage: y = L.random_element() # needs sage.libs.ntl sage: (x*y).norm() == x.norm() * y.norm() # not tested, known bug (see :trac:`32085`) True @@ -1099,22 +1103,22 @@ cdef class pAdicGenericElement(LocalGenericElement): EXAMPLES:: - sage: Zp(5,5)(5).trace() + sage: Zp(5,5)(5).trace() # needs sage.libs.ntl 5 + O(5^6) + sage: # needs sage.libs.ntl sage: K. = QqCR(2^3,7) sage: S. = K[] sage: L. = K.extension(x^4 - 4*a*x^3 + 2*a) - - sage: pi.trace() # trace over K + sage: pi.trace() # trace over K # needs sage.symbolic a*2^2 + O(2^8) - sage: (pi+1).trace() + sage: (pi+1).trace() # needs sage.symbolic (a + 1)*2^2 + O(2^7) TESTS:: - sage: x = L.random_element() - sage: y = L.random_element() + sage: x = L.random_element() # needs sage.libs.ntl + sage: y = L.random_element() # needs sage.libs.ntl sage: (x+y).trace() == x.trace() + y.trace() # not tested, known bug (see :trac:`32085`) True @@ -1371,8 +1375,8 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: p = next_prime(200) sage: F = Qp(p) - sage: l1 = [F(a/(p-1)).gamma(algorithm='pari') for a in range(p-1)] # long time - sage: l2 = [F(a/(p-1)).gamma(algorithm='sage') for a in range(p-1)] # long time + sage: l1 = [F(a/(p-1)).gamma(algorithm='pari') for a in range(p-1)] # long time + sage: l2 = [F(a/(p-1)).gamma(algorithm='sage') for a in range(p-1)] # long time sage: all(l1[i] == l2[i] for i in range(p-1)) # long time True @@ -1504,24 +1508,22 @@ cdef class pAdicGenericElement(LocalGenericElement): The implementation also works over extensions:: + sage: # needs sage.libs.ntl sage: K = Qp(3) sage: R. = K[] sage: L. = K.extension(a^3-3) sage: (a+3).gcd(3) 1 + O(a^60) - sage: R = Zp(3) sage: S. = R[] sage: S. = R.extension(a^3-3) sage: (a+3).gcd(3) a + O(a^61) - sage: K = Qp(3) sage: R. = K[] sage: L. = K.extension(a^2-2) sage: (a+3).gcd(3) 1 + O(3^20) - sage: R = Zp(3) sage: S. = R[] sage: S. = R.extension(a^2-2) @@ -1620,6 +1622,7 @@ cdef class pAdicGenericElement(LocalGenericElement): If only one element is zero, then the result depends on its precision:: + sage: # needs sage.rings.padics sage: R(9).xgcd(R(0,1)) (O(3), 0, 1 + O(3^20)) sage: R(9).xgcd(R(0,2)) @@ -1646,6 +1649,7 @@ cdef class pAdicGenericElement(LocalGenericElement): The implementation also works over extensions:: + sage: # needs sage.libs.ntl sage: K = Qp(3) sage: R. = K[] sage: L. = K.extension(a^3-3) @@ -1657,7 +1661,6 @@ cdef class pAdicGenericElement(LocalGenericElement): + 2*a^40 + 2*a^41 + 2*a^44 + 2*a^45 + 2*a^48 + 2*a^49 + 2*a^52 + 2*a^53 + 2*a^56 + 2*a^57 + O(a^59), 0) - sage: R = Zp(3) sage: S. = R[] sage: S. = R.extension(a^3-3) @@ -1669,7 +1672,6 @@ cdef class pAdicGenericElement(LocalGenericElement): + 2*a^41 + 2*a^42 + 2*a^45 + 2*a^46 + 2*a^49 + 2*a^50 + 2*a^53 + 2*a^54 + 2*a^57 + 2*a^58 + O(a^60), 0) - sage: K = Qp(3) sage: R. = K[] sage: L. = K.extension(a^2-2) @@ -1680,7 +1682,6 @@ cdef class pAdicGenericElement(LocalGenericElement): + (2*a + 2)*3^12 + a*3^13 + (2*a + 1)*3^14 + (a + 2)*3^16 + 3^17 + (2*a + 2)*3^18 + a*3^19 + O(3^20), 0) - sage: R = Zp(3) sage: S. = R[] sage: S. = R.extension(a^2-2) @@ -1933,6 +1934,7 @@ cdef class pAdicGenericElement(LocalGenericElement): Over unramified extensions:: + sage: # needs sage.libs.ntl sage: L1. = Qq(5^3) sage: c = L1.teichmuller(a) sage: c.multiplicative_order() @@ -1942,6 +1944,7 @@ cdef class pAdicGenericElement(LocalGenericElement): Over totally ramified extensions:: + sage: # needs sage.libs.ntl sage: x = polygen(ZZ, 'x') sage: L2. = Qp(5).extension(x^4 + 5*x^3 + 10*x^2 + 10*x + 5) sage: u = 1 + pi @@ -2071,8 +2074,8 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: R(1/50).valuation() -2 - sage: K. = Qq(25) - sage: K(0).valuation() + sage: K. = Qq(25) # needs sage.libs.ntl + sage: K(0).valuation() # needs sage.libs.ntl +Infinity sage: R(1/50).valuation(5) @@ -2107,7 +2110,7 @@ cdef class pAdicGenericElement(LocalGenericElement): :: - sage: Zp(5)(5).valuation() #indirect doctest + sage: Zp(5)(5).valuation() # indirect doctest 1 """ raise NotImplementedError @@ -2182,9 +2185,10 @@ cdef class pAdicGenericElement(LocalGenericElement): :: + sage: # needs sage.libs.ntl sage: x = polygen(ZZ, 'x') sage: B. = A.extension(x^5 - 2) - sage: pi.is_prime() + sage: pi.is_prime() # needs sage.symbolic True sage: B(2).is_prime() False @@ -2239,7 +2243,7 @@ cdef class pAdicGenericElement(LocalGenericElement): EXAMPLES:: sage: R = Zp(7,5) - sage: QQ(R(125)) # indirect doctest + sage: QQ(R(125)) # indirect doctest 125 """ try: @@ -2258,9 +2262,9 @@ cdef class pAdicGenericElement(LocalGenericElement): EXAMPLES:: - sage: R. = Zq(125) - sage: K = R.exact_field() - sage: a._number_field_(K) + sage: R. = Zq(125) # needs sage.libs.ntl + sage: K = R.exact_field() # needs sage.libs.ntl + sage: a._number_field_(K) # needs sage.libs.ntl a """ Kbase = K.base_ring() @@ -2280,6 +2284,7 @@ cdef class pAdicGenericElement(LocalGenericElement): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = ZZ[] sage: K. = Qq(25, modulus=x^2-2) sage: L. = Qq(625, modulus=x^4-2) @@ -2293,14 +2298,15 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: psi(z*w) == psi(z) * psi(w) True + sage: # needs sage.libs.ntl sage: P. = K.extension(x^2 - 5) sage: cc = K.hom([-a]) sage: alpha = P.hom([pi], base_map=cc); alpha(a) + a O(pi^40) sage: zz = (1 + a*pi).log() - sage: ww = pi.exp() + sage: ww = pi.exp() # needs sage.symbolic sage: beta = P.hom([-pi], base_map=cc) - sage: beta(ww*zz) == beta(ww)*beta(zz) + sage: beta(ww*zz) == beta(ww)*beta(zz) # needs sage.symbolic True """ L = self.parent() @@ -2641,16 +2647,17 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: R = Zp(5,5) sage: S. = ZZ[] sage: f = x^4 + 15*x^2 + 625*x - 5 - sage: W. = R.ext(f) - sage: z = 1 + w^2 + 4*w^7; z + sage: W. = R.ext(f) # needs sage.libs.ntl + sage: z = 1 + w^2 + 4*w^7; z # needs sage.libs.ntl 1 + w^2 + 4*w^7 + O(w^20) - sage: z.log() + sage: z.log() # needs sage.libs.ntl w^2 + 2*w^4 + 3*w^6 + 4*w^7 + w^9 + 4*w^10 + 4*w^11 + 4*w^12 + 3*w^14 + w^15 + w^17 + 3*w^18 + 3*w^19 + O(w^20) In an extension, there will usually be a difference between specifying ``p_branch`` and ``pi_branch``:: + sage: # needs sage.libs.ntl sage: b = W(5) sage: b.log() Traceback (most recent call last): @@ -2677,11 +2684,12 @@ cdef class pAdicGenericElement(LocalGenericElement): Check that log is multiplicative:: - sage: y.log(p_branch=0) + z.log() - (y*z).log(p_branch=0) + sage: y.log(p_branch=0) + z.log() - (y*z).log(p_branch=0) # needs sage.libs.ntl O(w^20) Now an unramified example:: + sage: # needs sage.libs.ntl sage: g = x^3 + 3*x + 3 sage: A. = R.ext(g) sage: b = 1 + 5*(1 + a^2) + 5^3*(3 + 2*a) @@ -2691,6 +2699,7 @@ cdef class pAdicGenericElement(LocalGenericElement): Check that log is multiplicative:: + sage: # needs sage.libs.ntl sage: c = 3 + 5^2*(2 + 4*a) sage: b.log() + c.log() - (b*c).log() O(5^5) @@ -2729,13 +2738,13 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: R = ZpCA(3,10) sage: S. = R[] sage: f = x^3 - 3 - sage: W. = R.ext(f) - sage: w.log(p_branch=2) + sage: W. = R.ext(f) # needs sage.libs.ntl sage.rings.padics + sage: w.log(p_branch=2) # needs sage.libs.ntl sage.rings.padics Traceback (most recent call last): ... ValueError: logarithm is not integral, use change_frac=True to obtain a result in the fraction field - sage: w.log(p_branch=2, change_frac=True) + sage: w.log(p_branch=2, change_frac=True) # needs sage.libs.ntl sage.rings.padics 2*w^-3 + O(w^24) TESTS: @@ -2813,7 +2822,7 @@ cdef class pAdicGenericElement(LocalGenericElement): 7 + 3*7^2 + 4*7^3 + 3*7^4 sage: x.log(aprec = 7) 7 + 3*7^2 + 4*7^3 + 3*7^4 + 7^5 + 3*7^6 - sage: x.log() + sage: x.log() # needs sage.symbolic 7 + 3*7^2 + 4*7^3 + 3*7^4 + 7^5 + 3*7^6 + 7^7 + 3*7^8 + 4*7^9 Check that precision is computed correctly in highly ramified @@ -2822,6 +2831,8 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: S. = ZZ[] sage: K = Qp(5,5) sage: f = x^625 - 5*x - 5 + + sage: # needs sage.libs.ntl sage.rings.padics sage: W. = K.extension(f) sage: z = 1 - w^2 + O(w^11) sage: x = 1 - z @@ -2834,9 +2845,10 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: (x^125/125).precision_absolute() -775 + sage: # needs sage.libs.ntl sage: z = 1 - w + O(w^2) sage: x = 1 - z - sage: z.log().precision_absolute() + sage: z.log().precision_absolute() # needs sage.rings.padics -1625 sage: (x^5/5).precision_absolute() -615 @@ -2847,7 +2859,7 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: (x^625/625).precision_absolute() -1250 - sage: z.log().precision_relative() + sage: z.log().precision_relative() # needs sage.libs.ntl sage.rings.padics 250 Performances:: @@ -2974,9 +2986,9 @@ cdef class pAdicGenericElement(LocalGenericElement): EXAMPLES:: - sage: R. = Zq(7^2,5) - sage: x = R(7*w) - sage: x.exp(algorithm="generic") # indirect doctest + sage: R. = Zq(7^2,5) # needs sage.libs.ntl + sage: x = R(7*w) # needs sage.libs.ntl + sage: x.exp(algorithm="generic") # indirect doctest # needs sage.libs.ntl 1 + w*7 + (4*w + 2)*7^2 + (w + 6)*7^3 + 5*7^4 + O(7^5) AUTHORS: @@ -3123,9 +3135,9 @@ cdef class pAdicGenericElement(LocalGenericElement): EXAMPLES:: - sage: R. = Zq(7^2,5) - sage: x = R(7*w) - sage: x.exp(algorithm="newton") # indirect doctest + sage: R. = Zq(7^2,5) # needs sage.libs.ntl + sage: x = R(7*w) # needs sage.libs.ntl + sage: x.exp(algorithm="newton") # indirect doctest # needs sage.libs.ntl 1 + w*7 + (4*w + 2)*7^2 + (w + 6)*7^3 + 5*7^4 + O(7^5) """ R = self.parent() @@ -3223,6 +3235,7 @@ cdef class pAdicGenericElement(LocalGenericElement): Logarithms and exponentials in extension fields. First, in an Eisenstein extension:: + sage: # needs sage.libs.ntl sage: R = Zp(5,5) sage: S. = R[] sage: f = x^4 + 15*x^2 + 625*x - 5 @@ -3234,6 +3247,7 @@ cdef class pAdicGenericElement(LocalGenericElement): Now an unramified example:: + sage: # needs sage.libs.ntl sage: R = Zp(5,5) sage: S. = R[] sage: g = x^3 + 3*x + 3 @@ -3270,6 +3284,7 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: a.log().exp() 1 + 13 + O(13^10) + sage: # needs sage.libs.ntl sage: R = ZpCA(5,5) sage: S. = R[] sage: f = x^4 + 15*x^2 + 625*x - 5 @@ -3287,6 +3302,7 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: a.log().exp() 1 + 13 + sage: # needs sage.libs.ntl sage: R = ZpFM(5,5) sage: S. = R[] sage: f = x^4 + 15*x^2 + 625*x - 5 @@ -3304,6 +3320,7 @@ cdef class pAdicGenericElement(LocalGenericElement): ... ValueError: Exponential does not converge for that input. + sage: # needs sage.libs.ntl sage: S. = Z2[] sage: W. = Z2.ext(x^3-2) sage: (w^2).exp() @@ -3436,12 +3453,13 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: R2(4).square_root() 2 + O(2^20) - sage: R. = Zq(2^10, 10) - sage: u = 1 + 8*t - sage: u.square_root() + sage: R. = Zq(2^10, 10) # needs sage.libs.ntl + sage: u = 1 + 8*t # needs sage.libs.ntl + sage: u.square_root() # needs sage.libs.ntl 1 + t*2^2 + t^2*2^3 + t^2*2^4 + (t^4 + t^3 + t^2)*2^5 + (t^4 + t^2)*2^6 + (t^5 + t^2)*2^7 + (t^6 + t^5 + t^4 + t^2)*2^8 + O(2^9) + sage: # needs sage.libs.ntl sage: x = polygen(ZZ, 'x') sage: R. = Zp(2).extension(x^3 - 2) sage: u = R(1 + a^4 + a^5 + a^7 + a^8, 10); u @@ -3452,21 +3470,20 @@ cdef class pAdicGenericElement(LocalGenericElement): However, observe that the precision increases to its original value when we recompute the square of the square root:: - sage: v^2 + sage: v^2 # needs sage.libs.ntl 1 + a^4 + a^5 + a^7 + a^8 + O(a^10) If the input does not have enough precision in order to determine if the given element has a square root in the ground field, an error is raised:: + sage: # needs sage.libs.ntl sage: R(1, 6).square_root() Traceback (most recent call last): ... PrecisionError: not enough precision to be sure that this element has a square root - sage: R(1, 7).square_root() 1 + O(a^4) - sage: R(1+a^6, 7).square_root(extend=False) Traceback (most recent call last): ... @@ -3617,6 +3634,7 @@ cdef class pAdicGenericElement(LocalGenericElement): Everything works over extensions as well:: + sage: # needs sage.libs.ntl sage: W. = Zq(5^3) sage: S. = W[] sage: R. = W.extension(x^7 - 5) @@ -3628,7 +3646,7 @@ cdef class pAdicGenericElement(LocalGenericElement): An error is raised if the given element is not an `n`-th power in the ring:: - sage: R(5).nth_root(11) + sage: R(5).nth_root(11) # needs sage.libs.ntl Traceback (most recent call last): ... ValueError: this element is not a nth power @@ -3636,6 +3654,7 @@ cdef class pAdicGenericElement(LocalGenericElement): Similarly, when precision on the input is too small, an error is raised:: + sage: # needs sage.libs.ntl sage: x = R(1,6); x 1 + O(pi^6) sage: x.nth_root(5) @@ -3645,6 +3664,7 @@ cdef class pAdicGenericElement(LocalGenericElement): Check that :trac:`30314` is fixed:: + sage: # needs sage.libs.ntl sage: K = Qp(29) sage: x = polygen(K) sage: L. = K.extension(x^2 - 29) @@ -3655,6 +3675,7 @@ cdef class pAdicGenericElement(LocalGenericElement): We check that it works over different fields:: + sage: # needs sage.libs.ntl sage: K. = Qq(2^3) sage: S. = K[] sage: L. = K.extension(x^2 + 2*x + 2) @@ -3668,6 +3689,7 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: elt in (elt^56).nth_root(56, all=True) True + sage: # needs sage.libs.ntl sage: K. = Qq(3^2) sage: S. = K[] sage: Z = (1+x)^3 @@ -3683,6 +3705,7 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: elt in (elt^108).nth_root(108, all=True) True + sage: # needs sage.libs.flint sage.libs.ntl sage: K. = ZqCA(3^2) sage: S. = K[] sage: Z = (1+x)^3 + 3*x^2 @@ -3692,16 +3715,17 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: elt in (elt^9).nth_root(9, all=True) True sage: elt = L.random_element() - sage: try: + sage: try: # needs sage.rings.real_double ....: assert elt in (elt^27).nth_root(27, all=True) ....: except sage.rings.padics.precision_error.PrecisionError: ....: pass sage: elt = L.random_element() - sage: try: + sage: try: # needs sage.rings.real_double ....: assert elt in (elt^108).nth_root(108, all=True) ....: except sage.rings.padics.precision_error.PrecisionError: ....: pass + sage: # needs sage.libs.ntl sage: K. = Qq(3^2) sage: S. = K[] sage: Z = (1+x)^3 + 3*x^3 @@ -3847,6 +3871,7 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: [ R.teichmuller(x).nth_root(11) == R.teichmuller(x) for x in range(1,11) ] # indirect doctest [True, True, True, True, True, True, True, True, True, True] + sage: # needs sage.libs.ntl sage: W. = Zq(5^3) sage: S. = W[] sage: R. = W.extension(x^8 + 15*a*x - 5) @@ -3977,6 +4002,7 @@ cdef class pAdicGenericElement(LocalGenericElement): An unramified extension:: + sage: # needs sage.libs.ntl sage: R = Zp(5,5) sage: P. = PolynomialRing(R) sage: Z25. = R.ext(x^2 - 3) @@ -3987,6 +4013,7 @@ cdef class pAdicGenericElement(LocalGenericElement): A ramified extension:: + sage: # needs sage.libs.ntl sage: W. = R.ext(x^5 + 75*x^3 - 15*x^2 + 125*x - 5) sage: abs(w) 0.724779663677696 @@ -4012,15 +4039,16 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: a = Qp(5)(15); a.abs() 1/5 - sage: a.abs(53) + sage: a.abs(53) # needs sage.rings.real_mpfr 0.200000000000000 sage: Qp(7)(0).abs() 0 - sage: Qp(7)(0).abs(prec=20) + sage: Qp(7)(0).abs(prec=20) # needs sage.rings.real_mpfr 0.00000 An unramified extension:: + sage: # needs sage.libs.ntl sage: R = Zp(5,5) sage: P. = PolynomialRing(R) sage: Z25. = R.ext(x^2 - 3) @@ -4031,6 +4059,7 @@ cdef class pAdicGenericElement(LocalGenericElement): A ramified extension:: + sage: # needs sage.libs.ntl sage: W. = R.ext(x^5 + 75*x^3 - 15*x^2 + 125*x - 5) sage: w.abs() 0.724779663677696 @@ -4084,7 +4113,7 @@ cdef class pAdicGenericElement(LocalGenericElement): EXAMPLES:: - sage: Qp(2)(-1)._polylog_res_1(6) == 0 + sage: Qp(2)(-1)._polylog_res_1(6) == 0 # needs sage.symbolic True sage: Qp(5)(1)._polylog_res_1(1) @@ -4169,25 +4198,25 @@ cdef class pAdicGenericElement(LocalGenericElement): The `n`-th polylogarithm of `-1` is `0` for even `n`:: - sage: Qp(13)(-1).polylog(6) == 0 + sage: Qp(13)(-1).polylog(6) == 0 # needs sage.rings.real_mpfr sage.symbolic True We can check some identities, for example those mentioned in [DCW2016]_:: sage: x = Qp(7, prec=30)(1/3) - sage: (x^2).polylog(4) - 8*x.polylog(4) - 8*(-x).polylog(4) == 0 + sage: (x^2).polylog(4) - 8*x.polylog(4) - 8*(-x).polylog(4) == 0 # needs sage.symbolic True :: sage: x = Qp(5, prec=30)(4) - sage: x.polylog(2) + (1/x).polylog(2) + x.log(0)**2/2 == 0 + sage: x.polylog(2) + (1/x).polylog(2) + x.log(0)**2/2 == 0 # needs sage.symbolic True :: sage: x = Qp(11, prec=30)(2) - sage: x.polylog(2) + (1-x).polylog(2) + x.log(0)**2*(1-x).log(0) == 0 + sage: x.polylog(2) + (1-x).polylog(2) + x.log(0)**2*(1-x).log(0) == 0 # needs sage.symbolic True `Li_1(z) = -\log(1-z)` for `|z| < 1`:: @@ -4197,14 +4226,14 @@ cdef class pAdicGenericElement(LocalGenericElement): The dilogarithm of 1 is zero:: - sage: Qp(5)(1).polylog(2) + sage: Qp(5)(1).polylog(2) # needs sage.rings.real_mpfr sage.symbolic O(5^20) The cubing relation holds for the trilogarithm at 1:: sage: K = Qp(7) sage: z = K.zeta(3) - sage: -8*K(1).polylog(3) == 9*(K(z).polylog(3) + K(z^2).polylog(3)) + sage: -8*K(1).polylog(3) == 9*(K(z).polylog(3) + K(z^2).polylog(3)) # needs sage.rings.padics sage.rings.real_mpfr sage.symbolic True The polylogarithm of 0 is 0:: @@ -4222,7 +4251,7 @@ cdef class pAdicGenericElement(LocalGenericElement): Check that :trac:`29222` is fixed:: sage: K = Qp(7) - sage: print(K(1 + 7^11).polylog(4)) + sage: print(K(1 + 7^11).polylog(4)) # needs sage.symbolic 6*7^14 + 3*7^15 + 7^16 + 7^17 + O(7^18) ALGORITHM: @@ -4365,7 +4394,7 @@ def _AHE_coefficients(p, N, prec): However, the result is *not* guaranteed to be correct beyond the requested precision:: - sage: L = _AHE_coefficients(2, 513, 1); L + sage: L = _AHE_coefficients(2, 513, 1); L # needs sage.symbolic [1, 1, 1, @@ -4380,13 +4409,13 @@ def _AHE_coefficients(p, N, prec): sage: S. = PowerSeriesRing(QQ, 513) sage: AH = exp(sum(x^(2^i) / 2^i for i in range(10))) sage: R = ZpFM(2, 1) - sage: [ R(c) for c in L ] == [ R(c) for c in AH.list() ] + sage: [ R(c) for c in L ] == [ R(c) for c in AH.list() ] # needs sage.rings.padics True But it is not modulo `2^{10}`:: sage: R = ZpFM(2, 10) - sage: [ R(c) for c in L ] == [ R(c) for c in AH.list() ] + sage: [ R(c) for c in L ] == [ R(c) for c in AH.list() ] # needs sage.rings.padics False """ @@ -4424,7 +4453,7 @@ def _polylog_c(n, p): EXAMPLES:: - sage: sage.rings.padics.padic_generic_element._polylog_c(1, 2) + sage: sage.rings.padics.padic_generic_element._polylog_c(1, 2) # needs sage.symbolic 4.52876637294490 """ return p/(p-1) - (n-1)/p.log().n() + (n-1)*(n*(p-1)/p.log().n()).log(p).n() + (2*p*(p-1)*n/p.log().n()).log(p).n() @@ -4446,7 +4475,7 @@ def _findprec(c_1, c_2, c_3, p): EXAMPLES:: - sage: sage.rings.padics.padic_generic_element._findprec(1, 1, 2, 2) + sage: sage.rings.padics.padic_generic_element._findprec(1, 1, 2, 2) # needs sage.rings.real_double sage.rings.real_mpfr sage.symbolic 5 sage: 5*1 - 5*log(1, 2) > 2 True @@ -4470,7 +4499,7 @@ def _compute_g(p, n, prec, terms): EXAMPLES:: - sage: sage.rings.padics.padic_generic_element._compute_g(7, 3, 3, 3)[0] + sage: sage.rings.padics.padic_generic_element._compute_g(7, 3, 3, 3)[0] # needs sage.libs.ntl sage.rings.real_double O(7^3)*v^2 + (1 + O(7^3))*v + O(7^3) """ from sage.rings.power_series_ring import PowerSeriesRing diff --git a/src/sage/rings/padics/padic_lattice_element.py b/src/sage/rings/padics/padic_lattice_element.py index a8d9e507b90..e2c80855b71 100644 --- a/src/sage/rings/padics/padic_lattice_element.py +++ b/src/sage/rings/padics/padic_lattice_element.py @@ -17,7 +17,7 @@ sage: R3 = QpLC(2) sage: R4 = QpLF(2) - sage: # long time + sage: # long time, needs sage.rings.padics sage: TestSuite(R1).run(skip=['_test_teichmuller', '_test_matrix_smith']) sage: TestSuite(R2).run(skip=['_test_teichmuller', '_test_matrix_smith']) sage: TestSuite(R3).run(skip=['_test_teichmuller', '_test_matrix_smith']) diff --git a/src/sage/rings/padics/padic_printing.pyx b/src/sage/rings/padics/padic_printing.pyx index a75f85b4cf0..caf19c7bdf9 100644 --- a/src/sage/rings/padics/padic_printing.pyx +++ b/src/sage/rings/padics/padic_printing.pyx @@ -211,7 +211,7 @@ class pAdicPrinterDefaults(SageObject): sage: padic_printing.max_unram_terms(2) sage: padic_printing.max_unram_terms() 2 - sage: Zq(5^6, 5, names='a')([1,2,3,-1])^17 + sage: Zq(5^6, 5, names='a')([1,2,3,-1])^17 # needs sage.libs.ntl (3*a^4 + ... + 3) + (a^5 + ... + a)*5 + (3*a^3 + ... + 2)*5^2 + (3*a^5 + ... + 2)*5^3 + (4*a^5 + ... + 4)*5^4 + O(5^5) sage: padic_printing.max_unram_terms(-1) @@ -236,7 +236,7 @@ class pAdicPrinterDefaults(SageObject): sage: padic_printing.max_poly_terms() 3 sage: padic_printing.mode('terse') - sage: Zq(7^5, 5, names='a')([2,3,4])^8 + sage: Zq(7^5, 5, names='a')([2,3,4])^8 # needs sage.libs.ntl 2570 + 15808*a + 9018*a^2 + ... + O(7^5) sage: padic_printing.max_poly_terms(-1) @@ -379,7 +379,7 @@ cdef class pAdicPrinter_class(SageObject): TESTS:: - sage: R = Qp(7, print_mode='bars', print_sep='&') #indirect doctest + sage: R = Qp(7, print_mode='bars', print_sep='&') # indirect doctest sage: R = Zp(5, print_mode='digits', print_max_terms=10) Traceback (most recent call last): @@ -614,7 +614,7 @@ cdef class pAdicPrinter_class(SageObject): EXAMPLES:: - sage: Zp(5)._printer #indirect doctest + sage: Zp(5)._printer # indirect doctest series printer for 5-adic Ring with capped relative precision 20 """ return "%s printer for %s"%(self._print_mode(), self.ring) @@ -830,7 +830,7 @@ cdef class pAdicPrinter_class(SageObject): EXAMPLES:: sage: P = Zp(17)._printer - sage: P._base_p_list(1298734,True) #indirect doctest + sage: P._base_p_list(1298734,True) # indirect doctest [2, 15, 5, 9, 15] sage: P._base_p_list(1298734,False) [2, -2, 6, -8, -1, 1] @@ -900,7 +900,7 @@ cdef class pAdicPrinter_class(SageObject): EXAMPLES:: - sage: R = Zp(7,4,'capped-rel','val-unit'); a = R(364); a #indirect doctest + sage: R = Zp(7,4,'capped-rel','val-unit'); a = R(364); a # indirect doctest 7 * 52 + O(7^5) sage: print(a.str('terse')) 364 + O(7^5) diff --git a/src/sage/rings/padics/padic_template_element.pxi b/src/sage/rings/padics/padic_template_element.pxi index 4ca0356774f..7dcb624b666 100644 --- a/src/sage/rings/padics/padic_template_element.pxi +++ b/src/sage/rings/padics/padic_template_element.pxi @@ -97,6 +97,7 @@ cdef class pAdicTemplateElement(pAdicGenericElement): TESTS:: + sage: # needs sage.libs.ntl sage: QQq. = Qq(25,4) sage: FFp = Zp(5,5).residue_field() sage: QQq(FFp.zero()) @@ -517,6 +518,7 @@ cdef class pAdicTemplateElement(pAdicGenericElement): Check to see that :trac:`10292` is resolved:: + sage: # needs sage.schemes sage: E = EllipticCurve('37a') sage: R = E.padic_regulator(7) sage: len(R.expansion()) @@ -613,6 +615,7 @@ cdef class pAdicTemplateElement(pAdicGenericElement): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(125) sage: b = a^2 + 5*a + 1 sage: b._ext_p_list(True) @@ -633,6 +636,7 @@ cdef class pAdicTemplateElement(pAdicGenericElement): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Zq(125) sage: (5*a).unit_part() a + O(5^20) @@ -692,6 +696,7 @@ cdef class pAdicTemplateElement(pAdicGenericElement): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Zq(27, 4) sage: (3 + 3*a).residue() 0 @@ -700,6 +705,7 @@ cdef class pAdicTemplateElement(pAdicGenericElement): TESTS:: + sage: # needs sage.libs.ntl sage: a.residue(0) 0 sage: a.residue(2) @@ -715,12 +721,14 @@ cdef class pAdicTemplateElement(pAdicGenericElement): ... NotImplementedError: reduction modulo p^n with n>1 + sage: # needs sage.libs.flint sage: R. = ZqCA(27, 4) sage: (3 + 3*a).residue() 0 sage: (a + 1).residue() a0 + 1 + sage: # needs sage.libs.ntl sage: R. = Qq(27, 4) sage: (3 + 3*a).residue() 0 @@ -825,7 +833,7 @@ cdef long padic_pow_helper(celement result, celement base, long base_val, long b sage: a = R(9283732, 6); b = R(17^3*237, 7) sage: str(a) '...692AAF' - sage: str(a^b) # indirect doctest + sage: str(a^b) # indirect doctest '...55GA0001' sage: str((a // R.teichmuller(15))^b) '...55GA0001' @@ -898,7 +906,7 @@ cdef class ExpansionIter(): EXAMPLES:: sage: E = Zp(5,4)(373).expansion() - sage: I = iter(E) # indirect doctest + sage: I = iter(E) # indirect doctest sage: type(I) """ @@ -1031,7 +1039,7 @@ cdef class ExpansionIterable(): EXAMPLES:: - sage: E = Zp(5,4)(373).expansion() # indirect doctest + sage: E = Zp(5,4)(373).expansion() # indirect doctest sage: type(E) """ diff --git a/src/sage/rings/padics/padic_valuation.py b/src/sage/rings/padics/padic_valuation.py index ec85d00c3f2..cb0207c10d4 100644 --- a/src/sage/rings/padics/padic_valuation.py +++ b/src/sage/rings/padics/padic_valuation.py @@ -8,9 +8,9 @@ 2-adic valuation sage: QQ.valuation(3) 3-adic valuation - sage: CyclotomicField(5).valuation(5) + sage: CyclotomicField(5).valuation(5) # needs sage.rings.number_field 5-adic valuation - sage: GaussianIntegers().valuation(7) + sage: GaussianIntegers().valuation(7) # needs sage.rings.number_field 7-adic valuation sage: Zp(11).valuation() 11-adic valuation @@ -21,7 +21,7 @@ sage: v = ZZ.valuation(2) sage: R. = ZZ[] sage: f = x^5 + x^4 + x^3 + x^2 + x - 1 - sage: v.montes_factorization(f, required_precision=20) + sage: v.montes_factorization(f, required_precision=20) # needs sage.geometry.polyhedron (x + 676027) * (x^4 + 372550*x^3 + 464863*x^2 + 385052*x + 297869) AUTHORS: @@ -92,6 +92,7 @@ class PadicValuationFactory(UniqueFactory): quotient of a polynomial ring (since number field extensions always compute an absolute polynomial defining the extension which can be very costly):: + sage: # needs sage.rings.number_field sage: R. = QQ[] sage: K. = NumberField(x^2 + 1) sage: R. = K[] @@ -115,7 +116,7 @@ def create_key_and_extra_args(self, R, prime=None, approximants=None): EXAMPLES:: - sage: QQ.valuation(2) # indirect doctest + sage: QQ.valuation(2) # indirect doctest 2-adic valuation """ @@ -145,7 +146,7 @@ def create_key_for_integers(self, R, prime): EXAMPLES:: - sage: QQ.valuation(2) # indirect doctest + sage: QQ.valuation(2) # indirect doctest 2-adic valuation """ @@ -166,7 +167,7 @@ def create_key_for_local_ring(self, R, prime): EXAMPLES:: - sage: Qp(2).valuation() # indirect doctest + sage: Qp(2).valuation() # indirect doctest 2-adic valuation """ @@ -188,7 +189,7 @@ def create_key_and_extra_args_for_number_field(self, R, prime, approximants): EXAMPLES:: - sage: GaussianIntegers().valuation(2) # indirect doctest + sage: GaussianIntegers().valuation(2) # indirect doctest # needs sage.rings.number_field 2-adic valuation """ @@ -218,7 +219,7 @@ def create_key_and_extra_args_for_number_field_from_valuation(self, R, v, prime, EXAMPLES:: - sage: GaussianIntegers().valuation(ZZ.valuation(2)) # indirect doctest + sage: GaussianIntegers().valuation(ZZ.valuation(2)) # indirect doctest # needs sage.rings.number_field 2-adic valuation TESTS: @@ -227,10 +228,10 @@ def create_key_and_extra_args_for_number_field_from_valuation(self, R, v, prime, sage: R. = ZZ[] sage: S = R.quo(x^2 + 1) - sage: v = valuations.pAdicValuation(S, 2) + sage: v = valuations.pAdicValuation(S, 2) # needs sage.geometry.polyhedron sage: R. = QQ[] sage: S = R.quo(x^2 + 1) - sage: v = valuations.pAdicValuation(S, v) + sage: v = valuations.pAdicValuation(S, v) # needs sage.geometry.polyhedron """ K, L, G = self._normalize_number_field_data(R) @@ -282,13 +283,15 @@ def create_key_and_extra_args_for_number_field_from_ideal(self, R, I, prime): EXAMPLES:: - sage: GaussianIntegers().valuation(GaussianIntegers().number_field().fractional_ideal(2)) # indirect doctest + sage: # needs sage.rings.number_field + sage: GaussianIntegers().valuation(GaussianIntegers().number_field().fractional_ideal(2)) # indirect doctest 2-adic valuation TESTS: Verify that :trac:`28976` has been resolved:: + sage: # needs sage.rings.number_field sage: R. = QQ[] sage: K. = NumberField(x^6 - 18*x^4 - 24*x^3 + 27*x^2 + 36*x - 6) sage: I = K.fractional_ideal((2, -7/44*a^5 + 19/44*a^4 + 87/44*a^3 - 87/44*a^2 - 5/2*a + 39/22)) @@ -301,6 +304,7 @@ def create_key_and_extra_args_for_number_field_from_ideal(self, R, I, prime): :: + sage: # needs sage.rings.number_field sage: K. = NumberField([x^2 - 2, x^2 + x + 1]) sage: K.valuation(2) 2-adic valuation @@ -384,7 +388,7 @@ def create_object(self, version, key, **extra_args): EXAMPLES:: - sage: ZZ.valuation(5) # indirect doctest + sage: ZZ.valuation(5) # indirect doctest 5-adic valuation """ @@ -448,9 +452,9 @@ class pAdicValuation_base(DiscreteValuation): TESTS:: - sage: TestSuite(ZZ.valuation(3)).run() # long time - sage: TestSuite(QQ.valuation(5)).run() # long time - sage: TestSuite(Zp(5).valuation()).run() # long time + sage: TestSuite(ZZ.valuation(3)).run() # long time # needs sage.geometry.polyhedron + sage: TestSuite(QQ.valuation(5)).run() # long time # needs sage.geometry.polyhedron + sage: TestSuite(Zp(5).valuation()).run() # long time # needs sage.geometry.polyhedron """ def __init__(self, parent, p): @@ -473,7 +477,7 @@ def p(self): EXAMPLES:: - sage: GaussianIntegers().valuation(2).p() + sage: GaussianIntegers().valuation(2).p() # needs sage.rings.number_field 2 """ @@ -562,7 +566,7 @@ def is_unramified(self, G, include_steps=False, assume_squarefree=False): However, even if ``G`` factors, it might define an unramified extension:: - sage: v.is_unramified(x^2 + 2*x + 4) + sage: v.is_unramified(x^2 + 2*x + 4) # needs sage.geometry.polyhedron True """ @@ -626,11 +630,12 @@ def is_totally_ramified(self, G, include_steps=False, assume_squarefree=False): EXAMPLES:: + sage: # needs sage.libs.ntl sage: k = Qp(5,4) sage: v = k.valuation() sage: R. = k[] sage: G = x^2 + 1 - sage: v.is_totally_ramified(G) + sage: v.is_totally_ramified(G) # needs sage.geometry.polyhedron False sage: G = x + 1 sage: v.is_totally_ramified(G) @@ -639,9 +644,9 @@ def is_totally_ramified(self, G, include_steps=False, assume_squarefree=False): sage: v.is_totally_ramified(G) False sage: G = x^2 + 5 - sage: v.is_totally_ramified(G) + sage: v.is_totally_ramified(G) # needs sage.geometry.polyhedron True - sage: v.is_totally_ramified(G, include_steps=True) + sage: v.is_totally_ramified(G, include_steps=True) # needs sage.geometry.polyhedron (True, [Gauss valuation induced by 5-adic valuation, [ Gauss valuation induced by 5-adic valuation, v((1 + O(5^4))*x) = 1/2 ]]) We consider an extension as totally ramified if its ramification index @@ -659,7 +664,7 @@ def is_totally_ramified(self, G, include_steps=False, assume_squarefree=False): sage: R = ZpFM(3, 20) sage: S. = R[] sage: f = x^9 + 9*x^2 + 3 - sage: R.valuation().is_totally_ramified(f) + sage: R.valuation().is_totally_ramified(f) # needs sage.geometry.polyhedron True """ @@ -734,11 +739,12 @@ def extensions(self, ring): EXAMPLES:: sage: v = ZZ.valuation(2) - sage: v.extensions(GaussianIntegers()) + sage: v.extensions(GaussianIntegers()) # needs sage.rings.number_field [2-adic valuation] TESTS:: + sage: # needs sage.rings.number_field sage: R. = QQ[] sage: x = polygen(ZZ, 'x') sage: L. = QQ.extension(x^3 - 2) @@ -749,6 +755,7 @@ def extensions(self, ring): Check that we can extend to a field written as a quotient:: + sage: # needs sage.rings.number_field sage: R. = QQ[] sage: K. = QQ.extension(x^2 + 1) sage: R. = K[] @@ -759,6 +766,7 @@ def extensions(self, ring): A case where there was at some point an internal error in the approximants code:: + sage: # needs sage.rings.number_field sage: R. = QQ[] sage: L. = NumberField(x^4 + 2*x^3 + 2*x^2 + 8) sage: QQ.valuation(2).extensions(L) @@ -767,6 +775,7 @@ def extensions(self, ring): A case where the extension was incorrect at some point:: + sage: # needs sage.rings.number_field sage: v = QQ.valuation(2) sage: L. = NumberField(x^2 + 2) sage: M. = L.extension(x^2 + 1) @@ -776,6 +785,7 @@ def extensions(self, ring): A case where the extensions could not be separated at some point:: + sage: # needs sage.rings.number_field sage: v = QQ.valuation(2) sage: R. = QQ[] sage: F = x^48 + 120*x^45 + 56*x^42 + 108*x^36 + 32*x^33 + 40*x^30 + 48*x^27 + 80*x^24 + 112*x^21 + 96*x^18 + 96*x^15 + 24*x^12 + 96*x^9 + 16*x^6 + 96*x^3 + 68 @@ -819,8 +829,8 @@ def restriction(self, ring): EXAMPLES:: - sage: v = GaussianIntegers().valuation(2) - sage: v.restriction(ZZ) + sage: v = GaussianIntegers().valuation(2) # needs sage.rings.number_field + sage: v.restriction(ZZ) # needs sage.rings.number_field 2-adic valuation """ @@ -839,8 +849,8 @@ def value_semigroup(self): EXAMPLES:: - sage: v = GaussianIntegers().valuation(2) - sage: v.value_semigroup() + sage: v = GaussianIntegers().valuation(2) # needs sage.rings.number_field + sage: v.value_semigroup() # needs sage.rings.number_field Additive Abelian Semigroup generated by 1/2 """ @@ -862,12 +872,12 @@ class pAdicValuation_padic(pAdicValuation_base): EXAMPLES:: - sage: v = Qp(2).valuation(); v #indirect doctest + sage: v = Qp(2).valuation(); v # indirect doctest 2-adic valuation TESTS:: - sage: TestSuite(v).run() # long time + sage: TestSuite(v).run() # long time # needs sage.geometry.polyhedron """ def __init__(self, parent): @@ -952,6 +962,7 @@ def element_with_valuation(self, v): sage: v.element_with_valuation(3) 3^3 + O(3^23) + sage: # needs sage.libs.ntl sage: K = Qp(3) sage: R. = K[] sage: L. = K.extension(y^2 + 3*y + 3) @@ -986,9 +997,9 @@ def _call_(self, x): EXAMPLES:: sage: K = Qp(3) - sage: R. = K[] - sage: L. = K.extension(y^2 - 3) - sage: L.valuation()(3) + sage: R. = K[] # needs sage.libs.ntl + sage: L. = K.extension(y^2 - 3) # needs sage.libs.ntl + sage: L.valuation()(3) # needs sage.libs.ntl 1 """ @@ -1000,7 +1011,7 @@ def residue_ring(self): EXAMPLES:: - sage: Qq(9, names='a').valuation().residue_ring() + sage: Qq(9, names='a').valuation().residue_ring() # needs sage.libs.ntl Finite Field in a0 of size 3^2 """ @@ -1027,6 +1038,7 @@ def shift(self, x, s): sage: v.shift(R.one(), -1) O(2^19) + sage: # needs sage.libs.ntl sage.rings.padics sage: S. = R[] sage: S. = R.extension(y^3 - 2) sage: v = S.valuation() @@ -1089,7 +1101,7 @@ class pAdicValuation_int(pAdicValuation_base): TESTS:: - sage: TestSuite(v).run() # long time + sage: TestSuite(v).run() # long time # needs sage.geometry.polyhedron """ def _repr_(self): @@ -1343,17 +1355,17 @@ class pAdicFromLimitValuation(FiniteExtensionFromLimitValuation, pAdicValuation_ EXAMPLES:: - sage: v = GaussianIntegers().valuation(3); v + sage: v = GaussianIntegers().valuation(3); v # needs sage.rings.number_field 3-adic valuation TESTS:: - sage: TestSuite(v).run(skip='_test_shift') # long time + sage: TestSuite(v).run(skip='_test_shift') # long time # needs sage.rings.number_field The ``_test_shift`` test fails because the parent of the shift is incorrect, see :trac:`23971`:: - sage: v.shift(1, -1).parent() + sage: v.shift(1, -1).parent() # needs sage.rings.number_field Number Field in I with defining polynomial x^2 + 1 with I = 1*I """ @@ -1361,9 +1373,9 @@ def __init__(self, parent, approximant, G, approximants): r""" TESTS:: - sage: v = GaussianIntegers().valuation(3) + sage: v = GaussianIntegers().valuation(3) # needs sage.rings.number_field sage: from sage.rings.padics.padic_valuation import pAdicFromLimitValuation - sage: isinstance(v, pAdicFromLimitValuation) + sage: isinstance(v, pAdicFromLimitValuation) # needs sage.rings.number_field True """ @@ -1377,15 +1389,16 @@ def _to_base_domain(self, f): EXAMPLES:: - sage: v = GaussianIntegers().valuation(3) - sage: I = GaussianIntegers().fraction_field().gen() - sage: v._to_base_domain(I) + sage: v = GaussianIntegers().valuation(3) # needs sage.rings.number_field + sage: I = GaussianIntegers().fraction_field().gen() # needs sage.rings.number_field + sage: v._to_base_domain(I) # needs sage.rings.number_field x TESTS: Check that this also works for relative extensions:: + sage: # needs sage.rings.number_field sage: v = QQ.valuation(2) sage: x = polygen(ZZ, 'x') sage: L. = NumberField(x^2 + 2) @@ -1405,8 +1418,8 @@ def _from_base_domain(self, f): EXAMPLES:: - sage: v = GaussianIntegers().valuation(3) - sage: v._from_base_domain(v._base_valuation.domain().gen()) + sage: v = GaussianIntegers().valuation(3) # needs sage.rings.number_field + sage: v._from_base_domain(v._base_valuation.domain().gen()) # needs sage.rings.number_field I """ @@ -1418,8 +1431,8 @@ def extensions(self, ring): EXAMPLES:: - sage: v = GaussianIntegers().valuation(3) - sage: v.extensions(v.domain().fraction_field()) + sage: v = GaussianIntegers().valuation(3) # needs sage.rings.number_field + sage: v.extensions(v.domain().fraction_field()) # needs sage.rings.number_field [3-adic valuation] """ diff --git a/src/sage/rings/padics/pow_computer.pyx b/src/sage/rings/padics/pow_computer.pyx index 4753be2c6ee..83aa163d36b 100644 --- a/src/sage/rings/padics/pow_computer.pyx +++ b/src/sage/rings/padics/pow_computer.pyx @@ -153,7 +153,7 @@ cdef class PowComputer_class(SageObject): EXAMPLES:: sage: PC = PowComputer(3, 5, 10) - sage: PC.pow_Integer_Integer(2) #indirect doctest + sage: PC.pow_Integer_Integer(2) # indirect doctest 9 """ cdef Integer ans = PY_NEW(Integer) @@ -175,6 +175,8 @@ cdef class PowComputer_class(SageObject): 1 sage: PC.pow_Integer_Integer(10) 59049 + + sage: # needs sage.libs.ntl sage: PC = PowComputer_ext_maker(3, 5, 10, 20, False, ntl.ZZ_pX([-3,0,1], 3^10), 'big','e',ntl.ZZ_pX([1],3^10)) sage: PC.pow_Integer_Integer(4) 81 @@ -226,7 +228,7 @@ cdef class PowComputer_class(SageObject): to that mpz_t. So if you try to use the results of two calls at once, things will break. :: - sage: PC._pow_mpz_t_tmp_demo(6, 8) # 244140625 on some architectures and 152587890625 on others: random + sage: PC._pow_mpz_t_tmp_demo(6, 8) # 244140625 on some architectures and 152587890625 on others: random 244140625 sage: 5^6*5^8 6103515625 @@ -265,6 +267,8 @@ cdef class PowComputer_class(SageObject): 1 sage: PC._pow_mpz_t_tmp_test(10) 59049 + + sage: # needs sage.libs.ntl sage: PC = PowComputer_ext_maker(3, 5, 10, 20, False, ntl.ZZ_pX([-3,0,1], 3^10), 'big','e',ntl.ZZ_pX([1],3^10)) sage: PC._pow_mpz_t_tmp_test(4) 81 @@ -287,7 +291,7 @@ cdef class PowComputer_class(SageObject): EXAMPLES:: sage: PC = PowComputer(3, 5, 10) - sage: PC._pow_mpz_t_top_test() #indirect doctest + sage: PC._pow_mpz_t_top_test() # indirect doctest 59049 """ raise NotImplementedError @@ -301,6 +305,8 @@ cdef class PowComputer_class(SageObject): sage: PC = PowComputer(3, 5, 10) sage: PC._pow_mpz_t_top_test() 59049 + + sage: # needs sage.libs.ntl sage: PC = PowComputer_ext_maker(3, 5, 10, 20, False, ntl.ZZ_pX([-3,0,1], 3^10), 'big','e',ntl.ZZ_pX([1],3^10)) sage: PC._pow_mpz_t_top_test() 59049 @@ -424,6 +430,7 @@ cdef class PowComputer_class(SageObject): else: return self.pow_Integer(mpz_get_ui(_n.value)) + cdef class PowComputer_base(PowComputer_class): def __cinit__(self, Integer prime, long cache_limit, long prec_cap, long ram_prec_cap, bint in_field, poly=None, shift_seed=None): """ @@ -556,7 +563,7 @@ cdef class PowComputer_base(PowComputer_class): EXAMPLES:: sage: PC = PowComputer(3, 5, 10) - sage: PC._pow_mpz_t_top_test() #indirect doctest + sage: PC._pow_mpz_t_top_test() # indirect doctest 59049 """ return self.top_power @@ -600,7 +607,7 @@ cdef PowComputer_base PowComputer_c(Integer m, Integer cache_limit, Integer prec EXAMPLES:: - sage: PC = PowComputer(3, 5, 10) # indirect doctest + sage: PC = PowComputer(3, 5, 10) # indirect doctest sage: PC(4) 81 """ diff --git a/src/sage/rings/padics/pow_computer_ext.pyx b/src/sage/rings/padics/pow_computer_ext.pyx index 742464a492d..82140353d10 100644 --- a/src/sage/rings/padics/pow_computer_ext.pyx +++ b/src/sage/rings/padics/pow_computer_ext.pyx @@ -4,6 +4,7 @@ # distutils: library_dirs = NTL_LIBDIR # distutils: extra_link_args = NTL_LIBEXTRA # distutils: language = c++ +# sage.doctest: needs sage.rings.padics """ PowComputer_ext @@ -89,7 +90,7 @@ cdef int ZZ_pX_Eis_init(PowComputer_ZZ_pX prime_pow, ntl_ZZ_pX shift_seed) excep EXAMPLES:: - sage: A = PowComputer_ext_maker(5, 10, 10, 40, False, ntl.ZZ_pX([-5,65,125,0,1],5^10), 'small','e',ntl.ZZ_pX([1,-13,-25],5^10)) # indirect doctest + sage: A = PowComputer_ext_maker(5, 10, 10, 40, False, ntl.ZZ_pX([-5,65,125,0,1],5^10), 'small','e',ntl.ZZ_pX([1,-13,-25],5^10)) # indirect doctest """ if prime_pow.deg <= 1: raise ValueError("Eisenstein extension must have degree at least 2") @@ -307,7 +308,7 @@ cdef int ZZ_pX_eis_shift_p(PowComputer_ZZ_pX self, ZZ_pX_c* x, ZZ_pX_c* a, long sage: R. = QQ[] sage: K = Qp(11,10) - sage: J. = K.extension(x^30-11) + sage: J. = K.extension(x^30 - 11) sage: M. = PowerSeriesRing(J) sage: S. = QQ[] sage: xr = O(a^152)*t + (8*a^2 + 10*a^32 + 7*a^62 + 10*a^92 + 7*a^122 + O(a^152))*t^2 + O(a^154)*t^3 + (2*a^4 + 10*a^64 + 2*a^124 + O(a^154))*t^4 + O(a^156)*t^5 + (5*a^6 + 2*a^96 + a^126 + O(a^156))*t^6 + O(a^158)*t^7 + (7*a^8 + 6*a^38 + 8*a^68 + 2*a^98 + 5*a^128 + O(a^158))*t^8 + O(a^160)*t^9 + (8*a^10 + 10*a^40 + a^70 + 5*a^130 + O(a^160))*t^10 + O(a^162)*t^11 + (9*a^12 + 7*a^42 + 8*a^72 + 6*a^102 + 9*a^132 + O(a^162))*t^12 + O(a^164)*t^13 + (2*a^14 + 5*a^44 + 3*a^74 + a^104 + 4*a^134 + O(a^164))*t^14 + O(a^166)*t^15 + (2*a^16 + 5*a^46 + 8*a^76 + 5*a^106 + 7*a^136 + O(a^166))*t^16 + O(a^168)*t^17 + (7*a^18 + 3*a^48 + 6*a^78 + 9*a^138 + O(a^168))*t^18 + O(a^172)*t^19 + (7*a^50 + 3*a^80 + 5*a^110 + 5*a^140 + 7*a^170 + O(a^172))*t^20 + O(a^172)*t^21 + (a^22 + a^52 + 3*a^82 + 3*a^112 + 2*a^142 + O(a^172))*t^22 + O(a^174)*t^23 + (4*a^24 + 7*a^54 + 9*a^84 + 4*a^114 + 7*a^144 + O(a^174))*t^24 + O(a^176)*t^25 + (3*a^26 + 8*a^56 + 8*a^116 + 5*a^146 + O(a^176))*t^26 + O(a^178)*t^27 + (2*a^28 + 2*a^58 + 6*a^88 + a^118 + 10*a^148 + O(a^178))*t^28 + O(a^180)*t^29 + (8*a^30 + 5*a^60 + 8*a^90 + 5*a^120 + 6*a^150 + O(a^180))*t^30 + O(a^184)*t^31 + (7*a^62 + 9*a^92 + 2*a^182 + O(a^184))*t^32 @@ -465,7 +466,7 @@ cdef class PowComputer_ext(PowComputer_class): EXAMPLES:: - sage: PC = PowComputer_ext_maker(5, 10, 10, 20, False, ntl.ZZ_pX([-5, 0, 1], 5^10), 'small', 'e',ntl.ZZ_pX([1],5^10)) #indirect doctest + sage: PC = PowComputer_ext_maker(5, 10, 10, 20, False, ntl.ZZ_pX([-5, 0, 1], 5^10), 'small', 'e',ntl.ZZ_pX([1],5^10)) # indirect doctest """ PowComputer_class.__init__(self, prime, cache_limit, prec_cap, ram_prec_cap, in_field, poly, shift_seed) @@ -500,7 +501,7 @@ cdef class PowComputer_ext(PowComputer_class): EXAMPLES:: sage: PC = PowComputer_ext_maker(5, 5, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'FM', 'e',ntl.ZZ_pX([1],5^10)) - sage: del PC # indirect doctest + sage: del PC # indirect doctest """ if (self)._initialized: self.cleanup_ext() @@ -512,7 +513,7 @@ cdef class PowComputer_ext(PowComputer_class): EXAMPLES:: sage: PC = PowComputer_ext_maker(5, 10, 10, 20, False, ntl.ZZ_pX([-5, 0, 1], 5^10), 'small', 'e',ntl.ZZ_pX([1],5^10)) - sage: PC # indirect doctest + sage: PC # indirect doctest PowComputer_ext for 5, with polynomial [9765620 0 1] """ return "PowComputer_ext for %s, with polynomial %s"%(self.prime, self.polynomial()) @@ -544,7 +545,7 @@ cdef class PowComputer_ext(PowComputer_class): EXAMPLES:: sage: PC = PowComputer_ext_maker(5, 5, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'FM', 'e',ntl.ZZ_pX([1],5^10)) - sage: del PC # indirect doctest + sage: del PC # indirect doctest """ Delete_ZZ_array(self.small_powers) mpz_clear(self.temp_m) @@ -570,7 +571,7 @@ cdef class PowComputer_ext(PowComputer_class): EXAMPLES:: sage: PC = PowComputer_ext_maker(5, 10, 10, 20, False, ntl.ZZ_pX([-5, 0, 1], 5^10), 'small', 'e',ntl.ZZ_pX([1],5^10)) - sage: PC._pow_mpz_t_tmp_test(4) #indirect doctest + sage: PC._pow_mpz_t_tmp_test(4) # indirect doctest 625 """ if n < 0: @@ -607,7 +608,7 @@ cdef class PowComputer_ext(PowComputer_class): EXAMPLES:: sage: PC = PowComputer_ext_maker(5, 10, 10, 20, False, ntl.ZZ_pX([-5, 0, 1], 5^10), 'small', 'e',ntl.ZZ_pX([1],5^10)) - sage: PC._pow_mpz_t_tmp_test(4) #indirect doctest + sage: PC._pow_mpz_t_tmp_test(4) # indirect doctest 625 """ if n < 0: @@ -681,7 +682,7 @@ cdef class PowComputer_ext(PowComputer_class): EXAMPLES:: sage: PC = PowComputer_ext_maker(5, 6, 6, 12, False, ntl.ZZ_pX([-5,0,1],5^6),'small', 'e',ntl.ZZ_pX([1],5^6)) - sage: PC._pow_mpz_t_top_test() #indirect doctest + sage: PC._pow_mpz_t_top_test() # indirect doctest 15625 """ ZZ_to_mpz(self.temp_m, &self.top_power) @@ -694,7 +695,7 @@ cdef class PowComputer_ext(PowComputer_class): EXAMPLES:: sage: PC = PowComputer_ext_maker(5, 6, 6, 12, False, ntl.ZZ_pX([-5,0,1],5^6),'small', 'e',ntl.ZZ_pX([1],5^6)) - sage: PC._pow_ZZ_top_test() #indirect doctest + sage: PC._pow_ZZ_top_test() # indirect doctest 15625 """ return &self.top_power @@ -766,7 +767,7 @@ cdef class PowComputer_ZZ_pX(PowComputer_ext): EXAMPLES:: sage: PC = PowComputer_ext_maker(5, 10, 10, 20, False, ntl.ZZ_pX([-5, 0, 1], 5^10), 'FM', 'e',ntl.ZZ_pX([1],5^10)) - sage: PC._get_context_test(15) #indirect doctest + sage: PC._get_context_test(15) # indirect doctest NTL modulus 30517578125 """ cdef ntl_ZZ pn = ntl_ZZ.__new__(ntl_ZZ) @@ -802,7 +803,7 @@ cdef class PowComputer_ZZ_pX(PowComputer_ext): EXAMPLES:: sage: PC = PowComputer_ext_maker(5, 10, 10, 20, False, ntl.ZZ_pX([-5, 0, 1], 5^10), 'FM', 'e',ntl.ZZ_pX([1],5^10)) - sage: PC._get_context_capdiv_test(30) #indirect doctest + sage: PC._get_context_capdiv_test(30) # indirect doctest NTL modulus 30517578125 """ return self.get_context(self.capdiv(n)) @@ -840,7 +841,7 @@ cdef class PowComputer_ZZ_pX(PowComputer_ext): EXAMPLES:: sage: PC = PowComputer_ext_maker(5, 10, 10, 20, False, ntl.ZZ_pX([-5, 0, 1], 5^10), 'small', 'e',ntl.ZZ_pX([1],5^10)) - sage: PC.speed_test(10, 10^6) # random + sage: PC.speed_test(10, 10^6) # random 0.0090679999999991878 """ cdef Py_ssize_t i, end, _n @@ -859,7 +860,7 @@ cdef class PowComputer_ZZ_pX(PowComputer_ext): TESTS:: sage: PC = PowComputer_ext_maker(5, 5, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'FM', 'e',ntl.ZZ_pX([1],5^10)) - sage: PC._get_top_context_test() #indirect doctest + sage: PC._get_top_context_test() # indirect doctest NTL modulus 9765625 """ return self.get_context(self.prec_cap) @@ -883,7 +884,7 @@ cdef class PowComputer_ZZ_pX(PowComputer_ext): EXAMPLES:: sage: PC = PowComputer_ext_maker(5, 5, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'FM', 'e',ntl.ZZ_pX([1],5^10)) - sage: PC._restore_context_test(4) #indirect doctest + sage: PC._restore_context_test(4) # indirect doctest """ self.get_context(n).restore_c() @@ -906,7 +907,7 @@ cdef class PowComputer_ZZ_pX(PowComputer_ext): EXAMPLES:: sage: PC = PowComputer_ext_maker(5, 5, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'FM', 'e',ntl.ZZ_pX([1],5^10)) - sage: PC._restore_context_capdiv_test(4) #indirect doctest + sage: PC._restore_context_capdiv_test(4) # indirect doctest """ self.restore_context(self.capdiv(n)) @@ -917,7 +918,7 @@ cdef class PowComputer_ZZ_pX(PowComputer_ext): EXAMPLES:: sage: PC = PowComputer_ext_maker(5, 5, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'FM', 'e',ntl.ZZ_pX([1],5^10)) - sage: PC._restore_context_capdiv_test(8) #indirect doctest + sage: PC._restore_context_capdiv_test(8) # indirect doctest """ cdef Integer _n = Integer(n) self.restore_context_capdiv(mpz_get_si(_n.value)) @@ -953,7 +954,7 @@ cdef class PowComputer_ZZ_pX(PowComputer_ext): sage: A = PowComputer_ext_maker(5, 10, 1000, 2000, False, ntl.ZZ_pX([-5,0,1],5^1000), 'big', 'e',ntl.ZZ_pX([1],5^1000)) sage: a = ntl.ZZ_pX([4,2],5^2) sage: b = ntl.ZZ_pX([6,3],5^2) - sage: A._get_modulus_test(a, b, 2) # indirect doctest + sage: A._get_modulus_test(a, b, 2) # indirect doctest [4 24] """ # Exception will be ignored by Cython @@ -972,7 +973,7 @@ cdef class PowComputer_ZZ_pX(PowComputer_ext): [4 24] sage: a * b [24 24 6] - sage: mod(6 * 5 + 24, 25) + sage: mod(6 * 5 + 24, 25) # needs sage.rings.finite_rings 4 """ if self.pow_Integer(mpz_get_si(n.value)) != Integer(a.c.p): @@ -1004,7 +1005,7 @@ cdef class PowComputer_ZZ_pX(PowComputer_ext): sage: A = PowComputer_ext_maker(5, 3, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'FM', 'e',ntl.ZZ_pX([1],5^10)) sage: a = ntl.ZZ_pX([129223,1231],5^10) sage: b = ntl.ZZ_pX([289741,323],5^10) - sage: A._get_top_modulus_test(a, b) #indirect doctest + sage: A._get_top_modulus_test(a, b) # indirect doctest [1783058 7785200] """ # Exception will be ignored by Cython @@ -1024,7 +1025,7 @@ cdef class PowComputer_ZZ_pX(PowComputer_ext): [1783058 7785200] sage: a*b [9560618 7785200 397613] - sage: mod(397613 * 5 + 9560618, 5^10) + sage: mod(397613 * 5 + 9560618, 5^10) # needs sage.rings.finite_rings 1783058 """ cdef ntl_ZZ_pX ans = a._new() @@ -1115,7 +1116,6 @@ cdef class PowComputer_ZZ_pX(PowComputer_ext): sage: W. = R.ext(f) sage: y = W.teichmuller(3,10); y 3 + 13*w^5 + 4*w^7 + 9*w^8 + 13*w^9 + O(w^10) - sage: y^17 == y True sage: g = x^3 + 9*x^2 + 1 @@ -1222,7 +1222,7 @@ cdef class PowComputer_ZZ_pX_FM(PowComputer_ZZ_pX): EXAMPLES:: - sage: A = PowComputer_ext_maker(5, 3, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'FM', 'e',ntl.ZZ_pX([1],5^10)) #indirect doctest + sage: A = PowComputer_ext_maker(5, 3, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'FM', 'e',ntl.ZZ_pX([1],5^10)) # indirect doctest sage: A PowComputer_ext for 5, with polynomial [9765620 0 1] """ @@ -1255,7 +1255,7 @@ cdef class PowComputer_ZZ_pX_FM(PowComputer_ZZ_pX): EXAMPLES:: sage: PC = PowComputer_ext_maker(5, 5, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'FM', 'e',ntl.ZZ_pX([1],5^10)) - sage: PC._get_top_context_test() # indirect doctest + sage: PC._get_top_context_test() # indirect doctest NTL modulus 9765625 """ return self.c @@ -1267,7 +1267,7 @@ cdef class PowComputer_ZZ_pX_FM(PowComputer_ZZ_pX): EXAMPLES:: sage: PC = PowComputer_ext_maker(5, 5, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'FM', 'e',ntl.ZZ_pX([1],5^10)) - sage: PC._restore_top_context_test() #indirect doctest + sage: PC._restore_top_context_test() # indirect doctest """ self.c.restore_c() @@ -1280,7 +1280,7 @@ cdef class PowComputer_ZZ_pX_FM(PowComputer_ZZ_pX): sage: A = PowComputer_ext_maker(5, 3, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'FM', 'e',ntl.ZZ_pX([1],5^10)) sage: a = ntl.ZZ_pX([129223,1231],5^10) sage: b = ntl.ZZ_pX([289741,323],5^10) - sage: A._get_top_modulus_test(a, b) #indirect doctest + sage: A._get_top_modulus_test(a, b) # indirect doctest [1783058 7785200] """ return &self.mod @@ -1296,7 +1296,7 @@ cdef class PowComputer_ZZ_pX_FM(PowComputer_ZZ_pX): sage: A = PowComputer_ext_maker(5, 3, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'FM', 'e',ntl.ZZ_pX([1],5^10)) sage: a = ntl.ZZ_pX([129223,1231],5^10) sage: b = ntl.ZZ_pX([289741,323],5^10) - sage: A._get_modulus_test(a, b, 10) #indirect doctest + sage: A._get_modulus_test(a, b, 10) # indirect doctest [1783058 7785200] """ if n == self.prec_cap: @@ -1316,7 +1316,7 @@ cdef class PowComputer_ZZ_pX_FM_Eis(PowComputer_ZZ_pX_FM): TESTS:: - sage: A = PowComputer_ext_maker(5, 3, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'FM', 'e',ntl.ZZ_pX([1],5^10)) #indirect doctest + sage: A = PowComputer_ext_maker(5, 3, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'FM', 'e',ntl.ZZ_pX([1],5^10)) # indirect doctest """ # The __new__ method for PowComputer_ZZ_pX_FM has already run, so we have access to self.mod self._ext_type = 'e' @@ -1416,7 +1416,7 @@ cdef class PowComputer_ZZ_pX_FM_Eis(PowComputer_ZZ_pX_FM): TESTS:: sage: A = PowComputer_ext_maker(5, 3, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'FM', 'e',ntl.ZZ_pX([1],5^10)) - sage: del A # indirect doctest + sage: del A # indirect doctest """ if self._initialized: self.cleanup_ZZ_pX_FM_Eis() @@ -1429,7 +1429,7 @@ cdef class PowComputer_ZZ_pX_FM_Eis(PowComputer_ZZ_pX_FM): TESTS:: sage: A = PowComputer_ext_maker(5, 3, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'FM', 'e',ntl.ZZ_pX([1],5^10)) - sage: del A # indirect doctest + sage: del A # indirect doctest """ Delete_ZZ_pX_Multiplier_array(self.low_shifter) Delete_ZZ_pX_Multiplier_array(self.high_shifter) @@ -1444,7 +1444,7 @@ cdef class PowComputer_ZZ_pX_FM_Eis(PowComputer_ZZ_pX_FM): sage: from sage.rings.padics.pow_computer_ext import ZZ_pX_eis_shift_test sage: A = PowComputer_ext_maker(5, 3, 10, 40, False, ntl.ZZ_pX([-5,75,15,0,1],5^10), 'FM', 'e',ntl.ZZ_pX([1,-15,-3],5^10)) - sage: ZZ_pX_eis_shift_test(A, [0, 1], 1, 5) #indirect doctest + sage: ZZ_pX_eis_shift_test(A, [0, 1], 1, 5) # indirect doctest [1] sage: ZZ_pX_eis_shift_test(A, [0, 0, 1], 1, 5) [0 1] @@ -1543,7 +1543,7 @@ cdef class PowComputer_ZZ_pX_small(PowComputer_ZZ_pX): EXAMPLES:: - sage: A = PowComputer_ext_maker(5, 10, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'small', 'e',ntl.ZZ_pX([1],5^10)) # indirect doctest + sage: A = PowComputer_ext_maker(5, 10, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'small', 'e',ntl.ZZ_pX([1],5^10)) # indirect doctest sage: A PowComputer_ext for 5, with polynomial [9765620 0 1] """ @@ -1604,7 +1604,7 @@ cdef class PowComputer_ZZ_pX_small(PowComputer_ZZ_pX): EXAMPLES:: sage: A = PowComputer_ext_maker(5, 10, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'small','e',ntl.ZZ_pX([1],5^10)) - sage: del A # indirect doctest + sage: del A # indirect doctest """ if self._initialized: self.cleanup_ZZ_pX_small() @@ -1616,7 +1616,7 @@ cdef class PowComputer_ZZ_pX_small(PowComputer_ZZ_pX): EXAMPLES:: sage: A = PowComputer_ext_maker(5, 10, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'small','e',ntl.ZZ_pX([1],5^10)) - sage: del A # indirect doctest + sage: del A # indirect doctest """ Delete_ZZ_pX_Modulus_array(self.mod) @@ -1636,7 +1636,7 @@ cdef class PowComputer_ZZ_pX_small(PowComputer_ZZ_pX): EXAMPLES:: sage: A = PowComputer_ext_maker(5, 10, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'small','e',ntl.ZZ_pX([1],5^10)) - sage: A._get_context_test(4) #indirect doctest + sage: A._get_context_test(4) # indirect doctest NTL modulus 625 """ if n < 0: @@ -1658,7 +1658,7 @@ cdef class PowComputer_ZZ_pX_small(PowComputer_ZZ_pX): EXAMPLES:: sage: A = PowComputer_ext_maker(5, 10, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'small','e',ntl.ZZ_pX([1],5^10)) - sage: A._restore_context_test(4) #indirect doctest + sage: A._restore_context_test(4) # indirect doctest """ if n < 0: n = -n @@ -1674,7 +1674,7 @@ cdef class PowComputer_ZZ_pX_small(PowComputer_ZZ_pX): EXAMPLES:: sage: PC = PowComputer_ext_maker(5, 10, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'small','e',ntl.ZZ_pX([1],5^10)) - sage: PC._get_top_context_test() # indirect doctest + sage: PC._get_top_context_test() # indirect doctest NTL modulus 9765625 """ return self.c[self.prec_cap] @@ -1686,7 +1686,7 @@ cdef class PowComputer_ZZ_pX_small(PowComputer_ZZ_pX): EXAMPLES:: sage: PC = PowComputer_ext_maker(5, 10, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'small','e',ntl.ZZ_pX([1],5^10)) - sage: PC._restore_top_context_test() #indirect doctest + sage: PC._restore_top_context_test() # indirect doctest """ (self.c[self.prec_cap]).restore_c() @@ -1727,7 +1727,7 @@ cdef class PowComputer_ZZ_pX_small(PowComputer_ZZ_pX): sage: A = PowComputer_ext_maker(5, 10, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'small','e',ntl.ZZ_pX([1],5^10)) sage: a = ntl.ZZ_pX([129223,1231],5^10) sage: b = ntl.ZZ_pX([289741,323],5^10) - sage: A._get_top_modulus_test(a, b) #indirect doctest + sage: A._get_top_modulus_test(a, b) # indirect doctest [1783058 7785200] """ return &(self.mod[self.prec_cap]) @@ -1848,7 +1848,7 @@ cdef class PowComputer_ZZ_pX_small_Eis(PowComputer_ZZ_pX_small): TESTS:: sage: A = PowComputer_ext_maker(5, 10, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'small', 'e',ntl.ZZ_pX([1],5^10)) - sage: del A # indirect doctest + sage: del A # indirect doctest """ if self._initialized: self.cleanup_ZZ_pX_small_Eis() @@ -1861,7 +1861,7 @@ cdef class PowComputer_ZZ_pX_small_Eis(PowComputer_ZZ_pX_small): TESTS:: sage: A = PowComputer_ext_maker(5, 3, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'FM', 'e',ntl.ZZ_pX([1],5^10)) - sage: del A # indirect doctest + sage: del A # indirect doctest """ Delete_ZZ_pX_array(self.low_shifter) Delete_ZZ_pX_array(self.high_shifter) @@ -1876,7 +1876,7 @@ cdef class PowComputer_ZZ_pX_small_Eis(PowComputer_ZZ_pX_small): sage: from sage.rings.padics.pow_computer_ext import ZZ_pX_eis_shift_test sage: A = PowComputer_ext_maker(5, 10, 10, 40, False, ntl.ZZ_pX([-5,75,15,0,1],5^10), 'small', 'e',ntl.ZZ_pX([1,-15,-3],5^10)) - sage: ZZ_pX_eis_shift_test(A, [0, 1], 1, 5) #indirect doctest + sage: ZZ_pX_eis_shift_test(A, [0, 1], 1, 5) # indirect doctest [1] sage: ZZ_pX_eis_shift_test(A, [0, 0, 1], 1, 5) [0 1] @@ -1906,7 +1906,7 @@ cdef class PowComputer_ZZ_pX_big(PowComputer_ZZ_pX): EXAMPLES:: - sage: A = PowComputer_ext_maker(5, 6, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'big','e',ntl.ZZ_pX([1],5^10)) # indirect doctest + sage: A = PowComputer_ext_maker(5, 6, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'big','e',ntl.ZZ_pX([1],5^10)) # indirect doctest sage: A PowComputer_ext for 5, with polynomial [9765620 0 1] """ @@ -1971,7 +1971,7 @@ cdef class PowComputer_ZZ_pX_big(PowComputer_ZZ_pX): EXAMPLES:: sage: A = PowComputer_ext_maker(5, 6, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'big','e',ntl.ZZ_pX([1],5^10)) - sage: del A # indirect doctest + sage: del A # indirect doctest """ if self._initialized: self.cleanup_ZZ_pX_big() @@ -1983,7 +1983,7 @@ cdef class PowComputer_ZZ_pX_big(PowComputer_ZZ_pX): EXAMPLES:: sage: A = PowComputer_ext_maker(5, 6, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'big','e',ntl.ZZ_pX([1],5^10)) - sage: del A # indirect doctest + sage: del A # indirect doctest """ Delete_ZZ_pX_Modulus_array(self.modulus_list) @@ -2058,9 +2058,9 @@ cdef class PowComputer_ZZ_pX_big(PowComputer_ZZ_pX): EXAMPLES:: sage: A = PowComputer_ext_maker(5, 6, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'big') - sage: A._get_context_test(4) #indirect doctest + sage: A._get_context_test(4) # indirect doctest NTL modulus 625 - sage: A._get_context_test(8) #indirect doctest + sage: A._get_context_test(8) # indirect doctest NTL modulus 390625 """ if n == 0: @@ -2086,7 +2086,7 @@ cdef class PowComputer_ZZ_pX_big(PowComputer_ZZ_pX): EXAMPLES:: sage: PC = PowComputer_ext_maker(5, 5, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'big','e',ntl.ZZ_pX([1],5^10)) - sage: PC._get_top_context_test() # indirect doctest + sage: PC._get_top_context_test() # indirect doctest NTL modulus 9765625 """ return self.top_context @@ -2098,7 +2098,7 @@ cdef class PowComputer_ZZ_pX_big(PowComputer_ZZ_pX): EXAMPLES:: sage: PC = PowComputer_ext_maker(5, 5, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'big','e',ntl.ZZ_pX([1],5^10)) - sage: PC._restore_top_context_test() #indirect doctest + sage: PC._restore_top_context_test() # indirect doctest """ self.top_context.restore_c() @@ -2115,13 +2115,13 @@ cdef class PowComputer_ZZ_pX_big(PowComputer_ZZ_pX): sage: A = PowComputer_ext_maker(5, 3, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'big','e',ntl.ZZ_pX([1],5^10)) sage: a = ntl.ZZ_pX([4,2],5^2) sage: b = ntl.ZZ_pX([6,3],5^2) - sage: A._get_modulus_test(a, b, 2) # indirect doctest + sage: A._get_modulus_test(a, b, 2) # indirect doctest [4 24] sage: a = ntl.ZZ_pX([4,2],5^6) sage: b = ntl.ZZ_pX([6,3],5^6) - sage: A._get_modulus_test(a, b, 6) # indirect doctest + sage: A._get_modulus_test(a, b, 6) # indirect doctest [54 24] - sage: A._get_modulus_test(a, b, 6) # indirect doctest + sage: A._get_modulus_test(a, b, 6) # indirect doctest [54 24] """ cdef ntl_ZZ_pX tmp @@ -2158,7 +2158,7 @@ cdef class PowComputer_ZZ_pX_big(PowComputer_ZZ_pX): sage: A = PowComputer_ext_maker(5, 5, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'big','e',ntl.ZZ_pX([1],5^10)) sage: a = ntl.ZZ_pX([129223,1231],5^10) sage: b = ntl.ZZ_pX([289741,323],5^10) - sage: A._get_top_modulus_test(a, b) #indirect doctest + sage: A._get_top_modulus_test(a, b) # indirect doctest [1783058 7785200] """ return &self.top_mod @@ -2279,7 +2279,7 @@ cdef class PowComputer_ZZ_pX_big_Eis(PowComputer_ZZ_pX_big): TESTS:: sage: A = PowComputer_ext_maker(5, 10, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'big', 'e',ntl.ZZ_pX([1],5^10)) - sage: del A # indirect doctest + sage: del A # indirect doctest """ if self._initialized: self.cleanup_ZZ_pX_big_Eis() @@ -2292,7 +2292,7 @@ cdef class PowComputer_ZZ_pX_big_Eis(PowComputer_ZZ_pX_big): TESTS:: sage: A = PowComputer_ext_maker(5, 3, 10, 20, False, ntl.ZZ_pX([-5,0,1],5^10), 'FM', 'e',ntl.ZZ_pX([1],5^10)) - sage: del A # indirect doctest + sage: del A # indirect doctest """ Delete_ZZ_pX_array(self.low_shifter) Delete_ZZ_pX_array(self.high_shifter) @@ -2307,7 +2307,7 @@ cdef class PowComputer_ZZ_pX_big_Eis(PowComputer_ZZ_pX_big): sage: from sage.rings.padics.pow_computer_ext import ZZ_pX_eis_shift_test sage: A = PowComputer_ext_maker(5, 10, 10, 40, False, ntl.ZZ_pX([-5,75,15,0,1],5^10), 'big', 'e',ntl.ZZ_pX([1,-15,-3],5^10)) - sage: ZZ_pX_eis_shift_test(A, [0, 1], 1, 5) #indirect doctest + sage: ZZ_pX_eis_shift_test(A, [0, 1], 1, 5) # indirect doctest [1] sage: ZZ_pX_eis_shift_test(A, [0, 0, 1], 1, 5) [0 1] diff --git a/src/sage/rings/padics/pow_computer_flint.pyx b/src/sage/rings/padics/pow_computer_flint.pyx index 2525a8bd040..6d0837f7ee5 100644 --- a/src/sage/rings/padics/pow_computer_flint.pyx +++ b/src/sage/rings/padics/pow_computer_flint.pyx @@ -69,7 +69,7 @@ cdef class PowComputer_flint(PowComputer_class): sage: from sage.rings.padics.pow_computer_flint import PowComputer_flint_maker sage: R. = ZZ[]; f = x^3 - 8*x - 2 - sage: A = PowComputer_flint_maker(5, 20, 20, 20, False, f, 'capped-rel') # indirect doctest + sage: A = PowComputer_flint_maker(5, 20, 20, 20, False, f, 'capped-rel') # indirect doctest sage: TestSuite(A).run() """ @@ -103,8 +103,8 @@ cdef class PowComputer_flint(PowComputer_class): sage: from sage.rings.padics.pow_computer_flint import PowComputer_flint_maker sage: R. = ZZ[]; f = x^3 - 8*x - 2 - sage: A = PowComputer_flint_maker(5, 20, 20, 20, False, f, 'capped-rel') # indirect doctest - sage: A._test_pickling() # indirect doctest + sage: A = PowComputer_flint_maker(5, 20, 20, 20, False, f, 'capped-rel') # indirect doctest + sage: A._test_pickling() # indirect doctest """ return PowComputer_flint_maker, (self.prime, self.cache_limit, self.prec_cap, self.ram_prec_cap, self.in_field, self.polynomial(), self._prec_type) diff --git a/src/sage/rings/padics/pow_computer_relative.pyx b/src/sage/rings/padics/pow_computer_relative.pyx index 88f39e6ffe6..55c53a12a63 100644 --- a/src/sage/rings/padics/pow_computer_relative.pyx +++ b/src/sage/rings/padics/pow_computer_relative.pyx @@ -41,6 +41,7 @@ cdef class PowComputer_relative(PowComputer_class): EXAMPLES:: + sage: # needs sage.libs.flint sage: from sage.rings.padics.pow_computer_relative import PowComputer_relative_maker sage: R. = ZqFM(25) sage: S. = R[] @@ -52,7 +53,7 @@ cdef class PowComputer_relative(PowComputer_class): TESTS:: sage: from sage.rings.padics.pow_computer_relative import PowComputer_relative - sage: isinstance(PC, PowComputer_relative) + sage: isinstance(PC, PowComputer_relative) # needs sage.libs.flint True """ @@ -60,6 +61,7 @@ cdef class PowComputer_relative(PowComputer_class): r""" TESTS:: + sage: # needs sage.libs.flint sage: from sage.rings.padics.pow_computer_relative import PowComputer_relative_maker sage: R. = ZqFM(25) sage: S. = R[] @@ -75,12 +77,13 @@ cdef class PowComputer_relative(PowComputer_class): r""" TESTS:: + sage: # needs sage.libs.flint sage: from sage.rings.padics.pow_computer_relative import PowComputer_relative_maker sage: R. = ZqFM(25) sage: S. = R[]; f = x^3 - 5*x - 5*a sage: RFP = R.change(field=False, show_prec=False, type='floating-point') sage: shift_seed = (-f[:3] // 5).change_ring(RFP) - sage: PC = PowComputer_relative_maker(5, 20, 20, 60, False, f, shift_seed, 'fixed-mod') # indirect doctest + sage: PC = PowComputer_relative_maker(5, 20, 20, 60, False, f, shift_seed, 'fixed-mod') # indirect doctest sage: TestSuite(PC).run() """ @@ -105,6 +108,7 @@ cdef class PowComputer_relative(PowComputer_class): r""" TESTS:: + sage: # needs sage.libs.flint sage: from sage.rings.padics.pow_computer_relative import PowComputer_relative_maker sage: R. = ZqFM(25) sage: S. = R[] @@ -122,13 +126,14 @@ cdef class PowComputer_relative(PowComputer_class): TESTS:: + sage: # needs sage.libs.flint sage: from sage.rings.padics.pow_computer_relative import PowComputer_relative_maker sage: R. = ZqFM(25) sage: S. = R[] sage: f = x^3 - 5*x - 5*a sage: RFP = R.change(field=False, show_prec=False, type='floating-point') sage: shift_seed = (-f[:3] // 5).change_ring(RFP) - sage: PC = PowComputer_relative_maker(5, 20, 20, 60, False, f, shift_seed, 'fixed-mod') # indirect doctest + sage: PC = PowComputer_relative_maker(5, 20, 20, 60, False, f, shift_seed, 'fixed-mod') # indirect doctest sage: loads(dumps(PC)) == PC True """ @@ -140,13 +145,14 @@ cdef class PowComputer_relative(PowComputer_class): EXAMPLES:: + sage: # needs sage.libs.flint sage: from sage.rings.padics.pow_computer_relative import PowComputer_relative_maker sage: R. = ZqFM(25,print_pos=False,show_prec=False) sage: S. = R[] sage: f = x^3 + 5*x + 5*a sage: RFP = R.change(field=False, show_prec=False, type='floating-point') sage: shift_seed = (-f[:3] // 5).change_ring(RFP) - sage: PowComputer_relative_maker(5, 20, 20, 60, False, f, shift_seed, 'fixed-mod') # indirect doctest + sage: PowComputer_relative_maker(5, 20, 20, 60, False, f, shift_seed, 'fixed-mod') # indirect doctest Relative PowComputer for modulus x^3 + 5*x + a*5 """ @@ -169,12 +175,13 @@ cdef class PowComputer_relative(PowComputer_class): EXAMPLES:: + sage: # needs sage.libs.flint sage: from sage.rings.padics.pow_computer_relative import PowComputer_relative_maker sage: R. = ZqFM(25) sage: S. = R[]; f = x^3 - 5*x - 5*a sage: RFP = R.change(field=False, show_prec=False, type='floating-point') sage: shift_seed = (-f[:3] // 5).change_ring(RFP) - sage: PC = PowComputer_relative_maker(5, 20, 20, 60, False, f, shift_seed, 'fixed-mod') # indirect doctest + sage: PC = PowComputer_relative_maker(5, 20, 20, 60, False, f, shift_seed, 'fixed-mod') # indirect doctest sage: PC.polynomial() is f True @@ -190,6 +197,7 @@ cdef class PowComputer_relative_eis(PowComputer_relative): EXAMPLES:: + sage: # needs sage.libs.flint sage: from sage.rings.padics.pow_computer_relative import PowComputer_relative_eis, PowComputer_relative_maker sage: R. = ZqFM(25) sage: S. = R[]; f = x^3 - 5*x - 5*a @@ -199,7 +207,7 @@ cdef class PowComputer_relative_eis(PowComputer_relative): TESTS:: - sage: isinstance(PC, PowComputer_relative_eis) + sage: isinstance(PC, PowComputer_relative_eis) # needs sage.libs.flint True """ @@ -207,6 +215,7 @@ cdef class PowComputer_relative_eis(PowComputer_relative): r""" TESTS:: + sage: # needs sage.libs.flint sage: from sage.rings.padics.pow_computer_relative import PowComputer_relative_maker sage: R. = ZqFM(25) sage: S. = R[]; f = x^3 - 5*x - 5*a @@ -236,6 +245,7 @@ cdef class PowComputer_relative_eis(PowComputer_relative): EXAMPLES:: + sage: # needs sage.libs.flint sage: from sage.rings.padics.pow_computer_relative import PowComputer_relative_maker sage: R. = ZqFM(25,3) sage: S. = R[]; f = x^3 - 5*x - 5*a @@ -283,6 +293,7 @@ cdef class PowComputer_relative_eis(PowComputer_relative): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Zq(25, prec=3) sage: S. = R[]; f = x^3 - 5*x - 5*a sage: W. = R.ext(f) @@ -315,6 +326,7 @@ cdef class PowComputer_relative_eis(PowComputer_relative): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Zq(25, prec=3) sage: S. = R[]; f = x^3 - 5*x - 5*a sage: W. = R.ext(f) @@ -348,6 +360,7 @@ cdef class PowComputer_relative_eis(PowComputer_relative): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Zq(25, prec=3) sage: S. = R[]; f = x^3 - 5*x - 5*a sage: W. = R.ext(f) @@ -405,6 +418,7 @@ def PowComputer_relative_maker(prime, cache_limit, prec_cap, ram_prec_cap, in_fi EXAMPLES:: + sage: # needs sage.libs.flint sage: from sage.rings.padics.pow_computer_relative import PowComputer_relative_maker sage: R. = ZqFM(25, prec=2) sage: S. = R[] diff --git a/src/sage/rings/padics/relative_extension_leaves.py b/src/sage/rings/padics/relative_extension_leaves.py index a9f20adce21..0310f2b21c3 100644 --- a/src/sage/rings/padics/relative_extension_leaves.py +++ b/src/sage/rings/padics/relative_extension_leaves.py @@ -39,6 +39,7 @@ class pAdicRelativeBaseringInjection(Morphism): EXAMPLES:: + sage: # needs sage.libs.ntl sage: K. = Qq(125) sage: R. = K[] sage: W. = K.extension(x^3 + 15*a*x - 5*(1+a^2)) @@ -53,6 +54,7 @@ def __init__(self, R, S): EXAMPLES:: + sage: # needs sage.libs.ntl sage: K. = Qq(125) sage: R. = K[] sage: W. = K.extension(x^3 + 15*a*x - 5*(1+a^2)) @@ -72,11 +74,12 @@ def _call_(self, x): EXAMPLES:: + sage: # needs sage.libs.ntl sage: K. = Qq(125,2) sage: R. = K[] sage: W. = K.extension(x^3 + 15*a*x - 5*(1+a^2)) sage: f = W.coerce_map_from(K) - sage: f(a+5) # indirect doctest + sage: f(a+5) # indirect doctest a + (4*a^2 + 4*a + 3)*w^3 + (a + 2)*w^4 + (2*a^2 + 4*a + 2)*w^5 + O(w^6) """ if x.is_zero(): @@ -91,13 +94,14 @@ def _call_with_args(self, x, args=(), kwds={}): EXAMPLES:: + sage: # needs sage.libs.ntl sage: K. = Qq(125,2) sage: R. = K[] sage: W. = K.extension(x^3 + 15*a*x - 5*(1+a^2)) sage: f = W.coerce_map_from(K) sage: f(5*a,5) (4*a^2 + a + 3)*w^3 + (a^2 + 2*a)*w^4 + O(w^5) - sage: f(5*a,8,2) # indirect doctest + sage: f(5*a,8,2) # indirect doctest (4*a^2 + a + 3)*w^3 + (a^2 + 2*a)*w^4 + O(w^5) """ return self.codomain()([x], *args, **kwds) @@ -108,6 +112,7 @@ def section(self): EXAMPLES:: + sage: # needs sage.libs.ntl sage: K. = Qq(125,2) sage: R. = K[] sage: W. = K.extension(x^3 + 15*a*x - 5*(1+a^2)) @@ -124,6 +129,7 @@ class pAdicRelativeBaseringSection(Morphism): EXAMPLES:: + sage: # needs sage.libs.ntl sage: K. = Qq(2^10) sage: R. = K[] sage: W. = K.extension(x^4 + 2*a*x^2 - 16*x - 6) @@ -138,6 +144,7 @@ def __init__(self, S, R): EXAMPLES:: + sage: # needs sage.libs.ntl sage: K. = Qq(2^10) sage: R. = K[] sage: W. = K.extension(x^4 + 2*a*x^2 - 16*x - 6*a) @@ -153,11 +160,12 @@ def _call_(self, x): EXAMPLES:: + sage: # needs sage.libs.ntl sage: K. = Qq(2^10) sage: R. = K[] sage: W. = K.extension(x^4 + 2*a*x^2 - 16*x - 6*a) sage: f = K.convert_map_from(W) - sage: f(a + w - w) # indirect doctest + sage: f(a + w - w) # indirect doctest a + O(2^20) sage: f(w) Traceback (most recent call last): @@ -175,11 +183,12 @@ def _call_with_args(self, x, args=(), kwds={}): EXAMPLES:: + sage: # needs sage.libs.ntl sage: K. = Qq(2^10) sage: R. = K[] sage: W. = K.extension(x^4 + 2*a*x^2 - 16*x - 6*a) sage: f = K.convert_map_from(W) - sage: f(a, 5) # indirect doctest + sage: f(a, 5) # indirect doctest a + O(2^5) """ return self.codomain()(self._call_(x), *args, **kwds) @@ -190,6 +199,7 @@ class RelativeRamifiedExtensionRingFixedMod(EisensteinExtensionGeneric, pAdicFix EXAMPLES:: + sage: # needs sage.libs.flint sage: A. = ZqFM(2^10) sage: R. = A[] sage: W. = A.extension(x^4 + 2*a*x^2 - 16*x - 6*a); W @@ -203,10 +213,11 @@ def __init__(self, exact_modulus, approx_modulus, prec, print_mode, shift_seed, EXAMPLES:: + sage: # needs sage.libs.flint sage: A. = ZqFM(5^4) sage: R. = A[] sage: W. = A.extension(x^3 - 25*(a+1)*x + 10*(a^2+2)) - sage: TestSuite(W).run(max_samples=16) # long time + sage: TestSuite(W).run(max_samples=16) # long time """ self._exact_modulus = exact_modulus unram_prec = (prec + approx_modulus.degree() - 1) // approx_modulus.degree() @@ -225,6 +236,7 @@ class RelativeRamifiedExtensionRingCappedAbsolute(EisensteinExtensionGeneric, pA EXAMPLES:: + sage: # needs sage.libs.flint sage: A. = ZqCA(2^10) sage: R. = A[] sage: W. = A.extension(x^4 + 2*a*x^2 - 16*x - 6*a); W @@ -238,10 +250,11 @@ def __init__(self, exact_modulus, approx_modulus, prec, print_mode, shift_seed, EXAMPLES:: + sage: # needs sage.libs.flint sage: A. = ZqCA(5^4) sage: R. = A[] sage: W. = A.extension(x^3 - 25*(a+1)*x + 10*(a^2+2)) - sage: TestSuite(W).run(max_samples=16) # long time + sage: TestSuite(W).run(max_samples=16) # long time """ self._exact_modulus = exact_modulus unram_prec = (prec + approx_modulus.degree() - 1) // approx_modulus.degree() @@ -260,6 +273,7 @@ class RelativeRamifiedExtensionRingCappedRelative(EisensteinExtensionGeneric, pA EXAMPLES:: + sage: # needs sage.libs.ntl sage: A. = ZqCR(2^10) sage: R. = A[] sage: W. = A.extension(x^4 + 2*a*x^2 - 16*x - 6*a); W @@ -273,10 +287,11 @@ def __init__(self, exact_modulus, approx_modulus, prec, print_mode, shift_seed, EXAMPLES:: + sage: # needs sage.libs.ntl sage: A. = ZqCR(5^4) sage: R. = A[] sage: W. = A.extension(x^3 - 25*(a+1)*x + 10*(a^2+2)) - sage: TestSuite(W).run(max_samples=16) # long time + sage: TestSuite(W).run(max_samples=16) # long time """ self._exact_modulus = exact_modulus unram_prec = (prec + approx_modulus.degree() - 1) // approx_modulus.degree() @@ -295,6 +310,7 @@ class RelativeRamifiedExtensionFieldCappedRelative(EisensteinExtensionGeneric, p EXAMPLES:: + sage: # needs sage.libs.ntl sage: A. = QqCR(2^10) sage: R. = A[] sage: W. = A.extension(x^4 + 2*a*x^2 - 16*x - 6*a); W @@ -308,10 +324,11 @@ def __init__(self, exact_modulus, approx_modulus, prec, print_mode, shift_seed, EXAMPLES:: + sage: # needs sage.libs.ntl sage: A. = QqCR(5^4) sage: R. = A[] sage: W. = A.extension(x^3 - 25*(a+1)*x + 10*(a^2+2)) - sage: TestSuite(W).run(max_samples=16) # long time + sage: TestSuite(W).run(max_samples=16) # long time """ self._exact_modulus = exact_modulus unram_prec = (prec + approx_modulus.degree() - 1) // approx_modulus.degree() @@ -332,6 +349,7 @@ class RelativeRamifiedExtensionRingFloatingPoint(EisensteinExtensionGeneric, pAd EXAMPLES:: + sage: # needs sage.libs.flint sage: A. = ZqFP(2^10) sage: R. = A[] sage: W. = A.extension(x^4 + 2*a*x^2 - 16*x - 6*a); W @@ -345,10 +363,11 @@ def __init__(self, exact_modulus, approx_modulus, prec, print_mode, shift_seed, EXAMPLES:: + sage: # needs sage.libs.flint sage: A. = ZqFP(5^4) sage: R. = A[] sage: W. = A.extension(x^3 - 25*(a+1)*x + 10*(a^2+2)) - sage: TestSuite(W).run(max_samples=16) # long time + sage: TestSuite(W).run(max_samples=16) # long time """ self._exact_modulus = exact_modulus unram_prec = (prec + approx_modulus.degree() - 1) // approx_modulus.degree() @@ -367,6 +386,7 @@ class RelativeRamifiedExtensionFieldFloatingPoint(EisensteinExtensionGeneric, pA EXAMPLES:: + sage: # needs sage.libs.flint sage: A. = QqFP(2^10) sage: R. = A[] sage: W. = A.extension(x^4 + 2*a*x^2 - 16*x - 6*a); W @@ -380,10 +400,11 @@ def __init__(self, exact_modulus, approx_modulus, prec, print_mode, shift_seed, EXAMPLES:: + sage: # needs sage.libs.flint sage: A. = QqFP(5^4) sage: R. = A[] sage: W. = A.extension(x^3 - 25*(a+1)*x + 10*(a^2+2)) - sage: TestSuite(W).run(max_samples=16) # long time + sage: TestSuite(W).run(max_samples=16) # long time """ self._exact_modulus = exact_modulus unram_prec = (prec + approx_modulus.degree() - 1) // approx_modulus.degree() diff --git a/src/sage/rings/padics/relative_ramified_CA.pyx b/src/sage/rings/padics/relative_ramified_CA.pyx index 0a2df891f87..42337d04979 100644 --- a/src/sage/rings/padics/relative_ramified_CA.pyx +++ b/src/sage/rings/padics/relative_ramified_CA.pyx @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint include "sage/libs/linkages/padics/Polynomial_ram.pxi" include "CA_template.pxi" diff --git a/src/sage/rings/padics/relative_ramified_CR.pyx b/src/sage/rings/padics/relative_ramified_CR.pyx index fa2defc6b34..5263c190966 100644 --- a/src/sage/rings/padics/relative_ramified_CR.pyx +++ b/src/sage/rings/padics/relative_ramified_CR.pyx @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.ntl include "sage/libs/linkages/padics/Polynomial_ram.pxi" include "CR_template.pxi" diff --git a/src/sage/rings/padics/relative_ramified_FM.pyx b/src/sage/rings/padics/relative_ramified_FM.pyx index 739da94f7c3..27d18035ccb 100644 --- a/src/sage/rings/padics/relative_ramified_FM.pyx +++ b/src/sage/rings/padics/relative_ramified_FM.pyx @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint include "sage/libs/linkages/padics/Polynomial_ram.pxi" include "FM_template.pxi" diff --git a/src/sage/rings/padics/relative_ramified_FP.pyx b/src/sage/rings/padics/relative_ramified_FP.pyx index 4fd227c4f4d..3cbae5e55d3 100644 --- a/src/sage/rings/padics/relative_ramified_FP.pyx +++ b/src/sage/rings/padics/relative_ramified_FP.pyx @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint include "sage/libs/linkages/padics/Polynomial_ram.pxi" include "FP_template.pxi" diff --git a/src/sage/rings/padics/relaxed_template.pxi b/src/sage/rings/padics/relaxed_template.pxi index 6e0fd4fac50..fe70657acda 100644 --- a/src/sage/rings/padics/relaxed_template.pxi +++ b/src/sage/rings/padics/relaxed_template.pxi @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.flint r""" Template for relaxed `p`-adic rings and fields. diff --git a/src/sage/rings/padics/tests.py b/src/sage/rings/padics/tests.py index 5574f931356..1d0e3f3c5d6 100644 --- a/src/sage/rings/padics/tests.py +++ b/src/sage/rings/padics/tests.py @@ -2,8 +2,8 @@ TESTS:: sage: R = Zp(5, prec=5, type='fixed-mod') - sage: a = random_matrix(R,5) - sage: a.determinant().parent() is R + sage: a = random_matrix(R,5) # needs sage.geometry.polyhedron + sage: a.determinant().parent() is R # needs sage.geometry.polyhedron True sage: K = Qp(3, 10,'capped-rel'); K.krull_dimension() 0 @@ -26,8 +26,8 @@ sage: a = Zp(5)(-3); loads(dumps(a)) == a True - sage: M = MatrixSpace(pAdicField(3,100),2) - sage: (M([1,0,0,90]) - (1+O(3^100)) * M(1)).left_kernel() + sage: M = MatrixSpace(pAdicField(3,100),2) # needs sage.geometry.polyhedron + sage: (M([1,0,0,90]) - (1+O(3^100)) * M(1)).left_kernel() # needs sage.geometry.polyhedron Vector space of degree 2 and dimension 1 over 3-adic Field with capped relative precision 100 Basis matrix: [1 + O(3^100) 0] diff --git a/src/sage/rings/padics/tutorial.py b/src/sage/rings/padics/tutorial.py index d281ae663a9..45459711382 100644 --- a/src/sage/rings/padics/tutorial.py +++ b/src/sage/rings/padics/tutorial.py @@ -309,7 +309,7 @@ ``Zq`` also requires a name for the generator of the residue field. One can specify this name as follows:: - sage: R. = Zq(125, prec = 20); R + sage: R. = Zq(125, prec=20); R # needs sage.libs.ntl 5-adic Unramified Extension Ring in c defined by x^3 + 3*x + 3 Eisenstein Extensions @@ -328,11 +328,11 @@ Finally, use the ``ext`` function on the ground field to create the desired extension.:: - sage: W. = R.ext(f) + sage: W. = R.ext(f) # needs sage.libs.ntl sage.rings.padics You can do arithmetic in this Eisenstein extension:: - sage: (1 + w)^7 + sage: (1 + w)^7 # needs sage.libs.ntl sage.rings.padics 1 + 2*w + w^2 + w^5 + 3*w^6 + 3*w^7 + 3*w^8 + w^9 + O(w^10) Note that the precision cap increased by a factor of 5, since the diff --git a/src/sage/rings/padics/unramified_extension_generic.py b/src/sage/rings/padics/unramified_extension_generic.py index 6892c7fbddf..3ca4d07b2b0 100644 --- a/src/sage/rings/padics/unramified_extension_generic.py +++ b/src/sage/rings/padics/unramified_extension_generic.py @@ -44,7 +44,7 @@ def __init__(self, poly, prec, print_mode, names, element_class): EXAMPLES:: - sage: R. = Zq(27) #indirect doctest + sage: R. = Zq(27) # indirect doctest # needs sage.libs.ntl """ #base = poly.base_ring() #if base.is_field(): @@ -63,13 +63,13 @@ def _extension_type(self): EXAMPLES:: - sage: K. = Qq(5^3) - sage: K._extension_type() + sage: K. = Qq(5^3) # needs sage.libs.ntl + sage: K._extension_type() # needs sage.libs.ntl 'Unramified' sage: x = polygen(ZZ, 'x') - sage: L. = Qp(5).extension(x^2 - 5) - sage: L._extension_type() + sage: L. = Qp(5).extension(x^2 - 5) # needs sage.libs.ntl + sage: L._extension_type() # needs sage.libs.ntl 'Eisenstein' """ return "Unramified" @@ -81,13 +81,13 @@ def absolute_f(self): EXAMPLES:: - sage: K. = Qq(3^5) - sage: K.absolute_f() + sage: K. = Qq(3^5) # needs sage.libs.ntl + sage: K.absolute_f() # needs sage.libs.ntl 5 sage: x = polygen(ZZ, 'x') - sage: L. = Qp(3).extension(x^2 - 3) - sage: L.absolute_f() + sage: L. = Qp(3).extension(x^2 - 3) # needs sage.libs.ntl + sage: L.absolute_f() # needs sage.libs.ntl 1 """ return self.modulus().degree() * self.base_ring().absolute_f() @@ -104,7 +104,7 @@ def residue_class_field(self): EXAMPLES:: - sage: R. = Zq(125); R.residue_class_field() + sage: R. = Zq(125); R.residue_class_field() # needs sage.libs.ntl Finite Field in a0 of size 5^3 """ #should eventually take advantage of finite field @@ -119,13 +119,13 @@ def residue_ring(self, n): EXAMPLES:: - sage: R. = Zq(125) - sage: R.residue_ring(1) + sage: R. = Zq(125) # needs sage.libs.ntl + sage: R.residue_ring(1) # needs sage.libs.ntl Finite Field in a0 of size 5^3 The following requires implementing more general Artinian rings:: - sage: R.residue_ring(2) + sage: R.residue_ring(2) # needs sage.libs.ntl Traceback (most recent call last): ... NotImplementedError @@ -145,8 +145,8 @@ def discriminant(self, K=None): EXAMPLES:: - sage: R. = Zq(125) - sage: R.discriminant() + sage: R. = Zq(125) # needs sage.libs.ntl + sage: R.discriminant() # needs sage.libs.ntl Traceback (most recent call last): ... NotImplementedError @@ -186,7 +186,7 @@ def is_galois(self, K=None): EXAMPLES:: - sage: R. = Zq(125); R.is_galois() + sage: R. = Zq(125); R.is_galois() # needs sage.libs.ntl True """ if K is None or K is self: @@ -203,7 +203,7 @@ def gen(self, n=0): EXAMPLES:: - sage: R. = Zq(125); R.gen() + sage: R. = Zq(125); R.gen() # needs sage.libs.ntl a + O(5^20) """ if n != 0: @@ -217,8 +217,8 @@ def _frob_gen(self, arithmetic=True): EXAMPLES:: - sage: R. = Zq(9) - sage: R._frob_gen() + sage: R. = Zq(9) # needs sage.libs.ntl + sage: R._frob_gen() # needs sage.libs.ntl (2*a + 1) + (2*a + 2)*3 + (2*a + 2)*3^2 + (2*a + 2)*3^3 + (2*a + 2)*3^4 + (2*a + 2)*3^5 + (2*a + 2)*3^6 + (2*a + 2)*3^7 + (2*a + 2)*3^8 + (2*a + 2)*3^9 + (2*a + 2)*3^10 + (2*a + 2)*3^11 + (2*a + 2)*3^12 + (2*a + 2)*3^13 + (2*a + 2)*3^14 + (2*a + 2)*3^15 + (2*a + 2)*3^16 + (2*a + 2)*3^17 + (2*a + 2)*3^18 + (2*a + 2)*3^19 + O(3^20) """ p = self.prime() @@ -239,8 +239,8 @@ def uniformizer_pow(self, n): EXAMPLES:: - sage: R. = ZqCR(125) - sage: R.uniformizer_pow(5) + sage: R. = ZqCR(125) # needs sage.libs.ntl + sage: R.uniformizer_pow(5) # needs sage.libs.ntl 5^5 + O(5^25) """ return self(self.prime_pow(n)) @@ -254,8 +254,8 @@ def uniformizer(self): EXAMPLES:: - sage: R. = ZqCR(125) - sage: R.uniformizer() + sage: R. = ZqCR(125) # needs sage.libs.ntl + sage: R.uniformizer() # needs sage.libs.ntl 5 + O(5^21) """ return self(self.ground_ring().uniformizer()) @@ -266,7 +266,7 @@ def _uniformizer_print(self): EXAMPLES:: - sage: R. = Zq(125); R._uniformizer_print() + sage: R. = Zq(125); R._uniformizer_print() # needs sage.libs.ntl '5' """ return self.ground_ring()._uniformizer_print() @@ -277,7 +277,7 @@ def _unram_print(self): EXAMPLES:: - sage: R. = Zq(125); R._unram_print() + sage: R. = Zq(125); R._unram_print() # needs sage.libs.ntl 'a' """ return self.variable_name() @@ -300,9 +300,9 @@ def has_pth_root(self): EXAMPLES:: - sage: R. = Zq(1024); R.has_pth_root() + sage: R. = Zq(1024); R.has_pth_root() # needs sage.libs.ntl True - sage: R. = Zq(17^5); R.has_pth_root() + sage: R. = Zq(17^5); R.has_pth_root() # needs sage.libs.ntl False """ return self.ground_ring().has_pth_root() @@ -323,6 +323,7 @@ def has_root_of_unity(self, n): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Zq(37^8) sage: R.has_root_of_unity(144) True diff --git a/src/sage/rings/polynomial/flatten.py b/src/sage/rings/polynomial/flatten.py index cfc5f96179c..74783285396 100644 --- a/src/sage/rings/polynomial/flatten.py +++ b/src/sage/rings/polynomial/flatten.py @@ -382,7 +382,7 @@ def _call_(self, p): sage: rings = [ZZ['x']['y']['a,b,c']] sage: rings += [GF(4)['x','y']['a','b']] # needs sage.rings.finite_rings sage: rings += [AA['x']['a','b']['y'], QQbar['a1','a2']['t']['X','Y']] # needs sage.rings.number_field - sage: for R in rings: + sage: for R in rings: # needs sage.modules ....: f = FlatteningMorphism(R) ....: g = f.section() ....: for _ in range(10): diff --git a/src/sage/rings/polynomial/hilbert.pyx b/src/sage/rings/polynomial/hilbert.pyx index 754a2bad1b7..975e2f42d9e 100644 --- a/src/sage/rings/polynomial/hilbert.pyx +++ b/src/sage/rings/polynomial/hilbert.pyx @@ -441,6 +441,8 @@ def first_hilbert_series(I, grading=None, return_grading=False): EXAMPLES:: sage: from sage.rings.polynomial.hilbert import first_hilbert_series + + sage: # needs sage.libs.singular sage: R = singular.ring(0,'(x,y,z)','dp') sage: I = singular.ideal(['x^2','y^2','z^2']) sage: first_hilbert_series(I) @@ -560,6 +562,7 @@ def hilbert_poincare_series(I, grading=None): EXAMPLES:: + sage: # needs sage.libs.singular sage: from sage.rings.polynomial.hilbert import hilbert_poincare_series sage: R = PolynomialRing(QQ,'x',9) sage: I = [m.lm() @@ -571,6 +574,7 @@ def hilbert_poincare_series(I, grading=None): The following example is taken from :trac:`20145`:: + sage: # needs sage.libs.singular sage: n=4; m=11; P = PolynomialRing(QQ, n*m, "x"); x = P.gens(); M = Matrix(n, x) sage: from sage.rings.polynomial.hilbert import first_hilbert_series sage: I = P.ideal(M.minors(2)) diff --git a/src/sage/rings/polynomial/infinite_polynomial_element.py b/src/sage/rings/polynomial/infinite_polynomial_element.py index 760c0dd57ab..a32c2fb0f7e 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_element.py +++ b/src/sage/rings/polynomial/infinite_polynomial_element.py @@ -465,7 +465,8 @@ def subs(self, fixed=None, **kwargs): TESTS:: - sage: g.subs(fixed=x[0], x_1=N) # needs sage.modules + sage: # needs sage.modules + sage: g.subs(fixed=x[0], x_1=N) Traceback (most recent call last): ... ValueError: fixed must be a dict diff --git a/src/sage/rings/polynomial/laurent_polynomial.pyx b/src/sage/rings/polynomial/laurent_polynomial.pyx index 9d28ed6a872..32dfa655ea7 100644 --- a/src/sage/rings/polynomial/laurent_polynomial.pyx +++ b/src/sage/rings/polynomial/laurent_polynomial.pyx @@ -182,9 +182,10 @@ cdef class LaurentPolynomial(CommutativeAlgebraElement): Check that :trac:`22277` is fixed:: - sage: R. = LaurentPolynomialRing(QQ) # needs sage.modules - sage: a = 2*x^2 + 3*x^3 + 4*x^-1 # needs sage.modules - sage: a.change_ring(GF(3)) # needs sage.modules + sage: # needs sage.modules + sage: R. = LaurentPolynomialRing(QQ) + sage: a = 2*x^2 + 3*x^3 + 4*x^-1 + sage: a.change_ring(GF(3)) -x^2 + x^-1 """ return self._parent.change_ring(R)(self) @@ -259,9 +260,9 @@ cdef class LaurentPolynomial(CommutativeAlgebraElement): sage: f = x*a + a sage: f.map_coefficients(lambda a: a + 1) (a + 1) + (a + 1)*x - sage: R. = LaurentPolynomialRing(k, 2) - sage: f = x*a + 2*x^3*y*a + a - sage: f.map_coefficients(lambda a: a + 1) + sage: R. = LaurentPolynomialRing(k, 2) # needs sage.modules + sage: f = x*a + 2*x^3*y*a + a # needs sage.modules + sage: f.map_coefficients(lambda a: a + 1) # needs sage.modules (2*a + 1)*x^3*y + (a + 1)*x + a + 1 Examples with different base ring:: diff --git a/src/sage/rings/polynomial/msolve.py b/src/sage/rings/polynomial/msolve.py index 70af8250f58..1905d0a8a57 100644 --- a/src/sage/rings/polynomial/msolve.py +++ b/src/sage/rings/polynomial/msolve.py @@ -8,7 +8,7 @@ This module provide implementations of some operations on polynomial ideals based on msolve. -Note that the `optional package msolve <../spkg/msolve.html>`_ must be installed. +Note that the `optional package msolve <../../../../spkg/msolve.html>`_ must be installed. .. SEEALSO:: diff --git a/src/sage/rings/polynomial/multi_polynomial.pyx b/src/sage/rings/polynomial/multi_polynomial.pyx index d680f227210..6cb9593081b 100644 --- a/src/sage/rings/polynomial/multi_polynomial.pyx +++ b/src/sage/rings/polynomial/multi_polynomial.pyx @@ -142,7 +142,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: ZZ(RR['x,y'](0)) # indirect doctest 0 - sage: ZZ(RR['x,y'](0.5)) + sage: ZZ(RR['x,y'](0.5)) # needs sage.rings.real_mpfr Traceback (most recent call last): ... TypeError: Attempt to coerce non-integral RealNumber to Integer @@ -1047,21 +1047,22 @@ cdef class MPolynomial(CommutativePolynomial): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # optional - magma, needs sage.rings.finite_rings sage: k. = GF(25); R. = k[] sage: f = y*x^2*b + x*(b+1) + 1 sage: magma = Magma() # so var names same below - sage: magma(f) # optional - magma + sage: magma(f) b*x^2*y + b^22*x + 1 - sage: f._magma_init_(magma) # optional - magma + sage: f._magma_init_(magma) '_sage_[...]!((_sage_[...]!(_sage_[...]))*_sage_[...]^2*_sage_[...]+(_sage_[...]!(_sage_[...] + 1))*_sage_[...]+(_sage_[...]!(1))*1)' A more complicated nested example:: + sage: # optional - magma sage: R. = QQ[]; S. = R[]; f = (2/3)*x^3*z + w^2 + 5 - sage: f._magma_init_(magma) # optional - magma + sage: f._magma_init_(magma) '_sage_[...]!((_sage_[...]!((1/1)*1))*_sage_[...]^2+(_sage_[...]!((2/3)*_sage_[...]^3))*_sage_[...]+(_sage_[...]!((5/1)*1))*1)' - sage: magma(f) # optional - magma + sage: magma(f) w^2 + 2/3*x^3*z + 5 """ R = magma(self.parent()) @@ -1549,9 +1550,9 @@ cdef class MPolynomial(CommutativePolynomial): sage: f = x^5*y + 3*x^2*y^2 - 2*x + y - 1 sage: f.discriminant(y) # needs sage.libs.singular x^10 + 2*x^5 + 24*x^3 + 12*x^2 + 1 - sage: f.polynomial(y).discriminant() + sage: f.polynomial(y).discriminant() # needs sage.libs.pari sage.modules x^10 + 2*x^5 + 24*x^3 + 12*x^2 + 1 - sage: f.discriminant(y).parent() == f.polynomial(y).discriminant().parent() # needs sage.libs.singular + sage: f.discriminant(y).parent() == f.polynomial(y).discriminant().parent() # needs sage.libs.singular sage.modules False TESTS: @@ -1561,7 +1562,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: # needs sage.rings.number_field sage: R. = QQbar[] sage: f = x^5*y + 3*x^2*y^2 - 2*x + y - 1 - sage: f.discriminant(y) + sage: f.discriminant(y) # needs sage.libs.singular x^10 + 2*x^5 + 24*x^3 + 12*x^2 + 1 AUTHOR: Miguel Marco @@ -1790,10 +1791,11 @@ cdef class MPolynomial(CommutativePolynomial): :: - sage: R. = RR[] # needs sage.rings.real_mpfr - sage: f = a + b + RR('0.3'); f # needs sage.rings.real_mpfr + sage: # needs sage.rings.real_mpfr + sage: R. = RR[] + sage: f = a + b + RR('0.3'); f a + b + 0.300000000000000 - sage: f.denominator() # needs sage.rings.real_mpfr + sage: f.denominator() 1.00000000000000 Check that the denominator is an element over the base whenever the base @@ -2086,7 +2088,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: r = x*y*z*t + 1 sage: p = r * (x - y + z - t + 1) sage: q = r * (x*z - y*t) - sage: gcd(p, q) + sage: gcd(p, q) # needs sage.libs.singular z*t*x*y + 1 sage: _.parent() Multivariate Polynomial Ring in x, y over @@ -2726,6 +2728,7 @@ cdef class MPolynomial(CommutativePolynomial): is not a subring of the real numbers, as the notion is not defined in this case:: + sage: # needs sage.rings.real_mpfr sage: Q. = CC[] sage: q = z^2 + w^2 sage: q.is_lorentzian() diff --git a/src/sage/rings/polynomial/multi_polynomial_ideal.py b/src/sage/rings/polynomial/multi_polynomial_ideal.py index 66dd4a6db3d..a752af29e75 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ideal.py +++ b/src/sage/rings/polynomial/multi_polynomial_ideal.py @@ -2585,7 +2585,7 @@ def variety(self, ring=None, *, algorithm="triangular_decomposition", proof=True {y: 0.3611030805286474?, x: 2.769292354238632?}, {y: 1, x: 1}] - We can also use the `optional package msolve <../spkg/msolve.html>`_ + We can also use the `optional package msolve <../../../../spkg/msolve.html>`_ to compute the variety. See :mod:`~sage.rings.polynomial.msolve` for more information. :: @@ -2667,7 +2667,7 @@ def variety(self, ring=None, *, algorithm="triangular_decomposition", proof=True on a toy implementation otherwise. - With ``algorithm`` = ``"msolve"``, uses the - `optional package msolve <../spkg/msolve.html>`_. + `optional package msolve <../../../../spkg/msolve.html>`_. Note that msolve uses heuristics and therefore requires setting the ``proof`` flag to ``False``. See :mod:`~sage.rings.polynomial.msolve` for more information. @@ -4275,7 +4275,7 @@ def groebner_basis(self, algorithm='', deg_bound=None, mult_bound=None, prot=Fal Macaulay2's ``GroebnerBasis`` command with the strategy "MGB" (if available) ``'msolve'`` - `optional package msolve <../spkg/msolve.html>`_ (degrevlex order) + `optional package msolve <../../../../spkg/msolve.html>`_ (degrevlex order) ``'magma:GroebnerBasis'`` Magma's ``Groebnerbasis`` command (if available) @@ -4403,7 +4403,7 @@ def groebner_basis(self, algorithm='', deg_bound=None, mult_bound=None, prot=Fal b*c - 19*c^2 + 10*b + 40*c, a + 2*b + 2*c - 1] Over prime fields of small characteristic, we can also use the - `optional package msolve <../spkg/msolve.html>`_:: + `optional package msolve <../../../../spkg/msolve.html>`_:: sage: R. = PolynomialRing(GF(101), 3) sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching diff --git a/src/sage/rings/polynomial/multi_polynomial_sequence.py b/src/sage/rings/polynomial/multi_polynomial_sequence.py index 19c53c392b2..b52fb34f721 100644 --- a/src/sage/rings/polynomial/multi_polynomial_sequence.py +++ b/src/sage/rings/polynomial/multi_polynomial_sequence.py @@ -394,22 +394,22 @@ def __init__(self, parts, ring, immutable=False, cr=False, cr_str=None): EXAMPLES:: sage: P. = PolynomialRing(GF(127), 4) - sage: I = sage.rings.ideal.Katsura(P) # needs sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # needs sage.libs.singular - sage: Sequence([I.gens()], I.ring()) # indirect doctest # needs sage.rings.finite_rings + sage: Sequence([I.gens()], I.ring()) # indirect doctest # needs sage.libs.singular [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] If an ideal is provided, the generators are used.:: - sage: Sequence(I) # needs sage.rings.finite_rings + sage: Sequence(I) # needs sage.libs.singular [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] If a list of polynomials is provided, the system has only one part.:: - sage: Sequence(I.gens(), I.ring()) # needs sage.rings.finite_rings + sage: Sequence(I.gens(), I.ring()) # needs sage.libs.singular [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] """ @@ -637,6 +637,7 @@ def algebraic_dependence(self): EXAMPLES:: + sage: # needs sage.libs.singular sage: R. = PolynomialRing(QQ) sage: S = Sequence([x, x*y]) sage: I = S.algebraic_dependence(); I @@ -644,22 +645,26 @@ def algebraic_dependence(self): :: + sage: # needs sage.libs.singular sage: R. = PolynomialRing(QQ) sage: S = Sequence([x, (x^2 + y^2 - 1)^2, x*y - 2]) sage: I = S.algebraic_dependence(); I - Ideal (16 + 32*T2 - 8*T0^2 + 24*T2^2 - 8*T0^2*T2 + 8*T2^3 + 9*T0^4 - 2*T0^2*T2^2 + T2^4 - T0^4*T1 + 8*T0^4*T2 - 2*T0^6 + 2*T0^4*T2^2 + T0^8) of Multivariate Polynomial Ring in T0, T1, T2 over Rational Field + Ideal (16 + 32*T2 - 8*T0^2 + 24*T2^2 - 8*T0^2*T2 + 8*T2^3 + 9*T0^4 - 2*T0^2*T2^2 + + T2^4 - T0^4*T1 + 8*T0^4*T2 - 2*T0^6 + 2*T0^4*T2^2 + T0^8) + of Multivariate Polynomial Ring in T0, T1, T2 over Rational Field sage: [F(S) for F in I.gens()] [0] :: + sage: # needs sage.libs.singular sage: R. = PolynomialRing(GF(7)) sage: S = Sequence([x, (x^2 + y^2 - 1)^2, x*y - 2]) - sage: I = S.algebraic_dependence(); I # needs sage.rings.finite_rings + sage: I = S.algebraic_dependence(); I Ideal (2 - 3*T2 - T0^2 + 3*T2^2 - T0^2*T2 + T2^3 + 2*T0^4 - 2*T0^2*T2^2 + T2^4 - T0^4*T1 + T0^4*T2 - 2*T0^6 + 2*T0^4*T2^2 + T0^8) of Multivariate Polynomial Ring in T0, T1, T2 over Finite Field of size 7 - sage: [F(S) for F in I.gens()] # needs sage.rings.finite_rings + sage: [F(S) for F in I.gens()] [0] .. NOTE:: @@ -1125,7 +1130,7 @@ def reduced(self): sage: Sequence([2*x,y]).reduced() [x, y] - sage: P. = CC[] + sage: P. = CC[] # needs sage.rings.real_mpfr sage: Sequence([2*x,y]).reduced() [x, y] @@ -1187,6 +1192,7 @@ def is_groebner(self, singular=singular): EXAMPLES:: + sage: # needs sage.libs.singular sage: R. = PolynomialRing(GF(127), 10) sage: I = sage.rings.ideal.Cyclic(R, 4) sage: I.basis.is_groebner() diff --git a/src/sage/rings/polynomial/padics/polynomial_padic.py b/src/sage/rings/polynomial/padics/polynomial_padic.py index b9c16923cc3..f19d6ccefa4 100644 --- a/src/sage/rings/polynomial/padics/polynomial_padic.py +++ b/src/sage/rings/polynomial/padics/polynomial_padic.py @@ -36,7 +36,7 @@ def _repr(self, name=None): r""" EXAMPLES:: - sage: R. = PolynomialRing(Zp(5, prec=5, type = 'capped-abs', print_mode = 'val-unit')) + sage: R. = PolynomialRing(Zp(5, prec=5, type='capped-abs', print_mode='val-unit')) sage: f = 24 + R(4/3)*w + w^4 sage: f._repr() '(1 + O(5^5))*w^4 + O(5^5)*w^3 + O(5^5)*w^2 + (1043 + O(5^5))*w + 24 + O(5^5)' @@ -45,6 +45,7 @@ def _repr(self, name=None): TESTS:: + sage: # needs sage.libs.ntl sage: k = Qp(5,10) sage: R. = k[] sage: f = R([k(0,-3), 0, k(0,-1)]); f @@ -97,6 +98,7 @@ def content(self): EXAMPLES:: + sage: # needs sage.libs.ntl sage: K = Zp(13,7) sage: R. = K[] sage: f = 13^7*t^3 + K(169,4)*t - 13^4 @@ -109,6 +111,7 @@ def content(self): sage: f.content() O(13^3) + sage: # needs sage.libs.ntl sage: P. = ZZ[] sage: f = x + 2 sage: f.content() @@ -125,6 +128,7 @@ def content(self): content is only defined up to multiplication with a unit. However, we return `\pi^k` where `k` is the minimal valuation of any coefficient:: + sage: # needs sage.libs.ntl sage: K = Qp(13,7) sage: R. = K[] sage: f = 13^7*t^3 + K(169,4)*t - 13^-4 @@ -152,7 +156,8 @@ def factor(self): EXAMPLES:: - sage: R. = PolynomialRing(Qp(3,3,print_mode='terse',print_pos=False)) + sage: # needs sage.libs.ntl + sage: R. = PolynomialRing(Qp(3, 3, print_mode='terse', print_pos=False)) sage: pol = t^8 - 1 sage: for p,e in pol.factor(): ....: print("{} {}".format(e, p)) @@ -161,9 +166,8 @@ def factor(self): 1 (1 + O(3^3))*t^2 + (5 + O(3^3))*t - 1 + O(3^3) 1 (1 + O(3^3))*t^2 + (-5 + O(3^3))*t - 1 + O(3^3) 1 (1 + O(3^3))*t^2 + O(3^3)*t + 1 + O(3^3) - sage: R. = PolynomialRing(Qp(5,6,print_mode='terse',print_pos=False)) - sage: pol = 100 * (5*t - 1) * (t - 5) - sage: pol + sage: R. = PolynomialRing(Qp(5, 6, print_mode='terse', print_pos=False)) + sage: pol = 100 * (5*t - 1) * (t - 5); pol (500 + O(5^9))*t^2 + (-2600 + O(5^8))*t + 500 + O(5^9) sage: pol.factor() (500 + O(5^9)) * ((1 + O(5^5))*t - 1/5 + O(5^5)) * ((1 + O(5^6))*t - 5 + O(5^6)) @@ -174,9 +178,9 @@ def factor(self): part is a `p`-adic unit and the power of `p` is considered to be a factor:: - sage: R. = PolynomialRing(Zp(5,6,print_mode='terse',print_pos=False)) - sage: pol = 100 * (5*t - 1) * (t - 5) - sage: pol + sage: # needs sage.libs.ntl + sage: R. = PolynomialRing(Zp(5, 6, print_mode='terse', print_pos=False)) + sage: pol = 100 * (5*t - 1) * (t - 5); pol (500 + O(5^9))*t^2 + (-2600 + O(5^8))*t + 500 + O(5^9) sage: pol.factor() (4 + O(5^6)) * (5 + O(5^7))^2 * ((1 + O(5^6))*t - 5 + O(5^6)) * ((5 + O(5^6))*t - 1 + O(5^6)) @@ -186,7 +190,7 @@ def factor(self): In the following example, the discriminant is zero, so the `p`-adic factorization is not well defined:: - sage: factor(t^2) + sage: factor(t^2) # needs sage.libs.ntl Traceback (most recent call last): ... PrecisionError: p-adic factorization not well-defined since @@ -194,36 +198,43 @@ def factor(self): An example of factoring a constant polynomial (see :trac:`26669`):: - sage: R. = Qp(5)[] - sage: R(2).factor() + sage: R. = Qp(5)[] # needs sage.libs.ntl + sage: R(2).factor() # needs sage.libs.ntl 2 + O(5^20) More examples over `\ZZ_p`:: - sage: R. = PolynomialRing(Zp(5, prec=6, type = 'capped-abs', print_mode = 'val-unit')) - sage: f = w^5-1 - sage: f.factor() - ((1 + O(5^6))*w + 3124 + O(5^6)) * ((1 + O(5^6))*w^4 + (12501 + O(5^6))*w^3 + (9376 + O(5^6))*w^2 + (6251 + O(5^6))*w + 3126 + O(5^6)) + sage: R. = PolynomialRing(Zp(5, prec=6, type='capped-abs', print_mode='val-unit')) + sage: f = w^5 - 1 + sage: f.factor() # needs sage.libs.ntl + ((1 + O(5^6))*w + 3124 + O(5^6)) + * ((1 + O(5^6))*w^4 + (12501 + O(5^6))*w^3 + (9376 + O(5^6))*w^2 + + (6251 + O(5^6))*w + 3126 + O(5^6)) See :trac:`4038`:: - sage: E = EllipticCurve('37a1') - sage: K =Qp(7,10) - sage: EK = E.base_extend(K) + sage: # needs sage.libs.ntl sage.schemes sage: E = EllipticCurve('37a1') sage: K = Qp(7,10) sage: EK = E.base_extend(K) sage: g = EK.division_polynomial_0(3) sage: g.factor() - (3 + O(7^10)) * ((1 + O(7^10))*x + 1 + 2*7 + 4*7^2 + 2*7^3 + 5*7^4 + 7^5 + 5*7^6 + 3*7^7 + 5*7^8 + 3*7^9 + O(7^10)) * ((1 + O(7^10))*x^3 + (6 + 4*7 + 2*7^2 + 4*7^3 + 7^4 + 5*7^5 + 7^6 + 3*7^7 + 7^8 + 3*7^9 + O(7^10))*x^2 + (6 + 3*7 + 5*7^2 + 2*7^4 + 7^5 + 7^6 + 2*7^8 + 3*7^9 + O(7^10))*x + 2 + 5*7 + 4*7^2 + 2*7^3 + 6*7^4 + 3*7^5 + 7^6 + 4*7^7 + O(7^10)) + (3 + O(7^10)) + * ((1 + O(7^10))*x + + 1 + 2*7 + 4*7^2 + 2*7^3 + 5*7^4 + 7^5 + 5*7^6 + 3*7^7 + 5*7^8 + 3*7^9 + O(7^10)) + * ((1 + O(7^10))*x^3 + + (6 + 4*7 + 2*7^2 + 4*7^3 + 7^4 + 5*7^5 + + 7^6 + 3*7^7 + 7^8 + 3*7^9 + O(7^10))*x^2 + + (6 + 3*7 + 5*7^2 + 2*7^4 + 7^5 + 7^6 + 2*7^8 + 3*7^9 + O(7^10))*x + + 2 + 5*7 + 4*7^2 + 2*7^3 + 6*7^4 + 3*7^5 + 7^6 + 4*7^7 + O(7^10)) TESTS: Check that :trac:`13293` is fixed:: - sage: R. = Qp(3)[] - sage: f = 1926*T^2 + 312*T + 387 - sage: f.factor() + sage: R. = Qp(3)[] # needs sage.libs.ntl + sage: f = 1926*T^2 + 312*T + 387 # needs sage.libs.ntl + sage: f.factor() # needs sage.libs.ntl (3^2 + 2*3^3 + 2*3^4 + 3^5 + 2*3^6 + O(3^22)) * ((1 + O(3^19))*T + 2*3^-1 + 3 + 3^2 + 2*3^5 + 2*3^6 + 2*3^7 + 3^8 + 3^9 + 2*3^11 + 3^15 + 3^17 + O(3^19)) * ((1 + O(3^20))*T + 2*3 + 3^2 + 3^3 + 3^5 + 2*3^6 + 2*3^7 + 3^8 + 3^10 + 3^11 + 2*3^12 + 2*3^14 + 2*3^15 + 2*3^17 + 2*3^18 + O(3^20)) Check that :trac:`24065` is fixed:: @@ -268,23 +279,23 @@ def root_field(self, names, check_irreducible=True, **kwds): EXAMPLES:: - sage: R. = Qp(3,5,print_mode='digits')[] - sage: f = x^2 - 3 - sage: f.root_field('x') + sage: R. = Qp(3,5,print_mode='digits')[] # needs sage.libs.ntl + sage: f = x^2 - 3 # needs sage.libs.ntl + sage: f.root_field('x') # needs sage.libs.ntl 3-adic Eisenstein Extension Field in x defined by x^2 - 3 :: - sage: R. = Qp(5,5,print_mode='digits')[] - sage: f = x^2 - 3 - sage: f.root_field('x', print_mode='bars') + sage: R. = Qp(5,5,print_mode='digits')[] # needs sage.libs.ntl + sage: f = x^2 - 3 # needs sage.libs.ntl + sage: f.root_field('x', print_mode='bars') # needs sage.libs.ntl 5-adic Unramified Extension Field in x defined by x^2 - 3 :: - sage: R. = Qp(11,5,print_mode='digits')[] - sage: f = x^2 - 3 - sage: f.root_field('x', print_mode='bars') + sage: R. = Qp(11,5,print_mode='digits')[] # needs sage.libs.ntl + sage: f = x^2 - 3 # needs sage.libs.ntl + sage: f.root_field('x', print_mode='bars') # needs sage.libs.ntl Traceback (most recent call last): ... ValueError: polynomial must be irreducible diff --git a/src/sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py b/src/sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py index 204ae5c54f4..fced8551fcd 100644 --- a/src/sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py +++ b/src/sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.ntl """ p-adic Capped Relative Dense Polynomials """ @@ -21,9 +22,11 @@ import copy from sage.libs.pari.all import pari, pari_gen -from sage.libs.ntl.all import ZZX +from sage.misc.lazy_import import lazy_import from sage.rings.infinity import infinity +lazy_import('sage.libs.ntl.all', 'ZZX') + min = misc.min ZZ = sage.rings.integer_ring.ZZ PrecisionError = precision_error.PrecisionError @@ -1145,13 +1148,13 @@ def newton_polygon(self): sage: K = Qp(2, prec=5) sage: P. = K[] sage: f = x^4 + 2^3*x^3 + 2^13*x^2 + 2^21*x + 2^37 - sage: f.newton_polygon() + sage: f.newton_polygon() # needs sage.geometry.polyhedron Finite Newton polygon with 4 vertices: (0, 37), (1, 21), (3, 3), (4, 0) sage: K = Qp(5) sage: R. = K[] sage: f = 5 + 3*t + t^4 + 25*t^10 - sage: f.newton_polygon() + sage: f.newton_polygon() # needs sage.geometry.polyhedron Finite Newton polygon with 4 vertices: (0, 1), (1, 0), (4, 0), (10, 2) Here is an example where the computation fails because precision is @@ -1159,14 +1162,14 @@ def newton_polygon(self): sage: g = f + K(0,0)*t^4; g (5^2 + O(5^22))*t^10 + O(5^0)*t^4 + (3 + O(5^20))*t + 5 + O(5^21) - sage: g.newton_polygon() + sage: g.newton_polygon() # needs sage.geometry.polyhedron Traceback (most recent call last): ... PrecisionError: The coefficient of t^4 has not enough precision TESTS:: - sage: (5*f).newton_polygon() + sage: (5*f).newton_polygon() # needs sage.geometry.polyhedron Finite Newton polygon with 4 vertices: (0, 2), (1, 1), (4, 1), (10, 3) AUTHOR: @@ -1283,13 +1286,13 @@ def newton_slopes(self, repetition=True): sage: K = Qp(5) sage: R. = K[] sage: f = 5 + 3*t + t^4 + 25*t^10 - sage: f.newton_polygon() + sage: f.newton_polygon() # needs sage.geometry.polyhedron Finite Newton polygon with 4 vertices: (0, 1), (1, 0), (4, 0), (10, 2) - sage: f.newton_slopes() + sage: f.newton_slopes() # needs sage.geometry.polyhedron [1, 0, 0, 0, -1/3, -1/3, -1/3, -1/3, -1/3, -1/3] - sage: f.newton_slopes(repetition=False) + sage: f.newton_slopes(repetition=False) # needs sage.geometry.polyhedron [1, 0, -1/3] AUTHOR: diff --git a/src/sage/rings/polynomial/polydict.pyx b/src/sage/rings/polynomial/polydict.pyx index aaefb2d99d2..d65d5464778 100644 --- a/src/sage/rings/polynomial/polydict.pyx +++ b/src/sage/rings/polynomial/polydict.pyx @@ -879,6 +879,8 @@ cdef class PolyDict: sage: PolyDict({(1, 0): GF(4)(1)}).poly_repr(['x', 'y']) # needs sage.rings.finite_rings 'x' + + sage: # needs sage.modules sage: P. = LaurentPolynomialRing(GF(2), 2) sage: P.gens() (x, y) diff --git a/src/sage/rings/polynomial/polynomial_complex_arb.pyx b/src/sage/rings/polynomial/polynomial_complex_arb.pyx index 3e3482330a6..81e799b7a8d 100644 --- a/src/sage/rings/polynomial/polynomial_complex_arb.pyx +++ b/src/sage/rings/polynomial/polynomial_complex_arb.pyx @@ -120,7 +120,7 @@ cdef class Polynomial_complex_arb(Polynomial): 2.000000000000000*x sage: Polynomial_complex_arb(Pol, (1,)) 1.000000000000000 - sage: Polynomial_complex_arb(Pol, (CBF(i), 1)) + sage: Polynomial_complex_arb(Pol, (CBF(i), 1)) # needs sage.symbolic x + I sage: Polynomial_complex_arb(Pol, polygen(QQ,'y')+2) x + 2.000000000000000 @@ -199,6 +199,7 @@ cdef class Polynomial_complex_arb(Polynomial): TESTS:: + sage: # needs sage.symbolic sage: Pol. = ComplexBallField(42)[] sage: pol = (x + i)/3 sage: pol2 = loads(dumps(pol)) diff --git a/src/sage/rings/polynomial/polynomial_element.pyx b/src/sage/rings/polynomial/polynomial_element.pyx index 7eaa195cbfe..8e9c4822a7b 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -1362,17 +1362,17 @@ cdef class Polynomial(CommutativePolynomial): 0.2 sage: CDF(a) # needs sage.rings.complex_double 0.2 - sage: RR(a) + sage: RR(a) # needs sage.rings.real_mpfr 0.200000000000000 - sage: CC(a) + sage: CC(a) # needs sage.rings.real_mpfr 0.200000000000000 sage: RBF(a) # needs sage.libs.flint [0.2000000000000000 +/- 4.45e-17] sage: CBF(a) # needs sage.libs.flint [0.2000000000000000 +/- 4.45e-17] - sage: RIF(a) + sage: RIF(a) # needs sage.rings.real_interval_field 0.2000000000000000? - sage: CIF(a) + sage: CIF(a) # needs sage.rings.complex_interval_field 0.2000000000000000? sage: float(a) 0.2 @@ -1383,11 +1383,11 @@ cdef class Polynomial(CommutativePolynomial): sage: b = AA['x'](AA(2/3).sqrt()) sage: AA(b) 0.8164965809277260? - sage: RR(b) + sage: RR(b) # needs sage.rings.real_mpfr 0.816496580927726 sage: RBF(b) # needs sage.libs.flint [0.816496580927726 +/- 2.44e-16] - sage: RIF(b) + sage: RIF(b) # needs sage.rings.real_interval_field 0.8164965809277260? sage: float(b) 0.816496580927726 @@ -1398,11 +1398,11 @@ cdef class Polynomial(CommutativePolynomial): 0.6324555320336758?*I sage: CDF(c) 0.6324555320336758*I - sage: CC(c) + sage: CC(c) # needs sage.rings.real_mpfr 0.632455532033676*I sage: CBF(c) # abs tol 1e-16 # needs sage.libs.flint [0.6324555320336759 +/- 3.38e-17]*I - sage: CIF(c) + sage: CIF(c) # needs sage.rings.complex_interval_field 0.6324555320336758?*I sage: complex(c) 0.6324555320336758j @@ -1585,7 +1585,7 @@ cdef class Polynomial(CommutativePolynomial): error the product may not always exactly equal the constant polynomial 1 and have extra terms with coefficients close to zero. :: - sage: # needs sage.modules + sage: # needs scipy sage.modules sage: R. = RDF[] sage: epsilon = RDF(1).ulp()*50 # Allow an error of up to 50 ulp sage: f = inverse_mod(x^2 + 1, x^5 + x + 1); f # abs tol 1e-14 @@ -2131,7 +2131,7 @@ cdef class Polynomial(CommutativePolynomial): Check root computation over large finite fields:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.libs.m4ri sage.rings.finite_rings sage: K. = GF(2**50) sage: x = polygen(K) sage: (x**10+x+a).any_root() @@ -2980,8 +2980,8 @@ cdef class Polynomial(CommutativePolynomial): sage: D = d0 + d1*y + d2*y^2 + d3*y^3 + d4*y^4 + d5*y^5 + d6*y^6 + d7*y^7 sage: F = D.subs({y: B}) sage: G = A.subs({y: F}) + C - sage: g = G.mod(y^8 + y) - sage: g.degree(y) + sage: g = G.mod(y^8 + y) # needs sage.libs.singular + sage: g.degree(y) # needs sage.libs.singular 7 """ return self % other @@ -3117,6 +3117,7 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: + sage: # needs sage.rings.real_mpfr sage: S. = PolynomialRing(RR) sage: f = y^10 - 1.393493*y + 0.3 sage: f._mul_karatsuba(f,0) @@ -3642,6 +3643,7 @@ cdef class Polynomial(CommutativePolynomial): :: + sage: # needs sage.rings.real_mpfr sage: R. = RR[] sage: f = x + RR('0.3'); f x + 0.300000000000000 @@ -3730,6 +3732,7 @@ cdef class Polynomial(CommutativePolynomial): :: + sage: # needs sage.rings.real_mpfr sage: R. = RR[] sage: f = x + RR('0.3'); f x + 0.300000000000000 @@ -4531,14 +4534,14 @@ cdef class Polynomial(CommutativePolynomial): sage: P. = PolynomialRing(ZZ) sage: R. = PolynomialRing(FractionField(P)) sage: p = (x - a) * (b*x + c) * (a*b*x + a*c) / (a + 2) - sage: factor(p) + sage: factor(p) # needs sage.libs.singular (a/(a + 2)) * (x - a) * (b*x + c)^2 Check that :trac:`24973` is fixed:: sage: x1 = ZZ['x'].gen() sage: x2 = ZZ['x']['x'].gen() - sage: (x1 - x2).factor() + sage: (x1 - x2).factor() # needs sage.libs.singular -x + x Check that :trac:`26421' is fixed:: @@ -4546,16 +4549,16 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = LaurentPolynomialRing(ZZ) sage: P. = R[] sage: p = x^4 + (-5 - 2*t)*x^3 + (-2 + 10*t)*x^2 + (10 + 4*t)*x - 20*t - sage: p.factor() + sage: p.factor() # needs sage.libs.singular (x - 5) * (x - 2*t) * (x^2 - 2) Check that :trac:`29266` is fixed: sage: f = t*x + t - sage: f.is_irreducible() + sage: f.is_irreducible() # needs sage.libs.singular True sage: f = 2*x + 4 - sage: f.is_irreducible() + sage: f.is_irreducible() # needs sage.libs.singular Traceback (most recent call last): ... NotImplementedError @@ -6875,9 +6878,9 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: S. = R[] sage: f = x^2 + a; g = y^3 + a - sage: h = f.resultant(g); h # needs sage.libs.pari + sage: h = f.resultant(g); h # needs sage.libs.pari sage.modules y^3 - x^2 - sage: h.parent() is R # needs sage.libs.pari + sage: h.parent() is R # needs sage.libs.pari sage.modules True Check that :trac:`13672` is fixed:: @@ -6902,7 +6905,7 @@ cdef class Polynomial(CommutativePolynomial): sage: K. = FunctionField(QQ) sage: R. = K[] - sage: y.resultant(y + x) # needs sage.libs.pari + sage: y.resultant(y + x) # needs sage.libs.pari sage.modules x sage: # needs sage.libs.singular @@ -7336,9 +7339,9 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: # needs sage.libs.pari + sage: # needs sage.libs.pari sage.libs.singular sage: f = cyclotomic_polynomial(30) - sage: f.adams_operator(7)==f + sage: f.adams_operator(7) == f True sage: f.adams_operator(6) == cyclotomic_polynomial(5)**2 True @@ -7499,7 +7502,7 @@ cdef class Polynomial(CommutativePolynomial): -31 sage: d.parent() is QQ # needs sage.libs.pari True - sage: EllipticCurve([1, 1]).discriminant()/16 # needs sage.libs.pari + sage: EllipticCurve([1, 1]).discriminant()/16 # needs sage.libs.pari sage.schemes -31 :: @@ -7727,7 +7730,7 @@ cdef class Polynomial(CommutativePolynomial): sage: f = x^3 - 1 sage: f.roots() [(1, 1)] - sage: f.roots(ring=CC) # ... - low order bits slightly different on ppc + sage: f.roots(ring=CC) # ... - low order bits slightly different on ppc # needs sage.rings.real_mpfr [(1.00000000000000, 1), (-0.500000000000000 - 0.86602540378443...*I, 1), (-0.500000000000000 + 0.86602540378443...*I, 1)] @@ -7787,6 +7790,7 @@ cdef class Polynomial(CommutativePolynomial): :: + sage: # needs sage.rings.real_mpfr sage: x = CC['x'].0 sage: f = x^3 - 2 sage: f.roots() # needs numpy @@ -8268,9 +8272,10 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: - sage: K. = CyclotomicField(2) # needs sage.rings.number_field - sage: R. = K[] # needs sage.rings.number_field - sage: factor(x^3 - 1) # needs sage.rings.number_field + sage: # needs sage.rings.number_field + sage: K. = CyclotomicField(2) + sage: R. = K[] + sage: factor(x^3 - 1) (x - 1) * (x^2 + x + 1) This shows that the issue from :trac:`6237` is fixed:: @@ -8330,7 +8335,7 @@ cdef class Polynomial(CommutativePolynomial): Spurious crash with pari-2.5.5, see :trac:`16165`:: sage: f = (1+x+x^2)^3 - sage: f.roots(ring=CC) + sage: f.roots(ring=CC) # needs sage.libs.pari sage.rings.real_mpfr [(-0.500000000000000 - 0.866025403784439*I, 3), (-0.500000000000000 + 0.866025403784439*I, 3)] @@ -8338,7 +8343,7 @@ cdef class Polynomial(CommutativePolynomial): sage: polRing. = PolynomialRing(ZZ) sage: j = (x+1)^2 * (x-1)^7 * (x^2-x+1)^5 - sage: j.roots(CC) + sage: j.roots(CC) # needs sage.libs.pari sage.rings.real_mpfr [(-1.00000000000000, 2), (1.00000000000000, 7), (0.500000000000000 - 0.866025403784439*I, 5), @@ -8361,7 +8366,7 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = LaurentPolynomialRing(ZZ) sage: P. = R[] sage: p = x^4 + (-5 - 2*t)*x^3 + (-2 + 10*t)*x^2 + (10 + 4*t)*x - 20*t - sage: p.roots() + sage: p.roots() # needs sage.libs.singular [(5, 1), (2*t, 1)] Check that :trac:`31040` is fixed:: @@ -8383,6 +8388,7 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`33979` is fixed:: + sage: # needs sage.libs.pari sage: n = randint(2, 10^6) sage: K = Integers(n) sage: R. = PolynomialRing(K) @@ -8733,20 +8739,20 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: x = polygen(ZZ) - sage: (x^2 - x - 1).real_roots() # needs sage.rings.real_mpfr + sage: (x^2 - x - 1).real_roots() # needs sage.libs.pari sage.rings.real_mpfr [-0.618033988749895, 1.61803398874989] TESTS:: - sage: x = polygen(RealField(100)) # needs sage.rings.real_mpfr - sage: (x^2 - x - 1).real_roots()[0].parent() # needs sage.rings.real_mpfr + sage: x = polygen(RealField(100)) # needs sage.libs.pari sage.rings.real_mpfr + sage: (x^2 - x - 1).real_roots()[0].parent() # needs sage.libs.pari sage.rings.real_mpfr Real Field with 100 bits of precision sage: x = polygen(RDF) sage: (x^2 - x - 1).real_roots()[0].parent() # needs numpy Real Double Field - sage: x = polygen(ZZ,'x'); v = (x^2 - x - 1).real_roots() # needs sage.rings.real_mpfr - sage: v[0].parent() is RR # needs sage.rings.real_mpfr + sage: x = polygen(ZZ,'x'); v = (x^2 - x - 1).real_roots() # needs sage.libs.pari sage.rings.real_mpfr + sage: v[0].parent() is RR # needs sage.libs.pari sage.rings.real_mpfr True """ K = self.base_ring() @@ -8768,16 +8774,18 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: + sage: # needs sage.libs.pari sage.rings.real_mpfr sage: x = polygen(ZZ) - sage: (x^3 - 1).complex_roots() # note: low order bits slightly different on ppc. # needs sage.rings.real_mpfr + sage: (x^3 - 1).complex_roots() # note: low order bits slightly different on ppc. [1.00000000000000, -0.500000000000000 - 0.86602540378443...*I, -0.500000000000000 + 0.86602540378443...*I] TESTS:: - sage: x = polygen(RR) # needs sage.rings.real_mpfr - sage: (x^3 - 1).complex_roots()[0].parent() # needs sage.rings.real_mpfr + sage: # needs sage.libs.pari sage.rings.real_mpfr + sage: x = polygen(RR) + sage: (x^3 - 1).complex_roots()[0].parent() Complex Field with 53 bits of precision sage: x = polygen(RDF) @@ -9193,6 +9201,7 @@ cdef class Polynomial(CommutativePolynomial): is not a subring of the real numbers, as the notion is not defined in this case:: + sage: # needs sage.rings.real_mpfr sage: Q. = CC[] sage: q = y^2 sage: q.is_lorentzian() @@ -9432,6 +9441,7 @@ cdef class Polynomial(CommutativePolynomial): Over `\RR[z]`:: + sage: # needs sage.rings.real_mpfr sage: z = PowerSeriesRing(RR, 'z').gen() sage: P = PolynomialRing(RR, 'x') sage: x = P.gen() @@ -10091,9 +10101,10 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: - sage: R. = RR[] # needs sage.rings.real_mpfr - sage: f = x^6 + x^2 + -x^4 -x^3 # needs sage.rings.real_mpfr - sage: f.norm(int(2)) # needs sage.rings.real_mpfr + sage: # needs sage.rings.real_mpfr + sage: R. = RR[] + sage: f = x^6 + x^2 + -x^4 -x^3 + sage: f.norm(int(2)) 2.00000000000000 Check that :trac:`18600` is fixed:: @@ -10823,7 +10834,7 @@ cdef class Polynomial(CommutativePolynomial): Some random tests:: - sage: for R in [QQ['x'], GF(4)['x']]: # needs sage.rings.finite_rings + sage: for R in [QQ['x'], GF(4)['x']]: # needs sage.modules sage.rings.finite_rings ....: for _ in range(30): ....: p = R.random_element(degree=randint(10,20)) ....: n = ZZ.random_element(2,20) diff --git a/src/sage/rings/polynomial/polynomial_element_generic.py b/src/sage/rings/polynomial/polynomial_element_generic.py index 8f8a296b488..5b99c2aaea8 100644 --- a/src/sage/rings/polynomial/polynomial_element_generic.py +++ b/src/sage/rings/polynomial/polynomial_element_generic.py @@ -777,7 +777,7 @@ def shift(self, n): x^1267650600228229401496703205386 - 5*x^10 sage: p.shift(-10) x^1267650600228229401496703205366 - sage: p.shift(1.5) + sage: p.shift(1.5) # needs sage.rings.real_mpfr Traceback (most recent call last): ... TypeError: Attempt to coerce non-integral RealNumber to Integer @@ -1166,7 +1166,7 @@ def newton_slopes(self, repetition=True): EXAMPLES:: - sage: # needs sage.rings.padics + sage: # needs sage.geometry.polyhedron sage.rings.padics sage: K = Qp(5) sage: R. = K[] sage: f = 5 + 3*t + t^4 + 25*t^10 @@ -1174,8 +1174,7 @@ def newton_slopes(self, repetition=True): Finite Newton polygon with 4 vertices: (0, 1), (1, 0), (4, 0), (10, 2) sage: f.newton_slopes() [1, 0, 0, 0, -1/3, -1/3, -1/3, -1/3, -1/3, -1/3] - - sage: f.newton_slopes(repetition=False) # needs sage.rings.padics + sage: f.newton_slopes(repetition=False) [1, 0, -1/3] AUTHOR: @@ -1195,16 +1194,15 @@ def newton_polygon(self): EXAMPLES:: - sage: # needs sage.rings.padics + sage: # needs sage.geometry.polyhedron sage.rings.padics sage: K = Qp(5) sage: R. = K[] sage: f = 5 + 3*t + t^4 + 25*t^10 sage: f.newton_polygon() Finite Newton polygon with 4 vertices: (0, 1), (1, 0), (4, 0), (10, 2) - - sage: g = f + K(0,0)*t^4; g # needs sage.rings.padics + sage: g = f + K(0,0)*t^4; g (5^2 + O(5^22))*t^10 + O(5^0)*t^4 + (3 + O(5^20))*t + 5 + O(5^21) - sage: g.newton_polygon() # needs sage.rings.padics + sage: g.newton_polygon() Traceback (most recent call last): ... PrecisionError: The coefficient of t^4 has not enough precision @@ -1365,7 +1363,7 @@ def factor_of_slope(self, slope=None): EXAMPLES:: - sage: # needs sage.rings.padics + sage: # needs sage.geometry.polyhedron sage.rings.padics sage: K = Qp(5) sage: R. = K[] sage: K = Qp(5) @@ -1373,23 +1371,21 @@ def factor_of_slope(self, slope=None): sage: f = 5 + 3*t + t^4 + 25*t^10 sage: f.newton_slopes() [1, 0, 0, 0, -1/3, -1/3, -1/3, -1/3, -1/3, -1/3] - - sage: g = f.factor_of_slope(0) # needs sage.rings.padics - sage: g.newton_slopes() # needs sage.rings.padics + sage: g = f.factor_of_slope(0) + sage: g.newton_slopes() [0, 0, 0] - sage: (f % g).is_zero() # needs sage.rings.padics + sage: (f % g).is_zero() True - - sage: h = f.factor_of_slope() # needs sage.rings.padics - sage: h.newton_slopes() # needs sage.rings.padics + sage: h = f.factor_of_slope() + sage: h.newton_slopes() [1] - sage: (f % h).is_zero() # needs sage.rings.padics + sage: (f % h).is_zero() True If ``slope`` is not a slope of ``self``, the corresponding factor is `1`:: - sage: f.factor_of_slope(-1) # needs sage.rings.padics + sage: f.factor_of_slope(-1) # needs sage.geometry.polyhedron sage.rings.padics 1 + O(5^20) AUTHOR: @@ -1435,7 +1431,7 @@ def slope_factorization(self): EXAMPLES:: - sage: # needs sage.rings.padics + sage: # needs sage.geometry.polyhedron sage.rings.padics sage: K = Qp(5) sage: R. = K[] sage: K = Qp(5) @@ -1443,11 +1439,10 @@ def slope_factorization(self): sage: f = 5 + 3*t + t^4 + 25*t^10 sage: f.newton_slopes() [1, 0, 0, 0, -1/3, -1/3, -1/3, -1/3, -1/3, -1/3] - - sage: F = f.slope_factorization() # needs sage.rings.padics - sage: F.prod() == f # needs sage.rings.padics + sage: F = f.slope_factorization() + sage: F.prod() == f True - sage: for (f,_) in F: # needs sage.rings.padics + sage: for (f,_) in F: ....: print(f.newton_slopes()) [-1/3, -1/3, -1/3, -1/3, -1/3, -1/3] [0, 0, 0] @@ -1513,7 +1508,7 @@ def _roots(self, secure, minval, hint): TESTS:: - sage: # needs sage.rings.padics + sage: # needs sage.geometry.polyhedron sage.rings.padics sage: R = Zp(2) sage: S. = R[] sage: P = (x-1) * (x-2) * (x-4) * (x-8) * (x-16) diff --git a/src/sage/rings/polynomial/polynomial_integer_dense_flint.pyx b/src/sage/rings/polynomial/polynomial_integer_dense_flint.pyx index 20a1d75e66c..c9d196ff893 100644 --- a/src/sage/rings/polynomial/polynomial_integer_dense_flint.pyx +++ b/src/sage/rings/polynomial/polynomial_integer_dense_flint.pyx @@ -351,8 +351,8 @@ cdef class Polynomial_integer_dense_flint(Polynomial): 1 sage: p = x^3 - x^2 - x - 1 - sage: r = p.roots(RIF, multiplicities=False)[0] - sage: p._eval_mpfi_(r) + sage: r = p.roots(RIF, multiplicities=False)[0] # needs sage.libs.linbox + sage: p._eval_mpfi_(r) # needs sage.libs.linbox 0.?e-27 """ cdef RealIntervalFieldElement res = a._new() @@ -395,7 +395,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): True sage: (t^2+3)(RealBallField(100)(1/3)) [3.1111111111111111111111111111...] - sage: (t^2+3)(ComplexBallField(10)(i)) + sage: (t^2+3)(ComplexBallField(10)(i)) # needs sage.symbolic 2.00 """ cdef Polynomial_integer_dense_flint f @@ -1354,7 +1354,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): sage: R. = PolynomialRing(ZZ) sage: f = 1 - x^2 - x^3 - x^4 + x^6 - sage: f.real_root_intervals() + sage: f.real_root_intervals() # needs sage.libs.linbox [((1/2, 3/4), 1), ((1, 3/2), 1)] """ diff --git a/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx b/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx index 71234543840..ef695cdc6e2 100644 --- a/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx +++ b/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx @@ -312,8 +312,8 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): 1 sage: p = x^3 - x^2 - x - 1 - sage: r = p.roots(RIF, multiplicities=False)[0] - sage: p._eval_mpfi_(r) + sage: r = p.roots(RIF, multiplicities=False)[0] # needs sage.libs.linbox + sage: p._eval_mpfi_(r) # needs sage.libs.linbox 0.?e-27 """ cdef RealIntervalFieldElement res = a._new() @@ -795,7 +795,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): sage: R. = PolynomialRing(ZZ, implementation='NTL') sage: f = 1 - x^2 - x^3 - x^4 + x^6 - sage: f.real_root_intervals() + sage: f.real_root_intervals() # needs sage.libs.linbox [((1/2, 3/4), 1), ((1, 3/2), 1)] """ diff --git a/src/sage/rings/polynomial/polynomial_quotient_ring.py b/src/sage/rings/polynomial/polynomial_quotient_ring.py index ee97f641990..0468efd8c68 100644 --- a/src/sage/rings/polynomial/polynomial_quotient_ring.py +++ b/src/sage/rings/polynomial/polynomial_quotient_ring.py @@ -1089,6 +1089,7 @@ def is_integral_domain(self, proof=True): EXAMPLES:: sage: R. = PolynomialRing(ZZ) + sage: S = R.quotient(z^2 - z) sage: S.is_integral_domain() False @@ -1098,12 +1099,14 @@ def is_integral_domain(self, proof=True): sage: U = R.quotient(-1) sage: U.is_integral_domain() False + + sage: # needs sage.libs.singular sage: R2. = PolynomialRing(R) sage: S2 = R2.quotient(z^2 - y^3) - sage: S2.is_integral_domain() # needs sage.libs.singular + sage: S2.is_integral_domain() True sage: S3 = R2.quotient(z^2 - 2*y*z + y^2) - sage: S3.is_integral_domain() # needs sage.libs.singular + sage: S3.is_integral_domain() False sage: R. = PolynomialRing(ZZ.quotient(4)) @@ -1915,7 +1918,7 @@ def _factor_multivariate_polynomial(self, f, proof=True): sage: K. = FunctionField(l) sage: R. = K[] sage: F = t * x - sage: F.factor(proof=False) + sage: F.factor(proof=False) # needs sage.modules (x) * t """ @@ -1945,9 +1948,9 @@ def _factor_univariate_polynomial(self, f): sage: R. = M[] sage: R(y).factor() # indirect doctest y - sage: (T^2 + T + x).factor() # indirect doctest + sage: (T^2 + T + x).factor() # indirect doctest # needs sage.modules (T + y) * (T + y + 1) - sage: (y*T^2 + y*T + y*x).factor() # indirect doctest + sage: (y*T^2 + y*T + y*x).factor() # indirect doctest # needs sage.modules (y) * (T + y) * (T + y + 1) """ @@ -1988,7 +1991,7 @@ def _isomorphic_ring(self): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.modules sage.rings.finite_rings sage: K. = GF(4) sage: R. = K[] sage: L. = K.extension(b^2 + b + a); L @@ -1996,14 +1999,13 @@ def _isomorphic_ring(self): over Finite Field in a of size 2^2 with modulus b^2 + b + a sage: from_M, to_M, M = L._isomorphic_ring(); M Finite Field in z4 of size 2^4 - - sage: R. = L[] # needs sage.rings.finite_rings - sage: M. = L.extension(c^2 + b*c + b); M # needs sage.rings.finite_rings + sage: R. = L[] + sage: M. = L.extension(c^2 + b*c + b); M Univariate Quotient Polynomial Ring in c over Univariate Quotient Polynomial Ring in b over Finite Field in a of size 2^2 with modulus b^2 + b + a with modulus c^2 + b*c + b - sage: from_N, to_N, N = M._isomorphic_ring(); N # needs sage.rings.finite_rings + sage: from_N, to_N, N = M._isomorphic_ring(); N Finite Field in z8 of size 2^8 sage: R. = QQ[] @@ -2135,7 +2137,7 @@ def _test_isomorphic_ring(self, **options): TESTS:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.modules sage.rings.finite_rings sage: K. = GF(4) sage: R. = K[] sage: L. = K.extension(b^2 + b + a) @@ -2367,7 +2369,7 @@ def field_extension(self, names): Over a finite field, the corresponding field extension is not a number field:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.modules sage.rings.finite_rings sage: R. = GF(25, 'a')['x'] sage: S. = R.quo(x^3 + 2*x + 1) sage: F, g, h = S.field_extension('b') diff --git a/src/sage/rings/polynomial/polynomial_quotient_ring_element.py b/src/sage/rings/polynomial/polynomial_quotient_ring_element.py index 4185f0d1455..57947c345bf 100644 --- a/src/sage/rings/polynomial/polynomial_quotient_ring_element.py +++ b/src/sage/rings/polynomial/polynomial_quotient_ring_element.py @@ -592,7 +592,7 @@ def charpoly(self, var): sage: R. = PolynomialRing(QQ) sage: S. = R.quo(x^3 -389*x^2 + 2*x - 5) - sage: a.charpoly('X') + sage: a.charpoly('X') # needs sage.modules X^3 - 389*X^2 + 2*X - 5 """ return self.matrix().charpoly(var) @@ -606,9 +606,9 @@ def fcp(self, var='x'): sage: R. = PolynomialRing(QQ) sage: S. = R.quotient(x^3 -389*x^2 + 2*x - 5) - sage: a.fcp('x') + sage: a.fcp('x') # needs sage.modules x^3 - 389*x^2 + 2*x - 5 - sage: S(1).fcp('y') + sage: S(1).fcp('y') # needs sage.modules (y - 1)^3 """ return self.charpoly(var).factor() @@ -621,7 +621,7 @@ def lift(self): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^3-2) + sage: S. = R.quotient(x^3 - 2) sage: b = a^2 - 3 sage: b a^2 - 3 @@ -661,7 +661,7 @@ def matrix(self): sage: R. = PolynomialRing(QQ) sage: S. = R.quotient(x^3 + 2*x - 5) - sage: a.matrix() + sage: a.matrix() # needs sage.modules [ 0 1 0] [ 0 0 1] [ 5 -2 0] @@ -699,9 +699,9 @@ def minpoly(self): sage: R. = PolynomialRing(QQ) sage: S. = R.quotient(x^3 + 2*x - 5) - sage: (a + 123).minpoly() + sage: (a + 123).minpoly() # needs sage.modules x^3 - 369*x^2 + 45389*x - 1861118 - sage: (a + 123).matrix().minpoly() + sage: (a + 123).matrix().minpoly() # needs sage.modules x^3 - 369*x^2 + 45389*x - 1861118 One useful application of this function is to compute a minimal @@ -711,10 +711,10 @@ def minpoly(self): sage: # needs sage.rings.finite_rings sage: F2. = GF((431,2), modulus=[1,0,1]) sage: F6. = F2.extension(3) - sage: (u + 1).minpoly() + sage: (u + 1).minpoly() # needs sage.modules x^6 + 425*x^5 + 19*x^4 + 125*x^3 + 189*x^2 + 239*x + 302 - sage: ext = F6.over(F2) - sage: ext(u + 1).minpoly() # indirect doctest + sage: ext = F6.over(F2) # needs sage.modules + sage: ext(u + 1).minpoly() # indirect doctest # needs sage.modules x^3 + (396*i + 428)*x^2 + (80*i + 39)*x + 9*i + 178 TESTS: @@ -750,7 +750,7 @@ def norm(self): sage: R. = PolynomialRing(QQ) sage: S. = R.quotient(x^3 - 389*x^2 + 2*x - 5) - sage: a.norm() + sage: a.norm() # needs sage.modules 5 """ return self.matrix().determinant() @@ -763,8 +763,8 @@ def trace(self): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^3 -389*x^2 + 2*x - 5) - sage: a.trace() + sage: S. = R.quotient(x^3 - 389*x^2 + 2*x - 5) + sage: a.trace() # needs sage.modules 389 """ return self.matrix().trace() diff --git a/src/sage/rings/polynomial/polynomial_rational_flint.pyx b/src/sage/rings/polynomial/polynomial_rational_flint.pyx index f651c9f3512..04eaefc9fed 100644 --- a/src/sage/rings/polynomial/polynomial_rational_flint.pyx +++ b/src/sage/rings/polynomial/polynomial_rational_flint.pyx @@ -344,7 +344,7 @@ cdef class Polynomial_rational_flint(Polynomial): sage: P. = PolynomialRing(QQ) sage: f = 3*x^2 + 2*x + 5 - sage: singular(f) + sage: singular(f) # needs sage.libs.singular 3*x^2+2*x+5 """ self._parent._singular_(singular).set_ring() # Expensive! @@ -486,7 +486,7 @@ cdef class Polynomial_rational_flint(Polynomial): True sage: (t/3)(RealBallField(100)(1)) [0.33333333333333333333333333333...] - sage: (t/3)(ComplexBallField(10)(1+i)) + sage: (t/3)(ComplexBallField(10)(1+i)) # needs sage.symbolic [0.33...] + [0.33...]*I """ cdef Polynomial_rational_flint f @@ -2097,6 +2097,7 @@ cdef class Polynomial_rational_flint(Polynomial): EXAMPLES:: + sage: # needs sage.libs.pari sage: R. = QQ[] sage: f = x^4 - 17*x^3 - 2*x + 1 sage: G = f.galois_group(); G @@ -2113,6 +2114,7 @@ cdef class Polynomial_rational_flint(Polynomial): :: + sage: # needs sage.libs.pari sage: f = x^4 - 17*x^3 - 2*x + 1 sage: G = f.galois_group(pari_group=True); G PARI group [24, -1, 5, "S4"] of degree 4 @@ -2126,10 +2128,12 @@ cdef class Polynomial_rational_flint(Polynomial): :: + sage: R. = QQ[] sage: f = x^4 - 17*x^3 - 2*x + 1 sage: f.galois_group(algorithm='kash') # optional - kash Transitive group number 5 of degree 4 + sage: # needs sage.libs.gap sage: f = x^4 - 17*x^3 - 2*x + 1 sage: f.galois_group(algorithm='gap') Transitive group number 5 of degree 4 @@ -2139,6 +2143,7 @@ cdef class Polynomial_rational_flint(Polynomial): sage: f = x^12 - 2*x^8 - x^7 + 2*x^6 + 4*x^4 - 2*x^3 - x^2 - x + 1 sage: f.galois_group(algorithm='gap') Transitive group number 183 of degree 12 + sage: f.galois_group(algorithm='magma') # optional - magma Transitive group number 5 of degree 4 @@ -2157,7 +2162,7 @@ cdef class Polynomial_rational_flint(Polynomial): are supported (see :trac:`20631`):: sage: R. = QQ[] - sage: (zeta^2 + zeta + 1).galois_group(pari_group=True) + sage: (zeta^2 + zeta + 1).galois_group(pari_group=True) # needs sage.libs.pari PARI group [2, -1, 1, "S2"] of degree 2 """ from sage.groups.pari_group import PariGroup @@ -2287,6 +2292,7 @@ cdef class Polynomial_rational_flint(Polynomial): EXAMPLES:: + sage: # needs sage.rings.padic sage: R. = QQ[] sage: f = x^3 - 2 sage: f.factor_padic(2) @@ -2307,6 +2313,7 @@ cdef class Polynomial_rational_flint(Polynomial): the same as first coercing to `\QQ_p` and then factoring (see also :trac:`15422`):: + sage: # needs sage.rings.padic sage: f = x^2 - 3^6 sage: f.factor_padic(3, 5) ((1 + O(3^5))*x + 3^3 + O(3^5)) * ((1 + O(3^5))*x + 2*3^3 + 2*3^4 + O(3^5)) @@ -2318,13 +2325,15 @@ cdef class Polynomial_rational_flint(Polynomial): A more difficult example:: + sage: R. = QQ[] sage: f = 100 * (5*x + 1)^2 * (x + 5)^2 - sage: f.factor_padic(5, 10) + sage: f.factor_padic(5, 10) # needs sage.rings.padic (4*5^4 + O(5^14)) * ((1 + O(5^9))*x + 5^-1 + O(5^9))^2 * ((1 + O(5^10))*x + 5 + O(5^10))^2 Try some bogus inputs:: + sage: # needs sage.rings.padic sage: f.factor_padic(3, -1) Traceback (most recent call last): ... @@ -2469,7 +2478,7 @@ cdef class Polynomial_rational_flint(Polynomial): -31 sage: d.parent() is QQ True - sage: EllipticCurve([1, 1]).discriminant() / 16 + sage: EllipticCurve([1, 1]).discriminant() / 16 # needs sage.schemes -31 :: diff --git a/src/sage/rings/polynomial/polynomial_ring.py b/src/sage/rings/polynomial/polynomial_ring.py index 0b2daea1e0b..8801ed6709c 100644 --- a/src/sage/rings/polynomial/polynomial_ring.py +++ b/src/sage/rings/polynomial/polynomial_ring.py @@ -1057,10 +1057,11 @@ def change_ring(self, R): EXAMPLES:: + sage: # needs sage.rings.finite_rings sage.rings.real_interval_field sage: R. = RealIntervalField()[]; R Univariate Polynomial Ring in ZZZ over Real Interval Field with 53 bits of precision - sage: R.change_ring(GF(19^2, 'b')) # needs sage.rings.finite_rings + sage: R.change_ring(GF(19^2, 'b')) Univariate Polynomial Ring in ZZZ over Finite Field in b of size 19^2 """ from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing @@ -1160,6 +1161,7 @@ def characteristic(self): EXAMPLES:: + sage: # needs sage.rings.real_interval_field sage: R. = RealIntervalField()[]; R Univariate Polynomial Ring in ZZZ over Real Interval Field with 53 bits of precision sage: R.characteristic() @@ -1797,6 +1799,7 @@ def _roots_univariate_polynomial(self, p, ring=None, multiplicities=True, algori EXAMPLES:: + sage: # needs sage.libs.singular sage: R. = QQ[] sage: S. = R[] sage: p = y^3 + (-x^2 - 3)*y^2 + (2*x^3 - x^2 + 3)*y - x^4 + 2*x^2 - 1 @@ -2067,9 +2070,11 @@ def __init__(self, base_ring, name="x", sparse=False, implementation=None, Sparse Univariate Polynomial Ring in x over Rational Field sage: type(R.gen()) - sage: R = PRing(CC, 'x'); R # needs sage.rings.real_mpfr + + sage: # needs sage.rings.real_mpfr + sage: R = PRing(CC, 'x'); R Univariate Polynomial Ring in x over Complex Field with 53 bits of precision - sage: type(R.gen()) # needs sage.rings.real_mpfr + sage: type(R.gen()) Demonstrate that :trac:`8762` is fixed:: @@ -2163,6 +2168,7 @@ def divided_difference(self, points, full_table=False): Only return the divided-difference coefficients `F_{i,i}`. This example is taken from Example 1, page 121 of [BF2005]_:: + sage: # needs sage.rings.real_mpfr sage: points = [(1.0, 0.7651977), (1.3, 0.6200860), (1.6, 0.4554022), ....: (1.9, 0.2818186), (2.2, 0.1103623)] sage: R = PolynomialRing(RR, "x") @@ -2175,6 +2181,7 @@ def divided_difference(self, points, full_table=False): Now return the full divided-difference table:: + sage: # needs sage.rings.real_mpfr sage: points = [(1.0, 0.7651977), (1.3, 0.6200860), (1.6, 0.4554022), ....: (1.9, 0.2818186), (2.2, 0.1103623)] sage: R = PolynomialRing(RR, "x") @@ -2585,7 +2592,7 @@ def irreducible_element(self, n, algorithm=None): EXAMPLES:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.modules sage.rings.finite_rings sage: f = GF(5^3, 'a')['x'].irreducible_element(2) sage: f.degree() 2 diff --git a/src/sage/rings/polynomial/polynomial_ring_constructor.py b/src/sage/rings/polynomial/polynomial_ring_constructor.py index ecccc51519e..ba9b9453e76 100644 --- a/src/sage/rings/polynomial/polynomial_ring_constructor.py +++ b/src/sage/rings/polynomial/polynomial_ring_constructor.py @@ -442,7 +442,7 @@ def PolynomialRing(base_ring, *args, **kwds): sage: S = PolynomialRing(GF(2), 'j'); TestSuite(S).run(); type(S) - sage: R = PolynomialRing(ZZ, 'x,y', implementation="generic"); TestSuite(R).run(skip=['_test_elements', '_test_elements_eq_transitive']); type(R) # needs sage.libs.singular + sage: R = PolynomialRing(ZZ, 'x,y', implementation="generic"); TestSuite(R).run(skip=['_test_elements', '_test_elements_eq_transitive']); type(R) sage: S = PolynomialRing(ZZ, 'x,y'); TestSuite(S).run(skip='_test_elements'); type(S) # needs sage.libs.singular @@ -611,10 +611,13 @@ def PolynomialRing(base_ring, *args, **kwds): sage: R = PolynomialRing(GF(49), 'j', sparse=True); TestSuite(R).run(); type(R) # needs sage.rings.finite_rings + + sage: # needs sage.rings.real_interval_field sage: P. = PolynomialRing(RealIntervalField(2)) sage: TestSuite(P).run(skip=['_test_elements', '_test_elements_eq_transitive']) sage: Q. = PolynomialRing(P) - sage: TestSuite(Q).run(skip=['_test_additive_associativity', '_test_associativity', '_test_distributivity', '_test_prod']) + sage: TestSuite(Q).run(skip=['_test_additive_associativity', '_test_associativity', + ....: '_test_distributivity', '_test_prod']) sage: R. = PolynomialRing(RIF,2) sage: TestSuite(R).run(skip=['_test_elements', '_test_elements_eq_transitive']) """ diff --git a/src/sage/rings/polynomial/real_roots.pyx b/src/sage/rings/polynomial/real_roots.pyx index 79fdf47ca0f..f52fd1f6e79 100644 --- a/src/sage/rings/polynomial/real_roots.pyx +++ b/src/sage/rings/polynomial/real_roots.pyx @@ -1,3 +1,4 @@ +# sage.doctest: needs numpy sage.libs.linbox """ Isolate Real Roots of Real Polynomials diff --git a/src/sage/rings/polynomial/skew_polynomial_finite_field.pyx b/src/sage/rings/polynomial/skew_polynomial_finite_field.pyx index 8066670c4a0..99b3b7e64c9 100644 --- a/src/sage/rings/polynomial/skew_polynomial_finite_field.pyx +++ b/src/sage/rings/polynomial/skew_polynomial_finite_field.pyx @@ -1079,7 +1079,7 @@ cdef class SkewPolynomial_finite_field_dense(SkewPolynomial_finite_order_dense): we can get different orderings:: sage: factorizations2 = [ F for F in a.factorizations() ] - sage: factorizations == factorizations2 + sage: factorizations == factorizations2 # random False sage: sorted(factorizations) == sorted(factorizations2) True diff --git a/src/sage/rings/polynomial/toy_d_basis.py b/src/sage/rings/polynomial/toy_d_basis.py index 393eb0452b2..00209396614 100644 --- a/src/sage/rings/polynomial/toy_d_basis.py +++ b/src/sage/rings/polynomial/toy_d_basis.py @@ -35,10 +35,10 @@ the corresponding computation over `\ZZ`:: sage: I = A.ideal([f, fx, fy]) - sage: gb = d_basis(I); gb + sage: gb = d_basis(I); gb # needs sage.libs.singular [x - 2020, y - 11313, 22627] - sage: gb[-1].factor() + sage: gb[-1].factor() # needs sage.libs.singular 11^3 * 17 This Groebner Basis gives a lot of information. First, the only @@ -51,6 +51,7 @@ Another example. This one is from the Magma Handbook:: + sage: # needs sage.libs.singular sage: P. = PolynomialRing(IntegerRing(), 3, order='lex') sage: I = ideal(x^2 - 1, y^2 - 1, 2*x*y - z) sage: I = Ideal(d_basis(I)) @@ -61,6 +62,7 @@ To compute modulo 4, we can add the generator 4 to our basis.:: + sage: # needs sage.libs.singular sage: I = ideal(x^2 - 1, y^2 - 1, 2*x*y - z, 4) sage: gb = d_basis(I) sage: R = P.change_ring(IntegerModRing(4)) @@ -80,7 +82,7 @@ sage: P. = PolynomialRing(IntegerRing(), 3, order='degneglex') sage: I = ideal(x^2 - 3*y, y^3 - x*y, z^3 - x, x^4 - y*z + 1) - sage: I.change_ring(P.change_ring(RationalField())).groebner_basis() + sage: I.change_ring(P.change_ring(RationalField())).groebner_basis() # needs sage.libs.singular [1] However, when we compute the Groebner basis of I (defined over `\ZZ`), we @@ -102,7 +104,7 @@ sage: I.change_ring(P.change_ring(GF(103))).groebner_basis() [z - 18, y + 8, x + 39] - sage: I.change_ring( P.change_ring(GF(27173681))).groebner_basis() # needs sage.libs.pari + sage: I.change_ring(P.change_ring(GF(27173681))).groebner_basis() # needs sage.rings.finite_rings [z + 10380032, y + 3186055, x - 536027] Of course, modulo any other prime the Groebner basis is trivial so @@ -212,7 +214,7 @@ def d_basis(F, strat=True): sage: fx = f.derivative(x) sage: fy = f.derivative(y) sage: I = A.ideal([f,fx,fy]) - sage: gb = d_basis(I); gb + sage: gb = d_basis(I); gb # needs sage.libs.singular [x - 2020, y - 11313, 22627] """ R = F.ring() diff --git a/src/sage/rings/polynomial/toy_variety.py b/src/sage/rings/polynomial/toy_variety.py index 5b51dc5eb00..6b0572e6010 100644 --- a/src/sage/rings/polynomial/toy_variety.py +++ b/src/sage/rings/polynomial/toy_variety.py @@ -164,7 +164,7 @@ def is_linearly_dependent(polys) -> bool: sage: p = x*B[0] sage: is_linearly_dependent(B + [p]) # needs sage.modules False - sage: is_linearly_dependent([]) # needs sage.modules + sage: is_linearly_dependent([]) False """ if not polys: diff --git a/src/sage/rings/power_series_pari.pyx b/src/sage/rings/power_series_pari.pyx index 6b8d02b5762..5178392c618 100644 --- a/src/sage/rings/power_series_pari.pyx +++ b/src/sage/rings/power_series_pari.pyx @@ -9,7 +9,7 @@ PARI by passing the keyword ``implementation='pari'`` to the sage: R. = PowerSeriesRing(ZZ, implementation='pari'); R Power Series Ring in q over Integer Ring - sage: S. = PowerSeriesRing(CC, implementation='pari'); S + sage: S. = PowerSeriesRing(CC, implementation='pari'); S # needs sage.rings.real_mpfr Power Series Ring in t over Complex Field with 53 bits of precision Note that only the type of the elements depends on the implementation, @@ -19,9 +19,9 @@ not the type of the parents:: sage: type(q) - sage: type(S) + sage: type(S) # needs sage.rings.real_mpfr - sage: type(t) + sage: type(t) # needs sage.rings.real_mpfr If `k` is a finite field implemented using PARI, this is the default @@ -137,6 +137,7 @@ cdef class PowerSeries_pari(PowerSeries): TESTS:: + sage: # needs sage.rings.real_mpfr sage: R. = PowerSeriesRing(CC, implementation='pari') sage: TestSuite(q).run() sage: f = q - q^3 + O(q^10) @@ -664,6 +665,7 @@ cdef class PowerSeries_pari(PowerSeries): sage: f.list() [1, 0, 0, -5, 0, 1] + sage: # needs sage.rings.padics sage: S. = PowerSeriesRing(pAdicRing(5), implementation='pari') sage: (2 + u).list() [2 + O(5^20), 1 + O(5^20)] diff --git a/src/sage/rings/power_series_poly.pyx b/src/sage/rings/power_series_poly.pyx index 083fddaa805..519e13c1226 100644 --- a/src/sage/rings/power_series_poly.pyx +++ b/src/sage/rings/power_series_poly.pyx @@ -501,6 +501,7 @@ cdef class PowerSeries_poly(PowerSeries): In the past this could die with EXC_BAD_ACCESS (:trac:`8029`):: + sage: # needs sage.rings.real_mpfr sage: A. = RR['x'] sage: B. = PowerSeriesRing(A) sage: 1. + O(t) @@ -1152,6 +1153,7 @@ cdef class PowerSeries_poly(PowerSeries): With real coefficients:: + sage: # needs sage.rings.real_mpfr sage: R. = RR[[]] sage: f = exp(2*z) sage: f.pade(3, 3) # abs tol 1e-10 @@ -1159,6 +1161,7 @@ cdef class PowerSeries_poly(PowerSeries): When precision is too low:: + sage: # needs sage.rings.real_mpfr sage: f = z + O(z**6) sage: f.pade(4, 4) Traceback (most recent call last): @@ -1168,13 +1171,13 @@ cdef class PowerSeries_poly(PowerSeries): Check that :trac:`21212` is fixed:: sage: QQx. = QQ[[]] - sage: (1+x+O(x^100)).pade(2,2) + sage: (1 + x + O(x^100)).pade(2,2) x + 1 Check for correct precision:: sage: QQx. = QQ[[]] - sage: (1+x+O(x^2)).pade(0,1) + sage: (1 + x + O(x^2)).pade(0,1) -1/(x - 1) """ if self.precision_absolute() < n + m + 1: diff --git a/src/sage/rings/power_series_ring_element.pyx b/src/sage/rings/power_series_ring_element.pyx index ceb8198fafc..b2ce51e09b3 100644 --- a/src/sage/rings/power_series_ring_element.pyx +++ b/src/sage/rings/power_series_ring_element.pyx @@ -1302,6 +1302,7 @@ cdef class PowerSeries(AlgebraElement): Tests other implementations:: + sage: # needs sage.libs.pari sage: R. = PowerSeriesRing(GF(11), implementation='pari') sage: f = q - q^3 + O(q^10) sage: f.map_coefficients(lambda c: c - 2) @@ -1341,8 +1342,8 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: sage: t = PowerSeriesRing(QQ, 't').gen() - sage: s = sum(factorial(k) * t**k for k in range(12)).O(12) # needs sage.rings.complex_double - sage: s.jacobi_continued_fraction() # needs sage.rings.complex_double + sage: s = sum(factorial(k) * t**k for k in range(12)).O(12) + sage: s.jacobi_continued_fraction() ((-1, -1), (-3, -4), (-5, -9), (-7, -16), (-9, -25)) Another example:: @@ -1506,26 +1507,26 @@ cdef class PowerSeries(AlgebraElement): def sqrt(self, prec=None, extend=False, all=False, name=None): r""" - Return a square root of self. + Return a square root of ``self``. INPUT: - - ``prec`` - integer (default: ``None``): if not ``None`` - and the series has infinite precision, truncates series at - precision prec. + - ``prec`` -- integer (default: ``None``): if not ``None`` and the series + has infinite precision, truncates series at precision + ``prec``. - - ``extend`` - bool (default: ``False``); if ``True``, return a square + - ``extend`` -- bool (default: ``False``); if ``True``, return a square root in an extension ring, if necessary. Otherwise, raise - a :class:`ValueError` if the square root is not in the - base power series ring. For example, if ``extend`` is ``True`` - the square root of a power series with odd degree leading - coefficient is defined as an element of a formal extension ring. + a :class:`ValueError` if the square root is not in the base power series + ring. For example, if ``extend`` is ``True``, the square root of a + power series with odd degree leading coefficient is + defined as an element of a formal extension ring. - - ``name`` - string; if ``extend`` is ``True``, you must also specify the print + - ``name`` -- string; if ``extend`` is ``True``, you must also specify the print name of the formal square root. - - ``all`` - bool (default: ``False``); if ``True``, return all square - roots of self, instead of just one. + - ``all`` -- bool (default: ``False``); if ``True``, return all square + roots of ``self``, instead of just one. ALGORITHM: Newton's method @@ -1538,20 +1539,22 @@ cdef class PowerSeries(AlgebraElement): sage: K. = PowerSeriesRing(QQ, 't', 5) sage: sqrt(t^2) t - sage: sqrt(1+t) + sage: sqrt(1 + t) 1 + 1/2*t - 1/8*t^2 + 1/16*t^3 - 5/128*t^4 + O(t^5) - sage: sqrt(4+t) + sage: sqrt(4 + t) 2 + 1/4*t - 1/64*t^2 + 1/512*t^3 - 5/16384*t^4 + O(t^5) - sage: u = sqrt(2+t, prec=2, extend=True, name = 'alpha'); u + sage: u = sqrt(2 + t, prec=2, extend=True, name = 'alpha'); u alpha sage: u^2 2 + t sage: u.parent() - Univariate Quotient Polynomial Ring in alpha over Power Series Ring in t over Rational Field with modulus x^2 - 2 - t + Univariate Quotient Polynomial Ring in alpha + over Power Series Ring in t over Rational Field + with modulus x^2 - 2 - t sage: K. = PowerSeriesRing(QQ, 't', 50) - sage: sqrt(1+2*t+t^2) + sage: sqrt(1 + 2*t + t^2) 1 + t - sage: sqrt(t^2 +2*t^4 + t^6) + sage: sqrt(t^2 + 2*t^4 + t^6) t + t^3 sage: sqrt(1 + t + t^2 + 7*t^3)^2 1 + t + t^2 + 7*t^3 + O(t^50) @@ -1562,7 +1565,8 @@ cdef class PowerSeries(AlgebraElement): :: - sage: K. = PowerSeriesRing(CDF, 5) # needs sage.rings.complex_double + sage: # needs sage.rings.complex_double + sage: K. = PowerSeriesRing(CDF, 5) sage: v = sqrt(-1 + t + t^3, all=True); v [1.0*I - 0.5*I*t - 0.125*I*t^2 - 0.5625*I*t^3 - 0.2890625*I*t^4 + O(t^5), -1.0*I + 0.5*I*t + 0.125*I*t^2 + 0.5625*I*t^3 + 0.2890625*I*t^4 + O(t^5)] @@ -1578,7 +1582,9 @@ cdef class PowerSeries(AlgebraElement): sage: s^2 2*t + t^3 + O(t^4) sage: parent(s) - Univariate Quotient Polynomial Ring in sqrtf over Power Series Ring in t over Rational Field with modulus x^2 - 2*t - t^3 + O(t^4) + Univariate Quotient Polynomial Ring in sqrtf + over Power Series Ring in t over Rational Field + with modulus x^2 - 2*t - t^3 + O(t^4) TESTS:: @@ -1687,7 +1693,7 @@ cdef class PowerSeries(AlgebraElement): def square_root(self): """ - Return the square root of self in this ring. If this cannot be done + Return the square root of ``self`` in this ring. If this cannot be done, then an error will be raised. This function succeeds if and only if @@ -1696,14 +1702,15 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: sage: K. = PowerSeriesRing(QQ, 't', 5) - sage: (1+t).square_root() + sage: (1 + t).square_root() 1 + 1/2*t - 1/8*t^2 + 1/16*t^3 - 5/128*t^4 + O(t^5) - sage: (2+t).square_root() + sage: (2 + t).square_root() Traceback (most recent call last): ... ValueError: Square root does not live in this ring. - sage: (2+t.change_ring(RR)).square_root() - 1.41421356237309 + 0.353553390593274*t - 0.0441941738241592*t^2 + 0.0110485434560398*t^3 - 0.00345266983001244*t^4 + O(t^5) + sage: (2 + t.change_ring(RR)).square_root() # needs sage.rings.real_mpfr + 1.41421356237309 + 0.353553390593274*t - 0.0441941738241592*t^2 + + 0.0110485434560398*t^3 - 0.00345266983001244*t^4 + O(t^5) sage: t.square_root() Traceback (most recent call last): ... @@ -1712,7 +1719,7 @@ cdef class PowerSeries(AlgebraElement): sage: f = (1+t)^20 sage: f.square_root() 1 + 10*t + 45*t^2 + 120*t^3 + 210*t^4 + O(t^5) - sage: f = 1+t + sage: f = 1 + t sage: f.square_root() Traceback (most recent call last): ... @@ -2478,7 +2485,8 @@ cdef class PowerSeries(AlgebraElement): Check that `\exp(t)` is, well, `\exp(t)`:: sage: (t + O(t^10)).exp() - 1 + t + 1/2*t^2 + 1/6*t^3 + 1/24*t^4 + 1/120*t^5 + 1/720*t^6 + 1/5040*t^7 + 1/40320*t^8 + 1/362880*t^9 + O(t^10) + 1 + t + 1/2*t^2 + 1/6*t^3 + 1/24*t^4 + 1/120*t^5 + 1/720*t^6 + + 1/5040*t^7 + 1/40320*t^8 + 1/362880*t^9 + O(t^10) Check that `\exp(\log(1+t))` is `1+t`:: @@ -2488,7 +2496,8 @@ cdef class PowerSeries(AlgebraElement): Check that `\exp(2t + t^2 - t^5)` is whatever it is:: sage: (2*t + t^2 - t^5 + O(t^10)).exp() - 1 + 2*t + 3*t^2 + 10/3*t^3 + 19/6*t^4 + 8/5*t^5 - 7/90*t^6 - 538/315*t^7 - 425/168*t^8 - 30629/11340*t^9 + O(t^10) + 1 + 2*t + 3*t^2 + 10/3*t^3 + 19/6*t^4 + 8/5*t^5 - 7/90*t^6 + - 538/315*t^7 - 425/168*t^8 - 30629/11340*t^9 + O(t^10) Check requesting lower precision:: @@ -2509,6 +2518,7 @@ cdef class PowerSeries(AlgebraElement): Handle nonzero constant term (fixes :trac:`4477`):: + sage: # needs sage.rings.real_mpfr sage: R. = PowerSeriesRing(RR) sage: (1 + x + x^2 + O(x^3)).exp() 2.71828182845905 + 2.71828182845905*x + 4.07742274268857*x^2 + O(x^3) @@ -2519,7 +2529,8 @@ cdef class PowerSeries(AlgebraElement): sage: (1 + x + O(x^2)).exp() # needs sage.symbolic Traceback (most recent call last): ... - ArithmeticError: exponential of constant term does not belong to coefficient ring (consider working in a larger ring) + ArithmeticError: exponential of constant term does not belong + to coefficient ring (consider working in a larger ring) :: @@ -2569,7 +2580,8 @@ cdef class PowerSeries(AlgebraElement): sage: R. = PowerSeriesRing(QQ, default_prec=10) sage: (1 + t + O(t^10)).log() - t - 1/2*t^2 + 1/3*t^3 - 1/4*t^4 + 1/5*t^5 - 1/6*t^6 + 1/7*t^7 - 1/8*t^8 + 1/9*t^9 + O(t^10) + t - 1/2*t^2 + 1/3*t^3 - 1/4*t^4 + 1/5*t^5 - 1/6*t^6 + 1/7*t^7 + - 1/8*t^8 + 1/9*t^9 + O(t^10) sage: t.exp().log() t + O(t^10) @@ -2582,8 +2594,9 @@ cdef class PowerSeries(AlgebraElement): ... ArithmeticError: constant term of power series is not 1 + sage: # needs sage.rings.real_mpfr sage: R. = PowerSeriesRing(RR) - sage: (2+t).log().exp() + sage: (2 + t).log().exp() 2.00000000000000 + 1.00000000000000*t + O(t^20) """ if prec is None: diff --git a/src/sage/rings/qqbar.py b/src/sage/rings/qqbar.py index 77d035896d0..3be8051935c 100644 --- a/src/sage/rings/qqbar.py +++ b/src/sage/rings/qqbar.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.libs.linbox r""" Field of Algebraic Numbers @@ -748,24 +748,21 @@ def _factor_multivariate_polynomial(self, f, proof=True): sage: R. = QQbar[] sage: A. = AA[] - sage: L = QQbar._factor_multivariate_polynomial(x^2-y^2) - sage: L + sage: # needs sage.libs.singular + sage: L = QQbar._factor_multivariate_polynomial(x^2 - y^2); L (x - y) * (x + y) - sage: L = QQbar._factor_multivariate_polynomial(x^2+y^2) - sage: L + sage: L = QQbar._factor_multivariate_polynomial(x^2 + y^2); L (x + (-1*I)*y) * (x + 1*I*y) sage: L.value() x^2 + y^2 - - sage: L = AA._factor_multivariate_polynomial(u^2-v^2) - sage: L + sage: L = AA._factor_multivariate_polynomial(u^2 - v^2); L (u - v) * (u + v) - sage: L = AA._factor_multivariate_polynomial(u^2+v^2) - sage: L + sage: L = AA._factor_multivariate_polynomial(u^2 + v^2); L u^2 + v^2 The test from Singular's ``absfact`` documentation:: + sage: # needs sage.libs.singular sage: p = (-7*x^2 + 2*x*y^2 + 6*x + y^4 + 14*y^2 + 47)*(5*x^2+y^2)^3*(x-y)^4 sage: F = QQbar._factor_multivariate_polynomial(p) sage: F @@ -775,7 +772,6 @@ def _factor_multivariate_polynomial(self, f, proof=True): * (y^2 + 3.828427124746190?*x + 8.414213562373095?) sage: F.value() == p True - sage: p = (-7*u^2 + 2*u*v^2 + 6*u + v^4 + 14*v^2 + 47)*(5*u^2+v^2)^3*(u-v)^4 sage: F = AA._factor_multivariate_polynomial(p) sage: F @@ -789,15 +785,13 @@ def _factor_multivariate_polynomial(self, f, proof=True): A test requiring us to further extend a number field that was used to specify the polynomial:: - sage: # needs sage.symbolic + sage: # needs sage.libs.singular sage.symbolic sage: p = x^2 + QQbar(sqrt(2))*y^2 sage: F = QQbar._factor_multivariate_polynomial(p) sage: F (x + (-1.189207115002722?*I)*y) * (x + 1.189207115002722?*I*y) sage: F.value() == p True - - sage: # needs sage.symbolic sage: p = u^2 + AA(sqrt(2))*v^2 sage: F = AA._factor_multivariate_polynomial(p) sage: F @@ -808,15 +802,13 @@ def _factor_multivariate_polynomial(self, f, proof=True): A test requiring a number field different from the number field used to specify the polynomial:: - sage: # needs sage.symbolic + sage: # needs sage.libs.singular sage.symbolic sage: p = QQbar(sqrt(2))*(x^2+y^2) sage: F = QQbar._factor_multivariate_polynomial(p) sage: F (1.414213562373095?) * (x + (-1*I)*y) * (x + 1*I*y) sage: F.value() == p True - - sage: # needs sage.symbolic sage: p = AA(sqrt(2))*(u^2+v^2) sage: F = AA._factor_multivariate_polynomial(p) sage: F @@ -827,19 +819,15 @@ def _factor_multivariate_polynomial(self, f, proof=True): A test where a factor introduces a number field that was already used to specify the polynomial:: - sage: # needs sage.symbolic + sage: # needs sage.libs.singular sage.symbolic sage: p = QQbar(sqrt(2))*(x^2-2*y^2)^2 - sage: F = QQbar._factor_multivariate_polynomial(p) - sage: F + sage: F = QQbar._factor_multivariate_polynomial(p); F (1.414213562373095?) * (x + (-1.414213562373095?)*y)^2 * (x + 1.414213562373095?*y)^2 sage: F.value() == p True - - sage: # needs sage.symbolic sage: p = AA(sqrt(2))*(u^2-2*v^2)^2 - sage: F = AA._factor_multivariate_polynomial(p) - sage: F + sage: F = AA._factor_multivariate_polynomial(p); F (1.414213562373095?) * (u - 1.414213562373095?*v)^2 * (u + 1.414213562373095?*v)^2 sage: F.value() == p @@ -847,19 +835,17 @@ def _factor_multivariate_polynomial(self, f, proof=True): A test where two factors produce the same factor in the norm:: - sage: # needs sage.symbolic + sage: # needs sage.libs.singular sage.symbolic sage: p = (x^2+QQbar(sqrt(2))*y^2)*(x^4-2*y^4) - sage: F = QQbar._factor_multivariate_polynomial(p) - sage: F + sage: F = QQbar._factor_multivariate_polynomial(p); F (x + (-1.189207115002722?)*y) * (x + 1.189207115002722?*y) * (x + (-1.189207115002722?*I)*y)^2 * (x + 1.189207115002722?*I*y)^2 sage: F.value() == p True - sage: # needs sage.symbolic + sage: # needs sage.libs.singular sage.symbolic sage: p = (u^2+AA(sqrt(2))*v^2)*(u^4-2*v^4) - sage: F = AA._factor_multivariate_polynomial(p) - sage: F + sage: F = AA._factor_multivariate_polynomial(p); F (u - 1.189207115002722?*v) * (u + 1.189207115002722?*v) * (u^2 + 1.414213562373095?*v^2)^2 sage: F.value() == p @@ -868,9 +854,9 @@ def _factor_multivariate_polynomial(self, f, proof=True): A test where the number field that expresses the result is a subfield of the number field that expressed the polynomial:: + sage: # needs sage.libs.singular sage: p = (x^2+QQbar(2)^(1/2)*y^2)*(x+QQbar(2)^(1/8)*y) - sage: F = QQbar._factor_multivariate_polynomial(p) - sage: F + sage: F = QQbar._factor_multivariate_polynomial(p); F (x + (-1.189207115002722?*I)*y) * (x + 1.189207115002722?*I*y) * (x + 1.090507732665258?*y) sage: F.value() == p @@ -879,14 +865,15 @@ def _factor_multivariate_polynomial(self, f, proof=True): A test where the polynomial variable names conflict with the number field generator:: + sage: # needs sage.libs.singular sage.symbolic sage: S. = QQbar[] - sage: p = a^2 + QQbar(sqrt(2))*b^2 # needs sage.symbolic - sage: F = QQbar._factor_multivariate_polynomial(p) # needs sage.symbolic - sage: F # needs sage.symbolic + sage: p = a^2 + QQbar(sqrt(2))*b^2 + sage: F = QQbar._factor_multivariate_polynomial(p); F (a + (-1.189207115002722?*I)*b) * (a + 1.189207115002722?*I*b) A test that led to :trac:`26898`:: + sage: # needs sage.libs.singular sage: R. = QQ[] sage: minpoly = 4*x^7 + 27 sage: NF. = NumberField(minpoly) @@ -896,6 +883,7 @@ def _factor_multivariate_polynomial(self, f, proof=True): Test :trac:`29076`:: + sage: # needs sage.libs.singular sage: AA['x','y'](1).factor() # indirect doctest 1 @@ -1520,7 +1508,7 @@ def _factor_univariate_polynomial(self, f): (12) * (x - 0.5773502691896258?) * (x + 0.5773502691896258?) sage: AA._factor_univariate_polynomial(12*x^2 + 4) (12) * (x^2 + 0.3333333333333334?) - sage: AA._factor_univariate_polynomial(EllipticCurve('11a1').change_ring(AA).division_polynomial(5)) + sage: AA._factor_univariate_polynomial(EllipticCurve('11a1').change_ring(AA).division_polynomial(5)) # needs sage.schemes (5) * (x - 16.00000000000000?) * (x - 5.000000000000000?) * (x - 1.959674775249769?) * (x + 2.959674775249769?) * (x^2 - 2.854101966249685?*x + 15.47213595499958?) * (x^2 + 1.909830056250526?*x + 1.660606461254312?) * (x^2 + 3.854101966249685?*x + 6.527864045000421?) * (x^2 + 13.09016994374948?*x + 93.33939353874569?) """ @@ -1700,8 +1688,9 @@ def _coerce_map_from_(self, from_par): sage: QQbar.has_coerce_map_from(SR) # needs sage.symbolic False - sage: i + QQbar(2) + sage: i + QQbar(2) # needs sage.symbolic I + 2 + sage: K. = QuadraticField(-1, embedding=ComplexField(13)(0,-1)) sage: ii + QQbar(2) -I + 2 @@ -2078,7 +2067,7 @@ def _factor_univariate_polynomial(self, f): (12) * (x - 0.5773502691896258?) * (x + 0.5773502691896258?) sage: QQbar._factor_univariate_polynomial(R(-1)) -1 - sage: QQbar._factor_univariate_polynomial(EllipticCurve('11a1').change_ring(QQbar).division_polynomial(5)) + sage: QQbar._factor_univariate_polynomial(EllipticCurve('11a1').change_ring(QQbar).division_polynomial(5)) # needs sage.schemes (5) * (x - 16) * (x - 5) * (x - 1.959674775249769?) * (x - 1.427050983124843? - 3.665468789467727?*I) * (x - 1.427050983124843? + 3.665468789467727?*I) * (x + 0.9549150281252629? - 0.8652998037182486?*I) * (x + 0.9549150281252629? + 0.8652998037182486?*I) * (x + 1.927050983124843? - 1.677599044300515?*I) * (x + 1.927050983124843? + 1.677599044300515?*I) * (x + 2.959674775249769?) * (x + 6.545084971874737? - 7.106423590645660?*I) * (x + 6.545084971874737? + 7.106423590645660?*I) """ @@ -2785,15 +2774,16 @@ def number_field_elements_from_algebraics(numbers, minimal=False, same_field=Fal Tests more complicated combinations:: + sage: # needs sage.libs.gap sage.symbolic sage: UCF = UniversalCyclotomicField() sage: E = UCF.gen(5) sage: L. = NumberField(x^2-189*x+16, embedding=200) sage: x = polygen(ZZ) - sage: my_nums = [-52*E - 136*E^2 - 136*E^3 - 52*E^4, # needs sage.symbolic + sage: my_nums = [-52*E - 136*E^2 - 136*E^3 - 52*E^4, ....: L.gen()._algebraic_(AA), ....: sqrt(2), AA.polynomial_root(x^3 - 3, RIF(0,3)), 11/9, 1] - sage: res = number_field_elements_from_algebraics(my_nums, embedded=True) # needs sage.symbolic - sage: res[0] # needs sage.symbolic + sage: res = number_field_elements_from_algebraics(my_nums, embedded=True) + sage: res[0] Number Field in a with defining polynomial y^24 - 107010*y^22 - 24*y^21 + ... + 250678447193040618624307096815048024318853254384 with a = 93.32530798172420? """ @@ -8581,10 +8571,10 @@ def exactify(self): We lower the recursion limit for this test to allow a test in reasonable time:: + sage: # needs sage.combinat sage: import sys sage: old_recursion_limit = sys.getrecursionlimit() sage: sys.setrecursionlimit(1000) - sage: sys.getrecursionlimit() 1000 sage: s = SymmetricFunctions(QQ).schur() @@ -8593,7 +8583,6 @@ def exactify(self): 0 sage: sys.getrecursionlimit() 1000 - sage: sys.setrecursionlimit(old_recursion_limit) """ import sys diff --git a/src/sage/rings/rational_field.py b/src/sage/rings/rational_field.py index 104c5463bf5..7296d227097 100644 --- a/src/sage/rings/rational_field.py +++ b/src/sage/rings/rational_field.py @@ -808,7 +808,7 @@ def hilbert_symbol_negative_at_S(self, S, b, check=True): :: - sage: QQ.hilbert_symbol_negative_at_S([5, 7], 2) # needs sage.libs.pari sage.modules + sage: QQ.hilbert_symbol_negative_at_S([5, 7], 2) # needs sage.libs.pari sage.modules sage.rings.padics Traceback (most recent call last): ... ValueError: second argument must be a nonsquare with @@ -1424,7 +1424,7 @@ def selmer_space(self, S, p, proof=None): sage: QS2gens # needs sage.rings.number_field [-1] - sage: all(QQ.selmer_space([], p)[0].dimension() == 0 # needs sage.libs.pari + sage: all(QQ.selmer_space([], p)[0].dimension() == 0 # needs sage.libs.pari sage.rings.number_field ....: for p in primes(3, 10)) True diff --git a/src/sage/rings/real_arb.pyx b/src/sage/rings/real_arb.pyx index a9ce06d14ca..17961ac36b2 100644 --- a/src/sage/rings/real_arb.pyx +++ b/src/sage/rings/real_arb.pyx @@ -3950,7 +3950,7 @@ cdef class RealBall(RingElement): [0.69314718055995 +/- ...e-15] sage: RBF(1/3).polylog(1/2) [0.44210883528067 +/- 6.7...e-15] - sage: RBF(1/3).polylog(RLF(pi)) + sage: RBF(1/3).polylog(RLF(pi)) # needs sage.symbolic [0.34728895057225 +/- ...e-15] TESTS:: diff --git a/src/sage/rings/real_interval_absolute.pyx b/src/sage/rings/real_interval_absolute.pyx index aab89c97d0e..5b5e663a5dc 100644 --- a/src/sage/rings/real_interval_absolute.pyx +++ b/src/sage/rings/real_interval_absolute.pyx @@ -173,7 +173,7 @@ cdef class RealIntervalAbsoluteField_class(Field): True sage: R.has_coerce_map_from(QQ) True - sage: R.has_coerce_map_from(Qp(5)) + sage: R.has_coerce_map_from(Qp(5)) # needs sage.rings.padics False sage: R(1/2) + 100 diff --git a/src/sage/rings/ring.pyx b/src/sage/rings/ring.pyx index a6e999b8805..75f58656385 100644 --- a/src/sage/rings/ring.pyx +++ b/src/sage/rings/ring.pyx @@ -134,7 +134,7 @@ cdef class Ring(ParentWithGens): running ._test_zero_divisors() . . . pass sage: TestSuite(QQ['x','y']).run(skip='_test_elements') # needs sage.libs.singular sage: TestSuite(ZZ['x','y']).run(skip='_test_elements') # needs sage.libs.singular - sage: TestSuite(ZZ['x','y']['t']).run() # needs sage.libs.singular + sage: TestSuite(ZZ['x','y']['t']).run() Test against another bug fixed in :trac:`9944`:: @@ -533,10 +533,10 @@ cdef class Ring(ParentWithGens): sage: S._ideal_class_(2) - sage: T. = S[] # needs sage.rings.finite_rings - sage: T._ideal_class_(5) # needs sage.rings.finite_rings + sage: T. = S[] # needs sage.libs.singular + sage: T._ideal_class_(5) # needs sage.libs.singular - sage: T._ideal_class_(1) # needs sage.rings.finite_rings + sage: T._ideal_class_(1) # needs sage.libs.singular Since :trac:`7797`, non-commutative rings have ideals as well:: diff --git a/src/sage/rings/sum_of_squares.pyx b/src/sage/rings/sum_of_squares.pyx index 737911ad53e..e6ec62dc7f1 100644 --- a/src/sage/rings/sum_of_squares.pyx +++ b/src/sage/rings/sum_of_squares.pyx @@ -166,7 +166,7 @@ def two_squares_pyx(uint32_t n): TESTS:: sage: s = lambda t: sum(i^2 for i in t) - sage: for ij in Subsets(Subsets(45000, 15).random_element(), 2): # needs sage.combinat + sage: for ij in Subsets(Subsets(45000, 15).random_element(), 2): ....: if s(two_squares_pyx(s(ij))) != s(ij): ....: print("hey") @@ -254,7 +254,7 @@ def three_squares_pyx(uint32_t n): TESTS:: sage: s = lambda t: sum(i^2 for i in t) - sage: for ijk in Subsets(Subsets(35000,15).random_element(),3): # needs sage.combinat + sage: for ijk in Subsets(Subsets(35000,15).random_element(),3): ....: if s(three_squares_pyx(s(ijk))) != s(ijk): ....: print("hey") """ diff --git a/src/sage/rings/tests.py b/src/sage/rings/tests.py index 13a205195d5..3eed7e1aa31 100644 --- a/src/sage/rings/tests.py +++ b/src/sage/rings/tests.py @@ -445,7 +445,7 @@ def test_karatsuba_multiplication(base_ring, maxdeg1, maxdeg2, sage: rings += [ZZ[I], ZZ[I, sqrt(2)]] # needs sage.rings.number_field sage.symbolic sage: rings += [GF(49, 'a')] # needs sage.rings.finite_rings sage: rings += [MatrixSpace(GF(17), 3)] # needs sage.modules - sage: for C in rings: + sage: for C in rings: # needs sage.modules ....: test_karatsuba_multiplication(C, 10, 10) Zero-tests over ``QQbar`` are currently very slow, so we test only very small examples:: diff --git a/src/sage/rings/universal_cyclotomic_field.py b/src/sage/rings/universal_cyclotomic_field.py index 8afd960006c..e60d59cd0db 100644 --- a/src/sage/rings/universal_cyclotomic_field.py +++ b/src/sage/rings/universal_cyclotomic_field.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.libs.gap r""" Universal cyclotomic field @@ -576,7 +577,7 @@ def to_cyclotomic_field(self, R=None): [ E(3) E(4)] [ E(5) -E(3)^2] - sage: Matrix(CyclotomicField(60),M) # indirect doctest + sage: Matrix(CyclotomicField(60),M) # indirect doctest [zeta60^10 - 1 zeta60^15] [ zeta60^12 zeta60^10] @@ -699,7 +700,7 @@ def _eval_complex_(self, R): 2.41421356237310? sage: (1 + E(8) - E(8,3))._eval_complex_(CC) 2.41421356237309 - sage: (1 + E(8) - E(8,3))._eval_complex_(CDF) # abs tol 1e-14 + sage: (1 + E(8) - E(8,3))._eval_complex_(CDF) # abs tol 1e-14 2.414213562373095 """ if self._obj.IsRat(): @@ -1331,7 +1332,7 @@ def _first_ngens(self, n): This method is needed to make the following work:: - sage: UCF. = UniversalCyclotomicField() # indirect doctest + sage: UCF. = UniversalCyclotomicField() # indirect doctest """ if n == 1: return (self.gen,) diff --git a/src/sage/rings/valuation/augmented_valuation.py b/src/sage/rings/valuation/augmented_valuation.py index 7019fc39e91..6b23dab9d90 100644 --- a/src/sage/rings/valuation/augmented_valuation.py +++ b/src/sage/rings/valuation/augmented_valuation.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r""" Augmented valuations on polynomial rings @@ -35,107 +34,108 @@ sage: R. = QQ[] sage: v = GaussValuation(R, QQ.valuation(2)) sage: w = v.augmentation(x, 1) - sage: TestSuite(w).run() # long time - + sage: TestSuite(w).run() # long time # needs sage.geometry.polyhedron sage: w = v.augmentation(x, 2) - sage: TestSuite(w).run() # long time + sage: TestSuite(w).run() # long time # needs sage.geometry.polyhedron Run the test suite for a valuation with a residual extension:: sage: R. = QQ[] sage: v = GaussValuation(R, QQ.valuation(2)) sage: w = v.augmentation(x^2 + x + 1, 1) - sage: TestSuite(w).run() # long time + sage: TestSuite(w).run() # long time # needs sage.geometry.polyhedron Run the test suite for an iterated residual extension starting from a non-prime residue field:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 40) sage: S. = R[] sage: v = GaussValuation(S) sage: w = v.augmentation(x^2 + x + u, 1/2) - sage: TestSuite(w).run() # long time - - sage: ww = w.augmentation(x^8 + 4*x^7 + 2*x^6 + 2*x^5 + x^4 + 2*x^3 + 4*(u + 1)*x^2 + 6*(u + 1)*x + 4 + 3*u, 10) + sage: TestSuite(w).run() # long time # needs sage.geometry.polyhedron + sage: ww = w.augmentation(x^8 + 4*x^7 + 2*x^6 + 2*x^5 + x^4 + 2*x^3 + ....: + 4*(u + 1)*x^2 + 6*(u + 1)*x + 4 + 3*u, 10) sage: TestSuite(ww).run() # long time Run the test suite for an augmentation of a ramified augmentation:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) sage: w = v.augmentation(x, 3/4) - sage: TestSuite(w).run() # long time - + sage: TestSuite(w).run() # long time # needs sage.geometry.polyhedron sage: ww = w.augmentation(x^4 + 8, 5) - sage: TestSuite(ww).run() # long time + sage: TestSuite(ww).run() # long time # needs sage.numerical.mip Run the test suite for a ramified augmentation of an unramified augmentation:: sage: R. = QQ[] sage: v = GaussValuation(R, QQ.valuation(2)) sage: w = v.augmentation(x^2 + x + 1, 1) - sage: TestSuite(w).run() # long time - + sage: TestSuite(w).run() # long time # needs sage.geometry.polyhedron sage: ww = w.augmentation(x^4 + 2*x^3 + 5*x^2 + 8*x + 3, 16/3) - sage: TestSuite(ww).run() # long time + sage: TestSuite(ww).run() # long time # needs sage.numerical.mip Run the test suite for a ramified augmentation of a ramified augmentation:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 20) sage: S. = R[] sage: v = GaussValuation(S) sage: w = v.augmentation(x^2 + x + u, 1/2) - sage: TestSuite(w).run() # long time - + sage: TestSuite(w).run() # long time # needs sage.geometry.polyhedron sage: ww = w.augmentation((x^2 + x + u)^2 + 2, 5/3) - sage: TestSuite(ww).run() # long time + sage: TestSuite(ww).run() # long time # needs sage.numerical.mip Run the test suite for another augmentation with iterated residue field extensions:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 10) sage: S. = R[] sage: v = GaussValuation(S) sage: w = v.augmentation(x^2 + x + u, 1) - sage: TestSuite(w).run() # long time - + sage: TestSuite(w).run() # long time # needs sage.geometry.polyhedron sage: ww = w.augmentation((x^2 + x + u)^2 + 2*x*(x^2 + x + u) + 4*x, 3) - sage: TestSuite(ww).run() # long time + sage: TestSuite(ww).run() # long time # needs sage.numerical.mip Run the test suite for a rather trivial pseudo-valuation:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) sage: w = v.augmentation(x, infinity) - sage: TestSuite(w).run() # long time + sage: TestSuite(w).run() # long time # needs sage.geometry.polyhedron Run the test suite for an infinite valuation which extends the residue field:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) sage: w = v.augmentation(x^2 + x + u, infinity) - sage: TestSuite(w).run() # long time + sage: TestSuite(w).run() # long time # needs sage.geometry.polyhedron Run the test suite for an infinite valuation which extends a valuation which extends the residue field:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) sage: w = v.augmentation(x^2 + x + u, 1/2) - sage: TestSuite(w).run() # long time - + sage: TestSuite(w).run() # long time # needs sage.geometry.polyhedron sage: ww = w.augmentation((x^2 + x + u)^2 + 2, infinity) - sage: TestSuite(ww).run() # long time + sage: TestSuite(ww).run() # long time # needs sage.numerical.mip Run the test suite if the polynomial ring is not over a field:: sage: R. = ZZ[] sage: v = GaussValuation(R, ZZ.valuation(2)) sage: w = v.augmentation(x, 1) - sage: TestSuite(w).run() # long time + sage: TestSuite(w).run() # long time # needs sage.geometry.polyhedron REFERENCES: @@ -174,7 +174,7 @@ class AugmentedValuationFactory(UniqueFactory): sage: R. = QQ[] sage: v = GaussValuation(R, QQ.valuation(2)) - sage: w = v.augmentation(x, 1) # indirect doctest + sage: w = v.augmentation(x, 1) # indirect doctest Note that trivial parts of the augmented valuation might be dropped, so you should not rely on ``_base_valuation`` to be the valuation you started @@ -202,7 +202,7 @@ def create_key(self, base_valuation, phi, mu, check=True): sage: R. = QQ[] sage: v = GaussValuation(R, QQ.valuation(2)) - sage: w = v.augmentation(x, 1) # indirect doctest + sage: w = v.augmentation(x, 1) # indirect doctest sage: ww = v.augmentation(x, 1) sage: w is ww True @@ -236,7 +236,7 @@ def create_object(self, version, key): sage: R. = QQ[] sage: v = GaussValuation(R, QQ.valuation(2)) - sage: w = v.augmentation(x^2 + x + 1, 1) # indirect doctest + sage: w = v.augmentation(x^2 + x + 1, 1) # indirect doctest """ base_valuation, phi, mu = key @@ -272,24 +272,27 @@ class AugmentedValuation_base(InductiveValuation): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K. = CyclotomicField(5) sage: R. = K[] sage: v = GaussValuation(R, K.valuation(2)) - sage: w = v.augmentation(x, 1/2); w # indirect doctest + sage: w = v.augmentation(x, 1/2); w # indirect doctest [ Gauss valuation induced by 2-adic valuation, v(x) = 1/2 ] sage: ww = w.augmentation(x^4 + 2*x^2 + 4*u, 3); ww [ Gauss valuation induced by 2-adic valuation, v(x) = 1/2, v(x^4 + 2*x^2 + 4*u) = 3 ] TESTS:: - sage: TestSuite(w).run() # long time - sage: TestSuite(ww).run() # long time + sage: # needs sage.rings.number_field + sage: TestSuite(w).run() # long time + sage: TestSuite(ww).run() # long time """ def __init__(self, parent, v, phi, mu): r""" TESTS:: + sage: # needs sage.libs.ntl sage: K. = Qq(4, 5) sage: R. = K[] sage: v = GaussValuation(R) @@ -298,8 +301,7 @@ def __init__(self, parent, v, phi, mu): sage: from sage.rings.valuation.augmented_valuation import AugmentedValuation_base sage: isinstance(w, AugmentedValuation_base) True - - sage: TestSuite(w).run() # long time + sage: TestSuite(w).run() # long time # needs sage.numerical.mip """ InductiveValuation.__init__(self, parent, phi) @@ -327,11 +329,11 @@ def equivalence_unit(self, s, reciprocal=False): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) sage: w = v.augmentation(x^2 + x + u, 1) - sage: w.equivalence_unit(0) 1 + O(2^5) sage: w.equivalence_unit(-4) @@ -341,21 +343,19 @@ def equivalence_unit(self, s, reciprocal=False): divide it. Therefore, its valuation is in the value group of the base valuation:: - sage: w = v.augmentation(x, 1/2) - - sage: w.equivalence_unit(3/2) + sage: w = v.augmentation(x, 1/2) # needs sage.libs.ntl + sage: w.equivalence_unit(3/2) # needs sage.libs.ntl Traceback (most recent call last): ... ValueError: 3/2 is not in the value semigroup of 2-adic valuation - sage: w.equivalence_unit(1) + sage: w.equivalence_unit(1) # needs sage.libs.ntl 2 + O(2^6) An equivalence unit might not be integral, even if ``s >= 0``:: - sage: w = v.augmentation(x, 3/4) - sage: ww = w.augmentation(x^4 + 8, 5) - - sage: ww.equivalence_unit(1/2) + sage: w = v.augmentation(x, 3/4) # needs sage.libs.ntl + sage: ww = w.augmentation(x^4 + 8, 5) # needs sage.libs.ntl + sage: ww.equivalence_unit(1/2) # needs sage.libs.ntl (2^-1 + O(2^4))*x^2 """ @@ -386,6 +386,7 @@ def element_with_valuation(self, s): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) @@ -403,7 +404,8 @@ def element_with_valuation(self, s): sage: w.element_with_valuation(1/3) Traceback (most recent call last): ... - ValueError: s must be in the value group of the valuation but 1/3 is not in Additive Abelian Group generated by 1/2. + ValueError: s must be in the value group of the valuation + but 1/3 is not in Additive Abelian Group generated by 1/2. """ if s not in self.value_group(): @@ -423,12 +425,14 @@ def _repr_(self): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) sage: w = v.augmentation(x^2 + x + u, 1/2) - sage: w # indirect doctest - [ Gauss valuation induced by 2-adic valuation, v((1 + O(2^5))*x^2 + (1 + O(2^5))*x + u + O(2^5)) = 1/2 ] + sage: w # indirect doctest + [ Gauss valuation induced by 2-adic valuation, + v((1 + O(2^5))*x^2 + (1 + O(2^5))*x + u + O(2^5)) = 1/2 ] """ vals = self.augmentation_chain() @@ -447,7 +451,7 @@ def augmentation_chain(self): sage: w = v.augmentation(x, 1) sage: w.augmentation_chain() [[ Gauss valuation induced by 2-adic valuation, v(x) = 1 ], - Gauss valuation induced by 2-adic valuation] + Gauss valuation induced by 2-adic valuation] For performance reasons, (and to simplify the underlying implementation,) trivial augmentations might get dropped. You should @@ -457,7 +461,7 @@ def augmentation_chain(self): sage: ww = w.augmentation(x, 2) sage: ww.augmentation_chain() [[ Gauss valuation induced by 2-adic valuation, v(x) = 2 ], - Gauss valuation induced by 2-adic valuation] + Gauss valuation induced by 2-adic valuation] """ return [self] + self._base_valuation.augmentation_chain() @@ -473,14 +477,13 @@ def psi(self): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) - sage: w = v.augmentation(x^2 + x + u, 1/2) sage: w.psi() x^2 + x + u0 - sage: ww = w.augmentation((x^2 + x + u)^2 + 2, 5/3) sage: ww.psi() x + 1 @@ -499,14 +502,13 @@ def E(self): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) - sage: w = v.augmentation(x^2 + x + u, 1) sage: w.E() 1 - sage: w = v.augmentation(x, 1/2) sage: w.E() 2 @@ -524,14 +526,13 @@ def F(self): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) - sage: w = v.augmentation(x^2 + x + u, 1) sage: w.F() 2 - sage: w = v.augmentation(x, 1/2) sage: w.F() 1 @@ -548,8 +549,7 @@ def extensions(self, ring): sage: R. = QQ[] sage: v = GaussValuation(R, QQ.valuation(2)) sage: w = v.augmentation(x^2 + x + 1, 1) - - sage: w.extensions(GaussianIntegers().fraction_field()['x']) + sage: w.extensions(GaussianIntegers().fraction_field()['x']) # needs sage.rings.number_field [[ Gauss valuation induced by 2-adic valuation, v(x^2 + x + 1) = 1 ]] """ @@ -584,12 +584,12 @@ def restriction(self, ring): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K = GaussianIntegers().fraction_field() sage: R. = K[] sage: v = GaussValuation(R, K.valuation(2)) sage: w = v.augmentation(x^2 + x + 1, 1) - - sage: w.restriction(QQ['x']) + sage: w.restriction(QQ['x']) # needs sage.lins.singular [ Gauss valuation induced by 2-adic valuation, v(x^2 + x + 1) = 1 ] """ if ring.is_subring(self.domain()): @@ -645,13 +645,12 @@ def monic_integral_model(self, G): sage: R. = QQ[] sage: v = GaussValuation(R, QQ.valuation(2)) sage: w = v.augmentation(x^2 + x + 1, 1) - sage: w.monic_integral_model(5*x^2 + 1/2*x + 1/4) (Ring endomorphism of Univariate Polynomial Ring in x over Rational Field Defn: x |--> 1/2*x, Ring endomorphism of Univariate Polynomial Ring in x over Rational Field Defn: x |--> 2*x, - x^2 + 1/5*x + 1/5) + x^2 + 1/5*x + 1/5) """ return self._base_valuation.monic_integral_model(G) @@ -771,8 +770,9 @@ def _relative_size(self, f): EXAMPLES:: + sage: # needs sage.rings.number_field sage: R. = QQ[] - sage: K. = QQ.extension(u^2 + u+ 1) + sage: K. = QQ.extension(u^2 + u + 1) sage: S. = K[] sage: v = GaussValuation(S, K.valuation(2)) sage: w = v.augmentation(x^2 + x + u, 1/2) @@ -810,6 +810,7 @@ def change_domain(self, ring): We can change the domain of an augmented valuation even if there is no coercion between rings:: + sage: # needs sage.rings.number_field sage: R. = GaussianIntegers()[] sage: v = GaussValuation(R, GaussianIntegers().valuation(2)) sage: v = v.augmentation(x, 1) @@ -866,14 +867,14 @@ def residue_ring(self): Rational Field sage: w = v.augmentation(x^2 + x + 1, infinity) - sage: w.residue_ring() + sage: w.residue_ring() # needs sage.rings.number_field Number Field in u1 with defining polynomial x^2 + x + 1 An example with a non-trivial base valuation:: sage: v = GaussValuation(R, QQ.valuation(2)) sage: w = v.augmentation(x^2 + x + 1, infinity) - sage: w.residue_ring() + sage: w.residue_ring() # needs sage.rings.finite_rings Finite Field in u1 of size 2^2 Since trivial extensions of finite fields are not implemented, the @@ -888,6 +889,7 @@ def residue_ring(self): We avoid clashes in generator names:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: v = K.valuation(x^2 + 2) sage: R. = K[] @@ -951,13 +953,14 @@ def reduce(self, f, check=True, degree_bound=None, coefficients=None, valuations 1 sage: w = v.augmentation(x^2 + x + 1, infinity) - sage: w.reduce(x) + sage: w.reduce(x) # needs sage.rings.number_field u1 TESTS: Cases with non-trivial base valuation:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 10) sage: S. = R[] sage: v = GaussValuation(S) @@ -965,7 +968,6 @@ def reduce(self, f, check=True, degree_bound=None, coefficients=None, valuations x sage: v.reduce(S(u)) u0 - sage: w = v.augmentation(x^2 + x + u, 1/2) sage: w.reduce(S.one()) 1 @@ -973,14 +975,14 @@ def reduce(self, f, check=True, degree_bound=None, coefficients=None, valuations 0 sage: w.reduce(S(u)) u0 - sage: w.reduce(x) # this gives the generator of the residue field extension of w over v + sage: w.reduce(x) # this gives the generator of the residue field extension of w over v u1 sage: f = (x^2 + x + u)^2 / 2 sage: w.reduce(f) x sage: w.reduce(f + x + 1) x + u1 + 1 - + sage: # needs sage.libs.ntl sage: ww = w.augmentation((x^2 + x + u)^2 + 2, 5/3) sage: g = ((x^2 + x + u)^2 + 2)^3 / 2^5 sage: ww.reduce(g) @@ -1026,16 +1028,17 @@ def _residue_field_generator(self): 0 sage: w = v.augmentation(x^2 + x + 1, infinity) - sage: w._residue_field_generator() + sage: w._residue_field_generator() # needs sage.rings.number_field u1 A case with non-trivial base valuation:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 10) sage: S. = R[] sage: v = GaussValuation(S) sage: w = v.augmentation(x^2 + x + u, infinity) - sage: w._residue_field_generator() + sage: w._residue_field_generator() # needs sage.rings.number_field u1 """ @@ -1073,22 +1076,24 @@ def lift(self, F): 1/2 sage: w = v.augmentation(x^2 + x + 1, infinity) - sage: w.lift(w.residue_ring().gen()) + sage: w.lift(w.residue_ring().gen()) # needs sage.rings.number_field x A case with non-trivial base valuation:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 10) sage: S. = R[] sage: v = GaussValuation(S) sage: w = v.augmentation(x^2 + x + u, infinity) - sage: w.lift(w.residue_ring().gen()) + sage: w.lift(w.residue_ring().gen()) # needs sage.rings.number_field (1 + O(2^10))*x TESTS: Verify that :trac:`30305` has been resolved:: + sage: # needs sage.rings.number_field sage: R. = QQ[] sage: K. = NumberField(T^2 + T + 1) sage: R. = K[] @@ -1163,9 +1168,8 @@ def residue_ring(self): sage: R. = QQ[] sage: v = GaussValuation(R, QQ.valuation(2)) - sage: w = v.augmentation(x^2 + x + 1, 1) - sage: w.residue_ring() + sage: w.residue_ring() # needs sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field in u1 of size 2^2 Since trivial valuations of finite fields are not implemented, the @@ -1242,6 +1246,7 @@ def reduce(self, f, check=True, degree_bound=None, coefficients=None, valuations EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 10) sage: S. = R[] sage: v = GaussValuation(S) @@ -1249,7 +1254,6 @@ def reduce(self, f, check=True, degree_bound=None, coefficients=None, valuations x sage: v.reduce(S(u)) u0 - sage: w = v.augmentation(x^2 + x + u, 1/2) sage: w.reduce(S.one()) 1 @@ -1257,14 +1261,13 @@ def reduce(self, f, check=True, degree_bound=None, coefficients=None, valuations 0 sage: w.reduce(S(u)) u0 - sage: w.reduce(x) # this gives the generator of the residue field extension of w over v + sage: w.reduce(x) # this gives the generator of the residue field extension of w over v u1 sage: f = (x^2 + x + u)^2 / 2 sage: w.reduce(f) x sage: w.reduce(f + x + 1) x + u1 + 1 - sage: ww = w.augmentation((x^2 + x + u)^2 + 2, 5/3) sage: g = ((x^2 + x + u)^2 + 2)^3 / 2^5 sage: ww.reduce(g) @@ -1340,6 +1343,7 @@ def _residue_field_generator(self): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 10) sage: S. = R[] sage: v = GaussValuation(S) @@ -1383,14 +1387,13 @@ def lift(self, F, report_coefficients=False): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 10) sage: S. = R[] sage: v = GaussValuation(S) - sage: w = v.augmentation(x^2 + x + u, 1/2) sage: y = w.residue_ring().gen() sage: u1 = w.residue_ring().base().gen() - sage: w.lift(1) 1 + O(2^10) sage: w.lift(0) @@ -1401,11 +1404,9 @@ def lift(self, F, report_coefficients=False): True sage: w.reduce(w.lift(y + u1 + 1)) == y + u1 + 1 True - sage: ww = w.augmentation((x^2 + x + u)^2 + 2, 5/3) sage: y = ww.residue_ring().gen() sage: u2 = ww.residue_ring().base().gen() - sage: ww.reduce(ww.lift(y)) == y True sage: ww.reduce(ww.lift(1)) == 1 @@ -1415,11 +1416,11 @@ def lift(self, F, report_coefficients=False): A more complicated example:: + sage: # needs sage.libs.ntl sage: v = GaussValuation(S) sage: w = v.augmentation(x^2 + x + u, 1) sage: ww = w.augmentation((x^2 + x + u)^2 + 2*x*(x^2 + x + u) + 4*x, 3) sage: u = ww.residue_ring().base().gen() - sage: F = ww.residue_ring()(u); F u2 sage: f = ww.lift(F); f @@ -1494,10 +1495,10 @@ def lift_to_key(self, F, check=True): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 10) sage: S. = R[] sage: v = GaussValuation(S) - sage: w = v.augmentation(x^2 + x + u, 1/2) sage: y = w.residue_ring().gen() sage: f = w.lift_to_key(y + 1); f @@ -1507,10 +1508,10 @@ def lift_to_key(self, F, check=True): A more complicated example:: + sage: # needs sage.libs.ntl sage: v = GaussValuation(S) sage: w = v.augmentation(x^2 + x + u, 1) sage: ww = w.augmentation((x^2 + x + u)^2 + 2*x*(x^2 + x + u) + 4*x, 3) - sage: u = ww.residue_ring().base().gen() sage: y = ww.residue_ring().gen() sage: f = ww.lift_to_key(y^3+y+u) @@ -1616,6 +1617,7 @@ class FiniteAugmentedValuation(AugmentedValuation_base, FiniteInductiveValuation EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) @@ -1626,6 +1628,7 @@ def __init__(self, parent, v, phi, mu): r""" EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) @@ -1645,14 +1648,13 @@ def value_group(self): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) - sage: w = v.augmentation(x^2 + x + u, 1/2) sage: w.value_group() Additive Abelian Group generated by 1/2 - sage: ww = w.augmentation((x^2 + x + u)^2 + 2, 5/3) sage: ww.value_group() Additive Abelian Group generated by 1/6 @@ -1666,14 +1668,13 @@ def value_semigroup(self): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Zq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) - sage: w = v.augmentation(x^2 + x + u, 1/2) sage: w.value_semigroup() Additive Abelian Semigroup generated by 1/2 - sage: ww = w.augmentation((x^2 + x + u)^2 + 2, 5/3) sage: ww.value_semigroup() Additive Abelian Semigroup generated by 1/2, 5/3 @@ -1706,14 +1707,13 @@ def valuations(self, f, coefficients=None, call_error=False): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) - sage: w = v.augmentation(x^2 + x + u, 1/2) sage: list(w.valuations( x^2 + 1 )) [0, 1/2] - sage: ww = w.augmentation((x^2 + x + u)^2 + 2, 5/3) sage: list(ww.valuations( ((x^2 + x + u)^2 + 2)^3 )) [+Infinity, +Infinity, +Infinity, 5] @@ -1774,6 +1774,7 @@ def simplify(self, f, error=None, force=False, effective_degree=None, size_heuri EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) @@ -1782,8 +1783,9 @@ def simplify(self, f, error=None, force=False, effective_degree=None, size_heuri (u + 1)*2^-1 + O(2^4) Check that :trac:`25607` has been resolved, i.e., the coefficients - in the following example are small::` + in the following example are small:: + sage: # needs sage.libs.ntl sage.rings.number_field sage: R. = QQ[] sage: K. = NumberField(x^3 + 6) sage: R. = K[] @@ -1796,7 +1798,11 @@ def simplify(self, f, error=None, force=False, effective_degree=None, size_heuri sage: v = F.valuation(v) sage: G = y^2 - 2*x^5 + 8*x^3 + 80*x^2 + 128*x + 192 sage: v.mac_lane_approximants(G) - [[ Gauss valuation induced by Valuation on rational function field induced by [ Gauss valuation induced by 2-adic valuation, v(x) = 3/2, v(x^2 + 8) = 13/4, v(x^4 + 16*x^2 + 32*x + 64) = 20/3 ], v(y + 4*x + 8) = 31/8 ]] + [[ Gauss valuation induced by + Valuation on rational function field induced by + [ Gauss valuation induced by 2-adic valuation, v(x) = 3/2, + v(x^2 + 8) = 13/4, v(x^4 + 16*x^2 + 32*x + 64) = 20/3 ], + v(y + 4*x + 8) = 31/8 ]] """ f = self.domain().coerce(f) @@ -1862,6 +1868,7 @@ def lower_bound(self, f): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) @@ -1904,6 +1911,7 @@ def upper_bound(self, f): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) @@ -2009,6 +2017,7 @@ def value_group(self): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) @@ -2026,6 +2035,7 @@ def value_semigroup(self): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Zq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) @@ -2061,6 +2071,7 @@ def valuations(self, f, coefficients=None, call_error=False): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) @@ -2104,6 +2115,7 @@ def simplify(self, f, error=None, force=False, effective_degree=None): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) @@ -2131,6 +2143,7 @@ def lower_bound(self, f): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) @@ -2150,6 +2163,7 @@ def upper_bound(self, f): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) diff --git a/src/sage/rings/valuation/developing_valuation.py b/src/sage/rings/valuation/developing_valuation.py index 3cfaa1147c3..d7724642415 100644 --- a/src/sage/rings/valuation/developing_valuation.py +++ b/src/sage/rings/valuation/developing_valuation.py @@ -68,7 +68,7 @@ class DevelopingValuation(DiscretePseudoValuation): TESTS:: - sage: TestSuite(v).run() # long time + sage: TestSuite(v).run() # long time # needs sage.geometry.polyhedron """ def __init__(self, parent, phi): @@ -102,9 +102,9 @@ def phi(self): EXAMPLES:: sage: R = Zp(2,5) - sage: S. = R[] - sage: v = GaussValuation(S) - sage: v.phi() + sage: S. = R[] # needs sage.libs.ntl + sage: v = GaussValuation(S) # needs sage.libs.ntl + sage: v.phi() # needs sage.libs.ntl (1 + O(2^5))*x """ @@ -124,6 +124,7 @@ def effective_degree(self, f, valuations=None): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R = Zp(2,5) sage: S. = R[] sage: v = GaussValuation(S) @@ -156,6 +157,7 @@ def _pow(self, f, e, error, effective_degree): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R = Zp(2,5) sage: S. = R[] sage: v = GaussValuation(S) @@ -189,11 +191,12 @@ def coefficients(self, f): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R = Qp(2,5) sage: S. = R[] sage: v = GaussValuation(S) sage: f = x^2 + 2*x + 3 - sage: list(v.coefficients(f)) # note that these constants are in the polynomial ring + sage: list(v.coefficients(f)) # note that these constants are in the polynomial ring [1 + 2 + O(2^5), 2 + O(2^6), 1 + O(2^5)] sage: v = v.augmentation( x^2 + x + 1, 1) sage: list(v.coefficients(f)) @@ -239,17 +242,17 @@ def newton_polygon(self, f, valuations=None): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R = Qp(2,5) sage: S. = R[] sage: v = GaussValuation(S) sage: f = x^2 + 2*x + 3 - sage: v.newton_polygon(f) + sage: v.newton_polygon(f) # needs sage.geometry.polyhedron Finite Newton polygon with 2 vertices: (0, 0), (2, 0) - sage: v = v.augmentation( x^2 + x + 1, 1) - sage: v.newton_polygon(f) + sage: v.newton_polygon(f) # needs sage.geometry.polyhedron Finite Newton polygon with 2 vertices: (0, 0), (1, 1) - sage: v.newton_polygon( f * v.phi()^3 ) + sage: v.newton_polygon( f * v.phi()^3 ) # needs sage.geometry.polyhedron Finite Newton polygon with 2 vertices: (3, 3), (4, 4) """ @@ -270,6 +273,7 @@ def _call_(self, f): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R = Qp(2,5) sage: S. = R[] sage: v = GaussValuation(S) @@ -277,6 +281,7 @@ def _call_(self, f): sage: v(f) 0 + sage: # needs sage.libs.ntl sage: v = v.augmentation( x^2 + x + 1, 1) sage: v(f) 0 @@ -315,6 +320,7 @@ def valuations(self, f): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R = Qp(2,5) sage: S. = R[] sage: v = GaussValuation(S, R.valuation()) @@ -331,9 +337,9 @@ def _test_effective_degree(self, **options): EXAMPLES:: sage: R = Zp(2,5) - sage: S. = R[] - sage: v = GaussValuation(S) - sage: v._test_effective_degree() + sage: S. = R[] # needs sage.libs.ntl + sage: v = GaussValuation(S) # needs sage.libs.ntl + sage: v._test_effective_degree() # needs sage.libs.ntl """ tester = self._tester(**options) S = tester.some_elements(self.domain().base_ring().some_elements()) diff --git a/src/sage/rings/valuation/gauss_valuation.py b/src/sage/rings/valuation/gauss_valuation.py index fce282aa0c7..759d2a4e03e 100644 --- a/src/sage/rings/valuation/gauss_valuation.py +++ b/src/sage/rings/valuation/gauss_valuation.py @@ -141,9 +141,9 @@ class GaussValuation_generic(NonFinalInductiveValuation): EXAMPLES:: sage: R = Zp(3,5) - sage: S. = R[] + sage: S. = R[] # needs sage.libs.ntl sage: v0 = R.valuation() - sage: v = GaussValuation(S, v0); v + sage: v = GaussValuation(S, v0); v # needs sage.libs.ntl Gauss valuation induced by 3-adic valuation sage: S. = QQ[] @@ -152,7 +152,7 @@ class GaussValuation_generic(NonFinalInductiveValuation): TESTS:: - sage: TestSuite(v).run() # long time + sage: TestSuite(v).run() # long time # needs sage.geometry.polyhedron """ def __init__(self, parent, v): @@ -295,9 +295,9 @@ def residue_ring(self): EXAMPLES:: - sage: S. = Qp(2,5)[] - sage: v = GaussValuation(S) - sage: v.residue_ring() + sage: S. = Qp(2,5)[] # needs sage.libs.ntl + sage: v = GaussValuation(S) # needs sage.libs.ntl + sage: v.residue_ring() # needs sage.libs.ntl Univariate Polynomial Ring in x over Finite Field of size 2 (using ...) """ @@ -329,6 +329,7 @@ def reduce(self, f, check=True, degree_bound=None, coefficients=None, valuations EXAMPLES:: + sage: # needs sage.libs.ntl sage: S. = Qp(2,5)[] sage: v = GaussValuation(S) sage: f = x^2 + 2*x + 16 @@ -339,8 +340,8 @@ def reduce(self, f, check=True, degree_bound=None, coefficients=None, valuations The reduction is only defined for integral elements:: - sage: f = x^2/2 - sage: v.reduce(f) + sage: f = x^2/2 # needs sage.libs.ntl + sage: v.reduce(f) # needs sage.libs.ntl Traceback (most recent call last): ... ValueError: reduction not defined for non-integral elements and (2^-1 + O(2^4))*x^2 is not integral over Gauss valuation induced by 2-adic valuation @@ -377,6 +378,7 @@ def lift(self, F): EXAMPLES:: + sage: # needs sage.libs.ntl sage: S. = Qp(3,5)[] sage: v = GaussValuation(S) sage: f = x^2 + 2*x + 16 @@ -449,6 +451,7 @@ def equivalence_unit(self, s, reciprocal=False): EXAMPLES:: + sage: # needs sage.libs.ntl sage: S. = Qp(3,5)[] sage: v = GaussValuation(S) sage: v.equivalence_unit(2) @@ -484,6 +487,7 @@ def E(self): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4,5) sage: S. = R[] sage: v = GaussValuation(S) @@ -501,6 +505,7 @@ def F(self): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4,5) sage: S. = R[] sage: v = GaussValuation(S) @@ -539,7 +544,7 @@ def extensions(self, ring): sage: v = ZZ.valuation(2) sage: R. = ZZ[] sage: w = GaussValuation(R, v) - sage: w.extensions(GaussianIntegers()['x']) + sage: w.extensions(GaussianIntegers()['x']) # needs sage.rings.number_field [Gauss valuation induced by 2-adic valuation] """ @@ -576,6 +581,7 @@ def is_gauss_valuation(self): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4,5) sage: S. = R[] sage: v = GaussValuation(S) @@ -592,6 +598,7 @@ def augmentation_chain(self): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4,5) sage: S. = R[] sage: v = GaussValuation(S) @@ -624,9 +631,9 @@ def monic_integral_model(self, G): EXAMPLES:: - sage: R. = Qp(2, 5)[] - sage: v = GaussValuation(R) - sage: v.monic_integral_model(5*x^2 + 1/2*x + 1/4) + sage: R. = Qp(2, 5)[] # needs sage.libs.ntl + sage: v = GaussValuation(R) # needs sage.libs.ntl + sage: v.monic_integral_model(5*x^2 + 1/2*x + 1/4) # needs sage.libs.ntl (Ring endomorphism of Univariate Polynomial Ring in x over 2-adic Field with capped relative precision 5 Defn: (1 + O(2^5))*x |--> (2^-1 + O(2^4))*x, Ring endomorphism of Univariate Polynomial Ring in x over 2-adic Field with capped relative precision 5 @@ -755,6 +762,7 @@ def simplify(self, f, error=None, force=False, size_heuristic_bound=32, effectiv EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) @@ -787,6 +795,7 @@ def lower_bound(self, f): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) @@ -815,6 +824,7 @@ def upper_bound(self, f): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) diff --git a/src/sage/rings/valuation/inductive_valuation.py b/src/sage/rings/valuation/inductive_valuation.py index 5da834ad018..1e3cb577416 100644 --- a/src/sage/rings/valuation/inductive_valuation.py +++ b/src/sage/rings/valuation/inductive_valuation.py @@ -56,7 +56,7 @@ class InductiveValuation(DevelopingValuation): TESTS:: - sage: TestSuite(v).run() # long time + sage: TestSuite(v).run() # long time # needs sage.geometry.polyhedron """ def is_equivalence_unit(self, f, valuations=None): @@ -71,6 +71,7 @@ def is_equivalence_unit(self, f, valuations=None): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R = Zp(2,5) sage: S. = R[] sage: v = GaussValuation(S) @@ -116,6 +117,7 @@ def equivalence_reciprocal(self, f, coefficients=None, valuations=None, check=Tr EXAMPLES:: + sage: # needs sage.libs.ntl sage: R = Zp(3,5) sage: S. = R[] sage: v = GaussValuation(S) @@ -127,6 +129,7 @@ def equivalence_reciprocal(self, f, coefficients=None, valuations=None, check=Tr In an extended valuation over an extension field:: + sage: # needs sage.libs.ntl sage: R. = Qq(4,5) sage: S. = R[] sage: v = GaussValuation(S) @@ -139,6 +142,7 @@ def equivalence_reciprocal(self, f, coefficients=None, valuations=None, check=Tr Extending the valuation once more:: + sage: # needs sage.libs.ntl sage: v = v.augmentation((x^2 + x + u)^2 + 2*x*(x^2 + x + u) + 4*x, 3) sage: h = v.equivalence_reciprocal(f); h (u + 1) + O(2^5) @@ -149,6 +153,7 @@ def equivalence_reciprocal(self, f, coefficients=None, valuations=None, check=Tr A case that caused problems at some point:: + sage: # needs sage.libs.ntl sage: K = Qp(2, 4) sage: R. = K[] sage: L. = K.extension(x^4 + 4*x^3 + 6*x^2 + 4*x + 2) @@ -239,6 +244,7 @@ def equivalence_unit(self, s, reciprocal=False): EXAMPLES:: + sage: # needs sage.libs.ntl sage: S. = Qp(3,5)[] sage: v = GaussValuation(S) sage: v.equivalence_unit(2) @@ -257,7 +263,8 @@ def equivalence_unit(self, s, reciprocal=False): sage: w.equivalence_unit(-1) Traceback (most recent call last): ... - ValueError: s must be in the value semigroup of this valuation but -1 is not in Additive Abelian Semigroup generated by 1 + ValueError: s must be in the value semigroup of this valuation + but -1 is not in Additive Abelian Semigroup generated by 1 """ @@ -269,6 +276,7 @@ def augmentation_chain(self): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4,5) sage: S. = R[] sage: v = GaussValuation(S) @@ -284,6 +292,7 @@ def is_gauss_valuation(self): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4,5) sage: S. = R[] sage: v = GaussValuation(S) @@ -300,6 +309,7 @@ def E(self): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4,5) sage: S. = R[] sage: v = GaussValuation(S) @@ -315,6 +325,7 @@ def F(self): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4,5) sage: S. = R[] sage: v = GaussValuation(S) @@ -339,7 +350,7 @@ def monic_integral_model(self, G): Defn: x |--> 1/2*x, Ring endomorphism of Univariate Polynomial Ring in x over Rational Field Defn: x |--> 2*x, - x^2 + 1/5*x + 1/5) + x^2 + 1/5*x + 1/5) """ @@ -363,7 +374,8 @@ def element_with_valuation(self, s): sage: v.element_with_valuation(-2) Traceback (most recent call last): ... - ValueError: s must be in the value semigroup of this valuation but -2 is not in Additive Abelian Semigroup generated by 1 + ValueError: s must be in the value semigroup of this valuation + but -2 is not in Additive Abelian Semigroup generated by 1 """ @@ -404,6 +416,7 @@ def _test_EF(self, **options): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4,5) sage: S. = R[] sage: v = GaussValuation(S) @@ -589,6 +602,7 @@ class NonFinalInductiveValuation(FiniteInductiveValuation, DiscreteValuation): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4,5) sage: S. = R[] sage: v = GaussValuation(S) @@ -599,6 +613,7 @@ def __init__(self, parent, phi): r""" TESTS:: + sage: # needs sage.libs.ntl sage: R. = Qq(4,5) sage: S. = R[] sage: v = GaussValuation(S) @@ -630,6 +645,7 @@ def augmentation(self, phi, mu, check=True): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4,5) sage: S. = R[] sage: v = GaussValuation(S) @@ -638,7 +654,11 @@ def augmentation(self, phi, mu, check=True): sage: v [ Gauss valuation induced by 2-adic valuation, v((1 + O(2^5))*x^2 + (1 + O(2^5))*x + u + O(2^5)) = 1, - v((1 + O(2^5))*x^4 + (2^2 + O(2^6))*x^3 + (1 + (u + 1)*2 + O(2^5))*x^2 + ((u + 1)*2^2 + O(2^6))*x + (u + 1) + (u + 1)*2 + (u + 1)*2^2 + (u + 1)*2^3 + (u + 1)*2^4 + O(2^5)) = 3 ] + v((1 + O(2^5))*x^4 + + (2^2 + O(2^6))*x^3 + + (1 + (u + 1)*2 + O(2^5))*x^2 + + ((u + 1)*2^2 + O(2^6))*x + + (u + 1) + (u + 1)*2 + (u + 1)*2^2 + (u + 1)*2^3 + (u + 1)*2^4 + O(2^5)) = 3 ] TESTS: @@ -710,7 +730,7 @@ def mac_lane_step(self, G, principal_part_bound=None, assume_squarefree=False, a sage: R. = QQ[] sage: v = QQ.valuation(2) sage: f = x^36 + 1160/81*x^31 + 9920/27*x^30 + 1040/81*x^26 + 52480/81*x^25 + 220160/81*x^24 - 5120/81*x^21 - 143360/81*x^20 - 573440/81*x^19 + 12451840/81*x^18 - 266240/567*x^16 - 20316160/567*x^15 - 198737920/189*x^14 - 1129840640/81*x^13 - 1907359744/27*x^12 + 8192/81*x^11 + 655360/81*x^10 + 5242880/21*x^9 + 2118123520/567*x^8 + 15460204544/567*x^7 + 6509559808/81*x^6 - 16777216/567*x^2 - 268435456/567*x - 1073741824/567 - sage: v.mac_lane_approximants(f) + sage: v.mac_lane_approximants(f) # needs sage.geometry.polyhedron [[ Gauss valuation induced by 2-adic valuation, v(x + 2056) = 23/2 ], [ Gauss valuation induced by 2-adic valuation, v(x) = 11/9 ], [ Gauss valuation induced by 2-adic valuation, v(x) = 2/5, v(x^5 + 4) = 7/2 ], @@ -721,7 +741,7 @@ def mac_lane_step(self, G, principal_part_bound=None, assume_squarefree=False, a some linear key polynomials in the above example:: sage: v0 = GaussValuation(R, v) - sage: V1 = sorted(v0.mac_lane_step(f)); V1 + sage: V1 = sorted(v0.mac_lane_step(f)); V1 # needs sage.geometry.polyhedron [[ Gauss valuation induced by 2-adic valuation, v(x) = 2/5 ], [ Gauss valuation induced by 2-adic valuation, v(x) = 3/5 ], [ Gauss valuation induced by 2-adic valuation, v(x) = 11/9 ], @@ -731,7 +751,7 @@ def mac_lane_step(self, G, principal_part_bound=None, assume_squarefree=False, a step on each of these branches, note however, that a direct call to this method might produce some unexpected results:: - sage: V1[1].mac_lane_step(f) + sage: V1[1].mac_lane_step(f) # needs sage.geometry.polyhedron [[ Gauss valuation induced by 2-adic valuation, v(x) = 3/5, v(x^5 + 8) = 5 ], [ Gauss valuation induced by 2-adic valuation, v(x) = 3/5, v(x^10 + 8*x^5 + 64) = 7 ], [ Gauss valuation induced by 2-adic valuation, v(x) = 3 ], @@ -742,7 +762,7 @@ def mac_lane_step(self, G, principal_part_bound=None, assume_squarefree=False, a greater than ``V1[1]``. To ignore such trivial augmentations, we can set ``allow_equivalent_key``:: - sage: V1[1].mac_lane_step(f, allow_equivalent_key=False) + sage: V1[1].mac_lane_step(f, allow_equivalent_key=False) # needs sage.geometry.polyhedron [[ Gauss valuation induced by 2-adic valuation, v(x) = 3/5, v(x^5 + 8) = 5 ], [ Gauss valuation induced by 2-adic valuation, v(x) = 3/5, v(x^10 + 8*x^5 + 64) = 7 ]] @@ -755,9 +775,9 @@ def mac_lane_step(self, G, principal_part_bound=None, assume_squarefree=False, a sage: v1 = v0.augmentation(K._ring.gen(), 1/3) sage: mu0 = K.valuation(v1) sage: eta0 = GaussValuation(S, mu0) - sage: eta1 = eta0.mac_lane_step(F)[0] - sage: eta2 = eta1.mac_lane_step(F)[0] - sage: eta2 + sage: eta1 = eta0.mac_lane_step(F)[0] # needs sage.geometry.polyhedron + sage: eta2 = eta1.mac_lane_step(F)[0] # needs sage.geometry.polyhedron + sage: eta2 # needs sage.geometry.polyhedron [ Gauss valuation induced by Valuation on rational function field induced by [ Gauss valuation induced by 3-adic valuation, v(x) = 1/3 ], v(y + x) = 2/3 ] Check that :trac:`26066` has been resolved:: @@ -766,7 +786,7 @@ def mac_lane_step(self, G, principal_part_bound=None, assume_squarefree=False, a sage: v = QQ.valuation(2) sage: v = GaussValuation(R, v).augmentation(x+1, 1/2) sage: f = x^4 - 30*x^2 - 75 - sage: v.mac_lane_step(f) + sage: v.mac_lane_step(f) # needs sage.geometry.polyhedron [[ Gauss valuation induced by 2-adic valuation, v(x + 1) = 3/4 ]] """ @@ -931,16 +951,16 @@ def is_key(self, phi, explain=False, assume_equivalence_irreducible=False): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) sage: v.is_key(x) True - sage: v.is_key(2*x, explain = True) + sage: v.is_key(2*x, explain=True) (False, 'phi must be monic') - sage: v.is_key(x^2, explain = True) + sage: v.is_key(x^2, explain=True) (False, 'phi must be equivalence irreducible') - sage: w = v.augmentation(x, 1) sage: w.is_key(x + 1, explain = True) (False, 'phi must be minimal') @@ -980,6 +1000,7 @@ def is_minimal(self, f, assume_equivalence_irreducible=False): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4, 5) sage: S. = R[] sage: v = GaussValuation(S) @@ -991,6 +1012,7 @@ def is_minimal(self, f, assume_equivalence_irreducible=False): TESTS:: + sage: # needs sage.libs.ntl sage: K = Qp(2, 10) sage: R. = K[] sage: vp = K.valuation() @@ -1003,9 +1025,9 @@ def is_minimal(self, f, assume_equivalence_irreducible=False): Polynomials which are equivalent to the key polynomial are minimal if and only if they have the same degree as the key polynomial:: - sage: v2.is_minimal(x^4 + 2) + sage: v2.is_minimal(x^4 + 2) # needs sage.libs.ntl True - sage: v2.is_minimal(x^4 + 4) + sage: v2.is_minimal(x^4 + 4) # needs sage.libs.ntl False """ @@ -1129,6 +1151,7 @@ def is_equivalence_irreducible(self, f, coefficients=None, valuations=None): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4,5) sage: S. = R[] sage: v = GaussValuation(S) @@ -1199,6 +1222,7 @@ def equivalence_decomposition(self, f, assume_not_equivalence_unit=False, coeffi EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4,10) sage: S. = R[] sage: v = GaussValuation(S) @@ -1217,26 +1241,26 @@ def equivalence_decomposition(self, f, assume_not_equivalence_unit=False, coeffi of a :class:`~sage.structure.factorization.Factorization`, leading to a unit non-minimal degree:: - sage: w = v.augmentation(x, 1) - sage: F = w.equivalence_decomposition(x^2+1); F + sage: w = v.augmentation(x, 1) # needs sage.libs.ntl + sage: F = w.equivalence_decomposition(x^2+1); F # needs sage.libs.ntl (1 + O(2^10))*x^2 + 1 + O(2^10) - sage: F.unit() + sage: F.unit() # needs sage.libs.ntl (1 + O(2^10))*x^2 + 1 + O(2^10) However, if the polynomial has a non-unit factor, then the unit might be replaced by a factor of lower degree:: - sage: f = x * (x^2 + 1) - sage: F = w.equivalence_decomposition(f); F + sage: f = x * (x^2 + 1) # needs sage.libs.ntl + sage: F = w.equivalence_decomposition(f); F # needs sage.libs.ntl (1 + O(2^10))*x - sage: F.unit() + sage: F.unit() # needs sage.libs.ntl 1 + O(2^10) Examples over an iterated unramified extension:: + sage: # needs sage.libs.ntl sage: v = v.augmentation(x^2 + x + u, 1) sage: v = v.augmentation((x^2 + x + u)^2 + 2*x*(x^2 + x + u) + 4*x, 3) - sage: v.equivalence_decomposition(x) (1 + O(2^10))*x sage: F = v.equivalence_decomposition( v.phi() ) @@ -1248,14 +1272,15 @@ def equivalence_decomposition(self, f, assume_not_equivalence_unit=False, coeffi TESTS:: + sage: # needs sage.geometry.polyhedron sage.groups sage.rings.number_field sage: R. = QQ[] - sage: K1.=NumberField(x^3 - 2) - sage: K.=K1.galois_closure() - sage: R.=K[] + sage: K1. = NumberField(x^3 - 2) + sage: K. = K1.galois_closure() + sage: R. = K[] sage: vp = QQ.valuation(2) sage: vp = vp.extension(K) sage: v0 = GaussValuation(R, vp) - sage: G=x^36 + 36*x^35 + 630*x^34 + 7144*x^33 + 59055*x^32 + 379688*x^31 +1978792*x^30 + 8604440*x^29 + 31895428*x^28 + 102487784*x^27 + 289310720*x^26 + 725361352*x^25 + 1629938380*x^24 + 3307417800*x^23 + 6098786184*x^22+10273444280*x^21 + 15878121214*x^20 + 22596599536*x^19 + 29695703772*x^18 +36117601976*x^17 + 40722105266*x^16 + 42608585080*x^15 + 41395961848*x^14 +37344435656*x^13 + 31267160756*x^12 + 24271543640*x^11 + 17439809008*x^10 + 11571651608*x^9 + 7066815164*x^8 + 3953912472*x^7 + 2013737432*x^6 + 925014888*x^5 + 378067657*x^4 + 134716588*x^3 + 40441790*x^2 + 9532544*x + 1584151 + sage: G = x^36 + 36*x^35 + 630*x^34 + 7144*x^33 + 59055*x^32 + 379688*x^31 +1978792*x^30 + 8604440*x^29 + 31895428*x^28 + 102487784*x^27 + 289310720*x^26 + 725361352*x^25 + 1629938380*x^24 + 3307417800*x^23 + 6098786184*x^22+10273444280*x^21 + 15878121214*x^20 + 22596599536*x^19 + 29695703772*x^18 +36117601976*x^17 + 40722105266*x^16 + 42608585080*x^15 + 41395961848*x^14 +37344435656*x^13 + 31267160756*x^12 + 24271543640*x^11 + 17439809008*x^10 + 11571651608*x^9 + 7066815164*x^8 + 3953912472*x^7 + 2013737432*x^6 + 925014888*x^5 + 378067657*x^4 + 134716588*x^3 + 40441790*x^2 + 9532544*x + 1584151 sage: v1 = v0.mac_lane_step(G)[0] sage: V = v1.mac_lane_step(G) sage: v2 = V[0] @@ -1362,12 +1387,14 @@ def minimal_representative(self, f): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4,10) sage: S. = R[] sage: v = GaussValuation(S) sage: v.minimal_representative(x + 2) (1 + O(2^10))*x + sage: # needs sage.libs.ntl sage: v = v.augmentation(x, 1) sage: v.minimal_representative(x + 2) (1 + O(2^10))*x + 2 + O(2^11) @@ -1440,6 +1467,7 @@ def lift_to_key(self, F): EXAMPLES:: + sage: # needs sage.libs.ntl sage: R. = Qq(4,10) sage: S. = R[] sage: v = GaussValuation(S) @@ -1550,7 +1578,7 @@ def _test_lift_to_key(self, **options): sage: R. = QQ[] sage: v = GaussValuation(R, valuations.TrivialValuation(QQ)) - sage: v._test_lift_to_key() + sage: v._test_lift_to_key() # needs sage.rings.number_field """ tester = self._tester(**options) diff --git a/src/sage/rings/valuation/limit_valuation.py b/src/sage/rings/valuation/limit_valuation.py index 6aae23d9cfa..fa23e2c0a69 100644 --- a/src/sage/rings/valuation/limit_valuation.py +++ b/src/sage/rings/valuation/limit_valuation.py @@ -30,10 +30,10 @@ point has two extensions to ``L``. The valuations corresponding to these extensions can only be approximated:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) - sage: v = K.valuation(1) sage: w = v.extensions(L); w [[ (x - 1)-adic valuation, v(y + 1) = 1 ]-adic valuation, @@ -41,6 +41,7 @@ The same phenomenon can be observed for valuations on number fields:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) @@ -55,16 +56,17 @@ valuation without using a limit. This is done to improve performance as many computations already can be done correctly with an approximation:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) - sage: v = K.valuation(1/x) sage: w = v.extension(L); w Valuation at the infinite place sage: w._base_valuation._base_valuation._improve_approximation() sage: w._base_valuation._base_valuation._approximation - [ Gauss valuation induced by Valuation at the infinite place, v(y) = 1/2, v(y^2 - 1/x) = +Infinity ] + [ Gauss valuation induced by Valuation at the infinite place, + v(y) = 1/2, v(y^2 - 1/x) = +Infinity ] REFERENCES: @@ -119,7 +121,7 @@ def create_key(self, base_valuation, G): sage: R. = QQ[] sage: v = GaussValuation(R, QQ.valuation(2)) - sage: w = valuations.LimitValuation(v, x) # indirect doctest + sage: w = valuations.LimitValuation(v, x) # indirect doctest sage: v = v.augmentation(x, infinity) sage: u = valuations.LimitValuation(v, x) sage: u == w @@ -142,7 +144,7 @@ def create_object(self, version, key): sage: R. = QQ[] sage: v = GaussValuation(R, QQ.valuation(2)) - sage: w = valuations.LimitValuation(v, x^2 + 1) # indirect doctest + sage: w = valuations.LimitValuation(v, x^2 + 1) # indirect doctest """ base_valuation, G = key @@ -163,10 +165,10 @@ class LimitValuation_generic(DiscretePseudoValuation): EXAMPLES:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) - sage: v = K.valuation(0) sage: w = v.extension(L) sage: w._base_valuation @@ -175,21 +177,22 @@ class LimitValuation_generic(DiscretePseudoValuation): The currently used approximation can be found in the ``_approximation`` field:: - sage: w._base_valuation._approximation + sage: w._base_valuation._approximation # needs sage.rings.function_field [ Gauss valuation induced by (x)-adic valuation, v(y) = 1/2 ] TESTS:: sage: from sage.rings.valuation.limit_valuation import LimitValuation_generic - sage: isinstance(w._base_valuation, LimitValuation_generic) + sage: isinstance(w._base_valuation, LimitValuation_generic) # needs sage.rings.function_field True - sage: TestSuite(w._base_valuation).run() # long time + sage: TestSuite(w._base_valuation).run() # long time # needs sage.rings.function_field """ def __init__(self, parent, approximation): r""" TESTS:: + sage: # needs sage.rings.number_field sage: R. = QQ[] sage: K. = QQ.extension(x^2 + 1) sage: v = K.valuation(2) @@ -217,13 +220,13 @@ def reduce(self, f, check=True): EXAMPLES:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - (x - 1)) - sage: v = K.valuation(0) sage: w = v.extension(L) - sage: w.reduce(y) # indirect doctest + sage: w.reduce(y) # indirect doctest u1 """ @@ -238,13 +241,13 @@ def _call_(self, f): EXAMPLES:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) - sage: v = K.valuation(0) sage: w = v.extension(L) - sage: w(y) # indirect doctest + sage: w(y) # indirect doctest 1/2 """ @@ -259,6 +262,7 @@ def _improve_approximation_for_reduce(self, f): EXAMPLES:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - (x - 1337)) @@ -266,6 +270,7 @@ def _improve_approximation_for_reduce(self, f): For the unique extension over the place at 1337, the initial approximation is sufficient to compute the reduction of ``y``:: + sage: # needs sage.rings.function_field sage: v = K.valuation(1337) sage: w = v.extension(L) sage: u = w._base_valuation @@ -279,19 +284,21 @@ def _improve_approximation_for_reduce(self, f): However, at a place over 1341, the initial approximation is not sufficient for some values (note that 1341-1337 is a square):: + sage: # needs sage.rings.function_field sage: v = K.valuation(1341) sage: w = v.extensions(L)[1] sage: u = w._base_valuation sage: u._approximation [ Gauss valuation induced by (x - 1341)-adic valuation, v(y - 2) = 1 ] - sage: w.reduce((y - 2) / (x - 1341)) # indirect doctest + sage: w.reduce((y - 2) / (x - 1341)) # indirect doctest 1/4 sage: u._approximation [ Gauss valuation induced by (x - 1341)-adic valuation, v(y - 1/4*x + 1333/4) = 2 ] - sage: w.reduce((y - 1/4*x + 1333/4) / (x - 1341)^2) # indirect doctest + sage: w.reduce((y - 1/4*x + 1333/4) / (x - 1341)^2) # indirect doctest -1/64 sage: u._approximation - [ Gauss valuation induced by (x - 1341)-adic valuation, v(y + 1/64*x^2 - 1349/32*x + 1819609/64) = 3 ] + [ Gauss valuation induced by (x - 1341)-adic valuation, + v(y + 1/64*x^2 - 1349/32*x + 1819609/64) = 3 ] """ @@ -303,6 +310,7 @@ def _improve_approximation_for_call(self, f): EXAMPLES:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - (x - 23)) @@ -310,6 +318,7 @@ def _improve_approximation_for_call(self, f): For the unique extension over the place at 23, the initial approximation is sufficient to compute all valuations:: + sage: # needs sage.rings.function_field sage: v = K.valuation(23) sage: w = v.extension(L) sage: u = w._base_valuation @@ -325,7 +334,8 @@ def _improve_approximation_for_call(self, f): improvement step is faster in this case than checking whether the approximation is sufficient):: - sage: w(y) # indirect doctest + sage: # needs sage.rings.function_field + sage: w(y) # indirect doctest 1/2 sage: u._approximation [ Gauss valuation induced by (x - 23)-adic valuation, v(y) = 1/2, v(y^2 - x + 23) = +Infinity ] @@ -338,6 +348,7 @@ def _repr_(self): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) @@ -369,9 +380,9 @@ class MacLaneLimitValuation(LimitValuation_generic, InfiniteDiscretePseudoValuat EXAMPLES:: + sage: # needs sage.rings.number_field sage: R. = QQ[] sage: K. = QQ.extension(x^2 + 1) - sage: v = K.valuation(2) sage: u = v._base_valuation; u [ Gauss valuation induced by 2-adic valuation, v(x + 1) = 1/2 , … ] @@ -381,6 +392,7 @@ def __init__(self, parent, approximation, G): r""" TESTS:: + sage: # needs sage.rings.number_field sage: R. = QQ[] sage: K. = QQ.extension(x^2 + 1) sage: v = K.valuation(2) @@ -403,6 +415,7 @@ def extensions(self, ring): EXAMPLES:: + sage: # needs sage.rings.number_field sage: v = GaussianIntegers().valuation(2) sage: u = v._base_valuation sage: u.extensions(QQ['x']) @@ -429,16 +442,16 @@ def lift(self, F): EXAMPLES:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^4 - x^2 - 2*x - 1) - sage: v = K.valuation(1) sage: w = v.extensions(L)[1]; w [ (x - 1)-adic valuation, v(y^2 - 2) = 1 ]-adic valuation sage: s = w.reduce(y); s u1 - sage: w.lift(s) # indirect doctest + sage: w.lift(s) # indirect doctest y """ @@ -451,13 +464,13 @@ def uniformizer(self): EXAMPLES:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) - sage: v = K.valuation(0) sage: w = v.extension(L) - sage: w.uniformizer() # indirect doctest + sage: w.uniformizer() # indirect doctest y """ @@ -469,20 +482,18 @@ def _call_(self, f): EXAMPLES:: + sage: # needs sage.geometry.polyhedron sage: K = QQ sage: R. = K[] sage: vK = K.valuation(2) sage: f = (x^2 + 7) * (x^2 + 9) sage: V = vK.mac_lane_approximants(f, require_incomparability=True) - sage: w = valuations.LimitValuation(V[0], f) sage: w((x^2 + 7) * (x + 3)) 3/2 - sage: w = valuations.LimitValuation(V[1], f) sage: w((x^2 + 7) * (x + 3)) +Infinity - sage: w = valuations.LimitValuation(V[2], f) sage: w((x^2 + 7) * (x + 3)) +Infinity @@ -500,6 +511,7 @@ def _improve_approximation(self): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) @@ -515,8 +527,8 @@ def _improve_approximation(self): This method has no effect, if the approximation is already an infinite valuation:: - sage: u._improve_approximation() - sage: u._approximation + sage: u._improve_approximation() # needs sage.rings.number_field + sage: u._approximation # needs sage.rings.number_field [ Gauss valuation induced by 2-adic valuation, v(t + 1) = 1/2, v(t^2 + 1) = +Infinity ] """ @@ -547,6 +559,7 @@ def _improve_approximation_for_call(self, f): approximation (perform one step of the Mac Lane algorithm) than to check for this:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) @@ -624,6 +637,7 @@ def _improve_approximation_for_reduce(self, f): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) @@ -653,6 +667,7 @@ def residue_ring(self): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) @@ -679,6 +694,7 @@ def _ge_(self, other): EXAMPLES:: + sage: # needs sage.geometry.polyhedron sage: R. = QQ[] sage: F = (x^2 + 7) * (x^2 + 9) sage: G = (x^2 + 7) @@ -722,6 +738,7 @@ def restriction(self, ring): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) @@ -744,6 +761,7 @@ def _weakly_separating_element(self, other): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) @@ -751,11 +769,12 @@ def _weakly_separating_element(self, other): sage: w = v.extension(L) sage: v = QQ.valuation(5) sage: u,uu = v.extensions(L) - sage: w._base_valuation._weakly_separating_element(u._base_valuation) # long time + sage: w._base_valuation._weakly_separating_element(u._base_valuation) # long time 2 - sage: u._base_valuation._weakly_separating_element(uu._base_valuation) # long time + sage: u._base_valuation._weakly_separating_element(uu._base_valuation) # long time t + 2 + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: v = K.valuation(1/x) sage: R. = K[] @@ -765,14 +784,14 @@ def _weakly_separating_element(self, other): sage: w,ww = v.extensions(L) sage: v = K.valuation(1) sage: v = v.extension(L) - sage: u.separating_element([uu,ww,w,v]) # long time, random output + sage: u.separating_element([uu,ww,w,v]) # random output # long time ((8*x^4 + 12*x^2 + 4)/(x^2 - x))*y + (8*x^4 + 8*x^2 + 1)/(x^3 - x^2) The underlying algorithm is quite naive and might not terminate in reasonable time. In particular, the order of the arguments sometimes has a huge impact on the runtime:: - sage: u.separating_element([ww,w,v,uu]) # not tested, takes forever + sage: u.separating_element([ww,w,v,uu]) # not tested, takes forever """ from .scaled_valuation import ScaledValuation_generic @@ -800,6 +819,7 @@ def value_semigroup(self): TESTS:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) @@ -817,6 +837,7 @@ def element_with_valuation(self, s): TESTS:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) @@ -842,6 +863,7 @@ def _relative_size(self, f): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) @@ -863,6 +885,7 @@ def simplify(self, f, error=None, force=False): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) @@ -892,6 +915,7 @@ def lower_bound(self, f): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) @@ -915,6 +939,7 @@ def upper_bound(self, f): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) @@ -939,6 +964,7 @@ def is_negative_pseudo_valuation(self): For a Mac Lane limit valuation, this is never the case, so this method always returns ``False``:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) diff --git a/src/sage/rings/valuation/mapped_valuation.py b/src/sage/rings/valuation/mapped_valuation.py index 1aab2ff34b8..d5b3248ef1d 100644 --- a/src/sage/rings/valuation/mapped_valuation.py +++ b/src/sage/rings/valuation/mapped_valuation.py @@ -7,15 +7,16 @@ Extensions of valuations over finite field extensions `L=K[x]/(G)` are realized through an infinite valuation on `K[x]` which maps `G` to infinity:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) - sage: v = K.valuation(0) - sage: w = v.extension(L); w + sage: v = K.valuation(0) # needs sage.rings.function_field + sage: w = v.extension(L); w # needs sage.rings.function_field (x)-adic valuation - sage: w._base_valuation + sage: w._base_valuation # needs sage.rings.function_field [ Gauss valuation induced by (x)-adic valuation, v(y) = 1/2 , … ] AUTHORS: @@ -42,17 +43,17 @@ class MappedValuation_base(DiscretePseudoValuation): EXAMPLES:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) - sage: v = K.valuation(0) sage: w = v.extension(L); w (x)-adic valuation TESTS:: - sage: TestSuite(w).run() # long time + sage: TestSuite(w).run() # long time # needs sage.rings.function_field """ def __init__(self, parent, base_valuation): @@ -67,10 +68,10 @@ def __init__(self, parent, base_valuation): TESTS:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x^2 + 1) - sage: v = K.valuation(0) sage: w = v.extension(L); w (x)-adic valuation @@ -94,9 +95,9 @@ def _repr_(self): sage: K = QQ sage: R. = K[] - sage: L. = K.extension(t^2 + 1) + sage: L. = K.extension(t^2 + 1) # needs sage.rings.number_field sage: v = valuations.pAdicValuation(QQ, 2) - sage: v.extension(L) # indirect doctest + sage: v.extension(L) # indirect doctest # needs sage.rings.number_field 2-adic valuation """ @@ -109,9 +110,9 @@ def residue_ring(self): sage: K = QQ sage: R. = K[] - sage: L. = K.extension(t^2 + 1) + sage: L. = K.extension(t^2 + 1) # needs sage.rings.number_field sage: v = valuations.pAdicValuation(QQ, 2) - sage: v.extension(L).residue_ring() + sage: v.extension(L).residue_ring() # needs sage.rings.number_field Finite Field of size 2 """ @@ -125,9 +126,9 @@ def uniformizer(self): sage: K = QQ sage: R. = K[] - sage: L. = K.extension(t^2 + 1) + sage: L. = K.extension(t^2 + 1) # needs sage.rings.number_field sage: v = valuations.pAdicValuation(QQ, 2) - sage: v.extension(L).uniformizer() + sage: v.extension(L).uniformizer() # needs sage.rings.number_field t + 1 """ @@ -139,10 +140,10 @@ def _to_base_domain(self, f): EXAMPLES:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) - sage: v = K.valuation(0) sage: w = v.extensions(L)[0] sage: w._to_base_domain(y).parent() @@ -157,10 +158,10 @@ def _from_base_domain(self, f): EXAMPLES:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) - sage: v = K.valuation(0) sage: w = v.extension(L) sage: w._from_base_domain(w._base_valuation.domain().gen()).parent() @@ -175,13 +176,13 @@ def _call_(self, f): EXAMPLES:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) - sage: v = K.valuation(0) sage: w = v.extension(L) - sage: w(y) # indirect doctest + sage: w(y) # indirect doctest 1/2 """ @@ -193,10 +194,10 @@ def reduce(self, f): EXAMPLES:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - (x - 2)) - sage: v = K.valuation(0) sage: w = v.extension(L) sage: w.reduce(y) @@ -212,10 +213,10 @@ def lift(self, F): EXAMPLES:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) - sage: v = K.valuation(2) sage: w = v.extension(L) sage: w.lift(w.residue_field().gen()) @@ -239,24 +240,24 @@ def simplify(self, x, error=None, force=False): EXAMPLES:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) - sage: v = K.valuation(0) sage: w = v.extensions(L)[0] As :meth:`_relative_size` misses the bloated term ``x^32``, the following term does not get simplified:: - sage: w.simplify(y + x^32) + sage: w.simplify(y + x^32) # needs sage.rings.function_field y + x^32 In this case the simplification can be forced but this should not happen as a default as the recursive simplification can be quite costly:: - sage: w.simplify(y + x^32, force=True) + sage: w.simplify(y + x^32, force=True) # needs sage.rings.function_field y """ @@ -276,6 +277,7 @@ def _relative_size(self, x): EXAMPLES:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) @@ -285,7 +287,7 @@ def _relative_size(self, x): In this example, the method misses the size of the bloated term ``x^32``:: - sage: w._relative_size(y + x^32) + sage: w._relative_size(y + x^32) # needs sage.rings.function_field 1 """ @@ -298,10 +300,10 @@ def _to_base_residue_ring(self, F): EXAMPLES:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) - sage: v = K.valuation(0) sage: w = v.extensions(L)[0] sage: w._to_base_residue_ring(1) @@ -317,10 +319,10 @@ def _from_base_residue_ring(self, F): EXAMPLES:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) - sage: v = K.valuation(0) sage: w = v.extensions(L)[0] sage: w._from_base_residue_ring(1) @@ -335,6 +337,7 @@ def element_with_valuation(self, s): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) @@ -353,10 +356,10 @@ def _test_to_from_base_domain(self, **options): EXAMPLES:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) - sage: v = K.valuation(0) sage: w = v.extensions(L)[0] sage: w._test_to_from_base_domain() @@ -375,10 +378,10 @@ def _test_to_from_base_residue_ring(self, **options): EXAMPLES:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) - sage: v = K.valuation(0) sage: w = v.extensions(L)[0] sage: w._test_to_from_base_residue_ring() @@ -408,10 +411,10 @@ class FiniteExtensionFromInfiniteValuation(MappedValuation_base, DiscreteValuati EXAMPLES:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) - sage: v = K.valuation(0) sage: w = v.extension(L); w (x)-adic valuation @@ -421,16 +424,16 @@ def __init__(self, parent, base_valuation): r""" TESTS:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) - sage: v = K.valuation(0) sage: w = v.extension(L) sage: from sage.rings.valuation.mapped_valuation import FiniteExtensionFromInfiniteValuation sage: isinstance(w, FiniteExtensionFromInfiniteValuation) True - sage: TestSuite(w).run() # long time + sage: TestSuite(w).run() # long time """ MappedValuation_base.__init__(self, parent, base_valuation) @@ -442,6 +445,7 @@ def _eq_(self, other): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) @@ -461,6 +465,7 @@ def restriction(self, ring): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) @@ -483,6 +488,7 @@ def _weakly_separating_element(self, other): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) @@ -512,6 +518,7 @@ def _relative_size(self, x): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) @@ -533,6 +540,7 @@ def simplify(self, x, error=None, force=False): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) @@ -559,6 +567,7 @@ def lower_bound(self, x): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) @@ -582,6 +591,7 @@ def upper_bound(self, x): EXAMPLES:: + sage: # needs sage.rings.number_field sage: K = QQ sage: R. = K[] sage: L. = K.extension(t^2 + 1) @@ -604,6 +614,7 @@ class FiniteExtensionFromLimitValuation(FiniteExtensionFromInfiniteValuation): EXAMPLES:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) @@ -614,8 +625,8 @@ class FiniteExtensionFromLimitValuation(FiniteExtensionFromInfiniteValuation): TESTS:: - sage: TestSuite(w[0]).run() # long time - sage: TestSuite(w[1]).run() # long time + sage: TestSuite(w[0]).run() # long time # needs sage.rings.function_field + sage: TestSuite(w[1]).run() # long time # needs sage.rings.function_field """ def __init__(self, parent, approximant, G, approximants): @@ -625,6 +636,7 @@ def __init__(self, parent, approximant, G, approximants): Note that this implementation is also used when the underlying limit is only taken over a finite sequence of valuations:: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) @@ -650,7 +662,7 @@ def _repr_(self): EXAMPLES:: - sage: valuations.pAdicValuation(GaussianIntegers().fraction_field(), 2) # indirect doctest + sage: valuations.pAdicValuation(GaussianIntegers().fraction_field(), 2) # indirect doctest # needs sage.rings.number_field 2-adic valuation """ diff --git a/src/sage/rings/valuation/scaled_valuation.py b/src/sage/rings/valuation/scaled_valuation.py index 31e06ddb483..84249392e3a 100644 --- a/src/sage/rings/valuation/scaled_valuation.py +++ b/src/sage/rings/valuation/scaled_valuation.py @@ -98,7 +98,7 @@ class ScaledValuation_generic(DiscreteValuation): TESTS:: - sage: TestSuite(v).run() # long time + sage: TestSuite(v).run() # long time # needs sage.geometry.polyhedron """ def __init__(self, parent, base_valuation, s): @@ -208,7 +208,7 @@ def extensions(self, ring): EXAMPLES:: sage: v = 3*ZZ.valuation(5) - sage: v.extensions(GaussianIntegers().fraction_field()) + sage: v.extensions(GaussianIntegers().fraction_field()) # needs sage.rings.number_field [3 * [ 5-adic valuation, v(x + 2) = 1 ]-adic valuation, 3 * [ 5-adic valuation, v(x + 3) = 1 ]-adic valuation] diff --git a/src/sage/rings/valuation/valuation.py b/src/sage/rings/valuation/valuation.py index ec39b0d98ea..62c5dac33d7 100644 --- a/src/sage/rings/valuation/valuation.py +++ b/src/sage/rings/valuation/valuation.py @@ -12,10 +12,9 @@ Discrete valuations can be created on a variety of rings:: - sage: # needs sage.rings.padics sage: ZZ.valuation(2) 2-adic valuation - sage: GaussianIntegers().valuation(3) + sage: GaussianIntegers().valuation(3) # needs sage.rings.number_field 3-adic valuation sage: QQ.valuation(5) 5-adic valuation @@ -24,6 +23,7 @@ :: + sage: # needs sage.rings.function_field sage: K. = FunctionField(QQ) sage: K.valuation(x) (x)-adic valuation @@ -35,15 +35,15 @@ :: sage: R. = QQ[] - sage: v = QQ.valuation(2) # needs sage.rings.padics - sage: w = GaussValuation(R, v) # needs sage.rings.padics - sage: w.augmentation(x, 3) # needs sage.rings.padics + sage: v = QQ.valuation(2) + sage: w = GaussValuation(R, v) + sage: w.augmentation(x, 3) [ Gauss valuation induced by 2-adic valuation, v(x) = 3 ] We can also define discrete pseudo-valuations, i.e., discrete valuations that send more than just zero to infinity:: - sage: w.augmentation(x, infinity) # needs sage.rings.padics + sage: w.augmentation(x, infinity) [ Gauss valuation induced by 2-adic valuation, v(x) = +Infinity ] """ # **************************************************************************** @@ -77,7 +77,7 @@ class DiscretePseudoValuation(Morphism): TESTS:: - sage: TestSuite(v).run() # long time + sage: TestSuite(v).run() # long time # needs sage.geometry.polyhedron """ def __init__(self, parent): @@ -85,7 +85,7 @@ def __init__(self, parent): TESTS:: sage: from sage.rings.valuation.valuation import DiscretePseudoValuation - sage: isinstance(ZZ.valuation(2), DiscretePseudoValuation) # needs sage.rings.padics + sage: isinstance(ZZ.valuation(2), DiscretePseudoValuation) True """ @@ -97,7 +97,6 @@ def is_equivalent(self, f, g): EXAMPLES:: - sage: # needs sage.rings.padics sage: v = QQ.valuation(2) sage: v.is_equivalent(2, 1) False @@ -126,8 +125,8 @@ def __hash__(self): EXAMPLES:: - sage: v = QQ.valuation(2) # needs sage.rings.padics - sage: hash(v) == hash(v) # indirect doctest # needs sage.rings.padics + sage: v = QQ.valuation(2) + sage: hash(v) == hash(v) # indirect doctest True """ @@ -147,8 +146,8 @@ def _hash_(self): EXAMPLES:: - sage: v = QQ.valuation(2) # needs sage.rings.padics - sage: hash(v) == hash(v) # indirect doctest # needs sage.rings.padics + sage: v = QQ.valuation(2) + sage: hash(v) == hash(v) # indirect doctest True """ @@ -169,7 +168,6 @@ def _richcmp_(self, other, op): EXAMPLES:: - sage: # needs sage.rings.padics sage: v = QQ.valuation(2) sage: v == v True @@ -230,8 +228,8 @@ def _le_(self, other): EXAMPLES:: sage: v = valuations.TrivialValuation(QQ) - sage: w = QQ.valuation(2) # needs sage.rings.padics - sage: v <= w # needs sage.rings.padics + sage: w = QQ.valuation(2) + sage: v <= w True """ return other >= self @@ -247,8 +245,8 @@ def _ge_(self, other): EXAMPLES:: sage: v = valuations.TrivialValuation(QQ) - sage: w = QQ.valuation(2) # needs sage.rings.padics - sage: v >= w # needs sage.rings.padics + sage: w = QQ.valuation(2) + sage: v >= w False """ if self == other: @@ -272,7 +270,7 @@ def _test_valuation_inheritance(self, **options): EXAMPLES:: - sage: QQ.valuation(2)._test_valuation_inheritance() # needs sage.rings.padics + sage: QQ.valuation(2)._test_valuation_inheritance() """ tester = self._tester(**options) tester.assertNotEqual(isinstance(self, InfiniteDiscretePseudoValuation), @@ -286,18 +284,18 @@ class InfiniteDiscretePseudoValuation(DiscretePseudoValuation): EXAMPLES:: - sage: v = QQ.valuation(2) # needs sage.rings.padics + sage: v = QQ.valuation(2) sage: R. = QQ[] - sage: v = GaussValuation(R, v) # needs sage.rings.padics - sage: w = v.augmentation(x, infinity); w # indirect doctest # needs sage.rings.padics + sage: v = GaussValuation(R, v) + sage: w = v.augmentation(x, infinity); w # indirect doctest [ Gauss valuation induced by 2-adic valuation, v(x) = +Infinity ] TESTS:: sage: from sage.rings.valuation.valuation import InfiniteDiscretePseudoValuation - sage: isinstance(w, InfiniteDiscretePseudoValuation) # needs sage.rings.padics + sage: isinstance(w, InfiniteDiscretePseudoValuation) True - sage: TestSuite(w).run() # long time # needs sage.rings.padics + sage: TestSuite(w).run() # long time # needs sage.geometry.polyhedron sage.rings.padics """ def is_discrete_valuation(self): @@ -306,7 +304,6 @@ def is_discrete_valuation(self): EXAMPLES:: - sage: # needs sage.rings.padics sage: v = QQ.valuation(2) sage: R. = QQ[] sage: v = GaussValuation(R, v) @@ -335,7 +332,7 @@ class NegativeInfiniteDiscretePseudoValuation(InfiniteDiscretePseudoValuation): TESTS:: - sage: TestSuite(w).run() # long time + sage: TestSuite(w).run() # long time """ def is_negative_pseudo_valuation(self): @@ -364,18 +361,18 @@ class DiscreteValuation(DiscretePseudoValuation): EXAMPLES:: - sage: v = QQ.valuation(2) # needs sage.rings.padics + sage: v = QQ.valuation(2) sage: R. = QQ[] - sage: v = GaussValuation(R, v) # needs sage.rings.padics - sage: w = v.augmentation(x, 1337); w # indirect doctest # needs sage.rings.padics + sage: v = GaussValuation(R, v) + sage: w = v.augmentation(x, 1337); w # indirect doctest [ Gauss valuation induced by 2-adic valuation, v(x) = 1337 ] TESTS:: sage: from sage.rings.valuation.valuation import DiscreteValuation - sage: isinstance(w, DiscreteValuation) # needs sage.rings.padics + sage: isinstance(w, DiscreteValuation) True - sage: TestSuite(w).run() # long time # needs sage.rings.padics + sage: TestSuite(w).run() # long time # needs sage.geometry.polyhedron sage.rings.padics """ def is_discrete_valuation(self): @@ -436,12 +433,11 @@ def mac_lane_approximants(self, G, assume_squarefree=False, require_final_EF=Tru EXAMPLES:: - sage: # needs sage.rings.padics sage: v = QQ.valuation(2) sage: R. = QQ[] - sage: v.mac_lane_approximants(x^2 + 1) + sage: v.mac_lane_approximants(x^2 + 1) # needs sage.geometry.polyhedron [[ Gauss valuation induced by 2-adic valuation, v(x + 1) = 1/2 ]] - sage: v.mac_lane_approximants(x^2 + 1, required_precision=infinity) + sage: v.mac_lane_approximants(x^2 + 1, required_precision=infinity) # needs sage.geometry.polyhedron [[ Gauss valuation induced by 2-adic valuation, v(x + 1) = 1/2, v(x^2 + 1) = +Infinity ]] sage: v.mac_lane_approximants(x^2 + x + 1) @@ -451,13 +447,13 @@ def mac_lane_approximants(self, G, assume_squarefree=False, require_final_EF=Tru factor `x + 1` and an approximate factor `x + 1` (which is an approximation to `x - 1`):: - sage: v.mac_lane_approximants(x^2 - 1) # needs sage.rings.padics + sage: v.mac_lane_approximants(x^2 - 1) # needs sage.geometry.polyhedron sage.rings.padics [[ Gauss valuation induced by 2-adic valuation, v(x + 1) = +Infinity ], [ Gauss valuation induced by 2-adic valuation, v(x + 1) = 1 ]] However, it needs to be squarefree:: - sage: v.mac_lane_approximants(x^2) # needs sage.rings.padics + sage: v.mac_lane_approximants(x^2) Traceback (most recent call last): ... ValueError: G must be squarefree @@ -466,26 +462,26 @@ def mac_lane_approximants(self, G, assume_squarefree=False, require_final_EF=Tru Some difficult cases provided by Mark van Hoeij:: - sage: # needs sage.rings.finite_rings + sage: # needs sage.rings.finite_rings sage.rings.function_field sage: k = GF(2) sage: K. = FunctionField(k) sage: R. = K[] sage: F = y^21 + x*y^20 + (x^3 + x + 1)*y^18 + (x^3 + 1)*y^17 + (x^4 + x)*y^16 + (x^7 + x^6 + x^3 + x + 1)*y^15 + x^7*y^14 + (x^8 + x^7 + x^6 + x^4 + x^3 + 1)*y^13 + (x^9 + x^8 + x^4 + 1)*y^12 + (x^11 + x^9 + x^8 + x^5 + x^4 + x^3 + x^2)*y^11 + (x^12 + x^9 + x^8 + x^7 + x^5 + x^3 + x + 1)*y^10 + (x^14 + x^13 + x^10 + x^9 + x^8 + x^7 + x^6 + x^3 + x^2 + 1)*y^9 + (x^13 + x^9 + x^8 + x^6 + x^4 + x^3 + x)*y^8 + (x^16 + x^15 + x^13 + x^12 + x^11 + x^7 + x^3 + x)*y^7 + (x^17 + x^16 + x^13 + x^9 + x^8 + x)*y^6 + (x^17 + x^16 + x^12 + x^7 + x^5 + x^2 + x + 1)*y^5 + (x^19 + x^16 + x^15 + x^12 + x^6 + x^5 + x^3 + 1)*y^4 + (x^18 + x^15 + x^12 + x^10 + x^9 + x^7 + x^4 + x)*y^3 + (x^22 + x^21 + x^20 + x^18 + x^13 + x^12 + x^9 + x^8 + x^7 + x^5 + x^4 + x^3)*y^2 + (x^23 + x^22 + x^20 + x^17 + x^15 + x^14 + x^12 + x^9)*y + x^25 + x^23 + x^19 + x^17 + x^15 + x^13 + x^11 + x^5 sage: x = K._ring.gen() sage: v0 = K.valuation(GaussValuation(K._ring, valuations.TrivialValuation(k)).augmentation(x,1)) - sage: v0.mac_lane_approximants(F, assume_squarefree=True) # assumes squarefree for speed + sage: v0.mac_lane_approximants(F, assume_squarefree=True) # assumes squarefree for speed # needs sage.geometry.polyhedron [[ Gauss valuation induced by (x)-adic valuation, v(y + x + 1) = 3/2 ], [ Gauss valuation induced by (x)-adic valuation, v(y) = 1 ], [ Gauss valuation induced by (x)-adic valuation, v(y) = 4/3 ], [ Gauss valuation induced by (x)-adic valuation, v(y^15 + y^13 + y^12 + y^10 + y^9 + y^8 + y^4 + y^3 + y^2 + y + 1) = 1 ]] sage: v0 = K.valuation(GaussValuation(K._ring, valuations.TrivialValuation(k)).augmentation(x+1,1)) - sage: v0.mac_lane_approximants(F, assume_squarefree=True) # assumes squarefree for speed + sage: v0.mac_lane_approximants(F, assume_squarefree=True) # assumes squarefree for speed # needs sage.geometry.polyhedron [[ Gauss valuation induced by (x + 1)-adic valuation, v(y + x^2 + 1) = 7/2 ], [ Gauss valuation induced by (x + 1)-adic valuation, v(y) = 3/4 ], [ Gauss valuation induced by (x + 1)-adic valuation, v(y) = 7/2 ], [ Gauss valuation induced by (x + 1)-adic valuation, v(y^13 + y^12 + y^10 + y^7 + y^6 + y^3 + 1) = 1 ]] sage: v0 = valuations.FunctionFieldValuation(K, GaussValuation(K._ring, valuations.TrivialValuation(k)).augmentation(x^3+x^2+1,1)) - sage: v0.mac_lane_approximants(F, assume_squarefree=True) # assumes squarefree for speed + sage: v0.mac_lane_approximants(F, assume_squarefree=True) # assumes squarefree for speed # needs sage.rings.function_field [[ Gauss valuation induced by (x^3 + x^2 + 1)-adic valuation, v(y + x^3 + x^2 + x) = 2, v(y^2 + (x^6 + x^4 + 1)*y + x^14 + x^10 + x^9 + x^8 + x^5 + x^4 + x^3 + x^2 + x) = 5 ], [ Gauss valuation induced by (x^3 + x^2 + 1)-adic valuation, v(y^2 + (x^2 + x)*y + 1) = 1 ], [ Gauss valuation induced by (x^3 + x^2 + 1)-adic valuation, v(y^3 + (x + 1)*y^2 + (x + 1)*y + x^2 + x + 1) = 1 ], @@ -495,62 +491,58 @@ def mac_lane_approximants(self, G, assume_squarefree=False, require_final_EF=Tru Cases with trivial residue field extensions:: - sage: # needs sage.rings.padics sage: K. = FunctionField(QQ) sage: S. = K[] sage: F = y^2 - x^2 - x^3 - 3 sage: v0 = GaussValuation(K._ring, QQ.valuation(3)) sage: v1 = v0.augmentation(K._ring.gen(),1/3) sage: mu0 = valuations.FunctionFieldValuation(K, v1) - sage: mu0.mac_lane_approximants(F) + sage: mu0.mac_lane_approximants(F) # needs sage.geometry.polyhedron [[ Gauss valuation induced by Valuation on rational function field induced by [ Gauss valuation induced by 3-adic valuation, v(x) = 1/3 ], v(y + 2*x) = 2/3 ], [ Gauss valuation induced by Valuation on rational function field induced by [ Gauss valuation induced by 3-adic valuation, v(x) = 1/3 ], v(y + x) = 2/3 ]] Over a complete base field:: - sage: k = Qp(2,10) # needs sage.rings.padics - sage: v = k.valuation() # needs sage.rings.padics - - sage: # needs sage.rings.padics + sage: # needs sage.libs.ntl + sage: k = Qp(2,10) + sage: v = k.valuation() sage: R. = k[] sage: G = x sage: v.mac_lane_approximants(G) [Gauss valuation induced by 2-adic valuation] sage: v.mac_lane_approximants(G, required_precision=infinity) [[ Gauss valuation induced by 2-adic valuation, v((1 + O(2^10))*x) = +Infinity ]] - - sage: G = x^2 + 1 # needs sage.rings.padics - sage: v.mac_lane_approximants(G) # needs sage.rings.padics + sage: G = x^2 + 1 + sage: v.mac_lane_approximants(G) # needs sage.geometry.polyhedron [[ Gauss valuation induced by 2-adic valuation, v((1 + O(2^10))*x + 1 + O(2^10)) = 1/2 ]] - sage: v.mac_lane_approximants(G, required_precision=infinity) # needs sage.rings.padics + sage: v.mac_lane_approximants(G, required_precision=infinity) # needs sage.geometry.polyhedron [[ Gauss valuation induced by 2-adic valuation, v((1 + O(2^10))*x + 1 + O(2^10)) = 1/2, v((1 + O(2^10))*x^2 + 1 + O(2^10)) = +Infinity ]] - - sage: G = x^4 + 2*x^3 + 2*x^2 - 2*x + 2 # needs sage.rings.padics - sage: v.mac_lane_approximants(G) # needs sage.rings.padics + sage: G = x^4 + 2*x^3 + 2*x^2 - 2*x + 2 + sage: v.mac_lane_approximants(G) # needs sage.geometry.polyhedron [[ Gauss valuation induced by 2-adic valuation, v((1 + O(2^10))*x) = 1/4 ]] - sage: v.mac_lane_approximants(G, required_precision=infinity) # needs sage.rings.padics + sage: v.mac_lane_approximants(G, required_precision=infinity) # needs sage.geometry.polyhedron [[ Gauss valuation induced by 2-adic valuation, v((1 + O(2^10))*x) = 1/4, v((1 + O(2^10))*x^4 + (2 + O(2^11))*x^3 + (2 + O(2^11))*x^2 + (2 + 2^2 + 2^3 + 2^4 + 2^5 + 2^6 + 2^7 + 2^8 + 2^9 + 2^10 + O(2^11))*x + 2 + O(2^11)) = +Infinity ]] The factorization of primes in the Gaussian integers can be read off the Mac Lane approximants:: - sage: v0 = QQ.valuation(2) # needs sage.rings.padics + sage: v0 = QQ.valuation(2) sage: R. = QQ[] sage: G = x^2 + 1 - sage: v0.mac_lane_approximants(G) # needs sage.rings.padics + sage: v0.mac_lane_approximants(G) # needs sage.geometry.polyhedron sage.rings.padics [[ Gauss valuation induced by 2-adic valuation, v(x + 1) = 1/2 ]] - sage: v0 = QQ.valuation(3) # needs sage.rings.padics - sage: v0.mac_lane_approximants(G) # needs sage.rings.padics + sage: v0 = QQ.valuation(3) + sage: v0.mac_lane_approximants(G) [[ Gauss valuation induced by 3-adic valuation, v(x^2 + 1) = +Infinity ]] - sage: v0 = QQ.valuation(5) # needs sage.rings.padics - sage: v0.mac_lane_approximants(G) # needs sage.rings.padics + sage: v0 = QQ.valuation(5) + sage: v0.mac_lane_approximants(G) # needs sage.geometry.polyhedron sage.rings.padics [[ Gauss valuation induced by 5-adic valuation, v(x + 2) = 1 ], [ Gauss valuation induced by 5-adic valuation, v(x + 3) = 1 ]] - sage: v0.mac_lane_approximants(G, required_precision=10) # needs sage.rings.padics + sage: v0.mac_lane_approximants(G, required_precision=10) # needs sage.geometry.polyhedron sage.rings.padics [[ Gauss valuation induced by 5-adic valuation, v(x + 3116/237) = 10 ], [ Gauss valuation induced by 5-adic valuation, v(x - 3116/237) = 10 ]] @@ -561,68 +553,78 @@ def mac_lane_approximants(self, G, assume_squarefree=False, require_final_EF=Tru sage: # needs sage.rings.padics sage: k = Qp(5,4) sage: v = k.valuation() - sage: R. = k[] + sage: R. = k[] # needs sage.libs.ntl sage: G = x^2 + 1 - sage: v1,v2 = v.mac_lane_approximants(G); v1,v2 - ([ Gauss valuation induced by 5-adic valuation, v((1 + O(5^4))*x + 2 + O(5^4)) = 1 ], - [ Gauss valuation induced by 5-adic valuation, v((1 + O(5^4))*x + 3 + O(5^4)) = 1 ]) - sage: w1, w2 = v.mac_lane_approximants(G, required_precision = 2); w1,w2 - ([ Gauss valuation induced by 5-adic valuation, v((1 + O(5^4))*x + 2 + 5 + O(5^4)) = 2 ], - [ Gauss valuation induced by 5-adic valuation, v((1 + O(5^4))*x + 3 + 3*5 + O(5^4)) = 2 ]) + sage: v1,v2 = v.mac_lane_approximants(G); v1,v2 # needs sage.geometry.polyhedron + ([ Gauss valuation induced by 5-adic valuation, + v((1 + O(5^4))*x + 2 + O(5^4)) = 1 ], + [ Gauss valuation induced by 5-adic valuation, + v((1 + O(5^4))*x + 3 + O(5^4)) = 1 ]) + sage: w1, w2 = v.mac_lane_approximants(G, required_precision=2); w1, w2 # needs sage.geometry.polyhedron + ([ Gauss valuation induced by 5-adic valuation, + v((1 + O(5^4))*x + 2 + 5 + O(5^4)) = 2 ], + [ Gauss valuation induced by 5-adic valuation, + v((1 + O(5^4))*x + 3 + 3*5 + O(5^4)) = 2 ]) Note how the latter give a better approximation to the factors of `x^2 + 1`:: - sage: v1.phi() * v2.phi() - G # needs sage.rings.padics + sage: # needs sage.geometry.polyhedron sage.rings.padics + sage: v1.phi() * v2.phi() - G O(5^4)*x^2 + (5 + O(5^4))*x + 5 + O(5^4) - sage: w1.phi() * w2.phi() - G # needs sage.rings.padics + sage: w1.phi() * w2.phi() - G O(5^4)*x^2 + (5^2 + O(5^4))*x + 5^3 + O(5^4) In this example, the process stops with a factorization of `x^2 + 1`:: - sage: v.mac_lane_approximants(G, required_precision=infinity) # needs sage.rings.padics - [[ Gauss valuation induced by 5-adic valuation, v((1 + O(5^4))*x + 2 + 5 + 2*5^2 + 5^3 + O(5^4)) = +Infinity ], - [ Gauss valuation induced by 5-adic valuation, v((1 + O(5^4))*x + 3 + 3*5 + 2*5^2 + 3*5^3 + O(5^4)) = +Infinity ]] + sage: # needs sage.geometry.polyhedron sage.rings.padics + sage: v.mac_lane_approximants(G, required_precision=infinity) + [[ Gauss valuation induced by 5-adic valuation, + v((1 + O(5^4))*x + 2 + 5 + 2*5^2 + 5^3 + O(5^4)) = +Infinity ], + [ Gauss valuation induced by 5-adic valuation, + v((1 + O(5^4))*x + 3 + 3*5 + 2*5^2 + 3*5^3 + O(5^4)) = +Infinity ]] This obviously cannot happen over the rationals where we only get an approximate factorization:: - sage: # needs sage.rings.padics sage: v = QQ.valuation(5) sage: R. = QQ[] sage: G = x^2 + 1 - sage: v.mac_lane_approximants(G) + sage: v.mac_lane_approximants(G) # needs sage.geometry.polyhedron [[ Gauss valuation induced by 5-adic valuation, v(x + 2) = 1 ], [ Gauss valuation induced by 5-adic valuation, v(x + 3) = 1 ]] - sage: v.mac_lane_approximants(G, required_precision=5) + sage: v.mac_lane_approximants(G, required_precision=5) # needs sage.geometry.polyhedron [[ Gauss valuation induced by 5-adic valuation, v(x + 79/3) = 5 ], [ Gauss valuation induced by 5-adic valuation, v(x - 79/3) = 5 ]] Initial versions ran into problems with the trivial residue field extensions in this case:: - sage: K = Qp(3, 20, print_mode='digits') # needs sage.rings.padics - sage: R. = K[] # needs sage.rings.padics - - sage: # needs sage.rings.padics + sage: # needs sage.libs.ntl + sage: K = Qp(3, 20, print_mode='digits') + sage: R. = K[] sage: alpha = T^3/4 sage: G = 3^3*T^3*(alpha^4 - alpha)^2 - (4*alpha^3 - 1)^3 sage: G = G/G.leading_coefficient() - sage: K.valuation().mac_lane_approximants(G) - [[ Gauss valuation induced by 3-adic valuation, v(...1*T + ...2) = 1/9, v(...1*T^9 + ...20*T^8 + ...210*T^7 + ...20*T^6 + ...20*T^5 + ...10*T^4 + ...220*T^3 + ...20*T^2 + ...110*T + ...122) = 55/27 ]] + sage: K.valuation().mac_lane_approximants(G) # needs sage.geometry.polyhedron + [[ Gauss valuation induced by 3-adic valuation, v(...1*T + ...2) = 1/9, + v(...1*T^9 + ...20*T^8 + ...210*T^7 + ...20*T^6 + ...20*T^5 + ...10*T^4 + + ...220*T^3 + ...20*T^2 + ...110*T + ...122) = 55/27 ]] A similar example:: sage: R. = QQ[] - sage: v = QQ.valuation(3) # needs sage.rings.padics - sage: G = (x^3 + 3)^3 - 81 # needs sage.rings.padics - sage: v.mac_lane_approximants(G) # needs sage.rings.padics - [[ Gauss valuation induced by 3-adic valuation, v(x) = 1/3, v(x^3 + 3*x + 3) = 13/9 ]] + sage: v = QQ.valuation(3) + sage: G = (x^3 + 3)^3 - 81 + sage: v.mac_lane_approximants(G) # needs sage.geometry.polyhedron sage.rings.padics + [[ Gauss valuation induced by 3-adic valuation, + v(x) = 1/3, v(x^3 + 3*x + 3) = 13/9 ]] Another problematic case:: sage: # needs sage.rings.number_field sage.rings.padics sage: R. = QQ[] - sage: Delta = x^12 + 20*x^11 + 154*x^10 + 664*x^9 + 1873*x^8 + 3808*x^7 + 5980*x^6 + 7560*x^5 + 7799*x^4 + 6508*x^3 + 4290*x^2 + 2224*x + 887 + sage: Delta = (x^12 + 20*x^11 + 154*x^10 + 664*x^9 + 1873*x^8 + 3808*x^7 + 5980*x^6 + ....: + 7560*x^5 + 7799*x^4 + 6508*x^3 + 4290*x^2 + 2224*x + 887) sage: K. = NumberField(x^6 + 108) sage: K.is_galois() True @@ -633,51 +635,61 @@ def mac_lane_approximants(self, G, assume_squarefree=False, require_final_EF=Tru 1/3 sage: G = Delta.change_ring(K) sage: vK.mac_lane_approximants(G) - [[ Gauss valuation induced by 2-adic valuation, v(x + 1) = 1/4, v(x^4 + 1/2*theta^4 + 3*theta + 1) = 3/2 ], - [ Gauss valuation induced by 2-adic valuation, v(x + 1) = 1/4, v(x^4 + 1/2*theta^4 + theta + 1) = 3/2 ], - [ Gauss valuation induced by 2-adic valuation, v(x + 1) = 1/4, v(x^4 + 2*theta + 1) = 3/2 ]] + [[ Gauss valuation induced by 2-adic valuation, + v(x + 1) = 1/4, v(x^4 + 1/2*theta^4 + 3*theta + 1) = 3/2 ], + [ Gauss valuation induced by 2-adic valuation, + v(x + 1) = 1/4, v(x^4 + 1/2*theta^4 + theta + 1) = 3/2 ], + [ Gauss valuation induced by 2-adic valuation, + v(x + 1) = 1/4, v(x^4 + 2*theta + 1) = 3/2 ]] An easy case that produced the wrong error at some point:: sage: R. = QQ[] - sage: v = QQ.valuation(2) # needs sage.rings.padics - sage: v.mac_lane_approximants(x^2 - 1/2) # needs sage.rings.padics + sage: v = QQ.valuation(2) + sage: v.mac_lane_approximants(x^2 - 1/2) Traceback (most recent call last): ... ValueError: G must be integral Some examples that Sebastian Pauli used in a talk at Sage Days 87. + Here we use ``assume_squarefree=True`` because :meth:`is_squarefree` + is not properly implemented yet. :: - sage: # needs sage.rings.padics sage: R = ZpFM(3, 7, print_mode='terse') sage: S. = R[] sage: v = R.valuation() sage: f = x^4 + 234 - sage: len(v.mac_lane_approximants(f, # is_squarefree() is not properly implemented yet - ....: assume_squarefree=True)) + sage: len(v.mac_lane_approximants(f, assume_squarefree=True)) # needs sage.geometry.polyhedron + ....: 2 :: - sage: # needs sage.rings.padics sage: R = ZpFM(2, 50, print_mode='terse') sage: S. = R[] sage: f = (x^32 + 16)*(x^32 + 16 + 2^16*x^2) + 2^34 sage: v = R.valuation() - sage: len(v.mac_lane_approximants(f, # is_squarefree() is not properly implemented yet - ....: assume_squarefree=True)) + sage: len(v.mac_lane_approximants(f, assume_squarefree=True)) # needs sage.geometry.polyhedron + ....: 2 A case that triggered an assertion at some point:: - sage: # needs sage.rings.padics sage: v = QQ.valuation(3) sage: R. = QQ[] - sage: f = x^36 + 60552000*x^33 + 268157412*x^30 + 173881701*x^27 + 266324841*x^24 + 83125683*x^21 + 111803814*x^18 + 31925826*x^15 + 205726716*x^12 +17990262*x^9 + 351459648*x^6 + 127014399*x^3 + 359254116 - sage: v.mac_lane_approximants(f) - [[ Gauss valuation induced by 3-adic valuation, v(x) = 1/3, v(x^3 - 3) = 3/2, v(x^12 - 3*x^9 + 54*x^6 + 27/2*x^3 + 405/2) = 13/2, v(x^36 + 60552000*x^33 + 268157412*x^30 + 173881701*x^27 + 266324841*x^24 + 83125683*x^21 + 111803814*x^18 + 31925826*x^15 + 205726716*x^12 + 17990262*x^9 + 351459648*x^6 + 127014399*x^3 + 359254116) = +Infinity ]] + sage: f = (x^36 + 60552000*x^33 + 268157412*x^30 + 173881701*x^27 + 266324841*x^24 + ....: + 83125683*x^21 + 111803814*x^18 + 31925826*x^15 + 205726716*x^12 + ....: + 17990262*x^9 + 351459648*x^6 + 127014399*x^3 + 359254116) + sage: v.mac_lane_approximants(f) # needs sage.geometry.polyhedron + [[ Gauss valuation induced by 3-adic valuation, + v(x) = 1/3, + v(x^3 - 3) = 3/2, + v(x^12 - 3*x^9 + 54*x^6 + 27/2*x^3 + 405/2) = 13/2, + v(x^36 + 60552000*x^33 + 268157412*x^30 + 173881701*x^27 + 266324841*x^24 + + 83125683*x^21 + 111803814*x^18 + 31925826*x^15 + 205726716*x^12 + + 17990262*x^9 + 351459648*x^6 + 127014399*x^3 + 359254116) = +Infinity ]] """ R = G.parent() @@ -805,10 +817,10 @@ def _pow(self, x, e, error): EXAMPLES:: - sage: v = QQ.valuation(2) # needs sage.rings.padics - sage: v._pow(2, 2, error=4) # needs sage.rings.padics + sage: v = QQ.valuation(2) + sage: v._pow(2, 2, error=4) 4 - sage: v._pow(2, 1000, error=4) # needs sage.rings.padics + sage: v._pow(2, 1000, error=4) 0 """ @@ -838,33 +850,33 @@ def mac_lane_approximant(self, G, valuation, approximants=None): EXAMPLES:: - sage: v = QQ.valuation(2) # needs sage.rings.padics - sage: R. = QQ[] # needs sage.rings.padics - sage: G = x^2 + 1 # needs sage.rings.padics + sage: v = QQ.valuation(2) + sage: R. = QQ[] + sage: G = x^2 + 1 We can select an approximant by approximating it:: - sage: w = GaussValuation(R, v).augmentation(x + 1, 1/2) # needs sage.rings.padics - sage: v.mac_lane_approximant(G, w) # needs sage.rings.padics + sage: w = GaussValuation(R, v).augmentation(x + 1, 1/2) + sage: v.mac_lane_approximant(G, w) # needs sage.geometry.polyhedron sage.rings.padics [ Gauss valuation induced by 2-adic valuation, v(x + 1) = 1/2 ] As long as this is the only matching approximant, the approximation can be very coarse:: - sage: w = GaussValuation(R, v) # needs sage.rings.padics - sage: v.mac_lane_approximant(G, w) # needs sage.rings.padics + sage: w = GaussValuation(R, v) + sage: v.mac_lane_approximant(G, w) # needs sage.geometry.polyhedron sage.rings.padics [ Gauss valuation induced by 2-adic valuation, v(x + 1) = 1/2 ] Or it can be very specific:: - sage: w = GaussValuation(R, v).augmentation(x + 1, 1/2).augmentation(G, infinity) # needs sage.rings.padics - sage: v.mac_lane_approximant(G, w) # needs sage.rings.padics + sage: w = GaussValuation(R, v).augmentation(x + 1, 1/2).augmentation(G, infinity) + sage: v.mac_lane_approximant(G, w) # needs sage.geometry.polyhedron sage.rings.padics [ Gauss valuation induced by 2-adic valuation, v(x + 1) = 1/2 ] But it must be an approximation of an approximant:: - sage: w = GaussValuation(R, v).augmentation(x, 1/2) # needs sage.rings.padics - sage: v.mac_lane_approximant(G, w) # needs sage.rings.padics + sage: w = GaussValuation(R, v).augmentation(x, 1/2) + sage: v.mac_lane_approximant(G, w) Traceback (most recent call last): ... ValueError: The valuation @@ -875,29 +887,29 @@ def mac_lane_approximant(self, G, valuation, approximants=None): The ``valuation`` must single out one approximant:: - sage: G = x^2 - 1 # needs sage.rings.padics - sage: w = GaussValuation(R, v) # needs sage.rings.padics - sage: v.mac_lane_approximant(G, w) # needs sage.rings.padics + sage: G = x^2 - 1 + sage: w = GaussValuation(R, v) + sage: v.mac_lane_approximant(G, w) # needs sage.geometry.polyhedron sage.rings.padics Traceback (most recent call last): ... ValueError: The valuation Gauss valuation induced by 2-adic valuation does not approximate a unique extension of 2-adic valuation with respect to x^2 - 1 - sage: w = GaussValuation(R, v).augmentation(x + 1, 1) # needs sage.rings.padics - sage: v.mac_lane_approximant(G, w) # needs sage.rings.padics + sage: w = GaussValuation(R, v).augmentation(x + 1, 1) + sage: v.mac_lane_approximant(G, w) # needs sage.geometry.polyhedron sage.rings.padics Traceback (most recent call last): ... ValueError: The valuation [ Gauss valuation induced by 2-adic valuation, v(x + 1) = 1 ] does not approximate a unique extension of 2-adic valuation with respect to x^2 - 1 - sage: w = GaussValuation(R, v).augmentation(x + 1, 2) # needs sage.rings.padics - sage: v.mac_lane_approximant(G, w) # needs sage.rings.padics + sage: w = GaussValuation(R, v).augmentation(x + 1, 2) + sage: v.mac_lane_approximant(G, w) # needs sage.geometry.polyhedron sage.rings.padics [ Gauss valuation induced by 2-adic valuation, v(x + 1) = +Infinity ] - sage: w = GaussValuation(R, v).augmentation(x + 3, 2) # needs sage.rings.padics - sage: v.mac_lane_approximant(G, w) # needs sage.rings.padics + sage: w = GaussValuation(R, v).augmentation(x + 3, 2) + sage: v.mac_lane_approximant(G, w) # needs sage.geometry.polyhedron sage.rings.padics [ Gauss valuation induced by 2-adic valuation, v(x + 1) = 1 ] """ @@ -957,12 +969,12 @@ def montes_factorization(self, G, assume_squarefree=False, required_precision=No EXAMPLES:: - sage: # needs sage.rings.padics + sage: # needs sage.libs.ntl sage: k = Qp(5,4) sage: v = k.valuation() sage: R. = k[] sage: G = x^2 + 1 - sage: v.montes_factorization(G) + sage: v.montes_factorization(G) # needs sage.geometry.polyhedron ((1 + O(5^4))*x + 2 + 5 + 2*5^2 + 5^3 + O(5^4)) * ((1 + O(5^4))*x + 3 + 3*5 + 2*5^2 + 3*5^3 + O(5^4)) @@ -970,13 +982,13 @@ def montes_factorization(self, G, assume_squarefree=False, required_precision=No particular because the factors can not be represented there):: sage: R. = QQ[] - sage: v = QQ.valuation(2) # needs sage.rings.padics - sage: v.montes_factorization(x^6 - 1) # needs sage.rings.padics + sage: v = QQ.valuation(2) + sage: v.montes_factorization(x^6 - 1) # needs sage.geometry.polyhedron sage.rings.padics (x - 1) * (x + 1) * (x^2 - x + 1) * (x^2 + x + 1) sage: v.montes_factorization(x^7 - 1) # not tested # needs sage.rings.padics - sage: v.montes_factorization(x^7 - 1, required_precision=5) # needs sage.rings.padics + sage: v.montes_factorization(x^7 - 1, required_precision=5) # needs sage.geometry.polyhedron sage.rings.padics (x - 1) * (x^3 - 5*x^2 - 6*x - 1) * (x^3 + 6*x^2 + 5*x - 1) TESTS: @@ -986,7 +998,7 @@ def montes_factorization(self, G, assume_squarefree=False, required_precision=No In this example, ``f`` factors as three factors of degree 50 over an unramified extension:: - sage: # needs sage.rings.padics + sage: # needs sage.libs.flint sage: R. = ZqFM(125) sage: S. = R[] sage: f = (x^6+2)^25 + 5 @@ -996,14 +1008,14 @@ def montes_factorization(self, G, assume_squarefree=False, required_precision=No In this case, ``f`` factors into degrees 1, 2, and 5 over a totally ramified extension:: - sage: # needs sage.rings.padics + sage: # needs sage.libs.ntl sage: R = Zp(5) sage: S. = R[] sage: R. = R.extension(w^3 + 5) sage: S. = R[] sage: f = (x^3 + 5)*(x^5 + w) + 625 sage: v = R.valuation() - sage: v.montes_factorization(f, assume_squarefree=True, required_precision=0) + sage: v.montes_factorization(f, assume_squarefree=True, required_precision=0) # needs sage.libs.flint ((1 + O(w^60))*x + 4*w + O(w^61)) * ((1 + O(w^60))*x^2 + (w + O(w^61))*x + w^2 + O(w^62)) * ((1 + O(w^60))*x^5 + w + O(w^61)) REFERENCES: @@ -1066,8 +1078,8 @@ class MacLaneApproximantNode(): TESTS:: - sage: v = ZZ.valuation(3) # needs sage.rings.padics - sage: v.extension(GaussianIntegers()) # indirect doctest # needs sage.rings.padics + sage: v = ZZ.valuation(3) + sage: v.extension(GaussianIntegers()) # indirect doctest # needs sage.rings.number_field sage.rings.padics 3-adic valuation """ @@ -1076,8 +1088,8 @@ def __init__(self, valuation, parent, ef, principal_part_bound, coefficients, va TESTS:: sage: from sage.rings.valuation.valuation import MacLaneApproximantNode - sage: node = MacLaneApproximantNode(QQ.valuation(2), None, 1, None, None, None) # needs sage.rings.padics - sage: TestSuite(node).run() # needs sage.rings.padics + sage: node = MacLaneApproximantNode(QQ.valuation(2), None, 1, None, None, None) + sage: TestSuite(node).run() """ self.valuation = valuation @@ -1094,7 +1106,6 @@ def __eq__(self, other): EXAMPLES:: - sage: # needs sage.rings.padics sage: from sage.rings.valuation.valuation import MacLaneApproximantNode sage: n = MacLaneApproximantNode(QQ.valuation(2), None, 1, None, None, None) sage: m = MacLaneApproximantNode(QQ.valuation(3), None, 1, None, None, None) @@ -1114,7 +1125,6 @@ def __ne__(self, other): EXAMPLES:: - sage: # needs sage.rings.padics sage: from sage.rings.valuation.valuation import MacLaneApproximantNode sage: n = MacLaneApproximantNode(QQ.valuation(2), None, 1, None, None, None) sage: m = MacLaneApproximantNode(QQ.valuation(3), None, 1, None, None, None) diff --git a/src/sage/rings/valuation/valuation_space.py b/src/sage/rings/valuation/valuation_space.py index ce737c93969..c721fef2df8 100644 --- a/src/sage/rings/valuation/valuation_space.py +++ b/src/sage/rings/valuation/valuation_space.py @@ -510,8 +510,7 @@ def residue_ring(self): sage: valuations.TrivialValuation(ZZ).residue_ring() Integer Ring sage: GaussValuation(ZZ['x'], ZZ.valuation(2)).residue_ring() - Univariate Polynomial Ring in x over Finite Field of size 2 (using ...) - + Univariate Polynomial Ring in x over Finite Field of size 2... """ @@ -1336,7 +1335,7 @@ def _test_value_semigroup(self, **options): TESTS:: sage: v = QQ.valuation(5) - sage: v._test_value_semigroup() + sage: v._test_value_semigroup() # needs sage.geometry.polyhedron """ tester = self._tester(**options) @@ -1355,7 +1354,7 @@ def _test_element_with_valuation(self, **options): TESTS:: sage: v = QQ.valuation(5) - sage: v._test_element_with_valuation() + sage: v._test_element_with_valuation() # needs sage.geometry.polyhedron """ tester = self._tester(**options) diff --git a/src/sage/rings/valuation/value_group.py b/src/sage/rings/valuation/value_group.py index 57a6c1b2719..b39eec60bdd 100644 --- a/src/sage/rings/valuation/value_group.py +++ b/src/sage/rings/valuation/value_group.py @@ -136,9 +136,9 @@ class DiscreteValueGroup(UniqueRepresentation, Parent): TESTS:: - sage: TestSuite(D1).run() # long time - sage: TestSuite(D2).run() # long time - sage: TestSuite(D3).run() # long time + sage: TestSuite(D1).run() # long time + sage: TestSuite(D2).run() # long time + sage: TestSuite(D3).run() # long time """ @staticmethod @@ -431,9 +431,9 @@ class DiscreteValueSemigroup(UniqueRepresentation, Parent): TESTS:: - sage: TestSuite(D1).run() # long time - sage: TestSuite(D2).run() # long time - sage: TestSuite(D3).run() # long time + sage: TestSuite(D1).run() # long time + sage: TestSuite(D2).run() # long time # needs sage.geometry.polyhedron + sage: TestSuite(D3).run() # long time # needs sage.numerical.mip """ @staticmethod @@ -511,7 +511,7 @@ def _solve_linear_program(self, target): sage: from sage.rings.valuation.value_group import DiscreteValueSemigroup sage: D = DiscreteValueSemigroup([2,3,5]) - sage: D._solve_linear_program(12) + sage: D._solve_linear_program(12) # needs sage.numerical.mip {0: 1, 1: 0, 2: 2} sage: 1*2 + 0*3 + 2*5 12 @@ -670,7 +670,7 @@ def some_elements(self): EXAMPLES:: sage: from sage.rings.valuation.value_group import DiscreteValueSemigroup - sage: list(DiscreteValueSemigroup([-3/8,1/2]).some_elements()) + sage: list(DiscreteValueSemigroup([-3/8,1/2]).some_elements()) # needs sage.numerical.mip [0, -3/8, 1/2, ...] """ yield self(0) diff --git a/src/sage/sat/solvers/dimacs.py b/src/sage/sat/solvers/dimacs.py index f9688ecd8d6..cfe3c7cd4ed 100644 --- a/src/sage/sat/solvers/dimacs.py +++ b/src/sage/sat/solvers/dimacs.py @@ -93,7 +93,7 @@ def __init__(self, command=None, filename=None, verbosity=0, **kwds): else: self._command = self.__class__.command - self._tail = open(tmp_filename(),'w') + self._tail = open(tmp_filename(), 'w') self._var = 0 self._lit = 0 diff --git a/src/sage/schemes/curves/curve.py b/src/sage/schemes/curves/curve.py index 79fcc820618..0538db66fee 100644 --- a/src/sage/schemes/curves/curve.py +++ b/src/sage/schemes/curves/curve.py @@ -184,7 +184,11 @@ def divisor(self, v, base_ring=None, check=True, reduce=True): sage: x,y,z = PolynomialRing(QQ, 3, names='x,y,z').gens() sage: C = Curve(y^2*z - x^3 - 17*x*z^2 + y*z^2) - + sage: p1 = C(0, -1, 1) + sage: p2 = C(0, 0, 1) + sage: p3 = C(0, 1, 0) + sage: C.divisor([(1, p1), (-1, p2), (2, p3)]) + (x, y + z) - (x, y) + 2*(x, z) """ return Divisor_curve(v, check=check, reduce=reduce, parent=self.divisor_group(base_ring)) diff --git a/src/sage/schemes/cyclic_covers/cycliccover_finite_field.py b/src/sage/schemes/cyclic_covers/cycliccover_finite_field.py index 82583c14cfc..82504873715 100644 --- a/src/sage/schemes/cyclic_covers/cycliccover_finite_field.py +++ b/src/sage/schemes/cyclic_covers/cycliccover_finite_field.py @@ -733,8 +733,8 @@ def _initialize_fat_horizontal(self, s, L): targets[2 * l] = self._p * l targets[2 * l + 1] = self._p * (l + 1) - d - 1 (m0, m1), (M0, M1) = self._horizontal_matrix_reduction(s) - M0, M1 = [elt.change_ring(self._Zq0) for elt in [M0, M1]] - D0, D1 = [matrix(self._Zq0, [elt]) for elt in [m0, m1]] + M0, M1 = (elt.change_ring(self._Zq0) for elt in [M0, M1]) + D0, D1 = (matrix(self._Zq0, [elt]) for elt in [m0, m1]) MH = interval_products(M0, M1, targets) DH = [elt[0, 0] for elt in interval_products(D0, D1, targets)] if L > N: # Vandermonde interpolation diff --git a/src/sage/schemes/elliptic_curves/constructor.py b/src/sage/schemes/elliptic_curves/constructor.py index e7a1767cecb..f6f7828cb8e 100644 --- a/src/sage/schemes/elliptic_curves/constructor.py +++ b/src/sage/schemes/elliptic_curves/constructor.py @@ -1132,7 +1132,7 @@ def EllipticCurve_from_cubic(F, P=None, morphism=True): if flex_point is not None: # first case: base point is a flex P = flex_point L = tangent_at_smooth_point(C,P) - dx, dy, dz = [L.coefficient(v) for v in R.gens()] + dx, dy, dz = (L.coefficient(v) for v in R.gens()) # find an invertible matrix M such that (0,1,0)M=P and # ML'=(0,0,1)' where L=[dx,dy,dx]. Then the linear transform diff --git a/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py b/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py index cccfce646b3..75d10d147d6 100644 --- a/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py +++ b/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py @@ -1745,7 +1745,7 @@ def __set_pre_isomorphism(self, domain, isomorphism): # calculate the isomorphism as a rational map. - u, r, s, t = [self.__base_field(c) for c in isomorphism.tuple()] + u, r, s, t = (self.__base_field(c) for c in isomorphism.tuple()) uinv = 1/u uinv2 = uinv**2 uinv3 = uinv*uinv2 @@ -1787,7 +1787,7 @@ def __set_post_isomorphism(self, codomain, isomorphism): # calculate the isomorphism as a rational map. - u, r, s, t = [self.__base_field(c) for c in isomorphism.tuple()] + u, r, s, t = (self.__base_field(c) for c in isomorphism.tuple()) uinv = 1/u uinv2 = uinv**2 uinv3 = uinv*uinv2 diff --git a/src/sage/schemes/elliptic_curves/ell_point.py b/src/sage/schemes/elliptic_curves/ell_point.py index 24908b9743e..1e760dcfd6c 100644 --- a/src/sage/schemes/elliptic_curves/ell_point.py +++ b/src/sage/schemes/elliptic_curves/ell_point.py @@ -3035,7 +3035,7 @@ def archimedean_local_height(self, v=None, prec=None, weighted=False): # (with infinite precision) and then trim back to RR or CC. x = RC(v_inf(self[0])) - b2, b4, b6, b8 = [RC(v_inf(b)) for b in E.b_invariants()] + b2, b4, b6, b8 = (RC(v_inf(b)) for b in E.b_invariants()) # The following comes from Silverman Theorem 4.2. Silverman # uses decimal precision d, so his term (5/3)d = diff --git a/src/sage/schemes/elliptic_curves/gal_reps_number_field.py b/src/sage/schemes/elliptic_curves/gal_reps_number_field.py index 8861f643198..48f742a6cd0 100644 --- a/src/sage/schemes/elliptic_curves/gal_reps_number_field.py +++ b/src/sage/schemes/elliptic_curves/gal_reps_number_field.py @@ -877,7 +877,7 @@ def _semistable_reducible_primes(E, verbose=False): last_p = p Px, Py = precomp - x, y = [PP.gens_reduced()[0] for PP in precomp] + x, y = (PP.gens_reduced()[0] for PP in precomp) EmodPx = E.reduction(Px) if d > 1 else E.reduction(x) EmodPy = E.reduction(Py) if d > 1 else E.reduction(y) fxpol = EmodPx.frobenius_polynomial() diff --git a/src/sage/schemes/elliptic_curves/height.py b/src/sage/schemes/elliptic_curves/height.py index 64d025a6481..30709dccf96 100644 --- a/src/sage/schemes/elliptic_curves/height.py +++ b/src/sage/schemes/elliptic_curves/height.py @@ -928,7 +928,7 @@ def alpha(self, v, tol=0.01): 0.347263296676126 """ from sage.rings.polynomial.polynomial_ring import polygen - b2, b4, b6, b8 = [v(b) for b in self.E.b_invariants()] + b2, b4, b6, b8 = (v(b) for b in self.E.b_invariants()) x = polygen(v.codomain()) f = 4*x**3 + b2*x**2 + 2*b4*x + b6 g = x**4 - b4*x**2 - 2*b6*x - b8 diff --git a/src/sage/schemes/elliptic_curves/period_lattice.py b/src/sage/schemes/elliptic_curves/period_lattice.py index a4cd489a34c..c12e3f12cbc 100644 --- a/src/sage/schemes/elliptic_curves/period_lattice.py +++ b/src/sage/schemes/elliptic_curves/period_lattice.py @@ -1427,7 +1427,7 @@ def e_log_RC(self, xP, yP, prec=None, reduce=True): R = RealField(prec2) C = ComplexField(prec2) e1,e2,e3 = self._ei - a1,a2,a3 = [self.embedding(a) for a in self.E.ainvs()[:3]] + a1,a2,a3 = (self.embedding(a) for a in self.E.ainvs()[:3]) wP = 2*yP+a1*xP+a3 @@ -1716,7 +1716,7 @@ def elliptic_logarithm(self, P, prec=None, reduce=True): # Compute the real or complex coordinates of P: - xP, yP = [self.embedding(coord) for coord in P.xy()] + xP, yP = (self.embedding(coord) for coord in P.xy()) # The real work is done over R or C now: @@ -1915,7 +1915,7 @@ def elliptic_exponential(self, z, to_curve=True): # the same precision as the input. x, y = pari(self.basis(prec=prec)).ellwp(z, flag=1) - x, y = [C(t) for t in (x, y)] + x, y = (C(t) for t in (x, y)) if self.real_flag and z_is_real: x = x.real() @@ -1924,7 +1924,7 @@ def elliptic_exponential(self, z, to_curve=True): if to_curve: K = x.parent() v = refine_embedding(self.embedding, Infinity) - a1, a2, a3, a4, a6 = [K(v(a)) for a in self.E.ainvs()] + a1, a2, a3, a4, a6 = (K(v(a)) for a in self.E.ainvs()) b2 = K(v(self.E.b2())) x = x - b2 / 12 y = (y - (a1 * x + a3)) / 2 diff --git a/src/sage/schemes/riemann_surfaces/riemann_surface.py b/src/sage/schemes/riemann_surfaces/riemann_surface.py index 3166cbf11e3..b7e3f1ac8f6 100644 --- a/src/sage/schemes/riemann_surfaces/riemann_surface.py +++ b/src/sage/schemes/riemann_surfaces/riemann_surface.py @@ -282,7 +282,7 @@ def numerical_inverse(C): with mpall.workprec(prec): Cmp = mpall.matrix([mpall.sage_to_mpmath(list(c), prec) for c in C]) PLU = mpall.lu(Cmp) - P, L, U = [R([mpall.mpmath_to_sage(c, prec) for c in M]) for M in PLU] + P, L, U = (R([mpall.mpmath_to_sage(c, prec) for c in M]) for M in PLU) return U.inverse() * L.inverse() * P diff --git a/src/sage/stats/distributions/discrete_gaussian_integer.pxd b/src/sage/stats/distributions/discrete_gaussian_integer.pxd index 7235a9397f7..d6edbe88d43 100644 --- a/src/sage/stats/distributions/discrete_gaussian_integer.pxd +++ b/src/sage/stats/distributions/discrete_gaussian_integer.pxd @@ -1,8 +1,8 @@ -from .dgs cimport dgs_disc_gauss_mp_t, dgs_disc_gauss_dp_t - -from sage.structure.sage_object cimport SageObject -from sage.rings.real_mpfr cimport RealNumber from sage.rings.integer cimport Integer +from sage.rings.real_mpfr cimport RealNumber +from sage.stats.distributions.dgs cimport dgs_disc_gauss_mp_t, dgs_disc_gauss_dp_t +from sage.structure.sage_object cimport SageObject + cdef class DiscreteGaussianDistributionIntegerSampler(SageObject): cdef readonly RealNumber sigma diff --git a/src/sage/stats/distributions/discrete_gaussian_integer.pyx b/src/sage/stats/distributions/discrete_gaussian_integer.pyx index 2aa28609180..6d50074102b 100644 --- a/src/sage/stats/distributions/discrete_gaussian_integer.pyx +++ b/src/sage/stats/distributions/discrete_gaussian_integer.pyx @@ -148,9 +148,9 @@ from sage.libs.mpfr cimport mpfr_set, MPFR_RNDN from sage.rings.integer cimport Integer from sage.misc.randstate cimport randstate, current_randstate -from .dgs cimport dgs_disc_gauss_mp_init, dgs_disc_gauss_mp_clear, dgs_disc_gauss_mp_flush_cache -from .dgs cimport dgs_disc_gauss_dp_init, dgs_disc_gauss_dp_clear, dgs_disc_gauss_dp_flush_cache -from .dgs cimport DGS_DISC_GAUSS_UNIFORM_TABLE, DGS_DISC_GAUSS_UNIFORM_ONLINE, DGS_DISC_GAUSS_UNIFORM_LOGTABLE, DGS_DISC_GAUSS_SIGMA2_LOGTABLE +from sage.stats.distributions.dgs cimport dgs_disc_gauss_mp_init, dgs_disc_gauss_mp_clear, dgs_disc_gauss_mp_flush_cache +from sage.stats.distributions.dgs cimport dgs_disc_gauss_dp_init, dgs_disc_gauss_dp_clear, dgs_disc_gauss_dp_flush_cache +from sage.stats.distributions.dgs cimport DGS_DISC_GAUSS_UNIFORM_TABLE, DGS_DISC_GAUSS_UNIFORM_ONLINE, DGS_DISC_GAUSS_UNIFORM_LOGTABLE, DGS_DISC_GAUSS_SIGMA2_LOGTABLE cdef class DiscreteGaussianDistributionIntegerSampler(SageObject): r""" diff --git a/src/sage/stats/hmm/chmm.pyx b/src/sage/stats/hmm/chmm.pyx index aa35b8cefdc..fe09b3f9cfb 100644 --- a/src/sage/stats/hmm/chmm.pyx +++ b/src/sage/stats/hmm/chmm.pyx @@ -28,9 +28,9 @@ from sage.structure.element import is_Matrix from sage.stats.time_series cimport TimeSeries from sage.stats.intlist cimport IntList -from .hmm cimport HiddenMarkovModel -from .util cimport HMM_Util -from .distributions cimport GaussianMixtureDistribution +from sage.stats.hmm.hmm cimport HiddenMarkovModel +from sage.stats.hmm.util cimport HMM_Util +from sage.stats.hmm.distributions cimport GaussianMixtureDistribution cdef HMM_Util util = HMM_Util() diff --git a/src/sage/stats/hmm/hmm.pyx b/src/sage/stats/hmm/hmm.pyx index 86de50cc1a3..fe8ab69cc66 100644 --- a/src/sage/stats/hmm/hmm.pyx +++ b/src/sage/stats/hmm/hmm.pyx @@ -41,7 +41,7 @@ from sage.matrix.constructor import matrix from sage.misc.randstate cimport current_randstate, randstate from cpython.object cimport PyObject_RichCompare -from .util cimport HMM_Util +from sage.stats.hmm.util cimport HMM_Util cdef HMM_Util util = HMM_Util() diff --git a/src/sage/structure/all.py b/src/sage/structure/all.py index 311bf869ef2..df0114c8382 100644 --- a/src/sage/structure/all.py +++ b/src/sage/structure/all.py @@ -1,12 +1,12 @@ -from .factorization import Factorization +from sage.structure.factorization import Factorization -from .sequence import Sequence, seq +from sage.structure.sequence import Sequence, seq -from .unique_representation import UniqueRepresentation +from sage.structure.unique_representation import UniqueRepresentation -from .sage_object import SageObject +from sage.structure.sage_object import SageObject -from .element import ( +from sage.structure.element import ( canonical_coercion, coercion_model, get_coercion_model, @@ -14,16 +14,16 @@ parent ) -from .parent import Parent +from sage.structure.parent import Parent -from .parent_gens import localvars +from sage.structure.parent_gens import localvars -from .proof import all as proof +from sage.structure.proof import all as proof from sage.misc.lazy_import import lazy_import lazy_import('sage.structure.formal_sum', ['FormalSums', 'FormalSum']) del lazy_import -from .mutability import Mutability +from sage.structure.mutability import Mutability -from .element_wrapper import ElementWrapper +from sage.structure.element_wrapper import ElementWrapper diff --git a/src/sage/structure/coerce.pxd b/src/sage/structure/coerce.pxd index 8856950d685..0ab42fe9666 100644 --- a/src/sage/structure/coerce.pxd +++ b/src/sage/structure/coerce.pxd @@ -1,5 +1,5 @@ -from .parent cimport Parent -from .coerce_dict cimport TripleDict +from sage.structure.parent cimport Parent +from sage.structure.coerce_dict cimport TripleDict cpdef py_scalar_parent(py_type) noexcept cpdef py_scalar_to_element(py) noexcept diff --git a/src/sage/structure/coerce.pyx b/src/sage/structure/coerce.pyx index 6dc194c5cf9..8eed934aea3 100644 --- a/src/sage/structure/coerce.pyx +++ b/src/sage/structure/coerce.pyx @@ -84,11 +84,11 @@ cimport gmpy2 cdef mul, truediv from operator import mul, truediv -from .richcmp cimport rich_to_bool, revop -from .sage_object cimport SageObject -from .parent cimport Parent_richcmp_element_without_coercion -from .element cimport bin_op_exception, parent, Element -from .coerce_exceptions import CoercionException +from sage.structure.richcmp cimport rich_to_bool, revop +from sage.structure.sage_object cimport SageObject +from sage.structure.parent cimport Parent_richcmp_element_without_coercion +from sage.structure.element cimport bin_op_exception, parent, Element +from sage.structure.coerce_exceptions import CoercionException from sage.rings.integer_fake cimport is_Integer from sage.categories.map cimport Map from sage.categories.morphism import IdentityMorphism diff --git a/src/sage/structure/coerce_actions.pyx b/src/sage/structure/coerce_actions.pyx index 7b1d9491f56..9a26db7be64 100644 --- a/src/sage/structure/coerce_actions.pyx +++ b/src/sage/structure/coerce_actions.pyx @@ -18,10 +18,10 @@ from cpython.long cimport * from cpython.number cimport * from cysignals.signals cimport sig_check -from .coerce cimport coercion_model -from .element cimport parent, Element, ModuleElement -from .parent cimport Parent -from .coerce_exceptions import CoercionException +from sage.structure.coerce cimport coercion_model +from sage.structure.element cimport parent, Element, ModuleElement +from sage.structure.parent cimport Parent +from sage.structure.coerce_exceptions import CoercionException from sage.categories.action cimport InverseAction, PrecomposedAction from sage.arith.long cimport integer_check_long diff --git a/src/sage/structure/element.pxd b/src/sage/structure/element.pxd index 1cef67617ff..487a3d126a1 100644 --- a/src/sage/structure/element.pxd +++ b/src/sage/structure/element.pxd @@ -1,5 +1,5 @@ -from .sage_object cimport SageObject -from .parent cimport Parent +from sage.structure.sage_object cimport SageObject +from sage.structure.parent cimport Parent from sage.misc.inherit_comparison cimport InheritComparisonMetaclass diff --git a/src/sage/structure/factorization_integer.py b/src/sage/structure/factorization_integer.py index 2ea04be826e..4d01cea5a6f 100644 --- a/src/sage/structure/factorization_integer.py +++ b/src/sage/structure/factorization_integer.py @@ -69,9 +69,9 @@ def __init__(self, x, unit=None, cr=False, sort=True, simplify=True, else: self._Factorization__unit = unit - self._Factorization__x = x + self._Factorization__x = x self._Factorization__universe = ZZ - self._Factorization__cr = cr + self._Factorization__cr = cr if sort: self.sort() diff --git a/src/sage/structure/factory.pyx b/src/sage/structure/factory.pyx index 1b83ea0c2a9..d3f551ef24d 100644 --- a/src/sage/structure/factory.pyx +++ b/src/sage/structure/factory.pyx @@ -56,7 +56,7 @@ AUTHORS: import types -from .sage_object cimport SageObject +from sage.structure.sage_object cimport SageObject cdef sage_version from sage.version import version as sage_version diff --git a/src/sage/structure/parent.pyx b/src/sage/structure/parent.pyx index 6c073e8cd98..9a0cbd66b9a 100644 --- a/src/sage/structure/parent.pyx +++ b/src/sage/structure/parent.pyx @@ -119,13 +119,13 @@ from sage.misc.lazy_attribute import lazy_attribute from sage.categories.sets_cat import Sets, EmptySetError from sage.misc.lazy_string cimport _LazyString from sage.sets.pythonclass cimport Set_PythonType_class -from .category_object import CategoryObject -from .coerce cimport coercion_model -from .coerce cimport parent_is_integers -from .coerce_exceptions import CoercionException -from .coerce_maps cimport (NamedConvertMap, DefaultConvertMap, +from sage.structure.category_object import CategoryObject +from sage.structure.coerce cimport coercion_model +from sage.structure.coerce cimport parent_is_integers +from sage.structure.coerce_exceptions import CoercionException +from sage.structure.coerce_maps cimport (NamedConvertMap, DefaultConvertMap, DefaultConvertMap_unique, CallableConvertMap) -from .element cimport parent +from sage.structure.element cimport parent cdef _record_exception() noexcept: diff --git a/src/sage/structure/parent_base.pxd b/src/sage/structure/parent_base.pxd index 225fccabcae..8ffac64eff2 100644 --- a/src/sage/structure/parent_base.pxd +++ b/src/sage/structure/parent_base.pxd @@ -6,7 +6,7 @@ # https://www.gnu.org/licenses/ ############################################################################### -from .parent_old cimport Parent as Parent_old +from sage.structure.parent_old cimport Parent as Parent_old cdef class ParentWithBase(Parent_old): pass diff --git a/src/sage/structure/parent_base.pyx b/src/sage/structure/parent_base.pyx index 64277588819..f5ecc15affa 100644 --- a/src/sage/structure/parent_base.pyx +++ b/src/sage/structure/parent_base.pyx @@ -12,7 +12,7 @@ Base class for old-style parent objects with a base ring # **************************************************************************** cimport sage.structure.parent as parent -from .coerce_exceptions import CoercionException +from sage.structure.coerce_exceptions import CoercionException cdef inline check_old_coerce(parent.Parent p) noexcept: if p._element_constructor is not None: diff --git a/src/sage/structure/parent_gens.pxd b/src/sage/structure/parent_gens.pxd index 6ec0e6e83f0..cf3b416317f 100644 --- a/src/sage/structure/parent_gens.pxd +++ b/src/sage/structure/parent_gens.pxd @@ -12,7 +12,7 @@ Parent objects with generators # http://www.gnu.org/licenses/ #***************************************************************************** -from .parent_base cimport ParentWithBase +from sage.structure.parent_base cimport ParentWithBase cdef class ParentWithGens(ParentWithBase): diff --git a/src/sage/structure/parent_old.pyx b/src/sage/structure/parent_old.pyx index b92a826020f..c093febf375 100644 --- a/src/sage/structure/parent_old.pyx +++ b/src/sage/structure/parent_old.pyx @@ -27,7 +27,7 @@ This came up in some subtle bug once:: # https://www.gnu.org/licenses/ # **************************************************************************** from sage.misc.superseded import deprecation -from .coerce cimport py_scalar_parent +from sage.structure.coerce cimport py_scalar_parent from sage.ext.stdsage cimport HAS_DICTIONARY from sage.sets.pythonclass cimport Set_PythonType, Set_PythonType_class diff --git a/src/sage/structure/sage_object_test.py b/src/sage/structure/sage_object_test.py index 0922545a62c..721c1ad7719 100644 --- a/src/sage/structure/sage_object_test.py +++ b/src/sage/structure/sage_object_test.py @@ -1,6 +1,7 @@ import pytest -from .sage_object import SageObject +from sage.structure.sage_object import SageObject + class SageObjectTests: diff --git a/src/sage/tensor/modules/tensor_free_submodule.py b/src/sage/tensor/modules/tensor_free_submodule.py index 177eb1f3248..6503c310a91 100644 --- a/src/sage/tensor/modules/tensor_free_submodule.py +++ b/src/sage/tensor/modules/tensor_free_submodule.py @@ -152,7 +152,7 @@ def power_name(op, s, latex=False): if latex: superscript = r'\{' + superscript + r'\}' else: - superscript = '{' + superscript + '}' + superscript = '{' + superscript + '}' if latex: if len(superscript) != 1: superscript = '{' + superscript + '}' diff --git a/src/sage/tests/book_stein_ent.py b/src/sage/tests/book_stein_ent.py index c056e43aa55..af4f77eb566 100644 --- a/src/sage/tests/book_stein_ent.py +++ b/src/sage/tests/book_stein_ent.py @@ -193,7 +193,7 @@ ....: proof=proof) ....: q = next_prime(ZZ.random_element(2**(bits//2 +1)), ....: proof=proof) -....: if (p != q): break +....: if (p != q and p > 2 and q > 2): break ....: n = p * q ....: phi_n = (p-1) * (q-1) ....: while True: diff --git a/src/sage/topology/simplicial_set_examples.py b/src/sage/topology/simplicial_set_examples.py index 2bb46ac1f5a..1fc85df3f6e 100644 --- a/src/sage/topology/simplicial_set_examples.py +++ b/src/sage/topology/simplicial_set_examples.py @@ -684,7 +684,7 @@ def simplicial_data_from_kenzo_output(filename): for s in [_.strip() for _ in simplex_string.split('Simplex : ')]: if s: - name, face_str = [_.strip() for _ in s.split('Faces : ')] + name, face_str = (_.strip() for _ in s.split('Faces : ')) face_str = face_str.strip('()') face_str = face_str.split('