passagemath-modules 10.6.31rc3__cp314-cp314-musllinux_1_2_x86_64.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.
Potentially problematic release.
This version of passagemath-modules might be problematic. Click here for more details.
- passagemath_modules-10.6.31rc3.dist-info/METADATA +281 -0
- passagemath_modules-10.6.31rc3.dist-info/RECORD +808 -0
- passagemath_modules-10.6.31rc3.dist-info/WHEEL +5 -0
- passagemath_modules-10.6.31rc3.dist-info/top_level.txt +2 -0
- passagemath_modules.libs/libgcc_s-0cd532bd.so.1 +0 -0
- passagemath_modules.libs/libgfortran-2c33b284.so.5.0.0 +0 -0
- passagemath_modules.libs/libgmp-0e7fc84e.so.10.5.0 +0 -0
- passagemath_modules.libs/libgsl-42cda06f.so.28.0.0 +0 -0
- passagemath_modules.libs/libmpc-d8ebe4b5.so.3.3.1 +0 -0
- passagemath_modules.libs/libmpfr-aaecbfc0.so.6.2.1 +0 -0
- passagemath_modules.libs/libopenblasp-r0-905cb27d.3.29.so +0 -0
- passagemath_modules.libs/libquadmath-bb76a5fc.so.0.0.0 +0 -0
- sage/algebras/all__sagemath_modules.py +20 -0
- sage/algebras/catalog.py +148 -0
- sage/algebras/clifford_algebra.py +3107 -0
- sage/algebras/clifford_algebra_element.cpython-314-x86_64-linux-musl.so +0 -0
- sage/algebras/clifford_algebra_element.pxd +16 -0
- sage/algebras/clifford_algebra_element.pyx +997 -0
- sage/algebras/commutative_dga.py +4252 -0
- sage/algebras/exterior_algebra_groebner.cpython-314-x86_64-linux-musl.so +0 -0
- sage/algebras/exterior_algebra_groebner.pxd +55 -0
- sage/algebras/exterior_algebra_groebner.pyx +727 -0
- sage/algebras/finite_dimensional_algebras/all.py +2 -0
- sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra.py +1029 -0
- sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_element.cpython-314-x86_64-linux-musl.so +0 -0
- sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_element.pxd +12 -0
- sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_element.pyx +706 -0
- sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_ideal.py +196 -0
- sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_morphism.py +255 -0
- sage/algebras/finite_gca.py +528 -0
- sage/algebras/group_algebra.py +232 -0
- sage/algebras/lie_algebras/abelian.py +197 -0
- sage/algebras/lie_algebras/affine_lie_algebra.py +1213 -0
- sage/algebras/lie_algebras/all.py +25 -0
- sage/algebras/lie_algebras/all__sagemath_modules.py +1 -0
- sage/algebras/lie_algebras/bch.py +177 -0
- sage/algebras/lie_algebras/bgg_dual_module.py +1184 -0
- sage/algebras/lie_algebras/bgg_resolution.py +232 -0
- sage/algebras/lie_algebras/center_uea.py +767 -0
- sage/algebras/lie_algebras/classical_lie_algebra.py +2516 -0
- sage/algebras/lie_algebras/examples.py +683 -0
- sage/algebras/lie_algebras/free_lie_algebra.py +973 -0
- sage/algebras/lie_algebras/heisenberg.py +820 -0
- sage/algebras/lie_algebras/lie_algebra.py +1562 -0
- sage/algebras/lie_algebras/lie_algebra_element.cpython-314-x86_64-linux-musl.so +0 -0
- sage/algebras/lie_algebras/lie_algebra_element.pxd +68 -0
- sage/algebras/lie_algebras/lie_algebra_element.pyx +2122 -0
- sage/algebras/lie_algebras/morphism.py +661 -0
- sage/algebras/lie_algebras/nilpotent_lie_algebra.py +457 -0
- sage/algebras/lie_algebras/onsager.py +1324 -0
- sage/algebras/lie_algebras/poincare_birkhoff_witt.py +816 -0
- sage/algebras/lie_algebras/quotient.py +462 -0
- sage/algebras/lie_algebras/rank_two_heisenberg_virasoro.py +355 -0
- sage/algebras/lie_algebras/representation.py +1040 -0
- sage/algebras/lie_algebras/structure_coefficients.py +459 -0
- sage/algebras/lie_algebras/subalgebra.py +967 -0
- sage/algebras/lie_algebras/symplectic_derivation.py +289 -0
- sage/algebras/lie_algebras/verma_module.py +1630 -0
- sage/algebras/lie_algebras/virasoro.py +1186 -0
- sage/algebras/octonion_algebra.cpython-314-x86_64-linux-musl.so +0 -0
- sage/algebras/octonion_algebra.pxd +20 -0
- sage/algebras/octonion_algebra.pyx +987 -0
- sage/algebras/orlik_solomon.py +907 -0
- sage/algebras/orlik_terao.py +779 -0
- sage/algebras/steenrod/all.py +7 -0
- sage/algebras/steenrod/steenrod_algebra.py +4258 -0
- sage/algebras/steenrod/steenrod_algebra_bases.py +1179 -0
- sage/algebras/steenrod/steenrod_algebra_misc.py +1167 -0
- sage/algebras/steenrod/steenrod_algebra_mult.py +954 -0
- sage/algebras/weyl_algebra.py +1126 -0
- sage/all__sagemath_modules.py +62 -0
- sage/calculus/all__sagemath_modules.py +19 -0
- sage/calculus/expr.py +205 -0
- sage/calculus/integration.cpython-314-x86_64-linux-musl.so +0 -0
- sage/calculus/integration.pyx +698 -0
- sage/calculus/interpolation.cpython-314-x86_64-linux-musl.so +0 -0
- sage/calculus/interpolation.pxd +13 -0
- sage/calculus/interpolation.pyx +387 -0
- sage/calculus/interpolators.cpython-314-x86_64-linux-musl.so +0 -0
- sage/calculus/interpolators.pyx +326 -0
- sage/calculus/ode.cpython-314-x86_64-linux-musl.so +0 -0
- sage/calculus/ode.pxd +5 -0
- sage/calculus/ode.pyx +610 -0
- sage/calculus/riemann.cpython-314-x86_64-linux-musl.so +0 -0
- sage/calculus/riemann.pyx +1521 -0
- sage/calculus/test_sympy.py +201 -0
- sage/calculus/transforms/all.py +7 -0
- sage/calculus/transforms/dft.py +844 -0
- sage/calculus/transforms/dwt.cpython-314-x86_64-linux-musl.so +0 -0
- sage/calculus/transforms/dwt.pxd +7 -0
- sage/calculus/transforms/dwt.pyx +160 -0
- sage/calculus/transforms/fft.cpython-314-x86_64-linux-musl.so +0 -0
- sage/calculus/transforms/fft.pxd +12 -0
- sage/calculus/transforms/fft.pyx +487 -0
- sage/calculus/wester.py +662 -0
- sage/coding/abstract_code.py +1108 -0
- sage/coding/ag_code.py +868 -0
- sage/coding/ag_code_decoders.cpython-314-x86_64-linux-musl.so +0 -0
- sage/coding/ag_code_decoders.pyx +2639 -0
- sage/coding/all.py +15 -0
- sage/coding/bch_code.py +494 -0
- sage/coding/binary_code.cpython-314-x86_64-linux-musl.so +0 -0
- sage/coding/binary_code.pxd +124 -0
- sage/coding/binary_code.pyx +4139 -0
- sage/coding/bounds_catalog.py +43 -0
- sage/coding/channel.py +819 -0
- sage/coding/channels_catalog.py +29 -0
- sage/coding/code_bounds.py +755 -0
- sage/coding/code_constructions.py +804 -0
- sage/coding/codes_catalog.py +111 -0
- sage/coding/cyclic_code.py +1329 -0
- sage/coding/databases.py +316 -0
- sage/coding/decoder.py +373 -0
- sage/coding/decoders_catalog.py +88 -0
- sage/coding/delsarte_bounds.py +709 -0
- sage/coding/encoder.py +390 -0
- sage/coding/encoders_catalog.py +64 -0
- sage/coding/extended_code.py +468 -0
- sage/coding/gabidulin_code.py +1058 -0
- sage/coding/golay_code.py +404 -0
- sage/coding/goppa_code.py +441 -0
- sage/coding/grs_code.py +2371 -0
- sage/coding/guava.py +107 -0
- sage/coding/guruswami_sudan/all.py +1 -0
- sage/coding/guruswami_sudan/gs_decoder.py +897 -0
- sage/coding/guruswami_sudan/interpolation.py +409 -0
- sage/coding/guruswami_sudan/utils.py +176 -0
- sage/coding/hamming_code.py +176 -0
- sage/coding/information_set_decoder.py +1032 -0
- sage/coding/kasami_codes.cpython-314-x86_64-linux-musl.so +0 -0
- sage/coding/kasami_codes.pyx +351 -0
- sage/coding/linear_code.py +3067 -0
- sage/coding/linear_code_no_metric.py +1354 -0
- sage/coding/linear_rank_metric.py +961 -0
- sage/coding/parity_check_code.py +353 -0
- sage/coding/punctured_code.py +719 -0
- sage/coding/reed_muller_code.py +999 -0
- sage/coding/self_dual_codes.py +942 -0
- sage/coding/source_coding/all.py +2 -0
- sage/coding/source_coding/huffman.py +553 -0
- sage/coding/subfield_subcode.py +423 -0
- sage/coding/two_weight_db.py +399 -0
- sage/combinat/all__sagemath_modules.py +7 -0
- sage/combinat/cartesian_product.py +347 -0
- sage/combinat/family.py +11 -0
- sage/combinat/free_module.py +1977 -0
- sage/combinat/root_system/all.py +147 -0
- sage/combinat/root_system/ambient_space.py +527 -0
- sage/combinat/root_system/associahedron.py +471 -0
- sage/combinat/root_system/braid_move_calculator.py +143 -0
- sage/combinat/root_system/braid_orbit.cpython-314-x86_64-linux-musl.so +0 -0
- sage/combinat/root_system/braid_orbit.pyx +144 -0
- sage/combinat/root_system/branching_rules.py +2301 -0
- sage/combinat/root_system/cartan_matrix.py +1245 -0
- sage/combinat/root_system/cartan_type.py +3069 -0
- sage/combinat/root_system/coxeter_group.py +162 -0
- sage/combinat/root_system/coxeter_matrix.py +1261 -0
- sage/combinat/root_system/coxeter_type.py +681 -0
- sage/combinat/root_system/dynkin_diagram.py +900 -0
- sage/combinat/root_system/extended_affine_weyl_group.py +2993 -0
- sage/combinat/root_system/fundamental_group.py +795 -0
- sage/combinat/root_system/hecke_algebra_representation.py +1203 -0
- sage/combinat/root_system/integrable_representations.py +1227 -0
- sage/combinat/root_system/non_symmetric_macdonald_polynomials.py +1965 -0
- sage/combinat/root_system/pieri_factors.py +1147 -0
- sage/combinat/root_system/plot.py +1615 -0
- sage/combinat/root_system/root_lattice_realization_algebras.py +1214 -0
- sage/combinat/root_system/root_lattice_realizations.py +4628 -0
- sage/combinat/root_system/root_space.py +487 -0
- sage/combinat/root_system/root_system.py +882 -0
- sage/combinat/root_system/type_A.py +348 -0
- sage/combinat/root_system/type_A_affine.py +227 -0
- sage/combinat/root_system/type_A_infinity.py +241 -0
- sage/combinat/root_system/type_B.py +347 -0
- sage/combinat/root_system/type_BC_affine.py +287 -0
- sage/combinat/root_system/type_B_affine.py +216 -0
- sage/combinat/root_system/type_C.py +317 -0
- sage/combinat/root_system/type_C_affine.py +188 -0
- sage/combinat/root_system/type_D.py +357 -0
- sage/combinat/root_system/type_D_affine.py +208 -0
- sage/combinat/root_system/type_E.py +641 -0
- sage/combinat/root_system/type_E_affine.py +231 -0
- sage/combinat/root_system/type_F.py +387 -0
- sage/combinat/root_system/type_F_affine.py +137 -0
- sage/combinat/root_system/type_G.py +293 -0
- sage/combinat/root_system/type_G_affine.py +132 -0
- sage/combinat/root_system/type_H.py +105 -0
- sage/combinat/root_system/type_I.py +110 -0
- sage/combinat/root_system/type_Q.py +150 -0
- sage/combinat/root_system/type_affine.py +509 -0
- sage/combinat/root_system/type_dual.py +704 -0
- sage/combinat/root_system/type_folded.py +301 -0
- sage/combinat/root_system/type_marked.py +748 -0
- sage/combinat/root_system/type_reducible.py +601 -0
- sage/combinat/root_system/type_relabel.py +730 -0
- sage/combinat/root_system/type_super_A.py +837 -0
- sage/combinat/root_system/weight_lattice_realizations.py +1188 -0
- sage/combinat/root_system/weight_space.py +639 -0
- sage/combinat/root_system/weyl_characters.py +2238 -0
- sage/crypto/__init__.py +4 -0
- sage/crypto/all.py +28 -0
- sage/crypto/block_cipher/all.py +7 -0
- sage/crypto/block_cipher/des.py +1065 -0
- sage/crypto/block_cipher/miniaes.py +2171 -0
- sage/crypto/block_cipher/present.py +909 -0
- sage/crypto/block_cipher/sdes.py +1527 -0
- sage/crypto/boolean_function.cpython-314-x86_64-linux-musl.so +0 -0
- sage/crypto/boolean_function.pxd +10 -0
- sage/crypto/boolean_function.pyx +1487 -0
- sage/crypto/cipher.py +78 -0
- sage/crypto/classical.py +3668 -0
- sage/crypto/classical_cipher.py +569 -0
- sage/crypto/cryptosystem.py +387 -0
- sage/crypto/key_exchange/all.py +7 -0
- sage/crypto/key_exchange/catalog.py +24 -0
- sage/crypto/key_exchange/diffie_hellman.py +323 -0
- sage/crypto/key_exchange/key_exchange_scheme.py +107 -0
- sage/crypto/lattice.py +312 -0
- sage/crypto/lfsr.py +295 -0
- sage/crypto/lwe.py +840 -0
- sage/crypto/mq/__init__.py +4 -0
- sage/crypto/mq/mpolynomialsystemgenerator.py +204 -0
- sage/crypto/mq/rijndael_gf.py +2345 -0
- sage/crypto/mq/sbox.py +7 -0
- sage/crypto/mq/sr.py +3344 -0
- sage/crypto/public_key/all.py +5 -0
- sage/crypto/public_key/blum_goldwasser.py +776 -0
- sage/crypto/sbox.cpython-314-x86_64-linux-musl.so +0 -0
- sage/crypto/sbox.pyx +2090 -0
- sage/crypto/sboxes.py +2090 -0
- sage/crypto/stream.py +390 -0
- sage/crypto/stream_cipher.py +297 -0
- sage/crypto/util.py +519 -0
- sage/ext/all__sagemath_modules.py +1 -0
- sage/ext/interpreters/__init__.py +1 -0
- sage/ext/interpreters/all__sagemath_modules.py +2 -0
- sage/ext/interpreters/wrapper_cc.cpython-314-x86_64-linux-musl.so +0 -0
- sage/ext/interpreters/wrapper_cc.pxd +30 -0
- sage/ext/interpreters/wrapper_cc.pyx +252 -0
- sage/ext/interpreters/wrapper_cdf.cpython-314-x86_64-linux-musl.so +0 -0
- sage/ext/interpreters/wrapper_cdf.pxd +26 -0
- sage/ext/interpreters/wrapper_cdf.pyx +245 -0
- sage/ext/interpreters/wrapper_rdf.cpython-314-x86_64-linux-musl.so +0 -0
- sage/ext/interpreters/wrapper_rdf.pxd +23 -0
- sage/ext/interpreters/wrapper_rdf.pyx +221 -0
- sage/ext/interpreters/wrapper_rr.cpython-314-x86_64-linux-musl.so +0 -0
- sage/ext/interpreters/wrapper_rr.pxd +28 -0
- sage/ext/interpreters/wrapper_rr.pyx +335 -0
- sage/geometry/all__sagemath_modules.py +5 -0
- sage/geometry/toric_lattice.py +1745 -0
- sage/geometry/toric_lattice_element.cpython-314-x86_64-linux-musl.so +0 -0
- sage/geometry/toric_lattice_element.pyx +432 -0
- sage/groups/abelian_gps/abelian_group.py +1925 -0
- sage/groups/abelian_gps/abelian_group_element.py +164 -0
- sage/groups/abelian_gps/all__sagemath_modules.py +5 -0
- sage/groups/abelian_gps/dual_abelian_group.py +421 -0
- sage/groups/abelian_gps/dual_abelian_group_element.py +179 -0
- sage/groups/abelian_gps/element_base.py +341 -0
- sage/groups/abelian_gps/values.py +488 -0
- sage/groups/additive_abelian/additive_abelian_group.py +476 -0
- sage/groups/additive_abelian/additive_abelian_wrapper.py +857 -0
- sage/groups/additive_abelian/all.py +4 -0
- sage/groups/additive_abelian/qmodnz.py +231 -0
- sage/groups/additive_abelian/qmodnz_element.py +349 -0
- sage/groups/affine_gps/affine_group.py +535 -0
- sage/groups/affine_gps/all.py +1 -0
- sage/groups/affine_gps/catalog.py +17 -0
- sage/groups/affine_gps/euclidean_group.py +246 -0
- sage/groups/affine_gps/group_element.py +562 -0
- sage/groups/all__sagemath_modules.py +12 -0
- sage/groups/galois_group.py +479 -0
- sage/groups/matrix_gps/all.py +4 -0
- sage/groups/matrix_gps/all__sagemath_modules.py +13 -0
- sage/groups/matrix_gps/catalog.py +26 -0
- sage/groups/matrix_gps/coxeter_group.py +927 -0
- sage/groups/matrix_gps/finitely_generated.py +487 -0
- sage/groups/matrix_gps/group_element.cpython-314-x86_64-linux-musl.so +0 -0
- sage/groups/matrix_gps/group_element.pxd +11 -0
- sage/groups/matrix_gps/group_element.pyx +431 -0
- sage/groups/matrix_gps/linear.py +440 -0
- sage/groups/matrix_gps/matrix_group.py +617 -0
- sage/groups/matrix_gps/named_group.py +296 -0
- sage/groups/matrix_gps/orthogonal.py +544 -0
- sage/groups/matrix_gps/symplectic.py +251 -0
- sage/groups/matrix_gps/unitary.py +436 -0
- sage/groups/misc_gps/all__sagemath_modules.py +1 -0
- sage/groups/misc_gps/argument_groups.py +1905 -0
- sage/groups/misc_gps/imaginary_groups.py +479 -0
- sage/groups/perm_gps/all__sagemath_modules.py +1 -0
- sage/groups/perm_gps/partn_ref/all__sagemath_modules.py +1 -0
- sage/groups/perm_gps/partn_ref/refinement_binary.cpython-314-x86_64-linux-musl.so +0 -0
- sage/groups/perm_gps/partn_ref/refinement_binary.pxd +41 -0
- sage/groups/perm_gps/partn_ref/refinement_binary.pyx +1167 -0
- sage/groups/perm_gps/partn_ref/refinement_matrices.cpython-314-x86_64-linux-musl.so +0 -0
- sage/groups/perm_gps/partn_ref/refinement_matrices.pxd +31 -0
- sage/groups/perm_gps/partn_ref/refinement_matrices.pyx +385 -0
- sage/homology/algebraic_topological_model.py +595 -0
- sage/homology/all.py +2 -0
- sage/homology/all__sagemath_modules.py +8 -0
- sage/homology/chain_complex.py +2148 -0
- sage/homology/chain_complex_homspace.py +165 -0
- sage/homology/chain_complex_morphism.py +629 -0
- sage/homology/chain_homotopy.py +604 -0
- sage/homology/chains.py +653 -0
- sage/homology/free_resolution.py +923 -0
- sage/homology/graded_resolution.py +567 -0
- sage/homology/hochschild_complex.py +756 -0
- sage/homology/homology_group.py +188 -0
- sage/homology/homology_morphism.py +422 -0
- sage/homology/homology_vector_space_with_basis.py +1454 -0
- sage/homology/koszul_complex.py +169 -0
- sage/homology/matrix_utils.py +205 -0
- sage/libs/all__sagemath_modules.py +1 -0
- sage/libs/gsl/__init__.py +1 -0
- sage/libs/gsl/airy.pxd +56 -0
- sage/libs/gsl/all.pxd +66 -0
- sage/libs/gsl/array.cpython-314-x86_64-linux-musl.so +0 -0
- sage/libs/gsl/array.pxd +5 -0
- sage/libs/gsl/array.pyx +102 -0
- sage/libs/gsl/bessel.pxd +208 -0
- sage/libs/gsl/blas.pxd +116 -0
- sage/libs/gsl/blas_types.pxd +34 -0
- sage/libs/gsl/block.pxd +52 -0
- sage/libs/gsl/chebyshev.pxd +37 -0
- sage/libs/gsl/clausen.pxd +12 -0
- sage/libs/gsl/combination.pxd +47 -0
- sage/libs/gsl/complex.pxd +151 -0
- sage/libs/gsl/coulomb.pxd +30 -0
- sage/libs/gsl/coupling.pxd +21 -0
- sage/libs/gsl/dawson.pxd +12 -0
- sage/libs/gsl/debye.pxd +24 -0
- sage/libs/gsl/dilog.pxd +14 -0
- sage/libs/gsl/eigen.pxd +46 -0
- sage/libs/gsl/elementary.pxd +12 -0
- sage/libs/gsl/ellint.pxd +48 -0
- sage/libs/gsl/elljac.pxd +8 -0
- sage/libs/gsl/erf.pxd +32 -0
- sage/libs/gsl/errno.pxd +26 -0
- sage/libs/gsl/exp.pxd +44 -0
- sage/libs/gsl/expint.pxd +44 -0
- sage/libs/gsl/fermi_dirac.pxd +44 -0
- sage/libs/gsl/fft.pxd +121 -0
- sage/libs/gsl/fit.pxd +50 -0
- sage/libs/gsl/gamma.pxd +94 -0
- sage/libs/gsl/gegenbauer.pxd +26 -0
- sage/libs/gsl/histogram.pxd +176 -0
- sage/libs/gsl/hyperg.pxd +52 -0
- sage/libs/gsl/integration.pxd +69 -0
- sage/libs/gsl/interp.pxd +109 -0
- sage/libs/gsl/laguerre.pxd +24 -0
- sage/libs/gsl/lambert.pxd +16 -0
- sage/libs/gsl/legendre.pxd +90 -0
- sage/libs/gsl/linalg.pxd +185 -0
- sage/libs/gsl/log.pxd +26 -0
- sage/libs/gsl/math.pxd +43 -0
- sage/libs/gsl/matrix.pxd +143 -0
- sage/libs/gsl/matrix_complex.pxd +130 -0
- sage/libs/gsl/min.pxd +67 -0
- sage/libs/gsl/monte.pxd +56 -0
- sage/libs/gsl/ntuple.pxd +32 -0
- sage/libs/gsl/odeiv.pxd +70 -0
- sage/libs/gsl/permutation.pxd +78 -0
- sage/libs/gsl/poly.pxd +40 -0
- sage/libs/gsl/pow_int.pxd +12 -0
- sage/libs/gsl/psi.pxd +28 -0
- sage/libs/gsl/qrng.pxd +29 -0
- sage/libs/gsl/random.pxd +257 -0
- sage/libs/gsl/rng.pxd +100 -0
- sage/libs/gsl/roots.pxd +72 -0
- sage/libs/gsl/sort.pxd +36 -0
- sage/libs/gsl/statistics.pxd +59 -0
- sage/libs/gsl/sum.pxd +55 -0
- sage/libs/gsl/synchrotron.pxd +16 -0
- sage/libs/gsl/transport.pxd +24 -0
- sage/libs/gsl/trig.pxd +58 -0
- sage/libs/gsl/types.pxd +137 -0
- sage/libs/gsl/vector.pxd +101 -0
- sage/libs/gsl/vector_complex.pxd +83 -0
- sage/libs/gsl/wavelet.pxd +49 -0
- sage/libs/gsl/zeta.pxd +28 -0
- sage/libs/mpc/__init__.pxd +114 -0
- sage/libs/mpc/types.pxd +28 -0
- sage/libs/mpfr/__init__.pxd +299 -0
- sage/libs/mpfr/types.pxd +26 -0
- sage/libs/mpmath/__init__.py +1 -0
- sage/libs/mpmath/all.py +27 -0
- sage/libs/mpmath/all__sagemath_modules.py +1 -0
- sage/libs/mpmath/utils.cpython-314-x86_64-linux-musl.so +0 -0
- sage/libs/mpmath/utils.pxd +4 -0
- sage/libs/mpmath/utils.pyx +319 -0
- sage/matrix/action.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/action.pxd +26 -0
- sage/matrix/action.pyx +596 -0
- sage/matrix/all.py +9 -0
- sage/matrix/args.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/args.pxd +144 -0
- sage/matrix/args.pyx +1668 -0
- sage/matrix/benchmark.py +1258 -0
- sage/matrix/berlekamp_massey.py +95 -0
- sage/matrix/compute_J_ideal.py +926 -0
- sage/matrix/constructor.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/constructor.pyx +750 -0
- sage/matrix/docs.py +430 -0
- sage/matrix/echelon_matrix.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/echelon_matrix.pyx +155 -0
- sage/matrix/matrix.pxd +2 -0
- sage/matrix/matrix0.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/matrix0.pxd +68 -0
- sage/matrix/matrix0.pyx +6324 -0
- sage/matrix/matrix1.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/matrix1.pxd +8 -0
- sage/matrix/matrix1.pyx +2851 -0
- sage/matrix/matrix2.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/matrix2.pxd +25 -0
- sage/matrix/matrix2.pyx +20181 -0
- sage/matrix/matrix_cdv.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/matrix_cdv.pxd +4 -0
- sage/matrix/matrix_cdv.pyx +93 -0
- sage/matrix/matrix_complex_double_dense.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/matrix_complex_double_dense.pxd +5 -0
- sage/matrix/matrix_complex_double_dense.pyx +98 -0
- sage/matrix/matrix_dense.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/matrix_dense.pxd +5 -0
- sage/matrix/matrix_dense.pyx +343 -0
- sage/matrix/matrix_domain_dense.pxd +5 -0
- sage/matrix/matrix_domain_sparse.pxd +5 -0
- sage/matrix/matrix_double_dense.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/matrix_double_dense.pxd +7 -0
- sage/matrix/matrix_double_dense.pyx +3906 -0
- sage/matrix/matrix_double_sparse.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/matrix_double_sparse.pxd +6 -0
- sage/matrix/matrix_double_sparse.pyx +248 -0
- sage/matrix/matrix_generic_dense.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/matrix_generic_dense.pxd +7 -0
- sage/matrix/matrix_generic_dense.pyx +354 -0
- sage/matrix/matrix_generic_sparse.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/matrix_generic_sparse.pxd +7 -0
- sage/matrix/matrix_generic_sparse.pyx +461 -0
- sage/matrix/matrix_laurent_mpolynomial_dense.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/matrix_laurent_mpolynomial_dense.pxd +5 -0
- sage/matrix/matrix_laurent_mpolynomial_dense.pyx +115 -0
- sage/matrix/matrix_misc.py +313 -0
- sage/matrix/matrix_numpy_dense.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/matrix_numpy_dense.pxd +14 -0
- sage/matrix/matrix_numpy_dense.pyx +450 -0
- sage/matrix/matrix_numpy_integer_dense.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/matrix_numpy_integer_dense.pxd +7 -0
- sage/matrix/matrix_numpy_integer_dense.pyx +59 -0
- sage/matrix/matrix_polynomial_dense.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/matrix_polynomial_dense.pxd +5 -0
- sage/matrix/matrix_polynomial_dense.pyx +5341 -0
- sage/matrix/matrix_real_double_dense.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/matrix_real_double_dense.pxd +7 -0
- sage/matrix/matrix_real_double_dense.pyx +122 -0
- sage/matrix/matrix_space.py +2848 -0
- sage/matrix/matrix_sparse.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/matrix_sparse.pxd +5 -0
- sage/matrix/matrix_sparse.pyx +1222 -0
- sage/matrix/matrix_window.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/matrix_window.pxd +37 -0
- sage/matrix/matrix_window.pyx +242 -0
- sage/matrix/misc_mpfr.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/misc_mpfr.pyx +80 -0
- sage/matrix/operation_table.py +1182 -0
- sage/matrix/special.py +3666 -0
- sage/matrix/strassen.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/strassen.pyx +851 -0
- sage/matrix/symplectic_basis.py +541 -0
- sage/matrix/template.pxd +6 -0
- sage/matrix/tests.py +71 -0
- sage/matroids/advanced.py +77 -0
- sage/matroids/all.py +13 -0
- sage/matroids/basis_exchange_matroid.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matroids/basis_exchange_matroid.pxd +96 -0
- sage/matroids/basis_exchange_matroid.pyx +2344 -0
- sage/matroids/basis_matroid.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matroids/basis_matroid.pxd +45 -0
- sage/matroids/basis_matroid.pyx +1217 -0
- sage/matroids/catalog.py +44 -0
- sage/matroids/chow_ring.py +473 -0
- sage/matroids/chow_ring_ideal.py +849 -0
- sage/matroids/circuit_closures_matroid.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matroids/circuit_closures_matroid.pxd +16 -0
- sage/matroids/circuit_closures_matroid.pyx +559 -0
- sage/matroids/circuits_matroid.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matroids/circuits_matroid.pxd +38 -0
- sage/matroids/circuits_matroid.pyx +947 -0
- sage/matroids/constructor.py +1086 -0
- sage/matroids/database_collections.py +365 -0
- sage/matroids/database_matroids.py +5338 -0
- sage/matroids/dual_matroid.py +583 -0
- sage/matroids/extension.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matroids/extension.pxd +34 -0
- sage/matroids/extension.pyx +519 -0
- sage/matroids/flats_matroid.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matroids/flats_matroid.pxd +28 -0
- sage/matroids/flats_matroid.pyx +715 -0
- sage/matroids/gammoid.py +600 -0
- sage/matroids/graphic_matroid.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matroids/graphic_matroid.pxd +39 -0
- sage/matroids/graphic_matroid.pyx +2024 -0
- sage/matroids/lean_matrix.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matroids/lean_matrix.pxd +126 -0
- sage/matroids/lean_matrix.pyx +3667 -0
- sage/matroids/linear_matroid.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matroids/linear_matroid.pxd +180 -0
- sage/matroids/linear_matroid.pyx +6649 -0
- sage/matroids/matroid.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matroids/matroid.pxd +243 -0
- sage/matroids/matroid.pyx +8759 -0
- sage/matroids/matroids_catalog.py +190 -0
- sage/matroids/matroids_plot_helpers.py +890 -0
- sage/matroids/minor_matroid.py +480 -0
- sage/matroids/minorfix.h +9 -0
- sage/matroids/named_matroids.py +5 -0
- sage/matroids/rank_matroid.py +268 -0
- sage/matroids/set_system.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matroids/set_system.pxd +38 -0
- sage/matroids/set_system.pyx +800 -0
- sage/matroids/transversal_matroid.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matroids/transversal_matroid.pxd +14 -0
- sage/matroids/transversal_matroid.pyx +893 -0
- sage/matroids/union_matroid.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matroids/union_matroid.pxd +20 -0
- sage/matroids/union_matroid.pyx +331 -0
- sage/matroids/unpickling.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matroids/unpickling.pyx +843 -0
- sage/matroids/utilities.py +809 -0
- sage/misc/all__sagemath_modules.py +20 -0
- sage/misc/c3.cpython-314-x86_64-linux-musl.so +0 -0
- sage/misc/c3.pyx +238 -0
- sage/misc/compat.py +87 -0
- sage/misc/element_with_label.py +173 -0
- sage/misc/func_persist.py +79 -0
- sage/misc/pickle_old.cpython-314-x86_64-linux-musl.so +0 -0
- sage/misc/pickle_old.pyx +19 -0
- sage/misc/proof.py +7 -0
- sage/misc/replace_dot_all.py +472 -0
- sage/misc/sagedoc_conf.py +168 -0
- sage/misc/sphinxify.py +167 -0
- sage/misc/test_class_pickling.py +85 -0
- sage/modules/all.py +42 -0
- sage/modules/complex_double_vector.py +25 -0
- sage/modules/diamond_cutting.py +380 -0
- sage/modules/fg_pid/all.py +1 -0
- sage/modules/fg_pid/fgp_element.py +456 -0
- sage/modules/fg_pid/fgp_module.py +2091 -0
- sage/modules/fg_pid/fgp_morphism.py +550 -0
- sage/modules/filtered_vector_space.py +1271 -0
- sage/modules/finite_submodule_iter.cpython-314-x86_64-linux-musl.so +0 -0
- sage/modules/finite_submodule_iter.pxd +27 -0
- sage/modules/finite_submodule_iter.pyx +452 -0
- sage/modules/fp_graded/all.py +1 -0
- sage/modules/fp_graded/element.py +346 -0
- sage/modules/fp_graded/free_element.py +298 -0
- sage/modules/fp_graded/free_homspace.py +53 -0
- sage/modules/fp_graded/free_module.py +1060 -0
- sage/modules/fp_graded/free_morphism.py +217 -0
- sage/modules/fp_graded/homspace.py +563 -0
- sage/modules/fp_graded/module.py +1340 -0
- sage/modules/fp_graded/morphism.py +1990 -0
- sage/modules/fp_graded/steenrod/all.py +1 -0
- sage/modules/fp_graded/steenrod/homspace.py +65 -0
- sage/modules/fp_graded/steenrod/module.py +477 -0
- sage/modules/fp_graded/steenrod/morphism.py +404 -0
- sage/modules/fp_graded/steenrod/profile.py +241 -0
- sage/modules/free_module.py +8447 -0
- sage/modules/free_module_element.cpython-314-x86_64-linux-musl.so +0 -0
- sage/modules/free_module_element.pxd +22 -0
- sage/modules/free_module_element.pyx +5445 -0
- sage/modules/free_module_homspace.py +369 -0
- sage/modules/free_module_integer.py +896 -0
- sage/modules/free_module_morphism.py +823 -0
- sage/modules/free_module_pseudohomspace.py +352 -0
- sage/modules/free_module_pseudomorphism.py +578 -0
- sage/modules/free_quadratic_module.py +1706 -0
- sage/modules/free_quadratic_module_integer_symmetric.py +1790 -0
- sage/modules/matrix_morphism.py +1745 -0
- sage/modules/misc.py +103 -0
- sage/modules/module_functors.py +192 -0
- sage/modules/multi_filtered_vector_space.py +719 -0
- sage/modules/ore_module.py +2208 -0
- sage/modules/ore_module_element.py +178 -0
- sage/modules/ore_module_homspace.py +147 -0
- sage/modules/ore_module_morphism.py +968 -0
- sage/modules/quotient_module.py +699 -0
- sage/modules/real_double_vector.py +22 -0
- sage/modules/submodule.py +255 -0
- sage/modules/tensor_operations.py +567 -0
- sage/modules/torsion_quadratic_module.py +1352 -0
- sage/modules/tutorial_free_modules.py +248 -0
- sage/modules/vector_complex_double_dense.cpython-314-x86_64-linux-musl.so +0 -0
- sage/modules/vector_complex_double_dense.pxd +6 -0
- sage/modules/vector_complex_double_dense.pyx +117 -0
- sage/modules/vector_double_dense.cpython-314-x86_64-linux-musl.so +0 -0
- sage/modules/vector_double_dense.pxd +6 -0
- sage/modules/vector_double_dense.pyx +604 -0
- sage/modules/vector_integer_dense.cpython-314-x86_64-linux-musl.so +0 -0
- sage/modules/vector_integer_dense.pxd +15 -0
- sage/modules/vector_integer_dense.pyx +361 -0
- sage/modules/vector_integer_sparse.cpython-314-x86_64-linux-musl.so +0 -0
- sage/modules/vector_integer_sparse.pxd +29 -0
- sage/modules/vector_integer_sparse.pyx +406 -0
- sage/modules/vector_modn_dense.cpython-314-x86_64-linux-musl.so +0 -0
- sage/modules/vector_modn_dense.pxd +12 -0
- sage/modules/vector_modn_dense.pyx +394 -0
- sage/modules/vector_modn_sparse.cpython-314-x86_64-linux-musl.so +0 -0
- sage/modules/vector_modn_sparse.pxd +21 -0
- sage/modules/vector_modn_sparse.pyx +298 -0
- sage/modules/vector_numpy_dense.cpython-314-x86_64-linux-musl.so +0 -0
- sage/modules/vector_numpy_dense.pxd +15 -0
- sage/modules/vector_numpy_dense.pyx +304 -0
- sage/modules/vector_numpy_integer_dense.cpython-314-x86_64-linux-musl.so +0 -0
- sage/modules/vector_numpy_integer_dense.pxd +7 -0
- sage/modules/vector_numpy_integer_dense.pyx +54 -0
- sage/modules/vector_rational_dense.cpython-314-x86_64-linux-musl.so +0 -0
- sage/modules/vector_rational_dense.pxd +15 -0
- sage/modules/vector_rational_dense.pyx +387 -0
- sage/modules/vector_rational_sparse.cpython-314-x86_64-linux-musl.so +0 -0
- sage/modules/vector_rational_sparse.pxd +30 -0
- sage/modules/vector_rational_sparse.pyx +413 -0
- sage/modules/vector_real_double_dense.cpython-314-x86_64-linux-musl.so +0 -0
- sage/modules/vector_real_double_dense.pxd +6 -0
- sage/modules/vector_real_double_dense.pyx +126 -0
- sage/modules/vector_space_homspace.py +430 -0
- sage/modules/vector_space_morphism.py +989 -0
- sage/modules/with_basis/all.py +15 -0
- sage/modules/with_basis/cell_module.py +494 -0
- sage/modules/with_basis/indexed_element.cpython-314-x86_64-linux-musl.so +0 -0
- sage/modules/with_basis/indexed_element.pxd +13 -0
- sage/modules/with_basis/indexed_element.pyx +1058 -0
- sage/modules/with_basis/invariant.py +1075 -0
- sage/modules/with_basis/morphism.py +1636 -0
- sage/modules/with_basis/representation.py +2939 -0
- sage/modules/with_basis/subquotient.py +685 -0
- sage/numerical/all__sagemath_modules.py +6 -0
- sage/numerical/gauss_legendre.cpython-314-x86_64-linux-musl.so +0 -0
- sage/numerical/gauss_legendre.pyx +381 -0
- sage/numerical/optimize.py +910 -0
- sage/probability/all.py +10 -0
- sage/probability/probability_distribution.cpython-314-x86_64-linux-musl.so +0 -0
- sage/probability/probability_distribution.pyx +1242 -0
- sage/probability/random_variable.py +411 -0
- sage/quadratic_forms/all.py +4 -0
- sage/quadratic_forms/all__sagemath_modules.py +15 -0
- sage/quadratic_forms/binary_qf.py +2042 -0
- sage/quadratic_forms/bqf_class_group.py +748 -0
- sage/quadratic_forms/constructions.py +93 -0
- sage/quadratic_forms/count_local_2.cpython-314-x86_64-linux-musl.so +0 -0
- sage/quadratic_forms/count_local_2.pyx +365 -0
- sage/quadratic_forms/extras.py +195 -0
- sage/quadratic_forms/quadratic_form.py +1753 -0
- sage/quadratic_forms/quadratic_form__count_local_2.py +221 -0
- sage/quadratic_forms/quadratic_form__equivalence_testing.py +708 -0
- sage/quadratic_forms/quadratic_form__evaluate.cpython-314-x86_64-linux-musl.so +0 -0
- sage/quadratic_forms/quadratic_form__evaluate.pyx +139 -0
- sage/quadratic_forms/quadratic_form__local_density_congruence.py +977 -0
- sage/quadratic_forms/quadratic_form__local_field_invariants.py +1072 -0
- sage/quadratic_forms/quadratic_form__neighbors.py +424 -0
- sage/quadratic_forms/quadratic_form__reduction_theory.py +488 -0
- sage/quadratic_forms/quadratic_form__split_local_covering.py +416 -0
- sage/quadratic_forms/quadratic_form__ternary_Tornaria.py +657 -0
- sage/quadratic_forms/quadratic_form__theta.py +352 -0
- sage/quadratic_forms/quadratic_form__variable_substitutions.py +370 -0
- sage/quadratic_forms/random_quadraticform.py +209 -0
- sage/quadratic_forms/ternary.cpython-314-x86_64-linux-musl.so +0 -0
- sage/quadratic_forms/ternary.pyx +1154 -0
- sage/quadratic_forms/ternary_qf.py +2027 -0
- sage/rings/all__sagemath_modules.py +28 -0
- sage/rings/asymptotic/all__sagemath_modules.py +1 -0
- sage/rings/asymptotic/misc.py +1252 -0
- sage/rings/cc.py +4 -0
- sage/rings/cfinite_sequence.py +1306 -0
- sage/rings/complex_conversion.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/complex_conversion.pxd +8 -0
- sage/rings/complex_conversion.pyx +23 -0
- sage/rings/complex_double.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/complex_double.pxd +21 -0
- sage/rings/complex_double.pyx +2654 -0
- sage/rings/complex_mpc.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/complex_mpc.pxd +21 -0
- sage/rings/complex_mpc.pyx +2576 -0
- sage/rings/complex_mpfr.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/complex_mpfr.pxd +18 -0
- sage/rings/complex_mpfr.pyx +3602 -0
- sage/rings/derivation.py +2334 -0
- sage/rings/finite_rings/all__sagemath_modules.py +1 -0
- sage/rings/finite_rings/maps_finite_field.py +191 -0
- sage/rings/function_field/all__sagemath_modules.py +8 -0
- sage/rings/function_field/derivations.py +102 -0
- sage/rings/function_field/derivations_rational.py +132 -0
- sage/rings/function_field/differential.py +853 -0
- sage/rings/function_field/divisor.py +1107 -0
- sage/rings/function_field/drinfeld_modules/action.py +199 -0
- sage/rings/function_field/drinfeld_modules/all.py +1 -0
- sage/rings/function_field/drinfeld_modules/charzero_drinfeld_module.py +673 -0
- sage/rings/function_field/drinfeld_modules/drinfeld_module.py +2087 -0
- sage/rings/function_field/drinfeld_modules/finite_drinfeld_module.py +1131 -0
- sage/rings/function_field/drinfeld_modules/homset.py +420 -0
- sage/rings/function_field/drinfeld_modules/morphism.py +820 -0
- sage/rings/function_field/hermite_form_polynomial.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/function_field/hermite_form_polynomial.pyx +188 -0
- sage/rings/function_field/khuri_makdisi.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/function_field/khuri_makdisi.pyx +935 -0
- sage/rings/invariants/all.py +4 -0
- sage/rings/invariants/invariant_theory.py +4597 -0
- sage/rings/invariants/reconstruction.py +395 -0
- sage/rings/polynomial/all__sagemath_modules.py +17 -0
- sage/rings/polynomial/integer_valued_polynomials.py +1230 -0
- sage/rings/polynomial/laurent_polynomial_mpair.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/polynomial/laurent_polynomial_mpair.pxd +15 -0
- sage/rings/polynomial/laurent_polynomial_mpair.pyx +2023 -0
- sage/rings/polynomial/ore_function_element.py +952 -0
- sage/rings/polynomial/ore_function_field.py +1028 -0
- sage/rings/polynomial/ore_polynomial_element.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/polynomial/ore_polynomial_element.pxd +48 -0
- sage/rings/polynomial/ore_polynomial_element.pyx +3145 -0
- sage/rings/polynomial/ore_polynomial_ring.py +1334 -0
- sage/rings/polynomial/polynomial_real_mpfr_dense.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/polynomial/polynomial_real_mpfr_dense.pyx +788 -0
- sage/rings/polynomial/q_integer_valued_polynomials.py +1264 -0
- sage/rings/polynomial/skew_polynomial_element.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/polynomial/skew_polynomial_element.pxd +9 -0
- sage/rings/polynomial/skew_polynomial_element.pyx +684 -0
- sage/rings/polynomial/skew_polynomial_finite_field.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/polynomial/skew_polynomial_finite_field.pxd +19 -0
- sage/rings/polynomial/skew_polynomial_finite_field.pyx +1093 -0
- sage/rings/polynomial/skew_polynomial_finite_order.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/polynomial/skew_polynomial_finite_order.pxd +10 -0
- sage/rings/polynomial/skew_polynomial_finite_order.pyx +567 -0
- sage/rings/polynomial/skew_polynomial_ring.py +908 -0
- sage/rings/real_double_element_gsl.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/real_double_element_gsl.pxd +8 -0
- sage/rings/real_double_element_gsl.pyx +794 -0
- sage/rings/real_field.py +58 -0
- sage/rings/real_mpfr.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/real_mpfr.pxd +29 -0
- sage/rings/real_mpfr.pyx +6122 -0
- sage/rings/ring_extension.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/ring_extension.pxd +42 -0
- sage/rings/ring_extension.pyx +2779 -0
- sage/rings/ring_extension_conversion.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/ring_extension_conversion.pxd +16 -0
- sage/rings/ring_extension_conversion.pyx +462 -0
- sage/rings/ring_extension_element.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/ring_extension_element.pxd +21 -0
- sage/rings/ring_extension_element.pyx +1635 -0
- sage/rings/ring_extension_homset.py +64 -0
- sage/rings/ring_extension_morphism.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/ring_extension_morphism.pxd +35 -0
- sage/rings/ring_extension_morphism.pyx +920 -0
- sage/schemes/all__sagemath_modules.py +1 -0
- sage/schemes/projective/all__sagemath_modules.py +1 -0
- sage/schemes/projective/coherent_sheaf.py +300 -0
- sage/schemes/projective/cohomology.py +510 -0
- sage/stats/all.py +15 -0
- sage/stats/basic_stats.py +489 -0
- sage/stats/distributions/all.py +7 -0
- sage/stats/distributions/catalog.py +34 -0
- sage/stats/distributions/dgs.h +50 -0
- sage/stats/distributions/dgs.pxd +111 -0
- sage/stats/distributions/dgs_bern.h +400 -0
- sage/stats/distributions/dgs_gauss.h +614 -0
- sage/stats/distributions/dgs_misc.h +104 -0
- sage/stats/distributions/discrete_gaussian_integer.cpython-314-x86_64-linux-musl.so +0 -0
- sage/stats/distributions/discrete_gaussian_integer.pxd +14 -0
- sage/stats/distributions/discrete_gaussian_integer.pyx +498 -0
- sage/stats/distributions/discrete_gaussian_lattice.py +908 -0
- sage/stats/distributions/discrete_gaussian_polynomial.py +141 -0
- sage/stats/hmm/all.py +15 -0
- sage/stats/hmm/chmm.cpython-314-x86_64-linux-musl.so +0 -0
- sage/stats/hmm/chmm.pyx +1595 -0
- sage/stats/hmm/distributions.cpython-314-x86_64-linux-musl.so +0 -0
- sage/stats/hmm/distributions.pxd +29 -0
- sage/stats/hmm/distributions.pyx +531 -0
- sage/stats/hmm/hmm.cpython-314-x86_64-linux-musl.so +0 -0
- sage/stats/hmm/hmm.pxd +17 -0
- sage/stats/hmm/hmm.pyx +1388 -0
- sage/stats/hmm/util.cpython-314-x86_64-linux-musl.so +0 -0
- sage/stats/hmm/util.pxd +7 -0
- sage/stats/hmm/util.pyx +165 -0
- sage/stats/intlist.cpython-314-x86_64-linux-musl.so +0 -0
- sage/stats/intlist.pxd +14 -0
- sage/stats/intlist.pyx +588 -0
- sage/stats/r.py +49 -0
- sage/stats/time_series.cpython-314-x86_64-linux-musl.so +0 -0
- sage/stats/time_series.pxd +6 -0
- sage/stats/time_series.pyx +2546 -0
- sage/tensor/all.py +2 -0
- sage/tensor/modules/all.py +8 -0
- sage/tensor/modules/alternating_contr_tensor.py +761 -0
- sage/tensor/modules/comp.py +5598 -0
- sage/tensor/modules/ext_pow_free_module.py +824 -0
- sage/tensor/modules/finite_rank_free_module.py +3589 -0
- sage/tensor/modules/format_utilities.py +333 -0
- sage/tensor/modules/free_module_alt_form.py +858 -0
- sage/tensor/modules/free_module_automorphism.py +1207 -0
- sage/tensor/modules/free_module_basis.py +1074 -0
- sage/tensor/modules/free_module_element.py +284 -0
- sage/tensor/modules/free_module_homset.py +652 -0
- sage/tensor/modules/free_module_linear_group.py +564 -0
- sage/tensor/modules/free_module_morphism.py +1581 -0
- sage/tensor/modules/free_module_tensor.py +3289 -0
- sage/tensor/modules/reflexive_module.py +386 -0
- sage/tensor/modules/tensor_free_module.py +780 -0
- sage/tensor/modules/tensor_free_submodule.py +538 -0
- sage/tensor/modules/tensor_free_submodule_basis.py +140 -0
- sage/tensor/modules/tensor_with_indices.py +1043 -0
|
@@ -0,0 +1,3602 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-modules
|
|
2
|
+
"""
|
|
3
|
+
Arbitrary precision floating point complex numbers using GNU MPFR
|
|
4
|
+
|
|
5
|
+
AUTHORS:
|
|
6
|
+
|
|
7
|
+
- William Stein (2006-01-26): complete rewrite
|
|
8
|
+
|
|
9
|
+
- Joel B. Mohler (2006-12-16): naive rewrite into pyrex
|
|
10
|
+
|
|
11
|
+
- William Stein(2007-01): rewrite of Mohler's rewrite
|
|
12
|
+
|
|
13
|
+
- Vincent Delecroix (2010-01): plot function
|
|
14
|
+
|
|
15
|
+
- Niles Johnson (2010-08): :issue:`3893`: ``random_element()`` should pass on
|
|
16
|
+
``*args`` and ``**kwds``.
|
|
17
|
+
|
|
18
|
+
- Travis Scrimshaw (2012-10-18): Added documentation for full coverage
|
|
19
|
+
|
|
20
|
+
- Vincent Klein (2017-11-14) : add __mpc__() to class ComplexNumber.
|
|
21
|
+
ComplexNumber constructor support gmpy2.mpc parameter.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
# ****************************************************************************
|
|
25
|
+
# Copyright (C) 2006 William Stein <wstein@gmail.com>
|
|
26
|
+
# 2020 Vincent Delecroix <20100.delecroix@gmail.com>
|
|
27
|
+
#
|
|
28
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
|
29
|
+
# as published by the Free Software Foundation; either version 2 of
|
|
30
|
+
# the License, or (at your option) any later version.
|
|
31
|
+
# https://www.gnu.org/licenses/
|
|
32
|
+
# ****************************************************************************
|
|
33
|
+
import re
|
|
34
|
+
import weakref
|
|
35
|
+
|
|
36
|
+
from sage.libs.mpfr cimport *
|
|
37
|
+
|
|
38
|
+
from sage.structure.parent cimport Parent
|
|
39
|
+
from sage.structure.element cimport RingElement, Element
|
|
40
|
+
from sage.structure.richcmp cimport rich_to_bool
|
|
41
|
+
from sage.categories.map cimport Map
|
|
42
|
+
|
|
43
|
+
import sage.rings.abc
|
|
44
|
+
from sage.arith.constants cimport LOG_TEN_TWO_PLUS_EPSILON
|
|
45
|
+
from sage.rings import infinity
|
|
46
|
+
from sage.rings.integer cimport Integer
|
|
47
|
+
|
|
48
|
+
from sage.rings.complex_double cimport ComplexDoubleElement
|
|
49
|
+
from sage.rings.real_mpfr cimport RealNumber
|
|
50
|
+
|
|
51
|
+
from sage.libs.mpmath.utils cimport mpfr_to_mpfval
|
|
52
|
+
from sage.rings.integer_ring import ZZ
|
|
53
|
+
|
|
54
|
+
cimport gmpy2
|
|
55
|
+
gmpy2.import_gmpy2()
|
|
56
|
+
|
|
57
|
+
try:
|
|
58
|
+
from cypari2.gen import Gen as pari_gen
|
|
59
|
+
from cypari2.handle_error import PariError
|
|
60
|
+
from sage.libs.pari import pari
|
|
61
|
+
except ImportError:
|
|
62
|
+
pari_gen = PariError = ()
|
|
63
|
+
|
|
64
|
+
# Some objects that are not imported at startup in order to break
|
|
65
|
+
# circular imports
|
|
66
|
+
NumberFieldElement_quadratic = ()
|
|
67
|
+
AA = None
|
|
68
|
+
QQbar = None
|
|
69
|
+
CDF = CLF = RLF = None
|
|
70
|
+
|
|
71
|
+
# useful for parsing
|
|
72
|
+
NUMBERS = re.compile("[0-9]")
|
|
73
|
+
BLOCK = re.compile(r'[+-]?(?:I\*|)[0-9\.]*(?:e[+-]?[0-9]*|)\*?I?')
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def late_import():
|
|
77
|
+
"""
|
|
78
|
+
Import the objects/modules after build (when needed).
|
|
79
|
+
|
|
80
|
+
TESTS::
|
|
81
|
+
|
|
82
|
+
sage: sage.rings.complex_mpfr.late_import()
|
|
83
|
+
"""
|
|
84
|
+
global NumberFieldElement_quadratic
|
|
85
|
+
global AA, QQbar
|
|
86
|
+
global CLF, RLF, CDF
|
|
87
|
+
if CLF is None:
|
|
88
|
+
try:
|
|
89
|
+
from sage.rings.number_field.number_field_element_quadratic import NumberFieldElement_quadratic
|
|
90
|
+
from sage.rings.qqbar import AA, QQbar
|
|
91
|
+
except ImportError:
|
|
92
|
+
pass
|
|
93
|
+
from sage.rings.real_lazy import CLF, RLF
|
|
94
|
+
from sage.rings.complex_double import CDF
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
cdef object numpy_complex_interface = {'typestr': '=c16'}
|
|
98
|
+
cdef object numpy_object_interface = {'typestr': '|O'}
|
|
99
|
+
|
|
100
|
+
cdef mpfr_rnd_t rnd
|
|
101
|
+
rnd = MPFR_RNDN
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def set_global_complex_round_mode(n):
|
|
105
|
+
"""
|
|
106
|
+
Set the global complex rounding mode.
|
|
107
|
+
|
|
108
|
+
.. WARNING::
|
|
109
|
+
|
|
110
|
+
Do not call this function explicitly. The default rounding mode is
|
|
111
|
+
``n = 0``.
|
|
112
|
+
|
|
113
|
+
EXAMPLES::
|
|
114
|
+
|
|
115
|
+
sage: sage.rings.complex_mpfr.set_global_complex_round_mode(0)
|
|
116
|
+
"""
|
|
117
|
+
global rnd
|
|
118
|
+
rnd = n
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def is_ComplexNumber(x):
|
|
122
|
+
r"""
|
|
123
|
+
Return ``True`` if ``x`` is a complex number. In particular, if ``x`` is
|
|
124
|
+
of the :class:`ComplexNumber` type.
|
|
125
|
+
|
|
126
|
+
EXAMPLES::
|
|
127
|
+
|
|
128
|
+
sage: from sage.rings.complex_mpfr import is_ComplexNumber
|
|
129
|
+
sage: a = ComplexNumber(1, 2); a
|
|
130
|
+
1.00000000000000 + 2.00000000000000*I
|
|
131
|
+
sage: is_ComplexNumber(a)
|
|
132
|
+
doctest:warning...
|
|
133
|
+
DeprecationWarning: The function is_ComplexNumber is deprecated;
|
|
134
|
+
use 'isinstance(..., ComplexNumber)' instead.
|
|
135
|
+
See https://github.com/sagemath/sage/issues/38128 for details.
|
|
136
|
+
True
|
|
137
|
+
sage: b = ComplexNumber(1); b
|
|
138
|
+
1.00000000000000
|
|
139
|
+
sage: is_ComplexNumber(b)
|
|
140
|
+
True
|
|
141
|
+
|
|
142
|
+
Note that the global element ``I`` is a number field element, of type
|
|
143
|
+
:class:`sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_gaussian`,
|
|
144
|
+
while elements of the class :class:`ComplexField_class`
|
|
145
|
+
are of type :class:`ComplexNumber`::
|
|
146
|
+
|
|
147
|
+
sage: # needs sage.symbolic
|
|
148
|
+
sage: c = 1 + 2*I
|
|
149
|
+
sage: is_ComplexNumber(c)
|
|
150
|
+
False
|
|
151
|
+
sage: d = CC(1 + 2*I)
|
|
152
|
+
sage: is_ComplexNumber(d)
|
|
153
|
+
True
|
|
154
|
+
"""
|
|
155
|
+
from sage.misc.superseded import deprecation_cython
|
|
156
|
+
deprecation_cython(38128,
|
|
157
|
+
"The function is_ComplexNumber is deprecated; "
|
|
158
|
+
"use 'isinstance(..., ComplexNumber)' instead.")
|
|
159
|
+
return isinstance(x, ComplexNumber)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
cache = {}
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def ComplexField(prec=53, names=None):
|
|
166
|
+
"""
|
|
167
|
+
Return the complex field with real and imaginary parts having prec
|
|
168
|
+
*bits* of precision.
|
|
169
|
+
|
|
170
|
+
EXAMPLES::
|
|
171
|
+
|
|
172
|
+
sage: ComplexField()
|
|
173
|
+
Complex Field with 53 bits of precision
|
|
174
|
+
sage: ComplexField(100)
|
|
175
|
+
Complex Field with 100 bits of precision
|
|
176
|
+
sage: ComplexField(100).base_ring()
|
|
177
|
+
Real Field with 100 bits of precision
|
|
178
|
+
sage: i = ComplexField(200).gen()
|
|
179
|
+
sage: i^2
|
|
180
|
+
-1.0000000000000000000000000000000000000000000000000000000000
|
|
181
|
+
|
|
182
|
+
.. SEEALSO::
|
|
183
|
+
|
|
184
|
+
- :class:`~sage.rings.complex_mpfr.ComplexField_class`
|
|
185
|
+
- :class:`~sage.rings.real_arb.ComplexBallField` (complex numbers with
|
|
186
|
+
rigorous error bounds)
|
|
187
|
+
"""
|
|
188
|
+
global cache
|
|
189
|
+
if prec in cache:
|
|
190
|
+
X = cache[prec]
|
|
191
|
+
C = X()
|
|
192
|
+
if C is not None:
|
|
193
|
+
return C
|
|
194
|
+
C = ComplexField_class(prec)
|
|
195
|
+
cache[prec] = weakref.ref(C)
|
|
196
|
+
return C
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
class ComplexField_class(sage.rings.abc.ComplexField):
|
|
200
|
+
"""
|
|
201
|
+
An approximation to the field of complex numbers using floating
|
|
202
|
+
point numbers with any specified precision. Answers derived from
|
|
203
|
+
calculations in this approximation may differ from what they would
|
|
204
|
+
be if those calculations were performed in the true field of
|
|
205
|
+
complex numbers. This is due to the rounding errors inherent to
|
|
206
|
+
finite precision calculations.
|
|
207
|
+
|
|
208
|
+
EXAMPLES::
|
|
209
|
+
|
|
210
|
+
sage: C = ComplexField(); C
|
|
211
|
+
Complex Field with 53 bits of precision
|
|
212
|
+
sage: Q = RationalField()
|
|
213
|
+
sage: C(1/3)
|
|
214
|
+
0.333333333333333
|
|
215
|
+
sage: C(1/3, 2)
|
|
216
|
+
0.333333333333333 + 2.00000000000000*I
|
|
217
|
+
sage: C(RR.pi())
|
|
218
|
+
3.14159265358979
|
|
219
|
+
sage: C(RR.log2(), RR.pi())
|
|
220
|
+
0.693147180559945 + 3.14159265358979*I
|
|
221
|
+
|
|
222
|
+
We can also coerce rational numbers and integers into C, but
|
|
223
|
+
coercing a polynomial will raise an exception::
|
|
224
|
+
|
|
225
|
+
sage: Q = RationalField()
|
|
226
|
+
sage: C(1/3)
|
|
227
|
+
0.333333333333333
|
|
228
|
+
sage: S = PolynomialRing(Q, 'x')
|
|
229
|
+
sage: C(S.gen())
|
|
230
|
+
Traceback (most recent call last):
|
|
231
|
+
...
|
|
232
|
+
TypeError: cannot convert nonconstant polynomial
|
|
233
|
+
|
|
234
|
+
This illustrates precision::
|
|
235
|
+
|
|
236
|
+
sage: CC = ComplexField(10); CC(1/3, 2/3)
|
|
237
|
+
0.33 + 0.67*I
|
|
238
|
+
sage: CC
|
|
239
|
+
Complex Field with 10 bits of precision
|
|
240
|
+
sage: CC = ComplexField(100); CC
|
|
241
|
+
Complex Field with 100 bits of precision
|
|
242
|
+
sage: z = CC(1/3, 2/3); z
|
|
243
|
+
0.33333333333333333333333333333 + 0.66666666666666666666666666667*I
|
|
244
|
+
|
|
245
|
+
We can load and save complex numbers and the complex field::
|
|
246
|
+
|
|
247
|
+
sage: loads(z.dumps()) == z
|
|
248
|
+
True
|
|
249
|
+
sage: loads(CC.dumps()) == CC
|
|
250
|
+
True
|
|
251
|
+
sage: k = ComplexField(100)
|
|
252
|
+
sage: loads(dumps(k)) == k
|
|
253
|
+
True
|
|
254
|
+
|
|
255
|
+
This illustrates basic properties of a complex field::
|
|
256
|
+
|
|
257
|
+
sage: CC = ComplexField(200)
|
|
258
|
+
sage: CC.is_field()
|
|
259
|
+
True
|
|
260
|
+
sage: CC.characteristic()
|
|
261
|
+
0
|
|
262
|
+
sage: CC.precision()
|
|
263
|
+
200
|
|
264
|
+
sage: CC.variable_name()
|
|
265
|
+
'I'
|
|
266
|
+
sage: CC == ComplexField(200)
|
|
267
|
+
True
|
|
268
|
+
sage: CC == ComplexField(53)
|
|
269
|
+
False
|
|
270
|
+
sage: CC == 1.1
|
|
271
|
+
False
|
|
272
|
+
|
|
273
|
+
.. SEEALSO::
|
|
274
|
+
|
|
275
|
+
- :func:`~sage.rings.complex_mpfr.ComplexField` (constructor)
|
|
276
|
+
- :class:`~sage.rings.real_arb.ComplexBallField` (complex numbers with
|
|
277
|
+
rigorous error bounds)
|
|
278
|
+
- :mod:`~sage.rings.real_mpfr`
|
|
279
|
+
"""
|
|
280
|
+
def __init__(self, prec=53):
|
|
281
|
+
"""
|
|
282
|
+
Initialize ``self``.
|
|
283
|
+
|
|
284
|
+
TESTS::
|
|
285
|
+
|
|
286
|
+
sage: C = ComplexField(200)
|
|
287
|
+
sage: C.category()
|
|
288
|
+
Join of Category of fields and Category of infinite sets and Category of complete metric spaces
|
|
289
|
+
sage: TestSuite(C).run()
|
|
290
|
+
|
|
291
|
+
sage: CC.is_field()
|
|
292
|
+
True
|
|
293
|
+
|
|
294
|
+
sage: CC.is_finite()
|
|
295
|
+
False
|
|
296
|
+
"""
|
|
297
|
+
self._prec = int(prec)
|
|
298
|
+
from sage.categories.fields import Fields
|
|
299
|
+
Parent.__init__(self, self._real_field(), names=('I',),
|
|
300
|
+
normalize=False,
|
|
301
|
+
category=Fields().Infinite().Metric().Complete())
|
|
302
|
+
self._populate_coercion_lists_(coerce_list=[RRtoCC(self._real_field(), self)],
|
|
303
|
+
convert_method_name='_complex_mpfr_')
|
|
304
|
+
|
|
305
|
+
def __reduce__(self):
|
|
306
|
+
"""
|
|
307
|
+
For pickling.
|
|
308
|
+
|
|
309
|
+
EXAMPLES::
|
|
310
|
+
|
|
311
|
+
sage: loads(dumps(ComplexField())) == ComplexField()
|
|
312
|
+
True
|
|
313
|
+
"""
|
|
314
|
+
return ComplexField, (self._prec, )
|
|
315
|
+
|
|
316
|
+
def is_exact(self):
|
|
317
|
+
"""
|
|
318
|
+
Return whether or not this field is exact, which is always ``False``.
|
|
319
|
+
|
|
320
|
+
EXAMPLES::
|
|
321
|
+
|
|
322
|
+
sage: ComplexField().is_exact()
|
|
323
|
+
False
|
|
324
|
+
"""
|
|
325
|
+
return False
|
|
326
|
+
|
|
327
|
+
def prec(self):
|
|
328
|
+
"""
|
|
329
|
+
Return the precision of this complex field.
|
|
330
|
+
|
|
331
|
+
EXAMPLES::
|
|
332
|
+
|
|
333
|
+
sage: ComplexField().prec()
|
|
334
|
+
53
|
|
335
|
+
sage: ComplexField(15).prec()
|
|
336
|
+
15
|
|
337
|
+
"""
|
|
338
|
+
return self._prec
|
|
339
|
+
|
|
340
|
+
def _magma_init_(self, magma):
|
|
341
|
+
r"""
|
|
342
|
+
Return a string representation of ``self`` in the Magma language.
|
|
343
|
+
|
|
344
|
+
EXAMPLES::
|
|
345
|
+
|
|
346
|
+
sage: ComplexField()._magma_init_(magma) # optional - magma
|
|
347
|
+
'ComplexField(53 : Bits := true)'
|
|
348
|
+
sage: magma(ComplexField(200)) # optional - magma
|
|
349
|
+
Complex field of precision 60
|
|
350
|
+
sage: 10^60 < 2^200 < 10^61
|
|
351
|
+
True
|
|
352
|
+
sage: s = magma(ComplexField(200)).sage(); s # optional - magma
|
|
353
|
+
Complex Field with 200 bits of precision
|
|
354
|
+
sage: 2^199 < 10^60 < 2^200
|
|
355
|
+
True
|
|
356
|
+
sage: s is ComplexField(200) # optional - magma
|
|
357
|
+
True
|
|
358
|
+
"""
|
|
359
|
+
return "ComplexField(%s : Bits := true)" % self.prec()
|
|
360
|
+
|
|
361
|
+
precision = prec
|
|
362
|
+
|
|
363
|
+
def to_prec(self, prec):
|
|
364
|
+
"""
|
|
365
|
+
Return the complex field to the specified precision.
|
|
366
|
+
|
|
367
|
+
EXAMPLES::
|
|
368
|
+
|
|
369
|
+
sage: CC.to_prec(10)
|
|
370
|
+
Complex Field with 10 bits of precision
|
|
371
|
+
sage: CC.to_prec(100)
|
|
372
|
+
Complex Field with 100 bits of precision
|
|
373
|
+
"""
|
|
374
|
+
return ComplexField(prec)
|
|
375
|
+
|
|
376
|
+
# very useful to cache this.
|
|
377
|
+
def _real_field(self):
|
|
378
|
+
"""
|
|
379
|
+
Return the underlying real field with the same precision.
|
|
380
|
+
|
|
381
|
+
EXAMPLES::
|
|
382
|
+
|
|
383
|
+
sage: RF = ComplexField(10)._real_field(); RF
|
|
384
|
+
Real Field with 10 bits of precision
|
|
385
|
+
sage: ComplexField(10)._real_field() is RF
|
|
386
|
+
True
|
|
387
|
+
"""
|
|
388
|
+
try:
|
|
389
|
+
return self.__real_field
|
|
390
|
+
except AttributeError:
|
|
391
|
+
from sage.rings.real_mpfr import RealField
|
|
392
|
+
self.__real_field = RealField(self._prec)
|
|
393
|
+
return self.__real_field
|
|
394
|
+
|
|
395
|
+
def __eq__(self, other):
|
|
396
|
+
"""
|
|
397
|
+
Check whether ``self`` is not equal to ``other``.
|
|
398
|
+
|
|
399
|
+
If ``other`` is not a :class:`ComplexField_class`, then this
|
|
400
|
+
return ``False``. Otherwise it compares their precision.
|
|
401
|
+
|
|
402
|
+
EXAMPLES::
|
|
403
|
+
|
|
404
|
+
sage: ComplexField() == ComplexField()
|
|
405
|
+
True
|
|
406
|
+
sage: ComplexField(10) == ComplexField(15)
|
|
407
|
+
False
|
|
408
|
+
"""
|
|
409
|
+
if not isinstance(other, ComplexField_class):
|
|
410
|
+
return NotImplemented
|
|
411
|
+
return self._prec == other._prec
|
|
412
|
+
|
|
413
|
+
def __hash__(self):
|
|
414
|
+
"""
|
|
415
|
+
Return the hash.
|
|
416
|
+
|
|
417
|
+
EXAMPLES::
|
|
418
|
+
|
|
419
|
+
sage: C = ComplexField(200)
|
|
420
|
+
sage: from sage.rings.complex_mpfr import ComplexField_class
|
|
421
|
+
sage: D = ComplexField_class(200)
|
|
422
|
+
sage: hash(C) == hash(D)
|
|
423
|
+
True
|
|
424
|
+
"""
|
|
425
|
+
return hash((self.__class__, self._prec))
|
|
426
|
+
|
|
427
|
+
def __ne__(self, other):
|
|
428
|
+
"""
|
|
429
|
+
Check whether ``self`` is not equal to ``other``.
|
|
430
|
+
|
|
431
|
+
EXAMPLES::
|
|
432
|
+
|
|
433
|
+
sage: ComplexField() != ComplexField()
|
|
434
|
+
False
|
|
435
|
+
sage: ComplexField(10) != ComplexField(15)
|
|
436
|
+
True
|
|
437
|
+
"""
|
|
438
|
+
return not (self == other)
|
|
439
|
+
|
|
440
|
+
def __call__(self, x=None, im=None):
|
|
441
|
+
"""
|
|
442
|
+
Create a complex number.
|
|
443
|
+
|
|
444
|
+
EXAMPLES::
|
|
445
|
+
|
|
446
|
+
sage: CC(2) # indirect doctest
|
|
447
|
+
2.00000000000000
|
|
448
|
+
sage: CC(CC.0)
|
|
449
|
+
1.00000000000000*I
|
|
450
|
+
sage: CC('1+I')
|
|
451
|
+
1.00000000000000 + 1.00000000000000*I
|
|
452
|
+
sage: CC(2,3)
|
|
453
|
+
2.00000000000000 + 3.00000000000000*I
|
|
454
|
+
sage: CC(QQ[I].gen()) # needs sage.symbolic
|
|
455
|
+
1.00000000000000*I
|
|
456
|
+
sage: CC.gen() + QQ[I].gen() # needs sage.symbolic
|
|
457
|
+
2.00000000000000*I
|
|
458
|
+
sage: x = polygen(ZZ, 'x')
|
|
459
|
+
sage: CC.gen() + QQ.extension(x^2 + 1, 'I', embedding=None).gen() # needs sage.rings.number_field
|
|
460
|
+
Traceback (most recent call last):
|
|
461
|
+
...
|
|
462
|
+
TypeError: unsupported operand parent(s) for +:
|
|
463
|
+
'Complex Field with 53 bits of precision' and
|
|
464
|
+
'Number Field in I with defining polynomial x^2 + 1'
|
|
465
|
+
|
|
466
|
+
In the absence of arguments we return zero::
|
|
467
|
+
|
|
468
|
+
sage: a = CC(); a
|
|
469
|
+
0.000000000000000
|
|
470
|
+
sage: a.parent()
|
|
471
|
+
Complex Field with 53 bits of precision
|
|
472
|
+
"""
|
|
473
|
+
if x is None:
|
|
474
|
+
return self.zero()
|
|
475
|
+
# we leave this here to handle the imaginary parameter
|
|
476
|
+
if im is not None:
|
|
477
|
+
x = x, im
|
|
478
|
+
return Parent.__call__(self, x)
|
|
479
|
+
|
|
480
|
+
def _element_constructor_(self, x):
|
|
481
|
+
"""
|
|
482
|
+
Construct a complex number.
|
|
483
|
+
|
|
484
|
+
EXAMPLES::
|
|
485
|
+
|
|
486
|
+
sage: CC((1,2)) # indirect doctest
|
|
487
|
+
1.00000000000000 + 2.00000000000000*I
|
|
488
|
+
|
|
489
|
+
Check that :issue:`14989` is fixed::
|
|
490
|
+
|
|
491
|
+
sage: x = polygen(ZZ, 'x')
|
|
492
|
+
sage: QQi = NumberField(x^2 + 1, 'i', embedding=CC(0,1)) # needs sage.rings.number_field
|
|
493
|
+
sage: i = QQi.order(QQi.gen()).gen(1) # needs sage.rings.number_field
|
|
494
|
+
sage: CC(i) # needs sage.rings.number_field
|
|
495
|
+
1.00000000000000*I
|
|
496
|
+
|
|
497
|
+
TESTS::
|
|
498
|
+
|
|
499
|
+
sage: CC('1.2+3.4*j')
|
|
500
|
+
1.20000000000000 + 3.40000000000000*I
|
|
501
|
+
sage: CC("+4-13.59658451496887*I")
|
|
502
|
+
4.00000000000000 - 13.5965845149689*I
|
|
503
|
+
sage: CC('1.2*I+3.4')
|
|
504
|
+
3.40000000000000 + 1.20000000000000*I
|
|
505
|
+
sage: CC('1.2*I')
|
|
506
|
+
1.20000000000000*I
|
|
507
|
+
sage: CC('9-I*1.2')
|
|
508
|
+
9.00000000000000 - 1.20000000000000*I
|
|
509
|
+
sage: CC('3.4')
|
|
510
|
+
3.40000000000000
|
|
511
|
+
sage: CC('3.4e-6+7.8e11*I')
|
|
512
|
+
3.40000000000000e-6 + 7.80000000000000e11*I
|
|
513
|
+
sage: CC('hello')
|
|
514
|
+
Traceback (most recent call last):
|
|
515
|
+
...
|
|
516
|
+
ValueError: given string 'hello' is not a complex number
|
|
517
|
+
sage: CC('1+2+3*I')
|
|
518
|
+
Traceback (most recent call last):
|
|
519
|
+
...
|
|
520
|
+
ValueError: given string '1+2+3*I' is not a complex number
|
|
521
|
+
"""
|
|
522
|
+
if not isinstance(x, (RealNumber, tuple)):
|
|
523
|
+
if isinstance(x, ComplexDoubleElement):
|
|
524
|
+
return ComplexNumber(self, x.real(), x.imag())
|
|
525
|
+
elif isinstance(x, str):
|
|
526
|
+
x = x.replace(' ', '')
|
|
527
|
+
x = x.replace('i', 'I')
|
|
528
|
+
x = x.replace('j', 'I')
|
|
529
|
+
x = x.replace('E', 'e')
|
|
530
|
+
allowed = '+-.*0123456789Ie'
|
|
531
|
+
if len(x) == 0 or not all(letter in allowed for letter in x):
|
|
532
|
+
raise ValueError(f'given string {x!r} is not a complex number')
|
|
533
|
+
split = [group for group in BLOCK.findall(x) if group]
|
|
534
|
+
N = len(split)
|
|
535
|
+
if N == 1:
|
|
536
|
+
split = split[0]
|
|
537
|
+
real, imag = ('0', split) if 'I' in split else (split, '0')
|
|
538
|
+
elif N == 2:
|
|
539
|
+
real, imag = split
|
|
540
|
+
if 'I' in real:
|
|
541
|
+
real, imag = imag, real
|
|
542
|
+
else:
|
|
543
|
+
raise ValueError(f'given string {x!r} is not a complex number')
|
|
544
|
+
if not NUMBERS.search(imag):
|
|
545
|
+
imag = imag.replace('I', '1')
|
|
546
|
+
else:
|
|
547
|
+
imag = imag.replace('*', '').replace('I', '')
|
|
548
|
+
return ComplexNumber(self, real, imag)
|
|
549
|
+
|
|
550
|
+
late_import()
|
|
551
|
+
if isinstance(x, NumberFieldElement_quadratic):
|
|
552
|
+
if isinstance(x.parent(), sage.rings.abc.NumberField_quadratic) and list(x.parent().polynomial()) == [1, 0, 1]:
|
|
553
|
+
real, imag = list(x)
|
|
554
|
+
return ComplexNumber(self, real, imag)
|
|
555
|
+
|
|
556
|
+
try:
|
|
557
|
+
return self(x.sage())
|
|
558
|
+
except (AttributeError, TypeError):
|
|
559
|
+
pass
|
|
560
|
+
try:
|
|
561
|
+
return x._complex_mpfr_field_(self)
|
|
562
|
+
except AttributeError:
|
|
563
|
+
pass
|
|
564
|
+
return ComplexNumber(self, x)
|
|
565
|
+
|
|
566
|
+
def _coerce_map_from_(self, S):
|
|
567
|
+
"""
|
|
568
|
+
The rings that canonically coerce to the MPFR complex field are:
|
|
569
|
+
|
|
570
|
+
- This MPFR complex field, or any other of higher precision
|
|
571
|
+
|
|
572
|
+
- Anything that canonically coerces to the mpfr real field
|
|
573
|
+
with this prec
|
|
574
|
+
|
|
575
|
+
EXAMPLES::
|
|
576
|
+
|
|
577
|
+
sage: ComplexField(200)(1) + RealField(90)(1) # indirect doctest
|
|
578
|
+
2.0000000000000000000000000
|
|
579
|
+
sage: parent(ComplexField(200)(1) + RealField(90)(1)) # indirect doctest
|
|
580
|
+
Complex Field with 90 bits of precision
|
|
581
|
+
sage: CC.0 + RLF(1/3) # indirect doctest
|
|
582
|
+
0.333333333333333 + 1.00000000000000*I
|
|
583
|
+
sage: ComplexField(20).has_coerce_map_from(CDF)
|
|
584
|
+
True
|
|
585
|
+
sage: ComplexField(200).has_coerce_map_from(CDF)
|
|
586
|
+
False
|
|
587
|
+
sage: ComplexField(53).has_coerce_map_from(complex)
|
|
588
|
+
True
|
|
589
|
+
sage: ComplexField(200).has_coerce_map_from(complex)
|
|
590
|
+
False
|
|
591
|
+
"""
|
|
592
|
+
RR = self._real_field()
|
|
593
|
+
if RR.has_coerce_map_from(S):
|
|
594
|
+
return RRtoCC(RR, self) * RR._internal_coerce_map_from(S)
|
|
595
|
+
if isinstance(S, ComplexField_class):
|
|
596
|
+
if self._prec <= S._prec:
|
|
597
|
+
return self._generic_coerce_map(S)
|
|
598
|
+
else:
|
|
599
|
+
return None
|
|
600
|
+
if S is complex:
|
|
601
|
+
if self._prec <= 53:
|
|
602
|
+
return self._generic_coerce_map(S)
|
|
603
|
+
else:
|
|
604
|
+
return None
|
|
605
|
+
late_import()
|
|
606
|
+
if S is CDF:
|
|
607
|
+
if self._prec <= 53:
|
|
608
|
+
return self._generic_coerce_map(S)
|
|
609
|
+
else:
|
|
610
|
+
return None
|
|
611
|
+
if S in [AA, QQbar, CLF, RLF]:
|
|
612
|
+
return self._generic_coerce_map(S)
|
|
613
|
+
# Needed to discover the correct coerce map. Without this, the maps
|
|
614
|
+
# (direct or via QQbar, with slightly different behavior wrt imaginary
|
|
615
|
+
# parts of real elements) that get picked for conversion from UCF both
|
|
616
|
+
# to CC and to other types of complex fields depend in which order the
|
|
617
|
+
# coercions are discovered.
|
|
618
|
+
if isinstance(S, sage.rings.abc.UniversalCyclotomicField):
|
|
619
|
+
return self._generic_coerce_map(S)
|
|
620
|
+
return self._coerce_map_via([CLF], S)
|
|
621
|
+
|
|
622
|
+
def _repr_(self) -> str:
|
|
623
|
+
"""
|
|
624
|
+
Return a string representation of ``self``.
|
|
625
|
+
|
|
626
|
+
EXAMPLES::
|
|
627
|
+
|
|
628
|
+
sage: ComplexField() # indirect doctest
|
|
629
|
+
Complex Field with 53 bits of precision
|
|
630
|
+
sage: ComplexField(15) # indirect doctest
|
|
631
|
+
Complex Field with 15 bits of precision
|
|
632
|
+
"""
|
|
633
|
+
return "Complex Field with %s bits of precision" % self._prec
|
|
634
|
+
|
|
635
|
+
def _latex_(self) -> str:
|
|
636
|
+
r"""
|
|
637
|
+
Return a latex representation of ``self``.
|
|
638
|
+
|
|
639
|
+
EXAMPLES::
|
|
640
|
+
|
|
641
|
+
sage: latex(ComplexField()) # indirect doctest
|
|
642
|
+
\Bold{C}
|
|
643
|
+
sage: latex(ComplexField(15)) # indirect doctest
|
|
644
|
+
\Bold{C}
|
|
645
|
+
"""
|
|
646
|
+
return "\\Bold{C}"
|
|
647
|
+
|
|
648
|
+
def _sage_input_(self, sib, coerce):
|
|
649
|
+
r"""
|
|
650
|
+
Produce an expression which will reproduce this value when evaluated.
|
|
651
|
+
|
|
652
|
+
EXAMPLES::
|
|
653
|
+
|
|
654
|
+
sage: sage_input(CC, verify=True)
|
|
655
|
+
# Verified
|
|
656
|
+
CC
|
|
657
|
+
sage: sage_input(ComplexField(25), verify=True)
|
|
658
|
+
# Verified
|
|
659
|
+
ComplexField(25)
|
|
660
|
+
sage: k = (CC, ComplexField(75))
|
|
661
|
+
sage: sage_input(k, verify=True)
|
|
662
|
+
# Verified
|
|
663
|
+
(CC, ComplexField(75))
|
|
664
|
+
sage: sage_input((k, k), verify=True)
|
|
665
|
+
# Verified
|
|
666
|
+
CC75 = ComplexField(75)
|
|
667
|
+
((CC, CC75), (CC, CC75))
|
|
668
|
+
sage: from sage.misc.sage_input import SageInputBuilder
|
|
669
|
+
sage: ComplexField(99)._sage_input_(SageInputBuilder(), False)
|
|
670
|
+
{call: {atomic:ComplexField}({atomic:99})}
|
|
671
|
+
"""
|
|
672
|
+
if self.prec() == 53:
|
|
673
|
+
return sib.name('CC')
|
|
674
|
+
|
|
675
|
+
v = sib.name('ComplexField')(sib.int(self.prec()))
|
|
676
|
+
|
|
677
|
+
name = 'CC%d' % (self.prec())
|
|
678
|
+
sib.cache(self, v, name)
|
|
679
|
+
return v
|
|
680
|
+
|
|
681
|
+
def characteristic(self):
|
|
682
|
+
r"""
|
|
683
|
+
Return the characteristic of `\CC`, which is 0.
|
|
684
|
+
|
|
685
|
+
EXAMPLES::
|
|
686
|
+
|
|
687
|
+
sage: ComplexField().characteristic()
|
|
688
|
+
0
|
|
689
|
+
"""
|
|
690
|
+
return Integer(0)
|
|
691
|
+
|
|
692
|
+
def gen(self, n=0):
|
|
693
|
+
"""
|
|
694
|
+
Return the generator of the complex field.
|
|
695
|
+
|
|
696
|
+
EXAMPLES::
|
|
697
|
+
|
|
698
|
+
sage: ComplexField().gen(0)
|
|
699
|
+
1.00000000000000*I
|
|
700
|
+
"""
|
|
701
|
+
if n != 0:
|
|
702
|
+
raise IndexError("n must be 0")
|
|
703
|
+
return ComplexNumber(self, 0, 1)
|
|
704
|
+
|
|
705
|
+
def construction(self):
|
|
706
|
+
"""
|
|
707
|
+
Return the functorial construction of ``self``, namely the algebraic
|
|
708
|
+
closure of the real field with the same precision.
|
|
709
|
+
|
|
710
|
+
EXAMPLES::
|
|
711
|
+
|
|
712
|
+
sage: c, S = CC.construction(); S
|
|
713
|
+
Real Field with 53 bits of precision
|
|
714
|
+
sage: CC == c(S)
|
|
715
|
+
True
|
|
716
|
+
"""
|
|
717
|
+
from sage.categories.pushout import AlgebraicClosureFunctor
|
|
718
|
+
return (AlgebraicClosureFunctor(), self._real_field())
|
|
719
|
+
|
|
720
|
+
def random_element(self, component_max=1, *args, **kwds):
|
|
721
|
+
r"""
|
|
722
|
+
Return a uniformly distributed random number inside a square
|
|
723
|
+
centered on the origin (by default, the square `[-1,1] \times [-1,1]`).
|
|
724
|
+
|
|
725
|
+
Passes additional arguments and keywords to underlying real field.
|
|
726
|
+
|
|
727
|
+
EXAMPLES::
|
|
728
|
+
|
|
729
|
+
sage: CC.random_element().parent() is CC
|
|
730
|
+
True
|
|
731
|
+
sage: re, im = CC.random_element()
|
|
732
|
+
sage: -1 <= re <= 1, -1 <= im <= 1
|
|
733
|
+
(True, True)
|
|
734
|
+
sage: CC6 = ComplexField(6)
|
|
735
|
+
sage: CC6.random_element().parent() is CC6
|
|
736
|
+
True
|
|
737
|
+
sage: re, im = CC6.random_element(2^-20)
|
|
738
|
+
sage: -2^-20 <= re <= 2^-20, -2^-20 <= im <= 2^-20
|
|
739
|
+
(True, True)
|
|
740
|
+
sage: re, im = CC6.random_element(pi^20) # needs sage.symbolic
|
|
741
|
+
sage: bool(-pi^20 <= re <= pi^20), bool(-pi^20 <= im <= pi^20) # needs sage.symbolic
|
|
742
|
+
(True, True)
|
|
743
|
+
|
|
744
|
+
Passes extra positional or keyword arguments through::
|
|
745
|
+
|
|
746
|
+
sage: CC.random_element(distribution='1/n').parent() is CC
|
|
747
|
+
True
|
|
748
|
+
"""
|
|
749
|
+
size = self._real_field()(component_max)
|
|
750
|
+
real = self._real_field().random_element(-size, size, *args, **kwds)
|
|
751
|
+
imag = self._real_field().random_element(-size, size, *args, **kwds)
|
|
752
|
+
return self(real, imag)
|
|
753
|
+
|
|
754
|
+
def pi(self):
|
|
755
|
+
r"""
|
|
756
|
+
Return `\pi` as a complex number.
|
|
757
|
+
|
|
758
|
+
EXAMPLES::
|
|
759
|
+
|
|
760
|
+
sage: ComplexField().pi()
|
|
761
|
+
3.14159265358979
|
|
762
|
+
sage: ComplexField(100).pi()
|
|
763
|
+
3.1415926535897932384626433833
|
|
764
|
+
"""
|
|
765
|
+
return self(self._real_field().pi())
|
|
766
|
+
|
|
767
|
+
def ngens(self):
|
|
768
|
+
r"""
|
|
769
|
+
The number of generators of this complex field as an `\RR`-algebra.
|
|
770
|
+
|
|
771
|
+
There is one generator, namely ``sqrt(-1)``.
|
|
772
|
+
|
|
773
|
+
EXAMPLES::
|
|
774
|
+
|
|
775
|
+
sage: ComplexField().ngens()
|
|
776
|
+
1
|
|
777
|
+
"""
|
|
778
|
+
return 1
|
|
779
|
+
|
|
780
|
+
def zeta(self, n=2):
|
|
781
|
+
"""
|
|
782
|
+
Return a primitive `n`-th root of unity.
|
|
783
|
+
|
|
784
|
+
INPUT:
|
|
785
|
+
|
|
786
|
+
- ``n`` -- integer (default: 2)
|
|
787
|
+
|
|
788
|
+
OUTPUT: a complex `n`-th root of unity
|
|
789
|
+
|
|
790
|
+
EXAMPLES::
|
|
791
|
+
|
|
792
|
+
sage: C = ComplexField()
|
|
793
|
+
sage: C.zeta(2)
|
|
794
|
+
-1.00000000000000
|
|
795
|
+
sage: C.zeta(5)
|
|
796
|
+
0.309016994374947 + 0.951056516295154*I
|
|
797
|
+
"""
|
|
798
|
+
n = Integer(n)
|
|
799
|
+
if n == 1:
|
|
800
|
+
x = self(1)
|
|
801
|
+
elif n == 2:
|
|
802
|
+
x = self(-1)
|
|
803
|
+
elif n >= 3:
|
|
804
|
+
# Use De Moivre
|
|
805
|
+
# e^(2*pi*i/n) = cos(2pi/n) + i *sin(2pi/n)
|
|
806
|
+
RR = self._real_field()
|
|
807
|
+
pi = RR.pi()
|
|
808
|
+
z = 2*pi/n
|
|
809
|
+
x = ComplexNumber(self, z.cos(), z.sin())
|
|
810
|
+
x._set_multiplicative_order( n )
|
|
811
|
+
return x
|
|
812
|
+
|
|
813
|
+
def scientific_notation(self, status=None):
|
|
814
|
+
"""
|
|
815
|
+
Set or return the scientific notation printing flag.
|
|
816
|
+
|
|
817
|
+
If this flag is ``True`` then complex numbers with this space as parent
|
|
818
|
+
print using scientific notation.
|
|
819
|
+
|
|
820
|
+
EXAMPLES::
|
|
821
|
+
|
|
822
|
+
sage: C = ComplexField()
|
|
823
|
+
sage: C((0.025, 2))
|
|
824
|
+
0.0250000000000000 + 2.00000000000000*I
|
|
825
|
+
sage: C.scientific_notation(True)
|
|
826
|
+
sage: C((0.025, 2))
|
|
827
|
+
2.50000000000000e-2 + 2.00000000000000e0*I
|
|
828
|
+
sage: C.scientific_notation(False)
|
|
829
|
+
sage: C((0.025, 2))
|
|
830
|
+
0.0250000000000000 + 2.00000000000000*I
|
|
831
|
+
"""
|
|
832
|
+
return self._real_field().scientific_notation(status)
|
|
833
|
+
|
|
834
|
+
def algebraic_closure(self):
|
|
835
|
+
"""
|
|
836
|
+
Return the algebraic closure of ``self`` (which is itself).
|
|
837
|
+
|
|
838
|
+
EXAMPLES::
|
|
839
|
+
|
|
840
|
+
sage: CC
|
|
841
|
+
Complex Field with 53 bits of precision
|
|
842
|
+
sage: CC.algebraic_closure()
|
|
843
|
+
Complex Field with 53 bits of precision
|
|
844
|
+
sage: CC = ComplexField(1000)
|
|
845
|
+
sage: CC.algebraic_closure() is CC
|
|
846
|
+
True
|
|
847
|
+
"""
|
|
848
|
+
return self
|
|
849
|
+
|
|
850
|
+
def _factor_univariate_polynomial(self, f):
|
|
851
|
+
"""
|
|
852
|
+
Factor the univariate polynomial ``f``.
|
|
853
|
+
|
|
854
|
+
INPUT:
|
|
855
|
+
|
|
856
|
+
- ``f`` -- a univariate polynomial defined over the complex numbers
|
|
857
|
+
|
|
858
|
+
OUTPUT:
|
|
859
|
+
|
|
860
|
+
- A factorization of ``f`` over the complex numbers into a unit and
|
|
861
|
+
monic irreducible factors
|
|
862
|
+
|
|
863
|
+
.. NOTE::
|
|
864
|
+
|
|
865
|
+
This is a helper method for
|
|
866
|
+
:meth:`sage.rings.polynomial.polynomial_element.Polynomial.factor`.
|
|
867
|
+
|
|
868
|
+
This method calls PARI to compute the factorization.
|
|
869
|
+
|
|
870
|
+
TESTS::
|
|
871
|
+
|
|
872
|
+
sage: # needs sage.libs.pari
|
|
873
|
+
sage: k = ComplexField(100)
|
|
874
|
+
sage: R.<x> = k[]
|
|
875
|
+
sage: k._factor_univariate_polynomial(x)
|
|
876
|
+
x
|
|
877
|
+
sage: k._factor_univariate_polynomial(2*x)
|
|
878
|
+
(2.0000000000000000000000000000) * x
|
|
879
|
+
sage: k._factor_univariate_polynomial(x^2)
|
|
880
|
+
x^2
|
|
881
|
+
sage: k._factor_univariate_polynomial(x^2 + 3)
|
|
882
|
+
(x - 1.7320508075688772935274463415*I) * (x + 1.7320508075688772935274463415*I)
|
|
883
|
+
sage: k._factor_univariate_polynomial(x^2 + 1)
|
|
884
|
+
(x - I) * (x + I)
|
|
885
|
+
sage: k._factor_univariate_polynomial(k(I) * (x^2 + 1)) # needs sage.symbolic
|
|
886
|
+
(1.0000000000000000000000000000*I) * (x - I) * (x + I)
|
|
887
|
+
"""
|
|
888
|
+
R = f.parent()
|
|
889
|
+
|
|
890
|
+
# if the polynomial does not have complex coefficients, PARI will
|
|
891
|
+
# factor it over the reals. To make sure it has complex coefficients we
|
|
892
|
+
# multiply with I.
|
|
893
|
+
I = R.base_ring().gen()
|
|
894
|
+
g = f * I if f.leading_coefficient() != I else f
|
|
895
|
+
|
|
896
|
+
F = list(g._pari_with_name().factor())
|
|
897
|
+
|
|
898
|
+
from sage.structure.factorization import Factorization
|
|
899
|
+
return Factorization([(R(gg).monic(), e) for gg, e in zip(*F)],
|
|
900
|
+
f.leading_coefficient())
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
cdef class ComplexNumber(sage.structure.element.FieldElement):
|
|
904
|
+
"""
|
|
905
|
+
A floating point approximation to a complex number using any
|
|
906
|
+
specified precision. Answers derived from calculations with such
|
|
907
|
+
approximations may differ from what they would be if those
|
|
908
|
+
calculations were performed with true complex numbers. This is due
|
|
909
|
+
to the rounding errors inherent to finite precision calculations.
|
|
910
|
+
|
|
911
|
+
EXAMPLES::
|
|
912
|
+
|
|
913
|
+
sage: I = CC.0
|
|
914
|
+
sage: b = 1.5 + 2.5*I
|
|
915
|
+
sage: loads(b.dumps()) == b
|
|
916
|
+
True
|
|
917
|
+
"""
|
|
918
|
+
|
|
919
|
+
cdef ComplexNumber _new(self):
|
|
920
|
+
"""
|
|
921
|
+
Quickly create a new initialized complex number with the same
|
|
922
|
+
parent as ``self``.
|
|
923
|
+
"""
|
|
924
|
+
cdef ComplexNumber x
|
|
925
|
+
x = ComplexNumber.__new__(ComplexNumber)
|
|
926
|
+
x._parent = self._parent
|
|
927
|
+
x._prec = self._prec
|
|
928
|
+
x._multiplicative_order = None
|
|
929
|
+
mpfr_init2(x.__re, self._prec)
|
|
930
|
+
mpfr_init2(x.__im, self._prec)
|
|
931
|
+
return x
|
|
932
|
+
|
|
933
|
+
def __cinit__(self, parent=None, real=None, imag=None):
|
|
934
|
+
"""
|
|
935
|
+
Cython initialize ``self``.
|
|
936
|
+
|
|
937
|
+
EXAMPLES::
|
|
938
|
+
|
|
939
|
+
sage: ComplexNumber(2,1) # indirect doctest
|
|
940
|
+
2.00000000000000 + 1.00000000000000*I
|
|
941
|
+
"""
|
|
942
|
+
self._prec = -1
|
|
943
|
+
|
|
944
|
+
def __init__(self, parent, real, imag=None):
|
|
945
|
+
r"""
|
|
946
|
+
Initialize :class:`ComplexNumber` instance.
|
|
947
|
+
|
|
948
|
+
EXAMPLES::
|
|
949
|
+
|
|
950
|
+
sage: a = ComplexNumber(2,1)
|
|
951
|
+
sage: a.__init__(CC,2,1)
|
|
952
|
+
sage: a
|
|
953
|
+
2.00000000000000 + 1.00000000000000*I
|
|
954
|
+
sage: parent(a)
|
|
955
|
+
Complex Field with 53 bits of precision
|
|
956
|
+
sage: real(a)
|
|
957
|
+
2.00000000000000
|
|
958
|
+
sage: imag(a)
|
|
959
|
+
1.00000000000000
|
|
960
|
+
|
|
961
|
+
Conversion from gmpy2 numbers::
|
|
962
|
+
|
|
963
|
+
sage: from gmpy2 import *
|
|
964
|
+
sage: c = mpc('2.0+1.0j')
|
|
965
|
+
sage: CC(c)
|
|
966
|
+
2.00000000000000 + 1.00000000000000*I
|
|
967
|
+
"""
|
|
968
|
+
cdef RealNumber rr, ii
|
|
969
|
+
self._parent = parent
|
|
970
|
+
self._prec = self._parent._prec
|
|
971
|
+
self._multiplicative_order = None
|
|
972
|
+
|
|
973
|
+
mpfr_init2(self.__re, self._prec)
|
|
974
|
+
mpfr_init2(self.__im, self._prec)
|
|
975
|
+
|
|
976
|
+
if imag is None:
|
|
977
|
+
if real is None: return
|
|
978
|
+
|
|
979
|
+
if isinstance(real, ComplexNumber):
|
|
980
|
+
real, imag = (<ComplexNumber>real).real(), (<ComplexNumber>real).imag()
|
|
981
|
+
elif isinstance(real, pari_gen):
|
|
982
|
+
real, imag = real.real(), real.imag()
|
|
983
|
+
elif isinstance(real, (list, tuple)):
|
|
984
|
+
real, imag = real
|
|
985
|
+
elif isinstance(real, complex):
|
|
986
|
+
real, imag = real.real, real.imag
|
|
987
|
+
elif type(real) is gmpy2.mpc:
|
|
988
|
+
real, imag = (<gmpy2.mpc>real).real, (<gmpy2.mpc>real).imag
|
|
989
|
+
else:
|
|
990
|
+
imag = 0
|
|
991
|
+
try:
|
|
992
|
+
R = parent._real_field()
|
|
993
|
+
rr = R(real)
|
|
994
|
+
ii = R(imag)
|
|
995
|
+
mpfr_set(self.__re, rr.value, rnd)
|
|
996
|
+
mpfr_set(self.__im, ii.value, rnd)
|
|
997
|
+
except TypeError:
|
|
998
|
+
raise TypeError("unable to coerce to a ComplexNumber: %s" % type(real))
|
|
999
|
+
|
|
1000
|
+
def __dealloc__(self):
|
|
1001
|
+
"""
|
|
1002
|
+
TESTS:
|
|
1003
|
+
|
|
1004
|
+
Check that :issue:`12038` is resolved::
|
|
1005
|
+
|
|
1006
|
+
sage: from sage.rings.complex_mpfr import ComplexNumber as CN
|
|
1007
|
+
sage: coerce(CN, 1+I) # needs sage.symbolic
|
|
1008
|
+
Traceback (most recent call last):
|
|
1009
|
+
...
|
|
1010
|
+
TypeError: ...__init__() takes at least 2 positional arguments (1 given)
|
|
1011
|
+
"""
|
|
1012
|
+
if self._prec != -1:
|
|
1013
|
+
mpfr_clear(self.__re)
|
|
1014
|
+
mpfr_clear(self.__im)
|
|
1015
|
+
|
|
1016
|
+
def _interface_init_(self, I=None):
|
|
1017
|
+
"""
|
|
1018
|
+
Return ``self`` formatted as a string, suitable as input to another
|
|
1019
|
+
computer algebra system. (This is the default function used for
|
|
1020
|
+
exporting to other computer algebra systems.)
|
|
1021
|
+
|
|
1022
|
+
EXAMPLES::
|
|
1023
|
+
|
|
1024
|
+
sage: s1 = CC(exp(I)); s1 # needs sage.symbolic
|
|
1025
|
+
0.540302305868140 + 0.841470984807897*I
|
|
1026
|
+
sage: s1._interface_init_() # needs sage.symbolic
|
|
1027
|
+
'0.54030230586813977 + 0.84147098480789650*I'
|
|
1028
|
+
sage: s1 == CC(gp(s1)) # needs sage.libs.pari sage.symbolic
|
|
1029
|
+
True
|
|
1030
|
+
"""
|
|
1031
|
+
return self.str()
|
|
1032
|
+
|
|
1033
|
+
def _mathematica_init_(self):
|
|
1034
|
+
"""
|
|
1035
|
+
EXAMPLES::
|
|
1036
|
+
|
|
1037
|
+
sage: mathematica(CC(3.5e-15, 2.3e15)) # indirect doctest, optional - mathematica
|
|
1038
|
+
3.5*^-15 + 2.3*^15*I
|
|
1039
|
+
"""
|
|
1040
|
+
return self.str(e='*^')
|
|
1041
|
+
|
|
1042
|
+
def _maxima_init_(self, I=None):
|
|
1043
|
+
"""
|
|
1044
|
+
Return a string representation of this complex number in the syntax of
|
|
1045
|
+
Maxima. That is, use ``%i`` to represent the complex unit.
|
|
1046
|
+
|
|
1047
|
+
EXAMPLES::
|
|
1048
|
+
|
|
1049
|
+
sage: CC.0._maxima_init_()
|
|
1050
|
+
'1.0000000000000000*%i'
|
|
1051
|
+
sage: CC(.5 + I)._maxima_init_() # needs sage.symbolic
|
|
1052
|
+
'0.50000000000000000 + 1.0000000000000000*%i'
|
|
1053
|
+
"""
|
|
1054
|
+
return self.str(istr='%i')
|
|
1055
|
+
|
|
1056
|
+
@property
|
|
1057
|
+
def __array_interface__(self):
|
|
1058
|
+
"""
|
|
1059
|
+
Used for NumPy conversion.
|
|
1060
|
+
|
|
1061
|
+
EXAMPLES::
|
|
1062
|
+
|
|
1063
|
+
sage: import numpy # needs numpy
|
|
1064
|
+
sage: numpy.array([1.0, 2.5j]).dtype # needs numpy
|
|
1065
|
+
dtype('complex128')
|
|
1066
|
+
sage: numpy.array([1.000000000000000000000000000000000000j]).dtype # needs numpy
|
|
1067
|
+
dtype('O')
|
|
1068
|
+
"""
|
|
1069
|
+
if self._prec <= 53:
|
|
1070
|
+
return numpy_complex_interface
|
|
1071
|
+
else:
|
|
1072
|
+
return numpy_object_interface
|
|
1073
|
+
|
|
1074
|
+
def _sage_input_(self, sib, coerced):
|
|
1075
|
+
r"""
|
|
1076
|
+
Produce an expression which will reproduce this value when evaluated.
|
|
1077
|
+
|
|
1078
|
+
EXAMPLES::
|
|
1079
|
+
|
|
1080
|
+
sage: for prec in (2, 53, 200): # not tested, known bug (see :issue:`32129`)
|
|
1081
|
+
....: fld = ComplexField(prec)
|
|
1082
|
+
....: var = polygen(fld)
|
|
1083
|
+
....: ins = [-20, 0, 1, -2^4000, 2^-4000] + [fld._real_field().random_element() for _ in range(3)]
|
|
1084
|
+
....: for v1 in ins:
|
|
1085
|
+
....: for v2 in ins:
|
|
1086
|
+
....: v = fld(v1, v2)
|
|
1087
|
+
....: _ = sage_input(fld(v), verify=True)
|
|
1088
|
+
....: _ = sage_input(fld(v) * var, verify=True)
|
|
1089
|
+
sage: x = polygen(CC)
|
|
1090
|
+
sage: for v1 in [-2, 0, 2]:
|
|
1091
|
+
....: for v2 in [-2, -1, 0, 1, 2]:
|
|
1092
|
+
....: print(str(sage_input(x + CC(v1, v2))).splitlines()[1])
|
|
1093
|
+
x + CC(-2 - RR(2)*I)
|
|
1094
|
+
x + CC(-2 - RR(1)*I)
|
|
1095
|
+
x - 2
|
|
1096
|
+
x + CC(-2 + RR(1)*I)
|
|
1097
|
+
x + CC(-2 + RR(2)*I)
|
|
1098
|
+
x - CC(RR(2)*I)
|
|
1099
|
+
x - CC(RR(1)*I)
|
|
1100
|
+
x
|
|
1101
|
+
x + CC(RR(1)*I)
|
|
1102
|
+
x + CC(RR(2)*I)
|
|
1103
|
+
x + CC(2 - RR(2)*I)
|
|
1104
|
+
x + CC(2 - RR(1)*I)
|
|
1105
|
+
x + 2
|
|
1106
|
+
x + CC(2 + RR(1)*I)
|
|
1107
|
+
x + CC(2 + RR(2)*I)
|
|
1108
|
+
sage: from sage.misc.sage_input import SageInputBuilder
|
|
1109
|
+
sage: sib = SageInputBuilder()
|
|
1110
|
+
sage: sib_np = SageInputBuilder(preparse=False)
|
|
1111
|
+
sage: CC(-infinity)._sage_input_(sib, True)
|
|
1112
|
+
{unop:- {call: {atomic:RR}({atomic:Infinity})}}
|
|
1113
|
+
sage: CC(0, infinity)._sage_input_(sib, True)
|
|
1114
|
+
{call: {atomic:CC}({call: {atomic:RR}({atomic:0})}, {call: {atomic:RR}({atomic:Infinity})})}
|
|
1115
|
+
sage: CC(NaN, 5)._sage_input_(sib, True) # needs sage.symbolic
|
|
1116
|
+
{call: {atomic:CC}({call: {atomic:RR}({atomic:NaN})}, {call: {atomic:RR}({atomic:5})})}
|
|
1117
|
+
sage: CC(5, NaN)._sage_input_(sib, True) # needs sage.symbolic
|
|
1118
|
+
{call: {atomic:CC}({call: {atomic:RR}({atomic:5})}, {call: {atomic:RR}({atomic:NaN})})}
|
|
1119
|
+
sage: CC(12345)._sage_input_(sib, True)
|
|
1120
|
+
{atomic:12345}
|
|
1121
|
+
sage: CC(-12345)._sage_input_(sib, False)
|
|
1122
|
+
{call: {atomic:CC}({binop:+ {unop:- {atomic:12345}} {binop:* {call: {atomic:RR}({atomic:0})} {atomic:I}}})}
|
|
1123
|
+
sage: CC(0, 12345)._sage_input_(sib, True)
|
|
1124
|
+
{call: {atomic:CC}({binop:* {call: {atomic:RR}({atomic:12345})} {atomic:I}})}
|
|
1125
|
+
sage: CC(0, -12345)._sage_input_(sib, False)
|
|
1126
|
+
{unop:- {call: {atomic:CC}({binop:* {call: {atomic:RR}({atomic:12345})} {atomic:I}})}}
|
|
1127
|
+
sage: CC(1.579)._sage_input_(sib, True)
|
|
1128
|
+
{atomic:1.579}
|
|
1129
|
+
sage: CC(1.579)._sage_input_(sib_np, True)
|
|
1130
|
+
{atomic:1.579}
|
|
1131
|
+
sage: ComplexField(150).zeta(37)._sage_input_(sib, True)
|
|
1132
|
+
{call: {call: {atomic:ComplexField}({atomic:150})}({binop:+ {atomic:0.98561591034770846226477029397621845736859851519} {binop:* {call: {call: {atomic:RealField}({atomic:150})}({atomic:0.16900082032184907409303555538443060626072476297})} {atomic:I}}})}
|
|
1133
|
+
sage: ComplexField(150).zeta(37)._sage_input_(sib_np, True)
|
|
1134
|
+
{call: {call: {atomic:ComplexField}({atomic:150})}({binop:+ {call: {call: {atomic:RealField}({atomic:150})}({atomic:'0.98561591034770846226477029397621845736859851519'})} {binop:* {call: {call: {atomic:RealField}({atomic:150})}({atomic:'0.16900082032184907409303555538443060626072476297'})} {atomic:I}}})}
|
|
1135
|
+
"""
|
|
1136
|
+
if coerced and self.imag() == 0:
|
|
1137
|
+
return sib(self.real(), True)
|
|
1138
|
+
|
|
1139
|
+
# The body will be coerced first to symbolics and then to CC.
|
|
1140
|
+
# This works fine if we produce integer or float literals, but
|
|
1141
|
+
# not for infinity or NaN.
|
|
1142
|
+
if not (mpfr_number_p(self.__re) and mpfr_number_p(self.__im)):
|
|
1143
|
+
return sib(self.parent())(self.real(), self.imag())
|
|
1144
|
+
|
|
1145
|
+
# The following uses of .sum() and .prod() will simplify
|
|
1146
|
+
# 3+0*I to 3, 0+1*I to I, etc.
|
|
1147
|
+
real_part = sib(self.real(), 2)
|
|
1148
|
+
imag_part = sib.prod([sib(self.imag()), sib.name('I')],
|
|
1149
|
+
simplify=True)
|
|
1150
|
+
sum = sib.sum([real_part, imag_part], simplify=True)
|
|
1151
|
+
if sum._sie_is_negation():
|
|
1152
|
+
return -sib(self.parent())(sum._sie_operand)
|
|
1153
|
+
else:
|
|
1154
|
+
return sib(self.parent())(sum)
|
|
1155
|
+
|
|
1156
|
+
# The following (untested) implementation sets CC_I = CC.gen(),
|
|
1157
|
+
# allowing to write 2 + 3*CC_I instead of CC(2 + 3*I).
|
|
1158
|
+
# cdef int prec
|
|
1159
|
+
# if self.real().is_zero() and self.imag() == 1:
|
|
1160
|
+
# v = sib(self.parent()).gen()
|
|
1161
|
+
# prec = self.prec()
|
|
1162
|
+
# if prec == 53:
|
|
1163
|
+
# gen_name = 'CC_I'
|
|
1164
|
+
# else:
|
|
1165
|
+
# gen_name = 'CC%d_I' % prec
|
|
1166
|
+
# sib.cache(self, v, gen_name)
|
|
1167
|
+
# real_part = sib(self.real())
|
|
1168
|
+
# imag_part = sib.prod([self.imag(), self.parent().gen()], simplify=True)
|
|
1169
|
+
# return sib.sum([real_part, imag_part], simplify=True)
|
|
1170
|
+
|
|
1171
|
+
def _repr_(self):
|
|
1172
|
+
r"""
|
|
1173
|
+
Return ``self`` formatted as a string.
|
|
1174
|
+
|
|
1175
|
+
EXAMPLES::
|
|
1176
|
+
|
|
1177
|
+
sage: a = ComplexNumber(2,1); a
|
|
1178
|
+
2.00000000000000 + 1.00000000000000*I
|
|
1179
|
+
sage: a._repr_()
|
|
1180
|
+
'2.00000000000000 + 1.00000000000000*I'
|
|
1181
|
+
"""
|
|
1182
|
+
return self.str(truncate=True)
|
|
1183
|
+
|
|
1184
|
+
def __hash__(self):
|
|
1185
|
+
"""
|
|
1186
|
+
Return the hash of ``self``, which coincides with the python complex
|
|
1187
|
+
and float (and often int) types.
|
|
1188
|
+
|
|
1189
|
+
This has the drawback that two very close high precision numbers
|
|
1190
|
+
will have the same hash, but allows them to play nicely with other
|
|
1191
|
+
real types.
|
|
1192
|
+
|
|
1193
|
+
EXAMPLES::
|
|
1194
|
+
|
|
1195
|
+
sage: hash(CC(1.2, 33)) == hash(complex(1.2, 33))
|
|
1196
|
+
True
|
|
1197
|
+
"""
|
|
1198
|
+
return hash(complex(self))
|
|
1199
|
+
|
|
1200
|
+
def __getitem__(self, i):
|
|
1201
|
+
r"""
|
|
1202
|
+
Return either the real or imaginary component of ``self`` depending on
|
|
1203
|
+
the choice of ``i``: real (``i=0``), imaginary (``i=1``).
|
|
1204
|
+
|
|
1205
|
+
INPUT:
|
|
1206
|
+
|
|
1207
|
+
- ``i`` -- 0 or 1
|
|
1208
|
+
- ``0`` -- will return the real component of ``self``
|
|
1209
|
+
- ``1`` -- will return the imaginary component of ``self``
|
|
1210
|
+
|
|
1211
|
+
EXAMPLES::
|
|
1212
|
+
|
|
1213
|
+
sage: a = ComplexNumber(2,1)
|
|
1214
|
+
sage: a.__getitem__(0)
|
|
1215
|
+
2.00000000000000
|
|
1216
|
+
sage: a.__getitem__(1)
|
|
1217
|
+
1.00000000000000
|
|
1218
|
+
|
|
1219
|
+
::
|
|
1220
|
+
|
|
1221
|
+
sage: b = CC(42,0)
|
|
1222
|
+
sage: b
|
|
1223
|
+
42.0000000000000
|
|
1224
|
+
sage: b.__getitem__(1)
|
|
1225
|
+
0.000000000000000
|
|
1226
|
+
"""
|
|
1227
|
+
if i == 0:
|
|
1228
|
+
return self.real()
|
|
1229
|
+
elif i == 1:
|
|
1230
|
+
return self.imag()
|
|
1231
|
+
raise IndexError("i must be between 0 and 1.")
|
|
1232
|
+
|
|
1233
|
+
def __reduce__(self):
|
|
1234
|
+
"""
|
|
1235
|
+
Pickling support.
|
|
1236
|
+
|
|
1237
|
+
EXAMPLES::
|
|
1238
|
+
|
|
1239
|
+
sage: a = CC(1 + I) # needs sage.symbolic
|
|
1240
|
+
sage: loads(dumps(a)) == a # needs sage.symbolic
|
|
1241
|
+
True
|
|
1242
|
+
"""
|
|
1243
|
+
# TODO: This is potentially slow -- make a 1 version that
|
|
1244
|
+
# is native and much faster -- doesn't use .real()/.imag()
|
|
1245
|
+
return (make_ComplexNumber0, (self._parent, self._multiplicative_order, self.real(), self.imag()))
|
|
1246
|
+
|
|
1247
|
+
def _set_multiplicative_order(self, n):
|
|
1248
|
+
r"""
|
|
1249
|
+
Function for setting the attribute :meth:`multiplicative_order` of
|
|
1250
|
+
``self``.
|
|
1251
|
+
|
|
1252
|
+
.. WARNING::
|
|
1253
|
+
|
|
1254
|
+
It is not advisable to explicitly call
|
|
1255
|
+
``_set_multiplicative_order()`` for explicitly declared complex
|
|
1256
|
+
numbers.
|
|
1257
|
+
|
|
1258
|
+
INPUT:
|
|
1259
|
+
|
|
1260
|
+
- ``n`` -- integer which will define the multiplicative order
|
|
1261
|
+
|
|
1262
|
+
EXAMPLES::
|
|
1263
|
+
|
|
1264
|
+
sage: a = ComplexNumber(2,1)
|
|
1265
|
+
sage: a.multiplicative_order()
|
|
1266
|
+
+Infinity
|
|
1267
|
+
sage: a._set_multiplicative_order(5)
|
|
1268
|
+
sage: a.multiplicative_order()
|
|
1269
|
+
5
|
|
1270
|
+
sage: a^5
|
|
1271
|
+
-38.0000000000000 + 41.0000000000000*I
|
|
1272
|
+
"""
|
|
1273
|
+
self._multiplicative_order = Integer(n)
|
|
1274
|
+
|
|
1275
|
+
def str(self, base=10, istr='I', **kwds):
|
|
1276
|
+
r"""
|
|
1277
|
+
Return a string representation of ``self``.
|
|
1278
|
+
|
|
1279
|
+
INPUT:
|
|
1280
|
+
|
|
1281
|
+
- ``base`` -- (default: 10) base for output
|
|
1282
|
+
|
|
1283
|
+
- ``istr`` -- (default: ``I``) string representation of the complex unit
|
|
1284
|
+
|
|
1285
|
+
- ``**kwds`` -- other arguments to pass to the ``str()``
|
|
1286
|
+
method of the real numbers in the real and imaginary parts
|
|
1287
|
+
|
|
1288
|
+
EXAMPLES::
|
|
1289
|
+
|
|
1290
|
+
sage: # needs sage.symbolic
|
|
1291
|
+
sage: a = CC(pi + I*e); a
|
|
1292
|
+
3.14159265358979 + 2.71828182845905*I
|
|
1293
|
+
sage: a.str(truncate=True)
|
|
1294
|
+
'3.14159265358979 + 2.71828182845905*I'
|
|
1295
|
+
sage: a.str()
|
|
1296
|
+
'3.1415926535897931 + 2.7182818284590451*I'
|
|
1297
|
+
sage: a.str(base=2)
|
|
1298
|
+
'11.001001000011111101101010100010001000010110100011000 + 10.101101111110000101010001011000101000101011101101001*I'
|
|
1299
|
+
sage: CC(0.5 + 0.625*I).str(base=2)
|
|
1300
|
+
'0.10000000000000000000000000000000000000000000000000000 + 0.10100000000000000000000000000000000000000000000000000*I'
|
|
1301
|
+
sage: a.str(base=16)
|
|
1302
|
+
'3.243f6a8885a30 + 2.b7e151628aed2*I'
|
|
1303
|
+
sage: a.str(base=36)
|
|
1304
|
+
'3.53i5ab8p5fc + 2.puw5nggjf8f*I'
|
|
1305
|
+
|
|
1306
|
+
sage: CC(0)
|
|
1307
|
+
0.000000000000000
|
|
1308
|
+
sage: CC.0.str(istr='%i')
|
|
1309
|
+
'1.0000000000000000*%i'
|
|
1310
|
+
"""
|
|
1311
|
+
s = ""
|
|
1312
|
+
if self.real():
|
|
1313
|
+
s = self.real().str(base, **kwds)
|
|
1314
|
+
if self.imag():
|
|
1315
|
+
y = self.imag()
|
|
1316
|
+
if s:
|
|
1317
|
+
if y < 0:
|
|
1318
|
+
s += " - "
|
|
1319
|
+
y = -y
|
|
1320
|
+
else:
|
|
1321
|
+
s += " + "
|
|
1322
|
+
ystr = y.str(base, **kwds)
|
|
1323
|
+
s += ystr + "*" + istr
|
|
1324
|
+
if not s:
|
|
1325
|
+
s = self.real().str(base, **kwds)
|
|
1326
|
+
return s
|
|
1327
|
+
|
|
1328
|
+
def __format__(self, format_spec):
|
|
1329
|
+
"""
|
|
1330
|
+
Return a formatted string representation of this complex number.
|
|
1331
|
+
|
|
1332
|
+
INPUT:
|
|
1333
|
+
|
|
1334
|
+
- ``format_spec`` -- string; a floating point format specifier as
|
|
1335
|
+
defined by :python:`the format specification mini-language
|
|
1336
|
+
<library/string.html#formatspec>` in Python
|
|
1337
|
+
|
|
1338
|
+
EXAMPLES::
|
|
1339
|
+
|
|
1340
|
+
sage: format(CC(32/3, 0), ' .4f')
|
|
1341
|
+
' 10.6667 + 0.0000*I'
|
|
1342
|
+
sage: format(CC(-2/3, -2/3), '.4e')
|
|
1343
|
+
'-6.6667e-1 - 6.6667e-1*I'
|
|
1344
|
+
|
|
1345
|
+
If the representation type character is absent, the output matches the
|
|
1346
|
+
string representation of the complex number. This has the effect that
|
|
1347
|
+
real and imaginary part are only shown if they are not zero::
|
|
1348
|
+
|
|
1349
|
+
sage: format(CC(0, 2/3), '.4')
|
|
1350
|
+
'0.6667*I'
|
|
1351
|
+
sage: format(CC(2, 0), '.4')
|
|
1352
|
+
'2.000'
|
|
1353
|
+
sage: format(ComplexField(240)(0, 1/7), '.60')
|
|
1354
|
+
'0.142857142857142857142857142857142857142857142857142857142857*I'
|
|
1355
|
+
sage: format(ComplexField(240)(0, 1/7), '.60f')
|
|
1356
|
+
'0.000000000000000000000000000000000000000000000000000000000000
|
|
1357
|
+
+ 0.142857142857142857142857142857142857142857142857142857142857*I'
|
|
1358
|
+
|
|
1359
|
+
Note that the general format does not exactly match the behaviour of
|
|
1360
|
+
``float``. Some Python versions do not implement the full spec
|
|
1361
|
+
(see :issue:`30689`)::
|
|
1362
|
+
|
|
1363
|
+
sage: format(CC(3, 0), '.4g')
|
|
1364
|
+
'3.000 + 0e-15*I'
|
|
1365
|
+
sage: try:
|
|
1366
|
+
....: assert format(CC(3, 0), '#.4g') == '3.000 + 0.e-15*I'
|
|
1367
|
+
....: assert format(CC(0, 0), '+#.4') == '+0.E-15'
|
|
1368
|
+
....: except ValueError:
|
|
1369
|
+
....: pass
|
|
1370
|
+
"""
|
|
1371
|
+
return _format_complex_number(self.real(), self.imag(), format_spec)
|
|
1372
|
+
|
|
1373
|
+
def _latex_(self):
|
|
1374
|
+
r"""
|
|
1375
|
+
Method for converting ``self`` to a string with latex formatting.
|
|
1376
|
+
Called by the global function ``latex``.
|
|
1377
|
+
|
|
1378
|
+
EXAMPLES::
|
|
1379
|
+
|
|
1380
|
+
sage: a = ComplexNumber(2,1)
|
|
1381
|
+
sage: a
|
|
1382
|
+
2.00000000000000 + 1.00000000000000*I
|
|
1383
|
+
sage: latex(a)
|
|
1384
|
+
2.00000000000000 + 1.00000000000000i
|
|
1385
|
+
sage: a._latex_()
|
|
1386
|
+
'2.00000000000000 + 1.00000000000000i'
|
|
1387
|
+
|
|
1388
|
+
::
|
|
1389
|
+
|
|
1390
|
+
sage: b = ComplexNumber(7,4,min_prec=16)
|
|
1391
|
+
sage: b
|
|
1392
|
+
7.000 + 4.000*I
|
|
1393
|
+
sage: latex(b)
|
|
1394
|
+
7.000 + 4.000i
|
|
1395
|
+
sage: b._latex_()
|
|
1396
|
+
'7.000 + 4.000i'
|
|
1397
|
+
|
|
1398
|
+
::
|
|
1399
|
+
|
|
1400
|
+
sage: ComplexNumber(0).log()._latex_()
|
|
1401
|
+
'-\\infty'
|
|
1402
|
+
"""
|
|
1403
|
+
s = repr(self).replace('*I', 'i').replace('infinity','\\infty')
|
|
1404
|
+
return re.sub(r"e(-?\d+)", r" \\times 10^{\1}", s)
|
|
1405
|
+
|
|
1406
|
+
def __pari__(self):
|
|
1407
|
+
r"""
|
|
1408
|
+
Coerces ``self`` into a PARI ``t_COMPLEX`` object,
|
|
1409
|
+
or a ``t_REAL`` if ``self`` is real.
|
|
1410
|
+
|
|
1411
|
+
EXAMPLES:
|
|
1412
|
+
|
|
1413
|
+
Coerce the object using the ``pari`` function::
|
|
1414
|
+
|
|
1415
|
+
sage: # needs sage.libs.pari
|
|
1416
|
+
sage: a = ComplexNumber(2,1)
|
|
1417
|
+
sage: pari(a)
|
|
1418
|
+
2.00000000000000 + 1.00000000000000*I
|
|
1419
|
+
sage: pari(a).type()
|
|
1420
|
+
't_COMPLEX'
|
|
1421
|
+
sage: type(pari(a))
|
|
1422
|
+
<class 'cypari2.gen.Gen'>
|
|
1423
|
+
sage: a.__pari__()
|
|
1424
|
+
2.00000000000000 + 1.00000000000000*I
|
|
1425
|
+
sage: type(a.__pari__())
|
|
1426
|
+
<class 'cypari2.gen.Gen'>
|
|
1427
|
+
sage: a = CC(pi) # needs sage.symbolic
|
|
1428
|
+
sage: pari(a) # needs sage.symbolic
|
|
1429
|
+
3.14159265358979
|
|
1430
|
+
sage: pari(a).type() # needs sage.symbolic
|
|
1431
|
+
't_REAL'
|
|
1432
|
+
sage: a = CC(-2).sqrt()
|
|
1433
|
+
sage: pari(a)
|
|
1434
|
+
1.41421356237310*I
|
|
1435
|
+
"""
|
|
1436
|
+
if self.is_real():
|
|
1437
|
+
return self.real().__pari__()
|
|
1438
|
+
return pari.complex(self.real() or 0, self.imag())
|
|
1439
|
+
|
|
1440
|
+
def __mpc__(self):
|
|
1441
|
+
"""
|
|
1442
|
+
Convert Sage ``ComplexNumber`` to gmpy2 ``mpc``.
|
|
1443
|
+
|
|
1444
|
+
EXAMPLES::
|
|
1445
|
+
|
|
1446
|
+
sage: c = ComplexNumber(2,1)
|
|
1447
|
+
sage: c.__mpc__()
|
|
1448
|
+
mpc('2.0+1.0j')
|
|
1449
|
+
sage: from gmpy2 import mpc
|
|
1450
|
+
sage: mpc(c)
|
|
1451
|
+
mpc('2.0+1.0j')
|
|
1452
|
+
sage: CF = ComplexField(134)
|
|
1453
|
+
sage: mpc(CF.pi()).precision
|
|
1454
|
+
(134, 134)
|
|
1455
|
+
sage: CF = ComplexField(45)
|
|
1456
|
+
sage: mpc(CF.zeta(5)).precision
|
|
1457
|
+
(45, 45)
|
|
1458
|
+
sage: CF = ComplexField(255)
|
|
1459
|
+
sage: x = CF(5, 8)
|
|
1460
|
+
sage: y = mpc(x)
|
|
1461
|
+
sage: y.precision
|
|
1462
|
+
(255, 255)
|
|
1463
|
+
sage: CF(y) == x
|
|
1464
|
+
True
|
|
1465
|
+
sage: x = mpc('1.324+4e50j', precision=(70,70))
|
|
1466
|
+
sage: CF = ComplexField(70)
|
|
1467
|
+
sage: y = CF(x)
|
|
1468
|
+
sage: x == mpc(y)
|
|
1469
|
+
True
|
|
1470
|
+
"""
|
|
1471
|
+
return gmpy2.GMPy_MPC_From_mpfr(self.__re, self.__im)
|
|
1472
|
+
|
|
1473
|
+
def _mpmath_(self, prec=None, rounding=None):
|
|
1474
|
+
"""
|
|
1475
|
+
Return an mpmath version of ``self``.
|
|
1476
|
+
|
|
1477
|
+
.. NOTE::
|
|
1478
|
+
|
|
1479
|
+
Currently, the rounding mode is ignored.
|
|
1480
|
+
|
|
1481
|
+
EXAMPLES::
|
|
1482
|
+
|
|
1483
|
+
sage: CC(1,2)._mpmath_()
|
|
1484
|
+
mpc(real='1.0', imag='2.0')
|
|
1485
|
+
"""
|
|
1486
|
+
if prec is not None:
|
|
1487
|
+
return ComplexField(prec)(self)._mpmath_()
|
|
1488
|
+
from sage.libs.mpmath.all import make_mpc
|
|
1489
|
+
real = mpfr_to_mpfval(self.__re)
|
|
1490
|
+
imag = mpfr_to_mpfval(self.__im)
|
|
1491
|
+
return make_mpc((real, imag))
|
|
1492
|
+
|
|
1493
|
+
def _sympy_(self):
|
|
1494
|
+
"""
|
|
1495
|
+
Convert this complex number to Sympy.
|
|
1496
|
+
|
|
1497
|
+
EXAMPLES::
|
|
1498
|
+
|
|
1499
|
+
sage: CC(1, 0)._sympy_() # needs sympy
|
|
1500
|
+
1.00000000000000
|
|
1501
|
+
sage: CC(1/3, 1)._sympy_() # needs sympy
|
|
1502
|
+
0.333333333333333 + 1.0*I
|
|
1503
|
+
sage: type(_) # needs sympy
|
|
1504
|
+
<class 'sympy.core.add.Add'>
|
|
1505
|
+
"""
|
|
1506
|
+
import sympy
|
|
1507
|
+
return self.real()._sympy_() + self.imag()._sympy_() * sympy.I
|
|
1508
|
+
|
|
1509
|
+
cpdef _add_(self, right):
|
|
1510
|
+
"""
|
|
1511
|
+
Add ``self`` to ``right``.
|
|
1512
|
+
|
|
1513
|
+
EXAMPLES::
|
|
1514
|
+
|
|
1515
|
+
sage: CC(2, 1)._add_(CC(1, -2))
|
|
1516
|
+
3.00000000000000 - 1.00000000000000*I
|
|
1517
|
+
"""
|
|
1518
|
+
cdef ComplexNumber x
|
|
1519
|
+
x = self._new()
|
|
1520
|
+
mpfr_add(x.__re, self.__re, (<ComplexNumber>right).__re, rnd)
|
|
1521
|
+
mpfr_add(x.__im, self.__im, (<ComplexNumber>right).__im, rnd)
|
|
1522
|
+
return x
|
|
1523
|
+
|
|
1524
|
+
cpdef _sub_(self, right):
|
|
1525
|
+
"""
|
|
1526
|
+
Subtract ``right`` from ``self``.
|
|
1527
|
+
|
|
1528
|
+
EXAMPLES::
|
|
1529
|
+
|
|
1530
|
+
sage: CC(2, 1)._sub_(CC(1, -2))
|
|
1531
|
+
1.00000000000000 + 3.00000000000000*I
|
|
1532
|
+
"""
|
|
1533
|
+
cdef ComplexNumber x
|
|
1534
|
+
x = self._new()
|
|
1535
|
+
mpfr_sub(x.__re, self.__re, (<ComplexNumber>right).__re, rnd)
|
|
1536
|
+
mpfr_sub(x.__im, self.__im, (<ComplexNumber>right).__im, rnd)
|
|
1537
|
+
return x
|
|
1538
|
+
|
|
1539
|
+
cpdef _mul_(self, right):
|
|
1540
|
+
"""
|
|
1541
|
+
Multiply ``self`` by ``right``.
|
|
1542
|
+
|
|
1543
|
+
EXAMPLES::
|
|
1544
|
+
|
|
1545
|
+
sage: CC(2, 1)._mul_(CC(1, -2))
|
|
1546
|
+
4.00000000000000 - 3.00000000000000*I
|
|
1547
|
+
"""
|
|
1548
|
+
cdef ComplexNumber x
|
|
1549
|
+
x = self._new()
|
|
1550
|
+
cdef mpfr_t t0, t1
|
|
1551
|
+
mpfr_init2(t0, self._prec)
|
|
1552
|
+
mpfr_init2(t1, self._prec)
|
|
1553
|
+
mpfr_mul(t0, self.__re, (<ComplexNumber>right).__re, rnd)
|
|
1554
|
+
mpfr_mul(t1, self.__im, (<ComplexNumber>right).__im, rnd)
|
|
1555
|
+
mpfr_sub(x.__re, t0, t1, rnd)
|
|
1556
|
+
mpfr_mul(t0, self.__re, (<ComplexNumber>right).__im, rnd)
|
|
1557
|
+
mpfr_mul(t1, self.__im, (<ComplexNumber>right).__re, rnd)
|
|
1558
|
+
mpfr_add(x.__im, t0, t1, rnd)
|
|
1559
|
+
mpfr_clear(t0)
|
|
1560
|
+
mpfr_clear(t1)
|
|
1561
|
+
return x
|
|
1562
|
+
|
|
1563
|
+
def norm(self):
|
|
1564
|
+
r"""
|
|
1565
|
+
Return the norm of this complex number.
|
|
1566
|
+
|
|
1567
|
+
If `c = a + bi` is a complex number, then the norm of `c` is defined as
|
|
1568
|
+
the product of `c` and its complex conjugate:
|
|
1569
|
+
|
|
1570
|
+
.. MATH::
|
|
1571
|
+
|
|
1572
|
+
\text{norm}(c)
|
|
1573
|
+
=
|
|
1574
|
+
\text{norm}(a + bi)
|
|
1575
|
+
=
|
|
1576
|
+
c \cdot \overline{c}
|
|
1577
|
+
=
|
|
1578
|
+
a^2 + b^2.
|
|
1579
|
+
|
|
1580
|
+
The norm of a complex number is different from its absolute value.
|
|
1581
|
+
The absolute value of a complex number is defined to be the square
|
|
1582
|
+
root of its norm. A typical use of the complex norm is in the
|
|
1583
|
+
integral domain `\ZZ[i]` of Gaussian integers, where the norm of
|
|
1584
|
+
each Gaussian integer `c = a + bi` is defined as its complex norm.
|
|
1585
|
+
|
|
1586
|
+
.. SEEALSO::
|
|
1587
|
+
|
|
1588
|
+
- :func:`sage.misc.functional.norm`
|
|
1589
|
+
|
|
1590
|
+
- :meth:`sage.rings.complex_double.ComplexDoubleElement.norm`
|
|
1591
|
+
|
|
1592
|
+
EXAMPLES:
|
|
1593
|
+
|
|
1594
|
+
This indeed acts as the square function when the
|
|
1595
|
+
imaginary component of ``self`` is equal to zero::
|
|
1596
|
+
|
|
1597
|
+
sage: a = ComplexNumber(2,1)
|
|
1598
|
+
sage: a.norm()
|
|
1599
|
+
5.00000000000000
|
|
1600
|
+
sage: b = ComplexNumber(4.2,0)
|
|
1601
|
+
sage: b.norm()
|
|
1602
|
+
17.6400000000000
|
|
1603
|
+
sage: b^2
|
|
1604
|
+
17.6400000000000
|
|
1605
|
+
"""
|
|
1606
|
+
return self.norm_c()
|
|
1607
|
+
|
|
1608
|
+
cdef RealNumber norm_c(ComplexNumber self):
|
|
1609
|
+
cdef RealNumber x
|
|
1610
|
+
x = RealNumber(self._parent._real_field(), None)
|
|
1611
|
+
|
|
1612
|
+
cdef mpfr_t t0, t1
|
|
1613
|
+
mpfr_init2(t0, self._prec)
|
|
1614
|
+
mpfr_init2(t1, self._prec)
|
|
1615
|
+
|
|
1616
|
+
mpfr_mul(t0, self.__re, self.__re, rnd)
|
|
1617
|
+
mpfr_mul(t1, self.__im, self.__im, rnd)
|
|
1618
|
+
|
|
1619
|
+
mpfr_add(x.value, t0, t1, rnd)
|
|
1620
|
+
|
|
1621
|
+
mpfr_clear(t0)
|
|
1622
|
+
mpfr_clear(t1)
|
|
1623
|
+
return x
|
|
1624
|
+
|
|
1625
|
+
cdef RealNumber abs_c(ComplexNumber self):
|
|
1626
|
+
cdef RealNumber x
|
|
1627
|
+
x = RealNumber(self._parent._real_field(), None)
|
|
1628
|
+
|
|
1629
|
+
cdef mpfr_t t0, t1
|
|
1630
|
+
mpfr_init2(t0, self._prec)
|
|
1631
|
+
mpfr_init2(t1, self._prec)
|
|
1632
|
+
|
|
1633
|
+
mpfr_mul(t0, self.__re, self.__re, rnd)
|
|
1634
|
+
mpfr_mul(t1, self.__im, self.__im, rnd)
|
|
1635
|
+
|
|
1636
|
+
mpfr_add(x.value, t0, t1, rnd)
|
|
1637
|
+
mpfr_sqrt(x.value, x.value, rnd)
|
|
1638
|
+
|
|
1639
|
+
mpfr_clear(t0)
|
|
1640
|
+
mpfr_clear(t1)
|
|
1641
|
+
return x
|
|
1642
|
+
|
|
1643
|
+
cpdef _div_(self, right):
|
|
1644
|
+
"""
|
|
1645
|
+
Divide ``self`` by ``right``.
|
|
1646
|
+
|
|
1647
|
+
EXAMPLES::
|
|
1648
|
+
|
|
1649
|
+
sage: CC(2, 1)._div_(CC(1, -2))
|
|
1650
|
+
1.00000000000000*I
|
|
1651
|
+
"""
|
|
1652
|
+
cdef ComplexNumber x
|
|
1653
|
+
x = self._new()
|
|
1654
|
+
cdef mpfr_t a, b, t0, t1, right_nm
|
|
1655
|
+
mpfr_init2(t0, self._prec)
|
|
1656
|
+
mpfr_init2(t1, self._prec)
|
|
1657
|
+
mpfr_init2(a, self._prec)
|
|
1658
|
+
mpfr_init2(b, self._prec)
|
|
1659
|
+
mpfr_init2(right_nm, self._prec)
|
|
1660
|
+
|
|
1661
|
+
mpfr_mul(t0, (<ComplexNumber>right).__re, (<ComplexNumber>right).__re, rnd)
|
|
1662
|
+
mpfr_mul(t1, (<ComplexNumber>right).__im, (<ComplexNumber>right).__im, rnd)
|
|
1663
|
+
mpfr_add(right_nm, t0, t1, rnd)
|
|
1664
|
+
|
|
1665
|
+
mpfr_div(a, (<ComplexNumber>right).__re, right_nm, rnd)
|
|
1666
|
+
mpfr_div(b, (<ComplexNumber>right).__im, right_nm, rnd)
|
|
1667
|
+
|
|
1668
|
+
## Do this: x.__re = a * self.__re + b * self.__im
|
|
1669
|
+
mpfr_mul(t0, a, self.__re, rnd)
|
|
1670
|
+
mpfr_mul(t1, b, self.__im, rnd)
|
|
1671
|
+
mpfr_add(x.__re, t0, t1, rnd)
|
|
1672
|
+
|
|
1673
|
+
## Do this: x.__im = a * self.__im - b * self.__re
|
|
1674
|
+
mpfr_mul(t0, a, self.__im, rnd)
|
|
1675
|
+
mpfr_mul(t1, b, self.__re, rnd)
|
|
1676
|
+
mpfr_sub(x.__im, t0, t1, rnd)
|
|
1677
|
+
mpfr_clear(t0)
|
|
1678
|
+
mpfr_clear(t1)
|
|
1679
|
+
mpfr_clear(a)
|
|
1680
|
+
mpfr_clear(b)
|
|
1681
|
+
mpfr_clear(right_nm)
|
|
1682
|
+
return x
|
|
1683
|
+
|
|
1684
|
+
def __pow__(self, right, modulus):
|
|
1685
|
+
r"""
|
|
1686
|
+
Raise ``self`` to the ``right`` exponent.
|
|
1687
|
+
|
|
1688
|
+
This takes `a^b` and computes `\exp(b \log(a))`.
|
|
1689
|
+
|
|
1690
|
+
EXAMPLES::
|
|
1691
|
+
|
|
1692
|
+
sage: C.<i> = ComplexField(20)
|
|
1693
|
+
sage: a = i^2; a
|
|
1694
|
+
-1.0000
|
|
1695
|
+
sage: a.parent()
|
|
1696
|
+
Complex Field with 20 bits of precision
|
|
1697
|
+
sage: a = (1+i)^i; a
|
|
1698
|
+
0.42883 + 0.15487*I
|
|
1699
|
+
sage: (1+i)^(1+i)
|
|
1700
|
+
0.27396 + 0.58370*I
|
|
1701
|
+
sage: a.parent()
|
|
1702
|
+
Complex Field with 20 bits of precision
|
|
1703
|
+
sage: i^i
|
|
1704
|
+
0.20788
|
|
1705
|
+
sage: (2+i)^(0.5)
|
|
1706
|
+
1.4553 + 0.34356*I
|
|
1707
|
+
|
|
1708
|
+
TESTS:
|
|
1709
|
+
|
|
1710
|
+
Check that :issue:`11323` is fixed::
|
|
1711
|
+
|
|
1712
|
+
sage: float(5)^(0.5 + 14.1347251*I) # needs sage.symbolic
|
|
1713
|
+
-1.62414637645790 - 1.53692828324508*I
|
|
1714
|
+
"""
|
|
1715
|
+
if isinstance(right, (int, Integer)):
|
|
1716
|
+
return RingElement.__pow__(self, right)
|
|
1717
|
+
|
|
1718
|
+
try:
|
|
1719
|
+
return (self.log()*right).exp()
|
|
1720
|
+
except (AttributeError, TypeError):
|
|
1721
|
+
pass
|
|
1722
|
+
|
|
1723
|
+
try:
|
|
1724
|
+
self = right.parent()(self)
|
|
1725
|
+
return self**right
|
|
1726
|
+
except AttributeError:
|
|
1727
|
+
raise TypeError
|
|
1728
|
+
|
|
1729
|
+
def _magma_init_(self, magma):
|
|
1730
|
+
r"""
|
|
1731
|
+
EXAMPLES::
|
|
1732
|
+
|
|
1733
|
+
sage: magma(CC([1, 2])) # indirect doctest, optional - magma
|
|
1734
|
+
1.00000000000000 + 2.00000000000000*$.1
|
|
1735
|
+
sage: v = magma(CC([1, 2])).sage(); v # indirect, optional - magma
|
|
1736
|
+
1.00000000000000 + 2.00000000000000*I
|
|
1737
|
+
sage: v.parent() # optional - magma
|
|
1738
|
+
Complex Field with 53 bits of precision
|
|
1739
|
+
|
|
1740
|
+
sage: i = ComplexField(200).gen()
|
|
1741
|
+
sage: sqrt(i)
|
|
1742
|
+
0.70710678118654752440084436210484903928483593768847403658834 + 0.70710678118654752440084436210484903928483593768847403658834*I
|
|
1743
|
+
sage: magma(sqrt(i)) # indirect, optional - magma
|
|
1744
|
+
0.707106781186547524400844362104849039284835937688474036588340 + 0.707106781186547524400844362104849039284835937688474036588340*$.1
|
|
1745
|
+
sage: magma(i).Sqrt() # indirect, optional - magma
|
|
1746
|
+
0.707106781186547524400844362104849039284835937688474036588340 + 0.707106781186547524400844362104849039284835937688474036588340*$.1
|
|
1747
|
+
|
|
1748
|
+
sage: magma(ComplexField(200)(1/3)) # indirect, optional - magma
|
|
1749
|
+
0.333333333333333333333333333333333333333333333333333333333333
|
|
1750
|
+
"""
|
|
1751
|
+
real_string = self.real().str()
|
|
1752
|
+
imag_string = self.imag().str()
|
|
1753
|
+
digit_precision_bound = len(real_string)
|
|
1754
|
+
return "%s![%sp%s, %sp%s]" % (self.parent()._magma_init_(magma),
|
|
1755
|
+
real_string, digit_precision_bound,
|
|
1756
|
+
imag_string, digit_precision_bound)
|
|
1757
|
+
|
|
1758
|
+
def __bool__(self):
|
|
1759
|
+
"""
|
|
1760
|
+
Return ``True`` if ``self`` is not zero. This is an internal function;
|
|
1761
|
+
use :meth:`is_zero` instead.
|
|
1762
|
+
|
|
1763
|
+
EXAMPLES::
|
|
1764
|
+
|
|
1765
|
+
sage: z = 1 + CC(I) # needs sage.symbolic
|
|
1766
|
+
sage: z.is_zero() # needs sage.symbolic
|
|
1767
|
+
False
|
|
1768
|
+
"""
|
|
1769
|
+
return not (mpfr_zero_p(self.__re) and mpfr_zero_p(self.__im))
|
|
1770
|
+
|
|
1771
|
+
def prec(self):
|
|
1772
|
+
"""
|
|
1773
|
+
Return precision of this complex number.
|
|
1774
|
+
|
|
1775
|
+
EXAMPLES::
|
|
1776
|
+
|
|
1777
|
+
sage: i = ComplexField(2000).0
|
|
1778
|
+
sage: i.prec()
|
|
1779
|
+
2000
|
|
1780
|
+
"""
|
|
1781
|
+
return self._parent.prec()
|
|
1782
|
+
|
|
1783
|
+
def real(self):
|
|
1784
|
+
"""
|
|
1785
|
+
Return real part of ``self``.
|
|
1786
|
+
|
|
1787
|
+
EXAMPLES::
|
|
1788
|
+
|
|
1789
|
+
sage: i = ComplexField(100).0
|
|
1790
|
+
sage: z = 2 + 3*i
|
|
1791
|
+
sage: x = z.real(); x
|
|
1792
|
+
2.0000000000000000000000000000
|
|
1793
|
+
sage: x.parent()
|
|
1794
|
+
Real Field with 100 bits of precision
|
|
1795
|
+
sage: z.real_part()
|
|
1796
|
+
2.0000000000000000000000000000
|
|
1797
|
+
"""
|
|
1798
|
+
cdef RealNumber x
|
|
1799
|
+
x = RealNumber(self._parent._real_field(), None)
|
|
1800
|
+
mpfr_set(x.value, self.__re, rnd)
|
|
1801
|
+
return x
|
|
1802
|
+
|
|
1803
|
+
real_part = real
|
|
1804
|
+
|
|
1805
|
+
def imag(self):
|
|
1806
|
+
"""
|
|
1807
|
+
Return imaginary part of ``self``.
|
|
1808
|
+
|
|
1809
|
+
EXAMPLES::
|
|
1810
|
+
|
|
1811
|
+
sage: i = ComplexField(100).0
|
|
1812
|
+
sage: z = 2 + 3*i
|
|
1813
|
+
sage: x = z.imag(); x
|
|
1814
|
+
3.0000000000000000000000000000
|
|
1815
|
+
sage: x.parent()
|
|
1816
|
+
Real Field with 100 bits of precision
|
|
1817
|
+
sage: z.imag_part()
|
|
1818
|
+
3.0000000000000000000000000000
|
|
1819
|
+
"""
|
|
1820
|
+
cdef RealNumber x
|
|
1821
|
+
x = RealNumber(self._parent._real_field(), None)
|
|
1822
|
+
mpfr_set(x.value, self.__im, rnd)
|
|
1823
|
+
return x
|
|
1824
|
+
|
|
1825
|
+
imag_part = imag
|
|
1826
|
+
|
|
1827
|
+
def __neg__(self):
|
|
1828
|
+
r"""
|
|
1829
|
+
Method for computing the negative of ``self``.
|
|
1830
|
+
|
|
1831
|
+
.. MATH::
|
|
1832
|
+
|
|
1833
|
+
-(a + bi) = -a - bi
|
|
1834
|
+
|
|
1835
|
+
EXAMPLES::
|
|
1836
|
+
|
|
1837
|
+
sage: a = ComplexNumber(2,1)
|
|
1838
|
+
sage: -a
|
|
1839
|
+
-2.00000000000000 - 1.00000000000000*I
|
|
1840
|
+
sage: a.__neg__()
|
|
1841
|
+
-2.00000000000000 - 1.00000000000000*I
|
|
1842
|
+
"""
|
|
1843
|
+
cdef ComplexNumber x
|
|
1844
|
+
x = self._new()
|
|
1845
|
+
mpfr_neg(x.__re, self.__re, rnd)
|
|
1846
|
+
mpfr_neg(x.__im, self.__im, rnd)
|
|
1847
|
+
return x
|
|
1848
|
+
|
|
1849
|
+
def __pos__(self):
|
|
1850
|
+
r"""
|
|
1851
|
+
Method for computing the "positive" of ``self``.
|
|
1852
|
+
|
|
1853
|
+
EXAMPLES::
|
|
1854
|
+
|
|
1855
|
+
sage: a = ComplexNumber(2,1)
|
|
1856
|
+
sage: +a
|
|
1857
|
+
2.00000000000000 + 1.00000000000000*I
|
|
1858
|
+
sage: a.__pos__()
|
|
1859
|
+
2.00000000000000 + 1.00000000000000*I
|
|
1860
|
+
"""
|
|
1861
|
+
return self
|
|
1862
|
+
|
|
1863
|
+
def __abs__(self):
|
|
1864
|
+
r"""
|
|
1865
|
+
Method for computing the absolute value or modulus of ``self``.
|
|
1866
|
+
|
|
1867
|
+
.. MATH::
|
|
1868
|
+
|
|
1869
|
+
`|a + bi| = sqrt(a^2 + b^2)`
|
|
1870
|
+
|
|
1871
|
+
EXAMPLES:
|
|
1872
|
+
|
|
1873
|
+
Note that the absolute value of a complex number with imaginary
|
|
1874
|
+
component equal to zero is the absolute value of the real component.
|
|
1875
|
+
|
|
1876
|
+
::
|
|
1877
|
+
|
|
1878
|
+
sage: a = ComplexNumber(2,1)
|
|
1879
|
+
sage: abs(a)
|
|
1880
|
+
2.23606797749979
|
|
1881
|
+
sage: a.__abs__()
|
|
1882
|
+
2.23606797749979
|
|
1883
|
+
sage: float(sqrt(2^2 + 1^1)) # needs sage.symbolic
|
|
1884
|
+
2.23606797749979
|
|
1885
|
+
|
|
1886
|
+
::
|
|
1887
|
+
|
|
1888
|
+
sage: b = ComplexNumber(42,0)
|
|
1889
|
+
sage: abs(b)
|
|
1890
|
+
42.0000000000000
|
|
1891
|
+
sage: b.__abs__()
|
|
1892
|
+
42.0000000000000
|
|
1893
|
+
sage: b
|
|
1894
|
+
42.0000000000000
|
|
1895
|
+
"""
|
|
1896
|
+
return self.abs_c()
|
|
1897
|
+
|
|
1898
|
+
def __invert__(self):
|
|
1899
|
+
"""
|
|
1900
|
+
Return the multiplicative inverse.
|
|
1901
|
+
|
|
1902
|
+
EXAMPLES::
|
|
1903
|
+
|
|
1904
|
+
sage: I = CC.0
|
|
1905
|
+
sage: a = ~(5+I)
|
|
1906
|
+
sage: a * (5+I)
|
|
1907
|
+
1.00000000000000
|
|
1908
|
+
"""
|
|
1909
|
+
cdef ComplexNumber x
|
|
1910
|
+
x = self._new()
|
|
1911
|
+
|
|
1912
|
+
cdef mpfr_t t0, t1
|
|
1913
|
+
mpfr_init2(t0, self._prec)
|
|
1914
|
+
mpfr_init2(t1, self._prec)
|
|
1915
|
+
|
|
1916
|
+
mpfr_mul(t0, self.__re, self.__re, rnd)
|
|
1917
|
+
mpfr_mul(t1, self.__im, self.__im, rnd)
|
|
1918
|
+
|
|
1919
|
+
mpfr_add(t0, t0, t1, rnd) # now t0 is the norm
|
|
1920
|
+
mpfr_div(x.__re, self.__re, t0, rnd) # x.__re = self.__re/norm
|
|
1921
|
+
|
|
1922
|
+
mpfr_neg(t1, self.__im, rnd)
|
|
1923
|
+
mpfr_div(x.__im, t1, t0, rnd) # x.__im = -self.__im/norm
|
|
1924
|
+
|
|
1925
|
+
mpfr_clear(t0)
|
|
1926
|
+
mpfr_clear(t1)
|
|
1927
|
+
|
|
1928
|
+
return x
|
|
1929
|
+
|
|
1930
|
+
def __int__(self):
|
|
1931
|
+
r"""
|
|
1932
|
+
Method for converting ``self`` to type ``int``.
|
|
1933
|
+
|
|
1934
|
+
Called by the ``int`` function. Note that calling this method returns
|
|
1935
|
+
an error since, in general, complex numbers cannot be coerced into
|
|
1936
|
+
integers.
|
|
1937
|
+
|
|
1938
|
+
EXAMPLES::
|
|
1939
|
+
|
|
1940
|
+
sage: a = ComplexNumber(2,1)
|
|
1941
|
+
sage: int(a)
|
|
1942
|
+
Traceback (most recent call last):
|
|
1943
|
+
...
|
|
1944
|
+
TypeError: can...t convert complex to int; use int(abs(z))
|
|
1945
|
+
sage: a.__int__()
|
|
1946
|
+
Traceback (most recent call last):
|
|
1947
|
+
...
|
|
1948
|
+
TypeError: can...t convert complex to int; use int(abs(z))
|
|
1949
|
+
"""
|
|
1950
|
+
raise TypeError("can't convert complex to int; use int(abs(z))")
|
|
1951
|
+
|
|
1952
|
+
def __float__(self):
|
|
1953
|
+
r"""
|
|
1954
|
+
Method for converting ``self`` to type ``float``.
|
|
1955
|
+
|
|
1956
|
+
Called by the ``float`` function. This conversion will throw an error
|
|
1957
|
+
if the number has a nonzero imaginary part.
|
|
1958
|
+
|
|
1959
|
+
EXAMPLES::
|
|
1960
|
+
|
|
1961
|
+
sage: a = ComplexNumber(1, 0)
|
|
1962
|
+
sage: float(a)
|
|
1963
|
+
1.0
|
|
1964
|
+
sage: a = ComplexNumber(2,1)
|
|
1965
|
+
sage: float(a)
|
|
1966
|
+
Traceback (most recent call last):
|
|
1967
|
+
...
|
|
1968
|
+
TypeError: unable to convert 2.00000000000000 + 1.00000000000000*I to float; use abs() or real_part() as desired
|
|
1969
|
+
sage: a.__float__()
|
|
1970
|
+
Traceback (most recent call last):
|
|
1971
|
+
...
|
|
1972
|
+
TypeError: unable to convert 2.00000000000000 + 1.00000000000000*I to float; use abs() or real_part() as desired
|
|
1973
|
+
sage: float(abs(ComplexNumber(1,1)))
|
|
1974
|
+
1.4142135623730951
|
|
1975
|
+
"""
|
|
1976
|
+
if mpfr_zero_p(self.__im) or mpfr_nan_p(self.__re):
|
|
1977
|
+
return mpfr_get_d(self.__re, rnd)
|
|
1978
|
+
else:
|
|
1979
|
+
raise TypeError("unable to convert {!r} to float; use abs() or real_part() as desired".format(self))
|
|
1980
|
+
|
|
1981
|
+
def __complex__(self):
|
|
1982
|
+
r"""
|
|
1983
|
+
Method for converting ``self`` to type ``complex``.
|
|
1984
|
+
|
|
1985
|
+
Called by the ``complex`` function.
|
|
1986
|
+
|
|
1987
|
+
EXAMPLES::
|
|
1988
|
+
|
|
1989
|
+
sage: a = ComplexNumber(2,1)
|
|
1990
|
+
sage: complex(a)
|
|
1991
|
+
(2+1j)
|
|
1992
|
+
sage: type(complex(a))
|
|
1993
|
+
<... 'complex'>
|
|
1994
|
+
sage: a.__complex__()
|
|
1995
|
+
(2+1j)
|
|
1996
|
+
"""
|
|
1997
|
+
return complex(mpfr_get_d(self.__re, rnd),
|
|
1998
|
+
mpfr_get_d(self.__im, rnd))
|
|
1999
|
+
|
|
2000
|
+
cpdef _richcmp_(left, right, int op):
|
|
2001
|
+
"""
|
|
2002
|
+
Compare ``left`` and ``right``.
|
|
2003
|
+
|
|
2004
|
+
EXAMPLES::
|
|
2005
|
+
|
|
2006
|
+
sage: CC(2, 1) > CC(-1, 2)
|
|
2007
|
+
True
|
|
2008
|
+
sage: CC(2, 1) == CC(2, 1)
|
|
2009
|
+
True
|
|
2010
|
+
"""
|
|
2011
|
+
cdef int a, b
|
|
2012
|
+
a = mpfr_nan_p(left.__re)
|
|
2013
|
+
b = mpfr_nan_p((<ComplexNumber>right).__re)
|
|
2014
|
+
if a != b:
|
|
2015
|
+
return rich_to_bool(op, -1)
|
|
2016
|
+
|
|
2017
|
+
cdef int i
|
|
2018
|
+
i = mpfr_cmp(left.__re, (<ComplexNumber>right).__re)
|
|
2019
|
+
if i < 0:
|
|
2020
|
+
return rich_to_bool(op, -1)
|
|
2021
|
+
elif i > 0:
|
|
2022
|
+
return rich_to_bool(op, 1)
|
|
2023
|
+
i = mpfr_cmp(left.__im, (<ComplexNumber>right).__im)
|
|
2024
|
+
if i < 0:
|
|
2025
|
+
return rich_to_bool(op, -1)
|
|
2026
|
+
elif i > 0:
|
|
2027
|
+
return rich_to_bool(op, 1)
|
|
2028
|
+
return rich_to_bool(op, 0)
|
|
2029
|
+
|
|
2030
|
+
def multiplicative_order(self):
|
|
2031
|
+
"""
|
|
2032
|
+
Return the multiplicative order of this complex number, if known,
|
|
2033
|
+
or raise a :exc:`NotImplementedError`.
|
|
2034
|
+
|
|
2035
|
+
EXAMPLES::
|
|
2036
|
+
|
|
2037
|
+
sage: C.<i> = ComplexField()
|
|
2038
|
+
sage: i.multiplicative_order()
|
|
2039
|
+
4
|
|
2040
|
+
sage: C(1).multiplicative_order()
|
|
2041
|
+
1
|
|
2042
|
+
sage: C(-1).multiplicative_order()
|
|
2043
|
+
2
|
|
2044
|
+
sage: C(i^2).multiplicative_order()
|
|
2045
|
+
2
|
|
2046
|
+
sage: C(-i).multiplicative_order()
|
|
2047
|
+
4
|
|
2048
|
+
sage: C(2).multiplicative_order()
|
|
2049
|
+
+Infinity
|
|
2050
|
+
sage: w = (1+sqrt(-3.0))/2; w
|
|
2051
|
+
0.500000000000000 + 0.866025403784439*I
|
|
2052
|
+
sage: abs(w)
|
|
2053
|
+
1.00000000000000
|
|
2054
|
+
sage: w.multiplicative_order()
|
|
2055
|
+
Traceback (most recent call last):
|
|
2056
|
+
...
|
|
2057
|
+
NotImplementedError: order of element not known
|
|
2058
|
+
"""
|
|
2059
|
+
if self == 1:
|
|
2060
|
+
return Integer(1)
|
|
2061
|
+
elif self == -1:
|
|
2062
|
+
return Integer(2)
|
|
2063
|
+
elif self == self._parent.gen():
|
|
2064
|
+
return Integer(4)
|
|
2065
|
+
elif self == -self._parent.gen():
|
|
2066
|
+
return Integer(4)
|
|
2067
|
+
elif self._multiplicative_order is not None:
|
|
2068
|
+
return Integer(self._multiplicative_order)
|
|
2069
|
+
elif abs(abs(self) - 1) > 0.1: # clearly not a root of unity
|
|
2070
|
+
return infinity.infinity
|
|
2071
|
+
raise NotImplementedError("order of element not known")
|
|
2072
|
+
|
|
2073
|
+
########################################################################
|
|
2074
|
+
# Plotting
|
|
2075
|
+
########################################################################
|
|
2076
|
+
|
|
2077
|
+
def plot(self, **kargs):
|
|
2078
|
+
"""
|
|
2079
|
+
Plots this complex number as a point in the plane.
|
|
2080
|
+
|
|
2081
|
+
The accepted options are the ones of :meth:`~sage.plot.point.point2d`.
|
|
2082
|
+
Type ``point2d.options`` to see all options.
|
|
2083
|
+
|
|
2084
|
+
.. NOTE::
|
|
2085
|
+
|
|
2086
|
+
Just wraps the sage.plot.point.point2d method
|
|
2087
|
+
|
|
2088
|
+
EXAMPLES:
|
|
2089
|
+
|
|
2090
|
+
You can either use the indirect::
|
|
2091
|
+
|
|
2092
|
+
sage: z = CC(0,1)
|
|
2093
|
+
sage: plot(z) # needs sage.plot
|
|
2094
|
+
Graphics object consisting of 1 graphics primitive
|
|
2095
|
+
|
|
2096
|
+
or the more direct::
|
|
2097
|
+
|
|
2098
|
+
sage: z = CC(0,1)
|
|
2099
|
+
sage: z.plot() # needs sage.plot
|
|
2100
|
+
Graphics object consisting of 1 graphics primitive
|
|
2101
|
+
"""
|
|
2102
|
+
return sage.plot.point.point2d((self.real(), self.imag()), **kargs)
|
|
2103
|
+
|
|
2104
|
+
########################################################################
|
|
2105
|
+
# Transcendental (and other) functions
|
|
2106
|
+
########################################################################
|
|
2107
|
+
|
|
2108
|
+
# Trig functions
|
|
2109
|
+
def arccos(self):
|
|
2110
|
+
"""
|
|
2111
|
+
Return the arccosine of ``self``.
|
|
2112
|
+
|
|
2113
|
+
EXAMPLES::
|
|
2114
|
+
|
|
2115
|
+
sage: (1+CC(I)).arccos() # needs sage.libs.pari sage.symbolic
|
|
2116
|
+
0.904556894302381 - 1.06127506190504*I
|
|
2117
|
+
"""
|
|
2118
|
+
return self._parent(self.__pari__().acos())
|
|
2119
|
+
|
|
2120
|
+
def arccosh(self):
|
|
2121
|
+
"""
|
|
2122
|
+
Return the hyperbolic arccosine of ``self``.
|
|
2123
|
+
|
|
2124
|
+
EXAMPLES::
|
|
2125
|
+
|
|
2126
|
+
sage: (1+CC(I)).arccosh() # needs sage.libs.pari sage.symbolic
|
|
2127
|
+
1.06127506190504 + 0.904556894302381*I
|
|
2128
|
+
"""
|
|
2129
|
+
return self._parent(self.__pari__().acosh())
|
|
2130
|
+
|
|
2131
|
+
def arcsin(self):
|
|
2132
|
+
"""
|
|
2133
|
+
Return the arcsine of ``self``.
|
|
2134
|
+
|
|
2135
|
+
EXAMPLES::
|
|
2136
|
+
|
|
2137
|
+
sage: (1+CC(I)).arcsin() # needs sage.libs.pari sage.symbolic
|
|
2138
|
+
0.666239432492515 + 1.06127506190504*I
|
|
2139
|
+
"""
|
|
2140
|
+
return self._parent(self.__pari__().asin())
|
|
2141
|
+
|
|
2142
|
+
def arcsinh(self):
|
|
2143
|
+
"""
|
|
2144
|
+
Return the hyperbolic arcsine of ``self``.
|
|
2145
|
+
|
|
2146
|
+
EXAMPLES::
|
|
2147
|
+
|
|
2148
|
+
sage: (1+CC(I)).arcsinh() # needs sage.libs.pari sage.symbolic
|
|
2149
|
+
1.06127506190504 + 0.666239432492515*I
|
|
2150
|
+
"""
|
|
2151
|
+
return self._parent(self.__pari__().asinh())
|
|
2152
|
+
|
|
2153
|
+
def arctan(self):
|
|
2154
|
+
"""
|
|
2155
|
+
Return the arctangent of ``self``.
|
|
2156
|
+
|
|
2157
|
+
EXAMPLES::
|
|
2158
|
+
|
|
2159
|
+
sage: (1+CC(I)).arctan() # needs sage.libs.pari sage.symbolic
|
|
2160
|
+
1.01722196789785 + 0.402359478108525*I
|
|
2161
|
+
"""
|
|
2162
|
+
return self._parent(self.__pari__().atan())
|
|
2163
|
+
|
|
2164
|
+
def arctanh(self):
|
|
2165
|
+
"""
|
|
2166
|
+
Return the hyperbolic arctangent of ``self``.
|
|
2167
|
+
|
|
2168
|
+
EXAMPLES::
|
|
2169
|
+
|
|
2170
|
+
sage: (1+CC(I)).arctanh() # needs sage.libs.pari sage.symbolic
|
|
2171
|
+
0.402359478108525 + 1.01722196789785*I
|
|
2172
|
+
"""
|
|
2173
|
+
return self._parent(self.__pari__().atanh())
|
|
2174
|
+
|
|
2175
|
+
def coth(self):
|
|
2176
|
+
"""
|
|
2177
|
+
Return the hyperbolic cotangent of ``self``.
|
|
2178
|
+
|
|
2179
|
+
EXAMPLES::
|
|
2180
|
+
|
|
2181
|
+
sage: ComplexField(100)(1,1).coth() # needs sage.libs.pari
|
|
2182
|
+
0.86801414289592494863584920892 - 0.21762156185440268136513424361*I
|
|
2183
|
+
"""
|
|
2184
|
+
return ~(self.tanh())
|
|
2185
|
+
|
|
2186
|
+
def arccoth(self):
|
|
2187
|
+
"""
|
|
2188
|
+
Return the hyperbolic arccotangent of ``self``.
|
|
2189
|
+
|
|
2190
|
+
EXAMPLES::
|
|
2191
|
+
|
|
2192
|
+
sage: ComplexField(100)(1,1).arccoth() # needs sage.libs.pari
|
|
2193
|
+
0.40235947810852509365018983331 - 0.55357435889704525150853273009*I
|
|
2194
|
+
"""
|
|
2195
|
+
return (~self).arctanh()
|
|
2196
|
+
|
|
2197
|
+
def csc(self):
|
|
2198
|
+
"""
|
|
2199
|
+
Return the cosecant of ``self``.
|
|
2200
|
+
|
|
2201
|
+
EXAMPLES::
|
|
2202
|
+
|
|
2203
|
+
sage: ComplexField(100)(1,1).csc() # needs sage.libs.pari
|
|
2204
|
+
0.62151801717042842123490780586 - 0.30393100162842645033448560451*I
|
|
2205
|
+
"""
|
|
2206
|
+
return ~(self.sin())
|
|
2207
|
+
|
|
2208
|
+
def csch(self):
|
|
2209
|
+
"""
|
|
2210
|
+
Return the hyperbolic cosecant of ``self``.
|
|
2211
|
+
|
|
2212
|
+
EXAMPLES::
|
|
2213
|
+
|
|
2214
|
+
sage: ComplexField(100)(1,1).csch() # needs sage.libs.pari
|
|
2215
|
+
0.30393100162842645033448560451 - 0.62151801717042842123490780586*I
|
|
2216
|
+
"""
|
|
2217
|
+
return ~(self.sinh())
|
|
2218
|
+
|
|
2219
|
+
def arccsch(self):
|
|
2220
|
+
"""
|
|
2221
|
+
Return the hyperbolic arccosecant of ``self``.
|
|
2222
|
+
|
|
2223
|
+
EXAMPLES::
|
|
2224
|
+
|
|
2225
|
+
sage: ComplexField(100)(1,1).arccsch() # needs sage.libs.pari
|
|
2226
|
+
0.53063753095251782601650945811 - 0.45227844715119068206365839783*I
|
|
2227
|
+
"""
|
|
2228
|
+
return (~self).arcsinh()
|
|
2229
|
+
|
|
2230
|
+
def sec(self):
|
|
2231
|
+
"""
|
|
2232
|
+
Return the secant of ``self``.
|
|
2233
|
+
|
|
2234
|
+
EXAMPLES::
|
|
2235
|
+
|
|
2236
|
+
sage: ComplexField(100)(1,1).sec() # needs sage.libs.pari
|
|
2237
|
+
0.49833703055518678521380589177 + 0.59108384172104504805039169297*I
|
|
2238
|
+
"""
|
|
2239
|
+
return ~(self.cos())
|
|
2240
|
+
|
|
2241
|
+
def sech(self):
|
|
2242
|
+
"""
|
|
2243
|
+
Return the hyperbolic secant of ``self``.
|
|
2244
|
+
|
|
2245
|
+
EXAMPLES::
|
|
2246
|
+
|
|
2247
|
+
sage: ComplexField(100)(1,1).sech() # needs sage.libs.pari
|
|
2248
|
+
0.49833703055518678521380589177 - 0.59108384172104504805039169297*I
|
|
2249
|
+
"""
|
|
2250
|
+
return ~(self.cosh())
|
|
2251
|
+
|
|
2252
|
+
def arcsech(self):
|
|
2253
|
+
"""
|
|
2254
|
+
Return the hyperbolic arcsecant of ``self``.
|
|
2255
|
+
|
|
2256
|
+
EXAMPLES::
|
|
2257
|
+
|
|
2258
|
+
sage: ComplexField(100)(1,1).arcsech() # needs sage.libs.pari
|
|
2259
|
+
0.53063753095251782601650945811 - 1.1185178796437059371676632938*I
|
|
2260
|
+
"""
|
|
2261
|
+
return (~self).arccosh()
|
|
2262
|
+
|
|
2263
|
+
def cot(self):
|
|
2264
|
+
"""
|
|
2265
|
+
Return the cotangent of ``self``.
|
|
2266
|
+
|
|
2267
|
+
EXAMPLES::
|
|
2268
|
+
|
|
2269
|
+
sage: # needs sage.libs.pari
|
|
2270
|
+
sage: (1+CC(I)).cot() # needs sage.symbolic
|
|
2271
|
+
0.217621561854403 - 0.868014142895925*I
|
|
2272
|
+
sage: i = ComplexField(200).0
|
|
2273
|
+
sage: (1+i).cot()
|
|
2274
|
+
0.21762156185440268136513424360523807352075436916785404091068 - 0.86801414289592494863584920891627388827343874994609327121115*I
|
|
2275
|
+
sage: i = ComplexField(220).0
|
|
2276
|
+
sage: (1+i).cot()
|
|
2277
|
+
0.21762156185440268136513424360523807352075436916785404091068124239 - 0.86801414289592494863584920891627388827343874994609327121115071646*I
|
|
2278
|
+
|
|
2279
|
+
TESTS:
|
|
2280
|
+
|
|
2281
|
+
Verify that :issue:`29409` is fixed::
|
|
2282
|
+
|
|
2283
|
+
sage: cot(1 + I).n() # needs sage.symbolic
|
|
2284
|
+
0.217621561854403 - 0.868014142895925*I
|
|
2285
|
+
"""
|
|
2286
|
+
return ~(self.tan())
|
|
2287
|
+
|
|
2288
|
+
def cos(self):
|
|
2289
|
+
"""
|
|
2290
|
+
Return the cosine of ``self``.
|
|
2291
|
+
|
|
2292
|
+
EXAMPLES::
|
|
2293
|
+
|
|
2294
|
+
sage: (1+CC(I)).cos() # needs sage.symbolic
|
|
2295
|
+
0.833730025131149 - 0.988897705762865*I
|
|
2296
|
+
"""
|
|
2297
|
+
# write self = a + i*b, then
|
|
2298
|
+
# cos(self) = cosh(b)*cos(a) - i*sinh(b)*sin(a)
|
|
2299
|
+
cdef ComplexNumber z
|
|
2300
|
+
z = self._new()
|
|
2301
|
+
cdef mpfr_t ch, sh
|
|
2302
|
+
mpfr_init2(sh, self._prec)
|
|
2303
|
+
mpfr_sinh(sh, self.__im, rnd)
|
|
2304
|
+
mpfr_init2(ch, self._prec)
|
|
2305
|
+
mpfr_sqr(ch, sh, rnd)
|
|
2306
|
+
mpfr_add_ui(ch, ch, 1, rnd)
|
|
2307
|
+
mpfr_sqrt(ch, ch, rnd)
|
|
2308
|
+
mpfr_neg(sh, sh, rnd)
|
|
2309
|
+
mpfr_sin_cos(z.__im, z.__re, self.__re, rnd)
|
|
2310
|
+
mpfr_mul(z.__re, z.__re, ch, rnd)
|
|
2311
|
+
mpfr_mul(z.__im, z.__im, sh, rnd)
|
|
2312
|
+
mpfr_clear(sh)
|
|
2313
|
+
mpfr_clear(ch)
|
|
2314
|
+
return z
|
|
2315
|
+
|
|
2316
|
+
def cosh(self):
|
|
2317
|
+
"""
|
|
2318
|
+
Return the hyperbolic cosine of ``self``.
|
|
2319
|
+
|
|
2320
|
+
EXAMPLES::
|
|
2321
|
+
|
|
2322
|
+
sage: (1+CC(I)).cosh() # needs sage.symbolic
|
|
2323
|
+
0.833730025131149 + 0.988897705762865*I
|
|
2324
|
+
"""
|
|
2325
|
+
# write self = a + i*b, then
|
|
2326
|
+
# cosh(self) = cosh(a)*cos(b) + i*sinh(a)*sin(b)
|
|
2327
|
+
cdef ComplexNumber z
|
|
2328
|
+
z = self._new()
|
|
2329
|
+
cdef mpfr_t ch, sh
|
|
2330
|
+
mpfr_init2(sh, self._prec)
|
|
2331
|
+
mpfr_sinh(sh, self.__re, rnd)
|
|
2332
|
+
mpfr_init2(ch, self._prec)
|
|
2333
|
+
mpfr_sqr(ch, sh, rnd)
|
|
2334
|
+
mpfr_add_ui(ch, ch, 1, rnd)
|
|
2335
|
+
mpfr_sqrt(ch, ch, rnd)
|
|
2336
|
+
mpfr_sin_cos(z.__im, z.__re, self.__im, rnd)
|
|
2337
|
+
mpfr_mul(z.__re, z.__re, ch, rnd)
|
|
2338
|
+
mpfr_mul(z.__im, z.__im, sh, rnd)
|
|
2339
|
+
mpfr_clear(sh)
|
|
2340
|
+
mpfr_clear(ch)
|
|
2341
|
+
return z
|
|
2342
|
+
|
|
2343
|
+
def eta(self, omit_frac=False):
|
|
2344
|
+
r"""
|
|
2345
|
+
Return the value of the Dedekind `\eta` function on ``self``,
|
|
2346
|
+
intelligently computed using `\mathbb{SL}(2,\ZZ)`
|
|
2347
|
+
transformations.
|
|
2348
|
+
|
|
2349
|
+
The `\eta` function is
|
|
2350
|
+
|
|
2351
|
+
.. MATH::
|
|
2352
|
+
|
|
2353
|
+
\eta(z) = e^{\pi i z / 12} \prod_{n=1}^{\infty}(1-e^{2\pi inz})
|
|
2354
|
+
|
|
2355
|
+
INPUT:
|
|
2356
|
+
|
|
2357
|
+
- ``self`` -- element of the upper half plane (if not,
|
|
2358
|
+
raises a :exc:`ValueError`)
|
|
2359
|
+
|
|
2360
|
+
- ``omit_frac`` -- -- boolean (default: ``False``); if ``True``,
|
|
2361
|
+
omit the `e^{\pi i z / 12}` factor
|
|
2362
|
+
|
|
2363
|
+
OUTPUT: a complex number
|
|
2364
|
+
|
|
2365
|
+
ALGORITHM: Uses the PARI C library.
|
|
2366
|
+
|
|
2367
|
+
EXAMPLES:
|
|
2368
|
+
|
|
2369
|
+
First we compute `\eta(1+i)`::
|
|
2370
|
+
|
|
2371
|
+
sage: i = CC.0
|
|
2372
|
+
sage: z = 1 + i; z.eta() # needs sage.libs.pari
|
|
2373
|
+
0.742048775836565 + 0.198831370229911*I
|
|
2374
|
+
|
|
2375
|
+
We compute eta to low precision directly from the definition::
|
|
2376
|
+
|
|
2377
|
+
sage: pi = CC(pi) # otherwise we will get a symbolic result. # needs sage.symbolic
|
|
2378
|
+
sage: exp(pi * i * z / 12) * prod(1 - exp(2*pi*i*n*z) # needs sage.libs.pari sage.symbolic
|
|
2379
|
+
....: for n in range(1,10))
|
|
2380
|
+
0.742048775836565 + 0.198831370229911*I
|
|
2381
|
+
|
|
2382
|
+
The optional argument allows us to omit the fractional part::
|
|
2383
|
+
|
|
2384
|
+
sage: z.eta(omit_frac=True) # needs sage.libs.pari
|
|
2385
|
+
0.998129069925959
|
|
2386
|
+
sage: prod(1 - exp(2*pi*i*n*z) for n in range(1,10)) # needs sage.libs.pari sage.symbolic
|
|
2387
|
+
0.998129069925958 + 4.59099857829247e-19*I
|
|
2388
|
+
|
|
2389
|
+
We illustrate what happens when `z` is not in the upper
|
|
2390
|
+
half plane::
|
|
2391
|
+
|
|
2392
|
+
sage: z = CC(1)
|
|
2393
|
+
sage: z.eta() # needs sage.libs.pari
|
|
2394
|
+
Traceback (most recent call last):
|
|
2395
|
+
...
|
|
2396
|
+
ValueError: value must be in the upper half plane
|
|
2397
|
+
|
|
2398
|
+
You can also use functional notation::
|
|
2399
|
+
|
|
2400
|
+
sage: eta(1 + CC(I)) # needs sage.libs.pari sage.symbolic
|
|
2401
|
+
0.742048775836565 + 0.198831370229911*I
|
|
2402
|
+
"""
|
|
2403
|
+
try:
|
|
2404
|
+
return self._parent(self.__pari__().eta(not omit_frac))
|
|
2405
|
+
except PariError:
|
|
2406
|
+
raise ValueError("value must be in the upper half plane")
|
|
2407
|
+
|
|
2408
|
+
def sin(self):
|
|
2409
|
+
"""
|
|
2410
|
+
Return the sine of ``self``.
|
|
2411
|
+
|
|
2412
|
+
EXAMPLES::
|
|
2413
|
+
|
|
2414
|
+
sage: (1+CC(I)).sin() # needs sage.symbolic
|
|
2415
|
+
1.29845758141598 + 0.634963914784736*I
|
|
2416
|
+
"""
|
|
2417
|
+
# write self = a + i*b, then
|
|
2418
|
+
# sin(self) = cosh(b)*sin(a) + i*sinh(b)*cos(a)
|
|
2419
|
+
cdef ComplexNumber z
|
|
2420
|
+
z = self._new()
|
|
2421
|
+
cdef mpfr_t ch, sh
|
|
2422
|
+
mpfr_init2(sh, self._prec)
|
|
2423
|
+
mpfr_sinh(sh, self.__im, rnd)
|
|
2424
|
+
mpfr_init2(ch, self._prec)
|
|
2425
|
+
mpfr_sqr(ch, sh, rnd)
|
|
2426
|
+
mpfr_add_ui(ch, ch, 1, rnd)
|
|
2427
|
+
mpfr_sqrt(ch, ch, rnd)
|
|
2428
|
+
mpfr_sin_cos(z.__re, z.__im, self.__re, rnd)
|
|
2429
|
+
mpfr_mul(z.__re, z.__re, ch, rnd)
|
|
2430
|
+
mpfr_mul(z.__im, z.__im, sh, rnd)
|
|
2431
|
+
mpfr_clear(sh)
|
|
2432
|
+
mpfr_clear(ch)
|
|
2433
|
+
return z
|
|
2434
|
+
|
|
2435
|
+
def sinh(self):
|
|
2436
|
+
"""
|
|
2437
|
+
Return the hyperbolic sine of ``self``.
|
|
2438
|
+
|
|
2439
|
+
EXAMPLES::
|
|
2440
|
+
|
|
2441
|
+
sage: (1+CC(I)).sinh() # needs sage.symbolic
|
|
2442
|
+
0.634963914784736 + 1.29845758141598*I
|
|
2443
|
+
"""
|
|
2444
|
+
# write self = a + i*b, then
|
|
2445
|
+
# sinh(self) = sinh(a)*cos(b) + i*cosh(a)*sin(b)
|
|
2446
|
+
cdef ComplexNumber z
|
|
2447
|
+
z = self._new()
|
|
2448
|
+
cdef mpfr_t ch, sh
|
|
2449
|
+
mpfr_init2(sh, self._prec)
|
|
2450
|
+
mpfr_sinh(sh, self.__re, rnd)
|
|
2451
|
+
mpfr_init2(ch, self._prec)
|
|
2452
|
+
mpfr_sqr(ch, sh, rnd)
|
|
2453
|
+
mpfr_add_ui(ch, ch, 1, rnd)
|
|
2454
|
+
mpfr_sqrt(ch, ch, rnd)
|
|
2455
|
+
mpfr_sin_cos(z.__im, z.__re, self.__im, rnd)
|
|
2456
|
+
mpfr_mul(z.__re, z.__re, sh, rnd)
|
|
2457
|
+
mpfr_mul(z.__im, z.__im, ch, rnd)
|
|
2458
|
+
mpfr_clear(sh)
|
|
2459
|
+
mpfr_clear(ch)
|
|
2460
|
+
return z
|
|
2461
|
+
|
|
2462
|
+
def tan(self):
|
|
2463
|
+
"""
|
|
2464
|
+
Return the tangent of ``self``.
|
|
2465
|
+
|
|
2466
|
+
EXAMPLES::
|
|
2467
|
+
|
|
2468
|
+
sage: (1+CC(I)).tan() # needs sage.symbolic
|
|
2469
|
+
0.271752585319512 + 1.08392332733869*I
|
|
2470
|
+
"""
|
|
2471
|
+
# write self = a + i*b, then
|
|
2472
|
+
# tan(self) = [cos(a)*sin(a) + i*cosh(b)*sinh(b)]/[sinh^2(b)+cos^2(a)]
|
|
2473
|
+
cdef ComplexNumber z
|
|
2474
|
+
z = self._new()
|
|
2475
|
+
cdef mpfr_t ch, sh, c, s, a, b
|
|
2476
|
+
mpfr_init2(sh, self._prec)
|
|
2477
|
+
mpfr_sinh(sh, self.__im, rnd)
|
|
2478
|
+
mpfr_init2(ch, self._prec)
|
|
2479
|
+
mpfr_init2(a, self._prec)
|
|
2480
|
+
mpfr_sqr(a, sh, rnd)
|
|
2481
|
+
mpfr_add_ui(ch, a, 1, rnd)
|
|
2482
|
+
mpfr_sqrt(ch, ch, rnd)
|
|
2483
|
+
mpfr_init2(c, self._prec)
|
|
2484
|
+
mpfr_init2(s, self._prec)
|
|
2485
|
+
mpfr_sin_cos(s, c, self.__re, rnd)
|
|
2486
|
+
mpfr_init2(b, self._prec)
|
|
2487
|
+
mpfr_sqr(b, c, rnd)
|
|
2488
|
+
mpfr_add(a, a, b, rnd)
|
|
2489
|
+
mpfr_mul(z.__re, c, s, rnd)
|
|
2490
|
+
mpfr_div(z.__re, z.__re, a, rnd)
|
|
2491
|
+
mpfr_mul(z.__im, ch, sh, rnd)
|
|
2492
|
+
mpfr_div(z.__im, z.__im, a, rnd)
|
|
2493
|
+
mpfr_clear(sh)
|
|
2494
|
+
mpfr_clear(ch)
|
|
2495
|
+
mpfr_clear(c)
|
|
2496
|
+
mpfr_clear(s)
|
|
2497
|
+
mpfr_clear(b)
|
|
2498
|
+
mpfr_clear(a)
|
|
2499
|
+
return z
|
|
2500
|
+
|
|
2501
|
+
def tanh(self):
|
|
2502
|
+
"""
|
|
2503
|
+
Return the hyperbolic tangent of ``self``.
|
|
2504
|
+
|
|
2505
|
+
EXAMPLES::
|
|
2506
|
+
|
|
2507
|
+
sage: (1+CC(I)).tanh() # needs sage.symbolic
|
|
2508
|
+
1.08392332733869 + 0.271752585319512*I
|
|
2509
|
+
"""
|
|
2510
|
+
# write self = a + i*b, then
|
|
2511
|
+
# tanh(self) = [cosh(a)*sinh(a) + i*cos(b)*sin(b)]/[sinh^2(a)+cos^2(b)]
|
|
2512
|
+
cdef ComplexNumber z
|
|
2513
|
+
z = self._new()
|
|
2514
|
+
cdef mpfr_t ch, sh, c, s, a, b
|
|
2515
|
+
mpfr_init2(sh, self._prec)
|
|
2516
|
+
mpfr_sinh(sh, self.__re, rnd)
|
|
2517
|
+
mpfr_init2(ch, self._prec)
|
|
2518
|
+
mpfr_init2(a, self._prec)
|
|
2519
|
+
mpfr_sqr(a, sh, rnd)
|
|
2520
|
+
mpfr_add_ui(ch, a, 1, rnd)
|
|
2521
|
+
mpfr_sqrt(ch, ch, rnd)
|
|
2522
|
+
mpfr_init2(c, self._prec)
|
|
2523
|
+
mpfr_init2(s, self._prec)
|
|
2524
|
+
mpfr_sin_cos(s, c, self.__im, rnd)
|
|
2525
|
+
mpfr_init2(b, self._prec)
|
|
2526
|
+
mpfr_sqr(b, c, rnd)
|
|
2527
|
+
mpfr_add(a, a, b, rnd)
|
|
2528
|
+
mpfr_mul(z.__im, c, s, rnd)
|
|
2529
|
+
mpfr_div(z.__im, z.__im, a, rnd)
|
|
2530
|
+
mpfr_mul(z.__re, ch, sh, rnd)
|
|
2531
|
+
mpfr_div(z.__re, z.__re, a, rnd)
|
|
2532
|
+
mpfr_clear(sh)
|
|
2533
|
+
mpfr_clear(ch)
|
|
2534
|
+
mpfr_clear(c)
|
|
2535
|
+
mpfr_clear(s)
|
|
2536
|
+
mpfr_clear(b)
|
|
2537
|
+
mpfr_clear(a)
|
|
2538
|
+
return z
|
|
2539
|
+
|
|
2540
|
+
# Other special functions
|
|
2541
|
+
def agm(self, right, algorithm='optimal'):
|
|
2542
|
+
r"""
|
|
2543
|
+
Return the Arithmetic-Geometric Mean (AGM) of ``self`` and ``right``.
|
|
2544
|
+
|
|
2545
|
+
INPUT:
|
|
2546
|
+
|
|
2547
|
+
- ``right`` -- complex; another complex number
|
|
2548
|
+
|
|
2549
|
+
- ``algorithm`` -- string (default: ``'optimal'``); the algorithm to use
|
|
2550
|
+
(see below)
|
|
2551
|
+
|
|
2552
|
+
OUTPUT:
|
|
2553
|
+
|
|
2554
|
+
(complex) A value of the AGM of ``self`` and ``right``. Note that
|
|
2555
|
+
this is a multi-valued function, and the algorithm used
|
|
2556
|
+
affects the value returned, as follows:
|
|
2557
|
+
|
|
2558
|
+
- ``'pari'``: Call the :pari:`agm` function from the PARI library.
|
|
2559
|
+
|
|
2560
|
+
- ``'optimal'``: Use the AGM sequence such that at each stage
|
|
2561
|
+
`(a,b)` is replaced by `(a_1,b_1)=((a+b)/2,\pm\sqrt{ab})`
|
|
2562
|
+
where the sign is chosen so that `|a_1-b_1|\le|a_1+b_1|`, or
|
|
2563
|
+
equivalently `\Re(b_1/a_1)\ge 0`. The resulting limit is
|
|
2564
|
+
maximal among all possible values.
|
|
2565
|
+
|
|
2566
|
+
- ``'principal'``: Use the AGM sequence such that at each stage
|
|
2567
|
+
`(a,b)` is replaced by `(a_1,b_1)=((a+b)/2,\pm\sqrt{ab})`
|
|
2568
|
+
where the sign is chosen so that `\Re(b_1)\ge 0` (the
|
|
2569
|
+
so-called principal branch of the square root).
|
|
2570
|
+
|
|
2571
|
+
The values `AGM(a,0)`, `AGM(0,a)`, and `AGM(a,-a)` are all taken to be 0.
|
|
2572
|
+
|
|
2573
|
+
EXAMPLES::
|
|
2574
|
+
|
|
2575
|
+
sage: a = CC(1,1)
|
|
2576
|
+
sage: b = CC(2,-1)
|
|
2577
|
+
sage: a.agm(b)
|
|
2578
|
+
1.62780548487271 + 0.136827548397369*I
|
|
2579
|
+
sage: a.agm(b, algorithm='optimal')
|
|
2580
|
+
1.62780548487271 + 0.136827548397369*I
|
|
2581
|
+
sage: a.agm(b, algorithm='principal')
|
|
2582
|
+
1.62780548487271 + 0.136827548397369*I
|
|
2583
|
+
sage: a.agm(b, algorithm='pari') # needs sage.libs.pari
|
|
2584
|
+
1.62780548487271 + 0.136827548397369*I
|
|
2585
|
+
|
|
2586
|
+
An example to show that the returned value depends on the algorithm
|
|
2587
|
+
parameter::
|
|
2588
|
+
|
|
2589
|
+
sage: a = CC(-0.95,-0.65)
|
|
2590
|
+
sage: b = CC(0.683,0.747)
|
|
2591
|
+
sage: a.agm(b, algorithm='optimal')
|
|
2592
|
+
-0.371591652351761 + 0.319894660206830*I
|
|
2593
|
+
sage: a.agm(b, algorithm='principal')
|
|
2594
|
+
0.338175462986180 - 0.0135326969565405*I
|
|
2595
|
+
sage: a.agm(b, algorithm='pari') # needs sage.libs.pari
|
|
2596
|
+
-0.371591652351761 + 0.319894660206830*I
|
|
2597
|
+
sage: a.agm(b, algorithm='optimal').abs()
|
|
2598
|
+
0.490319232466314
|
|
2599
|
+
sage: a.agm(b, algorithm='principal').abs()
|
|
2600
|
+
0.338446122230459
|
|
2601
|
+
sage: a.agm(b, algorithm='pari').abs() # needs sage.libs.pari
|
|
2602
|
+
0.490319232466314
|
|
2603
|
+
|
|
2604
|
+
TESTS:
|
|
2605
|
+
|
|
2606
|
+
An example which came up in testing::
|
|
2607
|
+
|
|
2608
|
+
sage: # needs sage.symbolic
|
|
2609
|
+
sage: I = CC(I)
|
|
2610
|
+
sage: a = 0.501648970493109 + 1.11877240294744*I
|
|
2611
|
+
sage: b = 1.05946309435930 + 1.05946309435930*I
|
|
2612
|
+
sage: a.agm(b)
|
|
2613
|
+
0.774901870587681 + 1.10254945079875*I
|
|
2614
|
+
|
|
2615
|
+
sage: a = CC(-0.32599972608379413, 0.60395514542928641)
|
|
2616
|
+
sage: b = CC( 0.6062314525690593, 0.1425693337776659)
|
|
2617
|
+
sage: a.agm(b)
|
|
2618
|
+
0.199246281325876 + 0.478401702759654*I
|
|
2619
|
+
sage: a.agm(-a)
|
|
2620
|
+
0.000000000000000
|
|
2621
|
+
sage: a.agm(0)
|
|
2622
|
+
0.000000000000000
|
|
2623
|
+
sage: CC(0).agm(a)
|
|
2624
|
+
0.000000000000000
|
|
2625
|
+
|
|
2626
|
+
Consistency::
|
|
2627
|
+
|
|
2628
|
+
sage: # needs sage.symbolic
|
|
2629
|
+
sage: a = 1 + 0.5*I
|
|
2630
|
+
sage: b = 2 - 0.25*I
|
|
2631
|
+
sage: a.agm(b) - ComplexField(100)(a).agm(b)
|
|
2632
|
+
0.000000000000000
|
|
2633
|
+
sage: ComplexField(200)(a).agm(b) - ComplexField(500)(a).agm(b)
|
|
2634
|
+
0.00000000000000000000000000000000000000000000000000000000000
|
|
2635
|
+
sage: ComplexField(500)(a).agm(b) - ComplexField(1000)(a).agm(b)
|
|
2636
|
+
0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
2637
|
+
"""
|
|
2638
|
+
if algorithm=="pari":
|
|
2639
|
+
t = self._parent(right).__pari__()
|
|
2640
|
+
return self._parent(self.__pari__().agm(t))
|
|
2641
|
+
|
|
2642
|
+
cdef ComplexNumber a, b, a1, b1, d, e, res
|
|
2643
|
+
cdef mp_exp_t rel_prec
|
|
2644
|
+
cdef bint optimal = algorithm == "optimal"
|
|
2645
|
+
|
|
2646
|
+
if optimal or algorithm == "principal":
|
|
2647
|
+
|
|
2648
|
+
if not isinstance(right, ComplexNumber) or (<ComplexNumber>right)._parent is not self._parent:
|
|
2649
|
+
right = self._parent(right)
|
|
2650
|
+
|
|
2651
|
+
res = self._new()
|
|
2652
|
+
|
|
2653
|
+
if mpfr_zero_p(self.__re) and mpfr_zero_p(self.__im):
|
|
2654
|
+
return self
|
|
2655
|
+
elif mpfr_zero_p((<ComplexNumber>right).__re) and mpfr_zero_p((<ComplexNumber>right).__im):
|
|
2656
|
+
return right
|
|
2657
|
+
elif (mpfr_cmpabs(self.__re, (<ComplexNumber>right).__re) == 0 and
|
|
2658
|
+
mpfr_cmpabs(self.__im, (<ComplexNumber>right).__im) == 0 and
|
|
2659
|
+
mpfr_cmp(self.__re, (<ComplexNumber>right).__re) != 0 and
|
|
2660
|
+
mpfr_cmp(self.__im, (<ComplexNumber>right).__im) != 0):
|
|
2661
|
+
# self = -right
|
|
2662
|
+
mpfr_set_ui(res.__re, 0, rnd)
|
|
2663
|
+
mpfr_set_ui(res.__im, 0, rnd)
|
|
2664
|
+
return res
|
|
2665
|
+
|
|
2666
|
+
# Do the computations to a bit higher precision so rounding error
|
|
2667
|
+
# won't obscure the termination condition.
|
|
2668
|
+
a = ComplexNumber(self._parent.to_prec(self._prec+5), None)
|
|
2669
|
+
b = a._new()
|
|
2670
|
+
a1 = a._new()
|
|
2671
|
+
b1 = a._new()
|
|
2672
|
+
|
|
2673
|
+
d = a._new()
|
|
2674
|
+
if optimal:
|
|
2675
|
+
e = a._new()
|
|
2676
|
+
|
|
2677
|
+
# Make copies so we don't mutate self or right.
|
|
2678
|
+
mpfr_set(a.__re, self.__re, rnd)
|
|
2679
|
+
mpfr_set(a.__im, self.__im, rnd)
|
|
2680
|
+
mpfr_set(b.__re, (<ComplexNumber>right).__re, rnd)
|
|
2681
|
+
mpfr_set(b.__im, (<ComplexNumber>right).__im, rnd)
|
|
2682
|
+
|
|
2683
|
+
if optimal:
|
|
2684
|
+
mpfr_add(e.__re, a.__re, b.__re, rnd)
|
|
2685
|
+
mpfr_add(e.__im, a.__im, b.__im, rnd)
|
|
2686
|
+
|
|
2687
|
+
while True:
|
|
2688
|
+
|
|
2689
|
+
# a1 = (a+b)/2
|
|
2690
|
+
if optimal:
|
|
2691
|
+
mpfr_swap(a1.__re, e.__re)
|
|
2692
|
+
mpfr_swap(a1.__im, e.__im)
|
|
2693
|
+
else:
|
|
2694
|
+
mpfr_add(a1.__re, a.__re, b.__re, rnd)
|
|
2695
|
+
mpfr_add(a1.__im, a.__im, b.__im, rnd)
|
|
2696
|
+
mpfr_mul_2si(a1.__re, a1.__re, -1, rnd)
|
|
2697
|
+
mpfr_mul_2si(a1.__im, a1.__im, -1, rnd)
|
|
2698
|
+
|
|
2699
|
+
# b1 = sqrt(a*b)
|
|
2700
|
+
mpfr_mul(d.__re, a.__re, b.__re, rnd)
|
|
2701
|
+
mpfr_mul(d.__im, a.__im, b.__im, rnd)
|
|
2702
|
+
mpfr_sub(b1.__re, d.__re, d.__im, rnd)
|
|
2703
|
+
mpfr_mul(d.__re, a.__re, b.__im, rnd)
|
|
2704
|
+
mpfr_mul(d.__im, a.__im, b.__re, rnd)
|
|
2705
|
+
mpfr_add(b1.__im, d.__re, d.__im, rnd)
|
|
2706
|
+
b1 = b1.sqrt() # this would be a *lot* of code duplication
|
|
2707
|
+
|
|
2708
|
+
# d = a1 - b1
|
|
2709
|
+
mpfr_sub(d.__re, a1.__re, b1.__re, rnd)
|
|
2710
|
+
mpfr_sub(d.__im, a1.__im, b1.__im, rnd)
|
|
2711
|
+
if mpfr_zero_p(d.__re) and mpfr_zero_p(d.__im):
|
|
2712
|
+
mpfr_set(res.__re, a1.__re, rnd)
|
|
2713
|
+
mpfr_set(res.__im, a1.__im, rnd)
|
|
2714
|
+
return res
|
|
2715
|
+
|
|
2716
|
+
if optimal:
|
|
2717
|
+
# e = a1+b1
|
|
2718
|
+
mpfr_add(e.__re, a1.__re, b1.__re, rnd)
|
|
2719
|
+
mpfr_add(e.__im, a1.__im, b1.__im, rnd)
|
|
2720
|
+
if mpfr_zero_p(e.__re) and mpfr_zero_p(e.__im):
|
|
2721
|
+
mpfr_set(res.__re, a1.__re, rnd)
|
|
2722
|
+
mpfr_set(res.__im, a1.__im, rnd)
|
|
2723
|
+
return res
|
|
2724
|
+
|
|
2725
|
+
# |e| < |d|
|
|
2726
|
+
if cmp_abs(e, d) < 0:
|
|
2727
|
+
mpfr_swap(d.__re, e.__re)
|
|
2728
|
+
mpfr_swap(d.__im, e.__im)
|
|
2729
|
+
mpfr_neg(b1.__re, b1.__re, rnd)
|
|
2730
|
+
mpfr_neg(b1.__im, b1.__im, rnd)
|
|
2731
|
+
|
|
2732
|
+
rel_prec = min_exp_t(max_exp(a1), max_exp(b1)) - max_exp(d)
|
|
2733
|
+
if rel_prec > self._prec:
|
|
2734
|
+
mpfr_set(res.__re, a1.__re, rnd)
|
|
2735
|
+
mpfr_set(res.__im, a1.__im, rnd)
|
|
2736
|
+
return res
|
|
2737
|
+
|
|
2738
|
+
# a, b = a1, b1
|
|
2739
|
+
mpfr_swap(a.__re, a1.__re)
|
|
2740
|
+
mpfr_swap(a.__im, a1.__im)
|
|
2741
|
+
mpfr_swap(b.__re, b1.__re)
|
|
2742
|
+
mpfr_swap(b.__im, b1.__im)
|
|
2743
|
+
|
|
2744
|
+
raise ValueError("agm algorithm must be one of 'pari', 'optimal', 'principal'")
|
|
2745
|
+
|
|
2746
|
+
def argument(self):
|
|
2747
|
+
r"""
|
|
2748
|
+
The argument (angle) of the complex number, normalized so that
|
|
2749
|
+
`-\pi < \theta \leq \pi`.
|
|
2750
|
+
|
|
2751
|
+
EXAMPLES::
|
|
2752
|
+
|
|
2753
|
+
sage: i = CC.0
|
|
2754
|
+
sage: (i^2).argument()
|
|
2755
|
+
3.14159265358979
|
|
2756
|
+
sage: (1+i).argument()
|
|
2757
|
+
0.785398163397448
|
|
2758
|
+
sage: i.argument()
|
|
2759
|
+
1.57079632679490
|
|
2760
|
+
sage: (-i).argument()
|
|
2761
|
+
-1.57079632679490
|
|
2762
|
+
sage: (RR('-0.001') - i).argument()
|
|
2763
|
+
-1.57179632646156
|
|
2764
|
+
"""
|
|
2765
|
+
cdef RealNumber x
|
|
2766
|
+
x = RealNumber(self._parent._real_field(), None)
|
|
2767
|
+
mpfr_atan2(x.value, self.__im, self.__re, rnd)
|
|
2768
|
+
return x
|
|
2769
|
+
|
|
2770
|
+
def arg(self):
|
|
2771
|
+
"""
|
|
2772
|
+
See :meth:`argument`.
|
|
2773
|
+
|
|
2774
|
+
EXAMPLES::
|
|
2775
|
+
|
|
2776
|
+
sage: i = CC.0
|
|
2777
|
+
sage: (i^2).arg()
|
|
2778
|
+
3.14159265358979
|
|
2779
|
+
"""
|
|
2780
|
+
return self.argument()
|
|
2781
|
+
|
|
2782
|
+
def conjugate(self):
|
|
2783
|
+
"""
|
|
2784
|
+
Return the complex conjugate of this complex number.
|
|
2785
|
+
|
|
2786
|
+
EXAMPLES::
|
|
2787
|
+
|
|
2788
|
+
sage: i = CC.0
|
|
2789
|
+
sage: (1+i).conjugate()
|
|
2790
|
+
1.00000000000000 - 1.00000000000000*I
|
|
2791
|
+
"""
|
|
2792
|
+
cdef ComplexNumber x
|
|
2793
|
+
x = self._new()
|
|
2794
|
+
|
|
2795
|
+
cdef mpfr_t i
|
|
2796
|
+
mpfr_init2(i, self._prec)
|
|
2797
|
+
mpfr_neg(i, self.__im, rnd)
|
|
2798
|
+
mpfr_set(x.__re, self.__re, rnd)
|
|
2799
|
+
mpfr_set(x.__im, i, rnd)
|
|
2800
|
+
mpfr_clear(i)
|
|
2801
|
+
return x
|
|
2802
|
+
|
|
2803
|
+
def dilog(self):
|
|
2804
|
+
r"""
|
|
2805
|
+
Return the complex dilogarithm of ``self``.
|
|
2806
|
+
|
|
2807
|
+
The complex dilogarithm, or Spence's function, is defined by
|
|
2808
|
+
|
|
2809
|
+
.. MATH::
|
|
2810
|
+
|
|
2811
|
+
Li_2(z) = - \int_0^z \frac{\log|1-\zeta|}{\zeta} d(\zeta)
|
|
2812
|
+
= \sum_{k=1}^\infty \frac{z^k}{k}
|
|
2813
|
+
|
|
2814
|
+
Note that the series definition can only be used for `|z| < 1`.
|
|
2815
|
+
|
|
2816
|
+
EXAMPLES::
|
|
2817
|
+
|
|
2818
|
+
sage: a = ComplexNumber(1,0)
|
|
2819
|
+
sage: a.dilog() # needs sage.libs.pari
|
|
2820
|
+
1.64493406684823
|
|
2821
|
+
sage: float(pi^2/6) # needs sage.symbolic
|
|
2822
|
+
1.6449340668482262
|
|
2823
|
+
|
|
2824
|
+
::
|
|
2825
|
+
|
|
2826
|
+
sage: b = ComplexNumber(0,1)
|
|
2827
|
+
sage: b.dilog() # needs sage.libs.pari
|
|
2828
|
+
-0.205616758356028 + 0.915965594177219*I
|
|
2829
|
+
|
|
2830
|
+
::
|
|
2831
|
+
|
|
2832
|
+
sage: c = ComplexNumber(0,0)
|
|
2833
|
+
sage: c.dilog() # needs sage.libs.pari
|
|
2834
|
+
0.000000000000000
|
|
2835
|
+
"""
|
|
2836
|
+
return self._parent(self.__pari__().dilog())
|
|
2837
|
+
|
|
2838
|
+
def exp(ComplexNumber self):
|
|
2839
|
+
r"""
|
|
2840
|
+
Compute `e^z` or `\exp(z)`.
|
|
2841
|
+
|
|
2842
|
+
EXAMPLES::
|
|
2843
|
+
|
|
2844
|
+
sage: i = ComplexField(300).0
|
|
2845
|
+
sage: z = 1 + i
|
|
2846
|
+
sage: z.exp()
|
|
2847
|
+
1.46869393991588515713896759732660426132695673662900872279767567631093696585951213872272450 + 2.28735528717884239120817190670050180895558625666835568093865811410364716018934540926734485*I
|
|
2848
|
+
"""
|
|
2849
|
+
# write self = a + i*b, then
|
|
2850
|
+
# exp(self) = exp(a)*(cos(b) + i*sin(b))
|
|
2851
|
+
cdef ComplexNumber z
|
|
2852
|
+
z = self._new()
|
|
2853
|
+
cdef mpfr_t r
|
|
2854
|
+
mpfr_init2(r, self._prec)
|
|
2855
|
+
mpfr_exp(r, self.__re, rnd)
|
|
2856
|
+
mpfr_sin_cos(z.__im, z.__re, self.__im, rnd)
|
|
2857
|
+
mpfr_mul(z.__re, z.__re, r, rnd)
|
|
2858
|
+
mpfr_mul(z.__im, z.__im, r, rnd)
|
|
2859
|
+
mpfr_clear(r)
|
|
2860
|
+
return z
|
|
2861
|
+
|
|
2862
|
+
def gamma(self):
|
|
2863
|
+
"""
|
|
2864
|
+
Return the Gamma function evaluated at this complex number.
|
|
2865
|
+
|
|
2866
|
+
EXAMPLES::
|
|
2867
|
+
|
|
2868
|
+
sage: i = ComplexField(30).0
|
|
2869
|
+
sage: (1 + i).gamma() # needs sage.libs.pari
|
|
2870
|
+
0.49801567 - 0.15494983*I
|
|
2871
|
+
|
|
2872
|
+
TESTS::
|
|
2873
|
+
|
|
2874
|
+
sage: CC(0).gamma() # needs sage.libs.pari
|
|
2875
|
+
Infinity
|
|
2876
|
+
|
|
2877
|
+
::
|
|
2878
|
+
|
|
2879
|
+
sage: CC(-1).gamma() # needs sage.libs.pari
|
|
2880
|
+
Infinity
|
|
2881
|
+
"""
|
|
2882
|
+
try:
|
|
2883
|
+
return self._parent(self.__pari__().gamma())
|
|
2884
|
+
except PariError:
|
|
2885
|
+
from sage.rings.infinity import UnsignedInfinityRing
|
|
2886
|
+
return UnsignedInfinityRing.gen()
|
|
2887
|
+
|
|
2888
|
+
def gamma_inc(self, t):
|
|
2889
|
+
"""
|
|
2890
|
+
Return the incomplete Gamma function evaluated at this complex
|
|
2891
|
+
number.
|
|
2892
|
+
|
|
2893
|
+
EXAMPLES::
|
|
2894
|
+
|
|
2895
|
+
sage: # needs sage.libs.pari
|
|
2896
|
+
sage: C, i = ComplexField(30).objgen()
|
|
2897
|
+
sage: (1+i).gamma_inc(2 + 3*i) # abs tol 2e-10
|
|
2898
|
+
0.0020969149 - 0.059981914*I
|
|
2899
|
+
sage: (1+i).gamma_inc(5)
|
|
2900
|
+
-0.0013781309 + 0.0065198200*I
|
|
2901
|
+
sage: C(2).gamma_inc(1 + i)
|
|
2902
|
+
0.70709210 - 0.42035364*I
|
|
2903
|
+
sage: CC(2).gamma_inc(5)
|
|
2904
|
+
0.0404276819945128
|
|
2905
|
+
|
|
2906
|
+
TESTS:
|
|
2907
|
+
|
|
2908
|
+
Check that :issue:`7099` is fixed::
|
|
2909
|
+
|
|
2910
|
+
sage: C = ComplexField(400)
|
|
2911
|
+
sage: C(2 + I).gamma_inc(C(3 + I)) # abs tol 1e-120 # needs sage.libs.pari sage.symbolic
|
|
2912
|
+
0.121515644664508695525971545977439666159749344176962379708992904126499444842886620664991650378432544392118359044438541515 + 0.101533909079826033296475736021224621546966200987295663190553587086145836461236284668967411665020429964946098113930918850*I
|
|
2913
|
+
"""
|
|
2914
|
+
return self._parent(self.__pari__().incgam(t, precision=self.prec()))
|
|
2915
|
+
|
|
2916
|
+
def log(self, base=None):
|
|
2917
|
+
r"""
|
|
2918
|
+
Complex logarithm of `z` with branch chosen as follows: Write
|
|
2919
|
+
`z = \rho e^{i \theta}` with `-\pi < \theta \leq \pi`. Then
|
|
2920
|
+
`\log(z) = \log(\rho) + i \theta`.
|
|
2921
|
+
|
|
2922
|
+
.. WARNING::
|
|
2923
|
+
|
|
2924
|
+
Currently the real log is computed using floats, so there
|
|
2925
|
+
is potential precision loss.
|
|
2926
|
+
|
|
2927
|
+
EXAMPLES::
|
|
2928
|
+
|
|
2929
|
+
sage: a = ComplexNumber(2,1)
|
|
2930
|
+
sage: a.log()
|
|
2931
|
+
0.804718956217050 + 0.463647609000806*I
|
|
2932
|
+
sage: log(a.abs())
|
|
2933
|
+
0.804718956217050
|
|
2934
|
+
sage: a.argument()
|
|
2935
|
+
0.463647609000806
|
|
2936
|
+
|
|
2937
|
+
::
|
|
2938
|
+
|
|
2939
|
+
sage: b = ComplexNumber(float(exp(42)),0) # needs sage.symbolic
|
|
2940
|
+
sage: b.log() # abs tol 1e-12 # needs sage.symbolic
|
|
2941
|
+
41.99999999999971
|
|
2942
|
+
|
|
2943
|
+
::
|
|
2944
|
+
|
|
2945
|
+
sage: c = ComplexNumber(-1,0)
|
|
2946
|
+
sage: c.log()
|
|
2947
|
+
3.14159265358979*I
|
|
2948
|
+
|
|
2949
|
+
The option of a base is included for compatibility with other logs::
|
|
2950
|
+
|
|
2951
|
+
sage: c = ComplexNumber(-1,0)
|
|
2952
|
+
sage: c.log(2)
|
|
2953
|
+
4.53236014182719*I
|
|
2954
|
+
|
|
2955
|
+
If either component (real or imaginary) of the complex number
|
|
2956
|
+
is NaN (not a number), log will return the complex NaN::
|
|
2957
|
+
|
|
2958
|
+
sage: c = ComplexNumber(NaN,2) # needs sage.symbolic
|
|
2959
|
+
sage: c.log() # needs sage.symbolic
|
|
2960
|
+
NaN + NaN*I
|
|
2961
|
+
"""
|
|
2962
|
+
if mpfr_nan_p(self.__re):
|
|
2963
|
+
return ComplexNumber(self._parent,self.real(),self.real())
|
|
2964
|
+
if mpfr_nan_p(self.__im):
|
|
2965
|
+
return ComplexNumber(self._parent,self.imag(),self.imag())
|
|
2966
|
+
theta = self.argument()
|
|
2967
|
+
rho = abs(self)
|
|
2968
|
+
if base is None:
|
|
2969
|
+
return ComplexNumber(self._parent, rho.log(), theta)
|
|
2970
|
+
else:
|
|
2971
|
+
from sage.rings.real_mpfr import RealField
|
|
2972
|
+
return ComplexNumber(self._parent, rho.log()/RealNumber(RealField(self.prec()),base).log(), theta/RealNumber(RealField(self.prec()),base).log())
|
|
2973
|
+
|
|
2974
|
+
def additive_order(self):
|
|
2975
|
+
"""
|
|
2976
|
+
Return the additive order of ``self``.
|
|
2977
|
+
|
|
2978
|
+
EXAMPLES::
|
|
2979
|
+
|
|
2980
|
+
sage: CC(0).additive_order()
|
|
2981
|
+
1
|
|
2982
|
+
sage: CC.gen().additive_order()
|
|
2983
|
+
+Infinity
|
|
2984
|
+
"""
|
|
2985
|
+
if self == 0:
|
|
2986
|
+
return 1
|
|
2987
|
+
else:
|
|
2988
|
+
return infinity.infinity
|
|
2989
|
+
|
|
2990
|
+
def sqrt(self, all=False):
|
|
2991
|
+
"""
|
|
2992
|
+
The square root function, taking the branch cut to be the negative
|
|
2993
|
+
real axis.
|
|
2994
|
+
|
|
2995
|
+
INPUT:
|
|
2996
|
+
|
|
2997
|
+
- ``all`` -- boolean (default: ``False``); if ``True``, return a
|
|
2998
|
+
list of all square roots
|
|
2999
|
+
|
|
3000
|
+
EXAMPLES::
|
|
3001
|
+
|
|
3002
|
+
sage: C.<i> = ComplexField(30)
|
|
3003
|
+
sage: i.sqrt()
|
|
3004
|
+
0.70710678 + 0.70710678*I
|
|
3005
|
+
sage: (1+i).sqrt()
|
|
3006
|
+
1.0986841 + 0.45508986*I
|
|
3007
|
+
sage: (C(-1)).sqrt()
|
|
3008
|
+
1.0000000*I
|
|
3009
|
+
sage: (1 + 1e-100*i).sqrt()^2
|
|
3010
|
+
1.0000000 + 1.0000000e-100*I
|
|
3011
|
+
sage: i = ComplexField(200).0
|
|
3012
|
+
sage: i.sqrt()
|
|
3013
|
+
0.70710678118654752440084436210484903928483593768847403658834 + 0.70710678118654752440084436210484903928483593768847403658834*I
|
|
3014
|
+
"""
|
|
3015
|
+
cdef ComplexNumber z = self._new()
|
|
3016
|
+
if mpfr_zero_p(self.__im):
|
|
3017
|
+
if mpfr_sgn(self.__re) >= 0:
|
|
3018
|
+
mpfr_set_ui(z.__im, 0, rnd)
|
|
3019
|
+
mpfr_sqrt(z.__re, self.__re, rnd)
|
|
3020
|
+
else:
|
|
3021
|
+
mpfr_set_ui(z.__re, 0, rnd)
|
|
3022
|
+
mpfr_neg(z.__im, self.__re, rnd)
|
|
3023
|
+
mpfr_sqrt(z.__im, z.__im, rnd)
|
|
3024
|
+
if all:
|
|
3025
|
+
return [z, -z] if z else [z]
|
|
3026
|
+
else:
|
|
3027
|
+
return z
|
|
3028
|
+
# self = x + yi = (a+bi)^2
|
|
3029
|
+
# expand, substitute, solve
|
|
3030
|
+
# a^2 = (x + sqrt(x^2+y^2))/2
|
|
3031
|
+
cdef bint avoid_branch = mpfr_sgn(self.__re) < 0 and mpfr_cmpabs(self.__im, self.__re) < 0
|
|
3032
|
+
cdef mpfr_t a2
|
|
3033
|
+
mpfr_init2(a2, self._prec)
|
|
3034
|
+
mpfr_hypot(a2, self.__re, self.__im, rnd)
|
|
3035
|
+
if avoid_branch:
|
|
3036
|
+
# x + sqrt(x^2+y^2) numerically unstable for x near negative real axis
|
|
3037
|
+
# so we compute sqrt of (-z) and shift by i at the end
|
|
3038
|
+
mpfr_sub(a2, a2, self.__re, rnd)
|
|
3039
|
+
else:
|
|
3040
|
+
mpfr_add(a2, a2, self.__re, rnd)
|
|
3041
|
+
mpfr_mul_2si(a2, a2, -1, rnd)
|
|
3042
|
+
# a = sqrt(a2)
|
|
3043
|
+
mpfr_sqrt(z.__re, a2, rnd)
|
|
3044
|
+
# b = y/(2a)
|
|
3045
|
+
mpfr_div(z.__im, self.__im, z.__re, rnd)
|
|
3046
|
+
mpfr_mul_2si(z.__im, z.__im, -1, rnd)
|
|
3047
|
+
mpfr_clear(a2)
|
|
3048
|
+
if avoid_branch:
|
|
3049
|
+
mpfr_swap(z.__re, z.__im)
|
|
3050
|
+
# Note that y (hence b) was never negated, so we have z=i*sqrt(self).
|
|
3051
|
+
# if we were below the branch cut, we want the other branch
|
|
3052
|
+
if mpfr_sgn(self.__im) < 0:
|
|
3053
|
+
mpfr_neg(z.__re, z.__re, rnd)
|
|
3054
|
+
mpfr_neg(z.__im, z.__im, rnd)
|
|
3055
|
+
if all:
|
|
3056
|
+
return [z, -z]
|
|
3057
|
+
else:
|
|
3058
|
+
return z
|
|
3059
|
+
|
|
3060
|
+
def nth_root(self, n, all=False):
|
|
3061
|
+
"""
|
|
3062
|
+
The `n`-th root function.
|
|
3063
|
+
|
|
3064
|
+
INPUT:
|
|
3065
|
+
|
|
3066
|
+
- ``all`` -- boolean (default: ``False``); if ``True``, return a
|
|
3067
|
+
list of all `n`-th roots
|
|
3068
|
+
|
|
3069
|
+
EXAMPLES::
|
|
3070
|
+
|
|
3071
|
+
sage: a = CC(27)
|
|
3072
|
+
sage: a.nth_root(3)
|
|
3073
|
+
3.00000000000000
|
|
3074
|
+
sage: a.nth_root(3, all=True)
|
|
3075
|
+
[3.00000000000000,
|
|
3076
|
+
-1.50000000000000 + 2.59807621135332*I,
|
|
3077
|
+
-1.50000000000000 - 2.59807621135332*I]
|
|
3078
|
+
sage: a = ComplexField(20)(2,1)
|
|
3079
|
+
sage: [r^7 for r in a.nth_root(7, all=True)]
|
|
3080
|
+
[2.0000 + 1.0000*I, 2.0000 + 1.0000*I, 2.0000 + 1.0000*I, 2.0000 + 1.0000*I,
|
|
3081
|
+
2.0000 + 1.0000*I, 2.0000 + 1.0001*I, 2.0000 + 1.0001*I]
|
|
3082
|
+
"""
|
|
3083
|
+
if self.is_zero():
|
|
3084
|
+
return [self] if all else self
|
|
3085
|
+
|
|
3086
|
+
cdef ComplexNumber z
|
|
3087
|
+
z = self._new()
|
|
3088
|
+
|
|
3089
|
+
cdef RealNumber arg, rho
|
|
3090
|
+
cdef mpfr_t r
|
|
3091
|
+
rho = abs(self)
|
|
3092
|
+
arg = self.argument() / n
|
|
3093
|
+
mpfr_init2(r, self._prec)
|
|
3094
|
+
mpfr_rootn_ui(r, rho.value, n, rnd)
|
|
3095
|
+
|
|
3096
|
+
mpfr_sin_cos(z.__im, z.__re, arg.value, rnd)
|
|
3097
|
+
mpfr_mul(z.__re, z.__re, r, rnd)
|
|
3098
|
+
mpfr_mul(z.__im, z.__im, r, rnd)
|
|
3099
|
+
|
|
3100
|
+
if not all:
|
|
3101
|
+
mpfr_clear(r)
|
|
3102
|
+
return z
|
|
3103
|
+
|
|
3104
|
+
R = self._parent._real_field()
|
|
3105
|
+
cdef RealNumber theta
|
|
3106
|
+
theta = R.pi()*2/n
|
|
3107
|
+
zlist = [z]
|
|
3108
|
+
for k in range(1, n):
|
|
3109
|
+
z = self._new()
|
|
3110
|
+
arg += theta
|
|
3111
|
+
mpfr_sin_cos(z.__im, z.__re, arg.value, rnd)
|
|
3112
|
+
mpfr_mul(z.__re, z.__re, r, rnd)
|
|
3113
|
+
mpfr_mul(z.__im, z.__im, r, rnd)
|
|
3114
|
+
zlist.append(z)
|
|
3115
|
+
|
|
3116
|
+
mpfr_clear(r)
|
|
3117
|
+
return zlist
|
|
3118
|
+
|
|
3119
|
+
def is_square(self):
|
|
3120
|
+
r"""
|
|
3121
|
+
This function always returns true as `\CC` is algebraically closed.
|
|
3122
|
+
|
|
3123
|
+
EXAMPLES::
|
|
3124
|
+
|
|
3125
|
+
sage: a = ComplexNumber(2,1)
|
|
3126
|
+
sage: a.is_square()
|
|
3127
|
+
True
|
|
3128
|
+
|
|
3129
|
+
`\CC` is algebraically closed, hence every element
|
|
3130
|
+
is a square::
|
|
3131
|
+
|
|
3132
|
+
sage: b = ComplexNumber(5)
|
|
3133
|
+
sage: b.is_square()
|
|
3134
|
+
True
|
|
3135
|
+
"""
|
|
3136
|
+
return True
|
|
3137
|
+
|
|
3138
|
+
def is_real(self):
|
|
3139
|
+
"""
|
|
3140
|
+
Return ``True`` if ``self`` is real, i.e., has imaginary part zero.
|
|
3141
|
+
|
|
3142
|
+
EXAMPLES::
|
|
3143
|
+
|
|
3144
|
+
sage: CC(1.23).is_real()
|
|
3145
|
+
True
|
|
3146
|
+
sage: CC(1+i).is_real() # needs sage.symbolic
|
|
3147
|
+
False
|
|
3148
|
+
"""
|
|
3149
|
+
return (mpfr_zero_p(self.__im) != 0)
|
|
3150
|
+
|
|
3151
|
+
def is_imaginary(self):
|
|
3152
|
+
"""
|
|
3153
|
+
Return ``True`` if ``self`` is imaginary, i.e., has real part zero.
|
|
3154
|
+
|
|
3155
|
+
EXAMPLES::
|
|
3156
|
+
|
|
3157
|
+
sage: CC(1.23*i).is_imaginary() # needs sage.symbolic
|
|
3158
|
+
True
|
|
3159
|
+
sage: CC(1+i).is_imaginary() # needs sage.symbolic
|
|
3160
|
+
False
|
|
3161
|
+
"""
|
|
3162
|
+
return (mpfr_zero_p(self.__re) != 0)
|
|
3163
|
+
|
|
3164
|
+
def is_integer(self):
|
|
3165
|
+
"""
|
|
3166
|
+
Return ``True`` if ``self`` is an integer.
|
|
3167
|
+
|
|
3168
|
+
EXAMPLES::
|
|
3169
|
+
|
|
3170
|
+
sage: CC(3).is_integer()
|
|
3171
|
+
True
|
|
3172
|
+
sage: CC(1,2).is_integer()
|
|
3173
|
+
False
|
|
3174
|
+
"""
|
|
3175
|
+
return self.is_real() and self.real() in ZZ
|
|
3176
|
+
|
|
3177
|
+
def is_positive_infinity(self):
|
|
3178
|
+
r"""
|
|
3179
|
+
Check if ``self`` is `+\infty`.
|
|
3180
|
+
|
|
3181
|
+
EXAMPLES::
|
|
3182
|
+
|
|
3183
|
+
sage: CC(1, 2).is_positive_infinity()
|
|
3184
|
+
False
|
|
3185
|
+
sage: CC(oo, 0).is_positive_infinity()
|
|
3186
|
+
True
|
|
3187
|
+
sage: CC(0, oo).is_positive_infinity()
|
|
3188
|
+
False
|
|
3189
|
+
"""
|
|
3190
|
+
return self.real().is_positive_infinity() and self.imag().is_zero()
|
|
3191
|
+
|
|
3192
|
+
def is_negative_infinity(self):
|
|
3193
|
+
r"""
|
|
3194
|
+
Check if ``self`` is `-\infty`.
|
|
3195
|
+
|
|
3196
|
+
EXAMPLES::
|
|
3197
|
+
|
|
3198
|
+
sage: CC(1, 2).is_negative_infinity()
|
|
3199
|
+
False
|
|
3200
|
+
sage: CC(-oo, 0).is_negative_infinity()
|
|
3201
|
+
True
|
|
3202
|
+
sage: CC(0, -oo).is_negative_infinity()
|
|
3203
|
+
False
|
|
3204
|
+
"""
|
|
3205
|
+
return self.real().is_negative_infinity() and self.imag().is_zero()
|
|
3206
|
+
|
|
3207
|
+
def is_infinity(self):
|
|
3208
|
+
r"""
|
|
3209
|
+
Check if ``self`` is `\infty`.
|
|
3210
|
+
|
|
3211
|
+
EXAMPLES::
|
|
3212
|
+
|
|
3213
|
+
sage: CC(1, 2).is_infinity()
|
|
3214
|
+
False
|
|
3215
|
+
sage: CC(0, oo).is_infinity()
|
|
3216
|
+
True
|
|
3217
|
+
"""
|
|
3218
|
+
return self.real().is_infinity() or self.imag().is_infinity()
|
|
3219
|
+
|
|
3220
|
+
def is_NaN(self):
|
|
3221
|
+
r"""
|
|
3222
|
+
Check if ``self`` is not-a-number.
|
|
3223
|
+
|
|
3224
|
+
EXAMPLES::
|
|
3225
|
+
|
|
3226
|
+
sage: CC(1, 2).is_NaN()
|
|
3227
|
+
False
|
|
3228
|
+
sage: CC(NaN).is_NaN() # needs sage.symbolic
|
|
3229
|
+
True
|
|
3230
|
+
sage: CC(NaN, 2).log().is_NaN() # needs sage.symbolic
|
|
3231
|
+
True
|
|
3232
|
+
"""
|
|
3233
|
+
return mpfr_nan_p(self.__re) or mpfr_nan_p(self.__im)
|
|
3234
|
+
|
|
3235
|
+
def zeta(self):
|
|
3236
|
+
"""
|
|
3237
|
+
Return the Riemann zeta function evaluated at this complex number.
|
|
3238
|
+
|
|
3239
|
+
EXAMPLES::
|
|
3240
|
+
|
|
3241
|
+
sage: i = ComplexField(30).gen()
|
|
3242
|
+
sage: z = 1 + i
|
|
3243
|
+
sage: z.zeta() # needs sage.libs.pari
|
|
3244
|
+
0.58215806 - 0.92684856*I
|
|
3245
|
+
sage: zeta(z) # needs sage.libs.pari
|
|
3246
|
+
0.58215806 - 0.92684856*I
|
|
3247
|
+
|
|
3248
|
+
sage: CC(1).zeta()
|
|
3249
|
+
Infinity
|
|
3250
|
+
"""
|
|
3251
|
+
if mpfr_zero_p(self.__im) and mpfr_cmp_ui(self.__re, 1) == 0:
|
|
3252
|
+
return infinity.unsigned_infinity
|
|
3253
|
+
return self._parent(self.__pari__().zeta())
|
|
3254
|
+
|
|
3255
|
+
def algebraic_dependency(self, n, **kwds):
|
|
3256
|
+
"""
|
|
3257
|
+
Return an irreducible polynomial of degree at most `n` which is
|
|
3258
|
+
approximately satisfied by this complex number.
|
|
3259
|
+
|
|
3260
|
+
ALGORITHM: Uses the PARI C-library :pari:`algdep` command.
|
|
3261
|
+
|
|
3262
|
+
INPUT: Type ``algebraic_dependency?`` at the top level prompt.
|
|
3263
|
+
|
|
3264
|
+
All additional parameters are passed onto the top-level
|
|
3265
|
+
:func:`algebraic_dependency` command.
|
|
3266
|
+
|
|
3267
|
+
EXAMPLES::
|
|
3268
|
+
|
|
3269
|
+
sage: # needs fpylll
|
|
3270
|
+
sage: C = ComplexField()
|
|
3271
|
+
sage: z = (1/2)*(1 + sqrt(3.0) *C.0); z
|
|
3272
|
+
0.500000000000000 + 0.866025403784439*I
|
|
3273
|
+
sage: p = z.algebraic_dependency(5); p
|
|
3274
|
+
x^2 - x + 1
|
|
3275
|
+
sage: p(z)
|
|
3276
|
+
1.11022302462516e-16
|
|
3277
|
+
"""
|
|
3278
|
+
from sage.arith.misc import algebraic_dependency
|
|
3279
|
+
return algebraic_dependency(self, n, **kwds)
|
|
3280
|
+
|
|
3281
|
+
# Alias
|
|
3282
|
+
algdep = algebraic_dependency
|
|
3283
|
+
|
|
3284
|
+
|
|
3285
|
+
def make_ComplexNumber0(fld, mult_order, real, imag):
|
|
3286
|
+
"""
|
|
3287
|
+
Create a complex number for pickling.
|
|
3288
|
+
|
|
3289
|
+
EXAMPLES::
|
|
3290
|
+
|
|
3291
|
+
sage: a = CC(1 + I) # needs sage.symbolic
|
|
3292
|
+
sage: loads(dumps(a)) == a # indirect doctest # needs sage.symbolic
|
|
3293
|
+
True
|
|
3294
|
+
"""
|
|
3295
|
+
x = ComplexNumber(fld, real, imag)
|
|
3296
|
+
x._set_multiplicative_order(mult_order)
|
|
3297
|
+
return x
|
|
3298
|
+
|
|
3299
|
+
|
|
3300
|
+
def create_ComplexNumber(s_real, s_imag=None, int pad=0, min_prec=53):
|
|
3301
|
+
r"""
|
|
3302
|
+
Return the complex number defined by the strings ``s_real`` and
|
|
3303
|
+
``s_imag`` as an element of ``ComplexField(prec=n)``,
|
|
3304
|
+
where `n` potentially has slightly more (controlled by pad) bits than
|
|
3305
|
+
given by `s`.
|
|
3306
|
+
|
|
3307
|
+
INPUT:
|
|
3308
|
+
|
|
3309
|
+
- ``s_real`` -- string that defines a real number
|
|
3310
|
+
(or something whose string representation defines a number)
|
|
3311
|
+
|
|
3312
|
+
- ``s_imag`` -- string that defines a real number
|
|
3313
|
+
(or something whose string representation defines a number)
|
|
3314
|
+
|
|
3315
|
+
- ``pad`` -- integer at least 0
|
|
3316
|
+
|
|
3317
|
+
- ``min_prec`` -- number will have at least this many bits of precision,
|
|
3318
|
+
no matter what
|
|
3319
|
+
|
|
3320
|
+
EXAMPLES::
|
|
3321
|
+
|
|
3322
|
+
sage: ComplexNumber('2.3')
|
|
3323
|
+
2.30000000000000
|
|
3324
|
+
sage: ComplexNumber('2.3','1.1')
|
|
3325
|
+
2.30000000000000 + 1.10000000000000*I
|
|
3326
|
+
sage: ComplexNumber(10)
|
|
3327
|
+
10.0000000000000
|
|
3328
|
+
sage: ComplexNumber(10,10)
|
|
3329
|
+
10.0000000000000 + 10.0000000000000*I
|
|
3330
|
+
sage: ComplexNumber(1.000000000000000000000000000,2)
|
|
3331
|
+
1.00000000000000000000000000 + 2.00000000000000000000000000*I
|
|
3332
|
+
sage: ComplexNumber(1,2.000000000000000000000)
|
|
3333
|
+
1.00000000000000000000 + 2.00000000000000000000*I
|
|
3334
|
+
|
|
3335
|
+
::
|
|
3336
|
+
|
|
3337
|
+
sage: sage.rings.complex_mpfr.create_ComplexNumber(s_real=2,s_imag=1)
|
|
3338
|
+
2.00000000000000 + 1.00000000000000*I
|
|
3339
|
+
|
|
3340
|
+
TESTS:
|
|
3341
|
+
|
|
3342
|
+
Make sure we've rounded up ``log(10,2)`` enough to guarantee
|
|
3343
|
+
sufficient precision (:issue:`10164`)::
|
|
3344
|
+
|
|
3345
|
+
sage: s = "1." + "0"*10**6 + "1"
|
|
3346
|
+
sage: sage.rings.complex_mpfr.create_ComplexNumber(s,0).real()-1 == 0
|
|
3347
|
+
False
|
|
3348
|
+
sage: sage.rings.complex_mpfr.create_ComplexNumber(0,s).imag()-1 == 0
|
|
3349
|
+
False
|
|
3350
|
+
"""
|
|
3351
|
+
if s_imag is None:
|
|
3352
|
+
s_imag = 0
|
|
3353
|
+
|
|
3354
|
+
if not isinstance(s_real, str):
|
|
3355
|
+
s_real = str(s_real).strip()
|
|
3356
|
+
if not isinstance(s_imag, str):
|
|
3357
|
+
s_imag = str(s_imag).strip()
|
|
3358
|
+
#if base == 10:
|
|
3359
|
+
bits = max(int(LOG_TEN_TWO_PLUS_EPSILON*len(s_real)),
|
|
3360
|
+
int(LOG_TEN_TWO_PLUS_EPSILON*len(s_imag)))
|
|
3361
|
+
#else:
|
|
3362
|
+
# bits = max(int(math.log(base,2)*len(s_imag)),int(math.log(base,2)*len(s_imag)))
|
|
3363
|
+
C = ComplexField(prec=max(bits+pad, min_prec))
|
|
3364
|
+
|
|
3365
|
+
return ComplexNumber(C, s_real, s_imag)
|
|
3366
|
+
|
|
3367
|
+
|
|
3368
|
+
cdef class RRtoCC(Map):
|
|
3369
|
+
|
|
3370
|
+
cdef ComplexNumber _zero
|
|
3371
|
+
|
|
3372
|
+
def __init__(self, RR, CC):
|
|
3373
|
+
"""
|
|
3374
|
+
EXAMPLES::
|
|
3375
|
+
|
|
3376
|
+
sage: from sage.rings.complex_mpfr import RRtoCC
|
|
3377
|
+
sage: RRtoCC(RR, CC)
|
|
3378
|
+
Natural map:
|
|
3379
|
+
From: Real Field with 53 bits of precision
|
|
3380
|
+
To: Complex Field with 53 bits of precision
|
|
3381
|
+
"""
|
|
3382
|
+
Map.__init__(self, RR, CC)
|
|
3383
|
+
self._zero = ComplexNumber(CC, 0)
|
|
3384
|
+
self._repr_type_str = "Natural"
|
|
3385
|
+
|
|
3386
|
+
cdef dict _extra_slots(self):
|
|
3387
|
+
"""
|
|
3388
|
+
A helper for pickling and copying.
|
|
3389
|
+
|
|
3390
|
+
INPUT:
|
|
3391
|
+
|
|
3392
|
+
- ``_slots`` -- dictionary
|
|
3393
|
+
|
|
3394
|
+
OUTPUT: the given dictionary, with zero added
|
|
3395
|
+
|
|
3396
|
+
EXAMPLES::
|
|
3397
|
+
|
|
3398
|
+
sage: from sage.rings.complex_mpfr import RRtoCC
|
|
3399
|
+
sage: f = RRtoCC(RR, CC)
|
|
3400
|
+
sage: g = copy(f) # indirect doctest
|
|
3401
|
+
sage: g
|
|
3402
|
+
Natural map:
|
|
3403
|
+
From: Real Field with 53 bits of precision
|
|
3404
|
+
To: Complex Field with 53 bits of precision
|
|
3405
|
+
"""
|
|
3406
|
+
slots = Map._extra_slots(self)
|
|
3407
|
+
slots['_zero'] = self._zero
|
|
3408
|
+
return slots
|
|
3409
|
+
|
|
3410
|
+
cdef _update_slots(self, dict _slots):
|
|
3411
|
+
"""
|
|
3412
|
+
A helper for unpickling and copying.
|
|
3413
|
+
|
|
3414
|
+
INPUT:
|
|
3415
|
+
|
|
3416
|
+
- ``_slots`` -- dictionary providing values for the c(p)def slots of ``self``
|
|
3417
|
+
|
|
3418
|
+
EXAMPLES::
|
|
3419
|
+
|
|
3420
|
+
sage: from sage.rings.complex_mpfr import RRtoCC
|
|
3421
|
+
sage: RRtoCC(RR, CC)
|
|
3422
|
+
Natural map:
|
|
3423
|
+
From: Real Field with 53 bits of precision
|
|
3424
|
+
To: Complex Field with 53 bits of precision
|
|
3425
|
+
"""
|
|
3426
|
+
Map._update_slots(self, _slots)
|
|
3427
|
+
self._zero = _slots['_zero']
|
|
3428
|
+
|
|
3429
|
+
cpdef Element _call_(self, x):
|
|
3430
|
+
"""
|
|
3431
|
+
EXAMPLES::
|
|
3432
|
+
|
|
3433
|
+
sage: from sage.rings.complex_mpfr import RRtoCC
|
|
3434
|
+
sage: f = RRtoCC(RealField(100), ComplexField(10)) # indirect doctest
|
|
3435
|
+
sage: f(1/3)
|
|
3436
|
+
0.33
|
|
3437
|
+
"""
|
|
3438
|
+
cdef ComplexNumber z = self._zero._new()
|
|
3439
|
+
mpfr_set(z.__re, (<RealNumber>x).value, rnd)
|
|
3440
|
+
mpfr_set_ui(z.__im, 0, rnd)
|
|
3441
|
+
return z
|
|
3442
|
+
|
|
3443
|
+
cdef inline mp_exp_t min_exp_t(mp_exp_t a, mp_exp_t b) noexcept:
|
|
3444
|
+
return a if a < b else b
|
|
3445
|
+
|
|
3446
|
+
cdef inline mp_exp_t max_exp_t(mp_exp_t a, mp_exp_t b) noexcept:
|
|
3447
|
+
return a if a > b else b
|
|
3448
|
+
|
|
3449
|
+
cdef inline mp_exp_t max_exp(ComplexNumber z) noexcept:
|
|
3450
|
+
"""
|
|
3451
|
+
Quickly return the maximum exponent of the real and complex parts of z,
|
|
3452
|
+
which is useful for estimating its magnitude.
|
|
3453
|
+
"""
|
|
3454
|
+
if mpfr_zero_p(z.__im):
|
|
3455
|
+
return mpfr_get_exp(z.__re)
|
|
3456
|
+
elif mpfr_zero_p(z.__re):
|
|
3457
|
+
return mpfr_get_exp(z.__im)
|
|
3458
|
+
return max_exp_t(mpfr_get_exp(z.__re), mpfr_get_exp(z.__im))
|
|
3459
|
+
|
|
3460
|
+
cpdef int cmp_abs(ComplexNumber a, ComplexNumber b) noexcept:
|
|
3461
|
+
"""
|
|
3462
|
+
Return `-1`, `0`, or `1` according to whether `|a|` is less than, equal to, or
|
|
3463
|
+
greater than `|b|`.
|
|
3464
|
+
|
|
3465
|
+
Optimized for non-close numbers, where the ordering can be determined by
|
|
3466
|
+
examining exponents.
|
|
3467
|
+
|
|
3468
|
+
EXAMPLES::
|
|
3469
|
+
|
|
3470
|
+
sage: from sage.rings.complex_mpfr import cmp_abs
|
|
3471
|
+
sage: cmp_abs(CC(5), CC(1))
|
|
3472
|
+
1
|
|
3473
|
+
sage: cmp_abs(CC(5), CC(4))
|
|
3474
|
+
1
|
|
3475
|
+
sage: cmp_abs(CC(5), CC(5))
|
|
3476
|
+
0
|
|
3477
|
+
sage: cmp_abs(CC(5), CC(6))
|
|
3478
|
+
-1
|
|
3479
|
+
sage: cmp_abs(CC(5), CC(100))
|
|
3480
|
+
-1
|
|
3481
|
+
sage: cmp_abs(CC(-100), CC(1))
|
|
3482
|
+
1
|
|
3483
|
+
sage: cmp_abs(CC(-100), CC(100))
|
|
3484
|
+
0
|
|
3485
|
+
sage: cmp_abs(CC(-100), CC(1000))
|
|
3486
|
+
-1
|
|
3487
|
+
sage: cmp_abs(CC(1,1), CC(1))
|
|
3488
|
+
1
|
|
3489
|
+
sage: cmp_abs(CC(1,1), CC(2))
|
|
3490
|
+
-1
|
|
3491
|
+
sage: cmp_abs(CC(1,1), CC(1,0.99999))
|
|
3492
|
+
1
|
|
3493
|
+
sage: cmp_abs(CC(1,1), CC(1,-1))
|
|
3494
|
+
0
|
|
3495
|
+
sage: cmp_abs(CC(0), CC(1))
|
|
3496
|
+
-1
|
|
3497
|
+
sage: cmp_abs(CC(1), CC(0))
|
|
3498
|
+
1
|
|
3499
|
+
sage: cmp_abs(CC(0), CC(0))
|
|
3500
|
+
0
|
|
3501
|
+
sage: cmp_abs(CC(2,1), CC(1,2))
|
|
3502
|
+
0
|
|
3503
|
+
"""
|
|
3504
|
+
if mpfr_zero_p(b.__re) and mpfr_zero_p(b.__im):
|
|
3505
|
+
return not ((mpfr_zero_p(a.__re) and mpfr_zero_p(a.__im)))
|
|
3506
|
+
elif (mpfr_zero_p(a.__re) and mpfr_zero_p(a.__im)):
|
|
3507
|
+
return -1
|
|
3508
|
+
cdef mp_exp_t exp_diff = max_exp(a) - max_exp(b)
|
|
3509
|
+
if exp_diff <= -2:
|
|
3510
|
+
return -1
|
|
3511
|
+
elif exp_diff >= 2:
|
|
3512
|
+
return 1
|
|
3513
|
+
|
|
3514
|
+
cdef int res
|
|
3515
|
+
cdef mpfr_t abs_a, abs_b, tmp
|
|
3516
|
+
mpfr_init2(abs_a, mpfr_get_prec(a.__re))
|
|
3517
|
+
mpfr_init2(abs_b, mpfr_get_prec(b.__re))
|
|
3518
|
+
mpfr_init2(tmp, mpfr_get_prec(a.__re))
|
|
3519
|
+
|
|
3520
|
+
mpfr_sqr(abs_a, a.__re, rnd)
|
|
3521
|
+
mpfr_sqr(tmp, a.__im, rnd)
|
|
3522
|
+
mpfr_add(abs_a, abs_a, tmp, rnd)
|
|
3523
|
+
|
|
3524
|
+
mpfr_sqr(abs_b, b.__re, rnd)
|
|
3525
|
+
mpfr_sqr(tmp, b.__im, rnd)
|
|
3526
|
+
mpfr_add(abs_b, abs_b, tmp, rnd)
|
|
3527
|
+
|
|
3528
|
+
res = mpfr_cmpabs(abs_a, abs_b)
|
|
3529
|
+
|
|
3530
|
+
mpfr_clear(abs_a)
|
|
3531
|
+
mpfr_clear(abs_b)
|
|
3532
|
+
mpfr_clear(tmp)
|
|
3533
|
+
|
|
3534
|
+
return res
|
|
3535
|
+
|
|
3536
|
+
|
|
3537
|
+
def _format_complex_number(real, imag, format_spec):
|
|
3538
|
+
"""
|
|
3539
|
+
Construct a formatted string from real and imaginary parts.
|
|
3540
|
+
|
|
3541
|
+
TESTS::
|
|
3542
|
+
|
|
3543
|
+
sage: s = format(CDF(1/80, -1/2), '25'); s
|
|
3544
|
+
' 0.0125 - 0.5*I'
|
|
3545
|
+
sage: len(s) == 25
|
|
3546
|
+
True
|
|
3547
|
+
sage: '{:=^ 25}'.format(CDF(1/80, -1/2))
|
|
3548
|
+
'===== 0.0125 - 0.5*I====='
|
|
3549
|
+
sage: format(float(3), '#.4') == format(CDF(3, 0), '#.4')
|
|
3550
|
+
True
|
|
3551
|
+
sage: format(CDF(1, 2), '=+20')
|
|
3552
|
+
Traceback (most recent call last):
|
|
3553
|
+
...
|
|
3554
|
+
ValueError: '=' alignment not allowed in complex format specifier
|
|
3555
|
+
|
|
3556
|
+
::
|
|
3557
|
+
|
|
3558
|
+
sage: format(CC(1/80, -1/2), '55') == format(str(CC(1/80, -1/2)), '>55')
|
|
3559
|
+
True
|
|
3560
|
+
sage: '{:=^ 55}'.format(CC(1/80, -1/2))
|
|
3561
|
+
'======= 0.0125000000000000 - 0.500000000000000*I======='
|
|
3562
|
+
sage: format(CC(1, 2), '=+20')
|
|
3563
|
+
Traceback (most recent call last):
|
|
3564
|
+
...
|
|
3565
|
+
ValueError: '=' alignment not allowed in complex format specifier
|
|
3566
|
+
"""
|
|
3567
|
+
match = re.match(r'^(.?[><=^])?' # 1: fill and align
|
|
3568
|
+
r'([ +-]?)' # 2: sign
|
|
3569
|
+
r'[^\d\.]*?0?(\d*)' # 3: width
|
|
3570
|
+
r'.*?([eEfFgGn%])?$', # 4: type
|
|
3571
|
+
format_spec)
|
|
3572
|
+
if not match:
|
|
3573
|
+
raise ValueError("invalid format specifier %s" % format_spec)
|
|
3574
|
+
|
|
3575
|
+
# format floats without align and width
|
|
3576
|
+
float_format = (format_spec[match.start(2):match.start(3)]
|
|
3577
|
+
+ format_spec[match.end(3):])
|
|
3578
|
+
|
|
3579
|
+
use_str_format = not match.group(4)
|
|
3580
|
+
if use_str_format and imag == 0:
|
|
3581
|
+
result = format(real, float_format)
|
|
3582
|
+
elif use_str_format and real == 0:
|
|
3583
|
+
result = format(imag, float_format) + '*I'
|
|
3584
|
+
else:
|
|
3585
|
+
x = format(real, float_format)
|
|
3586
|
+
y = format(imag, '+' + format_spec[match.end(2):match.start(3)]
|
|
3587
|
+
+ format_spec[match.end(3):])
|
|
3588
|
+
result = f"{x} {y[:1]} {y[1:]}*I"
|
|
3589
|
+
|
|
3590
|
+
width = match.group(3)
|
|
3591
|
+
if width:
|
|
3592
|
+
align = match.group(1) or '>'
|
|
3593
|
+
if align.endswith('='):
|
|
3594
|
+
raise ValueError("'=' alignment not allowed in "
|
|
3595
|
+
"complex format specifier")
|
|
3596
|
+
result = format(result, align + width)
|
|
3597
|
+
return result
|
|
3598
|
+
|
|
3599
|
+
|
|
3600
|
+
# Support Python's numbers abstract base class
|
|
3601
|
+
import numbers
|
|
3602
|
+
numbers.Complex.register(ComplexNumber)
|