passagemath-categories 10.6.32__cp314-cp314t-musllinux_1_2_aarch64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- passagemath_categories-10.6.32.dist-info/METADATA +156 -0
- passagemath_categories-10.6.32.dist-info/RECORD +719 -0
- passagemath_categories-10.6.32.dist-info/WHEEL +5 -0
- passagemath_categories-10.6.32.dist-info/top_level.txt +2 -0
- passagemath_categories.libs/libgcc_s-2d945d6c.so.1 +0 -0
- passagemath_categories.libs/libgmp-28992bcb.so.10.5.0 +0 -0
- passagemath_categories.libs/libstdc++-85f2cd6d.so.6.0.33 +0 -0
- sage/all__sagemath_categories.py +28 -0
- sage/arith/all.py +38 -0
- sage/arith/constants.pxd +27 -0
- sage/arith/functions.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/arith/functions.pxd +4 -0
- sage/arith/functions.pyx +221 -0
- sage/arith/misc.py +6552 -0
- sage/arith/multi_modular.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/arith/multi_modular.pxd +39 -0
- sage/arith/multi_modular.pyx +994 -0
- sage/arith/rational_reconstruction.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/arith/rational_reconstruction.pxd +4 -0
- sage/arith/rational_reconstruction.pyx +115 -0
- sage/arith/srange.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/arith/srange.pyx +571 -0
- sage/calculus/all__sagemath_categories.py +2 -0
- sage/calculus/functional.py +481 -0
- sage/calculus/functions.py +151 -0
- sage/categories/additive_groups.py +73 -0
- sage/categories/additive_magmas.py +1044 -0
- sage/categories/additive_monoids.py +114 -0
- sage/categories/additive_semigroups.py +184 -0
- sage/categories/affine_weyl_groups.py +238 -0
- sage/categories/algebra_ideals.py +95 -0
- sage/categories/algebra_modules.py +96 -0
- sage/categories/algebras.py +349 -0
- sage/categories/algebras_with_basis.py +377 -0
- sage/categories/all.py +160 -0
- sage/categories/aperiodic_semigroups.py +29 -0
- sage/categories/associative_algebras.py +47 -0
- sage/categories/bialgebras.py +101 -0
- sage/categories/bialgebras_with_basis.py +414 -0
- sage/categories/bimodules.py +206 -0
- sage/categories/chain_complexes.py +268 -0
- sage/categories/classical_crystals.py +480 -0
- sage/categories/coalgebras.py +405 -0
- sage/categories/coalgebras_with_basis.py +232 -0
- sage/categories/coercion_methods.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/categories/coercion_methods.pyx +52 -0
- sage/categories/commutative_additive_groups.py +104 -0
- sage/categories/commutative_additive_monoids.py +45 -0
- sage/categories/commutative_additive_semigroups.py +48 -0
- sage/categories/commutative_algebra_ideals.py +87 -0
- sage/categories/commutative_algebras.py +94 -0
- sage/categories/commutative_ring_ideals.py +58 -0
- sage/categories/commutative_rings.py +736 -0
- sage/categories/complete_discrete_valuation.py +293 -0
- sage/categories/complex_reflection_groups.py +145 -0
- sage/categories/complex_reflection_or_generalized_coxeter_groups.py +1249 -0
- sage/categories/coxeter_group_algebras.py +186 -0
- sage/categories/coxeter_groups.py +3402 -0
- sage/categories/crystals.py +2628 -0
- sage/categories/cw_complexes.py +216 -0
- sage/categories/dedekind_domains.py +137 -0
- sage/categories/discrete_valuation.py +325 -0
- sage/categories/distributive_magmas_and_additive_magmas.py +100 -0
- sage/categories/division_rings.py +114 -0
- sage/categories/domains.py +95 -0
- sage/categories/drinfeld_modules.py +789 -0
- sage/categories/dual.py +42 -0
- sage/categories/enumerated_sets.py +1146 -0
- sage/categories/euclidean_domains.py +271 -0
- sage/categories/examples/algebras_with_basis.py +102 -0
- sage/categories/examples/all.py +1 -0
- sage/categories/examples/commutative_additive_monoids.py +130 -0
- sage/categories/examples/commutative_additive_semigroups.py +199 -0
- sage/categories/examples/coxeter_groups.py +8 -0
- sage/categories/examples/crystals.py +236 -0
- sage/categories/examples/cw_complexes.py +163 -0
- sage/categories/examples/facade_sets.py +187 -0
- sage/categories/examples/filtered_algebras_with_basis.py +204 -0
- sage/categories/examples/filtered_modules_with_basis.py +154 -0
- sage/categories/examples/finite_coxeter_groups.py +252 -0
- sage/categories/examples/finite_dimensional_algebras_with_basis.py +148 -0
- sage/categories/examples/finite_dimensional_lie_algebras_with_basis.py +495 -0
- sage/categories/examples/finite_enumerated_sets.py +208 -0
- sage/categories/examples/finite_monoids.py +150 -0
- sage/categories/examples/finite_semigroups.py +190 -0
- sage/categories/examples/finite_weyl_groups.py +191 -0
- sage/categories/examples/graded_connected_hopf_algebras_with_basis.py +152 -0
- sage/categories/examples/graded_modules_with_basis.py +168 -0
- sage/categories/examples/graphs.py +122 -0
- sage/categories/examples/hopf_algebras_with_basis.py +145 -0
- sage/categories/examples/infinite_enumerated_sets.py +190 -0
- sage/categories/examples/lie_algebras.py +352 -0
- sage/categories/examples/lie_algebras_with_basis.py +196 -0
- sage/categories/examples/magmas.py +162 -0
- sage/categories/examples/manifolds.py +94 -0
- sage/categories/examples/monoids.py +144 -0
- sage/categories/examples/posets.py +178 -0
- sage/categories/examples/semigroups.py +580 -0
- sage/categories/examples/semigroups_cython.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/categories/examples/semigroups_cython.pyx +221 -0
- sage/categories/examples/semirings.py +249 -0
- sage/categories/examples/sets_cat.py +706 -0
- sage/categories/examples/sets_with_grading.py +101 -0
- sage/categories/examples/with_realizations.py +542 -0
- sage/categories/fields.py +991 -0
- sage/categories/filtered_algebras.py +63 -0
- sage/categories/filtered_algebras_with_basis.py +548 -0
- sage/categories/filtered_hopf_algebras_with_basis.py +138 -0
- sage/categories/filtered_modules.py +210 -0
- sage/categories/filtered_modules_with_basis.py +1209 -0
- sage/categories/finite_complex_reflection_groups.py +1506 -0
- sage/categories/finite_coxeter_groups.py +1138 -0
- sage/categories/finite_crystals.py +103 -0
- sage/categories/finite_dimensional_algebras_with_basis.py +1860 -0
- sage/categories/finite_dimensional_bialgebras_with_basis.py +33 -0
- sage/categories/finite_dimensional_coalgebras_with_basis.py +33 -0
- sage/categories/finite_dimensional_graded_lie_algebras_with_basis.py +231 -0
- sage/categories/finite_dimensional_hopf_algebras_with_basis.py +38 -0
- sage/categories/finite_dimensional_lie_algebras_with_basis.py +2774 -0
- sage/categories/finite_dimensional_modules_with_basis.py +1407 -0
- sage/categories/finite_dimensional_nilpotent_lie_algebras_with_basis.py +167 -0
- sage/categories/finite_dimensional_semisimple_algebras_with_basis.py +270 -0
- sage/categories/finite_enumerated_sets.py +769 -0
- sage/categories/finite_fields.py +252 -0
- sage/categories/finite_groups.py +256 -0
- sage/categories/finite_lattice_posets.py +242 -0
- sage/categories/finite_monoids.py +316 -0
- sage/categories/finite_permutation_groups.py +339 -0
- sage/categories/finite_posets.py +1994 -0
- sage/categories/finite_semigroups.py +136 -0
- sage/categories/finite_sets.py +93 -0
- sage/categories/finite_weyl_groups.py +39 -0
- sage/categories/finitely_generated_lambda_bracket_algebras.py +112 -0
- sage/categories/finitely_generated_lie_conformal_algebras.py +114 -0
- sage/categories/finitely_generated_magmas.py +57 -0
- sage/categories/finitely_generated_semigroups.py +214 -0
- sage/categories/function_fields.py +76 -0
- sage/categories/g_sets.py +77 -0
- sage/categories/gcd_domains.py +65 -0
- sage/categories/generalized_coxeter_groups.py +94 -0
- sage/categories/graded_algebras.py +85 -0
- sage/categories/graded_algebras_with_basis.py +258 -0
- sage/categories/graded_bialgebras.py +32 -0
- sage/categories/graded_bialgebras_with_basis.py +32 -0
- sage/categories/graded_coalgebras.py +65 -0
- sage/categories/graded_coalgebras_with_basis.py +51 -0
- sage/categories/graded_hopf_algebras.py +41 -0
- sage/categories/graded_hopf_algebras_with_basis.py +169 -0
- sage/categories/graded_lie_algebras.py +91 -0
- sage/categories/graded_lie_algebras_with_basis.py +44 -0
- sage/categories/graded_lie_conformal_algebras.py +74 -0
- sage/categories/graded_modules.py +133 -0
- sage/categories/graded_modules_with_basis.py +329 -0
- sage/categories/graphs.py +138 -0
- sage/categories/group_algebras.py +430 -0
- sage/categories/groupoid.py +94 -0
- sage/categories/groups.py +667 -0
- sage/categories/h_trivial_semigroups.py +64 -0
- sage/categories/hecke_modules.py +185 -0
- sage/categories/highest_weight_crystals.py +980 -0
- sage/categories/hopf_algebras.py +219 -0
- sage/categories/hopf_algebras_with_basis.py +309 -0
- sage/categories/infinite_enumerated_sets.py +115 -0
- sage/categories/integral_domains.py +203 -0
- sage/categories/j_trivial_semigroups.py +29 -0
- sage/categories/kac_moody_algebras.py +82 -0
- sage/categories/kahler_algebras.py +203 -0
- sage/categories/l_trivial_semigroups.py +63 -0
- sage/categories/lambda_bracket_algebras.py +280 -0
- sage/categories/lambda_bracket_algebras_with_basis.py +107 -0
- sage/categories/lattice_posets.py +89 -0
- sage/categories/left_modules.py +49 -0
- sage/categories/lie_algebras.py +1070 -0
- sage/categories/lie_algebras_with_basis.py +261 -0
- sage/categories/lie_conformal_algebras.py +350 -0
- sage/categories/lie_conformal_algebras_with_basis.py +147 -0
- sage/categories/lie_groups.py +73 -0
- sage/categories/loop_crystals.py +1290 -0
- sage/categories/magmas.py +1189 -0
- sage/categories/magmas_and_additive_magmas.py +149 -0
- sage/categories/magmatic_algebras.py +365 -0
- sage/categories/manifolds.py +352 -0
- sage/categories/matrix_algebras.py +40 -0
- sage/categories/metric_spaces.py +387 -0
- sage/categories/modular_abelian_varieties.py +78 -0
- sage/categories/modules.py +989 -0
- sage/categories/modules_with_basis.py +2794 -0
- sage/categories/monoid_algebras.py +38 -0
- sage/categories/monoids.py +739 -0
- sage/categories/noetherian_rings.py +87 -0
- sage/categories/number_fields.py +242 -0
- sage/categories/ore_modules.py +189 -0
- sage/categories/partially_ordered_monoids.py +49 -0
- sage/categories/permutation_groups.py +63 -0
- sage/categories/pointed_sets.py +42 -0
- sage/categories/polyhedra.py +74 -0
- sage/categories/poor_man_map.py +270 -0
- sage/categories/posets.py +722 -0
- sage/categories/principal_ideal_domains.py +270 -0
- sage/categories/quantum_group_representations.py +543 -0
- sage/categories/quotient_fields.py +728 -0
- sage/categories/r_trivial_semigroups.py +45 -0
- sage/categories/regular_crystals.py +898 -0
- sage/categories/regular_supercrystals.py +170 -0
- sage/categories/right_modules.py +49 -0
- sage/categories/ring_ideals.py +74 -0
- sage/categories/rings.py +1904 -0
- sage/categories/rngs.py +175 -0
- sage/categories/schemes.py +393 -0
- sage/categories/semigroups.py +1060 -0
- sage/categories/semirings.py +71 -0
- sage/categories/semisimple_algebras.py +114 -0
- sage/categories/sets_with_grading.py +235 -0
- sage/categories/shephard_groups.py +43 -0
- sage/categories/signed_tensor.py +120 -0
- sage/categories/simplicial_complexes.py +134 -0
- sage/categories/simplicial_sets.py +1206 -0
- sage/categories/super_algebras.py +149 -0
- sage/categories/super_algebras_with_basis.py +144 -0
- sage/categories/super_hopf_algebras_with_basis.py +126 -0
- sage/categories/super_lie_conformal_algebras.py +193 -0
- sage/categories/super_modules.py +229 -0
- sage/categories/super_modules_with_basis.py +193 -0
- sage/categories/supercommutative_algebras.py +99 -0
- sage/categories/supercrystals.py +406 -0
- sage/categories/tensor.py +110 -0
- sage/categories/topological_spaces.py +170 -0
- sage/categories/triangular_kac_moody_algebras.py +439 -0
- sage/categories/tutorial.py +58 -0
- sage/categories/unique_factorization_domains.py +318 -0
- sage/categories/unital_algebras.py +426 -0
- sage/categories/vector_bundles.py +159 -0
- sage/categories/vector_spaces.py +357 -0
- sage/categories/weyl_groups.py +853 -0
- sage/combinat/all__sagemath_categories.py +34 -0
- sage/combinat/backtrack.py +180 -0
- sage/combinat/combinat.py +2269 -0
- sage/combinat/combinat_cython.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/combinat/combinat_cython.pxd +6 -0
- sage/combinat/combinat_cython.pyx +390 -0
- sage/combinat/combination.py +796 -0
- sage/combinat/combinatorial_map.py +416 -0
- sage/combinat/composition.py +2192 -0
- sage/combinat/dlx.py +510 -0
- sage/combinat/integer_lists/__init__.py +7 -0
- sage/combinat/integer_lists/base.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/combinat/integer_lists/base.pxd +16 -0
- sage/combinat/integer_lists/base.pyx +713 -0
- sage/combinat/integer_lists/invlex.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/combinat/integer_lists/invlex.pxd +4 -0
- sage/combinat/integer_lists/invlex.pyx +1650 -0
- sage/combinat/integer_lists/lists.py +328 -0
- sage/combinat/integer_lists/nn.py +48 -0
- sage/combinat/integer_vector.py +1818 -0
- sage/combinat/integer_vector_weighted.py +413 -0
- sage/combinat/matrices/all__sagemath_categories.py +5 -0
- sage/combinat/matrices/dancing_links.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/combinat/matrices/dancing_links.pyx +1159 -0
- sage/combinat/matrices/dancing_links_c.h +380 -0
- sage/combinat/matrices/dlxcpp.py +136 -0
- sage/combinat/partition.py +10070 -0
- sage/combinat/partitions.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/combinat/partitions.pyx +743 -0
- sage/combinat/permutation.py +10168 -0
- sage/combinat/permutation_cython.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/combinat/permutation_cython.pxd +11 -0
- sage/combinat/permutation_cython.pyx +407 -0
- sage/combinat/q_analogues.py +1090 -0
- sage/combinat/ranker.py +268 -0
- sage/combinat/subset.py +1561 -0
- sage/combinat/subsets_hereditary.py +202 -0
- sage/combinat/subsets_pairwise.py +184 -0
- sage/combinat/tools.py +63 -0
- sage/combinat/tuple.py +348 -0
- sage/data_structures/all.py +2 -0
- sage/data_structures/all__sagemath_categories.py +2 -0
- sage/data_structures/binary_matrix.pxd +138 -0
- sage/data_structures/binary_search.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/data_structures/binary_search.pxd +3 -0
- sage/data_structures/binary_search.pyx +66 -0
- sage/data_structures/bitset.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/data_structures/bitset.pxd +40 -0
- sage/data_structures/bitset.pyx +2385 -0
- sage/data_structures/bitset_base.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/data_structures/bitset_base.pxd +926 -0
- sage/data_structures/bitset_base.pyx +117 -0
- sage/data_structures/bitset_intrinsics.h +487 -0
- sage/data_structures/blas_dict.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/data_structures/blas_dict.pxd +12 -0
- sage/data_structures/blas_dict.pyx +469 -0
- sage/data_structures/list_of_pairs.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/data_structures/list_of_pairs.pxd +16 -0
- sage/data_structures/list_of_pairs.pyx +122 -0
- sage/data_structures/mutable_poset.py +3312 -0
- sage/data_structures/pairing_heap.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/data_structures/pairing_heap.h +346 -0
- sage/data_structures/pairing_heap.pxd +88 -0
- sage/data_structures/pairing_heap.pyx +1464 -0
- sage/data_structures/sparse_bitset.pxd +62 -0
- sage/data_structures/stream.py +5070 -0
- sage/databases/all__sagemath_categories.py +7 -0
- sage/databases/sql_db.py +2236 -0
- sage/ext/all__sagemath_categories.py +3 -0
- sage/ext/fast_callable.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/ext/fast_callable.pxd +4 -0
- sage/ext/fast_callable.pyx +2746 -0
- sage/ext/fast_eval.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/ext/fast_eval.pxd +1 -0
- sage/ext/fast_eval.pyx +102 -0
- sage/ext/interpreters/__init__.py +1 -0
- sage/ext/interpreters/all__sagemath_categories.py +2 -0
- sage/ext/interpreters/wrapper_el.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/ext/interpreters/wrapper_el.pxd +18 -0
- sage/ext/interpreters/wrapper_el.pyx +148 -0
- sage/ext/interpreters/wrapper_py.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/ext/interpreters/wrapper_py.pxd +17 -0
- sage/ext/interpreters/wrapper_py.pyx +133 -0
- sage/functions/airy.py +937 -0
- sage/functions/all.py +97 -0
- sage/functions/bessel.py +2102 -0
- sage/functions/error.py +784 -0
- sage/functions/exp_integral.py +1529 -0
- sage/functions/gamma.py +1087 -0
- sage/functions/generalized.py +672 -0
- sage/functions/hyperbolic.py +747 -0
- sage/functions/hypergeometric.py +1156 -0
- sage/functions/jacobi.py +1705 -0
- sage/functions/log.py +1402 -0
- sage/functions/min_max.py +338 -0
- sage/functions/orthogonal_polys.py +3106 -0
- sage/functions/other.py +2303 -0
- sage/functions/piecewise.py +1505 -0
- sage/functions/prime_pi.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/functions/prime_pi.pyx +262 -0
- sage/functions/special.py +1212 -0
- sage/functions/spike_function.py +278 -0
- sage/functions/transcendental.py +690 -0
- sage/functions/trig.py +1062 -0
- sage/functions/wigner.py +726 -0
- sage/geometry/abc.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/geometry/abc.pyx +82 -0
- sage/geometry/all__sagemath_categories.py +1 -0
- sage/groups/all__sagemath_categories.py +11 -0
- sage/groups/generic.py +1733 -0
- sage/groups/groups_catalog.py +113 -0
- sage/groups/perm_gps/all__sagemath_categories.py +1 -0
- sage/groups/perm_gps/partn_ref/all.py +1 -0
- sage/groups/perm_gps/partn_ref/all__sagemath_categories.py +1 -0
- sage/groups/perm_gps/partn_ref/automorphism_group_canonical_label.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/groups/perm_gps/partn_ref/automorphism_group_canonical_label.pxd +52 -0
- sage/groups/perm_gps/partn_ref/automorphism_group_canonical_label.pyx +906 -0
- sage/groups/perm_gps/partn_ref/canonical_augmentation.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/groups/perm_gps/partn_ref/canonical_augmentation.pxd +85 -0
- sage/groups/perm_gps/partn_ref/canonical_augmentation.pyx +534 -0
- sage/groups/perm_gps/partn_ref/data_structures.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/groups/perm_gps/partn_ref/data_structures.pxd +576 -0
- sage/groups/perm_gps/partn_ref/data_structures.pyx +1792 -0
- sage/groups/perm_gps/partn_ref/double_coset.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/groups/perm_gps/partn_ref/double_coset.pxd +45 -0
- sage/groups/perm_gps/partn_ref/double_coset.pyx +739 -0
- sage/groups/perm_gps/partn_ref/refinement_lists.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/groups/perm_gps/partn_ref/refinement_lists.pxd +18 -0
- sage/groups/perm_gps/partn_ref/refinement_lists.pyx +82 -0
- sage/groups/perm_gps/partn_ref/refinement_python.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/groups/perm_gps/partn_ref/refinement_python.pxd +16 -0
- sage/groups/perm_gps/partn_ref/refinement_python.pyx +564 -0
- sage/groups/perm_gps/partn_ref/refinement_sets.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/groups/perm_gps/partn_ref/refinement_sets.pxd +60 -0
- sage/groups/perm_gps/partn_ref/refinement_sets.pyx +858 -0
- sage/interfaces/abc.py +140 -0
- sage/interfaces/all.py +58 -0
- sage/interfaces/all__sagemath_categories.py +1 -0
- sage/interfaces/expect.py +1643 -0
- sage/interfaces/interface.py +1682 -0
- sage/interfaces/process.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/interfaces/process.pxd +5 -0
- sage/interfaces/process.pyx +288 -0
- sage/interfaces/quit.py +167 -0
- sage/interfaces/sage0.py +604 -0
- sage/interfaces/sagespawn.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/interfaces/sagespawn.pyx +308 -0
- sage/interfaces/tab_completion.py +101 -0
- sage/misc/all__sagemath_categories.py +78 -0
- sage/misc/allocator.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/misc/allocator.pxd +6 -0
- sage/misc/allocator.pyx +47 -0
- sage/misc/binary_tree.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/misc/binary_tree.pxd +29 -0
- sage/misc/binary_tree.pyx +537 -0
- sage/misc/callable_dict.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/misc/callable_dict.pyx +89 -0
- sage/misc/citation.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/misc/citation.pyx +159 -0
- sage/misc/converting_dict.py +293 -0
- sage/misc/defaults.py +129 -0
- sage/misc/derivative.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/misc/derivative.pyx +223 -0
- sage/misc/functional.py +2005 -0
- sage/misc/html.py +589 -0
- sage/misc/latex.py +2673 -0
- sage/misc/latex_macros.py +236 -0
- sage/misc/latex_standalone.py +1833 -0
- sage/misc/map_threaded.py +38 -0
- sage/misc/mathml.py +76 -0
- sage/misc/method_decorator.py +88 -0
- sage/misc/mrange.py +755 -0
- sage/misc/multireplace.py +41 -0
- sage/misc/object_multiplexer.py +92 -0
- sage/misc/parser.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/misc/parser.pyx +1107 -0
- sage/misc/random_testing.py +264 -0
- sage/misc/rest_index_of_methods.py +377 -0
- sage/misc/search.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/misc/search.pxd +2 -0
- sage/misc/search.pyx +68 -0
- sage/misc/stopgap.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/misc/stopgap.pyx +95 -0
- sage/misc/table.py +853 -0
- sage/monoids/all__sagemath_categories.py +1 -0
- sage/monoids/indexed_free_monoid.py +1071 -0
- sage/monoids/monoid.py +82 -0
- sage/numerical/all__sagemath_categories.py +1 -0
- sage/numerical/backends/all__sagemath_categories.py +1 -0
- sage/numerical/backends/generic_backend.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/numerical/backends/generic_backend.pxd +61 -0
- sage/numerical/backends/generic_backend.pyx +1893 -0
- sage/numerical/backends/generic_sdp_backend.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/numerical/backends/generic_sdp_backend.pxd +38 -0
- sage/numerical/backends/generic_sdp_backend.pyx +755 -0
- sage/parallel/all.py +6 -0
- sage/parallel/decorate.py +575 -0
- sage/parallel/map_reduce.py +1997 -0
- sage/parallel/multiprocessing_sage.py +76 -0
- sage/parallel/ncpus.py +35 -0
- sage/parallel/parallelism.py +364 -0
- sage/parallel/reference.py +47 -0
- sage/parallel/use_fork.py +333 -0
- sage/rings/abc.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/abc.pxd +31 -0
- sage/rings/abc.pyx +526 -0
- sage/rings/algebraic_closure_finite_field.py +1154 -0
- sage/rings/all__sagemath_categories.py +91 -0
- sage/rings/big_oh.py +227 -0
- sage/rings/continued_fraction.py +2754 -0
- sage/rings/continued_fraction_gosper.py +220 -0
- sage/rings/factorint.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/factorint.pyx +295 -0
- sage/rings/fast_arith.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/fast_arith.pxd +21 -0
- sage/rings/fast_arith.pyx +535 -0
- sage/rings/finite_rings/all__sagemath_categories.py +9 -0
- sage/rings/finite_rings/conway_polynomials.py +542 -0
- sage/rings/finite_rings/element_base.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/finite_rings/element_base.pxd +12 -0
- sage/rings/finite_rings/element_base.pyx +1176 -0
- sage/rings/finite_rings/finite_field_base.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/finite_rings/finite_field_base.pxd +7 -0
- sage/rings/finite_rings/finite_field_base.pyx +2171 -0
- sage/rings/finite_rings/finite_field_constructor.py +827 -0
- sage/rings/finite_rings/finite_field_prime_modn.py +372 -0
- sage/rings/finite_rings/galois_group.py +154 -0
- sage/rings/finite_rings/hom_finite_field.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/finite_rings/hom_finite_field.pxd +23 -0
- sage/rings/finite_rings/hom_finite_field.pyx +856 -0
- sage/rings/finite_rings/hom_prime_finite_field.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/finite_rings/hom_prime_finite_field.pxd +15 -0
- sage/rings/finite_rings/hom_prime_finite_field.pyx +164 -0
- sage/rings/finite_rings/homset.py +357 -0
- sage/rings/finite_rings/integer_mod.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/finite_rings/integer_mod.pxd +56 -0
- sage/rings/finite_rings/integer_mod.pyx +4586 -0
- sage/rings/finite_rings/integer_mod_limits.h +11 -0
- sage/rings/finite_rings/integer_mod_ring.py +2044 -0
- sage/rings/finite_rings/residue_field.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/finite_rings/residue_field.pxd +30 -0
- sage/rings/finite_rings/residue_field.pyx +1811 -0
- sage/rings/finite_rings/stdint.pxd +19 -0
- sage/rings/fraction_field.py +1452 -0
- sage/rings/fraction_field_element.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/fraction_field_element.pyx +1357 -0
- sage/rings/function_field/all.py +7 -0
- sage/rings/function_field/all__sagemath_categories.py +2 -0
- sage/rings/function_field/constructor.py +218 -0
- sage/rings/function_field/element.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/function_field/element.pxd +11 -0
- sage/rings/function_field/element.pyx +1008 -0
- sage/rings/function_field/element_rational.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/function_field/element_rational.pyx +513 -0
- sage/rings/function_field/extensions.py +230 -0
- sage/rings/function_field/function_field.py +1468 -0
- sage/rings/function_field/function_field_rational.py +1005 -0
- sage/rings/function_field/ideal.py +1155 -0
- sage/rings/function_field/ideal_rational.py +629 -0
- sage/rings/function_field/jacobian_base.py +826 -0
- sage/rings/function_field/jacobian_hess.py +1053 -0
- sage/rings/function_field/jacobian_khuri_makdisi.py +1027 -0
- sage/rings/function_field/maps.py +1039 -0
- sage/rings/function_field/order.py +281 -0
- sage/rings/function_field/order_basis.py +586 -0
- sage/rings/function_field/order_rational.py +576 -0
- sage/rings/function_field/place.py +426 -0
- sage/rings/function_field/place_rational.py +181 -0
- sage/rings/generic.py +320 -0
- sage/rings/homset.py +332 -0
- sage/rings/ideal.py +1885 -0
- sage/rings/ideal_monoid.py +215 -0
- sage/rings/infinity.py +1890 -0
- sage/rings/integer.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/integer.pxd +45 -0
- sage/rings/integer.pyx +7874 -0
- sage/rings/integer_ring.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/integer_ring.pxd +8 -0
- sage/rings/integer_ring.pyx +1693 -0
- sage/rings/laurent_series_ring.py +931 -0
- sage/rings/laurent_series_ring_element.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/laurent_series_ring_element.pxd +11 -0
- sage/rings/laurent_series_ring_element.pyx +1927 -0
- sage/rings/lazy_series.py +7815 -0
- sage/rings/lazy_series_ring.py +4356 -0
- sage/rings/localization.py +1043 -0
- sage/rings/morphism.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/morphism.pxd +39 -0
- sage/rings/morphism.pyx +3299 -0
- sage/rings/multi_power_series_ring.py +1145 -0
- sage/rings/multi_power_series_ring_element.py +2184 -0
- sage/rings/noncommutative_ideals.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/noncommutative_ideals.pyx +423 -0
- sage/rings/number_field/all__sagemath_categories.py +1 -0
- sage/rings/number_field/number_field_base.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/number_field/number_field_base.pxd +8 -0
- sage/rings/number_field/number_field_base.pyx +507 -0
- sage/rings/number_field/number_field_element_base.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/number_field/number_field_element_base.pxd +6 -0
- sage/rings/number_field/number_field_element_base.pyx +36 -0
- sage/rings/number_field/number_field_ideal.py +3550 -0
- sage/rings/padics/all__sagemath_categories.py +4 -0
- sage/rings/padics/local_generic.py +1670 -0
- sage/rings/padics/local_generic_element.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/padics/local_generic_element.pxd +5 -0
- sage/rings/padics/local_generic_element.pyx +1017 -0
- sage/rings/padics/misc.py +256 -0
- sage/rings/padics/padic_generic.py +1911 -0
- sage/rings/padics/pow_computer.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/padics/pow_computer.pxd +38 -0
- sage/rings/padics/pow_computer.pyx +671 -0
- sage/rings/padics/precision_error.py +24 -0
- sage/rings/polynomial/all__sagemath_categories.py +25 -0
- sage/rings/polynomial/commutative_polynomial.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/polynomial/commutative_polynomial.pxd +6 -0
- sage/rings/polynomial/commutative_polynomial.pyx +24 -0
- sage/rings/polynomial/cyclotomic.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/polynomial/cyclotomic.pyx +404 -0
- sage/rings/polynomial/flatten.py +711 -0
- sage/rings/polynomial/ideal.py +102 -0
- sage/rings/polynomial/infinite_polynomial_element.py +1768 -0
- sage/rings/polynomial/infinite_polynomial_ring.py +1653 -0
- sage/rings/polynomial/laurent_polynomial.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/polynomial/laurent_polynomial.pxd +18 -0
- sage/rings/polynomial/laurent_polynomial.pyx +2190 -0
- sage/rings/polynomial/laurent_polynomial_ideal.py +590 -0
- sage/rings/polynomial/laurent_polynomial_ring.py +832 -0
- sage/rings/polynomial/laurent_polynomial_ring_base.py +708 -0
- sage/rings/polynomial/multi_polynomial.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/polynomial/multi_polynomial.pxd +12 -0
- sage/rings/polynomial/multi_polynomial.pyx +3082 -0
- sage/rings/polynomial/multi_polynomial_element.py +2570 -0
- sage/rings/polynomial/multi_polynomial_ideal.py +5771 -0
- sage/rings/polynomial/multi_polynomial_ring.py +947 -0
- sage/rings/polynomial/multi_polynomial_ring_base.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/polynomial/multi_polynomial_ring_base.pxd +15 -0
- sage/rings/polynomial/multi_polynomial_ring_base.pyx +1855 -0
- sage/rings/polynomial/multi_polynomial_sequence.py +2204 -0
- sage/rings/polynomial/polydict.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/polynomial/polydict.pxd +45 -0
- sage/rings/polynomial/polydict.pyx +2701 -0
- sage/rings/polynomial/polynomial_compiled.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/polynomial/polynomial_compiled.pxd +59 -0
- sage/rings/polynomial/polynomial_compiled.pyx +509 -0
- sage/rings/polynomial/polynomial_element.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/polynomial/polynomial_element.pxd +64 -0
- sage/rings/polynomial/polynomial_element.pyx +13255 -0
- sage/rings/polynomial/polynomial_element_generic.py +1637 -0
- sage/rings/polynomial/polynomial_fateman.py +97 -0
- sage/rings/polynomial/polynomial_quotient_ring.py +2465 -0
- sage/rings/polynomial/polynomial_quotient_ring_element.py +779 -0
- sage/rings/polynomial/polynomial_ring.py +3784 -0
- sage/rings/polynomial/polynomial_ring_constructor.py +1051 -0
- sage/rings/polynomial/polynomial_ring_homomorphism.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/polynomial/polynomial_ring_homomorphism.pxd +5 -0
- sage/rings/polynomial/polynomial_ring_homomorphism.pyx +121 -0
- sage/rings/polynomial/polynomial_singular_interface.py +549 -0
- sage/rings/polynomial/symmetric_ideal.py +989 -0
- sage/rings/polynomial/symmetric_reduction.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/polynomial/symmetric_reduction.pxd +8 -0
- sage/rings/polynomial/symmetric_reduction.pyx +669 -0
- sage/rings/polynomial/term_order.py +2279 -0
- sage/rings/polynomial/toy_buchberger.py +449 -0
- sage/rings/polynomial/toy_d_basis.py +387 -0
- sage/rings/polynomial/toy_variety.py +362 -0
- sage/rings/power_series_mpoly.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/power_series_mpoly.pxd +9 -0
- sage/rings/power_series_mpoly.pyx +161 -0
- sage/rings/power_series_poly.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/power_series_poly.pxd +10 -0
- sage/rings/power_series_poly.pyx +1317 -0
- sage/rings/power_series_ring.py +1441 -0
- sage/rings/power_series_ring_element.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/power_series_ring_element.pxd +12 -0
- sage/rings/power_series_ring_element.pyx +3028 -0
- sage/rings/puiseux_series_ring.py +487 -0
- sage/rings/puiseux_series_ring_element.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/puiseux_series_ring_element.pxd +7 -0
- sage/rings/puiseux_series_ring_element.pyx +1055 -0
- sage/rings/qqbar_decorators.py +167 -0
- sage/rings/quotient_ring.py +1598 -0
- sage/rings/quotient_ring_element.py +979 -0
- sage/rings/rational.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/rational.pxd +20 -0
- sage/rings/rational.pyx +4284 -0
- sage/rings/rational_field.py +1730 -0
- sage/rings/real_double.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/real_double.pxd +16 -0
- sage/rings/real_double.pyx +2218 -0
- sage/rings/real_lazy.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/real_lazy.pxd +30 -0
- sage/rings/real_lazy.pyx +1773 -0
- sage/rings/ring.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/ring.pxd +30 -0
- sage/rings/ring.pyx +850 -0
- sage/rings/semirings/all.py +3 -0
- sage/rings/semirings/non_negative_integer_semiring.py +107 -0
- sage/rings/semirings/tropical_mpolynomial.py +972 -0
- sage/rings/semirings/tropical_polynomial.py +997 -0
- sage/rings/semirings/tropical_semiring.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/semirings/tropical_semiring.pyx +676 -0
- sage/rings/semirings/tropical_variety.py +1701 -0
- sage/rings/sum_of_squares.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/rings/sum_of_squares.pxd +3 -0
- sage/rings/sum_of_squares.pyx +336 -0
- sage/rings/tests.py +504 -0
- sage/schemes/affine/affine_homset.py +508 -0
- sage/schemes/affine/affine_morphism.py +1574 -0
- sage/schemes/affine/affine_point.py +460 -0
- sage/schemes/affine/affine_rational_point.py +308 -0
- sage/schemes/affine/affine_space.py +1264 -0
- sage/schemes/affine/affine_subscheme.py +592 -0
- sage/schemes/affine/all.py +25 -0
- sage/schemes/all__sagemath_categories.py +5 -0
- sage/schemes/generic/algebraic_scheme.py +2092 -0
- sage/schemes/generic/all.py +5 -0
- sage/schemes/generic/ambient_space.py +400 -0
- sage/schemes/generic/divisor.py +465 -0
- sage/schemes/generic/divisor_group.py +313 -0
- sage/schemes/generic/glue.py +84 -0
- sage/schemes/generic/homset.py +820 -0
- sage/schemes/generic/hypersurface.py +234 -0
- sage/schemes/generic/morphism.py +2107 -0
- sage/schemes/generic/point.py +237 -0
- sage/schemes/generic/scheme.py +1190 -0
- sage/schemes/generic/spec.py +199 -0
- sage/schemes/product_projective/all.py +6 -0
- sage/schemes/product_projective/homset.py +236 -0
- sage/schemes/product_projective/morphism.py +517 -0
- sage/schemes/product_projective/point.py +568 -0
- sage/schemes/product_projective/rational_point.py +550 -0
- sage/schemes/product_projective/space.py +1301 -0
- sage/schemes/product_projective/subscheme.py +466 -0
- sage/schemes/projective/all.py +24 -0
- sage/schemes/projective/proj_bdd_height.py +453 -0
- sage/schemes/projective/projective_homset.py +718 -0
- sage/schemes/projective/projective_morphism.py +2792 -0
- sage/schemes/projective/projective_point.py +1484 -0
- sage/schemes/projective/projective_rational_point.py +569 -0
- sage/schemes/projective/projective_space.py +2571 -0
- sage/schemes/projective/projective_subscheme.py +1574 -0
- sage/sets/all.py +17 -0
- sage/sets/cartesian_product.py +376 -0
- sage/sets/condition_set.py +525 -0
- sage/sets/disjoint_set.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/sets/disjoint_set.pxd +36 -0
- sage/sets/disjoint_set.pyx +998 -0
- sage/sets/disjoint_union_enumerated_sets.py +625 -0
- sage/sets/family.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/sets/family.pxd +12 -0
- sage/sets/family.pyx +1556 -0
- sage/sets/finite_enumerated_set.py +406 -0
- sage/sets/finite_set_map_cy.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/sets/finite_set_map_cy.pxd +34 -0
- sage/sets/finite_set_map_cy.pyx +708 -0
- sage/sets/finite_set_maps.py +591 -0
- sage/sets/image_set.py +448 -0
- sage/sets/integer_range.py +829 -0
- sage/sets/non_negative_integers.py +241 -0
- sage/sets/positive_integers.py +93 -0
- sage/sets/primes.py +188 -0
- sage/sets/real_set.py +2760 -0
- sage/sets/recursively_enumerated_set.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/sets/recursively_enumerated_set.pxd +31 -0
- sage/sets/recursively_enumerated_set.pyx +2082 -0
- sage/sets/set.py +2083 -0
- sage/sets/set_from_iterator.py +1021 -0
- sage/sets/totally_ordered_finite_set.py +329 -0
- sage/symbolic/all__sagemath_categories.py +1 -0
- sage/symbolic/function.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/symbolic/function.pxd +29 -0
- sage/symbolic/function.pyx +1488 -0
- sage/symbolic/symbols.py +56 -0
- sage/tests/all__sagemath_categories.py +1 -0
- sage/tests/cython.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/tests/cython.pyx +37 -0
- sage/tests/stl_vector.cpython-314t-aarch64-linux-musl.so +0 -0
- sage/tests/stl_vector.pyx +171 -0
- sage/typeset/all.py +6 -0
- sage/typeset/ascii_art.py +295 -0
- sage/typeset/character_art.py +789 -0
- sage/typeset/character_art_factory.py +572 -0
- sage/typeset/symbols.py +334 -0
- sage/typeset/unicode_art.py +183 -0
- sage/typeset/unicode_characters.py +101 -0
|
@@ -0,0 +1,1693 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-categories
|
|
2
|
+
r"""
|
|
3
|
+
Ring `\ZZ` of Integers
|
|
4
|
+
|
|
5
|
+
The :class:`IntegerRing_class` represents the ring `\ZZ` of (arbitrary
|
|
6
|
+
precision) integers. Each integer is an instance of :class:`Integer`,
|
|
7
|
+
which is defined in a Pyrex extension module that wraps GMP integers
|
|
8
|
+
(the ``mpz_t`` type in GMP).
|
|
9
|
+
|
|
10
|
+
::
|
|
11
|
+
|
|
12
|
+
sage: Z = IntegerRing(); Z
|
|
13
|
+
Integer Ring
|
|
14
|
+
sage: Z.characteristic()
|
|
15
|
+
0
|
|
16
|
+
sage: Z.is_field()
|
|
17
|
+
False
|
|
18
|
+
|
|
19
|
+
There is a unique instance of the :class:`integer ring<IntegerRing_class>`.
|
|
20
|
+
To create an :class:`Integer`, coerce either a Python int, long, or a string. Various
|
|
21
|
+
other types will also coerce to the integers, when it makes sense.
|
|
22
|
+
|
|
23
|
+
::
|
|
24
|
+
|
|
25
|
+
sage: a = Z(1234); a
|
|
26
|
+
1234
|
|
27
|
+
sage: b = Z(5678); b
|
|
28
|
+
5678
|
|
29
|
+
sage: type(a)
|
|
30
|
+
<class 'sage.rings.integer.Integer'>
|
|
31
|
+
sage: a + b
|
|
32
|
+
6912
|
|
33
|
+
sage: Z('94803849083985934859834583945394')
|
|
34
|
+
94803849083985934859834583945394
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
#*****************************************************************************
|
|
38
|
+
# Copyright (C) 2005 William Stein <wstein@gmail.com>
|
|
39
|
+
#
|
|
40
|
+
# This program is free software: you can redistribute it and/or modify
|
|
41
|
+
# it under the terms of the GNU General Public License as published by
|
|
42
|
+
# the Free Software Foundation, either version 2 of the License, or
|
|
43
|
+
# (at your option) any later version.
|
|
44
|
+
# http://www.gnu.org/licenses/
|
|
45
|
+
#*****************************************************************************
|
|
46
|
+
|
|
47
|
+
from cpython.long cimport *
|
|
48
|
+
from cpython.list cimport *
|
|
49
|
+
from cpython.object cimport Py_NE
|
|
50
|
+
|
|
51
|
+
from cysignals.signals cimport sig_check, sig_on, sig_off
|
|
52
|
+
|
|
53
|
+
from sage.libs.gmp.mpz cimport *
|
|
54
|
+
import sage.rings.infinity
|
|
55
|
+
import sage.rings.rational
|
|
56
|
+
import sage.rings.rational_field
|
|
57
|
+
import sage.rings.ideal
|
|
58
|
+
from sage.categories.basic import EuclideanDomains, DedekindDomains
|
|
59
|
+
from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets
|
|
60
|
+
from sage.categories.noetherian_rings import NoetherianRings
|
|
61
|
+
from sage.rings.number_field.number_field_element_base import NumberFieldElement_base
|
|
62
|
+
from sage.structure.coerce cimport is_numpy_type
|
|
63
|
+
from sage.structure.element cimport parent
|
|
64
|
+
from sage.structure.parent cimport Parent
|
|
65
|
+
from sage.structure.richcmp cimport rich_to_bool
|
|
66
|
+
|
|
67
|
+
from sage.misc.misc_c import prod
|
|
68
|
+
from sage.misc.randstate cimport randstate, current_randstate, SAGE_RAND_MAX
|
|
69
|
+
|
|
70
|
+
cimport sage.rings.integer as integer
|
|
71
|
+
|
|
72
|
+
from sage.rings import ring
|
|
73
|
+
|
|
74
|
+
arith = None
|
|
75
|
+
cdef void late_import() noexcept:
|
|
76
|
+
# A hack to avoid circular imports.
|
|
77
|
+
global arith
|
|
78
|
+
if arith is None:
|
|
79
|
+
import sage.arith.all
|
|
80
|
+
arith = sage.arith.all
|
|
81
|
+
|
|
82
|
+
cdef int number_of_integer_rings = 0
|
|
83
|
+
|
|
84
|
+
# Used by IntegerRing_class._randomize_mpz():
|
|
85
|
+
# When the user requests an integer sampled from a
|
|
86
|
+
# DiscreteGaussianDistributionIntegerSampler with parameter sigma, we store the pair
|
|
87
|
+
# (sigma, sampler) here. When the user requests an integer for the same
|
|
88
|
+
# sigma, we do not recreate the sampler but take it from this "cache".
|
|
89
|
+
_prev_discrete_gaussian_integer_sampler = (None, None)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def is_IntegerRing(x):
|
|
93
|
+
r"""
|
|
94
|
+
Internal function: return ``True`` iff ``x`` is the ring `\ZZ` of integers.
|
|
95
|
+
|
|
96
|
+
TESTS::
|
|
97
|
+
|
|
98
|
+
sage: from sage.rings.integer_ring import is_IntegerRing
|
|
99
|
+
sage: is_IntegerRing(ZZ)
|
|
100
|
+
doctest:warning...
|
|
101
|
+
DeprecationWarning: The function is_IntegerRing is deprecated;
|
|
102
|
+
use 'isinstance(..., IntegerRing_class)' instead.
|
|
103
|
+
See https://github.com/sagemath/sage/issues/38128 for details.
|
|
104
|
+
True
|
|
105
|
+
sage: is_IntegerRing(QQ)
|
|
106
|
+
False
|
|
107
|
+
sage: is_IntegerRing(parent(3))
|
|
108
|
+
True
|
|
109
|
+
sage: is_IntegerRing(parent(1/3))
|
|
110
|
+
False
|
|
111
|
+
"""
|
|
112
|
+
from sage.misc.superseded import deprecation_cython
|
|
113
|
+
deprecation_cython(38128,
|
|
114
|
+
"The function is_IntegerRing is deprecated; "
|
|
115
|
+
"use 'isinstance(..., IntegerRing_class)' instead.")
|
|
116
|
+
return isinstance(x, IntegerRing_class)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
cdef class IntegerRing_class(CommutativeRing):
|
|
120
|
+
r"""
|
|
121
|
+
The ring of integers.
|
|
122
|
+
|
|
123
|
+
In order to introduce the ring `\ZZ` of integers, we illustrate
|
|
124
|
+
creation, calling a few functions, and working with its elements.
|
|
125
|
+
|
|
126
|
+
::
|
|
127
|
+
|
|
128
|
+
sage: Z = IntegerRing(); Z
|
|
129
|
+
Integer Ring
|
|
130
|
+
sage: Z.characteristic()
|
|
131
|
+
0
|
|
132
|
+
sage: Z.is_field()
|
|
133
|
+
False
|
|
134
|
+
sage: Z.category()
|
|
135
|
+
Join of Category of Dedekind domains
|
|
136
|
+
and Category of euclidean domains
|
|
137
|
+
and Category of noetherian rings
|
|
138
|
+
and Category of infinite enumerated sets
|
|
139
|
+
and Category of metric spaces
|
|
140
|
+
sage: Z(2^(2^5) + 1)
|
|
141
|
+
4294967297
|
|
142
|
+
|
|
143
|
+
One can give strings to create integers. Strings starting with
|
|
144
|
+
``0x`` are interpreted as hexadecimal, and strings starting with
|
|
145
|
+
``0o`` are interpreted as octal::
|
|
146
|
+
|
|
147
|
+
sage: parent('37')
|
|
148
|
+
<... 'str'>
|
|
149
|
+
sage: parent(Z('37'))
|
|
150
|
+
Integer Ring
|
|
151
|
+
sage: Z('0x10')
|
|
152
|
+
16
|
|
153
|
+
sage: Z('0x1a')
|
|
154
|
+
26
|
|
155
|
+
sage: Z('0o20')
|
|
156
|
+
16
|
|
157
|
+
|
|
158
|
+
As an inverse to :meth:`~sage.rings.integer.Integer.digits`,
|
|
159
|
+
lists of digits are accepted, provided that you give a base.
|
|
160
|
+
The lists are interpreted in little-endian order, so that
|
|
161
|
+
entry ``i`` of the list is the coefficient of ``base^i``::
|
|
162
|
+
|
|
163
|
+
sage: Z([4,1,7], base=100)
|
|
164
|
+
70104
|
|
165
|
+
sage: Z([4,1,7], base=10)
|
|
166
|
+
714
|
|
167
|
+
sage: Z([3, 7], 10)
|
|
168
|
+
73
|
|
169
|
+
sage: Z([3, 7], 9)
|
|
170
|
+
66
|
|
171
|
+
sage: Z([], 10)
|
|
172
|
+
0
|
|
173
|
+
|
|
174
|
+
Alphanumeric strings can be used for bases 2..36; letters ``a`` to
|
|
175
|
+
``z`` represent numbers 10 to 36. Letter case does not matter.
|
|
176
|
+
::
|
|
177
|
+
|
|
178
|
+
sage: Z("sage", base=32)
|
|
179
|
+
928270
|
|
180
|
+
sage: Z("SAGE", base=32)
|
|
181
|
+
928270
|
|
182
|
+
sage: Z("Sage", base=32)
|
|
183
|
+
928270
|
|
184
|
+
sage: Z([14, 16, 10, 28], base=32)
|
|
185
|
+
928270
|
|
186
|
+
sage: 14 + 16*32 + 10*32^2 + 28*32^3
|
|
187
|
+
928270
|
|
188
|
+
|
|
189
|
+
We next illustrate basic arithmetic in `\ZZ`::
|
|
190
|
+
|
|
191
|
+
sage: a = Z(1234); a
|
|
192
|
+
1234
|
|
193
|
+
sage: b = Z(5678); b
|
|
194
|
+
5678
|
|
195
|
+
sage: type(a)
|
|
196
|
+
<class 'sage.rings.integer.Integer'>
|
|
197
|
+
sage: a + b
|
|
198
|
+
6912
|
|
199
|
+
sage: b + a
|
|
200
|
+
6912
|
|
201
|
+
sage: a * b
|
|
202
|
+
7006652
|
|
203
|
+
sage: b * a
|
|
204
|
+
7006652
|
|
205
|
+
sage: a - b
|
|
206
|
+
-4444
|
|
207
|
+
sage: b - a
|
|
208
|
+
4444
|
|
209
|
+
|
|
210
|
+
When we divide two integers using ``/``, the result is automatically
|
|
211
|
+
coerced to the field of rational numbers, even if the result is
|
|
212
|
+
an integer.
|
|
213
|
+
|
|
214
|
+
::
|
|
215
|
+
|
|
216
|
+
sage: a / b
|
|
217
|
+
617/2839
|
|
218
|
+
sage: type(a/b)
|
|
219
|
+
<class 'sage.rings.rational.Rational'>
|
|
220
|
+
sage: a/a
|
|
221
|
+
1
|
|
222
|
+
sage: type(a/a)
|
|
223
|
+
<class 'sage.rings.rational.Rational'>
|
|
224
|
+
|
|
225
|
+
For floor division, use the ``//`` operator instead::
|
|
226
|
+
|
|
227
|
+
sage: a // b
|
|
228
|
+
0
|
|
229
|
+
sage: type(a//b)
|
|
230
|
+
<class 'sage.rings.integer.Integer'>
|
|
231
|
+
|
|
232
|
+
Next we illustrate arithmetic with automatic coercion. The types
|
|
233
|
+
that coerce are: str, int, long, Integer.
|
|
234
|
+
|
|
235
|
+
::
|
|
236
|
+
|
|
237
|
+
sage: a + 17
|
|
238
|
+
1251
|
|
239
|
+
sage: a * 374
|
|
240
|
+
461516
|
|
241
|
+
sage: 374 * a
|
|
242
|
+
461516
|
|
243
|
+
sage: a/19
|
|
244
|
+
1234/19
|
|
245
|
+
sage: 0 + Z(-64)
|
|
246
|
+
-64
|
|
247
|
+
|
|
248
|
+
Integers can be coerced::
|
|
249
|
+
|
|
250
|
+
sage: a = Z(-64)
|
|
251
|
+
sage: int(a)
|
|
252
|
+
-64
|
|
253
|
+
|
|
254
|
+
We can create integers from several types of objects::
|
|
255
|
+
|
|
256
|
+
sage: Z(17/1)
|
|
257
|
+
17
|
|
258
|
+
sage: Z(Mod(19,23))
|
|
259
|
+
19
|
|
260
|
+
sage: Z(2 + 3*5 + O(5^3)) # needs sage.rings.padics
|
|
261
|
+
17
|
|
262
|
+
|
|
263
|
+
Arbitrary numeric bases are supported; strings or list of integers
|
|
264
|
+
are used to provide the digits (more details in
|
|
265
|
+
:class:`IntegerRing_class`)::
|
|
266
|
+
|
|
267
|
+
sage: Z("sage", base=32)
|
|
268
|
+
928270
|
|
269
|
+
sage: Z([14, 16, 10, 28], base=32)
|
|
270
|
+
928270
|
|
271
|
+
|
|
272
|
+
The :meth:`digits<~sage.rings.integer.Integer.digits>` method
|
|
273
|
+
allows you to get the list of digits of an integer in a different
|
|
274
|
+
basis (note that the digits are returned in little-endian order)::
|
|
275
|
+
|
|
276
|
+
sage: b = Z([4,1,7], base=100)
|
|
277
|
+
sage: b
|
|
278
|
+
70104
|
|
279
|
+
sage: b.digits(base=71)
|
|
280
|
+
[27, 64, 13]
|
|
281
|
+
|
|
282
|
+
sage: Z(15).digits(2)
|
|
283
|
+
[1, 1, 1, 1]
|
|
284
|
+
sage: Z(15).digits(3)
|
|
285
|
+
[0, 2, 1]
|
|
286
|
+
|
|
287
|
+
The :meth:`str<~sage.rings.integer.Integer.str>` method returns a
|
|
288
|
+
string of the digits, using letters ``a`` to ``z`` to represent
|
|
289
|
+
digits 10..36::
|
|
290
|
+
|
|
291
|
+
sage: Z(928270).str(base=32)
|
|
292
|
+
'sage'
|
|
293
|
+
|
|
294
|
+
Note that :meth:`str<~sage.rings.integer.Integer.str>` only works
|
|
295
|
+
with bases 2 through 36.
|
|
296
|
+
|
|
297
|
+
TESTS::
|
|
298
|
+
|
|
299
|
+
sage: TestSuite(ZZ).run()
|
|
300
|
+
sage: list(ZZ)
|
|
301
|
+
Traceback (most recent call last):
|
|
302
|
+
...
|
|
303
|
+
NotImplementedError: len() of an infinite set
|
|
304
|
+
|
|
305
|
+
sage: ZZ.is_finite()
|
|
306
|
+
False
|
|
307
|
+
sage: ZZ.cardinality()
|
|
308
|
+
+Infinity
|
|
309
|
+
"""
|
|
310
|
+
|
|
311
|
+
def __init__(self):
|
|
312
|
+
"""
|
|
313
|
+
Initialize ``self``.
|
|
314
|
+
|
|
315
|
+
TESTS::
|
|
316
|
+
|
|
317
|
+
sage: from sage.rings.integer_ring import IntegerRing_class
|
|
318
|
+
sage: A = IntegerRing_class()
|
|
319
|
+
|
|
320
|
+
We check that ``ZZ`` is an infinite enumerated set
|
|
321
|
+
(see :issue:`16239`)::
|
|
322
|
+
|
|
323
|
+
sage: A in InfiniteEnumeratedSets()
|
|
324
|
+
True
|
|
325
|
+
"""
|
|
326
|
+
cat = (EuclideanDomains(), DedekindDomains(),
|
|
327
|
+
InfiniteEnumeratedSets().Metric(), NoetherianRings())
|
|
328
|
+
Parent.__init__(self, base=self, names=('x',), normalize=False,
|
|
329
|
+
category=cat)
|
|
330
|
+
self._populate_coercion_lists_(init_no_parent=True,
|
|
331
|
+
convert_method_name='_integer_')
|
|
332
|
+
|
|
333
|
+
_element_constructor_ = integer.Integer
|
|
334
|
+
|
|
335
|
+
def __reduce__(self):
|
|
336
|
+
"""
|
|
337
|
+
For pickling.
|
|
338
|
+
|
|
339
|
+
TESTS::
|
|
340
|
+
|
|
341
|
+
sage: loads(dumps(ZZ)) is ZZ
|
|
342
|
+
True
|
|
343
|
+
"""
|
|
344
|
+
return IntegerRing, ()
|
|
345
|
+
|
|
346
|
+
def __hash__(self):
|
|
347
|
+
"""
|
|
348
|
+
Return the hash value of ``self``.
|
|
349
|
+
|
|
350
|
+
TESTS::
|
|
351
|
+
|
|
352
|
+
sage: from sage.rings.integer_ring import IntegerRing_class
|
|
353
|
+
sage: A = IntegerRing_class()
|
|
354
|
+
sage: A.__hash__()
|
|
355
|
+
554590422
|
|
356
|
+
"""
|
|
357
|
+
return 554590422
|
|
358
|
+
|
|
359
|
+
def __richcmp__(left, right, int op):
|
|
360
|
+
"""
|
|
361
|
+
Rich comparison of ``left`` and ``right``.
|
|
362
|
+
|
|
363
|
+
TESTS::
|
|
364
|
+
|
|
365
|
+
sage: from sage.rings.integer_ring import IntegerRing_class
|
|
366
|
+
sage: ZZ == ZZ
|
|
367
|
+
True
|
|
368
|
+
sage: ZZ != QQ
|
|
369
|
+
True
|
|
370
|
+
"""
|
|
371
|
+
if left is right:
|
|
372
|
+
return rich_to_bool(op, 0)
|
|
373
|
+
|
|
374
|
+
if isinstance(right, IntegerRing_class):
|
|
375
|
+
return rich_to_bool(op, 0)
|
|
376
|
+
|
|
377
|
+
if isinstance(right, sage.rings.rational_field.RationalField):
|
|
378
|
+
return rich_to_bool(op, -1)
|
|
379
|
+
|
|
380
|
+
return op == Py_NE
|
|
381
|
+
|
|
382
|
+
def _repr_(self):
|
|
383
|
+
"""
|
|
384
|
+
Return a string representation of ``self``.
|
|
385
|
+
|
|
386
|
+
TESTS::
|
|
387
|
+
|
|
388
|
+
sage: ZZ # indirect doctest
|
|
389
|
+
Integer Ring
|
|
390
|
+
"""
|
|
391
|
+
return "Integer Ring"
|
|
392
|
+
|
|
393
|
+
def _latex_(self):
|
|
394
|
+
r"""
|
|
395
|
+
Return a latex representation of ``self``.
|
|
396
|
+
|
|
397
|
+
TESTS::
|
|
398
|
+
|
|
399
|
+
sage: latex(ZZ) # indirect doctest
|
|
400
|
+
\Bold{Z}
|
|
401
|
+
"""
|
|
402
|
+
return "\\Bold{Z}"
|
|
403
|
+
|
|
404
|
+
def __getitem__(self, x):
|
|
405
|
+
r"""
|
|
406
|
+
Return the ring `\ZZ[...]` obtained by adjoining to the integers one
|
|
407
|
+
or several elements.
|
|
408
|
+
|
|
409
|
+
EXAMPLES::
|
|
410
|
+
|
|
411
|
+
sage: ZZ['x']
|
|
412
|
+
Univariate Polynomial Ring in x over Integer Ring
|
|
413
|
+
sage: ZZ['x,y']
|
|
414
|
+
Multivariate Polynomial Ring in x, y over Integer Ring
|
|
415
|
+
|
|
416
|
+
sage: # needs fpylll sage.rings.number_field sage.symbolic
|
|
417
|
+
sage: ZZ[sqrt(2), sqrt(3)]
|
|
418
|
+
Relative Order generated by [-sqrt3*sqrt2 + 3, 6*sqrt2 - 5*sqrt3, 11*sqrt2 - 9*sqrt3]
|
|
419
|
+
in Number Field in sqrt2 with defining polynomial x^2 - 2 over its base field
|
|
420
|
+
sage: R = ZZ[sqrt(5) + 1]; R
|
|
421
|
+
Order of conductor 2 generated by a in Number Field in a
|
|
422
|
+
with defining polynomial x^2 - 2*x - 4 with a = 3.236067977499790?
|
|
423
|
+
sage: R.is_maximal()
|
|
424
|
+
False
|
|
425
|
+
sage: R = ZZ[(1 + sqrt(5))/2]; R
|
|
426
|
+
Maximal Order generated by a in Number Field in a
|
|
427
|
+
with defining polynomial x^2 - x - 1 with a = 1.618033988749895?
|
|
428
|
+
sage: R.is_maximal()
|
|
429
|
+
True
|
|
430
|
+
"""
|
|
431
|
+
if x in self:
|
|
432
|
+
return self
|
|
433
|
+
|
|
434
|
+
if isinstance(x, NumberFieldElement_base):
|
|
435
|
+
K, _ = parent(x).subfield(x)
|
|
436
|
+
return K.order(K.gen())
|
|
437
|
+
|
|
438
|
+
return CommutativeRing.__getitem__(self, x)
|
|
439
|
+
|
|
440
|
+
def range(self, start, end=None, step=None):
|
|
441
|
+
"""
|
|
442
|
+
Optimized range function for Sage integers.
|
|
443
|
+
|
|
444
|
+
AUTHORS:
|
|
445
|
+
|
|
446
|
+
- Robert Bradshaw (2007-09-20)
|
|
447
|
+
|
|
448
|
+
EXAMPLES::
|
|
449
|
+
|
|
450
|
+
sage: ZZ.range(10)
|
|
451
|
+
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
452
|
+
sage: ZZ.range(-5, 5)
|
|
453
|
+
[-5, -4, -3, -2, -1, 0, 1, 2, 3, 4]
|
|
454
|
+
sage: ZZ.range(0, 50, 5)
|
|
455
|
+
[0, 5, 10, 15, 20, 25, 30, 35, 40, 45]
|
|
456
|
+
sage: ZZ.range(0, 50, -5)
|
|
457
|
+
[]
|
|
458
|
+
sage: ZZ.range(50, 0, -5)
|
|
459
|
+
[50, 45, 40, 35, 30, 25, 20, 15, 10, 5]
|
|
460
|
+
sage: ZZ.range(50, 0, 5)
|
|
461
|
+
[]
|
|
462
|
+
sage: ZZ.range(50, -1, -5)
|
|
463
|
+
[50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 0]
|
|
464
|
+
|
|
465
|
+
It uses different code if the step doesn't fit in a long::
|
|
466
|
+
|
|
467
|
+
sage: ZZ.range(0, 2^83, 2^80)
|
|
468
|
+
[0, 1208925819614629174706176, 2417851639229258349412352,
|
|
469
|
+
3626777458843887524118528, 4835703278458516698824704, 6044629098073145873530880,
|
|
470
|
+
7253554917687775048237056, 8462480737302404222943232]
|
|
471
|
+
|
|
472
|
+
Make sure :issue:`8818` is fixed::
|
|
473
|
+
|
|
474
|
+
sage: ZZ.range(1r, 10r)
|
|
475
|
+
[1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
476
|
+
"""
|
|
477
|
+
if end is None:
|
|
478
|
+
end = start
|
|
479
|
+
start = Integer.__new__(Integer)
|
|
480
|
+
if step is None:
|
|
481
|
+
step = 1
|
|
482
|
+
if type(step) is not int:
|
|
483
|
+
if not isinstance(step, integer.Integer):
|
|
484
|
+
step = integer.Integer(step)
|
|
485
|
+
if mpz_fits_slong_p((<Integer>step).value):
|
|
486
|
+
step = int(step)
|
|
487
|
+
if not isinstance(start, integer.Integer):
|
|
488
|
+
start = integer.Integer(start)
|
|
489
|
+
if not isinstance(end, integer.Integer):
|
|
490
|
+
end = integer.Integer(end)
|
|
491
|
+
cdef integer.Integer a = <Integer>start
|
|
492
|
+
cdef integer.Integer b = <Integer>end
|
|
493
|
+
|
|
494
|
+
cdef int step_sign
|
|
495
|
+
cdef long istep
|
|
496
|
+
cdef integer.Integer zstep, last
|
|
497
|
+
|
|
498
|
+
L = []
|
|
499
|
+
if type(step) is int:
|
|
500
|
+
istep = PyLong_AsLong(step)
|
|
501
|
+
step_sign = istep
|
|
502
|
+
else:
|
|
503
|
+
zstep = <Integer>step
|
|
504
|
+
step_sign = mpz_sgn(zstep.value)
|
|
505
|
+
|
|
506
|
+
sig_on()
|
|
507
|
+
while mpz_cmp(a.value, b.value)*step_sign < 0:
|
|
508
|
+
last = a
|
|
509
|
+
a = Integer.__new__(Integer)
|
|
510
|
+
if type(step) is int: # count on branch prediction...
|
|
511
|
+
if istep > 0:
|
|
512
|
+
mpz_add_ui(a.value, last.value, istep)
|
|
513
|
+
else:
|
|
514
|
+
mpz_sub_ui(a.value, last.value, -istep)
|
|
515
|
+
else:
|
|
516
|
+
mpz_add(a.value, last.value, zstep.value)
|
|
517
|
+
PyList_Append(L, last)
|
|
518
|
+
sig_off()
|
|
519
|
+
return L
|
|
520
|
+
|
|
521
|
+
def __iter__(self):
|
|
522
|
+
"""
|
|
523
|
+
Iterate over all integers: 0 1 -1 2 -2 3 -3 ...
|
|
524
|
+
|
|
525
|
+
EXAMPLES::
|
|
526
|
+
|
|
527
|
+
sage: for n in ZZ:
|
|
528
|
+
....: if n < 3: print(n)
|
|
529
|
+
....: else: break
|
|
530
|
+
0
|
|
531
|
+
1
|
|
532
|
+
-1
|
|
533
|
+
2
|
|
534
|
+
-2
|
|
535
|
+
"""
|
|
536
|
+
yield self(0)
|
|
537
|
+
n = self(1)
|
|
538
|
+
while True:
|
|
539
|
+
sig_check()
|
|
540
|
+
yield n
|
|
541
|
+
yield -n
|
|
542
|
+
n += 1
|
|
543
|
+
|
|
544
|
+
cpdef _coerce_map_from_(self, S):
|
|
545
|
+
r"""
|
|
546
|
+
``x`` canonically coerces to the integers `\ZZ` only if ``x``
|
|
547
|
+
is an int, long or already an element of `\ZZ`.
|
|
548
|
+
|
|
549
|
+
EXAMPLES::
|
|
550
|
+
|
|
551
|
+
sage: ZZ.coerce(int(5)) # indirect doctest
|
|
552
|
+
5
|
|
553
|
+
sage: ZZ.coerce(GF(7)(2))
|
|
554
|
+
Traceback (most recent call last):
|
|
555
|
+
...
|
|
556
|
+
TypeError: no canonical coercion from Finite Field of size 7 to Integer Ring
|
|
557
|
+
|
|
558
|
+
The rational number ``3/1 == 3`` does not canonically coerce into the
|
|
559
|
+
integers, since there is no canonical coercion map from the full
|
|
560
|
+
field of rational numbers to the integers.
|
|
561
|
+
|
|
562
|
+
::
|
|
563
|
+
|
|
564
|
+
sage: a = 3/1; parent(a)
|
|
565
|
+
Rational Field
|
|
566
|
+
sage: ZZ(a)
|
|
567
|
+
3
|
|
568
|
+
sage: ZZ.coerce(a)
|
|
569
|
+
Traceback (most recent call last):
|
|
570
|
+
...
|
|
571
|
+
TypeError: no canonical coercion from Rational Field to Integer Ring
|
|
572
|
+
|
|
573
|
+
Coercions are available from numpy integer types::
|
|
574
|
+
|
|
575
|
+
sage: # needs numpy
|
|
576
|
+
sage: import numpy
|
|
577
|
+
sage: ZZ.coerce(numpy.int8('1'))
|
|
578
|
+
1
|
|
579
|
+
sage: ZZ.coerce(numpy.int32('32'))
|
|
580
|
+
32
|
|
581
|
+
sage: ZZ.coerce(numpy.int64('-12'))
|
|
582
|
+
-12
|
|
583
|
+
sage: ZZ.coerce(numpy.uint64('11'))
|
|
584
|
+
11
|
|
585
|
+
|
|
586
|
+
TESTS::
|
|
587
|
+
|
|
588
|
+
sage: 5r + True
|
|
589
|
+
6
|
|
590
|
+
sage: 5 + True
|
|
591
|
+
6
|
|
592
|
+
|
|
593
|
+
sage: f = ZZ.coerce_map_from(int); f
|
|
594
|
+
Native morphism:
|
|
595
|
+
From: Set of Python objects of class 'int'
|
|
596
|
+
To: Integer Ring
|
|
597
|
+
sage: f(4r)
|
|
598
|
+
4
|
|
599
|
+
sage: f(-7r)
|
|
600
|
+
-7
|
|
601
|
+
"""
|
|
602
|
+
if S is int:
|
|
603
|
+
return sage.rings.integer.int_to_Z()
|
|
604
|
+
elif S is bool:
|
|
605
|
+
return True
|
|
606
|
+
elif is_numpy_type(S):
|
|
607
|
+
import numpy
|
|
608
|
+
if issubclass(S, numpy.integer):
|
|
609
|
+
return True
|
|
610
|
+
return None
|
|
611
|
+
|
|
612
|
+
def random_element(self, x=None, y=None, distribution=None):
|
|
613
|
+
r"""
|
|
614
|
+
Return a random integer.
|
|
615
|
+
|
|
616
|
+
INPUT:
|
|
617
|
+
|
|
618
|
+
- ``x``, ``y`` integers -- bounds for the result
|
|
619
|
+
|
|
620
|
+
- ``distribution`` -- string:
|
|
621
|
+
|
|
622
|
+
- ``'uniform'``
|
|
623
|
+
- ``'mpz_rrandomb'``
|
|
624
|
+
- ``'1/n'``
|
|
625
|
+
- ``'gaussian'``
|
|
626
|
+
|
|
627
|
+
OUTPUT: with no input, return a random integer
|
|
628
|
+
|
|
629
|
+
If only one integer `x` is given, return an integer
|
|
630
|
+
between 0 and `x-1`.
|
|
631
|
+
|
|
632
|
+
If two integers are given, return an integer
|
|
633
|
+
between `x` and `y-1` inclusive.
|
|
634
|
+
|
|
635
|
+
If at least one bound is given, the default distribution is the
|
|
636
|
+
uniform distribution; otherwise, it is the distribution described
|
|
637
|
+
below.
|
|
638
|
+
|
|
639
|
+
If the distribution ``'1/n'`` is specified, the bounds are ignored.
|
|
640
|
+
|
|
641
|
+
If the distribution ``'mpz_rrandomb'`` is specified, the output is
|
|
642
|
+
in the range from 0 to `2^x - 1`.
|
|
643
|
+
|
|
644
|
+
If the distribution ``'gaussian'`` is specified, the output is
|
|
645
|
+
sampled from a discrete Gaussian distribution with parameter
|
|
646
|
+
`\sigma=x` and centered at zero. That is, the integer `v` is returned
|
|
647
|
+
with probability proportional to `\mathrm{exp}(-v^2/(2\sigma^2))`.
|
|
648
|
+
See :mod:`sage.stats.distributions.discrete_gaussian_integer` for
|
|
649
|
+
details. Note that if many samples from the same discrete Gaussian
|
|
650
|
+
distribution are needed, it is faster to construct a
|
|
651
|
+
:class:`sage.stats.distributions.discrete_gaussian_integer.DiscreteGaussianDistributionIntegerSampler`
|
|
652
|
+
object which is then repeatedly queried.
|
|
653
|
+
|
|
654
|
+
The default distribution for ``ZZ.random_element()`` is based on
|
|
655
|
+
`X = \mbox{trunc}(4/(5R))`, where `R` is a random
|
|
656
|
+
variable uniformly distributed between `-1` and `1`. This gives
|
|
657
|
+
`\mbox{Pr}(X = 0) = 1/5`, and
|
|
658
|
+
`\mbox{Pr}(X = n) = 2/(5|n|(|n|+1))` for
|
|
659
|
+
`n \neq 0`. Most of the samples will be small; `-1`, `0`, and `1`
|
|
660
|
+
occur with probability `1/5` each. But we also have a small but
|
|
661
|
+
non-negligible proportion of "outliers";
|
|
662
|
+
`\mbox{Pr}(|X| \geq n) = 4/(5n)`, so for instance, we
|
|
663
|
+
expect that `|X| \geq 1000` on one in 1250 samples.
|
|
664
|
+
|
|
665
|
+
We actually use an easy-to-compute truncation of the above
|
|
666
|
+
distribution; the probabilities given above hold fairly well up to
|
|
667
|
+
about `|n| = 10000`, but around `|n| = 30000` some
|
|
668
|
+
values will never be returned at all, and we will never return
|
|
669
|
+
anything greater than `2^{30}`.
|
|
670
|
+
|
|
671
|
+
EXAMPLES::
|
|
672
|
+
|
|
673
|
+
sage: ZZ.random_element().parent() is ZZ
|
|
674
|
+
True
|
|
675
|
+
|
|
676
|
+
The default uniform distribution is integers in `[-2, 2]`::
|
|
677
|
+
|
|
678
|
+
sage: from collections import defaultdict
|
|
679
|
+
sage: def add_samples(*args, **kwds):
|
|
680
|
+
....: global dic, counter
|
|
681
|
+
....: for _ in range(100):
|
|
682
|
+
....: counter += 1
|
|
683
|
+
....: dic[ZZ.random_element(*args, **kwds)] += 1
|
|
684
|
+
|
|
685
|
+
sage: def prob(x):
|
|
686
|
+
....: return 1/5
|
|
687
|
+
sage: dic = defaultdict(Integer)
|
|
688
|
+
sage: counter = 0.0
|
|
689
|
+
sage: add_samples(distribution='uniform')
|
|
690
|
+
sage: while any(abs(dic[i]/counter - prob(i)) > 0.01 for i in dic):
|
|
691
|
+
....: add_samples(distribution='uniform')
|
|
692
|
+
|
|
693
|
+
Here we use the distribution ``'1/n'``::
|
|
694
|
+
|
|
695
|
+
sage: def prob(n):
|
|
696
|
+
....: if n == 0:
|
|
697
|
+
....: return 1/5
|
|
698
|
+
....: return 2/(5*abs(n)*(abs(n) + 1))
|
|
699
|
+
sage: dic = defaultdict(Integer)
|
|
700
|
+
sage: counter = 0.0
|
|
701
|
+
sage: add_samples(distribution='1/n')
|
|
702
|
+
sage: while any(abs(dic[i]/counter - prob(i)) > 0.01 for i in dic):
|
|
703
|
+
....: add_samples(distribution='1/n')
|
|
704
|
+
|
|
705
|
+
If a range is given, the default distribution is uniform in that
|
|
706
|
+
range::
|
|
707
|
+
|
|
708
|
+
sage: -10 <= ZZ.random_element(-10, 10) < 10
|
|
709
|
+
True
|
|
710
|
+
sage: def prob(x):
|
|
711
|
+
....: return 1/20
|
|
712
|
+
sage: dic = defaultdict(Integer)
|
|
713
|
+
sage: counter = 0.0
|
|
714
|
+
sage: add_samples(-10, 10)
|
|
715
|
+
sage: while any(abs(dic[i]/counter - prob(i)) > 0.01 for i in dic):
|
|
716
|
+
....: add_samples(-10, 10)
|
|
717
|
+
|
|
718
|
+
sage: 0 <= ZZ.random_element(5) < 5
|
|
719
|
+
True
|
|
720
|
+
sage: def prob(x):
|
|
721
|
+
....: return 1/5
|
|
722
|
+
sage: dic = defaultdict(Integer)
|
|
723
|
+
sage: counter = 0.0
|
|
724
|
+
sage: add_samples(5)
|
|
725
|
+
sage: while any(abs(dic[i]/counter - prob(i)) > 0.01 for i in dic):
|
|
726
|
+
....: add_samples(5)
|
|
727
|
+
|
|
728
|
+
sage: while ZZ.random_element(10^50) < 10^49:
|
|
729
|
+
....: pass
|
|
730
|
+
|
|
731
|
+
Notice that the right endpoint is not included::
|
|
732
|
+
|
|
733
|
+
sage: all(ZZ.random_element(-2, 2) < 2 for _ in range(100))
|
|
734
|
+
True
|
|
735
|
+
|
|
736
|
+
We return a sample from a discrete Gaussian distribution::
|
|
737
|
+
|
|
738
|
+
sage: ZZ.random_element(11.0, distribution='gaussian').parent() is ZZ # needs sage.modules
|
|
739
|
+
True
|
|
740
|
+
|
|
741
|
+
TESTS:
|
|
742
|
+
|
|
743
|
+
Check that :issue:`32124` is fixed::
|
|
744
|
+
|
|
745
|
+
sage: ZZ.random_element(5, -5, distribution='1/n').parent() is ZZ
|
|
746
|
+
True
|
|
747
|
+
sage: ZZ.random_element(5, -5, distribution='gaussian').parent() is ZZ # needs sage.modules
|
|
748
|
+
True
|
|
749
|
+
sage: ZZ.random_element(5, -5, distribution='mpz_rrandomb').parent() is ZZ
|
|
750
|
+
True
|
|
751
|
+
|
|
752
|
+
sage: ZZ.random_element(-10, -5, distribution='mpz_rrandomb')
|
|
753
|
+
Traceback (most recent call last):
|
|
754
|
+
...
|
|
755
|
+
TypeError: x must be > 0
|
|
756
|
+
sage: ZZ.random_element(-10, -5, distribution='gaussian')
|
|
757
|
+
Traceback (most recent call last):
|
|
758
|
+
...
|
|
759
|
+
TypeError: x must be > 0
|
|
760
|
+
|
|
761
|
+
Checking error messages::
|
|
762
|
+
|
|
763
|
+
sage: ZZ.random_element(-3)
|
|
764
|
+
Traceback (most recent call last):
|
|
765
|
+
...
|
|
766
|
+
TypeError: x must be > 0
|
|
767
|
+
sage: ZZ.random_element(4, 2)
|
|
768
|
+
Traceback (most recent call last):
|
|
769
|
+
...
|
|
770
|
+
TypeError: x must be < y
|
|
771
|
+
"""
|
|
772
|
+
cdef Integer z = Integer.__new__(Integer)
|
|
773
|
+
if distribution == "1/n":
|
|
774
|
+
x = None
|
|
775
|
+
y = None
|
|
776
|
+
elif distribution == "mpz_rrandomb" or distribution == "gaussian":
|
|
777
|
+
y = None
|
|
778
|
+
if x is not None and y is None and x <= 0:
|
|
779
|
+
raise TypeError("x must be > 0")
|
|
780
|
+
if x is not None and y is not None and x >= y:
|
|
781
|
+
raise TypeError("x must be < y")
|
|
782
|
+
self._randomize_mpz(z.value, x, y, distribution)
|
|
783
|
+
return z
|
|
784
|
+
|
|
785
|
+
cdef int _randomize_mpz(self, mpz_t value, x, y, distribution) except -1:
|
|
786
|
+
"""
|
|
787
|
+
This is an internal function, called by random_element.
|
|
788
|
+
|
|
789
|
+
INPUT:
|
|
790
|
+
|
|
791
|
+
- ``value`` -- this is the variable in which the answer will be
|
|
792
|
+
returned
|
|
793
|
+
|
|
794
|
+
- ``x``, ``y``, ``distribution`` -- see :meth:`random_element`
|
|
795
|
+
|
|
796
|
+
TESTS::
|
|
797
|
+
|
|
798
|
+
sage: ZZ.random_element() # indirect doctest # random
|
|
799
|
+
6
|
|
800
|
+
"""
|
|
801
|
+
cdef integer.Integer r
|
|
802
|
+
cdef integer.Integer n_max, n_min, n_width
|
|
803
|
+
cdef randstate rstate = current_randstate()
|
|
804
|
+
cdef int den = rstate.c_random()-SAGE_RAND_MAX/2
|
|
805
|
+
if den == 0:
|
|
806
|
+
den = 1
|
|
807
|
+
if (distribution is None and x is None) or distribution == "1/n":
|
|
808
|
+
mpz_set_si(value, (SAGE_RAND_MAX/5*2) / den)
|
|
809
|
+
elif distribution is None or distribution == "uniform":
|
|
810
|
+
if y is None:
|
|
811
|
+
if x is None:
|
|
812
|
+
mpz_set_si(value, rstate.c_random() % 5 - 2)
|
|
813
|
+
else:
|
|
814
|
+
n_max = x if isinstance(x, integer.Integer) else self(x)
|
|
815
|
+
mpz_urandomm(value, rstate.gmp_state, n_max.value)
|
|
816
|
+
else:
|
|
817
|
+
n_min = x if isinstance(x, integer.Integer) else self(x)
|
|
818
|
+
n_max = y if isinstance(y, integer.Integer) else self(y)
|
|
819
|
+
n_width = n_max - n_min
|
|
820
|
+
if mpz_sgn(n_width.value) <= 0:
|
|
821
|
+
n_min = self(-2)
|
|
822
|
+
n_width = self(5)
|
|
823
|
+
mpz_urandomm(value, rstate.gmp_state, n_width.value)
|
|
824
|
+
mpz_add(value, value, n_min.value)
|
|
825
|
+
elif distribution == "mpz_rrandomb":
|
|
826
|
+
if x is None:
|
|
827
|
+
raise ValueError("must specify x to use 'distribution=mpz_rrandomb'")
|
|
828
|
+
mpz_rrandomb(value, rstate.gmp_state, int(x))
|
|
829
|
+
elif distribution == "gaussian":
|
|
830
|
+
global _prev_discrete_gaussian_integer_sampler
|
|
831
|
+
if x == _prev_discrete_gaussian_integer_sampler[0]:
|
|
832
|
+
r = _prev_discrete_gaussian_integer_sampler[1]()
|
|
833
|
+
else:
|
|
834
|
+
from sage.stats.distributions.discrete_gaussian_integer import DiscreteGaussianDistributionIntegerSampler
|
|
835
|
+
D = DiscreteGaussianDistributionIntegerSampler(sigma=x, algorithm='uniform+logtable')
|
|
836
|
+
r = D()
|
|
837
|
+
_prev_discrete_gaussian_integer_sampler = (x, D)
|
|
838
|
+
mpz_set(value, r.value)
|
|
839
|
+
else:
|
|
840
|
+
raise ValueError("Unknown distribution for the integers: %s" % distribution)
|
|
841
|
+
|
|
842
|
+
def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None):
|
|
843
|
+
r"""
|
|
844
|
+
Test whether the map from `\ZZ` to codomain, which takes the
|
|
845
|
+
generator of `\ZZ` to ``im_gens[0]``, is a ring homomorphism.
|
|
846
|
+
(This amounts to checking that 1 goes to 1.)
|
|
847
|
+
|
|
848
|
+
TESTS::
|
|
849
|
+
|
|
850
|
+
sage: ZZ._is_valid_homomorphism_(ZZ,[1])
|
|
851
|
+
True
|
|
852
|
+
sage: ZZ._is_valid_homomorphism_(ZZ,[2])
|
|
853
|
+
False
|
|
854
|
+
sage: ZZ._is_valid_homomorphism_(ZZ.quotient_ring(8), [ZZ.quotient_ring(8)(1)])
|
|
855
|
+
True
|
|
856
|
+
"""
|
|
857
|
+
if base_map is None:
|
|
858
|
+
base_map = codomain.coerce_map_from(self)
|
|
859
|
+
if base_map is None:
|
|
860
|
+
return False
|
|
861
|
+
try:
|
|
862
|
+
return im_gens[0] == base_map(self.gen(0))
|
|
863
|
+
except TypeError:
|
|
864
|
+
return False
|
|
865
|
+
|
|
866
|
+
def _repr_option(self, key):
|
|
867
|
+
"""
|
|
868
|
+
Metadata about the :meth:`_repr_` output.
|
|
869
|
+
|
|
870
|
+
See :meth:`sage.structure.parent._repr_option` for details.
|
|
871
|
+
|
|
872
|
+
EXAMPLES::
|
|
873
|
+
|
|
874
|
+
sage: ZZ._repr_option('element_is_atomic')
|
|
875
|
+
True
|
|
876
|
+
"""
|
|
877
|
+
if key == 'element_is_atomic':
|
|
878
|
+
return True
|
|
879
|
+
return super()._repr_option(key)
|
|
880
|
+
|
|
881
|
+
def is_field(self, proof=True):
|
|
882
|
+
"""
|
|
883
|
+
Return ``False`` since the integers are not a field.
|
|
884
|
+
|
|
885
|
+
EXAMPLES::
|
|
886
|
+
|
|
887
|
+
sage: ZZ.is_field()
|
|
888
|
+
False
|
|
889
|
+
"""
|
|
890
|
+
return False
|
|
891
|
+
|
|
892
|
+
def fraction_field(self):
|
|
893
|
+
"""
|
|
894
|
+
Return the field of rational numbers - the fraction field of the
|
|
895
|
+
integers.
|
|
896
|
+
|
|
897
|
+
EXAMPLES::
|
|
898
|
+
|
|
899
|
+
sage: ZZ.fraction_field()
|
|
900
|
+
Rational Field
|
|
901
|
+
sage: ZZ.fraction_field() == QQ
|
|
902
|
+
True
|
|
903
|
+
"""
|
|
904
|
+
return sage.rings.rational_field.Q
|
|
905
|
+
|
|
906
|
+
def extension(self, poly, names, **kwds):
|
|
907
|
+
"""
|
|
908
|
+
Return the order generated by the specified list of polynomials.
|
|
909
|
+
|
|
910
|
+
INPUT:
|
|
911
|
+
|
|
912
|
+
- ``poly`` -- list of one or more polynomials
|
|
913
|
+
|
|
914
|
+
- ``names`` -- a parameter which will be passed to
|
|
915
|
+
:func:`EquationOrder`
|
|
916
|
+
|
|
917
|
+
- ``embedding`` -- a parameter which will be passed to
|
|
918
|
+
:func:`EquationOrder`
|
|
919
|
+
|
|
920
|
+
OUTPUT:
|
|
921
|
+
|
|
922
|
+
- Given a single polynomial as input, return the order generated by a
|
|
923
|
+
root of the polynomial in the field generated by a root of the
|
|
924
|
+
polynomial.
|
|
925
|
+
|
|
926
|
+
Given a list of polynomials as input, return the relative order
|
|
927
|
+
generated by a root of the first polynomial in the list, over the
|
|
928
|
+
order generated by the roots of the subsequent polynomials.
|
|
929
|
+
|
|
930
|
+
EXAMPLES::
|
|
931
|
+
|
|
932
|
+
sage: x = polygen(ZZ, 'x')
|
|
933
|
+
sage: ZZ.extension(x^2 - 5, 'a') # needs sage.rings.number_field
|
|
934
|
+
Order of conductor 2 generated by a in Number Field in a with defining polynomial x^2 - 5
|
|
935
|
+
sage: ZZ.extension([x^2 + 1, x^2 + 2], 'a,b') # needs sage.rings.number_field
|
|
936
|
+
Relative Order generated by [-b*a - 1, -3*a + 2*b] in Number Field in a
|
|
937
|
+
with defining polynomial x^2 + 1 over its base field
|
|
938
|
+
"""
|
|
939
|
+
from sage.rings.number_field.order import EquationOrder
|
|
940
|
+
return EquationOrder(poly, names=names, **kwds)
|
|
941
|
+
|
|
942
|
+
def quotient(self, I, names=None, **kwds):
|
|
943
|
+
r"""
|
|
944
|
+
Return the quotient of `\ZZ` by the ideal or integer ``I``.
|
|
945
|
+
|
|
946
|
+
EXAMPLES::
|
|
947
|
+
|
|
948
|
+
sage: ZZ.quo(6*ZZ)
|
|
949
|
+
Ring of integers modulo 6
|
|
950
|
+
sage: ZZ.quo(0*ZZ)
|
|
951
|
+
Integer Ring
|
|
952
|
+
sage: ZZ.quo(3)
|
|
953
|
+
Ring of integers modulo 3
|
|
954
|
+
sage: ZZ.quo(3*QQ)
|
|
955
|
+
Traceback (most recent call last):
|
|
956
|
+
...
|
|
957
|
+
TypeError: I must be an ideal of ZZ
|
|
958
|
+
"""
|
|
959
|
+
if isinstance(I, sage.rings.integer.Integer):
|
|
960
|
+
n = I
|
|
961
|
+
elif isinstance(I, sage.rings.ideal.Ideal_generic):
|
|
962
|
+
if not (I.ring() is self):
|
|
963
|
+
raise TypeError("I must be an ideal of ZZ")
|
|
964
|
+
n = I.gens()[0]
|
|
965
|
+
else:
|
|
966
|
+
raise TypeError("I must be an ideal of ZZ or an integer")
|
|
967
|
+
if n == 0:
|
|
968
|
+
return self
|
|
969
|
+
return sage.rings.finite_rings.integer_mod_ring.IntegerModRing(n, **kwds)
|
|
970
|
+
|
|
971
|
+
def residue_field(self, prime, check=True, names=None):
|
|
972
|
+
r"""
|
|
973
|
+
Return the residue field of the integers modulo the given prime, i.e.
|
|
974
|
+
`\ZZ/p\ZZ`.
|
|
975
|
+
|
|
976
|
+
INPUT:
|
|
977
|
+
|
|
978
|
+
- ``prime`` -- a prime number
|
|
979
|
+
|
|
980
|
+
- ``check`` -- boolean (default: ``True``); whether or not
|
|
981
|
+
to check the primality of prime
|
|
982
|
+
|
|
983
|
+
- ``names`` -- ignored (for compatibility with number fields)
|
|
984
|
+
|
|
985
|
+
OUTPUT: the residue field at this prime
|
|
986
|
+
|
|
987
|
+
EXAMPLES::
|
|
988
|
+
|
|
989
|
+
sage: # needs sage.libs.pari
|
|
990
|
+
sage: F = ZZ.residue_field(61); F
|
|
991
|
+
Residue field of Integers modulo 61
|
|
992
|
+
sage: pi = F.reduction_map(); pi
|
|
993
|
+
Partially defined reduction map:
|
|
994
|
+
From: Rational Field
|
|
995
|
+
To: Residue field of Integers modulo 61
|
|
996
|
+
sage: pi(123/234)
|
|
997
|
+
6
|
|
998
|
+
sage: pi(1/61)
|
|
999
|
+
Traceback (most recent call last):
|
|
1000
|
+
...
|
|
1001
|
+
ZeroDivisionError: Cannot reduce rational 1/61 modulo 61:
|
|
1002
|
+
it has negative valuation
|
|
1003
|
+
sage: lift = F.lift_map(); lift
|
|
1004
|
+
Lifting map:
|
|
1005
|
+
From: Residue field of Integers modulo 61
|
|
1006
|
+
To: Integer Ring
|
|
1007
|
+
sage: lift(F(12345/67890))
|
|
1008
|
+
33
|
|
1009
|
+
sage: (12345/67890) % 61
|
|
1010
|
+
33
|
|
1011
|
+
|
|
1012
|
+
Construction can be from a prime ideal instead of a prime::
|
|
1013
|
+
|
|
1014
|
+
sage: ZZ.residue_field(ZZ.ideal(97))
|
|
1015
|
+
Residue field of Integers modulo 97
|
|
1016
|
+
|
|
1017
|
+
TESTS::
|
|
1018
|
+
|
|
1019
|
+
sage: ZZ.residue_field(ZZ.ideal(96))
|
|
1020
|
+
Traceback (most recent call last):
|
|
1021
|
+
...
|
|
1022
|
+
TypeError: Principal ideal (96) of Integer Ring is not prime
|
|
1023
|
+
sage: ZZ.residue_field(96)
|
|
1024
|
+
Traceback (most recent call last):
|
|
1025
|
+
...
|
|
1026
|
+
TypeError: 96 is not prime
|
|
1027
|
+
"""
|
|
1028
|
+
if isinstance(prime, sage.rings.integer.Integer):
|
|
1029
|
+
p = self.ideal(prime)
|
|
1030
|
+
elif isinstance(prime, sage.rings.ideal.Ideal_generic):
|
|
1031
|
+
if not (prime.ring() is self):
|
|
1032
|
+
raise TypeError("%s is not an ideal of ZZ" % prime)
|
|
1033
|
+
p = prime
|
|
1034
|
+
else:
|
|
1035
|
+
raise TypeError("%s is neither an ideal of ZZ nor an integer" % prime)
|
|
1036
|
+
if check and not p.is_prime():
|
|
1037
|
+
raise TypeError("%s is not prime" % prime)
|
|
1038
|
+
from sage.rings.finite_rings.residue_field import ResidueField
|
|
1039
|
+
return ResidueField(p, names = None, check = check)
|
|
1040
|
+
|
|
1041
|
+
def gens(self) -> tuple:
|
|
1042
|
+
"""
|
|
1043
|
+
Return the tuple ``(1,)`` containing a single element, the additive
|
|
1044
|
+
generator of the integers, which is 1.
|
|
1045
|
+
|
|
1046
|
+
EXAMPLES::
|
|
1047
|
+
|
|
1048
|
+
sage: ZZ.gens(); ZZ.gens()[0]
|
|
1049
|
+
(1,)
|
|
1050
|
+
1
|
|
1051
|
+
sage: type(ZZ.gens()[0])
|
|
1052
|
+
<class 'sage.rings.integer.Integer'>
|
|
1053
|
+
"""
|
|
1054
|
+
return (self(1), )
|
|
1055
|
+
|
|
1056
|
+
def gen(self, n=0):
|
|
1057
|
+
"""
|
|
1058
|
+
Return the additive generator of the integers, which is 1.
|
|
1059
|
+
|
|
1060
|
+
INPUT:
|
|
1061
|
+
|
|
1062
|
+
- ``n`` -- (default: 0) in a ring with more than one generator, the
|
|
1063
|
+
optional parameter `n` indicates which generator to return; since
|
|
1064
|
+
there is only one generator in this case, the only valid value for
|
|
1065
|
+
`n` is 0
|
|
1066
|
+
|
|
1067
|
+
EXAMPLES::
|
|
1068
|
+
|
|
1069
|
+
sage: ZZ.gen()
|
|
1070
|
+
1
|
|
1071
|
+
sage: type(ZZ.gen())
|
|
1072
|
+
<class 'sage.rings.integer.Integer'>
|
|
1073
|
+
"""
|
|
1074
|
+
if n == 0:
|
|
1075
|
+
return self(1)
|
|
1076
|
+
else:
|
|
1077
|
+
raise IndexError("n must be 0")
|
|
1078
|
+
|
|
1079
|
+
def ngens(self):
|
|
1080
|
+
"""
|
|
1081
|
+
Return the number of additive generators of the ring, which is 1.
|
|
1082
|
+
|
|
1083
|
+
EXAMPLES::
|
|
1084
|
+
|
|
1085
|
+
sage: ZZ.ngens()
|
|
1086
|
+
1
|
|
1087
|
+
sage: len(ZZ.gens())
|
|
1088
|
+
1
|
|
1089
|
+
"""
|
|
1090
|
+
return 1
|
|
1091
|
+
|
|
1092
|
+
def degree(self):
|
|
1093
|
+
"""
|
|
1094
|
+
Return the degree of the integers, which is 1.
|
|
1095
|
+
|
|
1096
|
+
Here, degree refers to the rank of the ring as a module over the
|
|
1097
|
+
integers.
|
|
1098
|
+
|
|
1099
|
+
EXAMPLES::
|
|
1100
|
+
|
|
1101
|
+
sage: ZZ.degree()
|
|
1102
|
+
1
|
|
1103
|
+
"""
|
|
1104
|
+
return 1
|
|
1105
|
+
|
|
1106
|
+
def absolute_degree(self):
|
|
1107
|
+
"""
|
|
1108
|
+
Return the absolute degree of the integers, which is 1.
|
|
1109
|
+
|
|
1110
|
+
Here, absolute degree refers to the rank of the ring as a module
|
|
1111
|
+
over the integers.
|
|
1112
|
+
|
|
1113
|
+
EXAMPLES::
|
|
1114
|
+
|
|
1115
|
+
sage: ZZ.absolute_degree()
|
|
1116
|
+
1
|
|
1117
|
+
"""
|
|
1118
|
+
return 1
|
|
1119
|
+
|
|
1120
|
+
def characteristic(self):
|
|
1121
|
+
"""
|
|
1122
|
+
Return the characteristic of the integers, which is 0.
|
|
1123
|
+
|
|
1124
|
+
EXAMPLES::
|
|
1125
|
+
|
|
1126
|
+
sage: ZZ.characteristic()
|
|
1127
|
+
0
|
|
1128
|
+
"""
|
|
1129
|
+
return ZZ.zero()
|
|
1130
|
+
|
|
1131
|
+
def krull_dimension(self):
|
|
1132
|
+
"""
|
|
1133
|
+
Return the Krull dimension of the integers, which is 1.
|
|
1134
|
+
|
|
1135
|
+
.. NOTE::
|
|
1136
|
+
|
|
1137
|
+
This should rather be inherited from the category
|
|
1138
|
+
of ``DedekindDomains``.
|
|
1139
|
+
|
|
1140
|
+
EXAMPLES::
|
|
1141
|
+
|
|
1142
|
+
sage: ZZ.krull_dimension()
|
|
1143
|
+
1
|
|
1144
|
+
"""
|
|
1145
|
+
return 1
|
|
1146
|
+
|
|
1147
|
+
def completion(self, p, prec, extras={}):
|
|
1148
|
+
r"""
|
|
1149
|
+
Return the metric completion of the integers at the prime `p`.
|
|
1150
|
+
|
|
1151
|
+
INPUT:
|
|
1152
|
+
|
|
1153
|
+
- ``p`` -- a prime (or ``infinity``)
|
|
1154
|
+
|
|
1155
|
+
- ``prec`` -- the desired precision
|
|
1156
|
+
|
|
1157
|
+
- ``extras`` -- any further parameters to pass to the method used to
|
|
1158
|
+
create the completion
|
|
1159
|
+
|
|
1160
|
+
OUTPUT: the completion of `\ZZ` at `p`
|
|
1161
|
+
|
|
1162
|
+
EXAMPLES::
|
|
1163
|
+
|
|
1164
|
+
sage: ZZ.completion(infinity, 53)
|
|
1165
|
+
Integer Ring
|
|
1166
|
+
sage: ZZ.completion(5, 15, {'print_mode': 'bars'}) # needs sage.rings.padics
|
|
1167
|
+
5-adic Ring with capped relative precision 15
|
|
1168
|
+
"""
|
|
1169
|
+
if p == sage.rings.infinity.Infinity:
|
|
1170
|
+
return self
|
|
1171
|
+
else:
|
|
1172
|
+
from sage.rings.padics.factory import Zp
|
|
1173
|
+
return Zp(p, prec, **extras)
|
|
1174
|
+
|
|
1175
|
+
def order(self):
|
|
1176
|
+
"""
|
|
1177
|
+
Return the order (cardinality) of the integers, which is
|
|
1178
|
+
``+Infinity``.
|
|
1179
|
+
|
|
1180
|
+
EXAMPLES::
|
|
1181
|
+
|
|
1182
|
+
sage: ZZ.order()
|
|
1183
|
+
+Infinity
|
|
1184
|
+
"""
|
|
1185
|
+
return sage.rings.infinity.infinity
|
|
1186
|
+
|
|
1187
|
+
def zeta(self, n=2):
|
|
1188
|
+
r"""
|
|
1189
|
+
Return a primitive ``n``-th root of unity in the integers, or raise an
|
|
1190
|
+
error if none exists.
|
|
1191
|
+
|
|
1192
|
+
INPUT:
|
|
1193
|
+
|
|
1194
|
+
- ``n`` -- (default: 2) a positive integer
|
|
1195
|
+
|
|
1196
|
+
OUTPUT:
|
|
1197
|
+
|
|
1198
|
+
an ``n``-th root of unity in `\ZZ`
|
|
1199
|
+
|
|
1200
|
+
EXAMPLES::
|
|
1201
|
+
|
|
1202
|
+
sage: ZZ.zeta()
|
|
1203
|
+
-1
|
|
1204
|
+
sage: ZZ.zeta(1)
|
|
1205
|
+
1
|
|
1206
|
+
sage: ZZ.zeta(3)
|
|
1207
|
+
Traceback (most recent call last):
|
|
1208
|
+
...
|
|
1209
|
+
ValueError: no nth root of unity in integer ring
|
|
1210
|
+
sage: ZZ.zeta(0)
|
|
1211
|
+
Traceback (most recent call last):
|
|
1212
|
+
...
|
|
1213
|
+
ValueError: n must be positive in zeta()
|
|
1214
|
+
"""
|
|
1215
|
+
if n == 1:
|
|
1216
|
+
return sage.rings.integer.Integer(1)
|
|
1217
|
+
elif n == 2:
|
|
1218
|
+
return sage.rings.integer.Integer(-1)
|
|
1219
|
+
elif n < 1:
|
|
1220
|
+
raise ValueError("n must be positive in zeta()")
|
|
1221
|
+
else:
|
|
1222
|
+
raise ValueError("no nth root of unity in integer ring")
|
|
1223
|
+
|
|
1224
|
+
def parameter(self):
|
|
1225
|
+
r"""
|
|
1226
|
+
Return an integer of degree 1 for the Euclidean property of `\ZZ`,
|
|
1227
|
+
namely 1.
|
|
1228
|
+
|
|
1229
|
+
EXAMPLES::
|
|
1230
|
+
|
|
1231
|
+
sage: ZZ.parameter()
|
|
1232
|
+
1
|
|
1233
|
+
"""
|
|
1234
|
+
return self(1)
|
|
1235
|
+
|
|
1236
|
+
def _roots_univariate_polynomial(self, p, ring=None, multiplicities=True, algorithm=None):
|
|
1237
|
+
r"""
|
|
1238
|
+
Return the roots of the univariate polynomial ``p``.
|
|
1239
|
+
|
|
1240
|
+
INPUT:
|
|
1241
|
+
|
|
1242
|
+
- ``p`` -- univariate integer polynomial
|
|
1243
|
+
|
|
1244
|
+
- ``ring`` -- ring (default: ``None``); a ring containing `\ZZ` to
|
|
1245
|
+
compute the roots in; ``None`` is equivalent to ``ZZ``
|
|
1246
|
+
|
|
1247
|
+
- ``multiplicities`` -- boolean (default: ``True``); whether to
|
|
1248
|
+
compute the multiplicities
|
|
1249
|
+
|
|
1250
|
+
- ``algorithm`` -- ``'dense'``, ``'sparse'`` or ``None`` (default:
|
|
1251
|
+
``None``); the algorithm to use
|
|
1252
|
+
|
|
1253
|
+
OUTPUT:
|
|
1254
|
+
|
|
1255
|
+
- If ``multiplicities=True``, the list of pairs `(r, n)` where
|
|
1256
|
+
`r` is a root and `n` the corresponding multiplicity;
|
|
1257
|
+
|
|
1258
|
+
- If ``multiplicities=False``, the list of distincts roots with no
|
|
1259
|
+
information about the multiplicities.
|
|
1260
|
+
|
|
1261
|
+
ALGORITHM:
|
|
1262
|
+
|
|
1263
|
+
If ``algorithm`` is ``'dense'``, the roots are computed using
|
|
1264
|
+
:meth:`_roots_from_factorization`.
|
|
1265
|
+
|
|
1266
|
+
If ``algorithm`` is ``'sparse'``, the roots are computed using the
|
|
1267
|
+
algorithm described in [CKS1999]_.
|
|
1268
|
+
|
|
1269
|
+
If ``algorithm`` is ``None``, use the ``'dense'`` algorithm for
|
|
1270
|
+
polynomials of degree at most `100`, and ``'sparse'`` otherwise.
|
|
1271
|
+
|
|
1272
|
+
.. NOTE::
|
|
1273
|
+
|
|
1274
|
+
This is a helper method for
|
|
1275
|
+
:meth:`sage.rings.polynomial.polynomial_element.Polynomial.roots`.
|
|
1276
|
+
|
|
1277
|
+
TESTS::
|
|
1278
|
+
|
|
1279
|
+
sage: # needs sage.libs.pari
|
|
1280
|
+
sage: R.<x> = PolynomialRing(ZZ, sparse=True)
|
|
1281
|
+
sage: p = (x + 1)^23 * (x - 1)^23 * (x - 100) * (x + 5445)^5
|
|
1282
|
+
sage: ZZ._roots_univariate_polynomial(p)
|
|
1283
|
+
[(100, 1), (-5445, 5), (1, 23), (-1, 23)]
|
|
1284
|
+
sage: p *= (1 + x^3458645 - 76*x^3435423343 + x^45346567867756556)
|
|
1285
|
+
sage: ZZ._roots_univariate_polynomial(p)
|
|
1286
|
+
[(1, 23), (-1, 23), (100, 1), (-5445, 5)]
|
|
1287
|
+
sage: p *= x^156468451540687043504386074354036574634735074
|
|
1288
|
+
sage: ZZ._roots_univariate_polynomial(p)
|
|
1289
|
+
[(0, 156468451540687043504386074354036574634735074),
|
|
1290
|
+
(1, 23),
|
|
1291
|
+
(-1, 23),
|
|
1292
|
+
(100, 1),
|
|
1293
|
+
(-5445, 5)]
|
|
1294
|
+
sage: ZZ._roots_univariate_polynomial(p, multiplicities=False)
|
|
1295
|
+
[0, 1, -1, 100, -5445]
|
|
1296
|
+
|
|
1297
|
+
sage: # needs sage.libs.pari
|
|
1298
|
+
sage: R.<x> = PolynomialRing(ZZ, sparse=False)
|
|
1299
|
+
sage: p = (x + 1)^23 * (x - 1)^23 * (x - 100) * (x + 5445)^5
|
|
1300
|
+
sage: ZZ._roots_univariate_polynomial(p)
|
|
1301
|
+
[(100, 1), (-5445, 5), (1, 23), (-1, 23)]
|
|
1302
|
+
sage: ZZ._roots_univariate_polynomial(p, multiplicities=False)
|
|
1303
|
+
[100, -5445, 1, -1]
|
|
1304
|
+
sage: ZZ._roots_univariate_polynomial(p, algorithm='sparse')
|
|
1305
|
+
[(100, 1), (-5445, 5), (1, 23), (-1, 23)]
|
|
1306
|
+
sage: ZZ._roots_univariate_polynomial(p, algorithm='dense')
|
|
1307
|
+
[(100, 1), (-5445, 5), (1, 23), (-1, 23)]
|
|
1308
|
+
sage: ZZ._roots_univariate_polynomial(p, algorithm='foobar')
|
|
1309
|
+
Traceback (most recent call last):
|
|
1310
|
+
...
|
|
1311
|
+
ValueError: unknown algorithm 'foobar'
|
|
1312
|
+
|
|
1313
|
+
sage: p = x^20 * p # needs sage.libs.pari
|
|
1314
|
+
sage: ZZ._roots_univariate_polynomial(p, algorithm='sparse') # needs sage.libs.pari
|
|
1315
|
+
[(0, 20), (100, 1), (-5445, 5), (1, 23), (-1, 23)]
|
|
1316
|
+
sage: ZZ._roots_univariate_polynomial(p, algorithm='dense') # needs sage.libs.pari
|
|
1317
|
+
[(100, 1), (-5445, 5), (0, 20), (1, 23), (-1, 23)]
|
|
1318
|
+
"""
|
|
1319
|
+
deg = p.degree()
|
|
1320
|
+
if deg < 0:
|
|
1321
|
+
raise ValueError("roots of 0 are not defined")
|
|
1322
|
+
|
|
1323
|
+
# A specific algorithm is available only for integer roots of integer polynomials
|
|
1324
|
+
if ring is not self and ring is not None:
|
|
1325
|
+
raise NotImplementedError
|
|
1326
|
+
|
|
1327
|
+
# Automatic choice of algorithm
|
|
1328
|
+
if algorithm is None:
|
|
1329
|
+
if deg > 100:
|
|
1330
|
+
algorithm = "sparse"
|
|
1331
|
+
else:
|
|
1332
|
+
algorithm = "dense"
|
|
1333
|
+
|
|
1334
|
+
if algorithm != "dense" and algorithm != "sparse":
|
|
1335
|
+
raise ValueError("unknown algorithm '{}'".format(algorithm))
|
|
1336
|
+
|
|
1337
|
+
# Check if the polynomial is a constant, in which case there are
|
|
1338
|
+
# no roots. Note that the polynomial is not 0.
|
|
1339
|
+
if deg == 0:
|
|
1340
|
+
return []
|
|
1341
|
+
|
|
1342
|
+
# The dense algorithm is to compute the roots from the factorization.
|
|
1343
|
+
if algorithm == "dense":
|
|
1344
|
+
cont = p.content_ideal().gen()
|
|
1345
|
+
if not cont.is_unit():
|
|
1346
|
+
p = p.map_coefficients(lambda c: c // cont)
|
|
1347
|
+
return p._roots_from_factorization(p.factor(), multiplicities)
|
|
1348
|
+
|
|
1349
|
+
v = p.valuation()
|
|
1350
|
+
deg -= v
|
|
1351
|
+
cdef list roots
|
|
1352
|
+
|
|
1353
|
+
# Root 0
|
|
1354
|
+
if v > 0:
|
|
1355
|
+
roots = [(self.zero(), v)] if multiplicities else [self.zero()]
|
|
1356
|
+
if deg == 0: # The shifted polynomial will be constant
|
|
1357
|
+
return roots
|
|
1358
|
+
else:
|
|
1359
|
+
roots = []
|
|
1360
|
+
|
|
1361
|
+
p = p.shift(-v)
|
|
1362
|
+
cdef list e = p.exponents()
|
|
1363
|
+
cdef int i_min, i, j, k = len(e)
|
|
1364
|
+
|
|
1365
|
+
# totally dense polynomial
|
|
1366
|
+
if k == 1 + deg:
|
|
1367
|
+
return roots + p._roots_from_factorization(p.factor(), multiplicities)
|
|
1368
|
+
|
|
1369
|
+
cont = p.content_ideal().gen()
|
|
1370
|
+
if not cont.is_unit():
|
|
1371
|
+
p = p.map_coefficients(lambda c: c // cont)
|
|
1372
|
+
|
|
1373
|
+
cdef list c = p.coefficients()
|
|
1374
|
+
|
|
1375
|
+
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
|
|
1376
|
+
R = PolynomialRing(p.base_ring(), p.variable_name(), sparse=False)
|
|
1377
|
+
c_max_nbits = c[0].nbits()
|
|
1378
|
+
i_min = 0
|
|
1379
|
+
g = R.zero()
|
|
1380
|
+
|
|
1381
|
+
# Looking for "large" gaps in the exponents
|
|
1382
|
+
# These gaps split the polynomial into lower degree components
|
|
1383
|
+
# Roots of modulus > 1 are common roots of the components
|
|
1384
|
+
for i in range(1, k):
|
|
1385
|
+
if e[i] - e[i-1] > c_max_nbits:
|
|
1386
|
+
g = g.gcd(R( {e[j] - e[i_min]: c[j] for j in range(i_min, i)} ))
|
|
1387
|
+
if g.is_one():
|
|
1388
|
+
break
|
|
1389
|
+
i_min = i
|
|
1390
|
+
c_max_nbits = c[i].nbits()
|
|
1391
|
+
else:
|
|
1392
|
+
c_max_nbits = max(c[i].nbits(), c_max_nbits)
|
|
1393
|
+
|
|
1394
|
+
# if no gap, directly return the roots of p
|
|
1395
|
+
if g.is_zero():
|
|
1396
|
+
roots.extend(p._roots_from_factorization(p.factor(), multiplicities))
|
|
1397
|
+
return roots
|
|
1398
|
+
|
|
1399
|
+
g = g.gcd(R( {e[j] - e[i_min]: c[j] for j in range(i_min, k)} ))
|
|
1400
|
+
|
|
1401
|
+
cdef list cc
|
|
1402
|
+
cdef list ee
|
|
1403
|
+
cdef int m1, m2
|
|
1404
|
+
cdef bint b1, b2
|
|
1405
|
+
# Computation of the roots of modulus 1, without multiplicities
|
|
1406
|
+
# 1 is root iff p(1) == 0 ; -1 iff p(-1) == 0
|
|
1407
|
+
if not multiplicities:
|
|
1408
|
+
if not sum(c):
|
|
1409
|
+
roots.append(self.one())
|
|
1410
|
+
s = 0
|
|
1411
|
+
for j in range(k):
|
|
1412
|
+
s += -c[j] if (e[j] % 2) else c[j]
|
|
1413
|
+
if not s:
|
|
1414
|
+
roots.append(-self.one())
|
|
1415
|
+
|
|
1416
|
+
# Computation of the roots of modulus 1, with multiplicities
|
|
1417
|
+
# For the multiplicities, take the derivatives
|
|
1418
|
+
else:
|
|
1419
|
+
cc = c
|
|
1420
|
+
ee = e
|
|
1421
|
+
m1 = m2 = 0
|
|
1422
|
+
b1 = b2 = True
|
|
1423
|
+
|
|
1424
|
+
for i in range(k):
|
|
1425
|
+
s1 = s2 = 0
|
|
1426
|
+
for j in range(k-i):
|
|
1427
|
+
if b1: s1 += cc[j]
|
|
1428
|
+
if b2: s2 += -cc[j] if (ee[j] % 2) else cc[j]
|
|
1429
|
+
if b1 and s1:
|
|
1430
|
+
m1 = i
|
|
1431
|
+
b1 = False
|
|
1432
|
+
if b2 and s2:
|
|
1433
|
+
m2 = i
|
|
1434
|
+
b2 = False
|
|
1435
|
+
# Stop asap
|
|
1436
|
+
if not (b1 or b2):
|
|
1437
|
+
break
|
|
1438
|
+
|
|
1439
|
+
# Sparse derivative, that is (p/x^v)' where v = p.val():
|
|
1440
|
+
ee = [ee[j] - ee[0] - 1 for j in range(1,k-i)]
|
|
1441
|
+
cc = [(ee[j] + 1) * cc[j+1] for j in range(k-i-1)]
|
|
1442
|
+
|
|
1443
|
+
if m1 > 0:
|
|
1444
|
+
roots.append((self.one(), m1))
|
|
1445
|
+
if m2 > 0:
|
|
1446
|
+
roots.append((-self.one(), m2))
|
|
1447
|
+
|
|
1448
|
+
# Add roots of modulus > 1 to `roots`:
|
|
1449
|
+
if multiplicities:
|
|
1450
|
+
roots.extend(r for r in g._roots_from_factorization(g.factor(), True)
|
|
1451
|
+
if r[0].abs() > 1)
|
|
1452
|
+
else:
|
|
1453
|
+
roots.extend(r for r in g._roots_from_factorization(g.factor(), False)
|
|
1454
|
+
if r.abs() > 1)
|
|
1455
|
+
|
|
1456
|
+
return roots
|
|
1457
|
+
|
|
1458
|
+
#################################
|
|
1459
|
+
# Coercions to interfaces
|
|
1460
|
+
#################################
|
|
1461
|
+
|
|
1462
|
+
def _gap_init_(self):
|
|
1463
|
+
"""
|
|
1464
|
+
Return a GAP representation of ``self``.
|
|
1465
|
+
|
|
1466
|
+
EXAMPLES::
|
|
1467
|
+
|
|
1468
|
+
sage: gap(ZZ) # indirect doctest # needs sage.libs.gap
|
|
1469
|
+
Integers
|
|
1470
|
+
"""
|
|
1471
|
+
return 'Integers'
|
|
1472
|
+
|
|
1473
|
+
def _fricas_init_(self):
|
|
1474
|
+
"""
|
|
1475
|
+
Return a FriCAS representation of ``self``.
|
|
1476
|
+
|
|
1477
|
+
EXAMPLES::
|
|
1478
|
+
|
|
1479
|
+
sage: fricas(ZZ) # indirect doctest, optional - fricas
|
|
1480
|
+
Integer
|
|
1481
|
+
"""
|
|
1482
|
+
return 'Integer'
|
|
1483
|
+
|
|
1484
|
+
def _lean_init_(self):
|
|
1485
|
+
return 'int'
|
|
1486
|
+
|
|
1487
|
+
def _magma_init_(self, magma):
|
|
1488
|
+
"""
|
|
1489
|
+
Return a magma representation of ``self``.
|
|
1490
|
+
|
|
1491
|
+
EXAMPLES::
|
|
1492
|
+
|
|
1493
|
+
sage: magma(ZZ) # indirect doctest, optional - magma
|
|
1494
|
+
Integer Ring
|
|
1495
|
+
"""
|
|
1496
|
+
return 'IntegerRing()'
|
|
1497
|
+
|
|
1498
|
+
def _macaulay2_init_(self, macaulay2=None):
|
|
1499
|
+
"""
|
|
1500
|
+
Return a macaulay2 representation of ``self``.
|
|
1501
|
+
|
|
1502
|
+
EXAMPLES::
|
|
1503
|
+
|
|
1504
|
+
sage: macaulay2(ZZ) # optional - macaulay2
|
|
1505
|
+
ZZ
|
|
1506
|
+
"""
|
|
1507
|
+
return "ZZ"
|
|
1508
|
+
|
|
1509
|
+
def _polymake_init_(self):
|
|
1510
|
+
r"""
|
|
1511
|
+
Return the polymake representation of the integer ring.
|
|
1512
|
+
|
|
1513
|
+
EXAMPLES::
|
|
1514
|
+
|
|
1515
|
+
sage: polymake(ZZ) # optional - jupymake # indirect doctest
|
|
1516
|
+
Integer
|
|
1517
|
+
"""
|
|
1518
|
+
return '"Integer"'
|
|
1519
|
+
|
|
1520
|
+
def _sympy_(self):
|
|
1521
|
+
r"""
|
|
1522
|
+
Return the SymPy set ``Integers``.
|
|
1523
|
+
|
|
1524
|
+
EXAMPLES::
|
|
1525
|
+
|
|
1526
|
+
sage: ZZ._sympy_() # needs sympy
|
|
1527
|
+
Integers
|
|
1528
|
+
"""
|
|
1529
|
+
from sympy import Integers
|
|
1530
|
+
from sage.interfaces.sympy import sympy_init
|
|
1531
|
+
sympy_init()
|
|
1532
|
+
return Integers
|
|
1533
|
+
|
|
1534
|
+
def _sage_input_(self, sib, coerced):
|
|
1535
|
+
r"""
|
|
1536
|
+
Produce an expression which will reproduce this value when
|
|
1537
|
+
evaluated.
|
|
1538
|
+
|
|
1539
|
+
EXAMPLES::
|
|
1540
|
+
|
|
1541
|
+
sage: sage_input(ZZ, verify=True)
|
|
1542
|
+
# Verified
|
|
1543
|
+
ZZ
|
|
1544
|
+
sage: from sage.misc.sage_input import SageInputBuilder
|
|
1545
|
+
sage: ZZ._sage_input_(SageInputBuilder(), False)
|
|
1546
|
+
{atomic:ZZ}
|
|
1547
|
+
"""
|
|
1548
|
+
return sib.name('ZZ')
|
|
1549
|
+
|
|
1550
|
+
def valuation(self, p):
|
|
1551
|
+
r"""
|
|
1552
|
+
Return the discrete valuation with uniformizer ``p``.
|
|
1553
|
+
|
|
1554
|
+
EXAMPLES::
|
|
1555
|
+
|
|
1556
|
+
sage: v = ZZ.valuation(3); v # needs sage.rings.padics
|
|
1557
|
+
3-adic valuation
|
|
1558
|
+
sage: v(3) # needs sage.rings.padics
|
|
1559
|
+
1
|
|
1560
|
+
|
|
1561
|
+
.. SEEALSO::
|
|
1562
|
+
|
|
1563
|
+
:meth:`Order.valuation() <sage.rings.number_field.order.Order.valuation>`,
|
|
1564
|
+
:meth:`RationalField.valuation() <sage.rings.rational_field.RationalField.valuation>`
|
|
1565
|
+
"""
|
|
1566
|
+
from sage.rings.padics.padic_valuation import pAdicValuation
|
|
1567
|
+
return pAdicValuation(self, p)
|
|
1568
|
+
|
|
1569
|
+
def from_bytes(self, input_bytes, byteorder='big', is_signed=False):
|
|
1570
|
+
r"""
|
|
1571
|
+
Return the integer represented by the given array of bytes.
|
|
1572
|
+
|
|
1573
|
+
Internally relies on the python ``int.from_bytes()`` method.
|
|
1574
|
+
|
|
1575
|
+
INPUT:
|
|
1576
|
+
|
|
1577
|
+
- ``input_bytes`` -- a bytes-like object or iterable producing bytes
|
|
1578
|
+
- ``byteorder`` -- string (default: ``'big'``); determines the byte order of
|
|
1579
|
+
``input_bytes`` (can only be ``'big'`` or ``'little'``)
|
|
1580
|
+
- ``is_signed`` -- boolean (default: ``False``); determines whether to use two's
|
|
1581
|
+
compliment to represent the integer
|
|
1582
|
+
|
|
1583
|
+
EXAMPLES::
|
|
1584
|
+
|
|
1585
|
+
sage: ZZ.from_bytes(b'\x00\x10', byteorder='big')
|
|
1586
|
+
16
|
|
1587
|
+
sage: ZZ.from_bytes(b'\x00\x10', byteorder='little')
|
|
1588
|
+
4096
|
|
1589
|
+
sage: ZZ.from_bytes(b'\xfc\x00', byteorder='big', is_signed=True)
|
|
1590
|
+
-1024
|
|
1591
|
+
sage: ZZ.from_bytes(b'\xfc\x00', byteorder='big', is_signed=False)
|
|
1592
|
+
64512
|
|
1593
|
+
sage: ZZ.from_bytes([255, 0, 0], byteorder='big')
|
|
1594
|
+
16711680
|
|
1595
|
+
sage: type(_)
|
|
1596
|
+
<class 'sage.rings.integer.Integer'>
|
|
1597
|
+
"""
|
|
1598
|
+
python_int = int.from_bytes(input_bytes, byteorder=byteorder, signed=is_signed)
|
|
1599
|
+
return self(python_int)
|
|
1600
|
+
|
|
1601
|
+
ZZ = IntegerRing_class()
|
|
1602
|
+
Z = ZZ
|
|
1603
|
+
|
|
1604
|
+
|
|
1605
|
+
def IntegerRing():
|
|
1606
|
+
"""
|
|
1607
|
+
Return the integer ring.
|
|
1608
|
+
|
|
1609
|
+
EXAMPLES::
|
|
1610
|
+
|
|
1611
|
+
sage: IntegerRing()
|
|
1612
|
+
Integer Ring
|
|
1613
|
+
sage: ZZ==IntegerRing()
|
|
1614
|
+
True
|
|
1615
|
+
"""
|
|
1616
|
+
return ZZ
|
|
1617
|
+
|
|
1618
|
+
|
|
1619
|
+
def crt_basis(X, xgcd=None):
|
|
1620
|
+
r"""
|
|
1621
|
+
Compute and return a Chinese Remainder Theorem basis for the list ``X``
|
|
1622
|
+
of coprime integers.
|
|
1623
|
+
|
|
1624
|
+
INPUT:
|
|
1625
|
+
|
|
1626
|
+
- ``X`` -- list of Integers that are coprime in pairs
|
|
1627
|
+
|
|
1628
|
+
- ``xgcd`` -- an optional parameter which is ignored
|
|
1629
|
+
|
|
1630
|
+
OUTPUT:
|
|
1631
|
+
|
|
1632
|
+
- ``E`` -- list of Integers such that ``E[i] = 1`` (mod ``X[i]``) and
|
|
1633
|
+
``E[i] = 0`` (mod ``X[j]``) for all `j \neq i`
|
|
1634
|
+
|
|
1635
|
+
For this explanation, let ``E[i]`` be denoted by `E_i`.
|
|
1636
|
+
|
|
1637
|
+
The `E_i` have the property that if `A` is a list of objects, e.g.,
|
|
1638
|
+
integers, vectors, matrices, etc., where `A_i` is understood modulo
|
|
1639
|
+
`X_i`, then a CRT lift of `A` is simply
|
|
1640
|
+
|
|
1641
|
+
.. MATH::
|
|
1642
|
+
|
|
1643
|
+
\sum_i E_i A_i.
|
|
1644
|
+
|
|
1645
|
+
ALGORITHM: To compute `E_i`, compute integers `s` and `t` such that
|
|
1646
|
+
|
|
1647
|
+
.. MATH::
|
|
1648
|
+
|
|
1649
|
+
s X_i + t \prod_{i \neq j} X_j = 1. (\*)
|
|
1650
|
+
|
|
1651
|
+
Then
|
|
1652
|
+
|
|
1653
|
+
.. MATH::
|
|
1654
|
+
|
|
1655
|
+
E_i = t \prod_{i \neq j} X[j].
|
|
1656
|
+
|
|
1657
|
+
Notice that equation
|
|
1658
|
+
(\*) implies that `E_i` is congruent to 1 modulo `X_i` and to 0
|
|
1659
|
+
modulo the other `X_j` for `j \neq i`.
|
|
1660
|
+
|
|
1661
|
+
COMPLEXITY: We compute ``len(X)`` extended GCD's.
|
|
1662
|
+
|
|
1663
|
+
EXAMPLES::
|
|
1664
|
+
|
|
1665
|
+
sage: X = [11,20,31,51]
|
|
1666
|
+
sage: E = crt_basis([11,20,31,51])
|
|
1667
|
+
sage: E[0]%X[0], E[1]%X[0], E[2]%X[0], E[3]%X[0]
|
|
1668
|
+
(1, 0, 0, 0)
|
|
1669
|
+
sage: E[0]%X[1], E[1]%X[1], E[2]%X[1], E[3]%X[1]
|
|
1670
|
+
(0, 1, 0, 0)
|
|
1671
|
+
sage: E[0]%X[2], E[1]%X[2], E[2]%X[2], E[3]%X[2]
|
|
1672
|
+
(0, 0, 1, 0)
|
|
1673
|
+
sage: E[0]%X[3], E[1]%X[3], E[2]%X[3], E[3]%X[3]
|
|
1674
|
+
(0, 0, 0, 1)
|
|
1675
|
+
"""
|
|
1676
|
+
if not isinstance(X, list):
|
|
1677
|
+
raise TypeError("X must be a list")
|
|
1678
|
+
if len(X) == 0:
|
|
1679
|
+
return []
|
|
1680
|
+
|
|
1681
|
+
P = prod(X)
|
|
1682
|
+
|
|
1683
|
+
Y = []
|
|
1684
|
+
# 2. Compute extended GCD's
|
|
1685
|
+
ONE = parent(X[0]).one()
|
|
1686
|
+
for i in range(len(X)):
|
|
1687
|
+
p = X[i]
|
|
1688
|
+
others = P // p
|
|
1689
|
+
g, _, t = p.xgcd(others)
|
|
1690
|
+
if g != ONE:
|
|
1691
|
+
raise ArithmeticError("the elements of the list X must be coprime in pairs")
|
|
1692
|
+
Y.append(t * others)
|
|
1693
|
+
return Y
|