Ticket #11868: trac_11868-t0GEN.patch
File trac_11868-t0GEN.patch, 71.2 KB (added by , 9 years ago) |
---|
-
sage/libs/pari/gen.pxd
# HG changeset patch # User Peter Bruin <P.Bruin@warwick.ac.uk> # Date 1385259470 0 # Node ID 9a9096a3c9a32d1957a7c89ab04ebd8caba217c7 # 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 NULL36 cdef GEN toGEN(self, x) except NULL 40 37 cdef GEN _new_GEN_from_mpz_t_matrix(self, mpz_t** B, Py_ssize_t nr, Py_ssize_t nc) 41 38 cdef GEN _new_GEN_from_mpz_t_matrix_rotate90(self, mpz_t** B, Py_ssize_t nr, Py_ssize_t nc) 42 39 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 pari_catch_sig_on() 661 cdef GEN t0 = P.toGEN(n) 662 return P.new_gen(gpow(self.g, t0, 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:713 def get_nf(self): 746 714 """ 747 715 Given a PARI object `self`, convert it to a proper PARI number 748 716 field (nf) structure. … … 781 749 cdef long nftyp 782 750 pari_catch_sig_on() 783 751 nf = get_nf(self.g, &nftyp) 784 pari_catch_sig_off()785 752 if not nf: 753 pari_catch_sig_off() 786 754 raise TypeError("Not a PARI number field") 787 return nf755 return P.new_gen(nf) 788 756 789 757 def nf_get_pol(self): 790 758 """ … … 815 783 ... 816 784 TypeError: Not a PARI number field 817 785 """ 818 cdef GENnf = self.get_nf()819 pari_catch_sig_on() 820 return self.new_gen(nf_get_pol(nf))786 cdef gen nf = self.get_nf() 787 pari_catch_sig_on() 788 return P.new_gen(nf_get_pol(nf.g)) 821 789 822 790 def nf_get_diff(self): 823 791 """ … … 834 802 sage: pari(K).nf_get_diff() 835 803 [12, 0, 0, 0; 0, 12, 8, 0; 0, 0, 4, 0; 0, 0, 0, 4] 836 804 """ 837 cdef GENnf = self.get_nf()805 cdef gen nf = self.get_nf() 838 806 pari_catch_sig_on() 839 807 # Very bad code, but there doesn't seem to be a better way 840 return self.new_gen(gel(gel(nf, 5), 5))808 return P.new_gen(gel(gel(nf.g, 5), 5)) 841 809 842 810 def nf_get_sign(self): 843 811 """ … … 863 831 """ 864 832 cdef long r1 865 833 cdef long r2 866 cdef GENnf = self.get_nf()867 nf_get_sign(nf , &r1, &r2)834 cdef gen nf = self.get_nf() 835 nf_get_sign(nf.g, &r1, &r2) 868 836 return [r1, r2] 869 837 870 838 def nf_get_zk(self): … … 883 851 sage: pari(K).nf_get_zk() 884 852 [1, y, y^3 - 4*y, y^2 - 2] 885 853 """ 886 cdef GENnf = self.get_nf()887 pari_catch_sig_on() 888 return self.new_gen(nf_get_zk(nf))854 cdef gen nf = self.get_nf() 855 pari_catch_sig_on() 856 return P.new_gen(nf_get_zk(nf.g)) 889 857 890 858 def bnf_get_no(self): 891 859 """ … … 1628 1596 sage: int(pari("Mod(2, 7)")) 1629 1597 2 1630 1598 """ 1599 late_import() 1631 1600 return int(Integer(self)) 1632 1601 1633 1602 def int_unsafe(gen self): … … 1822 1791 sage: long(pari("Mod(2, 7)")) 1823 1792 2L 1824 1793 """ 1794 late_import() 1825 1795 return long(Integer(self)) 1826 1796 1827 1797 def __float__(gen self): … … 1913 1883 sage: a.gequal(c) 1914 1884 False 1915 1885 """ 1916 t0GEN(b)1917 pari_catch_sig_on()1886 pari_catch_sig_on() 1887 cdef GEN t0 = P.toGEN(b) 1918 1888 cdef int ret = gequal(a.g, t0) 1919 pari_catch_sig_off()1889 P.clear_stack() 1920 1890 return ret != 0 1921 1891 1922 1892 def gequal0(gen a): … … 2134 2104 """ 2135 2105 cdef int n 2136 2106 cdef GEN x 2107 cdef GEN t0 2137 2108 2138 2109 if k is None: 2139 2110 pari_catch_sig_on() 2140 2111 n = gisanypower(self.g, &x) 2141 2112 if n == 0: 2142 pari_catch_sig_off()2113 P.clear_stack() 2143 2114 return 1, self 2144 2115 else: 2145 2116 return n, P.new_gen(x) 2146 2117 else: 2147 2118 k = int(k) 2148 t0GEN(k)2149 2119 pari_catch_sig_on() 2120 t0 = P.toGEN(k) 2150 2121 n = ispower(self.g, t0, &x) 2151 2122 if n == 0: 2152 pari_catch_sig_off()2123 P.clear_stack() 2153 2124 return False, None 2154 2125 else: 2155 2126 return k, P.new_gen(x) … … 2163 2134 2-dimensional column vector the quotient and the remainder, with 2164 2135 respect to v (to main variable if v is omitted). 2165 2136 """ 2166 t0GEN(y)2167 2137 pari_catch_sig_on() 2138 cdef GEN t0 = P.toGEN(y) 2168 2139 return P.new_gen(divrem(x.g, t0, P.get_var(var))) 2169 2140 2170 2141 def lex(gen x, y): … … 2172 2143 lex(x,y): Compare x and y lexicographically (1 if xy, 0 if x==y, -1 2173 2144 if xy) 2174 2145 """ 2175 t0GEN(y)2176 2146 pari_catch_sig_on() 2147 cdef GEN t0 = P.toGEN(y) 2177 2148 return lexcmp(x.g, t0) 2178 2149 2179 2150 def max(gen x, y): 2180 2151 """ 2181 2152 max(x,y): Return the maximum of x and y. 2182 2153 """ 2183 t0GEN(y)2184 pari_catch_sig_on()2154 pari_catch_sig_on() 2155 cdef GEN t0 = P.toGEN(y) 2185 2156 return P.new_gen(gmax(x.g, t0)) 2186 2157 2187 2158 def min(gen x, y): 2188 2159 """ 2189 2160 min(x,y): Return the minimum of x and y. 2190 2161 """ 2191 t0GEN(y)2192 pari_catch_sig_on()2162 pari_catch_sig_on() 2163 cdef GEN t0 = P.toGEN(y) 2193 2164 return P.new_gen(gmin(x.g, t0)) 2194 2165 2195 2166 def shift(gen x, long n): … … 2486 2457 sage: a.type() 2487 2458 't_POLMOD' 2488 2459 """ 2489 t0GEN(y)2490 pari_catch_sig_on()2491 return P.new_gen(gmodulo(x.g, t0))2460 pari_catch_sig_on() 2461 cdef GEN t0 = P.toGEN(y) 2462 return P.new_gen(gmodulo(x.g, t0)) 2492 2463 2493 2464 def Pol(self, v=-1): 2494 2465 """ … … 2634 2605 ... 2635 2606 PariError: square discriminant in Qfb 2636 2607 """ 2637 t0GEN(b); t1GEN(c); t2GEN(D) 2638 pari_catch_sig_on() 2608 pari_catch_sig_on() 2609 cdef GEN t0 = P.toGEN(b) 2610 cdef GEN t1 = P.toGEN(c) 2611 cdef GEN t2 = P.toGEN(D) 2639 2612 return P.new_gen(Qfb0(a.g, t0, t1, t2, prec)) 2640 2613 2641 2614 … … 2768 2741 cdef char* c 2769 2742 pari_catch_sig_on() 2770 2743 c = GENtostr(self.g) 2771 v = self.new_gen(strtoGENstr(c))2744 v = P.new_gen(strtoGENstr(c)) 2772 2745 pari_free(c) 2773 2746 return v 2774 2747 … … 3083 3056 sage: pari(-1).bitand(-1) 3084 3057 -1 3085 3058 """ 3086 t0GEN(y)3087 pari_catch_sig_on()3059 pari_catch_sig_on() 3060 cdef GEN t0 = P.toGEN(y) 3088 3061 return P.new_gen(gbitand(x.g, t0)) 3089 3062 3090 3063 … … 3163 3136 sage: pari(8+4).bitnegimply(8) 3164 3137 4 3165 3138 """ 3166 t0GEN(y)3167 pari_catch_sig_on()3139 pari_catch_sig_on() 3140 cdef GEN t0 = P.toGEN(y) 3168 3141 return P.new_gen(gbitnegimply(x.g, t0)) 3169 3142 3170 3143 … … 3198 3171 sage: pari(13).bitor(1) 3199 3172 13 3200 3173 """ 3201 t0GEN(y)3202 pari_catch_sig_on()3174 pari_catch_sig_on() 3175 cdef GEN t0 = P.toGEN(y) 3203 3176 return P.new_gen(gbitor(x.g, t0)) 3204 3177 3205 3178 … … 3272 3245 sage: pari(6).bitxor(0) 3273 3246 6 3274 3247 """ 3275 t0GEN(y)3276 pari_catch_sig_on()3248 pari_catch_sig_on() 3249 cdef GEN t0 = P.toGEN(y) 3277 3250 return P.new_gen(gbitxor(x.g, t0)) 3278 3251 3279 3252 … … 4164 4137 2147483647 # 32-bit 4165 4138 9223372036854775807 # 64-bit 4166 4139 """ 4167 cdef long v 4168 t0GEN(p) 4169 pari_catch_sig_on() 4140 pari_catch_sig_on() 4141 cdef GEN t0 = P.toGEN(p) 4170 4142 v = ggval(x.g, t0) 4171 pari_catch_sig_off()4143 P.clear_stack() 4172 4144 return v 4173 4145 4174 4146 def _valp(gen x): … … 4333 4305 sage: pari(1+i).agm(-3) 4334 4306 -0.964731722290876 + 1.15700282952632*I 4335 4307 """ 4336 t0GEN(y)4337 pari_catch_sig_on()4308 pari_catch_sig_on() 4309 cdef GEN t0 = P.toGEN(y) 4338 4310 return P.new_gen(agm(x.g, t0, pbw(precision))) 4339 4311 4340 4312 def arg(gen x, precision=0): … … 4510 4482 sage: pari(2).besselh1(3) 4511 4483 0.486091260585891 - 0.160400393484924*I 4512 4484 """ 4513 t0GEN(x)4514 pari_catch_sig_on()4515 return P.new_gen(hbessel1(nu.g, t0, p bw(precision)))4485 pari_catch_sig_on() 4486 cdef GEN t0 = P.toGEN(x) 4487 return P.new_gen(hbessel1(nu.g, t0, prec_bits_to_words(precision))) 4516 4488 4517 4489 def besselh2(gen nu, x, precision=0): 4518 4490 r""" … … 4530 4502 sage: pari(2).besselh2(3) 4531 4503 0.486091260585891 + 0.160400393484924*I 4532 4504 """ 4533 t0GEN(x)4534 pari_catch_sig_on()4535 return P.new_gen(hbessel2(nu.g, t0, p bw(precision)))4505 pari_catch_sig_on() 4506 cdef GEN t0 = P.toGEN(x) 4507 return P.new_gen(hbessel2(nu.g, t0, prec_bits_to_words(precision))) 4536 4508 4537 4509 def besselj(gen nu, x, precision=0): 4538 4510 r""" … … 4553 4525 sage: pari(2).besselj(3) 4554 4526 0.486091260585891 4555 4527 """ 4556 t0GEN(x)4557 pari_catch_sig_on()4558 return P.new_gen(jbessel(nu.g, t0, p bw(precision)))4528 pari_catch_sig_on() 4529 cdef GEN t0 = P.toGEN(x) 4530 return P.new_gen(jbessel(nu.g, t0, prec_bits_to_words(precision))) 4559 4531 4560 4532 def besseljh(gen nu, x, precision=0): 4561 4533 """ … … 4578 4550 0.4127100324 # 32-bit 4579 4551 0.412710032209716 # 64-bit 4580 4552 """ 4581 t0GEN(x)4582 pari_catch_sig_on()4583 return P.new_gen(jbesselh(nu.g, t0, p bw(precision)))4553 pari_catch_sig_on() 4554 cdef GEN t0 = P.toGEN(x) 4555 return P.new_gen(jbesselh(nu.g, t0, prec_bits_to_words(precision))) 4584 4556 4585 4557 def besseli(gen nu, x, precision=0): 4586 4558 r""" … … 4604 4576 sage: pari(2).besseli(3+i) 4605 4577 1.12539407613913 + 2.08313822670661*I 4606 4578 """ 4607 t0GEN(x)4608 pari_catch_sig_on()4609 return P.new_gen(ibessel(nu.g, t0, p bw(precision)))4579 pari_catch_sig_on() 4580 cdef GEN t0 = P.toGEN(x) 4581 return P.new_gen(ibessel(nu.g, t0, prec_bits_to_words(precision))) 4610 4582 4611 4583 def besselk(gen nu, x, long flag=0, precision=0): 4612 4584 """ … … 4647 4619 sage: pari(2+i).besselk(300, flag=1) 4648 4620 3.74224603319728 E-132 + 2.49071062641525 E-134*I 4649 4621 """ 4650 t0GEN(x)4651 pari_catch_sig_on()4652 return P.new_gen(kbessel(nu.g, t0, p bw(precision)))4622 pari_catch_sig_on() 4623 cdef GEN t0 = P.toGEN(x) 4624 return P.new_gen(kbessel(nu.g, t0, prec_bits_to_words(precision))) 4653 4625 4654 4626 def besseln(gen nu, x, precision=0): 4655 4627 """ … … 4668 4640 sage: pari(2+i).besseln(3) 4669 4641 -0.280775566958244 - 0.486708533223726*I 4670 4642 """ 4671 t0GEN(x)4672 pari_catch_sig_on()4673 return P.new_gen(nbessel(nu.g, t0, p bw(precision)))4643 pari_catch_sig_on() 4644 cdef GEN t0 = P.toGEN(x) 4645 return P.new_gen(nbessel(nu.g, t0, prec_bits_to_words(precision))) 4674 4646 4675 4647 def cos(gen x, precision=0): 4676 4648 """ … … 4935 4907 sage: pari(1).hyperu(2,3) 4936 4908 0.333333333333333 4937 4909 """ 4938 t0GEN(b)4939 t1GEN(x)4940 pari_catch_sig_on()4941 return P.new_gen(hyperu(a.g, t0, t1, p bw(precision)))4910 pari_catch_sig_on() 4911 cdef GEN t0 = P.toGEN(b) 4912 cdef GEN t1 = P.toGEN(x) 4913 return P.new_gen(hyperu(a.g, t0, t1, prec_bits_to_words(precision))) 4942 4914 4943 4915 def incgam(gen s, x, y=None, precision=0): 4944 4916 r""" … … 4956 4928 sage: pari(1+i).incgam(3-i) 4957 4929 -0.0458297859919946 + 0.0433696818726677*I 4958 4930 """ 4959 t0GEN(x) 4960 pari_catch_sig_on() 4931 pari_catch_sig_on() 4932 cdef GEN t0 = P.toGEN(x) 4933 cdef GEN t1 4961 4934 if y is None: 4962 return P.new_gen(incgam(s.g, t0, p bw(precision)))4935 return P.new_gen(incgam(s.g, t0, prec_bits_to_words(precision))) 4963 4936 else: 4964 t1 GEN(y)4965 return P.new_gen(incgam0(s.g, t0, t1, p bw(precision)))4937 t1 = P.toGEN(y) 4938 return P.new_gen(incgam0(s.g, t0, t1, prec_bits_to_words(precision))) 4966 4939 4967 4940 def incgamc(gen s, x, precision=0): 4968 4941 r""" … … 4986 4959 sage: pari(1).incgamc(2) 4987 4960 0.864664716763387 4988 4961 """ 4989 t0GEN(x)4990 pari_catch_sig_on()4991 return P.new_gen(incgamc(s.g, t0, p bw(precision)))4962 pari_catch_sig_on() 4963 cdef GEN t0 = P.toGEN(x) 4964 return P.new_gen(incgamc(s.g, t0, prec_bits_to_words(precision))) 4992 4965 4993 4966 def log(gen x, precision=0): 4994 4967 r""" … … 5262 5235 2.00000000000000 + 9.21571846612679 E-19*I # 64-bit 5263 5236 """ 5264 5237 # TODO: ??? lots of good examples in the PARI docs ??? 5238 pari_catch_sig_on() 5265 5239 cdef GEN zetan 5266 t0GEN(n) 5267 pari_catch_sig_on() 5268 ans = P.new_gen_noclear(gsqrtn(x.g, t0, &zetan, pbw(precision))) 5240 cdef GEN t0 = P.toGEN(n) 5241 ans = P.new_gen_noclear(gsqrtn(x.g, t0, &zetan, prec_bits_to_words(precision))) 5269 5242 return ans, P.new_gen(zetan) 5270 5243 5271 5244 def tan(gen x, precision=0): … … 5343 5316 sage: pari(0.5).theta(2) 5344 5317 1.63202590295260 5345 5318 """ 5346 t0GEN(z)5347 pari_catch_sig_on()5348 return P.new_gen(theta(q.g, t0, p bw(precision)))5319 pari_catch_sig_on() 5320 cdef GEN t0 = P.toGEN(z) 5321 return P.new_gen(theta(q.g, t0, prec_bits_to_words(precision))) 5349 5322 5350 5323 def thetanullk(gen q, long k, precision=0): 5351 5324 """ … … 5443 5416 4*7^-2 + 5*7^-1 + O(7^0) 5444 5417 """ 5445 5418 pari_catch_sig_on() 5446 return P.new_gen(gzeta(s.g, p bw(precision)))5419 return P.new_gen(gzeta(s.g, prec_bits_to_words(precision))) 5447 5420 5448 5421 ########################################### 5449 5422 # 4: NUMBER THEORETICAL functions 5450 5423 ########################################### 5451 5424 5452 5425 def bezout(gen x, y): 5426 pari_catch_sig_on() 5453 5427 cdef gen u, v, g 5454 5428 cdef GEN U, V, G 5455 t0GEN(y) 5456 pari_catch_sig_on() 5429 cdef GEN t0 = P.toGEN(y) 5457 5430 G = gbezout(x.g, t0, &U, &V) 5458 5431 g = P.new_gen_noclear(G) 5459 5432 u = P.new_gen_noclear(U) … … 5492 5465 a bound for the number of terms in the continued fraction 5493 5466 expansion. 5494 5467 """ 5495 t0GEN(b)5496 pari_catch_sig_on()5468 pari_catch_sig_on() 5469 cdef GEN t0 = P.toGEN(b) 5497 5470 return P.new_gen(contfrac0(x.g, t0, lmax)) 5498 5471 5499 5472 def contfracpnqn(gen x, b=0, long lmax=0): … … 5578 5551 (x and y must be polynomials), 2 use the subresultant algorithm (x 5579 5552 and y must be polynomials) 5580 5553 """ 5581 t0GEN(y)5582 pari_catch_sig_on()5554 pari_catch_sig_on() 5555 cdef GEN t0 = P.toGEN(y) 5583 5556 return P.new_gen(ggcd0(x.g, t0)) 5584 5557 5585 5558 def issquare(gen x, find_root=False): … … 5624 5597 sage: pari(10).lcm(15) 5625 5598 30 5626 5599 """ 5627 t0GEN(y)5628 pari_catch_sig_on()5600 pari_catch_sig_on() 5601 cdef GEN t0 = P.toGEN(y) 5629 5602 return P.new_gen(glcm(x.g, t0)) 5630 5603 5631 5604 def numdiv(gen n): … … 5859 5832 sage: e.elladd([1,0], [-1,1]) 5860 5833 [-3/4, -15/8] 5861 5834 """ 5862 t0GEN(z0); t1GEN(z1) 5863 pari_catch_sig_on() 5864 return self.new_gen(addell(self.g, t0, t1)) 5835 pari_catch_sig_on() 5836 cdef GEN t0 = P.toGEN(z0) 5837 cdef GEN t1 = P.toGEN(z1) 5838 return P.new_gen(addell(self.g, t0, t1)) 5865 5839 5866 5840 def ellak(self, n): 5867 5841 r""" … … 5897 5871 sage: e.ellak(0) 5898 5872 0 5899 5873 """ 5900 t0GEN(n)5901 pari_catch_sig_on()5902 return self.new_gen(akell(self.g, t0))5874 pari_catch_sig_on() 5875 cdef GEN t0 = P.toGEN(n) 5876 return P.new_gen(akell(self.g, t0)) 5903 5877 5904 5878 5905 5879 def ellan(self, long n, python_ints=False): … … 5992 5966 sage: e.ellak(-1) 5993 5967 0 5994 5968 """ 5995 t0GEN(p)5996 pari_catch_sig_on()5997 return self.new_gen(ellap(self.g, t0))5969 pari_catch_sig_on() 5970 cdef GEN t0 = P.toGEN(p) 5971 return P.new_gen(ellap(self.g, t0)) 5998 5972 5999 5973 6000 5974 def ellaplist(self, long n, python_ints=False): … … 6049 6023 # 1. make a table of primes up to n. 6050 6024 pari_catch_sig_on() 6051 6025 if n < 2: 6052 return self.new_gen(zerovec(0))6026 return P.new_gen(zerovec(0)) 6053 6027 cdef GEN g 6054 pari.init_primes(n+1)6055 t0GEN(n)6028 P.init_primes(n+1) 6029 cdef GEN t0 = P.toGEN(n) 6056 6030 g = primes(gtolong(primepi(t0))) 6057 6031 6058 6032 # 2. Replace each prime in the table by ellap of it. … … 6089 6063 sage: e.ellbil([1, 0], [-1, 1]) 6090 6064 0.418188984498861 6091 6065 """ 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))6066 pari_catch_sig_on() 6067 cdef GEN t0 = P.toGEN(z0) 6068 cdef GEN t1 = P.toGEN(z1) 6069 return P.new_gen(bilhell(self.g, t0, t1, prec)) 6096 6070 6097 6071 def ellchangecurve(self, ch): 6098 6072 """ … … 6121 6095 sage: f[:5] 6122 6096 [1, -1, 0, 4, 3] 6123 6097 """ 6124 t0GEN(ch)6125 pari_catch_sig_on()6126 return self.new_gen(ellchangecurve(self.g, t0))6098 pari_catch_sig_on() 6099 cdef GEN t0 = P.toGEN(ch) 6100 return P.new_gen(ellchangecurve(self.g, t0)) 6127 6101 6128 6102 def elleta(self): 6129 6103 """ … … 6190 6164 sage: e.ellheight([1,0], flag=1) 6191 6165 0.476711659343740 6192 6166 """ 6193 t0GEN(a)6194 pari_catch_sig_on()6195 return self.new_gen(ellheight0(self.g, t0, flag, pbw(precision)))6167 pari_catch_sig_on() 6168 cdef GEN t0 = P.toGEN(a) 6169 return P.new_gen(ellheight0(self.g, t0, flag, prec_bits_to_words(precision))) 6196 6170 6197 6171 def ellheightmatrix(self, x): 6198 6172 """ … … 6218 6192 sage: e.ellheightmatrix([[1,0], [-1,1]]) 6219 6193 [0.476711659343740, 0.418188984498861; 0.418188984498861, 0.686667083305587] 6220 6194 """ 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)) 6195 pari_catch_sig_on() 6196 cdef GEN t0 = P.toGEN(x) 6197 return P.new_gen(mathell(self.g, t0, prec)) 6225 6198 6226 6199 def ellisoncurve(self, x): 6227 6200 """ … … 6245 6218 sage: e.ellisoncurve([0]) 6246 6219 True 6247 6220 """ 6248 t0GEN(x)6249 pari_catch_sig_on()6221 pari_catch_sig_on() 6222 cdef GEN t0 = P.toGEN(x) 6250 6223 t = bool(oncurve(self.g, t0) == 1) 6251 pari_catch_sig_off()6224 P.clear_stack() 6252 6225 return t 6253 6226 6254 6227 def elllocalred(self, p): … … 6402 6375 sage: e.elllocalred(3) 6403 6376 [2, -10, [1, 96, 1, 316], 4] 6404 6377 """ 6405 t0GEN(p)6406 pari_catch_sig_on()6407 return self.new_gen(elllocalred(self.g, t0))6378 pari_catch_sig_on() 6379 cdef GEN t0 = P.toGEN(p) 6380 return P.new_gen(elllocalred(self.g, t0)) 6408 6381 6409 6382 def elllseries(self, s, A=1): 6410 6383 """ … … 6444 6417 sage: e.elllseries(2.1, A=1.1) 6445 6418 0.402838047956645 6446 6419 """ 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))6420 pari_catch_sig_on() 6421 cdef GEN t0 = P.toGEN(s) 6422 cdef GEN t1 = P.toGEN(A) 6423 return P.new_gen(elllseries(self.g, t0, t1, prec)) 6451 6424 6452 6425 def ellminimalmodel(self): 6453 6426 """ … … 6514 6487 sage: e.ellorder([1,0]) 6515 6488 0 6516 6489 """ 6517 t0GEN(x)6518 pari_catch_sig_on()6519 return self.new_gen(orderell(self.g, t0))6490 pari_catch_sig_on() 6491 cdef GEN t0 = P.toGEN(x) 6492 return P.new_gen(orderell(self.g, t0)) 6520 6493 6521 6494 def ellordinate(self, x): 6522 6495 """ … … 6545 6518 sage: e.ellordinate('z+2*z^2+O(z^4)') 6546 6519 [-2*z - 7*z^2 - 23*z^3 + O(z^4), -1 + 2*z + 7*z^2 + 23*z^3 + O(z^4)] 6547 6520 """ 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 6521 pari_catch_sig_on() 6522 cdef GEN t0 = P.toGEN(x) 6523 return P.new_gen(ellordinate(self.g, t0, prec)) 6524 6525 def ellpointtoz(self, pt, long precision=0): 6526 """ 6527 e.ellpointtoz(pt): return the complex number (in the fundamental 6528 parallelogram) corresponding to the point ``pt`` on the elliptic curve 6557 6529 e, under the complex uniformization of e given by the Weierstrass 6558 6530 p-function. 6559 6531 … … 6572 6544 sage: e.ellpointtoz([0]) 6573 6545 0 6574 6546 """ 6575 t0GEN(P)6576 pari_catch_sig_on()6577 return self.new_gen(zell(self.g, t0, pbw(precision)))6547 pari_catch_sig_on() 6548 cdef GEN t0 = P.toGEN(pt) 6549 return P.new_gen(zell(self.g, t0, prec_bits_to_words(precision))) 6578 6550 6579 6551 def ellpow(self, z, n): 6580 6552 """ … … 6634 6606 ....: P0 = e.elladd(e.ellpow(P, cm_minpoly[0]), e.ellpow(P2, cm)) 6635 6607 ....: assert(P0 == E(0)) 6636 6608 """ 6637 t0GEN(z); t1GEN(n) 6638 pari_catch_sig_on() 6639 return self.new_gen(powell(self.g, t0, t1)) 6609 pari_catch_sig_on() 6610 cdef GEN t0 = P.toGEN(z) 6611 cdef GEN t1 = P.toGEN(n) 6612 return P.new_gen(powell(self.g, t0, t1)) 6640 6613 6641 6614 def ellrootno(self, p=1): 6642 6615 """ … … 6669 6642 sage: e.ellrootno(1009) 6670 6643 1 6671 6644 """ 6672 cdef long rootno 6673 t0GEN(p) 6674 pari_catch_sig_on() 6645 pari_catch_sig_on() 6646 cdef GEN t0 = P.toGEN(p) 6675 6647 rootno = ellrootno(self.g, t0) 6676 pari_catch_sig_off()6648 P.clear_stack() 6677 6649 return rootno 6678 6650 6679 6651 def ellsigma(self, z, flag=0): … … 6689 6661 sage: e.ellsigma(2+i) 6690 6662 1.43490215804166 + 1.80307856719256*I 6691 6663 """ 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)) 6664 pari_catch_sig_on() 6665 cdef GEN t0 = P.toGEN(z) 6666 return P.new_gen(ellsigma(self.g, t0, flag, prec)) 6696 6667 6697 6668 def ellsub(self, z0, z1): 6698 6669 """ … … 6716 6687 sage: e.ellsub([1,0], [-1,1]) 6717 6688 [0, 0] 6718 6689 """ 6719 t0GEN(z0); t1GEN(z1) 6720 pari_catch_sig_on() 6721 return self.new_gen(subell(self.g, t0, t1)) 6690 pari_catch_sig_on() 6691 cdef GEN t0 = P.toGEN(z0) 6692 cdef GEN t1 = P.toGEN(z1) 6693 return P.new_gen(subell(self.g, t0, t1)) 6722 6694 6723 6695 def elltaniyama(self): 6724 6696 pari_catch_sig_on() 6725 return self.new_gen(taniyama(self.g))6697 return P.new_gen(taniyama(self.g)) 6726 6698 6727 6699 def elltors(self, flag=0): 6728 6700 """ … … 6799 6771 sage: e.ellzeta(i-1) 6800 6772 -0.350122658523049 - 0.350122658523049*I 6801 6773 """ 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)) 6774 pari_catch_sig_on() 6775 cdef GEN t0 = P.toGEN(z) 6776 return P.new_gen(ellzeta(self.g, t0, prec)) 6806 6777 6807 6778 def ellztopoint(self, z): 6808 6779 """ … … 6834 6805 sage: e.ellztopoint(0) 6835 6806 [0] 6836 6807 """ 6837 t0GEN(z) 6808 pari_catch_sig_on() 6809 cdef GEN t0 = P.toGEN(z) 6838 6810 try: 6839 6811 dprec = prec_words_to_dec(z.precision()) 6840 6812 except AttributeError: 6841 6813 dprec = prec 6842 pari_catch_sig_on() 6843 # the prec argument has no effect 6844 return self.new_gen(pointell(self.g, t0, dprec)) 6814 return P.new_gen(pointell(self.g, t0, dprec)) 6845 6815 6846 6816 def omega(self): 6847 6817 """ … … 6912 6882 .. [PariUsers] User's Guide to PARI/GP, 6913 6883 http://pari.math.u-bordeaux.fr/pub/pari/manuals/2.5.1/users.pdf 6914 6884 """ 6915 cdef long n6916 6885 pari_catch_sig_on() 6917 6886 n = bnfcertify(self.g) 6918 6887 pari_catch_sig_off() 6919 6888 return n 6920 6889 6921 6890 def bnfinit(self, long flag=0, tech=None): 6891 cdef GEN t0 6892 pari_catch_sig_on() 6922 6893 if tech is None: 6923 pari_catch_sig_on() 6924 return P.new_gen(bnfinit0(self.g, flag, <GEN>0, prec)) 6894 t0 = NULL 6925 6895 else: 6926 t0GEN(tech) 6927 pari_catch_sig_on() 6928 return P.new_gen(bnfinit0(self.g, flag, t0, prec)) 6896 t0 = P.toGEN(tech) 6897 return P.new_gen(bnfinit0(self.g, flag, t0, prec)) 6929 6898 6930 6899 def bnfisintnorm(self, x): 6931 t0GEN(x)6932 pari_catch_sig_on()6933 return self.new_gen(bnfisintnorm(self.g, t0))6900 pari_catch_sig_on() 6901 cdef GEN t0 = P.toGEN(x) 6902 return P.new_gen(bnfisintnorm(self.g, t0)) 6934 6903 6935 6904 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))6905 pari_catch_sig_on() 6906 cdef GEN t0 = P.toGEN(x) 6907 return P.new_gen(bnfisnorm(self.g, t0, flag)) 6939 6908 6940 6909 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))6910 pari_catch_sig_on() 6911 cdef GEN t0 = P.toGEN(x) 6912 return P.new_gen(bnfisprincipal0(self.g, t0, flag)) 6944 6913 6945 6914 def bnfnarrow(self): 6946 6915 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)))6916 return P.new_gen(buchnarrow(self.g)) 6917 6918 def bnfsunit(self, S, long precision=0): 6919 pari_catch_sig_on() 6920 cdef GEN t0 = P.toGEN(S) 6921 return P.new_gen(bnfsunit(self.g, t0, prec_bits_to_words(precision))) 6953 6922 6954 6923 def bnfunit(self): 6955 6924 pari_catch_sig_on() 6956 return self.new_gen(bnf_get_fu(self.g))6925 return P.new_gen(bnf_get_fu(self.g)) 6957 6926 6958 6927 def bnfisunit(self, x): 6959 t0GEN(x)6960 pari_catch_sig_on()6961 return self.new_gen(bnfisunit(self.g, t0))6928 pari_catch_sig_on() 6929 cdef GEN t0 = P.toGEN(x) 6930 return P.new_gen(bnfisunit(self.g, t0)) 6962 6931 6963 6932 def bnrclassno(self, I): 6964 6933 r""" … … 6978 6947 sage: K.pari_bnf().bnrclassno(p._pari_bid_()) 6979 6948 3 6980 6949 """ 6981 t0GEN(I)6982 pari_catch_sig_on()6983 return self.new_gen(bnrclassno(self.g, t0))6950 pari_catch_sig_on() 6951 cdef GEN t0 = P.toGEN(I) 6952 return P.new_gen(bnrclassno(self.g, t0)) 6984 6953 6985 6954 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))6955 pari_catch_sig_on() 6956 cdef GEN t0 = P.toGEN(x) 6957 cdef GEN t1 = P.toGEN(sunit_data) 6958 return P.new_gen(bnfissunit(self.g, t1, t0)) 6990 6959 6991 6960 def dirzetak(self, n): 6992 t0GEN(n)6993 pari_catch_sig_on()6994 return self.new_gen(dirzetak(self.g, t0))6961 pari_catch_sig_on() 6962 cdef GEN t0 = P.toGEN(n) 6963 return P.new_gen(dirzetak(self.g, t0)) 6995 6964 6996 6965 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))6966 pari_catch_sig_on() 6967 cdef GEN t0 = P.toGEN(aut) 6968 cdef GEN t1 = P.toGEN(x) 6969 return P.new_gen(galoisapply(self.g, t0, t1)) 7001 6970 7002 6971 def galoisinit(self, den=None): 7003 6972 """ 7004 6973 galoisinit(K{,den}): calculate Galois group of number field K; see PARI manual 7005 6974 for meaning of den 7006 6975 """ 6976 cdef GEN t0 6977 pari_catch_sig_on() 7007 6978 if den is None: 7008 pari_catch_sig_on() 7009 return self.new_gen(galoisinit(self.g, NULL)) 6979 t0 = NULL 7010 6980 else: 7011 t0GEN(den) 7012 pari_catch_sig_on() 7013 return self.new_gen(galoisinit(self.g, t0)) 6981 t0 = P.toGEN(den) 6982 return P.new_gen(galoisinit(self.g, t0)) 7014 6983 7015 6984 def galoispermtopol(self, perm): 7016 t0GEN(perm)7017 pari_catch_sig_on()7018 return self.new_gen(galoispermtopol(self.g, t0))6985 pari_catch_sig_on() 6986 cdef GEN t0 = P.toGEN(perm) 6987 return P.new_gen(galoispermtopol(self.g, t0)) 7019 6988 7020 6989 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)))6990 pari_catch_sig_on() 6991 cdef GEN t0 = P.toGEN(perm) 6992 return P.new_gen(galoisfixedfield(self.g, t0, flag, P.get_var(v))) 7024 6993 7025 6994 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)) 6995 pari_catch_sig_on() 6996 cdef GEN t0 = P.toGEN(I) 6997 cdef GEN t1 = P.toGEN(vdir) 6998 return P.new_gen(idealred0(self.g, t0, t1 if vdir else NULL)) 7029 6999 7030 7000 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)) 7001 pari_catch_sig_on() 7002 cdef GEN t0 = P.toGEN(x) 7003 cdef GEN t1 = P.toGEN(y) 7004 return P.new_gen(idealadd(self.g, t0, t1)) 7034 7005 7035 7006 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)) 7007 pari_catch_sig_on() 7008 cdef GEN t0 = P.toGEN(x) 7009 cdef GEN t1 = P.toGEN(y) 7010 return P.new_gen(idealaddtoone0(self.g, t0, t1)) 7039 7011 7040 7012 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))7013 pari_catch_sig_on() 7014 cdef GEN t0 = P.toGEN(x) 7015 return P.new_gen(idealappr0(self.g, t0, flag)) 7044 7016 7045 7017 def idealcoprime(self, x, y): 7046 7018 """ … … 7062 7034 sage: nf.idealcoprime(x, y) 7063 7035 [5/43, 9/43, -1/43]~ 7064 7036 """ 7065 t0GEN(x); t1GEN(y) 7066 pari_catch_sig_on() 7067 return self.new_gen(idealcoprime(self.g, t0, t1)) 7037 pari_catch_sig_on() 7038 cdef GEN t0 = P.toGEN(x) 7039 cdef GEN t1 = P.toGEN(y) 7040 return P.new_gen(idealcoprime(self.g, t0, t1)) 7068 7041 7069 7042 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)) 7043 pari_catch_sig_on() 7044 cdef GEN t0 = P.toGEN(x) 7045 cdef GEN t1 = P.toGEN(y) 7046 return P.new_gen(idealdiv0(self.g, t0, t1, flag)) 7073 7047 7074 7048 def idealfactor(self, x): 7075 t0GEN(x)7076 pari_catch_sig_on()7077 return self.new_gen(idealfactor(self.g, t0))7049 pari_catch_sig_on() 7050 cdef GEN t0 = P.toGEN(x) 7051 return P.new_gen(idealfactor(self.g, t0)) 7078 7052 7079 7053 def idealhnf(self, a, b=None): 7080 t0GEN(a) 7054 pari_catch_sig_on() 7055 cdef GEN t0 = P.toGEN(a) 7056 cdef GEN t1 7081 7057 if b is None: 7082 pari_catch_sig_on() 7083 return self.new_gen(idealhnf(self.g, t0)) 7058 return P.new_gen(idealhnf(self.g, t0)) 7084 7059 else: 7085 t1GEN(b) 7086 pari_catch_sig_on() 7087 return self.new_gen(idealhnf0(self.g, t0, t1)) 7060 t1 = P.toGEN(b) 7061 return P.new_gen(idealhnf0(self.g, t0, t1)) 7088 7062 7089 7063 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)) 7064 pari_catch_sig_on() 7065 cdef GEN t0 = P.toGEN(x) 7066 cdef GEN t1 = P.toGEN(y) 7067 return P.new_gen(idealintersect(self.g, t0, t1)) 7093 7068 7094 7069 def ideallist(self, long bound, long flag = 4): 7095 7070 """ … … 7146 7121 sage: nf.ideallog(x, bid) 7147 7122 [25]~ 7148 7123 """ 7149 t0GEN(x); t1GEN(bid) 7150 pari_catch_sig_on() 7151 return self.new_gen(ideallog(self.g, t0, t1)) 7124 pari_catch_sig_on() 7125 cdef GEN t0 = P.toGEN(x) 7126 cdef GEN t1 = P.toGEN(bid) 7127 return P.new_gen(ideallog(self.g, t0, t1)) 7152 7128 7153 7129 def idealmul(self, x, y, long flag=0): 7154 t0GEN(x); t1GEN(y) 7155 pari_catch_sig_on() 7130 pari_catch_sig_on() 7131 cdef GEN t0 = P.toGEN(x) 7132 cdef GEN t1 = P.toGEN(y) 7156 7133 if flag == 0: 7157 return self.new_gen(idealmul(self.g, t0, t1))7134 return P.new_gen(idealmul(self.g, t0, t1)) 7158 7135 else: 7159 return self.new_gen(idealmulred(self.g, t0, t1))7136 return P.new_gen(idealmulred(self.g, t0, t1)) 7160 7137 7161 7138 def idealnorm(self, x): 7162 t0GEN(x)7163 pari_catch_sig_on()7164 return self.new_gen(idealnorm(self.g, t0))7139 pari_catch_sig_on() 7140 cdef GEN t0 = P.toGEN(x) 7141 return P.new_gen(idealnorm(self.g, t0)) 7165 7142 7166 7143 def idealprimedec(nf, p): 7167 7144 """ … … 7179 7156 sage: F[0].pr_get_p() 7180 7157 5 7181 7158 """ 7182 t0GEN(p)7183 pari_catch_sig_on()7184 return nf.new_gen(idealprimedec(nf.g, t0))7159 pari_catch_sig_on() 7160 cdef GEN t0 = P.toGEN(p) 7161 return P.new_gen(idealprimedec(nf.g, t0)) 7185 7162 7186 7163 def idealstar(self, I, long flag=1): 7187 7164 """ … … 7219 7196 sage: nf.idealstar(I) 7220 7197 [[[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 7198 """ 7222 t0GEN(I)7223 pari_catch_sig_on()7224 return self.new_gen(idealstar0(self.g, t0, flag))7199 pari_catch_sig_on() 7200 cdef GEN t0 = P.toGEN(I) 7201 return P.new_gen(idealstar0(self.g, t0, flag)) 7225 7202 7226 7203 def idealtwoelt(self, x, a=None): 7227 t0GEN(x) 7204 pari_catch_sig_on() 7205 cdef GEN t0 = P.toGEN(x) 7206 cdef GEN t1 7228 7207 if a is None: 7229 pari_catch_sig_on() 7230 return self.new_gen(idealtwoelt0(self.g, t0, NULL)) 7208 return P.new_gen(idealtwoelt0(self.g, t0, NULL)) 7231 7209 else: 7232 t1GEN(a) 7233 pari_catch_sig_on() 7234 return self.new_gen(idealtwoelt0(self.g, t0, t1)) 7210 t1 = P.toGEN(a) 7211 return P.new_gen(idealtwoelt0(self.g, t0, t1)) 7235 7212 7236 7213 def idealval(self, x, p): 7237 cdef long v7238 t0GEN(x); t1GEN(p)7239 pari_catch_sig_on()7214 pari_catch_sig_on() 7215 cdef GEN t0 = P.toGEN(x) 7216 cdef GEN t1 = P.toGEN(p) 7240 7217 v = idealval(self.g, t0, t1) 7241 pari_catch_sig_off()7218 P.clear_stack() 7242 7219 return v 7243 7220 7244 7221 def elementval(self, x, p): 7245 cdef long v7246 t0GEN(x); t1GEN(p)7247 pari_catch_sig_on()7222 pari_catch_sig_on() 7223 cdef GEN t0 = P.toGEN(x) 7224 cdef GEN t1 = P.toGEN(p) 7248 7225 v = nfval(self.g, t0, t1) 7249 pari_catch_sig_off()7226 P.clear_stack() 7250 7227 return v 7251 7228 7252 7229 def modreverse(self): … … 7298 7275 sage: pari('x^3 - 17').nfbasis(flag = 2) 7299 7276 [1, x, 1/3*x^2 - 1/3*x + 1/3] 7300 7277 """ 7301 global t07302 t0GEN(fa)7278 pari_catch_sig_on() 7279 cdef GEN t0 = P.toGEN(fa) 7303 7280 if typ(t0) != t_MAT: 7304 t0 = <GEN>0 7305 pari_catch_sig_on() 7306 return self.new_gen(nfbasis0(self.g, flag, t0)) 7281 t0 = NULL 7282 return P.new_gen(nfbasis0(self.g, flag, t0)) 7307 7283 7308 7284 def nfbasis_d(self, long flag=0, fa=0): 7309 7285 """ … … 7327 7303 sage: pari([-2,0,0,1]).Polrev().nfbasis_d() 7328 7304 ([1, x, x^2], -108) 7329 7305 """ 7330 global t07306 pari_catch_sig_on() 7331 7307 cdef GEN disc 7332 t0GEN(fa)7308 cdef GEN t0 = P.toGEN(fa) 7333 7309 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); 7310 t0 = NULL 7311 B = P.new_gen_noclear(nfbasis(self.g, &disc, flag, t0)) 7312 D = P.new_gen(disc); 7338 7313 return B,D 7339 7314 7340 7315 def nfbasistoalg(nf, x): … … 7367 7342 sage: Kpari.getattr('zk') * pari("[3/2, -5, 0]~") 7368 7343 -5/3*y^2 + 5/3*y - 1/6 7369 7344 """ 7370 t0GEN(x)7371 pari_catch_sig_on()7372 return nf.new_gen(basistoalg(nf.g, t0))7345 pari_catch_sig_on() 7346 cdef GEN t0 = P.toGEN(x) 7347 return P.new_gen(basistoalg(nf.g, t0)) 7373 7348 7374 7349 def nfbasistoalg_lift(nf, x): 7375 7350 r""" … … 7400 7375 sage: Kpari.getattr('zk') * pari("[3/2, -5, 0]~") 7401 7376 -5/3*y^2 + 5/3*y - 1/6 7402 7377 """ 7403 t0GEN(x)7404 pari_catch_sig_on()7405 return nf.new_gen(gel(basistoalg(nf.g, t0), 2))7378 pari_catch_sig_on() 7379 cdef GEN t0 = P.toGEN(x) 7380 return P.new_gen(gel(basistoalg(nf.g, t0), 2)) 7406 7381 7407 7382 def nfdisc(self, long flag=0, p=0): 7408 7383 """ … … 7452 7427 sage: pari(k).nfeltdiveuc(pari(x), pari(y)) 7453 7428 [2, -2]~ 7454 7429 """ 7455 t0GEN(x); t1GEN(y) 7456 pari_catch_sig_on() 7457 return self.new_gen(nfdiveuc(self.g, t0, t1)) 7430 pari_catch_sig_on() 7431 cdef GEN t0 = P.toGEN(x) 7432 cdef GEN t1 = P.toGEN(y) 7433 return P.new_gen(nfdiveuc(self.g, t0, t1)) 7458 7434 7459 7435 def nfeltreduce(self, x, I): 7460 7436 """ … … 7472 7448 sage: 12 - k(kp.nfeltreduce(12, I.pari_hnf())) in I 7473 7449 True 7474 7450 """ 7475 t0GEN(x); t1GEN(I) 7476 pari_catch_sig_on() 7477 return self.new_gen(nfreduce(self.g, t0, t1)) 7451 pari_catch_sig_on() 7452 cdef GEN t0 = P.toGEN(x) 7453 cdef GEN t1 = P.toGEN(I) 7454 return P.new_gen(nfreduce(self.g, t0, t1)) 7478 7455 7479 7456 def nffactor(self, x): 7480 t0GEN(x)7481 pari_catch_sig_on()7482 return self.new_gen(nffactor(self.g, t0))7457 pari_catch_sig_on() 7458 cdef GEN t0 = P.toGEN(x) 7459 return P.new_gen(nffactor(self.g, t0)) 7483 7460 7484 7461 def nfgenerator(self): 7485 7462 f = self[0] … … 7508 7485 sage: pari(K).nfhilbert(pari(t), pari(t+2), P.pari_prime()) 7509 7486 1 7510 7487 """ 7511 cdef long r 7512 t0GEN(a) 7513 t1GEN(b) 7488 pari_catch_sig_on() 7489 cdef GEN t0 = P.toGEN(a) 7490 cdef GEN t1 = P.toGEN(b) 7491 cdef GEN t2 7514 7492 if p: 7515 t2GEN(p) 7516 pari_catch_sig_on() 7493 t2 = P.toGEN(p) 7517 7494 r = nfhilbert0(self.g, t0, t1, t2) 7518 7495 else: 7519 pari_catch_sig_on()7520 7496 r = nfhilbert(self.g, t0, t1) 7521 7497 P.clear_stack() 7522 7498 return r … … 7584 7560 7585 7561 - Aly Deines (2012-09-19) 7586 7562 """ 7587 t0GEN(x) 7588 pari_catch_sig_on() 7589 return self.new_gen(nfhnf(self.g,t0)) 7590 7591 7563 pari_catch_sig_on() 7564 cdef GEN t0 = P.toGEN(x) 7565 return P.new_gen(nfhnf(self.g, t0)) 7592 7566 7593 7567 7594 7568 def nfinit(self, long flag=0, long precision=0): … … 7715 7689 - ``d`` - C long integer 7716 7690 """ 7717 7691 pari_catch_sig_on() 7718 return self.new_gen(nfsubfields(self.g, d))7692 return P.new_gen(nfsubfields(self.g, d)) 7719 7693 7720 7694 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))) 7695 pari_catch_sig_on() 7696 cdef GEN t0 = P.toGEN(T) 7697 cdef GEN t1 = P.toGEN(a) 7698 cdef GEN t2 = P.toGEN(v) 7699 return P.new_gen(rnfcharpoly(self.g, t0, t1, gvar(t2))) 7724 7700 7725 7701 def rnfdisc(self, x): 7726 t0GEN(x)7727 pari_catch_sig_on()7728 return self.new_gen(rnfdiscf(self.g, t0))7702 pari_catch_sig_on() 7703 cdef GEN t0 = P.toGEN(x) 7704 return P.new_gen(rnfdiscf(self.g, t0)) 7729 7705 7730 7706 def rnfeltabstorel(self, x): 7731 t0GEN(x)7732 pari_catch_sig_on()7733 return self.new_gen(rnfelementabstorel(self.g, t0))7707 pari_catch_sig_on() 7708 cdef GEN t0 = P.toGEN(x) 7709 return P.new_gen(rnfelementabstorel(self.g, t0)) 7734 7710 7735 7711 def rnfeltreltoabs(self, x): 7736 t0GEN(x)7737 pari_catch_sig_on()7738 return self.new_gen(rnfelementreltoabs(self.g, t0))7712 pari_catch_sig_on() 7713 cdef GEN t0 = P.toGEN(x) 7714 return P.new_gen(rnfelementreltoabs(self.g, t0)) 7739 7715 7740 7716 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))7717 pari_catch_sig_on() 7718 cdef GEN t0 = P.toGEN(poly) 7719 return P.new_gen(rnfequation0(self.g, t0, flag)) 7744 7720 7745 7721 def rnfidealabstorel(self, x): 7746 t0GEN(x)7747 pari_catch_sig_on()7748 return self.new_gen(rnfidealabstorel(self.g, t0))7722 pari_catch_sig_on() 7723 cdef GEN t0 = P.toGEN(x) 7724 return P.new_gen(rnfidealabstorel(self.g, t0)) 7749 7725 7750 7726 def rnfidealdown(self, x): 7751 7727 r""" … … 7768 7744 sage: rnf.rnfidealdown(P) 7769 7745 [2, 0; 0, 2] 7770 7746 """ 7771 t0GEN(x)7772 pari_catch_sig_on()7773 return self.new_gen(rnfidealdown(self.g, t0))7747 pari_catch_sig_on() 7748 cdef GEN t0 = P.toGEN(x) 7749 return P.new_gen(rnfidealdown(self.g, t0)) 7774 7750 7775 7751 def rnfidealhnf(self, x): 7776 t0GEN(x)7777 pari_catch_sig_on()7778 return self.new_gen(rnfidealhermite(self.g, t0))7752 pari_catch_sig_on() 7753 cdef GEN t0 = P.toGEN(x) 7754 return P.new_gen(rnfidealhermite(self.g, t0)) 7779 7755 7780 7756 def rnfidealnormrel(self, x): 7781 t0GEN(x)7782 pari_catch_sig_on()7783 return self.new_gen(rnfidealnormrel(self.g, t0))7757 pari_catch_sig_on() 7758 cdef GEN t0 = P.toGEN(x) 7759 return P.new_gen(rnfidealnormrel(self.g, t0)) 7784 7760 7785 7761 def rnfidealreltoabs(self, x): 7786 t0GEN(x)7787 pari_catch_sig_on()7788 return self.new_gen(rnfidealreltoabs(self.g, t0))7762 pari_catch_sig_on() 7763 cdef GEN t0 = P.toGEN(x) 7764 return P.new_gen(rnfidealreltoabs(self.g, t0)) 7789 7765 7790 7766 def rnfidealtwoelt(self, x): 7791 t0GEN(x)7792 pari_catch_sig_on()7793 return self.new_gen(rnfidealtwoelement(self.g, t0))7767 pari_catch_sig_on() 7768 cdef GEN t0 = P.toGEN(x) 7769 return P.new_gen(rnfidealtwoelement(self.g, t0)) 7794 7770 7795 7771 def rnfinit(self, poly): 7796 7772 """ … … 7804 7780 sage: g = x^5 - x^2 + y 7805 7781 sage: L = K.rnfinit(g) 7806 7782 """ 7807 t0GEN(poly)7808 pari_catch_sig_on()7783 pari_catch_sig_on() 7784 cdef GEN t0 = P.toGEN(poly) 7809 7785 return P.new_gen(rnfinit(self.g, t0)) 7810 7786 7811 7787 def rnfisfree(self, poly): 7812 t0GEN(poly)7813 pari_catch_sig_on()7788 pari_catch_sig_on() 7789 cdef GEN t0 = P.toGEN(poly) 7814 7790 r = rnfisfree(self.g, t0) 7815 pari_catch_sig_off()7791 P.clear_stack() 7816 7792 return r 7817 7793 7818 7794 def quadhilbert(self): … … 7861 7837 2/15 7862 7838 """ 7863 7839 pari_catch_sig_on() 7864 return self.new_gen(content(self.g))7840 return P.new_gen(content(self.g)) 7865 7841 7866 7842 def deriv(self, v=-1): 7867 7843 pari_catch_sig_on() 7868 return self.new_gen(deriv(self.g, self.get_var(v)))7844 return P.new_gen(deriv(self.g, P.get_var(v))) 7869 7845 7870 7846 def eval(self, x): 7871 t0GEN(x)7872 pari_catch_sig_on()7873 return self.new_gen(poleval(self.g, t0))7847 pari_catch_sig_on() 7848 cdef GEN t0 = P.toGEN(x) 7849 return P.new_gen(poleval(self.g, t0)) 7874 7850 7875 7851 def __call__(self, x): 7876 7852 return self.eval(x) … … 7889 7865 sage: pari(x^2 - 2).factornf(K.pari_polynomial("a")) 7890 7866 [x + Mod(-4*a, 8*a^2 - 1), 1; x + Mod(4*a, 8*a^2 - 1), 1] 7891 7867 """ 7892 t0GEN(t)7893 pari_catch_sig_on()7894 return self.new_gen(polfnf(self.g, t0))7868 pari_catch_sig_on() 7869 cdef GEN t0 = P.toGEN(t) 7870 return P.new_gen(polfnf(self.g, t0)) 7895 7871 7896 7872 def factorpadic(self, p, long r=20, long flag=0): 7897 7873 """ … … 7899 7875 polynomial x to precision r. flag is optional and may be set to 0 7900 7876 (use round 4) or 1 (use Buchmann-Lenstra) 7901 7877 """ 7902 t0GEN(p)7903 pari_catch_sig_on()7904 return self.new_gen(factorpadic0(self.g, t0, r, flag))7878 pari_catch_sig_on() 7879 cdef GEN t0 = P.toGEN(p) 7880 return P.new_gen(factorpadic0(self.g, t0, r, flag)) 7905 7881 7906 7882 def factormod(self, p, long flag=0): 7907 7883 """ … … 7910 7886 simple factormod, same except that only the degrees of the 7911 7887 irreducible factors are given. 7912 7888 """ 7913 t0GEN(p)7914 pari_catch_sig_on()7915 return self.new_gen(factormod0(self.g, t0, flag))7889 pari_catch_sig_on() 7890 cdef GEN t0 = P.toGEN(p) 7891 return P.new_gen(factormod0(self.g, t0, flag)) 7916 7892 7917 7893 def intformal(self, y=-1): 7918 7894 """ … … 7920 7896 variable of y, or to the main variable of x if y is omitted 7921 7897 """ 7922 7898 pari_catch_sig_on() 7923 return self.new_gen(integ(self.g, self.get_var(y)))7899 return P.new_gen(integ(self.g, P.get_var(y))) 7924 7900 7925 7901 def padicappr(self, a): 7926 7902 """ 7927 7903 x.padicappr(a): p-adic roots of the polynomial x congruent to a mod 7928 7904 p 7929 7905 """ 7930 t0GEN(a)7931 pari_catch_sig_on()7932 return self.new_gen(padicappr(self.g, t0))7906 pari_catch_sig_on() 7907 cdef GEN t0 = P.toGEN(a) 7908 return P.new_gen(padicappr(self.g, t0)) 7933 7909 7934 7910 def newtonpoly(self, p): 7935 7911 """ … … 7942 7918 sage: x.newtonpoly(3) 7943 7919 [1, 1, -1/3, -1/3, -1/3, -1/3, -1/3, -1/3] 7944 7920 """ 7945 t0GEN(p)7946 pari_catch_sig_on()7947 return self.new_gen(newtonpoly(self.g, t0))7921 pari_catch_sig_on() 7922 cdef GEN t0 = P.toGEN(p) 7923 return P.new_gen(newtonpoly(self.g, t0)) 7948 7924 7949 7925 def polcoeff(self, long n, var=-1): 7950 7926 """ … … 7963 7939 x 7964 7940 """ 7965 7941 pari_catch_sig_on() 7966 return self.new_gen(polcoeff0(self.g, n, self.get_var(var)))7942 return P.new_gen(polcoeff0(self.g, n, P.get_var(var))) 7967 7943 7968 7944 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))7945 pari_catch_sig_on() 7946 cdef GEN t0 = P.toGEN(pol2) 7947 return P.new_gen(polcompositum0(self.g, t0, flag)) 7972 7948 7973 7949 def poldegree(self, var=-1): 7974 7950 """ 7975 7951 f.poldegree(var=x): Return the degree of this polynomial. 7976 7952 """ 7977 7953 pari_catch_sig_on() 7978 n = poldegree(self.g, self.get_var(var))7954 n = poldegree(self.g, P.get_var(var)) 7979 7955 pari_catch_sig_off() 7980 7956 return n 7981 7957 … … 8018 7994 sage: nf.nfgaloisconj() 8019 7995 [-x, x]~ 8020 7996 """ 8021 global t0 7997 pari_catch_sig_on() 7998 cdef GEN t0 8022 7999 if denom is not None: 8023 t0 GEN(denom)8000 t0 = P.toGEN(denom) 8024 8001 else: 8025 8002 t0 = NULL 8026 pari_catch_sig_on() 8027 return self.new_gen(galoisconj0(self.g, flag, t0, pbw(precision))) 8003 return P.new_gen(galoisconj0(self.g, flag, t0, prec_bits_to_words(precision))) 8028 8004 8029 8005 def nfroots(self, poly): 8030 8006 r""" … … 8044 8020 sage: nf.nfroots(y^4 + 2) 8045 8021 [Mod(-zz, zz^4 + 2), Mod(zz, zz^4 + 2)] 8046 8022 """ 8047 t0GEN(poly)8048 pari_catch_sig_on()8049 return self.new_gen(nfroots(self.g, t0))8023 pari_catch_sig_on() 8024 cdef GEN t0 = P.toGEN(poly) 8025 return P.new_gen(nfroots(self.g, t0)) 8050 8026 8051 8027 def polhensellift(self, y, p, long e): 8052 8028 """ … … 8054 8030 modulo p to a factorization modulo `p^e` using Hensel lift. 8055 8031 The factors in y must be pairwise relatively prime modulo p. 8056 8032 """ 8057 t0GEN(y)8058 t1GEN(p)8059 pari_catch_sig_on()8060 return self.new_gen(polhensellift(self.g, t0, t1, e))8033 pari_catch_sig_on() 8034 cdef GEN t0 = P.toGEN(y) 8035 cdef GEN t1 = P.toGEN(p) 8036 return P.new_gen(polhensellift(self.g, t0, t1, e)) 8061 8037 8062 8038 def polisirreducible(self): 8063 8039 """ … … 8076 8052 variable v otherwise 8077 8053 """ 8078 8054 pari_catch_sig_on() 8079 return self.new_gen(pollead(self.g, self.get_var(v)))8055 return P.new_gen(pollead(self.g, P.get_var(v))) 8080 8056 8081 8057 def polrecip(self): 8082 8058 pari_catch_sig_on() 8083 return self.new_gen(polrecip(self.g))8059 return P.new_gen(polrecip(self.g)) 8084 8060 8085 8061 def polred(self, flag=0, fa=None): 8062 pari_catch_sig_on() 8063 cdef GEN t0 8086 8064 if fa is None: 8087 pari_catch_sig_on() 8088 return self.new_gen(polred0(self.g, flag, NULL)) 8065 t0 = NULL 8089 8066 else: 8090 t0GEN(fa) 8091 pari_catch_sig_on() 8092 return self.new_gen(polred0(self.g, flag, t0)) 8067 t0 = P.toGEN(fa) 8068 return P.new_gen(polred0(self.g, flag, t0)) 8093 8069 8094 8070 def polredabs(self, flag=0): 8095 8071 pari_catch_sig_on() 8096 return self.new_gen(polredabs0(self.g, flag))8072 return P.new_gen(polredabs0(self.g, flag)) 8097 8073 8098 8074 def polredbest(self, flag=0): 8099 8075 pari_catch_sig_on() 8100 return self.new_gen(polredbest(self.g, flag))8076 return P.new_gen(polredbest(self.g, flag)) 8101 8077 8102 8078 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))8079 pari_catch_sig_on() 8080 t0 = P.toGEN(y) 8081 return P.new_gen(polresultant0(self.g, t0, P.get_var(var), flag)) 8106 8082 8107 8083 def polroots(self, flag=0, precision=0): 8108 8084 """ … … 8111 8087 by Gourdon, or 1: uses a modified Newton method. 8112 8088 """ 8113 8089 pari_catch_sig_on() 8114 return self.new_gen(roots0(self.g, flag, pbw(precision)))8090 return P.new_gen(roots0(self.g, flag, prec_bits_to_words(precision))) 8115 8091 8116 8092 def polrootsmod(self, p, flag=0): 8117 t0GEN(p)8118 pari_catch_sig_on()8119 return self.new_gen(rootmod0(self.g, t0, flag))8093 pari_catch_sig_on() 8094 cdef GEN t0 = P.toGEN(p) 8095 return P.new_gen(rootmod0(self.g, t0, flag)) 8120 8096 8121 8097 def polrootspadic(self, p, r=20): 8122 t0GEN(p)8123 pari_catch_sig_on()8124 return self.new_gen(rootpadic(self.g, t0, r))8098 pari_catch_sig_on() 8099 cdef GEN t0 = P.toGEN(p) 8100 return P.new_gen(rootpadic(self.g, t0, r)) 8125 8101 8126 8102 def polrootspadicfast(self, p, r=20): 8127 t0GEN(p)8128 pari_catch_sig_on()8129 return self.new_gen(rootpadicfast(self.g, t0, r))8103 pari_catch_sig_on() 8104 cdef GEN t0 = P.toGEN(p) 8105 return P.new_gen(rootpadicfast(self.g, t0, r)) 8130 8106 8131 8107 def polsturm(self, a, b): 8132 t0GEN(a)8133 t1GEN(b)8134 pari_catch_sig_on()8108 pari_catch_sig_on() 8109 cdef GEN t0 = P.toGEN(a) 8110 cdef GEN t1 = P.toGEN(b) 8135 8111 n = sturmpart(self.g, t0, t1) 8136 pari_catch_sig_off()8112 P.clear_stack() 8137 8113 return n 8138 8114 8139 8115 def polsturm_full(self): … … 8143 8119 return n 8144 8120 8145 8121 def polsylvestermatrix(self, g): 8146 t0GEN(g)8147 pari_catch_sig_on()8148 return self.new_gen(sylvestermatrix(self.g, t0))8122 pari_catch_sig_on() 8123 cdef GEN t0 = P.toGEN(g) 8124 return P.new_gen(sylvestermatrix(self.g, t0)) 8149 8125 8150 8126 def polsym(self, long n): 8151 8127 pari_catch_sig_on() 8152 return self.new_gen(polsym(self.g, n))8128 return P.new_gen(polsym(self.g, n)) 8153 8129 8154 8130 def serconvol(self, g): 8155 t0GEN(g)8156 pari_catch_sig_on()8157 return self.new_gen(convol(self.g, t0))8131 pari_catch_sig_on() 8132 cdef GEN t0 = P.toGEN(g) 8133 return P.new_gen(convol(self.g, t0)) 8158 8134 8159 8135 def serlaplace(self): 8160 8136 pari_catch_sig_on() 8161 return self.new_gen(laplace(self.g))8137 return P.new_gen(laplace(self.g)) 8162 8138 8163 8139 def serreverse(self): 8164 8140 """ … … 8179 8155 x + O(x^4) 8180 8156 """ 8181 8157 pari_catch_sig_on() 8182 return self.new_gen(recip(self.g))8158 return P.new_gen(recip(self.g)) 8183 8159 8184 8160 def thueinit(self, flag=0): 8185 8161 pari_catch_sig_on() 8186 return self.new_gen(thueinit(self.g, flag, prec))8162 return P.new_gen(thueinit(self.g, flag, prec)) 8187 8163 8188 8164 8189 8165 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))8166 pari_catch_sig_on() 8167 cdef GEN t0 = P.toGEN(polrel) 8168 return P.new_gen(rnfisnorminit(self.g, t0, flag)) 8193 8169 8194 8170 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))8171 pari_catch_sig_on() 8172 cdef GEN t0 = P.toGEN(T) 8173 return P.new_gen(rnfisnorm(t0, self.g, flag)) 8198 8174 8199 8175 ########################################### 8200 8176 # 8: Vectors, matrices, LINEAR ALGEBRA and sets … … 8214 8190 This function uses the PARI row and column indexing, so the 8215 8191 first row or column is indexed by 1 instead of 0. 8216 8192 """ 8217 t0GEN(y) 8193 pari_catch_sig_on() 8194 cdef GEN t0 = P.toGEN(y) 8195 cdef GEN t1 8218 8196 if z is None: 8219 pari_catch_sig_on()8220 8197 return P.new_gen(shallowextract(self.g, t0)) 8221 8198 else: 8222 t1GEN(z) 8223 pari_catch_sig_on() 8199 t1 = P.toGEN(z) 8224 8200 return P.new_gen(extract0(self.g, t0, t1)) 8225 8201 8226 8202 def ncols(self): … … 8328 8304 robust, slower implementation, valid for non integral quadratic 8329 8305 forms. 8330 8306 """ 8331 t0GEN(B)8332 t1GEN(max)8333 pari_catch_sig_on()8334 return self.new_gen(qfminim0(self.g,t0,t1,flag,precdl))8307 pari_catch_sig_on() 8308 cdef GEN t0 = P.toGEN(B) 8309 cdef GEN t1 = P.toGEN(max) 8310 return P.new_gen(qfminim0(self.g, t0, t1, flag, precdl)) 8335 8311 8336 8312 def qfrep(self, B, long flag=0): 8337 8313 """ … … 8340 8316 digits of flag mean 1: count vectors of even norm from 1 to 2B, 2: 8341 8317 return a t_VECSMALL instead of a t_VEC. 8342 8318 """ 8343 t0GEN(B)8344 pari_catch_sig_on()8345 return self.new_gen(qfrep0(self.g,t0,flag))8319 pari_catch_sig_on() 8320 cdef GEN t0 = P.toGEN(B) 8321 return P.new_gen(qfrep0(self.g, t0, flag)) 8346 8322 8347 8323 def matsolve(self, B): 8348 8324 """ … … 8367 8343 sage: pari('[1,1;1,-1]').matsolve(pari('[1;0]')) 8368 8344 [1/2; 1/2] 8369 8345 """ 8370 t0GEN(B)8371 pari_catch_sig_on()8372 return self.new_gen(gauss(self.g,t0))8346 pari_catch_sig_on() 8347 cdef GEN t0 = P.toGEN(B) 8348 return P.new_gen(gauss(self.g, t0)) 8373 8349 8374 8350 def matsolvemod(self, D, B, long flag = 0): 8375 8351 r""" … … 8413 8389 sage: M2.matsolvemod(9, pari('[2,45]~'), 1) 8414 8390 [[1, 1]~, [-1, -4; 1, -5]] 8415 8391 """ 8416 t0GEN(D)8417 t1GEN(B)8418 pari_catch_sig_on()8419 return self.new_gen(matsolvemod0(self.g, t0, t1, flag))8392 pari_catch_sig_on() 8393 cdef GEN t0 = P.toGEN(D) 8394 cdef GEN t1 = P.toGEN(B) 8395 return P.new_gen(matsolvemod0(self.g, t0, t1, flag)) 8420 8396 8421 8397 def matker(self, long flag=0): 8422 8398 """ … … 8563 8539 sage: pari(M).mathnfmod(12) 8564 8540 [1, 0, 0; 0, 2, 0; 0, 0, 6] 8565 8541 """ 8566 t0GEN(d)8567 pari_catch_sig_on()8568 return self.new_gen(hnfmod(self.g, t0))8542 pari_catch_sig_on() 8543 cdef GEN t0 = P.toGEN(d) 8544 return P.new_gen(hnfmod(self.g, t0)) 8569 8545 8570 8546 def mathnfmodid(self, d): 8571 8547 """ … … 8592 8568 sage: pari(M).mathnfmod(6) 8593 8569 [1, 0, 0; 0, 1, 0; 0, 0, 6] 8594 8570 """ 8595 t0GEN(d)8596 pari_catch_sig_on()8597 return self.new_gen(hnfmodid(self.g, t0))8571 pari_catch_sig_on() 8572 cdef GEN t0 = P.toGEN(d) 8573 return P.new_gen(hnfmodid(self.g, t0)) 8598 8574 8599 8575 def matsnf(self, flag=0): 8600 8576 """ … … 8701 8677 PariError: sorry, factor for general polynomials is not yet implemented 8702 8678 """ 8703 8679 cdef int r 8680 cdef GEN t0 8704 8681 cdef GEN cutoff 8705 8682 if limit == -1 and typ(self.g) == t_INT and proof: 8706 8683 pari_catch_sig_on() … … 8722 8699 ########################################### 8723 8700 8724 8701 def hilbert(x, y, p): 8725 cdef long ret 8726 t0GEN(y) 8727 t1GEN(p) 8728 pari_catch_sig_on() 8702 pari_catch_sig_on() 8703 cdef GEN t0 = P.toGEN(y) 8704 cdef GEN t1 = P.toGEN(p) 8729 8705 ret = hilbert0(x.g, t0, t1) 8730 pari_catch_sig_off()8706 P.clear_stack() 8731 8707 return ret 8732 8708 8733 8709 def chinese(self, y): 8734 t0GEN(y)8735 pari_catch_sig_on()8710 pari_catch_sig_on() 8711 cdef GEN t0 = P.toGEN(y) 8736 8712 return P.new_gen(chinese(self.g, t0)) 8737 8713 8738 8714 def order(self): … … 8867 8843 sage: f.subst(x, "xyz")^2 8868 8844 xyz^6 + 34*xyz^4 + 6*xyz^3 + 289*xyz^2 + 102*xyz + 9 8869 8845 """ 8870 cdef long n 8871 n = P.get_var(var) 8872 t0GEN(z) 8873 pari_catch_sig_on() 8846 pari_catch_sig_on() 8847 cdef long n = P.get_var(var) 8848 cdef GEN t0 = P.toGEN(z) 8874 8849 return P.new_gen(gsubst(self.g, n, t0)) 8875 8850 8876 8851 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))8852 pari_catch_sig_on() 8853 cdef GEN t0 = P.toGEN(y) 8854 cdef GEN t1 = P.toGEN(z) 8855 return P.new_gen(gsubstpol(self.g, t0, t1)) 8881 8856 8882 8857 def nf_subst(self, z): 8883 8858 """ … … 8916 8891 sage: Lpari.bnf_get_cyc() # We still have a bnf after substituting 8917 8892 [2] 8918 8893 """ 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))8894 pari_catch_sig_on() 8895 cdef gen nf = self.get_nf() 8896 cdef GEN t0 = P.toGEN(z) 8897 return P.new_gen(gsubst(self.g, nf_get_varn(nf.g), t0)) 8923 8898 8924 8899 def taylor(self, v=-1): 8925 8900 pari_catch_sig_on() 8926 return self.new_gen(tayl(self.g, self.get_var(v), precdl))8901 return P.new_gen(tayl(self.g, P.get_var(v), precdl)) 8927 8902 8928 8903 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))8904 pari_catch_sig_on() 8905 cdef GEN t0 = P.toGEN(rhs) 8906 cdef GEN t1 = P.toGEN(ne) 8907 return P.new_gen(thue(self.g, t0, t1)) 8933 8908 8934 8909 def charpoly(self, var=-1, flag=0): 8935 8910 """ … … 8943 8918 8944 8919 8945 8920 def kronecker(gen self, y): 8946 t0GEN(y)8947 8921 pari_catch_sig_on() 8922 cdef GEN t0 = P.toGEN(y) 8948 8923 return P.new_gen(gkronecker(self.g, t0)) 8949 8924 8950 8925 … … 9013 8988 P(self[i]) = ya[i] for all i). Also return an error estimate on the 9014 8989 returned value. 9015 8990 """ 9016 t0GEN(ya) 9017 t1GEN(x) 8991 pari_catch_sig_on() 8992 cdef GEN t0 = P.toGEN(ya) 8993 cdef GEN t1 = P.toGEN(x) 9018 8994 cdef GEN dy, g 9019 pari_catch_sig_on()9020 8995 g = polint(self.g, t0, t1, &dy) 9021 dif = self.new_gen_noclear(dy)9022 return self.new_gen(g), dif8996 dif = P.new_gen_noclear(dy) 8997 return P.new_gen(g), dif 9023 8998 9024 8999 def algdep(self, long n): 9025 9000 """ … … 9037 9012 210 9038 9013 """ 9039 9014 pari_catch_sig_on() 9040 return self.new_gen(algdep(self.g, n))9015 return P.new_gen(algdep(self.g, n)) 9041 9016 9042 9017 def concat(self, y): 9043 t0GEN(y)9044 pari_catch_sig_on()9045 return self.new_gen(concat(self.g, t0))9018 pari_catch_sig_on() 9019 cdef GEN t0 = P.toGEN(y) 9020 return P.new_gen(concat(self.g, t0)) 9046 9021 9047 9022 def lindep(self, flag=0): 9048 9023 pari_catch_sig_on() 9049 return self.new_gen(lindep0(self.g, flag))9024 return P.new_gen(lindep0(self.g, flag)) 9050 9025 9051 9026 def listinsert(self, obj, long n): 9052 t0GEN(obj)9053 pari_catch_sig_on()9054 return self.new_gen(listinsert(self.g, t0, n))9027 pari_catch_sig_on() 9028 cdef GEN t0 = P.toGEN(obj) 9029 return P.new_gen(listinsert(self.g, t0, n)) 9055 9030 9056 9031 def listput(self, obj, long n): 9057 t0GEN(obj)9058 pari_catch_sig_on()9059 return self.new_gen(listput(self.g, t0, n))9032 pari_catch_sig_on() 9033 cdef GEN t0 = P.toGEN(obj) 9034 return P.new_gen(listput(self.g, t0, n)) 9060 9035 9061 9036 9062 9037 … … 9167 9142 sage: E.ellwp(1, flag=1) 9168 9143 [13.9658695257485 + 0.E-18*I, 50.5619300880073 ... E-18*I] 9169 9144 """ 9170 t0GEN(z)9171 pari_catch_sig_on()9145 pari_catch_sig_on() 9146 cdef GEN t0 = P.toGEN(z) 9172 9147 cdef long dprec 9173 9148 dprec = gprecision(t0) 9174 9149 if dprec: 9175 9150 dprec = prec_words_to_dec(dprec) 9176 9151 else: 9177 9152 dprec = prec 9178 return self.new_gen(ellwp0(self.g, t0, flag, n+2, dprec))9153 return P.new_gen(ellwp0(self.g, t0, flag, n+2, dprec)) 9179 9154 9180 9155 def ellchangepoint(self, y): 9181 9156 """ … … 9198 9173 sage: f.ellisoncurve([-1,4]) 9199 9174 True 9200 9175 """ 9201 t0GEN(y)9202 pari_catch_sig_on()9203 return self.new_gen(ellchangepoint(self.g, t0))9176 pari_catch_sig_on() 9177 cdef GEN t0 = P.toGEN(y) 9178 return P.new_gen(ellchangepoint(self.g, t0)) 9204 9179 9205 9180 def debug(gen self, long depth = -1): 9206 9181 r""" … … 9446 9421 """ 9447 9422 return int(self.default('debug')) 9448 9423 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 9424 def set_real_precision(self, long n): 9460 9425 """ 9461 9426 Sets the PARI default real precision. … … 9497 9462 9498 9463 def get_series_precision(self): 9499 9464 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 ########################################### 9465 9466 cdef void clear_stack(self): 9467 """ 9468 Call ``pari_catch_sig_off()``, and clear the entire PARI stack 9469 if we are leaving the outermost ``pari_catch_sig_on() ... 9470 pari_catch_sig_off()`` block. 9471 9472 """ 9473 global mytop, avma 9474 if _signals.sig_on_count <= 1: 9475 avma = mytop 9476 pari_catch_sig_off() 9507 9477 9508 9478 cdef gen new_gen(self, GEN x): 9509 9479 """ 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() 9480 Create a new gen wrapping `x`, then call ``clear_stack()``. 9481 """ 9482 cdef gen g = _new_gen(x) 9483 self.clear_stack() 9518 9484 return g 9519 9485 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 9486 cdef gen new_gen_noclear(self, GEN x): 9548 9487 """ 9549 9488 Create a new gen, but don't free any memory on the stack and don't … … 9724 9663 """ 9725 9664 Create a new complex number, initialized from re and im. 9726 9665 """ 9727 t0GEN(re) 9728 t1GEN(im) 9729 cdef GEN cp 9730 pari_catch_sig_on() 9731 cp = cgetg(3, t_COMPLEX) 9666 pari_catch_sig_on() 9667 cdef GEN cp = cgetg(3, t_COMPLEX) 9668 cdef GEN t0 = self.toGEN(re) 9669 cdef GEN t1 = self.toGEN(im) 9732 9670 set_gel(cp, 1, t0) 9733 9671 set_gel(cp, 2, t1) 9734 9672 return self.new_gen(cp) … … 9793 9731 9794 9732 See :func:`pari` for more examples. 9795 9733 """ 9796 cdef int length, i 9797 cdef gen v 9798 9799 late_import() 9800 9734 cdef GEN g 9801 9735 if isinstance(s, gen): 9802 9736 return s 9803 elif isinstance(s, Integer):9804 return self.new_gen_from_mpz_t(<void *>s + mpz_t_offset)9805 9737 elif PyObject_HasAttrString(s, "_pari_"): 9806 9738 return s._pari_() 9739 else: 9740 pari_catch_sig_on() 9741 g = self.toGEN(s) 9742 if g == gnil: 9743 self.clear_stack() 9744 return None 9745 else: 9746 return self.new_gen(g) 9747 9748 cdef GEN toGEN(self, s) except NULL: 9749 """ 9750 Convert `s` to a GEN. 9751 9752 One should call ``pari_catch_sig_on()`` before and 9753 ``pari_catch_sig_off()`` after. 9754 9755 """ 9756 cdef int length, i 9757 cdef mpz_t mpz_int 9758 cdef GEN g 9759 cdef gen h 9760 9761 if isinstance(s, gen): 9762 return (<gen>s).g 9763 elif PyObject_HasAttrString(s, "_pari_"): 9764 h = s._pari_() 9765 return gcopy(h.g) 9807 9766 9808 9767 # Check basic Python types 9809 9768 if PyInt_Check(s): 9810 pari_catch_sig_on() 9811 return self.new_gen(stoi(PyInt_AS_LONG(s))) 9769 return stoi(PyInt_AS_LONG(s)) 9812 9770 if PyBool_Check(s): 9813 return self.PARI_ONE if s else self.PARI_ZERO 9814 cdef mpz_t mpz_int 9815 cdef GEN g 9771 return gen_1 if s else gen_0 9816 9772 if PyLong_Check(s): 9817 pari_catch_sig_on()9818 9773 mpz_init(mpz_int) 9819 9774 mpz_set_pylong(mpz_int, s) 9820 9775 g = self._new_GEN_from_mpz_t(mpz_int) 9821 9776 mpz_clear(mpz_int) 9822 return self.new_gen(g)9777 return g 9823 9778 if PyFloat_Check(s): 9824 pari_catch_sig_on() 9825 return self.new_gen(dbltor(PyFloat_AS_DOUBLE(s))) 9779 return dbltor(PyFloat_AS_DOUBLE(s)) 9826 9780 if PyComplex_Check(s): 9827 pari_catch_sig_on()9828 9781 g = cgetg(3, t_COMPLEX) 9829 9782 set_gel(g, 1, dbltor(PyComplex_RealAsDouble(s))) 9830 9783 set_gel(g, 2, dbltor(PyComplex_ImagAsDouble(s))) 9831 return self.new_gen(g)9784 return g 9832 9785 9833 9786 if isinstance(s, (types.ListType, types.XRangeType, 9834 9787 types.TupleType, types.GeneratorType)): 9835 9788 length = len(s) 9836 v = self._empty_vector(length)9789 g = cgetg(length + 1, t_VEC) 9837 9790 for i from 0 <= i < length: 9838 v[i] = self(s[i])9839 return v9791 set_gel(g, i + 1, self.toGEN(s[i])) 9792 return g 9840 9793 9841 9794 t = str(s) 9842 pari_catch_sig_str('evaluating PARI string') 9843 g = gp_read_str(t) 9844 if g == gnil: 9845 pari_catch_sig_off() 9846 return None 9847 return self.new_gen(g) 9795 return gp_read_str(t) 9848 9796 9849 9797 cdef GEN _new_GEN_from_mpz_t_matrix(self, mpz_t** B, Py_ssize_t nr, Py_ssize_t nc): 9850 9798 r""" … … 10380 10328 sage: cyclotomic_polynomial(8)(2) 10381 10329 17 10382 10330 """ 10383 t0GEN(v)10384 pari_catch_sig_on()10331 pari_catch_sig_on() 10332 cdef GEN t0 = self.toGEN(v) 10385 10333 return self.new_gen(polcyclo_eval(n, t0)) 10386 10334 10387 10335 def polsubcyclo(self, long n, long d, v=-1): … … 10450 10398 ... 10451 10399 PariError: incorrect type in setrand 10452 10400 """ 10453 t0GEN(seed)10454 pari_catch_sig_on()10401 pari_catch_sig_on() 10402 cdef GEN t0 = self.toGEN(seed) 10455 10403 setrand(t0) 10456 pari_catch_sig_off()10404 self.clear_stack() 10457 10405 10458 10406 def getrand(self): 10459 10407 """ -
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 """