Ticket #11868: trac_11868-t0GEN_new.patch
File trac_11868-t0GEN_new.patch, 73.4 KB (added by , 9 years ago) |
---|
-
sage/libs/pari/gen.pxd
# HG changeset patch # User Peter Bruin <P.Bruin@warwick.ac.uk> # Date 1385402703 0 # Node ID ac52ef68ec4472b529334cdd9c5211077db2f446 # Parent 33a4ab61f20f40e2d3ba5f075ab97a4ac368b6b7 Trac 11868: eliminate global GEN variables diff --git a/sage/libs/pari/gen.pxd b/sage/libs/pari/gen.pxd
a b 14 14 cdef gen pari(self, object x) 15 15 cdef GEN _deepcopy_to_python_heap(self, GEN x, pari_sp* address) 16 16 cdef long get_var(self, v) 17 cdef GEN get_nf(self) except NULL18 17 19 18 cdef class PariInstance(sage.structure.parent_base.ParentWithBase): 20 19 cdef gen PARI_ZERO, PARI_ONE, PARI_TWO 21 20 cdef gen new_gen(self, GEN x) 22 cdef object new_gen_to_string(self, GEN x)23 21 cdef gen new_gen_noclear(self, GEN x) 24 22 cdef gen new_gen_from_mpz_t(self, mpz_t value) 25 23 cdef inline GEN _new_GEN_from_mpz_t(self, mpz_t value) … … 29 27 cdef gen new_t_POL_from_int_star(self, int *vals, int length, long varnum) 30 28 cdef gen new_gen_from_padic(self, long ordp, long relprec, mpz_t prime, mpz_t p_pow, mpz_t unit) 31 29 cdef void clear_stack(self) 32 cdef void set_mytop_to_avma(self)33 30 cdef gen double_to_gen_c(self, double) 34 31 cdef GEN double_to_GEN(self, double) 35 32 cdef GEN deepcopy_to_python_heap(self, GEN x, pari_sp* address) 36 33 cdef gen new_ref(self, GEN g, gen parent) 37 34 cdef gen _empty_vector(self, long n) 38 35 cdef long get_var(self, v) 39 cdef GEN toGEN(self, x, int i) except NULL40 36 cdef GEN _new_GEN_from_mpz_t_matrix(self, mpz_t** B, Py_ssize_t nr, Py_ssize_t nc) 41 37 cdef GEN _new_GEN_from_mpz_t_matrix_rotate90(self, mpz_t** B, Py_ssize_t nr, Py_ssize_t nc) 42 38 cdef gen integer_matrix(self, mpz_t** B, Py_ssize_t nr, Py_ssize_t nc, bint permute_for_hnf) -
sage/libs/pari/gen.pyx
diff --git a/sage/libs/pari/gen.pyx b/sage/libs/pari/gen.pyx
a b 189 189 cdef extern from "mpz_pylong.h": 190 190 cdef int mpz_set_pylong(mpz_t dst, src) except -1 191 191 192 # Make sure we don't use mpz_t_offset before initializing it by193 # putting in a value that's likely to provoke a segmentation fault,194 # rather than silently corrupting memory.195 cdef long mpz_t_offset = 1000000000196 197 192 # so Galois groups are represented in a sane way 198 193 # See the polgalois section of the PARI users manual. 199 194 new_galois_format = 1 … … 376 371 # Also a copy of PARI accessible from external pure python code. 377 372 pari = pari_instance 378 373 379 # temp variables380 cdef GEN t0,t1,t2,t3,t4381 t0heap = [0]*5382 383 cdef t0GEN(x):384 global t0385 t0 = P.toGEN(x, 0)386 387 cdef t1GEN(x):388 global t1389 t1 = P.toGEN(x, 1)390 391 cdef t2GEN(x):392 global t2393 t2 = P.toGEN(x, 2)394 395 cdef t3GEN(x):396 global t3397 t3 = P.toGEN(x, 3)398 399 cdef t4GEN(x):400 global t4401 t4 = P.toGEN(x, 4)402 403 374 cdef object Integer 404 375 405 376 cdef void late_import(): … … 411 382 import sage.rings.integer 412 383 Integer = sage.rings.integer.Integer 413 384 414 global mpz_t_offset415 mpz_t_offset = sage.rings.integer.mpz_t_offset_python416 385 417 386 cdef class gen(sage.structure.element.RingElement): 418 387 """ … … 442 411 sage_free(<void*> self.b) 443 412 444 413 def __repr__(self): 445 pari_catch_sig_on() 446 return P.new_gen_to_string(self.g) 414 cdef char *c 415 cdef str s 416 pari_catch_sig_on() 417 c = GENtostr(self.g) 418 s = str(c) 419 pari_free(c) 420 pari_catch_sig_off() 421 return s 447 422 448 423 def __hash__(self): 449 424 """ … … 681 656 return P.new_gen(gmod(selfgen.g, othergen.g)) 682 657 return sage.structure.element.bin_op(self, other, operator.mod) 683 658 684 def __pow__(self, n, m): 685 t0GEN(self) 686 t1GEN(n) 687 pari_catch_sig_on() 688 # Note: the prec parameter here has no effect when t0,t1 are 689 # real; the precision of the result is the minimum of the 690 # precisions of t0 and t1. In any case the 3rd parameter to 691 # gpow should be a word-precision, not a decimal precision. 692 return P.new_gen(gpow(t0, t1, prec)) 659 def __pow__(gen self, n, m): 660 cdef gen t0 = P(n) 661 pari_catch_sig_on() 662 return P.new_gen(gpow(self.g, t0.g, prec)) 693 663 694 664 def __neg__(gen self): 695 665 pari_catch_sig_on() … … 715 685 # ACCESS 716 686 ########################################### 717 687 def getattr(self, attr): 718 t0GEN(str(self) + '.' + str(attr)) 719 pari_catch_sig_on() 720 return self.new_gen(t0) 688 return P(str(self) + '.' + str(attr)) 721 689 722 690 def mod(self): 723 691 """ … … 742 710 # stored. 743 711 return self.new_gen(gel(self.g, 1)) 744 712 745 cdef GEN get_nf(self) except NULL: 746 """ 747 Given a PARI object `self`, convert it to a proper PARI number 748 field (nf) structure. 713 def nf_get_pol(self): 714 """ 715 Returns the defining polynomial of this number field. 749 716 750 717 INPUT: 751 718 752 719 - ``self`` -- A PARI number field being the output of ``nfinit()``, 753 720 ``bnfinit()`` or ``bnrinit()``. 754 721 755 TESTS: 756 757 We test this indirectly through `nf_get_pol()`:: 722 EXAMPLES:: 723 724 sage: K.<a> = NumberField(x^4 - 4*x^2 + 1) 725 sage: pari(K).nf_get_pol() 726 y^4 - 4*y^2 + 1 727 sage: bnr = pari("K = bnfinit(x^4 - 4*x^2 + 1); bnrinit(K, 2*x)") 728 sage: bnr.nf_get_pol() 729 x^4 - 4*x^2 + 1 730 731 For relative extensions, this returns the absolute polynomial, 732 not the relative one:: 733 734 sage: L.<b> = K.extension(x^2 - 5) 735 sage: pari(L).nf_get_pol() # Absolute polynomial 736 y^8 - 28*y^6 + 208*y^4 - 408*y^2 + 36 737 sage: L.pari_rnf().nf_get_pol() 738 x^8 - 28*x^6 + 208*x^4 - 408*x^2 + 36 739 740 TESTS:: 758 741 759 742 sage: x = polygen(QQ) 760 743 sage: K.<a> = NumberField(x^4 - 4*x^2 + 1) … … 762 745 y^4 - 4*y^2 + 1 763 746 sage: K.pari_bnf().nf_get_pol() 764 747 y^4 - 4*y^2 + 1 765 sage: bnr = pari("K = bnfinit(x^4 - 4*x^2 + 1); bnrinit(K, 2*x)") 766 sage: bnr.nf_get_pol() 767 x^4 - 4*x^2 + 1 768 769 It does not work with ``rnfinit()`` or garbage input:: 770 771 sage: K.extension(x^2 - 5, 'b').pari_rnf().nf_get_pol() 772 Traceback (most recent call last): 773 ... 774 TypeError: Not a PARI number field 748 749 An error is raised for invalid input:: 750 775 751 sage: pari("[0]").nf_get_pol() 776 752 Traceback (most recent call last): 777 753 ... 778 TypeError: Not a PARI number field 779 """ 780 cdef GEN nf 781 cdef long nftyp 782 pari_catch_sig_on() 783 nf = get_nf(self.g, &nftyp) 784 pari_catch_sig_off() 785 if not nf: 786 raise TypeError("Not a PARI number field") 787 return nf 788 789 def nf_get_pol(self): 790 """ 791 Returns the defining polynomial of this number field. 792 793 INPUT: 794 795 - ``self`` -- A PARI number field being the output of ``nfinit()``, 796 ``bnfinit()`` or ``bnrinit()``. 797 798 EXAMPLES:: 799 800 sage: K.<a> = NumberField(x^4 - 4*x^2 + 1) 801 sage: pari(K).nf_get_pol() 802 y^4 - 4*y^2 + 1 803 sage: bnr = pari("K = bnfinit(x^4 - 4*x^2 + 1); bnrinit(K, 2*x)") 804 sage: bnr.nf_get_pol() 805 x^4 - 4*x^2 + 1 806 807 For relative extensions, we can only get the absolute polynomial, 808 not the relative one:: 809 810 sage: L.<b> = K.extension(x^2 - 5) 811 sage: pari(L).nf_get_pol() # Absolute polynomial 812 y^8 - 28*y^6 + 208*y^4 - 408*y^2 + 36 813 sage: L.pari_rnf().nf_get_pol() 814 Traceback (most recent call last): 815 ... 816 TypeError: Not a PARI number field 817 """ 818 cdef GEN nf = self.get_nf() 819 pari_catch_sig_on() 820 return self.new_gen(nf_get_pol(nf)) 754 PariError: incorrect type in pol 755 """ 756 pari_catch_sig_on() 757 return P.new_gen(member_pol(self.g)) 821 758 822 759 def nf_get_diff(self): 823 760 """ … … 834 771 sage: pari(K).nf_get_diff() 835 772 [12, 0, 0, 0; 0, 12, 8, 0; 0, 0, 4, 0; 0, 0, 0, 4] 836 773 """ 837 cdef GEN nf = self.get_nf() 838 pari_catch_sig_on() 839 # Very bad code, but there doesn't seem to be a better way 840 return self.new_gen(gel(gel(nf, 5), 5)) 774 pari_catch_sig_on() 775 return P.new_gen(member_diff(self.g)) 841 776 842 777 def nf_get_sign(self): 843 778 """ … … 863 798 """ 864 799 cdef long r1 865 800 cdef long r2 866 cdef GEN nf = self.get_nf() 867 nf_get_sign(nf, &r1, &r2) 801 cdef GEN sign 802 pari_catch_sig_on() 803 sign = member_sign(self.g) 804 r1 = itos(gel(sign, 1)) 805 r2 = itos(gel(sign, 2)) 806 pari_catch_sig_off() 868 807 return [r1, r2] 869 808 870 809 def nf_get_zk(self): … … 883 822 sage: pari(K).nf_get_zk() 884 823 [1, y, y^3 - 4*y, y^2 - 2] 885 824 """ 886 cdef GEN nf = self.get_nf() 887 pari_catch_sig_on() 888 return self.new_gen(nf_get_zk(nf)) 825 pari_catch_sig_on() 826 return P.new_gen(member_zk(self.g)) 889 827 890 828 def bnf_get_no(self): 891 829 """ … … 1628 1566 sage: int(pari("Mod(2, 7)")) 1629 1567 2 1630 1568 """ 1569 late_import() 1631 1570 return int(Integer(self)) 1632 1571 1633 1572 def int_unsafe(gen self): … … 1822 1761 sage: long(pari("Mod(2, 7)")) 1823 1762 2L 1824 1763 """ 1764 late_import() 1825 1765 return long(Integer(self)) 1826 1766 1827 1767 def __float__(gen self): … … 1913 1853 sage: a.gequal(c) 1914 1854 False 1915 1855 """ 1916 t0GEN(b)1917 pari_catch_sig_on() 1918 cdef int ret = gequal(a.g, t0 )1856 cdef gen t0 = P(b) 1857 pari_catch_sig_on() 1858 cdef int ret = gequal(a.g, t0.g) 1919 1859 pari_catch_sig_off() 1920 1860 return ret != 0 1921 1861 … … 2134 2074 """ 2135 2075 cdef int n 2136 2076 cdef GEN x 2077 cdef gen t0 2137 2078 2138 2079 if k is None: 2139 2080 pari_catch_sig_on() … … 2144 2085 else: 2145 2086 return n, P.new_gen(x) 2146 2087 else: 2147 k = int(k) 2148 t0GEN(k) 2088 t0 = P(k) 2149 2089 pari_catch_sig_on() 2150 n = ispower(self.g, t0 , &x)2090 n = ispower(self.g, t0.g, &x) 2151 2091 if n == 0: 2152 2092 pari_catch_sig_off() 2153 2093 return False, None … … 2163 2103 2-dimensional column vector the quotient and the remainder, with 2164 2104 respect to v (to main variable if v is omitted). 2165 2105 """ 2166 t0GEN(y)2106 cdef gen t0 = P(y) 2167 2107 pari_catch_sig_on() 2168 return P.new_gen(divrem(x.g, t0 , P.get_var(var)))2108 return P.new_gen(divrem(x.g, t0.g, P.get_var(var))) 2169 2109 2170 2110 def lex(gen x, y): 2171 2111 """ 2172 2112 lex(x,y): Compare x and y lexicographically (1 if xy, 0 if x==y, -1 2173 2113 if xy) 2174 2114 """ 2175 t0GEN(y)2115 cdef gen t0 = P(y) 2176 2116 pari_catch_sig_on() 2177 return lexcmp(x.g, t0) 2117 r = lexcmp(x.g, t0.g) 2118 pari_catch_sig_off() 2119 return r 2178 2120 2179 2121 def max(gen x, y): 2180 2122 """ 2181 2123 max(x,y): Return the maximum of x and y. 2182 2124 """ 2183 t0GEN(y)2184 pari_catch_sig_on() 2185 return P.new_gen(gmax(x.g, t0 ))2125 cdef gen t0 = P(y) 2126 pari_catch_sig_on() 2127 return P.new_gen(gmax(x.g, t0.g)) 2186 2128 2187 2129 def min(gen x, y): 2188 2130 """ 2189 2131 min(x,y): Return the minimum of x and y. 2190 2132 """ 2191 t0GEN(y)2192 pari_catch_sig_on() 2193 return P.new_gen(gmin(x.g, t0 ))2133 cdef gen t0 = P(y) 2134 pari_catch_sig_on() 2135 return P.new_gen(gmin(x.g, t0.g)) 2194 2136 2195 2137 def shift(gen x, long n): 2196 2138 """ … … 2221 2163 # Pari throws an error if you attempt to take the sign of 2222 2164 # a complex number. 2223 2165 pari_catch_sig_on() 2224 return gsigne(x.g) 2166 r = gsigne(x.g) 2167 pari_catch_sig_off() 2168 return r 2225 2169 2226 2170 def vecmax(gen x): 2227 2171 """ … … 2486 2430 sage: a.type() 2487 2431 't_POLMOD' 2488 2432 """ 2489 t0GEN(y)2490 pari_catch_sig_on() 2491 return P.new_gen(gmodulo(x.g, t0))2433 cdef gen t0 = P(y) 2434 pari_catch_sig_on() 2435 return P.new_gen(gmodulo(x.g, t0.g)) 2492 2436 2493 2437 def Pol(self, v=-1): 2494 2438 """ … … 2634 2578 ... 2635 2579 PariError: square discriminant in Qfb 2636 2580 """ 2637 t0GEN(b); t1GEN(c); t2GEN(D) 2638 pari_catch_sig_on() 2639 return P.new_gen(Qfb0(a.g, t0, t1, t2, prec)) 2581 cdef gen t0 = P(b) 2582 cdef gen t1 = P(c) 2583 cdef gen t2 = P(D) 2584 pari_catch_sig_on() 2585 return P.new_gen(Qfb0(a.g, t0.g, t1.g, t2.g, prec)) 2640 2586 2641 2587 2642 2588 def Ser(gen x, v=-1, long seriesprecision = 16): … … 2768 2714 cdef char* c 2769 2715 pari_catch_sig_on() 2770 2716 c = GENtostr(self.g) 2771 v = self.new_gen(strtoGENstr(c))2717 v = P.new_gen(strtoGENstr(c)) 2772 2718 pari_free(c) 2773 2719 return v 2774 2720 … … 3083 3029 sage: pari(-1).bitand(-1) 3084 3030 -1 3085 3031 """ 3086 t0GEN(y)3087 pari_catch_sig_on() 3088 return P.new_gen(gbitand(x.g, t0 ))3032 cdef gen t0 = P(y) 3033 pari_catch_sig_on() 3034 return P.new_gen(gbitand(x.g, t0.g)) 3089 3035 3090 3036 3091 3037 def bitneg(gen x, long n=-1): … … 3163 3109 sage: pari(8+4).bitnegimply(8) 3164 3110 4 3165 3111 """ 3166 t0GEN(y)3167 pari_catch_sig_on() 3168 return P.new_gen(gbitnegimply(x.g, t0 ))3112 cdef gen t0 = P(y) 3113 pari_catch_sig_on() 3114 return P.new_gen(gbitnegimply(x.g, t0.g)) 3169 3115 3170 3116 3171 3117 def bitor(gen x, y): … … 3198 3144 sage: pari(13).bitor(1) 3199 3145 13 3200 3146 """ 3201 t0GEN(y)3202 pari_catch_sig_on() 3203 return P.new_gen(gbitor(x.g, t0 ))3147 cdef gen t0 = P(y) 3148 pari_catch_sig_on() 3149 return P.new_gen(gbitor(x.g, t0.g)) 3204 3150 3205 3151 3206 3152 def bittest(gen x, long n): … … 3272 3218 sage: pari(6).bitxor(0) 3273 3219 6 3274 3220 """ 3275 t0GEN(y)3276 pari_catch_sig_on() 3277 return P.new_gen(gbitxor(x.g, t0 ))3221 cdef gen t0 = P(y) 3222 pari_catch_sig_on() 3223 return P.new_gen(gbitxor(x.g, t0.g)) 3278 3224 3279 3225 3280 3226 def ceil(gen x): … … 4164 4110 2147483647 # 32-bit 4165 4111 9223372036854775807 # 64-bit 4166 4112 """ 4167 cdef long v 4168 t0GEN(p) 4169 pari_catch_sig_on() 4170 v = ggval(x.g, t0) 4113 cdef gen t0 = P(p) 4114 pari_catch_sig_on() 4115 v = ggval(x.g, t0.g) 4171 4116 pari_catch_sig_off() 4172 4117 return v 4173 4118 … … 4333 4278 sage: pari(1+i).agm(-3) 4334 4279 -0.964731722290876 + 1.15700282952632*I 4335 4280 """ 4336 t0GEN(y)4337 pari_catch_sig_on() 4338 return P.new_gen(agm(x.g, t0 , pbw(precision)))4281 cdef gen t0 = P(y) 4282 pari_catch_sig_on() 4283 return P.new_gen(agm(x.g, t0.g, prec_bits_to_words(precision))) 4339 4284 4340 4285 def arg(gen x, precision=0): 4341 4286 r""" … … 4510 4455 sage: pari(2).besselh1(3) 4511 4456 0.486091260585891 - 0.160400393484924*I 4512 4457 """ 4513 t0GEN(x)4514 pari_catch_sig_on() 4515 return P.new_gen(hbessel1(nu.g, t0 , pbw(precision)))4458 cdef gen t0 = P(x) 4459 pari_catch_sig_on() 4460 return P.new_gen(hbessel1(nu.g, t0.g, prec_bits_to_words(precision))) 4516 4461 4517 4462 def besselh2(gen nu, x, precision=0): 4518 4463 r""" … … 4530 4475 sage: pari(2).besselh2(3) 4531 4476 0.486091260585891 + 0.160400393484924*I 4532 4477 """ 4533 t0GEN(x)4534 pari_catch_sig_on() 4535 return P.new_gen(hbessel2(nu.g, t0 , pbw(precision)))4478 cdef gen t0 = P(x) 4479 pari_catch_sig_on() 4480 return P.new_gen(hbessel2(nu.g, t0.g, prec_bits_to_words(precision))) 4536 4481 4537 4482 def besselj(gen nu, x, precision=0): 4538 4483 r""" … … 4553 4498 sage: pari(2).besselj(3) 4554 4499 0.486091260585891 4555 4500 """ 4556 t0GEN(x)4557 pari_catch_sig_on() 4558 return P.new_gen(jbessel(nu.g, t0 , pbw(precision)))4501 cdef gen t0 = P(x) 4502 pari_catch_sig_on() 4503 return P.new_gen(jbessel(nu.g, t0.g, prec_bits_to_words(precision))) 4559 4504 4560 4505 def besseljh(gen nu, x, precision=0): 4561 4506 """ … … 4578 4523 0.4127100324 # 32-bit 4579 4524 0.412710032209716 # 64-bit 4580 4525 """ 4581 t0GEN(x)4582 pari_catch_sig_on() 4583 return P.new_gen(jbesselh(nu.g, t0 , pbw(precision)))4526 cdef gen t0 = P(x) 4527 pari_catch_sig_on() 4528 return P.new_gen(jbesselh(nu.g, t0.g, prec_bits_to_words(precision))) 4584 4529 4585 4530 def besseli(gen nu, x, precision=0): 4586 4531 r""" … … 4604 4549 sage: pari(2).besseli(3+i) 4605 4550 1.12539407613913 + 2.08313822670661*I 4606 4551 """ 4607 t0GEN(x)4608 pari_catch_sig_on() 4609 return P.new_gen(ibessel(nu.g, t0 , pbw(precision)))4552 cdef gen t0 = P(x) 4553 pari_catch_sig_on() 4554 return P.new_gen(ibessel(nu.g, t0.g, prec_bits_to_words(precision))) 4610 4555 4611 4556 def besselk(gen nu, x, long flag=0, precision=0): 4612 4557 """ … … 4647 4592 sage: pari(2+i).besselk(300, flag=1) 4648 4593 3.74224603319728 E-132 + 2.49071062641525 E-134*I 4649 4594 """ 4650 t0GEN(x)4651 pari_catch_sig_on() 4652 return P.new_gen(kbessel(nu.g, t0 , pbw(precision)))4595 cdef gen t0 = P(x) 4596 pari_catch_sig_on() 4597 return P.new_gen(kbessel(nu.g, t0.g, prec_bits_to_words(precision))) 4653 4598 4654 4599 def besseln(gen nu, x, precision=0): 4655 4600 """ … … 4668 4613 sage: pari(2+i).besseln(3) 4669 4614 -0.280775566958244 - 0.486708533223726*I 4670 4615 """ 4671 t0GEN(x)4672 pari_catch_sig_on() 4673 return P.new_gen(nbessel(nu.g, t0 , pbw(precision)))4616 cdef gen t0 = P(x) 4617 pari_catch_sig_on() 4618 return P.new_gen(nbessel(nu.g, t0.g, prec_bits_to_words(precision))) 4674 4619 4675 4620 def cos(gen x, precision=0): 4676 4621 """ … … 4935 4880 sage: pari(1).hyperu(2,3) 4936 4881 0.333333333333333 4937 4882 """ 4938 t0GEN(b)4939 t1GEN(x)4940 pari_catch_sig_on() 4941 return P.new_gen(hyperu(a.g, t0 , t1, pbw(precision)))4883 cdef gen t0 = P(b) 4884 cdef gen t1 = P(x) 4885 pari_catch_sig_on() 4886 return P.new_gen(hyperu(a.g, t0.g, t1.g, prec_bits_to_words(precision))) 4942 4887 4943 4888 def incgam(gen s, x, y=None, precision=0): 4944 4889 r""" … … 4956 4901 sage: pari(1+i).incgam(3-i) 4957 4902 -0.0458297859919946 + 0.0433696818726677*I 4958 4903 """ 4959 t0GEN(x)4960 pari_catch_sig_on()4904 cdef gen t0 = P(x) 4905 cdef gen t1 4961 4906 if y is None: 4962 return P.new_gen(incgam(s.g, t0, pbw(precision))) 4907 pari_catch_sig_on() 4908 return P.new_gen(incgam(s.g, t0.g, prec_bits_to_words(precision))) 4963 4909 else: 4964 t1GEN(y) 4965 return P.new_gen(incgam0(s.g, t0, t1, pbw(precision))) 4910 t1 = P(y) 4911 pari_catch_sig_on() 4912 return P.new_gen(incgam0(s.g, t0.g, t1.g, prec_bits_to_words(precision))) 4966 4913 4967 4914 def incgamc(gen s, x, precision=0): 4968 4915 r""" … … 4986 4933 sage: pari(1).incgamc(2) 4987 4934 0.864664716763387 4988 4935 """ 4989 t0GEN(x)4990 pari_catch_sig_on() 4991 return P.new_gen(incgamc(s.g, t0 , pbw(precision)))4936 cdef gen t0 = P(x) 4937 pari_catch_sig_on() 4938 return P.new_gen(incgamc(s.g, t0.g, prec_bits_to_words(precision))) 4992 4939 4993 4940 def log(gen x, precision=0): 4994 4941 r""" … … 5263 5210 """ 5264 5211 # TODO: ??? lots of good examples in the PARI docs ??? 5265 5212 cdef GEN zetan 5266 t0GEN(n)5267 pari_catch_sig_on() 5268 ans = P.new_gen_noclear(gsqrtn(x.g, t0 , &zetan, pbw(precision)))5213 cdef gen t0 = P(n) 5214 pari_catch_sig_on() 5215 ans = P.new_gen_noclear(gsqrtn(x.g, t0.g, &zetan, prec_bits_to_words(precision))) 5269 5216 return ans, P.new_gen(zetan) 5270 5217 5271 5218 def tan(gen x, precision=0): … … 5343 5290 sage: pari(0.5).theta(2) 5344 5291 1.63202590295260 5345 5292 """ 5346 t0GEN(z)5347 pari_catch_sig_on() 5348 return P.new_gen(theta(q.g, t0 , pbw(precision)))5293 cdef gen t0 = P(z) 5294 pari_catch_sig_on() 5295 return P.new_gen(theta(q.g, t0.g, prec_bits_to_words(precision))) 5349 5296 5350 5297 def thetanullk(gen q, long k, precision=0): 5351 5298 """ … … 5443 5390 4*7^-2 + 5*7^-1 + O(7^0) 5444 5391 """ 5445 5392 pari_catch_sig_on() 5446 return P.new_gen(gzeta(s.g, p bw(precision)))5393 return P.new_gen(gzeta(s.g, prec_bits_to_words(precision))) 5447 5394 5448 5395 ########################################### 5449 5396 # 4: NUMBER THEORETICAL functions … … 5452 5399 def bezout(gen x, y): 5453 5400 cdef gen u, v, g 5454 5401 cdef GEN U, V, G 5455 t0GEN(y)5456 pari_catch_sig_on() 5457 G = gbezout(x.g, t0 , &U, &V)5402 cdef gen t0 = P(y) 5403 pari_catch_sig_on() 5404 G = gbezout(x.g, t0.g, &U, &V) 5458 5405 g = P.new_gen_noclear(G) 5459 5406 u = P.new_gen_noclear(U) 5460 5407 v = P.new_gen(V) … … 5492 5439 a bound for the number of terms in the continued fraction 5493 5440 expansion. 5494 5441 """ 5495 t0GEN(b)5496 pari_catch_sig_on() 5497 return P.new_gen(contfrac0(x.g, t0 , lmax))5442 cdef gen t0 = P(b) 5443 pari_catch_sig_on() 5444 return P.new_gen(contfrac0(x.g, t0.g, lmax)) 5498 5445 5499 5446 def contfracpnqn(gen x, b=0, long lmax=0): 5500 5447 """ … … 5578 5525 (x and y must be polynomials), 2 use the subresultant algorithm (x 5579 5526 and y must be polynomials) 5580 5527 """ 5581 t0GEN(y)5582 pari_catch_sig_on() 5583 return P.new_gen(ggcd0(x.g, t0 ))5528 cdef gen t0 = P(y) 5529 pari_catch_sig_on() 5530 return P.new_gen(ggcd0(x.g, t0.g)) 5584 5531 5585 5532 def issquare(gen x, find_root=False): 5586 5533 """ … … 5624 5571 sage: pari(10).lcm(15) 5625 5572 30 5626 5573 """ 5627 t0GEN(y)5628 pari_catch_sig_on() 5629 return P.new_gen(glcm(x.g, t0 ))5574 cdef gen t0 = P(y) 5575 pari_catch_sig_on() 5576 return P.new_gen(glcm(x.g, t0.g)) 5630 5577 5631 5578 def numdiv(gen n): 5632 5579 """ … … 5859 5806 sage: e.elladd([1,0], [-1,1]) 5860 5807 [-3/4, -15/8] 5861 5808 """ 5862 t0GEN(z0); t1GEN(z1) 5863 pari_catch_sig_on() 5864 return self.new_gen(addell(self.g, t0, t1)) 5809 cdef gen t0 = P(z0) 5810 cdef gen t1 = P(z1) 5811 pari_catch_sig_on() 5812 return P.new_gen(addell(self.g, t0.g, t1.g)) 5865 5813 5866 5814 def ellak(self, n): 5867 5815 r""" … … 5897 5845 sage: e.ellak(0) 5898 5846 0 5899 5847 """ 5900 t0GEN(n)5901 pari_catch_sig_on() 5902 return self.new_gen(akell(self.g, t0))5848 cdef gen t0 = P(n) 5849 pari_catch_sig_on() 5850 return P.new_gen(akell(self.g, t0.g)) 5903 5851 5904 5852 5905 5853 def ellan(self, long n, python_ints=False): … … 5992 5940 sage: e.ellak(-1) 5993 5941 0 5994 5942 """ 5995 t0GEN(p)5996 pari_catch_sig_on() 5997 return self.new_gen(ellap(self.g, t0))5943 cdef gen t0 = P(p) 5944 pari_catch_sig_on() 5945 return P.new_gen(ellap(self.g, t0.g)) 5998 5946 5999 5947 6000 5948 def ellaplist(self, long n, python_ints=False): … … 6046 5994 sage: type(v[0]) 6047 5995 <type 'int'> 6048 5996 """ 6049 # 1. make a table of primes up to n. 6050 pari_catch_sig_on() 5997 cdef gen t0 5998 cdef GEN g 5999 cdef long i 6000 6051 6001 if n < 2: 6052 return self.new_gen(zerovec(0)) 6053 cdef GEN g 6054 pari.init_primes(n+1) 6055 t0GEN(n) 6056 g = primes(gtolong(primepi(t0))) 6002 pari_catch_sig_on() 6003 return P.new_gen(zerovec(0)) 6004 6005 # 1. Make a table of primes up to n. 6006 P.init_primes(n+1) 6007 t0 = P(n) 6008 pari_catch_sig_on() 6009 g = primes(gtolong(primepi(t0.g))) 6057 6010 6058 6011 # 2. Replace each prime in the table by ellap of it. 6059 cdef long i6060 6061 6012 if python_ints: 6062 v = [gtolong(ellap(self.g, <GEN> g[i+1])) \6013 v = [gtolong(ellap(self.g, gel(g, i + 1))) \ 6063 6014 for i in range(glength(g))] 6064 (<PariInstance>pari).clear_stack()6015 P.clear_stack() 6065 6016 return v 6066 6017 else: 6067 6018 for i from 0 <= i < glength(g): 6068 g[i+1] = <long> ellap(self.g, <GEN> g[i+1])6019 set_gel(g, i + 1, ellap(self.g, gel(g, i + 1))) 6069 6020 return self.new_gen(g) 6070 6021 6071 6022 … … 6089 6040 sage: e.ellbil([1, 0], [-1, 1]) 6090 6041 0.418188984498861 6091 6042 """ 6092 t0GEN(z0); t1GEN(z1)6093 pari_catch_sig_on()6094 # the prec argument has no effect6095 return self.new_gen(bilhell(self.g, t0, t1, prec))6043 cdef gen t0 = P(z0) 6044 cdef gen t1 = P(z1) 6045 pari_catch_sig_on() 6046 return P.new_gen(bilhell(self.g, t0.g, t1.g, prec)) 6096 6047 6097 6048 def ellchangecurve(self, ch): 6098 6049 """ … … 6121 6072 sage: f[:5] 6122 6073 [1, -1, 0, 4, 3] 6123 6074 """ 6124 t0GEN(ch)6125 pari_catch_sig_on() 6126 return self.new_gen(ellchangecurve(self.g, t0))6075 cdef gen t0 = P(ch) 6076 pari_catch_sig_on() 6077 return P.new_gen(ellchangecurve(self.g, t0.g)) 6127 6078 6128 6079 def elleta(self): 6129 6080 """ … … 6190 6141 sage: e.ellheight([1,0], flag=1) 6191 6142 0.476711659343740 6192 6143 """ 6193 t0GEN(a)6194 pari_catch_sig_on() 6195 return self.new_gen(ellheight0(self.g, t0, flag, pbw(precision)))6144 cdef gen t0 = P(a) 6145 pari_catch_sig_on() 6146 return P.new_gen(ellheight0(self.g, t0.g, flag, prec_bits_to_words(precision))) 6196 6147 6197 6148 def ellheightmatrix(self, x): 6198 6149 """ … … 6218 6169 sage: e.ellheightmatrix([[1,0], [-1,1]]) 6219 6170 [0.476711659343740, 0.418188984498861; 0.418188984498861, 0.686667083305587] 6220 6171 """ 6221 t0GEN(x) 6222 pari_catch_sig_on() 6223 # the argument prec has no effect 6224 return self.new_gen(mathell(self.g, t0, prec)) 6172 cdef gen t0 = P(x) 6173 pari_catch_sig_on() 6174 return P.new_gen(mathell(self.g, t0.g, prec)) 6225 6175 6226 6176 def ellisoncurve(self, x): 6227 6177 """ … … 6245 6195 sage: e.ellisoncurve([0]) 6246 6196 True 6247 6197 """ 6248 t0GEN(x)6249 pari_catch_sig_on() 6250 t = bool(oncurve(self.g, t0 ) == 1)6198 cdef gen t0 = P(x) 6199 pari_catch_sig_on() 6200 t = bool(oncurve(self.g, t0.g) == 1) 6251 6201 pari_catch_sig_off() 6252 6202 return t 6253 6203 … … 6402 6352 sage: e.elllocalred(3) 6403 6353 [2, -10, [1, 96, 1, 316], 4] 6404 6354 """ 6405 t0GEN(p)6406 pari_catch_sig_on() 6407 return self.new_gen(elllocalred(self.g, t0))6355 cdef gen t0 = P(p) 6356 pari_catch_sig_on() 6357 return P.new_gen(elllocalred(self.g, t0.g)) 6408 6358 6409 6359 def elllseries(self, s, A=1): 6410 6360 """ … … 6444 6394 sage: e.elllseries(2.1, A=1.1) 6445 6395 0.402838047956645 6446 6396 """ 6447 t0GEN(s); t1GEN(A)6448 pari_catch_sig_on()6449 # the argument prec has no effect6450 return self.new_gen(elllseries(self.g, t0, t1, prec))6397 cdef gen t0 = P(s) 6398 cdef gen t1 = P(A) 6399 pari_catch_sig_on() 6400 return P.new_gen(elllseries(self.g, t0.g, t1.g, prec)) 6451 6401 6452 6402 def ellminimalmodel(self): 6453 6403 """ … … 6514 6464 sage: e.ellorder([1,0]) 6515 6465 0 6516 6466 """ 6517 t0GEN(x)6518 pari_catch_sig_on() 6519 return self.new_gen(orderell(self.g, t0))6467 cdef gen t0 = P(x) 6468 pari_catch_sig_on() 6469 return P.new_gen(orderell(self.g, t0.g)) 6520 6470 6521 6471 def ellordinate(self, x): 6522 6472 """ … … 6545 6495 sage: e.ellordinate('z+2*z^2+O(z^4)') 6546 6496 [-2*z - 7*z^2 - 23*z^3 + O(z^4), -1 + 2*z + 7*z^2 + 23*z^3 + O(z^4)] 6547 6497 """ 6548 t0GEN(x) 6549 pari_catch_sig_on() 6550 # the prec argument has no effect 6551 return self.new_gen(ellordinate(self.g, t0, prec)) 6552 6553 def ellpointtoz(self, P, long precision=0): 6554 """ 6555 e.ellpointtoz(P): return the complex number (in the fundamental 6556 parallelogram) corresponding to the point P on the elliptic curve 6498 cdef gen t0 = P(x) 6499 pari_catch_sig_on() 6500 return P.new_gen(ellordinate(self.g, t0.g, prec)) 6501 6502 def ellpointtoz(self, pt, long precision=0): 6503 """ 6504 e.ellpointtoz(pt): return the complex number (in the fundamental 6505 parallelogram) corresponding to the point ``pt`` on the elliptic curve 6557 6506 e, under the complex uniformization of e given by the Weierstrass 6558 6507 p-function. 6559 6508 … … 6572 6521 sage: e.ellpointtoz([0]) 6573 6522 0 6574 6523 """ 6575 t0GEN(P)6576 pari_catch_sig_on() 6577 return self.new_gen(zell(self.g, t0, pbw(precision)))6524 cdef gen t0 = P(pt) 6525 pari_catch_sig_on() 6526 return P.new_gen(zell(self.g, t0.g, prec_bits_to_words(precision))) 6578 6527 6579 6528 def ellpow(self, z, n): 6580 6529 """ … … 6634 6583 ....: P0 = e.elladd(e.ellpow(P, cm_minpoly[0]), e.ellpow(P2, cm)) 6635 6584 ....: assert(P0 == E(0)) 6636 6585 """ 6637 t0GEN(z); t1GEN(n) 6638 pari_catch_sig_on() 6639 return self.new_gen(powell(self.g, t0, t1)) 6586 cdef gen t0 = P(z) 6587 cdef gen t1 = P(n) 6588 pari_catch_sig_on() 6589 return P.new_gen(powell(self.g, t0.g, t1.g)) 6640 6590 6641 6591 def ellrootno(self, p=1): 6642 6592 """ … … 6669 6619 sage: e.ellrootno(1009) 6670 6620 1 6671 6621 """ 6672 cdef long rootno 6673 t0GEN(p) 6674 pari_catch_sig_on() 6675 rootno = ellrootno(self.g, t0) 6622 cdef gen t0 = P(p) 6623 pari_catch_sig_on() 6624 rootno = ellrootno(self.g, t0.g) 6676 6625 pari_catch_sig_off() 6677 6626 return rootno 6678 6627 … … 6689 6638 sage: e.ellsigma(2+i) 6690 6639 1.43490215804166 + 1.80307856719256*I 6691 6640 """ 6692 t0GEN(z) 6693 pari_catch_sig_on() 6694 # the prec argument has no effect 6695 return self.new_gen(ellsigma(self.g, t0, flag, prec)) 6641 cdef gen t0 = P(z) 6642 pari_catch_sig_on() 6643 return P.new_gen(ellsigma(self.g, t0.g, flag, prec)) 6696 6644 6697 6645 def ellsub(self, z0, z1): 6698 6646 """ … … 6716 6664 sage: e.ellsub([1,0], [-1,1]) 6717 6665 [0, 0] 6718 6666 """ 6719 t0GEN(z0); t1GEN(z1) 6720 pari_catch_sig_on() 6721 return self.new_gen(subell(self.g, t0, t1)) 6667 cdef gen t0 = P(z0) 6668 cdef gen t1 = P(z1) 6669 pari_catch_sig_on() 6670 return P.new_gen(subell(self.g, t0.g, t1.g)) 6722 6671 6723 6672 def elltaniyama(self): 6724 6673 pari_catch_sig_on() 6725 return self.new_gen(taniyama(self.g))6674 return P.new_gen(taniyama(self.g)) 6726 6675 6727 6676 def elltors(self, flag=0): 6728 6677 """ … … 6799 6748 sage: e.ellzeta(i-1) 6800 6749 -0.350122658523049 - 0.350122658523049*I 6801 6750 """ 6802 t0GEN(z) 6803 pari_catch_sig_on() 6804 # the prec argument has no effect 6805 return self.new_gen(ellzeta(self.g, t0, prec)) 6751 cdef gen t0 = P(z) 6752 pari_catch_sig_on() 6753 return P.new_gen(ellzeta(self.g, t0.g, prec)) 6806 6754 6807 6755 def ellztopoint(self, z): 6808 6756 """ … … 6834 6782 sage: e.ellztopoint(0) 6835 6783 [0] 6836 6784 """ 6837 t0GEN(z)6785 cdef gen t0 = P(z) 6838 6786 try: 6839 6787 dprec = prec_words_to_dec(z.precision()) 6840 6788 except AttributeError: 6841 6789 dprec = prec 6842 6790 pari_catch_sig_on() 6843 # the prec argument has no effect 6844 return self.new_gen(pointell(self.g, t0, dprec)) 6791 return P.new_gen(pointell(self.g, t0.g, dprec)) 6845 6792 6846 6793 def omega(self): 6847 6794 """ … … 6912 6859 .. [PariUsers] User's Guide to PARI/GP, 6913 6860 http://pari.math.u-bordeaux.fr/pub/pari/manuals/2.5.1/users.pdf 6914 6861 """ 6915 cdef long n6916 6862 pari_catch_sig_on() 6917 6863 n = bnfcertify(self.g) 6918 6864 pari_catch_sig_off() 6919 6865 return n 6920 6866 6921 6867 def bnfinit(self, long flag=0, tech=None): 6868 cdef gen t0 6922 6869 if tech is None: 6923 6870 pari_catch_sig_on() 6924 return P.new_gen(bnfinit0(self.g, flag, <GEN>0, prec))6871 return P.new_gen(bnfinit0(self.g, flag, NULL, prec)) 6925 6872 else: 6926 t0 GEN(tech)6873 t0 = P(tech) 6927 6874 pari_catch_sig_on() 6928 return P.new_gen(bnfinit0(self.g, flag, t0 , prec))6875 return P.new_gen(bnfinit0(self.g, flag, t0.g, prec)) 6929 6876 6930 6877 def bnfisintnorm(self, x): 6931 t0GEN(x)6932 pari_catch_sig_on() 6933 return self.new_gen(bnfisintnorm(self.g, t0))6878 cdef gen t0 = P(x) 6879 pari_catch_sig_on() 6880 return P.new_gen(bnfisintnorm(self.g, t0.g)) 6934 6881 6935 6882 def bnfisnorm(self, x, long flag=0): 6936 t0GEN(x)6937 pari_catch_sig_on() 6938 return self.new_gen(bnfisnorm(self.g, t0, flag))6883 cdef gen t0 = P(x) 6884 pari_catch_sig_on() 6885 return P.new_gen(bnfisnorm(self.g, t0.g, flag)) 6939 6886 6940 6887 def bnfisprincipal(self, x, long flag=1): 6941 t0GEN(x)6942 pari_catch_sig_on() 6943 return self.new_gen(bnfisprincipal0(self.g, t0, flag))6888 cdef gen t0 = P(x) 6889 pari_catch_sig_on() 6890 return P.new_gen(bnfisprincipal0(self.g, t0.g, flag)) 6944 6891 6945 6892 def bnfnarrow(self): 6946 6893 pari_catch_sig_on() 6947 return self.new_gen(buchnarrow(self.g))6948 6949 def bnfsunit( bnf, S, long precision=0):6950 t0GEN(S)6951 pari_catch_sig_on() 6952 return bnf.new_gen(bnfsunit(bnf.g, t0, pbw(precision)))6894 return P.new_gen(buchnarrow(self.g)) 6895 6896 def bnfsunit(self, S, long precision=0): 6897 cdef gen t0 = P(S) 6898 pari_catch_sig_on() 6899 return P.new_gen(bnfsunit(self.g, t0.g, prec_bits_to_words(precision))) 6953 6900 6954 6901 def bnfunit(self): 6955 6902 pari_catch_sig_on() 6956 return self.new_gen(bnf_get_fu(self.g))6903 return P.new_gen(bnf_get_fu(self.g)) 6957 6904 6958 6905 def bnfisunit(self, x): 6959 t0GEN(x)6960 pari_catch_sig_on() 6961 return self.new_gen(bnfisunit(self.g, t0))6906 cdef gen t0 = P(x) 6907 pari_catch_sig_on() 6908 return P.new_gen(bnfisunit(self.g, t0.g)) 6962 6909 6963 6910 def bnrclassno(self, I): 6964 6911 r""" … … 6978 6925 sage: K.pari_bnf().bnrclassno(p._pari_bid_()) 6979 6926 3 6980 6927 """ 6981 t0GEN(I)6982 pari_catch_sig_on() 6983 return self.new_gen(bnrclassno(self.g, t0))6928 cdef gen t0 = P(I) 6929 pari_catch_sig_on() 6930 return P.new_gen(bnrclassno(self.g, t0.g)) 6984 6931 6985 6932 def bnfissunit(self, sunit_data, x): 6986 t0GEN(x)6987 t1GEN(sunit_data)6988 pari_catch_sig_on() 6989 return self.new_gen(bnfissunit(self.g, t1, t0))6933 cdef gen t0 = P(x) 6934 cdef gen t1 = P(sunit_data) 6935 pari_catch_sig_on() 6936 return P.new_gen(bnfissunit(self.g, t1.g, t0.g)) 6990 6937 6991 6938 def dirzetak(self, n): 6992 t0GEN(n)6993 pari_catch_sig_on() 6994 return self.new_gen(dirzetak(self.g, t0))6939 cdef gen t0 = P(n) 6940 pari_catch_sig_on() 6941 return P.new_gen(dirzetak(self.g, t0.g)) 6995 6942 6996 6943 def galoisapply(self, aut, x): 6997 t0GEN(aut)6998 t1GEN(x)6999 pari_catch_sig_on() 7000 return self.new_gen(galoisapply(self.g, t0, t1))6944 cdef gen t0 = P(aut) 6945 cdef gen t1 = P(x) 6946 pari_catch_sig_on() 6947 return P.new_gen(galoisapply(self.g, t0.g, t1.g)) 7001 6948 7002 6949 def galoisinit(self, den=None): 7003 6950 """ 7004 6951 galoisinit(K{,den}): calculate Galois group of number field K; see PARI manual 7005 6952 for meaning of den 7006 6953 """ 6954 cdef gen t0 7007 6955 if den is None: 7008 6956 pari_catch_sig_on() 7009 return self.new_gen(galoisinit(self.g, NULL))6957 return P.new_gen(galoisinit(self.g, NULL)) 7010 6958 else: 7011 t0 GEN(den)6959 t0 = P(den) 7012 6960 pari_catch_sig_on() 7013 return self.new_gen(galoisinit(self.g, t0))6961 return P.new_gen(galoisinit(self.g, t0.g)) 7014 6962 7015 6963 def galoispermtopol(self, perm): 7016 t0GEN(perm)7017 pari_catch_sig_on() 7018 return self.new_gen(galoispermtopol(self.g, t0))6964 cdef gen t0 = P(perm) 6965 pari_catch_sig_on() 6966 return P.new_gen(galoispermtopol(self.g, t0.g)) 7019 6967 7020 6968 def galoisfixedfield(self, perm, long flag=0, v=-1): 7021 t0GEN(perm);7022 pari_catch_sig_on() 7023 return self.new_gen(galoisfixedfield(self.g, t0, flag, P.get_var(v)))6969 cdef gen t0 = P(perm) 6970 pari_catch_sig_on() 6971 return P.new_gen(galoisfixedfield(self.g, t0.g, flag, P.get_var(v))) 7024 6972 7025 6973 def idealred(self, I, vdir=0): 7026 t0GEN(I); t1GEN(vdir) 7027 pari_catch_sig_on() 7028 return self.new_gen(idealred0(self.g, t0, t1 if vdir else NULL)) 6974 cdef gen t0 = P(I) 6975 cdef gen t1 = P(vdir) 6976 pari_catch_sig_on() 6977 return P.new_gen(idealred0(self.g, t0.g, t1.g if vdir else NULL)) 7029 6978 7030 6979 def idealadd(self, x, y): 7031 t0GEN(x); t1GEN(y) 7032 pari_catch_sig_on() 7033 return self.new_gen(idealadd(self.g, t0, t1)) 6980 cdef gen t0 = P(x) 6981 cdef gen t1 = P(y) 6982 pari_catch_sig_on() 6983 return P.new_gen(idealadd(self.g, t0.g, t1.g)) 7034 6984 7035 6985 def idealaddtoone(self, x, y): 7036 t0GEN(x); t1GEN(y) 7037 pari_catch_sig_on() 7038 return self.new_gen(idealaddtoone0(self.g, t0, t1)) 6986 cdef gen t0 = P(x) 6987 cdef gen t1 = P(y) 6988 pari_catch_sig_on() 6989 return P.new_gen(idealaddtoone0(self.g, t0.g, t1.g)) 7039 6990 7040 6991 def idealappr(self, x, long flag=0): 7041 t0GEN(x)7042 pari_catch_sig_on() 7043 return self.new_gen(idealappr0(self.g, t0, flag))6992 cdef gen t0 = P(x) 6993 pari_catch_sig_on() 6994 return P.new_gen(idealappr0(self.g, t0.g, flag)) 7044 6995 7045 6996 def idealcoprime(self, x, y): 7046 6997 """ … … 7062 7013 sage: nf.idealcoprime(x, y) 7063 7014 [5/43, 9/43, -1/43]~ 7064 7015 """ 7065 t0GEN(x); t1GEN(y) 7066 pari_catch_sig_on() 7067 return self.new_gen(idealcoprime(self.g, t0, t1)) 7016 cdef gen t0 = P(x) 7017 cdef gen t1 = P(y) 7018 pari_catch_sig_on() 7019 return P.new_gen(idealcoprime(self.g, t0.g, t1.g)) 7068 7020 7069 7021 def idealdiv(self, x, y, long flag=0): 7070 t0GEN(x); t1GEN(y) 7071 pari_catch_sig_on() 7072 return self.new_gen(idealdiv0(self.g, t0, t1, flag)) 7022 cdef gen t0 = P(x) 7023 cdef gen t1 = P(y) 7024 pari_catch_sig_on() 7025 return P.new_gen(idealdiv0(self.g, t0.g, t1.g, flag)) 7073 7026 7074 7027 def idealfactor(self, x): 7075 t0GEN(x)7076 pari_catch_sig_on() 7077 return self.new_gen(idealfactor(self.g, t0))7028 cdef gen t0 = P(x) 7029 pari_catch_sig_on() 7030 return P.new_gen(idealfactor(self.g, t0.g)) 7078 7031 7079 7032 def idealhnf(self, a, b=None): 7080 t0GEN(a) 7033 cdef gen t0 = P(a) 7034 cdef gen t1 7081 7035 if b is None: 7082 7036 pari_catch_sig_on() 7083 return self.new_gen(idealhnf(self.g, t0))7037 return P.new_gen(idealhnf(self.g, t0.g)) 7084 7038 else: 7085 t1 GEN(b)7039 t1 = P(b) 7086 7040 pari_catch_sig_on() 7087 return self.new_gen(idealhnf0(self.g, t0, t1))7041 return P.new_gen(idealhnf0(self.g, t0.g, t1.g)) 7088 7042 7089 7043 def idealintersection(self, x, y): 7090 t0GEN(x); t1GEN(y) 7091 pari_catch_sig_on() 7092 return self.new_gen(idealintersect(self.g, t0, t1)) 7044 cdef gen t0 = P(x) 7045 cdef gen t1 = P(y) 7046 pari_catch_sig_on() 7047 return P.new_gen(idealintersect(self.g, t0.g, t1.g)) 7093 7048 7094 7049 def ideallist(self, long bound, long flag = 4): 7095 7050 """ … … 7146 7101 sage: nf.ideallog(x, bid) 7147 7102 [25]~ 7148 7103 """ 7149 t0GEN(x); t1GEN(bid) 7150 pari_catch_sig_on() 7151 return self.new_gen(ideallog(self.g, t0, t1)) 7104 cdef gen t0 = P(x) 7105 cdef gen t1 = P(bid) 7106 pari_catch_sig_on() 7107 return P.new_gen(ideallog(self.g, t0.g, t1.g)) 7152 7108 7153 7109 def idealmul(self, x, y, long flag=0): 7154 t0GEN(x); t1GEN(y) 7110 cdef gen t0 = P(x) 7111 cdef gen t1 = P(y) 7155 7112 pari_catch_sig_on() 7156 7113 if flag == 0: 7157 return self.new_gen(idealmul(self.g, t0, t1))7114 return P.new_gen(idealmul(self.g, t0.g, t1.g)) 7158 7115 else: 7159 return self.new_gen(idealmulred(self.g, t0, t1))7116 return P.new_gen(idealmulred(self.g, t0.g, t1.g)) 7160 7117 7161 7118 def idealnorm(self, x): 7162 t0GEN(x)7163 pari_catch_sig_on() 7164 return self.new_gen(idealnorm(self.g, t0))7119 cdef gen t0 = P(x) 7120 pari_catch_sig_on() 7121 return P.new_gen(idealnorm(self.g, t0.g)) 7165 7122 7166 7123 def idealprimedec(nf, p): 7167 7124 """ … … 7179 7136 sage: F[0].pr_get_p() 7180 7137 5 7181 7138 """ 7182 t0GEN(p)7183 pari_catch_sig_on() 7184 return nf.new_gen(idealprimedec(nf.g, t0))7139 cdef gen t0 = P(p) 7140 pari_catch_sig_on() 7141 return P.new_gen(idealprimedec(nf.g, t0.g)) 7185 7142 7186 7143 def idealstar(self, I, long flag=1): 7187 7144 """ … … 7219 7176 sage: nf.idealstar(I) 7220 7177 [[[43, 9, 5; 0, 1, 0; 0, 0, 1], [0]], [42, [42]], Mat([[43, [9, 1, 0]~, 1, 1, [-5, -9, 1]~], 1]), [[[[42], [[3, 0, 0]~], [[3, 0, 0]~], [Vecsmall([])], 1]], [[], [], []]], Mat(1)] 7221 7178 """ 7222 t0GEN(I)7223 pari_catch_sig_on() 7224 return self.new_gen(idealstar0(self.g, t0, flag))7179 cdef gen t0 = P(I) 7180 pari_catch_sig_on() 7181 return P.new_gen(idealstar0(self.g, t0.g, flag)) 7225 7182 7226 7183 def idealtwoelt(self, x, a=None): 7227 t0GEN(x) 7184 cdef gen t0 = P(x) 7185 cdef gen t1 7228 7186 if a is None: 7229 7187 pari_catch_sig_on() 7230 return self.new_gen(idealtwoelt0(self.g, t0, NULL))7188 return P.new_gen(idealtwoelt0(self.g, t0.g, NULL)) 7231 7189 else: 7232 t1 GEN(a)7190 t1 = P(a) 7233 7191 pari_catch_sig_on() 7234 return self.new_gen(idealtwoelt0(self.g, t0, t1))7192 return P.new_gen(idealtwoelt0(self.g, t0.g, t1.g)) 7235 7193 7236 7194 def idealval(self, x, p): 7237 cdef long v7238 t0GEN(x); t1GEN(p)7239 pari_catch_sig_on() 7240 v = idealval(self.g, t0 , t1)7195 cdef gen t0 = P(x) 7196 cdef gen t1 = P(p) 7197 pari_catch_sig_on() 7198 v = idealval(self.g, t0.g, t1.g) 7241 7199 pari_catch_sig_off() 7242 7200 return v 7243 7201 7244 7202 def elementval(self, x, p): 7245 cdef long v7246 t0GEN(x); t1GEN(p)7247 pari_catch_sig_on() 7248 v = nfval(self.g, t0 , t1)7203 cdef gen t0 = P(x) 7204 cdef gen t1 = P(p) 7205 pari_catch_sig_on() 7206 v = nfval(self.g, t0.g, t1.g) 7249 7207 pari_catch_sig_off() 7250 7208 return v 7251 7209 … … 7298 7256 sage: pari('x^3 - 17').nfbasis(flag = 2) 7299 7257 [1, x, 1/3*x^2 - 1/3*x + 1/3] 7300 7258 """ 7301 global t0 7302 t0GEN(fa) 7303 if typ(t0) != t_MAT: 7304 t0 = <GEN>0 7305 pari_catch_sig_on() 7306 return self.new_gen(nfbasis0(self.g, flag, t0)) 7259 cdef gen t0 = P(fa) 7260 pari_catch_sig_on() 7261 return P.new_gen(nfbasis0(self.g, flag, t0.g if typ(t0.g) == t_MAT else NULL)) 7307 7262 7308 7263 def nfbasis_d(self, long flag=0, fa=0): 7309 7264 """ … … 7327 7282 sage: pari([-2,0,0,1]).Polrev().nfbasis_d() 7328 7283 ([1, x, x^2], -108) 7329 7284 """ 7330 global t07331 7285 cdef GEN disc 7332 t0GEN(fa) 7333 if typ(t0) != t_MAT: 7334 t0 = <GEN>0 7335 pari_catch_sig_on() 7336 B = self.new_gen_noclear(nfbasis(self.g, &disc, flag, t0)) 7337 D = self.new_gen(disc); 7286 cdef gen t0 = P(fa) 7287 pari_catch_sig_on() 7288 B = P.new_gen_noclear(nfbasis(self.g, &disc, flag, t0.g if typ(t0.g) == t_MAT else NULL)) 7289 D = P.new_gen(disc); 7338 7290 return B,D 7339 7291 7340 7292 def nfbasistoalg(nf, x): … … 7367 7319 sage: Kpari.getattr('zk') * pari("[3/2, -5, 0]~") 7368 7320 -5/3*y^2 + 5/3*y - 1/6 7369 7321 """ 7370 t0GEN(x)7371 pari_catch_sig_on() 7372 return nf.new_gen(basistoalg(nf.g, t0))7322 cdef gen t0 = P(x) 7323 pari_catch_sig_on() 7324 return P.new_gen(basistoalg(nf.g, t0.g)) 7373 7325 7374 7326 def nfbasistoalg_lift(nf, x): 7375 7327 r""" … … 7400 7352 sage: Kpari.getattr('zk') * pari("[3/2, -5, 0]~") 7401 7353 -5/3*y^2 + 5/3*y - 1/6 7402 7354 """ 7403 t0GEN(x)7404 pari_catch_sig_on() 7405 return nf.new_gen(gel(basistoalg(nf.g, t0), 2))7355 cdef gen t0 = P(x) 7356 pari_catch_sig_on() 7357 return P.new_gen(gel(basistoalg(nf.g, t0.g), 2)) 7406 7358 7407 7359 def nfdisc(self, long flag=0, p=0): 7408 7360 """ … … 7452 7404 sage: pari(k).nfeltdiveuc(pari(x), pari(y)) 7453 7405 [2, -2]~ 7454 7406 """ 7455 t0GEN(x); t1GEN(y) 7456 pari_catch_sig_on() 7457 return self.new_gen(nfdiveuc(self.g, t0, t1)) 7407 cdef gen t0 = P(x) 7408 cdef gen t1 = P(y) 7409 pari_catch_sig_on() 7410 return P.new_gen(nfdiveuc(self.g, t0.g, t1.g)) 7458 7411 7459 7412 def nfeltreduce(self, x, I): 7460 7413 """ … … 7472 7425 sage: 12 - k(kp.nfeltreduce(12, I.pari_hnf())) in I 7473 7426 True 7474 7427 """ 7475 t0GEN(x); t1GEN(I) 7476 pari_catch_sig_on() 7477 return self.new_gen(nfreduce(self.g, t0, t1)) 7428 cdef gen t0 = P(x) 7429 cdef gen t1 = P(I) 7430 pari_catch_sig_on() 7431 return P.new_gen(nfreduce(self.g, t0.g, t1.g)) 7478 7432 7479 7433 def nffactor(self, x): 7480 t0GEN(x)7481 pari_catch_sig_on() 7482 return self.new_gen(nffactor(self.g, t0))7434 cdef gen t0 = P(x) 7435 pari_catch_sig_on() 7436 return P.new_gen(nffactor(self.g, t0.g)) 7483 7437 7484 7438 def nfgenerator(self): 7485 7439 f = self[0] … … 7508 7462 sage: pari(K).nfhilbert(pari(t), pari(t+2), P.pari_prime()) 7509 7463 1 7510 7464 """ 7511 cdef long r7512 t0GEN(a)7513 t1GEN(b)7465 cdef gen t0 = P(a) 7466 cdef gen t1 = P(b) 7467 cdef gen t2 7514 7468 if p: 7515 t2 GEN(p)7469 t2 = P(p) 7516 7470 pari_catch_sig_on() 7517 r = nfhilbert0(self.g, t0 , t1, t2)7471 r = nfhilbert0(self.g, t0.g, t1.g, t2.g) 7518 7472 else: 7519 7473 pari_catch_sig_on() 7520 r = nfhilbert(self.g, t0 , t1)7521 P.clear_stack()7474 r = nfhilbert(self.g, t0.g, t1.g) 7475 pari_catch_sig_off() 7522 7476 return r 7523 7477 7524 7478 … … 7584 7538 7585 7539 - Aly Deines (2012-09-19) 7586 7540 """ 7587 t0GEN(x) 7588 pari_catch_sig_on() 7589 return self.new_gen(nfhnf(self.g,t0)) 7590 7591 7541 cdef gen t0 = P(x) 7542 pari_catch_sig_on() 7543 return P.new_gen(nfhnf(self.g, t0.g)) 7592 7544 7593 7545 7594 7546 def nfinit(self, long flag=0, long precision=0): … … 7715 7667 - ``d`` - C long integer 7716 7668 """ 7717 7669 pari_catch_sig_on() 7718 return self.new_gen(nfsubfields(self.g, d))7670 return P.new_gen(nfsubfields(self.g, d)) 7719 7671 7720 7672 def rnfcharpoly(self, T, a, v='x'): 7721 t0GEN(T); t1GEN(a); t2GEN(v) 7722 pari_catch_sig_on() 7723 return self.new_gen(rnfcharpoly(self.g, t0, t1, gvar(t2))) 7673 cdef gen t0 = P(T) 7674 cdef gen t1 = P(a) 7675 cdef gen t2 = P(v) 7676 pari_catch_sig_on() 7677 return P.new_gen(rnfcharpoly(self.g, t0.g, t1.g, gvar(t2.g))) 7724 7678 7725 7679 def rnfdisc(self, x): 7726 t0GEN(x)7727 pari_catch_sig_on() 7728 return self.new_gen(rnfdiscf(self.g, t0))7680 cdef gen t0 = P(x) 7681 pari_catch_sig_on() 7682 return P.new_gen(rnfdiscf(self.g, t0.g)) 7729 7683 7730 7684 def rnfeltabstorel(self, x): 7731 t0GEN(x)7732 pari_catch_sig_on() 7733 return self.new_gen(rnfelementabstorel(self.g, t0))7685 cdef gen t0 = P(x) 7686 pari_catch_sig_on() 7687 return P.new_gen(rnfelementabstorel(self.g, t0.g)) 7734 7688 7735 7689 def rnfeltreltoabs(self, x): 7736 t0GEN(x)7737 pari_catch_sig_on() 7738 return self.new_gen(rnfelementreltoabs(self.g, t0))7690 cdef gen t0 = P(x) 7691 pari_catch_sig_on() 7692 return P.new_gen(rnfelementreltoabs(self.g, t0.g)) 7739 7693 7740 7694 def rnfequation(self, poly, long flag=0): 7741 t0GEN(poly)7742 pari_catch_sig_on() 7743 return self.new_gen(rnfequation0(self.g, t0, flag))7695 cdef gen t0 = P(poly) 7696 pari_catch_sig_on() 7697 return P.new_gen(rnfequation0(self.g, t0.g, flag)) 7744 7698 7745 7699 def rnfidealabstorel(self, x): 7746 t0GEN(x)7747 pari_catch_sig_on() 7748 return self.new_gen(rnfidealabstorel(self.g, t0))7700 cdef gen t0 = P(x) 7701 pari_catch_sig_on() 7702 return P.new_gen(rnfidealabstorel(self.g, t0.g)) 7749 7703 7750 7704 def rnfidealdown(self, x): 7751 7705 r""" … … 7768 7722 sage: rnf.rnfidealdown(P) 7769 7723 [2, 0; 0, 2] 7770 7724 """ 7771 t0GEN(x)7772 pari_catch_sig_on() 7773 return self.new_gen(rnfidealdown(self.g, t0))7725 cdef gen t0 = P(x) 7726 pari_catch_sig_on() 7727 return P.new_gen(rnfidealdown(self.g, t0.g)) 7774 7728 7775 7729 def rnfidealhnf(self, x): 7776 t0GEN(x)7777 pari_catch_sig_on() 7778 return self.new_gen(rnfidealhermite(self.g, t0))7730 cdef gen t0 = P(x) 7731 pari_catch_sig_on() 7732 return P.new_gen(rnfidealhermite(self.g, t0.g)) 7779 7733 7780 7734 def rnfidealnormrel(self, x): 7781 t0GEN(x)7782 pari_catch_sig_on() 7783 return self.new_gen(rnfidealnormrel(self.g, t0))7735 cdef gen t0 = P(x) 7736 pari_catch_sig_on() 7737 return P.new_gen(rnfidealnormrel(self.g, t0.g)) 7784 7738 7785 7739 def rnfidealreltoabs(self, x): 7786 t0GEN(x)7787 pari_catch_sig_on() 7788 return self.new_gen(rnfidealreltoabs(self.g, t0))7740 cdef gen t0 = P(x) 7741 pari_catch_sig_on() 7742 return P.new_gen(rnfidealreltoabs(self.g, t0.g)) 7789 7743 7790 7744 def rnfidealtwoelt(self, x): 7791 t0GEN(x)7792 pari_catch_sig_on() 7793 return self.new_gen(rnfidealtwoelement(self.g, t0))7745 cdef gen t0 = P(x) 7746 pari_catch_sig_on() 7747 return P.new_gen(rnfidealtwoelement(self.g, t0.g)) 7794 7748 7795 7749 def rnfinit(self, poly): 7796 7750 """ … … 7804 7758 sage: g = x^5 - x^2 + y 7805 7759 sage: L = K.rnfinit(g) 7806 7760 """ 7807 t0GEN(poly)7808 pari_catch_sig_on() 7809 return P.new_gen(rnfinit(self.g, t0 ))7761 cdef gen t0 = P(poly) 7762 pari_catch_sig_on() 7763 return P.new_gen(rnfinit(self.g, t0.g)) 7810 7764 7811 7765 def rnfisfree(self, poly): 7812 t0GEN(poly)7813 pari_catch_sig_on() 7814 r = rnfisfree(self.g, t0 )7766 cdef gen t0 = P(poly) 7767 pari_catch_sig_on() 7768 r = rnfisfree(self.g, t0.g) 7815 7769 pari_catch_sig_off() 7816 7770 return r 7817 7771 … … 7861 7815 2/15 7862 7816 """ 7863 7817 pari_catch_sig_on() 7864 return self.new_gen(content(self.g))7818 return P.new_gen(content(self.g)) 7865 7819 7866 7820 def deriv(self, v=-1): 7867 7821 pari_catch_sig_on() 7868 return self.new_gen(deriv(self.g, self.get_var(v)))7822 return P.new_gen(deriv(self.g, P.get_var(v))) 7869 7823 7870 7824 def eval(self, x): 7871 t0GEN(x)7872 pari_catch_sig_on() 7873 return self.new_gen(poleval(self.g, t0))7825 cdef gen t0 = P(x) 7826 pari_catch_sig_on() 7827 return P.new_gen(poleval(self.g, t0.g)) 7874 7828 7875 7829 def __call__(self, x): 7876 7830 return self.eval(x) … … 7889 7843 sage: pari(x^2 - 2).factornf(K.pari_polynomial("a")) 7890 7844 [x + Mod(-4*a, 8*a^2 - 1), 1; x + Mod(4*a, 8*a^2 - 1), 1] 7891 7845 """ 7892 t0GEN(t)7893 pari_catch_sig_on() 7894 return self.new_gen(polfnf(self.g, t0))7846 cdef gen t0 = P(t) 7847 pari_catch_sig_on() 7848 return P.new_gen(polfnf(self.g, t0.g)) 7895 7849 7896 7850 def factorpadic(self, p, long r=20, long flag=0): 7897 7851 """ … … 7899 7853 polynomial x to precision r. flag is optional and may be set to 0 7900 7854 (use round 4) or 1 (use Buchmann-Lenstra) 7901 7855 """ 7902 t0GEN(p)7903 pari_catch_sig_on() 7904 return self.new_gen(factorpadic0(self.g, t0, r, flag))7856 cdef gen t0 = P(p) 7857 pari_catch_sig_on() 7858 return P.new_gen(factorpadic0(self.g, t0.g, r, flag)) 7905 7859 7906 7860 def factormod(self, p, long flag=0): 7907 7861 """ … … 7910 7864 simple factormod, same except that only the degrees of the 7911 7865 irreducible factors are given. 7912 7866 """ 7913 t0GEN(p)7914 pari_catch_sig_on() 7915 return self.new_gen(factormod0(self.g, t0, flag))7867 cdef gen t0 = P(p) 7868 pari_catch_sig_on() 7869 return P.new_gen(factormod0(self.g, t0.g, flag)) 7916 7870 7917 7871 def intformal(self, y=-1): 7918 7872 """ … … 7920 7874 variable of y, or to the main variable of x if y is omitted 7921 7875 """ 7922 7876 pari_catch_sig_on() 7923 return self.new_gen(integ(self.g, self.get_var(y)))7877 return P.new_gen(integ(self.g, P.get_var(y))) 7924 7878 7925 7879 def padicappr(self, a): 7926 7880 """ 7927 7881 x.padicappr(a): p-adic roots of the polynomial x congruent to a mod 7928 7882 p 7929 7883 """ 7930 t0GEN(a)7931 pari_catch_sig_on() 7932 return self.new_gen(padicappr(self.g, t0))7884 cdef gen t0 = P(a) 7885 pari_catch_sig_on() 7886 return P.new_gen(padicappr(self.g, t0.g)) 7933 7887 7934 7888 def newtonpoly(self, p): 7935 7889 """ … … 7942 7896 sage: x.newtonpoly(3) 7943 7897 [1, 1, -1/3, -1/3, -1/3, -1/3, -1/3, -1/3] 7944 7898 """ 7945 t0GEN(p)7946 pari_catch_sig_on() 7947 return self.new_gen(newtonpoly(self.g, t0))7899 cdef gen t0 = P(p) 7900 pari_catch_sig_on() 7901 return P.new_gen(newtonpoly(self.g, t0.g)) 7948 7902 7949 7903 def polcoeff(self, long n, var=-1): 7950 7904 """ … … 7963 7917 x 7964 7918 """ 7965 7919 pari_catch_sig_on() 7966 return self.new_gen(polcoeff0(self.g, n, self.get_var(var)))7920 return P.new_gen(polcoeff0(self.g, n, P.get_var(var))) 7967 7921 7968 7922 def polcompositum(self, pol2, long flag=0): 7969 t0GEN(pol2)7970 pari_catch_sig_on() 7971 return self.new_gen(polcompositum0(self.g, t0, flag))7923 cdef gen t0 = P(pol2) 7924 pari_catch_sig_on() 7925 return P.new_gen(polcompositum0(self.g, t0.g, flag)) 7972 7926 7973 7927 def poldegree(self, var=-1): 7974 7928 """ 7975 7929 f.poldegree(var=x): Return the degree of this polynomial. 7976 7930 """ 7977 7931 pari_catch_sig_on() 7978 n = poldegree(self.g, self.get_var(var))7932 n = poldegree(self.g, P.get_var(var)) 7979 7933 pari_catch_sig_off() 7980 7934 return n 7981 7935 … … 8018 7972 sage: nf.nfgaloisconj() 8019 7973 [-x, x]~ 8020 7974 """ 8021 global t0 8022 if denom is not None: 8023 t0GEN(denom) 7975 cdef gen t0 7976 if denom is None: 7977 pari_catch_sig_on() 7978 return P.new_gen(galoisconj0(self.g, flag, NULL, prec_bits_to_words(precision))) 8024 7979 else: 8025 t0 = NULL8026 pari_catch_sig_on()8027 return self.new_gen(galoisconj0(self.g, flag, t0, pbw(precision)))7980 t0 = P(denom) 7981 pari_catch_sig_on() 7982 return P.new_gen(galoisconj0(self.g, flag, t0.g, prec_bits_to_words(precision))) 8028 7983 8029 7984 def nfroots(self, poly): 8030 7985 r""" … … 8044 7999 sage: nf.nfroots(y^4 + 2) 8045 8000 [Mod(-zz, zz^4 + 2), Mod(zz, zz^4 + 2)] 8046 8001 """ 8047 t0GEN(poly)8048 pari_catch_sig_on() 8049 return self.new_gen(nfroots(self.g, t0))8002 cdef gen t0 = P(poly) 8003 pari_catch_sig_on() 8004 return P.new_gen(nfroots(self.g, t0.g)) 8050 8005 8051 8006 def polhensellift(self, y, p, long e): 8052 8007 """ … … 8054 8009 modulo p to a factorization modulo `p^e` using Hensel lift. 8055 8010 The factors in y must be pairwise relatively prime modulo p. 8056 8011 """ 8057 t0GEN(y)8058 t1GEN(p)8059 pari_catch_sig_on() 8060 return self.new_gen(polhensellift(self.g, t0, t1, e))8012 cdef gen t0 = P(y) 8013 cdef gen t1 = P(p) 8014 pari_catch_sig_on() 8015 return P.new_gen(polhensellift(self.g, t0.g, t1.g, e)) 8061 8016 8062 8017 def polisirreducible(self): 8063 8018 """ … … 8076 8031 variable v otherwise 8077 8032 """ 8078 8033 pari_catch_sig_on() 8079 return self.new_gen(pollead(self.g, self.get_var(v)))8034 return P.new_gen(pollead(self.g, P.get_var(v))) 8080 8035 8081 8036 def polrecip(self): 8082 8037 pari_catch_sig_on() 8083 return self.new_gen(polrecip(self.g))8038 return P.new_gen(polrecip(self.g)) 8084 8039 8085 8040 def polred(self, flag=0, fa=None): 8041 cdef gen t0 8086 8042 if fa is None: 8087 8043 pari_catch_sig_on() 8088 return self.new_gen(polred0(self.g, flag, NULL))8044 return P.new_gen(polred0(self.g, flag, NULL)) 8089 8045 else: 8090 t0 GEN(fa)8046 t0 = P(fa) 8091 8047 pari_catch_sig_on() 8092 return self.new_gen(polred0(self.g, flag, t0))8048 return P.new_gen(polred0(self.g, flag, t0.g)) 8093 8049 8094 8050 def polredabs(self, flag=0): 8095 8051 pari_catch_sig_on() 8096 return self.new_gen(polredabs0(self.g, flag))8052 return P.new_gen(polredabs0(self.g, flag)) 8097 8053 8098 8054 def polredbest(self, flag=0): 8099 8055 pari_catch_sig_on() 8100 return self.new_gen(polredbest(self.g, flag))8056 return P.new_gen(polredbest(self.g, flag)) 8101 8057 8102 8058 def polresultant(self, y, var=-1, flag=0): 8103 t0GEN(y)8104 pari_catch_sig_on() 8105 return self.new_gen(polresultant0(self.g, t0, self.get_var(var), flag))8059 cdef gen t0 = P(y) 8060 pari_catch_sig_on() 8061 return P.new_gen(polresultant0(self.g, t0.g, P.get_var(var), flag)) 8106 8062 8107 8063 def polroots(self, flag=0, precision=0): 8108 8064 """ … … 8111 8067 by Gourdon, or 1: uses a modified Newton method. 8112 8068 """ 8113 8069 pari_catch_sig_on() 8114 return self.new_gen(roots0(self.g, flag, pbw(precision)))8070 return P.new_gen(roots0(self.g, flag, prec_bits_to_words(precision))) 8115 8071 8116 8072 def polrootsmod(self, p, flag=0): 8117 t0GEN(p)8118 pari_catch_sig_on() 8119 return self.new_gen(rootmod0(self.g, t0, flag))8073 cdef gen t0 = P(p) 8074 pari_catch_sig_on() 8075 return P.new_gen(rootmod0(self.g, t0.g, flag)) 8120 8076 8121 8077 def polrootspadic(self, p, r=20): 8122 t0GEN(p)8123 pari_catch_sig_on() 8124 return self.new_gen(rootpadic(self.g, t0, r))8078 cdef gen t0 = P(p) 8079 pari_catch_sig_on() 8080 return P.new_gen(rootpadic(self.g, t0.g, r)) 8125 8081 8126 8082 def polrootspadicfast(self, p, r=20): 8127 t0GEN(p)8128 pari_catch_sig_on() 8129 return self.new_gen(rootpadicfast(self.g, t0, r))8083 cdef gen t0 = P(p) 8084 pari_catch_sig_on() 8085 return P.new_gen(rootpadicfast(self.g, t0.g, r)) 8130 8086 8131 8087 def polsturm(self, a, b): 8132 t0GEN(a)8133 t1GEN(b)8134 pari_catch_sig_on() 8135 n = sturmpart(self.g, t0 , t1)8088 cdef gen t0 = P(a) 8089 cdef gen t1 = P(b) 8090 pari_catch_sig_on() 8091 n = sturmpart(self.g, t0.g, t1.g) 8136 8092 pari_catch_sig_off() 8137 8093 return n 8138 8094 … … 8143 8099 return n 8144 8100 8145 8101 def polsylvestermatrix(self, g): 8146 t0GEN(g)8147 pari_catch_sig_on() 8148 return self.new_gen(sylvestermatrix(self.g, t0))8102 cdef gen t0 = P(g) 8103 pari_catch_sig_on() 8104 return P.new_gen(sylvestermatrix(self.g, t0.g)) 8149 8105 8150 8106 def polsym(self, long n): 8151 8107 pari_catch_sig_on() 8152 return self.new_gen(polsym(self.g, n))8108 return P.new_gen(polsym(self.g, n)) 8153 8109 8154 8110 def serconvol(self, g): 8155 t0GEN(g)8156 pari_catch_sig_on() 8157 return self.new_gen(convol(self.g, t0))8111 cdef gen t0 = P(g) 8112 pari_catch_sig_on() 8113 return P.new_gen(convol(self.g, t0.g)) 8158 8114 8159 8115 def serlaplace(self): 8160 8116 pari_catch_sig_on() 8161 return self.new_gen(laplace(self.g))8117 return P.new_gen(laplace(self.g)) 8162 8118 8163 8119 def serreverse(self): 8164 8120 """ … … 8179 8135 x + O(x^4) 8180 8136 """ 8181 8137 pari_catch_sig_on() 8182 return self.new_gen(recip(self.g))8138 return P.new_gen(recip(self.g)) 8183 8139 8184 8140 def thueinit(self, flag=0): 8185 8141 pari_catch_sig_on() 8186 return self.new_gen(thueinit(self.g, flag, prec))8142 return P.new_gen(thueinit(self.g, flag, prec)) 8187 8143 8188 8144 8189 8145 def rnfisnorminit(self, polrel, long flag=2): 8190 t0GEN(polrel)8191 pari_catch_sig_on() 8192 return self.new_gen(rnfisnorminit(self.g, t0, flag))8146 cdef gen t0 = P(polrel) 8147 pari_catch_sig_on() 8148 return P.new_gen(rnfisnorminit(self.g, t0.g, flag)) 8193 8149 8194 8150 def rnfisnorm(self, T, long flag=0): 8195 t0GEN(T)8196 pari_catch_sig_on() 8197 return self.new_gen(rnfisnorm(t0, self.g, flag))8151 cdef gen t0 = P(T) 8152 pari_catch_sig_on() 8153 return P.new_gen(rnfisnorm(t0.g, self.g, flag)) 8198 8154 8199 8155 ########################################### 8200 8156 # 8: Vectors, matrices, LINEAR ALGEBRA and sets … … 8214 8170 This function uses the PARI row and column indexing, so the 8215 8171 first row or column is indexed by 1 instead of 0. 8216 8172 """ 8217 t0GEN(y) 8173 cdef gen t0 = P(y) 8174 cdef gen t1 8218 8175 if z is None: 8219 8176 pari_catch_sig_on() 8220 return P.new_gen(shallowextract(self.g, t0 ))8177 return P.new_gen(shallowextract(self.g, t0.g)) 8221 8178 else: 8222 t1 GEN(z)8179 t1 = P(z) 8223 8180 pari_catch_sig_on() 8224 return P.new_gen(extract0(self.g, t0 , t1))8181 return P.new_gen(extract0(self.g, t0.g, t1.g)) 8225 8182 8226 8183 def ncols(self): 8227 8184 """ … … 8328 8285 robust, slower implementation, valid for non integral quadratic 8329 8286 forms. 8330 8287 """ 8331 t0GEN(B)8332 t1GEN(max)8333 pari_catch_sig_on() 8334 return self.new_gen(qfminim0(self.g,t0,t1,flag,precdl))8288 cdef gen t0 = P(B) 8289 cdef gen t1 = P(max) 8290 pari_catch_sig_on() 8291 return P.new_gen(qfminim0(self.g, t0.g, t1.g, flag, precdl)) 8335 8292 8336 8293 def qfrep(self, B, long flag=0): 8337 8294 """ … … 8340 8297 digits of flag mean 1: count vectors of even norm from 1 to 2B, 2: 8341 8298 return a t_VECSMALL instead of a t_VEC. 8342 8299 """ 8343 t0GEN(B)8344 pari_catch_sig_on() 8345 return self.new_gen(qfrep0(self.g,t0,flag))8300 cdef gen t0 = P(B) 8301 pari_catch_sig_on() 8302 return P.new_gen(qfrep0(self.g, t0.g, flag)) 8346 8303 8347 8304 def matsolve(self, B): 8348 8305 """ … … 8367 8324 sage: pari('[1,1;1,-1]').matsolve(pari('[1;0]')) 8368 8325 [1/2; 1/2] 8369 8326 """ 8370 t0GEN(B)8371 pari_catch_sig_on() 8372 return self.new_gen(gauss(self.g,t0))8327 cdef gen t0 = P(B) 8328 pari_catch_sig_on() 8329 return P.new_gen(gauss(self.g, t0.g)) 8373 8330 8374 8331 def matsolvemod(self, D, B, long flag = 0): 8375 8332 r""" … … 8413 8370 sage: M2.matsolvemod(9, pari('[2,45]~'), 1) 8414 8371 [[1, 1]~, [-1, -4; 1, -5]] 8415 8372 """ 8416 t0GEN(D)8417 t1GEN(B)8418 pari_catch_sig_on() 8419 return self.new_gen(matsolvemod0(self.g, t0, t1, flag))8373 cdef gen t0 = P(D) 8374 cdef gen t1 = P(B) 8375 pari_catch_sig_on() 8376 return P.new_gen(matsolvemod0(self.g, t0.g, t1.g, flag)) 8420 8377 8421 8378 def matker(self, long flag=0): 8422 8379 """ … … 8563 8520 sage: pari(M).mathnfmod(12) 8564 8521 [1, 0, 0; 0, 2, 0; 0, 0, 6] 8565 8522 """ 8566 t0GEN(d)8567 pari_catch_sig_on() 8568 return self.new_gen(hnfmod(self.g, t0))8523 cdef gen t0 = P(d) 8524 pari_catch_sig_on() 8525 return P.new_gen(hnfmod(self.g, t0.g)) 8569 8526 8570 8527 def mathnfmodid(self, d): 8571 8528 """ … … 8592 8549 sage: pari(M).mathnfmod(6) 8593 8550 [1, 0, 0; 0, 1, 0; 0, 0, 6] 8594 8551 """ 8595 t0GEN(d)8596 pari_catch_sig_on() 8597 return self.new_gen(hnfmodid(self.g, t0))8552 cdef gen t0 = P(d) 8553 pari_catch_sig_on() 8554 return P.new_gen(hnfmodid(self.g, t0.g)) 8598 8555 8599 8556 def matsnf(self, flag=0): 8600 8557 """ … … 8701 8658 PariError: sorry, factor for general polynomials is not yet implemented 8702 8659 """ 8703 8660 cdef int r 8661 cdef GEN t0 8704 8662 cdef GEN cutoff 8705 8663 if limit == -1 and typ(self.g) == t_INT and proof: 8706 8664 pari_catch_sig_on() … … 8722 8680 ########################################### 8723 8681 8724 8682 def hilbert(x, y, p): 8725 cdef long ret 8726 t0GEN(y) 8727 t1GEN(p) 8728 pari_catch_sig_on() 8729 ret = hilbert0(x.g, t0, t1) 8683 cdef gen t0 = P(y) 8684 cdef gen t1 = P(p) 8685 pari_catch_sig_on() 8686 ret = hilbert0(x.g, t0.g, t1.g) 8730 8687 pari_catch_sig_off() 8731 8688 return ret 8732 8689 8733 8690 def chinese(self, y): 8734 t0GEN(y)8735 pari_catch_sig_on() 8736 return P.new_gen(chinese(self.g, t0 ))8691 cdef gen t0 = P(y) 8692 pari_catch_sig_on() 8693 return P.new_gen(chinese(self.g, t0.g)) 8737 8694 8738 8695 def order(self): 8739 8696 pari_catch_sig_on() … … 8867 8824 sage: f.subst(x, "xyz")^2 8868 8825 xyz^6 + 34*xyz^4 + 6*xyz^3 + 289*xyz^2 + 102*xyz + 9 8869 8826 """ 8870 cdef long n 8871 n = P.get_var(var) 8872 t0GEN(z) 8873 pari_catch_sig_on() 8874 return P.new_gen(gsubst(self.g, n, t0)) 8827 cdef gen t0 = P(z) 8828 pari_catch_sig_on() 8829 cdef long n = P.get_var(var) 8830 return P.new_gen(gsubst(self.g, n, t0.g)) 8875 8831 8876 8832 def substpol(self, y, z): 8877 t0GEN(y)8878 t1GEN(z)8879 pari_catch_sig_on() 8880 return self.new_gen(gsubstpol(self.g, t0, t1))8833 cdef gen t0 = P(y) 8834 cdef gen t1 = P(z) 8835 pari_catch_sig_on() 8836 return P.new_gen(gsubstpol(self.g, t0.g, t1.g)) 8881 8837 8882 8838 def nf_subst(self, z): 8883 8839 """ … … 8916 8872 sage: Lpari.bnf_get_cyc() # We still have a bnf after substituting 8917 8873 [2] 8918 8874 """ 8919 cdef GEN nf = self.get_nf() 8920 t0GEN(z) 8921 pari_catch_sig_on() 8922 return P.new_gen(gsubst(self.g, nf_get_varn(nf), t0)) 8875 cdef gen t0 = P(z) 8876 pari_catch_sig_on() 8877 return P.new_gen(gsubst(self.g, gvar(self.g), t0.g)) 8923 8878 8924 8879 def taylor(self, v=-1): 8925 8880 pari_catch_sig_on() 8926 return self.new_gen(tayl(self.g, self.get_var(v), precdl))8881 return P.new_gen(tayl(self.g, P.get_var(v), precdl)) 8927 8882 8928 8883 def thue(self, rhs, ne): 8929 t0GEN(rhs)8930 t1GEN(ne)8931 pari_catch_sig_on() 8932 return self.new_gen(thue(self.g, t0, t1))8884 cdef gen t0 = P(rhs) 8885 cdef gen t1 = P(ne) 8886 pari_catch_sig_on() 8887 return P.new_gen(thue(self.g, t0.g, t1.g)) 8933 8888 8934 8889 def charpoly(self, var=-1, flag=0): 8935 8890 """ … … 8943 8898 8944 8899 8945 8900 def kronecker(gen self, y): 8946 t0GEN(y)8901 cdef gen t0 = P(y) 8947 8902 pari_catch_sig_on() 8948 return P.new_gen(gkronecker(self.g, t0 ))8903 return P.new_gen(gkronecker(self.g, t0.g)) 8949 8904 8950 8905 8951 8906 def type(gen self): … … 9013 8968 P(self[i]) = ya[i] for all i). Also return an error estimate on the 9014 8969 returned value. 9015 8970 """ 9016 t0GEN(ya)9017 t1GEN(x)8971 cdef gen t0 = P(ya) 8972 cdef gen t1 = P(x) 9018 8973 cdef GEN dy, g 9019 8974 pari_catch_sig_on() 9020 g = polint(self.g, t0 , t1, &dy)9021 dif = self.new_gen_noclear(dy)9022 return self.new_gen(g), dif8975 g = polint(self.g, t0.g, t1.g, &dy) 8976 dif = P.new_gen_noclear(dy) 8977 return P.new_gen(g), dif 9023 8978 9024 8979 def algdep(self, long n): 9025 8980 """ … … 9037 8992 210 9038 8993 """ 9039 8994 pari_catch_sig_on() 9040 return self.new_gen(algdep(self.g, n))8995 return P.new_gen(algdep(self.g, n)) 9041 8996 9042 8997 def concat(self, y): 9043 t0GEN(y)9044 pari_catch_sig_on() 9045 return self.new_gen(concat(self.g, t0))8998 cdef gen t0 = P(y) 8999 pari_catch_sig_on() 9000 return P.new_gen(concat(self.g, t0.g)) 9046 9001 9047 9002 def lindep(self, flag=0): 9048 9003 pari_catch_sig_on() 9049 return self.new_gen(lindep0(self.g, flag))9004 return P.new_gen(lindep0(self.g, flag)) 9050 9005 9051 9006 def listinsert(self, obj, long n): 9052 t0GEN(obj)9053 pari_catch_sig_on() 9054 return self.new_gen(listinsert(self.g, t0, n))9007 cdef gen t0 = P(obj) 9008 pari_catch_sig_on() 9009 return P.new_gen(listinsert(self.g, t0.g, n)) 9055 9010 9056 9011 def listput(self, obj, long n): 9057 t0GEN(obj)9058 pari_catch_sig_on() 9059 return self.new_gen(listput(self.g, t0, n))9012 cdef gen t0 = P(obj) 9013 pari_catch_sig_on() 9014 return P.new_gen(listput(self.g, t0.g, n)) 9060 9015 9061 9016 9062 9017 … … 9167 9122 sage: E.ellwp(1, flag=1) 9168 9123 [13.9658695257485 + 0.E-18*I, 50.5619300880073 ... E-18*I] 9169 9124 """ 9170 t0GEN(z)9125 cdef gen t0 = P(z) 9171 9126 pari_catch_sig_on() 9172 9127 cdef long dprec 9173 dprec = gprecision(t0 )9128 dprec = gprecision(t0.g) 9174 9129 if dprec: 9175 9130 dprec = prec_words_to_dec(dprec) 9176 9131 else: 9177 9132 dprec = prec 9178 return self.new_gen(ellwp0(self.g, t0, flag, n+2, dprec))9133 return P.new_gen(ellwp0(self.g, t0.g, flag, n+2, dprec)) 9179 9134 9180 9135 def ellchangepoint(self, y): 9181 9136 """ … … 9198 9153 sage: f.ellisoncurve([-1,4]) 9199 9154 True 9200 9155 """ 9201 t0GEN(y)9202 pari_catch_sig_on() 9203 return self.new_gen(ellchangepoint(self.g, t0))9156 cdef gen t0 = P(y) 9157 pari_catch_sig_on() 9158 return P.new_gen(ellchangepoint(self.g, t0.g)) 9204 9159 9205 9160 def debug(gen self, long depth = -1): 9206 9161 r""" … … 9446 9401 """ 9447 9402 return int(self.default('debug')) 9448 9403 9449 cdef GEN toGEN(self, x, int i) except NULL:9450 cdef gen _x9451 if PY_TYPE_CHECK(x, gen):9452 _x = x9453 return _x.g9454 9455 t0heap[i] = self(x)9456 _x = t0heap[i]9457 return _x.g9458 9459 9404 def set_real_precision(self, long n): 9460 9405 """ 9461 9406 Sets the PARI default real precision. … … 9497 9442 9498 9443 def get_series_precision(self): 9499 9444 return precdl 9500 9501 9502 ########################################### 9503 # Create a gen from a GEN object. 9504 # This *steals* a reference to the GEN, as it 9505 # frees the memory the GEN occupied. 9506 ########################################### 9445 9446 cdef void clear_stack(self): 9447 """ 9448 Call ``pari_catch_sig_off()``, and clear the entire PARI stack 9449 if we are leaving the outermost ``pari_catch_sig_on() ... 9450 pari_catch_sig_off()`` block. 9451 9452 """ 9453 global mytop, avma 9454 if _signals.sig_on_count <= 1: 9455 avma = mytop 9456 pari_catch_sig_off() 9507 9457 9508 9458 cdef gen new_gen(self, GEN x): 9509 9459 """ 9510 Create a new gen, then free the \*entire\* stack and call 9511 pari_catch_sig_off(). 9512 """ 9513 cdef gen g 9514 g = _new_gen(x) 9515 global mytop, avma 9516 avma = mytop 9517 pari_catch_sig_off() 9460 Create a new gen wrapping `x`, then call ``clear_stack()``. 9461 """ 9462 cdef gen g = _new_gen(x) 9463 self.clear_stack() 9518 9464 return g 9519 9465 9520 cdef object new_gen_to_string(self, GEN x):9521 """9522 Converts a gen to a Python string, free the \*entire\* stack and call9523 pari_catch_sig_off(). This is meant to be used in place of new_gen().9524 """9525 cdef char* c9526 cdef int n9527 c = GENtostr(x)9528 s = str(c)9529 pari_free(c)9530 global mytop, avma9531 avma = mytop9532 pari_catch_sig_off()9533 return s9534 9535 cdef void clear_stack(self):9536 """9537 Clear the entire PARI stack and call pari_catch_sig_off().9538 """9539 global mytop, avma9540 avma = mytop9541 pari_catch_sig_off()9542 9543 cdef void set_mytop_to_avma(self):9544 global mytop, avma9545 mytop = avma9546 9547 9466 cdef gen new_gen_noclear(self, GEN x): 9548 9467 """ 9549 9468 Create a new gen, but don't free any memory on the stack and don't … … 9724 9643 """ 9725 9644 Create a new complex number, initialized from re and im. 9726 9645 """ 9727 t0GEN(re) 9728 t1GEN(im) 9729 cdef GEN cp 9730 pari_catch_sig_on() 9731 cp = cgetg(3, t_COMPLEX) 9732 set_gel(cp, 1, t0) 9733 set_gel(cp, 2, t1) 9646 cdef gen t0 = self(re) 9647 cdef gen t1 = self(im) 9648 pari_catch_sig_on() 9649 cdef GEN cp = mkcomplex(t0.g, t1.g) 9734 9650 return self.new_gen(cp) 9735 9651 9736 9652 cdef GEN deepcopy_to_python_heap(self, GEN x, pari_sp* address): … … 9793 9709 9794 9710 See :func:`pari` for more examples. 9795 9711 """ 9712 cdef GEN g 9796 9713 cdef int length, i 9714 cdef mpz_t mpz_int 9797 9715 cdef gen v 9798 9716 9799 late_import()9800 9801 9717 if isinstance(s, gen): 9802 9718 return s 9803 elif isinstance(s, Integer):9804 return self.new_gen_from_mpz_t(<void *>s + mpz_t_offset)9805 9719 elif PyObject_HasAttrString(s, "_pari_"): 9806 9720 return s._pari_() 9807 9721 … … 9811 9725 return self.new_gen(stoi(PyInt_AS_LONG(s))) 9812 9726 if PyBool_Check(s): 9813 9727 return self.PARI_ONE if s else self.PARI_ZERO 9814 cdef mpz_t mpz_int9815 cdef GEN g9816 9728 if PyLong_Check(s): 9817 9729 pari_catch_sig_on() 9818 9730 mpz_init(mpz_int) … … 9839 9751 return v 9840 9752 9841 9753 t = str(s) 9842 pari_catch_sig_ str('evaluating PARI string')9754 pari_catch_sig_on() 9843 9755 g = gp_read_str(t) 9844 9756 if g == gnil: 9845 9757 pari_catch_sig_off() … … 10380 10292 sage: cyclotomic_polynomial(8)(2) 10381 10293 17 10382 10294 """ 10383 t0GEN(v)10384 pari_catch_sig_on() 10385 return self.new_gen(polcyclo_eval(n, t0 ))10295 cdef gen t0 = self(v) 10296 pari_catch_sig_on() 10297 return self.new_gen(polcyclo_eval(n, t0.g)) 10386 10298 10387 10299 def polsubcyclo(self, long n, long d, v=-1): 10388 10300 """ … … 10450 10362 ... 10451 10363 PariError: incorrect type in setrand 10452 10364 """ 10453 t0GEN(seed)10454 pari_catch_sig_on() 10455 setrand(t0 )10365 cdef gen t0 = self(seed) 10366 pari_catch_sig_on() 10367 setrand(t0.g) 10456 10368 pari_catch_sig_off() 10457 10369 10458 10370 def getrand(self): -
sage/rings/finite_rings/element_pari_ffelt.pyx
diff --git a/sage/rings/finite_rings/element_pari_ffelt.pyx b/sage/rings/finite_rings/element_pari_ffelt.pyx
a b 326 326 c^4 + 2*c^3 327 327 """ 328 328 pari_catch_sig_on() 329 return pari.new_gen_to_string(self.val)329 return str(pari.new_gen(self.val)) 330 330 331 331 def __hash__(FiniteFieldElement_pari_ffelt self): 332 332 """