| 1 | """nodoctest |
|---|
| 2 | Interface to PARI |
|---|
| 3 | """ |
|---|
| 4 | |
|---|
| 5 | doc=r""" |
|---|
| 6 | Interface to PARI |
|---|
| 7 | |
|---|
| 8 | This module provides an interface to the PARI C-library. |
|---|
| 9 | This interface is modeled on the GP interpreter, and compared |
|---|
| 10 | to GP it has advantages and disadvantages. First |
|---|
| 11 | we list some advantages: |
|---|
| 12 | \begin{enumerate} |
|---|
| 13 | \item Improved memory management and garbage collection: |
|---|
| 14 | \begin{enumerate} |
|---|
| 15 | \item Automatic garbage collection: Each SAGE/PARI object |
|---|
| 16 | has its own piece of memory allocated from the Python |
|---|
| 17 | heap. When objects go out of scope the Python memory |
|---|
| 18 | manager deletes them. (Implementation: I grafted |
|---|
| 19 | genuine memory management onto PARI by creatinging a |
|---|
| 20 | mini ``PARI stack'' in the Python heap for each GEN that |
|---|
| 21 | is wrapped by a Python object. In some cases it is |
|---|
| 22 | necessary to copy this GEN back to the main PARI stack |
|---|
| 23 | for computations, which entails a performance penalty.) |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | \item It is less likely that the ``PARI stack overflows''. |
|---|
| 27 | This is because the main stack is {\em only} used for |
|---|
| 28 | individual computations; as soon as an object is computed |
|---|
| 29 | it is moved of the stack into its own chunk of memory in |
|---|
| 30 | the Python heap. |
|---|
| 31 | \end{enumerate} |
|---|
| 32 | |
|---|
| 33 | \item Exception handling: try, except, raise. GP doesn't have |
|---|
| 34 | any exception handling. |
|---|
| 35 | |
|---|
| 36 | \item Python is a genuine object-oriented language with user |
|---|
| 37 | defined classes, multiple inheritence, polymorphism, etc. The |
|---|
| 38 | GP language was written initially for testing the C library, |
|---|
| 39 | and is not as sophisticated a language as Python. |
|---|
| 40 | |
|---|
| 41 | \item Object serialization: This can make loading and saving |
|---|
| 42 | objects to disk easier. |
|---|
| 43 | |
|---|
| 44 | sage: a = pari(5) |
|---|
| 45 | sage: import pickle |
|---|
| 46 | sage: s = pickle.dumps(a); |
|---|
| 47 | sage: z = pickle.loads(s); |
|---|
| 48 | sage: print z |
|---|
| 49 | 5 |
|---|
| 50 | sage: type(z) |
|---|
| 51 | <type '_py_pari.gen'> |
|---|
| 52 | sage: a == z |
|---|
| 53 | True |
|---|
| 54 | sage: a is z |
|---|
| 55 | False |
|---|
| 56 | |
|---|
| 57 | \item Documentation: Each method has (or will have) example |
|---|
| 58 | usage, so there will be more examples of usage than in the PARI |
|---|
| 59 | documentation. |
|---|
| 60 | |
|---|
| 61 | \end{enumerate} |
|---|
| 62 | |
|---|
| 63 | There are also several disadvantages: |
|---|
| 64 | |
|---|
| 65 | \begin{enumerate} |
|---|
| 66 | \item \module{py_pari} currently does not export all the functionality |
|---|
| 67 | of PARI. For example, there is currently no support for numerical integration. |
|---|
| 68 | |
|---|
| 69 | \item There is overhead associated with doing more complicated memory |
|---|
| 70 | management than GP, so SAGE/PARI can be slower than GP. |
|---|
| 71 | |
|---|
| 72 | \item PARI functions run at the C-level and cannot be interrupted from |
|---|
| 73 | the Python interpreter with ctrl-C until they return from C level. |
|---|
| 74 | This is in accord with how the Python interpreter works. |
|---|
| 75 | |
|---|
| 76 | \item Some of the PARI error and log messages print to stdout. This |
|---|
| 77 | can be annoying, since it might interfere with output the |
|---|
| 78 | user is trying to send to a file. This is fortunately rare. |
|---|
| 79 | \end{enumerate} |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | """ |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | # |
|---|
| 87 | """ |
|---|
| 88 | TODO |
|---|
| 89 | * Make it so when asking for, e.g., the n-th prime, if not enough primes have |
|---|
| 90 | been precomputed, py_pari automatically precomputes enough primes and answers |
|---|
| 91 | the question. Make py_pari robust like MAGMA, and not lame like gp. |
|---|
| 92 | |
|---|
| 93 | """ |
|---|
| 94 | |
|---|
| 95 | ######################################################### |
|---|
| 96 | ## NOTES about memory management. |
|---|
| 97 | |
|---|
| 98 | ## The idea for the trick I arrived at for adding memory management to |
|---|
| 99 | ## PARI is the following. In some cases it has a performance penalty, |
|---|
| 100 | ## but in practice (and benchmarks) so far it is barely noticeable and |
|---|
| 101 | ## worth the tradeoff in my opinion. The memory model in PARI is one |
|---|
| 102 | ## big stack. When this stack runs out of space, game over. Or at |
|---|
| 103 | ## least that's what the documentation suggest. After much reading of |
|---|
| 104 | ## the source code I figured out that when you type "allocatemem()" in |
|---|
| 105 | ## the GP interpreter, it creates yet another stack -- so now there |
|---|
| 106 | ## are TWO stacks. And if you do it again, it creates a third, etc. |
|---|
| 107 | ## There are some global variables (top, bot, and avma) that define |
|---|
| 108 | ## what is the current stack for PARI library functions. So you can |
|---|
| 109 | ## take any chunk of memory at all, point top, bot and avma at it, and |
|---|
| 110 | ## all the PARI library functions will view that chunck of memory as |
|---|
| 111 | ## "the" PARI stack. |
|---|
| 112 | |
|---|
| 113 | ## So here's what I do. First, when you create a PARI object (a GEN), |
|---|
| 114 | ## you do this by using some PARI library function, which puts the |
|---|
| 115 | ## result and all objects created as part of your object on the stack. |
|---|
| 116 | ## Also the avma pointer is moved down (since the PARI stack is upside |
|---|
| 117 | ## down). So what I do is just forcecopy into the Python heap all the |
|---|
| 118 | ## memory between where avma is now and where it was before making |
|---|
| 119 | ## your object. I then set avma back to where it was before all this |
|---|
| 120 | ## happened, thus freeing that memory. This copy, which is a little |
|---|
| 121 | ## piece of memory, is managed by the Python memory manager, so when |
|---|
| 122 | ## the associated Python object goes out of scope (no more references |
|---|
| 123 | ## to it), then it is garbage collected. This garbage collection |
|---|
| 124 | ## doesn't affect the PARI stack at all, and doesn't require anything |
|---|
| 125 | ## like calling grepilemany. |
|---|
| 126 | |
|---|
| 127 | ## And that's basically it. Also, when a PARI computation fails for |
|---|
| 128 | ## lack of memory, I just toss the main stack and make a new one. |
|---|
| 129 | ## Since none of my objects are stored on the stack, this doesn't mess |
|---|
| 130 | ## anything up. |
|---|
| 131 | |
|---|
| 132 | ## Also, for some reason, some PARI operations fail if the GEN they |
|---|
| 133 | ## take as input is not on the main stack. Thus in many cases I use |
|---|
| 134 | ## the forcecopy() PARI library function to copy the object from the |
|---|
| 135 | ## Python heap back to the PARI stack, do the operation, then copy |
|---|
| 136 | ## back the result. There is overhead with these object copies, but |
|---|
| 137 | ## in practice it isn't too much, and it's worth it for such an easy |
|---|
| 138 | ## way of adding better memory management to PARI. |
|---|
| 139 | |
|---|
| 140 | ## In summary: the PARI library does it's game on the stack, but all |
|---|
| 141 | ## the user variables are stored elsewhere, and only put on the stack |
|---|
| 142 | ## for a moment when taking part in a computation. It's very simple, |
|---|
| 143 | ## gives proper memory management, and doesn't require rewriting even |
|---|
| 144 | ## a single line of PARI, with the only tradeoffs lots of extra |
|---|
| 145 | ## memcpy's, which are extremely fast anyways. |
|---|
| 146 | |
|---|
| 147 | ######################################### |
|---|
| 148 | |
|---|
| 149 | cdef int MEMERR |
|---|
| 150 | MEMERR = 25 |
|---|
| 151 | |
|---|
| 152 | import gc |
|---|
| 153 | |
|---|
| 154 | include "interrupt.pxi" |
|---|
| 155 | |
|---|
| 156 | cdef extern from "stdlib.h": |
|---|
| 157 | ctypedef unsigned long size_t |
|---|
| 158 | void free(void *ptr) |
|---|
| 159 | void *malloc(size_t size) |
|---|
| 160 | void *realloc(void *ptr, size_t size) |
|---|
| 161 | void exit (int __status) |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | cdef extern from "string.h": |
|---|
| 165 | void *memmove(void *dest, void *src, size_t n) |
|---|
| 166 | void *memcpy(void *dest, void *src, size_t n) |
|---|
| 167 | |
|---|
| 168 | cdef extern from "Python.h": |
|---|
| 169 | void PyMem_Free(void *p) |
|---|
| 170 | void* PyMem_Malloc(int) |
|---|
| 171 | void* PyMem_Realloc(void *p, size_t n) |
|---|
| 172 | |
|---|
| 173 | cdef extern from 'setjmp.h': |
|---|
| 174 | struct __jmp_buf_tag: |
|---|
| 175 | pass |
|---|
| 176 | ctypedef __jmp_buf_tag jmp_buf |
|---|
| 177 | int setjmp (jmp_buf __env) |
|---|
| 178 | int longjmp (jmp_buf __env, int val) |
|---|
| 179 | |
|---|
| 180 | ctypedef unsigned long ulong |
|---|
| 181 | |
|---|
| 182 | cdef extern from 'pari/paricfg.h': |
|---|
| 183 | char* PARIVERSION |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | cdef extern from 'pari/pari.h': |
|---|
| 187 | ctypedef long* GEN |
|---|
| 188 | ctypedef void entree # fake -- not used |
|---|
| 189 | ctypedef void FILE # fake -- not used |
|---|
| 190 | ctypedef void pariFILE # fake -- not used |
|---|
| 191 | ctypedef void va_list # fake -- not used |
|---|
| 192 | ctypedef void pari_timer # fake -- not used |
|---|
| 193 | ctypedef void stackzone # fake -- not used |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | # misc ... |
|---|
| 197 | GEN gp_read_str(char *t) |
|---|
| 198 | long typ(GEN x) |
|---|
| 199 | long itos(GEN x) |
|---|
| 200 | double gtodouble(GEN x) |
|---|
| 201 | GEN stoi(long s) |
|---|
| 202 | #GEN dbltor(double s) |
|---|
| 203 | # These types are actually an enum type, but I can't get Pyrex to "properly" |
|---|
| 204 | # wrap enums. It doesn't matter as long as they are treated as ints by pyrexc. |
|---|
| 205 | extern int t_INT, t_REAL, t_INTMOD, t_FRAC, t_COMPLEX, t_PADIC, t_QUAD, \ |
|---|
| 206 | t_POLMOD, t_POL, t_SER, t_RFRAC, t_QFR, t_QFI, t_VEC, t_COL, \ |
|---|
| 207 | t_MAT, t_LIST, t_STR, t_VECSMALL |
|---|
| 208 | |
|---|
| 209 | extern unsigned long precdl, prec |
|---|
| 210 | extern char * diffptr |
|---|
| 211 | |
|---|
| 212 | extern int BYTES_IN_LONG |
|---|
| 213 | |
|---|
| 214 | ctypedef unsigned long pari_sp |
|---|
| 215 | pari_sp avma, bot, top, zonetop |
|---|
| 216 | |
|---|
| 217 | GEN sd_realprecision(char* n, int flag) |
|---|
| 218 | |
|---|
| 219 | |
|---|
| 220 | # Flx.c |
|---|
| 221 | GEN Fl_to_Flx(ulong x, long sv) |
|---|
| 222 | GEN Flm_id(long n) |
|---|
| 223 | GEN Flm_to_FlxV(GEN x, long sv) |
|---|
| 224 | GEN Flm_to_FlxX(GEN x, long v,long w) |
|---|
| 225 | GEN Flm_to_ZM(GEN z) |
|---|
| 226 | GEN Flv_to_Flx(GEN x, long vs) |
|---|
| 227 | GEN Flv_to_ZC(GEN z) |
|---|
| 228 | GEN Flv_to_ZV(GEN z) |
|---|
| 229 | GEN Flv_polint(GEN xa, GEN ya, ulong p, long vs) |
|---|
| 230 | GEN Flv_roots_to_pol(GEN a, ulong p, long vs) |
|---|
| 231 | GEN Flx_Fl_mul(GEN y, ulong x, ulong p) |
|---|
| 232 | GEN Flx_to_Flv(GEN x, long N) |
|---|
| 233 | GEN Flx_to_ZX(GEN z) |
|---|
| 234 | GEN Flx_to_ZX_inplace(GEN z) |
|---|
| 235 | GEN Flx_add(GEN x, GEN y, ulong p) |
|---|
| 236 | GEN Flx_deriv(GEN z, ulong p) |
|---|
| 237 | GEN Flx_div_by_X_x(GEN a, ulong x, ulong p, ulong *rem) |
|---|
| 238 | GEN Flx_divrem(GEN x, GEN y, ulong p, GEN *pr) |
|---|
| 239 | ulong Flx_eval(GEN x, ulong y, ulong p) |
|---|
| 240 | GEN Flx_extgcd(GEN a, GEN b, ulong p, GEN *ptu, GEN *ptv) |
|---|
| 241 | ulong Flx_extresultant(GEN a, GEN b, ulong p, GEN *ptU, GEN *ptV) |
|---|
| 242 | GEN Flx_gcd(GEN a, GEN b, ulong p) |
|---|
| 243 | GEN Flx_gcd_i(GEN a, GEN b, ulong p) |
|---|
| 244 | GEN Flx_invmontgomery(GEN T, ulong p) |
|---|
| 245 | int Flx_is_squarefree(GEN z, ulong p) |
|---|
| 246 | GEN Flx_mul(GEN x, GEN y, ulong p) |
|---|
| 247 | GEN Flx_neg(GEN x, ulong p) |
|---|
| 248 | GEN Flx_neg_inplace(GEN x, ulong p) |
|---|
| 249 | GEN Flx_normalize(GEN z, ulong p) |
|---|
| 250 | GEN Flx_pow(GEN x, long n, ulong p) |
|---|
| 251 | GEN Flx_recip(GEN x) |
|---|
| 252 | GEN Flx_red(GEN z, ulong p) |
|---|
| 253 | GEN Flx_rem_montgomery(GEN x, GEN mg, GEN T, ulong p) |
|---|
| 254 | GEN Flx_rem(GEN x, GEN y, ulong p) |
|---|
| 255 | GEN Flx_renormalize(GEN x, long l) |
|---|
| 256 | ulong Flx_resultant(GEN a, GEN b, ulong p) |
|---|
| 257 | GEN Flx_shift(GEN a, long n) |
|---|
| 258 | GEN Flx_sqr(GEN x, ulong p) |
|---|
| 259 | GEN Flx_sub(GEN x, GEN y, ulong p) |
|---|
| 260 | long Flx_valuation(GEN x) |
|---|
| 261 | GEN FlxM_to_ZXM(GEN z) |
|---|
| 262 | GEN FlxV_Flv_innerprod(GEN V, GEN W, ulong p) |
|---|
| 263 | GEN FlxV_to_Flm(GEN v, long n) |
|---|
| 264 | GEN FlxV_to_ZXC(GEN x) |
|---|
| 265 | GEN FlxX_add(GEN P, GEN Q, ulong p) |
|---|
| 266 | GEN FlxX_shift(GEN a, long n) |
|---|
| 267 | GEN FlxX_to_Flm(GEN v, long n) |
|---|
| 268 | GEN FlxX_to_ZXX(GEN B) |
|---|
| 269 | GEN FlxYqQ_pow(GEN x, GEN n, GEN S, GEN T, ulong p) |
|---|
| 270 | GEN Flxq_inv(GEN x,GEN T,ulong p) |
|---|
| 271 | GEN Flxq_invsafe(GEN x, GEN T, ulong p) |
|---|
| 272 | GEN Flxq_mul(GEN y,GEN x,GEN T,ulong p) |
|---|
| 273 | GEN Flxq_pow(GEN x, GEN n, GEN T, ulong p) |
|---|
| 274 | GEN Flxq_powers(GEN x, long l, GEN T, ulong p) |
|---|
| 275 | GEN Flxq_sqr(GEN y,GEN T,ulong p) |
|---|
| 276 | GEN FlxqX_normalize(GEN z, GEN T, ulong p) |
|---|
| 277 | GEN FlxqX_Flxq_mul(GEN P, GEN U, GEN T, ulong p) |
|---|
| 278 | GEN FlxqX_red(GEN z, GEN T, ulong p) |
|---|
| 279 | GEN FlxqX_mul(GEN x, GEN y, GEN T, ulong p) |
|---|
| 280 | GEN FlxqX_safegcd(GEN P, GEN Q, GEN T, ulong p) |
|---|
| 281 | GEN FlxqX_sqr(GEN x, GEN T, ulong p) |
|---|
| 282 | GEN FlxqX_divrem(GEN x, GEN y, GEN T, ulong p, GEN *pr) |
|---|
| 283 | GEN FlxqXQ_pow(GEN x, GEN n, GEN S, GEN T, ulong p) |
|---|
| 284 | GEN Z_to_Flx(GEN x, ulong p, long v) |
|---|
| 285 | GEN ZM_to_Flm(GEN x, ulong p) |
|---|
| 286 | GEN ZV_to_Flv(GEN x, ulong p) |
|---|
| 287 | GEN ZX_to_Flx(GEN x, ulong p) |
|---|
| 288 | GEN ZXV_to_FlxV(GEN v, ulong p) |
|---|
| 289 | GEN ZXX_to_FlxX(GEN B, ulong p, long v) |
|---|
| 290 | GEN polx_Flx(long sv) |
|---|
| 291 | GEN zero_Flx(long sv) |
|---|
| 292 | |
|---|
| 293 | # alglin1.c |
|---|
| 294 | |
|---|
| 295 | GEN Flm_Flv_mul(GEN x, GEN y, ulong p) |
|---|
| 296 | GEN Flm_deplin(GEN x, ulong p) |
|---|
| 297 | GEN Flm_indexrank(GEN x, ulong p) |
|---|
| 298 | GEN Flm_inv(GEN x, ulong p) |
|---|
| 299 | GEN Flm_ker(GEN x, ulong p) |
|---|
| 300 | GEN Flm_ker_sp(GEN x, ulong p, long deplin) |
|---|
| 301 | GEN Flm_mul(GEN x, GEN y, ulong p) |
|---|
| 302 | GEN FlxqM_ker(GEN x, GEN T, ulong p) |
|---|
| 303 | GEN FpC_FpV_mul(GEN x, GEN y, GEN p) |
|---|
| 304 | GEN FpM_FpV_mul(GEN x, GEN y, GEN p) |
|---|
| 305 | GEN FpM_deplin(GEN x, GEN p) |
|---|
| 306 | GEN FpM_image(GEN x, GEN p) |
|---|
| 307 | GEN FpM_intersect(GEN x, GEN y, GEN p) |
|---|
| 308 | GEN FpM_inv(GEN x, GEN p) |
|---|
| 309 | GEN FpM_invimage(GEN m, GEN v, GEN p) |
|---|
| 310 | GEN FpM_ker(GEN x, GEN p) |
|---|
| 311 | GEN FpM_mul(GEN x, GEN y, GEN p) |
|---|
| 312 | long FpM_rank(GEN x, GEN p) |
|---|
| 313 | GEN FpM_indexrank(GEN x, GEN p) |
|---|
| 314 | GEN FpM_suppl(GEN x, GEN p) |
|---|
| 315 | GEN FqM_gauss(GEN a, GEN b, GEN T, GEN p) |
|---|
| 316 | GEN FqM_ker(GEN x, GEN T, GEN p) |
|---|
| 317 | GEN FqM_suppl(GEN x, GEN T, GEN p) |
|---|
| 318 | GEN QM_inv(GEN M, GEN dM) |
|---|
| 319 | GEN ZM_inv(GEN M, GEN dM) |
|---|
| 320 | void appendL(GEN x, GEN t) |
|---|
| 321 | GEN cget1(long l, long t) |
|---|
| 322 | GEN concat(GEN x, GEN y) |
|---|
| 323 | GEN concatsp(GEN x, GEN y) |
|---|
| 324 | GEN concatsp3(GEN x, GEN y, GEN z) |
|---|
| 325 | GEN deplin(GEN x) |
|---|
| 326 | GEN det(GEN a) |
|---|
| 327 | GEN det0(GEN a,long flag) |
|---|
| 328 | GEN det2(GEN a) |
|---|
| 329 | GEN dethnf(GEN x) |
|---|
| 330 | GEN dethnf_i(GEN mat) |
|---|
| 331 | GEN detint(GEN x) |
|---|
| 332 | GEN diagonal(GEN x) |
|---|
| 333 | GEN eigen(GEN x, long prec) |
|---|
| 334 | GEN extract(GEN x, GEN l) |
|---|
| 335 | GEN extract0(GEN x, GEN l1, GEN l2) |
|---|
| 336 | GEN gaddmat(GEN x, GEN y) |
|---|
| 337 | GEN gaddmat_i(GEN x, GEN y) |
|---|
| 338 | GEN gauss(GEN a, GEN b) |
|---|
| 339 | GEN gaussmodulo(GEN M, GEN D, GEN Y) |
|---|
| 340 | GEN gaussmodulo2(GEN M, GEN D, GEN Y) |
|---|
| 341 | GEN gscalcol(GEN x, long n) |
|---|
| 342 | GEN gscalcol_i(GEN x, long n) |
|---|
| 343 | GEN gscalcol_proto(GEN z, GEN myzero, long n) |
|---|
| 344 | GEN gscalmat(GEN x, long n) |
|---|
| 345 | GEN gscalsmat(long x, long n) |
|---|
| 346 | GEN gtomat(GEN x) |
|---|
| 347 | GEN gtrans(GEN x) |
|---|
| 348 | GEN gtrans_i(GEN x) |
|---|
| 349 | int hnfdivide(GEN A, GEN B) |
|---|
| 350 | GEN idmat(long n) |
|---|
| 351 | GEN idmat_intern(long n,GEN myun,GEN myzero) |
|---|
| 352 | GEN image(GEN x) |
|---|
| 353 | GEN image2(GEN x) |
|---|
| 354 | GEN imagecompl(GEN x) |
|---|
| 355 | GEN indexrank(GEN x) |
|---|
| 356 | GEN inverseimage(GEN mat, GEN y) |
|---|
| 357 | long isdiagonal(GEN x) |
|---|
| 358 | long isscalarmat(GEN x, GEN s) |
|---|
| 359 | GEN ker(GEN x) |
|---|
| 360 | GEN keri(GEN x) |
|---|
| 361 | GEN matextract(GEN x, GEN l1, GEN l2) |
|---|
| 362 | GEN matimage0(GEN x,long flag) |
|---|
| 363 | GEN matker0(GEN x, long flag) |
|---|
| 364 | GEN matmuldiagonal(GEN x, GEN d) |
|---|
| 365 | GEN matmultodiagonal(GEN x, GEN y) |
|---|
| 366 | GEN matsolvemod0(GEN M, GEN D, GEN Y,long flag) |
|---|
| 367 | GEN mattodiagonal(GEN m) |
|---|
| 368 | GEN mattodiagonal_i(GEN m) |
|---|
| 369 | long rank(GEN x) |
|---|
| 370 | GEN row(GEN A, long x1) |
|---|
| 371 | GEN row_i(GEN A, long x0, long x1, long x2) |
|---|
| 372 | GEN rowextract_i(GEN A, long x1, long x2) |
|---|
| 373 | GEN rowextract_ip(GEN A, GEN p, long x1, long x2) |
|---|
| 374 | GEN rowextract_p(GEN A, GEN p) |
|---|
| 375 | GEN sindexrank(GEN x) |
|---|
| 376 | GEN sum(GEN v, long a, long b) |
|---|
| 377 | GEN suppl(GEN x) |
|---|
| 378 | GEN vconcat(GEN A, GEN B) |
|---|
| 379 | GEN vec_ei(long n, long i) |
|---|
| 380 | GEN vec_Cei(long n, long i, GEN c) |
|---|
| 381 | GEN vecextract_i(GEN A, long y1, long y2) |
|---|
| 382 | GEN vecextract_ip(GEN A, GEN p, long y1, long y2) |
|---|
| 383 | GEN vecextract_p(GEN A, GEN p) |
|---|
| 384 | |
|---|
| 385 | # alglin2.c |
|---|
| 386 | |
|---|
| 387 | GEN QuickNormL1(GEN x,long prec) |
|---|
| 388 | GEN QuickNormL2(GEN x,long prec) |
|---|
| 389 | GEN ZM_to_zm(GEN z) |
|---|
| 390 | GEN adj(GEN x) |
|---|
| 391 | GEN assmat(GEN x) |
|---|
| 392 | GEN caract(GEN x, int v) |
|---|
| 393 | GEN caract2(GEN p, GEN x, int v) |
|---|
| 394 | GEN caradj(GEN x, long v, GEN *py) |
|---|
| 395 | GEN caradj0(GEN x, long v) |
|---|
| 396 | GEN carhess(GEN x, long v) |
|---|
| 397 | GEN charpoly0(GEN x, int v,long flag) |
|---|
| 398 | GEN conjvec(GEN x,long prec) |
|---|
| 399 | GEN gconj(GEN x) |
|---|
| 400 | GEN gnorm(GEN x) |
|---|
| 401 | GEN gnorml1(GEN x,long prec) |
|---|
| 402 | GEN gnorml2(GEN x) |
|---|
| 403 | GEN gtrace(GEN x) |
|---|
| 404 | GEN hess(GEN x) |
|---|
| 405 | GEN hnf(GEN x) |
|---|
| 406 | GEN hnfall(GEN x) |
|---|
| 407 | GEN hnflll(GEN x) |
|---|
| 408 | GEN hnflll_i(GEN A, GEN *ptB, int remove) |
|---|
| 409 | GEN hnfmod(GEN x, GEN detmat) |
|---|
| 410 | GEN hnfmodid(GEN x,GEN p) |
|---|
| 411 | GEN hnfmodidpart(GEN x, GEN p) |
|---|
| 412 | GEN hnfperm(GEN x) |
|---|
| 413 | GEN intersect(GEN x, GEN y) |
|---|
| 414 | GEN jacobi(GEN a, long prec) |
|---|
| 415 | GEN matfrobenius(GEN M, long flag) |
|---|
| 416 | GEN matrixqz(GEN x, GEN pp) |
|---|
| 417 | GEN matrixqz0(GEN x, GEN pp) |
|---|
| 418 | GEN matrixqz2(GEN x) |
|---|
| 419 | GEN matrixqz3(GEN x) |
|---|
| 420 | GEN signat(GEN a) |
|---|
| 421 | GEN smith(GEN x) |
|---|
| 422 | GEN smith2(GEN x) |
|---|
| 423 | GEN smithall(GEN x, GEN *ptU, GEN *ptV) |
|---|
| 424 | GEN smithclean(GEN z) |
|---|
| 425 | GEN sqred(GEN a) |
|---|
| 426 | GEN sqred1(GEN a) |
|---|
| 427 | GEN sqred1intern(GEN a) |
|---|
| 428 | GEN sqred3(GEN a) |
|---|
| 429 | GEN zm_to_ZM(GEN z) |
|---|
| 430 | GEN zx_to_ZX(GEN z) |
|---|
| 431 | |
|---|
| 432 | # anal.c |
|---|
| 433 | |
|---|
| 434 | void addhelp(entree *ep, char *s) |
|---|
| 435 | void delete_named_var(entree *ep) |
|---|
| 436 | long delete_var() |
|---|
| 437 | entree *fetch_named_var(char *s, int doerr) |
|---|
| 438 | long fetch_user_var(char *s) |
|---|
| 439 | long fetch_var() |
|---|
| 440 | GEN flisexpr(char *t) |
|---|
| 441 | GEN flisseq(char *t) |
|---|
| 442 | void freeep(entree *ep) |
|---|
| 443 | entree *gp_variable(char *s) |
|---|
| 444 | long hashvalue(char *s) |
|---|
| 445 | entree* install(void *f, char *name, char *code) |
|---|
| 446 | entree *is_entry(char *s) |
|---|
| 447 | void kill0(entree *ep) |
|---|
| 448 | GEN lisexpr(char *t) |
|---|
| 449 | GEN lisseq(char *t) |
|---|
| 450 | long manage_var(long n, entree *ep) |
|---|
| 451 | void name_var(long n, char *s) |
|---|
| 452 | GEN readseq(char *c, int strict) |
|---|
| 453 | GEN strtoGENstr(char *s) |
|---|
| 454 | GEN type0(GEN x) |
|---|
| 455 | |
|---|
| 456 | # arith1.c |
|---|
| 457 | |
|---|
| 458 | GEN bestappr0(GEN x, GEN a, GEN b) |
|---|
| 459 | GEN bestappr(GEN x, GEN k) |
|---|
| 460 | long carrecomplet(GEN x, GEN *pt) |
|---|
| 461 | long cgcd(long a,long b) |
|---|
| 462 | void check_quaddisc(GEN x, long *s, long *r, char *f) |
|---|
| 463 | GEN chinese(GEN x, GEN y) |
|---|
| 464 | GEN chinois(GEN x, GEN y) |
|---|
| 465 | GEN classno2(GEN x) |
|---|
| 466 | GEN classno(GEN x) |
|---|
| 467 | long clcm(long a,long b) |
|---|
| 468 | GEN compimag(GEN x, GEN y) |
|---|
| 469 | GEN compimagraw(GEN x, GEN y) |
|---|
| 470 | GEN compraw(GEN x, GEN y) |
|---|
| 471 | GEN compreal(GEN x, GEN y) |
|---|
| 472 | GEN comprealraw(GEN x, GEN y) |
|---|
| 473 | GEN contfrac0(GEN x, GEN b, long flag) |
|---|
| 474 | GEN fibo(long n) |
|---|
| 475 | GEN Fp_gener_fact(GEN p, GEN fa) |
|---|
| 476 | GEN Fp_gener(GEN p) |
|---|
| 477 | GEN FpXQ_gener(GEN T, GEN p) |
|---|
| 478 | GEN fundunit(GEN x) |
|---|
| 479 | GEN gboundcf(GEN x, long k) |
|---|
| 480 | GEN gcarrecomplet(GEN x, GEN *pt) |
|---|
| 481 | GEN gcarreparfait(GEN x) |
|---|
| 482 | GEN gcf2(GEN b, GEN x) |
|---|
| 483 | GEN gcf(GEN x) |
|---|
| 484 | GEN gener(GEN m) |
|---|
| 485 | GEN gfundunit(GEN x) |
|---|
| 486 | GEN ggener(GEN m) |
|---|
| 487 | long gisanypower(GEN x, GEN *pty) |
|---|
| 488 | GEN gisfundamental(GEN x) |
|---|
| 489 | GEN gisprime(GEN x, long flag) |
|---|
| 490 | GEN gispseudoprime(GEN x, long flag) |
|---|
| 491 | GEN gispsp(GEN x) |
|---|
| 492 | GEN gkrogs(GEN x, long y) |
|---|
| 493 | GEN gkronecker(GEN x, GEN y) |
|---|
| 494 | GEN gmillerrabin(GEN n, long k) |
|---|
| 495 | GEN gnextprime(GEN n) |
|---|
| 496 | GEN gprecprime(GEN n) |
|---|
| 497 | GEN gracine(GEN a) |
|---|
| 498 | GEN gregula(GEN x, long prec) |
|---|
| 499 | GEN hclassno(GEN x) |
|---|
| 500 | long hil0(GEN x, GEN y, GEN p) |
|---|
| 501 | long hil(GEN x, GEN y, GEN p) |
|---|
| 502 | long isanypower(GEN x, GEN *y) |
|---|
| 503 | long isfundamental(GEN x) |
|---|
| 504 | long ispower(GEN x, GEN k, GEN *pty) |
|---|
| 505 | long isprimeAPRCL(GEN N) |
|---|
| 506 | long isprime(GEN x) |
|---|
| 507 | long isprimeSelfridge(GEN x) |
|---|
| 508 | long ispseudoprime(GEN x, long flag) |
|---|
| 509 | long ispsp(GEN x) |
|---|
| 510 | long krois(GEN x, long y) |
|---|
| 511 | long kronecker(GEN x, GEN y) |
|---|
| 512 | long krosi(long s, GEN x) |
|---|
| 513 | long kross(long x, long y) |
|---|
| 514 | long krouu(ulong x, ulong y) |
|---|
| 515 | GEN lcmii(GEN a, GEN b) |
|---|
| 516 | GEN mpfact(long n) |
|---|
| 517 | GEN mpfactr(long n, long prec) |
|---|
| 518 | GEN Fp_inv(GEN a, GEN m) |
|---|
| 519 | GEN Fp_invsafe(GEN a, GEN m) |
|---|
| 520 | GEN Fp_pow(GEN a, GEN n, GEN m) |
|---|
| 521 | GEN Fp_sqrt(GEN a, GEN p) |
|---|
| 522 | GEN Fp_sqrtn(GEN a, GEN n, GEN p, GEN *zetan) |
|---|
| 523 | GEN nucomp(GEN x, GEN y, GEN l) |
|---|
| 524 | GEN nudupl(GEN x, GEN l) |
|---|
| 525 | GEN nupow(GEN x, GEN n) |
|---|
| 526 | GEN order(GEN x) |
|---|
| 527 | GEN pnqn(GEN x) |
|---|
| 528 | GEN powraw(GEN x, long n) |
|---|
| 529 | GEN powrealraw(GEN x, long n) |
|---|
| 530 | GEN primeform(GEN x, GEN p, long prec) |
|---|
| 531 | GEN Qfb0(GEN x, GEN y, GEN z, GEN d, long prec) |
|---|
| 532 | GEN qfbclassno0(GEN x,long flag) |
|---|
| 533 | GEN qfbimagsolvep(GEN Q, GEN n) |
|---|
| 534 | GEN qfbred0(GEN x, long flag, GEN D, GEN isqrtD, GEN sqrtD) |
|---|
| 535 | GEN qfbsolve(GEN Q, GEN n) |
|---|
| 536 | GEN qfi(GEN x, GEN y, GEN z) |
|---|
| 537 | GEN qfr(GEN x, GEN y, GEN z, GEN d) |
|---|
| 538 | GEN quaddisc(GEN x) |
|---|
| 539 | GEN racine(GEN a) |
|---|
| 540 | GEN redimag(GEN x) |
|---|
| 541 | GEN redreal(GEN x) |
|---|
| 542 | GEN redrealnod(GEN x, GEN isqrtD) |
|---|
| 543 | GEN regula(GEN x, long prec) |
|---|
| 544 | GEN rhoreal(GEN x) |
|---|
| 545 | GEN rhorealnod(GEN x, GEN isqrtD) |
|---|
| 546 | GEN seq_umul(ulong a, ulong b) |
|---|
| 547 | GEN sqcompimag(GEN x) |
|---|
| 548 | GEN sqcompreal(GEN x) |
|---|
| 549 | ulong Fl_sqrt(ulong a, ulong p) |
|---|
| 550 | ulong Fl_gener_fact(ulong p, GEN fa) |
|---|
| 551 | ulong Fl_gener(ulong p) |
|---|
| 552 | GEN znstar(GEN x) |
|---|
| 553 | |
|---|
| 554 | # arith2.c |
|---|
| 555 | |
|---|
| 556 | GEN addprimes(GEN primes) |
|---|
| 557 | GEN auxdecomp(GEN n, long all) |
|---|
| 558 | long bigomega(GEN n) |
|---|
| 559 | GEN binaire(GEN x) |
|---|
| 560 | long bittest(GEN x, long n) |
|---|
| 561 | GEN boundfact(GEN n, long lim) |
|---|
| 562 | GEN core(GEN n) |
|---|
| 563 | GEN corepartial(GEN n, long l) |
|---|
| 564 | GEN core0(GEN n,long flag) |
|---|
| 565 | GEN core2(GEN n) |
|---|
| 566 | GEN core2partial(GEN n, long l) |
|---|
| 567 | GEN coredisc(GEN n) |
|---|
| 568 | GEN coredisc0(GEN n,long flag) |
|---|
| 569 | GEN coredisc2(GEN n) |
|---|
| 570 | GEN decomp(GEN n) |
|---|
| 571 | GEN decomp_small(long n) |
|---|
| 572 | GEN divisors(GEN n) |
|---|
| 573 | GEN factorint(GEN n, long flag) |
|---|
| 574 | GEN gbigomega(GEN n) |
|---|
| 575 | GEN gbitand(GEN x, GEN y) |
|---|
| 576 | GEN gbitneg(GEN x, long n) |
|---|
| 577 | GEN gbitnegimply(GEN x, GEN y) |
|---|
| 578 | GEN gbitor(GEN x, GEN y) |
|---|
| 579 | GEN gbittest(GEN x, GEN n) |
|---|
| 580 | GEN gbittest3(GEN x, GEN n, long c) |
|---|
| 581 | GEN gbitxor(GEN x, GEN y) |
|---|
| 582 | GEN gboundfact(GEN n, long lim) |
|---|
| 583 | GEN gissquarefree(GEN x) |
|---|
| 584 | GEN gmu(GEN n) |
|---|
| 585 | GEN gnumbdiv(GEN n) |
|---|
| 586 | GEN gomega(GEN n) |
|---|
| 587 | GEN gphi(GEN n) |
|---|
| 588 | GEN gsumdiv(GEN n) |
|---|
| 589 | GEN gsumdivk(GEN n,long k) |
|---|
| 590 | char* initprimes(ulong maxnum) |
|---|
| 591 | long issquarefree(GEN x) |
|---|
| 592 | ulong maxprime() |
|---|
| 593 | void maxprime_check(ulong c) |
|---|
| 594 | long mu(GEN n) |
|---|
| 595 | GEN numbdiv(GEN n) |
|---|
| 596 | long omega(GEN n) |
|---|
| 597 | GEN phi(GEN n) |
|---|
| 598 | GEN prime(long n) |
|---|
| 599 | GEN primepi(GEN x) |
|---|
| 600 | GEN primes(long n) |
|---|
| 601 | GEN removeprimes(GEN primes) |
|---|
| 602 | GEN smallfact(GEN n) |
|---|
| 603 | GEN sumdiv(GEN n) |
|---|
| 604 | GEN sumdivk(GEN n,long k) |
|---|
| 605 | |
|---|
| 606 | # base1.c |
|---|
| 607 | |
|---|
| 608 | GEN bnfnewprec(GEN nf, long prec) |
|---|
| 609 | GEN bnrnewprec(GEN bnr, long prec) |
|---|
| 610 | void check_pol_int(GEN x, char *s) |
|---|
| 611 | GEN check_units(GEN x, char *f) |
|---|
| 612 | void checkbid(GEN bid) |
|---|
| 613 | GEN checkbnf(GEN bnf) |
|---|
| 614 | GEN checkbnf_discard(GEN bnf) |
|---|
| 615 | void checkbnr(GEN bnr) |
|---|
| 616 | void checkbnrgen(GEN bnr) |
|---|
| 617 | void checkid(GEN x, long N) |
|---|
| 618 | GEN checknf(GEN nf) |
|---|
| 619 | GEN checknfelt_mod(GEN nf, GEN x, char *s) |
|---|
| 620 | void checkprimeid(GEN bid) |
|---|
| 621 | void checkrnf(GEN rnf) |
|---|
| 622 | GEN galois(GEN x, long prec) |
|---|
| 623 | GEN galoisapply(GEN nf, GEN aut, GEN x) |
|---|
| 624 | GEN get_bnf(GEN x,int *t) |
|---|
| 625 | GEN get_bnfpol(GEN x, GEN *bnf, GEN *nf) |
|---|
| 626 | GEN get_nf(GEN x,int *t) |
|---|
| 627 | GEN get_nfpol(GEN x, GEN *nf) |
|---|
| 628 | GEN get_primeid(GEN x) |
|---|
| 629 | GEN glambdak(GEN nfz, GEN s, long prec) |
|---|
| 630 | int gpolcomp(GEN p1, GEN p2) |
|---|
| 631 | GEN gsmith(GEN x) |
|---|
| 632 | GEN gsmith2(GEN x) |
|---|
| 633 | GEN gzetak(GEN nfz, GEN s, long prec) |
|---|
| 634 | GEN gzetakall(GEN nfz, GEN s, long flag, long prec) |
|---|
| 635 | GEN initalg(GEN x, long prec) |
|---|
| 636 | GEN initalgred(GEN x, long prec) |
|---|
| 637 | GEN initalgred2(GEN x, long prec) |
|---|
| 638 | GEN initzeta(GEN pol, long prec) |
|---|
| 639 | GEN mathnf0(GEN x,long flag) |
|---|
| 640 | GEN matsnf0(GEN x,long flag) |
|---|
| 641 | long nf_get_r1(GEN nf) |
|---|
| 642 | long nf_get_r2(GEN nf) |
|---|
| 643 | void nf_get_sign(GEN nf, long *r1, long *r2) |
|---|
| 644 | long nfgetprec(GEN x) |
|---|
| 645 | GEN nfinit0(GEN x,long flag, long prec) |
|---|
| 646 | GEN nfnewprec(GEN nf, long prec) |
|---|
| 647 | GEN nfnewprec_i(GEN nf, long prec) |
|---|
| 648 | GEN rootsof1(GEN x) |
|---|
| 649 | GEN tschirnhaus(GEN x) |
|---|
| 650 | |
|---|
| 651 | # base2.c |
|---|
| 652 | |
|---|
| 653 | GEN allbase(GEN f, int flag, GEN *dx, GEN *dK, GEN *index, GEN *ptw) |
|---|
| 654 | GEN base(GEN x, GEN *y) |
|---|
| 655 | GEN base2(GEN x, GEN *y) |
|---|
| 656 | void checkmodpr(GEN modpr) |
|---|
| 657 | GEN compositum(GEN pol1, GEN pol2) |
|---|
| 658 | GEN compositum2(GEN pol1, GEN pol2) |
|---|
| 659 | GEN discf(GEN x) |
|---|
| 660 | GEN discf2(GEN x) |
|---|
| 661 | GEN factoredbase(GEN x, GEN p, GEN *y) |
|---|
| 662 | GEN factoreddiscf(GEN x, GEN p) |
|---|
| 663 | GEN ff_to_nf(GEN x, GEN modpr) |
|---|
| 664 | GEN fix_relative_pol(GEN nf, GEN x, int chk_lead) |
|---|
| 665 | GEN gcdpm(GEN f1,GEN f2,GEN pm) |
|---|
| 666 | long idealval(GEN nf,GEN ix,GEN vp) |
|---|
| 667 | GEN idealprodprime(GEN nf, GEN L) |
|---|
| 668 | GEN indexpartial(GEN P, GEN DP) |
|---|
| 669 | GEN modprX(GEN x, GEN nf,GEN modpr) |
|---|
| 670 | GEN modprX_lift(GEN x, GEN modpr) |
|---|
| 671 | GEN modprM(GEN z, GEN nf,GEN modpr) |
|---|
| 672 | GEN modprM_lift(GEN z, GEN modpr) |
|---|
| 673 | GEN nf_to_ff_init(GEN nf, GEN *pr, GEN *T, GEN *p) |
|---|
| 674 | GEN nf_to_ff(GEN nf, GEN x, GEN modpr) |
|---|
| 675 | GEN nfbasis(GEN x, GEN *y,long flag,GEN p) |
|---|
| 676 | GEN nfbasis0(GEN x,long flag,GEN p) |
|---|
| 677 | GEN nfdiscf0(GEN x,long flag, GEN p) |
|---|
| 678 | GEN nfreducemodideal(GEN nf,GEN x,GEN ideal) |
|---|
| 679 | GEN nfreducemodpr(GEN nf, GEN x, GEN modpr) |
|---|
| 680 | GEN polcompositum0(GEN pol1, GEN pol2,long flag) |
|---|
| 681 | GEN primedec(GEN nf,GEN p) |
|---|
| 682 | GEN rnfbasis(GEN bnf, GEN order) |
|---|
| 683 | GEN rnfdet(GEN nf, GEN order) |
|---|
| 684 | GEN rnfdet2(GEN nf, GEN A, GEN I) |
|---|
| 685 | GEN rnfdiscf(GEN nf, GEN pol) |
|---|
| 686 | GEN rnfequation(GEN nf, GEN pol2) |
|---|
| 687 | GEN rnfequation0(GEN nf, GEN pol2, long flall) |
|---|
| 688 | GEN rnfequation2(GEN nf, GEN pol) |
|---|
| 689 | GEN rnfhermitebasis(GEN bnf, GEN order) |
|---|
| 690 | long rnfisfree(GEN bnf, GEN order) |
|---|
| 691 | GEN rnflllgram(GEN nf, GEN pol, GEN order,long prec) |
|---|
| 692 | GEN rnfpolred(GEN nf, GEN pol, long prec) |
|---|
| 693 | GEN rnfpolredabs(GEN nf, GEN pol, long flag) |
|---|
| 694 | GEN rnfpseudobasis(GEN nf, GEN pol) |
|---|
| 695 | GEN rnfsimplifybasis(GEN bnf, GEN order) |
|---|
| 696 | GEN rnfsteinitz(GEN nf, GEN order) |
|---|
| 697 | GEN smallbase(GEN x, GEN *y) |
|---|
| 698 | GEN smalldiscf(GEN x) |
|---|
| 699 | long val_fact(ulong n, ulong p) |
|---|
| 700 | GEN zk_to_ff_init(GEN nf, GEN *pr, GEN *T, GEN *p) |
|---|
| 701 | GEN zk_to_ff(GEN x, GEN modpr) |
|---|
| 702 | GEN zkmodprinit(GEN nf, GEN pr) |
|---|
| 703 | |
|---|
| 704 | # base3.c |
|---|
| 705 | |
|---|
| 706 | GEN _algtobasis(GEN nf, GEN x) |
|---|
| 707 | GEN _algtobasis_cp(GEN nf, GEN x) |
|---|
| 708 | GEN _basistoalg(GEN nf, GEN x) |
|---|
| 709 | GEN algtobasis(GEN nf, GEN x) |
|---|
| 710 | GEN algtobasis_i(GEN nf,GEN x) |
|---|
| 711 | GEN arch_to_perm(GEN arch) |
|---|
| 712 | GEN basistoalg(GEN nf, GEN x) |
|---|
| 713 | GEN element_div(GEN nf, GEN x, GEN y) |
|---|
| 714 | GEN element_inv(GEN nf, GEN x) |
|---|
| 715 | GEN element_invmodideal(GEN nf, GEN x, GEN ideal) |
|---|
| 716 | GEN element_mul(GEN nf,GEN x,GEN y) |
|---|
| 717 | GEN element_muli(GEN nf,GEN x,GEN y) |
|---|
| 718 | GEN element_mulid(GEN nf, GEN x, long i) |
|---|
| 719 | GEN element_mulvec(GEN nf, GEN x, GEN v) |
|---|
| 720 | GEN element_pow(GEN nf,GEN x,GEN k) |
|---|
| 721 | GEN element_pow_mod_p(GEN nf, GEN x, GEN n, GEN p) |
|---|
| 722 | GEN element_powmodideal(GEN nf,GEN x,GEN k,GEN ideal) |
|---|
| 723 | GEN element_powmodidele(GEN nf,GEN x,GEN k,GEN idele,GEN structarch) |
|---|
| 724 | GEN element_sqr(GEN nf,GEN x) |
|---|
| 725 | GEN element_sqri(GEN nf, GEN x) |
|---|
| 726 | long element_val(GEN nf, GEN x, GEN vp) |
|---|
| 727 | GEN eltmul_get_table(GEN nf, GEN x) |
|---|
| 728 | GEN ideallist(GEN nf,long bound) |
|---|
| 729 | GEN ideallist0(GEN nf,long bound, long flag) |
|---|
| 730 | GEN ideallistarch(GEN nf, GEN list, GEN arch) |
|---|
| 731 | GEN ideallistarch0(GEN nf, GEN list, GEN arch,long flag) |
|---|
| 732 | GEN ideallistarchgen(GEN nf, GEN list, GEN arch) |
|---|
| 733 | GEN ideallistunit(GEN nf,long bound) |
|---|
| 734 | GEN ideallistunitarch(GEN bnf,GEN list,GEN arch) |
|---|
| 735 | GEN ideallistunitarchgen(GEN bnf,GEN list,GEN arch) |
|---|
| 736 | GEN ideallistunitgen(GEN nf,long bound) |
|---|
| 737 | GEN ideallistzstar(GEN nf,long bound) |
|---|
| 738 | GEN ideallistzstargen(GEN nf,long bound) |
|---|
| 739 | GEN idealstar0(GEN nf, GEN x,long flag) |
|---|
| 740 | int isnfscalar(GEN x) |
|---|
| 741 | GEN lllreducemodmatrix(GEN x,GEN y) |
|---|
| 742 | GEN nfdiveuc(GEN nf, GEN a, GEN b) |
|---|
| 743 | GEN nfdivrem(GEN nf, GEN a, GEN b) |
|---|
| 744 | GEN nfmod(GEN nf, GEN a, GEN b) |
|---|
| 745 | GEN nfreducemodidele(GEN nf,GEN g,GEN idele,GEN structarch) |
|---|
| 746 | GEN reducemodinvertible(GEN x, GEN y) |
|---|
| 747 | GEN reducemodmatrix(GEN x, GEN y) |
|---|
| 748 | GEN reducemodHNF(GEN x, GEN y, GEN *Q) |
|---|
| 749 | GEN set_sign_mod_idele(GEN nf, GEN x, GEN y, GEN idele, GEN sarch) |
|---|
| 750 | GEN smithrel(GEN H, GEN *newU, GEN *newUi) |
|---|
| 751 | GEN vecmodii(GEN a, GEN b) |
|---|
| 752 | GEN zarchstar(GEN nf,GEN x,GEN arch) |
|---|
| 753 | GEN zideallog(GEN nf,GEN x,GEN bigideal) |
|---|
| 754 | GEN zidealstar(GEN nf, GEN x) |
|---|
| 755 | GEN zidealstarinit(GEN nf, GEN x) |
|---|
| 756 | GEN zidealstarinitall(GEN nf, GEN x,long flun) |
|---|
| 757 | GEN zidealstarinitgen(GEN nf, GEN x) |
|---|
| 758 | GEN znlog(GEN x, GEN g) |
|---|
| 759 | GEN zsigne(GEN nf,GEN alpha,GEN arch) |
|---|
| 760 | GEN zsigns(GEN nf,GEN alpha) |
|---|
| 761 | |
|---|
| 762 | # base4.c |
|---|
| 763 | |
|---|
| 764 | int Z_ishnfall(GEN x) |
|---|
| 765 | GEN element_divmodpr(GEN nf, GEN x, GEN y, GEN modpr) |
|---|
| 766 | GEN element_invmodpr(GEN nf, GEN y, GEN modpr) |
|---|
| 767 | GEN element_mulmodpr(GEN nf, GEN x, GEN y, GEN modpr) |
|---|
| 768 | GEN element_powmodpr(GEN nf, GEN x, GEN k, GEN modpr) |
|---|
| 769 | GEN element_reduce(GEN nf, GEN x, GEN ideal) |
|---|
| 770 | GEN ideal_two_elt(GEN nf, GEN ix) |
|---|
| 771 | GEN ideal_two_elt0(GEN nf, GEN ix, GEN a) |
|---|
| 772 | GEN ideal_two_elt2(GEN nf, GEN x, GEN a) |
|---|
| 773 | GEN idealadd(GEN nf, GEN x, GEN y) |
|---|
| 774 | GEN idealaddmultoone(GEN nf, GEN list) |
|---|
| 775 | GEN idealaddtoone(GEN nf, GEN x, GEN y) |
|---|
| 776 | GEN idealaddtoone0(GEN nf, GEN x, GEN y) |
|---|
| 777 | GEN idealappr(GEN nf, GEN x) |
|---|
| 778 | GEN idealappr0(GEN nf, GEN x, long fl) |
|---|
| 779 | GEN idealapprfact(GEN nf, GEN x) |
|---|
| 780 | GEN idealchinese(GEN nf, GEN x, GEN y) |
|---|
| 781 | GEN idealcoprime(GEN nf, GEN x, GEN y) |
|---|
| 782 | GEN idealdiv(GEN nf, GEN x, GEN y) |
|---|
| 783 | GEN idealdiv0(GEN nf, GEN x, GEN y,long flag) |
|---|
| 784 | GEN idealdivexact(GEN nf, GEN x, GEN y) |
|---|
| 785 | GEN idealdivpowprime(GEN nf, GEN x, GEN vp, GEN n) |
|---|
| 786 | GEN idealmulpowprime(GEN nf, GEN x, GEN vp, GEN n) |
|---|
| 787 | GEN idealfactor(GEN nf, GEN x) |
|---|
| 788 | GEN idealhermite(GEN nf, GEN x) |
|---|
| 789 | GEN idealhermite2(GEN nf, GEN a, GEN b) |
|---|
| 790 | GEN idealhnf0(GEN nf, GEN a, GEN b) |
|---|
| 791 | GEN idealintersect(GEN nf, GEN x, GEN y) |
|---|
| 792 | GEN idealinv(GEN nf, GEN ix) |
|---|
| 793 | GEN ideallllred(GEN nf,GEN ix,GEN vdir,long prec) |
|---|
| 794 | GEN idealred_elt(GEN nf, GEN I) |
|---|
| 795 | GEN ideallllred_elt(GEN nf, GEN I, GEN vdir) |
|---|
| 796 | GEN idealmul(GEN nf, GEN ix, GEN iy) |
|---|
| 797 | GEN idealmul0(GEN nf, GEN ix, GEN iy, long flag, long prec) |
|---|
| 798 | GEN idealmulh(GEN nf, GEN ix, GEN iy) |
|---|
| 799 | GEN idealmulprime(GEN nf,GEN ix,GEN vp) |
|---|
| 800 | GEN idealmulred(GEN nf, GEN ix, GEN iy, long prec) |
|---|
| 801 | GEN idealnorm(GEN nf, GEN x) |
|---|
| 802 | GEN idealpow(GEN nf, GEN ix, GEN n) |
|---|
| 803 | GEN idealpow0(GEN nf, GEN ix, GEN n, long flag, long prec) |
|---|
| 804 | GEN idealpowred(GEN nf, GEN ix, GEN n,long prec) |
|---|
| 805 | GEN idealpows(GEN nf, GEN ideal, long iexp) |
|---|
| 806 | long idealtyp(GEN *ideal, GEN *arch) |
|---|
| 807 | GEN ideleaddone(GEN nf, GEN x, GEN idele) |
|---|
| 808 | int ishnfall(GEN x) |
|---|
| 809 | int isidentity(GEN x) |
|---|
| 810 | GEN hnfall_i(GEN A, GEN *ptB, long remove) |
|---|
| 811 | long isideal(GEN nf,GEN x) |
|---|
| 812 | long isinvector(GEN v, GEN x, long n) |
|---|
| 813 | GEN minideal(GEN nf,GEN ix,GEN vdir,long prec) |
|---|
| 814 | GEN mul_content(GEN cx, GEN cy) |
|---|
| 815 | GEN nfdetint(GEN nf,GEN pseudo) |
|---|
| 816 | GEN nfhermite(GEN nf, GEN x) |
|---|
| 817 | GEN nfhermitemod(GEN nf, GEN x, GEN detmat) |
|---|
| 818 | GEN nfkermodpr(GEN nf, GEN x, GEN modpr) |
|---|
| 819 | GEN nfmodprinit(GEN nf, GEN pr) |
|---|
| 820 | GEN nfsmith(GEN nf, GEN x) |
|---|
| 821 | GEN nfsolvemodpr(GEN nf, GEN a, GEN b, GEN modpr) |
|---|
| 822 | GEN prime_to_ideal(GEN nf, GEN vp) |
|---|
| 823 | GEN principalideal(GEN nf, GEN a) |
|---|
| 824 | GEN principalidele(GEN nf, GEN a, long prec) |
|---|
| 825 | GEN vecdiv(GEN x, GEN y) |
|---|
| 826 | GEN vecinv(GEN x) |
|---|
| 827 | GEN vecmul(GEN x, GEN y) |
|---|
| 828 | GEN vecpow(GEN x, GEN n) |
|---|
| 829 | |
|---|
| 830 | # base5.c |
|---|
| 831 | |
|---|
| 832 | GEN lift_to_pol(GEN x) |
|---|
| 833 | GEN matalgtobasis(GEN nf, GEN x) |
|---|
| 834 | GEN matbasistoalg(GEN nf, GEN x) |
|---|
| 835 | GEN rnfalgtobasis(GEN rnf, GEN x) |
|---|
| 836 | GEN rnfbasistoalg(GEN rnf, GEN x) |
|---|
| 837 | GEN rnfelementabstorel(GEN rnf, GEN x) |
|---|
| 838 | GEN rnfelementdown(GEN rnf, GEN x) |
|---|
| 839 | GEN rnfelementreltoabs(GEN rnf, GEN x) |
|---|
| 840 | GEN rnfelementup(GEN rnf, GEN x) |
|---|
| 841 | GEN rnfidealabstorel(GEN rnf, GEN x) |
|---|
| 842 | GEN rnfidealdown(GEN rnf, GEN x) |
|---|
| 843 | GEN rnfidealhermite(GEN rnf, GEN x) |
|---|
| 844 | GEN rnfidealmul(GEN rnf,GEN x,GEN y) |
|---|
| 845 | GEN rnfidealnormabs(GEN rnf, GEN x) |
|---|
| 846 | GEN rnfidealnormrel(GEN rnf, GEN x) |
|---|
| 847 | GEN rnfidealreltoabs(GEN rnf, GEN x) |
|---|
| 848 | GEN rnfidealtwoelement(GEN rnf,GEN x) |
|---|
| 849 | GEN rnfidealup(GEN rnf, GEN x) |
|---|
| 850 | GEN rnfinitalg(GEN nf,GEN pol,long prec) |
|---|
| 851 | |
|---|
| 852 | # bibli1.c |
|---|
| 853 | |
|---|
| 854 | GEN ZM_zc_mul(GEN x, GEN y) |
|---|
| 855 | GEN ZM_zm_mul(GEN x, GEN y) |
|---|
| 856 | GEN T2_from_embed(GEN x, long r1) |
|---|
| 857 | GEN algdep(GEN x, long n, long prec) |
|---|
| 858 | GEN algdep0(GEN x, long n, long bit,long prec) |
|---|
| 859 | GEN algdep2(GEN x, long n, long bit) |
|---|
| 860 | GEN factoredpolred(GEN x, GEN p) |
|---|
| 861 | GEN factoredpolred2(GEN x, GEN p) |
|---|
| 862 | GEN kerint(GEN x) |
|---|
| 863 | GEN kerint1(GEN x) |
|---|
| 864 | GEN lindep(GEN x, long prec) |
|---|
| 865 | GEN lindep0(GEN x, long flag,long prec) |
|---|
| 866 | GEN lindep2(GEN x, long bit) |
|---|
| 867 | GEN lll(GEN x, long prec) |
|---|
| 868 | GEN lllgen(GEN x) |
|---|
| 869 | GEN lllgram(GEN x, long prec) |
|---|
| 870 | GEN lllgramall(GEN x, long alpha, long flag) |
|---|
| 871 | GEN lllgramgen(GEN x) |
|---|
| 872 | GEN lllgramint(GEN x) |
|---|
| 873 | GEN lllgramintern(GEN x, long alpha, long flag, long prec) |
|---|
| 874 | GEN lllgramkerim(GEN x) |
|---|
| 875 | GEN lllgramkerimgen(GEN x) |
|---|
| 876 | GEN lllint(GEN x) |
|---|
| 877 | GEN lllint_i(GEN x, long alpha, int gram, GEN *h, GEN *ptfl, GEN *ptB) |
|---|
| 878 | GEN lllint_ip(GEN x, long alpha) |
|---|
| 879 | GEN lllintern(GEN x, long D, long flag, long prec) |
|---|
| 880 | GEN lllintpartial(GEN mat) |
|---|
| 881 | GEN lllintpartial_ip(GEN mat) |
|---|
| 882 | GEN lllkerim(GEN x) |
|---|
| 883 | GEN lllkerimgen(GEN x) |
|---|
| 884 | GEN matkerint0(GEN x,long flag) |
|---|
| 885 | GEN minim(GEN a, GEN borne, GEN stockmax) |
|---|
| 886 | GEN nf_get_LLL(GEN nf) |
|---|
| 887 | GEN qfrep0(GEN a, GEN borne, long flag) |
|---|
| 888 | GEN qfminim0(GEN a, GEN borne, GEN stockmax,long flag, long prec) |
|---|
| 889 | GEN minim2(GEN a, GEN borne, GEN stockmax) |
|---|
| 890 | GEN ordred(GEN x) |
|---|
| 891 | GEN perf(GEN a) |
|---|
| 892 | GEN polred(GEN x) |
|---|
| 893 | GEN polred0(GEN x, long flag, GEN p) |
|---|
| 894 | GEN polred2(GEN x) |
|---|
| 895 | GEN polredabs(GEN x) |
|---|
| 896 | GEN polredabs0(GEN x, long flag) |
|---|
| 897 | GEN polredabs2(GEN x) |
|---|
| 898 | GEN polredabsall(GEN x, long flun) |
|---|
| 899 | GEN qflll0(GEN x, long flag, long prec) |
|---|
| 900 | GEN qflllgram0(GEN x, long flag, long prec) |
|---|
| 901 | GEN smallpolred(GEN x) |
|---|
| 902 | GEN smallpolred2(GEN x) |
|---|
| 903 | char *stackmalloc(size_t N) |
|---|
| 904 | GEN zncoppersmith(GEN P0, GEN N, GEN X, GEN B) |
|---|
| 905 | |
|---|
| 906 | # bibli2.c |
|---|
| 907 | |
|---|
| 908 | GEN binome(GEN x, long k) |
|---|
| 909 | int cmp_pol(GEN x, GEN y) |
|---|
| 910 | int cmp_prime_ideal(GEN x, GEN y) |
|---|
| 911 | int cmp_prime_over_p(GEN x, GEN y) |
|---|
| 912 | int cmp_vecint(GEN x, GEN y) |
|---|
| 913 | GEN convol(GEN x, GEN y) |
|---|
| 914 | GEN cyclo(long n, long v) |
|---|
| 915 | GEN dirdiv(GEN x, GEN y) |
|---|
| 916 | GEN dirmul(GEN x, GEN y) |
|---|
| 917 | GEN dirzetak(GEN nf, GEN b) |
|---|
| 918 | long gen_search(GEN x, GEN y, int flag, int (*cmp)(GEN,GEN)) |
|---|
| 919 | GEN gen_setminus(GEN set1, GEN set2, int (*cmp)(GEN,GEN)) |
|---|
| 920 | GEN gen_sort(GEN x, int flag, int (*cmp)(GEN,GEN)) |
|---|
| 921 | GEN genrand(GEN N) |
|---|
| 922 | GEN getheap() |
|---|
| 923 | long getrand() |
|---|
| 924 | long getstack() |
|---|
| 925 | long gettime() |
|---|
| 926 | GEN gprec(GEN x, long l) |
|---|
| 927 | GEN gprec_trunc(GEN x, long pr) |
|---|
| 928 | GEN gprec_w(GEN x, long pr) |
|---|
| 929 | GEN ggrando(GEN x, long n) |
|---|
| 930 | GEN gtor(GEN x, long l) |
|---|
| 931 | GEN gtoset(GEN x) |
|---|
| 932 | GEN indexlexsort(GEN x) |
|---|
| 933 | GEN indexsort(GEN x) |
|---|
| 934 | GEN laplace(GEN x) |
|---|
| 935 | GEN legendre(long n, long v) |
|---|
| 936 | GEN lexsort(GEN x) |
|---|
| 937 | GEN mathilbert(long n) |
|---|
| 938 | GEN matqpascal(long n, GEN q) |
|---|
| 939 | GEN modreverse_i(GEN a, GEN T) |
|---|
| 940 | GEN numtoperm(long n, GEN x) |
|---|
| 941 | int pari_compare_int(int *a,int *b) |
|---|
| 942 | int pari_compare_long(long *a,long *b) |
|---|
| 943 | GEN permtonum(GEN x) |
|---|
| 944 | GEN polint(GEN xa, GEN ya, GEN x, GEN *dy) |
|---|
| 945 | GEN polrecip(GEN x) |
|---|
| 946 | GEN polymodrecip(GEN x) |
|---|
| 947 | GEN roots_to_pol(GEN a, long v) |
|---|
| 948 | GEN setintersect(GEN x, GEN y) |
|---|
| 949 | long setisset(GEN x) |
|---|
| 950 | GEN setminus(GEN x, GEN y) |
|---|
| 951 | long setrand(long seed) |
|---|
| 952 | long setsearch(GEN x, GEN y, long flag) |
|---|
| 953 | GEN setunion(GEN x, GEN y) |
|---|
| 954 | GEN sindexlexsort(GEN x) |
|---|
| 955 | GEN sindexsort(GEN x) |
|---|
| 956 | GEN sort(GEN x) |
|---|
| 957 | long tablesearch(GEN T, GEN x, int (*cmp)(GEN,GEN)) |
|---|
| 958 | GEN tayl(GEN x, long v, long precdl) |
|---|
| 959 | GEN tchebi(long n, long v) |
|---|
| 960 | GEN vecbinome(long n) |
|---|
| 961 | GEN vecsort(GEN x, GEN k) |
|---|
| 962 | GEN vecsort0(GEN x, GEN k, long flag) |
|---|
| 963 | |
|---|
| 964 | # buch1.c |
|---|
| 965 | |
|---|
| 966 | GEN buchimag(GEN D, GEN gcbach, GEN gcbach2, GEN gCO) |
|---|
| 967 | GEN buchreal(GEN D, GEN gsens, GEN gcbach, GEN gcbach2, GEN gRELSUP, long prec) |
|---|
| 968 | GEN cgetalloc(long t, size_t l) |
|---|
| 969 | GEN quadclassunit0(GEN x, long flag,GEN data, long prec) |
|---|
| 970 | GEN quadhilbert(GEN D, GEN flag, long prec) |
|---|
| 971 | GEN quadray(GEN bnf, GEN f, GEN flag, long prec) |
|---|
| 972 | |
|---|
| 973 | |
|---|
| 974 | # buch2.c |
|---|
| 975 | |
|---|
| 976 | GEN bnfclassunit0(GEN P,long flag,GEN data,long prec) |
|---|
| 977 | GEN bnfinit0(GEN P,long flag,GEN data,long prec) |
|---|
| 978 | GEN bnfmake(GEN sbnf,long prec) |
|---|
| 979 | GEN buchall(GEN P, double bach, double bach2, long nbrelpid, long flun, long prec) |
|---|
| 980 | GEN buchfu(GEN bignf) |
|---|
| 981 | GEN check_and_build_obj(GEN S, int tag, GEN (*build)(GEN)) |
|---|
| 982 | GEN classgrouponly(GEN P,GEN data,long prec) |
|---|
| 983 | GEN isprincipal(GEN bignf, GEN x) |
|---|
| 984 | GEN isprincipalall(GEN bignf, GEN x,long flall) |
|---|
| 985 | GEN isprincipalfact(GEN bnf,GEN P, GEN e, GEN C, long flag) |
|---|
| 986 | GEN isprincipalforce(GEN bignf,GEN x) |
|---|
| 987 | GEN isprincipalgen(GEN bignf, GEN x) |
|---|
| 988 | GEN isprincipalgenforce(GEN bignf,GEN x) |
|---|
| 989 | GEN isunit(GEN bignf, GEN x) |
|---|
| 990 | GEN quick_isprincipalgen(GEN bnf, GEN x) |
|---|
| 991 | GEN regulator(GEN P,GEN data,long prec) |
|---|
| 992 | GEN signunits(GEN bignf) |
|---|
| 993 | GEN smallbuchinit(GEN pol,double bach,double bach2,long nbrelpid,long prec) |
|---|
| 994 | GEN zsignunits(GEN bnf, GEN archp, int add_zu) |
|---|
| 995 | |
|---|
| 996 | # buch3.c |
|---|
| 997 | |
|---|
| 998 | GEN bnrclass0(GEN bignf, GEN ideal, long flag) |
|---|
| 999 | GEN bnrconductor(GEN arg0,GEN arg1,GEN arg2,GEN flag) |
|---|
| 1000 | GEN bnrconductorofchar(GEN bnr,GEN chi) |
|---|
| 1001 | GEN bnrdisc0(GEN arg0, GEN arg1, GEN arg2, long flag) |
|---|
| 1002 | GEN bnrdisclist0(GEN bnf,GEN borne, GEN arch, long all) |
|---|
| 1003 | GEN bnrinit0(GEN bignf,GEN ideal,long flag) |
|---|
| 1004 | long bnrisconductor(GEN arg0,GEN arg1,GEN arg2) |
|---|
| 1005 | GEN buchnarrow(GEN bignf) |
|---|
| 1006 | GEN buchray(GEN bignf,GEN ideal) |
|---|
| 1007 | GEN buchrayinit(GEN bignf,GEN ideal) |
|---|
| 1008 | GEN buchrayinitgen(GEN bignf,GEN ideal) |
|---|
| 1009 | long certifybuchall(GEN bnf) |
|---|
| 1010 | GEN conductor(GEN bnr,GEN subgroup,long all) |
|---|
| 1011 | GEN decodemodule(GEN nf, GEN fa) |
|---|
| 1012 | GEN discrayabs(GEN bnr,GEN subgroup) |
|---|
| 1013 | GEN discrayabscond(GEN bnr,GEN subgroup) |
|---|
| 1014 | GEN discrayabslist(GEN bnf,GEN listes) |
|---|
| 1015 | GEN discrayabslistarch(GEN bnf, GEN arch, long bound) |
|---|
| 1016 | GEN discrayabslistlong(GEN bnf, long bound) |
|---|
| 1017 | GEN discrayrel(GEN bnr,GEN subgroup) |
|---|
| 1018 | GEN discrayrelcond(GEN bnr,GEN subgroup) |
|---|
| 1019 | GEN idealmodidele(GEN bnr, GEN x) |
|---|
| 1020 | GEN isprincipalray(GEN bignf, GEN x) |
|---|
| 1021 | GEN isprincipalrayall(GEN bignf, GEN x,long flall) |
|---|
| 1022 | GEN isprincipalraygen(GEN bignf, GEN x) |
|---|
| 1023 | GEN rayclassno(GEN bignf,GEN ideal) |
|---|
| 1024 | GEN rayclassnolist(GEN bnf,GEN listes) |
|---|
| 1025 | GEN rnfconductor(GEN bnf, GEN polrel, long flag) |
|---|
| 1026 | GEN rnfkummer(GEN bnr, GEN subgroup, long all, long prec) |
|---|
| 1027 | GEN rnfnormgroup(GEN bnr, GEN polrel) |
|---|
| 1028 | GEN subgrouplist0(GEN bnr, GEN indexbound, long all) |
|---|
| 1029 | |
|---|
| 1030 | # buch4.c |
|---|
| 1031 | |
|---|
| 1032 | GEN bnfisnorm(GEN bnf,GEN x,long flag,long PREC) |
|---|
| 1033 | GEN rnfisnorm(GEN S, GEN x, long flag) |
|---|
| 1034 | GEN rnfisnorminit(GEN bnf, GEN relpol, int galois) |
|---|
| 1035 | GEN bnfissunit(GEN bnf,GEN suni,GEN x) |
|---|
| 1036 | GEN bnfsunit(GEN bnf,GEN s,long PREC) |
|---|
| 1037 | long nfhilbert(GEN bnf,GEN a,GEN b) |
|---|
| 1038 | long nfhilbert0(GEN bnf,GEN a,GEN b,GEN p) |
|---|
| 1039 | long nfhilbertp(GEN bnf,GEN a,GEN b,GEN p) |
|---|
| 1040 | long qpsoluble(GEN pol,GEN p) |
|---|
| 1041 | long qpsolublenf(GEN bnf,GEN pol,GEN p) |
|---|
| 1042 | long zpsoluble(GEN pol,GEN p) |
|---|
| 1043 | long zpsolublenf(GEN bnf,GEN pol,GEN p) |
|---|
| 1044 | |
|---|
| 1045 | # elliptic.c |
|---|
| 1046 | |
|---|
| 1047 | GEN addell(GEN e, GEN z1, GEN z2) |
|---|
| 1048 | GEN akell(GEN e, GEN n) |
|---|
| 1049 | GEN anell(GEN e, long n) |
|---|
| 1050 | GEN apell(GEN e, GEN p) |
|---|
| 1051 | GEN apell2(GEN e, GEN p) |
|---|
| 1052 | GEN bilhell(GEN e, GEN z1, GEN z2, long prec) |
|---|
| 1053 | GEN coordch(GEN e, GEN ch) |
|---|
| 1054 | GEN ellap0(GEN e, GEN p, long flag) |
|---|
| 1055 | GEN elleisnum(GEN om, long k, long flag, long prec) |
|---|
| 1056 | GEN elleta(GEN om, long prec) |
|---|
| 1057 | GEN ellheight0(GEN e, GEN a, long flag,long prec) |
|---|
| 1058 | GEN ellinit0(GEN x,long flag,long prec) |
|---|
| 1059 | GEN ellminimalmodel(GEN E, GEN *ptv) |
|---|
| 1060 | long ellrootno(GEN e, GEN p) |
|---|
| 1061 | GEN ellsigma(GEN om, GEN z, long flag, long prec) |
|---|
| 1062 | GEN elltors0(GEN e, long flag) |
|---|
| 1063 | GEN ellwp0(GEN e, GEN z, long flag, long prec, long PREC) |
|---|
| 1064 | |
|---|
| 1065 | GEN ellzeta(GEN om, GEN z, long prec) |
|---|
| 1066 | GEN ghell(GEN e, GEN a, long prec) |
|---|
| 1067 | GEN ghell2(GEN e, GEN a, long prec) |
|---|
| 1068 | GEN globalreduction(GEN e1) |
|---|
| 1069 | GEN initell(GEN x, long prec) |
|---|
| 1070 | GEN elllocalred(GEN e, GEN p1) |
|---|
| 1071 | GEN lseriesell(GEN e, GEN s, GEN A, long prec) |
|---|
| 1072 | GEN mathell(GEN e, GEN x, long prec) |
|---|
| 1073 | int oncurve(GEN e, GEN z) |
|---|
| 1074 | GEN ordell(GEN e, GEN x, long prec) |
|---|
| 1075 | GEN orderell(GEN e, GEN p) |
|---|
| 1076 | GEN pointch(GEN x, GEN ch) |
|---|
| 1077 | GEN pointell(GEN e, GEN z, long prec) |
|---|
| 1078 | GEN powell(GEN e, GEN z, GEN n) |
|---|
| 1079 | GEN smallinitell(GEN x) |
|---|
| 1080 | GEN subell(GEN e, GEN z1, GEN z2) |
|---|
| 1081 | GEN taniyama(GEN e) |
|---|
| 1082 | GEN torsell(GEN e) |
|---|
| 1083 | GEN weipell(GEN e, long precdl) |
|---|
| 1084 | GEN zell(GEN e, GEN z, long prec) |
|---|
| 1085 | |
|---|
| 1086 | # es.c |
|---|
| 1087 | GEN GENtocanonicalstr(GEN x) |
|---|
| 1088 | GEN GENtoGENstr(GEN x) |
|---|
| 1089 | char* GENtoTeXstr(GEN x) |
|---|
| 1090 | char* GENtostr(GEN x) |
|---|
| 1091 | GEN Str(GEN g) |
|---|
| 1092 | GEN Strchr(GEN g) |
|---|
| 1093 | GEN Strexpand(GEN g) |
|---|
| 1094 | GEN Strtex(GEN g) |
|---|
| 1095 | void brute(GEN g, char format, long dec) |
|---|
| 1096 | void bruteall(GEN g, char f, long d, long sp) |
|---|
| 1097 | void bruterr(GEN x,char format,long dec) |
|---|
| 1098 | void error0(GEN g) |
|---|
| 1099 | void etatpile(unsigned int n) |
|---|
| 1100 | char* expand_tilde(char *s) |
|---|
| 1101 | int file_is_binary(FILE *f) |
|---|
| 1102 | void flusherr() |
|---|
| 1103 | void fprintferr(char* pat, ...) |
|---|
| 1104 | void killallfiles(int check) |
|---|
| 1105 | int killfile(pariFILE *f) |
|---|
| 1106 | GEN lisGEN(FILE *f) |
|---|
| 1107 | void matbrute(GEN g, char format, long dec) |
|---|
| 1108 | pariFILE* newfile(FILE *f, char *name, int type) |
|---|
| 1109 | void os_close(long fd) |
|---|
| 1110 | char* os_getenv(char *s) |
|---|
| 1111 | long os_open(char *s, int mode) |
|---|
| 1112 | void os_read(long fd, char ch[], long s) |
|---|
| 1113 | void (*os_signal(int sig, void (*f)(int)))(int) |
|---|
| 1114 | void outbeaut(GEN x) |
|---|
| 1115 | void outbeauterr(GEN x) |
|---|
| 1116 | void outbrute(GEN x) |
|---|
| 1117 | void outerr(GEN x) |
|---|
| 1118 | void outmat(GEN x) |
|---|
| 1119 | void output(GEN x) |
|---|
| 1120 | void outsor(GEN x) |
|---|
| 1121 | void outtex(GEN x) |
|---|
| 1122 | char* pGENtostr(GEN g, long flag) |
|---|
| 1123 | void pari_fclose(pariFILE *f) |
|---|
| 1124 | pariFILE* pari_fopen(char *s, char *mode) |
|---|
| 1125 | pariFILE* pari_safefopen(char *s, char *mode) |
|---|
| 1126 | char* pari_strdup(char *s) |
|---|
| 1127 | char* pari_strndup(char *s, long n) |
|---|
| 1128 | char* pari_unique_filename(char *s) |
|---|
| 1129 | void pari_unlink(char *s) |
|---|
| 1130 | void pariflush() |
|---|
| 1131 | void pariputc(char c) |
|---|
| 1132 | void pariputs(char *s) |
|---|
| 1133 | void pariputsf(char *format, ...) |
|---|
| 1134 | int popinfile() |
|---|
| 1135 | #void print(GEN g) # syntax error |
|---|
| 1136 | void print1(GEN g) |
|---|
| 1137 | void printp(GEN g) |
|---|
| 1138 | void printp1(GEN g) |
|---|
| 1139 | void printtex(GEN g) |
|---|
| 1140 | GEN readbin(char *name, FILE *f) |
|---|
| 1141 | void sor(GEN g, char fo, long dd, long chmp) |
|---|
| 1142 | void switchin(char *name) |
|---|
| 1143 | void switchout(char *name) |
|---|
| 1144 | void texe(GEN g, char format, long dec) |
|---|
| 1145 | pariFILE* try_pipe(char *cmd, int flag) |
|---|
| 1146 | char* type_name(long t) |
|---|
| 1147 | void voir(GEN x, long nb) |
|---|
| 1148 | #void vpariputs(char* format, va_list args) |
|---|
| 1149 | void write0(char *s, GEN g) |
|---|
| 1150 | void write1(char *s, GEN g) |
|---|
| 1151 | void writebin(char *name, GEN x) |
|---|
| 1152 | void writetex(char *s, GEN g) |
|---|
| 1153 | |
|---|
| 1154 | # galconj.c |
|---|
| 1155 | |
|---|
| 1156 | GEN checkgal(GEN gal) |
|---|
| 1157 | GEN galoisconj(GEN nf) |
|---|
| 1158 | GEN galoisconj0(GEN nf, long flag, GEN d, long prec) |
|---|
| 1159 | GEN galoisconj2(GEN x, long nbmax, long prec) |
|---|
| 1160 | GEN galoisconj4(GEN T, GEN den, long flag, long karma) |
|---|
| 1161 | GEN galoisexport(GEN gal, long format) |
|---|
| 1162 | GEN galoisfixedfield(GEN gal, GEN v, long flag, long y) |
|---|
| 1163 | GEN galoisidentify(GEN gal) |
|---|
| 1164 | GEN galoisinit(GEN nf, GEN den, long karma) |
|---|
| 1165 | GEN galoisisabelian(GEN gal, long flag) |
|---|
| 1166 | GEN galoispermtopol(GEN gal, GEN perm) |
|---|
| 1167 | GEN galoissubgroups(GEN G) |
|---|
| 1168 | GEN galoissubfields(GEN G, long flag, long v) |
|---|
| 1169 | long numberofconjugates(GEN T, long pdepart) |
|---|
| 1170 | GEN vandermondeinverse(GEN L, GEN T, GEN den, GEN prep) |
|---|
| 1171 | # gen1.c |
|---|
| 1172 | |
|---|
| 1173 | GEN gadd(GEN x, GEN y) |
|---|
| 1174 | GEN gaddsg(long x, GEN y) |
|---|
| 1175 | GEN gdiv(GEN x, GEN y) |
|---|
| 1176 | GEN gmul(GEN x, GEN y) |
|---|
| 1177 | GEN gsqr(GEN x) |
|---|
| 1178 | GEN gsub(GEN x, GEN y) |
|---|
| 1179 | |
|---|
| 1180 | # gen2.c |
|---|
| 1181 | GEN gopgs2(GEN (*f)(GEN, GEN), GEN y, long s) |
|---|
| 1182 | GEN gopsg2(GEN (*f)(GEN, GEN), long s, GEN y) |
|---|
| 1183 | void gopsgz(GEN (*f)(GEN, GEN), long s, GEN y, GEN z) |
|---|
| 1184 | int opgs2(int (*f)(GEN, GEN), GEN y, long s) |
|---|
| 1185 | |
|---|
| 1186 | long ZX_valuation(GEN x, GEN *Z) |
|---|
| 1187 | GEN cgetimag() |
|---|
| 1188 | GEN cgetp(GEN x) |
|---|
| 1189 | GEN cvtop(GEN x, GEN p, long l) |
|---|
| 1190 | GEN cvtop2(GEN x, GEN y) |
|---|
| 1191 | GEN from_Kronecker(GEN z, GEN pol) |
|---|
| 1192 | GEN gabs(GEN x, long prec) |
|---|
| 1193 | void gaffect(GEN x, GEN y) |
|---|
| 1194 | void gaffsg(long s, GEN x) |
|---|
| 1195 | GEN gclone(GEN x) |
|---|
| 1196 | int gcmp(GEN x, GEN y) |
|---|
| 1197 | int gcmpsg(long x, GEN y) |
|---|
| 1198 | int gcmp0(GEN x) |
|---|
| 1199 | int gcmp1(GEN x) |
|---|
| 1200 | int gcmp_1(GEN x) |
|---|
| 1201 | GEN gcvtop(GEN x, GEN p, long r) |
|---|
| 1202 | int gegal(GEN x, GEN y) |
|---|
| 1203 | int gegalsg(long s, GEN x) |
|---|
| 1204 | long gexpo(GEN x) |
|---|
| 1205 | long ggval(GEN x, GEN p) |
|---|
| 1206 | long glength(GEN x) |
|---|
| 1207 | GEN gmax(GEN x, GEN y) |
|---|
| 1208 | GEN gmin(GEN x, GEN y) |
|---|
| 1209 | GEN gneg(GEN x) |
|---|
| 1210 | GEN gneg_i(GEN x) |
|---|
| 1211 | GEN greffe(GEN x, long l, long use_stack) |
|---|
| 1212 | int gsigne(GEN x) |
|---|
| 1213 | GEN gtofp(GEN z, long prec) |
|---|
| 1214 | GEN gtolist(GEN x) |
|---|
| 1215 | long gtolong(GEN x) |
|---|
| 1216 | int lexcmp(GEN x, GEN y) |
|---|
| 1217 | GEN listconcat(GEN list1, GEN list2) |
|---|
| 1218 | GEN listcreate(long n) |
|---|
| 1219 | GEN listinsert(GEN list, GEN object, long index) |
|---|
| 1220 | void listkill(GEN list) |
|---|
| 1221 | GEN listput(GEN list, GEN object, long index) |
|---|
| 1222 | GEN listsort(GEN list, long flag) |
|---|
| 1223 | GEN matsize(GEN x) |
|---|
| 1224 | GEN normalize(GEN x) |
|---|
| 1225 | GEN normalizepol(GEN x) |
|---|
| 1226 | GEN normalizepol_i(GEN x, long lx) |
|---|
| 1227 | long polvaluation(GEN x, GEN *z) |
|---|
| 1228 | long polvaluation_inexact(GEN x, GEN *Z) |
|---|
| 1229 | GEN pureimag(GEN x) |
|---|
| 1230 | GEN quadtoc(GEN x, long l) |
|---|
| 1231 | long sizedigit(GEN x) |
|---|
| 1232 | long u_lval(ulong x, ulong p) |
|---|
| 1233 | long u_lvalrem(ulong x, ulong p, ulong *py) |
|---|
| 1234 | long u_pvalrem(ulong x, GEN p, ulong *py) |
|---|
| 1235 | GEN to_Kronecker(GEN P, GEN Q) |
|---|
| 1236 | GEN vecmax(GEN x) |
|---|
| 1237 | GEN vecmin(GEN x) |
|---|
| 1238 | long Z_lval(GEN n, ulong p) |
|---|
| 1239 | long Z_lvalrem(GEN n, ulong p, GEN *py) |
|---|
| 1240 | long z_pval(long n, GEN p) |
|---|
| 1241 | long Z_pval(GEN n, GEN p) |
|---|
| 1242 | long Z_pvalrem(GEN x, GEN p, GEN *py) |
|---|
| 1243 | |
|---|
| 1244 | # gen3.c |
|---|
| 1245 | |
|---|
| 1246 | GEN _toser(GEN x) |
|---|
| 1247 | GEN Mod0(GEN x, GEN y,long flag) |
|---|
| 1248 | GEN ceil_safe(GEN x) |
|---|
| 1249 | GEN ceilr(GEN x) |
|---|
| 1250 | GEN centerlift(GEN x) |
|---|
| 1251 | GEN centerlift0(GEN x,long v) |
|---|
| 1252 | GEN coefs_to_col(long n, ...) |
|---|
| 1253 | GEN coefs_to_int(long n, ...) |
|---|
| 1254 | GEN coefs_to_pol(long n, ...) |
|---|
| 1255 | GEN coefs_to_vec(long n, ...) |
|---|
| 1256 | GEN compo(GEN x, long n) |
|---|
| 1257 | GEN deg1pol(GEN x1, GEN x0,long v) |
|---|
| 1258 | GEN deg1pol_i(GEN x1, GEN x0,long v) |
|---|
| 1259 | long degree(GEN x) |
|---|
| 1260 | GEN denom(GEN x) |
|---|
| 1261 | GEN deriv(GEN x, long v) |
|---|
| 1262 | GEN derivpol(GEN x) |
|---|
| 1263 | GEN derivser(GEN x) |
|---|
| 1264 | GEN diviiround(GEN x, GEN y) |
|---|
| 1265 | GEN divrem(GEN x, GEN y, long v) |
|---|
| 1266 | GEN gand(GEN x, GEN y) |
|---|
| 1267 | GEN gceil(GEN x) |
|---|
| 1268 | GEN gcvtoi(GEN x, long *e) |
|---|
| 1269 | GEN gdivent(GEN x, GEN y) |
|---|
| 1270 | GEN gdiventres(GEN x, GEN y) |
|---|
| 1271 | GEN gdivgs(GEN x, long s) |
|---|
| 1272 | GEN gdivmod(GEN x, GEN y, GEN *pr) |
|---|
| 1273 | GEN gdivround(GEN x, GEN y) |
|---|
| 1274 | GEN geq(GEN x, GEN y) |
|---|
| 1275 | GEN geval(GEN x) |
|---|
| 1276 | GEN gfloor(GEN x) |
|---|
| 1277 | GEN gfloor2n(GEN x, long s) |
|---|
| 1278 | GEN gfrac(GEN x) |
|---|
| 1279 | GEN gge(GEN x, GEN y) |
|---|
| 1280 | GEN ggprecision(GEN x) |
|---|
| 1281 | GEN ggt(GEN x, GEN y) |
|---|
| 1282 | GEN gimag(GEN x) |
|---|
| 1283 | GEN ginv(GEN x) |
|---|
| 1284 | GEN gle(GEN x, GEN y) |
|---|
| 1285 | GEN glt(GEN x, GEN y) |
|---|
| 1286 | GEN gmod(GEN x, GEN y) |
|---|
| 1287 | GEN gmodulcp(GEN x,GEN y) |
|---|
| 1288 | GEN gmodulo(GEN x,GEN y) |
|---|
| 1289 | GEN gmodulsg(long x, GEN y) |
|---|
| 1290 | GEN gmodulss(long x, long y) |
|---|
| 1291 | GEN gmul2n(GEN x, long n) |
|---|
| 1292 | GEN gmulsg(long s, GEN y) |
|---|
| 1293 | GEN gne(GEN x, GEN y) |
|---|
| 1294 | GEN gnot(GEN x) |
|---|
| 1295 | GEN gor(GEN x, GEN y) |
|---|
| 1296 | GEN gpolvar(GEN y) |
|---|
| 1297 | long gprecision(GEN x) |
|---|
| 1298 | GEN gram_matrix(GEN M) |
|---|
| 1299 | GEN greal(GEN x) |
|---|
| 1300 | GEN grndtoi(GEN x, long *e) |
|---|
| 1301 | GEN ground(GEN x) |
|---|
| 1302 | GEN gshift(GEN x, long n) |
|---|
| 1303 | GEN gsubst(GEN x, long v, GEN y) |
|---|
| 1304 | GEN gsubstpol(GEN x, GEN v, GEN y) |
|---|
| 1305 | GEN gtocol(GEN x) |
|---|
| 1306 | GEN gtopoly(GEN x, long v) |
|---|
| 1307 | GEN gtopolyrev(GEN x, long v) |
|---|
| 1308 | GEN gtoser(GEN x, long v) |
|---|
| 1309 | GEN gtovec(GEN x) |
|---|
| 1310 | GEN gtovecsmall(GEN x) |
|---|
| 1311 | GEN gtrunc(GEN x) |
|---|
| 1312 | int gvar(GEN x) |
|---|
| 1313 | int gvar2(GEN x) |
|---|
| 1314 | int gvar9(GEN x) |
|---|
| 1315 | GEN hqfeval(GEN q, GEN x) |
|---|
| 1316 | GEN imag_i(GEN x) |
|---|
| 1317 | GEN int2n(long n) |
|---|
| 1318 | GEN integ(GEN x, long v) |
|---|
| 1319 | int iscomplex(GEN x) |
|---|
| 1320 | int isexactzero(GEN g) |
|---|
| 1321 | int isexactzeroscalar(GEN g) |
|---|
| 1322 | int isinexactreal(GEN x) |
|---|
| 1323 | long isint(GEN n, long *ptk) |
|---|
| 1324 | int ismonome(GEN x) |
|---|
| 1325 | GEN lift(GEN x) |
|---|
| 1326 | GEN lift0(GEN x,long v) |
|---|
| 1327 | GEN lift_intern0(GEN x,long v) |
|---|
| 1328 | GEN truncr(GEN x) |
|---|
| 1329 | GEN mulmat_real(GEN x, GEN y) |
|---|
| 1330 | GEN numer(GEN x) |
|---|
| 1331 | long padicprec(GEN x, GEN p) |
|---|
| 1332 | GEN polcoeff0(GEN x,long n,long v) |
|---|
| 1333 | GEN polcoeff_i(GEN x, long n, long v) |
|---|
| 1334 | long poldegree(GEN x,long v) |
|---|
| 1335 | GEN poleval(GEN x, GEN y) |
|---|
| 1336 | GEN pollead(GEN x,long v) |
|---|
| 1337 | long precision(GEN x) |
|---|
| 1338 | GEN precision0(GEN x,long n) |
|---|
| 1339 | GEN qf_base_change(GEN q, GEN M, int flag) |
|---|
| 1340 | GEN qfeval(GEN q, GEN x) |
|---|
| 1341 | GEN real_i(GEN x) |
|---|
| 1342 | GEN real2n(long n, long prec) |
|---|
| 1343 | GEN recip(GEN x) |
|---|
| 1344 | GEN round0(GEN x, GEN *pte) |
|---|
| 1345 | GEN roundr(GEN x) |
|---|
| 1346 | GEN scalarpol(GEN x, long v) |
|---|
| 1347 | GEN scalarser(GEN x, long v, long prec) |
|---|
| 1348 | GEN simplify(GEN x) |
|---|
| 1349 | GEN simplify_i(GEN x) |
|---|
| 1350 | GEN truecoeff(GEN x, long n) |
|---|
| 1351 | GEN trunc0(GEN x, GEN *pte) |
|---|
| 1352 | GEN u2toi(ulong a, ulong b) |
|---|
| 1353 | GEN zerocol(long n) |
|---|
| 1354 | GEN zeromat(long m, long n) |
|---|
| 1355 | GEN zeropadic(GEN p, long e) |
|---|
| 1356 | GEN zeropol(long v) |
|---|
| 1357 | GEN zeroser(long v, long prec) |
|---|
| 1358 | GEN zerovec(long n) |
|---|
| 1359 | |
|---|
| 1360 | # groupid.c |
|---|
| 1361 | |
|---|
| 1362 | long group_ident(GEN G, GEN S) |
|---|
| 1363 | |
|---|
| 1364 | # ifactor1.c |
|---|
| 1365 | |
|---|
| 1366 | long BSW_psp(GEN N) |
|---|
| 1367 | long is_357_power(GEN x, GEN *pt, ulong *mask) |
|---|
| 1368 | long is_odd_power(GEN x, GEN *pt, ulong *curexp, ulong cutoffbits) |
|---|
| 1369 | long millerrabin(GEN n, long k) |
|---|
| 1370 | GEN nextprime(GEN n) |
|---|
| 1371 | GEN plisprime(GEN N, long flag) |
|---|
| 1372 | GEN precprime(GEN n) |
|---|
| 1373 | |
|---|
| 1374 | # init.c |
|---|
| 1375 | |
|---|
| 1376 | long TIMER(pari_timer *T) |
|---|
| 1377 | void TIMERstart(pari_timer *T) |
|---|
| 1378 | long allocatemoremem(size_t newsize) |
|---|
| 1379 | GEN changevar(GEN x, GEN y) |
|---|
| 1380 | void disable_dbg(long val) |
|---|
| 1381 | GEN dummycopy(GEN x) |
|---|
| 1382 | void err(long numerr, ...) |
|---|
| 1383 | #void *err_catch(long errnum, jmp_buf *penv) |
|---|
| 1384 | void err_leave(void **v) |
|---|
| 1385 | GEN forcecopy(GEN x) |
|---|
| 1386 | void freeall() |
|---|
| 1387 | GEN gcopy(GEN x) |
|---|
| 1388 | GEN gcopy_i(GEN x, long lx) |
|---|
| 1389 | GEN gerepile(pari_sp ltop, pari_sp lbot, GEN q) |
|---|
| 1390 | void gerepileall(pari_sp av, int n, ...) |
|---|
| 1391 | void gerepileallsp(pari_sp av, pari_sp tetpil, int n, ...) |
|---|
| 1392 | void gerepilecoeffs(pari_sp av, GEN x, int n) |
|---|
| 1393 | void gerepilecoeffssp(pari_sp av, pari_sp tetpil, long *g, int n) |
|---|
| 1394 | GEN gerepilecopy(pari_sp av, GEN x) |
|---|
| 1395 | void gerepilemany(pari_sp av, GEN* g[], int n) |
|---|
| 1396 | void gerepilemanysp(pari_sp av, pari_sp tetpil, GEN* g[], int n) |
|---|
| 1397 | GEN gerepileupto(pari_sp av, GEN q) |
|---|
| 1398 | GEN gerepileuptoint(pari_sp av, GEN q) |
|---|
| 1399 | GEN gerepileuptoleaf(pari_sp av, GEN q) |
|---|
| 1400 | char* gpmalloc(size_t bytes) |
|---|
| 1401 | char* gprealloc(void *pointer,size_t size) |
|---|
| 1402 | void gunclone(GEN x) |
|---|
| 1403 | void killbloc(GEN x) |
|---|
| 1404 | void msgTIMER(pari_timer *T, char *format, ...) |
|---|
| 1405 | void msgtimer(char *format, ...) |
|---|
| 1406 | GEN newbloc(long n) |
|---|
| 1407 | void pari_init(size_t parisize, ulong maxprime) |
|---|
| 1408 | GEN reorder(GEN x) |
|---|
| 1409 | void stackdummy(GEN x, long l) |
|---|
| 1410 | GEN stackify(GEN x) |
|---|
| 1411 | stackzone* switch_stack(stackzone *z, long n) |
|---|
| 1412 | long taille(GEN x) |
|---|
| 1413 | long taille2(GEN x) |
|---|
| 1414 | long timer() |
|---|
| 1415 | long timer2() |
|---|
| 1416 | |
|---|
| 1417 | # members.c |
|---|
| 1418 | |
|---|
| 1419 | GEN member_a1(GEN x) |
|---|
| 1420 | GEN member_a2(GEN x) |
|---|
| 1421 | GEN member_a3(GEN x) |
|---|
| 1422 | GEN member_a4(GEN x) |
|---|
| 1423 | GEN member_a6(GEN x) |
|---|
| 1424 | GEN member_area(GEN x) |
|---|
| 1425 | GEN member_b2(GEN x) |
|---|
| 1426 | GEN member_b4(GEN x) |
|---|
| 1427 | GEN member_b6(GEN x) |
|---|
| 1428 | GEN member_b8(GEN x) |
|---|
| 1429 | GEN member_bnf(GEN x) |
|---|
| 1430 | GEN member_c4(GEN x) |
|---|
| 1431 | GEN member_c6(GEN x) |
|---|
| 1432 | GEN member_clgp(GEN x) |
|---|
| 1433 | GEN member_codiff(GEN x) |
|---|
| 1434 | GEN member_cyc(GEN clg) |
|---|
| 1435 | GEN member_diff(GEN x) |
|---|
| 1436 | GEN member_disc(GEN x) |
|---|
| 1437 | GEN member_e(GEN x) |
|---|
| 1438 | GEN member_eta(GEN x) |
|---|
| 1439 | GEN member_f(GEN x) |
|---|
| 1440 | GEN member_fu(GEN x) |
|---|
| 1441 | GEN member_futu(GEN x) |
|---|
| 1442 | GEN member_gen(GEN x) |
|---|
| 1443 | GEN member_group(GEN x) |
|---|
| 1444 | GEN member_index(GEN x) |
|---|
| 1445 | GEN member_j(GEN x) |
|---|
| 1446 | GEN member_mod(GEN x) |
|---|
| 1447 | GEN member_nf(GEN x) |
|---|
| 1448 | GEN member_no(GEN clg) |
|---|
| 1449 | GEN member_omega(GEN x) |
|---|
| 1450 | GEN member_orders(GEN x) |
|---|
| 1451 | GEN member_p(GEN x) |
|---|
| 1452 | GEN member_pol(GEN x) |
|---|
| 1453 | GEN member_reg(GEN x) |
|---|
| 1454 | GEN member_roots(GEN x) |
|---|
| 1455 | GEN member_sign(GEN x) |
|---|
| 1456 | GEN member_t2(GEN x) |
|---|
| 1457 | GEN member_tate(GEN x) |
|---|
| 1458 | GEN member_tufu(GEN x) |
|---|
| 1459 | GEN member_tu(GEN x) |
|---|
| 1460 | GEN member_w(GEN x) |
|---|
| 1461 | GEN member_zk(GEN x) |
|---|
| 1462 | GEN member_zkst(GEN bid) |
|---|
| 1463 | |
|---|
| 1464 | # mp.c |
|---|
| 1465 | |
|---|
| 1466 | int absi_cmp(GEN x, GEN y) |
|---|
| 1467 | int absi_equal(GEN x, GEN y) |
|---|
| 1468 | int absr_cmp(GEN x, GEN y) |
|---|
| 1469 | GEN addii_sign(GEN x, long sx, GEN y, long sy) |
|---|
| 1470 | GEN addir_sign(GEN x, long sx, GEN y, long sy) |
|---|
| 1471 | GEN addrr_sign(GEN x, long sx, GEN y, long sy) |
|---|
| 1472 | GEN addsi_sign(long x, GEN y, long sy) |
|---|
| 1473 | GEN addsr(long x, GEN y) |
|---|
| 1474 | GEN addss(long x, long y) |
|---|
| 1475 | void affir(GEN x, GEN y) |
|---|
| 1476 | void affrr(GEN x, GEN y) |
|---|
| 1477 | GEN bezout(GEN a, GEN b, GEN *u, GEN *v) |
|---|
| 1478 | long cbezout(long a,long b,long *uu,long *vv) |
|---|
| 1479 | void cgiv(GEN x) |
|---|
| 1480 | int cmpii(GEN x, GEN y) |
|---|
| 1481 | int cmprr(GEN x, GEN y) |
|---|
| 1482 | int cmpsi(long x, GEN y) |
|---|
| 1483 | int cmpui(ulong x, GEN y) |
|---|
| 1484 | GEN dbltor(double x) |
|---|
| 1485 | GEN diviiexact(GEN x, GEN y) |
|---|
| 1486 | GEN diviuexact(GEN x, ulong y) |
|---|
| 1487 | GEN divir(GEN x, GEN y) |
|---|
| 1488 | GEN divis(GEN y, long x) |
|---|
| 1489 | GEN divis_rem(GEN x, long y, long *rem) |
|---|
| 1490 | GEN diviu_rem(GEN y, ulong x, ulong *rem) |
|---|
| 1491 | GEN divri(GEN x, GEN y) |
|---|
| 1492 | GEN divrr(GEN x, GEN y) |
|---|
| 1493 | GEN divrs(GEN x, long y) |
|---|
| 1494 | GEN divsi(long x, GEN y) |
|---|
| 1495 | GEN divsr(long x, GEN y) |
|---|
| 1496 | GEN dvmdii(GEN x, GEN y, GEN *z) |
|---|
| 1497 | int egalii(GEN x, GEN y) |
|---|
| 1498 | GEN floorr(GEN x) |
|---|
| 1499 | GEN gcdii(GEN x, GEN y) |
|---|
| 1500 | GEN int_normalize(GEN x, long known_zero_words) |
|---|
| 1501 | int invmod(GEN a, GEN b, GEN *res) |
|---|
| 1502 | ulong invrev(ulong b) |
|---|
| 1503 | ulong Fl_inv(ulong x, ulong p) |
|---|
| 1504 | GEN ishiftr(GEN x, long n) |
|---|
| 1505 | GEN modii(GEN x, GEN y) |
|---|
| 1506 | void modiiz(GEN x, GEN y, GEN z) |
|---|
| 1507 | void mpdivz(GEN x, GEN y, GEN z) |
|---|
| 1508 | GEN mulii(GEN x, GEN y) |
|---|
| 1509 | GEN mulir(GEN x, GEN y) |
|---|
| 1510 | GEN mulrr(GEN x, GEN y) |
|---|
| 1511 | GEN mulsi(long x, GEN y) |
|---|
| 1512 | GEN mulsr(long x, GEN y) |
|---|
| 1513 | GEN mulss(long x, long y) |
|---|
| 1514 | GEN mului(ulong x, GEN y) |
|---|
| 1515 | GEN mulur(ulong x, GEN y) |
|---|
| 1516 | GEN muluu(ulong x, ulong y) |
|---|
| 1517 | long pari_rand31() |
|---|
| 1518 | GEN randomi(GEN x) |
|---|
| 1519 | int ratlift(GEN x, GEN m, GEN *a, GEN *b, GEN amax, GEN bmax) |
|---|
| 1520 | GEN resmod2n(GEN x, long n) |
|---|
| 1521 | double rtodbl(GEN x) |
|---|
| 1522 | GEN shifti(GEN x, long n) |
|---|
| 1523 | GEN shifti3(GEN x, long n, long flag) |
|---|
| 1524 | GEN sqri(GEN x) |
|---|
| 1525 | #define sqrti(x) sqrtremi((x),NULL) |
|---|
| 1526 | GEN sqrtremi(GEN S, GEN *R) |
|---|
| 1527 | GEN subsr(long x, GEN y) |
|---|
| 1528 | GEN truedvmdii(GEN x, GEN y, GEN *z) |
|---|
| 1529 | ulong umodiu(GEN y, ulong x) |
|---|
| 1530 | long vals(ulong x) |
|---|
| 1531 | |
|---|
| 1532 | # nffactor.c |
|---|
| 1533 | |
|---|
| 1534 | GEN nffactor(GEN nf,GEN x) |
|---|
| 1535 | GEN nffactormod(GEN nf,GEN pol,GEN pr) |
|---|
| 1536 | int nfisgalois(GEN nf, GEN x) |
|---|
| 1537 | GEN nfroots(GEN nf,GEN pol) |
|---|
| 1538 | GEN rnfcharpoly(GEN nf,GEN T,GEN alpha,int n) |
|---|
| 1539 | GEN rnfdedekind(GEN nf,GEN T,GEN pr) |
|---|
| 1540 | GEN unifpol(GEN nf,GEN pol,long flag) |
|---|
| 1541 | |
|---|
| 1542 | # part.c |
|---|
| 1543 | |
|---|
| 1544 | GEN numbpart(GEN x) |
|---|
| 1545 | |
|---|
| 1546 | # perm.c |
|---|
| 1547 | |
|---|
| 1548 | GEN abelian_group(GEN G) |
|---|
| 1549 | GEN bitvec_alloc(long n) |
|---|
| 1550 | void bitvec_clear(GEN bitvec, long b) |
|---|
| 1551 | void bitvec_set(GEN bitvec, long b) |
|---|
| 1552 | GEN bitvec_shorten(GEN bitvec, long n) |
|---|
| 1553 | long bitvec_test(GEN bitvec, long b) |
|---|
| 1554 | GEN cyclicgroup(GEN g, long s) |
|---|
| 1555 | GEN cyclicperm(long l, long d) |
|---|
| 1556 | GEN cyc_pow(GEN cyc, long exp) |
|---|
| 1557 | GEN cyc_pow_perm(GEN cyc, long exp) |
|---|
| 1558 | GEN dicyclicgroup(GEN g1, GEN g2, long s1, long s2) |
|---|
| 1559 | GEN group_abelianHNF(GEN G, GEN L) |
|---|
| 1560 | GEN group_abelianSNF(GEN G, GEN L) |
|---|
| 1561 | long group_domain(GEN G) |
|---|
| 1562 | GEN group_elts(GEN G, long n) |
|---|
| 1563 | GEN group_export(GEN G, long format) |
|---|
| 1564 | long group_isA4S4(GEN G) |
|---|
| 1565 | long group_isabelian(GEN G) |
|---|
| 1566 | GEN group_leftcoset(GEN G, GEN g) |
|---|
| 1567 | long group_order(GEN G) |
|---|
| 1568 | long group_perm_normalize(GEN N, GEN g) |
|---|
| 1569 | GEN group_quotient(GEN G, GEN H) |
|---|
| 1570 | GEN group_rightcoset(GEN G, GEN g) |
|---|
| 1571 | GEN group_subgroups(GEN G) |
|---|
| 1572 | GEN groupelts_center(GEN S) |
|---|
| 1573 | GEN groupelts_abelian_group(GEN S) |
|---|
| 1574 | int perm_commute(GEN p, GEN q) |
|---|
| 1575 | GEN perm_cycles(GEN v) |
|---|
| 1576 | GEN perm_identity(long l) |
|---|
| 1577 | GEN perm_inv(GEN x) |
|---|
| 1578 | GEN perm_mul(GEN s, GEN t) |
|---|
| 1579 | long perm_order(GEN perm) |
|---|
| 1580 | GEN perm_pow(GEN perm, long exp) |
|---|
| 1581 | GEN quotient_group(GEN C, GEN G) |
|---|
| 1582 | GEN quotient_perm(GEN C, GEN p) |
|---|
| 1583 | GEN vec_to_vecsmall(GEN z) |
|---|
| 1584 | GEN vecperm_orbits(GEN v, long n) |
|---|
| 1585 | GEN vecsmall_append(GEN V, long s) |
|---|
| 1586 | long vecsmall_coincidence(GEN u, GEN v) |
|---|
| 1587 | GEN vecsmall_concat(GEN u, GEN v) |
|---|
| 1588 | GEN vecsmall_const(long n, long c) |
|---|
| 1589 | GEN vecsmall_copy(GEN x) |
|---|
| 1590 | int vecsmall_lexcmp(GEN x, GEN y) |
|---|
| 1591 | long vecsmall_pack(GEN V, long base, long mod) |
|---|
| 1592 | int vecsmall_prefixcmp(GEN x, GEN y) |
|---|
| 1593 | GEN vecsmall_prepend(GEN V, long s) |
|---|
| 1594 | GEN vecsmall_shorten(GEN v, long n) |
|---|
| 1595 | void vecsmall_sort(GEN V) |
|---|
| 1596 | GEN vecsmall_to_col(GEN z) |
|---|
| 1597 | GEN vecsmall_to_vec(GEN z) |
|---|
| 1598 | GEN vecsmall_uniq(GEN V) |
|---|
| 1599 | GEN vecvecsmall_indexsort(GEN x) |
|---|
| 1600 | GEN vecvecsmall_sort(GEN x) |
|---|
| 1601 | long vecvecsmall_search(GEN x, GEN y, long flag) |
|---|
| 1602 | |
|---|
| 1603 | # polarit1.c |
|---|
| 1604 | |
|---|
| 1605 | long Flx_nbfact(GEN z, ulong p) |
|---|
| 1606 | long Flx_nbroots(GEN f, ulong p) |
|---|
| 1607 | GEN FpX_degfact(GEN f, GEN p) |
|---|
| 1608 | long FpX_is_irred(GEN f, GEN p) |
|---|
| 1609 | long FpX_is_squarefree(GEN f, GEN p) |
|---|
| 1610 | long FpX_is_totally_split(GEN f, GEN p) |
|---|
| 1611 | GEN FpX_factor(GEN f, GEN p) |
|---|
| 1612 | long FpX_nbfact(GEN f, GEN p) |
|---|
| 1613 | long FpX_nbroots(GEN f, GEN p) |
|---|
| 1614 | GEN FpXQX_gcd(GEN P, GEN Q, GEN T, GEN p) |
|---|
| 1615 | GEN FqX_factor(GEN x, GEN T, GEN p) |
|---|
| 1616 | GEN FqX_gcd(GEN P, GEN Q, GEN T, GEN p) |
|---|
| 1617 | long FqX_is_squarefree(GEN P, GEN T, GEN p) |
|---|
| 1618 | long FqX_nbfact(GEN u, GEN T, GEN p) |
|---|
| 1619 | long FqX_nbroots(GEN f, GEN T, GEN p) |
|---|
| 1620 | GEN FpX_rand(long d, long v, GEN p) |
|---|
| 1621 | GEN FpX_roots(GEN f, GEN p) |
|---|
| 1622 | GEN apprgen(GEN f, GEN a) |
|---|
| 1623 | GEN apprgen9(GEN f, GEN a) |
|---|
| 1624 | GEN factcantor(GEN x, GEN p) |
|---|
| 1625 | GEN factmod(GEN f, GEN p) |
|---|
| 1626 | GEN factmod9(GEN f, GEN p, GEN a) |
|---|
| 1627 | GEN factormod0(GEN f, GEN p,long flag) |
|---|
| 1628 | GEN factorpadic0(GEN f,GEN p,long r,long flag) |
|---|
| 1629 | GEN factorpadic2(GEN x, GEN p, long r) |
|---|
| 1630 | GEN factorpadic4(GEN x, GEN p, long r) |
|---|
| 1631 | GEN ffinit(GEN p,long n, long v) |
|---|
| 1632 | int gdvd(GEN x, GEN y) |
|---|
| 1633 | long hensel_lift_accel(long n, long *pmask) |
|---|
| 1634 | GEN init_Fq(GEN p, long n, long v) |
|---|
| 1635 | GEN padicsqrtnlift(GEN a, GEN n, GEN S, GEN p, long e) |
|---|
| 1636 | int poldvd(GEN x, GEN y, GEN *z) |
|---|
| 1637 | GEN poldivrem(GEN x, GEN y, GEN *pr) |
|---|
| 1638 | GEN poldivrem_i(GEN x, GEN y, GEN *pr, long vx) |
|---|
| 1639 | GEN rootmod(GEN f, GEN p) |
|---|
| 1640 | GEN rootmod0(GEN f, GEN p,long flag) |
|---|
| 1641 | GEN rootmod2(GEN f, GEN p) |
|---|
| 1642 | GEN rootpadic(GEN f, GEN p, long r) |
|---|
| 1643 | GEN rootpadicfast(GEN f, GEN p, long e) |
|---|
| 1644 | GEN rootpadiclift(GEN T, GEN S, GEN q, long e) |
|---|
| 1645 | GEN rootpadicliftroots(GEN f, GEN S, GEN q, long e) |
|---|
| 1646 | GEN roots2(GEN pol,long PREC) |
|---|
| 1647 | GEN rootsold(GEN x, long l) |
|---|
| 1648 | GEN simplefactmod(GEN f, GEN p) |
|---|
| 1649 | |
|---|
| 1650 | # polarit2.c |
|---|
| 1651 | |
|---|
| 1652 | GEN Newton_exponents(long e) |
|---|
| 1653 | GEN Q_content(GEN x) |
|---|
| 1654 | GEN Q_denom(GEN x) |
|---|
| 1655 | GEN Q_div_to_int(GEN x, GEN c) |
|---|
| 1656 | GEN Q_muli_to_int(GEN x, GEN d) |
|---|
| 1657 | GEN Q_primitive_part(GEN x, GEN *ptc) |
|---|
| 1658 | GEN Q_primpart(GEN x) |
|---|
| 1659 | GEN Q_remove_denom(GEN x, GEN *ptd) |
|---|
| 1660 | GEN RgX_extgcd(GEN x, GEN y, GEN *U, GEN *V) |
|---|
| 1661 | GEN ZX_squff(GEN f, GEN *ex) |
|---|
| 1662 | GEN centermod(GEN x, GEN p) |
|---|
| 1663 | GEN centermod_i(GEN x, GEN p, GEN ps2) |
|---|
| 1664 | GEN centermodii(GEN x, GEN p, GEN po2) |
|---|
| 1665 | GEN concat_factor(GEN f, GEN g) |
|---|
| 1666 | GEN content(GEN x) |
|---|
| 1667 | GEN deg1_from_roots(GEN L, long v) |
|---|
| 1668 | GEN discsr(GEN x) |
|---|
| 1669 | GEN divide_conquer_prod(GEN x, GEN (*mul)(GEN,GEN)) |
|---|
| 1670 | GEN factor(GEN x) |
|---|
| 1671 | GEN factor0(GEN x,long flag) |
|---|
| 1672 | GEN factorback(GEN fa,GEN nf) |
|---|
| 1673 | GEN factorback0(GEN fa,GEN e, GEN nf) |
|---|
| 1674 | GEN factorbackelt(GEN fa, GEN e, GEN nf) |
|---|
| 1675 | GEN factpol(GEN x, long hint) |
|---|
| 1676 | GEN gbezout(GEN x, GEN y, GEN *u, GEN *v) |
|---|
| 1677 | GEN gcd0(GEN x, GEN y,long flag) |
|---|
| 1678 | GEN gdeflate(GEN x, long v, long d) |
|---|
| 1679 | GEN gdivexact(GEN x, GEN y) |
|---|
| 1680 | GEN ggcd(GEN x, GEN y) |
|---|
| 1681 | GEN ginvmod(GEN x, GEN y) |
|---|
| 1682 | GEN gisirreducible(GEN x) |
|---|
| 1683 | GEN glcm(GEN x, GEN y) |
|---|
| 1684 | GEN glcm0(GEN x, GEN y) |
|---|
| 1685 | GEN hensel_lift_fact(GEN pol, GEN Q, GEN T, GEN p, GEN pe, long e) |
|---|
| 1686 | GEN leftright_pow(GEN,GEN,void*,GEN (*sqr)(void*,GEN),GEN (*mul)(void*,GEN,GEN)) |
|---|
| 1687 | GEN leftright_pow_u(GEN x, ulong n, void *data, GEN (*sqr)(void*,GEN), GEN (*mul)(void*,GEN,GEN)) |
|---|
| 1688 | long logint(GEN B, GEN y, GEN *ptq) |
|---|
| 1689 | GEN newtonpoly(GEN x, GEN p) |
|---|
| 1690 | GEN nfgcd(GEN P, GEN Q, GEN nf, GEN den) |
|---|
| 1691 | GEN nfisincl(GEN a, GEN b) |
|---|
| 1692 | GEN nfisisom(GEN a, GEN b) |
|---|
| 1693 | GEN nfrootsQ(GEN x) |
|---|
| 1694 | GEN poldeflate(GEN x0, long *m) |
|---|
| 1695 | GEN poldeflate_i(GEN x0, long d) |
|---|
| 1696 | GEN poldisc0(GEN x, long v) |
|---|
| 1697 | GEN polfnf(GEN a, GEN t) |
|---|
| 1698 | GEN polhensellift(GEN pol, GEN fct, GEN p, long exp) |
|---|
| 1699 | GEN polinflate(GEN x0, long d) |
|---|
| 1700 | GEN polresultant0(GEN x, GEN y,long v,long flag) |
|---|
| 1701 | GEN polsym(GEN x, long n) |
|---|
| 1702 | GEN primitive_part(GEN x, GEN *c) |
|---|
| 1703 | GEN primpart(GEN x) |
|---|
| 1704 | GEN pseudorem(GEN x, GEN y) |
|---|
| 1705 | GEN quadgen(GEN x) |
|---|
| 1706 | GEN quadpoly(GEN x) |
|---|
| 1707 | GEN quadpoly0(GEN x, long v) |
|---|
| 1708 | GEN reduceddiscsmith(GEN pol) |
|---|
| 1709 | GEN resultant2(GEN x, GEN y) |
|---|
| 1710 | GEN resultantducos(GEN x, GEN y) |
|---|
| 1711 | GEN roots_from_deg1(GEN x) |
|---|
| 1712 | GEN sort_factor(GEN y, int (*cmp)(GEN,GEN)) |
|---|
| 1713 | GEN sort_factor_gen(GEN y, int (*cmp)(GEN,GEN)) |
|---|
| 1714 | GEN sort_vecpol(GEN a, int (*cmp)(GEN,GEN)) |
|---|
| 1715 | GEN srgcd(GEN x, GEN y) |
|---|
| 1716 | long sturmpart(GEN x, GEN a, GEN b) |
|---|
| 1717 | GEN subresall(GEN u, GEN v, GEN *sol) |
|---|
| 1718 | GEN subresext(GEN x, GEN y, GEN *U, GEN *V) |
|---|
| 1719 | GEN sylvestermatrix(GEN x,GEN y) |
|---|
| 1720 | GEN vecbezout(GEN x, GEN y) |
|---|
| 1721 | GEN vecbezoutres(GEN x, GEN y) |
|---|
| 1722 | |
|---|
| 1723 | # polarit3.c |
|---|
| 1724 | |
|---|
| 1725 | ulong Fl_pow(ulong x, ulong n, ulong p) |
|---|
| 1726 | GEN Fp_pows(GEN A, long k, GEN N) |
|---|
| 1727 | GEN Fp_powu(GEN x, ulong k, GEN p) |
|---|
| 1728 | GEN FpM_red(GEN z, GEN p) |
|---|
| 1729 | GEN FpM_to_mod(GEN z, GEN p) |
|---|
| 1730 | GEN FpV_polint(GEN xa, GEN ya, GEN p) |
|---|
| 1731 | GEN FpV_red(GEN z, GEN p) |
|---|
| 1732 | GEN FpV_roots_to_pol(GEN V, GEN p, long v) |
|---|
| 1733 | GEN FpV_to_mod(GEN z, GEN p) |
|---|
| 1734 | GEN FpX_FpXQ_compo(GEN f,GEN x,GEN T,GEN p) |
|---|
| 1735 | GEN FpX_FpXQV_compo(GEN f,GEN x,GEN T,GEN p) |
|---|
| 1736 | GEN FpX_Fp_add(GEN y,GEN x,GEN p) |
|---|
| 1737 | GEN FpX_Fp_mul(GEN y,GEN x,GEN p) |
|---|
| 1738 | GEN FpX_add(GEN x,GEN y,GEN p) |
|---|
| 1739 | GEN FpX_center(GEN T,GEN mod) |
|---|
| 1740 | GEN FpX_chinese_coprime(GEN x,GEN y,GEN Tx,GEN Ty,GEN Tz,GEN p) |
|---|
| 1741 | GEN FpX_divrem(GEN x, GEN y, GEN p, GEN *pr) |
|---|
| 1742 | GEN FpX_eval(GEN x,GEN y,GEN p) |
|---|
| 1743 | GEN FpX_extgcd(GEN x, GEN y, GEN p, GEN *ptu, GEN *ptv) |
|---|
| 1744 | GEN FpX_factorff_irred(GEN P, GEN Q, GEN l) |
|---|
| 1745 | void FpX_ffintersect(GEN P,GEN Q,long n,GEN l,GEN *SP,GEN *SQ,GEN MA,GEN MB) |
|---|
| 1746 | GEN FpX_ffisom(GEN P,GEN Q,GEN l) |
|---|
| 1747 | GEN FpX_gcd(GEN x, GEN y, GEN p) |
|---|
| 1748 | GEN FpX_mul(GEN x,GEN y,GEN p) |
|---|
| 1749 | GEN FpX_neg(GEN x,GEN p) |
|---|
| 1750 | GEN FpX_normalize(GEN z, GEN p) |
|---|
| 1751 | GEN FpX_red(GEN z, GEN p) |
|---|
| 1752 | GEN FpX_sqr(GEN x,GEN p) |
|---|
| 1753 | GEN FpX_sub(GEN x,GEN y,GEN p) |
|---|
| 1754 | GEN FpX_to_mod(GEN z, GEN p) |
|---|
| 1755 | GEN FpXQ_charpoly(GEN x, GEN T, GEN p) |
|---|
| 1756 | GEN FpXQ_div(GEN x,GEN y,GEN T,GEN p) |
|---|
| 1757 | GEN FpXQ_ffisom_inv(GEN S,GEN Tp, GEN p) |
|---|
| 1758 | GEN FpXQ_inv(GEN x,GEN T,GEN p) |
|---|
| 1759 | GEN FpXQ_invsafe(GEN x, GEN T, GEN p) |
|---|
| 1760 | GEN FpXQ_matrix_pow(long n, long m, GEN y, GEN P, GEN l) |
|---|
| 1761 | GEN FpXQ_minpoly(GEN x, GEN T, GEN p) |
|---|
| 1762 | GEN FpXQ_mul(GEN y,GEN x,GEN T,GEN p) |
|---|
| 1763 | GEN FpXQ_pow(GEN x, GEN n, GEN T, GEN p) |
|---|
| 1764 | GEN FpXQ_powers(GEN x, long l, GEN T, GEN p) |
|---|
| 1765 | GEN FpXQ_sqr(GEN y, GEN T, GEN p) |
|---|
| 1766 | GEN FpXQ_sqrtn(GEN a, GEN n, GEN T, GEN p, GEN *zetan) |
|---|
| 1767 | GEN FpXQX_mul(GEN x, GEN y, GEN T, GEN p) |
|---|
| 1768 | GEN FpXQX_red(GEN z, GEN T, GEN p) |
|---|
| 1769 | GEN FpXQX_sqr(GEN x, GEN T, GEN p) |
|---|
| 1770 | GEN FpXQX_extgcd(GEN x, GEN y, GEN T, GEN p, GEN *ptu, GEN *ptv) |
|---|
| 1771 | GEN FpXQX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *pr) |
|---|
| 1772 | GEN FpXQX_safegcd(GEN P, GEN Q, GEN T, GEN p) |
|---|
| 1773 | GEN FpXQXV_prod(GEN V, GEN Tp, GEN p) |
|---|
| 1774 | GEN FpXQYQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p) |
|---|
| 1775 | GEN FpXV_FpV_innerprod(GEN V, GEN W, GEN p) |
|---|
| 1776 | GEN FpXV_prod(GEN V, GEN p) |
|---|
| 1777 | GEN FpXV_red(GEN z, GEN p) |
|---|
| 1778 | GEN FpXX_red(GEN z, GEN p) |
|---|
| 1779 | GEN FpX_rescale(GEN P, GEN h, GEN p) |
|---|
| 1780 | GEN FpY_FpXY_resultant(GEN a, GEN b0, GEN p) |
|---|
| 1781 | GEN Fq_inv(GEN x, GEN T, GEN p) |
|---|
| 1782 | GEN Fq_invsafe(GEN x, GEN T, GEN p) |
|---|
| 1783 | GEN Fq_add(GEN x, GEN y, GEN T, GEN p) |
|---|
| 1784 | GEN Fq_mul(GEN x, GEN y, GEN T, GEN p) |
|---|
| 1785 | GEN Fq_neg(GEN x, GEN T, GEN p) |
|---|
| 1786 | GEN Fq_neg_inv(GEN x, GEN T, GEN p) |
|---|
| 1787 | GEN Fq_pow(GEN x, GEN n, GEN T, GEN p) |
|---|
| 1788 | GEN Fq_red(GEN x, GEN T, GEN p) |
|---|
| 1789 | GEN Fq_sub(GEN x, GEN y, GEN T, GEN p) |
|---|
| 1790 | GEN FqM_to_FlxM(GEN x, GEN T, GEN pp) |
|---|
| 1791 | GEN FqV_roots_to_pol(GEN V, GEN T, GEN p, long v) |
|---|
| 1792 | GEN FqV_red(GEN z, GEN T, GEN p) |
|---|
| 1793 | GEN FqV_to_FlxC(GEN v, GEN T, GEN pp) |
|---|
| 1794 | GEN FqX_Fq_mul(GEN P, GEN U, GEN T, GEN p) |
|---|
| 1795 | GEN FqX_div(GEN x, GEN y, GEN T, GEN p) |
|---|
| 1796 | GEN FqX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *z) |
|---|
| 1797 | GEN FqX_normalize(GEN z, GEN T, GEN p) |
|---|
| 1798 | GEN FqX_red(GEN z, GEN T, GEN p) |
|---|
| 1799 | GEN FqX_rem(GEN x, GEN y, GEN T, GEN p) |
|---|
| 1800 | GEN FqX_mul(GEN x, GEN y, GEN T, GEN p) |
|---|
| 1801 | GEN FqX_sqr(GEN x, GEN T, GEN p) |
|---|
| 1802 | GEN QXQ_inv(GEN A, GEN B) |
|---|
| 1803 | GEN ZX_caract(GEN A, GEN B, long v) |
|---|
| 1804 | GEN ZX_disc(GEN x) |
|---|
| 1805 | int ZX_is_squarefree(GEN x) |
|---|
| 1806 | GEN ZX_resultant(GEN A, GEN B) |
|---|
| 1807 | GEN ZX_QX_resultant(GEN A, GEN B) |
|---|
| 1808 | GEN ZX_s_add(GEN y,long x) |
|---|
| 1809 | long brent_kung_optpow(long d, long n) |
|---|
| 1810 | GEN modulargcd(GEN a,GEN b) |
|---|
| 1811 | GEN rescale_pol(GEN P, GEN h) |
|---|
| 1812 | GEN unscale_pol(GEN P, GEN h) |
|---|
| 1813 | GEN stopoly(ulong m, ulong p, long v) |
|---|
| 1814 | GEN stopoly_gen(GEN m, GEN p, long v) |
|---|
| 1815 | int u_pow(int p, int k) |
|---|
| 1816 | long u_val(ulong n, ulong p) |
|---|
| 1817 | |
|---|
| 1818 | # RgX.c |
|---|
| 1819 | |
|---|
| 1820 | int is_rational(GEN x) |
|---|
| 1821 | int RgX_is_rational(GEN x) |
|---|
| 1822 | GEN RgM_to_RgXV(GEN x, long v) |
|---|
| 1823 | GEN RgM_to_RgXX(GEN x, long v,long w) |
|---|
| 1824 | GEN RgM_zc_mul(GEN x, GEN y) |
|---|
| 1825 | GEN RgM_zm_mul(GEN x, GEN y) |
|---|
| 1826 | GEN RgV_to_RgX(GEN x, long v) |
|---|
| 1827 | GEN RgV_zc_mul(GEN x, GEN y) |
|---|
| 1828 | GEN RgV_zm_mul(GEN x, GEN y) |
|---|
| 1829 | GEN RgX_divrem(GEN x,GEN y,GEN *r) |
|---|
| 1830 | GEN RgX_mul(GEN x,GEN y) |
|---|
| 1831 | GEN RgX_mulspec(GEN a, GEN b, long na, long nb) |
|---|
| 1832 | GEN RgX_powers(GEN a, GEN T, long l) |
|---|
| 1833 | GEN RgXQX_divrem(GEN x,GEN y,GEN T,GEN *r) |
|---|
| 1834 | GEN RgXQX_mul(GEN x,GEN y,GEN T) |
|---|
| 1835 | GEN RgXQX_red(GEN P, GEN T) |
|---|
| 1836 | GEN RgXQX_RgXQ_mul(GEN x, GEN y, GEN T) |
|---|
| 1837 | GEN RgX_Rg_mul(GEN y, GEN x) |
|---|
| 1838 | GEN RgX_RgX_compo(GEN f, GEN x, GEN T) |
|---|
| 1839 | GEN RgX_shift(GEN x, long n) |
|---|
| 1840 | GEN RgX_sqr(GEN x) |
|---|
| 1841 | GEN RgX_sqrspec(GEN a, long na) |
|---|
| 1842 | GEN RgXV_to_RgM(GEN v, long n) |
|---|
| 1843 | GEN RgX_to_RgV(GEN x, long N) |
|---|
| 1844 | GEN RgXX_to_RgM(GEN v, long n) |
|---|
| 1845 | GEN RgXY_swap(GEN x, long n, long w) |
|---|
| 1846 | |
|---|
| 1847 | # rootpol.c |
|---|
| 1848 | |
|---|
| 1849 | GEN cleanroots(GEN x,long l) |
|---|
| 1850 | int isrealappr(GEN x, long l) |
|---|
| 1851 | GEN roots(GEN x,long l) |
|---|
| 1852 | GEN roots0(GEN x,long flag,long l) |
|---|
| 1853 | |
|---|
| 1854 | #subcyclo.c |
|---|
| 1855 | |
|---|
| 1856 | GEN galoissubcyclo(GEN N, GEN sg, long flag, long v) |
|---|
| 1857 | GEN polsubcyclo(long n, long d, long v) |
|---|
| 1858 | GEN subcyclo(long n, long d, long v) |
|---|
| 1859 | GEN znstar_small(GEN zn) |
|---|
| 1860 | |
|---|
| 1861 | # subfields.c |
|---|
| 1862 | |
|---|
| 1863 | GEN subfields(GEN nf,GEN d) |
|---|
| 1864 | GEN subfields0(GEN nf,GEN d) |
|---|
| 1865 | |
|---|
| 1866 | # subgroup.c |
|---|
| 1867 | |
|---|
| 1868 | void forsubgroup(entree *oep, GEN cyc, GEN bound, char *och) |
|---|
| 1869 | GEN subgrouplist(GEN cyc, GEN bound) |
|---|
| 1870 | |
|---|
| 1871 | # stark.c |
|---|
| 1872 | |
|---|
| 1873 | GEN bnrL1(GEN bnr, GEN sbgrp, long flag, long prec) |
|---|
| 1874 | GEN bnrrootnumber(GEN bnr, GEN chi, long flag, long prec) |
|---|
| 1875 | GEN bnrstark(GEN bnr, GEN subgroup, long prec) |
|---|
| 1876 | |
|---|
| 1877 | # sumiter.c |
|---|
| 1878 | |
|---|
| 1879 | GEN direuler(void *E, GEN (*eval)(GEN,void*), GEN ga, GEN gb, GEN c) |
|---|
| 1880 | GEN direuler0(entree *ep, GEN a, GEN b, char *ch, GEN c) |
|---|
| 1881 | GEN divsum(GEN num,entree *ep, char *ch) |
|---|
| 1882 | void fordiv(GEN a, entree *ep, char *ch) |
|---|
| 1883 | void forpari(entree *ep, GEN a, GEN b, char *ch) |
|---|
| 1884 | void forprime(entree *ep, GEN a, GEN b, char *ch) |
|---|
| 1885 | void forstep(entree *ep, GEN a, GEN b, GEN s, char *ch) |
|---|
| 1886 | void forvec(entree *ep, GEN x, char *ch, long flag) |
|---|
| 1887 | GEN forvec_start(GEN x, long flag, GEN *d, GEN (**next)(GEN,GEN)) |
|---|
| 1888 | GEN intnum(void *E, GEN (*e)(GEN, void*), GEN a,GEN b, GEN tab, long prec) |
|---|
| 1889 | long intnumstep(long prec) |
|---|
| 1890 | GEN intnumromb0(entree *ep, GEN a, GEN b, char *ch, long flag, long prec) |
|---|
| 1891 | GEN intnum0(entree *ep, GEN a, GEN b, char *ch, GEN tab, long prec) |
|---|
| 1892 | GEN intcirc0(entree *ep, GEN a, GEN R, char *ch, GEN tab, long prec) |
|---|
| 1893 | GEN intmellininv0(entree *ep, GEN sig, GEN x, char *ch, GEN tab, long prec) |
|---|
| 1894 | GEN intmellininvshort(GEN sig, GEN x, GEN tab, long prec) |
|---|
| 1895 | GEN intlaplaceinv0(entree *ep, GEN sig, GEN x, char *ch, GEN tab, long prec) |
|---|
| 1896 | GEN intnuminit(GEN a, GEN b, long m, long prec) |
|---|
| 1897 | GEN intnuminitgen0(entree *ep, GEN a, GEN b, char *ch, long m, long flag, long prec) |
|---|
| 1898 | GEN intfuncinit0(entree *ep, GEN a, GEN b, char *ch, long flag, long m, long prec) |
|---|
| 1899 | # GEN intnumdoub0(entree *epx, GEN a, GEN b, entree *epy, char *chc, char *chd, char *chf, GEN tabext, GEN tabint, long prec) |
|---|
| 1900 | GEN intfoursin0(entree *ep, GEN a, GEN b, GEN x, char *ch, GEN tab, long prec) |
|---|
| 1901 | GEN intfourcos0(entree *ep, GEN a, GEN b, GEN x, char *ch, GEN tab, long prec) |
|---|
| 1902 | GEN intfourexp0(entree *ep, GEN a, GEN b, GEN x, char *ch, GEN tab, long prec) |
|---|
| 1903 | GEN sumnum(void *E, GEN (*f)(GEN,void*), GEN a,GEN sig,GEN tab,long flag,long prec) |
|---|
| 1904 | GEN sumnum0(entree *ep, GEN a, GEN sig, char *ch, GEN tab, long flag, long prec) |
|---|
| 1905 | GEN sumnumalt(void *E, GEN (*f)(GEN,void*),GEN a,GEN s,GEN tab,long flag,long prec) |
|---|
| 1906 | GEN sumnumalt0(entree *ep, GEN a, GEN sig, char *ch, GEN tab, long flag, long prec) |
|---|
| 1907 | GEN sumnuminit(GEN sig, long m, long sgn, long prec) |
|---|
| 1908 | GEN matrice(GEN nlig, GEN ncol,entree *ep1, entree *ep2, char *ch) |
|---|
| 1909 | GEN polzag(long n, long m) |
|---|
| 1910 | GEN polzagreel(long n, long m, long prec) |
|---|
| 1911 | GEN prodeuler(void *E, GEN (*eval)(GEN,void*), GEN ga, GEN gb, long prec) |
|---|
| 1912 | GEN prodeuler0(entree *ep, GEN a, GEN b, char *ch, long prec) |
|---|
| 1913 | GEN prodinf(void *E, GEN (*eval)(GEN,void*), GEN a, long prec) |
|---|
| 1914 | GEN prodinf0(entree *ep, GEN a, char *ch, long flag, long prec) |
|---|
| 1915 | GEN prodinf1(void *E, GEN (*eval)(GEN,void*), GEN a, long prec) |
|---|
| 1916 | GEN produit(entree *ep, GEN a, GEN b, char *ch, GEN x) |
|---|
| 1917 | GEN somme(entree *ep, GEN a, GEN b, char *ch, GEN x) |
|---|
| 1918 | GEN sumalt(void *E, GEN (*eval)(GEN,void*), GEN a, long prec) |
|---|
| 1919 | GEN sumalt0(entree *ep, GEN a, char *ch,long flag, long prec) |
|---|
| 1920 | GEN sumalt2(void *E, GEN (*eval)(GEN,void*), GEN a, long prec) |
|---|
| 1921 | GEN sumpos(void *E, GEN (*eval)(GEN,void*), GEN a, long prec) |
|---|
| 1922 | GEN sumpos2(void *E, GEN (*eval)(GEN,void*), GEN a, long prec) |
|---|
| 1923 | GEN sumpos0(entree *ep, GEN a, char *ch, long flag,long prec) |
|---|
| 1924 | GEN suminf(void *E, GEN (*eval)(GEN,void*), GEN a, long prec) |
|---|
| 1925 | GEN suminf0(entree *ep, GEN a, char *ch, long prec) |
|---|
| 1926 | GEN vecteur(GEN nmax, entree *ep, char *ch) |
|---|
| 1927 | GEN vecteursmall(GEN nmax, entree *ep, char *ch) |
|---|
| 1928 | GEN vvecteur(GEN nmax, entree *ep, char *ch) |
|---|
| 1929 | GEN zbrent0(entree *ep, GEN a, GEN b, char *ch, long prec) |
|---|
| 1930 | GEN zbrent(void *E, GEN (*eval)(GEN,void*), GEN a, GEN b, long prec) |
|---|
| 1931 | |
|---|
| 1932 | # thue.c |
|---|
| 1933 | |
|---|
| 1934 | GEN bnfisintnorm(GEN x, GEN y) |
|---|
| 1935 | GEN thue(GEN thueres, GEN rhs, GEN ne) |
|---|
| 1936 | GEN thueinit(GEN pol, long flag, long prec) |
|---|
| 1937 | |
|---|
| 1938 | # trans1.c |
|---|
| 1939 | |
|---|
| 1940 | GEN Pi2n(long n, long prec) |
|---|
| 1941 | GEN PiI2(long prec) |
|---|
| 1942 | GEN PiI2n(long n, long prec) |
|---|
| 1943 | void consteuler(long prec) |
|---|
| 1944 | void constpi(long prec) |
|---|
| 1945 | GEN exp_Ir(GEN x) |
|---|
| 1946 | GEN gcos(GEN x, long prec) |
|---|
| 1947 | GEN gcotan(GEN x, long prec) |
|---|
| 1948 | GEN gexp(GEN x, long prec) |
|---|
| 1949 | GEN glog(GEN x, long prec) |
|---|
| 1950 | GEN gpow(GEN x, GEN n, long prec) |
|---|
| 1951 | GEN gpowgs(GEN x, long n) |
|---|
| 1952 | GEN gsin(GEN x, long prec) |
|---|
| 1953 | void gsincos(GEN x, GEN *s, GEN *c, long prec) |
|---|
| 1954 | GEN gsqrt(GEN x, long prec) |
|---|
| 1955 | GEN gsqrtn(GEN x, GEN n, GEN *zetan, long prec) |
|---|
| 1956 | GEN gtan(GEN x, long prec) |
|---|
| 1957 | GEN log0(GEN x,long flag, long prec) |
|---|
| 1958 | GEN mpcos(GEN x) |
|---|
| 1959 | GEN mpeuler(long prec) |
|---|
| 1960 | GEN mpexp(GEN x) |
|---|
| 1961 | GEN mpexp1(GEN x) |
|---|
| 1962 | GEN mplog(GEN x) |
|---|
| 1963 | GEN mplog2(long prec) |
|---|
| 1964 | GEN mppi(long prec) |
|---|
| 1965 | GEN mpsin(GEN x) |
|---|
| 1966 | void mpsincos(GEN x, GEN *s, GEN *c) |
|---|
| 1967 | GEN sqrtr(GEN x) |
|---|
| 1968 | GEN sqrtnr(GEN x, long n) |
|---|
| 1969 | GEN palog(GEN x) |
|---|
| 1970 | GEN powgi(GEN x, GEN n) |
|---|
| 1971 | GEN teich(GEN x) |
|---|
| 1972 | |
|---|
| 1973 | # trans2.c |
|---|
| 1974 | |
|---|
| 1975 | GEN bernfrac(long n) |
|---|
| 1976 | GEN bernreal(long n, long prec) |
|---|
| 1977 | GEN bernvec(long nomb) |
|---|
| 1978 | GEN gach(GEN x, long prec) |
|---|
| 1979 | GEN gacos(GEN x, long prec) |
|---|
| 1980 | GEN garg(GEN x, long prec) |
|---|
| 1981 | GEN gash(GEN x, long prec) |
|---|
| 1982 | GEN gasin(GEN x, long prec) |
|---|
| 1983 | GEN gatan(GEN x, long prec) |
|---|
| 1984 | GEN gath(GEN x, long prec) |
|---|
| 1985 | GEN gch(GEN x, long prec) |
|---|
| 1986 | GEN ggamd(GEN x, long prec) |
|---|
| 1987 | GEN ggamma(GEN x, long prec) |
|---|
| 1988 | GEN glngamma(GEN x, long prec) |
|---|
| 1989 | GEN gpsi(GEN x, long prec) |
|---|
| 1990 | GEN gsh(GEN x, long prec) |
|---|
| 1991 | GEN gth(GEN x, long prec) |
|---|
| 1992 | void mpbern(long nomb, long prec) |
|---|
| 1993 | |
|---|
| 1994 | # trans3.c |
|---|
| 1995 | |
|---|
| 1996 | GEN agm(GEN x, GEN y, long prec) |
|---|
| 1997 | GEN dilog(GEN x, long prec) |
|---|
| 1998 | GEN eint1(GEN x, long prec) |
|---|
| 1999 | GEN eta(GEN x, long prec) |
|---|
| 2000 | GEN eta0(GEN x, long flag,long prec) |
|---|
| 2001 | GEN gerfc(GEN x, long prec) |
|---|
| 2002 | GEN gpolylog(long m, GEN x, long prec) |
|---|
| 2003 | void gpolylogz(long m, GEN x, GEN y) |
|---|
| 2004 | GEN gzeta(GEN x, long prec) |
|---|
| 2005 | GEN hyperu(GEN a, GEN b, GEN gx, long prec) |
|---|
| 2006 | GEN incgam(GEN a, GEN x, long prec) |
|---|
| 2007 | GEN incgam0(GEN a, GEN x, GEN z,long prec) |
|---|
| 2008 | GEN incgam1(GEN a, GEN x, long prec) |
|---|
| 2009 | GEN incgam2(GEN a, GEN x, long prec) |
|---|
| 2010 | GEN incgam3(GEN a, GEN x, long prec) |
|---|
| 2011 | GEN incgamc(GEN a, GEN x, long prec) |
|---|
| 2012 | GEN hbessel1(GEN n, GEN z, long prec) |
|---|
| 2013 | GEN hbessel2(GEN n, GEN z, long prec) |
|---|
| 2014 | GEN ibessel(GEN n, GEN z, long prec) |
|---|
| 2015 | GEN jbessel(GEN n, GEN z, long prec) |
|---|
| 2016 | GEN jbesselh(GEN n, GEN z, long prec) |
|---|
| 2017 | GEN nbessel(GEN n, GEN z, long prec) |
|---|
| 2018 | GEN jell(GEN x, long prec) |
|---|
| 2019 | GEN kbessel(GEN nu, GEN gx, long prec) |
|---|
| 2020 | GEN kbessel0(GEN nu, GEN gx, long flag,long prec) |
|---|
| 2021 | GEN kbessel2(GEN nu, GEN x, long prec) |
|---|
| 2022 | GEN polylog(long m, GEN x, long prec) |
|---|
| 2023 | GEN polylog0(long m, GEN x, long flag, long prec) |
|---|
| 2024 | GEN polylogd(long m, GEN x, long prec) |
|---|
| 2025 | GEN polylogdold(long m, GEN x, long prec) |
|---|
| 2026 | GEN polylogp(long m, GEN x, long prec) |
|---|
| 2027 | GEN szeta(long x, long prec) |
|---|
| 2028 | GEN theta(GEN q, GEN z, long prec) |
|---|
| 2029 | GEN thetanullk(GEN q, long k, long prec) |
|---|
| 2030 | GEN trueeta(GEN x, long prec) |
|---|
| 2031 | GEN veceint1(GEN C, GEN nmax, long prec) |
|---|
| 2032 | GEN vecthetanullk(GEN q, long k, long prec) |
|---|
| 2033 | GEN weber0(GEN x, long flag,long prec) |
|---|
| 2034 | GEN wf(GEN x, long prec) |
|---|
| 2035 | GEN wf2(GEN x, long prec) |
|---|
| 2036 | |
|---|
| 2037 | GEN padicfieldslist(GEN p, GEN m, GEN d, long flag) |
|---|
| 2038 | |
|---|
| 2039 | cdef extern from 'pari/pari.h': |
|---|
| 2040 | extern GEN geuler |
|---|
| 2041 | extern GEN gpi |
|---|
| 2042 | |
|---|
| 2043 | |
|---|
| 2044 | cdef extern from 'pari/paripriv.h': |
|---|
| 2045 | struct __x: |
|---|
| 2046 | char format # e,f,g |
|---|
| 2047 | long fieldw # 0 (ignored) or field width |
|---|
| 2048 | long sigd # -1 (all) or number of significant digits printed */ |
|---|
| 2049 | int sp # 0 = suppress whitespace from output */ |
|---|
| 2050 | int prettyp # output style: raw, prettyprint, etc */ |
|---|
| 2051 | int TeXstyle |
|---|
| 2052 | ctypedef __x pariout_t |
|---|
| 2053 | |
|---|
| 2054 | struct __z: |
|---|
| 2055 | jmp_buf env |
|---|
| 2056 | pariout_t *fmt |
|---|
| 2057 | ctypedef __z gp_data |
|---|
| 2058 | extern gp_data* GP_DATA |
|---|
| 2059 | |
|---|
| 2060 | # Initialize the relevant part of GP for exception trapping. |
|---|
| 2061 | cdef gp_data __GP_DATA |
|---|
| 2062 | GP_DATA = &__GP_DATA |
|---|
| 2063 | |
|---|
| 2064 | cdef int REAL_PREC |
|---|
| 2065 | REAL_PREC = 5 |
|---|
| 2066 | |
|---|
| 2067 | cdef int is_int_or_real_type(GEN g): |
|---|
| 2068 | cdef int t |
|---|
| 2069 | t = typ(g) |
|---|
| 2070 | return t==t_INT or t==t_REAL |
|---|
| 2071 | |
|---|
| 2072 | cdef size_t fix_size(size_t a): |
|---|
| 2073 | cdef size_t b |
|---|
| 2074 | b = a - (a & (BYTES_IN_LONG-1)) # sizeof(long) | b <= a |
|---|
| 2075 | if b < 1024: |
|---|
| 2076 | b = 1024 |
|---|
| 2077 | return b |
|---|
| 2078 | |
|---|
| 2079 | cdef int init_stack(size_t size) except -1: |
|---|
| 2080 | cdef size_t s |
|---|
| 2081 | |
|---|
| 2082 | global top, bot, avma, stack_avma |
|---|
| 2083 | |
|---|
| 2084 | # delete this if get core dumps and change the 2* to a 1* below. |
|---|
| 2085 | if bot: |
|---|
| 2086 | #print "Freeing the old stack." |
|---|
| 2087 | PyMem_Free(<void*>bot) |
|---|
| 2088 | |
|---|
| 2089 | if size == 0: |
|---|
| 2090 | size = 2*(top-bot) |
|---|
| 2091 | |
|---|
| 2092 | # if size == -1, then allocate the biggest chunk possible |
|---|
| 2093 | if size == -1: |
|---|
| 2094 | s = 4294967295 |
|---|
| 2095 | while True: |
|---|
| 2096 | s = fix_size(s) |
|---|
| 2097 | bot = <pari_sp> PyMem_Malloc(s) |
|---|
| 2098 | if bot: |
|---|
| 2099 | break |
|---|
| 2100 | s = s/2 |
|---|
| 2101 | else: |
|---|
| 2102 | # Decide on size |
|---|
| 2103 | s = fix_size(size) |
|---|
| 2104 | |
|---|
| 2105 | # Alocate memory for new stack using Python's memory allocator. |
|---|
| 2106 | # As explained in the python/C api reference, using this instead |
|---|
| 2107 | # of malloc is much better (and more platform independent, etc.) |
|---|
| 2108 | bot = <pari_sp> PyMem_Malloc(s) |
|---|
| 2109 | if not bot: |
|---|
| 2110 | raise MemoryError, "Unable to allocate %s bytes memory for PARI."%(<long>size) |
|---|
| 2111 | #endif |
|---|
| 2112 | |
|---|
| 2113 | top = bot + s |
|---|
| 2114 | avma = top |
|---|
| 2115 | stack_avma = avma |
|---|
| 2116 | |
|---|
| 2117 | |
|---|
| 2118 | def _my_sigint(signum, frame): |
|---|
| 2119 | raise KeyboardInterrupt |
|---|
| 2120 | |
|---|
| 2121 | #def _my_sigsegv(signum, frame): |
|---|
| 2122 | # exit(0) |
|---|
| 2123 | #raise RuntimeError |
|---|
| 2124 | |
|---|
| 2125 | def _my_sigpipe(signum, frame): |
|---|
| 2126 | #raise IOError, (32,'Broken pipe') |
|---|
| 2127 | # If I do anything, it messes up Ipython's pager. |
|---|
| 2128 | pass |
|---|
| 2129 | |
|---|
| 2130 | cdef pariout_t fmt |
|---|
| 2131 | cdef unsigned long num_primes |
|---|
| 2132 | |
|---|
| 2133 | def _init_fmt(): |
|---|
| 2134 | GP_DATA.fmt.prettyp = 0 |
|---|
| 2135 | |
|---|
| 2136 | def pari_version(): |
|---|
| 2137 | return str(PARIVERSION) |
|---|
| 2138 | |
|---|
| 2139 | def _init(long size=200000000, unsigned long maxprime=500000): |
|---|
| 2140 | #def _init(long size=-1, unsigned long maxprime=500000): |
|---|
| 2141 | """ |
|---|
| 2142 | Initialize the PARI system. |
|---|
| 2143 | |
|---|
| 2144 | INPUT: |
|---|
| 2145 | size -- long, the number of bytes for the initial PARI stack |
|---|
| 2146 | (see note below) |
|---|
| 2147 | maxprime -- unsigned long, upper limit on a precomputed prime |
|---|
| 2148 | number table (default: 500000) |
|---|
| 2149 | |
|---|
| 2150 | NOTES: |
|---|
| 2151 | |
|---|
| 2152 | * In py_pari, the PARI stack is different than in gp or the |
|---|
| 2153 | PARI C library. In Python, instead of the PARI stack |
|---|
| 2154 | holding the results of all computations, it *only* holds the |
|---|
| 2155 | results of an individual computation. Each time a new |
|---|
| 2156 | Python/PARI object is computed, it it copied to its own |
|---|
| 2157 | space in the Python heap, and the memory it occupied on the |
|---|
| 2158 | PARI stack is freed. Thus it is not necessary to make the |
|---|
| 2159 | stack very large. Also, unlike in PARI, if the stack does |
|---|
| 2160 | overflow, in most cases the PARI stack is automatically |
|---|
| 2161 | increased and the relevant step of the computation rerun. |
|---|
| 2162 | |
|---|
| 2163 | This design obviously involves some performance penalties |
|---|
| 2164 | over the way PARI works, but it scales much better and is |
|---|
| 2165 | far more robus for large projects. |
|---|
| 2166 | |
|---|
| 2167 | * If you do not want prime numbers, put maxprime=2, but be |
|---|
| 2168 | careful because many PARI functions require this table. If |
|---|
| 2169 | you get the error message "not enough precomputed primes", |
|---|
| 2170 | increase this parameter. |
|---|
| 2171 | |
|---|
| 2172 | """ |
|---|
| 2173 | global initialized, num_primes, ZERO, ONE, TWO, avma, top, bot |
|---|
| 2174 | if bot: |
|---|
| 2175 | raise RuntimeError, "pari_init has already been called." |
|---|
| 2176 | #print "Initializing PARI (size=%s, maxprime=%s)"%(size,maxprime) |
|---|
| 2177 | pari_init(1024, maxprime) |
|---|
| 2178 | |
|---|
| 2179 | init_stack(size) |
|---|
| 2180 | _init_fmt() |
|---|
| 2181 | |
|---|
| 2182 | # Take control of SIGINT back from PARI. |
|---|
| 2183 | import signal |
|---|
| 2184 | signal.signal(signal.SIGINT, _my_sigint) |
|---|
| 2185 | signal.signal(signal.SIGSEGV, signal.SIG_DFL) |
|---|
| 2186 | |
|---|
| 2187 | # We do the following, since otherwise the IPython pager |
|---|
| 2188 | # causes sage to crash when it is exited early. Again, |
|---|
| 2189 | # this is because when PARI was initialized it set a trap |
|---|
| 2190 | # for this signal. |
|---|
| 2191 | signal.signal(signal.SIGPIPE, _my_sigpipe) |
|---|
| 2192 | initialized = 1 |
|---|
| 2193 | stack_avma = avma |
|---|
| 2194 | num_primes = maxprime |
|---|
| 2195 | ZERO = pari(0) # todo: gen_0 |
|---|
| 2196 | ONE = pari(1) |
|---|
| 2197 | TWO = pari(2) |
|---|
| 2198 | return 0 |
|---|
| 2199 | |
|---|
| 2200 | |
|---|
| 2201 | ############################################################ |
|---|
| 2202 | # conversion between GEN and string types |
|---|
| 2203 | # Note that string --> GEN evaluates the string in PARI, |
|---|
| 2204 | # where GEN_to_str returns a Python string. |
|---|
| 2205 | ############################################################ |
|---|
| 2206 | |
|---|
| 2207 | |
|---|
| 2208 | cdef GEN str_to_GEN(char* s) except NULL: |
|---|
| 2209 | cdef int n |
|---|
| 2210 | n = setjmp(GP_DATA.env) |
|---|
| 2211 | if n: _error(n,s) |
|---|
| 2212 | return flisseq(s) |
|---|
| 2213 | |
|---|
| 2214 | cdef object GEN_to_str(GEN g): |
|---|
| 2215 | cdef char* c |
|---|
| 2216 | cdef int n |
|---|
| 2217 | _sig_on |
|---|
| 2218 | c = GENtostr(g) |
|---|
| 2219 | _sig_off |
|---|
| 2220 | s = str(c) |
|---|
| 2221 | free(c) |
|---|
| 2222 | return s |
|---|
| 2223 | |
|---|
| 2224 | |
|---|
| 2225 | |
|---|
| 2226 | |
|---|
| 2227 | ############################################################ |
|---|
| 2228 | # Extension class that models the PARI GEN type. |
|---|
| 2229 | ############################################################ |
|---|
| 2230 | |
|---|
| 2231 | cdef class gen: |
|---|
| 2232 | """ |
|---|
| 2233 | Python extension class that models the PARI GEN type. |
|---|
| 2234 | """ |
|---|
| 2235 | cdef GEN g |
|---|
| 2236 | cdef object refers_to |
|---|
| 2237 | cdef pari_sp b |
|---|
| 2238 | |
|---|
| 2239 | cdef init(self, GEN g, pari_sp b): |
|---|
| 2240 | """ |
|---|
| 2241 | g -- PARI GEN |
|---|
| 2242 | b -- pointer to memory chunk where PARI gen lives |
|---|
| 2243 | (if nonzero then this memory is freed when the object |
|---|
| 2244 | goes out of scope) |
|---|
| 2245 | """ |
|---|
| 2246 | self.g = g |
|---|
| 2247 | self.b = b |
|---|
| 2248 | self.refers_to = {} |
|---|
| 2249 | |
|---|
| 2250 | def __dealloc__(self): |
|---|
| 2251 | if self.b: |
|---|
| 2252 | #print "Freeing a PARI/Python object." |
|---|
| 2253 | PyMem_Free(<void*> self.b) |
|---|
| 2254 | |
|---|
| 2255 | def __repr__(self): |
|---|
| 2256 | return(GEN_to_str(self.g)) |
|---|
| 2257 | |
|---|
| 2258 | cdef GEN _gen(self): |
|---|
| 2259 | return self.g |
|---|
| 2260 | |
|---|
| 2261 | def __reduce__(self): |
|---|
| 2262 | z = str(self) |
|---|
| 2263 | import sage.pari.py_pari_py |
|---|
| 2264 | return sage.pari.py_pari_py.pari, (z,) |
|---|
| 2265 | |
|---|
| 2266 | ########################################### |
|---|
| 2267 | # ARITHMETIC |
|---|
| 2268 | ########################################### |
|---|
| 2269 | |
|---|
| 2270 | def _add(gen self, gen other): |
|---|
| 2271 | n = setjmp(GP_DATA.env) |
|---|
| 2272 | if n: _error(n,"error adding PARI objects") |
|---|
| 2273 | _sig_on |
|---|
| 2274 | return new_gen(gadd(forcecopy(self.g), other.g)) |
|---|
| 2275 | |
|---|
| 2276 | def _sub(gen self, gen other): |
|---|
| 2277 | n = setjmp(GP_DATA.env) |
|---|
| 2278 | if n: _error(n,"error subtracting PARI objects") |
|---|
| 2279 | _sig_on |
|---|
| 2280 | return new_gen(gsub(forcecopy(self.g), other.g)) |
|---|
| 2281 | |
|---|
| 2282 | def _mul(gen self, gen other): |
|---|
| 2283 | n = setjmp(GP_DATA.env) |
|---|
| 2284 | if n: _error(n,"error multiplying PARI objects") |
|---|
| 2285 | _sig_on |
|---|
| 2286 | return new_gen(gmul(forcecopy(self.g), other.g)) |
|---|
| 2287 | |
|---|
| 2288 | def _div(gen self, gen other): |
|---|
| 2289 | n = setjmp(GP_DATA.env) |
|---|
| 2290 | if n: _error(n,"error dividing PARI objects") |
|---|
| 2291 | _sig_on |
|---|
| 2292 | return new_gen(gdiv(forcecopy(self.g), forcecopy(other.g))) |
|---|
| 2293 | |
|---|
| 2294 | def _mod(gen self, gen other): |
|---|
| 2295 | n = setjmp(GP_DATA.env) |
|---|
| 2296 | if n: _error(n,"error quotienting PARI objects") |
|---|
| 2297 | _sig_on |
|---|
| 2298 | return new_gen(gmod(forcecopy(self.g), other.g)) |
|---|
| 2299 | |
|---|
| 2300 | def __add__(self, other): |
|---|
| 2301 | self = pari(self); other = pari(other) |
|---|
| 2302 | return self._add(other) |
|---|
| 2303 | |
|---|
| 2304 | def __sub__(self, other): |
|---|
| 2305 | self = pari(self); other = pari(other) |
|---|
| 2306 | return self._sub(other) |
|---|
| 2307 | |
|---|
| 2308 | def __mul__(self, other): |
|---|
| 2309 | self = pari(self); other = pari(other) |
|---|
| 2310 | return self._mul(other) |
|---|
| 2311 | |
|---|
| 2312 | def __div__(self, other): |
|---|
| 2313 | self = pari(self); other = pari(other) |
|---|
| 2314 | return self._div(other) |
|---|
| 2315 | |
|---|
| 2316 | def __mod__(self, other): |
|---|
| 2317 | self = pari(self); other = pari(other) |
|---|
| 2318 | return self._mod(other) |
|---|
| 2319 | |
|---|
| 2320 | def __neg__(gen self): |
|---|
| 2321 | _sig_on |
|---|
| 2322 | return new_gen(gneg(forcecopy(self.g))) |
|---|
| 2323 | |
|---|
| 2324 | def __pow__(self, n, m): |
|---|
| 2325 | cdef gen _n, _self |
|---|
| 2326 | _n = pari(n) |
|---|
| 2327 | _self = pari(self) |
|---|
| 2328 | |
|---|
| 2329 | cdef int j |
|---|
| 2330 | j = setjmp(GP_DATA.env) |
|---|
| 2331 | if j: |
|---|
| 2332 | _error(j,"error exponentiating PARI object") |
|---|
| 2333 | |
|---|
| 2334 | _sig_on |
|---|
| 2335 | return new_gen(gpow(forcecopy(_self.g), _n.g, REAL_PREC)) |
|---|
| 2336 | |
|---|
| 2337 | def __xor__(gen self, n): |
|---|
| 2338 | raise RuntimeError, "Use ** for exponentiation, not '^', which means xor\n"+\ |
|---|
| 2339 | "in Python, and has the wrong precedence." |
|---|
| 2340 | |
|---|
| 2341 | def __rshift__(gen self, long n): |
|---|
| 2342 | n = setjmp(GP_DATA.env) |
|---|
| 2343 | if n: _error(n,"error right shifting PARI object") |
|---|
| 2344 | _sig_on |
|---|
| 2345 | return new_gen(gshift(forcecopy(self.g), -n)) |
|---|
| 2346 | |
|---|
| 2347 | def __lshift__(gen self, long n): |
|---|
| 2348 | n = setjmp(GP_DATA.env) |
|---|
| 2349 | if n: _error(n,"error left shifting PARI object") |
|---|
| 2350 | _sig_on |
|---|
| 2351 | return new_gen(gshift(forcecopy(self.g), n)) |
|---|
| 2352 | |
|---|
| 2353 | def __invert__(gen self): |
|---|
| 2354 | n = setjmp(GP_DATA.env) |
|---|
| 2355 | if n: _error(n,"error inverting PARI object") |
|---|
| 2356 | _sig_on |
|---|
| 2357 | return new_gen(ginv(forcecopy(self.g))) |
|---|
| 2358 | |
|---|
| 2359 | ########################################### |
|---|
| 2360 | # ACCESS |
|---|
| 2361 | ########################################### |
|---|
| 2362 | def __getitem__(gen self, n): |
|---|
| 2363 | """ |
|---|
| 2364 | Return a *copy* of the nth entry. |
|---|
| 2365 | |
|---|
| 2366 | The indexing is 0-based, like in Python. However, *copying* |
|---|
| 2367 | the nth entry instead of returning reference is different |
|---|
| 2368 | than what one usually does in Python. However, we do it |
|---|
| 2369 | this way for consistency with the PARI/GP interpreter, which |
|---|
| 2370 | does make copies. |
|---|
| 2371 | """ |
|---|
| 2372 | if typ(self.g) == t_POL: |
|---|
| 2373 | return self.polcoeff(n) |
|---|
| 2374 | |
|---|
| 2375 | if isinstance(n, tuple): |
|---|
| 2376 | i, j = n[0], n[1] |
|---|
| 2377 | if i < 0 or i >= self.nrows(): |
|---|
| 2378 | raise IndexError, "row i(=%s) must be between 0 and %s"%(i,self.nrows()) |
|---|
| 2379 | if j < 0 or j >= self.ncols(): |
|---|
| 2380 | raise IndexError, "column j(=%s) must be between 0 and %s"%(j,self.ncols()) |
|---|
| 2381 | return new_ref( <GEN> (<GEN>(self.g)[j+1])[i+1], self ) |
|---|
| 2382 | |
|---|
| 2383 | if n < 0 or n >= glength(self.g): |
|---|
| 2384 | raise IndexError, "index (%s) must be between 0 and %s"%(n,glength(self.g)-1) |
|---|
| 2385 | return new_ref(<GEN> (self.g[n+1]), self) |
|---|
| 2386 | |
|---|
| 2387 | |
|---|
| 2388 | def __getslice__(self, Py_ssize_t i, Py_ssize_t j): |
|---|
| 2389 | """ |
|---|
| 2390 | EXAMPLES: |
|---|
| 2391 | sage: v = pari(xrange(20)) |
|---|
| 2392 | sage: v[2:5] |
|---|
| 2393 | [2, 3, 4] |
|---|
| 2394 | sage: v[:] |
|---|
| 2395 | [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] |
|---|
| 2396 | sage: v[10:] |
|---|
| 2397 | [10, 11, 12, 13, 14, 15, 16, 17, 18, 19] |
|---|
| 2398 | sage: v[:5] |
|---|
| 2399 | [0, 1, 2, 3, 4] |
|---|
| 2400 | sage: v |
|---|
| 2401 | [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] |
|---|
| 2402 | sage: v[-1] |
|---|
| 2403 | Traceback (most recent call last): |
|---|
| 2404 | ... |
|---|
| 2405 | IndexError: index (-1) must be between 0 and 19 |
|---|
| 2406 | sage: v[:-3] |
|---|
| 2407 | [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] |
|---|
| 2408 | sage: v[5:] |
|---|
| 2409 | [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] |
|---|
| 2410 | """ |
|---|
| 2411 | cdef long l, k |
|---|
| 2412 | l = glength(self.g) |
|---|
| 2413 | if j >= l: j = l |
|---|
| 2414 | if i < 0: i = 0 |
|---|
| 2415 | if j <= i: return vector(0) |
|---|
| 2416 | v = vector(j-i) |
|---|
| 2417 | for k from i <= k < j: |
|---|
| 2418 | v[k-i] = self[k] |
|---|
| 2419 | return v |
|---|
| 2420 | |
|---|
| 2421 | def __setitem__(gen self, n, y): |
|---|
| 2422 | r""" |
|---|
| 2423 | Set the nth entry to a reference to y. |
|---|
| 2424 | |
|---|
| 2425 | \begin{notice} |
|---|
| 2426 | \begin{itemize} |
|---|
| 2427 | \item There is a known BUG: If v is a vector and entry i of v is a vector, |
|---|
| 2428 | \code{v[i][j] = x} |
|---|
| 2429 | should set entry j of v[i] to x. Instead it sets it to nonsense. |
|---|
| 2430 | I do not understand why this occurs. The following is a safe way |
|---|
| 2431 | to do the same thing: |
|---|
| 2432 | \code{tmp = v[i]; tmp[j] = x } |
|---|
| 2433 | |
|---|
| 2434 | \item The indexing is 0-based, like everywhere else in Python, but |
|---|
| 2435 | {\em unlike} in GP/PARI. |
|---|
| 2436 | |
|---|
| 2437 | \item Assignment sets the nth entry to a reference to y, |
|---|
| 2438 | assuming y is an object of type gen. This is the same |
|---|
| 2439 | as in Python, but {\em different} than what happens in the |
|---|
| 2440 | gp interpreter, where assignment makes a copy of y. |
|---|
| 2441 | |
|---|
| 2442 | \item Because setting creates references it is {\em possible} to |
|---|
| 2443 | make circular references, unlike in GP. Do {\em not} do |
|---|
| 2444 | this (see the example below). If you need circular |
|---|
| 2445 | references, work at the Python level (where they work |
|---|
| 2446 | well), not the PARI object level. |
|---|
| 2447 | \end{itemize} |
|---|
| 2448 | \end{notice} |
|---|
| 2449 | |
|---|
| 2450 | EXAMPLES: |
|---|
| 2451 | sage: v = pari(range(10)) |
|---|
| 2452 | sage: v |
|---|
| 2453 | [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] |
|---|
| 2454 | sage: v[0] = 10 |
|---|
| 2455 | sage: w = pari([5,8,-20]) |
|---|
| 2456 | sage: v |
|---|
| 2457 | [10, 1, 2, 3, 4, 5, 6, 7, 8, 9] |
|---|
| 2458 | sage: v[1] = w |
|---|
| 2459 | sage: v |
|---|
| 2460 | [10, [5, 8, -20], 2, 3, 4, 5, 6, 7, 8, 9] |
|---|
| 2461 | sage: w[0] = -30 |
|---|
| 2462 | sage: v |
|---|
| 2463 | [10, [-30, 8, -20], 2, 3, 4, 5, 6, 7, 8, 9] |
|---|
| 2464 | sage: t = v[1]; t[1] = 10 # don't do v[1][1] !!! (because of mysterious BUG...) |
|---|
| 2465 | sage: v |
|---|
| 2466 | [10, [-30, 10, -20], 2, 3, 4, 5, 6, 7, 8, 9] |
|---|
| 2467 | sage: w |
|---|
| 2468 | [-30, 10, -20] |
|---|
| 2469 | |
|---|
| 2470 | Finally, we create a circular reference: |
|---|
| 2471 | sage: v = pari([0]) |
|---|
| 2472 | sage: w = pari([v]) |
|---|
| 2473 | sage: v |
|---|
| 2474 | [0] |
|---|
| 2475 | sage: w |
|---|
| 2476 | [[0]] |
|---|
| 2477 | sage: v[0] = w |
|---|
| 2478 | sage: # Now there is a circular reference. Trying to access v[0] will crash SAGE. |
|---|
| 2479 | |
|---|
| 2480 | """ |
|---|
| 2481 | cdef int e |
|---|
| 2482 | e = setjmp(GP_DATA.env) |
|---|
| 2483 | if e: _error(e,"__setitem__") |
|---|
| 2484 | |
|---|
| 2485 | cdef gen x |
|---|
| 2486 | x = pari(y) |
|---|
| 2487 | if isinstance(n, tuple): |
|---|
| 2488 | self.refers_to[n] = x |
|---|
| 2489 | i = n[0] |
|---|
| 2490 | j = n[1] |
|---|
| 2491 | if i < 0 or i >= self.nrows(): |
|---|
| 2492 | raise IndexError, "row i(=%s) must be between 0 and %s"%(i,self.nrows()) |
|---|
| 2493 | if j < 0 or j >= self.ncols(): |
|---|
| 2494 | raise IndexError, "column j(=%s) must be between 0 and %s"%(j,self.ncols()) |
|---|
| 2495 | (<GEN>(self.g)[j+1])[i+1] = <long> x.g |
|---|
| 2496 | return |
|---|
| 2497 | |
|---|
| 2498 | if n < 0 or n >= glength(self.g): |
|---|
| 2499 | raise IndexError, "index (%s) must be between 0 and %s"%(n,glength(self.g)-1) |
|---|
| 2500 | self.refers_to[n] = x # so python memory manager will work correctly |
|---|
| 2501 | # and not free x if PARI part of self is the |
|---|
| 2502 | # only thing pointing to it. |
|---|
| 2503 | e = setjmp(GP_DATA.env) |
|---|
| 2504 | if e: _error(e,"__setitem__") |
|---|
| 2505 | (self.g)[n+1] = <long>(x.g) |
|---|
| 2506 | |
|---|
| 2507 | def __len__(gen self): |
|---|
| 2508 | return glength(self.g) |
|---|
| 2509 | |
|---|
| 2510 | def ncols(gen self): |
|---|
| 2511 | return glength(self.g) |
|---|
| 2512 | |
|---|
| 2513 | def nrows(gen self): |
|---|
| 2514 | cdef int n |
|---|
| 2515 | n = setjmp(GP_DATA.env) |
|---|
| 2516 | if n: _error(n,"nrows") |
|---|
| 2517 | return glength(<GEN>(self.g[1])) |
|---|
| 2518 | |
|---|
| 2519 | def polcoeff(gen self, long n, var=-1): |
|---|
| 2520 | """ |
|---|
| 2521 | EXAMPLES: |
|---|
| 2522 | sage: f = pari("x^2 + y^3 + x*y") |
|---|
| 2523 | sage: f |
|---|
| 2524 | x^2 + y*x + y^3 |
|---|
| 2525 | sage: f.polcoeff(1) |
|---|
| 2526 | y |
|---|
| 2527 | sage: f.polcoeff(3) |
|---|
| 2528 | 0 |
|---|
| 2529 | sage: f.polcoeff(3, "y") |
|---|
| 2530 | 1 |
|---|
| 2531 | sage: f.polcoeff(1, "y") |
|---|
| 2532 | x |
|---|
| 2533 | """ |
|---|
| 2534 | return new_gen(polcoeff0(forcecopy(self.g), n, get_var(var))) |
|---|
| 2535 | |
|---|
| 2536 | |
|---|
| 2537 | ########################################### |
|---|
| 2538 | # ? |
|---|
| 2539 | ########################################### |
|---|
| 2540 | |
|---|
| 2541 | def __cmp__(gen self, gen other): |
|---|
| 2542 | """ |
|---|
| 2543 | Comparisons. |
|---|
| 2544 | """ |
|---|
| 2545 | if gegal(self.g, other.g): |
|---|
| 2546 | return 0 |
|---|
| 2547 | cdef int tg, to |
|---|
| 2548 | tg = typ(self.g) |
|---|
| 2549 | to = typ(other.g) |
|---|
| 2550 | |
|---|
| 2551 | if is_int_or_real_type(self.g) and is_int_or_real_type(other.g): |
|---|
| 2552 | return gcmp(self.g, other.g) |
|---|
| 2553 | |
|---|
| 2554 | sg = str(self) |
|---|
| 2555 | so = str(other) |
|---|
| 2556 | if sg < so: |
|---|
| 2557 | return -1 |
|---|
| 2558 | else: |
|---|
| 2559 | return 1 |
|---|
| 2560 | |
|---|
| 2561 | |
|---|
| 2562 | def __richcmp__(gen self, other, int op): |
|---|
| 2563 | """ |
|---|
| 2564 | EXAMPLES: |
|---|
| 2565 | sage: a = pari(5) |
|---|
| 2566 | sage: b = 10 |
|---|
| 2567 | sage: a < b |
|---|
| 2568 | True |
|---|
| 2569 | sage: a <= b |
|---|
| 2570 | True |
|---|
| 2571 | sage: a <= 5 |
|---|
| 2572 | True |
|---|
| 2573 | sage: a > b |
|---|
| 2574 | False |
|---|
| 2575 | sage: a >= b |
|---|
| 2576 | False |
|---|
| 2577 | sage: a >= pari(10) |
|---|
| 2578 | False |
|---|
| 2579 | sage: a == 5 |
|---|
| 2580 | True |
|---|
| 2581 | sage: a is 5 |
|---|
| 2582 | False |
|---|
| 2583 | """ |
|---|
| 2584 | cdef int n |
|---|
| 2585 | cdef gen x |
|---|
| 2586 | x = pari(other) |
|---|
| 2587 | n = self.__cmp__(x) |
|---|
| 2588 | if op == 0: |
|---|
| 2589 | return bool(n < 0) |
|---|
| 2590 | elif op == 1: |
|---|
| 2591 | return bool(n <= 0) |
|---|
| 2592 | elif op == 2: |
|---|
| 2593 | return bool(n == 0) |
|---|
| 2594 | elif op == 3: |
|---|
| 2595 | return bool(n != 0) |
|---|
| 2596 | elif op == 4: |
|---|
| 2597 | return bool(n > 0) |
|---|
| 2598 | elif op == 5: |
|---|
| 2599 | return bool(n >= 0) |
|---|
| 2600 | |
|---|
| 2601 | def copy(gen self): |
|---|
| 2602 | return new_gen(forcecopy(self.g)) |
|---|
| 2603 | |
|---|
| 2604 | |
|---|
| 2605 | ########################################### |
|---|
| 2606 | # Conversion --> Python |
|---|
| 2607 | # Try to convert to a meaningful python object |
|---|
| 2608 | # in various ways |
|---|
| 2609 | ########################################### |
|---|
| 2610 | |
|---|
| 2611 | def list_str(gen self): |
|---|
| 2612 | """ |
|---|
| 2613 | Return str that might correctly evaluate to a Python-list. |
|---|
| 2614 | """ |
|---|
| 2615 | s = str(self) |
|---|
| 2616 | if s[:4] == "Mat(": |
|---|
| 2617 | s = "[" + s[4:-1] + "]" |
|---|
| 2618 | s = s.replace("~","") |
|---|
| 2619 | if s.find(";") != -1: |
|---|
| 2620 | s = s.replace(";","], [") |
|---|
| 2621 | s = "[" + s + "]" |
|---|
| 2622 | return eval(s) |
|---|
| 2623 | else: |
|---|
| 2624 | return eval(s) |
|---|
| 2625 | |
|---|
| 2626 | def __int__(gen self): |
|---|
| 2627 | """ |
|---|
| 2628 | Return Python int. Very fast unless the number is too large too |
|---|
| 2629 | fit into a C int, in which case a string is used. |
|---|
| 2630 | """ |
|---|
| 2631 | return int(str(self)) |
|---|
| 2632 | # NOTE: Could use int_unsafe below, which would be much faster, but |
|---|
| 2633 | # the default PARI prints annoying stuff to the screen when |
|---|
| 2634 | # the number is large. |
|---|
| 2635 | |
|---|
| 2636 | def int_unsafe(gen self): |
|---|
| 2637 | """ |
|---|
| 2638 | Returns int form of self. |
|---|
| 2639 | |
|---|
| 2640 | This is about 5 times faster than the usual int conversion. |
|---|
| 2641 | |
|---|
| 2642 | This function is fast, but if self does not fit in a C int, it |
|---|
| 2643 | will print an error and continue running. This error message |
|---|
| 2644 | is printed by the PARI C library, so I can't turn it off. |
|---|
| 2645 | """ |
|---|
| 2646 | cdef int err |
|---|
| 2647 | err = setjmp(GP_DATA.env) |
|---|
| 2648 | if err: |
|---|
| 2649 | print "(py_pari.int_unsafe(): The above PARI error message can be ignored.)" |
|---|
| 2650 | return int(str(self)) |
|---|
| 2651 | return gtolong(self.g) |
|---|
| 2652 | |
|---|
| 2653 | |
|---|
| 2654 | def python_list(gen self): |
|---|
| 2655 | """ |
|---|
| 2656 | Return a Python list of the PARI gens. This object must be of |
|---|
| 2657 | type t_VEC |
|---|
| 2658 | |
|---|
| 2659 | INPUT: None |
|---|
| 2660 | OUTPUT: |
|---|
| 2661 | list -- Python list whose elements are the |
|---|
| 2662 | elements of the input gen. |
|---|
| 2663 | EXAMPLES: |
|---|
| 2664 | sage: v=pari([1,2,3,10,102,10]) |
|---|
| 2665 | sage: w = v.python_list() |
|---|
| 2666 | sage: w |
|---|
| 2667 | [1, 2, 3, 10, 102, 10] |
|---|
| 2668 | sage: type(w[0]) |
|---|
| 2669 | <type '_py_pari.gen'> |
|---|
| 2670 | """ |
|---|
| 2671 | if typ(self.g) != t_VEC: |
|---|
| 2672 | raise TypeError, "Object (=%s) must be of type t_VEC."%self |
|---|
| 2673 | cdef long n, m |
|---|
| 2674 | cdef gen t |
|---|
| 2675 | m = glength(self.g) |
|---|
| 2676 | V = [] |
|---|
| 2677 | for n from 0 <= n < m: |
|---|
| 2678 | t = new_ref(<GEN> (self.g[n+1]), V) |
|---|
| 2679 | V.append(t) |
|---|
| 2680 | return V |
|---|
| 2681 | |
|---|
| 2682 | def python(gen self): |
|---|
| 2683 | """ |
|---|
| 2684 | Return Python eval of self. |
|---|
| 2685 | """ |
|---|
| 2686 | import sage.pari.py_pari_py |
|---|
| 2687 | return sage.pari.py_pari_py.python(self) |
|---|
| 2688 | |
|---|
| 2689 | def __long__(gen self): |
|---|
| 2690 | """ |
|---|
| 2691 | Return Python long. |
|---|
| 2692 | """ |
|---|
| 2693 | return long(str(self)) |
|---|
| 2694 | #cdef int err |
|---|
| 2695 | #err = setjmp(GP_DATA.env) |
|---|
| 2696 | #if err: |
|---|
| 2697 | # if err == 28: return long(str(self)) |
|---|
| 2698 | # _error(err,"error in __long__") |
|---|
| 2699 | #return long(gtolong(self.g)) |
|---|
| 2700 | |
|---|
| 2701 | def __float__(gen self): |
|---|
| 2702 | """ |
|---|
| 2703 | Return Python float. |
|---|
| 2704 | """ |
|---|
| 2705 | #return float(str(self)) |
|---|
| 2706 | cdef int err |
|---|
| 2707 | err = setjmp(GP_DATA.env) |
|---|
| 2708 | if err: |
|---|
| 2709 | if err == 28: return float(str(self)) |
|---|
| 2710 | _error(err,"error in __float__") |
|---|
| 2711 | return gtodouble(self.g) |
|---|
| 2712 | |
|---|
| 2713 | def __bool__(gen self): |
|---|
| 2714 | cdef int err |
|---|
| 2715 | err = setjmp(GP_DATA.env) |
|---|
| 2716 | if err: |
|---|
| 2717 | _error(err,"error in __bool__") |
|---|
| 2718 | return bool(self.g != stoi(0)) |
|---|
| 2719 | |
|---|
| 2720 | |
|---|
| 2721 | ########################################### |
|---|
| 2722 | # arith1.c |
|---|
| 2723 | ########################################### |
|---|
| 2724 | def isprime(gen self, flag=0): |
|---|
| 2725 | """ |
|---|
| 2726 | isprime(x, flag=0): Returns True if x is a PROVEN prime |
|---|
| 2727 | number, and False otherwise. |
|---|
| 2728 | |
|---|
| 2729 | INPUT: |
|---|
| 2730 | flag -- int |
|---|
| 2731 | 0 (default): use a combination of algorithms. |
|---|
| 2732 | 1: certify primality using the Pocklington-Lehmer Test. |
|---|
| 2733 | 2: certify primality using the APRCL test. |
|---|
| 2734 | OUTPUT: |
|---|
| 2735 | bool -- True or False |
|---|
| 2736 | EXAMPLES: |
|---|
| 2737 | sage: pari(9).isprime() |
|---|
| 2738 | False |
|---|
| 2739 | sage: pari(17).isprime() |
|---|
| 2740 | True |
|---|
| 2741 | sage: n = pari(561) # smallest Carmichael number |
|---|
| 2742 | sage: n.isprime() # not just a pseudo-primality test! |
|---|
| 2743 | False |
|---|
| 2744 | sage: n.isprime(1) |
|---|
| 2745 | False |
|---|
| 2746 | sage: n.isprime(2) |
|---|
| 2747 | False |
|---|
| 2748 | """ |
|---|
| 2749 | _sig_on |
|---|
| 2750 | t = bool(gisprime(self.g, flag) != stoi(0)) |
|---|
| 2751 | _sig_off |
|---|
| 2752 | return t |
|---|
| 2753 | |
|---|
| 2754 | |
|---|
| 2755 | ########################################### |
|---|
| 2756 | # 1: Standard monadic or dyadic OPERATORS |
|---|
| 2757 | ########################################### |
|---|
| 2758 | def divrem(gen x, y, var=-1): |
|---|
| 2759 | """ |
|---|
| 2760 | |
|---|
| 2761 | divrem(x, y, {v}): Euclidean division of x by y giving as a |
|---|
| 2762 | 2-dimensional column vector the quotient and the |
|---|
| 2763 | remainder, with respect to v (to main variable if v is |
|---|
| 2764 | omitted). |
|---|
| 2765 | |
|---|
| 2766 | sage: |
|---|
| 2767 | """ |
|---|
| 2768 | cdef gen _y |
|---|
| 2769 | _y = pari(y) |
|---|
| 2770 | _sig_on |
|---|
| 2771 | return new_gen(divrem(forcecopy(x.g), _y.g, get_var(var))) |
|---|
| 2772 | |
|---|
| 2773 | def lex(gen x, y): |
|---|
| 2774 | """ |
|---|
| 2775 | |
|---|
| 2776 | lex(x,y): Compare x and y lexicographically (1 if x>y, 0 if |
|---|
| 2777 | x==y, -1 if x<y) |
|---|
| 2778 | |
|---|
| 2779 | """ |
|---|
| 2780 | cdef gen _y |
|---|
| 2781 | _y = pari(y) |
|---|
| 2782 | return lexcmp(x.g, _y.g) |
|---|
| 2783 | |
|---|
| 2784 | def max(gen x, y): |
|---|
| 2785 | """ |
|---|
| 2786 | max(x,y): Return the maximum of x and y. |
|---|
| 2787 | """ |
|---|
| 2788 | cdef gen _y |
|---|
| 2789 | _y = pari(y) |
|---|
| 2790 | return new_gen(gmax(forcecopy(x.g), _y.g)) |
|---|
| 2791 | |
|---|
| 2792 | def min(gen x, y): |
|---|
| 2793 | """ |
|---|
| 2794 | min(x,y): Return the minumum of x and y. |
|---|
| 2795 | """ |
|---|
| 2796 | cdef gen _y |
|---|
| 2797 | _y = pari(y) |
|---|
| 2798 | return new_gen(gmin(forcecopy(x.g), _y.g)) |
|---|
| 2799 | |
|---|
| 2800 | def shift(gen x, long n): |
|---|
| 2801 | """ |
|---|
| 2802 | shift(x,n): shift x left n bits if n>=0, right -n bits if n<0. |
|---|
| 2803 | """ |
|---|
| 2804 | return new_gen(gshift(forcecopy(x.g), n)) |
|---|
| 2805 | |
|---|
| 2806 | def shiftmul(gen x, long n): |
|---|
| 2807 | """ |
|---|
| 2808 | shiftmul(x,n): Return the product of x by $2^n$. |
|---|
| 2809 | """ |
|---|
| 2810 | return new_gen(gmul2n(forcecopy(x.g), n)) |
|---|
| 2811 | |
|---|
| 2812 | def sign(gen x): |
|---|
| 2813 | """ |
|---|
| 2814 | sign(x): Return the sign of x, where x is of type integer, real |
|---|
| 2815 | or fraction. |
|---|
| 2816 | """ |
|---|
| 2817 | return gsigne(x.g) |
|---|
| 2818 | |
|---|
| 2819 | def vecmax(gen x): |
|---|
| 2820 | """ |
|---|
| 2821 | vecmax(x): Return the maximum of the elements of the vector/matrix x, |
|---|
| 2822 | """ |
|---|
| 2823 | _sig_on |
|---|
| 2824 | return new_gen(vecmax(forcecopy(x.g))) |
|---|
| 2825 | |
|---|
| 2826 | |
|---|
| 2827 | def vecmin(gen x): |
|---|
| 2828 | """ |
|---|
| 2829 | vecmin(x): Return the maximum of the elements of the vector/matrix x, |
|---|
| 2830 | """ |
|---|
| 2831 | _sig_on |
|---|
| 2832 | return new_gen(vecmin(forcecopy(x.g))) |
|---|
| 2833 | |
|---|
| 2834 | |
|---|
| 2835 | |
|---|
| 2836 | ########################################### |
|---|
| 2837 | # 2: CONVERSIONS and similar elementary functions |
|---|
| 2838 | ########################################### |
|---|
| 2839 | |
|---|
| 2840 | |
|---|
| 2841 | def Col(gen x): |
|---|
| 2842 | """ |
|---|
| 2843 | Col(x): Transforms the object x into a column vector. |
|---|
| 2844 | |
|---|
| 2845 | The vector will have only one component, except in the |
|---|
| 2846 | following cases: |
|---|
| 2847 | |
|---|
| 2848 | * When x is a vector or a quadratic form, the resulting |
|---|
| 2849 | vector is the initial object considered as a column |
|---|
| 2850 | vector. |
|---|
| 2851 | |
|---|
| 2852 | * When x is a matrix, the resulting vector is the column of |
|---|
| 2853 | row vectors comprising the matrix. |
|---|
| 2854 | |
|---|
| 2855 | * When x is a character string, the result is a column of |
|---|
| 2856 | individual characters. |
|---|
| 2857 | |
|---|
| 2858 | * When x is a polynomial, the coefficients of the vector |
|---|
| 2859 | start with the leading coefficient of the polynomial. |
|---|
| 2860 | |
|---|
| 2861 | * When x is a power series, only the significant |
|---|
| 2862 | coefficients are taken into account, but this time by |
|---|
| 2863 | increasing order of degree. |
|---|
| 2864 | |
|---|
| 2865 | INPUT: |
|---|
| 2866 | x -- gen |
|---|
| 2867 | OUTPUT: |
|---|
| 2868 | gen |
|---|
| 2869 | EXAMPLES: |
|---|
| 2870 | sage: pari(1.5).Col() |
|---|
| 2871 | [1.500000000000000000000000000]~ |
|---|
| 2872 | sage: pari([1,2,3,4]).Col() |
|---|
| 2873 | [1, 2, 3, 4]~ |
|---|
| 2874 | sage: pari('[1,2; 3,4]').Col() |
|---|
| 2875 | [[1, 2], [3, 4]]~ |
|---|
| 2876 | sage: pari('"SAGE"').Col() |
|---|
| 2877 | ["S", "A", "G", "E"]~ |
|---|
| 2878 | sage: pari('3*x^3 + x').Col() |
|---|
| 2879 | [3, 0, 1, 0]~ |
|---|
| 2880 | sage: pari('x + 3*x^3 + O(x^5)').Col() |
|---|
| 2881 | [1, 0, 3, 0]~ |
|---|
| 2882 | """ |
|---|
| 2883 | return new_gen(gtocol(x.g)) |
|---|
| 2884 | |
|---|
| 2885 | def List(gen x): |
|---|
| 2886 | """ |
|---|
| 2887 | List(x): transforms the PARI vector or list x into a list. |
|---|
| 2888 | |
|---|
| 2889 | EXAMPLES: |
|---|
| 2890 | sage: v = pari([1,2,3]) |
|---|
| 2891 | sage: v |
|---|
| 2892 | [1, 2, 3] |
|---|
| 2893 | sage: v.type() |
|---|
| 2894 | 't_VEC' |
|---|
| 2895 | sage: w = v.List() |
|---|
| 2896 | sage: w |
|---|
| 2897 | List([1, 2, 3]) |
|---|
| 2898 | sage: w.type() |
|---|
| 2899 | 't_LIST' |
|---|
| 2900 | """ |
|---|
| 2901 | return new_gen(gtolist(forcecopy(x.g))) |
|---|
| 2902 | |
|---|
| 2903 | def Mat(gen x): |
|---|
| 2904 | """ |
|---|
| 2905 | Mat(x): Returns the matrix defined by x. |
|---|
| 2906 | |
|---|
| 2907 | * If x is already a matrix, a copy of x is created and |
|---|
| 2908 | returned. |
|---|
| 2909 | |
|---|
| 2910 | * If x is not a vector or a matrix, this function returns a |
|---|
| 2911 | 1x1 matrix. |
|---|
| 2912 | |
|---|
| 2913 | * If x is a row (resp. column) vector, this functions |
|---|
| 2914 | returns a 1-row (resp. 1-column) matrix, *unless* all |
|---|
| 2915 | elements are column (resp. row) vectors of the same |
|---|
| 2916 | length, in which case the vectors are concatenated |
|---|
| 2917 | sideways and the associated big matrix is returned. |
|---|
| 2918 | |
|---|
| 2919 | INPUT: |
|---|
| 2920 | x -- gen |
|---|
| 2921 | OUTPUT: |
|---|
| 2922 | gen -- a PARI matrix |
|---|
| 2923 | |
|---|
| 2924 | EXAMPLES: |
|---|
| 2925 | sage: x = pari(5) |
|---|
| 2926 | sage: x.type() |
|---|
| 2927 | 't_INT' |
|---|
| 2928 | sage: y = x.Mat() |
|---|
| 2929 | sage: y |
|---|
| 2930 | Mat(5) |
|---|
| 2931 | sage: y.type() |
|---|
| 2932 | 't_MAT' |
|---|
| 2933 | sage: x = pari('[1,2;3,4]') |
|---|
| 2934 | sage: x.type() |
|---|
| 2935 | 't_MAT' |
|---|
| 2936 | sage: x = pari('[1,2,3,4]') |
|---|
| 2937 | sage: x.type() |
|---|
| 2938 | 't_VEC' |
|---|
| 2939 | sage: y = x.Mat() |
|---|
| 2940 | sage: y |
|---|
| 2941 | Mat([1, 2, 3, 4]) |
|---|
| 2942 | sage: y.type() |
|---|
| 2943 | 't_MAT' |
|---|
| 2944 | |
|---|
| 2945 | sage: v = pari('[1,2;3,4]').Vec(); v |
|---|
| 2946 | [[1, 3]~, [2, 4]~] |
|---|
| 2947 | sage: v.Mat() |
|---|
| 2948 | [1, 2; 3, 4] |
|---|
| 2949 | sage: v = pari('[1,2;3,4]').Col(); v |
|---|
| 2950 | [[1, 2], [3, 4]]~ |
|---|
| 2951 | sage: v.Mat() |
|---|
| 2952 | [1, 2; 3, 4] |
|---|
| 2953 | """ |
|---|
| 2954 | return new_gen(gtomat(forcecopy(x.g))) |
|---|
| 2955 | |
|---|
| 2956 | def Mod(gen x, y): |
|---|
| 2957 | """ |
|---|
| 2958 | Mod(x, y): Returns the object x modulo y, denoted Mod(x, y). |
|---|
| 2959 | |
|---|
| 2960 | The input y must be a an integer or a polynomial: |
|---|
| 2961 | |
|---|
| 2962 | * If y is an INTEGER, x must also be an integer, a rational |
|---|
| 2963 | number, or a p-adic number compatible with the modulus y. |
|---|
| 2964 | |
|---|
| 2965 | * If y is a POLYNOMIAL, x must be a scalar (which is not a polmod), |
|---|
| 2966 | a polynomial, a rational function, or a power series. |
|---|
| 2967 | |
|---|
| 2968 | WARNING: This function is not the same as x % y, the result of |
|---|
| 2969 | which is an integer or a polynomial. |
|---|
| 2970 | |
|---|
| 2971 | INPUT: |
|---|
| 2972 | x -- gen |
|---|
| 2973 | y -- integer or polynomial |
|---|
| 2974 | |
|---|
| 2975 | OUTPUT: |
|---|
| 2976 | gen -- intmod or polmod |
|---|
| 2977 | |
|---|
| 2978 | EXAMPLES: |
|---|
| 2979 | sage: z = pari(3) |
|---|
| 2980 | sage: x = z.Mod(pari(7)) |
|---|
| 2981 | sage: x |
|---|
| 2982 | Mod(3, 7) |
|---|
| 2983 | sage: x**2 |
|---|
| 2984 | Mod(2, 7) |
|---|
| 2985 | sage: x**100 |
|---|
| 2986 | Mod(4, 7) |
|---|
| 2987 | sage: x.type() |
|---|
| 2988 | 't_INTMOD' |
|---|
| 2989 | |
|---|
| 2990 | sage: f = pari("x^2 + x + 1") |
|---|
| 2991 | sage: g = pari("x") |
|---|
| 2992 | sage: a = g.Mod(f) |
|---|
| 2993 | sage: a |
|---|
| 2994 | Mod(x, x^2 + x + 1) |
|---|
| 2995 | sage: a*a |
|---|
| 2996 | Mod(-x - 1, x^2 + x + 1) |
|---|
| 2997 | sage: a.type() |
|---|
| 2998 | 't_POLMOD' |
|---|
| 2999 | """ |
|---|
| 3000 | cdef gen _y |
|---|
| 3001 | _y = pari(y) |
|---|
| 3002 | return new_gen(gmodulcp(forcecopy(x.g),_y.g)) |
|---|
| 3003 | |
|---|
| 3004 | def Pol(gen x, v=-1): |
|---|
| 3005 | """ |
|---|
| 3006 | Pol(x, {v}): convert x into a polynomial with main variable v |
|---|
| 3007 | and return the result. |
|---|
| 3008 | |
|---|
| 3009 | * If x is a scalar, returns a constant polynomial. |
|---|
| 3010 | |
|---|
| 3011 | * If x is a power series, the effect is identical |
|---|
| 3012 | to \kbd{truncate}, i.e.~it chops off the $O(X^k)$. |
|---|
| 3013 | |
|---|
| 3014 | * If x is a vector, this function creates the polynomial |
|---|
| 3015 | whose coefficients are given in x, with x[0] |
|---|
| 3016 | being the leading coefficient (which can be zero). |
|---|
| 3017 | |
|---|
| 3018 | WARNING: This is *not* a substitution function. It will not |
|---|
| 3019 | transform an object containing variables of higher priority |
|---|
| 3020 | than v: |
|---|
| 3021 | sage.: pari('x+y').Pol('y') |
|---|
| 3022 | Traceback (most recent call last): |
|---|
| 3023 | ... |
|---|
| 3024 | RuntimeError: PARI error 8: error in Pol |
|---|
| 3025 | |
|---|
| 3026 | INPUT: |
|---|
| 3027 | x -- gen |
|---|
| 3028 | v -- (optional) which variable, defaults to 'x' |
|---|
| 3029 | OUTPUT: |
|---|
| 3030 | gen -- a polynomial |
|---|
| 3031 | EXAMPLES: |
|---|
| 3032 | sage: v = pari("[1,2,3,4]") |
|---|
| 3033 | sage: f = v.Pol() |
|---|
| 3034 | sage: f |
|---|
| 3035 | x^3 + 2*x^2 + 3*x + 4 |
|---|
| 3036 | sage: f*f |
|---|
| 3037 | x^6 + 4*x^5 + 10*x^4 + 20*x^3 + 25*x^2 + 24*x + 16 |
|---|
| 3038 | |
|---|
| 3039 | sage: v = pari("[1,2;3,4]") |
|---|
| 3040 | sage: v.Pol() |
|---|
| 3041 | [1, 3]~*x + [2, 4]~ |
|---|
| 3042 | """ |
|---|
| 3043 | cdef int n |
|---|
| 3044 | n = setjmp(GP_DATA.env) |
|---|
| 3045 | if n: |
|---|
| 3046 | _error(n,"error in Pol") |
|---|
| 3047 | return new_gen(gtopoly(forcecopy(x.g), get_var(v))) |
|---|
| 3048 | |
|---|
| 3049 | def Polrev(gen x, v=-1): |
|---|
| 3050 | """ |
|---|
| 3051 | Polrev(x, {v}): Convert x into a polynomial with main variable |
|---|
| 3052 | v and return the result. This is the reverse of Pol if x is a |
|---|
| 3053 | vector, otherwise it is identical to Pol. By "reverse" we mean |
|---|
| 3054 | that the coefficients are reveresed. |
|---|
| 3055 | |
|---|
| 3056 | INPUT: |
|---|
| 3057 | x -- gen |
|---|
| 3058 | OUTPUT: |
|---|
| 3059 | gen -- a polynomial |
|---|
| 3060 | EXAMPLES: |
|---|
| 3061 | sage: v = pari("[1,2,3,4]") |
|---|
| 3062 | sage: f = v.Polrev() |
|---|
| 3063 | sage: f |
|---|
| 3064 | 4*x^3 + 3*x^2 + 2*x + 1 |
|---|
| 3065 | sage: v.Pol() |
|---|
| 3066 | x^3 + 2*x^2 + 3*x + 4 |
|---|
| 3067 | sage: v.Polrev('y') |
|---|
| 3068 | 4*y^3 + 3*y^2 + 2*y + 1 |
|---|
| 3069 | |
|---|
| 3070 | Note that Polrev does *not* reverse the coefficients of a polynomial! |
|---|
| 3071 | sage: f |
|---|
| 3072 | 4*x^3 + 3*x^2 + 2*x + 1 |
|---|
| 3073 | sage: f.Polrev() |
|---|
| 3074 | 4*x^3 + 3*x^2 + 2*x + 1 |
|---|
| 3075 | sage: v = pari("[1,2;3,4]") |
|---|
| 3076 | sage: v.Polrev() |
|---|
| 3077 | [2, 4]~*x + [1, 3]~ |
|---|
| 3078 | """ |
|---|
| 3079 | cdef int n |
|---|
| 3080 | n = setjmp(GP_DATA.env) |
|---|
| 3081 | if n: |
|---|
| 3082 | _error(n,"error in Polrev") |
|---|
| 3083 | return new_gen(gtopolyrev(forcecopy(x.g),get_var(v))) |
|---|
| 3084 | |
|---|
| 3085 | |
|---|
| 3086 | def Qfb(gen a, b, c, D=0): |
|---|
| 3087 | """ |
|---|
| 3088 | Qfb(a,b,c,{D=0.}): Returns the binary quadratic form |
|---|
| 3089 | $$ |
|---|
| 3090 | ax^2 + bxy + cy^2. |
|---|
| 3091 | $$ |
|---|
| 3092 | The optional D is 0 by default and initializes Shanks's |
|---|
| 3093 | distance if $b^2 - 4ac > 0$. |
|---|
| 3094 | |
|---|
| 3095 | NOTE: Negative definite forms are not implemented, so use their |
|---|
| 3096 | positive definitine counterparts instead. (I.e., if f is a |
|---|
| 3097 | negative definite quadratic form, then -f is positive |
|---|
| 3098 | definite.) |
|---|
| 3099 | |
|---|
| 3100 | INPUT: |
|---|
| 3101 | a -- gen |
|---|
| 3102 | b -- gen |
|---|
| 3103 | c -- gen |
|---|
| 3104 | D -- gen (optional, defaults to 0) |
|---|
| 3105 | OUTPUT: |
|---|
| 3106 | gen -- binary quadratic form |
|---|
| 3107 | EXAMPLES: |
|---|
| 3108 | sage: pari(3).Qfb(7, 2) |
|---|
| 3109 | Qfb(3, 7, 2, 0.E-28) |
|---|
| 3110 | """ |
|---|
| 3111 | cdef gen _b, _c, _D |
|---|
| 3112 | _b = pari(b) |
|---|
| 3113 | _c = pari(c) |
|---|
| 3114 | _D = pari(D) |
|---|
| 3115 | _sig_on |
|---|
| 3116 | return new_gen(Qfb0(forcecopy(a.g), _b.g, _c.g, _D.g, REAL_PREC)) |
|---|
| 3117 | |
|---|
| 3118 | |
|---|
| 3119 | def Ser(gen x, v=-1): |
|---|
| 3120 | """ |
|---|
| 3121 | Ser(x,{v=x}): Create a power series from x with main variable v |
|---|
| 3122 | and return the result. |
|---|
| 3123 | |
|---|
| 3124 | * If x is a scalar, this gives a constant power series with |
|---|
| 3125 | precision given by the default series precision, as returned |
|---|
| 3126 | by get_series_precision(). |
|---|
| 3127 | |
|---|
| 3128 | * If x is a polynomial, the precision is the greatest of |
|---|
| 3129 | get_series_precision() and the degree of the polynomial. |
|---|
| 3130 | |
|---|
| 3131 | * If x is a vector, the precision is similarly given, and |
|---|
| 3132 | the coefficients of the vector are understood to be the |
|---|
| 3133 | coefficients of the power series starting from the |
|---|
| 3134 | constant term (i.e.~the reverse of the function Pol). |
|---|
| 3135 | |
|---|
| 3136 | WARNING: This is *not* a substitution function. It will not |
|---|
| 3137 | transform an object containing variables of higher priority than v. |
|---|
| 3138 | |
|---|
| 3139 | INPUT: |
|---|
| 3140 | x -- gen |
|---|
| 3141 | v -- PARI variable (default: x) |
|---|
| 3142 | OUTPUT: |
|---|
| 3143 | gen -- PARI object of PARI type t_SER |
|---|
| 3144 | EXAMPLES: |
|---|
| 3145 | sage: pari(2).Ser() |
|---|
| 3146 | 2 + O(x^16) |
|---|
| 3147 | sage: x = pari([1,2,3,4,5]) |
|---|
| 3148 | sage: x.Ser() |
|---|
| 3149 | 1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 + O(x^5) |
|---|
| 3150 | sage: f = x.Ser('v'); print f |
|---|
| 3151 | 1 + 2*v + 3*v^2 + 4*v^3 + 5*v^4 + O(v^5) |
|---|
| 3152 | sage: pari(1)/f |
|---|
| 3153 | 1 - 2*v + v^2 + O(v^5) |
|---|
| 3154 | sage: pari(1).Ser() |
|---|
| 3155 | 1 + O(x^16) |
|---|
| 3156 | """ |
|---|
| 3157 | return new_gen(gtoser(x.g, get_var(v))) |
|---|
| 3158 | |
|---|
| 3159 | |
|---|
| 3160 | def Set(gen x): |
|---|
| 3161 | """ |
|---|
| 3162 | Set(x): convert x into a set, i.e. a row vector of strings in |
|---|
| 3163 | increasing lexicographic order. |
|---|
| 3164 | |
|---|
| 3165 | INPUT: |
|---|
| 3166 | x -- gen |
|---|
| 3167 | OUTPUT: |
|---|
| 3168 | gen -- a vector of strings in increasing lexicographic order. |
|---|
| 3169 | EXAMPLES: |
|---|
| 3170 | sage: pari([1,5,2]).Set() |
|---|
| 3171 | ["1", "2", "5"] |
|---|
| 3172 | sage: pari([]).Set() # the empty set |
|---|
| 3173 | [] |
|---|
| 3174 | sage: pari([1,1,-1,-1,3,3]).Set() |
|---|
| 3175 | ["-1", "1", "3"] |
|---|
| 3176 | sage: pari(1).Set() |
|---|
| 3177 | ["1"] |
|---|
| 3178 | sage: pari('1/(x*y)').Set() |
|---|
| 3179 | ["1/(y*x)"] |
|---|
| 3180 | sage: pari('["bc","ab","bc"]').Set() |
|---|
| 3181 | ["ab", "bc"] |
|---|
| 3182 | """ |
|---|
| 3183 | _sig_on |
|---|
| 3184 | return new_gen(gtoset(x.g)) |
|---|
| 3185 | |
|---|
| 3186 | |
|---|
| 3187 | def Str(gen x): |
|---|
| 3188 | """ |
|---|
| 3189 | Str(x): Concatenate the entries of the vector x into a single |
|---|
| 3190 | string. If x is not a t_VEC its print representation is |
|---|
| 3191 | returned. |
|---|
| 3192 | |
|---|
| 3193 | INPUT: |
|---|
| 3194 | x -- gen |
|---|
| 3195 | OUTPUT: |
|---|
| 3196 | gen -- a PARI gen of type t_STR, i.e., a PARI string |
|---|
| 3197 | EXAMPLES: |
|---|
| 3198 | sage: pari([1,2,['abc',1]]).Str() |
|---|
| 3199 | 12[abc, 1] |
|---|
| 3200 | sage: pari([1,1,1.54]).Str() |
|---|
| 3201 | 111.540000000000000000000000000 |
|---|
| 3202 | sage: pari([1,1.54,1]).Str() |
|---|
| 3203 | 11.5400000000000000000000000001 |
|---|
| 3204 | sage: pari(1).Str() # 1 is automatically converted to string rep |
|---|
| 3205 | 1 |
|---|
| 3206 | sage: x = pari('x') # PARI variable "x" |
|---|
| 3207 | sage: x.Str() # is converted to string rep. |
|---|
| 3208 | x |
|---|
| 3209 | sage: x.Str().type() |
|---|
| 3210 | 't_STR' |
|---|
| 3211 | """ |
|---|
| 3212 | cdef char* c |
|---|
| 3213 | cdef int n |
|---|
| 3214 | if x.type() != 't_VEC': |
|---|
| 3215 | n = setjmp(GP_DATA.env) |
|---|
| 3216 | if n: |
|---|
| 3217 | _error(n,"converting a gen to a string") |
|---|
| 3218 | c = GENtostr(x.g) |
|---|
| 3219 | v = new_gen(strtoGENstr(c)) |
|---|
| 3220 | free(c) |
|---|
| 3221 | return v |
|---|
| 3222 | _sig_on |
|---|
| 3223 | return new_gen(Str(x.g)) |
|---|
| 3224 | |
|---|
| 3225 | def Strchr(gen x): |
|---|
| 3226 | """ |
|---|
| 3227 | Strchr(x): converts x to a string, translating each integer |
|---|
| 3228 | into a character (in ASCII). |
|---|
| 3229 | |
|---|
| 3230 | NOTE: Vecsmall is (essentially) the inverse to Strchr(). |
|---|
| 3231 | |
|---|
| 3232 | INPUT: |
|---|
| 3233 | x -- PARI vector of integers |
|---|
| 3234 | OUTPUT: |
|---|
| 3235 | gen -- a PARI string |
|---|
| 3236 | EXAMPLES: |
|---|
| 3237 | sage: pari([65,66,123]).Strchr() |
|---|
| 3238 | AB{ |
|---|
| 3239 | sage: pari('"SAGE"').Vecsmall() # pari('"SAGE"') --> PARI t_STR |
|---|
| 3240 | Vecsmall([83, 65, 71, 69]) |
|---|
| 3241 | sage: _.Strchr() |
|---|
| 3242 | SAGE |
|---|
| 3243 | sage: pari([83, 65, 71, 69]).Strchr() |
|---|
| 3244 | SAGE |
|---|
| 3245 | """ |
|---|
| 3246 | cdef int n |
|---|
| 3247 | n = setjmp(GP_DATA.env) |
|---|
| 3248 | if n: |
|---|
| 3249 | raise ValueError, "Cannot convert %s, interpreted as ASCII values, to a string."%x |
|---|
| 3250 | _sig_on |
|---|
| 3251 | return new_gen(Strchr(x.g)) |
|---|
| 3252 | |
|---|
| 3253 | def Strexpand(gen x): |
|---|
| 3254 | """ |
|---|
| 3255 | Strexpand(x): Concatenate the entries of the vector x into a |
|---|
| 3256 | single string, performing tilde expansion. |
|---|
| 3257 | |
|---|
| 3258 | NOTE: I have no clue what the point of this function is. -- William |
|---|
| 3259 | """ |
|---|
| 3260 | if x.type() != 't_VEC': |
|---|
| 3261 | raise TypeError, "x must be of type t_VEC." |
|---|
| 3262 | _sig_on |
|---|
| 3263 | return new_gen(Strexpand(x.g)) |
|---|
| 3264 | |
|---|
| 3265 | |
|---|
| 3266 | def Strtex(gen x): |
|---|
| 3267 | r""" |
|---|
| 3268 | Strtex(x): Translates the vector x of PARI gens to TeX format |
|---|
| 3269 | and returns the resulting concatenated strings as a PARI t_STR. |
|---|
| 3270 | |
|---|
| 3271 | INPUT: |
|---|
| 3272 | x -- gen |
|---|
| 3273 | OUTPUT: |
|---|
| 3274 | gen -- PARI t_STR (string) |
|---|
| 3275 | EXAMPLES: |
|---|
| 3276 | sage: v=pari('x^2') |
|---|
| 3277 | sage: v.Strtex() |
|---|
| 3278 | x^2 |
|---|
| 3279 | sage: v=pari(['1/x^2','x']) |
|---|
| 3280 | sage: v.Strtex() |
|---|
| 3281 | \frac{1}{x^2}x |
|---|
| 3282 | sage: v=pari(['1 + 1/x + 1/(y+1)','x-1']) |
|---|
| 3283 | sage: v.Strtex() |
|---|
| 3284 | \frac{ \left(\frac{y |
|---|
| 3285 | + 2}{y |
|---|
| 3286 | + 1}\right) x |
|---|
| 3287 | + 1}{x}x |
|---|
| 3288 | - 1 |
|---|
| 3289 | """ |
|---|
| 3290 | if x.type() != 't_VEC': |
|---|
| 3291 | x = vector(1, [x]) |
|---|
| 3292 | _sig_on |
|---|
| 3293 | return new_gen(Strtex(x.g)) |
|---|
| 3294 | |
|---|
| 3295 | def printtex(gen x): |
|---|
| 3296 | return x.Strtex() |
|---|
| 3297 | |
|---|
| 3298 | def Vec(gen x): |
|---|
| 3299 | """ |
|---|
| 3300 | Vec(x): Transforms the object x into a vector. |
|---|
| 3301 | |
|---|
| 3302 | INPUT: |
|---|
| 3303 | x -- gen |
|---|
| 3304 | OUTPUT: |
|---|
| 3305 | gen -- of PARI type t_VEC |
|---|
| 3306 | EXAMPLES: |
|---|
| 3307 | sage: pari(1).Vec() |
|---|
| 3308 | [1] |
|---|
| 3309 | sage: pari('x^3').Vec() |
|---|
| 3310 | [1, 0, 0, 0] |
|---|
| 3311 | sage: pari('x^3 + 3*x - 2').Vec() |
|---|
| 3312 | [1, 0, 3, -2] |
|---|
| 3313 | sage: pari([1,2,3]).Vec() |
|---|
| 3314 | [1, 2, 3] |
|---|
| 3315 | sage: pari('ab').Vec() |
|---|
| 3316 | [1, 0] |
|---|
| 3317 | """ |
|---|
| 3318 | _sig_on |
|---|
| 3319 | return new_gen(gtovec(forcecopy(x.g))) |
|---|
| 3320 | |
|---|
| 3321 | def Vecsmall(gen x): |
|---|
| 3322 | """ |
|---|
| 3323 | Vecsmall(x): transforms the object x into a t_VECSMALL. |
|---|
| 3324 | |
|---|
| 3325 | INPUT: |
|---|
| 3326 | x -- gen |
|---|
| 3327 | OUTPUT: |
|---|
| 3328 | gen -- PARI t_VECSMALL |
|---|
| 3329 | EXAMPLES: |
|---|
| 3330 | sage: pari([1,2,3]).Vecsmall() |
|---|
| 3331 | Vecsmall([1, 2, 3]) |
|---|
| 3332 | sage: pari('"SAGE"').Vecsmall() |
|---|
| 3333 | Vecsmall([83, 65, 71, 69]) |
|---|
| 3334 | sage: pari(1234).Vecsmall() |
|---|
| 3335 | Vecsmall([1234]) |
|---|
| 3336 | """ |
|---|
| 3337 | n = setjmp(GP_DATA.env) |
|---|
| 3338 | if n: |
|---|
| 3339 | raise TypeError, "Cannot convert %s to Vecsmall."%x |
|---|
| 3340 | _sig_on |
|---|
| 3341 | return new_gen(gtovecsmall(x.g)) |
|---|
| 3342 | |
|---|
| 3343 | def binary(gen x): |
|---|
| 3344 | """ |
|---|
| 3345 | binary(x): gives the vector formed by the binary digits of |
|---|
| 3346 | abs(x), where x is of type t_INT. |
|---|
| 3347 | |
|---|
| 3348 | INPUT: |
|---|
| 3349 | x -- gen of type t_INT |
|---|
| 3350 | OUTPUT: |
|---|
| 3351 | gen -- of type t_VEC |
|---|
| 3352 | EXAMPLES: |
|---|
| 3353 | sage: pari(0).binary() |
|---|
| 3354 | [0] |
|---|
| 3355 | sage: pari(-5).binary() |
|---|
| 3356 | [1, 0, 1] |
|---|
| 3357 | sage: pari(5).binary() |
|---|
| 3358 | [1, 0, 1] |
|---|
| 3359 | sage: pari(2005).binary() |
|---|
| 3360 | [1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1] |
|---|
| 3361 | |
|---|
| 3362 | sage.: pari('"2"').binary() |
|---|
| 3363 | Traceback (most recent call last): |
|---|
| 3364 | ... |
|---|
| 3365 | TypeError: x (=2) must be of type t_INT, but is of type t_STR. |
|---|
| 3366 | """ |
|---|
| 3367 | if typ(x.g) != t_INT: |
|---|
| 3368 | raise TypeError, "x (=%s) must be of type t_INT, but is of type %s."%(x,x.type()) |
|---|
| 3369 | return new_gen(binaire(x.g)) |
|---|
| 3370 | |
|---|
| 3371 | def bitand(gen x, y): |
|---|
| 3372 | """ |
|---|
| 3373 | bitand(x,y): Bitwise and of two integers x and y. Negative |
|---|
| 3374 | numbers behave as if modulo some large power of 2. |
|---|
| 3375 | |
|---|
| 3376 | INPUT: |
|---|
| 3377 | x -- gen (of type t_INT) |
|---|
| 3378 | y -- coercible to gen (of type t_INT) |
|---|
| 3379 | OUTPUT: |
|---|
| 3380 | gen -- of type type t_INT |
|---|
| 3381 | EXAMPLES: |
|---|
| 3382 | sage: pari(8).bitand(4) |
|---|
| 3383 | 0 |
|---|
| 3384 | sage: pari(8).bitand(8) |
|---|
| 3385 | 8 |
|---|
| 3386 | sage: pari(6).binary() |
|---|
| 3387 | [1, 1, 0] |
|---|
| 3388 | sage: pari(7).binary() |
|---|
| 3389 | [1, 1, 1] |
|---|
| 3390 | sage: pari(6).bitand(7) |
|---|
| 3391 | 6 |
|---|
| 3392 | sage: pari(19).bitand(-1) |
|---|
| 3393 | 19 |
|---|
| 3394 | sage: pari(-1).bitand(-1) |
|---|
| 3395 | -1 |
|---|
| 3396 | """ |
|---|
| 3397 | cdef gen _y |
|---|
| 3398 | if typ(x.g) != t_INT: |
|---|
| 3399 | raise TypeError, "x (=%s) must be of type t_INT, but is of type %s."%(x,x.type()) |
|---|
| 3400 | _y = pari(y) |
|---|
| 3401 | if typ(_y.g) != t_INT: |
|---|
| 3402 | raise TypeError, "y (=%s) must be of type t_INT, but is of type %s."%(_y,_y.type()) |
|---|
| 3403 | return new_gen(gbitand(x.g, _y.g)) |
|---|
| 3404 | |
|---|
| 3405 | |
|---|
| 3406 | def bitneg(gen x, long n=-1): |
|---|
| 3407 | r""" |
|---|
| 3408 | bitneg(x,{n=-1}): Bitwise negation of the integer x truncated |
|---|
| 3409 | to n bits. n=-1 (the default) represents an infinite sequence |
|---|
| 3410 | of the bit 1. Negative numbers behave as if modulo some large |
|---|
| 3411 | power of 2. |
|---|
| 3412 | |
|---|
| 3413 | With n=-1, this function returns -n-1. With n >= 0, it returns |
|---|
| 3414 | a number a such that $a\cong -n-1 \pmod{2^n}$. |
|---|
| 3415 | |
|---|
| 3416 | INPUT: |
|---|
| 3417 | x -- gen (t_INT) |
|---|
| 3418 | n -- long, default = -1 |
|---|
| 3419 | OUTPUT: |
|---|
| 3420 | gen -- t_INT |
|---|
| 3421 | EXAMPLES: |
|---|
| 3422 | sage: pari(10).bitneg() |
|---|
| 3423 | -11 |
|---|
| 3424 | sage: pari(1).bitneg() |
|---|
| 3425 | -2 |
|---|
| 3426 | sage: pari(-2).bitneg() |
|---|
| 3427 | 1 |
|---|
| 3428 | sage: pari(-1).bitneg() |
|---|
| 3429 | 0 |
|---|
| 3430 | sage: pari(569).bitneg() |
|---|
| 3431 | -570 |
|---|
| 3432 | sage: pari(569).bitneg(10) |
|---|
| 3433 | 454 |
|---|
| 3434 | sage: 454 % 2**10 |
|---|
| 3435 | 454 |
|---|
| 3436 | sage: -570 % 2**10 |
|---|
| 3437 | 454 |
|---|
| 3438 | """ |
|---|
| 3439 | if typ(x.g) != t_INT: |
|---|
| 3440 | raise TypeError, "x (=%s) must be of type t_INT, but is of type %s."%(x,x.type()) |
|---|
| 3441 | return new_gen(gbitneg(x.g,n)) |
|---|
| 3442 | |
|---|
| 3443 | |
|---|
| 3444 | def bitnegimply(gen x, y): |
|---|
| 3445 | """ |
|---|
| 3446 | bitnegimply(x,y): Bitwise negated imply of two integers x and |
|---|
| 3447 | y, in other words, x BITAND BITNEG(y). Negative numbers behave |
|---|
| 3448 | as if modulo big power of 2. |
|---|
| 3449 | |
|---|
| 3450 | INPUT: |
|---|
| 3451 | x -- gen (of type t_INT) |
|---|
| 3452 | y -- coercible to gen (of type t_INT) |
|---|
| 3453 | OUTPUT: |
|---|
| 3454 | gen -- of type type t_INT |
|---|
| 3455 | EXAMPLES: |
|---|
| 3456 | sage: pari(14).bitnegimply(0) |
|---|
| 3457 | 14 |
|---|
| 3458 | sage: pari(8).bitnegimply(8) |
|---|
| 3459 | 0 |
|---|
| 3460 | sage: pari(8+4).bitnegimply(8) |
|---|
| 3461 | 4 |
|---|
| 3462 | """ |
|---|
| 3463 | cdef gen _y |
|---|
| 3464 | if typ(x.g) != t_INT: |
|---|
| 3465 | raise TypeError, "x (=%s) must be of type t_INT, but is of type %s."%(x,x.type()) |
|---|
| 3466 | _y = pari(y) |
|---|
| 3467 | if typ(_y.g) != t_INT: |
|---|
| 3468 | raise TypeError, "y (=%s) must be of type t_INT, but is of type %s."%(_y,_y.type()) |
|---|
| 3469 | return new_gen(gbitnegimply(x.g, _y.g)) |
|---|
| 3470 | |
|---|
| 3471 | |
|---|
| 3472 | def bitor(gen x, y): |
|---|
| 3473 | """ |
|---|
| 3474 | bitor(x,y): Bitwise or of two integers x and y. Negative |
|---|
| 3475 | numbers behave as if modulo big power of 2. |
|---|
| 3476 | |
|---|
| 3477 | INPUT: |
|---|
| 3478 | x -- gen (of type t_INT) |
|---|
| 3479 | y -- coercible to gen (of type t_INT) |
|---|
| 3480 | OUTPUT: |
|---|
| 3481 | gen -- of type type t_INT |
|---|
| 3482 | EXAMPLES: |
|---|
| 3483 | sage: pari(14).bitor(0) |
|---|
| 3484 | 14 |
|---|
| 3485 | sage: pari(8).bitor(4) |
|---|
| 3486 | 12 |
|---|
| 3487 | sage: pari(12).bitor(1) |
|---|
| 3488 | 13 |
|---|
| 3489 | sage: pari(13).bitor(1) |
|---|
| 3490 | 13 |
|---|
| 3491 | """ |
|---|
| 3492 | cdef gen _y |
|---|
| 3493 | if typ(x.g) != t_INT: |
|---|
| 3494 | raise TypeError, "x (=%s) must be of type t_INT, but is of type %s."%(x,x.type()) |
|---|
| 3495 | _y = pari(y) |
|---|
| 3496 | if typ(_y.g) != t_INT: |
|---|
| 3497 | raise TypeError, "y (=%s) must be of type t_INT, but is of type %s."%(_y,_y.type()) |
|---|
| 3498 | return new_gen(gbitor(x.g, _y.g)) |
|---|
| 3499 | |
|---|
| 3500 | |
|---|
| 3501 | def bittest(gen x, long n): |
|---|
| 3502 | """ |
|---|
| 3503 | bittest(x, long n): Returns bit number n (coefficient of $2^n$ in binary) |
|---|
| 3504 | of the integer x. Negative numbers behave as if modulo a big power of 2. |
|---|
| 3505 | |
|---|
| 3506 | INPUT: |
|---|
| 3507 | x -- gen (pari integer) |
|---|
| 3508 | OUTPUT: |
|---|
| 3509 | bool -- a Python bool |
|---|
| 3510 | EXAMPLES: |
|---|
| 3511 | sage: x = pari(6) |
|---|
| 3512 | sage: x.bittest(0) |
|---|
| 3513 | False |
|---|
| 3514 | sage: x.bittest(1) |
|---|
| 3515 | True |
|---|
| 3516 | sage: x.bittest(2) |
|---|
| 3517 | True |
|---|
| 3518 | sage: x.bittest(3) |
|---|
| 3519 | False |
|---|
| 3520 | sage: pari(-3).bittest(0) |
|---|
| 3521 | True |
|---|
| 3522 | sage: pari(-3).bittest(1) |
|---|
| 3523 | False |
|---|
| 3524 | sage: [pari(-3).bittest(n) for n in range(10)] |
|---|
| 3525 | [True, False, True, True, True, True, True, True, True, True] |
|---|
| 3526 | """ |
|---|
| 3527 | if typ(x.g) != t_INT: |
|---|
| 3528 | raise TypeError, "x (=%s) must be of type t_INT, but is of type %s."%(x,x.type()) |
|---|
| 3529 | return bool(bittest(x.g, n)) |
|---|
| 3530 | |
|---|
| 3531 | def bitxor(gen x, y): |
|---|
| 3532 | """ |
|---|
| 3533 | bitxor(x,y): Bitwise exclusive or of two integers x and y. |
|---|
| 3534 | Negative numbers behave as if modulo big power of 2. |
|---|
| 3535 | |
|---|
| 3536 | INPUT: |
|---|
| 3537 | x -- gen (of type t_INT) |
|---|
| 3538 | y -- coercible to gen (of type t_INT) |
|---|
| 3539 | OUTPUT: |
|---|
| 3540 | gen -- of type type t_INT |
|---|
| 3541 | EXAMPLES: |
|---|
| 3542 | sage: pari(6).bitxor(4) |
|---|
| 3543 | 2 |
|---|
| 3544 | sage: pari(0).bitxor(4) |
|---|
| 3545 | 4 |
|---|
| 3546 | sage: pari(6).bitxor(0) |
|---|
| 3547 | 6 |
|---|
| 3548 | """ |
|---|
| 3549 | cdef gen _y |
|---|
| 3550 | if typ(x.g) != t_INT: |
|---|
| 3551 | raise TypeError, "x (=%s) must be of type t_INT, but is of type %s."%(x,x.type()) |
|---|
| 3552 | _y = pari(y) |
|---|
| 3553 | if typ(_y.g) != t_INT: |
|---|
| 3554 | raise TypeError, "y (=%s) must be of type t_INT, but is of type %s."%(_y,_y.type()) |
|---|
| 3555 | return new_gen(gbitxor(x.g, _y.g)) |
|---|
| 3556 | |
|---|
| 3557 | |
|---|
| 3558 | def ceil(gen x): |
|---|
| 3559 | """ |
|---|
| 3560 | Return the smallest integer >= x. |
|---|
| 3561 | |
|---|
| 3562 | INPUT: |
|---|
| 3563 | x -- gen |
|---|
| 3564 | OUTPUT: |
|---|
| 3565 | gen -- integer |
|---|
| 3566 | EXAMPLES: |
|---|
| 3567 | sage: pari(1.4).ceil() |
|---|
| 3568 | 2 |
|---|
| 3569 | sage: pari(-1.4).ceil() |
|---|
| 3570 | -1 |
|---|
| 3571 | sage: pari('x').ceil() |
|---|
| 3572 | x |
|---|
| 3573 | sage: pari('x^2+5*x+2.2').ceil() |
|---|
| 3574 | x^2 + 5*x + 2.200000000000000000000000000 |
|---|
| 3575 | sage: pari('3/4').ceil() |
|---|
| 3576 | 1 |
|---|
| 3577 | """ |
|---|
| 3578 | n = setjmp(GP_DATA.env) |
|---|
| 3579 | if n == 20: |
|---|
| 3580 | raise TypeError, "Ceiling of %s not defined."%x |
|---|
| 3581 | return new_gen(gceil(x.g)) |
|---|
| 3582 | |
|---|
| 3583 | def centerlift(gen x, v=-1): |
|---|
| 3584 | """ |
|---|
| 3585 | centerlift(x,{v}): Centered lift of x. This function returns |
|---|
| 3586 | exactly the same thing as lift, except if x is an integer mod. |
|---|
| 3587 | |
|---|
| 3588 | INPUT: |
|---|
| 3589 | x -- gen |
|---|
| 3590 | v -- var (default: x) |
|---|
| 3591 | OUTPUT: |
|---|
| 3592 | gen |
|---|
| 3593 | EXAMPLES: |
|---|
| 3594 | sage: x = pari(-2).Mod(5) |
|---|
| 3595 | sage: x.centerlift() |
|---|
| 3596 | -2 |
|---|
| 3597 | sage: x.lift() |
|---|
| 3598 | 3 |
|---|
| 3599 | sage: f = pari('x-1').Mod('x^2 + 1') |
|---|
| 3600 | sage: f.centerlift() |
|---|
| 3601 | x - 1 |
|---|
| 3602 | sage: f.lift() |
|---|
| 3603 | x - 1 |
|---|
| 3604 | sage: f = pari('x-y').Mod('x^2+1') |
|---|
| 3605 | sage: f |
|---|
| 3606 | Mod(x - y, x^2 + 1) |
|---|
| 3607 | sage: f.centerlift('x') |
|---|
| 3608 | x - y |
|---|
| 3609 | sage: f.centerlift('y') |
|---|
| 3610 | Mod(x - y, x^2 + 1) |
|---|
| 3611 | """ |
|---|
| 3612 | return new_gen(centerlift0(x.g,get_var(v))) |
|---|
| 3613 | |
|---|
| 3614 | |
|---|
| 3615 | def changevar(gen x, y): |
|---|
| 3616 | """ |
|---|
| 3617 | changevar(gen x, y): change variables of x according to the vector y. |
|---|
| 3618 | |
|---|
| 3619 | INPUT: |
|---|
| 3620 | x -- gen |
|---|
| 3621 | y -- gen (or coercible to gen) |
|---|
| 3622 | OUTPUT: |
|---|
| 3623 | gen |
|---|
| 3624 | EXAMPLES: |
|---|
| 3625 | sage.: pari('X^3+1').changevar(['Y']) |
|---|
| 3626 | Y^3 + 1 |
|---|
| 3627 | sage.: pari('X^3 + Y^2').changevar(['Y','Z']) |
|---|
| 3628 | Y^3 + Z^2 |
|---|
| 3629 | sage.: pari('X^3 + Y^2').changevar(['Y','Z+1']) |
|---|
| 3630 | Y^3 + (Z^2 + 2*Z + 1) |
|---|
| 3631 | """# The above tests are not run because for some reason |
|---|
| 3632 | # they fail when run with all the other tests. In an |
|---|
| 3633 | # interactive session they work fine. Very frustrating. |
|---|
| 3634 | cdef gen _y |
|---|
| 3635 | _y = pari(y) |
|---|
| 3636 | if typ(_y.g) != t_VEC: |
|---|
| 3637 | raise TypeError, "y (=%s) must be of type t_VEC, but is of type %s."%(_y,_y.type()) |
|---|
| 3638 | _sig_on |
|---|
| 3639 | return new_gen(changevar(x.g, _y.g)) |
|---|
| 3640 | |
|---|
| 3641 | def component(gen x, long n): |
|---|
| 3642 | """ |
|---|
| 3643 | component(x, long n): Return n'th component of the internal |
|---|
| 3644 | representation of x. This this function is 1-based |
|---|
| 3645 | instead of 0-based. |
|---|
| 3646 | |
|---|
| 3647 | NOTE: For vectors or matrices, it is simpler to use x[n-1]. For |
|---|
| 3648 | list objects such as is output by nfinit, it is easier to use |
|---|
| 3649 | member functions. |
|---|
| 3650 | |
|---|
| 3651 | INPUT: |
|---|
| 3652 | x -- gen |
|---|
| 3653 | n -- C long (coercible to) |
|---|
| 3654 | OUTPUT: |
|---|
| 3655 | gen |
|---|
| 3656 | EXAMPLES: |
|---|
| 3657 | sage: pari([0,1,2,3,4]).component(1) |
|---|
| 3658 | 0 |
|---|
| 3659 | sage: pari([0,1,2,3,4]).component(2) |
|---|
| 3660 | 1 |
|---|
| 3661 | sage: pari([0,1,2,3,4]).component(4) |
|---|
| 3662 | 3 |
|---|
| 3663 | sage: pari('x^3 + 2').component(1) |
|---|
| 3664 | 2 |
|---|
| 3665 | sage: pari('x^3 + 2').component(2) |
|---|
| 3666 | 0 |
|---|
| 3667 | sage: pari('x^3 + 2').component(4) |
|---|
| 3668 | 1 |
|---|
| 3669 | sage: pari('x').component(0) |
|---|
| 3670 | Traceback (most recent call last): |
|---|
| 3671 | ... |
|---|
| 3672 | IndexError: component (=0) must be between 1 and 2, inclusive |
|---|
| 3673 | """ |
|---|
| 3674 | cdef long m |
|---|
| 3675 | m = glength(x.g) |
|---|
| 3676 | if n <= 0 or n > m: |
|---|
| 3677 | raise IndexError, "component (=%s) must be between 1 and %s, inclusive"%(n, m) |
|---|
| 3678 | return new_gen(compo(x.g, n)) |
|---|
| 3679 | |
|---|
| 3680 | def conj(gen x): |
|---|
| 3681 | """ |
|---|
| 3682 | conj(x): Return the algebraic conjugate of x. |
|---|
| 3683 | |
|---|
| 3684 | INPUT: |
|---|
| 3685 | x -- gen |
|---|
| 3686 | OUTPUT: |
|---|
| 3687 | gen |
|---|
| 3688 | EXAMPLES: |
|---|
| 3689 | sage: pari('x+1').conj() |
|---|
| 3690 | x + 1 |
|---|
| 3691 | sage: pari('x+I').conj() |
|---|
| 3692 | x - I |
|---|
| 3693 | sage: pari('1/(2*x+3*I)').conj() |
|---|
| 3694 | 1/(2*x - 3*I) |
|---|
| 3695 | sage: pari([1,2,'2-I','Mod(x,x^2+1)', 'Mod(x,x^2-2)']).conj() |
|---|
| 3696 | [1, 2, 2 + I, Mod(-x, x^2 + 1), Mod(-x, x^2 - 2)] |
|---|
| 3697 | sage: pari('Mod(x,x^2-2)').conj() |
|---|
| 3698 | Mod(-x, x^2 - 2) |
|---|
| 3699 | |
|---|
| 3700 | sage.: pari('Mod(x,x^3-3)').conj() |
|---|
| 3701 | Traceback (most recent call last): |
|---|
| 3702 | ... |
|---|
| 3703 | TypeError: x (=Mod(x, x^3 - 3)) has no conjugate. |
|---|
| 3704 | """ |
|---|
| 3705 | n = setjmp(GP_DATA.env) |
|---|
| 3706 | if n: |
|---|
| 3707 | if n == 20: |
|---|
| 3708 | raise TypeError, "x (=%s) has no conjugate."%x |
|---|
| 3709 | else: |
|---|
| 3710 | _error(n,"error in conj") |
|---|
| 3711 | _sig_on |
|---|
| 3712 | return new_gen(gconj(x.g)) |
|---|
| 3713 | |
|---|
| 3714 | def conjvec(gen x): |
|---|
| 3715 | """ |
|---|
| 3716 | conjvec(x): Returns the vector of all conjugates of the |
|---|
| 3717 | algebraic number x. An algebraic number is a polynomial over |
|---|
| 3718 | Q modulo an irreducible polynomial. |
|---|
| 3719 | |
|---|
| 3720 | INPUT: |
|---|
| 3721 | x -- gen |
|---|
| 3722 | OUTPUT: |
|---|
| 3723 | gen |
|---|
| 3724 | EXAMPLES: |
|---|
| 3725 | sage: pari('Mod(1+x,x^2-2)').conjvec() |
|---|
| 3726 | [-0.4142135623730950488016887242, 2.414213562373095048801688724]~ |
|---|
| 3727 | sage: pari('Mod(x,x^3-3)').conjvec() |
|---|
| 3728 | [1.442249570307408382321638311, -0.7211247851537041911608191554 + 1.249024766483406479413179544*I, -0.7211247851537041911608191554 - 1.249024766483406479413179544*I]~ |
|---|
| 3729 | """ |
|---|
| 3730 | n = setjmp(GP_DATA.env) |
|---|
| 3731 | if n: |
|---|
| 3732 | if n == 20: |
|---|
| 3733 | raise TypeError, "x (=%s) has no conjugate."%x |
|---|
| 3734 | else: |
|---|
| 3735 | _error(n,"error in conj") |
|---|
| 3736 | _sig_on |
|---|
| 3737 | return new_gen(conjvec(x.g, REAL_PREC)) |
|---|
| 3738 | |
|---|
| 3739 | def denominator(gen x): |
|---|
| 3740 | """ |
|---|
| 3741 | denominator(x): Return the denominator of x. When x is a |
|---|
| 3742 | vector, this is the least common multiple of the denominators |
|---|
| 3743 | of the components of x. |
|---|
| 3744 | |
|---|
| 3745 | what about poly? |
|---|
| 3746 | INPUT: |
|---|
| 3747 | x -- gen |
|---|
| 3748 | OUTPUT: |
|---|
| 3749 | gen |
|---|
| 3750 | EXAMPLES: |
|---|
| 3751 | sage: pari('5/9').denominator() |
|---|
| 3752 | 9 |
|---|
| 3753 | sage: pari('(x+1)/(x-2)').denominator() |
|---|
| 3754 | x - 2 |
|---|
| 3755 | sage: pari('2/3 + 5/8*x + 7/3*x^2 + 1/5*y').denominator() |
|---|
| 3756 | 1 |
|---|
| 3757 | sage: pari('2/3*x').denominator() |
|---|
| 3758 | 1 |
|---|
| 3759 | sage: pari('[2/3, 5/8, 7/3, 1/5]').denominator() |
|---|
| 3760 | 120 |
|---|
| 3761 | """ |
|---|
| 3762 | _sig_on |
|---|
| 3763 | return new_gen(denom(x.g)) |
|---|
| 3764 | |
|---|
| 3765 | def floor(gen x): |
|---|
| 3766 | """ |
|---|
| 3767 | floor(x): Return the floor of x, which is the largest integer <= x. |
|---|
| 3768 | This function also works component-wise on polynomials, vectors, etc. |
|---|
| 3769 | |
|---|
| 3770 | INPUT: |
|---|
| 3771 | x -- gen |
|---|
| 3772 | OUTPUT: |
|---|
| 3773 | gen |
|---|
| 3774 | EXAMPLES: |
|---|
| 3775 | sage: pari('5/9').floor() |
|---|
| 3776 | 0 |
|---|
| 3777 | sage: pari('11/9').floor() |
|---|
| 3778 | 1 |
|---|
| 3779 | sage: pari('1.17').floor() |
|---|
| 3780 | 1 |
|---|
| 3781 | sage: pari('x').floor() |
|---|
| 3782 | x |
|---|
| 3783 | sage: pari('x+1.5').floor() |
|---|
| 3784 | x + 1.500000000000000000000000000 |
|---|
| 3785 | sage: pari('[1.5,2.3,4.99]').floor() |
|---|
| 3786 | [1, 2, 4] |
|---|
| 3787 | sage: pari('[[1.1,2.2],[3.3,4.4]]').floor() |
|---|
| 3788 | [[1, 2], [3, 4]] |
|---|
| 3789 | |
|---|
| 3790 | sage.: pari('"hello world"').floor() |
|---|
| 3791 | Traceback (most recent call last): |
|---|
| 3792 | ... |
|---|
| 3793 | TypeError: x (=hello world) has no floor. |
|---|
| 3794 | """ |
|---|
| 3795 | n = setjmp(GP_DATA.env) |
|---|
| 3796 | if n: |
|---|
| 3797 | if n == 20: |
|---|
| 3798 | raise TypeError, "x (=%s) has no floor."%x |
|---|
| 3799 | else: |
|---|
| 3800 | _error(n,"error in floor") |
|---|
| 3801 | return new_gen(gfloor(x.g)) |
|---|
| 3802 | |
|---|
| 3803 | def frac(gen x): |
|---|
| 3804 | """ |
|---|
| 3805 | frac(x): Return the fractional part of x, which is x - floor(x). |
|---|
| 3806 | |
|---|
| 3807 | INPUT: |
|---|
| 3808 | x -- gen |
|---|
| 3809 | OUTPUT: |
|---|
| 3810 | gen |
|---|
| 3811 | EXAMPLES: |
|---|
| 3812 | sage: pari('1.7').frac() |
|---|
| 3813 | 0.7000000000000000000000000000 |
|---|
| 3814 | sage: pari('sqrt(2)').frac() |
|---|
| 3815 | 0.4142135623730950488016887242 |
|---|
| 3816 | |
|---|
| 3817 | sage.: pari('sqrt(-2)').frac() |
|---|
| 3818 | Traceback (most recent call last): |
|---|
| 3819 | ... |
|---|
| 3820 | TypeError: Fractional part of 1.4142135623730950488016887242*I not defined. |
|---|
| 3821 | """ |
|---|
| 3822 | n = setjmp(GP_DATA.env) |
|---|
| 3823 | if n: |
|---|
| 3824 | if n == 20: |
|---|
| 3825 | raise TypeError, "Fractional part of %s not defined."%x |
|---|
| 3826 | else: |
|---|
| 3827 | _error(n,"error in frac") |
|---|
| 3828 | return new_gen(gfrac(x.g)) |
|---|
| 3829 | |
|---|
| 3830 | def imag(gen x): |
|---|
| 3831 | """ |
|---|
| 3832 | imag(x): Return the imaginary part of x. This function also |
|---|
| 3833 | works component-wise. |
|---|
| 3834 | |
|---|
| 3835 | INPUT: |
|---|
| 3836 | x -- gen |
|---|
| 3837 | OUTPUT: |
|---|
| 3838 | gen |
|---|
| 3839 | EXAMPLES: |
|---|
| 3840 | sage: pari('1+2*I').imag() |
|---|
| 3841 | 2 |
|---|
| 3842 | sage: pari('sqrt(-2)').imag() |
|---|
| 3843 | 1.414213562373095048801688724 |
|---|
| 3844 | sage: pari('x+I').imag() |
|---|
| 3845 | 1 |
|---|
| 3846 | sage: pari('x+2*I').imag() |
|---|
| 3847 | 2 |
|---|
| 3848 | sage: pari('(1+I)*x^2+2*I').imag() |
|---|
| 3849 | x^2 + 2 |
|---|
| 3850 | sage: pari('[1,2,3] + [4*I,5,6]').imag() |
|---|
| 3851 | [4, 0, 0] |
|---|
| 3852 | """ |
|---|
| 3853 | cdef int n |
|---|
| 3854 | n = setjmp(GP_DATA.env) |
|---|
| 3855 | if n: |
|---|
| 3856 | if n == 20: |
|---|
| 3857 | raise TypeError, "Imaginary part of %s not defined."%x |
|---|
| 3858 | else: |
|---|
| 3859 | _error(n,"error in imag") |
|---|
| 3860 | return new_gen(gimag(forcecopy(forcecopy(x.g)))) |
|---|
| 3861 | |
|---|
| 3862 | def length(gen x): |
|---|
| 3863 | """ |
|---|
| 3864 | length(x): Return the number of non-code words in x. If x |
|---|
| 3865 | is a string, this is the number of characters of x. |
|---|
| 3866 | |
|---|
| 3867 | ?? terminator ?? carriage return ?? |
|---|
| 3868 | """ |
|---|
| 3869 | return glength(x.g) |
|---|
| 3870 | |
|---|
| 3871 | def lift(gen x, v=-1): |
|---|
| 3872 | """ |
|---|
| 3873 | lift(x,{v}): Returns the lift of an element of Z/nZ to Z or |
|---|
| 3874 | R[x]/(P) to R[x] for a type R if v is omitted. If v is given, |
|---|
| 3875 | lift only polymods with main variable v. If v does not occur |
|---|
| 3876 | in x, lift only intmods. |
|---|
| 3877 | |
|---|
| 3878 | INPUT: |
|---|
| 3879 | x -- gen |
|---|
| 3880 | v -- (optional) variable |
|---|
| 3881 | OUTPUT: |
|---|
| 3882 | gen |
|---|
| 3883 | EXAMPLES: |
|---|
| 3884 | sage: x = pari("x") |
|---|
| 3885 | sage: a = x.Mod(x**3 + 17*x + 3) |
|---|
| 3886 | sage: a |
|---|
| 3887 | Mod(x, x^3 + 17*x + 3) |
|---|
| 3888 | sage: b = a**4; b |
|---|
| 3889 | Mod(-17*x^2 - 3*x, x^3 + 17*x + 3) |
|---|
| 3890 | sage: b.lift() |
|---|
| 3891 | -17*x^2 - 3*x |
|---|
| 3892 | |
|---|
| 3893 | ??? more examples |
|---|
| 3894 | """ |
|---|
| 3895 | n = setjmp(GP_DATA.env) |
|---|
| 3896 | if n: |
|---|
| 3897 | _error(n,"error in lift") |
|---|
| 3898 | if v == -1: |
|---|
| 3899 | return new_gen(lift(forcecopy(x.g))) |
|---|
| 3900 | return new_gen(lift0(forcecopy(x.g), get_var(v))) |
|---|
| 3901 | |
|---|
| 3902 | def numerator(gen x): |
|---|
| 3903 | """ |
|---|
| 3904 | numerator(x): Returns the numerator of x. |
|---|
| 3905 | |
|---|
| 3906 | INPUT: |
|---|
| 3907 | x -- gen |
|---|
| 3908 | OUTPUT: |
|---|
| 3909 | gen |
|---|
| 3910 | EXAMPLES: |
|---|
| 3911 | |
|---|
| 3912 | """ |
|---|
| 3913 | raise new_gen(numer(x.g)) |
|---|
| 3914 | |
|---|
| 3915 | |
|---|
| 3916 | def numtoperm(gen k, long n): |
|---|
| 3917 | """ |
|---|
| 3918 | numtoperm(k, n): Return the permutation number k (mod n!) of n |
|---|
| 3919 | letters, where n is an integer. |
|---|
| 3920 | |
|---|
| 3921 | INPUT: |
|---|
| 3922 | k -- gen, integer |
|---|
| 3923 | n -- int |
|---|
| 3924 | OUTPUT: |
|---|
| 3925 | gen -- vector (permutation of {1,...,n}) |
|---|
| 3926 | EXAMPLES: |
|---|
| 3927 | """ |
|---|
| 3928 | _sig_on |
|---|
| 3929 | return new_gen(numtoperm(n, k.g)) |
|---|
| 3930 | |
|---|
| 3931 | |
|---|
| 3932 | def padicprec(gen x, p): |
|---|
| 3933 | """ |
|---|
| 3934 | padicprec(x,p): Return the absolute p-adic precision of the object x. |
|---|
| 3935 | |
|---|
| 3936 | INPUT: |
|---|
| 3937 | x -- gen |
|---|
| 3938 | OUTPUT: |
|---|
| 3939 | int |
|---|
| 3940 | EXAMPLES: |
|---|
| 3941 | """ |
|---|
| 3942 | cdef gen _p |
|---|
| 3943 | _p = pari(p) |
|---|
| 3944 | if typ(_p.g) != t_INT: |
|---|
| 3945 | raise TypeError, "p (=%s) must be of type t_INT, but is of type %s."%( |
|---|
| 3946 | _p, _p.type()) |
|---|
| 3947 | return padicprec(x.g, _p.g) |
|---|
| 3948 | |
|---|
| 3949 | def permtonum(gen x): |
|---|
| 3950 | """ |
|---|
| 3951 | permtonum(x): Return the ordinal (between 1 and n!) of permutation vector x. |
|---|
| 3952 | ??? Huh ??? say more. what is a perm vector. 0 to n-1 or 1-n. |
|---|
| 3953 | |
|---|
| 3954 | INPUT: |
|---|
| 3955 | x -- gen (vector of integers) |
|---|
| 3956 | OUTPUT: |
|---|
| 3957 | gen -- integer |
|---|
| 3958 | EXAMPLES: |
|---|
| 3959 | """ |
|---|
| 3960 | if typ(x.g) != t_VEC: |
|---|
| 3961 | raise TypeError, "x (=%s) must be of type t_VEC, but is of type %s."%(x,x.type()) |
|---|
| 3962 | raise new_gen(permtonum(x.g)) |
|---|
| 3963 | |
|---|
| 3964 | def precision(gen x, long n=-1): |
|---|
| 3965 | """ |
|---|
| 3966 | precision(x,{n}): Change the precision of x to be n, where n |
|---|
| 3967 | is a C-integer). If n is omitted, output the real precision of x. |
|---|
| 3968 | |
|---|
| 3969 | INPUT: |
|---|
| 3970 | x -- gen |
|---|
| 3971 | n -- (optional) int |
|---|
| 3972 | OUTPUT: |
|---|
| 3973 | nothing |
|---|
| 3974 | or |
|---|
| 3975 | gen if n is omitted |
|---|
| 3976 | EXAMPLES: |
|---|
| 3977 | """ |
|---|
| 3978 | if n <= -1: |
|---|
| 3979 | return precision(x.g) |
|---|
| 3980 | return new_gen(precision0(x.g, n)) |
|---|
| 3981 | |
|---|
| 3982 | def random(gen N): |
|---|
| 3983 | r""" |
|---|
| 3984 | \code{random(\{N=$2^31$\})}: Return a pseudo-random integer between 0 and $N-1$. |
|---|
| 3985 | |
|---|
| 3986 | INPUT: |
|---|
| 3987 | N -- gen, integer |
|---|
| 3988 | OUTPUT: |
|---|
| 3989 | gen -- integer |
|---|
| 3990 | EXAMPLES: |
|---|
| 3991 | """ |
|---|
| 3992 | if typ(N.g) != t_INT: |
|---|
| 3993 | raise TypeError, "x (=%s) must be of type t_INT, but is of type %s."%(N,N.type()) |
|---|
| 3994 | _sig_on |
|---|
| 3995 | return new_gen(genrand(N.g)) |
|---|
| 3996 | |
|---|
| 3997 | def real(gen x): |
|---|
| 3998 | """ |
|---|
| 3999 | real(x): Return the real part of x. |
|---|
| 4000 | |
|---|
| 4001 | INPUT: |
|---|
| 4002 | x -- gen |
|---|
| 4003 | OUTPUT: |
|---|
| 4004 | gen |
|---|
| 4005 | EXAMPLES: |
|---|
| 4006 | """ |
|---|
| 4007 | cdef int n |
|---|
| 4008 | n = setjmp(GP_DATA.env) |
|---|
| 4009 | if n: |
|---|
| 4010 | _error(n,"error in real") |
|---|
| 4011 | return new_gen(greal(forcecopy(x.g))) |
|---|
| 4012 | |
|---|
| 4013 | def round(gen x, estimate=False): |
|---|
| 4014 | """ |
|---|
| 4015 | round(x,estimat=False): If x is a real number, returns x rounded |
|---|
| 4016 | to the nearest integer (rounding up). If the optional argument |
|---|
| 4017 | estimate is True, also returns the binary exponent e of the difference |
|---|
| 4018 | between the original and the rounded value (the "fractional part") |
|---|
| 4019 | (this is the integer ceiling of log_2(error)). |
|---|
| 4020 | |
|---|
| 4021 | When x is a general PARI object, this function returns the result |
|---|
| 4022 | of rounding every coefficient at every level of PARI object. |
|---|
| 4023 | Note that this is different than what the truncate function |
|---|
| 4024 | does (see the example below). |
|---|
| 4025 | |
|---|
| 4026 | One use of round is to get exact results after a long |
|---|
| 4027 | approximate computation, when theory tells you that the |
|---|
| 4028 | coefficients must be integers. |
|---|
| 4029 | |
|---|
| 4030 | INPUT: |
|---|
| 4031 | x -- gen |
|---|
| 4032 | estimate -- (optional) bool, False by default |
|---|
| 4033 | OUTPUT: |
|---|
| 4034 | * if estimate == False, return a single gen. |
|---|
| 4035 | * if estimate == True, return rounded verison of x and |
|---|
| 4036 | error estimate in bits, both as gens. |
|---|
| 4037 | EXAMPLES: |
|---|
| 4038 | sage: pari('1.5').round() |
|---|
| 4039 | 2 |
|---|
| 4040 | sage: pari('1.5').round(True) |
|---|
| 4041 | (2, -1) |
|---|
| 4042 | sage: pari('1.5 + 2.1*I').round() |
|---|
| 4043 | 2 + 2*I |
|---|
| 4044 | sage: pari('1.0001').round(True) |
|---|
| 4045 | (1, -14) |
|---|
| 4046 | sage: pari('(2.4*x^2 - 1.7)/x').round() |
|---|
| 4047 | (2*x^2 - 2)/x |
|---|
| 4048 | sage: pari('(2.4*x^2 - 1.7)/x').truncate() |
|---|
| 4049 | 2.400000000000000000000000000*x |
|---|
| 4050 | """ |
|---|
| 4051 | cdef int n |
|---|
| 4052 | n = setjmp(GP_DATA.env) |
|---|
| 4053 | if n: |
|---|
| 4054 | _error(n,"error in round") |
|---|
| 4055 | if not estimate: |
|---|
| 4056 | return new_gen(ground(x.g)) |
|---|
| 4057 | cdef long e |
|---|
| 4058 | cdef gen y |
|---|
| 4059 | y = new_gen(grndtoi(x.g, &e)) |
|---|
| 4060 | return y, e |
|---|
| 4061 | |
|---|
| 4062 | def simplify(gen x): |
|---|
| 4063 | """ |
|---|
| 4064 | simplify(x): Simplify the object x as much as possible, and return |
|---|
| 4065 | the result. |
|---|
| 4066 | |
|---|
| 4067 | A complex or quadratic number whose imaginary part is an exact 0 |
|---|
| 4068 | (i.e., not an approximate one such as O(3) or 0.E-28) is converted |
|---|
| 4069 | to its real part, and a a polynomial of degree 0 is converted to |
|---|
| 4070 | its constant term. Simplification occurs recursively. |
|---|
| 4071 | |
|---|
| 4072 | This function is useful before using arithmetic functions, which |
|---|
| 4073 | expect integer arguments: |
|---|
| 4074 | |
|---|
| 4075 | EXAMPLES: |
|---|
| 4076 | sage: y = pari('y') |
|---|
| 4077 | sage: x = pari('9') + y - y |
|---|
| 4078 | sage: x |
|---|
| 4079 | 9 |
|---|
| 4080 | sage: x.type() |
|---|
| 4081 | 't_POL' |
|---|
| 4082 | sage: x.factor() |
|---|
| 4083 | matrix(0,2) |
|---|
| 4084 | sage: pari('9').factor() |
|---|
| 4085 | Mat([3, 2]) |
|---|
| 4086 | sage: x.simplify() |
|---|
| 4087 | 9 |
|---|
| 4088 | sage: x.simplify().factor() |
|---|
| 4089 | Mat([3, 2]) |
|---|
| 4090 | sage: x = pari('1.5 + 0*I') |
|---|
| 4091 | sage: x.type() |
|---|
| 4092 | 't_COMPLEX' |
|---|
| 4093 | sage: x.simplify() |
|---|
| 4094 | 1.500000000000000000000000000 |
|---|
| 4095 | sage: y = x.simplify() |
|---|
| 4096 | sage: y.type() |
|---|
| 4097 | 't_REAL' |
|---|
| 4098 | """ |
|---|
| 4099 | _sig_on |
|---|
| 4100 | return new_gen(simplify(x.g)) |
|---|
| 4101 | |
|---|
| 4102 | def sizebyte(gen x): |
|---|
| 4103 | """ |
|---|
| 4104 | sizebyte(x): Return the total number of bytes occupied by the |
|---|
| 4105 | complete tree of the object x. |
|---|
| 4106 | |
|---|
| 4107 | INPUT: |
|---|
| 4108 | x -- gen |
|---|
| 4109 | OUTPUT: |
|---|
| 4110 | int (a Python int) |
|---|
| 4111 | EXAMPLES: |
|---|
| 4112 | sage: pari('1').sizebyte() |
|---|
| 4113 | 12 |
|---|
| 4114 | sage: pari('10').sizebyte() |
|---|
| 4115 | 12 |
|---|
| 4116 | sage: pari('10000000000000').sizebyte() |
|---|
| 4117 | 16 |
|---|
| 4118 | sage: pari('10^100').sizebyte() |
|---|
| 4119 | 52 |
|---|
| 4120 | sage: pari('x').sizebyte() |
|---|
| 4121 | 36 |
|---|
| 4122 | sage: pari('x^20').sizebyte() |
|---|
| 4123 | 264 |
|---|
| 4124 | sage: pari('[x, 10^100]').sizebyte() |
|---|
| 4125 | 100 |
|---|
| 4126 | """ |
|---|
| 4127 | return taille2(x.g) |
|---|
| 4128 | |
|---|
| 4129 | def sizedigit(gen x): |
|---|
| 4130 | """ |
|---|
| 4131 | |
|---|
| 4132 | sizedigit(x): Return a quick estimate for the maximal number of |
|---|
| 4133 | decimal digits before the decimal point of any component of x. |
|---|
| 4134 | |
|---|
| 4135 | INPUT: |
|---|
| 4136 | x -- gen |
|---|
| 4137 | OUTPUT: |
|---|
| 4138 | int -- Python integer |
|---|
| 4139 | EXAMPLES: |
|---|
| 4140 | sage: x = pari('10^100') |
|---|
| 4141 | sage: x.Str().length() |
|---|
| 4142 | 101 |
|---|
| 4143 | sage: x.sizedigit() |
|---|
| 4144 | 101 |
|---|
| 4145 | |
|---|
| 4146 | Note that digits after the decimal point are ignored. |
|---|
| 4147 | sage: x = pari('1.234') |
|---|
| 4148 | sage: x |
|---|
| 4149 | 1.234000000000000000000000000 |
|---|
| 4150 | sage: x.sizedigit() |
|---|
| 4151 | 1 |
|---|
| 4152 | |
|---|
| 4153 | The estimate can be one too big: |
|---|
| 4154 | sage: pari('7234.1').sizedigit() |
|---|
| 4155 | 4 |
|---|
| 4156 | sage: pari('9234.1').sizedigit() |
|---|
| 4157 | 5 |
|---|
| 4158 | """ |
|---|
| 4159 | return sizedigit(x.g) |
|---|
| 4160 | |
|---|
| 4161 | def truncate(gen x, estimate=False): |
|---|
| 4162 | """ |
|---|
| 4163 | truncate(x,estimate=False): Return the truncation of x. |
|---|
| 4164 | If estimate is True, also return the number of error bits. |
|---|
| 4165 | |
|---|
| 4166 | When x is in the real numbers, this means that the part |
|---|
| 4167 | after the decimal point is chopped away, e is the binary |
|---|
| 4168 | exponent of the difference between the original and truncated |
|---|
| 4169 | value (the "fractional part"). If x is a rational |
|---|
| 4170 | function, the result is the integer part (Euclidean |
|---|
| 4171 | quotient of numerator by denominator) and if requested |
|---|
| 4172 | the error estimate is 0. |
|---|
| 4173 | |
|---|
| 4174 | When truncate is applied to a power series (in X), it |
|---|
| 4175 | transforms it into a polynomial or a rational function with |
|---|
| 4176 | denominator a power of X, by chopping away the $O(X^k)$. |
|---|
| 4177 | Similarly, when applied to a p-adic number, it transforms it |
|---|
| 4178 | into an integer or a rational number by chopping away the |
|---|
| 4179 | $O(p^k)$. |
|---|
| 4180 | |
|---|
| 4181 | INPUT: |
|---|
| 4182 | x -- gen |
|---|
| 4183 | estimate -- (optional) bool, which is False by default |
|---|
| 4184 | OUTPUT: |
|---|
| 4185 | * if estimate == False, return a single gen. |
|---|
| 4186 | * if estimate == True, return rounded verison of x and |
|---|
| 4187 | error estimate in bits, both as gens. |
|---|
| 4188 | OUTPUT: |
|---|
| 4189 | EXAMPLES: |
|---|
| 4190 | sage: pari('(x^2+1)/x').round() |
|---|
| 4191 | (x^2 + 1)/x |
|---|
| 4192 | sage: pari('(x^2+1)/x').truncate() |
|---|
| 4193 | x |
|---|
| 4194 | sage: pari('1.043').truncate() |
|---|
| 4195 | 1 |
|---|
| 4196 | sage: pari('1.043').truncate(True) |
|---|
| 4197 | (1, -5) |
|---|
| 4198 | sage: pari('1.6').truncate() |
|---|
| 4199 | 1 |
|---|
| 4200 | sage: pari('1.6').round() |
|---|
| 4201 | 2 |
|---|
| 4202 | sage: pari('1/3 + 2 + 3^2 + O(3^3)').truncate() |
|---|
| 4203 | 34/3 |
|---|
| 4204 | sage: pari('sin(x+O(x^10))').truncate() |
|---|
| 4205 | 1/362880*x^9 - 1/5040*x^7 + 1/120*x^5 - 1/6*x^3 + x |
|---|
| 4206 | sage: pari('sin(x+O(x^10))').round() # each coefficient has abs < 1 |
|---|
| 4207 | x + O(x^10) |
|---|
| 4208 | """ |
|---|
| 4209 | cdef int n |
|---|
| 4210 | n = setjmp(GP_DATA.env) |
|---|
| 4211 | if n: |
|---|
| 4212 | _error(n,"error in truncate") |
|---|
| 4213 | if not estimate: |
|---|
| 4214 | return new_gen(gtrunc(x.g)) |
|---|
| 4215 | cdef long e |
|---|
| 4216 | cdef gen y |
|---|
| 4217 | y = new_gen(gcvtoi(x.g, &e)) |
|---|
| 4218 | return y, e |
|---|
| 4219 | |
|---|
| 4220 | def valuation(gen x, p): |
|---|
| 4221 | """ |
|---|
| 4222 | valuation(x,p): Return the valuation of x with respect to p. |
|---|
| 4223 | |
|---|
| 4224 | The valuation is the highest exponent of p dividing x. |
|---|
| 4225 | |
|---|
| 4226 | * If p is an integer, x must be an integer, an intmod whose |
|---|
| 4227 | modulus is divisible by p, a rational number, a p-adic |
|---|
| 4228 | number, or a polynomial or power series in which case the |
|---|
| 4229 | valuation is the minimal of the valuations of the |
|---|
| 4230 | coefficients. |
|---|
| 4231 | |
|---|
| 4232 | * If p is a polynomial, x must be a polynomial or a |
|---|
| 4233 | rational fucntion. If p is a monomial then x may also be |
|---|
| 4234 | a power series. |
|---|
| 4235 | |
|---|
| 4236 | * If x is a vector, complex or quadratic number, then the |
|---|
| 4237 | valuation is the minimum of the component valuations. |
|---|
| 4238 | |
|---|
| 4239 | * If x = 0, the result is $2^31-1$ on 32-bit machines or |
|---|
| 4240 | $2^63-1$ on 64-bit machines if x is an exact object. |
|---|
| 4241 | If x is a p-adic number or power series, the result |
|---|
| 4242 | is the exponent of the zero. |
|---|
| 4243 | |
|---|
| 4244 | INPUT: |
|---|
| 4245 | x -- gen |
|---|
| 4246 | p -- coercible to gen |
|---|
| 4247 | OUTPUT: |
|---|
| 4248 | gen -- integer |
|---|
| 4249 | EXAMPLES: |
|---|
| 4250 | sage: pari(9).valuation(3) |
|---|
| 4251 | 2 |
|---|
| 4252 | sage: pari(9).valuation(9) |
|---|
| 4253 | 1 |
|---|
| 4254 | sage: x = pari(9).Mod(27); x.valuation(3) |
|---|
| 4255 | 2 |
|---|
| 4256 | sage: pari('5/3').valuation(3) |
|---|
| 4257 | -1 |
|---|
| 4258 | sage: pari('9 + 3*x + 15*x^2').valuation(3) |
|---|
| 4259 | 1 |
|---|
| 4260 | sage: pari([9,3,15]).valuation(3) |
|---|
| 4261 | 1 |
|---|
| 4262 | sage: pari('9 + 3*x + 15*x^2 + O(x^5)').valuation(3) |
|---|
| 4263 | 1 |
|---|
| 4264 | |
|---|
| 4265 | sage: pari('x^2*(x+1)^3').valuation(pari('x+1')) |
|---|
| 4266 | 3 |
|---|
| 4267 | sage: pari('x + O(x^5)').valuation('x') |
|---|
| 4268 | 1 |
|---|
| 4269 | sage: pari('2*x^2 + O(x^5)').valuation('x') |
|---|
| 4270 | 2 |
|---|
| 4271 | |
|---|
| 4272 | sage.: pari(0).valuation(3) # on 32-bit machine |
|---|
| 4273 | 2147483647 |
|---|
| 4274 | """ |
|---|
| 4275 | cdef gen _p |
|---|
| 4276 | _p = pari(p) |
|---|
| 4277 | cdef int n |
|---|
| 4278 | n = setjmp(GP_DATA.env) |
|---|
| 4279 | if n: |
|---|
| 4280 | _error(n,"error in valuation") |
|---|
| 4281 | return ggval(x.g, _p.g) |
|---|
| 4282 | |
|---|
| 4283 | def variable(gen x): |
|---|
| 4284 | """ |
|---|
| 4285 | variable(x): Return the main variable of the object x, or p |
|---|
| 4286 | if x is a p-adic number. |
|---|
| 4287 | |
|---|
| 4288 | This function raises a TypeError exception on scalars, i.e., |
|---|
| 4289 | on objects with no variable associated to them. |
|---|
| 4290 | |
|---|
| 4291 | INPUT: |
|---|
| 4292 | x -- gen |
|---|
| 4293 | OUTPUT: |
|---|
| 4294 | gen |
|---|
| 4295 | EXAMPLES: |
|---|
| 4296 | sage: pari('x^2 + x -2').variable() |
|---|
| 4297 | x |
|---|
| 4298 | sage: pari('1+2^3 + O(2^5)').variable() |
|---|
| 4299 | 2 |
|---|
| 4300 | sage: pari('x+y0').variable() |
|---|
| 4301 | x |
|---|
| 4302 | sage: pari('y0+z0').variable() |
|---|
| 4303 | y0 |
|---|
| 4304 | """ |
|---|
| 4305 | n = setjmp(GP_DATA.env) |
|---|
| 4306 | if n: |
|---|
| 4307 | _error(n,"error in valuation") |
|---|
| 4308 | return new_gen(gpolvar(x.g)) |
|---|
| 4309 | |
|---|
| 4310 | |
|---|
| 4311 | ########################################### |
|---|
| 4312 | # 3: TRANSCENDENTAL functions |
|---|
| 4313 | ########################################### |
|---|
| 4314 | def sqrt(gen x, int prec=0): |
|---|
| 4315 | cdef int err |
|---|
| 4316 | err = setjmp(GP_DATA.env) |
|---|
| 4317 | if err: _error(err,"error in sqrt") |
|---|
| 4318 | if prec < 3: |
|---|
| 4319 | prec = REAL_PREC |
|---|
| 4320 | _sig_on |
|---|
| 4321 | return new_gen(gsqrt(forcecopy(x.g), prec)) |
|---|
| 4322 | |
|---|
| 4323 | def gamma(gen s, int prec=0): |
|---|
| 4324 | """ |
|---|
| 4325 | gamma(x): Gamma function at s. |
|---|
| 4326 | INPUT: |
|---|
| 4327 | s -- gen (real or complex number |
|---|
| 4328 | OUTPUT: |
|---|
| 4329 | gen -- value of zeta at s. |
|---|
| 4330 | EXAMPLES: |
|---|
| 4331 | """ |
|---|
| 4332 | cdef int err |
|---|
| 4333 | err = setjmp(GP_DATA.env) |
|---|
| 4334 | if err: _error(err,"error evaluating gamma(%s)"%s) |
|---|
| 4335 | if prec < 3: |
|---|
| 4336 | prec = REAL_PREC |
|---|
| 4337 | _sig_on |
|---|
| 4338 | return new_gen(ggamma(forcecopy(s.g), prec)) |
|---|
| 4339 | |
|---|
| 4340 | |
|---|
| 4341 | def zeta(gen s, int prec=0): |
|---|
| 4342 | """ |
|---|
| 4343 | zeta(s): Riemann zeta function at s with s a complex |
|---|
| 4344 | or a p-adic number. |
|---|
| 4345 | INPUT: |
|---|
| 4346 | s -- gen (real or complex number |
|---|
| 4347 | OUTPUT: |
|---|
| 4348 | gen -- value of zeta at s. |
|---|
| 4349 | EXAMPLES: |
|---|
| 4350 | """ |
|---|
| 4351 | cdef int err |
|---|
| 4352 | err = setjmp(GP_DATA.env) |
|---|
| 4353 | if err: _error(err,"error evaluating zeta(%s)"%s) |
|---|
| 4354 | if prec < 3: |
|---|
| 4355 | prec = REAL_PREC |
|---|
| 4356 | _sig_on |
|---|
| 4357 | return new_gen(gzeta(forcecopy(s.g), prec)) |
|---|
| 4358 | |
|---|
| 4359 | |
|---|
| 4360 | ########################################### |
|---|
| 4361 | # 4: NUMBER THEORETICAL functions |
|---|
| 4362 | ########################################### |
|---|
| 4363 | |
|---|
| 4364 | def issquare(gen x, find_root=False): |
|---|
| 4365 | cdef int err |
|---|
| 4366 | cdef GEN G, t |
|---|
| 4367 | cdef gen g |
|---|
| 4368 | err = setjmp(GP_DATA.env) |
|---|
| 4369 | if err: |
|---|
| 4370 | _error(err,"error in issquare") |
|---|
| 4371 | if find_root: |
|---|
| 4372 | _sig_on |
|---|
| 4373 | t = gcarrecomplet(forcecopy(x.g), &G) |
|---|
| 4374 | _sig_off |
|---|
| 4375 | v = bool(new_gen_noclear(t)) |
|---|
| 4376 | if v: |
|---|
| 4377 | return v, new_gen(G) |
|---|
| 4378 | else: |
|---|
| 4379 | return v, None |
|---|
| 4380 | else: |
|---|
| 4381 | _sig_on |
|---|
| 4382 | return new_gen(gcarreparfait(x.g)) |
|---|
| 4383 | |
|---|
| 4384 | |
|---|
| 4385 | def issquarefree(gen self): |
|---|
| 4386 | _sig_on |
|---|
| 4387 | t = bool(issquarefree(forcecopy(self.g))) |
|---|
| 4388 | _sig_off |
|---|
| 4389 | return t |
|---|
| 4390 | |
|---|
| 4391 | def lcm(gen x, y): |
|---|
| 4392 | cdef gen _y |
|---|
| 4393 | _y = pari(y) |
|---|
| 4394 | cdef int err |
|---|
| 4395 | err = setjmp(GP_DATA.env) |
|---|
| 4396 | if err: _error(err,"error in lcm") |
|---|
| 4397 | _sig_on |
|---|
| 4398 | return new_gen(glcm(forcecopy(x.g), forcecopy(_y.g))) |
|---|
| 4399 | |
|---|
| 4400 | def gcd(gen x, y): |
|---|
| 4401 | cdef gen _y |
|---|
| 4402 | _y = pari(y) |
|---|
| 4403 | cdef int err |
|---|
| 4404 | err = setjmp(GP_DATA.env) |
|---|
| 4405 | if err: _error(err,"error in gcd") |
|---|
| 4406 | _sig_on |
|---|
| 4407 | return new_gen(ggcd(forcecopy(x.g), forcecopy(_y.g))) |
|---|
| 4408 | |
|---|
| 4409 | def bezout(gen x, y): |
|---|
| 4410 | cdef gen _y, u, v, g |
|---|
| 4411 | cdef GEN U, V, G |
|---|
| 4412 | _y = pari(y) |
|---|
| 4413 | cdef int err |
|---|
| 4414 | err = setjmp(GP_DATA.env) |
|---|
| 4415 | if err: _error(err,"error in bezout") |
|---|
| 4416 | _sig_on |
|---|
| 4417 | G = gbezout(forcecopy(x.g), forcecopy(_y.g), &U, &V) |
|---|
| 4418 | _sig_off |
|---|
| 4419 | g = new_gen_noclear(G) |
|---|
| 4420 | u = new_gen_noclear(U) |
|---|
| 4421 | v = new_gen(V) |
|---|
| 4422 | return g, u, v |
|---|
| 4423 | |
|---|
| 4424 | def xgcd(gen x, y): |
|---|
| 4425 | return x.bezout(y) |
|---|
| 4426 | |
|---|
| 4427 | ########################################### |
|---|
| 4428 | # 5: Functions related to ELLIPTIC CURVES |
|---|
| 4429 | ########################################### |
|---|
| 4430 | |
|---|
| 4431 | def elladd(gen self, z1, z2): |
|---|
| 4432 | """ |
|---|
| 4433 | e.elladd(z1, z2) |
|---|
| 4434 | |
|---|
| 4435 | Sum of the points z1 and z2 on the elliptic curve e. |
|---|
| 4436 | |
|---|
| 4437 | INPUT: |
|---|
| 4438 | e -- elliptic curve E |
|---|
| 4439 | z1 -- point on E |
|---|
| 4440 | z2 -- point on E |
|---|
| 4441 | |
|---|
| 4442 | OUTPUT: |
|---|
| 4443 | point on E |
|---|
| 4444 | |
|---|
| 4445 | EXAMPLES: |
|---|
| 4446 | First we create an elliptic curve: |
|---|
| 4447 | |
|---|
| 4448 | sage: e = pari([0, 1, 1, -2, 0]).ellinit() |
|---|
| 4449 | sage: str(e)[:65] # first part of output |
|---|
| 4450 | '[0, 1, 1, -2, 0, 4, -4, 1, -3, 112, -856, 389, 1404928/389, [0.90' |
|---|
| 4451 | |
|---|
| 4452 | Next we add two points on the elliptic curve. Notice that |
|---|
| 4453 | the Python lists are automatically converted to PARI objects so |
|---|
| 4454 | you don't have to do that explicitly in your code. |
|---|
| 4455 | |
|---|
| 4456 | sage: e.elladd([1,0,1], [-1,1,1]) |
|---|
| 4457 | [-3/4, -15/8] |
|---|
| 4458 | """ |
|---|
| 4459 | cdef gen _z1, _z2 |
|---|
| 4460 | _z1 = pari(z1); _z2 = pari(z2) |
|---|
| 4461 | cdef int n |
|---|
| 4462 | n = setjmp(GP_DATA.env) |
|---|
| 4463 | if n: _error(n,"error in elladd") |
|---|
| 4464 | _sig_on |
|---|
| 4465 | return new_gen(addell(forcecopy(self.g), _z1.g, _z2.g)) |
|---|
| 4466 | |
|---|
| 4467 | def ellak(gen self, n): |
|---|
| 4468 | r""" |
|---|
| 4469 | e.ellak(n): Returns the coefficient $a_n$ of the $L$-function of |
|---|
| 4470 | the elliptic curve e, i.e. the coefficient of a newform of |
|---|
| 4471 | weight 2 newform. |
|---|
| 4472 | |
|---|
| 4473 | \begin{notice} |
|---|
| 4474 | The curve $e$ {\em must} be a medium or long vector of the type given |
|---|
| 4475 | by ellinit. For this function to work for every n and not just |
|---|
| 4476 | those prime to the conductor, e must be a minimal Weierstrass |
|---|
| 4477 | equation. If this is not the case, use the function |
|---|
| 4478 | ellminimalmodel first before using ellak (or you will get |
|---|
| 4479 | INCORRECT RESULTS!) |
|---|
| 4480 | \end{notice} |
|---|
| 4481 | |
|---|
| 4482 | INPUT: |
|---|
| 4483 | e -- a PARI elliptic curve. |
|---|
| 4484 | n -- integer .. |
|---|
| 4485 | |
|---|
| 4486 | EXAMPLES: |
|---|
| 4487 | sage: e = pari([0, -1, 1, -10, -20]).ellinit() |
|---|
| 4488 | sage: e.ellak(6) |
|---|
| 4489 | 2 |
|---|
| 4490 | sage: e.ellak(2005) |
|---|
| 4491 | 2 |
|---|
| 4492 | sage: e.ellak(-1) |
|---|
| 4493 | 0 |
|---|
| 4494 | sage: e.ellak(0) |
|---|
| 4495 | 0 |
|---|
| 4496 | """ |
|---|
| 4497 | cdef gen _n |
|---|
| 4498 | _n = pari(n) |
|---|
| 4499 | cdef int r |
|---|
| 4500 | r = setjmp(GP_DATA.env) |
|---|
| 4501 | if r: _error(n,"error in ellak") |
|---|
| 4502 | _sig_on |
|---|
| 4503 | return new_gen(akell(forcecopy(self.g), _n.g)) |
|---|
| 4504 | |
|---|
| 4505 | def ellan(gen self, long n): |
|---|
| 4506 | """ |
|---|
| 4507 | EXAMPLES: |
|---|
| 4508 | sage: e = pari([0, -1, 1, -10, -20]).ellinit() |
|---|
| 4509 | sage: e.ellan(3) |
|---|
| 4510 | [1, -2, -1] |
|---|
| 4511 | sage: e.ellan(20) |
|---|
| 4512 | [1, -2, -1, 2, 1, 2, -2, 0, -2, -2, 1, -2, 4, 4, -1, -4, -2, 4, 0, 2] |
|---|
| 4513 | sage: e.ellan(-1) |
|---|
| 4514 | [] |
|---|
| 4515 | """ |
|---|
| 4516 | cdef int r |
|---|
| 4517 | r = setjmp(GP_DATA.env) |
|---|
| 4518 | if r == MEMERR: # out of memory -- increase and try again |
|---|
| 4519 | init_stack(0) |
|---|
| 4520 | return self.ellan(n) |
|---|
| 4521 | elif r: |
|---|
| 4522 | _error(n,"error in ellan") |
|---|
| 4523 | _sig_on |
|---|
| 4524 | return new_gen(anell(forcecopy(self.g), n)) |
|---|
| 4525 | |
|---|
| 4526 | def ellap(gen self, p): |
|---|
| 4527 | r""" |
|---|
| 4528 | e.ellap(p): Returns the prime-indexed coefficient $a_p$ of the |
|---|
| 4529 | $L$-function of the elliptic curve $e$, i.e. the coefficient of a |
|---|
| 4530 | newform of weight 2 newform. |
|---|
| 4531 | |
|---|
| 4532 | \begin{notice} |
|---|
| 4533 | If p is not prime, this function will return an {\bf incorrect} |
|---|
| 4534 | answer. |
|---|
| 4535 | |
|---|
| 4536 | The curve e must be a medium or long vector of the type given |
|---|
| 4537 | by ellinit. For this function to work for every n and not just |
|---|
| 4538 | those prime to the conductor, e must be a minimal Weierstrass |
|---|
| 4539 | equation. If this is not the case, use the function |
|---|
| 4540 | ellminimalmodel first before using ellak (or you will get |
|---|
| 4541 | INCORRECT RESULTS!) |
|---|
| 4542 | \end{notice} |
|---|
| 4543 | |
|---|
| 4544 | INPUT: |
|---|
| 4545 | e -- a PARI elliptic curve. |
|---|
| 4546 | p -- prime integer .. |
|---|
| 4547 | |
|---|
| 4548 | EXAMPLES: |
|---|
| 4549 | sage: e = pari([0, -1, 1, -10, -20]).ellinit() |
|---|
| 4550 | sage: e.ellap(2) |
|---|
| 4551 | -2 |
|---|
| 4552 | sage: e.ellap(2003) |
|---|
| 4553 | 4 |
|---|
| 4554 | sage: e.ellak(-1) |
|---|
| 4555 | 0 |
|---|
| 4556 | """ |
|---|
| 4557 | cdef gen _p |
|---|
| 4558 | _p = pari(p) |
|---|
| 4559 | cdef int n |
|---|
| 4560 | n = setjmp(GP_DATA.env) |
|---|
| 4561 | if n: _error(n,"in apell, p='%s' not a prime"%p) |
|---|
| 4562 | _sig_on |
|---|
| 4563 | return new_gen(apell(forcecopy(self.g), _p.g)) |
|---|
| 4564 | |
|---|
| 4565 | |
|---|
| 4566 | def ellbil(gen self, z1, z2): |
|---|
| 4567 | """ |
|---|
| 4568 | EXAMPLES: |
|---|
| 4569 | sage: e = pari([0,1,1,-2,0]).ellinit() |
|---|
| 4570 | sage: e.ellbil([1, 0, 1], [-1, 1, 1]) |
|---|
| 4571 | 0.4181889844988605856298894585 |
|---|
| 4572 | sage: get_real_precision() |
|---|
| 4573 | 5 |
|---|
| 4574 | """ |
|---|
| 4575 | ## Increasing the precision does not increase the precision |
|---|
| 4576 | ## result, since quantities related to the elliptic curve were |
|---|
| 4577 | ## computed to low precision. |
|---|
| 4578 | ## sage: set_real_precision(10) |
|---|
| 4579 | ## sage: e.ellbil([1, 0, 1], [-1, 1, 1]) |
|---|
| 4580 | ## 0.4181889844988605856298894585 |
|---|
| 4581 | ## However, if we recompute the elliptic curve after increasing |
|---|
| 4582 | ## the precision, then the bilinear pairing will be computed to |
|---|
| 4583 | ## higher precision as well. |
|---|
| 4584 | ## sage: e = pari([0,1,1,-2,0]).ellinit() |
|---|
| 4585 | ## sage: e.ellbil([1, 0, 1], [-1, 1, 1]) |
|---|
| 4586 | ## 0.4181889844988605856298894582 |
|---|
| 4587 | ## sage: set_real_precision(5) |
|---|
| 4588 | cdef gen _z1, _z2 |
|---|
| 4589 | _z1 = pari(z1) |
|---|
| 4590 | _z2 = pari(z2) |
|---|
| 4591 | cdef int n |
|---|
| 4592 | n = setjmp(GP_DATA.env) |
|---|
| 4593 | if n: _error(n,"error in ellbil") |
|---|
| 4594 | _sig_on |
|---|
| 4595 | return new_gen(bilhell(forcecopy(self.g), _z1.g, _z2.g, REAL_PREC)) |
|---|
| 4596 | |
|---|
| 4597 | def ellchangecurve(gen e, ch): |
|---|
| 4598 | """ |
|---|
| 4599 | EXAMPLES: |
|---|
| 4600 | sage: e = pari([1,2,3,4,5]).ellinit() |
|---|
| 4601 | sage: e.ellglobalred() |
|---|
| 4602 | [10351, [1, -1, 0, -1], 1] |
|---|
| 4603 | sage: f = e.ellchangecurve([1,-1,0,-1]) |
|---|
| 4604 | sage: f[:5] |
|---|
| 4605 | [1, -1, 0, 4, 3] |
|---|
| 4606 | """ |
|---|
| 4607 | cdef gen _ch |
|---|
| 4608 | _ch = pari(ch) |
|---|
| 4609 | cdef int n |
|---|
| 4610 | n = setjmp(GP_DATA.env) |
|---|
| 4611 | if n: _error(n,"error in ellchangecurve") |
|---|
| 4612 | _sig_on |
|---|
| 4613 | return new_gen(coordch(forcecopy(e.g), _ch.g)) |
|---|
| 4614 | |
|---|
| 4615 | def ellchangepoint(gen x, y): |
|---|
| 4616 | """ |
|---|
| 4617 | x.ellchangepoint(y): change data on point or vector of points x |
|---|
| 4618 | on an elliptic curve according to y=[u,r,s,t] |
|---|
| 4619 | |
|---|
| 4620 | EXAMPLES: |
|---|
| 4621 | sage: e = pari([0,1,1,-2,0]).ellinit() |
|---|
| 4622 | sage: x = pari([1,0,1]) |
|---|
| 4623 | sage: e.ellisoncurve([1,4,4]) |
|---|
| 4624 | False |
|---|
| 4625 | sage: e.ellisoncurve(x) |
|---|
| 4626 | True |
|---|
| 4627 | sage: f = e.ellchangecurve([1,2,3,-1]) |
|---|
| 4628 | sage: f[:5] # show only first five entries |
|---|
| 4629 | [6, -2, -1, 17, 8] |
|---|
| 4630 | sage: x.ellchangepoint([1,2,3,-1]) |
|---|
| 4631 | [-1, 4] |
|---|
| 4632 | sage: f.ellisoncurve([-1,4]) |
|---|
| 4633 | True |
|---|
| 4634 | """ |
|---|
| 4635 | cdef gen _y |
|---|
| 4636 | _y = pari(y) |
|---|
| 4637 | cdef int n |
|---|
| 4638 | n = setjmp(GP_DATA.env) |
|---|
| 4639 | if n: _error(n,"error in ellchangepoint") |
|---|
| 4640 | _sig_on |
|---|
| 4641 | return new_gen(pointch(forcecopy(x.g), _y.g)) |
|---|
| 4642 | |
|---|
| 4643 | def elleisnum(gen om, long k, int flag=0): |
|---|
| 4644 | """ |
|---|
| 4645 | om.elleisnum(k, {flag=0}, {prec}): om=[om1,om2] being a |
|---|
| 4646 | 2-component vector giving a basis of a lattice L and k an |
|---|
| 4647 | even positive integer, computes the numerical value of the |
|---|
| 4648 | Eisenstein series of weight k. When flag is non-zero and |
|---|
| 4649 | k=4 or 6, this gives g2 or g3 with the correct |
|---|
| 4650 | normalization. |
|---|
| 4651 | |
|---|
| 4652 | INPUT: |
|---|
| 4653 | om -- gen, 2-component vector giving a basis of a lattice L |
|---|
| 4654 | k -- int (even positive) |
|---|
| 4655 | flag -- int (default 0) |
|---|
| 4656 | pref -- precision |
|---|
| 4657 | |
|---|
| 4658 | OUTPUT: |
|---|
| 4659 | gen -- numerical value of E_k |
|---|
| 4660 | |
|---|
| 4661 | EXAMPLES: |
|---|
| 4662 | sage: e = pari([0,1,1,-2,0]).ellinit() |
|---|
| 4663 | sage: om = e.omega() |
|---|
| 4664 | sage: om |
|---|
| 4665 | [2.490212560855055075321357792, 1.971737701551648204422407698*I] |
|---|
| 4666 | sage: om.elleisnum(2) |
|---|
| 4667 | -5.288649339654257621791534695 |
|---|
| 4668 | sage: om.elleisnum(4) |
|---|
| 4669 | 112.0000000000000000000000000 |
|---|
| 4670 | sage: om.elleisnum(100) |
|---|
| 4671 | 2.153142485760776361127070332 E50 |
|---|
| 4672 | sage: om.elleisnum(5) |
|---|
| 4673 | Traceback (most recent call last): |
|---|
| 4674 | ... |
|---|
| 4675 | ArithmeticError: k(=5) must be even |
|---|
| 4676 | sage: om.elleisnum(0) |
|---|
| 4677 | Traceback (most recent call last): |
|---|
| 4678 | ... |
|---|
| 4679 | ArithmeticError: k(=0) must be positive |
|---|
| 4680 | """ |
|---|
| 4681 | if k <= 0: |
|---|
| 4682 | raise ArithmeticError, "k(=%s) must be positive"%k |
|---|
| 4683 | if k % 2: |
|---|
| 4684 | raise ArithmeticError, "k(=%s) must be even"%k |
|---|
| 4685 | cdef int n |
|---|
| 4686 | n = setjmp(GP_DATA.env) |
|---|
| 4687 | if n: _error(n,"in elleisnum: invalid input") |
|---|
| 4688 | _sig_on |
|---|
| 4689 | return new_gen(elleisnum(forcecopy(om.g), k, flag, REAL_PREC)) |
|---|
| 4690 | |
|---|
| 4691 | def elleta(gen self): |
|---|
| 4692 | cdef int n |
|---|
| 4693 | n = setjmp(GP_DATA.env) |
|---|
| 4694 | if n: _error(n,"error in elleta") |
|---|
| 4695 | _sig_on |
|---|
| 4696 | return new_gen(elleta(forcecopy(self.g), REAL_PREC)) |
|---|
| 4697 | |
|---|
| 4698 | def ellglobalred(gen e1): |
|---|
| 4699 | cdef int n |
|---|
| 4700 | n = setjmp(GP_DATA.env) |
|---|
| 4701 | if n: _error(n,"error in ellglobalred") |
|---|
| 4702 | _sig_on |
|---|
| 4703 | return new_gen(globalreduction(forcecopy(e1.g))) |
|---|
| 4704 | |
|---|
| 4705 | def ellheight(gen e, a, flag=0): |
|---|
| 4706 | cdef gen _a |
|---|
| 4707 | _a = pari(a) |
|---|
| 4708 | cdef int n |
|---|
| 4709 | n = setjmp(GP_DATA.env) |
|---|
| 4710 | if n: _error(n,"error in ellheight") |
|---|
| 4711 | _sig_on |
|---|
| 4712 | return new_gen(ellheight0(forcecopy(e.g), _a.g, flag, REAL_PREC)) |
|---|
| 4713 | |
|---|
| 4714 | def ellheightmatrix(gen e, x): |
|---|
| 4715 | """ |
|---|
| 4716 | ellheightmatrix(e,x) |
|---|
| 4717 | |
|---|
| 4718 | Returns the height matrix for vector of points x on elliptic curve e using |
|---|
| 4719 | theta functions. |
|---|
| 4720 | """ |
|---|
| 4721 | cdef gen _x |
|---|
| 4722 | _x = pari(x) |
|---|
| 4723 | cdef int n |
|---|
| 4724 | n = setjmp(GP_DATA.env) |
|---|
| 4725 | if n: _error(n,"error in ellheightmatrix") |
|---|
| 4726 | _sig_on |
|---|
| 4727 | return new_gen(mathell(forcecopy(e.g), _x.g, REAL_PREC)) |
|---|
| 4728 | |
|---|
| 4729 | def ellinit(gen self, int flag=0, prec=0): |
|---|
| 4730 | r""" |
|---|
| 4731 | ellinit(x,{flag=0}): x being the vector [a1,a2,a3,a4,a6], gives |
|---|
| 4732 | the vector: |
|---|
| 4733 | \begin{verbatim} |
|---|
| 4734 | [a1,a2,a3,a4,a6, |
|---|
| 4735 | b2,b4,b6,b8, |
|---|
| 4736 | c4,c6, |
|---|
| 4737 | delta,j, |
|---|
| 4738 | [e1,e2,e3], |
|---|
| 4739 | w1,w2,eta1,eta2,area]. |
|---|
| 4740 | \end{verbatim} |
|---|
| 4741 | If the curve is defined over a p-adic field, the last six components |
|---|
| 4742 | are replaced by root, $u^2$, u, q, w, 0. If optional flag is 1, omit them |
|---|
| 4743 | altogether. |
|---|
| 4744 | """ |
|---|
| 4745 | cdef int n |
|---|
| 4746 | n = setjmp(GP_DATA.env) |
|---|
| 4747 | if n: _error(n,"in ellinit: invalid input '%s' (flag=%s) to the elliptic curve creation function"%(self, flag)) |
|---|
| 4748 | if prec < 3: |
|---|
| 4749 | prec = REAL_PREC |
|---|
| 4750 | if flag < 0 or flag >= 1: |
|---|
| 4751 | raise ValueError, "flag must be 0 or 1" |
|---|
| 4752 | _sig_on |
|---|
| 4753 | return new_gen(ellinit0(forcecopy(self.g), flag, prec)) |
|---|
| 4754 | |
|---|
| 4755 | def ellisoncurve(gen e, x): |
|---|
| 4756 | cdef gen _x |
|---|
| 4757 | _x = pari(x) |
|---|
| 4758 | |
|---|
| 4759 | cdef int n |
|---|
| 4760 | n = setjmp(GP_DATA.env) |
|---|
| 4761 | if n: _error(n,"in elleisoncurve: invalid input e=%s, x=%s"%(e,x)) |
|---|
| 4762 | _sig_on |
|---|
| 4763 | t = bool(oncurve(e.g, _x.g) == 1) |
|---|
| 4764 | _sig_off |
|---|
| 4765 | return t |
|---|
| 4766 | |
|---|
| 4767 | def ellj(gen e): |
|---|
| 4768 | cdef int n |
|---|
| 4769 | n = setjmp(GP_DATA.env) |
|---|
| 4770 | if n: _error(n,"in ellj: invalid input '%s', argument must be element of the upper half plane"%e) |
|---|
| 4771 | _sig_on |
|---|
| 4772 | return new_gen(jell(forcecopy(e.g), REAL_PREC)) |
|---|
| 4773 | |
|---|
| 4774 | def elllocalred(gen e, p): |
|---|
| 4775 | cdef gen _p |
|---|
| 4776 | _p = pari(p) |
|---|
| 4777 | cdef int n |
|---|
| 4778 | n = setjmp(GP_DATA.env) |
|---|
| 4779 | if n: _error(n,"in ellj: invalid input '%s', argument must be element of the upper half plane"%e) |
|---|
| 4780 | #_sig_on |
|---|
| 4781 | return new_gen(elllocalred(forcecopy(e.g), _p.g)) |
|---|
| 4782 | |
|---|
| 4783 | def elllseries(gen e, s, A=1, long prec=0): |
|---|
| 4784 | cdef gen _s, _A |
|---|
| 4785 | _s = pari(s) |
|---|
| 4786 | _A = pari(A) |
|---|
| 4787 | if prec < 3: |
|---|
| 4788 | prec = REAL_PREC |
|---|
| 4789 | |
|---|
| 4790 | # The following line is a hack to get around a bug |
|---|
| 4791 | # in PARI 2.2.9-alpha, where L(E,n) crashes for n<=0 an integer. |
|---|
| 4792 | if s <= ZERO and int(s) == float(s): return ZERO |
|---|
| 4793 | |
|---|
| 4794 | n = setjmp(GP_DATA.env) |
|---|
| 4795 | if n: |
|---|
| 4796 | # I think this problem occurs only at nonpositive integer |
|---|
| 4797 | # points. At these points MAYBE(?) the L-series always |
|---|
| 4798 | # vanishes, so just returning 0 would be a trivial fix. |
|---|
| 4799 | _error(n,"in elllseries: Error evaluating L(E,%s)"%s) |
|---|
| 4800 | |
|---|
| 4801 | _sig_on |
|---|
| 4802 | return new_gen(lseriesell(forcecopy(e.g), _s.g, _A.g, prec)) |
|---|
| 4803 | |
|---|
| 4804 | def ellminimalmodel(gen e): |
|---|
| 4805 | """ |
|---|
| 4806 | |
|---|
| 4807 | ellminimalmodel(e): return the standard minimal integral model |
|---|
| 4808 | of the rational elliptic curve e and the corresponding change |
|---|
| 4809 | of variables. |
|---|
| 4810 | INPUT: |
|---|
| 4811 | e -- gen (that defines an elliptic curve) |
|---|
| 4812 | OUTPUT: |
|---|
| 4813 | gen -- minimal model |
|---|
| 4814 | gen -- change of coordinates |
|---|
| 4815 | EXAMPLES: |
|---|
| 4816 | sage: e = pari([1,2,3,4,5]).ellinit() |
|---|
| 4817 | sage: F, ch = e.ellminimalmodel() |
|---|
| 4818 | sage: F[:5] |
|---|
| 4819 | [1, -1, 0, 4, 3] |
|---|
| 4820 | sage: ch |
|---|
| 4821 | [1, -1, 0, -1] |
|---|
| 4822 | sage: e.ellchangecurve(ch)[:5] |
|---|
| 4823 | [1, -1, 0, 4, 3] |
|---|
| 4824 | """ |
|---|
| 4825 | cdef GEN x, y |
|---|
| 4826 | cdef gen model, change |
|---|
| 4827 | cdef pari_sp t |
|---|
| 4828 | cdef int n |
|---|
| 4829 | n = setjmp(GP_DATA.env) |
|---|
| 4830 | if n: _error(n,"error in ellminimalmodel") |
|---|
| 4831 | _sig_on |
|---|
| 4832 | x = ellminimalmodel(forcecopy(e.g), &y) |
|---|
| 4833 | model = new_gen_noclear(x) |
|---|
| 4834 | change = new_gen(y) |
|---|
| 4835 | return model, change |
|---|
| 4836 | |
|---|
| 4837 | def ellorder(gen e, x): |
|---|
| 4838 | cdef gen _x |
|---|
| 4839 | _x = pari(x) |
|---|
| 4840 | cdef int n |
|---|
| 4841 | n = setjmp(GP_DATA.env) |
|---|
| 4842 | if n: _error(n,"error in ellorder") |
|---|
| 4843 | _sig_on |
|---|
| 4844 | return new_gen(orderell(forcecopy(e.g), _x.g)) |
|---|
| 4845 | |
|---|
| 4846 | def ellordinate(gen e, x): |
|---|
| 4847 | cdef gen _x |
|---|
| 4848 | _x = pari(x) |
|---|
| 4849 | cdef int n |
|---|
| 4850 | n = setjmp(GP_DATA.env) |
|---|
| 4851 | if n: _error(n,"error in ellordinate") |
|---|
| 4852 | _sig_on |
|---|
| 4853 | return new_gen(ordell(forcecopy(e.g), _x.g, REAL_PREC)) |
|---|
| 4854 | |
|---|
| 4855 | def ellpointtoz(gen e, z): |
|---|
| 4856 | cdef gen _x |
|---|
| 4857 | _x = pari(z) |
|---|
| 4858 | cdef int n |
|---|
| 4859 | n = setjmp(GP_DATA.env) |
|---|
| 4860 | if n: _error(n,"error in ellpointtoz") |
|---|
| 4861 | _sig_on |
|---|
| 4862 | return new_gen(zell(forcecopy(e.g), _x.g, REAL_PREC)) |
|---|
| 4863 | |
|---|
| 4864 | def ellpow(gen e, z, n): |
|---|
| 4865 | cdef gen _z, _n |
|---|
| 4866 | _z = pari(z); _n = pari(n) |
|---|
| 4867 | cdef int r |
|---|
| 4868 | r = setjmp(GP_DATA.env) |
|---|
| 4869 | if r: _error(r,"in ellpow") |
|---|
| 4870 | _sig_on |
|---|
| 4871 | return new_gen(powell(forcecopy(e.g), _z.g, _n.g)) |
|---|
| 4872 | |
|---|
| 4873 | def ellrootno(gen e, p=1): |
|---|
| 4874 | cdef gen _p |
|---|
| 4875 | _p = pari(p) |
|---|
| 4876 | cdef int n |
|---|
| 4877 | n = setjmp(GP_DATA.env) |
|---|
| 4878 | if n: _error(n,"in ellrootno") |
|---|
| 4879 | _sig_on |
|---|
| 4880 | return ellrootno(forcecopy(e.g), _p.g) |
|---|
| 4881 | |
|---|
| 4882 | def ellsigma(gen om, z, flag=0): |
|---|
| 4883 | cdef gen _x |
|---|
| 4884 | _x = pari(z) |
|---|
| 4885 | cdef int n |
|---|
| 4886 | n = setjmp(GP_DATA.env) |
|---|
| 4887 | if n: _error(n,"in ellsigma") |
|---|
| 4888 | _sig_on |
|---|
| 4889 | return new_gen(ellsigma(forcecopy(om.g), _x.g, flag, REAL_PREC)) |
|---|
| 4890 | |
|---|
| 4891 | def ellsub(gen e, z1, z2): |
|---|
| 4892 | cdef gen _z1, _z2 |
|---|
| 4893 | _z1 = pari(z1); _z2 = pari(z2) |
|---|
| 4894 | cdef int n |
|---|
| 4895 | n = setjmp(GP_DATA.env) |
|---|
| 4896 | if n: _error(n,"in ellsub") |
|---|
| 4897 | _sig_on |
|---|
| 4898 | return new_gen(subell(forcecopy(e.g), _z1.g, _z2.g)) |
|---|
| 4899 | |
|---|
| 4900 | def elltaniyama(gen e): |
|---|
| 4901 | cdef int n |
|---|
| 4902 | n = setjmp(GP_DATA.env) |
|---|
| 4903 | if n: _error(n,"in elltaniyama") |
|---|
| 4904 | _sig_on |
|---|
| 4905 | return new_gen(taniyama(forcecopy(e.g))) |
|---|
| 4906 | |
|---|
| 4907 | def elltors(gen e, flag=0): |
|---|
| 4908 | cdef int n |
|---|
| 4909 | n = setjmp(GP_DATA.env) |
|---|
| 4910 | if n: |
|---|
| 4911 | if n == 22: |
|---|
| 4912 | # precision too low error |
|---|
| 4913 | raise RuntimeError, "Elliptic curve was created to too low of precision. Call ellinit with the real_precision higher." |
|---|
| 4914 | _error(n,"in elltors") |
|---|
| 4915 | _sig_on |
|---|
| 4916 | return new_gen(elltors0(forcecopy(e.g), flag)) |
|---|
| 4917 | |
|---|
| 4918 | def ellwp(gen e, z='z', long n=20, long flag=0): |
|---|
| 4919 | """ |
|---|
| 4920 | ellwp(E, z,{flag=0}): Return the complex value of the Weierstrass |
|---|
| 4921 | P-function at z on the lattice defined by e. |
|---|
| 4922 | |
|---|
| 4923 | INPUT: |
|---|
| 4924 | E -- list OR elliptic curve |
|---|
| 4925 | list -- [om1, om2], which are Z-generators for a lattice |
|---|
| 4926 | elliptic curve -- created using ellinit |
|---|
| 4927 | |
|---|
| 4928 | z -- (optional) complex number OR string (default = "z") |
|---|
| 4929 | complex number -- any number in the complex plane |
|---|
| 4930 | string (or PARI variable) -- name of a variable. |
|---|
| 4931 | |
|---|
| 4932 | n -- int (optional: default 20) if z is a variable, compute up to at least o(z^n). |
|---|
| 4933 | |
|---|
| 4934 | flag -- int: 0 (default): compute only P(z) |
|---|
| 4935 | 1 compute [P(z),P'(z)] |
|---|
| 4936 | 2 consider om or E as an elliptic curve and use P-function to |
|---|
| 4937 | compute the point on E (with the Weierstrass equation for E) |
|---|
| 4938 | P(z) |
|---|
| 4939 | for that curve (identical to ellztopoint in this case). |
|---|
| 4940 | |
|---|
| 4941 | OUTPUT: |
|---|
| 4942 | gen -- complex number or list of two complex numbers |
|---|
| 4943 | |
|---|
| 4944 | EXAMPLES: |
|---|
| 4945 | |
|---|
| 4946 | We first define the elliptic curve X_0(11): |
|---|
| 4947 | sage: E = pari([0,-1,1,-10,-20]).ellinit() |
|---|
| 4948 | |
|---|
| 4949 | Compute P(1). |
|---|
| 4950 | sage: E.ellwp(1) |
|---|
| 4951 | 13.96586952574849779469497769 + 2.660659330 E-28*I |
|---|
| 4952 | |
|---|
| 4953 | Compute P(1+I), where I = sqrt(-1). |
|---|
| 4954 | sage: E.ellwp(pari("1+I")) |
|---|
| 4955 | -1.115106825655550879209066487 + 2.334190523074698836184798800*I |
|---|
| 4956 | sage: E.ellwp("1+I") |
|---|
| 4957 | -1.115106825655550879209066487 + 2.334190523074698836184798800*I |
|---|
| 4958 | |
|---|
| 4959 | The series expansion, to the default 20 precision: |
|---|
| 4960 | sage: E.ellwp() |
|---|
| 4961 | z^-2 + 31/15*z^2 + 2501/756*z^4 + 961/675*z^6 + 77531/41580*z^8 + 1202285717/928746000*z^10 + 2403461/2806650*z^12 + 30211462703/43418875500*z^14 + 3539374016033/7723451736000*z^16 + 413306031683977/1289540602350000*z^18 + O(z^20) |
|---|
| 4962 | |
|---|
| 4963 | Compute the series for wp to lower precision: |
|---|
| 4964 | sage: E.ellwp(n=4) |
|---|
| 4965 | z^-2 + 31/15*z^2 + O(z^4) |
|---|
| 4966 | |
|---|
| 4967 | Next we use the version where the input is generators for a lattice: |
|---|
| 4968 | sage: pari([1.2692, '0.63 + 1.45*I']).ellwp(1) |
|---|
| 4969 | 13.96561469366894364802003736 + 0.0006448292728105361474541635979*I |
|---|
| 4970 | |
|---|
| 4971 | With flag 1 compute the pair P(z) and P'(z): |
|---|
| 4972 | sage: E.ellwp(1, flag=1) |
|---|
| 4973 | [13.96586952574849779469497769 + 2.660659330 E-28*I, 50.56193008800727525558465689 + 1.615587134 E-27*I] |
|---|
| 4974 | |
|---|
| 4975 | With flag=2, the computed pair is (x,y) on the curve instead of [P(z),P'(z)]: |
|---|
| 4976 | sage: E.ellwp(1, flag=2) |
|---|
| 4977 | [14.29920285908183112802831103 + 2.660659330 E-28*I, 50.06193008800727525558465689 + 1.615587134 E-27*I] |
|---|
| 4978 | """ |
|---|
| 4979 | cdef gen _z |
|---|
| 4980 | _z = pari(z) |
|---|
| 4981 | cdef int err |
|---|
| 4982 | err = setjmp(GP_DATA.env) |
|---|
| 4983 | if err: _error(err,"in ellwp") |
|---|
| 4984 | if n < 0: |
|---|
| 4985 | n = 0 |
|---|
| 4986 | if n%2 == 1: |
|---|
| 4987 | n = n + 1 |
|---|
| 4988 | _sig_on |
|---|
| 4989 | return new_gen(ellwp0(forcecopy(e.g), _z.g, flag, REAL_PREC, (n+2)/2)) |
|---|
| 4990 | |
|---|
| 4991 | def ellzeta(gen om, z): |
|---|
| 4992 | cdef gen _z |
|---|
| 4993 | _z = pari(z) |
|---|
| 4994 | cdef int n |
|---|
| 4995 | n = setjmp(GP_DATA.env) |
|---|
| 4996 | if n: _error(n,"in ellzeta") |
|---|
| 4997 | _sig_on |
|---|
| 4998 | return new_gen(ellzeta(forcecopy(om.g), _z.g, REAL_PREC)) |
|---|
| 4999 | |
|---|
| 5000 | def ellztopoint(gen e, gen z): |
|---|
| 5001 | cdef gen _z |
|---|
| 5002 | _z = pari(z) |
|---|
| 5003 | cdef int n |
|---|
| 5004 | n = setjmp(GP_DATA.env) |
|---|
| 5005 | if n: _error(n,"in ellztopoint") |
|---|
| 5006 | _sig_on |
|---|
| 5007 | return new_gen(pointell(forcecopy(e.g), _z.g, REAL_PREC)) |
|---|
| 5008 | |
|---|
| 5009 | def omega(gen e): |
|---|
| 5010 | """ |
|---|
| 5011 | e.omega(): return basis for the period lattice of the elliptic curve e. |
|---|
| 5012 | |
|---|
| 5013 | EXAMPLES: |
|---|
| 5014 | sage: e = pari([0, -1, 1, -10, -20]).ellinit() |
|---|
| 5015 | sage: e.omega() |
|---|
| 5016 | [1.269209304279553421688794617, 0.6346046521397767108443973084 + 1.458816616938495229330889612*I] |
|---|
| 5017 | """ |
|---|
| 5018 | return e[14:16] |
|---|
| 5019 | |
|---|
| 5020 | def disc(gen e): |
|---|
| 5021 | """ |
|---|
| 5022 | e.disc(): return the discriminant of the elliptic curve e. |
|---|
| 5023 | |
|---|
| 5024 | EXAMPLES: |
|---|
| 5025 | sage: e = pari([0, -1, 1, -10, -20]).ellinit() |
|---|
| 5026 | sage: e.disc() |
|---|
| 5027 | -161051 |
|---|
| 5028 | sage: _.factor() |
|---|
| 5029 | [-1, 1; 11, 5] |
|---|
| 5030 | """ |
|---|
| 5031 | return e[11] |
|---|
| 5032 | |
|---|
| 5033 | def j(gen e): |
|---|
| 5034 | """ |
|---|
| 5035 | e.j(): return the j-invariant of the elliptic curve e. |
|---|
| 5036 | |
|---|
| 5037 | EXAMPLES: |
|---|
| 5038 | sage: e = pari([0, -1, 1, -10, -20]).ellinit() |
|---|
| 5039 | sage: e.j() |
|---|
| 5040 | -122023936/161051 |
|---|
| 5041 | sage: _.factor() |
|---|
| 5042 | [-1, 1; 2, 12; 11, -5; 31, 3] |
|---|
| 5043 | """ |
|---|
| 5044 | return e[12] |
|---|
| 5045 | |
|---|
| 5046 | ########################################### |
|---|
| 5047 | # 6: Functions related to general NUMBER FIELDS |
|---|
| 5048 | ########################################### |
|---|
| 5049 | def bnfunit(gen k): |
|---|
| 5050 | cdef int n |
|---|
| 5051 | n = setjmp(GP_DATA.env) |
|---|
| 5052 | if n: |
|---|
| 5053 | _error(n,"error in bnfunit") |
|---|
| 5054 | _sig_on |
|---|
| 5055 | return new_gen(buchfu(forcecopy(k.g))) |
|---|
| 5056 | |
|---|
| 5057 | def bnfinit(gen f, long flag=0): |
|---|
| 5058 | cdef int n |
|---|
| 5059 | n = setjmp(GP_DATA.env) |
|---|
| 5060 | if n: |
|---|
| 5061 | _error(n,"error in nfinit") |
|---|
| 5062 | |
|---|
| 5063 | _sig_on |
|---|
| 5064 | return new_gen(bnfinit0(forcecopy(f.g), flag, <GEN>0, REAL_PREC)) |
|---|
| 5065 | |
|---|
| 5066 | def idealfactor(gen nf, x): |
|---|
| 5067 | cdef gen _x |
|---|
| 5068 | _x = pari(x) |
|---|
| 5069 | n = setjmp(GP_DATA.env) |
|---|
| 5070 | if n: |
|---|
| 5071 | _error(n,"error in idealfactor") |
|---|
| 5072 | _sig_on |
|---|
| 5073 | return new_gen(idealfactor(forcecopy(nf.g), _x.g)) |
|---|
| 5074 | |
|---|
| 5075 | def nfbasis(gen f, long flag=0, p=0): |
|---|
| 5076 | cdef gen _p |
|---|
| 5077 | cdef GEN g |
|---|
| 5078 | if p != 0: |
|---|
| 5079 | _p = pari(p) |
|---|
| 5080 | g = _p.g |
|---|
| 5081 | else: |
|---|
| 5082 | g = <GEN>NULL |
|---|
| 5083 | |
|---|
| 5084 | cdef int n |
|---|
| 5085 | n = setjmp(GP_DATA.env) |
|---|
| 5086 | if n: |
|---|
| 5087 | _error(n,"error in nfbasis") |
|---|
| 5088 | |
|---|
| 5089 | _sig_on |
|---|
| 5090 | return new_gen(nfbasis0(forcecopy(f.g), flag, g)) |
|---|
| 5091 | |
|---|
| 5092 | def nfinit(gen f, long flag=0): |
|---|
| 5093 | cdef int n |
|---|
| 5094 | n = setjmp(GP_DATA.env) |
|---|
| 5095 | if n: |
|---|
| 5096 | _error(n,"error in nfinit") |
|---|
| 5097 | _sig_on |
|---|
| 5098 | return new_gen(nfinit0(forcecopy(f.g), flag, REAL_PREC)) |
|---|
| 5099 | |
|---|
| 5100 | def polcompositum(gen pol1, pol2, long flag=0): |
|---|
| 5101 | cdef gen _pol2 |
|---|
| 5102 | _pol2 = pari(pol2) |
|---|
| 5103 | |
|---|
| 5104 | cdef int n |
|---|
| 5105 | n = setjmp(GP_DATA.env) |
|---|
| 5106 | if n: |
|---|
| 5107 | _error(n,"error in polcompositum") |
|---|
| 5108 | _sig_on |
|---|
| 5109 | return new_gen(polcompositum0(forcecopy(pol1.g), _pol2.g, flag)) |
|---|
| 5110 | |
|---|
| 5111 | |
|---|
| 5112 | ########################################### |
|---|
| 5113 | # 7: POLYNOMIALS and power series |
|---|
| 5114 | ########################################### |
|---|
| 5115 | def poldegree(gen x, var=-1): |
|---|
| 5116 | """ |
|---|
| 5117 | f.poldegree(var={x}): Return the degree of this polynomial. |
|---|
| 5118 | """ |
|---|
| 5119 | cdef int n |
|---|
| 5120 | n = setjmp(GP_DATA.env) |
|---|
| 5121 | if n: |
|---|
| 5122 | _error(n,"error in poldegree") |
|---|
| 5123 | return poldegree(x.g, get_var(var)) |
|---|
| 5124 | |
|---|
| 5125 | def poldisc(gen x, var=-1): |
|---|
| 5126 | """ |
|---|
| 5127 | f.poldist(var={x}): Return the discriminant of this polynomial. |
|---|
| 5128 | """ |
|---|
| 5129 | cdef int n |
|---|
| 5130 | n = setjmp(GP_DATA.env) |
|---|
| 5131 | if n: |
|---|
| 5132 | _error(n,"error in poldisc") |
|---|
| 5133 | _sig_on |
|---|
| 5134 | return new_gen(poldisc0(forcecopy(x.g), get_var(var))) |
|---|
| 5135 | |
|---|
| 5136 | def polgalois(gen x): |
|---|
| 5137 | """ |
|---|
| 5138 | f.polgalois(): Galois group of the polynomial f |
|---|
| 5139 | """ |
|---|
| 5140 | cdef int err |
|---|
| 5141 | err = setjmp(GP_DATA.env) |
|---|
| 5142 | if err: |
|---|
| 5143 | _error(err,"error in polgalois") |
|---|
| 5144 | _sig_on |
|---|
| 5145 | return new_gen(galois(forcecopy(x.g), REAL_PREC)) |
|---|
| 5146 | |
|---|
| 5147 | def polisirreducible(gen x): |
|---|
| 5148 | """ |
|---|
| 5149 | f.polisirreducible(): Returns True if f is an irreducible |
|---|
| 5150 | non-constant polynomial, or False if f is reducible or |
|---|
| 5151 | constant. |
|---|
| 5152 | """ |
|---|
| 5153 | cdef int err |
|---|
| 5154 | if typ(x.g) != t_POL: |
|---|
| 5155 | raise TypeError, "x (=%s) must be a polynomial."%x |
|---|
| 5156 | err = setjmp(GP_DATA.env) |
|---|
| 5157 | if err: |
|---|
| 5158 | _error(err,"error in polisirreducible") |
|---|
| 5159 | _sig_on |
|---|
| 5160 | return bool(new_gen(gisirreducible(forcecopy(x.g)))) |
|---|
| 5161 | |
|---|
| 5162 | |
|---|
| 5163 | def polresultant(gen x, y, var=-1, flag=0): |
|---|
| 5164 | cdef gen _y |
|---|
| 5165 | _y = pari(y) |
|---|
| 5166 | cdef int n |
|---|
| 5167 | n = setjmp(GP_DATA.env) |
|---|
| 5168 | if n: |
|---|
| 5169 | _error(n,"error in polresultant") |
|---|
| 5170 | |
|---|
| 5171 | _sig_on |
|---|
| 5172 | return new_gen(polresultant0(forcecopy(x.g), _y.g, get_var(var), flag)) |
|---|
| 5173 | |
|---|
| 5174 | def polroots(gen x, flag=0): |
|---|
| 5175 | """ |
|---|
| 5176 | polroots(x,{flag=0}): complex roots of the polynomial x. flag |
|---|
| 5177 | is optional, and can be 0: default, uses Schonhage's method modified |
|---|
| 5178 | by Gourdon, or 1: uses a modified Newton method. |
|---|
| 5179 | """ |
|---|
| 5180 | cdef int n |
|---|
| 5181 | n = setjmp(GP_DATA.env) |
|---|
| 5182 | if n: _error(n,"error in polroots") |
|---|
| 5183 | |
|---|
| 5184 | _sig_on |
|---|
| 5185 | return new_gen(roots0(forcecopy(x.g), flag, REAL_PREC)) |
|---|
| 5186 | |
|---|
| 5187 | |
|---|
| 5188 | ########################################### |
|---|
| 5189 | # 8: Vectors, matrices, LINEAR ALGEBRA and sets |
|---|
| 5190 | ########################################### |
|---|
| 5191 | |
|---|
| 5192 | ########################################### |
|---|
| 5193 | # 9: SUMS, products, integrals and similar functions |
|---|
| 5194 | ########################################### |
|---|
| 5195 | |
|---|
| 5196 | ########################################### |
|---|
| 5197 | # 11. PROGRAMMING under GP |
|---|
| 5198 | ########################################### |
|---|
| 5199 | |
|---|
| 5200 | ########################################### |
|---|
| 5201 | # polarit2.c |
|---|
| 5202 | ########################################### |
|---|
| 5203 | def factor(gen self, limit=-1): |
|---|
| 5204 | """ |
|---|
| 5205 | factor(x,{lim}): factorization of x. lim is optional and can |
|---|
| 5206 | be set whenever x is of (possibly recursive) rational |
|---|
| 5207 | type. If lim is set return partial factorization, using |
|---|
| 5208 | primes up to lim (up to primelimit if lim=0) |
|---|
| 5209 | """ |
|---|
| 5210 | _sig_on |
|---|
| 5211 | |
|---|
| 5212 | if sigsetjmp(_env,1): raise KeyboardInterrupt |
|---|
| 5213 | |
|---|
| 5214 | cdef int n |
|---|
| 5215 | |
|---|
| 5216 | _sig_on |
|---|
| 5217 | return new_gen(factor0(forcecopy(self.g), limit)) |
|---|
| 5218 | |
|---|
| 5219 | |
|---|
| 5220 | |
|---|
| 5221 | |
|---|
| 5222 | |
|---|
| 5223 | ########################################### |
|---|
| 5224 | # misc (classify when I know where they go) |
|---|
| 5225 | ########################################### |
|---|
| 5226 | |
|---|
| 5227 | def eint1(gen self, long n=0): |
|---|
| 5228 | """ |
|---|
| 5229 | eint1(x,{n}) |
|---|
| 5230 | |
|---|
| 5231 | Returns the exponential integral E1(x). If the optional |
|---|
| 5232 | argument n is given, computes the vector of the first n |
|---|
| 5233 | values of the exponential integral E1(x*n), for x > 0. |
|---|
| 5234 | |
|---|
| 5235 | REFERENCE: See page 262, Prop 5.6.12, of Cohen's book |
|---|
| 5236 | "A Course in Computational Algebraic Number Theory". |
|---|
| 5237 | """ |
|---|
| 5238 | cdef int err |
|---|
| 5239 | err = setjmp(GP_DATA.env) |
|---|
| 5240 | if err: _error(err,"error in eint1") |
|---|
| 5241 | |
|---|
| 5242 | cdef int t |
|---|
| 5243 | t = typ(self.g) |
|---|
| 5244 | if t != t_INT and t != t_REAL: |
|---|
| 5245 | raise TypeError, "Input (x=%s) must be a real number."%self |
|---|
| 5246 | |
|---|
| 5247 | if n <= 0: |
|---|
| 5248 | _sig_on |
|---|
| 5249 | return new_gen(eint1(forcecopy(self.g), REAL_PREC)) |
|---|
| 5250 | else: |
|---|
| 5251 | if gsigne(self.g) <= 0: |
|---|
| 5252 | raise ArithmeticError, "Input (x=%s) must be a positive real number."%self |
|---|
| 5253 | _sig_on |
|---|
| 5254 | return new_gen(veceint1(forcecopy(self.g), stoi(n), REAL_PREC)) |
|---|
| 5255 | |
|---|
| 5256 | |
|---|
| 5257 | def order(self): |
|---|
| 5258 | cdef int err |
|---|
| 5259 | err = setjmp(GP_DATA.env) |
|---|
| 5260 | if err: _error(err,"error in order") |
|---|
| 5261 | _sig_on |
|---|
| 5262 | return new_gen(order(forcecopy(self.g))) |
|---|
| 5263 | |
|---|
| 5264 | def znprimroot(self): |
|---|
| 5265 | cdef int n |
|---|
| 5266 | n = setjmp(GP_DATA.env) |
|---|
| 5267 | if n: _error(n,"error in znprimroot") |
|---|
| 5268 | _sig_on |
|---|
| 5269 | return new_gen(ggener(forcecopy(self.g))) |
|---|
| 5270 | |
|---|
| 5271 | def __abs__(self): |
|---|
| 5272 | return self.abs() |
|---|
| 5273 | |
|---|
| 5274 | def abs(gen self): |
|---|
| 5275 | cdef int err |
|---|
| 5276 | err = setjmp(GP_DATA.env) |
|---|
| 5277 | if err: _error(err,"error in abs") |
|---|
| 5278 | _sig_on |
|---|
| 5279 | return new_gen(gabs(forcecopy(self.g), REAL_PREC)) |
|---|
| 5280 | |
|---|
| 5281 | def mattranspose(gen self): |
|---|
| 5282 | """ |
|---|
| 5283 | """ |
|---|
| 5284 | cdef int n |
|---|
| 5285 | n = setjmp(GP_DATA.env) |
|---|
| 5286 | if n: _error(n,"error in mattranspose") |
|---|
| 5287 | _sig_on |
|---|
| 5288 | return new_gen(gtrans(forcecopy(self.g))) |
|---|
| 5289 | |
|---|
| 5290 | def matker(gen self, long flag=0): |
|---|
| 5291 | """ |
|---|
| 5292 | """ |
|---|
| 5293 | cdef int n |
|---|
| 5294 | n = setjmp(GP_DATA.env) |
|---|
| 5295 | if n: _error(n,"error in matker") |
|---|
| 5296 | _sig_on |
|---|
| 5297 | return new_gen(matker0(forcecopy(self.g), flag)) |
|---|
| 5298 | |
|---|
| 5299 | def matkerint(gen self, long flag=0): |
|---|
| 5300 | """ |
|---|
| 5301 | """ |
|---|
| 5302 | cdef int n |
|---|
| 5303 | n = setjmp(GP_DATA.env) |
|---|
| 5304 | if n: _error(n,"error in matkerint") |
|---|
| 5305 | _sig_on |
|---|
| 5306 | return new_gen(matkerint0(forcecopy(self.g), flag)) |
|---|
| 5307 | |
|---|
| 5308 | def trace(gen self): |
|---|
| 5309 | cdef int n |
|---|
| 5310 | n = setjmp(GP_DATA.env) |
|---|
| 5311 | if n: _error(n,"error in trace") |
|---|
| 5312 | _sig_on |
|---|
| 5313 | return new_gen(gtrace(forcecopy(self.g))) |
|---|
| 5314 | |
|---|
| 5315 | def norm(gen self): |
|---|
| 5316 | cdef int n |
|---|
| 5317 | n = setjmp(GP_DATA.env) |
|---|
| 5318 | if n: _error(n,"error in norm") |
|---|
| 5319 | _sig_on |
|---|
| 5320 | return new_gen(gnorm(forcecopy(self.g))) |
|---|
| 5321 | |
|---|
| 5322 | def charpoly(gen self, var=-1, flag=0): |
|---|
| 5323 | """ |
|---|
| 5324 | charpoly(A,{v=x},{flag=0}): det(v*Id-A) = characteristic polynomial of the |
|---|
| 5325 | matrix A using the comatrix. flag is optional and may be set to 1 (use |
|---|
| 5326 | Lagrange interpolation) or 2 (use Hessenberg form), 0 being the default. |
|---|
| 5327 | """ |
|---|
| 5328 | cdef int n |
|---|
| 5329 | n = setjmp(GP_DATA.env) |
|---|
| 5330 | if n: _error(n,"error in charpoly") |
|---|
| 5331 | _sig_on |
|---|
| 5332 | return new_gen(charpoly0(forcecopy(self.g), get_var(var), flag)) |
|---|
| 5333 | |
|---|
| 5334 | |
|---|
| 5335 | def nextprime(gen self): |
|---|
| 5336 | """ |
|---|
| 5337 | nextprime(x): smallest pseudoprime >= x |
|---|
| 5338 | """ |
|---|
| 5339 | cdef int n |
|---|
| 5340 | n = setjmp(GP_DATA.env) |
|---|
| 5341 | if n: _error(n,"error in nextprime") |
|---|
| 5342 | _sig_on |
|---|
| 5343 | return new_gen(gnextprime(forcecopy(self.g))) |
|---|
| 5344 | |
|---|
| 5345 | def subst(gen self, var, y): |
|---|
| 5346 | """ |
|---|
| 5347 | EXAMPLES: |
|---|
| 5348 | sage: x = pari("x"); y = pari("y") |
|---|
| 5349 | sage: f = x**3 + 17*x + 3 |
|---|
| 5350 | sage: f.subst(x, y) |
|---|
| 5351 | y^3 + 17*y + 3 |
|---|
| 5352 | sage: f.subst(x, "z") |
|---|
| 5353 | z^3 + 17*z + 3 |
|---|
| 5354 | sage: f.subst(x, "z")**2 |
|---|
| 5355 | z^6 + 34*z^4 + 6*z^3 + 289*z^2 + 102*z + 9 |
|---|
| 5356 | sage: f.subst(x, "x+1") |
|---|
| 5357 | x^3 + 3*x^2 + 20*x + 21 |
|---|
| 5358 | sage: f.subst(x, "xyz") |
|---|
| 5359 | xyz^3 + 17*xyz + 3 |
|---|
| 5360 | sage: f.subst(x, "xyz")**2 |
|---|
| 5361 | xyz^6 + 34*xyz^4 + 6*xyz^3 + 289*xyz^2 + 102*xyz + 9 |
|---|
| 5362 | """ |
|---|
| 5363 | cdef gen _y |
|---|
| 5364 | _y = pari(y) |
|---|
| 5365 | cdef int n |
|---|
| 5366 | n = setjmp(GP_DATA.env) |
|---|
| 5367 | if n: _error(n,"error in subst") |
|---|
| 5368 | _sig_on |
|---|
| 5369 | return new_gen(gsubst(forcecopy(self.g), get_var(var), _y.g)) |
|---|
| 5370 | |
|---|
| 5371 | |
|---|
| 5372 | def __call__(gen self, y): |
|---|
| 5373 | cdef gen _y |
|---|
| 5374 | _y = pari(y) |
|---|
| 5375 | cdef int n |
|---|
| 5376 | n = setjmp(GP_DATA.env) |
|---|
| 5377 | if n: _error(n,"error in __call__") |
|---|
| 5378 | _sig_on |
|---|
| 5379 | return new_gen(gsubst(forcecopy(self.g), get_var(0), _y.g)) |
|---|
| 5380 | |
|---|
| 5381 | def kronecker(gen self, y): |
|---|
| 5382 | cdef gen _y |
|---|
| 5383 | _y = pari(y) |
|---|
| 5384 | |
|---|
| 5385 | cdef int n |
|---|
| 5386 | n = setjmp(GP_DATA.env) |
|---|
| 5387 | if n: |
|---|
| 5388 | _error(n,"error in imag") |
|---|
| 5389 | _sig_on |
|---|
| 5390 | |
|---|
| 5391 | return new_gen(gkronecker(forcecopy(self.g), _y.g)) |
|---|
| 5392 | |
|---|
| 5393 | def exp(gen self): |
|---|
| 5394 | cdef int n |
|---|
| 5395 | n = setjmp(GP_DATA.env) |
|---|
| 5396 | if n: |
|---|
| 5397 | _error(n,"error in imag") |
|---|
| 5398 | _sig_on |
|---|
| 5399 | return new_gen(gexp(forcecopy(self.g), REAL_PREC)) |
|---|
| 5400 | |
|---|
| 5401 | def log(gen self): |
|---|
| 5402 | cdef int n |
|---|
| 5403 | n = setjmp(GP_DATA.env) |
|---|
| 5404 | if n: |
|---|
| 5405 | _error(n,"error in imag") |
|---|
| 5406 | _sig_on |
|---|
| 5407 | return new_gen(glog(forcecopy(self.g), REAL_PREC)) |
|---|
| 5408 | |
|---|
| 5409 | |
|---|
| 5410 | def type(gen self): |
|---|
| 5411 | return str(type_name(typ(self.g))) |
|---|
| 5412 | |
|---|
| 5413 | |
|---|
| 5414 | ########################################### |
|---|
| 5415 | # Create a gen from a GEN object. |
|---|
| 5416 | # This *steals* a reference to the GEN. |
|---|
| 5417 | ########################################### |
|---|
| 5418 | cdef pari_sp stack_avma |
|---|
| 5419 | |
|---|
| 5420 | cdef save_avma(): |
|---|
| 5421 | global avma, stack_avma |
|---|
| 5422 | stack_avma = avma |
|---|
| 5423 | |
|---|
| 5424 | cdef gen new_gen_noclear(GEN x): |
|---|
| 5425 | """ |
|---|
| 5426 | Create a new gen, but don't free any memory on the stack. |
|---|
| 5427 | """ |
|---|
| 5428 | global top |
|---|
| 5429 | |
|---|
| 5430 | return _new_gen(x,top) |
|---|
| 5431 | |
|---|
| 5432 | ## cdef gen new_gen_from(GEN x, pari_sp av): |
|---|
| 5433 | ## """ |
|---|
| 5434 | ## Create a new gen, then free everything on the stack below av. |
|---|
| 5435 | ## The gen *must* not reference anything on the stack above av. |
|---|
| 5436 | ## """ |
|---|
| 5437 | ## global avma |
|---|
| 5438 | ## cdef gen g |
|---|
| 5439 | ## g = _new_gen(x, av) |
|---|
| 5440 | ## avma = av |
|---|
| 5441 | ## return g |
|---|
| 5442 | |
|---|
| 5443 | cdef gen new_gen(GEN x): |
|---|
| 5444 | """ |
|---|
| 5445 | Create a new gen, then free the *entire* stack. |
|---|
| 5446 | """ |
|---|
| 5447 | cdef gen g |
|---|
| 5448 | global top, avma |
|---|
| 5449 | g = _new_gen(x, top) |
|---|
| 5450 | avma = top |
|---|
| 5451 | return g |
|---|
| 5452 | |
|---|
| 5453 | cdef gen __xxx_new_gen(GEN x, pari_sp start): |
|---|
| 5454 | cdef size_t s |
|---|
| 5455 | cdef pari_sp tmp_bot, tmp_top, tmp_avma |
|---|
| 5456 | cdef GEN h |
|---|
| 5457 | cdef gen p |
|---|
| 5458 | |
|---|
| 5459 | global avma, bot, top |
|---|
| 5460 | |
|---|
| 5461 | if <pari_sp>x < bot or <pari_sp>x > top: |
|---|
| 5462 | p = gen() |
|---|
| 5463 | p.init(x, 0) |
|---|
| 5464 | return p |
|---|
| 5465 | |
|---|
| 5466 | tmp_top = top |
|---|
| 5467 | tmp_bot = bot |
|---|
| 5468 | tmp_avma = avma |
|---|
| 5469 | s = <size_t> (start - avma) |
|---|
| 5470 | #print "Allocating %s bytes for PARI/Python object"%(<long> s) |
|---|
| 5471 | bot = <pari_sp> PyMem_Malloc(s) |
|---|
| 5472 | top = bot + s |
|---|
| 5473 | avma = top |
|---|
| 5474 | h = forcecopy(x) |
|---|
| 5475 | p = gen(); p.init(h, bot) |
|---|
| 5476 | |
|---|
| 5477 | # Restore the stack to how it was before x was created. |
|---|
| 5478 | top = tmp_top |
|---|
| 5479 | bot = tmp_bot |
|---|
| 5480 | avma = tmp_avma |
|---|
| 5481 | return p |
|---|
| 5482 | |
|---|
| 5483 | cdef gen _new_gen(GEN x, pari_sp start): |
|---|
| 5484 | cdef size_t s |
|---|
| 5485 | cdef pari_sp tmp_bot, tmp_top, tmp_avma |
|---|
| 5486 | cdef GEN h |
|---|
| 5487 | cdef gen p |
|---|
| 5488 | |
|---|
| 5489 | global avma, bot, top |
|---|
| 5490 | |
|---|
| 5491 | if <pari_sp>x < bot or <pari_sp>x > top: |
|---|
| 5492 | p = gen() |
|---|
| 5493 | p.init(x, 0) |
|---|
| 5494 | return p |
|---|
| 5495 | |
|---|
| 5496 | tmp_top = top |
|---|
| 5497 | tmp_bot = bot |
|---|
| 5498 | tmp_avma = avma |
|---|
| 5499 | h = forcecopy(x) |
|---|
| 5500 | s = <size_t> (tmp_avma - avma) |
|---|
| 5501 | #print "Allocating %s bytes for PARI/Python object"%(<long> s) |
|---|
| 5502 | bot = <pari_sp> PyMem_Malloc(s) |
|---|
| 5503 | top = bot + s |
|---|
| 5504 | avma = top |
|---|
| 5505 | h = forcecopy(x) |
|---|
| 5506 | p = gen(); p.init(h, bot) |
|---|
| 5507 | |
|---|
| 5508 | # Restore the stack to how it was before x was created. |
|---|
| 5509 | top = tmp_top |
|---|
| 5510 | bot = tmp_bot |
|---|
| 5511 | avma = tmp_avma |
|---|
| 5512 | return p |
|---|
| 5513 | |
|---|
| 5514 | cdef gen new_ref(GEN x, g): |
|---|
| 5515 | cdef gen p |
|---|
| 5516 | p = gen(); p.init(x, 0) |
|---|
| 5517 | p.refers_to[-1] = g # so underlying memory won't get deleted |
|---|
| 5518 | # out from under us. |
|---|
| 5519 | return p |
|---|
| 5520 | |
|---|
| 5521 | def pari(s): |
|---|
| 5522 | """ |
|---|
| 5523 | Create the PARI object got by evaluating s using PARI. |
|---|
| 5524 | """ |
|---|
| 5525 | cdef gen p |
|---|
| 5526 | cdef GEN g |
|---|
| 5527 | cdef pari_sp prev_avma |
|---|
| 5528 | global avma |
|---|
| 5529 | |
|---|
| 5530 | prev_avma = avma |
|---|
| 5531 | |
|---|
| 5532 | if isinstance(s, gen): |
|---|
| 5533 | return s |
|---|
| 5534 | elif isinstance(s, (list, xrange, tuple)): |
|---|
| 5535 | v = vector(len(s)) |
|---|
| 5536 | for i, x in enumerate(s): |
|---|
| 5537 | v[i] = pari(x) |
|---|
| 5538 | return v |
|---|
| 5539 | elif isinstance(s, bool): |
|---|
| 5540 | if s: |
|---|
| 5541 | return ONE |
|---|
| 5542 | return ZERO |
|---|
| 5543 | else: |
|---|
| 5544 | try: |
|---|
| 5545 | return s.pari() |
|---|
| 5546 | except AttributeError: |
|---|
| 5547 | pass |
|---|
| 5548 | |
|---|
| 5549 | t = str(s) |
|---|
| 5550 | again = True |
|---|
| 5551 | while again: |
|---|
| 5552 | try: |
|---|
| 5553 | _sig_on |
|---|
| 5554 | g = str_to_GEN(t) |
|---|
| 5555 | _sig_off |
|---|
| 5556 | again = False |
|---|
| 5557 | except MemoryError: |
|---|
| 5558 | again = True |
|---|
| 5559 | |
|---|
| 5560 | #return new_gen_from(g, prev_avma) |
|---|
| 5561 | return new_gen(g) |
|---|
| 5562 | |
|---|
| 5563 | |
|---|
| 5564 | cdef int get_var(v): |
|---|
| 5565 | """ |
|---|
| 5566 | Converts a Python string into a PARI variable reference number. |
|---|
| 5567 | Or if v = -1, returns -1. |
|---|
| 5568 | """ |
|---|
| 5569 | if v != -1: |
|---|
| 5570 | s = str(v) |
|---|
| 5571 | return fetch_user_var(s) |
|---|
| 5572 | return -1 |
|---|
| 5573 | |
|---|
| 5574 | def _stack_ptr(): |
|---|
| 5575 | return avma |
|---|
| 5576 | |
|---|
| 5577 | def _stack_top(): |
|---|
| 5578 | return top |
|---|
| 5579 | |
|---|
| 5580 | def _stack_bottom(): |
|---|
| 5581 | return bot |
|---|
| 5582 | |
|---|
| 5583 | def _stack_size(): |
|---|
| 5584 | """ |
|---|
| 5585 | Stack size, in bytes |
|---|
| 5586 | """ |
|---|
| 5587 | #return int((top-bot)/1048576) |
|---|
| 5588 | return top-bot |
|---|
| 5589 | |
|---|
| 5590 | def stack_usage(): |
|---|
| 5591 | """ |
|---|
| 5592 | Return how much memory in megabytes is currently being used by the |
|---|
| 5593 | PARI stack. |
|---|
| 5594 | """ |
|---|
| 5595 | #return (top-avma)/1048576 |
|---|
| 5596 | return top-avma |
|---|
| 5597 | |
|---|
| 5598 | def stack_available(): |
|---|
| 5599 | """ |
|---|
| 5600 | Return how much memory in megabytes is currently available on the |
|---|
| 5601 | PARI stack. |
|---|
| 5602 | """ |
|---|
| 5603 | #return (avma-bot)/1048576 |
|---|
| 5604 | return avma-bot |
|---|
| 5605 | |
|---|
| 5606 | |
|---|
| 5607 | ###################################################### |
|---|
| 5608 | # Direct interface to PARI C-level interpreter (avoid using this) |
|---|
| 5609 | ###################################################### |
|---|
| 5610 | |
|---|
| 5611 | def execute(s): |
|---|
| 5612 | """ |
|---|
| 5613 | Excecute s using the PARI C library. |
|---|
| 5614 | """ |
|---|
| 5615 | cdef int n |
|---|
| 5616 | n = setjmp(GP_DATA.env) |
|---|
| 5617 | if n: |
|---|
| 5618 | _error(n, s) |
|---|
| 5619 | _sig_on |
|---|
| 5620 | execute(s) # if call returns, then was memory error so try again |
|---|
| 5621 | _sig_off |
|---|
| 5622 | |
|---|
| 5623 | # Parse s in PARI. |
|---|
| 5624 | s = s + "\n" |
|---|
| 5625 | _sig_on |
|---|
| 5626 | flisseq(s) |
|---|
| 5627 | _sig_off |
|---|
| 5628 | |
|---|
| 5629 | def eval(s): |
|---|
| 5630 | """ |
|---|
| 5631 | Parse s in PARI and evaluate the result, then return it as a string. |
|---|
| 5632 | """ |
|---|
| 5633 | cdef int n |
|---|
| 5634 | n = setjmp(GP_DATA.env) |
|---|
| 5635 | if n: |
|---|
| 5636 | _error(n, s) |
|---|
| 5637 | return eval(s) # if call returns, then was memory error so try again |
|---|
| 5638 | |
|---|
| 5639 | cdef GEN x |
|---|
| 5640 | cdef char *c |
|---|
| 5641 | |
|---|
| 5642 | # Parse s in pari and evaluate result. |
|---|
| 5643 | s = s + "\n" |
|---|
| 5644 | _sig_on |
|---|
| 5645 | x = flisseq(s) |
|---|
| 5646 | # Get result as a C-string |
|---|
| 5647 | c = GENtostr(x) |
|---|
| 5648 | _sig_off |
|---|
| 5649 | # De-callocate memory used by x: |
|---|
| 5650 | cgiv(x) |
|---|
| 5651 | # Convert c to a Python string. |
|---|
| 5652 | s = str(c) |
|---|
| 5653 | # Free memory used by c |
|---|
| 5654 | free(c) |
|---|
| 5655 | return s |
|---|
| 5656 | |
|---|
| 5657 | def _error(n, s=""): |
|---|
| 5658 | _sig_off |
|---|
| 5659 | import sys |
|---|
| 5660 | ## if n == 20: |
|---|
| 5661 | ## raise TypeError, "Incorrect type (%s)"%s |
|---|
| 5662 | ## if n == 23: |
|---|
| 5663 | ## raise TypeError, "Unable to assign I-->S. (%s)"%s |
|---|
| 5664 | ## if n == 24: |
|---|
| 5665 | ## raise TypeError, "Unable to convert to integer: %s"%s |
|---|
| 5666 | ## if n == 65: |
|---|
| 5667 | ## raise OverflowError, "Object too big to fit in a codeword: %s"%s |
|---|
| 5668 | ## if n == 83: # not enough precomputed primes... (might be useful) |
|---|
| 5669 | ## global num_primes |
|---|
| 5670 | ## print "Doubling number of precomputed primes." |
|---|
| 5671 | ## init_primes(2*num_primes) |
|---|
| 5672 | ## return |
|---|
| 5673 | ## if n == 97: |
|---|
| 5674 | ## raise InputError, "Bad arguments to an elliptic curve function: %s"%s |
|---|
| 5675 | if n == MEMERR: # out of memory |
|---|
| 5676 | print "PARI ran out of memory, so we automatically increase the memory available to PARI." |
|---|
| 5677 | init_stack(0) # double current stack size; all data on stack is erased. |
|---|
| 5678 | return |
|---|
| 5679 | raise RuntimeError, "PARI error %s: %s"%(n,s) |
|---|
| 5680 | |
|---|
| 5681 | |
|---|
| 5682 | |
|---|
| 5683 | def min(x,y): |
|---|
| 5684 | """ |
|---|
| 5685 | min(x,y): Return the minimum of x and y. |
|---|
| 5686 | """ |
|---|
| 5687 | if x <= y: |
|---|
| 5688 | return x |
|---|
| 5689 | return y |
|---|
| 5690 | |
|---|
| 5691 | def max(x,y): |
|---|
| 5692 | """ |
|---|
| 5693 | max(x,y): Return the maximum of x and y. |
|---|
| 5694 | """ |
|---|
| 5695 | if x >= y: |
|---|
| 5696 | return x |
|---|
| 5697 | return y |
|---|
| 5698 | |
|---|
| 5699 | def prime_list(long n): |
|---|
| 5700 | """ |
|---|
| 5701 | prime_list(n): returns list of the first n primes |
|---|
| 5702 | |
|---|
| 5703 | INPUT: |
|---|
| 5704 | n -- C long |
|---|
| 5705 | OUTPUT: |
|---|
| 5706 | gen -- PARI list of first n primes |
|---|
| 5707 | EXAMPLES: |
|---|
| 5708 | sage: prime_list(0) |
|---|
| 5709 | [] |
|---|
| 5710 | sage: prime_list(-1) |
|---|
| 5711 | [] |
|---|
| 5712 | sage: prime_list(3) |
|---|
| 5713 | [2, 3, 5] |
|---|
| 5714 | sage: prime_list(10) |
|---|
| 5715 | [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] |
|---|
| 5716 | sage: prime_list(20) |
|---|
| 5717 | [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71] |
|---|
| 5718 | sage: len(prime_list(1000)) |
|---|
| 5719 | 1000 |
|---|
| 5720 | """ |
|---|
| 5721 | |
|---|
| 5722 | cdef int e |
|---|
| 5723 | e = setjmp(GP_DATA.env) |
|---|
| 5724 | if e: _error(e,"prime_list") |
|---|
| 5725 | _sig_on |
|---|
| 5726 | return new_gen(primes(n)) |
|---|
| 5727 | |
|---|
| 5728 | def nth_prime(long n): |
|---|
| 5729 | """ |
|---|
| 5730 | nth_prime(n): returns the n-th prime, where n is a C-int |
|---|
| 5731 | """ |
|---|
| 5732 | global num_primes |
|---|
| 5733 | |
|---|
| 5734 | if n <= 0: |
|---|
| 5735 | raise ArithmeticError, "nth prime meaningless for negative n (=%s)"%n |
|---|
| 5736 | cdef GEN g |
|---|
| 5737 | z = setjmp(GP_DATA.env) |
|---|
| 5738 | if z: |
|---|
| 5739 | init_primes(max(2*num_primes,20*n)) |
|---|
| 5740 | return nth_prime(n) |
|---|
| 5741 | #_error(z, "Not enough precomputed primes") |
|---|
| 5742 | _sig_on |
|---|
| 5743 | g = prime(n) |
|---|
| 5744 | return new_gen(g) |
|---|
| 5745 | |
|---|
| 5746 | def euler(int prec=0): |
|---|
| 5747 | """ |
|---|
| 5748 | Return Euler's constant. |
|---|
| 5749 | |
|---|
| 5750 | EXAMPLES: |
|---|
| 5751 | sage.: euler() |
|---|
| 5752 | 0.57721566490153286060651209008 |
|---|
| 5753 | sage.: get_real_precision() |
|---|
| 5754 | 5 |
|---|
| 5755 | sage.: euler(6) |
|---|
| 5756 | 0.57721566490153286060651209008240243104 |
|---|
| 5757 | sage.: set_real_precision(10) |
|---|
| 5758 | sage.: euler() |
|---|
| 5759 | 0.57721566490153286060651209008240243104215933593992359880576723488486772677767 |
|---|
| 5760 | |
|---|
| 5761 | We restore precision to the default. |
|---|
| 5762 | sage: set_real_precision(5) |
|---|
| 5763 | |
|---|
| 5764 | Note that euler is still saved to the largest precision to which it has been |
|---|
| 5765 | computed so far: |
|---|
| 5766 | sage.: euler() |
|---|
| 5767 | 0.57721566490153286060651209008240243104215933593992359880576723488486772677767 |
|---|
| 5768 | """ |
|---|
| 5769 | if prec<=3: |
|---|
| 5770 | consteuler(REAL_PREC) |
|---|
| 5771 | else: |
|---|
| 5772 | consteuler(prec) |
|---|
| 5773 | cdef gen g |
|---|
| 5774 | g = gen() |
|---|
| 5775 | g.init(geuler,0) |
|---|
| 5776 | return g |
|---|
| 5777 | |
|---|
| 5778 | def pi(int prec=0): |
|---|
| 5779 | """ |
|---|
| 5780 | Return the value of the constant pi = 3.1415.... |
|---|
| 5781 | |
|---|
| 5782 | EXAMPLES: |
|---|
| 5783 | sage.: set_real_precision(5) |
|---|
| 5784 | sage.: pi() |
|---|
| 5785 | 3.1415926535897932384626433833 |
|---|
| 5786 | sage.: pi(6) |
|---|
| 5787 | 3.14159265358979323846264338327950288419 |
|---|
| 5788 | sage.: get_real_precision() |
|---|
| 5789 | 5 |
|---|
| 5790 | sage.: set_real_precision(10) |
|---|
| 5791 | sage.: pi() |
|---|
| 5792 | 3.1415926535897932384626433832795028841971693993751058209749445923078164062862 |
|---|
| 5793 | |
|---|
| 5794 | We restore precision to the default. |
|---|
| 5795 | sage.: set_real_precision(5) |
|---|
| 5796 | |
|---|
| 5797 | Note that pi is still saved to the largest precision to which it has been |
|---|
| 5798 | computed so far: |
|---|
| 5799 | sage.: pi() |
|---|
| 5800 | 3.1415926535897932384626433832795028841971693993751058209749445923078164062862 |
|---|
| 5801 | """ |
|---|
| 5802 | if prec <= 3: |
|---|
| 5803 | constpi(REAL_PREC) |
|---|
| 5804 | else: |
|---|
| 5805 | constpi(prec) |
|---|
| 5806 | |
|---|
| 5807 | cdef gen g |
|---|
| 5808 | g = gen() |
|---|
| 5809 | g.init(gpi,0) |
|---|
| 5810 | return g |
|---|
| 5811 | |
|---|
| 5812 | def factorial(long n): |
|---|
| 5813 | """ |
|---|
| 5814 | Return the factorial of the integer n as a PARI gen. |
|---|
| 5815 | """ |
|---|
| 5816 | _sig_on |
|---|
| 5817 | return new_gen(mpfact(n)) |
|---|
| 5818 | |
|---|
| 5819 | def vector(long n, entries=None): |
|---|
| 5820 | """ |
|---|
| 5821 | vector(long n, entries=None): |
|---|
| 5822 | Create and return the length n PARI vector with given list of entries. |
|---|
| 5823 | """ |
|---|
| 5824 | cdef int e |
|---|
| 5825 | e = setjmp(GP_DATA.env) |
|---|
| 5826 | if e: _error(e,"vector") |
|---|
| 5827 | cdef gen v |
|---|
| 5828 | _sig_on |
|---|
| 5829 | v = new_gen(zerovec(n)) |
|---|
| 5830 | if entries != None: |
|---|
| 5831 | if len(entries) != n: |
|---|
| 5832 | raise IndexError, "length of entries (=%s) must equal n (=%s)"%\ |
|---|
| 5833 | (len(entries), n) |
|---|
| 5834 | for i, x in enumerate(entries): |
|---|
| 5835 | v[i] = x |
|---|
| 5836 | return v |
|---|
| 5837 | |
|---|
| 5838 | def matrix(long m, long n, entries=None): |
|---|
| 5839 | """ |
|---|
| 5840 | matrix(long m, long n, entries=None): |
|---|
| 5841 | Create and return the m x n PARI matrix with given list of entries. |
|---|
| 5842 | """ |
|---|
| 5843 | cdef int e, i, j, k |
|---|
| 5844 | e = setjmp(GP_DATA.env) |
|---|
| 5845 | if e: _error(e,"matrix") |
|---|
| 5846 | cdef gen A |
|---|
| 5847 | _sig_on |
|---|
| 5848 | A = new_gen(forcecopy(zeromat(m,n))) |
|---|
| 5849 | if entries != None: |
|---|
| 5850 | if len(entries) != m*n: |
|---|
| 5851 | raise IndexError, "len of entries (=%s) must be %s*%s=%s"%(len(entries),m,n,m*n) |
|---|
| 5852 | k = 0 |
|---|
| 5853 | for i from 0 <= i < m: |
|---|
| 5854 | for j from 0 <= j < n: |
|---|
| 5855 | A[i,j] = entries[k] |
|---|
| 5856 | k = k + 1 |
|---|
| 5857 | return A |
|---|
| 5858 | |
|---|
| 5859 | def finitefield_init(p, long n, var=-1): |
|---|
| 5860 | """ |
|---|
| 5861 | |
|---|
| 5862 | finitefield_init(p, long n, var="x"): Return a polynomial f(x) so |
|---|
| 5863 | that the extension of F_p of degree n is k = F_p[x]/(f). Moreover, |
|---|
| 5864 | the element x (mod f) of k is a generator for the multiplicative |
|---|
| 5865 | group of k. |
|---|
| 5866 | |
|---|
| 5867 | INPUT: |
|---|
| 5868 | p -- int, a prime number |
|---|
| 5869 | n -- int, positive integer |
|---|
| 5870 | var -- str, default to "x", but could be any pari variable. |
|---|
| 5871 | OUTPUT: |
|---|
| 5872 | pari polynomial mod p -- defines field |
|---|
| 5873 | EXAMPLES: |
|---|
| 5874 | sage: finitefield_init(97,1) |
|---|
| 5875 | Mod(1, 97)*x + Mod(92, 97) |
|---|
| 5876 | |
|---|
| 5877 | The last entry in each of the following two lines is |
|---|
| 5878 | determined by a random algorithm. |
|---|
| 5879 | sage.: finitefield_init(7,2) |
|---|
| 5880 | Mod(1, 7)*x^2 + Mod(6, 7)*x + Mod(3, 7) |
|---|
| 5881 | sage.: finitefield_init(2,3) |
|---|
| 5882 | Mod(1, 2)*x^3 + Mod(1, 2)*x^2 + Mod(1, 2) |
|---|
| 5883 | """ |
|---|
| 5884 | cdef gen _p, _f2, s |
|---|
| 5885 | cdef int err |
|---|
| 5886 | cdef long x |
|---|
| 5887 | cdef GEN v, g |
|---|
| 5888 | _p = pari(int(p)) |
|---|
| 5889 | err = setjmp(GP_DATA.env) |
|---|
| 5890 | if err: _error(err,"error in finitefield_init") |
|---|
| 5891 | if n < 1: |
|---|
| 5892 | raise ArithmeticError, "Degree n (=%s) must be at least 1."%n |
|---|
| 5893 | if _p < 2 or not _p.isprime(): |
|---|
| 5894 | raise ArithmeticError, "Prime p (=%s) must be prime."%_p |
|---|
| 5895 | x = get_var(var) |
|---|
| 5896 | if n == 1: |
|---|
| 5897 | return new_gen(ffinit(_p.g, n, x)) - _p.znprimroot() |
|---|
| 5898 | |
|---|
| 5899 | _sig_on |
|---|
| 5900 | f = new_gen(ffinit(_p.g, n, x)) |
|---|
| 5901 | _f2 = f.lift() |
|---|
| 5902 | g = FpXQ_gener(_f2.g, _p.g) |
|---|
| 5903 | s = new_gen(g)*ONE.Mod(p) |
|---|
| 5904 | return s.Mod(f).charpoly(var) |
|---|
| 5905 | |
|---|
| 5906 | |
|---|
| 5907 | ################################################################################# |
|---|
| 5908 | ## Note: The function finitefield_init above makes use of FpXQ_gener, which |
|---|
| 5909 | ## is not defined in any PARI headers or available from gp. I learned about |
|---|
| 5910 | ## it from a post by Karim Belabas from 2002 at |
|---|
| 5911 | ## |
|---|
| 5912 | ## http://pari.math.u-bordeaux.fr/archives/pari-users-0205/msg00013.html |
|---|
| 5913 | ## |
|---|
| 5914 | ## "There is something built-in, very carefully hidden [ used by idealstar() ]. |
|---|
| 5915 | ## provided you have an up-to-date development version from the CVS server, and |
|---|
| 5916 | ## provided install() works on your system, you can use the following: |
|---|
| 5917 | ## |
|---|
| 5918 | ## install(FpXQ_gener,GG) |
|---|
| 5919 | ## |
|---|
| 5920 | ## ffinitprim(p,n) = |
|---|
| 5921 | ## { local(ffp); |
|---|
| 5922 | ## |
|---|
| 5923 | ## ffp = ffinit(p,n,x); |
|---|
| 5924 | ## Mod(FpXQ_gener(lift(ffp), p) * Mod(1,p), ffp) |
|---|
| 5925 | ## } |
|---|
| 5926 | ## |
|---|
| 5927 | ## (14:07) gp > ranffinitprim(101, 40); |
|---|
| 5928 | ## time = 1mn, 40,980 ms. |
|---|
| 5929 | ## (14:08) gp > ranffinitprim(2, 100) |
|---|
| 5930 | ## *** user interrupt after 13mn, 57,260 ms. |
|---|
| 5931 | ## |
|---|
| 5932 | ## |
|---|
| 5933 | ## (14:28) gp > ffinitprim(101, 40); |
|---|
| 5934 | ## time = 940 ms. |
|---|
| 5935 | ## (14:28) gp > ffinitprim(2, 100) |
|---|
| 5936 | ## time = 330 ms. |
|---|
| 5937 | ## |
|---|
| 5938 | ## Obviously, this is quite a useful routine, so I'll have to make it directly |
|---|
| 5939 | ## available to gp someday (with a decent name). |
|---|
| 5940 | ## |
|---|
| 5941 | ## Cheers, |
|---|
| 5942 | ## |
|---|
| 5943 | ## Karim." |
|---|
| 5944 | ################################################################################# |
|---|
| 5945 | |
|---|
| 5946 | |
|---|
| 5947 | def set_real_precision(long n): |
|---|
| 5948 | """ |
|---|
| 5949 | Set the default precision to n words (word = 4 bytes on |
|---|
| 5950 | a 32-bit machine). |
|---|
| 5951 | |
|---|
| 5952 | EXAMPLES: |
|---|
| 5953 | sage: get_real_precision() |
|---|
| 5954 | 5 |
|---|
| 5955 | sage: set_real_precision(10) |
|---|
| 5956 | sage: get_real_precision() |
|---|
| 5957 | 10 |
|---|
| 5958 | sage: set_real_precision(5) |
|---|
| 5959 | """ |
|---|
| 5960 | global REAL_PREC |
|---|
| 5961 | if n <= 2: n = 3 |
|---|
| 5962 | REAL_PREC = n |
|---|
| 5963 | |
|---|
| 5964 | def get_real_precision(): |
|---|
| 5965 | """ |
|---|
| 5966 | Return the default PARI real precision. This is the precision |
|---|
| 5967 | to which many objects are computed by default. |
|---|
| 5968 | |
|---|
| 5969 | EXAMPLES: |
|---|
| 5970 | sage: get_real_precision() |
|---|
| 5971 | 5 |
|---|
| 5972 | sage: set_real_precision(10) |
|---|
| 5973 | sage: get_real_precision() |
|---|
| 5974 | 10 |
|---|
| 5975 | sage: set_real_precision(5) |
|---|
| 5976 | """ |
|---|
| 5977 | global REAL_PREC |
|---|
| 5978 | return REAL_PREC |
|---|
| 5979 | |
|---|
| 5980 | def set_series_precision(long n): |
|---|
| 5981 | """ |
|---|
| 5982 | Set the default precision used when coercing objects into power series. |
|---|
| 5983 | |
|---|
| 5984 | EXAMPLES: |
|---|
| 5985 | sage: default = get_series_precision() |
|---|
| 5986 | sage: f = pari('1+x + x^2 + x^3') |
|---|
| 5987 | sage: set_series_precision(3) |
|---|
| 5988 | sage: f.exp() |
|---|
| 5989 | 2.718281828459045235360287471 + 2.718281828459045235360287471*x + 4.077422742688567853040431207*x^2 + 5.889610628327931343280622855*x^3 + O(x^4) |
|---|
| 5990 | sage: set_series_precision(10) |
|---|
| 5991 | sage: f.exp() |
|---|
| 5992 | 2.718281828459045235360287471 + 2.718281828459045235360287471*x + 4.077422742688567853040431207*x^2 + 5.889610628327931343280622855*x^3 + 5.549825399770550688860586921*x^4 + 5.912262976898423386908625250*x^5 + 5.780124276903886465745277943*x^6 + 4.893446632858912186592041315*x^7 + 4.273810514670244409851059119*x^8 + 3.489008512344414242252330620*x^9 + O(x^10) |
|---|
| 5993 | sage: set_series_precision(default) |
|---|
| 5994 | """ |
|---|
| 5995 | global precdl |
|---|
| 5996 | if n <= 2: n = 3 |
|---|
| 5997 | precdl = n |
|---|
| 5998 | |
|---|
| 5999 | def get_series_precision(): |
|---|
| 6000 | """ |
|---|
| 6001 | Get the default precision used when coercing objects into power series. |
|---|
| 6002 | |
|---|
| 6003 | EXAMPLES: |
|---|
| 6004 | sage: get_series_precision() |
|---|
| 6005 | 16 |
|---|
| 6006 | """ |
|---|
| 6007 | global precdl |
|---|
| 6008 | return int(precdl) |
|---|
| 6009 | |
|---|
| 6010 | def series_precision(new_val=None): |
|---|
| 6011 | """ |
|---|
| 6012 | Return the default series precision, which is the default precision |
|---|
| 6013 | to which series are computed. |
|---|
| 6014 | """ |
|---|
| 6015 | if new_val != None: |
|---|
| 6016 | set_series_precision(new_val) |
|---|
| 6017 | return get_series_precision() |
|---|
| 6018 | |
|---|
| 6019 | def init_primes(unsigned long M): |
|---|
| 6020 | """ |
|---|
| 6021 | Recompute the primes table including at least all primes up to M. |
|---|
| 6022 | |
|---|
| 6023 | EXAMPLES: |
|---|
| 6024 | sage: init_primes(200000) |
|---|
| 6025 | """ |
|---|
| 6026 | global diffptr, num_primes |
|---|
| 6027 | free(<void*> diffptr) |
|---|
| 6028 | num_primes = M |
|---|
| 6029 | diffptr = initprimes(M) |
|---|
| 6030 | |
|---|
| 6031 | def __read_script(char* s): |
|---|
| 6032 | cdef int err |
|---|
| 6033 | cdef pari_sp av |
|---|
| 6034 | err = setjmp(GP_DATA.env) |
|---|
| 6035 | if err: |
|---|
| 6036 | _error(err,"error in import_pari_script") |
|---|
| 6037 | _sig_on |
|---|
| 6038 | gp_read_str(s) |
|---|
| 6039 | #flisseq(s) |
|---|
| 6040 | _sig_off |
|---|
| 6041 | global top, avma |
|---|
| 6042 | top = avma |
|---|
| 6043 | |
|---|
| 6044 | # new gp_read_str, gp_read_file |
|---|
| 6045 | |
|---|
| 6046 | |
|---|
| 6047 | def read(filename): |
|---|
| 6048 | r""" |
|---|
| 6049 | Read a script from the named filename into the interpreter, where |
|---|
| 6050 | s is a string. The functions defined in the script are then |
|---|
| 6051 | available for use from SAGE/PARI. |
|---|
| 6052 | |
|---|
| 6053 | EXAMPLE: |
|---|
| 6054 | |
|---|
| 6055 | If foo.gp is a script that contains |
|---|
| 6056 | \begin{verbatim} |
|---|
| 6057 | {foo(n) = |
|---|
| 6058 | n^2 |
|---|
| 6059 | } |
|---|
| 6060 | \end{verbatim} |
|---|
| 6061 | and you type \code{read("foo.gp")}, then the command |
|---|
| 6062 | \code{pari("foo(12)")} will create the Python/PARI gen which |
|---|
| 6063 | is the integer 144. |
|---|
| 6064 | |
|---|
| 6065 | CONSTRAINTS: |
|---|
| 6066 | The PARI script must *not* contain the following function calls: |
|---|
| 6067 | |
|---|
| 6068 | print, default, ??? (please report any others that cause trouble) |
|---|
| 6069 | |
|---|
| 6070 | Also multiline functions should be written in the following form: |
|---|
| 6071 | \begin{verbatim} |
|---|
| 6072 | {foo(x) = |
|---|
| 6073 | code... |
|---|
| 6074 | } |
|---|
| 6075 | \end{verbatim} |
|---|
| 6076 | |
|---|
| 6077 | and *NOT* in the form |
|---|
| 6078 | \begin{verbatim} |
|---|
| 6079 | foo(x) = |
|---|
| 6080 | { |
|---|
| 6081 | code... |
|---|
| 6082 | } |
|---|
| 6083 | \end{verbatim} |
|---|
| 6084 | """ |
|---|
| 6085 | F = open(filename).read() |
|---|
| 6086 | __read_script(F) |
|---|
| 6087 | return |
|---|
| 6088 | while True: |
|---|
| 6089 | i = F.find("{") |
|---|
| 6090 | if i == -1: |
|---|
| 6091 | __read_script(F) |
|---|
| 6092 | break |
|---|
| 6093 | __read_script(F[:i]) |
|---|
| 6094 | j = F[i:].find("}") + i |
|---|
| 6095 | __read_script(F[i:j+1]) |
|---|
| 6096 | F = F[j+1:] |
|---|
| 6097 | |
|---|
| 6098 | |
|---|
| 6099 | def pari_real_precision(n): |
|---|
| 6100 | """ |
|---|
| 6101 | Sets the PARI default real precision, both for creation of |
|---|
| 6102 | new objects and for printing. |
|---|
| 6103 | |
|---|
| 6104 | TODO: For example, log(2) is computed differently, depending on the |
|---|
| 6105 | pari_real_precision. |
|---|
| 6106 | """ |
|---|
| 6107 | n = int(n) |
|---|
| 6108 | s = str(n) |
|---|
| 6109 | err = setjmp(GP_DATA.env) |
|---|
| 6110 | if err: |
|---|
| 6111 | raise ValueError |
|---|
| 6112 | global REAL_PREC, prec |
|---|
| 6113 | # REAL_PREC = n |
|---|
| 6114 | sd_realprecision(s, 2) |
|---|
| 6115 | REAL_PREC = prec |
|---|
| 6116 | # TODO : series precision should match precdl also. |
|---|
| 6117 | |
|---|
| 6118 | # Some useful globals (initialized in init()) |
|---|
| 6119 | cdef gen ZERO, ONE, TWO |
|---|
| 6120 | |
|---|
| 6121 | |
|---|
| 6122 | def allocate_mem(): |
|---|
| 6123 | print "Doubling the PARI stack." |
|---|
| 6124 | init_stack(0) |
|---|
| 6125 | |
|---|
| 6126 | # Initialize the PARI system. There's a bit of a hack here. I've |
|---|
| 6127 | # found by experiment that the global PARI C-library variable precdl |
|---|
| 6128 | # (which is the default series precision) is 0 if and only if the PARI |
|---|
| 6129 | # system has not been initialized. A PARI expert could probably |
|---|
| 6130 | # replace this test by something more sensible. |
|---|
| 6131 | |
|---|
| 6132 | if bot == 0: |
|---|
| 6133 | _init() |
|---|