passagemath-pari 10.6.32__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-pari might be problematic. Click here for more details.
- PARIKernel/__init__.py +2 -0
- PARIKernel/__main__.py +5 -0
- PARIKernel/io.cpython-314-x86_64-linux-musl.so +0 -0
- PARIKernel/io.pxd +7 -0
- PARIKernel/io.pyx +84 -0
- PARIKernel/kernel.cpython-314-x86_64-linux-musl.so +0 -0
- PARIKernel/kernel.pyx +260 -0
- PARIKernel/paridecl.pxd +95 -0
- PARIKernel/svg.cpython-314-x86_64-linux-musl.so +0 -0
- PARIKernel/svg.pyx +52 -0
- cypari2/__init__.py +8 -0
- cypari2/auto_paridecl.pxd +1070 -0
- cypari2/closure.cpython-314-x86_64-linux-musl.so +0 -0
- cypari2/closure.pxd +5 -0
- cypari2/closure.pyx +246 -0
- cypari2/convert.cpython-314-x86_64-linux-musl.so +0 -0
- cypari2/convert.pxd +80 -0
- cypari2/convert.pyx +613 -0
- cypari2/custom_block.cpython-314-x86_64-linux-musl.so +0 -0
- cypari2/custom_block.pyx +30 -0
- cypari2/cypari.h +13 -0
- cypari2/gen.cpython-314-x86_64-linux-musl.so +0 -0
- cypari2/gen.pxd +69 -0
- cypari2/gen.pyx +4819 -0
- cypari2/handle_error.cpython-314-x86_64-linux-musl.so +0 -0
- cypari2/handle_error.pxd +7 -0
- cypari2/handle_error.pyx +232 -0
- cypari2/pari_instance.cpython-314-x86_64-linux-musl.so +0 -0
- cypari2/pari_instance.pxd +27 -0
- cypari2/pari_instance.pyx +1438 -0
- cypari2/paridecl.pxd +5353 -0
- cypari2/paripriv.pxd +34 -0
- cypari2/pycore_long.h +98 -0
- cypari2/pycore_long.pxd +9 -0
- cypari2/stack.cpython-314-x86_64-linux-musl.so +0 -0
- cypari2/stack.pxd +27 -0
- cypari2/stack.pyx +278 -0
- cypari2/string_utils.cpython-314-x86_64-linux-musl.so +0 -0
- cypari2/string_utils.pxd +29 -0
- cypari2/string_utils.pyx +65 -0
- cypari2/types.pxd +147 -0
- passagemath_pari-10.6.32.data/data/etc/jupyter/nbconfig/notebook.d/gp-mode.json +5 -0
- passagemath_pari-10.6.32.data/data/share/jupyter/kernels/pari_jupyter/kernel.js +28 -0
- passagemath_pari-10.6.32.data/data/share/jupyter/kernels/pari_jupyter/kernel.json +6 -0
- passagemath_pari-10.6.32.data/data/share/jupyter/kernels/pari_jupyter/logo-64x64.png +0 -0
- passagemath_pari-10.6.32.data/data/share/jupyter/kernels/xeus-gp/kernel.json +13 -0
- passagemath_pari-10.6.32.data/data/share/jupyter/kernels/xeus-gp/logo-32x32.png +0 -0
- passagemath_pari-10.6.32.data/data/share/jupyter/kernels/xeus-gp/logo-64x64.png +0 -0
- passagemath_pari-10.6.32.data/data/share/jupyter/kernels/xeus-gp/logo-svg.svg +75 -0
- passagemath_pari-10.6.32.data/data/share/jupyter/nbextensions/gp-mode/gp.js +284 -0
- passagemath_pari-10.6.32.data/data/share/jupyter/nbextensions/gp-mode/main.js +15 -0
- passagemath_pari-10.6.32.dist-info/METADATA +209 -0
- passagemath_pari-10.6.32.dist-info/RECORD +331 -0
- passagemath_pari-10.6.32.dist-info/WHEEL +5 -0
- passagemath_pari-10.6.32.dist-info/top_level.txt +4 -0
- passagemath_pari.libs/libcrypto-f04afe95.so.3 +0 -0
- passagemath_pari.libs/libflint-fd6f12fc.so.21.0.0 +0 -0
- passagemath_pari.libs/libgcc_s-0cd532bd.so.1 +0 -0
- passagemath_pari.libs/libgf2x-9e30c3e3.so.3.0.0 +0 -0
- passagemath_pari.libs/libgfortran-2c33b284.so.5.0.0 +0 -0
- passagemath_pari.libs/libgivaro-9a94c711.so.9.2.1 +0 -0
- passagemath_pari.libs/libgmp-0e7fc84e.so.10.5.0 +0 -0
- passagemath_pari.libs/libgmpxx-9e08595c.so.4.7.0 +0 -0
- passagemath_pari.libs/libgsl-42cda06f.so.28.0.0 +0 -0
- passagemath_pari.libs/libmpfr-aaecbfc0.so.6.2.1 +0 -0
- passagemath_pari.libs/libncursesw-9c9e32c3.so.6.5 +0 -0
- passagemath_pari.libs/libntl-26885ca2.so.44.0.1 +0 -0
- passagemath_pari.libs/libopenblasp-r0-905cb27d.3.29.so +0 -0
- passagemath_pari.libs/libpari-gmp-tls-f31f908f.so.2.17.2 +0 -0
- passagemath_pari.libs/libquadmath-bb76a5fc.so.0.0.0 +0 -0
- passagemath_pari.libs/libreadline-06542304.so.8.2 +0 -0
- passagemath_pari.libs/libstdc++-5d72f927.so.6.0.33 +0 -0
- passagemath_pari.libs/libuuid-f3770415.so.1.3.0 +0 -0
- passagemath_pari.libs/libxeus-735780ff.so.13.1.0 +0 -0
- passagemath_pari.libs/libxeus-zmq-c68577b4.so.6.0.1 +0 -0
- passagemath_pari.libs/libzmq-1ba9a3da.so.5.2.5 +0 -0
- sage/all__sagemath_pari.py +26 -0
- sage/databases/all__sagemath_pari.py +7 -0
- sage/databases/conway.py +274 -0
- sage/ext/all__sagemath_pari.py +1 -0
- sage/ext/memory.cpython-314-x86_64-linux-musl.so +0 -0
- sage/ext/memory.pyx +98 -0
- sage/ext_data/pari/buzzard/DimensionSk.g +286 -0
- sage/ext_data/pari/buzzard/Tpprog.g +179 -0
- sage/ext_data/pari/buzzard/genusn.g +129 -0
- sage/ext_data/pari/dokchitser/computel.gp +740 -0
- sage/ext_data/pari/dokchitser/computel.gp.template +740 -0
- sage/ext_data/pari/dokchitser/ex-bsw +43 -0
- sage/ext_data/pari/dokchitser/ex-chgen +48 -0
- sage/ext_data/pari/dokchitser/ex-chqua +37 -0
- sage/ext_data/pari/dokchitser/ex-delta +35 -0
- sage/ext_data/pari/dokchitser/ex-eisen +30 -0
- sage/ext_data/pari/dokchitser/ex-gen2 +38 -0
- sage/ext_data/pari/dokchitser/ex-gen3 +49 -0
- sage/ext_data/pari/dokchitser/ex-gen4 +54 -0
- sage/ext_data/pari/dokchitser/ex-nf +48 -0
- sage/ext_data/pari/dokchitser/ex-shin +50 -0
- sage/ext_data/pari/dokchitser/ex-tau2 +30 -0
- sage/ext_data/pari/dokchitser/ex-zeta +27 -0
- sage/ext_data/pari/dokchitser/ex-zeta2 +47 -0
- sage/ext_data/pari/dokchitser/testall +13 -0
- sage/ext_data/pari/simon/ell.gp +2129 -0
- sage/ext_data/pari/simon/ellQ.gp +2151 -0
- sage/ext_data/pari/simon/ellcommon.gp +126 -0
- sage/ext_data/pari/simon/qfsolve.gp +722 -0
- sage/ext_data/pari/simon/resultant3.gp +306 -0
- sage/groups/all__sagemath_pari.py +3 -0
- sage/groups/pari_group.py +175 -0
- sage/interfaces/all__sagemath_pari.py +1 -0
- sage/interfaces/genus2reduction.py +464 -0
- sage/interfaces/gp.py +1114 -0
- sage/libs/all__sagemath_pari.py +2 -0
- sage/libs/linkages/__init__.py +1 -0
- sage/libs/linkages/padics/API.pxi +617 -0
- sage/libs/linkages/padics/Polynomial_ram.pxi +388 -0
- sage/libs/linkages/padics/Polynomial_shared.pxi +554 -0
- sage/libs/linkages/padics/__init__.py +1 -0
- sage/libs/linkages/padics/fmpz_poly_unram.pxi +869 -0
- sage/libs/linkages/padics/mpz.pxi +691 -0
- sage/libs/linkages/padics/relaxed/API.pxi +518 -0
- sage/libs/linkages/padics/relaxed/__init__.py +1 -0
- sage/libs/linkages/padics/relaxed/flint.pxi +543 -0
- sage/libs/linkages/padics/unram_shared.pxi +247 -0
- sage/libs/pari/__init__.py +210 -0
- sage/libs/pari/all.py +5 -0
- sage/libs/pari/convert_flint.cpython-314-x86_64-linux-musl.so +0 -0
- sage/libs/pari/convert_flint.pxd +14 -0
- sage/libs/pari/convert_flint.pyx +159 -0
- sage/libs/pari/convert_gmp.cpython-314-x86_64-linux-musl.so +0 -0
- sage/libs/pari/convert_gmp.pxd +14 -0
- sage/libs/pari/convert_gmp.pyx +210 -0
- sage/libs/pari/convert_sage.cpython-314-x86_64-linux-musl.so +0 -0
- sage/libs/pari/convert_sage.pxd +16 -0
- sage/libs/pari/convert_sage.pyx +588 -0
- sage/libs/pari/convert_sage_complex_double.cpython-314-x86_64-linux-musl.so +0 -0
- sage/libs/pari/convert_sage_complex_double.pxd +14 -0
- sage/libs/pari/convert_sage_complex_double.pyx +132 -0
- sage/libs/pari/convert_sage_matrix.cpython-314-x86_64-linux-musl.so +0 -0
- sage/libs/pari/convert_sage_matrix.pyx +106 -0
- sage/libs/pari/convert_sage_real_double.cpython-314-x86_64-linux-musl.so +0 -0
- sage/libs/pari/convert_sage_real_double.pxd +5 -0
- sage/libs/pari/convert_sage_real_double.pyx +14 -0
- sage/libs/pari/convert_sage_real_mpfr.cpython-314-x86_64-linux-musl.so +0 -0
- sage/libs/pari/convert_sage_real_mpfr.pxd +7 -0
- sage/libs/pari/convert_sage_real_mpfr.pyx +108 -0
- sage/libs/pari/misc.cpython-314-x86_64-linux-musl.so +0 -0
- sage/libs/pari/misc.pxd +4 -0
- sage/libs/pari/misc.pyx +26 -0
- sage/libs/pari/tests.py +1848 -0
- sage/matrix/all__sagemath_pari.py +1 -0
- sage/matrix/matrix_integer_pari.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/matrix_integer_pari.pyx +187 -0
- sage/matrix/matrix_rational_pari.cpython-314-x86_64-linux-musl.so +0 -0
- sage/matrix/matrix_rational_pari.pyx +160 -0
- sage/quadratic_forms/all__sagemath_pari.py +10 -0
- sage/quadratic_forms/genera/all.py +9 -0
- sage/quadratic_forms/genera/genus.py +3506 -0
- sage/quadratic_forms/genera/normal_form.py +1519 -0
- sage/quadratic_forms/genera/spinor_genus.py +243 -0
- sage/quadratic_forms/qfsolve.py +255 -0
- sage/quadratic_forms/quadratic_form__automorphisms.py +427 -0
- sage/quadratic_forms/quadratic_form__genus.py +141 -0
- sage/quadratic_forms/quadratic_form__local_density_interfaces.py +140 -0
- sage/quadratic_forms/quadratic_form__local_normal_form.py +421 -0
- sage/quadratic_forms/quadratic_form__local_representation_conditions.py +889 -0
- sage/quadratic_forms/quadratic_form__mass.py +69 -0
- sage/quadratic_forms/quadratic_form__mass__Conway_Sloane_masses.py +663 -0
- sage/quadratic_forms/quadratic_form__mass__Siegel_densities.py +373 -0
- sage/quadratic_forms/quadratic_form__siegel_product.py +198 -0
- sage/quadratic_forms/special_values.py +323 -0
- sage/rings/all__sagemath_pari.py +15 -0
- sage/rings/factorint_pari.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/factorint_pari.pyx +80 -0
- sage/rings/finite_rings/all__sagemath_pari.py +1 -0
- sage/rings/finite_rings/element_givaro.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/finite_rings/element_givaro.pxd +91 -0
- sage/rings/finite_rings/element_givaro.pyx +1769 -0
- sage/rings/finite_rings/element_ntl_gf2e.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/finite_rings/element_ntl_gf2e.pxd +22 -0
- sage/rings/finite_rings/element_ntl_gf2e.pyx +1333 -0
- sage/rings/finite_rings/element_pari_ffelt.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/finite_rings/element_pari_ffelt.pxd +13 -0
- sage/rings/finite_rings/element_pari_ffelt.pyx +1441 -0
- sage/rings/finite_rings/finite_field_givaro.py +612 -0
- sage/rings/finite_rings/finite_field_pari_ffelt.py +238 -0
- sage/rings/finite_rings/hom_finite_field_givaro.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/finite_rings/hom_finite_field_givaro.pxd +28 -0
- sage/rings/finite_rings/hom_finite_field_givaro.pyx +280 -0
- sage/rings/finite_rings/residue_field_givaro.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/finite_rings/residue_field_givaro.pyx +133 -0
- sage/rings/finite_rings/residue_field_pari_ffelt.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/finite_rings/residue_field_pari_ffelt.pyx +128 -0
- sage/rings/function_field/all__sagemath_pari.py +1 -0
- sage/rings/function_field/valuation.py +1450 -0
- sage/rings/function_field/valuation_ring.py +212 -0
- sage/rings/number_field/all__sagemath_pari.py +14 -0
- sage/rings/number_field/totallyreal.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/number_field/totallyreal.pyx +509 -0
- sage/rings/number_field/totallyreal_data.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/number_field/totallyreal_data.pxd +26 -0
- sage/rings/number_field/totallyreal_data.pyx +928 -0
- sage/rings/number_field/totallyreal_phc.py +144 -0
- sage/rings/number_field/totallyreal_rel.py +1018 -0
- sage/rings/padics/CA_template.pxi +1847 -0
- sage/rings/padics/CA_template_header.pxi +50 -0
- sage/rings/padics/CR_template.pxi +2563 -0
- sage/rings/padics/CR_template_header.pxi +57 -0
- sage/rings/padics/FM_template.pxi +1575 -0
- sage/rings/padics/FM_template_header.pxi +50 -0
- sage/rings/padics/FP_template.pxi +2176 -0
- sage/rings/padics/FP_template_header.pxi +57 -0
- sage/rings/padics/all.py +3 -0
- sage/rings/padics/all__sagemath_pari.py +11 -0
- sage/rings/padics/common_conversion.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/padics/common_conversion.pxd +15 -0
- sage/rings/padics/common_conversion.pyx +508 -0
- sage/rings/padics/eisenstein_extension_generic.py +232 -0
- sage/rings/padics/factory.py +3623 -0
- sage/rings/padics/generic_nodes.py +1615 -0
- sage/rings/padics/lattice_precision.py +2889 -0
- sage/rings/padics/morphism.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/padics/morphism.pxd +11 -0
- sage/rings/padics/morphism.pyx +366 -0
- sage/rings/padics/padic_base_generic.py +467 -0
- sage/rings/padics/padic_base_leaves.py +1235 -0
- sage/rings/padics/padic_capped_absolute_element.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/padics/padic_capped_absolute_element.pxd +15 -0
- sage/rings/padics/padic_capped_absolute_element.pyx +520 -0
- sage/rings/padics/padic_capped_relative_element.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/padics/padic_capped_relative_element.pxd +14 -0
- sage/rings/padics/padic_capped_relative_element.pyx +614 -0
- sage/rings/padics/padic_extension_generic.py +990 -0
- sage/rings/padics/padic_extension_leaves.py +738 -0
- sage/rings/padics/padic_fixed_mod_element.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/padics/padic_fixed_mod_element.pxd +15 -0
- sage/rings/padics/padic_fixed_mod_element.pyx +584 -0
- sage/rings/padics/padic_floating_point_element.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/padics/padic_floating_point_element.pxd +14 -0
- sage/rings/padics/padic_floating_point_element.pyx +447 -0
- sage/rings/padics/padic_generic_element.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/padics/padic_generic_element.pxd +48 -0
- sage/rings/padics/padic_generic_element.pyx +4642 -0
- sage/rings/padics/padic_lattice_element.py +1342 -0
- sage/rings/padics/padic_printing.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/padics/padic_printing.pxd +38 -0
- sage/rings/padics/padic_printing.pyx +1505 -0
- sage/rings/padics/padic_relaxed_element.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/padics/padic_relaxed_element.pxd +56 -0
- sage/rings/padics/padic_relaxed_element.pyx +18 -0
- sage/rings/padics/padic_relaxed_errors.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/padics/padic_relaxed_errors.pxd +11 -0
- sage/rings/padics/padic_relaxed_errors.pyx +71 -0
- sage/rings/padics/padic_template_element.pxi +1212 -0
- sage/rings/padics/padic_template_element_header.pxi +50 -0
- sage/rings/padics/padic_valuation.py +1423 -0
- sage/rings/padics/pow_computer_flint.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/padics/pow_computer_flint.pxd +38 -0
- sage/rings/padics/pow_computer_flint.pyx +641 -0
- sage/rings/padics/pow_computer_relative.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/padics/pow_computer_relative.pxd +29 -0
- sage/rings/padics/pow_computer_relative.pyx +415 -0
- sage/rings/padics/qadic_flint_CA.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/padics/qadic_flint_CA.pxd +21 -0
- sage/rings/padics/qadic_flint_CA.pyx +130 -0
- sage/rings/padics/qadic_flint_CR.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/padics/qadic_flint_CR.pxd +13 -0
- sage/rings/padics/qadic_flint_CR.pyx +172 -0
- sage/rings/padics/qadic_flint_FM.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/padics/qadic_flint_FM.pxd +14 -0
- sage/rings/padics/qadic_flint_FM.pyx +111 -0
- sage/rings/padics/qadic_flint_FP.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/padics/qadic_flint_FP.pxd +12 -0
- sage/rings/padics/qadic_flint_FP.pyx +165 -0
- sage/rings/padics/relative_extension_leaves.py +429 -0
- sage/rings/padics/relative_ramified_CA.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/padics/relative_ramified_CA.pxd +9 -0
- sage/rings/padics/relative_ramified_CA.pyx +33 -0
- sage/rings/padics/relative_ramified_CR.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/padics/relative_ramified_CR.pxd +8 -0
- sage/rings/padics/relative_ramified_CR.pyx +33 -0
- sage/rings/padics/relative_ramified_FM.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/padics/relative_ramified_FM.pxd +9 -0
- sage/rings/padics/relative_ramified_FM.pyx +33 -0
- sage/rings/padics/relative_ramified_FP.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/padics/relative_ramified_FP.pxd +8 -0
- sage/rings/padics/relative_ramified_FP.pyx +33 -0
- sage/rings/padics/relaxed_template.pxi +4229 -0
- sage/rings/padics/relaxed_template_header.pxi +160 -0
- sage/rings/padics/tests.py +35 -0
- sage/rings/padics/tutorial.py +341 -0
- sage/rings/padics/unramified_extension_generic.py +335 -0
- sage/rings/padics/witt_vector.py +917 -0
- sage/rings/padics/witt_vector_ring.py +934 -0
- sage/rings/pari_ring.py +235 -0
- sage/rings/polynomial/all__sagemath_pari.py +1 -0
- sage/rings/polynomial/padics/all.py +1 -0
- sage/rings/polynomial/padics/polynomial_padic.py +360 -0
- sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py +1324 -0
- sage/rings/polynomial/padics/polynomial_padic_flat.py +72 -0
- sage/rings/power_series_pari.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/power_series_pari.pxd +6 -0
- sage/rings/power_series_pari.pyx +934 -0
- sage/rings/tate_algebra.py +1282 -0
- sage/rings/tate_algebra_element.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/tate_algebra_element.pxd +49 -0
- sage/rings/tate_algebra_element.pyx +3464 -0
- sage/rings/tate_algebra_ideal.cpython-314-x86_64-linux-musl.so +0 -0
- sage/rings/tate_algebra_ideal.pxd +7 -0
- sage/rings/tate_algebra_ideal.pyx +1307 -0
- sage/rings/valuation/all.py +7 -0
- sage/rings/valuation/augmented_valuation.py +2118 -0
- sage/rings/valuation/developing_valuation.py +362 -0
- sage/rings/valuation/gauss_valuation.py +812 -0
- sage/rings/valuation/inductive_valuation.py +1686 -0
- sage/rings/valuation/limit_valuation.py +946 -0
- sage/rings/valuation/mapped_valuation.py +656 -0
- sage/rings/valuation/scaled_valuation.py +322 -0
- sage/rings/valuation/trivial_valuation.py +382 -0
- sage/rings/valuation/valuation.py +1119 -0
- sage/rings/valuation/valuation_space.py +1615 -0
- sage/rings/valuation/valuations_catalog.py +10 -0
- sage/rings/valuation/value_group.py +697 -0
- sage/schemes/all__sagemath_pari.py +1 -0
- sage/schemes/elliptic_curves/all__sagemath_pari.py +1 -0
- sage/schemes/elliptic_curves/descent_two_isogeny_pari.cpython-314-x86_64-linux-musl.so +0 -0
- sage/schemes/elliptic_curves/descent_two_isogeny_pari.pyx +46 -0
- sage_wheels/bin/gp +0 -0
- sage_wheels/bin/gp2c +0 -0
- sage_wheels/bin/gp2c-run +57 -0
- sage_wheels/bin/xeus-gp +0 -0
- sage_wheels/share/gp2c/func.dsc +18414 -0
cypari2/gen.pyx
ADDED
|
@@ -0,0 +1,4819 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-pari
|
|
2
|
+
# cython: language_level=3str
|
|
3
|
+
"""
|
|
4
|
+
The Gen class wrapping PARI's GEN type
|
|
5
|
+
**************************************
|
|
6
|
+
|
|
7
|
+
AUTHORS:
|
|
8
|
+
|
|
9
|
+
- William Stein (2006-03-01): updated to work with PARI 2.2.12-beta
|
|
10
|
+
|
|
11
|
+
- William Stein (2006-03-06): added newtonpoly
|
|
12
|
+
|
|
13
|
+
- Justin Walker: contributed some of the function definitions
|
|
14
|
+
|
|
15
|
+
- Gonzalo Tornaria: improvements to conversions; much better error
|
|
16
|
+
handling.
|
|
17
|
+
|
|
18
|
+
- Robert Bradshaw, Jeroen Demeyer, William Stein (2010-08-15):
|
|
19
|
+
Upgrade to PARI 2.4.3 (:trac:`9343`)
|
|
20
|
+
|
|
21
|
+
- Jeroen Demeyer (2011-11-12): rewrite various conversion routines
|
|
22
|
+
(:trac:`11611`, :trac:`11854`, :trac:`11952`)
|
|
23
|
+
|
|
24
|
+
- Peter Bruin (2013-11-17): move Pari to a separate file
|
|
25
|
+
(:trac:`15185`)
|
|
26
|
+
|
|
27
|
+
- Jeroen Demeyer (2014-02-09): upgrade to PARI 2.7 (:trac:`15767`)
|
|
28
|
+
|
|
29
|
+
- Martin von Gagern (2014-12-17): Added some Galois functions (:trac:`17519`)
|
|
30
|
+
|
|
31
|
+
- Jeroen Demeyer (2015-01-12): upgrade to PARI 2.8 (:trac:`16997`)
|
|
32
|
+
|
|
33
|
+
- Jeroen Demeyer (2015-03-17): automatically generate methods from
|
|
34
|
+
``pari.desc`` (:trac:`17631` and :trac:`17860`)
|
|
35
|
+
|
|
36
|
+
- Kiran Kedlaya (2016-03-23): implement infinity type
|
|
37
|
+
|
|
38
|
+
- Luca De Feo (2016-09-06): Separate Sage-specific components from
|
|
39
|
+
generic C-interface in ``Pari`` (:trac:`20241`)
|
|
40
|
+
|
|
41
|
+
- Vincent Delecroix (2017-04-29): Python 3 support and doctest
|
|
42
|
+
conversion
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
# ****************************************************************************
|
|
46
|
+
# Copyright (C) 2006,2010 William Stein <wstein@gmail.com>
|
|
47
|
+
# Copyright (C) ???? Justin Walker
|
|
48
|
+
# Copyright (C) ???? Gonzalo Tornaria
|
|
49
|
+
# Copyright (C) 2010 Robert Bradshaw <robertwb@math.washington.edu>
|
|
50
|
+
# Copyright (C) 2010-2018 Jeroen Demeyer <J.Demeyer@UGent.be>
|
|
51
|
+
# Copyright (C) 2016 Luca De Feo <luca.defeo@polytechnique.edu>
|
|
52
|
+
# Copyright (C) 2017 Vincent Delecroix <vincent.delecroix@labri.fr>
|
|
53
|
+
#
|
|
54
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
|
55
|
+
# as published by the Free Software Foundation; either version 2 of
|
|
56
|
+
# the License, or (at your option) any later version.
|
|
57
|
+
# https://www.gnu.org/licenses/
|
|
58
|
+
# ****************************************************************************
|
|
59
|
+
|
|
60
|
+
cimport cython
|
|
61
|
+
|
|
62
|
+
from cpython.object cimport (Py_EQ, Py_NE, Py_LE, Py_GE, Py_LT, PyTypeObject)
|
|
63
|
+
|
|
64
|
+
from cysignals.memory cimport sig_free, check_malloc
|
|
65
|
+
from cysignals.signals cimport sig_check, sig_on, sig_off, sig_block, sig_unblock
|
|
66
|
+
|
|
67
|
+
from .types cimport *
|
|
68
|
+
from .string_utils cimport to_string, to_bytes
|
|
69
|
+
from .paripriv cimport *
|
|
70
|
+
from .convert cimport PyObject_AsGEN, gen_to_integer
|
|
71
|
+
from .pari_instance cimport DEFAULT_BITPREC, get_var
|
|
72
|
+
from .stack cimport (new_gen, new_gens2, new_gen_noclear,
|
|
73
|
+
clone_gen, clear_stack, reset_avma,
|
|
74
|
+
remove_from_pari_stack, move_gens_to_heap)
|
|
75
|
+
from .closure cimport objtoclosure
|
|
76
|
+
|
|
77
|
+
from .paridecl cimport *
|
|
78
|
+
|
|
79
|
+
include 'auto_gen.pxi'
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
cdef bint ellwp_flag1_bug = -1
|
|
83
|
+
cdef inline bint have_ellwp_flag1_bug() except -1:
|
|
84
|
+
"""
|
|
85
|
+
The PARI function ``ellwp(..., flag=1)`` has a bug in PARI versions
|
|
86
|
+
2.9.x where the derivative is a factor 2 too small.
|
|
87
|
+
|
|
88
|
+
This function does a cached check for this bug, returning 1 if
|
|
89
|
+
the bug is there and 0 if not.
|
|
90
|
+
"""
|
|
91
|
+
global ellwp_flag1_bug
|
|
92
|
+
if ellwp_flag1_bug >= 0:
|
|
93
|
+
return ellwp_flag1_bug
|
|
94
|
+
|
|
95
|
+
# Check whether our PARI/GP version is buggy or not. This
|
|
96
|
+
# computation should return 1.0, but in older PARI versions it
|
|
97
|
+
# returns 0.5.
|
|
98
|
+
sig_on()
|
|
99
|
+
cdef GEN res = gp_read_str(b"localbitprec(128); my(E=ellinit([0,1/4])); ellwp(E,ellpointtoz(E,[0,1/2]),1)[2]")
|
|
100
|
+
cdef double d = gtodouble(res)
|
|
101
|
+
sig_off()
|
|
102
|
+
|
|
103
|
+
if d == 1.0:
|
|
104
|
+
ellwp_flag1_bug = 0
|
|
105
|
+
elif d == 0.5:
|
|
106
|
+
ellwp_flag1_bug = 1
|
|
107
|
+
else:
|
|
108
|
+
raise AssertionError(f"unexpected result from ellwp() test: {d}")
|
|
109
|
+
return ellwp_flag1_bug
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
# Compatibility wrappers
|
|
113
|
+
cdef extern from *:
|
|
114
|
+
"""
|
|
115
|
+
#if PARI_VERSION_CODE >= PARI_VERSION(2, 10, 1)
|
|
116
|
+
#define new_nf_nfzk nf_nfzk
|
|
117
|
+
#define new_nfeltup nfeltup
|
|
118
|
+
#else
|
|
119
|
+
static GEN new_nf_nfzk(GEN nf, GEN rnfeq)
|
|
120
|
+
{
|
|
121
|
+
GEN zknf, czknf;
|
|
122
|
+
nf_nfzk(nf, rnfeq, &zknf, &czknf);
|
|
123
|
+
return mkvec2(zknf, czknf);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
static GEN new_nfeltup(GEN nf, GEN x, GEN arg)
|
|
127
|
+
{
|
|
128
|
+
GEN zknf = gel(arg, 1);
|
|
129
|
+
GEN czknf = gel(arg, 2);
|
|
130
|
+
return nfeltup(nf, x, zknf, czknf);
|
|
131
|
+
}
|
|
132
|
+
#endif
|
|
133
|
+
|
|
134
|
+
#if PARI_VERSION_CODE >= PARI_VERSION(2, 12, 0)
|
|
135
|
+
#define old_nfbasis(x, yptr, p) nfbasis(mkvec2(x, p), yptr)
|
|
136
|
+
#else
|
|
137
|
+
#define old_nfbasis nfbasis
|
|
138
|
+
#endif
|
|
139
|
+
"""
|
|
140
|
+
GEN new_nf_nfzk(GEN nf, GEN rnfeq)
|
|
141
|
+
GEN new_nfeltup(GEN nf, GEN x, GEN zknf)
|
|
142
|
+
GEN old_nfbasis(GEN x, GEN * y, GEN p)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
@cython.trashcan(True)
|
|
146
|
+
cdef class Gen(Gen_base):
|
|
147
|
+
"""
|
|
148
|
+
Wrapper for a PARI ``GEN`` with memory management.
|
|
149
|
+
|
|
150
|
+
This wraps PARI objects which live either on the PARI stack or on
|
|
151
|
+
the PARI heap. Results from PARI computations appear on the PARI
|
|
152
|
+
stack and we try to keep them there. However, when the stack fills
|
|
153
|
+
up, we copy ("clone" in PARI speak) all live objects from the stack
|
|
154
|
+
to the heap. This happens transparently for the user.
|
|
155
|
+
"""
|
|
156
|
+
def __init__(self):
|
|
157
|
+
raise RuntimeError("PARI objects cannot be instantiated directly; use pari(x) to convert x to PARI")
|
|
158
|
+
|
|
159
|
+
def __dealloc__(self):
|
|
160
|
+
if self.next is not None:
|
|
161
|
+
# stack
|
|
162
|
+
remove_from_pari_stack(self)
|
|
163
|
+
elif self.address is not NULL:
|
|
164
|
+
# clone
|
|
165
|
+
gunclone_deep(self.address)
|
|
166
|
+
|
|
167
|
+
cdef Gen new_ref(self, GEN g):
|
|
168
|
+
"""
|
|
169
|
+
Create a new ``Gen`` pointing to ``g``, which is a component
|
|
170
|
+
of ``self.g``.
|
|
171
|
+
|
|
172
|
+
In this case, ``g`` should point to some location in the memory
|
|
173
|
+
allocated by ``self``. This will not allocate any new memory:
|
|
174
|
+
the newly returned ``Gen`` will point to the memory allocated
|
|
175
|
+
for ``self``.
|
|
176
|
+
|
|
177
|
+
.. NOTE::
|
|
178
|
+
|
|
179
|
+
Usually, there is only one ``Gen`` pointing to a given PARI
|
|
180
|
+
``GEN``. This function can be used when a complicated
|
|
181
|
+
``GEN`` is allocated with a single ``Gen`` pointing to it,
|
|
182
|
+
and one needs a ``Gen`` pointing to one of its components.
|
|
183
|
+
|
|
184
|
+
For example, doing ``x = pari("[1, 2]")`` allocates a ``Gen``
|
|
185
|
+
pointing to the list ``[1, 2]``. To create a ``Gen`` pointing
|
|
186
|
+
to the first element, one can do ``x.new_ref(gel(x.fixGEN(), 1))``.
|
|
187
|
+
See :meth:`Gen.__getitem__` for an example of usage.
|
|
188
|
+
|
|
189
|
+
Examples:
|
|
190
|
+
|
|
191
|
+
>>> from cypari2 import Pari
|
|
192
|
+
>>> pari = Pari()
|
|
193
|
+
>>> pari("[[1, 2], 3]")[0][1] # indirect doctest
|
|
194
|
+
2
|
|
195
|
+
"""
|
|
196
|
+
if self.next is not None:
|
|
197
|
+
raise TypeError("cannot create reference to PARI stack (call fixGEN() first)")
|
|
198
|
+
if is_on_stack(g):
|
|
199
|
+
raise ValueError("new_ref() called with GEN which does not belong to parent")
|
|
200
|
+
|
|
201
|
+
if self.address is not NULL:
|
|
202
|
+
gclone_refc(self.address)
|
|
203
|
+
return Gen_new(g, self.address)
|
|
204
|
+
|
|
205
|
+
cdef GEN fixGEN(self) except NULL:
|
|
206
|
+
"""
|
|
207
|
+
Return the PARI ``GEN`` corresponding to ``self`` which is
|
|
208
|
+
guaranteed not to change.
|
|
209
|
+
"""
|
|
210
|
+
if self.next is not None:
|
|
211
|
+
move_gens_to_heap(self.sp())
|
|
212
|
+
return self.g
|
|
213
|
+
|
|
214
|
+
cdef GEN ref_target(self) except NULL:
|
|
215
|
+
"""
|
|
216
|
+
Return a PARI ``GEN`` corresponding to ``self`` which is usable
|
|
217
|
+
as target for a reference in another ``GEN``.
|
|
218
|
+
|
|
219
|
+
This increases the PARI refcount of ``self``.
|
|
220
|
+
"""
|
|
221
|
+
if is_universal_constant(self.g):
|
|
222
|
+
return self.g
|
|
223
|
+
return gcloneref(self.fixGEN())
|
|
224
|
+
|
|
225
|
+
def __repr__(self):
|
|
226
|
+
"""
|
|
227
|
+
Display representation of a gen.
|
|
228
|
+
|
|
229
|
+
OUTPUT: a Python string
|
|
230
|
+
|
|
231
|
+
Examples:
|
|
232
|
+
|
|
233
|
+
>>> from cypari2 import Pari
|
|
234
|
+
>>> pari = Pari()
|
|
235
|
+
>>> pari('vector(5,i,i)')
|
|
236
|
+
[1, 2, 3, 4, 5]
|
|
237
|
+
>>> pari('[1,2;3,4]')
|
|
238
|
+
[1, 2; 3, 4]
|
|
239
|
+
>>> pari('Str(hello)')
|
|
240
|
+
"hello"
|
|
241
|
+
"""
|
|
242
|
+
cdef char *c
|
|
243
|
+
sig_on()
|
|
244
|
+
# Use sig_block(), which is needed because GENtostr() uses
|
|
245
|
+
# malloc(), which is dangerous inside sig_on()
|
|
246
|
+
sig_block()
|
|
247
|
+
c = GENtostr(self.g)
|
|
248
|
+
sig_unblock()
|
|
249
|
+
sig_off()
|
|
250
|
+
|
|
251
|
+
s = bytes(c)
|
|
252
|
+
pari_free(c)
|
|
253
|
+
return to_string(s)
|
|
254
|
+
|
|
255
|
+
def __str__(self):
|
|
256
|
+
"""
|
|
257
|
+
Convert this Gen to a string.
|
|
258
|
+
|
|
259
|
+
Except for PARI strings, we have ``str(x) == repr(x)``.
|
|
260
|
+
For strings (type ``t_STR``), the returned string is not quoted.
|
|
261
|
+
|
|
262
|
+
OUTPUT: a Python string
|
|
263
|
+
|
|
264
|
+
Examples:
|
|
265
|
+
|
|
266
|
+
>>> from cypari2 import Pari
|
|
267
|
+
>>> pari = Pari()
|
|
268
|
+
>>> str(pari('vector(5,i,i)'))
|
|
269
|
+
'[1, 2, 3, 4, 5]'
|
|
270
|
+
>>> str(pari('[1,2;3,4]'))
|
|
271
|
+
'[1, 2; 3, 4]'
|
|
272
|
+
>>> str(pari('Str(hello)'))
|
|
273
|
+
'hello'
|
|
274
|
+
"""
|
|
275
|
+
# Use __repr__ except for strings
|
|
276
|
+
if typ(self.g) == t_STR:
|
|
277
|
+
return to_string(GSTR(self.g))
|
|
278
|
+
return repr(self)
|
|
279
|
+
|
|
280
|
+
def __hash__(self):
|
|
281
|
+
"""
|
|
282
|
+
Return the hash of self, computed using PARI's hash_GEN().
|
|
283
|
+
|
|
284
|
+
Tests:
|
|
285
|
+
|
|
286
|
+
>>> from cypari2 import Pari
|
|
287
|
+
>>> pari = Pari()
|
|
288
|
+
>>> type(pari('1 + 2.0*I').__hash__())
|
|
289
|
+
<... 'int'>
|
|
290
|
+
>>> L = pari("[42, 2/3, 3.14]")
|
|
291
|
+
>>> hash(L) == hash(L.__copy__())
|
|
292
|
+
True
|
|
293
|
+
>>> hash(pari.isprime(4)) == hash(pari(0))
|
|
294
|
+
True
|
|
295
|
+
"""
|
|
296
|
+
# There is a bug in PARI/GP where the hash value depends on the
|
|
297
|
+
# CLONE bit. So we remove that bit before hashing. See
|
|
298
|
+
# https://pari.math.u-bordeaux.fr/cgi-bin/bugreport.cgi?bug=2091
|
|
299
|
+
cdef ulong* G = <ulong*>self.g
|
|
300
|
+
cdef ulong G0 = G[0]
|
|
301
|
+
cdef ulong G0clean = G0 & ~<ulong>CLONEBIT
|
|
302
|
+
if G0 != G0clean:
|
|
303
|
+
# Only write if we actually need to change something, as
|
|
304
|
+
# G may point to read-only memory
|
|
305
|
+
G[0] = G0clean
|
|
306
|
+
h = hash_GEN(self.g)
|
|
307
|
+
if G0 != G0clean:
|
|
308
|
+
# Restore CLONE bit
|
|
309
|
+
G[0] = G0
|
|
310
|
+
return h
|
|
311
|
+
|
|
312
|
+
def __iter__(self):
|
|
313
|
+
"""
|
|
314
|
+
Iterate over the components of ``self``.
|
|
315
|
+
|
|
316
|
+
The items in the iteration are of type :class:`Gen` with the
|
|
317
|
+
following exceptions:
|
|
318
|
+
|
|
319
|
+
- items of a ``t_VECSMALL`` are of type ``int``
|
|
320
|
+
|
|
321
|
+
- items of a ``t_STR`` are of type ``str``
|
|
322
|
+
|
|
323
|
+
Examples:
|
|
324
|
+
|
|
325
|
+
We can iterate over PARI vectors or columns:
|
|
326
|
+
|
|
327
|
+
>>> from cypari2 import Pari
|
|
328
|
+
>>> pari = Pari()
|
|
329
|
+
>>> L = pari("vector(10,i,i^2)")
|
|
330
|
+
>>> L.__iter__()
|
|
331
|
+
<...generator object at ...>
|
|
332
|
+
>>> [x for x in L]
|
|
333
|
+
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
|
|
334
|
+
>>> list(L)
|
|
335
|
+
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
|
|
336
|
+
>>> list(pari("vector(10,i,i^2)~"))
|
|
337
|
+
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
|
|
338
|
+
|
|
339
|
+
For polynomials, we iterate over the list of coefficients:
|
|
340
|
+
|
|
341
|
+
>>> pol = pari("x^3 + 5/3*x"); list(pol)
|
|
342
|
+
[0, 5/3, 0, 1]
|
|
343
|
+
|
|
344
|
+
For power series or Laurent series, we get all coefficients starting
|
|
345
|
+
from the lowest degree term. This includes trailing zeros:
|
|
346
|
+
|
|
347
|
+
>>> list(pari('x^2 + O(x^8)'))
|
|
348
|
+
[1, 0, 0, 0, 0, 0]
|
|
349
|
+
>>> list(pari('x^-2 + O(x^0)'))
|
|
350
|
+
[1, 0]
|
|
351
|
+
|
|
352
|
+
For matrices, we iterate over the columns:
|
|
353
|
+
|
|
354
|
+
>>> M = pari.matrix(3,2,[1,4,2,5,3,6]); M
|
|
355
|
+
[1, 4; 2, 5; 3, 6]
|
|
356
|
+
>>> list(M)
|
|
357
|
+
[[1, 2, 3]~, [4, 5, 6]~]
|
|
358
|
+
|
|
359
|
+
Other types are first converted to a vector using :meth:`Vec`:
|
|
360
|
+
|
|
361
|
+
>>> Q = pari('Qfb(1, 2, 3)')
|
|
362
|
+
>>> tuple(Q)
|
|
363
|
+
(1, 2, 3)
|
|
364
|
+
>>> Q.Vec()
|
|
365
|
+
[1, 2, 3]
|
|
366
|
+
|
|
367
|
+
We get an error for "scalar" types or for types which cannot be
|
|
368
|
+
converted to a PARI vector:
|
|
369
|
+
|
|
370
|
+
>>> iter(pari(42))
|
|
371
|
+
Traceback (most recent call last):
|
|
372
|
+
...
|
|
373
|
+
TypeError: PARI object of type t_INT is not iterable
|
|
374
|
+
>>> iter(pari("x->x"))
|
|
375
|
+
Traceback (most recent call last):
|
|
376
|
+
...
|
|
377
|
+
PariError: incorrect type in gtovec (t_CLOSURE)
|
|
378
|
+
|
|
379
|
+
For ``t_VECSMALL``, the items are Python integers:
|
|
380
|
+
|
|
381
|
+
>>> v = pari("Vecsmall([1,2,3,4,5,6])")
|
|
382
|
+
>>> list(v)
|
|
383
|
+
[1, 2, 3, 4, 5, 6]
|
|
384
|
+
>>> type(list(v)[0]).__name__
|
|
385
|
+
'int'
|
|
386
|
+
|
|
387
|
+
For ``t_STR``, the items are Python strings:
|
|
388
|
+
|
|
389
|
+
>>> v = pari('"hello"')
|
|
390
|
+
>>> list(v)
|
|
391
|
+
['h', 'e', 'l', 'l', 'o']
|
|
392
|
+
"""
|
|
393
|
+
# We return a generator expression instead of using "yield"
|
|
394
|
+
# because we want to raise an exception for non-iterable
|
|
395
|
+
# objects immediately when calling __iter__() and not while
|
|
396
|
+
# iterating.
|
|
397
|
+
cdef long i
|
|
398
|
+
cdef long t = typ(self.g)
|
|
399
|
+
|
|
400
|
+
# First convert self to a vector type
|
|
401
|
+
cdef Gen v
|
|
402
|
+
if t == t_VEC or t == t_COL or t == t_MAT:
|
|
403
|
+
# These are vector-like and can be iterated over directly
|
|
404
|
+
v = self
|
|
405
|
+
elif t == t_POL:
|
|
406
|
+
v = self.Vecrev()
|
|
407
|
+
elif is_scalar_t(t):
|
|
408
|
+
raise TypeError(f"PARI object of type {self.type()} is not iterable")
|
|
409
|
+
elif t == t_VECSMALL:
|
|
410
|
+
# Special case: items of type int
|
|
411
|
+
return (self.g[i] for i in range(1, lg(self.g)))
|
|
412
|
+
elif t == t_STR:
|
|
413
|
+
# Special case: convert to str
|
|
414
|
+
return iter(to_string(GSTR(self.g)))
|
|
415
|
+
else:
|
|
416
|
+
v = self.Vec()
|
|
417
|
+
|
|
418
|
+
# Now iterate over the vector v
|
|
419
|
+
x = v.fixGEN()
|
|
420
|
+
return (v.new_ref(gel(x, i)) for i in range(1, lg(x)))
|
|
421
|
+
|
|
422
|
+
def list(self):
|
|
423
|
+
"""
|
|
424
|
+
Convert ``self`` to a Python list with :class:`Gen` components.
|
|
425
|
+
|
|
426
|
+
Examples:
|
|
427
|
+
|
|
428
|
+
A PARI vector becomes a Python list:
|
|
429
|
+
|
|
430
|
+
>>> from cypari2 import Pari
|
|
431
|
+
>>> pari = Pari()
|
|
432
|
+
|
|
433
|
+
>>> L = pari("vector(10,i,i^2)").list()
|
|
434
|
+
>>> L
|
|
435
|
+
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
|
|
436
|
+
>>> type(L)
|
|
437
|
+
<... 'list'>
|
|
438
|
+
>>> type(L[0])
|
|
439
|
+
<... 'cypari2.gen.Gen'>
|
|
440
|
+
|
|
441
|
+
For polynomials, list() returns the list of coefficients:
|
|
442
|
+
|
|
443
|
+
>>> pol = pari("x^3 + 5/3*x"); pol.list()
|
|
444
|
+
[0, 5/3, 0, 1]
|
|
445
|
+
|
|
446
|
+
For power series or Laurent series, we get all coefficients starting
|
|
447
|
+
from the lowest degree term. This includes trailing zeros:
|
|
448
|
+
|
|
449
|
+
>>> pari('x^2 + O(x^8)').list()
|
|
450
|
+
[1, 0, 0, 0, 0, 0]
|
|
451
|
+
>>> pari('x^-2 + O(x^0)').list()
|
|
452
|
+
[1, 0]
|
|
453
|
+
|
|
454
|
+
For matrices, we get a list of columns:
|
|
455
|
+
|
|
456
|
+
>>> M = pari.matrix(3,2,[1,4,2,5,3,6]); M
|
|
457
|
+
[1, 4; 2, 5; 3, 6]
|
|
458
|
+
>>> M.list()
|
|
459
|
+
[[1, 2, 3]~, [4, 5, 6]~]
|
|
460
|
+
"""
|
|
461
|
+
return [x for x in self]
|
|
462
|
+
|
|
463
|
+
def __reduce__(self):
|
|
464
|
+
"""
|
|
465
|
+
Examples:
|
|
466
|
+
|
|
467
|
+
>>> from cypari2 import Pari
|
|
468
|
+
>>> pari = Pari()
|
|
469
|
+
>>> from pickle import loads, dumps
|
|
470
|
+
|
|
471
|
+
>>> f = pari('x^3 - 3')
|
|
472
|
+
>>> loads(dumps(f)) == f
|
|
473
|
+
True
|
|
474
|
+
>>> f = pari('"hello world"')
|
|
475
|
+
>>> loads(dumps(f)) == f
|
|
476
|
+
True
|
|
477
|
+
"""
|
|
478
|
+
s = repr(self)
|
|
479
|
+
return (objtogen, (s,))
|
|
480
|
+
|
|
481
|
+
def __add__(left, right):
|
|
482
|
+
"""
|
|
483
|
+
Return ``left`` plus ``right``.
|
|
484
|
+
|
|
485
|
+
Examples:
|
|
486
|
+
|
|
487
|
+
>>> from cypari2 import Pari
|
|
488
|
+
>>> pari = Pari()
|
|
489
|
+
|
|
490
|
+
>>> pari(15) + pari(6)
|
|
491
|
+
21
|
|
492
|
+
>>> pari("x^3+x^2+x+1") + pari("x^2")
|
|
493
|
+
x^3 + 2*x^2 + x + 1
|
|
494
|
+
>>> 2e20 + pari("1e20")
|
|
495
|
+
3.00000000000000 E20
|
|
496
|
+
>>> -2 + pari(3)
|
|
497
|
+
1
|
|
498
|
+
"""
|
|
499
|
+
cdef Gen t0, t1
|
|
500
|
+
try:
|
|
501
|
+
t0 = objtogen(left)
|
|
502
|
+
t1 = objtogen(right)
|
|
503
|
+
except Exception:
|
|
504
|
+
return NotImplemented
|
|
505
|
+
sig_on()
|
|
506
|
+
return new_gen(gadd(t0.g, t1.g))
|
|
507
|
+
|
|
508
|
+
def __sub__(left, right):
|
|
509
|
+
"""
|
|
510
|
+
Return ``left`` minus ``right``.
|
|
511
|
+
|
|
512
|
+
Examples:
|
|
513
|
+
|
|
514
|
+
>>> from cypari2 import Pari
|
|
515
|
+
>>> pari = Pari()
|
|
516
|
+
|
|
517
|
+
>>> pari(15) - pari(6)
|
|
518
|
+
9
|
|
519
|
+
>>> pari("x^3+x^2+x+1") - pari("x^2")
|
|
520
|
+
x^3 + x + 1
|
|
521
|
+
>>> 2e20 - pari("1e20")
|
|
522
|
+
1.00000000000000 E20
|
|
523
|
+
>>> -2 - pari(3)
|
|
524
|
+
-5
|
|
525
|
+
"""
|
|
526
|
+
cdef Gen t0, t1
|
|
527
|
+
try:
|
|
528
|
+
t0 = objtogen(left)
|
|
529
|
+
t1 = objtogen(right)
|
|
530
|
+
except Exception:
|
|
531
|
+
return NotImplemented
|
|
532
|
+
sig_on()
|
|
533
|
+
return new_gen(gsub(t0.g, t1.g))
|
|
534
|
+
|
|
535
|
+
def __mul__(left, right):
|
|
536
|
+
cdef Gen t0, t1
|
|
537
|
+
try:
|
|
538
|
+
t0 = objtogen(left)
|
|
539
|
+
t1 = objtogen(right)
|
|
540
|
+
except Exception:
|
|
541
|
+
return NotImplemented
|
|
542
|
+
sig_on()
|
|
543
|
+
return new_gen(gmul(t0.g, t1.g))
|
|
544
|
+
|
|
545
|
+
def __div__(left, right):
|
|
546
|
+
# Python 2 old-style division: same implementation as __truediv__
|
|
547
|
+
cdef Gen t0, t1
|
|
548
|
+
try:
|
|
549
|
+
t0 = objtogen(left)
|
|
550
|
+
t1 = objtogen(right)
|
|
551
|
+
except Exception:
|
|
552
|
+
return NotImplemented
|
|
553
|
+
sig_on()
|
|
554
|
+
return new_gen(gdiv(t0.g, t1.g))
|
|
555
|
+
|
|
556
|
+
def __truediv__(left, right):
|
|
557
|
+
"""
|
|
558
|
+
Examples:
|
|
559
|
+
|
|
560
|
+
>>> from cypari2 import Pari; pari = Pari()
|
|
561
|
+
>>> pari(11) / pari(4)
|
|
562
|
+
11/4
|
|
563
|
+
>>> pari("x^2 + 2*x + 3") / pari("x")
|
|
564
|
+
(x^2 + 2*x + 3)/x
|
|
565
|
+
"""
|
|
566
|
+
cdef Gen t0, t1
|
|
567
|
+
try:
|
|
568
|
+
t0 = objtogen(left)
|
|
569
|
+
t1 = objtogen(right)
|
|
570
|
+
except Exception:
|
|
571
|
+
return NotImplemented
|
|
572
|
+
sig_on()
|
|
573
|
+
return new_gen(gdiv(t0.g, t1.g))
|
|
574
|
+
|
|
575
|
+
def __floordiv__(left, right):
|
|
576
|
+
"""
|
|
577
|
+
Examples:
|
|
578
|
+
|
|
579
|
+
>>> from cypari2 import Pari; pari = Pari()
|
|
580
|
+
>>> pari(11) // pari(4)
|
|
581
|
+
2
|
|
582
|
+
>>> pari("x^2 + 2*x + 3") // pari("x")
|
|
583
|
+
x + 2
|
|
584
|
+
"""
|
|
585
|
+
cdef Gen t0, t1
|
|
586
|
+
try:
|
|
587
|
+
t0 = objtogen(left)
|
|
588
|
+
t1 = objtogen(right)
|
|
589
|
+
except Exception:
|
|
590
|
+
return NotImplemented
|
|
591
|
+
sig_on()
|
|
592
|
+
return new_gen(gdivent(t0.g, t1.g))
|
|
593
|
+
|
|
594
|
+
def __mod__(left, right):
|
|
595
|
+
"""
|
|
596
|
+
Return ``left`` modulo ``right``.
|
|
597
|
+
|
|
598
|
+
Examples:
|
|
599
|
+
|
|
600
|
+
>>> from cypari2 import Pari
|
|
601
|
+
>>> pari = Pari()
|
|
602
|
+
|
|
603
|
+
>>> pari(15) % pari(6)
|
|
604
|
+
3
|
|
605
|
+
>>> pari("x^3+x^2+x+1") % pari("x^2")
|
|
606
|
+
x + 1
|
|
607
|
+
>>> pari(-2) % 3
|
|
608
|
+
1
|
|
609
|
+
>>> -2 % pari(3)
|
|
610
|
+
1
|
|
611
|
+
"""
|
|
612
|
+
cdef Gen t0, t1
|
|
613
|
+
try:
|
|
614
|
+
t0 = objtogen(left)
|
|
615
|
+
t1 = objtogen(right)
|
|
616
|
+
except Exception:
|
|
617
|
+
return NotImplemented
|
|
618
|
+
sig_on()
|
|
619
|
+
return new_gen(gmod(t0.g, t1.g))
|
|
620
|
+
|
|
621
|
+
def __pow__(left, right, m):
|
|
622
|
+
"""
|
|
623
|
+
Return ``left`` to the power ``right`` (if ``m`` is ``None``) or
|
|
624
|
+
``Mod(left, m)^right`` if ``m`` is not ``None``.
|
|
625
|
+
|
|
626
|
+
Examples:
|
|
627
|
+
|
|
628
|
+
>>> from cypari2 import Pari
|
|
629
|
+
>>> pari = Pari()
|
|
630
|
+
|
|
631
|
+
>>> pari(5) ** pari(3)
|
|
632
|
+
125
|
|
633
|
+
>>> pari("x-1") ** 3
|
|
634
|
+
x^3 - 3*x^2 + 3*x - 1
|
|
635
|
+
>>> pow(pari(5), pari(28), int(29))
|
|
636
|
+
Mod(1, 29)
|
|
637
|
+
>>> 2 ** pari(-5)
|
|
638
|
+
1/32
|
|
639
|
+
>>> pari(2) ** -5
|
|
640
|
+
1/32
|
|
641
|
+
"""
|
|
642
|
+
cdef Gen t0, t1
|
|
643
|
+
try:
|
|
644
|
+
t0 = objtogen(left)
|
|
645
|
+
t1 = objtogen(right)
|
|
646
|
+
except Exception:
|
|
647
|
+
return NotImplemented
|
|
648
|
+
if m is not None:
|
|
649
|
+
t0 = t0.Mod(m)
|
|
650
|
+
sig_on()
|
|
651
|
+
return new_gen(gpow(t0.g, t1.g, nbits2prec(DEFAULT_BITPREC)))
|
|
652
|
+
|
|
653
|
+
def __neg__(self):
|
|
654
|
+
sig_on()
|
|
655
|
+
return new_gen(gneg(self.g))
|
|
656
|
+
|
|
657
|
+
def __rshift__(self, long n):
|
|
658
|
+
"""
|
|
659
|
+
Divide ``self`` by `2^n` (truncating or not, depending on the
|
|
660
|
+
input type).
|
|
661
|
+
|
|
662
|
+
Examples:
|
|
663
|
+
|
|
664
|
+
>>> from cypari2 import Pari
|
|
665
|
+
>>> pari = Pari()
|
|
666
|
+
|
|
667
|
+
>>> pari(25) >> 3
|
|
668
|
+
3
|
|
669
|
+
>>> pari('25/2') >> 2
|
|
670
|
+
25/8
|
|
671
|
+
>>> pari("x") >> 3
|
|
672
|
+
1/8*x
|
|
673
|
+
>>> pari(1.0) >> 100
|
|
674
|
+
7.88860905221012 E-31
|
|
675
|
+
>>> 33 >> pari(2)
|
|
676
|
+
8
|
|
677
|
+
"""
|
|
678
|
+
cdef Gen t0 = objtogen(self)
|
|
679
|
+
sig_on()
|
|
680
|
+
return new_gen(gshift(t0.g, -n))
|
|
681
|
+
|
|
682
|
+
def __lshift__(self, long n):
|
|
683
|
+
"""
|
|
684
|
+
Multiply ``self`` by `2^n`.
|
|
685
|
+
|
|
686
|
+
Examples:
|
|
687
|
+
|
|
688
|
+
>>> from cypari2 import Pari
|
|
689
|
+
>>> pari = Pari()
|
|
690
|
+
|
|
691
|
+
>>> pari(25) << 3
|
|
692
|
+
200
|
|
693
|
+
>>> pari("25/32") << 2
|
|
694
|
+
25/8
|
|
695
|
+
>>> pari("x") << 3
|
|
696
|
+
8*x
|
|
697
|
+
>>> pari(1.0) << 100
|
|
698
|
+
1.26765060022823 E30
|
|
699
|
+
>>> 33 << pari(2)
|
|
700
|
+
132
|
|
701
|
+
"""
|
|
702
|
+
cdef Gen t0 = objtogen(self)
|
|
703
|
+
sig_on()
|
|
704
|
+
return new_gen(gshift(t0.g, n))
|
|
705
|
+
|
|
706
|
+
def __invert__(self):
|
|
707
|
+
sig_on()
|
|
708
|
+
return new_gen(ginv(self.g))
|
|
709
|
+
|
|
710
|
+
def getattr(self, attr):
|
|
711
|
+
"""
|
|
712
|
+
Return the PARI attribute with the given name.
|
|
713
|
+
|
|
714
|
+
Examples:
|
|
715
|
+
|
|
716
|
+
>>> from cypari2 import Pari
|
|
717
|
+
>>> pari = Pari()
|
|
718
|
+
|
|
719
|
+
>>> K = pari("nfinit(x^2 - x - 1)")
|
|
720
|
+
>>> K.getattr("pol")
|
|
721
|
+
x^2 - x - 1
|
|
722
|
+
>>> K.getattr("disc")
|
|
723
|
+
5
|
|
724
|
+
|
|
725
|
+
>>> K.getattr("reg")
|
|
726
|
+
Traceback (most recent call last):
|
|
727
|
+
...
|
|
728
|
+
PariError: _.reg: incorrect type in reg (t_VEC)
|
|
729
|
+
>>> K.getattr("zzz")
|
|
730
|
+
Traceback (most recent call last):
|
|
731
|
+
...
|
|
732
|
+
PariError: not a function in function call
|
|
733
|
+
"""
|
|
734
|
+
attr = to_bytes(attr)
|
|
735
|
+
t = b"_." + attr
|
|
736
|
+
sig_on()
|
|
737
|
+
return new_gen(closure_callgen1(strtofunction(t), self.g))
|
|
738
|
+
|
|
739
|
+
def mod(self):
|
|
740
|
+
"""
|
|
741
|
+
Given an INTMOD or POLMOD ``Mod(a,m)``, return the modulus `m`.
|
|
742
|
+
|
|
743
|
+
Examples:
|
|
744
|
+
|
|
745
|
+
>>> from cypari2 import Pari
|
|
746
|
+
>>> pari = Pari()
|
|
747
|
+
|
|
748
|
+
>>> pari(4).Mod(5).mod()
|
|
749
|
+
5
|
|
750
|
+
>>> pari("Mod(x, x*y)").mod()
|
|
751
|
+
y*x
|
|
752
|
+
>>> pari("[Mod(4,5)]").mod()
|
|
753
|
+
Traceback (most recent call last):
|
|
754
|
+
...
|
|
755
|
+
TypeError: Not an INTMOD or POLMOD in mod()
|
|
756
|
+
"""
|
|
757
|
+
if typ(self.g) != t_INTMOD and typ(self.g) != t_POLMOD:
|
|
758
|
+
raise TypeError("Not an INTMOD or POLMOD in mod()")
|
|
759
|
+
# The hardcoded 1 below refers to the position in the internal
|
|
760
|
+
# representation of a INTMOD or POLDMOD where the modulus is
|
|
761
|
+
# stored.
|
|
762
|
+
return self.new_ref(gel(self.fixGEN(), 1))
|
|
763
|
+
|
|
764
|
+
# Special case: SageMath uses polred(), so mark it as not
|
|
765
|
+
# obsolete: https://trac.sagemath.org/ticket/22165
|
|
766
|
+
def polred(self, *args, **kwds):
|
|
767
|
+
r'''
|
|
768
|
+
This function is :emphasis:`deprecated`,
|
|
769
|
+
use :meth:`~cypari2.gen.Gen_base.polredbest` instead.
|
|
770
|
+
'''
|
|
771
|
+
import warnings
|
|
772
|
+
with warnings.catch_warnings():
|
|
773
|
+
warnings.simplefilter("ignore")
|
|
774
|
+
return super(Gen, self).polred(*args, **kwds)
|
|
775
|
+
|
|
776
|
+
def nf_get_pol(self):
|
|
777
|
+
"""
|
|
778
|
+
Returns the defining polynomial of this number field.
|
|
779
|
+
|
|
780
|
+
INPUT:
|
|
781
|
+
|
|
782
|
+
- ``self`` -- A PARI number field being the output of ``nfinit()``,
|
|
783
|
+
``bnfinit()`` or ``bnrinit()``.
|
|
784
|
+
|
|
785
|
+
Examples:
|
|
786
|
+
|
|
787
|
+
>>> from cypari2 import Pari
|
|
788
|
+
>>> pari = Pari()
|
|
789
|
+
|
|
790
|
+
>>> x = pari('x')
|
|
791
|
+
>>> K = (x**4 - 4*x**2 + 1).bnfinit()
|
|
792
|
+
>>> bnr = K.bnrinit(2*x)
|
|
793
|
+
>>> bnr.nf_get_pol()
|
|
794
|
+
x^4 - 4*x^2 + 1
|
|
795
|
+
|
|
796
|
+
For relative number fields, this returns the relative
|
|
797
|
+
polynomial:
|
|
798
|
+
|
|
799
|
+
>>> y = pari.varhigher('y')
|
|
800
|
+
>>> L = K.rnfinit(y**2 - 5)
|
|
801
|
+
>>> L.nf_get_pol()
|
|
802
|
+
y^2 - 5
|
|
803
|
+
|
|
804
|
+
An error is raised for invalid input:
|
|
805
|
+
|
|
806
|
+
>>> pari("[0]").nf_get_pol()
|
|
807
|
+
Traceback (most recent call last):
|
|
808
|
+
...
|
|
809
|
+
PariError: incorrect type in pol (t_VEC)
|
|
810
|
+
"""
|
|
811
|
+
sig_on()
|
|
812
|
+
return clone_gen(member_pol(self.g))
|
|
813
|
+
|
|
814
|
+
def nf_get_diff(self):
|
|
815
|
+
"""
|
|
816
|
+
Returns the different of this number field as a PARI ideal.
|
|
817
|
+
|
|
818
|
+
INPUT:
|
|
819
|
+
|
|
820
|
+
- ``self`` -- A PARI number field being the output of ``nfinit()``,
|
|
821
|
+
``bnfinit()`` or ``bnrinit()``.
|
|
822
|
+
|
|
823
|
+
Examples:
|
|
824
|
+
|
|
825
|
+
>>> from cypari2 import Pari
|
|
826
|
+
>>> pari = Pari()
|
|
827
|
+
|
|
828
|
+
>>> x = pari('x')
|
|
829
|
+
>>> K = (x**4 - 4*x**2 + 1).nfinit()
|
|
830
|
+
>>> K.nf_get_diff()
|
|
831
|
+
[12, 0, 0, 0; 0, 12, 8, 0; 0, 0, 4, 0; 0, 0, 0, 4]
|
|
832
|
+
"""
|
|
833
|
+
sig_on()
|
|
834
|
+
return clone_gen(member_diff(self.g))
|
|
835
|
+
|
|
836
|
+
def nf_get_sign(self):
|
|
837
|
+
"""
|
|
838
|
+
Returns a Python list ``[r1, r2]``, where ``r1`` and ``r2`` are
|
|
839
|
+
Python ints representing the number of real embeddings and pairs
|
|
840
|
+
of complex embeddings of this number field, respectively.
|
|
841
|
+
|
|
842
|
+
INPUT:
|
|
843
|
+
|
|
844
|
+
- ``self`` -- A PARI number field being the output of ``nfinit()``,
|
|
845
|
+
``bnfinit()`` or ``bnrinit()``.
|
|
846
|
+
|
|
847
|
+
Examples:
|
|
848
|
+
|
|
849
|
+
>>> from cypari2 import Pari
|
|
850
|
+
>>> pari = Pari()
|
|
851
|
+
|
|
852
|
+
>>> x = pari('x')
|
|
853
|
+
>>> K = (x**4 - 4*x**2 + 1).nfinit()
|
|
854
|
+
>>> s = K.nf_get_sign(); s
|
|
855
|
+
[4, 0]
|
|
856
|
+
>>> type(s); type(s[0])
|
|
857
|
+
<... 'list'>
|
|
858
|
+
<... 'int'>
|
|
859
|
+
>>> pari.polcyclo(15).nfinit().nf_get_sign()
|
|
860
|
+
[0, 4]
|
|
861
|
+
"""
|
|
862
|
+
cdef long r1
|
|
863
|
+
cdef long r2
|
|
864
|
+
cdef GEN sign
|
|
865
|
+
sig_on()
|
|
866
|
+
sign = member_sign(self.g)
|
|
867
|
+
r1 = itos(gel(sign, 1))
|
|
868
|
+
r2 = itos(gel(sign, 2))
|
|
869
|
+
sig_off()
|
|
870
|
+
return [r1, r2]
|
|
871
|
+
|
|
872
|
+
def nf_get_zk(self):
|
|
873
|
+
r"""
|
|
874
|
+
Returns a vector with a `\ZZ`-basis for the ring of integers of
|
|
875
|
+
this number field. The first element is always `1`.
|
|
876
|
+
|
|
877
|
+
INPUT:
|
|
878
|
+
|
|
879
|
+
- ``self`` -- A PARI number field being the output of ``nfinit()``,
|
|
880
|
+
``bnfinit()`` or ``bnrinit()``.
|
|
881
|
+
|
|
882
|
+
Examples:
|
|
883
|
+
|
|
884
|
+
>>> from cypari2 import Pari
|
|
885
|
+
>>> pari = Pari()
|
|
886
|
+
|
|
887
|
+
>>> x = pari('x')
|
|
888
|
+
>>> K = (x**4 - 4*x**2 + 1).nfinit()
|
|
889
|
+
>>> K.nf_get_zk()
|
|
890
|
+
[1, x, x^3 - 4*x, x^2 - 2]
|
|
891
|
+
"""
|
|
892
|
+
sig_on()
|
|
893
|
+
return clone_gen(member_zk(self.g))
|
|
894
|
+
|
|
895
|
+
def bnf_get_fu(self):
|
|
896
|
+
"""
|
|
897
|
+
Return the fundamental units
|
|
898
|
+
|
|
899
|
+
Examples:
|
|
900
|
+
|
|
901
|
+
>>> from cypari2 import Pari
|
|
902
|
+
>>> pari = Pari()
|
|
903
|
+
|
|
904
|
+
>>> x = pari('x')
|
|
905
|
+
|
|
906
|
+
>>> pari.setrand(1)
|
|
907
|
+
>>> (x**2 - 65).bnfinit().bnf_get_fu()
|
|
908
|
+
[Mod(x - 8, x^2 - 65)]
|
|
909
|
+
>>> (x**4 - x**2 + 1).bnfinit().bnf_get_fu()
|
|
910
|
+
[Mod(x - 1, x^4 - x^2 + 1)]
|
|
911
|
+
>>> p = x**8 - 40*x**6 + 352*x**4 - 960*x**2 + 576
|
|
912
|
+
>>> len(p.bnfinit().bnf_get_fu())
|
|
913
|
+
7
|
|
914
|
+
"""
|
|
915
|
+
sig_on()
|
|
916
|
+
return clone_gen(member_fu(self.g))
|
|
917
|
+
|
|
918
|
+
def bnf_get_tu(self):
|
|
919
|
+
r"""
|
|
920
|
+
Return the torsion unit
|
|
921
|
+
|
|
922
|
+
Examples:
|
|
923
|
+
|
|
924
|
+
>>> from cypari2 import Pari
|
|
925
|
+
>>> pari = Pari()
|
|
926
|
+
|
|
927
|
+
>>> x = pari('x')
|
|
928
|
+
|
|
929
|
+
>>> for p in [x**2 - 65, x**4 - x**2 + 1, x**8 - 40*x**6 + 352*x**4 - 960*x**2 + 576]:
|
|
930
|
+
... bnf = p.bnfinit()
|
|
931
|
+
... n, z = bnf.bnf_get_tu()
|
|
932
|
+
... if pari.version() < (2,11,0) and z.lift().poldegree() == 0: z = z.lift()
|
|
933
|
+
... print([p, n, z])
|
|
934
|
+
[x^2 - 65, 2, -1]
|
|
935
|
+
[x^4 - x^2 + 1, 12, Mod(x, x^4 - x^2 + 1)]
|
|
936
|
+
[x^8 - 40*x^6 + 352*x^4 - 960*x^2 + 576, 2, -1]
|
|
937
|
+
"""
|
|
938
|
+
sig_on()
|
|
939
|
+
return clone_gen(member_tu(self.g))
|
|
940
|
+
|
|
941
|
+
def bnfunit(self):
|
|
942
|
+
r"""
|
|
943
|
+
Deprecated in cypari 2.1.2
|
|
944
|
+
|
|
945
|
+
Examples:
|
|
946
|
+
|
|
947
|
+
>>> from cypari2 import Pari
|
|
948
|
+
>>> pari = Pari()
|
|
949
|
+
|
|
950
|
+
|
|
951
|
+
>>> x = pari('x')
|
|
952
|
+
|
|
953
|
+
>>> import warnings
|
|
954
|
+
>>> with warnings.catch_warnings(record=True) as w:
|
|
955
|
+
... warnings.simplefilter('always')
|
|
956
|
+
... pari.setrand(1)
|
|
957
|
+
... funits = (x**2 - 65).bnfinit().bnfunit()
|
|
958
|
+
... assert len(w) == 1
|
|
959
|
+
... assert issubclass(w[0].category, DeprecationWarning)
|
|
960
|
+
>>> funits
|
|
961
|
+
[Mod(x - 8, x^2 - 65)]
|
|
962
|
+
"""
|
|
963
|
+
from warnings import warn
|
|
964
|
+
warn("'bnfunit' in cypari2 is deprecated, use 'bnf_get_fu'", DeprecationWarning)
|
|
965
|
+
return self.bnf_get_fu()
|
|
966
|
+
|
|
967
|
+
def bnf_get_no(self):
|
|
968
|
+
"""
|
|
969
|
+
Returns the class number of ``self``, a "big number field" (``bnf``).
|
|
970
|
+
|
|
971
|
+
Examples:
|
|
972
|
+
|
|
973
|
+
>>> from cypari2 import Pari
|
|
974
|
+
>>> pari = Pari()
|
|
975
|
+
|
|
976
|
+
>>> x = pari('x')
|
|
977
|
+
>>> K = (x**2 + 65).bnfinit()
|
|
978
|
+
>>> K.bnf_get_no()
|
|
979
|
+
8
|
|
980
|
+
"""
|
|
981
|
+
sig_on()
|
|
982
|
+
return clone_gen(bnf_get_no(self.g))
|
|
983
|
+
|
|
984
|
+
def bnf_get_cyc(self):
|
|
985
|
+
"""
|
|
986
|
+
Returns the structure of the class group of this number field as
|
|
987
|
+
a vector of SNF invariants.
|
|
988
|
+
|
|
989
|
+
NOTE: ``self`` must be a "big number field" (``bnf``).
|
|
990
|
+
|
|
991
|
+
Examples:
|
|
992
|
+
|
|
993
|
+
>>> from cypari2 import Pari
|
|
994
|
+
>>> pari = Pari()
|
|
995
|
+
|
|
996
|
+
>>> x = pari('x')
|
|
997
|
+
>>> K = (x**2 + 65).bnfinit()
|
|
998
|
+
>>> K.bnf_get_cyc()
|
|
999
|
+
[4, 2]
|
|
1000
|
+
"""
|
|
1001
|
+
sig_on()
|
|
1002
|
+
return clone_gen(bnf_get_cyc(self.g))
|
|
1003
|
+
|
|
1004
|
+
def bnf_get_gen(self):
|
|
1005
|
+
"""
|
|
1006
|
+
Returns a vector of generators of the class group of this
|
|
1007
|
+
number field.
|
|
1008
|
+
|
|
1009
|
+
NOTE: ``self`` must be a "big number field" (``bnf``).
|
|
1010
|
+
|
|
1011
|
+
Examples:
|
|
1012
|
+
|
|
1013
|
+
>>> from cypari2 import Pari
|
|
1014
|
+
>>> pari = Pari()
|
|
1015
|
+
|
|
1016
|
+
>>> x = pari('x')
|
|
1017
|
+
>>> K = (x**2 + 65).bnfinit()
|
|
1018
|
+
>>> G = K.bnf_get_gen(); G
|
|
1019
|
+
[[3, 2; 0, 1], [2, 1; 0, 1]]
|
|
1020
|
+
"""
|
|
1021
|
+
sig_on()
|
|
1022
|
+
return clone_gen(bnf_get_gen(self.g))
|
|
1023
|
+
|
|
1024
|
+
def bnf_get_reg(self):
|
|
1025
|
+
"""
|
|
1026
|
+
Returns the regulator of this number field.
|
|
1027
|
+
|
|
1028
|
+
NOTE: ``self`` must be a "big number field" (``bnf``).
|
|
1029
|
+
|
|
1030
|
+
Examples:
|
|
1031
|
+
|
|
1032
|
+
>>> from cypari2 import Pari
|
|
1033
|
+
>>> pari = Pari()
|
|
1034
|
+
|
|
1035
|
+
>>> x = pari('x')
|
|
1036
|
+
>>> K = (x**4 - 4*x**2 + 1).bnfinit()
|
|
1037
|
+
>>> K.bnf_get_reg()
|
|
1038
|
+
2.66089858019037...
|
|
1039
|
+
"""
|
|
1040
|
+
sig_on()
|
|
1041
|
+
return clone_gen(bnf_get_reg(self.g))
|
|
1042
|
+
|
|
1043
|
+
def idealmoddivisor(self, Gen ideal):
|
|
1044
|
+
"""
|
|
1045
|
+
Return a 'small' ideal equivalent to ``ideal`` in the
|
|
1046
|
+
ray class group that the bnr structure ``self`` encodes.
|
|
1047
|
+
|
|
1048
|
+
INPUT:
|
|
1049
|
+
|
|
1050
|
+
- ``self`` -- a bnr structure as outputted from bnrinit.
|
|
1051
|
+
- ``ideal`` -- an ideal in the underlying number field of
|
|
1052
|
+
the bnr structure.
|
|
1053
|
+
|
|
1054
|
+
OUTPUT: An ideal representing the same ray class as ``ideal``
|
|
1055
|
+
but with 'small' generators. If ``ideal`` is not coprime to
|
|
1056
|
+
the modulus of the bnr, this results in an error.
|
|
1057
|
+
|
|
1058
|
+
Examples:
|
|
1059
|
+
|
|
1060
|
+
>>> from cypari2 import Pari
|
|
1061
|
+
>>> pari = Pari()
|
|
1062
|
+
>>> i = pari('i')
|
|
1063
|
+
>>> K = (i**4 - 2).bnfinit()
|
|
1064
|
+
>>> R = K.bnrinit(5,1)
|
|
1065
|
+
>>> R.idealmoddivisor(K[6][6][1])
|
|
1066
|
+
[2, 0, 0, 0; 0, 1, 0, 0; 0, 0, 1, 0; 0, 0, 0, 1]
|
|
1067
|
+
>>> R.idealmoddivisor(K.idealhnf(5))
|
|
1068
|
+
Traceback (most recent call last):
|
|
1069
|
+
...
|
|
1070
|
+
PariError: elements not coprime in idealaddtoone:
|
|
1071
|
+
[5, 0, 0, 0; 0, 5, 0, 0; 0, 0, 5, 0; 0, 0, 0, 5]
|
|
1072
|
+
[5, 0, 0, 0; 0, 5, 0, 0; 0, 0, 5, 0; 0, 0, 0, 5]
|
|
1073
|
+
"""
|
|
1074
|
+
sig_on()
|
|
1075
|
+
return new_gen(idealmoddivisor(self.g, ideal.g))
|
|
1076
|
+
|
|
1077
|
+
def pr_get_p(self):
|
|
1078
|
+
r"""
|
|
1079
|
+
Returns the prime of `\ZZ` lying below this prime ideal.
|
|
1080
|
+
|
|
1081
|
+
NOTE: ``self`` must be a PARI prime ideal (as returned by
|
|
1082
|
+
``idealprimedec`` for example).
|
|
1083
|
+
|
|
1084
|
+
Examples:
|
|
1085
|
+
|
|
1086
|
+
>>> from cypari2 import Pari
|
|
1087
|
+
>>> pari = Pari()
|
|
1088
|
+
|
|
1089
|
+
>>> i = pari('i')
|
|
1090
|
+
>>> K = (i**2 + 1).nfinit()
|
|
1091
|
+
>>> F = K.idealprimedec(5); F
|
|
1092
|
+
[[5, [-2, 1]~, 1, 1, [2, -1; 1, 2]], [5, [2, 1]~, 1, 1, [-2, -1; 1, -2]]]
|
|
1093
|
+
>>> F[0].pr_get_p()
|
|
1094
|
+
5
|
|
1095
|
+
"""
|
|
1096
|
+
sig_on()
|
|
1097
|
+
return clone_gen(pr_get_p(self.g))
|
|
1098
|
+
|
|
1099
|
+
def pr_get_e(self):
|
|
1100
|
+
r"""
|
|
1101
|
+
Returns the ramification index (over `\QQ`) of this prime ideal.
|
|
1102
|
+
|
|
1103
|
+
NOTE: ``self`` must be a PARI prime ideal (as returned by
|
|
1104
|
+
``idealprimedec`` for example).
|
|
1105
|
+
|
|
1106
|
+
Examples:
|
|
1107
|
+
|
|
1108
|
+
>>> from cypari2 import Pari
|
|
1109
|
+
>>> pari = Pari()
|
|
1110
|
+
|
|
1111
|
+
>>> i = pari('i')
|
|
1112
|
+
>>> K = (i**2 + 1).nfinit()
|
|
1113
|
+
>>> K.idealprimedec(2)[0].pr_get_e()
|
|
1114
|
+
2
|
|
1115
|
+
>>> K.idealprimedec(3)[0].pr_get_e()
|
|
1116
|
+
1
|
|
1117
|
+
>>> K.idealprimedec(5)[0].pr_get_e()
|
|
1118
|
+
1
|
|
1119
|
+
"""
|
|
1120
|
+
cdef long e
|
|
1121
|
+
sig_on()
|
|
1122
|
+
e = pr_get_e(self.g)
|
|
1123
|
+
sig_off()
|
|
1124
|
+
return e
|
|
1125
|
+
|
|
1126
|
+
def pr_get_f(self):
|
|
1127
|
+
r"""
|
|
1128
|
+
Returns the residue class degree (over `\QQ`) of this prime ideal.
|
|
1129
|
+
|
|
1130
|
+
NOTE: ``self`` must be a PARI prime ideal (as returned by
|
|
1131
|
+
``idealprimedec`` for example).
|
|
1132
|
+
|
|
1133
|
+
Examples:
|
|
1134
|
+
|
|
1135
|
+
>>> from cypari2 import Pari
|
|
1136
|
+
>>> pari = Pari()
|
|
1137
|
+
|
|
1138
|
+
>>> i = pari('i')
|
|
1139
|
+
>>> K = (i**2 + 1).nfinit()
|
|
1140
|
+
>>> K.idealprimedec(2)[0].pr_get_f()
|
|
1141
|
+
1
|
|
1142
|
+
>>> K.idealprimedec(3)[0].pr_get_f()
|
|
1143
|
+
2
|
|
1144
|
+
>>> K.idealprimedec(5)[0].pr_get_f()
|
|
1145
|
+
1
|
|
1146
|
+
"""
|
|
1147
|
+
cdef long f
|
|
1148
|
+
sig_on()
|
|
1149
|
+
f = pr_get_f(self.g)
|
|
1150
|
+
sig_off()
|
|
1151
|
+
return f
|
|
1152
|
+
|
|
1153
|
+
def pr_get_gen(self):
|
|
1154
|
+
"""
|
|
1155
|
+
Returns the second generator of this PARI prime ideal, where the
|
|
1156
|
+
first generator is ``self.pr_get_p()``.
|
|
1157
|
+
|
|
1158
|
+
NOTE: ``self`` must be a PARI prime ideal (as returned by
|
|
1159
|
+
``idealprimedec`` for example).
|
|
1160
|
+
|
|
1161
|
+
Examples:
|
|
1162
|
+
|
|
1163
|
+
>>> from cypari2 import Pari
|
|
1164
|
+
>>> pari = Pari()
|
|
1165
|
+
|
|
1166
|
+
>>> i = pari('i')
|
|
1167
|
+
>>> K = (i**2 + 1).nfinit()
|
|
1168
|
+
>>> g = K.idealprimedec(2)[0].pr_get_gen(); g
|
|
1169
|
+
[1, 1]~
|
|
1170
|
+
>>> g = K.idealprimedec(3)[0].pr_get_gen(); g
|
|
1171
|
+
[3, 0]~
|
|
1172
|
+
>>> g = K.idealprimedec(5)[0].pr_get_gen(); g
|
|
1173
|
+
[-2, 1]~
|
|
1174
|
+
"""
|
|
1175
|
+
sig_on()
|
|
1176
|
+
return clone_gen(pr_get_gen(self.g))
|
|
1177
|
+
|
|
1178
|
+
def bid_get_cyc(self):
|
|
1179
|
+
"""
|
|
1180
|
+
Returns the structure of the group `(O_K/I)^*`, where `I` is the
|
|
1181
|
+
ideal represented by ``self``.
|
|
1182
|
+
|
|
1183
|
+
NOTE: ``self`` must be a "big ideal" (``bid``) as returned by
|
|
1184
|
+
``idealstar`` for example.
|
|
1185
|
+
|
|
1186
|
+
Examples:
|
|
1187
|
+
|
|
1188
|
+
>>> from cypari2 import Pari
|
|
1189
|
+
>>> pari = Pari()
|
|
1190
|
+
|
|
1191
|
+
>>> i = pari('i')
|
|
1192
|
+
>>> K = (i**2 + 1).bnfinit()
|
|
1193
|
+
>>> J = K.idealstar(4*i + 2)
|
|
1194
|
+
>>> J.bid_get_cyc()
|
|
1195
|
+
[4, 2]
|
|
1196
|
+
"""
|
|
1197
|
+
sig_on()
|
|
1198
|
+
return clone_gen(bid_get_cyc(self.g))
|
|
1199
|
+
|
|
1200
|
+
def bid_get_gen(self):
|
|
1201
|
+
"""
|
|
1202
|
+
Returns a vector of generators of the group `(O_K/I)^*`, where
|
|
1203
|
+
`I` is the ideal represented by ``self``.
|
|
1204
|
+
|
|
1205
|
+
NOTE: ``self`` must be a "big ideal" (``bid``) with generators,
|
|
1206
|
+
as returned by ``idealstar`` with ``flag`` = 2.
|
|
1207
|
+
|
|
1208
|
+
Examples:
|
|
1209
|
+
|
|
1210
|
+
>>> from cypari2 import Pari
|
|
1211
|
+
>>> pari = Pari()
|
|
1212
|
+
|
|
1213
|
+
>>> i = pari('i')
|
|
1214
|
+
>>> K = (i**2 + 1).bnfinit()
|
|
1215
|
+
>>> J = K.idealstar(4*i + 2, 2)
|
|
1216
|
+
>>> J.bid_get_gen()
|
|
1217
|
+
[7, [-2, -1]~]
|
|
1218
|
+
|
|
1219
|
+
We get an exception if we do not supply ``flag = 2`` to
|
|
1220
|
+
``idealstar``:
|
|
1221
|
+
|
|
1222
|
+
>>> J = K.idealstar(3)
|
|
1223
|
+
>>> J.bid_get_gen()
|
|
1224
|
+
Traceback (most recent call last):
|
|
1225
|
+
...
|
|
1226
|
+
PariError: missing bid generators. Use idealstar(,,2)
|
|
1227
|
+
"""
|
|
1228
|
+
sig_on()
|
|
1229
|
+
return clone_gen(bid_get_gen(self.g))
|
|
1230
|
+
|
|
1231
|
+
def __getitem__(self, n):
|
|
1232
|
+
"""
|
|
1233
|
+
Return the n-th entry of self.
|
|
1234
|
+
|
|
1235
|
+
.. NOTE::
|
|
1236
|
+
|
|
1237
|
+
The indexing is 0-based, like everywhere else in Python,
|
|
1238
|
+
but *unlike* in PARI/GP.
|
|
1239
|
+
|
|
1240
|
+
Examples:
|
|
1241
|
+
|
|
1242
|
+
>>> from cypari2 import Pari
|
|
1243
|
+
>>> pari = Pari()
|
|
1244
|
+
|
|
1245
|
+
>>> p = pari('1 + 2*x + 3*x^2')
|
|
1246
|
+
>>> p[0]
|
|
1247
|
+
1
|
|
1248
|
+
>>> p[2]
|
|
1249
|
+
3
|
|
1250
|
+
>>> p[100]
|
|
1251
|
+
0
|
|
1252
|
+
>>> p[-1]
|
|
1253
|
+
0
|
|
1254
|
+
>>> q = pari('x^2 + 3*x^3 + O(x^6)')
|
|
1255
|
+
>>> q[3]
|
|
1256
|
+
3
|
|
1257
|
+
>>> q[5]
|
|
1258
|
+
0
|
|
1259
|
+
>>> q[6]
|
|
1260
|
+
Traceback (most recent call last):
|
|
1261
|
+
...
|
|
1262
|
+
IndexError: index out of range
|
|
1263
|
+
>>> m = pari('[1,2;3,4]')
|
|
1264
|
+
>>> m[0]
|
|
1265
|
+
[1, 3]~
|
|
1266
|
+
>>> m[1,0]
|
|
1267
|
+
3
|
|
1268
|
+
>>> l = pari('List([1,2,3])')
|
|
1269
|
+
>>> l[1]
|
|
1270
|
+
2
|
|
1271
|
+
>>> s = pari('"hello, world!"')
|
|
1272
|
+
>>> s[0]
|
|
1273
|
+
'h'
|
|
1274
|
+
>>> s[4]
|
|
1275
|
+
'o'
|
|
1276
|
+
>>> s[12]
|
|
1277
|
+
'!'
|
|
1278
|
+
>>> s[13]
|
|
1279
|
+
Traceback (most recent call last):
|
|
1280
|
+
...
|
|
1281
|
+
IndexError: index out of range
|
|
1282
|
+
>>> v = pari('[1,2,3]')
|
|
1283
|
+
>>> v[0]
|
|
1284
|
+
1
|
|
1285
|
+
>>> c = pari('Col([1,2,3])')
|
|
1286
|
+
>>> c[1]
|
|
1287
|
+
2
|
|
1288
|
+
>>> sv = pari('Vecsmall([1,2,3])')
|
|
1289
|
+
>>> sv[2]
|
|
1290
|
+
3
|
|
1291
|
+
>>> type(sv[2])
|
|
1292
|
+
<... 'int'>
|
|
1293
|
+
>>> [pari('1 + 5*I')[i] for i in range(2)]
|
|
1294
|
+
[1, 5]
|
|
1295
|
+
>>> [pari('Qfb(1, 2, 3)')[i] for i in range(3)]
|
|
1296
|
+
[1, 2, 3]
|
|
1297
|
+
>>> pari(57)[0]
|
|
1298
|
+
Traceback (most recent call last):
|
|
1299
|
+
...
|
|
1300
|
+
TypeError: PARI object of type t_INT cannot be indexed
|
|
1301
|
+
>>> m = pari("[[1,2;3,4],5]") ; m[0][1,0]
|
|
1302
|
+
3
|
|
1303
|
+
>>> v = pari(range(20))
|
|
1304
|
+
>>> v[2:5]
|
|
1305
|
+
[2, 3, 4]
|
|
1306
|
+
>>> v[:]
|
|
1307
|
+
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
|
|
1308
|
+
>>> v[10:]
|
|
1309
|
+
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
|
|
1310
|
+
>>> v[:5]
|
|
1311
|
+
[0, 1, 2, 3, 4]
|
|
1312
|
+
>>> v[5:5]
|
|
1313
|
+
[]
|
|
1314
|
+
>>> v
|
|
1315
|
+
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
|
|
1316
|
+
>>> v[-1]
|
|
1317
|
+
Traceback (most recent call last):
|
|
1318
|
+
...
|
|
1319
|
+
IndexError: index out of range
|
|
1320
|
+
>>> v[:-3]
|
|
1321
|
+
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
|
|
1322
|
+
>>> v[5:]
|
|
1323
|
+
[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
|
|
1324
|
+
>>> pari([])[::]
|
|
1325
|
+
[]
|
|
1326
|
+
"""
|
|
1327
|
+
cdef Py_ssize_t i, j, k
|
|
1328
|
+
cdef object ind
|
|
1329
|
+
cdef int pari_type
|
|
1330
|
+
|
|
1331
|
+
pari_type = typ(self.g)
|
|
1332
|
+
|
|
1333
|
+
if isinstance(n, tuple):
|
|
1334
|
+
if pari_type != t_MAT:
|
|
1335
|
+
raise TypeError("tuple indices are only defined for matrices")
|
|
1336
|
+
|
|
1337
|
+
i, j = n
|
|
1338
|
+
|
|
1339
|
+
if i < 0 or i >= glength(gel(self.g, 1)):
|
|
1340
|
+
raise IndexError("row index out of range")
|
|
1341
|
+
if j < 0 or j >= glength(self.g):
|
|
1342
|
+
raise IndexError("column index out of range")
|
|
1343
|
+
|
|
1344
|
+
ind = (i, j)
|
|
1345
|
+
|
|
1346
|
+
if self.itemcache is not None and ind in self.itemcache:
|
|
1347
|
+
return self.itemcache[ind]
|
|
1348
|
+
else:
|
|
1349
|
+
# Create a new Gen as child of self
|
|
1350
|
+
# and store it in itemcache
|
|
1351
|
+
val = self.new_ref(gmael(self.fixGEN(), j+1, i+1))
|
|
1352
|
+
self.cache(ind, val)
|
|
1353
|
+
return val
|
|
1354
|
+
|
|
1355
|
+
elif isinstance(n, slice):
|
|
1356
|
+
l = glength(self.g)
|
|
1357
|
+
start, stop, step = n.indices(l)
|
|
1358
|
+
inds = xrange(start, stop, step)
|
|
1359
|
+
k = len(inds)
|
|
1360
|
+
# fast exit for empty vector
|
|
1361
|
+
if k == 0:
|
|
1362
|
+
sig_on()
|
|
1363
|
+
return new_gen(zerovec(0))
|
|
1364
|
+
# fast call, beware pari is one based
|
|
1365
|
+
if pari_type == t_VEC:
|
|
1366
|
+
if step==1:
|
|
1367
|
+
return self.vecextract('"'+str(start+1)+".."+str(stop)+'"')
|
|
1368
|
+
if step==-1:
|
|
1369
|
+
return self.vecextract('"'+str(start+1)+".."+str(stop+2)+'"')
|
|
1370
|
+
# slow call
|
|
1371
|
+
return objtogen(self[i] for i in inds)
|
|
1372
|
+
|
|
1373
|
+
# Index is not a tuple or slice, convert to integer
|
|
1374
|
+
i = n
|
|
1375
|
+
|
|
1376
|
+
# there are no "out of bounds" problems
|
|
1377
|
+
# for a polynomial or power series, so these go before
|
|
1378
|
+
# bounds testing
|
|
1379
|
+
if pari_type == t_POL:
|
|
1380
|
+
sig_on()
|
|
1381
|
+
return new_gen(polcoeff0(self.g, i, -1))
|
|
1382
|
+
|
|
1383
|
+
elif pari_type == t_SER:
|
|
1384
|
+
bound = valp(self.g) + lg(self.g) - 2
|
|
1385
|
+
if i >= bound:
|
|
1386
|
+
raise IndexError("index out of range")
|
|
1387
|
+
sig_on()
|
|
1388
|
+
return new_gen(polcoeff0(self.g, i, -1))
|
|
1389
|
+
|
|
1390
|
+
elif pari_type in (t_INT, t_REAL, t_FRAC, t_RFRAC, t_PADIC, t_QUAD, t_FFELT, t_INTMOD, t_POLMOD):
|
|
1391
|
+
# these are definitely scalar!
|
|
1392
|
+
raise TypeError(f"PARI object of type {self.type()} cannot be indexed")
|
|
1393
|
+
|
|
1394
|
+
elif i < 0 or i >= glength(self.g):
|
|
1395
|
+
raise IndexError("index out of range")
|
|
1396
|
+
|
|
1397
|
+
elif pari_type == t_VEC or pari_type == t_MAT:
|
|
1398
|
+
# t_VEC : row vector [ code ] [ x_1 ] ... [ x_k ]
|
|
1399
|
+
# t_MAT : matrix [ code ] [ col_1 ] ... [ col_k ]
|
|
1400
|
+
ind = i
|
|
1401
|
+
if self.itemcache is not None and ind in self.itemcache:
|
|
1402
|
+
return self.itemcache[ind]
|
|
1403
|
+
else:
|
|
1404
|
+
# Create a new Gen as child of self
|
|
1405
|
+
# and store it in itemcache
|
|
1406
|
+
val = self.new_ref(gel(self.fixGEN(), i+1))
|
|
1407
|
+
self.cache(ind, val)
|
|
1408
|
+
return val
|
|
1409
|
+
|
|
1410
|
+
elif pari_type == t_VECSMALL:
|
|
1411
|
+
# t_VECSMALL: vec. small ints [ code ] [ x_1 ] ... [ x_k ]
|
|
1412
|
+
return self.g[i+1]
|
|
1413
|
+
|
|
1414
|
+
elif pari_type == t_STR:
|
|
1415
|
+
# t_STR : string [ code ] [ man_1 ] ... [ man_k ]
|
|
1416
|
+
return chr(GSTR(self.g)[i])
|
|
1417
|
+
|
|
1418
|
+
elif pari_type == t_LIST:
|
|
1419
|
+
return self.component(i+1)
|
|
1420
|
+
|
|
1421
|
+
else:
|
|
1422
|
+
# generic code for other types
|
|
1423
|
+
return self.new_ref(gel(self.fixGEN(), i+1))
|
|
1424
|
+
|
|
1425
|
+
def __setitem__(self, n, y):
|
|
1426
|
+
r"""
|
|
1427
|
+
Set the n-th entry to a reference to y.
|
|
1428
|
+
|
|
1429
|
+
.. NOTE::
|
|
1430
|
+
|
|
1431
|
+
- The indexing is 0-based, like everywhere else in Python,
|
|
1432
|
+
but *unlike* in PARI/GP.
|
|
1433
|
+
|
|
1434
|
+
- Assignment sets the nth entry to a reference to y. This is
|
|
1435
|
+
the same as in Python, but *different* than what happens in
|
|
1436
|
+
the GP interpreter, where assignment makes a copy of y.
|
|
1437
|
+
|
|
1438
|
+
- Because setting creates references it is *possible* to make
|
|
1439
|
+
circular references, unlike in GP. Do *not* do this (see the
|
|
1440
|
+
example below). If you need circular references, work at the
|
|
1441
|
+
Python level (where they work well), not the PARI object
|
|
1442
|
+
level.
|
|
1443
|
+
|
|
1444
|
+
Examples:
|
|
1445
|
+
|
|
1446
|
+
>>> from cypari2 import Pari
|
|
1447
|
+
>>> pari = Pari()
|
|
1448
|
+
|
|
1449
|
+
>>> l = pari.List([1,2,3])
|
|
1450
|
+
>>> l[0] = 3
|
|
1451
|
+
>>> l
|
|
1452
|
+
List([3, 2, 3])
|
|
1453
|
+
|
|
1454
|
+
>>> v = pari(range(10))
|
|
1455
|
+
>>> v
|
|
1456
|
+
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
1457
|
+
>>> v[0] = 10
|
|
1458
|
+
>>> w = pari([5,8,-20])
|
|
1459
|
+
>>> v
|
|
1460
|
+
[10, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
1461
|
+
>>> v[1] = w
|
|
1462
|
+
>>> v
|
|
1463
|
+
[10, [5, 8, -20], 2, 3, 4, 5, 6, 7, 8, 9]
|
|
1464
|
+
>>> w[0] = -30
|
|
1465
|
+
>>> v
|
|
1466
|
+
[10, [-30, 8, -20], 2, 3, 4, 5, 6, 7, 8, 9]
|
|
1467
|
+
>>> t = v[1]; t[1] = 10 ; v
|
|
1468
|
+
[10, [-30, 10, -20], 2, 3, 4, 5, 6, 7, 8, 9]
|
|
1469
|
+
>>> v[1][0] = 54321 ; v
|
|
1470
|
+
[10, [54321, 10, -20], 2, 3, 4, 5, 6, 7, 8, 9]
|
|
1471
|
+
>>> w
|
|
1472
|
+
[54321, 10, -20]
|
|
1473
|
+
>>> v = pari([[[[0,1],2],3],4])
|
|
1474
|
+
>>> v[0][0][0][1] = 12
|
|
1475
|
+
>>> v
|
|
1476
|
+
[[[[0, 12], 2], 3], 4]
|
|
1477
|
+
>>> m = pari.matrix(2,2,range(4)) ; l = pari([5,6]) ; n = pari.matrix(2,2,[7,8,9,0]) ; m[1,0] = l ; l[1] = n ; m[1,0][1][1,1] = 1111 ; m
|
|
1478
|
+
[0, 1; [5, [7, 8; 9, 1111]], 3]
|
|
1479
|
+
>>> m = pari("[[1,2;3,4],5,6]") ; m[0][1,1] = 11 ; m
|
|
1480
|
+
[[1, 2; 3, 11], 5, 6]
|
|
1481
|
+
|
|
1482
|
+
Finally, we create a circular reference:
|
|
1483
|
+
|
|
1484
|
+
>>> v = pari([0])
|
|
1485
|
+
>>> w = pari([v])
|
|
1486
|
+
>>> v
|
|
1487
|
+
[0]
|
|
1488
|
+
>>> w
|
|
1489
|
+
[[0]]
|
|
1490
|
+
>>> v[0] = w
|
|
1491
|
+
|
|
1492
|
+
Now there is a circular reference. Accessing v[0] will crash Python.
|
|
1493
|
+
|
|
1494
|
+
>>> s = pari.vector(2,[0,0])
|
|
1495
|
+
>>> s[:1]
|
|
1496
|
+
[0]
|
|
1497
|
+
>>> s[:1]=[1]
|
|
1498
|
+
>>> s
|
|
1499
|
+
[1, 0]
|
|
1500
|
+
>>> type(s[0])
|
|
1501
|
+
<... 'cypari2.gen.Gen'>
|
|
1502
|
+
>>> s = pari(range(20)) ; s
|
|
1503
|
+
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
|
|
1504
|
+
>>> s[0:10:2] = range(50,55) ; s
|
|
1505
|
+
[50, 1, 51, 3, 52, 5, 53, 7, 54, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
|
|
1506
|
+
>>> s[10:20:3] = range(100,150) ; s
|
|
1507
|
+
[50, 1, 51, 3, 52, 5, 53, 7, 54, 9, 100, 11, 12, 101, 14, 15, 102, 17, 18, 103]
|
|
1508
|
+
|
|
1509
|
+
Tests:
|
|
1510
|
+
|
|
1511
|
+
>>> v = pari(range(10)) ; v
|
|
1512
|
+
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
1513
|
+
>>> v[:] = range(20, 30)
|
|
1514
|
+
>>> v
|
|
1515
|
+
[20, 21, 22, 23, 24, 25, 26, 27, 28, 29]
|
|
1516
|
+
>>> type(v[0])
|
|
1517
|
+
<... 'cypari2.gen.Gen'>
|
|
1518
|
+
"""
|
|
1519
|
+
cdef Py_ssize_t i, j
|
|
1520
|
+
cdef Gen x = objtogen(y)
|
|
1521
|
+
|
|
1522
|
+
if isinstance(n, tuple):
|
|
1523
|
+
if typ(self.g) != t_MAT:
|
|
1524
|
+
raise TypeError("cannot index PARI type %s by tuple" % typ(self.g))
|
|
1525
|
+
|
|
1526
|
+
if len(n) != 2:
|
|
1527
|
+
raise ValueError("matrix index must be [row, column]")
|
|
1528
|
+
|
|
1529
|
+
i, j = n
|
|
1530
|
+
|
|
1531
|
+
if i < 0 or i >= glength(gel(self.g, 1)):
|
|
1532
|
+
raise IndexError("row i(=%s) must be between 0 and %s" % (i, self.nrows()-1))
|
|
1533
|
+
if j < 0 or j >= glength(self.g):
|
|
1534
|
+
raise IndexError("column j(=%s) must be between 0 and %s" % (j, self.ncols()-1))
|
|
1535
|
+
|
|
1536
|
+
self.cache((i, j), x)
|
|
1537
|
+
xt = x.ref_target()
|
|
1538
|
+
set_gcoeff(self.g, i+1, j+1, xt)
|
|
1539
|
+
return
|
|
1540
|
+
|
|
1541
|
+
elif isinstance(n, slice):
|
|
1542
|
+
l = glength(self.g)
|
|
1543
|
+
inds = xrange(*n.indices(l))
|
|
1544
|
+
k = len(inds)
|
|
1545
|
+
if k > len(y):
|
|
1546
|
+
raise ValueError("attempt to assign sequence of size %s to slice of size %s" % (len(y), k))
|
|
1547
|
+
|
|
1548
|
+
# actually set the values
|
|
1549
|
+
for a, b in enumerate(inds):
|
|
1550
|
+
sig_check()
|
|
1551
|
+
self[b] = y[a]
|
|
1552
|
+
return
|
|
1553
|
+
|
|
1554
|
+
# Index is not a tuple or slice, convert to integer
|
|
1555
|
+
i = n
|
|
1556
|
+
|
|
1557
|
+
if i < 0 or i >= glength(self.g):
|
|
1558
|
+
raise IndexError("index (%s) must be between 0 and %s" % (i, glength(self.g)-1))
|
|
1559
|
+
|
|
1560
|
+
self.cache(i, x)
|
|
1561
|
+
xt = x.ref_target()
|
|
1562
|
+
if typ(self.g) == t_LIST:
|
|
1563
|
+
listput(self.g, xt, i+1)
|
|
1564
|
+
else:
|
|
1565
|
+
# Correct indexing for t_POLs
|
|
1566
|
+
if typ(self.g) == t_POL:
|
|
1567
|
+
i += 1
|
|
1568
|
+
# Actually set the value
|
|
1569
|
+
set_gel(self.g, i+1, xt)
|
|
1570
|
+
|
|
1571
|
+
def __len__(self):
|
|
1572
|
+
return glength(self.g)
|
|
1573
|
+
|
|
1574
|
+
def __richcmp__(self, right, int op):
|
|
1575
|
+
"""
|
|
1576
|
+
Compare ``self`` and ``right`` using ``op``.
|
|
1577
|
+
|
|
1578
|
+
Examples:
|
|
1579
|
+
|
|
1580
|
+
>>> from cypari2 import Pari
|
|
1581
|
+
>>> pari = Pari()
|
|
1582
|
+
|
|
1583
|
+
>>> a = pari(5)
|
|
1584
|
+
>>> b = 10
|
|
1585
|
+
>>> a < b
|
|
1586
|
+
True
|
|
1587
|
+
>>> a <= b
|
|
1588
|
+
True
|
|
1589
|
+
>>> a <= 5
|
|
1590
|
+
True
|
|
1591
|
+
>>> a > b
|
|
1592
|
+
False
|
|
1593
|
+
>>> a >= b
|
|
1594
|
+
False
|
|
1595
|
+
>>> a >= pari(10)
|
|
1596
|
+
False
|
|
1597
|
+
>>> a == 5
|
|
1598
|
+
True
|
|
1599
|
+
>>> a is 5
|
|
1600
|
+
False
|
|
1601
|
+
|
|
1602
|
+
>>> pari(2.5) > None
|
|
1603
|
+
True
|
|
1604
|
+
>>> pari(3) == pari(3)
|
|
1605
|
+
True
|
|
1606
|
+
>>> pari('x^2 + 1') == pari('I-1')
|
|
1607
|
+
False
|
|
1608
|
+
>>> pari(I) == pari(I)
|
|
1609
|
+
True
|
|
1610
|
+
|
|
1611
|
+
This does not define a total order. An error is raised when
|
|
1612
|
+
applying inequality operators to non-ordered types:
|
|
1613
|
+
|
|
1614
|
+
>>> pari("Mod(1,3)") <= pari("Mod(2,3)")
|
|
1615
|
+
Traceback (most recent call last):
|
|
1616
|
+
...
|
|
1617
|
+
PariError: forbidden comparison t_INTMOD , t_INTMOD
|
|
1618
|
+
>>> pari("[0]") <= pari("0")
|
|
1619
|
+
Traceback (most recent call last):
|
|
1620
|
+
...
|
|
1621
|
+
PariError: forbidden comparison t_VEC (1 elts) , t_INT
|
|
1622
|
+
|
|
1623
|
+
Tests:
|
|
1624
|
+
|
|
1625
|
+
Check that :trac:`16127` has been fixed:
|
|
1626
|
+
|
|
1627
|
+
>>> pari('1/2') < pari('1/3')
|
|
1628
|
+
False
|
|
1629
|
+
>>> pari(1) < pari('1/2')
|
|
1630
|
+
False
|
|
1631
|
+
|
|
1632
|
+
>>> pari('O(x)') == 0
|
|
1633
|
+
True
|
|
1634
|
+
>>> pari('O(2)') == 0
|
|
1635
|
+
True
|
|
1636
|
+
"""
|
|
1637
|
+
cdef Gen t1
|
|
1638
|
+
try:
|
|
1639
|
+
t1 = objtogen(right)
|
|
1640
|
+
except Exception:
|
|
1641
|
+
return NotImplemented
|
|
1642
|
+
cdef bint r
|
|
1643
|
+
cdef GEN x = self.g
|
|
1644
|
+
cdef GEN y = t1.g
|
|
1645
|
+
sig_on()
|
|
1646
|
+
if op == Py_EQ:
|
|
1647
|
+
r = (gequal(x, y) != 0)
|
|
1648
|
+
elif op == Py_NE:
|
|
1649
|
+
r = (gequal(x, y) == 0)
|
|
1650
|
+
elif op == Py_LE:
|
|
1651
|
+
r = (gcmp(x, y) <= 0)
|
|
1652
|
+
elif op == Py_GE:
|
|
1653
|
+
r = (gcmp(x, y) >= 0)
|
|
1654
|
+
elif op == Py_LT:
|
|
1655
|
+
r = (gcmp(x, y) < 0)
|
|
1656
|
+
else: # Py_GT
|
|
1657
|
+
r = (gcmp(x, y) > 0)
|
|
1658
|
+
sig_off()
|
|
1659
|
+
return r
|
|
1660
|
+
|
|
1661
|
+
def cmp(self, right):
|
|
1662
|
+
"""
|
|
1663
|
+
Compare ``self`` and ``right``.
|
|
1664
|
+
|
|
1665
|
+
This uses PARI's ``cmp_universal()`` routine, which defines
|
|
1666
|
+
a total ordering on the set of all PARI objects (up to the
|
|
1667
|
+
indistinguishability relation given by ``gidentical()``).
|
|
1668
|
+
|
|
1669
|
+
.. WARNING::
|
|
1670
|
+
|
|
1671
|
+
This comparison is only mathematically meaningful when
|
|
1672
|
+
comparing 2 integers. In particular, when comparing
|
|
1673
|
+
rationals or reals, this does not correspond to the natural
|
|
1674
|
+
ordering.
|
|
1675
|
+
|
|
1676
|
+
Examples:
|
|
1677
|
+
|
|
1678
|
+
>>> from cypari2 import Pari
|
|
1679
|
+
>>> pari = Pari()
|
|
1680
|
+
>>> pari(5).cmp(pari(5))
|
|
1681
|
+
0
|
|
1682
|
+
>>> pari('x^2 + 1').cmp(pari('I-1'))
|
|
1683
|
+
1
|
|
1684
|
+
>>> I = pari('I')
|
|
1685
|
+
>>> I.cmp(I)
|
|
1686
|
+
0
|
|
1687
|
+
>>> pari('2/3').cmp(pari('2/5'))
|
|
1688
|
+
-1
|
|
1689
|
+
>>> two = pari('2.000000000000000000000000')
|
|
1690
|
+
>>> two.cmp(pari(1.0))
|
|
1691
|
+
1
|
|
1692
|
+
>>> two.cmp(pari(2.0))
|
|
1693
|
+
1
|
|
1694
|
+
>>> two.cmp(pari(3.0))
|
|
1695
|
+
1
|
|
1696
|
+
>>> f = pari("0*ffgen(ffinit(29, 10))")
|
|
1697
|
+
>>> pari(0).cmp(f)
|
|
1698
|
+
-1
|
|
1699
|
+
>>> pari("'x").cmp(f)
|
|
1700
|
+
1
|
|
1701
|
+
>>> pari("'x").cmp(0)
|
|
1702
|
+
Traceback (most recent call last):
|
|
1703
|
+
...
|
|
1704
|
+
TypeError: Cannot convert int to cypari2.gen.Gen_base
|
|
1705
|
+
"""
|
|
1706
|
+
other = <Gen_base?>right
|
|
1707
|
+
sig_on()
|
|
1708
|
+
r = cmp_universal(self.g, other.g)
|
|
1709
|
+
sig_off()
|
|
1710
|
+
return r
|
|
1711
|
+
|
|
1712
|
+
def __copy__(self):
|
|
1713
|
+
sig_on()
|
|
1714
|
+
return clone_gen(self.g)
|
|
1715
|
+
|
|
1716
|
+
def __oct__(self):
|
|
1717
|
+
"""
|
|
1718
|
+
Return the octal digits of self in lower case.
|
|
1719
|
+
"""
|
|
1720
|
+
cdef GEN x
|
|
1721
|
+
cdef long lx
|
|
1722
|
+
cdef long *xp
|
|
1723
|
+
cdef long w
|
|
1724
|
+
cdef char *s
|
|
1725
|
+
cdef char *sp
|
|
1726
|
+
cdef char *octdigits = "01234567"
|
|
1727
|
+
cdef int i, j
|
|
1728
|
+
cdef int size
|
|
1729
|
+
x = self.g
|
|
1730
|
+
if typ(x) != t_INT:
|
|
1731
|
+
raise TypeError("gen must be of PARI type t_INT")
|
|
1732
|
+
if not signe(x):
|
|
1733
|
+
return "0"
|
|
1734
|
+
lx = lgefint(x) - 2 # number of words
|
|
1735
|
+
size = lx * 4 * sizeof(long)
|
|
1736
|
+
s = <char *>check_malloc(size+3) # 1 char for sign, 1 char for 0, 1 char for '\0'
|
|
1737
|
+
sp = s + size + 3 - 1 # last character
|
|
1738
|
+
sp[0] = 0
|
|
1739
|
+
xp = int_LSW(x)
|
|
1740
|
+
for i from 0 <= i < lx:
|
|
1741
|
+
w = xp[0]
|
|
1742
|
+
for j in range(4*sizeof(long)):
|
|
1743
|
+
sp -= 1
|
|
1744
|
+
sp[0] = octdigits[w & 7]
|
|
1745
|
+
w >>= 3
|
|
1746
|
+
xp = int_nextW(xp)
|
|
1747
|
+
# remove leading zeros!
|
|
1748
|
+
while sp[0] == c'0':
|
|
1749
|
+
sp += 1
|
|
1750
|
+
sp -= 1
|
|
1751
|
+
sp[0] = c'0'
|
|
1752
|
+
if signe(x) < 0:
|
|
1753
|
+
sp -= 1
|
|
1754
|
+
sp[0] = c'-'
|
|
1755
|
+
k = <bytes> sp
|
|
1756
|
+
sig_free(s)
|
|
1757
|
+
return k
|
|
1758
|
+
|
|
1759
|
+
def __hex__(self):
|
|
1760
|
+
"""
|
|
1761
|
+
Return the hexadecimal digits of self in lower case.
|
|
1762
|
+
"""
|
|
1763
|
+
cdef GEN x
|
|
1764
|
+
cdef long lx
|
|
1765
|
+
cdef long *xp
|
|
1766
|
+
cdef long w
|
|
1767
|
+
cdef char *s
|
|
1768
|
+
cdef char *sp
|
|
1769
|
+
cdef char *hexdigits = "0123456789abcdef"
|
|
1770
|
+
cdef int i, j
|
|
1771
|
+
cdef int size
|
|
1772
|
+
x = self.g
|
|
1773
|
+
if typ(x) != t_INT:
|
|
1774
|
+
raise TypeError("gen must be of PARI type t_INT")
|
|
1775
|
+
if not signe(x):
|
|
1776
|
+
return "0x0"
|
|
1777
|
+
lx = lgefint(x) - 2 # number of words
|
|
1778
|
+
size = lx*2*sizeof(long)
|
|
1779
|
+
s = <char *>check_malloc(size+4) # 1 char for sign, 2 chars for 0x, 1 char for '\0'
|
|
1780
|
+
sp = s + size + 4 - 1 # last character
|
|
1781
|
+
sp[0] = 0
|
|
1782
|
+
xp = int_LSW(x)
|
|
1783
|
+
for i from 0 <= i < lx:
|
|
1784
|
+
w = xp[0]
|
|
1785
|
+
for j in range(2*sizeof(long)):
|
|
1786
|
+
sp -= 1
|
|
1787
|
+
sp[0] = hexdigits[w & 15]
|
|
1788
|
+
w >>= 4
|
|
1789
|
+
xp = int_nextW(xp)
|
|
1790
|
+
# remove leading zeros!
|
|
1791
|
+
while sp[0] == c'0':
|
|
1792
|
+
sp = sp + 1
|
|
1793
|
+
sp -= 1
|
|
1794
|
+
sp[0] = 'x'
|
|
1795
|
+
sp -= 1
|
|
1796
|
+
sp[0] = '0'
|
|
1797
|
+
if signe(x) < 0:
|
|
1798
|
+
sp -= 1
|
|
1799
|
+
sp[0] = c'-'
|
|
1800
|
+
k = <bytes> sp
|
|
1801
|
+
sig_free(s)
|
|
1802
|
+
return k
|
|
1803
|
+
|
|
1804
|
+
def __int__(self):
|
|
1805
|
+
"""
|
|
1806
|
+
Convert ``self`` to a Python integer.
|
|
1807
|
+
|
|
1808
|
+
If the number is too large to fit into a Python ``int``, a
|
|
1809
|
+
Python ``long`` is returned instead.
|
|
1810
|
+
|
|
1811
|
+
Examples:
|
|
1812
|
+
|
|
1813
|
+
>>> from cypari2 import Pari
|
|
1814
|
+
>>> pari = Pari()
|
|
1815
|
+
|
|
1816
|
+
>>> int(pari(0))
|
|
1817
|
+
0
|
|
1818
|
+
>>> int(pari(10))
|
|
1819
|
+
10
|
|
1820
|
+
>>> int(pari(-10))
|
|
1821
|
+
-10
|
|
1822
|
+
>>> int(pari(123456789012345678901234567890)) == 123456789012345678901234567890
|
|
1823
|
+
True
|
|
1824
|
+
>>> int(pari(-123456789012345678901234567890)) == -123456789012345678901234567890
|
|
1825
|
+
True
|
|
1826
|
+
>>> int(pari(2**31-1))
|
|
1827
|
+
2147483647
|
|
1828
|
+
>>> int(pari(-2**31))
|
|
1829
|
+
-2147483648
|
|
1830
|
+
>>> int(pari("Pol(10)"))
|
|
1831
|
+
10
|
|
1832
|
+
>>> int(pari("Mod(2, 7)"))
|
|
1833
|
+
2
|
|
1834
|
+
|
|
1835
|
+
>>> int(pari(2**63-1)) == 9223372036854775807
|
|
1836
|
+
True
|
|
1837
|
+
>>> int(pari(2**63+2)) == 9223372036854775810
|
|
1838
|
+
True
|
|
1839
|
+
"""
|
|
1840
|
+
return gen_to_integer(self)
|
|
1841
|
+
|
|
1842
|
+
def __index__(self):
|
|
1843
|
+
"""
|
|
1844
|
+
Coerce ``self`` (which must be a :class:`Gen` of type
|
|
1845
|
+
``t_INT``) to a Python integer.
|
|
1846
|
+
|
|
1847
|
+
Examples:
|
|
1848
|
+
|
|
1849
|
+
>>> from cypari2 import Pari
|
|
1850
|
+
>>> pari = Pari()
|
|
1851
|
+
|
|
1852
|
+
>>> from operator import index
|
|
1853
|
+
>>> i = pari(2)
|
|
1854
|
+
>>> index(i)
|
|
1855
|
+
2
|
|
1856
|
+
>>> L = [0, 1, 2, 3, 4]
|
|
1857
|
+
>>> L[i]
|
|
1858
|
+
2
|
|
1859
|
+
>>> print(index(pari("2^100")))
|
|
1860
|
+
1267650600228229401496703205376
|
|
1861
|
+
>>> index(pari("2.5"))
|
|
1862
|
+
Traceback (most recent call last):
|
|
1863
|
+
...
|
|
1864
|
+
TypeError: cannot coerce 2.50000000000000 (type t_REAL) to integer
|
|
1865
|
+
|
|
1866
|
+
>>> for i in [0,1,2,15,16,17,1213051238]:
|
|
1867
|
+
... assert bin(pari(i)) == bin(i)
|
|
1868
|
+
... assert bin(pari(-i)) == bin(-i)
|
|
1869
|
+
... assert oct(pari(i)) == oct(i)
|
|
1870
|
+
... assert oct(pari(-i)) == oct(-i)
|
|
1871
|
+
... assert hex(pari(i)) == hex(i)
|
|
1872
|
+
... assert hex(pari(-i)) == hex(-i)
|
|
1873
|
+
"""
|
|
1874
|
+
if typ(self.g) != t_INT:
|
|
1875
|
+
raise TypeError(f"cannot coerce {self!r} (type {self.type()}) to integer")
|
|
1876
|
+
return gen_to_integer(self)
|
|
1877
|
+
|
|
1878
|
+
def python_list_small(self):
|
|
1879
|
+
"""
|
|
1880
|
+
Return a Python list of the PARI gens. This object must be of type
|
|
1881
|
+
t_VECSMALL, and the resulting list contains python 'int's.
|
|
1882
|
+
|
|
1883
|
+
Examples:
|
|
1884
|
+
|
|
1885
|
+
>>> from cypari2 import Pari
|
|
1886
|
+
>>> pari = Pari()
|
|
1887
|
+
|
|
1888
|
+
>>> v=pari([1,2,3,10,102,10]).Vecsmall()
|
|
1889
|
+
>>> w = v.python_list_small()
|
|
1890
|
+
>>> w
|
|
1891
|
+
[1, 2, 3, 10, 102, 10]
|
|
1892
|
+
>>> type(w[0])
|
|
1893
|
+
<... 'int'>
|
|
1894
|
+
"""
|
|
1895
|
+
cdef long n
|
|
1896
|
+
if typ(self.g) != t_VECSMALL:
|
|
1897
|
+
raise TypeError("Object (=%s) must be of type t_VECSMALL." % self)
|
|
1898
|
+
return [self.g[n+1] for n in range(glength(self.g))]
|
|
1899
|
+
|
|
1900
|
+
def python_list(self):
|
|
1901
|
+
"""
|
|
1902
|
+
Return a Python list of the PARI gens. This object must be of type
|
|
1903
|
+
t_VEC or t_COL.
|
|
1904
|
+
|
|
1905
|
+
INPUT: None
|
|
1906
|
+
|
|
1907
|
+
OUTPUT:
|
|
1908
|
+
|
|
1909
|
+
- ``list`` - Python list whose elements are the
|
|
1910
|
+
elements of the input gen.
|
|
1911
|
+
|
|
1912
|
+
|
|
1913
|
+
Examples:
|
|
1914
|
+
|
|
1915
|
+
>>> from cypari2 import Pari
|
|
1916
|
+
>>> pari = Pari()
|
|
1917
|
+
|
|
1918
|
+
>>> v = pari([1,2,3,10,102,10])
|
|
1919
|
+
>>> w = v.python_list()
|
|
1920
|
+
>>> w
|
|
1921
|
+
[1, 2, 3, 10, 102, 10]
|
|
1922
|
+
>>> type(w[0])
|
|
1923
|
+
<... 'cypari2.gen.Gen'>
|
|
1924
|
+
>>> pari("[1,2,3]").python_list()
|
|
1925
|
+
[1, 2, 3]
|
|
1926
|
+
|
|
1927
|
+
>>> pari("[1,2,3]~").python_list()
|
|
1928
|
+
[1, 2, 3]
|
|
1929
|
+
"""
|
|
1930
|
+
# TODO: deprecate
|
|
1931
|
+
cdef long n
|
|
1932
|
+
cdef Gen t
|
|
1933
|
+
|
|
1934
|
+
if typ(self.g) != t_VEC and typ(self.g) != t_COL:
|
|
1935
|
+
raise TypeError("Object (=%s) must be of type t_VEC or t_COL." % self)
|
|
1936
|
+
return [self[n] for n in range(glength(self.g))]
|
|
1937
|
+
|
|
1938
|
+
def python(self):
|
|
1939
|
+
"""
|
|
1940
|
+
Return the closest Python equivalent of the given PARI object.
|
|
1941
|
+
|
|
1942
|
+
See :func:`~sage.libs.cypari.convert.gen_to_python` for more informations.
|
|
1943
|
+
|
|
1944
|
+
Examples:
|
|
1945
|
+
|
|
1946
|
+
>>> from cypari2 import Pari
|
|
1947
|
+
>>> pari = Pari()
|
|
1948
|
+
|
|
1949
|
+
>>> pari('1.2').python()
|
|
1950
|
+
1.2
|
|
1951
|
+
>>> pari('389/17').python()
|
|
1952
|
+
Fraction(389, 17)
|
|
1953
|
+
"""
|
|
1954
|
+
from .convert import gen_to_python
|
|
1955
|
+
return gen_to_python(self)
|
|
1956
|
+
|
|
1957
|
+
def sage(self, locals=None):
|
|
1958
|
+
r"""
|
|
1959
|
+
Return the closest SageMath equivalent of the given PARI object.
|
|
1960
|
+
|
|
1961
|
+
INPUT:
|
|
1962
|
+
|
|
1963
|
+
- ``locals`` -- optional dictionary used in fallback cases that
|
|
1964
|
+
involve ``sage_eval``
|
|
1965
|
+
|
|
1966
|
+
See :func:`~sage.libs.pari.convert_sage.gen_to_sage` for more information.
|
|
1967
|
+
"""
|
|
1968
|
+
from sage.libs.pari.convert_sage import gen_to_sage
|
|
1969
|
+
return gen_to_sage(self, locals)
|
|
1970
|
+
|
|
1971
|
+
def __float__(self):
|
|
1972
|
+
"""
|
|
1973
|
+
Return Python float.
|
|
1974
|
+
"""
|
|
1975
|
+
cdef double d
|
|
1976
|
+
sig_on()
|
|
1977
|
+
d = gtodouble(self.g)
|
|
1978
|
+
sig_off()
|
|
1979
|
+
return d
|
|
1980
|
+
|
|
1981
|
+
def __complex__(self):
|
|
1982
|
+
r"""
|
|
1983
|
+
Return ``self`` as a Python ``complex`` value.
|
|
1984
|
+
|
|
1985
|
+
Examples:
|
|
1986
|
+
|
|
1987
|
+
>>> from cypari2 import Pari
|
|
1988
|
+
>>> pari = Pari()
|
|
1989
|
+
|
|
1990
|
+
>>> g = pari(-1.0)**(0.2); g
|
|
1991
|
+
0.809016994374947 + 0.587785252292473*I
|
|
1992
|
+
>>> g.__complex__()
|
|
1993
|
+
(0.8090169943749475+0.5877852522924731j)
|
|
1994
|
+
>>> complex(g)
|
|
1995
|
+
(0.8090169943749475+0.5877852522924731j)
|
|
1996
|
+
|
|
1997
|
+
>>> g = pari('2/3')
|
|
1998
|
+
>>> complex(g)
|
|
1999
|
+
(0.6666666666666666+0j)
|
|
2000
|
+
|
|
2001
|
+
>>> g = pari.quadgen(-23)
|
|
2002
|
+
>>> complex(g)
|
|
2003
|
+
(0.5+2.3979157616563596j)
|
|
2004
|
+
|
|
2005
|
+
>>> g = pari.quadgen(5) + pari('2/3')
|
|
2006
|
+
>>> complex(g)
|
|
2007
|
+
(2.2847006554165614+0j)
|
|
2008
|
+
|
|
2009
|
+
>>> g = pari('Mod(3,5)'); g
|
|
2010
|
+
Mod(3, 5)
|
|
2011
|
+
>>> complex(g)
|
|
2012
|
+
Traceback (most recent call last):
|
|
2013
|
+
...
|
|
2014
|
+
PariError: incorrect type in gtofp (t_INTMOD)
|
|
2015
|
+
"""
|
|
2016
|
+
cdef double re, im
|
|
2017
|
+
sig_on()
|
|
2018
|
+
# First convert to floating point (t_REAL or t_COMPLEX)
|
|
2019
|
+
# Note: DEFAULTPREC means 64 bits of precision
|
|
2020
|
+
fp = gtofp(self.g, DEFAULTPREC)
|
|
2021
|
+
if typ(fp) == t_REAL:
|
|
2022
|
+
re = rtodbl(fp)
|
|
2023
|
+
im = 0
|
|
2024
|
+
elif typ(fp) == t_COMPLEX:
|
|
2025
|
+
re = gtodouble(gel(fp, 1))
|
|
2026
|
+
im = gtodouble(gel(fp, 2))
|
|
2027
|
+
else:
|
|
2028
|
+
sig_off()
|
|
2029
|
+
raise AssertionError("unrecognized output from gtofp()")
|
|
2030
|
+
clear_stack()
|
|
2031
|
+
return complex(re, im)
|
|
2032
|
+
|
|
2033
|
+
def __nonzero__(self):
|
|
2034
|
+
"""
|
|
2035
|
+
Examples:
|
|
2036
|
+
|
|
2037
|
+
>>> from cypari2 import Pari
|
|
2038
|
+
>>> pari = Pari()
|
|
2039
|
+
|
|
2040
|
+
>>> pari('1').__nonzero__()
|
|
2041
|
+
True
|
|
2042
|
+
>>> pari('x').__nonzero__()
|
|
2043
|
+
True
|
|
2044
|
+
>>> bool(pari(0))
|
|
2045
|
+
False
|
|
2046
|
+
>>> a = pari('Mod(0,3)')
|
|
2047
|
+
>>> a.__nonzero__()
|
|
2048
|
+
False
|
|
2049
|
+
"""
|
|
2050
|
+
return not gequal0(self.g)
|
|
2051
|
+
|
|
2052
|
+
def gequal(a, b):
|
|
2053
|
+
r"""
|
|
2054
|
+
Check whether `a` and `b` are equal using PARI's ``gequal``.
|
|
2055
|
+
|
|
2056
|
+
Examples:
|
|
2057
|
+
|
|
2058
|
+
>>> from cypari2 import Pari
|
|
2059
|
+
>>> pari = Pari()
|
|
2060
|
+
|
|
2061
|
+
>>> a = pari(1); b = pari(1.0); c = pari('"some_string"')
|
|
2062
|
+
>>> a.gequal(a)
|
|
2063
|
+
True
|
|
2064
|
+
>>> b.gequal(b)
|
|
2065
|
+
True
|
|
2066
|
+
>>> c.gequal(c)
|
|
2067
|
+
True
|
|
2068
|
+
>>> a.gequal(b)
|
|
2069
|
+
True
|
|
2070
|
+
>>> a.gequal(c)
|
|
2071
|
+
False
|
|
2072
|
+
|
|
2073
|
+
WARNING: this relation is not transitive:
|
|
2074
|
+
|
|
2075
|
+
>>> a = pari('[0]'); b = pari(0); c = pari('[0,0]')
|
|
2076
|
+
>>> a.gequal(b)
|
|
2077
|
+
True
|
|
2078
|
+
>>> b.gequal(c)
|
|
2079
|
+
True
|
|
2080
|
+
>>> a.gequal(c)
|
|
2081
|
+
False
|
|
2082
|
+
"""
|
|
2083
|
+
cdef Gen t0 = objtogen(b)
|
|
2084
|
+
sig_on()
|
|
2085
|
+
cdef int ret = gequal(a.g, t0.g)
|
|
2086
|
+
sig_off()
|
|
2087
|
+
return ret != 0
|
|
2088
|
+
|
|
2089
|
+
def gequal0(a):
|
|
2090
|
+
r"""
|
|
2091
|
+
Check whether `a` is equal to zero.
|
|
2092
|
+
|
|
2093
|
+
Examples:
|
|
2094
|
+
|
|
2095
|
+
>>> from cypari2 import Pari
|
|
2096
|
+
>>> pari = Pari()
|
|
2097
|
+
|
|
2098
|
+
>>> pari(0).gequal0()
|
|
2099
|
+
True
|
|
2100
|
+
>>> pari(1).gequal0()
|
|
2101
|
+
False
|
|
2102
|
+
>>> pari(1e-100).gequal0()
|
|
2103
|
+
False
|
|
2104
|
+
>>> pari("0.0 + 0.0*I").gequal0()
|
|
2105
|
+
True
|
|
2106
|
+
>>> (pari('ffgen(3^20)')*0).gequal0()
|
|
2107
|
+
True
|
|
2108
|
+
"""
|
|
2109
|
+
sig_on()
|
|
2110
|
+
cdef int ret = gequal0(a.g)
|
|
2111
|
+
sig_off()
|
|
2112
|
+
return ret != 0
|
|
2113
|
+
|
|
2114
|
+
def gequal_long(a, long b):
|
|
2115
|
+
r"""
|
|
2116
|
+
Check whether `a` is equal to the ``long int`` `b` using PARI's ``gequalsg``.
|
|
2117
|
+
|
|
2118
|
+
Examples:
|
|
2119
|
+
|
|
2120
|
+
>>> from cypari2 import Pari
|
|
2121
|
+
>>> pari = Pari()
|
|
2122
|
+
|
|
2123
|
+
>>> a = pari(1); b = pari(2.0); c = pari('3*matid(3)')
|
|
2124
|
+
>>> a.gequal_long(1)
|
|
2125
|
+
True
|
|
2126
|
+
>>> a.gequal_long(-1)
|
|
2127
|
+
False
|
|
2128
|
+
>>> a.gequal_long(0)
|
|
2129
|
+
False
|
|
2130
|
+
>>> b.gequal_long(2)
|
|
2131
|
+
True
|
|
2132
|
+
>>> b.gequal_long(-2)
|
|
2133
|
+
False
|
|
2134
|
+
>>> c.gequal_long(3)
|
|
2135
|
+
True
|
|
2136
|
+
>>> c.gequal_long(-3)
|
|
2137
|
+
False
|
|
2138
|
+
"""
|
|
2139
|
+
sig_on()
|
|
2140
|
+
cdef int ret = gequalsg(b, a.g)
|
|
2141
|
+
sig_off()
|
|
2142
|
+
return ret != 0
|
|
2143
|
+
|
|
2144
|
+
def isprime(self, long flag=0):
|
|
2145
|
+
"""
|
|
2146
|
+
Return True if x is a PROVEN prime number, and False otherwise.
|
|
2147
|
+
|
|
2148
|
+
INPUT:
|
|
2149
|
+
|
|
2150
|
+
- ``flag`` -- If flag is 0 or omitted, use a combination of
|
|
2151
|
+
algorithms. If flag is 1, the primality is certified by the
|
|
2152
|
+
Pocklington-Lehmer Test. If flag is 2, the primality is
|
|
2153
|
+
certified using the APRCL test. If flag is 3, use ECPP.
|
|
2154
|
+
|
|
2155
|
+
OUTPUT: bool
|
|
2156
|
+
|
|
2157
|
+
Examples:
|
|
2158
|
+
|
|
2159
|
+
>>> from cypari2 import Pari
|
|
2160
|
+
>>> pari = Pari()
|
|
2161
|
+
>>> pari(9).isprime()
|
|
2162
|
+
False
|
|
2163
|
+
>>> pari(17).isprime()
|
|
2164
|
+
True
|
|
2165
|
+
>>> n = pari(561) # smallest Carmichael number
|
|
2166
|
+
>>> n.isprime() # not just a pseudo-primality test!
|
|
2167
|
+
False
|
|
2168
|
+
>>> n.isprime(1)
|
|
2169
|
+
False
|
|
2170
|
+
>>> n.isprime(2)
|
|
2171
|
+
False
|
|
2172
|
+
>>> n = pari(2**31-1)
|
|
2173
|
+
>>> n.isprime(1)
|
|
2174
|
+
True
|
|
2175
|
+
"""
|
|
2176
|
+
sig_on()
|
|
2177
|
+
x = gisprime(self.g, flag)
|
|
2178
|
+
# PARI-2.9 may return a primality certificate if flag==1.
|
|
2179
|
+
# So a non-INT is interpreted as True
|
|
2180
|
+
cdef bint ret = (typ(x) != t_INT) or (signe(x) != 0)
|
|
2181
|
+
clear_stack()
|
|
2182
|
+
return ret
|
|
2183
|
+
|
|
2184
|
+
def ispseudoprime(self, long flag=0):
|
|
2185
|
+
"""
|
|
2186
|
+
ispseudoprime(x, flag=0): Returns True if x is a pseudo-prime
|
|
2187
|
+
number, and False otherwise.
|
|
2188
|
+
|
|
2189
|
+
INPUT:
|
|
2190
|
+
|
|
2191
|
+
|
|
2192
|
+
- ``flag`` - int 0 (default): checks whether x is a
|
|
2193
|
+
Baillie-Pomerance-Selfridge-Wagstaff pseudo prime (strong
|
|
2194
|
+
Rabin-Miller pseudo prime for base 2, followed by strong Lucas test
|
|
2195
|
+
for the sequence (P,-1), P smallest positive integer such that
|
|
2196
|
+
`P^2 - 4` is not a square mod x). 0: checks whether x is a
|
|
2197
|
+
strong Miller-Rabin pseudo prime for flag randomly chosen bases
|
|
2198
|
+
(with end-matching to catch square roots of -1).
|
|
2199
|
+
|
|
2200
|
+
|
|
2201
|
+
OUTPUT:
|
|
2202
|
+
|
|
2203
|
+
|
|
2204
|
+
- ``bool`` - True or False, or when flag=1, either False or a tuple
|
|
2205
|
+
(True, cert) where ``cert`` is a primality certificate.
|
|
2206
|
+
|
|
2207
|
+
|
|
2208
|
+
Examples:
|
|
2209
|
+
|
|
2210
|
+
>>> from cypari2 import Pari
|
|
2211
|
+
>>> pari = Pari()
|
|
2212
|
+
>>> pari(9).ispseudoprime()
|
|
2213
|
+
False
|
|
2214
|
+
>>> pari(17).ispseudoprime()
|
|
2215
|
+
True
|
|
2216
|
+
>>> n = pari(561) # smallest Carmichael number
|
|
2217
|
+
>>> n.ispseudoprime(2)
|
|
2218
|
+
False
|
|
2219
|
+
"""
|
|
2220
|
+
sig_on()
|
|
2221
|
+
cdef long t = ispseudoprime(self.g, flag)
|
|
2222
|
+
sig_off()
|
|
2223
|
+
return t != 0
|
|
2224
|
+
|
|
2225
|
+
def ispower(self, k=None):
|
|
2226
|
+
r"""
|
|
2227
|
+
Determine whether or not self is a perfect k-th power. If k is not
|
|
2228
|
+
specified, find the largest k so that self is a k-th power.
|
|
2229
|
+
|
|
2230
|
+
INPUT:
|
|
2231
|
+
|
|
2232
|
+
|
|
2233
|
+
- ``k`` - int (optional)
|
|
2234
|
+
|
|
2235
|
+
|
|
2236
|
+
OUTPUT:
|
|
2237
|
+
|
|
2238
|
+
|
|
2239
|
+
- ``power`` - int, what power it is
|
|
2240
|
+
|
|
2241
|
+
- ``g`` - what it is a power of
|
|
2242
|
+
|
|
2243
|
+
|
|
2244
|
+
Examples:
|
|
2245
|
+
|
|
2246
|
+
>>> from cypari2 import Pari
|
|
2247
|
+
>>> pari = Pari()
|
|
2248
|
+
>>> pari(9).ispower()
|
|
2249
|
+
(2, 3)
|
|
2250
|
+
>>> pari(17).ispower()
|
|
2251
|
+
(1, 17)
|
|
2252
|
+
>>> pari(17).ispower(2)
|
|
2253
|
+
(False, None)
|
|
2254
|
+
>>> pari(17).ispower(1)
|
|
2255
|
+
(1, 17)
|
|
2256
|
+
>>> pari(2).ispower()
|
|
2257
|
+
(1, 2)
|
|
2258
|
+
"""
|
|
2259
|
+
cdef int n
|
|
2260
|
+
cdef GEN x
|
|
2261
|
+
cdef Gen t0
|
|
2262
|
+
|
|
2263
|
+
if k is None:
|
|
2264
|
+
sig_on()
|
|
2265
|
+
n = gisanypower(self.g, &x)
|
|
2266
|
+
if n == 0:
|
|
2267
|
+
sig_off()
|
|
2268
|
+
return 1, self
|
|
2269
|
+
else:
|
|
2270
|
+
return n, new_gen(x)
|
|
2271
|
+
else:
|
|
2272
|
+
t0 = objtogen(k)
|
|
2273
|
+
sig_on()
|
|
2274
|
+
n = ispower(self.g, t0.g, &x)
|
|
2275
|
+
if n == 0:
|
|
2276
|
+
sig_off()
|
|
2277
|
+
return False, None
|
|
2278
|
+
else:
|
|
2279
|
+
return k, new_gen(x)
|
|
2280
|
+
|
|
2281
|
+
def isprimepower(self):
|
|
2282
|
+
r"""
|
|
2283
|
+
Check whether ``self`` is a prime power (with an exponent >= 1).
|
|
2284
|
+
|
|
2285
|
+
INPUT:
|
|
2286
|
+
|
|
2287
|
+
- ``self`` - A PARI integer
|
|
2288
|
+
|
|
2289
|
+
OUTPUT:
|
|
2290
|
+
|
|
2291
|
+
A tuple ``(k, p)`` where `k` is a Python integer and `p` a PARI
|
|
2292
|
+
integer.
|
|
2293
|
+
|
|
2294
|
+
- If the input was a prime power, `p` is the prime and `k` the
|
|
2295
|
+
power.
|
|
2296
|
+
- Otherwise, `k = 0` and `p` is ``self``.
|
|
2297
|
+
|
|
2298
|
+
.. SEEALSO::
|
|
2299
|
+
|
|
2300
|
+
If you don't need a proof that `p` is prime, you can use
|
|
2301
|
+
:meth:`ispseudoprimepower` instead.
|
|
2302
|
+
|
|
2303
|
+
Examples:
|
|
2304
|
+
|
|
2305
|
+
>>> from cypari2 import Pari
|
|
2306
|
+
>>> pari = Pari()
|
|
2307
|
+
>>> pari(9).isprimepower()
|
|
2308
|
+
(2, 3)
|
|
2309
|
+
>>> pari(17).isprimepower()
|
|
2310
|
+
(1, 17)
|
|
2311
|
+
>>> pari(18).isprimepower()
|
|
2312
|
+
(0, 18)
|
|
2313
|
+
>>> pari(3**12345).isprimepower()
|
|
2314
|
+
(12345, 3)
|
|
2315
|
+
"""
|
|
2316
|
+
cdef GEN x
|
|
2317
|
+
cdef long n
|
|
2318
|
+
|
|
2319
|
+
sig_on()
|
|
2320
|
+
n = isprimepower(self.g, &x)
|
|
2321
|
+
if n == 0:
|
|
2322
|
+
sig_off()
|
|
2323
|
+
return 0, self
|
|
2324
|
+
else:
|
|
2325
|
+
return n, new_gen(x)
|
|
2326
|
+
|
|
2327
|
+
def ispseudoprimepower(self):
|
|
2328
|
+
r"""
|
|
2329
|
+
Check whether ``self`` is the power (with an exponent >= 1) of
|
|
2330
|
+
a pseudo-prime.
|
|
2331
|
+
|
|
2332
|
+
INPUT:
|
|
2333
|
+
|
|
2334
|
+
- ``self`` - A PARI integer
|
|
2335
|
+
|
|
2336
|
+
OUTPUT:
|
|
2337
|
+
|
|
2338
|
+
A tuple ``(k, p)`` where `k` is a Python integer and `p` a PARI
|
|
2339
|
+
integer.
|
|
2340
|
+
|
|
2341
|
+
- If the input was a pseudoprime power, `p` is the pseudoprime
|
|
2342
|
+
and `k` the power.
|
|
2343
|
+
- Otherwise, `k = 0` and `p` is ``self``.
|
|
2344
|
+
|
|
2345
|
+
Examples:
|
|
2346
|
+
|
|
2347
|
+
>>> from cypari2 import Pari
|
|
2348
|
+
>>> pari = Pari()
|
|
2349
|
+
|
|
2350
|
+
>>> pari(3**12345).ispseudoprimepower()
|
|
2351
|
+
(12345, 3)
|
|
2352
|
+
>>> p = pari(2**1500 + 1465) # nextprime(2^1500)
|
|
2353
|
+
>>> (p**11).ispseudoprimepower()[0] # very fast
|
|
2354
|
+
11
|
|
2355
|
+
"""
|
|
2356
|
+
cdef GEN x
|
|
2357
|
+
cdef long n
|
|
2358
|
+
|
|
2359
|
+
sig_on()
|
|
2360
|
+
n = ispseudoprimepower(self.g, &x)
|
|
2361
|
+
if n == 0:
|
|
2362
|
+
sig_off()
|
|
2363
|
+
return 0, self
|
|
2364
|
+
else:
|
|
2365
|
+
return n, new_gen(x)
|
|
2366
|
+
|
|
2367
|
+
def vecmax(x):
|
|
2368
|
+
"""
|
|
2369
|
+
Return the maximum of the elements of the vector/matrix `x`.
|
|
2370
|
+
|
|
2371
|
+
Examples:
|
|
2372
|
+
|
|
2373
|
+
>>> from cypari2 import Pari
|
|
2374
|
+
>>> pari = Pari()
|
|
2375
|
+
|
|
2376
|
+
>>> pari([1, '-5/3', 8.0]).vecmax()
|
|
2377
|
+
8.00000000000000
|
|
2378
|
+
"""
|
|
2379
|
+
sig_on()
|
|
2380
|
+
return new_gen(vecmax(x.g))
|
|
2381
|
+
|
|
2382
|
+
def vecmin(x):
|
|
2383
|
+
"""
|
|
2384
|
+
Return the minimum of the elements of the vector/matrix `x`.
|
|
2385
|
+
|
|
2386
|
+
Examples:
|
|
2387
|
+
|
|
2388
|
+
>>> from cypari2 import Pari
|
|
2389
|
+
>>> pari = Pari()
|
|
2390
|
+
|
|
2391
|
+
>>> pari([1, '-5/3', 8.0]).vecmin()
|
|
2392
|
+
-5/3
|
|
2393
|
+
"""
|
|
2394
|
+
sig_on()
|
|
2395
|
+
return new_gen(vecmin(x.g))
|
|
2396
|
+
|
|
2397
|
+
def Ser(f, v=None, long precision=-1):
|
|
2398
|
+
"""
|
|
2399
|
+
Return a power series or Laurent series in the variable `v`
|
|
2400
|
+
constructed from the object `f`.
|
|
2401
|
+
|
|
2402
|
+
INPUT:
|
|
2403
|
+
|
|
2404
|
+
- ``f`` -- PARI gen
|
|
2405
|
+
|
|
2406
|
+
- ``v`` -- PARI variable (default: `x`)
|
|
2407
|
+
|
|
2408
|
+
- ``precision`` -- the desired relative precision (default:
|
|
2409
|
+
the value returned by ``pari.get_series_precision()``).
|
|
2410
|
+
This is the absolute precision minus the `v`-adic valuation.
|
|
2411
|
+
|
|
2412
|
+
OUTPUT:
|
|
2413
|
+
|
|
2414
|
+
- PARI object of type ``t_SER``
|
|
2415
|
+
|
|
2416
|
+
The series is constructed from `f` in the following way:
|
|
2417
|
+
|
|
2418
|
+
- If `f` is a scalar, a constant power series is returned.
|
|
2419
|
+
|
|
2420
|
+
- If `f` is a polynomial, it is converted into a power series
|
|
2421
|
+
in the obvious way.
|
|
2422
|
+
|
|
2423
|
+
- If `f` is a rational function, it will be expanded in a
|
|
2424
|
+
Laurent series around `v = 0`.
|
|
2425
|
+
|
|
2426
|
+
- If `f` is a vector, its coefficients become the coefficients
|
|
2427
|
+
of the power series, starting from the constant term. This
|
|
2428
|
+
is the convention used by the function ``Polrev()``, and the
|
|
2429
|
+
reverse of that used by ``Pol()``.
|
|
2430
|
+
|
|
2431
|
+
.. warning::
|
|
2432
|
+
|
|
2433
|
+
This function will not transform objects containing
|
|
2434
|
+
variables of higher priority than `v`.
|
|
2435
|
+
|
|
2436
|
+
Examples:
|
|
2437
|
+
|
|
2438
|
+
>>> from cypari2 import Pari
|
|
2439
|
+
>>> pari = Pari()
|
|
2440
|
+
|
|
2441
|
+
>>> pari(2).Ser()
|
|
2442
|
+
2 + O(x^16)
|
|
2443
|
+
>>> pari('Mod(0, 7)').Ser()
|
|
2444
|
+
Mod(0, 7)*x^15 + O(x^16)
|
|
2445
|
+
|
|
2446
|
+
>>> x = pari([1, 2, 3, 4, 5])
|
|
2447
|
+
>>> x.Ser()
|
|
2448
|
+
1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 + O(x^16)
|
|
2449
|
+
>>> f = x.Ser('v'); print(f)
|
|
2450
|
+
1 + 2*v + 3*v^2 + 4*v^3 + 5*v^4 + O(v^16)
|
|
2451
|
+
>>> pari(1)/f
|
|
2452
|
+
1 - 2*v + v^2 + 6*v^5 - 17*v^6 + 16*v^7 - 5*v^8 + 36*v^10 - 132*v^11 + 181*v^12 - 110*v^13 + 25*v^14 + 216*v^15 + O(v^16)
|
|
2453
|
+
|
|
2454
|
+
>>> pari('x^5').Ser(precision=20)
|
|
2455
|
+
x^5 + O(x^25)
|
|
2456
|
+
>>> pari('1/x').Ser(precision=1)
|
|
2457
|
+
x^-1 + O(x^0)
|
|
2458
|
+
|
|
2459
|
+
"""
|
|
2460
|
+
if precision < 0:
|
|
2461
|
+
precision = precdl # Global PARI series precision
|
|
2462
|
+
sig_on()
|
|
2463
|
+
cdef long vn = get_var(v)
|
|
2464
|
+
if typ(f.g) == t_VEC:
|
|
2465
|
+
# The precision flag is ignored for vectors, so we first
|
|
2466
|
+
# convert the vector to a polynomial.
|
|
2467
|
+
return new_gen(gtoser(gtopolyrev(f.g, vn), vn, precision))
|
|
2468
|
+
else:
|
|
2469
|
+
return new_gen(gtoser(f.g, vn, precision))
|
|
2470
|
+
|
|
2471
|
+
def Str(self):
|
|
2472
|
+
"""
|
|
2473
|
+
Str(self): Return the print representation of self as a PARI
|
|
2474
|
+
object.
|
|
2475
|
+
|
|
2476
|
+
INPUT:
|
|
2477
|
+
|
|
2478
|
+
|
|
2479
|
+
- ``self`` - gen
|
|
2480
|
+
|
|
2481
|
+
|
|
2482
|
+
OUTPUT:
|
|
2483
|
+
|
|
2484
|
+
|
|
2485
|
+
- ``gen`` - a PARI Gen of type t_STR, i.e., a PARI
|
|
2486
|
+
string
|
|
2487
|
+
|
|
2488
|
+
|
|
2489
|
+
Examples:
|
|
2490
|
+
|
|
2491
|
+
>>> from cypari2 import Pari
|
|
2492
|
+
>>> pari = Pari()
|
|
2493
|
+
|
|
2494
|
+
>>> pari([1,2,['abc',1]]).Str()
|
|
2495
|
+
"[1, 2, [abc, 1]]"
|
|
2496
|
+
>>> pari([1,1, 1.54]).Str()
|
|
2497
|
+
"[1, 1, 1.54000000000000]"
|
|
2498
|
+
>>> pari(1).Str() # 1 is automatically converted to string rep
|
|
2499
|
+
"1"
|
|
2500
|
+
>>> x = pari('x') # PARI variable "x"
|
|
2501
|
+
>>> x.Str() # is converted to string rep.
|
|
2502
|
+
"x"
|
|
2503
|
+
>>> x.Str().type()
|
|
2504
|
+
't_STR'
|
|
2505
|
+
"""
|
|
2506
|
+
cdef char* c
|
|
2507
|
+
sig_on()
|
|
2508
|
+
# Use sig_block(), which is needed because GENtostr() uses
|
|
2509
|
+
# malloc(), which is dangerous inside sig_on()
|
|
2510
|
+
sig_block()
|
|
2511
|
+
c = GENtostr(self.g)
|
|
2512
|
+
sig_unblock()
|
|
2513
|
+
v = new_gen(strtoGENstr(c))
|
|
2514
|
+
pari_free(c)
|
|
2515
|
+
return v
|
|
2516
|
+
|
|
2517
|
+
def Strexpand(x):
|
|
2518
|
+
"""
|
|
2519
|
+
Concatenate the entries of the vector `x` into a single string,
|
|
2520
|
+
then perform tilde expansion and environment variable expansion
|
|
2521
|
+
similar to shells.
|
|
2522
|
+
|
|
2523
|
+
INPUT:
|
|
2524
|
+
|
|
2525
|
+
- ``x`` -- PARI gen. Either a vector or an element which is then
|
|
2526
|
+
treated like `[x]`.
|
|
2527
|
+
|
|
2528
|
+
OUTPUT:
|
|
2529
|
+
|
|
2530
|
+
- PARI string (type ``t_STR``)
|
|
2531
|
+
|
|
2532
|
+
Examples:
|
|
2533
|
+
|
|
2534
|
+
>>> from cypari2 import Pari
|
|
2535
|
+
>>> pari = Pari()
|
|
2536
|
+
|
|
2537
|
+
>>> pari('"~/subdir"').Strexpand()
|
|
2538
|
+
"..."
|
|
2539
|
+
>>> pari('"$SHELL"').Strexpand()
|
|
2540
|
+
"..."
|
|
2541
|
+
|
|
2542
|
+
Tests:
|
|
2543
|
+
|
|
2544
|
+
>>> a = pari('"$HOME"')
|
|
2545
|
+
>>> a.Strexpand() != a
|
|
2546
|
+
True
|
|
2547
|
+
"""
|
|
2548
|
+
if typ(x.g) != t_VEC:
|
|
2549
|
+
x = list_of_Gens_to_Gen([x])
|
|
2550
|
+
sig_on()
|
|
2551
|
+
return new_gen(Strexpand(x.g))
|
|
2552
|
+
|
|
2553
|
+
def Strtex(x):
|
|
2554
|
+
r"""
|
|
2555
|
+
Strtex(x): Translates the vector x of PARI gens to TeX format and
|
|
2556
|
+
returns the resulting concatenated strings as a PARI t_STR.
|
|
2557
|
+
|
|
2558
|
+
INPUT:
|
|
2559
|
+
|
|
2560
|
+
- ``x`` -- PARI gen. Either a vector or an element which is then
|
|
2561
|
+
treated like `[x]`.
|
|
2562
|
+
|
|
2563
|
+
OUTPUT:
|
|
2564
|
+
|
|
2565
|
+
- PARI string (type ``t_STR``)
|
|
2566
|
+
|
|
2567
|
+
Examples:
|
|
2568
|
+
|
|
2569
|
+
>>> from cypari2 import Pari
|
|
2570
|
+
>>> pari = Pari()
|
|
2571
|
+
|
|
2572
|
+
>>> v = pari('x^2')
|
|
2573
|
+
>>> v.Strtex()
|
|
2574
|
+
"x^2"
|
|
2575
|
+
>>> v = pari(['1/x^2','x'])
|
|
2576
|
+
>>> v.Strtex()
|
|
2577
|
+
"\\frac{1}{x^2}x"
|
|
2578
|
+
>>> v = pari(['1 + 1/x + 1/(y+1)','x-1'])
|
|
2579
|
+
>>> v.Strtex()
|
|
2580
|
+
"\\frac{ \\left(y\n + 2\\right) \\*x\n + \\left(y\n + 1\\right) }{ \\left(y\n + 1\\right) \\*x}x\n - 1"
|
|
2581
|
+
"""
|
|
2582
|
+
if typ(x.g) != t_VEC:
|
|
2583
|
+
x = list_of_Gens_to_Gen([x])
|
|
2584
|
+
sig_on()
|
|
2585
|
+
return new_gen(Strtex(x.g))
|
|
2586
|
+
|
|
2587
|
+
def bittest(x, long n):
|
|
2588
|
+
"""
|
|
2589
|
+
bittest(x, long n): Returns bit number n (coefficient of
|
|
2590
|
+
`2^n` in binary) of the integer x. Negative numbers behave
|
|
2591
|
+
as if modulo a big power of 2.
|
|
2592
|
+
|
|
2593
|
+
INPUT:
|
|
2594
|
+
|
|
2595
|
+
|
|
2596
|
+
- ``x`` - Gen (pari integer)
|
|
2597
|
+
|
|
2598
|
+
|
|
2599
|
+
OUTPUT:
|
|
2600
|
+
|
|
2601
|
+
|
|
2602
|
+
- ``bool`` - a Python bool
|
|
2603
|
+
|
|
2604
|
+
|
|
2605
|
+
Examples:
|
|
2606
|
+
|
|
2607
|
+
>>> from cypari2 import Pari
|
|
2608
|
+
>>> pari = Pari()
|
|
2609
|
+
|
|
2610
|
+
>>> x = pari(6)
|
|
2611
|
+
>>> x.bittest(0)
|
|
2612
|
+
False
|
|
2613
|
+
>>> x.bittest(1)
|
|
2614
|
+
True
|
|
2615
|
+
>>> x.bittest(2)
|
|
2616
|
+
True
|
|
2617
|
+
>>> x.bittest(3)
|
|
2618
|
+
False
|
|
2619
|
+
>>> pari(-3).bittest(0)
|
|
2620
|
+
True
|
|
2621
|
+
>>> pari(-3).bittest(1)
|
|
2622
|
+
False
|
|
2623
|
+
>>> [pari(-3).bittest(n) for n in range(10)]
|
|
2624
|
+
[True, False, True, True, True, True, True, True, True, True]
|
|
2625
|
+
"""
|
|
2626
|
+
sig_on()
|
|
2627
|
+
cdef long b = bittest(x.g, n)
|
|
2628
|
+
sig_off()
|
|
2629
|
+
return b != 0
|
|
2630
|
+
|
|
2631
|
+
lift_centered = Gen_base.centerlift
|
|
2632
|
+
|
|
2633
|
+
def padicprime(self):
|
|
2634
|
+
"""
|
|
2635
|
+
The uniformizer of the p-adic ring this element lies in, as a t_INT.
|
|
2636
|
+
|
|
2637
|
+
INPUT:
|
|
2638
|
+
|
|
2639
|
+
- ``x`` - gen, of type t_PADIC
|
|
2640
|
+
|
|
2641
|
+
OUTPUT:
|
|
2642
|
+
|
|
2643
|
+
- ``p`` - gen, of type t_INT
|
|
2644
|
+
|
|
2645
|
+
Examples:
|
|
2646
|
+
|
|
2647
|
+
>>> from cypari2 import Pari
|
|
2648
|
+
>>> pari = Pari()
|
|
2649
|
+
|
|
2650
|
+
>>> y = pari('11^-10 + 5*11^-7 + 11^-6 + O(11)')
|
|
2651
|
+
>>> y.padicprime()
|
|
2652
|
+
11
|
|
2653
|
+
>>> y.padicprime().type()
|
|
2654
|
+
't_INT'
|
|
2655
|
+
"""
|
|
2656
|
+
return self.new_ref(gel(self.fixGEN(), 2))
|
|
2657
|
+
|
|
2658
|
+
def round(x, bint estimate=False):
|
|
2659
|
+
"""
|
|
2660
|
+
round(x,estimate=False): If x is a real number, returns x rounded
|
|
2661
|
+
to the nearest integer (rounding up). If the optional argument
|
|
2662
|
+
estimate is True, also returns the binary exponent e of the
|
|
2663
|
+
difference between the original and the rounded value (the
|
|
2664
|
+
"fractional part") (this is the integer ceiling of log_2(error)).
|
|
2665
|
+
|
|
2666
|
+
When x is a general PARI object, this function returns the result
|
|
2667
|
+
of rounding every coefficient at every level of PARI object. Note
|
|
2668
|
+
that this is different than what the truncate function does (see
|
|
2669
|
+
the example below).
|
|
2670
|
+
|
|
2671
|
+
One use of round is to get exact results after a long approximate
|
|
2672
|
+
computation, when theory tells you that the coefficients must be
|
|
2673
|
+
integers.
|
|
2674
|
+
|
|
2675
|
+
INPUT:
|
|
2676
|
+
|
|
2677
|
+
|
|
2678
|
+
- ``x`` - gen
|
|
2679
|
+
|
|
2680
|
+
- ``estimate`` - (optional) bool, False by default
|
|
2681
|
+
|
|
2682
|
+
|
|
2683
|
+
OUTPUT:
|
|
2684
|
+
|
|
2685
|
+
- if estimate is False, return a single gen.
|
|
2686
|
+
|
|
2687
|
+
- if estimate is True, return rounded version of x and error
|
|
2688
|
+
estimate in bits, both as gens.
|
|
2689
|
+
|
|
2690
|
+
Examples:
|
|
2691
|
+
|
|
2692
|
+
>>> from cypari2 import Pari
|
|
2693
|
+
>>> pari = Pari()
|
|
2694
|
+
|
|
2695
|
+
>>> pari('1.5').round()
|
|
2696
|
+
2
|
|
2697
|
+
>>> pari('1.5').round(True)
|
|
2698
|
+
(2, -1)
|
|
2699
|
+
>>> pari('1.5 + 2.1*I').round()
|
|
2700
|
+
2 + 2*I
|
|
2701
|
+
>>> pari('1.0001').round(True)
|
|
2702
|
+
(1, -14)
|
|
2703
|
+
>>> pari('(2.4*x^2 - 1.7)/x').round()
|
|
2704
|
+
(2*x^2 - 2)/x
|
|
2705
|
+
>>> pari('(2.4*x^2 - 1.7)/x').truncate()
|
|
2706
|
+
2.40000000000000*x
|
|
2707
|
+
"""
|
|
2708
|
+
cdef int n
|
|
2709
|
+
cdef long e
|
|
2710
|
+
cdef Gen y
|
|
2711
|
+
sig_on()
|
|
2712
|
+
if not estimate:
|
|
2713
|
+
return new_gen(ground(x.g))
|
|
2714
|
+
y = new_gen(grndtoi(x.g, &e))
|
|
2715
|
+
return y, e
|
|
2716
|
+
|
|
2717
|
+
def sizeword(x):
|
|
2718
|
+
"""
|
|
2719
|
+
Return the total number of machine words occupied by the
|
|
2720
|
+
complete tree of the object x. A machine word is 32 or
|
|
2721
|
+
64 bits, depending on the computer.
|
|
2722
|
+
|
|
2723
|
+
INPUT:
|
|
2724
|
+
|
|
2725
|
+
- ``x`` - gen
|
|
2726
|
+
|
|
2727
|
+
OUTPUT: int (a Python int)
|
|
2728
|
+
|
|
2729
|
+
Examples:
|
|
2730
|
+
|
|
2731
|
+
>>> from cypari2 import Pari
|
|
2732
|
+
>>> pari = Pari()
|
|
2733
|
+
|
|
2734
|
+
>>> pari('0').sizeword()
|
|
2735
|
+
2
|
|
2736
|
+
>>> pari('1').sizeword()
|
|
2737
|
+
3
|
|
2738
|
+
>>> pari('1000000').sizeword()
|
|
2739
|
+
3
|
|
2740
|
+
|
|
2741
|
+
>>> import sys
|
|
2742
|
+
>>> bitness = '64' if sys.maxsize > (1 << 32) else '32'
|
|
2743
|
+
>>> pari('10^100').sizeword() == (13 if bitness == '32' else 8)
|
|
2744
|
+
True
|
|
2745
|
+
>>> pari(1.0).sizeword() == (4 if bitness == '32' else 3)
|
|
2746
|
+
True
|
|
2747
|
+
|
|
2748
|
+
>>> pari('x + 1').sizeword()
|
|
2749
|
+
10
|
|
2750
|
+
>>> pari('[x + 1, 1]').sizeword()
|
|
2751
|
+
16
|
|
2752
|
+
"""
|
|
2753
|
+
return gsizeword(x.g)
|
|
2754
|
+
|
|
2755
|
+
def sizebyte(x):
|
|
2756
|
+
"""
|
|
2757
|
+
Return the total number of bytes occupied by the complete tree
|
|
2758
|
+
of the object x. Note that this number depends on whether the
|
|
2759
|
+
computer is 32-bit or 64-bit.
|
|
2760
|
+
|
|
2761
|
+
INPUT:
|
|
2762
|
+
|
|
2763
|
+
- ``x`` - gen
|
|
2764
|
+
|
|
2765
|
+
OUTPUT: int (a Python int)
|
|
2766
|
+
|
|
2767
|
+
Examples:
|
|
2768
|
+
|
|
2769
|
+
>>> from cypari2 import Pari
|
|
2770
|
+
>>> pari = Pari()
|
|
2771
|
+
|
|
2772
|
+
>>> import sys
|
|
2773
|
+
>>> bitness = '64' if sys.maxsize > (1 << 32) else '32'
|
|
2774
|
+
>>> pari('1').sizebyte() == (12 if bitness == '32' else 24)
|
|
2775
|
+
True
|
|
2776
|
+
"""
|
|
2777
|
+
return gsizebyte(x.g)
|
|
2778
|
+
|
|
2779
|
+
def truncate(x, bint estimate=False):
|
|
2780
|
+
"""
|
|
2781
|
+
truncate(x,estimate=False): Return the truncation of x. If estimate
|
|
2782
|
+
is True, also return the number of error bits.
|
|
2783
|
+
|
|
2784
|
+
When x is in the real numbers, this means that the part after the
|
|
2785
|
+
decimal point is chopped away, e is the binary exponent of the
|
|
2786
|
+
difference between the original and truncated value (the
|
|
2787
|
+
"fractional part"). If x is a rational function, the result is the
|
|
2788
|
+
integer part (Euclidean quotient of numerator by denominator) and
|
|
2789
|
+
if requested the error estimate is 0.
|
|
2790
|
+
|
|
2791
|
+
When truncate is applied to a power series (in X), it transforms it
|
|
2792
|
+
into a polynomial or a rational function with denominator a power
|
|
2793
|
+
of X, by chopping away the `O(X^k)`. Similarly, when
|
|
2794
|
+
applied to a p-adic number, it transforms it into an integer or a
|
|
2795
|
+
rational number by chopping away the `O(p^k)`.
|
|
2796
|
+
|
|
2797
|
+
INPUT:
|
|
2798
|
+
|
|
2799
|
+
|
|
2800
|
+
- ``x`` - gen
|
|
2801
|
+
|
|
2802
|
+
- ``estimate`` - (optional) bool, which is False by
|
|
2803
|
+
default
|
|
2804
|
+
|
|
2805
|
+
|
|
2806
|
+
OUTPUT:
|
|
2807
|
+
|
|
2808
|
+
- if estimate is False, return a single gen.
|
|
2809
|
+
|
|
2810
|
+
- if estimate is True, return rounded version of x and error
|
|
2811
|
+
estimate in bits, both as gens.
|
|
2812
|
+
|
|
2813
|
+
Examples:
|
|
2814
|
+
|
|
2815
|
+
>>> from cypari2 import Pari
|
|
2816
|
+
>>> pari = Pari()
|
|
2817
|
+
|
|
2818
|
+
>>> pari('(x^2+1)/x').round()
|
|
2819
|
+
(x^2 + 1)/x
|
|
2820
|
+
>>> pari('(x^2+1)/x').truncate()
|
|
2821
|
+
x
|
|
2822
|
+
>>> pari('1.043').truncate()
|
|
2823
|
+
1
|
|
2824
|
+
>>> pari('1.043').truncate(True)
|
|
2825
|
+
(1, -5)
|
|
2826
|
+
>>> pari('1.6').truncate()
|
|
2827
|
+
1
|
|
2828
|
+
>>> pari('1.6').round()
|
|
2829
|
+
2
|
|
2830
|
+
>>> pari('1/3 + 2 + 3^2 + O(3^3)').truncate()
|
|
2831
|
+
34/3
|
|
2832
|
+
>>> pari('sin(x+O(x^10))').truncate()
|
|
2833
|
+
1/362880*x^9 - 1/5040*x^7 + 1/120*x^5 - 1/6*x^3 + x
|
|
2834
|
+
>>> pari('sin(x+O(x^10))').round() # each coefficient has abs < 1
|
|
2835
|
+
x + O(x^10)
|
|
2836
|
+
"""
|
|
2837
|
+
cdef long e
|
|
2838
|
+
cdef Gen y
|
|
2839
|
+
sig_on()
|
|
2840
|
+
if not estimate:
|
|
2841
|
+
return new_gen(gtrunc(x.g))
|
|
2842
|
+
y = new_gen(gcvtoi(x.g, &e))
|
|
2843
|
+
return y, e
|
|
2844
|
+
|
|
2845
|
+
def _valp(x):
|
|
2846
|
+
"""
|
|
2847
|
+
Return the valuation of x where x is a p-adic number (t_PADIC)
|
|
2848
|
+
or a Laurent series (t_SER). If x is a different type, this
|
|
2849
|
+
will give a bogus number.
|
|
2850
|
+
|
|
2851
|
+
Examples:
|
|
2852
|
+
|
|
2853
|
+
>>> from cypari2 import Pari
|
|
2854
|
+
>>> pari = Pari()
|
|
2855
|
+
|
|
2856
|
+
>>> pari('1/x^2 + O(x^10)')._valp()
|
|
2857
|
+
-2
|
|
2858
|
+
>>> pari('O(x^10)')._valp()
|
|
2859
|
+
10
|
|
2860
|
+
>>> pari('(1145234796 + O(3^10))/771966234')._valp()
|
|
2861
|
+
-2
|
|
2862
|
+
>>> pari('O(2^10)')._valp()
|
|
2863
|
+
10
|
|
2864
|
+
"""
|
|
2865
|
+
# This is a simple macro, so we don't need sig_on()
|
|
2866
|
+
return valp(x.g)
|
|
2867
|
+
|
|
2868
|
+
def bernfrac(self):
|
|
2869
|
+
r"""
|
|
2870
|
+
The Bernoulli number `B_x`, where `B_0 = 1`,
|
|
2871
|
+
`B_1 = -1/2`, `B_2 = 1/6,\ldots,` expressed as a
|
|
2872
|
+
rational number. The argument `x` should be of type
|
|
2873
|
+
integer.
|
|
2874
|
+
|
|
2875
|
+
Examples:
|
|
2876
|
+
|
|
2877
|
+
>>> from cypari2 import Pari
|
|
2878
|
+
>>> pari = Pari()
|
|
2879
|
+
|
|
2880
|
+
>>> pari(18).bernfrac()
|
|
2881
|
+
43867/798
|
|
2882
|
+
>>> [pari(n).bernfrac() for n in range(10)]
|
|
2883
|
+
[1, -1/2, 1/6, 0, -1/30, 0, 1/42, 0, -1/30, 0]
|
|
2884
|
+
"""
|
|
2885
|
+
sig_on()
|
|
2886
|
+
return new_gen(bernfrac(self))
|
|
2887
|
+
|
|
2888
|
+
def bernreal(self, unsigned long precision=DEFAULT_BITPREC):
|
|
2889
|
+
r"""
|
|
2890
|
+
The Bernoulli number `B_x`, as for the function bernfrac,
|
|
2891
|
+
but `B_x` is returned as a real number (with the current
|
|
2892
|
+
precision).
|
|
2893
|
+
|
|
2894
|
+
Examples:
|
|
2895
|
+
|
|
2896
|
+
>>> from cypari2 import Pari
|
|
2897
|
+
>>> pari = Pari()
|
|
2898
|
+
|
|
2899
|
+
>>> pari(18).bernreal()
|
|
2900
|
+
54.9711779448622
|
|
2901
|
+
"""
|
|
2902
|
+
sig_on()
|
|
2903
|
+
return new_gen(bernreal(self, nbits2prec(precision)))
|
|
2904
|
+
|
|
2905
|
+
def besselk(nu, x, unsigned long precision=DEFAULT_BITPREC):
|
|
2906
|
+
"""
|
|
2907
|
+
nu.besselk(x): K-Bessel function (modified Bessel function
|
|
2908
|
+
of the second kind) of index nu, which can be complex, and argument
|
|
2909
|
+
x.
|
|
2910
|
+
|
|
2911
|
+
If `nu` or `x` is an exact argument, it is first
|
|
2912
|
+
converted to a real or complex number using the optional parameter
|
|
2913
|
+
precision (in bits). If the arguments are inexact (e.g. real), the
|
|
2914
|
+
smallest of their precisions is used in the computation, and the
|
|
2915
|
+
parameter precision is ignored.
|
|
2916
|
+
|
|
2917
|
+
INPUT:
|
|
2918
|
+
|
|
2919
|
+
|
|
2920
|
+
- ``nu`` - a complex number
|
|
2921
|
+
|
|
2922
|
+
- ``x`` - real number (positive or negative)
|
|
2923
|
+
|
|
2924
|
+
Examples:
|
|
2925
|
+
|
|
2926
|
+
>>> from cypari2 import Pari
|
|
2927
|
+
>>> pari = Pari()
|
|
2928
|
+
|
|
2929
|
+
>>> pari(complex(2, 1)).besselk(3)
|
|
2930
|
+
0.0455907718407551 + 0.0289192946582081*I
|
|
2931
|
+
|
|
2932
|
+
>>> pari(complex(2, 1)).besselk(-3)
|
|
2933
|
+
-4.34870874986752 - 5.38744882697109*I
|
|
2934
|
+
|
|
2935
|
+
>>> pari(complex(2, 1)).besselk(300)
|
|
2936
|
+
3.74224603319728 E-132 + 2.49071062641525 E-134*I
|
|
2937
|
+
"""
|
|
2938
|
+
cdef Gen t0 = objtogen(x)
|
|
2939
|
+
sig_on()
|
|
2940
|
+
return new_gen(kbessel(nu.g, t0.g, nbits2prec(precision)))
|
|
2941
|
+
|
|
2942
|
+
def eint1(x, long n=0, unsigned long precision=DEFAULT_BITPREC):
|
|
2943
|
+
r"""
|
|
2944
|
+
x.eint1(n): exponential integral E1(x):
|
|
2945
|
+
|
|
2946
|
+
.. MATH::
|
|
2947
|
+
|
|
2948
|
+
\int_{x}^{\infty} \frac{e^{-t}}{t} dt
|
|
2949
|
+
|
|
2950
|
+
|
|
2951
|
+
If n is present, output the vector [eint1(x), eint1(2\*x), ...,
|
|
2952
|
+
eint1(n\*x)]. This is faster than repeatedly calling eint1(i\*x).
|
|
2953
|
+
|
|
2954
|
+
If `x` is an exact argument, it is first converted to a
|
|
2955
|
+
real or complex number using the optional parameter precision (in
|
|
2956
|
+
bits). If `x` is inexact (e.g. real), its own precision is
|
|
2957
|
+
used in the computation, and the parameter precision is ignored.
|
|
2958
|
+
|
|
2959
|
+
REFERENCE:
|
|
2960
|
+
|
|
2961
|
+
- See page 262, Prop 5.6.12, of Cohen's book "A Course in
|
|
2962
|
+
Computational Algebraic Number Theory".
|
|
2963
|
+
|
|
2964
|
+
Examples:
|
|
2965
|
+
"""
|
|
2966
|
+
sig_on()
|
|
2967
|
+
if n <= 0:
|
|
2968
|
+
return new_gen(eint1(x.g, nbits2prec(precision)))
|
|
2969
|
+
else:
|
|
2970
|
+
return new_gen(veceint1(x.g, stoi(n), nbits2prec(precision)))
|
|
2971
|
+
|
|
2972
|
+
log_gamma = Gen_base.lngamma
|
|
2973
|
+
|
|
2974
|
+
def polylog(x, long m, long flag=0,
|
|
2975
|
+
unsigned long precision=DEFAULT_BITPREC):
|
|
2976
|
+
"""
|
|
2977
|
+
x.polylog(m,flag=0): m-th polylogarithm of x. flag is optional, and
|
|
2978
|
+
can be 0: default, 1: D_m -modified m-th polylog of x, 2:
|
|
2979
|
+
D_m-modified m-th polylog of x, 3: P_m-modified m-th polylog of
|
|
2980
|
+
x.
|
|
2981
|
+
|
|
2982
|
+
If `x` is an exact argument, it is first converted to a
|
|
2983
|
+
real or complex number using the optional parameter precision (in
|
|
2984
|
+
bits). If `x` is inexact (e.g. real), its own precision is
|
|
2985
|
+
used in the computation, and the parameter precision is ignored.
|
|
2986
|
+
|
|
2987
|
+
TODO: Add more explanation, copied from the PARI manual.
|
|
2988
|
+
|
|
2989
|
+
Examples:
|
|
2990
|
+
|
|
2991
|
+
>>> from cypari2 import Pari
|
|
2992
|
+
>>> pari = Pari()
|
|
2993
|
+
|
|
2994
|
+
>>> pari(10).polylog(3)
|
|
2995
|
+
5.64181141475134 - 8.32820207698027*I
|
|
2996
|
+
>>> pari(10).polylog(3,0)
|
|
2997
|
+
5.64181141475134 - 8.32820207698027*I
|
|
2998
|
+
>>> pari(10).polylog(3,1)
|
|
2999
|
+
0.523778453502411
|
|
3000
|
+
>>> pari(10).polylog(3,2)
|
|
3001
|
+
-0.400459056163451
|
|
3002
|
+
"""
|
|
3003
|
+
sig_on()
|
|
3004
|
+
return new_gen(polylog0(m, x.g, flag, nbits2prec(precision)))
|
|
3005
|
+
|
|
3006
|
+
def sqrtn(x, n, unsigned long precision=DEFAULT_BITPREC):
|
|
3007
|
+
r"""
|
|
3008
|
+
x.sqrtn(n): return the principal branch of the n-th root of x,
|
|
3009
|
+
i.e., the one such that
|
|
3010
|
+
`\arg(\sqrt(x)) \in ]-\pi/n, \pi/n]`. Also returns a second
|
|
3011
|
+
argument which is a suitable root of unity allowing one to recover
|
|
3012
|
+
all the other roots. If it was not possible to find such a number,
|
|
3013
|
+
then this second return value is 0. If the argument is present and
|
|
3014
|
+
no square root exists, return 0 instead of raising an error.
|
|
3015
|
+
|
|
3016
|
+
If `x` is an exact argument, it is first converted to a
|
|
3017
|
+
real or complex number using the optional parameter precision (in
|
|
3018
|
+
bits). If `x` is inexact (e.g. real), its own precision is
|
|
3019
|
+
used in the computation, and the parameter precision is ignored.
|
|
3020
|
+
|
|
3021
|
+
.. NOTE::
|
|
3022
|
+
|
|
3023
|
+
intmods (modulo a prime) and `p`-adic numbers are
|
|
3024
|
+
allowed as arguments.
|
|
3025
|
+
|
|
3026
|
+
INPUT:
|
|
3027
|
+
|
|
3028
|
+
|
|
3029
|
+
- ``x`` - gen
|
|
3030
|
+
|
|
3031
|
+
- ``n`` - integer
|
|
3032
|
+
|
|
3033
|
+
|
|
3034
|
+
OUTPUT:
|
|
3035
|
+
|
|
3036
|
+
|
|
3037
|
+
- ``gen`` - principal n-th root of x
|
|
3038
|
+
|
|
3039
|
+
- ``gen`` - root of unity z that gives the other
|
|
3040
|
+
roots
|
|
3041
|
+
|
|
3042
|
+
|
|
3043
|
+
Examples:
|
|
3044
|
+
|
|
3045
|
+
>>> from cypari2 import Pari
|
|
3046
|
+
>>> pari = Pari()
|
|
3047
|
+
|
|
3048
|
+
>>> s, z = pari(2).sqrtn(5)
|
|
3049
|
+
>>> z
|
|
3050
|
+
0.309016994374947 + 0.951056516295154*I
|
|
3051
|
+
>>> s
|
|
3052
|
+
1.14869835499704
|
|
3053
|
+
>>> s**5
|
|
3054
|
+
2.00000000000000
|
|
3055
|
+
>>> (s*z)**5
|
|
3056
|
+
2.00000000000000 + 0.E-19*I
|
|
3057
|
+
|
|
3058
|
+
|
|
3059
|
+
>>> import sys
|
|
3060
|
+
>>> bitness = '64' if sys.maxsize > (1 << 32) else '32'
|
|
3061
|
+
>>> s = str(z**5)
|
|
3062
|
+
>>> s == ('1.00000000000000 - 2.710505431 E-20*I' if bitness == '32' else '1.00000000000000 - 2.71050543121376 E-20*I')
|
|
3063
|
+
True
|
|
3064
|
+
"""
|
|
3065
|
+
cdef GEN ans, zetan
|
|
3066
|
+
cdef Gen t0 = objtogen(n)
|
|
3067
|
+
sig_on()
|
|
3068
|
+
ans = gsqrtn(x.g, t0.g, &zetan, nbits2prec(precision))
|
|
3069
|
+
return new_gens2(ans, zetan)
|
|
3070
|
+
|
|
3071
|
+
def ffprimroot(self):
|
|
3072
|
+
r"""
|
|
3073
|
+
Return a primitive root of the multiplicative group of the
|
|
3074
|
+
definition field of the given finite field element.
|
|
3075
|
+
|
|
3076
|
+
INPUT:
|
|
3077
|
+
|
|
3078
|
+
- ``self`` -- a PARI finite field element (``FFELT``)
|
|
3079
|
+
|
|
3080
|
+
OUTPUT:
|
|
3081
|
+
|
|
3082
|
+
- A generator of the multiplicative group of the finite field
|
|
3083
|
+
generated by ``self``.
|
|
3084
|
+
|
|
3085
|
+
Examples:
|
|
3086
|
+
|
|
3087
|
+
>>> from cypari2 import Pari
|
|
3088
|
+
>>> pari = Pari()
|
|
3089
|
+
|
|
3090
|
+
>>> b = pari(9).ffgen().ffprimroot()
|
|
3091
|
+
>>> b.fforder()
|
|
3092
|
+
8
|
|
3093
|
+
"""
|
|
3094
|
+
sig_on()
|
|
3095
|
+
return new_gen(ffprimroot(self.g, NULL))
|
|
3096
|
+
|
|
3097
|
+
def fibonacci(self):
|
|
3098
|
+
r"""
|
|
3099
|
+
Return the Fibonacci number of index x.
|
|
3100
|
+
|
|
3101
|
+
Examples:
|
|
3102
|
+
|
|
3103
|
+
>>> from cypari2 import Pari
|
|
3104
|
+
>>> pari = Pari()
|
|
3105
|
+
|
|
3106
|
+
>>> pari(18).fibonacci()
|
|
3107
|
+
2584
|
|
3108
|
+
>>> [pari(n).fibonacci() for n in range(10)]
|
|
3109
|
+
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
|
|
3110
|
+
"""
|
|
3111
|
+
sig_on()
|
|
3112
|
+
return new_gen(fibo(self))
|
|
3113
|
+
|
|
3114
|
+
def issquare(x, find_root=False):
|
|
3115
|
+
"""
|
|
3116
|
+
issquare(x,n): ``True`` if x is a square, ``False`` if not. If
|
|
3117
|
+
``find_root`` is given, also returns the exact square root.
|
|
3118
|
+
"""
|
|
3119
|
+
cdef GEN G
|
|
3120
|
+
cdef long t
|
|
3121
|
+
cdef Gen g
|
|
3122
|
+
sig_on()
|
|
3123
|
+
if find_root:
|
|
3124
|
+
t = itos(gissquareall(x.g, &G))
|
|
3125
|
+
if t:
|
|
3126
|
+
return True, new_gen(G)
|
|
3127
|
+
else:
|
|
3128
|
+
clear_stack()
|
|
3129
|
+
return False, None
|
|
3130
|
+
else:
|
|
3131
|
+
t = itos(gissquare(x.g))
|
|
3132
|
+
clear_stack()
|
|
3133
|
+
return t != 0
|
|
3134
|
+
|
|
3135
|
+
def issquarefree(self):
|
|
3136
|
+
"""
|
|
3137
|
+
Examples:
|
|
3138
|
+
|
|
3139
|
+
>>> from cypari2 import Pari
|
|
3140
|
+
>>> pari = Pari()
|
|
3141
|
+
|
|
3142
|
+
>>> pari(10).issquarefree()
|
|
3143
|
+
True
|
|
3144
|
+
>>> pari(20).issquarefree()
|
|
3145
|
+
False
|
|
3146
|
+
"""
|
|
3147
|
+
sig_on()
|
|
3148
|
+
cdef long t = issquarefree(self.g)
|
|
3149
|
+
sig_off()
|
|
3150
|
+
return t != 0
|
|
3151
|
+
|
|
3152
|
+
def sumdiv(n):
|
|
3153
|
+
"""
|
|
3154
|
+
Return the sum of the divisors of `n`.
|
|
3155
|
+
|
|
3156
|
+
Examples:
|
|
3157
|
+
|
|
3158
|
+
>>> from cypari2 import Pari
|
|
3159
|
+
>>> pari = Pari()
|
|
3160
|
+
|
|
3161
|
+
>>> pari(10).sumdiv()
|
|
3162
|
+
18
|
|
3163
|
+
"""
|
|
3164
|
+
sig_on()
|
|
3165
|
+
return new_gen(sumdiv(n.g))
|
|
3166
|
+
|
|
3167
|
+
def sumdivk(n, long k):
|
|
3168
|
+
"""
|
|
3169
|
+
Return the sum of the k-th powers of the divisors of n.
|
|
3170
|
+
|
|
3171
|
+
Examples:
|
|
3172
|
+
|
|
3173
|
+
>>> from cypari2 import Pari
|
|
3174
|
+
>>> pari = Pari()
|
|
3175
|
+
|
|
3176
|
+
>>> pari(10).sumdivk(2)
|
|
3177
|
+
130
|
|
3178
|
+
"""
|
|
3179
|
+
sig_on()
|
|
3180
|
+
return new_gen(sumdivk(n.g, k))
|
|
3181
|
+
|
|
3182
|
+
def Zn_issquare(self, n):
|
|
3183
|
+
"""
|
|
3184
|
+
Return ``True`` if ``self`` is a square modulo `n`, ``False``
|
|
3185
|
+
if not.
|
|
3186
|
+
|
|
3187
|
+
INPUT:
|
|
3188
|
+
|
|
3189
|
+
- ``self`` -- integer
|
|
3190
|
+
|
|
3191
|
+
- ``n`` -- integer or factorisation matrix
|
|
3192
|
+
|
|
3193
|
+
Examples:
|
|
3194
|
+
|
|
3195
|
+
>>> from cypari2 import Pari
|
|
3196
|
+
>>> pari = Pari()
|
|
3197
|
+
|
|
3198
|
+
>>> pari(3).Zn_issquare(4)
|
|
3199
|
+
False
|
|
3200
|
+
>>> pari(4).Zn_issquare(pari(30).factor())
|
|
3201
|
+
True
|
|
3202
|
+
|
|
3203
|
+
"""
|
|
3204
|
+
cdef Gen t0 = objtogen(n)
|
|
3205
|
+
sig_on()
|
|
3206
|
+
cdef long t = Zn_issquare(self.g, t0.g)
|
|
3207
|
+
clear_stack()
|
|
3208
|
+
return t != 0
|
|
3209
|
+
|
|
3210
|
+
def Zn_sqrt(self, n):
|
|
3211
|
+
"""
|
|
3212
|
+
Return a square root of ``self`` modulo `n`, if such a square
|
|
3213
|
+
root exists; otherwise, raise a ``ValueError``.
|
|
3214
|
+
|
|
3215
|
+
INPUT:
|
|
3216
|
+
|
|
3217
|
+
- ``self`` -- integer
|
|
3218
|
+
|
|
3219
|
+
- ``n`` -- integer or factorisation matrix
|
|
3220
|
+
|
|
3221
|
+
Examples:
|
|
3222
|
+
|
|
3223
|
+
>>> from cypari2 import Pari
|
|
3224
|
+
>>> pari = Pari()
|
|
3225
|
+
|
|
3226
|
+
>>> pari(3).Zn_sqrt(4)
|
|
3227
|
+
Traceback (most recent call last):
|
|
3228
|
+
...
|
|
3229
|
+
ValueError: 3 is not a square modulo 4
|
|
3230
|
+
>>> pari(4).Zn_sqrt(pari(30).factor())
|
|
3231
|
+
22
|
|
3232
|
+
|
|
3233
|
+
"""
|
|
3234
|
+
cdef Gen t0 = objtogen(n)
|
|
3235
|
+
cdef GEN s
|
|
3236
|
+
sig_on()
|
|
3237
|
+
s = Zn_sqrt(self.g, t0.g)
|
|
3238
|
+
if s == NULL:
|
|
3239
|
+
clear_stack()
|
|
3240
|
+
raise ValueError("%s is not a square modulo %s" % (self, n))
|
|
3241
|
+
return new_gen(s)
|
|
3242
|
+
|
|
3243
|
+
def ellan(self, long n, python_ints=False):
|
|
3244
|
+
"""
|
|
3245
|
+
Return the first `n` Fourier coefficients of the modular
|
|
3246
|
+
form attached to this elliptic curve. See ellak for more details.
|
|
3247
|
+
|
|
3248
|
+
INPUT:
|
|
3249
|
+
|
|
3250
|
+
|
|
3251
|
+
- ``n`` - a long integer
|
|
3252
|
+
|
|
3253
|
+
- ``python_ints`` - bool (default is False); if True,
|
|
3254
|
+
return a list of Python ints instead of a PARI Gen wrapper.
|
|
3255
|
+
|
|
3256
|
+
|
|
3257
|
+
Examples:
|
|
3258
|
+
|
|
3259
|
+
>>> from cypari2 import Pari
|
|
3260
|
+
>>> pari = Pari()
|
|
3261
|
+
|
|
3262
|
+
>>> e = pari([0, -1, 1, -10, -20]).ellinit()
|
|
3263
|
+
>>> e.ellan(3)
|
|
3264
|
+
[1, -2, -1]
|
|
3265
|
+
>>> e.ellan(20)
|
|
3266
|
+
[1, -2, -1, 2, 1, 2, -2, 0, -2, -2, 1, -2, 4, 4, -1, -4, -2, 4, 0, 2]
|
|
3267
|
+
>>> e.ellan(-1)
|
|
3268
|
+
[]
|
|
3269
|
+
>>> v = e.ellan(10, python_ints=True); v
|
|
3270
|
+
[1, -2, -1, 2, 1, 2, -2, 0, -2, -2]
|
|
3271
|
+
>>> type(v)
|
|
3272
|
+
<... 'list'>
|
|
3273
|
+
>>> type(v[0])
|
|
3274
|
+
<... 'int'>
|
|
3275
|
+
"""
|
|
3276
|
+
sig_on()
|
|
3277
|
+
cdef Gen g = new_gen(ellan(self.g, n))
|
|
3278
|
+
if not python_ints:
|
|
3279
|
+
return g
|
|
3280
|
+
return [gtolong(gel(g.g, i+1)) for i in range(glength(g.g))]
|
|
3281
|
+
|
|
3282
|
+
def ellaplist(self, long n, python_ints=False):
|
|
3283
|
+
r"""
|
|
3284
|
+
e.ellaplist(n): Returns a PARI list of all the prime-indexed
|
|
3285
|
+
coefficients `a_p` (up to n) of the `L`-function
|
|
3286
|
+
of the elliptic curve `e`, i.e. the Fourier coefficients of
|
|
3287
|
+
the newform attached to `e`.
|
|
3288
|
+
|
|
3289
|
+
INPUT:
|
|
3290
|
+
|
|
3291
|
+
- ``self`` -- an elliptic curve
|
|
3292
|
+
|
|
3293
|
+
- ``n`` -- a long integer
|
|
3294
|
+
|
|
3295
|
+
- ``python_ints`` -- bool (default is False); if True,
|
|
3296
|
+
return a list of Python ints instead of a PARI Gen wrapper.
|
|
3297
|
+
|
|
3298
|
+
.. WARNING::
|
|
3299
|
+
|
|
3300
|
+
The curve e must be a medium or long vector of the type given by
|
|
3301
|
+
ellinit. For this function to work for every n and not just those
|
|
3302
|
+
prime to the conductor, e must be a minimal Weierstrass equation.
|
|
3303
|
+
If this is not the case, use the function ellminimalmodel first
|
|
3304
|
+
before using ellaplist (or you will get INCORRECT RESULTS!)
|
|
3305
|
+
|
|
3306
|
+
Examples:
|
|
3307
|
+
|
|
3308
|
+
>>> from cypari2 import Pari
|
|
3309
|
+
>>> pari = Pari()
|
|
3310
|
+
|
|
3311
|
+
>>> e = pari([0, -1, 1, -10, -20]).ellinit()
|
|
3312
|
+
>>> v = e.ellaplist(10); v
|
|
3313
|
+
[-2, -1, 1, -2]
|
|
3314
|
+
>>> type(v)
|
|
3315
|
+
<... 'cypari2.gen.Gen'>
|
|
3316
|
+
>>> v.type()
|
|
3317
|
+
't_VEC'
|
|
3318
|
+
>>> e.ellan(10)
|
|
3319
|
+
[1, -2, -1, 2, 1, 2, -2, 0, -2, -2]
|
|
3320
|
+
>>> v = e.ellaplist(10, python_ints=True); v
|
|
3321
|
+
[-2, -1, 1, -2]
|
|
3322
|
+
>>> type(v)
|
|
3323
|
+
<... 'list'>
|
|
3324
|
+
>>> type(v[0])
|
|
3325
|
+
<... 'int'>
|
|
3326
|
+
|
|
3327
|
+
Tests:
|
|
3328
|
+
|
|
3329
|
+
>>> v = e.ellaplist(1)
|
|
3330
|
+
>>> v, type(v)
|
|
3331
|
+
([], <... 'cypari2.gen.Gen'>)
|
|
3332
|
+
>>> v = e.ellaplist(1, python_ints=True)
|
|
3333
|
+
>>> v, type(v)
|
|
3334
|
+
([], <... 'list'>)
|
|
3335
|
+
"""
|
|
3336
|
+
if python_ints:
|
|
3337
|
+
return [int(x) for x in self.ellaplist(n)]
|
|
3338
|
+
|
|
3339
|
+
sig_on()
|
|
3340
|
+
if n < 2:
|
|
3341
|
+
return new_gen(zerovec(0))
|
|
3342
|
+
|
|
3343
|
+
# Make a table of primes up to n: this returns a t_VECSMALL
|
|
3344
|
+
# that we artificially change to a t_VEC
|
|
3345
|
+
cdef GEN g = primes_upto_zv(n)
|
|
3346
|
+
settyp(g, t_VEC)
|
|
3347
|
+
|
|
3348
|
+
# Replace each prime in the table by ellap of it
|
|
3349
|
+
cdef long i
|
|
3350
|
+
cdef GEN curve = self.g
|
|
3351
|
+
for i in range(1, lg(g)):
|
|
3352
|
+
set_gel(g, i, ellap(curve, utoi(g[i])))
|
|
3353
|
+
return new_gen(g)
|
|
3354
|
+
|
|
3355
|
+
def ellisoncurve(self, x):
|
|
3356
|
+
"""
|
|
3357
|
+
e.ellisoncurve(x): return True if the point x is on the elliptic
|
|
3358
|
+
curve e, False otherwise.
|
|
3359
|
+
|
|
3360
|
+
If the point or the curve have inexact coefficients, an attempt is
|
|
3361
|
+
made to take this into account.
|
|
3362
|
+
|
|
3363
|
+
Examples:
|
|
3364
|
+
|
|
3365
|
+
>>> from cypari2 import Pari
|
|
3366
|
+
>>> pari = Pari()
|
|
3367
|
+
|
|
3368
|
+
>>> e = pari([0,1,1,-2,0]).ellinit()
|
|
3369
|
+
>>> e.ellisoncurve([1,0])
|
|
3370
|
+
True
|
|
3371
|
+
>>> e.ellisoncurve([1,1])
|
|
3372
|
+
False
|
|
3373
|
+
>>> e.ellisoncurve([1,0.00000000000000001])
|
|
3374
|
+
False
|
|
3375
|
+
>>> e.ellisoncurve([1,0.000000000000000001])
|
|
3376
|
+
True
|
|
3377
|
+
>>> e.ellisoncurve([0])
|
|
3378
|
+
True
|
|
3379
|
+
"""
|
|
3380
|
+
cdef Gen t0 = objtogen(x)
|
|
3381
|
+
sig_on()
|
|
3382
|
+
cdef int t = oncurve(self.g, t0.g)
|
|
3383
|
+
sig_off()
|
|
3384
|
+
return t != 0
|
|
3385
|
+
|
|
3386
|
+
def ellminimalmodel(self):
|
|
3387
|
+
"""
|
|
3388
|
+
ellminimalmodel(e): return the standard minimal integral model of
|
|
3389
|
+
the rational elliptic curve e and the corresponding change of
|
|
3390
|
+
variables. INPUT:
|
|
3391
|
+
|
|
3392
|
+
|
|
3393
|
+
- ``e`` - Gen (that defines an elliptic curve)
|
|
3394
|
+
|
|
3395
|
+
|
|
3396
|
+
OUTPUT:
|
|
3397
|
+
|
|
3398
|
+
|
|
3399
|
+
- ``gen`` - minimal model
|
|
3400
|
+
|
|
3401
|
+
- ``gen`` - change of coordinates
|
|
3402
|
+
|
|
3403
|
+
|
|
3404
|
+
Examples:
|
|
3405
|
+
|
|
3406
|
+
>>> from cypari2 import Pari
|
|
3407
|
+
>>> pari = Pari()
|
|
3408
|
+
|
|
3409
|
+
>>> e = pari([1,2,3,4,5]).ellinit()
|
|
3410
|
+
>>> F, ch = e.ellminimalmodel()
|
|
3411
|
+
>>> F[:5]
|
|
3412
|
+
[1, -1, 0, 4, 3]
|
|
3413
|
+
>>> ch
|
|
3414
|
+
[1, -1, 0, -1]
|
|
3415
|
+
>>> e.ellchangecurve(ch)[:5]
|
|
3416
|
+
[1, -1, 0, 4, 3]
|
|
3417
|
+
"""
|
|
3418
|
+
cdef GEN x, y
|
|
3419
|
+
sig_on()
|
|
3420
|
+
x = ellminimalmodel(self.g, &y)
|
|
3421
|
+
return new_gens2(x, y)
|
|
3422
|
+
|
|
3423
|
+
def elltors(self):
|
|
3424
|
+
r"""
|
|
3425
|
+
Return information about the torsion subgroup of the given
|
|
3426
|
+
elliptic curve.
|
|
3427
|
+
|
|
3428
|
+
INPUT:
|
|
3429
|
+
|
|
3430
|
+
- ``e`` - elliptic curve over `\QQ`
|
|
3431
|
+
|
|
3432
|
+
OUTPUT:
|
|
3433
|
+
|
|
3434
|
+
|
|
3435
|
+
- ``gen`` - the order of the torsion subgroup, a.k.a.
|
|
3436
|
+
the number of points of finite order
|
|
3437
|
+
|
|
3438
|
+
- ``gen`` - vector giving the structure of the torsion
|
|
3439
|
+
subgroup as a product of cyclic groups, sorted in non-increasing
|
|
3440
|
+
order
|
|
3441
|
+
|
|
3442
|
+
- ``gen`` - vector giving points on e generating these
|
|
3443
|
+
cyclic groups
|
|
3444
|
+
|
|
3445
|
+
|
|
3446
|
+
Examples:
|
|
3447
|
+
|
|
3448
|
+
>>> from cypari2 import Pari
|
|
3449
|
+
>>> pari = Pari()
|
|
3450
|
+
|
|
3451
|
+
>>> e = pari([1,0,1,-19,26]).ellinit()
|
|
3452
|
+
>>> e.elltors()
|
|
3453
|
+
[12, [6, 2], [[1, 2], [3, -2]]]
|
|
3454
|
+
"""
|
|
3455
|
+
sig_on()
|
|
3456
|
+
return new_gen(elltors(self.g))
|
|
3457
|
+
|
|
3458
|
+
def omega(self):
|
|
3459
|
+
"""
|
|
3460
|
+
Return the basis for the period lattice of this elliptic curve.
|
|
3461
|
+
|
|
3462
|
+
Examples:
|
|
3463
|
+
|
|
3464
|
+
>>> from cypari2 import Pari
|
|
3465
|
+
>>> pari = Pari()
|
|
3466
|
+
|
|
3467
|
+
>>> e = pari([0, -1, 1, -10, -20]).ellinit()
|
|
3468
|
+
>>> e.omega()
|
|
3469
|
+
[1.26920930427955, 0.634604652139777 - 1.45881661693850*I]
|
|
3470
|
+
|
|
3471
|
+
The precision is determined by the ``ellinit`` call:
|
|
3472
|
+
|
|
3473
|
+
>>> e = pari([0, -1, 1, -10, -20]).ellinit(precision=256)
|
|
3474
|
+
>>> e.omega().bitprecision()
|
|
3475
|
+
256
|
|
3476
|
+
|
|
3477
|
+
This also works over quadratic imaginary number fields:
|
|
3478
|
+
|
|
3479
|
+
>>> e = pari.ellinit([0, -1, 1, -10, -20], "nfinit(y^2 - 2)")
|
|
3480
|
+
>>> if pari.version() >= (2, 10, 1):
|
|
3481
|
+
... w = e.omega()
|
|
3482
|
+
"""
|
|
3483
|
+
sig_on()
|
|
3484
|
+
return new_gen(member_omega(self.g))
|
|
3485
|
+
|
|
3486
|
+
def disc(self):
|
|
3487
|
+
"""
|
|
3488
|
+
Return the discriminant of this object.
|
|
3489
|
+
|
|
3490
|
+
Examples:
|
|
3491
|
+
|
|
3492
|
+
>>> from cypari2 import Pari
|
|
3493
|
+
>>> pari = Pari()
|
|
3494
|
+
|
|
3495
|
+
>>> e = pari([0, -1, 1, -10, -20]).ellinit()
|
|
3496
|
+
>>> e.disc()
|
|
3497
|
+
-161051
|
|
3498
|
+
>>> _.factor()
|
|
3499
|
+
[-1, 1; 11, 5]
|
|
3500
|
+
"""
|
|
3501
|
+
sig_on()
|
|
3502
|
+
return clone_gen(member_disc(self.g))
|
|
3503
|
+
|
|
3504
|
+
def j(self):
|
|
3505
|
+
"""
|
|
3506
|
+
Return the j-invariant of this object.
|
|
3507
|
+
|
|
3508
|
+
Examples:
|
|
3509
|
+
|
|
3510
|
+
>>> from cypari2 import Pari
|
|
3511
|
+
>>> pari = Pari()
|
|
3512
|
+
|
|
3513
|
+
>>> e = pari([0, -1, 1, -10, -20]).ellinit()
|
|
3514
|
+
>>> e.j()
|
|
3515
|
+
-122023936/161051
|
|
3516
|
+
>>> _.factor()
|
|
3517
|
+
[-1, 1; 2, 12; 11, -5; 31, 3]
|
|
3518
|
+
"""
|
|
3519
|
+
sig_on()
|
|
3520
|
+
return clone_gen(member_j(self.g))
|
|
3521
|
+
|
|
3522
|
+
def _eltabstorel(self, x):
|
|
3523
|
+
"""
|
|
3524
|
+
Return the relative number field element corresponding to `x`.
|
|
3525
|
+
|
|
3526
|
+
The result is a ``t_POLMOD`` with ``t_POLMOD`` coefficients.
|
|
3527
|
+
|
|
3528
|
+
.. WARNING::
|
|
3529
|
+
|
|
3530
|
+
This is a low-level version of :meth:`rnfeltabstorel` that
|
|
3531
|
+
only needs the output of :meth:`_nf_rnfeq`, not a full
|
|
3532
|
+
PARI ``rnf`` structure. This method may raise errors or
|
|
3533
|
+
return undefined results if called with invalid arguments.
|
|
3534
|
+
|
|
3535
|
+
Tests:
|
|
3536
|
+
|
|
3537
|
+
>>> from cypari2 import Pari
|
|
3538
|
+
>>> pari = Pari()
|
|
3539
|
+
|
|
3540
|
+
>>> K = pari('y^2 + 1').nfinit()
|
|
3541
|
+
>>> rnfeq = K._nf_rnfeq('x^2 + 2')
|
|
3542
|
+
>>> f_abs = rnfeq[0]; f_abs
|
|
3543
|
+
x^4 + 6*x^2 + 1
|
|
3544
|
+
>>> x_rel = rnfeq._eltabstorel('x'); x_rel
|
|
3545
|
+
Mod(x + Mod(-y, y^2 + 1), x^2 + 2)
|
|
3546
|
+
>>> f_abs(x_rel)
|
|
3547
|
+
Mod(0, x^2 + 2)
|
|
3548
|
+
"""
|
|
3549
|
+
cdef Gen t0 = objtogen(x)
|
|
3550
|
+
sig_on()
|
|
3551
|
+
return new_gen(eltabstorel(self.g, t0.g))
|
|
3552
|
+
|
|
3553
|
+
def _eltabstorel_lift(self, x):
|
|
3554
|
+
"""
|
|
3555
|
+
Return the relative number field element corresponding to `x`.
|
|
3556
|
+
|
|
3557
|
+
The result is a ``t_POL`` with ``t_POLMOD`` coefficients.
|
|
3558
|
+
|
|
3559
|
+
.. WARNING::
|
|
3560
|
+
|
|
3561
|
+
This is a low-level version of :meth:`rnfeltabstorel` that
|
|
3562
|
+
only needs the output of :meth:`_nf_rnfeq`, not a full
|
|
3563
|
+
PARI ``rnf`` structure. This method may raise errors or
|
|
3564
|
+
return undefined results if called with invalid arguments.
|
|
3565
|
+
|
|
3566
|
+
Tests:
|
|
3567
|
+
|
|
3568
|
+
>>> from cypari2 import Pari
|
|
3569
|
+
>>> pari = Pari()
|
|
3570
|
+
|
|
3571
|
+
>>> K = pari('y^2 + 1').nfinit()
|
|
3572
|
+
>>> rnfeq = K._nf_rnfeq('x^2 + 2')
|
|
3573
|
+
>>> rnfeq._eltabstorel_lift('x')
|
|
3574
|
+
x + Mod(-y, y^2 + 1)
|
|
3575
|
+
"""
|
|
3576
|
+
cdef Gen t0 = objtogen(x)
|
|
3577
|
+
sig_on()
|
|
3578
|
+
return new_gen(eltabstorel_lift(self.g, t0.g))
|
|
3579
|
+
|
|
3580
|
+
def _eltreltoabs(self, x):
|
|
3581
|
+
"""
|
|
3582
|
+
Return the absolute number field element corresponding to `x`.
|
|
3583
|
+
|
|
3584
|
+
The result is a ``t_POL``.
|
|
3585
|
+
|
|
3586
|
+
.. WARNING::
|
|
3587
|
+
|
|
3588
|
+
This is a low-level version of :meth:`rnfeltreltoabs` that
|
|
3589
|
+
only needs the output of :meth:`_nf_rnfeq`, not a full
|
|
3590
|
+
PARI ``rnf`` structure. This method may raise errors or
|
|
3591
|
+
return undefined results if called with invalid arguments.
|
|
3592
|
+
|
|
3593
|
+
Tests:
|
|
3594
|
+
|
|
3595
|
+
>>> from cypari2 import Pari
|
|
3596
|
+
>>> pari = Pari()
|
|
3597
|
+
|
|
3598
|
+
>>> K = pari('y^2 + 1').nfinit()
|
|
3599
|
+
>>> rnfeq = K._nf_rnfeq('x^2 + 2')
|
|
3600
|
+
>>> rnfeq._eltreltoabs('x')
|
|
3601
|
+
1/2*x^3 + 7/2*x
|
|
3602
|
+
>>> rnfeq._eltreltoabs('y')
|
|
3603
|
+
1/2*x^3 + 5/2*x
|
|
3604
|
+
"""
|
|
3605
|
+
cdef Gen t0 = objtogen(x)
|
|
3606
|
+
sig_on()
|
|
3607
|
+
return new_gen(eltreltoabs(self.g, t0.g))
|
|
3608
|
+
|
|
3609
|
+
def galoissubfields(self, long flag=0, v=None):
|
|
3610
|
+
"""
|
|
3611
|
+
List all subfields of the Galois group ``self``.
|
|
3612
|
+
|
|
3613
|
+
This wraps the `galoissubfields`_ function from PARI.
|
|
3614
|
+
|
|
3615
|
+
This method is essentially the same as applying
|
|
3616
|
+
:meth:`galoisfixedfield` to each group returned by
|
|
3617
|
+
:meth:`galoissubgroups`.
|
|
3618
|
+
|
|
3619
|
+
INPUT:
|
|
3620
|
+
|
|
3621
|
+
- ``self`` -- A Galois group as generated by :meth:`galoisinit`.
|
|
3622
|
+
|
|
3623
|
+
- ``flag`` -- Has the same meaning as in :meth:`galoisfixedfield`.
|
|
3624
|
+
|
|
3625
|
+
- ``v`` -- Has the same meaning as in :meth:`galoisfixedfield`.
|
|
3626
|
+
|
|
3627
|
+
OUTPUT:
|
|
3628
|
+
|
|
3629
|
+
A vector of all subfields of this group. Each entry is as
|
|
3630
|
+
described in the :meth:`galoisfixedfield` method.
|
|
3631
|
+
|
|
3632
|
+
Examples:
|
|
3633
|
+
|
|
3634
|
+
>>> from cypari2 import Pari
|
|
3635
|
+
>>> pari = Pari()
|
|
3636
|
+
|
|
3637
|
+
>>> G = pari('x^6 + 108').galoisinit()
|
|
3638
|
+
>>> G.galoissubfields(flag=1)
|
|
3639
|
+
[x, x^2 + 972, x^3 + 54, x^3 + 864, x^3 - 54, x^6 + 108]
|
|
3640
|
+
>>> G = pari('x^4 + 1').galoisinit()
|
|
3641
|
+
>>> G.galoissubfields(flag=2, v='z')[3]
|
|
3642
|
+
[...^2 + 2, Mod(x^3 + x, x^4 + 1), [x^2 - z*x - 1, x^2 + z*x - 1]]
|
|
3643
|
+
|
|
3644
|
+
.. _galoissubfields: http://pari.math.u-bordeaux.fr/dochtml/html.stable/Functions_related_to_general_number_fields.html#galoissubfields
|
|
3645
|
+
"""
|
|
3646
|
+
sig_on()
|
|
3647
|
+
return new_gen(galoissubfields(self.g, flag, get_var(v)))
|
|
3648
|
+
|
|
3649
|
+
def nfeltval(self, x, p):
|
|
3650
|
+
"""
|
|
3651
|
+
Return the valuation of the number field element `x` at the prime `p`.
|
|
3652
|
+
|
|
3653
|
+
Examples:
|
|
3654
|
+
|
|
3655
|
+
>>> from cypari2 import Pari
|
|
3656
|
+
>>> pari = Pari()
|
|
3657
|
+
|
|
3658
|
+
>>> nf = pari('x^2 + 1').nfinit()
|
|
3659
|
+
>>> p = nf.idealprimedec(5)[0]
|
|
3660
|
+
>>> nf.nfeltval('50 - 25*x', p)
|
|
3661
|
+
3
|
|
3662
|
+
"""
|
|
3663
|
+
cdef Gen t0 = objtogen(x)
|
|
3664
|
+
cdef Gen t1 = objtogen(p)
|
|
3665
|
+
sig_on()
|
|
3666
|
+
v = nfval(self.g, t0.g, t1.g)
|
|
3667
|
+
sig_off()
|
|
3668
|
+
return v
|
|
3669
|
+
|
|
3670
|
+
def nfbasis(self, long flag=0, fa=None):
|
|
3671
|
+
r"""
|
|
3672
|
+
Integral basis of the field `\QQ[a]`, where ``a`` is a root of
|
|
3673
|
+
the polynomial x.
|
|
3674
|
+
|
|
3675
|
+
INPUT:
|
|
3676
|
+
|
|
3677
|
+
- ``flag``: if set to 1 and ``fa`` is not given: assume that no
|
|
3678
|
+
square of a prime > 500000 divides the discriminant of ``x``.
|
|
3679
|
+
|
|
3680
|
+
- ``fa``: If present, encodes a subset of primes at which to
|
|
3681
|
+
check for maximality. This must be one of the three following
|
|
3682
|
+
things:
|
|
3683
|
+
|
|
3684
|
+
- an integer: check all primes up to ``fa`` using trial
|
|
3685
|
+
division.
|
|
3686
|
+
|
|
3687
|
+
- a vector: a list of primes to check.
|
|
3688
|
+
|
|
3689
|
+
- a matrix: a partial factorization of the discriminant
|
|
3690
|
+
of ``x``.
|
|
3691
|
+
|
|
3692
|
+
Examples:
|
|
3693
|
+
|
|
3694
|
+
>>> from cypari2 import Pari
|
|
3695
|
+
>>> pari = Pari()
|
|
3696
|
+
|
|
3697
|
+
>>> pari('x^3 - 17').nfbasis()
|
|
3698
|
+
[1, x, 1/3*x^2 - 1/3*x + 1/3]
|
|
3699
|
+
|
|
3700
|
+
We test ``flag`` = 1, noting it gives a wrong result when the
|
|
3701
|
+
discriminant (-4 * `p`^2 * `q` in the example below) has a big square
|
|
3702
|
+
factor:
|
|
3703
|
+
|
|
3704
|
+
>>> p = pari(10**10).nextprime(); q = (p+1).nextprime()
|
|
3705
|
+
>>> x = pari('x'); f = x**2 + p**2*q
|
|
3706
|
+
>>> pari(f).nfbasis(1) # Wrong result
|
|
3707
|
+
[1, x]
|
|
3708
|
+
>>> pari(f).nfbasis() # Correct result
|
|
3709
|
+
[1, 1/10000000019*x]
|
|
3710
|
+
>>> pari(f).nfbasis(fa=10**6) # Check primes up to 10^6: wrong result
|
|
3711
|
+
[1, x]
|
|
3712
|
+
>>> pari(f).nfbasis(fa="[2,2; %s,2]"%p) # Correct result and faster
|
|
3713
|
+
[1, 1/10000000019*x]
|
|
3714
|
+
>>> pari(f).nfbasis(fa=[2,p]) # Equivalent with the above
|
|
3715
|
+
[1, 1/10000000019*x]
|
|
3716
|
+
|
|
3717
|
+
The following alternative syntax closer to PARI/GP can be used
|
|
3718
|
+
|
|
3719
|
+
>>> pari.nfbasis([f, 1])
|
|
3720
|
+
[1, x]
|
|
3721
|
+
>>> pari.nfbasis(f)
|
|
3722
|
+
[1, 1/10000000019*x]
|
|
3723
|
+
>>> pari.nfbasis([f, 10**6])
|
|
3724
|
+
[1, x]
|
|
3725
|
+
>>> pari.nfbasis([f, "[2,2; %s,2]"%p])
|
|
3726
|
+
[1, 1/10000000019*x]
|
|
3727
|
+
>>> pari.nfbasis([f, [2,p]])
|
|
3728
|
+
[1, 1/10000000019*x]
|
|
3729
|
+
"""
|
|
3730
|
+
cdef Gen t0
|
|
3731
|
+
cdef GEN g0
|
|
3732
|
+
if fa is not None:
|
|
3733
|
+
t0 = objtogen(fa)
|
|
3734
|
+
g0 = t0.g
|
|
3735
|
+
elif flag:
|
|
3736
|
+
g0 = utoi(500000)
|
|
3737
|
+
else:
|
|
3738
|
+
g0 = NULL
|
|
3739
|
+
sig_on()
|
|
3740
|
+
return new_gen(old_nfbasis(self.g, NULL, g0))
|
|
3741
|
+
|
|
3742
|
+
def nfbasis_d(self, long flag=0, fa=None):
|
|
3743
|
+
"""
|
|
3744
|
+
Like :meth:`nfbasis`, but return a tuple ``(B, D)`` where `B`
|
|
3745
|
+
is the integral basis and `D` the discriminant.
|
|
3746
|
+
|
|
3747
|
+
Examples:
|
|
3748
|
+
|
|
3749
|
+
>>> from cypari2 import Pari
|
|
3750
|
+
>>> pari = Pari()
|
|
3751
|
+
|
|
3752
|
+
>>> F = pari('x^3 - 2').nfinit()
|
|
3753
|
+
>>> F[0].nfbasis_d()
|
|
3754
|
+
([1, x, x^2], -108)
|
|
3755
|
+
|
|
3756
|
+
>>> G = pari('x^5 - 11').nfinit()
|
|
3757
|
+
>>> G[0].nfbasis_d()
|
|
3758
|
+
([1, x, x^2, x^3, x^4], 45753125)
|
|
3759
|
+
|
|
3760
|
+
>>> pari([-2,0,0,1]).Polrev().nfbasis_d()
|
|
3761
|
+
([1, x, x^2], -108)
|
|
3762
|
+
"""
|
|
3763
|
+
cdef Gen t0
|
|
3764
|
+
cdef GEN g0
|
|
3765
|
+
cdef GEN ans, disc
|
|
3766
|
+
if fa is not None:
|
|
3767
|
+
t0 = objtogen(fa)
|
|
3768
|
+
g0 = t0.g
|
|
3769
|
+
elif flag & 1:
|
|
3770
|
+
g0 = utoi(500000)
|
|
3771
|
+
else:
|
|
3772
|
+
g0 = NULL
|
|
3773
|
+
sig_on()
|
|
3774
|
+
ans = old_nfbasis(self.g, &disc, g0)
|
|
3775
|
+
return new_gens2(ans, disc)
|
|
3776
|
+
|
|
3777
|
+
def nfbasistoalg_lift(nf, x):
|
|
3778
|
+
r"""
|
|
3779
|
+
Transforms the column vector ``x`` on the integral basis into a
|
|
3780
|
+
polynomial representing the algebraic number.
|
|
3781
|
+
|
|
3782
|
+
INPUT:
|
|
3783
|
+
|
|
3784
|
+
- ``nf`` -- a number field
|
|
3785
|
+
- ``x`` -- a column of rational numbers of length equal to the
|
|
3786
|
+
degree of ``nf`` or a single rational number
|
|
3787
|
+
|
|
3788
|
+
OUTPUT:
|
|
3789
|
+
|
|
3790
|
+
- ``nf.nfbasistoalg(x).lift()``
|
|
3791
|
+
|
|
3792
|
+
Examples:
|
|
3793
|
+
|
|
3794
|
+
>>> from cypari2 import Pari
|
|
3795
|
+
>>> pari = Pari()
|
|
3796
|
+
|
|
3797
|
+
>>> K = pari('x^3 - 17').nfinit()
|
|
3798
|
+
>>> K.nf_get_zk()
|
|
3799
|
+
[1, 1/3*x^2 - 1/3*x + 1/3, x]
|
|
3800
|
+
>>> K.nfbasistoalg_lift(42)
|
|
3801
|
+
42
|
|
3802
|
+
>>> K.nfbasistoalg_lift("[3/2, -5, 0]~")
|
|
3803
|
+
-5/3*x^2 + 5/3*x - 1/6
|
|
3804
|
+
>>> K.nf_get_zk() * pari("[3/2, -5, 0]~")
|
|
3805
|
+
-5/3*x^2 + 5/3*x - 1/6
|
|
3806
|
+
"""
|
|
3807
|
+
cdef Gen t0 = objtogen(x)
|
|
3808
|
+
sig_on()
|
|
3809
|
+
return new_gen(gel(basistoalg(nf.g, t0.g), 2))
|
|
3810
|
+
|
|
3811
|
+
def nfgenerator(self):
|
|
3812
|
+
f = self[0]
|
|
3813
|
+
x = f.variable()
|
|
3814
|
+
return x.Mod(f)
|
|
3815
|
+
|
|
3816
|
+
def _nf_rnfeq(self, relpol):
|
|
3817
|
+
"""
|
|
3818
|
+
Return data for converting number field elements between
|
|
3819
|
+
absolute and relative representation.
|
|
3820
|
+
|
|
3821
|
+
.. NOTE::
|
|
3822
|
+
|
|
3823
|
+
The output of this method is suitable for the methods
|
|
3824
|
+
:meth:`_eltabstorel`, :meth:`_eltabstorel_lift` and
|
|
3825
|
+
:meth:`_eltreltoabs`.
|
|
3826
|
+
|
|
3827
|
+
Tests:
|
|
3828
|
+
|
|
3829
|
+
>>> from cypari2 import Pari
|
|
3830
|
+
>>> pari = Pari()
|
|
3831
|
+
|
|
3832
|
+
>>> K = pari('y^2 + 1').nfinit()
|
|
3833
|
+
>>> K._nf_rnfeq('x^2 + 2')
|
|
3834
|
+
[x^4 + 6*x^2 + 1, 1/2*x^3 + 5/2*x, -1, y^2 + 1, x^2 + 2]
|
|
3835
|
+
"""
|
|
3836
|
+
cdef Gen t0 = objtogen(relpol)
|
|
3837
|
+
sig_on()
|
|
3838
|
+
return new_gen(nf_rnfeq(self.g, t0.g))
|
|
3839
|
+
|
|
3840
|
+
def _nf_nfzk(self, rnfeq):
|
|
3841
|
+
"""
|
|
3842
|
+
Return data for constructing relative number field elements
|
|
3843
|
+
from elements of the base field.
|
|
3844
|
+
|
|
3845
|
+
INPUT:
|
|
3846
|
+
|
|
3847
|
+
- ``rnfeq`` -- relative number field data as returned by
|
|
3848
|
+
:meth:`_nf_rnfeq`
|
|
3849
|
+
|
|
3850
|
+
.. NOTE::
|
|
3851
|
+
|
|
3852
|
+
The output of this method is suitable for the method
|
|
3853
|
+
:meth:`_nfeltup`.
|
|
3854
|
+
"""
|
|
3855
|
+
cdef Gen t0 = objtogen(rnfeq)
|
|
3856
|
+
sig_on()
|
|
3857
|
+
return new_gen(new_nf_nfzk(self.g, t0.g))
|
|
3858
|
+
|
|
3859
|
+
def _nfeltup(self, x, nfzk):
|
|
3860
|
+
"""
|
|
3861
|
+
Construct a relative number field element from an element of
|
|
3862
|
+
the base field.
|
|
3863
|
+
|
|
3864
|
+
INPUT:
|
|
3865
|
+
|
|
3866
|
+
- ``x`` -- element of the base field
|
|
3867
|
+
|
|
3868
|
+
- ``nfzk`` -- relative number field data as returned by
|
|
3869
|
+
:meth:`_nf_nfzk`
|
|
3870
|
+
|
|
3871
|
+
.. WARNING::
|
|
3872
|
+
|
|
3873
|
+
This is a low-level version of :meth:`rnfeltup` that only
|
|
3874
|
+
needs the output of :meth:`_nf_nfzk`, not a full PARI
|
|
3875
|
+
``rnf`` structure. This method may raise errors or return
|
|
3876
|
+
undefined results if called with invalid arguments.
|
|
3877
|
+
|
|
3878
|
+
Tests:
|
|
3879
|
+
|
|
3880
|
+
>>> from cypari2 import Pari
|
|
3881
|
+
>>> pari = Pari()
|
|
3882
|
+
|
|
3883
|
+
>>> nf = pari('nfinit(y^2 - 2)')
|
|
3884
|
+
>>> nfzk = nf._nf_nfzk(nf._nf_rnfeq('x^2 - 3'))
|
|
3885
|
+
>>> nf._nfeltup('y', nfzk)
|
|
3886
|
+
-1/2*x^3 + 9/2*x
|
|
3887
|
+
"""
|
|
3888
|
+
cdef Gen t0 = objtogen(x)
|
|
3889
|
+
cdef Gen t1 = objtogen(nfzk)
|
|
3890
|
+
sig_on()
|
|
3891
|
+
return clone_gen(new_nfeltup(self.g, t0.g, t1.g))
|
|
3892
|
+
|
|
3893
|
+
def eval(self, *args, **kwds):
|
|
3894
|
+
"""
|
|
3895
|
+
Evaluate ``self`` with the given arguments.
|
|
3896
|
+
|
|
3897
|
+
This is currently implemented in 3 cases:
|
|
3898
|
+
|
|
3899
|
+
- univariate polynomials, rational functions, power series and
|
|
3900
|
+
Laurent series (using a single unnamed argument or keyword
|
|
3901
|
+
arguments),
|
|
3902
|
+
- any PARI object supporting the PARI function :pari:`substvec`
|
|
3903
|
+
(in particular, multivariate polynomials) using keyword
|
|
3904
|
+
arguments,
|
|
3905
|
+
- objects of type ``t_CLOSURE`` (functions in GP bytecode form)
|
|
3906
|
+
using unnamed arguments.
|
|
3907
|
+
|
|
3908
|
+
In no case is mixing unnamed and keyword arguments allowed.
|
|
3909
|
+
|
|
3910
|
+
Examples:
|
|
3911
|
+
|
|
3912
|
+
>>> from cypari2 import Pari
|
|
3913
|
+
>>> pari = Pari()
|
|
3914
|
+
|
|
3915
|
+
>>> f = pari('x^2 + 1')
|
|
3916
|
+
>>> f.type()
|
|
3917
|
+
't_POL'
|
|
3918
|
+
>>> f.eval(pari('I'))
|
|
3919
|
+
0
|
|
3920
|
+
>>> f.eval(x=2)
|
|
3921
|
+
5
|
|
3922
|
+
>>> (1/f).eval(x=1)
|
|
3923
|
+
1/2
|
|
3924
|
+
|
|
3925
|
+
The notation ``f(x)`` is an alternative for ``f.eval(x)``:
|
|
3926
|
+
|
|
3927
|
+
>>> f(3) == f.eval(3)
|
|
3928
|
+
True
|
|
3929
|
+
|
|
3930
|
+
>>> f = pari('Mod(x^2 + x + 1, 3)')
|
|
3931
|
+
>>> f(2)
|
|
3932
|
+
Mod(1, 3)
|
|
3933
|
+
|
|
3934
|
+
Evaluating a power series:
|
|
3935
|
+
|
|
3936
|
+
>>> f = pari('1 + x + x^3 + O(x^7)')
|
|
3937
|
+
>>> f(2*pari('y')**2)
|
|
3938
|
+
1 + 2*y^2 + 8*y^6 + O(y^14)
|
|
3939
|
+
|
|
3940
|
+
Substituting zero is sometimes possible, and trying to do so
|
|
3941
|
+
in illegal cases can raise various errors:
|
|
3942
|
+
|
|
3943
|
+
>>> pari('1 + O(x^3)').eval(0)
|
|
3944
|
+
1
|
|
3945
|
+
>>> pari('1/x').eval(0)
|
|
3946
|
+
Traceback (most recent call last):
|
|
3947
|
+
...
|
|
3948
|
+
PariError: impossible inverse in gdiv: 0
|
|
3949
|
+
>>> pari('1/x + O(x^2)').eval(0)
|
|
3950
|
+
Traceback (most recent call last):
|
|
3951
|
+
...
|
|
3952
|
+
PariError: impossible inverse in gsubst: 0
|
|
3953
|
+
>>> pari('1/x + O(x^2)').eval(pari('O(x^3)'))
|
|
3954
|
+
Traceback (most recent call last):
|
|
3955
|
+
...
|
|
3956
|
+
PariError: impossible inverse in ...
|
|
3957
|
+
>>> pari('O(x^0)').eval(0)
|
|
3958
|
+
Traceback (most recent call last):
|
|
3959
|
+
...
|
|
3960
|
+
PariError: forbidden substitution t_SER , t_INT
|
|
3961
|
+
|
|
3962
|
+
Evaluating multivariate polynomials:
|
|
3963
|
+
|
|
3964
|
+
>>> f = pari('y^2 + x^3')
|
|
3965
|
+
>>> f(1) # Dangerous, depends on PARI variable ordering
|
|
3966
|
+
y^2 + 1
|
|
3967
|
+
>>> f(x=1) # Safe
|
|
3968
|
+
y^2 + 1
|
|
3969
|
+
>>> f(y=1)
|
|
3970
|
+
x^3 + 1
|
|
3971
|
+
>>> f(1, 2)
|
|
3972
|
+
Traceback (most recent call last):
|
|
3973
|
+
...
|
|
3974
|
+
TypeError: evaluating PARI t_POL takes exactly 1 argument (2 given)
|
|
3975
|
+
>>> f(y='x', x='2*y')
|
|
3976
|
+
x^2 + 8*y^3
|
|
3977
|
+
>>> f()
|
|
3978
|
+
x^3 + y^2
|
|
3979
|
+
|
|
3980
|
+
It's not an error to substitute variables which do not appear:
|
|
3981
|
+
|
|
3982
|
+
>>> f.eval(z=37)
|
|
3983
|
+
x^3 + y^2
|
|
3984
|
+
>>> pari(42).eval(t=0)
|
|
3985
|
+
42
|
|
3986
|
+
|
|
3987
|
+
We can define and evaluate closures as follows:
|
|
3988
|
+
|
|
3989
|
+
>>> T = pari('n -> n + 2')
|
|
3990
|
+
>>> T.type()
|
|
3991
|
+
't_CLOSURE'
|
|
3992
|
+
>>> T.eval(3)
|
|
3993
|
+
5
|
|
3994
|
+
|
|
3995
|
+
>>> T = pari('() -> 42')
|
|
3996
|
+
>>> T()
|
|
3997
|
+
42
|
|
3998
|
+
|
|
3999
|
+
>>> pr = pari('s -> print(s)')
|
|
4000
|
+
>>> pr.eval('"hello world"')
|
|
4001
|
+
hello world
|
|
4002
|
+
|
|
4003
|
+
>>> f = pari('myfunc(x,y) = x*y')
|
|
4004
|
+
>>> f.eval(5, 6)
|
|
4005
|
+
30
|
|
4006
|
+
|
|
4007
|
+
Default arguments work, missing arguments are treated as zero
|
|
4008
|
+
(like in GP):
|
|
4009
|
+
|
|
4010
|
+
>>> f = pari("(x, y, z=1.0) -> [x, y, z]")
|
|
4011
|
+
>>> f(1, 2, 3)
|
|
4012
|
+
[1, 2, 3]
|
|
4013
|
+
>>> f(1, 2)
|
|
4014
|
+
[1, 2, 1.00000000000000]
|
|
4015
|
+
>>> f(1)
|
|
4016
|
+
[1, 0, 1.00000000000000]
|
|
4017
|
+
>>> f()
|
|
4018
|
+
[0, 0, 1.00000000000000]
|
|
4019
|
+
|
|
4020
|
+
Variadic closures are supported as well (:trac:`18623`):
|
|
4021
|
+
|
|
4022
|
+
>>> f = pari("(v[..])->length(v)")
|
|
4023
|
+
>>> f('a', f)
|
|
4024
|
+
2
|
|
4025
|
+
>>> g = pari("(x,y,z[..])->[x,y,z]")
|
|
4026
|
+
>>> g(), g(1), g(1,2), g(1,2,3), g(1,2,3,4)
|
|
4027
|
+
([0, 0, []], [1, 0, []], [1, 2, []], [1, 2, [3]], [1, 2, [3, 4]])
|
|
4028
|
+
|
|
4029
|
+
Using keyword arguments, we can substitute in more complicated
|
|
4030
|
+
objects, for example a number field:
|
|
4031
|
+
|
|
4032
|
+
>>> nf = pari('x^2 + 1').nfinit()
|
|
4033
|
+
>>> nf
|
|
4034
|
+
[x^2 + 1, [0, 1], -4, 1, [Mat([1, 0.E-38 + 1.00000000000000*I]), [1, 1.00000000000000; 1, -1.00000000000000], ..., [2, 0; 0, -2], [2, 0; 0, 2], [1, 0; 0, -1], [1, [0, -1; 1, 0]], [2]], [0.E-38 + 1.00000000000000*I], [1, x], [1, 0; 0, 1], [1, 0, 0, -1; 0, 1, 1, 0]]
|
|
4035
|
+
>>> nf(x='y')
|
|
4036
|
+
[y^2 + 1, [0, 1], -4, 1, [Mat([1, 0.E-38 + 1.00000000000000*I]), [1, 1.00000000000000; 1, -1.00000000000000], ..., [2, 0; 0, -2], [2, 0; 0, 2], [1, 0; 0, -1], [1, [0, -1; 1, 0]], [2]], [0.E-38 + 1.00000000000000*I], [1, y], [1, 0; 0, 1], [1, 0, 0, -1; 0, 1, 1, 0]]
|
|
4037
|
+
|
|
4038
|
+
Tests:
|
|
4039
|
+
|
|
4040
|
+
>>> T = pari('n -> 1/n')
|
|
4041
|
+
>>> T.type()
|
|
4042
|
+
't_CLOSURE'
|
|
4043
|
+
>>> T(0)
|
|
4044
|
+
Traceback (most recent call last):
|
|
4045
|
+
...
|
|
4046
|
+
PariError: _/_: impossible inverse in gdiv: 0
|
|
4047
|
+
>>> pari('() -> 42')(1,2,3)
|
|
4048
|
+
Traceback (most recent call last):
|
|
4049
|
+
...
|
|
4050
|
+
PariError: too many parameters in user-defined function call
|
|
4051
|
+
>>> pari('n -> n')(n=2)
|
|
4052
|
+
Traceback (most recent call last):
|
|
4053
|
+
...
|
|
4054
|
+
TypeError: cannot evaluate a PARI closure using keyword arguments
|
|
4055
|
+
>>> pari('x + y')(4, y=1)
|
|
4056
|
+
Traceback (most recent call last):
|
|
4057
|
+
...
|
|
4058
|
+
TypeError: mixing unnamed and keyword arguments not allowed when evaluating a PARI object
|
|
4059
|
+
>>> pari("12345")(4)
|
|
4060
|
+
Traceback (most recent call last):
|
|
4061
|
+
...
|
|
4062
|
+
TypeError: cannot evaluate PARI t_INT using unnamed arguments
|
|
4063
|
+
"""
|
|
4064
|
+
return self(*args, **kwds)
|
|
4065
|
+
|
|
4066
|
+
def __call__(self, *args, **kwds):
|
|
4067
|
+
"""
|
|
4068
|
+
Evaluate ``self`` with the given arguments. See ``eval``.
|
|
4069
|
+
"""
|
|
4070
|
+
cdef long t = typ(self.g)
|
|
4071
|
+
cdef Gen t0
|
|
4072
|
+
cdef GEN result
|
|
4073
|
+
cdef long arity
|
|
4074
|
+
cdef long nargs = len(args)
|
|
4075
|
+
cdef long nkwds = len(kwds)
|
|
4076
|
+
|
|
4077
|
+
# Closure must be evaluated using *args
|
|
4078
|
+
if t == t_CLOSURE:
|
|
4079
|
+
if nkwds:
|
|
4080
|
+
raise TypeError("cannot evaluate a PARI closure using keyword arguments")
|
|
4081
|
+
if closure_is_variadic(self.g):
|
|
4082
|
+
arity = closure_arity(self.g) - 1
|
|
4083
|
+
args = list(args[:arity]) + [0]*(arity-nargs) + [args[arity:]]
|
|
4084
|
+
t0 = objtogen(args)
|
|
4085
|
+
sig_on()
|
|
4086
|
+
result = closure_callgenvec(self.g, t0.g)
|
|
4087
|
+
if result is gnil:
|
|
4088
|
+
clear_stack()
|
|
4089
|
+
return None
|
|
4090
|
+
return new_gen(result)
|
|
4091
|
+
|
|
4092
|
+
# Evaluate univariate polynomials, rational functions and
|
|
4093
|
+
# series using *args
|
|
4094
|
+
if nargs:
|
|
4095
|
+
if nkwds:
|
|
4096
|
+
raise TypeError("mixing unnamed and keyword arguments not allowed when evaluating a PARI object")
|
|
4097
|
+
if not (t == t_POL or t == t_RFRAC or t == t_SER):
|
|
4098
|
+
raise TypeError("cannot evaluate PARI %s using unnamed arguments" % self.type())
|
|
4099
|
+
if nargs != 1:
|
|
4100
|
+
raise TypeError("evaluating PARI %s takes exactly 1 argument (%d given)"
|
|
4101
|
+
% (self.type(), nargs))
|
|
4102
|
+
|
|
4103
|
+
t0 = objtogen(args[0])
|
|
4104
|
+
sig_on()
|
|
4105
|
+
if t == t_POL or t == t_RFRAC:
|
|
4106
|
+
return new_gen(poleval(self.g, t0.g))
|
|
4107
|
+
else: # t == t_SER
|
|
4108
|
+
return new_gen(gsubst(self.g, varn(self.g), t0.g))
|
|
4109
|
+
|
|
4110
|
+
# Call substvec() using **kwds
|
|
4111
|
+
cdef list V = [to_bytes(k) for k in kwds] # Variables as Python byte strings
|
|
4112
|
+
t0 = objtogen(kwds.values()) # Replacements
|
|
4113
|
+
|
|
4114
|
+
sig_on()
|
|
4115
|
+
cdef GEN v = cgetg(nkwds+1, t_VEC) # Variables as PARI polynomials
|
|
4116
|
+
cdef long i
|
|
4117
|
+
for i in range(nkwds):
|
|
4118
|
+
varname = <bytes>V[i]
|
|
4119
|
+
set_gel(v, i+1, pol_x(fetch_user_var(varname)))
|
|
4120
|
+
return new_gen(gsubstvec(self.g, v, t0.g))
|
|
4121
|
+
|
|
4122
|
+
def arity(self):
|
|
4123
|
+
"""
|
|
4124
|
+
Return the number of arguments of this ``t_CLOSURE``.
|
|
4125
|
+
|
|
4126
|
+
>>> from cypari2 import Pari
|
|
4127
|
+
>>> pari = Pari()
|
|
4128
|
+
>>> pari("() -> 42").arity()
|
|
4129
|
+
0
|
|
4130
|
+
>>> pari("(x) -> x").arity()
|
|
4131
|
+
1
|
|
4132
|
+
>>> pari("(x,y,z) -> x+y+z").arity()
|
|
4133
|
+
3
|
|
4134
|
+
"""
|
|
4135
|
+
if typ(self.g) != t_CLOSURE:
|
|
4136
|
+
raise TypeError("arity() requires a t_CLOSURE")
|
|
4137
|
+
return closure_arity(self.g)
|
|
4138
|
+
|
|
4139
|
+
def factorpadic(self, p, long r=20):
|
|
4140
|
+
"""
|
|
4141
|
+
p-adic factorization of the polynomial ``pol`` to precision ``r``.
|
|
4142
|
+
|
|
4143
|
+
Examples:
|
|
4144
|
+
|
|
4145
|
+
>>> from cypari2 import Pari
|
|
4146
|
+
>>> pari = Pari()
|
|
4147
|
+
|
|
4148
|
+
>>> pol = pari('x^2 - 1')**2
|
|
4149
|
+
>>> pari(pol).factorpadic(5)
|
|
4150
|
+
[(1 + O(5^20))*x + (1 + O(5^20)), 2; (1 + O(5^20))*x + (4 + 4*5 + 4*5^2 + 4*5^3 + 4*5^4 + 4*5^5 + 4*5^6 + 4*5^7 + 4*5^8 + 4*5^9 + 4*5^10 + 4*5^11 + 4*5^12 + 4*5^13 + 4*5^14 + 4*5^15 + 4*5^16 + 4*5^17 + 4*5^18 + 4*5^19 + O(5^20)), 2]
|
|
4151
|
+
>>> pari(pol).factorpadic(5,3)
|
|
4152
|
+
[(1 + O(5^3))*x + (1 + O(5^3)), 2; (1 + O(5^3))*x + (4 + 4*5 + 4*5^2 + O(5^3)), 2]
|
|
4153
|
+
"""
|
|
4154
|
+
cdef Gen t0 = objtogen(p)
|
|
4155
|
+
sig_on()
|
|
4156
|
+
return new_gen(factorpadic(self.g, t0.g, r))
|
|
4157
|
+
|
|
4158
|
+
def ncols(self):
|
|
4159
|
+
"""
|
|
4160
|
+
Return the number of columns of self.
|
|
4161
|
+
|
|
4162
|
+
Examples:
|
|
4163
|
+
|
|
4164
|
+
>>> from cypari2 import Pari
|
|
4165
|
+
>>> pari = Pari()
|
|
4166
|
+
|
|
4167
|
+
>>> pari('matrix(19,8)').ncols()
|
|
4168
|
+
8
|
|
4169
|
+
"""
|
|
4170
|
+
cdef long n
|
|
4171
|
+
sig_on()
|
|
4172
|
+
n = glength(self.g)
|
|
4173
|
+
sig_off()
|
|
4174
|
+
return n
|
|
4175
|
+
|
|
4176
|
+
def nrows(self):
|
|
4177
|
+
"""
|
|
4178
|
+
Return the number of rows of self.
|
|
4179
|
+
|
|
4180
|
+
Examples:
|
|
4181
|
+
|
|
4182
|
+
>>> from cypari2 import Pari
|
|
4183
|
+
>>> pari = Pari()
|
|
4184
|
+
|
|
4185
|
+
>>> pari('matrix(19,8)').nrows()
|
|
4186
|
+
19
|
|
4187
|
+
"""
|
|
4188
|
+
cdef long n
|
|
4189
|
+
sig_on()
|
|
4190
|
+
# if this matrix has no columns
|
|
4191
|
+
# then it has no rows.
|
|
4192
|
+
if self.ncols() == 0:
|
|
4193
|
+
sig_off()
|
|
4194
|
+
return 0
|
|
4195
|
+
n = glength(gel(self.g, 1))
|
|
4196
|
+
sig_off()
|
|
4197
|
+
return n
|
|
4198
|
+
|
|
4199
|
+
def mattranspose(self):
|
|
4200
|
+
"""
|
|
4201
|
+
Transpose of the matrix self.
|
|
4202
|
+
|
|
4203
|
+
Examples:
|
|
4204
|
+
|
|
4205
|
+
>>> from cypari2 import Pari
|
|
4206
|
+
>>> pari = Pari()
|
|
4207
|
+
|
|
4208
|
+
>>> pari('[1,2,3; 4,5,6; 7,8,9]').mattranspose()
|
|
4209
|
+
[1, 4, 7; 2, 5, 8; 3, 6, 9]
|
|
4210
|
+
|
|
4211
|
+
Unlike PARI, this always returns a matrix:
|
|
4212
|
+
|
|
4213
|
+
>>> pari('[1,2,3]').mattranspose()
|
|
4214
|
+
[1; 2; 3]
|
|
4215
|
+
>>> pari('[1,2,3]~').mattranspose()
|
|
4216
|
+
Mat([1, 2, 3])
|
|
4217
|
+
"""
|
|
4218
|
+
sig_on()
|
|
4219
|
+
return new_gen(gtrans(self.g)).Mat()
|
|
4220
|
+
|
|
4221
|
+
def lllgram(self):
|
|
4222
|
+
return self.qflllgram(0)
|
|
4223
|
+
|
|
4224
|
+
def lllgramint(self):
|
|
4225
|
+
return self.qflllgram(1)
|
|
4226
|
+
|
|
4227
|
+
def qfrep(self, B, long flag=0):
|
|
4228
|
+
"""
|
|
4229
|
+
Vector of (half) the number of vectors of norms from 1 to `B`
|
|
4230
|
+
for the integral and definite quadratic form ``self``.
|
|
4231
|
+
Binary digits of flag mean 1: count vectors of even norm from
|
|
4232
|
+
1 to `2B`, 2: return a ``t_VECSMALL`` instead of a ``t_VEC``
|
|
4233
|
+
(which is faster).
|
|
4234
|
+
|
|
4235
|
+
Examples:
|
|
4236
|
+
|
|
4237
|
+
>>> from cypari2 import Pari
|
|
4238
|
+
>>> pari = Pari()
|
|
4239
|
+
|
|
4240
|
+
>>> M = pari("[5,1,1;1,3,1;1,1,1]")
|
|
4241
|
+
>>> M.qfrep(20)
|
|
4242
|
+
[1, 1, 2, 2, 2, 4, 4, 3, 3, 4, 2, 4, 6, 0, 4, 6, 4, 5, 6, 4]
|
|
4243
|
+
>>> M.qfrep(20, flag=1)
|
|
4244
|
+
[1, 2, 4, 3, 4, 4, 0, 6, 5, 4, 12, 4, 4, 8, 0, 3, 8, 6, 12, 12]
|
|
4245
|
+
>>> M.qfrep(20, flag=2)
|
|
4246
|
+
Vecsmall([1, 1, 2, 2, 2, 4, 4, 3, 3, 4, 2, 4, 6, 0, 4, 6, 4, 5, 6, 4])
|
|
4247
|
+
"""
|
|
4248
|
+
# PARI 2.7 always returns a t_VECSMALL, but for backwards
|
|
4249
|
+
# compatibility, we keep returning a t_VEC (unless flag & 2)
|
|
4250
|
+
cdef Gen t0 = objtogen(B)
|
|
4251
|
+
cdef GEN r
|
|
4252
|
+
sig_on()
|
|
4253
|
+
r = qfrep0(self.g, t0.g, flag & 1)
|
|
4254
|
+
if (flag & 2) == 0:
|
|
4255
|
+
r = vecsmall_to_vec(r)
|
|
4256
|
+
return new_gen(r)
|
|
4257
|
+
|
|
4258
|
+
def matkerint(self, long flag=0):
|
|
4259
|
+
"""
|
|
4260
|
+
Return the integer kernel of a matrix.
|
|
4261
|
+
|
|
4262
|
+
This is the LLL-reduced Z-basis of the kernel of the matrix x with
|
|
4263
|
+
integral entries.
|
|
4264
|
+
|
|
4265
|
+
Examples:
|
|
4266
|
+
|
|
4267
|
+
>>> from cypari2 import Pari
|
|
4268
|
+
>>> pari = Pari()
|
|
4269
|
+
|
|
4270
|
+
>>> pari('[2,1;2,1]').matkerint()
|
|
4271
|
+
[1; -2]
|
|
4272
|
+
>>> import warnings
|
|
4273
|
+
>>> with warnings.catch_warnings(record=True) as w:
|
|
4274
|
+
... warnings.simplefilter('always')
|
|
4275
|
+
... pari('[2,1;2,1]').matkerint(1)
|
|
4276
|
+
... assert len(w) == 1
|
|
4277
|
+
... assert issubclass(w[0].category, DeprecationWarning)
|
|
4278
|
+
[1; -2]
|
|
4279
|
+
"""
|
|
4280
|
+
if flag:
|
|
4281
|
+
# Keep this deprecation warning as long as PARI supports
|
|
4282
|
+
# this deprecated flag
|
|
4283
|
+
from warnings import warn
|
|
4284
|
+
warn("the 'flag' argument of the PARI/GP function matkerint is obsolete", DeprecationWarning)
|
|
4285
|
+
sig_on()
|
|
4286
|
+
return new_gen(matkerint0(self.g, flag))
|
|
4287
|
+
|
|
4288
|
+
def factor(self, long limit=-1, proof=None):
|
|
4289
|
+
"""
|
|
4290
|
+
Return the factorization of x.
|
|
4291
|
+
|
|
4292
|
+
INPUT:
|
|
4293
|
+
|
|
4294
|
+
- ``limit`` -- (default: -1) is optional and can be set
|
|
4295
|
+
whenever x is of (possibly recursive) rational type. If limit is
|
|
4296
|
+
set, return partial factorization, using primes up to limit.
|
|
4297
|
+
|
|
4298
|
+
- ``proof`` -- optional flag. If ``False`` (not the default),
|
|
4299
|
+
returned factors larger than `2^{64}` may only be pseudoprimes.
|
|
4300
|
+
If ``True``, always check primality. If not given, use the
|
|
4301
|
+
global PARI default ``factor_proven`` which is ``True`` by
|
|
4302
|
+
default in cypari.
|
|
4303
|
+
|
|
4304
|
+
Examples:
|
|
4305
|
+
|
|
4306
|
+
>>> from cypari2 import Pari
|
|
4307
|
+
>>> pari = Pari()
|
|
4308
|
+
|
|
4309
|
+
>>> pari('x^10-1').factor()
|
|
4310
|
+
[x - 1, 1; x + 1, 1; x^4 - x^3 + x^2 - x + 1, 1; x^4 + x^3 + x^2 + x + 1, 1]
|
|
4311
|
+
>>> pari(2**100-1).factor()
|
|
4312
|
+
[3, 1; 5, 3; 11, 1; 31, 1; 41, 1; 101, 1; 251, 1; 601, 1; 1801, 1; 4051, 1; 8101, 1; 268501, 1]
|
|
4313
|
+
>>> pari(2**100-1).factor(proof=True)
|
|
4314
|
+
[3, 1; 5, 3; 11, 1; 31, 1; 41, 1; 101, 1; 251, 1; 601, 1; 1801, 1; 4051, 1; 8101, 1; 268501, 1]
|
|
4315
|
+
>>> pari(2**100-1).factor(proof=False)
|
|
4316
|
+
[3, 1; 5, 3; 11, 1; 31, 1; 41, 1; 101, 1; 251, 1; 601, 1; 1801, 1; 4051, 1; 8101, 1; 268501, 1]
|
|
4317
|
+
|
|
4318
|
+
We illustrate setting a limit:
|
|
4319
|
+
|
|
4320
|
+
>>> pari(pari(10**50).nextprime()*pari(10**60).nextprime()*pari(10**4).nextprime()).factor(10**5)
|
|
4321
|
+
[10007, 1; 100000000000000000000000000000000000000000000000151000000000700000000000000000000000000000000000000000000001057, 1]
|
|
4322
|
+
|
|
4323
|
+
Setting a limit is invalid when factoring polynomials:
|
|
4324
|
+
|
|
4325
|
+
>>> pari('x^11 + 1').factor(limit=17)
|
|
4326
|
+
Traceback (most recent call last):
|
|
4327
|
+
...
|
|
4328
|
+
PariError: incorrect type in boundfact (t_POL)
|
|
4329
|
+
"""
|
|
4330
|
+
cdef GEN g
|
|
4331
|
+
global factor_proven
|
|
4332
|
+
cdef int saved_factor_proven = factor_proven
|
|
4333
|
+
|
|
4334
|
+
try:
|
|
4335
|
+
if proof is not None:
|
|
4336
|
+
factor_proven = 1 if proof else 0
|
|
4337
|
+
sig_on()
|
|
4338
|
+
if limit >= 0:
|
|
4339
|
+
g = boundfact(self.g, limit)
|
|
4340
|
+
else:
|
|
4341
|
+
g = factor(self.g)
|
|
4342
|
+
return new_gen(g)
|
|
4343
|
+
finally:
|
|
4344
|
+
factor_proven = saved_factor_proven
|
|
4345
|
+
|
|
4346
|
+
# Standard name for SageMath
|
|
4347
|
+
multiplicative_order = Gen_base.znorder
|
|
4348
|
+
|
|
4349
|
+
def __abs__(self):
|
|
4350
|
+
return self.abs()
|
|
4351
|
+
|
|
4352
|
+
def nextprime(self, bint add_one=False):
|
|
4353
|
+
"""
|
|
4354
|
+
nextprime(x): smallest pseudoprime greater than or equal to `x`.
|
|
4355
|
+
If ``add_one`` is non-zero, return the smallest pseudoprime
|
|
4356
|
+
strictly greater than `x`.
|
|
4357
|
+
|
|
4358
|
+
Examples:
|
|
4359
|
+
|
|
4360
|
+
>>> from cypari2 import Pari
|
|
4361
|
+
>>> pari = Pari()
|
|
4362
|
+
|
|
4363
|
+
>>> pari(1).nextprime()
|
|
4364
|
+
2
|
|
4365
|
+
>>> pari(2).nextprime()
|
|
4366
|
+
2
|
|
4367
|
+
>>> pari(2).nextprime(add_one = 1)
|
|
4368
|
+
3
|
|
4369
|
+
>>> pari(2**100).nextprime()
|
|
4370
|
+
1267650600228229401496703205653
|
|
4371
|
+
"""
|
|
4372
|
+
sig_on()
|
|
4373
|
+
if add_one:
|
|
4374
|
+
return new_gen(nextprime(gaddsg(1, self.g)))
|
|
4375
|
+
return new_gen(nextprime(self.g))
|
|
4376
|
+
|
|
4377
|
+
def change_variable_name(self, var):
|
|
4378
|
+
"""
|
|
4379
|
+
In ``self``, which must be a ``t_POL`` or ``t_SER``, set the
|
|
4380
|
+
variable to ``var``. If the variable of ``self`` is already
|
|
4381
|
+
``var``, then return ``self``.
|
|
4382
|
+
|
|
4383
|
+
.. WARNING::
|
|
4384
|
+
|
|
4385
|
+
You should be careful with variable priorities when
|
|
4386
|
+
applying this on a polynomial or series of which the
|
|
4387
|
+
coefficients have polynomial components. To be safe, only
|
|
4388
|
+
use this function on polynomials with integer or rational
|
|
4389
|
+
coefficients. For a safer alternative, use :meth:`subst`.
|
|
4390
|
+
|
|
4391
|
+
Examples:
|
|
4392
|
+
|
|
4393
|
+
>>> from cypari2 import Pari
|
|
4394
|
+
>>> pari = Pari()
|
|
4395
|
+
|
|
4396
|
+
>>> f = pari('x^3 + 17*x + 3')
|
|
4397
|
+
>>> f.change_variable_name("y")
|
|
4398
|
+
y^3 + 17*y + 3
|
|
4399
|
+
>>> f = pari('1 + 2*y + O(y^10)')
|
|
4400
|
+
>>> f.change_variable_name("q")
|
|
4401
|
+
1 + 2*q + O(q^10)
|
|
4402
|
+
>>> f.change_variable_name("y") is f
|
|
4403
|
+
True
|
|
4404
|
+
|
|
4405
|
+
In PARI, ``I`` refers to the square root of -1, so it cannot be
|
|
4406
|
+
used as variable name. Note the difference with :meth:`subst`:
|
|
4407
|
+
|
|
4408
|
+
>>> f = pari('x^2 + 1')
|
|
4409
|
+
>>> f.change_variable_name("I")
|
|
4410
|
+
Traceback (most recent call last):
|
|
4411
|
+
...
|
|
4412
|
+
PariError: I already exists with incompatible valence
|
|
4413
|
+
>>> f.subst("x", "I")
|
|
4414
|
+
0
|
|
4415
|
+
"""
|
|
4416
|
+
cdef long n = get_var(var)
|
|
4417
|
+
if varn(self.g) == n:
|
|
4418
|
+
return self
|
|
4419
|
+
if typ(self.g) != t_POL and typ(self.g) != t_SER:
|
|
4420
|
+
raise TypeError("set_variable() only works for polynomials or power series")
|
|
4421
|
+
# Copy self and then change the variable in place
|
|
4422
|
+
sig_on()
|
|
4423
|
+
newg = clone_gen(self.g)
|
|
4424
|
+
setvarn(newg.g, n)
|
|
4425
|
+
return newg
|
|
4426
|
+
|
|
4427
|
+
def nf_subst(self, z):
|
|
4428
|
+
"""
|
|
4429
|
+
Given a PARI number field ``self``, return the same PARI
|
|
4430
|
+
number field but in the variable ``z``.
|
|
4431
|
+
|
|
4432
|
+
INPUT:
|
|
4433
|
+
|
|
4434
|
+
- ``self`` -- A PARI number field being the output of ``nfinit()``,
|
|
4435
|
+
``bnfinit()`` or ``bnrinit()``.
|
|
4436
|
+
|
|
4437
|
+
Examples:
|
|
4438
|
+
|
|
4439
|
+
>>> from cypari2 import Pari
|
|
4440
|
+
>>> pari = Pari()
|
|
4441
|
+
|
|
4442
|
+
>>> K = pari('y^2 + 5').nfinit()
|
|
4443
|
+
|
|
4444
|
+
We can substitute in a PARI ``nf`` structure:
|
|
4445
|
+
|
|
4446
|
+
>>> K.nf_get_pol()
|
|
4447
|
+
y^2 + 5
|
|
4448
|
+
>>> L = K.nf_subst('a')
|
|
4449
|
+
>>> L.nf_get_pol()
|
|
4450
|
+
a^2 + 5
|
|
4451
|
+
|
|
4452
|
+
We can also substitute in a PARI ``bnf`` structure:
|
|
4453
|
+
|
|
4454
|
+
>>> K = pari('y^2 + 5').bnfinit()
|
|
4455
|
+
>>> K.nf_get_pol()
|
|
4456
|
+
y^2 + 5
|
|
4457
|
+
>>> K.bnf_get_cyc() # Structure of class group
|
|
4458
|
+
[2]
|
|
4459
|
+
>>> L = K.nf_subst('a')
|
|
4460
|
+
>>> L.nf_get_pol()
|
|
4461
|
+
a^2 + 5
|
|
4462
|
+
>>> L.bnf_get_cyc() # We still have a bnf after substituting
|
|
4463
|
+
[2]
|
|
4464
|
+
"""
|
|
4465
|
+
cdef Gen t0 = objtogen(z)
|
|
4466
|
+
sig_on()
|
|
4467
|
+
return new_gen(gsubst(self.g, gvar(self.g), t0.g))
|
|
4468
|
+
|
|
4469
|
+
def type(self):
|
|
4470
|
+
"""
|
|
4471
|
+
Return the PARI type of self as a string.
|
|
4472
|
+
|
|
4473
|
+
.. NOTE::
|
|
4474
|
+
|
|
4475
|
+
In Cython, it is much faster to simply use typ(self.g) for
|
|
4476
|
+
checking PARI types.
|
|
4477
|
+
|
|
4478
|
+
Examples:
|
|
4479
|
+
|
|
4480
|
+
>>> from cypari2 import Pari
|
|
4481
|
+
>>> pari = Pari()
|
|
4482
|
+
|
|
4483
|
+
>>> pari(7).type()
|
|
4484
|
+
't_INT'
|
|
4485
|
+
>>> pari('x').type()
|
|
4486
|
+
't_POL'
|
|
4487
|
+
>>> pari('oo').type()
|
|
4488
|
+
't_INFINITY'
|
|
4489
|
+
"""
|
|
4490
|
+
sig_on()
|
|
4491
|
+
s = type_name(typ(self.g))
|
|
4492
|
+
sig_off()
|
|
4493
|
+
return to_string(s)
|
|
4494
|
+
|
|
4495
|
+
def polinterpolate(self, ya, x):
|
|
4496
|
+
"""
|
|
4497
|
+
self.polinterpolate(ya,x,e): polynomial interpolation at x
|
|
4498
|
+
according to data vectors self, ya (i.e. return P such that
|
|
4499
|
+
P(self[i]) = ya[i] for all i). Also return an error estimate on the
|
|
4500
|
+
returned value.
|
|
4501
|
+
"""
|
|
4502
|
+
cdef Gen t0 = objtogen(ya)
|
|
4503
|
+
cdef Gen t1 = objtogen(x)
|
|
4504
|
+
cdef GEN dy, g
|
|
4505
|
+
sig_on()
|
|
4506
|
+
g = polint(self.g, t0.g, t1.g, &dy)
|
|
4507
|
+
return new_gens2(g, dy)
|
|
4508
|
+
|
|
4509
|
+
def ellwp(self, z='z', long n=20, long flag=0,
|
|
4510
|
+
unsigned long precision=DEFAULT_BITPREC):
|
|
4511
|
+
"""
|
|
4512
|
+
Return the value or the series expansion of the Weierstrass
|
|
4513
|
+
`P`-function at `z` on the lattice `self` (or the lattice
|
|
4514
|
+
defined by the elliptic curve `self`).
|
|
4515
|
+
|
|
4516
|
+
INPUT:
|
|
4517
|
+
|
|
4518
|
+
- ``self`` -- an elliptic curve created using ``ellinit`` or a
|
|
4519
|
+
list ``[om1, om2]`` representing generators for a lattice.
|
|
4520
|
+
|
|
4521
|
+
- ``z`` -- (default: 'z') a complex number or a variable name
|
|
4522
|
+
(as string or PARI variable).
|
|
4523
|
+
|
|
4524
|
+
- ``n`` -- (default: 20) if 'z' is a variable, compute the
|
|
4525
|
+
series expansion up to at least `O(z^n)`.
|
|
4526
|
+
|
|
4527
|
+
- ``flag`` -- (default = 0): If ``flag`` is 0, compute only
|
|
4528
|
+
`P(z)`. If ``flag`` is 1, compute `[P(z), P'(z)]`.
|
|
4529
|
+
|
|
4530
|
+
OUTPUT:
|
|
4531
|
+
|
|
4532
|
+
- `P(z)` (if ``flag`` is 0) or `[P(z), P'(z)]` (if ``flag`` is 1).
|
|
4533
|
+
numbers
|
|
4534
|
+
|
|
4535
|
+
Examples:
|
|
4536
|
+
|
|
4537
|
+
We first define the elliptic curve X_0(11):
|
|
4538
|
+
|
|
4539
|
+
>>> from cypari2 import Pari
|
|
4540
|
+
>>> pari = Pari()
|
|
4541
|
+
|
|
4542
|
+
>>> E = pari([0,-1,1,-10,-20]).ellinit()
|
|
4543
|
+
|
|
4544
|
+
Compute P(1):
|
|
4545
|
+
|
|
4546
|
+
>>> E.ellwp(1)
|
|
4547
|
+
13.9658695257485
|
|
4548
|
+
|
|
4549
|
+
Compute P(1+i), where i = sqrt(-1):
|
|
4550
|
+
|
|
4551
|
+
>>> E.ellwp(pari(complex(1, 1)))
|
|
4552
|
+
-1.11510682565555 + 2.33419052307470*I
|
|
4553
|
+
>>> E.ellwp(complex(1, 1))
|
|
4554
|
+
-1.11510682565555 + 2.33419052307470*I
|
|
4555
|
+
|
|
4556
|
+
The series expansion, to the default `O(z^20)` precision:
|
|
4557
|
+
|
|
4558
|
+
>>> E.ellwp()
|
|
4559
|
+
z^-2 + 31/15*z^2 + 2501/756*z^4 + 961/675*z^6 + 77531/41580*z^8 + 1202285717/928746000*z^10 + 2403461/2806650*z^12 + 30211462703/43418875500*z^14 + 3539374016033/7723451736000*z^16 + 413306031683977/1289540602350000*z^18 + O(z^20)
|
|
4560
|
+
|
|
4561
|
+
Compute the series for wp to lower precision:
|
|
4562
|
+
|
|
4563
|
+
>>> E.ellwp(n=4)
|
|
4564
|
+
z^-2 + 31/15*z^2 + O(z^4)
|
|
4565
|
+
|
|
4566
|
+
Next we use the version where the input is generators for a
|
|
4567
|
+
lattice:
|
|
4568
|
+
|
|
4569
|
+
>>> pari([1.2692, complex(0.63, 1.45)]).ellwp(1)
|
|
4570
|
+
13.9656146936689 + 0.000644829272810...*I
|
|
4571
|
+
|
|
4572
|
+
With flag=1, compute the pair P(z) and P'(z):
|
|
4573
|
+
|
|
4574
|
+
>>> E.ellwp(1, flag=1)
|
|
4575
|
+
[13.9658695257485, 101.123860176015]
|
|
4576
|
+
"""
|
|
4577
|
+
cdef Gen t0 = objtogen(z)
|
|
4578
|
+
cdef GEN g0 = t0.g
|
|
4579
|
+
|
|
4580
|
+
sig_on()
|
|
4581
|
+
# Polynomial or rational function as input:
|
|
4582
|
+
# emulate toser_i() but with given precision
|
|
4583
|
+
if typ(g0) == t_POL:
|
|
4584
|
+
g0 = RgX_to_ser(g0, n+4)
|
|
4585
|
+
elif typ(g0) == t_RFRAC:
|
|
4586
|
+
g0 = rfrac_to_ser(g0, n+4)
|
|
4587
|
+
|
|
4588
|
+
cdef GEN r = ellwp0(self.g, g0, flag, nbits2prec(precision))
|
|
4589
|
+
if flag == 1 and have_ellwp_flag1_bug():
|
|
4590
|
+
# Work around ellwp() bug: double the second element
|
|
4591
|
+
set_gel(r, 2, gmulgs(gel(r, 2), 2))
|
|
4592
|
+
return new_gen(r)
|
|
4593
|
+
|
|
4594
|
+
def debug(self, long depth=-1):
|
|
4595
|
+
r"""
|
|
4596
|
+
Show the internal structure of self (like the ``\x`` command in gp).
|
|
4597
|
+
|
|
4598
|
+
Examples:
|
|
4599
|
+
|
|
4600
|
+
>>> from cypari2 import Pari
|
|
4601
|
+
>>> pari = Pari()
|
|
4602
|
+
|
|
4603
|
+
>>> pari('[1/2, 1 + 1.0*I]').debug()
|
|
4604
|
+
[&=...] VEC(lg=3):...
|
|
4605
|
+
1st component = [&=...] FRAC(lg=3):...
|
|
4606
|
+
num = [&=...] INT(lg=3):... (+,lgefint=3):...
|
|
4607
|
+
den = [&=...] INT(lg=3):... (+,lgefint=3):...
|
|
4608
|
+
2nd component = [&=...] COMPLEX(lg=3):...
|
|
4609
|
+
real = [&=...] INT(lg=3):... (+,lgefint=3):...
|
|
4610
|
+
imag = [&=...] REAL(lg=...):... (+,expo=0):...
|
|
4611
|
+
"""
|
|
4612
|
+
sig_on()
|
|
4613
|
+
dbgGEN(self.g, depth)
|
|
4614
|
+
clear_stack()
|
|
4615
|
+
return
|
|
4616
|
+
|
|
4617
|
+
def allocatemem(self, *args):
|
|
4618
|
+
"""
|
|
4619
|
+
Do not use this. Use ``pari.allocatemem()`` instead.
|
|
4620
|
+
|
|
4621
|
+
Tests:
|
|
4622
|
+
|
|
4623
|
+
>>> from cypari2 import Pari
|
|
4624
|
+
>>> pari = Pari()
|
|
4625
|
+
>>> pari(2**10).allocatemem(2**20)
|
|
4626
|
+
Traceback (most recent call last):
|
|
4627
|
+
...
|
|
4628
|
+
NotImplementedError: the method allocatemem() should not be used; use pari.allocatemem() instead
|
|
4629
|
+
"""
|
|
4630
|
+
raise NotImplementedError("the method allocatemem() should not be used; use pari.allocatemem() instead")
|
|
4631
|
+
|
|
4632
|
+
|
|
4633
|
+
cdef int Gen_clear(self) except -1:
|
|
4634
|
+
"""
|
|
4635
|
+
Implementation of tp_clear() for Gen. We need to override Cython's
|
|
4636
|
+
default since we do not want self.next to be cleared: it is crucial
|
|
4637
|
+
that the next Gen stays alive until remove_from_pari_stack(self) is
|
|
4638
|
+
called by __dealloc__.
|
|
4639
|
+
"""
|
|
4640
|
+
# Only itemcache needs to be cleared
|
|
4641
|
+
(<Gen>self).itemcache = None
|
|
4642
|
+
|
|
4643
|
+
|
|
4644
|
+
(<PyTypeObject*>Gen).tp_clear = Gen_clear
|
|
4645
|
+
|
|
4646
|
+
|
|
4647
|
+
@cython.boundscheck(False)
|
|
4648
|
+
@cython.wraparound(False)
|
|
4649
|
+
cdef Gen list_of_Gens_to_Gen(list s):
|
|
4650
|
+
"""
|
|
4651
|
+
Convert a Python list whole elements are all :class:`Gen` objects
|
|
4652
|
+
(this is not checked!) to a single PARI :class:`Gen` of type ``t_VEC``.
|
|
4653
|
+
|
|
4654
|
+
This is called from :func:`objtogen` to convert iterables to PARI.
|
|
4655
|
+
|
|
4656
|
+
Tests:
|
|
4657
|
+
|
|
4658
|
+
>>> from cypari2.gen import objtogen
|
|
4659
|
+
>>> from cypari2 import Pari
|
|
4660
|
+
>>> pari = Pari()
|
|
4661
|
+
|
|
4662
|
+
>>> objtogen(range(10))
|
|
4663
|
+
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
4664
|
+
>>> objtogen(i**2 for i in range(5))
|
|
4665
|
+
[0, 1, 4, 9, 16]
|
|
4666
|
+
>>> objtogen([pari("Mod(x, x^2+1)")])
|
|
4667
|
+
[Mod(x, x^2 + 1)]
|
|
4668
|
+
>>> objtogen([])
|
|
4669
|
+
[]
|
|
4670
|
+
"""
|
|
4671
|
+
cdef Py_ssize_t length = len(s)
|
|
4672
|
+
|
|
4673
|
+
sig_on()
|
|
4674
|
+
cdef GEN g = cgetg(length+1, t_VEC)
|
|
4675
|
+
|
|
4676
|
+
cdef Py_ssize_t i
|
|
4677
|
+
for i in range(length):
|
|
4678
|
+
set_gel(g, i+1, (<Gen>s[i]).g)
|
|
4679
|
+
return clone_gen(g)
|
|
4680
|
+
|
|
4681
|
+
|
|
4682
|
+
cpdef Gen objtogen(s):
|
|
4683
|
+
"""
|
|
4684
|
+
Convert any SageMath/Python object to a PARI :class:`Gen`.
|
|
4685
|
+
|
|
4686
|
+
For SageMath types, this uses the ``__pari__()`` method on the
|
|
4687
|
+
object. Basic Python types like ``int`` are converted directly.
|
|
4688
|
+
For other types, the string representation is used.
|
|
4689
|
+
|
|
4690
|
+
Examples:
|
|
4691
|
+
|
|
4692
|
+
>>> from cypari2 import Pari
|
|
4693
|
+
>>> pari = Pari()
|
|
4694
|
+
|
|
4695
|
+
>>> pari(0)
|
|
4696
|
+
0
|
|
4697
|
+
>>> pari([2,3,5])
|
|
4698
|
+
[2, 3, 5]
|
|
4699
|
+
|
|
4700
|
+
>>> a = pari(1)
|
|
4701
|
+
>>> a, a.type()
|
|
4702
|
+
(1, 't_INT')
|
|
4703
|
+
|
|
4704
|
+
>>> from fractions import Fraction
|
|
4705
|
+
>>> a = pari(Fraction('1/2'))
|
|
4706
|
+
>>> a, a.type()
|
|
4707
|
+
(1/2, 't_FRAC')
|
|
4708
|
+
|
|
4709
|
+
Conversion from reals uses the real's own precision:
|
|
4710
|
+
|
|
4711
|
+
>>> a = pari(1.2); a, a.type(), a.bitprecision()
|
|
4712
|
+
(1.20000000000000, 't_REAL', 64)
|
|
4713
|
+
|
|
4714
|
+
Conversion from strings uses the current PARI real precision.
|
|
4715
|
+
By default, this is 64 bits:
|
|
4716
|
+
|
|
4717
|
+
>>> a = pari('1.2'); a, a.type(), a.bitprecision()
|
|
4718
|
+
(1.20000000000000, 't_REAL', 64)
|
|
4719
|
+
|
|
4720
|
+
Unicode and bytes work fine:
|
|
4721
|
+
|
|
4722
|
+
>>> pari(b"zeta(3)")
|
|
4723
|
+
1.20205690315959
|
|
4724
|
+
>>> pari(u"zeta(3)")
|
|
4725
|
+
1.20205690315959
|
|
4726
|
+
|
|
4727
|
+
But we can change this precision:
|
|
4728
|
+
|
|
4729
|
+
>>> pari.set_real_precision(35) # precision in decimal digits
|
|
4730
|
+
15
|
|
4731
|
+
>>> a = pari('Pi'); a, a.type(), a.bitprecision()
|
|
4732
|
+
(3.1415926535897932384626433832795029, 't_REAL', 128)
|
|
4733
|
+
>>> a = pari('1.2'); a, a.type(), a.bitprecision()
|
|
4734
|
+
(1.2000000000000000000000000000000000, 't_REAL', 128)
|
|
4735
|
+
|
|
4736
|
+
Set the precision to 15 digits for the remaining tests:
|
|
4737
|
+
|
|
4738
|
+
>>> pari.set_real_precision(15)
|
|
4739
|
+
35
|
|
4740
|
+
|
|
4741
|
+
Conversion from basic Python types:
|
|
4742
|
+
|
|
4743
|
+
>>> pari(int(-5))
|
|
4744
|
+
-5
|
|
4745
|
+
>>> pari(2**150)
|
|
4746
|
+
1427247692705959881058285969449495136382746624
|
|
4747
|
+
>>> import math
|
|
4748
|
+
>>> pari(math.pi)
|
|
4749
|
+
3.14159265358979
|
|
4750
|
+
>>> one = pari(complex(1,0)); one, one.type()
|
|
4751
|
+
(1.00000000000000, 't_COMPLEX')
|
|
4752
|
+
>>> pari(complex(0, 1))
|
|
4753
|
+
1.00000000000000*I
|
|
4754
|
+
>>> pari(complex(0.3, 1.7))
|
|
4755
|
+
0.300000000000000 + 1.70000000000000*I
|
|
4756
|
+
|
|
4757
|
+
>>> pari(False)
|
|
4758
|
+
0
|
|
4759
|
+
>>> pari(True)
|
|
4760
|
+
1
|
|
4761
|
+
|
|
4762
|
+
The following looks strange, but it is what PARI does:
|
|
4763
|
+
|
|
4764
|
+
>>> pari(["print(x)"])
|
|
4765
|
+
x
|
|
4766
|
+
[0]
|
|
4767
|
+
>>> pari("[print(x)]")
|
|
4768
|
+
x
|
|
4769
|
+
[0]
|
|
4770
|
+
|
|
4771
|
+
Tests:
|
|
4772
|
+
|
|
4773
|
+
>>> pari(None)
|
|
4774
|
+
Traceback (most recent call last):
|
|
4775
|
+
...
|
|
4776
|
+
ValueError: Cannot convert None to pari
|
|
4777
|
+
|
|
4778
|
+
"""
|
|
4779
|
+
if isinstance(s, Gen):
|
|
4780
|
+
return s
|
|
4781
|
+
|
|
4782
|
+
try:
|
|
4783
|
+
m = s.__pari__
|
|
4784
|
+
except AttributeError:
|
|
4785
|
+
pass
|
|
4786
|
+
else:
|
|
4787
|
+
return m()
|
|
4788
|
+
|
|
4789
|
+
cdef GEN g = PyObject_AsGEN(s)
|
|
4790
|
+
if g is not NULL:
|
|
4791
|
+
res = new_gen_noclear(g)
|
|
4792
|
+
reset_avma()
|
|
4793
|
+
return res
|
|
4794
|
+
|
|
4795
|
+
# Check for iterables. Handle the common cases of lists and tuples
|
|
4796
|
+
# separately as an optimization
|
|
4797
|
+
cdef list L
|
|
4798
|
+
if isinstance(s, list):
|
|
4799
|
+
L = [objtogen(x) for x in <list>s]
|
|
4800
|
+
return list_of_Gens_to_Gen(L)
|
|
4801
|
+
if isinstance(s, tuple):
|
|
4802
|
+
L = [objtogen(x) for x in <tuple>s]
|
|
4803
|
+
return list_of_Gens_to_Gen(L)
|
|
4804
|
+
# Check for iterable object s
|
|
4805
|
+
try:
|
|
4806
|
+
L = [objtogen(x) for x in s]
|
|
4807
|
+
except TypeError:
|
|
4808
|
+
pass
|
|
4809
|
+
else:
|
|
4810
|
+
return list_of_Gens_to_Gen(L)
|
|
4811
|
+
|
|
4812
|
+
if callable(s):
|
|
4813
|
+
return objtoclosure(s)
|
|
4814
|
+
|
|
4815
|
+
if s is None:
|
|
4816
|
+
raise ValueError("Cannot convert None to pari")
|
|
4817
|
+
|
|
4818
|
+
# Simply use the string representation
|
|
4819
|
+
return objtogen(str(s))
|