cypari2-1.1.4/0000755000201600020160000000000013236012501014501 5ustar jdemeyerjdemeyer00000000000000cypari2-1.1.4/Makefile0000644000201600020160000000056013147517060016155 0ustar jdemeyerjdemeyer00000000000000# Optional Makefile for easier development VERSION = $(shell cat VERSION) PYTHON = python PIP = $(PYTHON) -m pip -v build: $(PYTHON) setup.py build install: $(PIP) install --no-index --ignore-installed . check: $(PYTHON) tests/rundoctest.py dist: chmod go+rX-w -R . umask 0022 && $(PYTHON) setup.py sdist --formats=gztar .PHONY: build install check dist cypari2-1.1.4/tests/0000755000201600020160000000000013236012501015643 5ustar jdemeyerjdemeyer00000000000000cypari2-1.1.4/tests/rundoctest.py0000755000201600020160000000234513227404342020426 0ustar jdemeyerjdemeyer00000000000000#!/usr/bin/env python import os import sys # Autogen tests must be run in the root dir, and with the proper module path path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)) os.chdir(path) sys.path.append(path) import autogen import cypari2 import doctest # The doctests assume utf-8 encoding cypari2.string_utils.encoding = "utf-8" # For doctests, we want exceptions to look the same, # regardless of the Python version. Python 3 will put the # module name in the traceback, which we avoid by faking # the module to be __main__. cypari2.handle_error.PariError.__module__ = "__main__" failed = 0 attempted = 0 for mod in [cypari2.closure, cypari2.convert, cypari2.gen, cypari2.handle_error, cypari2.pari_instance, cypari2.stack, cypari2.string_utils, autogen.doc, autogen.generator, autogen.parser, autogen.paths]: print("="*80) print("Testing {}".format(mod.__name__)) test = doctest.testmod(mod, optionflags=doctest.ELLIPSIS|doctest.REPORT_NDIFF) failed += test.failed attempted += test.attempted print("="*80) print("Summary result for cypari2:") print(" attempted = {}".format(attempted)) print(" failed = {}".format(failed)) sys.exit(failed) cypari2-1.1.4/VERSION0000644000201600020160000000000613236012310015543 0ustar jdemeyerjdemeyer000000000000001.1.4 cypari2-1.1.4/LICENSE0000644000201600020160000004325413136354561015534 0ustar jdemeyerjdemeyer00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. cypari2-1.1.4/PKG-INFO0000644000201600020160000000057113236012501015601 0ustar jdemeyerjdemeyer00000000000000Metadata-Version: 1.0 Name: cypari2 Version: 1.1.4 Summary: An interface to the number theory library libpari Home-page: https://github.com/defeo/cypari2 Author: Many people Author-email: sage-devel@googlegroups.com License: GNU General Public License, version 2 or later Description-Content-Type: UNKNOWN Description: UNKNOWN Keywords: PARI/GP number theory Platform: UNKNOWN cypari2-1.1.4/cypari2/0000755000201600020160000000000013236012500016051 5ustar jdemeyerjdemeyer00000000000000cypari2-1.1.4/cypari2/handle_error.pxd0000644000201600020160000000022213136354561021245 0ustar jdemeyerjdemeyer00000000000000from .types cimport GEN cdef void _pari_init_error_handling() cdef int _pari_err_handle(GEN E) except 0 cdef void _pari_err_recover(long errnum) cypari2-1.1.4/cypari2/string_utils.pxd0000644000201600020160000000114613136354561021335 0ustar jdemeyerjdemeyer00000000000000cdef extern from *: int PY_MAJOR_VERSION cpdef bytes to_bytes(s) cpdef unicode to_unicode(s) cpdef inline to_string(s): r""" Converts a bytes and unicode ``s`` to a string. String means bytes in Python2 and unicode in Python3 Examples: >>> from cypari2.string_utils import to_string >>> s1 = to_string(b'hello') >>> s2 = to_string('hello') >>> s3 = to_string(u'hello') >>> type(s1) == type(s2) == type(s3) == str True >>> s1 == s2 == s3 == 'hello' True """ if PY_MAJOR_VERSION <= 2: return to_bytes(s) else: return to_unicode(s) cypari2-1.1.4/cypari2/pari_instance.pyx0000644000201600020160000012670513236012275021456 0ustar jdemeyerjdemeyer00000000000000# -*- coding: utf-8 -*- r""" Interface to the PARI library ***************************** AUTHORS: - William Stein (2006-03-01): updated to work with PARI 2.2.12-beta - William Stein (2006-03-06): added newtonpoly - Justin Walker: contributed some of the function definitions - Gonzalo Tornaria: improvements to conversions; much better error handling. - Robert Bradshaw, Jeroen Demeyer, William Stein (2010-08-15): Upgrade to PARI 2.4.3 (:trac:`9343`) - Jeroen Demeyer (2011-11-12): rewrite various conversion routines (:trac:`11611`, :trac:`11854`, :trac:`11952`) - Peter Bruin (2013-11-17): split off this file from gen.pyx (:trac:`15185`) - Jeroen Demeyer (2014-02-09): upgrade to PARI 2.7 (:trac:`15767`) - Jeroen Demeyer (2014-09-19): upgrade to PARI 2.8 (:trac:`16997`) - Jeroen Demeyer (2015-03-17): automatically generate methods from ``pari.desc`` (:trac:`17631` and :trac:`17860`) - Luca De Feo (2016-09-06): Separate Sage-specific components from generic C-interface in ``Pari`` (:trac:`20241`) Examples: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari('5! + 10/x') (120*x + 10)/x >>> pari('intnum(x=0,13,sin(x)+sin(x^2) + x)') 85.6215190762676 >>> f = pari('x^3 - 1') >>> v = f.factor(); v [x - 1, 1; x^2 + x + 1, 1] >>> v[0] # indexing is 0-based unlike in GP. [x - 1, x^2 + x + 1]~ >>> v[1] [1, 1]~ For most functions, you can call the function as method of ``pari`` or you can first create a :class:`Gen` object and then call the function as method of that. In other words, the following two commands do the same: >>> pari('x^3 - 1').factor() [x - 1, 1; x^2 + x + 1, 1] >>> pari.factor('x^3 - 1') [x - 1, 1; x^2 + x + 1, 1] Arithmetic operations cause all arguments to be converted to PARI: >>> type(pari(1) + 1) <... 'cypari2.gen.Gen'> >>> type(1 + pari(1)) <... 'cypari2.gen.Gen'> Guide to real precision in the PARI interface ============================================= In the PARI interface, "real precision" refers to the precision of real numbers, so it is the floating-point precision. This is a non-trivial issue, since there are various interfaces for different things. Internal representation of floating-point numbers in PARI --------------------------------------------------------- Real numbers in PARI have a precision associated to them, which is always a multiple of the CPU wordsize. So, it is a multiple of 32 of 64 bits. When converting a ``float`` from Python to PARI, the ``float`` has 53 bits of precision which is rounded up to 64 bits in PARI: >>> x = 1.0 >>> pari(x) 1.00000000000000 >>> pari(x).bitprecision() 64 It is possible to change the precision of a PARI object with the :meth:`Gen.bitprecision` method: >>> p = pari(1.0) >>> p.bitprecision() 64 >>> p = p.bitprecision(100) >>> p.bitprecision() # Rounded up to a multiple of the wordsize 128 Beware that these extra bits are just bogus. For example, this will not give a more precision approximation of ``math.pi``: >>> import math >>> p = pari(math.pi) >>> pari("Pi") - p 1.225148... E-16 >>> p = p.bitprecision(1000) >>> pari("Pi") - p 1.225148... E-16 Another way to create numbers with many bits is to use a string with many digits: >>> p = pari("3.1415926535897932384626433832795028842") >>> p.bitprecision() 128 .. _pari_output_precision: Output precision for printing ----------------------------- Even though PARI reals have a precision, not all significant bits are printed by default. The maximum number of digits when printing a PARI real can be set using the methods :meth:`Pari.set_real_precision_bits` or :meth:`Pari.set_real_precision`. Note that this will also change the input precision for strings, see :ref:`pari_input_precision`. We create a very precise approximation of pi and see how it is printed in PARI: >>> pi = pari.pi(precision=1024) The default precision is 15 digits: >>> pi 3.14159265358979 With a different precision, we see more digits. Note that this does not affect the object ``pi`` at all, it only affects how it is printed: >>> _ = pari.set_real_precision(50) >>> pi 3.1415926535897932384626433832795028841971693993751 Back to the default: >>> _ = pari.set_real_precision(15) >>> pi 3.14159265358979 .. _pari_input_precision: Input precision for function calls ---------------------------------- When we talk about precision for PARI functions, we need to distinguish three kinds of calls: 1. Using the string interface, for example ``pari("sin(1)")``. 2. Using the library interface with exact inputs, for example ``pari(1).sin()``. 3. Using the library interface with inexact inputs, for example ``pari(1.0).sin()``. In the first case, the relevant precision is the one set by the methods :meth:`Pari.set_real_precision_bits` or :meth:`Pari.set_real_precision`: >>> pari.set_real_precision_bits(150) >>> pari("sin(1)") 0.841470984807896506652502321630298999622563061 >>> pari.set_real_precision_bits(53) >>> pari("sin(1)") 0.841470984807897 In the second case, the precision can be given as the argument ``precision`` in the function call, with a default of 53 bits. The real precision set by :meth:`Pari.set_real_precision_bits` or :meth:`Pari.set_real_precision` does not affect the call (but it still affects printing). As explained before, the precision increases to a multiple of the wordsize. : >>> a = pari(1).sin(precision=180); a 0.841470984807897 >>> a.bitprecision() 192 >>> b = pari(1).sin(precision=40); b 0.841470984807897 >>> b.bitprecision() 64 >>> c = pari(1).sin(); c 0.841470984807897 >>> c.bitprecision() 64 >>> pari.set_real_precision_bits(90) >>> print(a); print(b); print(c) 0.841470984807896506652502322 0.8414709848078965067 0.8414709848078965067 In the third case, the precision is determined only by the inexact inputs and the ``precision`` argument is ignored: >>> pari(1.0).sin(precision=180).bitprecision() 64 >>> pari(1.0).sin(precision=40).bitprecision() 64 >>> pari("1.0000000000000000000000000000000000000").sin().bitprecision() 128 Tests: Check that the documentation is generated correctly: >>> from inspect import getdoc >>> getdoc(pari.Pi) 'The constant :math:`\\pi` ...' Check that output from PARI's print command is actually seen by Python (:trac:`9636`): >>> pari('print("test")') test Verify that ``nfroots()`` (which has an unusual signature with a non-default argument following a default argument) works: >>> pari.nfroots(x='x^4 - 1') [-1, 1] >>> pari.nfroots(pari.nfinit('t^2 + 1'), "x^4 - 1") [-1, 1, Mod(-t, t^2 + 1), Mod(t, t^2 + 1)] """ #***************************************************************************** # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** from __future__ import absolute_import, division import sys from libc.stdio cimport * cimport cython from cysignals.signals cimport sig_check, sig_on, sig_off from .string_utils cimport to_string, to_bytes from .paridecl cimport * from .paripriv cimport * from .gen cimport Gen, objtogen from .stack cimport new_gen, new_gen_noclear, clear_stack from .convert cimport new_gen_from_double from .handle_error cimport _pari_init_error_handling from .closure cimport _pari_init_closure # Default precision (in PARI words) for the PARI library interface, # when no explicit precision is given and the inputs are exact. cdef long prec = prec_bits_to_words(53) ################################################################# # conversions between various real precision models ################################################################# def prec_bits_to_dec(long prec_in_bits): r""" Convert from precision expressed in bits to precision expressed in decimal. Examples: >>> from cypari2.pari_instance import prec_bits_to_dec >>> prec_bits_to_dec(53) 15 >>> [(32*n, prec_bits_to_dec(32*n)) for n in range(1, 9)] [(32, 9), (64, 19), (96, 28), (128, 38), (160, 48), (192, 57), (224, 67), (256, 77)] """ return nbits2ndec(prec_in_bits) def prec_dec_to_bits(long prec_in_dec): r""" Convert from precision expressed in decimal to precision expressed in bits. Examples: >>> from cypari2.pari_instance import prec_dec_to_bits >>> prec_dec_to_bits(15) 50 >>> [(n, prec_dec_to_bits(n)) for n in range(10, 100, 10)] [(10, 34), (20, 67), (30, 100), (40, 133), (50, 167), (60, 200), (70, 233), (80, 266), (90, 299)] """ cdef double log_10 = 3.32192809488736 return int(prec_in_dec*log_10 + 1.0) # Add one to round up cpdef long prec_bits_to_words(unsigned long prec_in_bits): r""" Convert from precision expressed in bits to pari real precision expressed in words. Note: this rounds up to the nearest word, adjusts for the two codewords of a pari real, and is architecture-dependent. Examples: >>> from cypari2.pari_instance import prec_bits_to_words >>> import sys >>> bitness = '64' if sys.maxsize > (1 << 32) else '32' >>> prec_bits_to_words(70) == (5 if bitness == '32' else 4) True >>> ans32 = [(32, 3), (64, 4), (96, 5), (128, 6), (160, 7), (192, 8), (224, 9), (256, 10)] >>> ans64 = [(32, 3), (64, 3), (96, 4), (128, 4), (160, 5), (192, 5), (224, 6), (256, 6)] >>> [(32*n, prec_bits_to_words(32*n)) for n in range(1, 9)] == (ans32 if bitness == '32' else ans64) True """ if not prec_in_bits: return prec cdef unsigned long wordsize = BITS_IN_LONG # This equals ceil(prec_in_bits/wordsize) + 2 return (prec_in_bits - 1)//wordsize + 3 cpdef long prec_words_to_bits(long prec_in_words): r""" Convert from pari real precision expressed in words to precision expressed in bits. Note: this adjusts for the two codewords of a pari real, and is architecture-dependent. Examples: >>> from cypari2.pari_instance import prec_words_to_bits >>> import sys >>> bitness = '64' if sys.maxsize > (1 << 32) else '32' >>> prec_words_to_bits(10) == (256 if bitness == '32' else 512) True >>> ans32 = [(3, 32), (4, 64), (5, 96), (6, 128), (7, 160), (8, 192), (9, 224)] >>> ans64 = [(3, 64), (4, 128), (5, 192), (6, 256), (7, 320), (8, 384), (9, 448)] # 64-bit >>> [(n, prec_words_to_bits(n)) for n in range(3, 10)] == (ans32 if bitness == '32' else ans64) True """ # see user's guide to the pari library, page 10 return (prec_in_words - 2) * BITS_IN_LONG cpdef long default_bitprec(): r""" Return the default precision in bits. Examples: >>> from cypari2.pari_instance import default_bitprec >>> default_bitprec() 64 """ return (prec - 2) * BITS_IN_LONG def prec_dec_to_words(long prec_in_dec): r""" Convert from precision expressed in decimal to precision expressed in words. Note: this rounds up to the nearest word, adjusts for the two codewords of a pari real, and is architecture-dependent. Examples: >>> from cypari2.pari_instance import prec_dec_to_words >>> import sys >>> bitness = '64' if sys.maxsize > (1 << 32) else '32' >>> prec_dec_to_words(38) == (6 if bitness == '32' else 4) True >>> ans32 = [(10, 4), (20, 5), (30, 6), (40, 7), (50, 8), (60, 9), (70, 10), (80, 11)] >>> ans64 = [(10, 3), (20, 4), (30, 4), (40, 5), (50, 5), (60, 6), (70, 6), (80, 7)] # 64-bit >>> [(n, prec_dec_to_words(n)) for n in range(10, 90, 10)] == (ans32 if bitness == '32' else ans64) True """ return prec_bits_to_words(prec_dec_to_bits(prec_in_dec)) def prec_words_to_dec(long prec_in_words): r""" Convert from precision expressed in words to precision expressed in decimal. Note: this adjusts for the two codewords of a pari real, and is architecture-dependent. Examples: >>> from cypari2.pari_instance import prec_words_to_dec >>> import sys >>> bitness = '64' if sys.maxsize > (1 << 32) else '32' >>> prec_words_to_dec(5) == (28 if bitness == '32' else 57) True >>> ans32 = [(3, 9), (4, 19), (5, 28), (6, 38), (7, 48), (8, 57), (9, 67)] >>> ans64 = [(3, 19), (4, 38), (5, 57), (6, 77), (7, 96), (8, 115), (9, 134)] >>> [(n, prec_words_to_dec(n)) for n in range(3, 10)] == (ans32 if bitness == '32' else ans64) True """ return prec_bits_to_dec(prec_words_to_bits(prec_in_words)) # Callbacks from PARI to print stuff using sys.stdout.write() instead # of C library functions like puts(). cdef PariOUT python_pariOut cdef void python_putchar(char c): cdef char s[2] s[0] = c s[1] = 0 try: # avoid string conversion if possible sys.stdout.buffer.write(s) except AttributeError: sys.stdout.write(to_string(s)) # Let PARI think the last character was a newline, # so it doesn't print one when an error occurs. pari_set_last_newline(1) cdef void python_puts(const char* s): try: # avoid string conversion if possible sys.stdout.buffer.write(s) except AttributeError: sys.stdout.write(to_string(s)) pari_set_last_newline(1) cdef void python_flush(): sys.stdout.flush() include 'auto_instance.pxi' cdef class Pari(Pari_auto): def __cinit__(self): r""" (Re)-initialize the PARI library. Tests: >>> from cypari2.pari_instance import Pari >>> Pari.__new__(Pari) Interface to the PARI C library >>> pari = Pari() >>> pari("print('hello')") """ # PARI is already initialized, nothing to do... if avma: return # Take 1MB as minimal stack. Use maxprime=0, which PARI will # internally increase to some small value like 65537. pari_init_opts(1000000, 0, INIT_DFTm) # Disable PARI's stack overflow checking which is incompatible # with multi-threading. pari_stackcheck_init(NULL) _pari_init_error_handling() _pari_init_closure() # Set printing functions global pariOut, pariErr pariOut = &python_pariOut pariOut.putch = python_putchar pariOut.puts = python_puts pariOut.flush = python_flush # Use 53 bits as default precision self.set_real_precision_bits(53) # Disable pretty-printing GP_DATA.fmt.prettyp = 0 # This causes PARI/GP to use output independent of the terminal # (which is what we want for the PARI library interface). GP_DATA.flags = gpd_TEST # Ensure that Galois groups are represented in a sane way, # see the polgalois section of the PARI users manual. global new_galois_format new_galois_format = 1 # By default, factor() should prove primality of returned # factors. This not only influences the factor() function, but # also many functions indirectly using factoring. global factor_proven factor_proven = 1 def __init__(self, size_t size=8000000, size_t sizemax=0, unsigned long maxprime=500000): """ (Re)-Initialize the PARI system. INPUT: - ``size`` -- (default: 8000000) the number of bytes for the initial PARI stack (see notes below) - ``sizemax`` -- the maximal number of bytes for the dynamically increasing PARI stack. The default ``0`` means to use the same value as ``size`` (see notes below) - ``maxprime`` -- (default: 500000) limit on the primes in the precomputed prime number table which is used for sieving algorithms When the PARI system is already initialized, the PARI stack is only grown if ``size`` is greater than the current stack, and the table of primes is only computed is ``maxprime`` is larger than the current bound. Examples: >>> from cypari2.pari_instance import Pari >>> pari = Pari() >>> pari2 = Pari(10**7) >>> pari2 Interface to the PARI C library >>> pari2 is pari False >>> pari2.PARI_ZERO == pari.PARI_ZERO True >>> pari2 = Pari(10**6) >>> pari.stacksize(), pari2.stacksize() (10000000, 10000000) For more information about how precision works in the PARI interface, see :mod:`cypari2.pari_instance`. .. NOTE:: PARI has a "real" stack size (``size``) and a "virtual" stack size (``sizemax``). The idea is that the real stack will be used if possible, but that the stack might be increased up to ``sizemax`` bytes. Therefore, it is not a problem to set ``sizemax`` to a large value. On the other hand, it also makes no sense to set this to a value larger than what your system can handle. .. NOTE:: In CyPari2, the PARI stack is different than in GP or the PARI C library. In CyPari2, instead of the PARI stack holding the results of all computations, it *only* holds the results of an individual computation. Each time a new Python/PARI object is computed, it it copied to its own space in the Python heap, and the memory it occupied on the PARI stack is freed. Thus it is not necessary to make the stack very large. This design obviously involves some performance penalties over the way PARI works, but it scales much better and is far more robust for large projects. """ # Increase (but don't decrease) size and sizemax to the # requested value size = max(size, pari_mainstack.rsize) sizemax = max(max(size, pari_mainstack.vsize), sizemax) paristack_setsize(size, sizemax) # Increase the table of primes if needed self.init_primes(maxprime) # Initialize some constants sig_on() self.PARI_ZERO = new_gen_noclear(gen_0) self.PARI_ONE = new_gen_noclear(gen_1) self.PARI_TWO = new_gen_noclear(gen_2) sig_off() IF HAVE_PLOT_SVG: # If we are running under IPython, setup for displaying SVG plots. if "IPython" in sys.modules: pari_set_plot_engine(get_plot_ipython) def _close(self): """ Deallocate the PARI library. If you want to reallocate the PARI library again, construct a new instance of :class:`Pari`. Examples: >>> from cypari2.pari_instance import Pari >>> pari = Pari() >>> pari2 = Pari(10**7) >>> pari2._close() >>> pari2 = Pari(10**6) >>> pari.stacksize() 1000000 .. WARNING:: Calling this method is dangerous since any further use of PARI (by this :class:`Pari` or another :class:`Pari` or even another non-Python library) will result in a segmentation fault after calling ``_close()``. For this reason, the :class:`Pari` class never deallocates PARI memory automatically. """ global avma if avma: pari_close() avma = 0 def debugstack(self): r""" Print the internal PARI variables ``top`` (top of stack), ``avma`` (available memory address, think of this as the stack pointer), ``bot`` (bottom of stack). """ # We deliberately use low-level functions to minimize the # chances that something goes wrong here (for example, if we # are out of memory). printf("top = %p\navma = %p\nbot = %p\nsize = %lu\n", pari_mainstack.top, avma, pari_mainstack.bot, pari_mainstack.rsize) fflush(stdout) def __repr__(self): return "Interface to the PARI C library" def __hash__(self): return 907629390 # hash('pari') def set_debug_level(self, level): """ Set the debug PARI C library variable. """ self.default('debug', int(level)) def get_debug_level(self): """ Set the debug PARI C library variable. """ return int(self.default('debug')) def set_real_precision_bits(self, n): """ Sets the PARI default real precision in bits. This is used both for creation of new objects from strings and for printing. It determines the number of digits in which real numbers numbers are printed. It also determines the precision of objects created by parsing strings (e.g. pari('1.2')), which is *not* the normal way of creating new PARI objects using cypari. It has *no* effect on the precision of computations within the PARI library. .. seealso:: :meth:`set_real_precision` to set the precision in decimal digits. Examples: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari.set_real_precision_bits(200) >>> pari('1.2') 1.20000000000000000000000000000000000000000000000000000000000 >>> pari.set_real_precision_bits(53) """ cdef bytes strn = to_bytes(n) sig_on() sd_realbitprecision(strn, d_SILENT) sig_off() def get_real_precision_bits(self): """ Return the current PARI default real precision in bits. This is used both for creation of new objects from strings and for printing. It determines the number of digits in which real numbers numbers are printed. It also determines the precision of objects created by parsing strings (e.g. pari('1.2')), which is *not* the normal way of creating new PARI objects using cypari. It has *no* effect on the precision of computations within the PARI library. .. seealso:: :meth:`get_real_precision` to get the precision in decimal digits. Examples: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari.get_real_precision_bits() 53 """ cdef long r sig_on() r = itos(sd_realbitprecision(NULL, d_RETURN)) sig_off() return r def set_real_precision(self, long n): """ Sets the PARI default real precision in decimal digits. This is used both for creation of new objects from strings and for printing. It is the number of digits *IN DECIMAL* in which real numbers are printed. It also determines the precision of objects created by parsing strings (e.g. pari('1.2')), which is *not* the normal way of creating new PARI objects in CyPari2. It has *no* effect on the precision of computations within the pari library. Returns the previous PARI real precision. .. seealso:: :meth:`set_real_precision_bits` to set the precision in bits. Examples: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari.set_real_precision(60) 15 >>> pari('1.2') 1.20000000000000000000000000000000000000000000000000000000000 >>> pari.set_real_precision(15) 60 """ old = self.get_real_precision() self.set_real_precision_bits(prec_dec_to_bits(n)) return old def get_real_precision(self): """ Returns the current PARI default real precision. This is used both for creation of new objects from strings and for printing. It is the number of digits *IN DECIMAL* in which real numbers are printed. It also determines the precision of objects created by parsing strings (e.g. pari('1.2')), which is *not* the normal way of creating new PARI objects in CyPari2. It has *no* effect on the precision of computations within the pari library. .. seealso:: :meth:`get_real_precision_bits` to get the precision in bits. Examples: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari.get_real_precision() 15 """ cdef long r sig_on() r = itos(sd_realprecision(NULL, d_RETURN)) sig_off() return r def set_series_precision(self, long n): global precdl precdl = n def get_series_precision(self): return precdl def double_to_gen(self, x): """ Create a new Gen with the value of the double x, using Pari's dbltor. Examples: >>> import cypari2 >>> pari = cypari2.Pari() >>> import warnings >>> import math >>> with warnings.catch_warnings(record=True) as w: ... warnings.simplefilter('always') ... pari.double_to_gen(1) ... pari.double_to_gen(1e30) ... pari.double_to_gen(0) ... pari.double_to_gen(-math.sqrt(2)) ... assert len(w) == 4 ... assert all(issubclass(u.category, DeprecationWarning) for u in w) 1.00000000000000 1.00000000000000 E30 0.E-15 -1.41421356237310 """ # Deprecated in https://trac.sagemath.org/ticket/20241 from warnings import warn warn("pari.double_to_gen(x) is deprecated, use pari(x) instead", DeprecationWarning) return new_gen_from_double(x) def complex(self, re, im): """ Create a new complex number, initialized from re and im. """ cdef Gen t0 = self(re) cdef Gen t1 = self(im) sig_on() return new_gen(mkcomplex(t0.g, t1.g)) def __call__(self, s): """ Create the PARI object obtained by evaluating s using PARI. Examples: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari(0) 0 >>> pari([2,3,5]) [2, 3, 5] >>> a = pari(1); a, a.type() (1, 't_INT') >>> a = pari('1/2'); a, a.type() (1/2, 't_FRAC') >>> s = pari(u'"éàèç"') >>> s.type() 't_STR' See :func:`pari` for more examples. """ return objtogen(s) cpdef Gen zero(self): """ Examples: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari.zero() 0 """ return self.PARI_ZERO cpdef Gen one(self): """ Examples: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari.one() 1 """ return self.PARI_ONE def new_with_bits_prec(self, s, long precision): r""" pari.new_with_bits_prec(self, s, precision) creates s as a PARI Gen with (at most) precision *bits* of precision. """ cdef unsigned long old_prec old_prec = GP_DATA.fmt.sigd precision = prec_bits_to_dec(precision) if not precision: precision = old_prec self.set_real_precision(precision) x = self(s) self.set_real_precision(old_prec) return x ############################################################ # Initialization ############################################################ def stacksize(self): r""" Return the current size of the PARI stack, which is `10^6` by default. However, the stack size is automatically doubled when needed up to some maximum. .. SEEALSO:: - :meth:`stacksizemax` to get the maximum stack size - :meth:`allocatemem` to change the current or maximum stack size Examples: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari.stacksize() 8000000 >>> pari.allocatemem(2**18, silent=True) >>> pari.stacksize() 262144 """ return pari_mainstack.size def stacksizemax(self): r""" Return the maximum size of the PARI stack, which is determined at startup in terms of available memory. Usually, the PARI stack size is (much) smaller than this maximum but the stack will be increased up to this maximum if needed. .. SEEALSO:: - :meth:`stacksize` to get the current stack size - :meth:`allocatemem` to change the current or maximum stack size Examples: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari.allocatemem(2**18, 2**26, silent=True) >>> pari.stacksizemax() 67108864 """ return pari_mainstack.vsize def allocatemem(self, size_t s=0, size_t sizemax=0, *, silent=False): r""" Change the PARI stack space to the given size ``s`` (or double the current size if ``s`` is `0`) and change the maximum stack size to ``sizemax``. PARI tries to use only its current stack (the size which is set by ``s``), but it will increase its stack if needed up to the maximum size which is set by ``sizemax``. The PARI stack is never automatically shrunk. You can use the command ``pari.allocatemem(10^6)`` to reset the size to `10^6`, which is the default size at startup. Note that the results of computations using cypari are copied to the Python heap, so they take up no space in the PARI stack. The PARI stack is cleared after every computation. It does no real harm to set this to a small value as the PARI stack will be automatically doubled when we run out of memory. INPUT: - ``s`` - an integer (default: 0). A non-zero argument is the size in bytes of the new PARI stack. If `s` is zero, double the current stack size. - ``sizemax`` - an integer (default: 0). A non-zero argument is the maximum size in bytes of the PARI stack. If ``sizemax`` is 0, the maximum of the current maximum and ``s`` is taken. Examples: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari.allocatemem(10**7) PARI stack size set to 10000000 bytes, maximum size set to 100... >>> pari.allocatemem() # Double the current size PARI stack size set to 20000000 bytes, maximum size set to 200... >>> pari.stacksize() 20000000 >>> pari.allocatemem(10**6) PARI stack size set to 1000000 bytes, maximum size set to 200... The following computation will automatically increase the PARI stack size: >>> a = pari('2^100000000') ``a`` is now a Python variable on the Python heap and does not take up any space on the PARI stack. The PARI stack is still large because of the computation of ``a``: >>> pari.stacksize() > 10**6 True Setting a small maximum size makes this fail: >>> pari.allocatemem(10**6, 2**22) PARI stack size set to 1000000 bytes, maximum size set to 4194304 >>> a = pari('2^100000000') Traceback (most recent call last): ... PariError: _^s: the PARI stack overflows (current size: 1000000; maximum size: 4194304) You can use pari.allocatemem() to change the stack size and try again Tests: Do the same without using the string interface and starting from a very small stack size: >>> pari.allocatemem(1, 2**26) PARI stack size set to 1024 bytes, maximum size set to 67108864 >>> a = pari(2)**100000000 >>> pari.stacksize() > 10**6 True We do not allow ``sizemax`` less than ``s``: >>> pari.allocatemem(10**7, 10**6) Traceback (most recent call last): ... ValueError: the maximum size (10000000) should be at least the stack size (1000000) """ if s == 0: s = pari_mainstack.size * 2 if s < pari_mainstack.size: raise OverflowError("cannot double stack size") elif s < 1024: s = 1024 # arbitrary minimum size if sizemax == 0: # For the default sizemax, use the maximum of current # sizemax and the given size s. if pari_mainstack.vsize > s: sizemax = pari_mainstack.vsize else: sizemax = s elif sizemax < s: raise ValueError("the maximum size ({}) should be at least the stack size ({})".format(s, sizemax)) sig_on() paristack_setsize(s, sizemax) sig_off() if not silent: print("PARI stack size set to {} bytes, maximum size set to {}". format(self.stacksize(), self.stacksizemax())) @staticmethod def pari_version(): """ Return a string describing the version of PARI/GP. >>> from cypari2 import Pari >>> Pari.pari_version() 'GP/PARI CALCULATOR Version ...' """ return to_string(PARIVERSION) def init_primes(self, unsigned long M): """ Recompute the primes table including at least all primes up to M (but possibly more). Examples: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari.init_primes(200000) We make sure that ticket :trac:`11741` has been fixed:: >>> pari.init_primes(2**30) Traceback (most recent call last): ... ValueError: Cannot compute primes beyond 436273290 """ # Hardcoded bound in PARI sources if M > 436273290: raise ValueError("Cannot compute primes beyond 436273290") if M <= maxprime(): return sig_on() initprimetable(M) sig_off() def primes(self, n=None, end=None): """ Return a pari vector containing the first `n` primes, the primes in the interval `[n, end]`, or the primes up to `end`. INPUT: Either - ``n`` -- integer or - ``n`` -- list or tuple `[a, b]` defining an interval of primes or - ``n, end`` -- start and end point of an interval of primes or - ``end`` -- end point for the list of primes OUTPUT: a PARI list of prime numbers Examples: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari.primes(3) [2, 3, 5] >>> pari.primes(10) [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] >>> pari.primes(20) [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71] >>> len(pari.primes(1000)) 1000 >>> pari.primes(11,29) [11, 13, 17, 19, 23, 29] >>> pari.primes((11,29)) [11, 13, 17, 19, 23, 29] >>> pari.primes(end=29) [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] >>> pari.primes(10**30, 10**30 + 100) [1000000000000000000000000000057, 1000000000000000000000000000099] Tests: >>> pari.primes(0) [] >>> pari.primes(-1) [] >>> pari.primes(end=1) [] >>> pari.primes(end=-1) [] >>> pari.primes(3,2) [] """ cdef Gen t0, t1 if end is None: t0 = objtogen(n) sig_on() return new_gen(primes0(t0.g)) elif n is None: t0 = self.PARI_TWO # First prime else: t0 = objtogen(n) t1 = objtogen(end) sig_on() return new_gen(primes_interval(t0.g, t1.g)) euler = Pari_auto.Euler pi = Pari_auto.Pi def polchebyshev(self, long n, v=None): """ Chebyshev polynomial of the first kind of degree `n`, in the variable `v`. Examples: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari.polchebyshev(7) 64*x^7 - 112*x^5 + 56*x^3 - 7*x >>> pari.polchebyshev(7, 'z') 64*z^7 - 112*z^5 + 56*z^3 - 7*z >>> pari.polchebyshev(0) 1 """ sig_on() return new_gen(polchebyshev1(n, get_var(v))) def factorial_int(self, long n): """ Return the factorial of the integer n as a PARI gen. Give result as an integer. Examples: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari.factorial_int(0) 1 >>> pari.factorial_int(1) 1 >>> pari.factorial_int(5) 120 >>> pari.factorial_int(25) 15511210043330985984000000 """ sig_on() return new_gen(mpfact(n)) def polsubcyclo(self, long n, long d, v=None): """ polsubcyclo(n, d, v=x): return the pari list of polynomial(s) defining the sub-abelian extensions of degree `d` of the cyclotomic field `\QQ(\zeta_n)`, where `d` divides `\phi(n)`. Examples:: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari.polsubcyclo(8, 4) [x^4 + 1] >>> pari.polsubcyclo(8, 2, 'z') [z^2 + 2, z^2 - 2, z^2 + 1] >>> pari.polsubcyclo(8, 1) [x - 1] >>> pari.polsubcyclo(8, 3) [] """ cdef Gen plist sig_on() plist = new_gen(polsubcyclo(n, d, get_var(v))) if typ(plist.g) != t_VEC: return self.vector(1, [plist]) else: return plist def setrand(self, seed): """ Sets PARI's current random number seed. INPUT: - ``seed`` -- either a strictly positive integer or a GEN of type ``t_VECSMALL`` as output by ``getrand()`` Examples: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari.setrand(50) >>> a = pari.getrand() >>> pari.setrand(a) >>> a == pari.getrand() True Tests: Check that invalid inputs are handled properly: >>> pari.setrand("foobar") Traceback (most recent call last): ... PariError: incorrect type in setrand (t_POL) """ cdef Gen t0 = self(seed) sig_on() setrand(t0.g) sig_off() def vector(self, long n, entries=None): """ vector(long n, entries=None): Create and return the length n PARI vector with given list of entries. Examples: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari.vector(5, [1, 2, 5, 4, 3]) [1, 2, 5, 4, 3] >>> pari.vector(2, ['x', 1]) [x, 1] >>> pari.vector(2, ['x', 1, 5]) Traceback (most recent call last): ... IndexError: length of entries (=3) must equal n (=2) """ cdef Gen v = self._empty_vector(n) if entries is not None: if len(entries) != n: raise IndexError("length of entries (=%s) must equal n (=%s)"%\ (len(entries), n)) for i, x in enumerate(entries): v[i] = x return v cdef Gen _empty_vector(self, long n): cdef Gen v sig_on() v = new_gen(zerovec(n)) return v def matrix(self, long m, long n, entries=None): """ matrix(long m, long n, entries=None): Create and return the m x n PARI matrix with given list of entries. Examples: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari.matrix(3,3,range(9)) [0, 1, 2; 3, 4, 5; 6, 7, 8] """ cdef long i, j, k cdef Gen A cdef Gen x sig_on() A = new_gen(zeromatcopy(m,n)) if entries is not None: if len(entries) != m*n: raise IndexError("len of entries (=%s) must be %s*%s=%s"%(len(entries),m,n,m*n)) k = 0 for i in range(m): for j in range(n): sig_check() x = self(entries[k]) A.cache((i,j), x) set_gcoeff(A.g, i+1, j+1, x.g) k += 1 return A def genus2red(self, P, P0=None): """ Let `P` be a polynomial with integer coefficients. Determines the reduction of the (proper, smooth) genus 2 curve `C/\QQ`, defined by the hyperelliptic equation `y^2 = P`. The special syntax ``genus2red([P,Q])`` is also allowed, where the polynomials `P` and `Q` have integer coefficients, to represent the model `y^2 + Q(x)y = P(x)`. Examples: >>> import cypari2 >>> pari = cypari2.Pari() >>> x = pari('x') >>> pari.genus2red([-5*x**5, x**3 - 2*x**2 - 2*x + 1]) [1416875, [2, -1; 5, 4; 2267, 1], x^6 - 240*x^4 - 2550*x^3 - 11400*x^2 - 24100*x - 19855, [[2, [2, [Mod(1, 2)]], []], [5, [1, []], ["[V] page 156", [3]]], [2267, [2, [Mod(432, 2267)]], ["[I{1-0-0}] page 170", []]]]] """ cdef Gen t0 = objtogen(P) sig_on() return new_gen(genus2red(t0.g, NULL)) def List(self, x=None): """ Create an empty list or convert `x` to a list. Examples:: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari.List(range(5)) List([0, 1, 2, 3, 4]) >>> L = pari.List() >>> L List([]) >>> L.listput(42, 1) 42 >>> L List([42]) >>> L.listinsert(24, 1) 24 >>> L List([24, 42]) """ if x is None: sig_on() return new_gen(mklist()) cdef Gen t0 = objtogen(x) sig_on() return new_gen(gtolist(t0.g)) cdef long get_var(v) except -2: """ Convert ``v`` into a PARI variable number. If ``v`` is a PARI object, return the variable number of ``variable(v)``. If ``v`` is ``None``, return -1. Otherwise, treat ``v`` as a string and return the number of the variable named ``v``. OUTPUT: a PARI variable number (varn) or -1 if there is no variable number. .. WARNING:: You can easily create variables with garbage names using this function. This can actually be used as a feature, if you want variable names which cannot be confused with ordinary user variables. Examples: We test this function using ``Pol()`` which calls this function: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari("[1,0]").Pol() x >>> pari("[2,0]").Pol('x') 2*x >>> pari("[Pi,0]").Pol('!@#$%^&') 3.14159265358979*!@#$%^& >>> pari("[1,0]").Pol(-1) # Deprecated x We can use ``varhigher()`` and ``varlower()`` to create temporary variables without a name. The ``"xx"`` below is just a string to display the variable, it doesn't create a variable ``"xx"``: >>> xx = pari.varhigher("xx") >>> pari("[x,0]").Pol(xx) x*xx Indeed, this is not the same as: >>> pari("[x,0]").Pol("xx") Traceback (most recent call last): ... PariError: incorrect priority in gtopoly: variable x <= xx """ if v is None: return -1 cdef long varno if isinstance(v, Gen): sig_on() varno = gvar((v).g) sig_off() if varno < 0: return -1 else: return varno if v == -1: from warnings import warn warn("using '-1' as variable name is deprecated, use 'None' to mean 'no variable'", DeprecationWarning) return -1 cdef bytes s = to_bytes(v) sig_on() varno = fetch_user_var(s) sig_off() return varno IF HAVE_PLOT_SVG: cdef void get_plot_ipython(PARI_plot* T): # Values copied from src/graph/plotsvg.c in PARI sources T.width = 480 T.height = 320 T.hunit = 3 T.vunit = 3 T.fwidth = 9 T.fheight = 12 T.draw = draw_ipython cdef void draw_ipython(PARI_plot *T, GEN w, GEN x, GEN y): global avma cdef pari_sp av = avma cdef char* svg = rect2svg(w, x, y, T) from IPython.core.display import SVG, display display(SVG(svg)) avma = av cypari2-1.1.4/cypari2/handle_error.pyx0000644000201600020160000001325113225661514021276 0ustar jdemeyerjdemeyer00000000000000""" Handling PARI errors ******************** AUTHORS: - Peter Bruin (September 2013): initial version (:trac:`9640`) - Jeroen Demeyer (January 2015): use ``cb_pari_err_handle`` (:trac:`14894`) """ #***************************************************************************** # Copyright (C) 2013 Peter Bruin # Copyright (C) 2015 Jeroen Demeyer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** from __future__ import absolute_import, division, print_function from cpython cimport PyErr_Occurred from cysignals.signals cimport sig_block, sig_unblock, sig_error from .paridecl cimport * from .paripriv cimport * from .stack cimport new_gen_noclear # We derive PariError from RuntimeError, for backward compatibility with # code that catches the latter. class PariError(RuntimeError): """ Error raised by PARI """ def errnum(self): r""" Return the PARI error number corresponding to this exception. EXAMPLES: >>> import cypari2 >>> pari = cypari2.Pari() >>> try: ... pari('1/0') ... except PariError as err: ... print(err.errnum()) 31 """ return self.args[0] def errtext(self): """ Return the message output by PARI when this error occurred. EXAMPLES: >>> import cypari2 >>> pari = cypari2.Pari() >>> try: ... pari('pi()') ... except PariError as e: ... print(e.errtext()) not a function in function call """ return self.args[1] def errdata(self): """ Return the error data (a ``t_ERROR`` gen) corresponding to this error. EXAMPLES: >>> import cypari2 >>> pari = cypari2.Pari() >>> try: ... pari('Mod(2,6)')**-1 ... except PariError as e: ... E = e.errdata() >>> E error("impossible inverse in Fp_inv: Mod(2, 6).") >>> E.component(2) Mod(2, 6) """ return self.args[2] def __repr__(self): r""" TESTS: >>> import cypari2 >>> pari = cypari2.Pari() >>> PariError(11) PariError(11) """ return "PariError(%d)"%self.errnum() def __str__(self): r""" Return a suitable message for displaying this exception. This is simply the error text with certain trailing characters stripped. EXAMPLES: >>> import cypari2 >>> pari = cypari2.Pari() >>> try: ... pari('1/0') ... except PariError as err: ... print(err) _/_: impossible inverse in gdiv: 0 A syntax error:: >>> pari('!@#$%^&*()') Traceback (most recent call last): ... PariError: syntax error, unexpected $undefined """ return self.errtext().rstrip(" .:") cdef void _pari_init_error_handling(): """ Set up our code for handling PARI errors. TESTS: >>> import cypari2 >>> pari = cypari2.Pari() >>> try: ... p = pari.polcyclo(-1) ... except PariError as e: ... print(e.errtext()) domain error in polcyclo: index <= 0 Warnings still work just like in GP:: >>> pari('warning("test")') """ global cb_pari_err_handle global cb_pari_err_recover cb_pari_err_handle = _pari_err_handle cb_pari_err_recover = _pari_err_recover cdef int _pari_err_handle(GEN E) except 0: """ Convert a PARI error into a Python exception. This function is a callback from the PARI error handler. EXAMPLES: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari('error("test")') Traceback (most recent call last): ... PariError: error: user error: test >>> pari(1)/pari(0) Traceback (most recent call last): ... PariError: impossible inverse in gdiv: 0 """ cdef long errnum = E[1] cdef char* errstr cdef const char* s if errnum == e_STACK: # Custom error message for PARI stack overflow pari_error_string = "the PARI stack overflows (current size: {}; maximum size: {})\n" pari_error_string += "You can use pari.allocatemem() to change the stack size and try again" pari_error_string = pari_error_string.format(pari_mainstack.size, pari_mainstack.vsize) else: sig_block() try: errstr = pari_err2str(E) pari_error_string = errstr.decode('ascii') pari_free(errstr) finally: sig_unblock() s = closure_func_err() if s is not NULL: pari_error_string = s.decode('ascii') + ": " + pari_error_string raise PariError(errnum, pari_error_string, new_gen_noclear(E)) cdef void _pari_err_recover(long errnum): """ Reset the error string and jump back to ``sig_on()``, either to retry the code (in case of no error) or to make the already-raised exception known to Python. TEST: Perform a computation that requires doubling the default stack several times: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari.allocatemem(2**12, 2**26) PARI stack size set to 4096 bytes, maximum size set to 67108864 >>> x = pari('2^(2^26)') >>> x == 2**(2**26) True """ # An exception was raised. Jump to the signal-handling code # which will cause sig_on() to see the exception. sig_error() cypari2-1.1.4/cypari2/gen.pxd0000644000201600020160000000226013236012275017350 0ustar jdemeyerjdemeyer00000000000000from .types cimport * cimport cython cdef class Gen_auto: # The actual PARI GEN cdef GEN g # Chunk of memory containing g, typically allocated in # deepcopy_to_python_heap(). cdef void* chunk # Parent Gen: this is usually None, but it can be used when this # Gen is a part of some other Gen. In that case, chunk will be NULL # because the parent has allocated the memory. cdef Gen_auto parent # A cache for __getitem__. Initially, this is None but it will be # turned into a dict when needed. This is not just an optional # cache, but it is required to implement __setitem__ correctly: # __setitem__ will set an entry of one Gen to another Gen. To # prevent Python from garbage collecting the other Gen, we must put # it in itemcache. cdef dict itemcache cdef inline int cache(self, key, value) except -1: """Add ``(key, value)`` to ``self.itemcache``.""" if self.itemcache is None: self.itemcache = {key: value} else: self.itemcache[key] = value @cython.final cdef class Gen(Gen_auto): cdef new_ref(self, GEN g) cdef Gen list_of_Gens_to_Gen(list s) cpdef Gen objtogen(s) cypari2-1.1.4/cypari2/types.pxd0000644000201600020160000000715513230361623017751 0ustar jdemeyerjdemeyer00000000000000""" Declarations for types used by PARI This includes both the C types as well as the PARI types (and a few macros for dealing with those). It is important that the functionality in this file does not call any PARI library functions. The reason is that we want to allow just using these types (for example, to define a Cython extension type) without linking to PARI. This file should consist only of typedefs and macros from PARI's include files. """ #***************************************************************************** # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** cdef extern from "pari/pari.h": ctypedef unsigned long ulong "pari_ulong" ctypedef long* GEN ctypedef char* byteptr ctypedef unsigned long pari_sp # PARI types enum: t_INT t_REAL t_INTMOD t_FRAC t_FFELT t_COMPLEX t_PADIC t_QUAD t_POLMOD t_POL t_SER t_RFRAC t_QFR t_QFI t_VEC t_COL t_MAT t_LIST t_STR t_VECSMALL t_CLOSURE t_ERROR t_INFINITY int BITS_IN_LONG int DEFAULTPREC # 64 bits precision int MEDDEFAULTPREC # 128 bits precision int BIGDEFAULTPREC # 192 bits precision long typ(GEN x) long settyp(GEN x, long s) long isclone(GEN x) long setisclone(GEN x) long unsetisclone(GEN x) long lg(GEN x) long setlg(GEN x, long s) long signe(GEN x) long setsigne(GEN x, long s) long lgefint(GEN x) long setlgefint(GEN x, long s) long expo(GEN x) long setexpo(GEN x, long s) long valp(GEN x) long setvalp(GEN x, long s) long precp(GEN x) long setprecp(GEN x, long s) long varn(GEN x) long setvarn(GEN x, long s) long evaltyp(long x) long evallg(long x) long evalvarn(long x) long evalsigne(long x) long evalprecp(long x) long evalvalp(long x) long evalexpo(long x) long evallgefint(long x) ctypedef struct PARI_plot: long width long height long hunit long vunit long fwidth long fheight void (*draw)(PARI_plot *T, GEN w, GEN x, GEN y) # Various structures that we don't interface but which need to be # declared, such that Cython understands the declarations of # functions using these types. struct bb_group struct bb_field struct bb_ring struct bb_algebra struct qfr_data struct nfmaxord_t struct forcomposite_t struct forpart_t struct forprime_t struct forvec_t struct entree struct gp_context struct nfbasic_t struct pariFILE struct pari_mt struct pari_stack struct pari_thread struct pari_timer struct GENbin struct hashentry struct hashtable # These are actually defined in cypari.h but we put them here to # prevent Cython from reordering the includes. GEN set_gel(GEN x, long n, GEN z) # gel(x, n) = z GEN set_gmael(GEN x, long i, long j, GEN z) # gmael(x, i, j) = z GEN set_gcoeff(GEN x, long i, long j, GEN z) # gcoeff(x, i, j) = z GEN set_uel(GEN x, long n, ulong z) # uel(x, n) = z # It is important that this gets included *after* all PARI includes cdef extern from "cypari.h": pass cypari2-1.1.4/cypari2/gen.pyx0000644000201600020160000042542113236012275017405 0ustar jdemeyerjdemeyer00000000000000""" The Gen class wrapping PARI's GEN type ************************************** AUTHORS: - William Stein (2006-03-01): updated to work with PARI 2.2.12-beta - William Stein (2006-03-06): added newtonpoly - Justin Walker: contributed some of the function definitions - Gonzalo Tornaria: improvements to conversions; much better error handling. - Robert Bradshaw, Jeroen Demeyer, William Stein (2010-08-15): Upgrade to PARI 2.4.3 (:trac:`9343`) - Jeroen Demeyer (2011-11-12): rewrite various conversion routines (:trac:`11611`, :trac:`11854`, :trac:`11952`) - Peter Bruin (2013-11-17): move Pari to a separate file (:trac:`15185`) - Jeroen Demeyer (2014-02-09): upgrade to PARI 2.7 (:trac:`15767`) - Martin von Gagern (2014-12-17): Added some Galois functions (:trac:`17519`) - Jeroen Demeyer (2015-01-12): upgrade to PARI 2.8 (:trac:`16997`) - Jeroen Demeyer (2015-03-17): automatically generate methods from ``pari.desc`` (:trac:`17631` and :trac:`17860`) - Kiran Kedlaya (2016-03-23): implement infinity type - Luca De Feo (2016-09-06): Separate Sage-specific components from generic C-interface in ``Pari`` (:trac:`20241`) - Vincent Delecroix (2017-04-29): Python 3 support and doctest conversion """ #***************************************************************************** # Copyright (C) 2006,2010 William Stein # Copyright (C) ???? Justin Walker # Copyright (C) ???? Gonzalo Tornaria # Copyright (C) 2010 Robert Bradshaw # Copyright (C) 2010-2016 Jeroen Demeyer # Copyright (C) 2016 Luca De Feo # Copyright (C) 2017 Vincent Delecroix # # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** from __future__ import absolute_import, division, print_function import types cimport cython from cpython.int cimport PyInt_Check from cpython.long cimport PyLong_Check from cpython.bytes cimport PyBytes_Check from cpython.unicode cimport PyUnicode_Check from cpython.float cimport PyFloat_AS_DOUBLE from cpython.complex cimport PyComplex_RealAsDouble, PyComplex_ImagAsDouble from cpython.object cimport Py_EQ, Py_NE, Py_LE, Py_GE, Py_LT, Py_GT from cysignals.memory cimport sig_free, check_malloc from cysignals.signals cimport sig_check, sig_on, sig_off, sig_block, sig_unblock from .types cimport * from .string_utils cimport to_string, to_bytes from .paripriv cimport * from .convert cimport (integer_to_gen, gen_to_integer, new_gen_from_double, new_t_COMPLEX_from_double) from .pari_instance cimport (prec_bits_to_words, prec_words_to_bits, default_bitprec, get_var) from .stack cimport new_gen, new_gen_noclear, clear_stack from .closure cimport objtoclosure from .paridecl cimport * include 'auto_gen.pxi' cdef bint ellwp_flag1_bug = -1 cdef inline bint have_ellwp_flag1_bug(): """ The PARI function ``ellwp(..., flag=1)`` has a bug in PARI versions up to 2.9.3 where the derivative is a factor 2 too small. This function does a cached check for this bug, returning 1 if the bug is there and 0 if not. """ global ellwp_flag1_bug if ellwp_flag1_bug >= 0: return ellwp_flag1_bug # Check whether our PARI/GP version is buggy or not. This # computation should return 1.0, but in older PARI versions it # returns 0.5. sig_on() cdef GEN res = gp_read_str(b"localbitprec(128); my(E=ellinit([0,1/4])); ellwp(E,ellpointtoz(E,[0,1/2]),1)[2]") cdef double d = gtodouble(res) sig_off() if d == 1.0: ellwp_flag1_bug = 0 elif d == 0.5: ellwp_flag1_bug = 1 else: raise AssertionError(f"unexpected result from ellwp() test: {d}") return ellwp_flag1_bug @cython.final cdef class Gen(Gen_auto): """ Cython extension class that models the PARI GEN type. """ def __init__(self): raise RuntimeError("PARI objects cannot be instantiated directly; use pari(x) to convert x to PARI") def __dealloc__(self): sig_free(self.chunk) cdef new_ref(self, GEN g): """ Create a new ``Gen`` pointing to ``g``, which is a component of ``self.g``. In this case, ``g`` should point to some location in the memory allocated by ``self``. This will not allocate any new memory: the newly returned ``Gen`` will point to the memory allocated for ``self``. .. NOTE:: Usually, there is only one ``Gen`` pointing to a given PARI ``GEN``. This function can be used when a complicated ``GEN`` is allocated with a single ``Gen`` pointing to it, and one needs a ``Gen`` pointing to one of its components. For example, doing ``x = pari("[1, 2]")`` allocates a ``Gen`` pointing to the list ``[1, 2]``. To create a ``Gen`` pointing to the first element, one can do ``x.new_ref(gel(x.g, 1))``. See :meth:`Gen.__getitem__` for an example of usage. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari("[[1, 2], 3]")[0][1] # indirect doctest 2 """ cdef Gen x = Gen.__new__(Gen) x.g = g x.parent = self return x def __repr__(self): """ Display representation of a gen. OUTPUT: a Python string Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari('vector(5,i,i)') [1, 2, 3, 4, 5] >>> pari('[1,2;3,4]') [1, 2; 3, 4] >>> pari('Str(hello)') "hello" """ cdef char *c sig_on() # Use sig_block(), which is needed because GENtostr() uses # malloc(), which is dangerous inside sig_on() sig_block() c = GENtostr(self.g) sig_unblock() sig_off() s = bytes(c) pari_free(c) return to_string(s) def __str__(self): """ Convert this Gen to a string. Except for PARI strings, we have ``str(x) == repr(x)``. For strings (type ``t_STR``), the returned string is not quoted. OUTPUT: a Python string Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> str(pari('vector(5,i,i)')) '[1, 2, 3, 4, 5]' >>> str(pari('[1,2;3,4]')) '[1, 2; 3, 4]' >>> str(pari('Str(hello)')) 'hello' """ # Use __repr__ except for strings if typ(self.g) == t_STR: return to_string(GSTR(self.g)) return repr(self) def __hash__(self): """ Return the hash of self, computed using PARI's hash_GEN(). Tests: >>> from cypari2 import Pari >>> pari = Pari() >>> type(pari('1 + 2.0*I').__hash__()) <... 'int'> """ cdef long h sig_on() h = hash_GEN(self.g) sig_off() return h def __iter__(self): """ Iterate over the components of ``self``. The items in the iteration are of type :class:`Gen` with the following exceptions: - items of a ``t_VECSMALL`` are of type ``int`` - items of a ``t_STR`` are of type ``str`` Examples: We can iterate over PARI vectors or columns: >>> from cypari2 import Pari >>> pari = Pari() >>> L = pari("vector(10,i,i^2)") >>> L.__iter__() >>> [x for x in L] [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] >>> list(L) [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] >>> list(pari("vector(10,i,i^2)~")) [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] For polynomials, we iterate over the list of coefficients: >>> pol = pari("x^3 + 5/3*x"); list(pol) [0, 5/3, 0, 1] For power series or Laurent series, we get all coefficients starting from the lowest degree term. This includes trailing zeros: >>> list(pari('x^2 + O(x^8)')) [1, 0, 0, 0, 0, 0] >>> list(pari('x^-2 + O(x^0)')) [1, 0] For matrices, we iterate over the columns: >>> M = pari.matrix(3,2,[1,4,2,5,3,6]); M [1, 4; 2, 5; 3, 6] >>> list(M) [[1, 2, 3]~, [4, 5, 6]~] Other types are first converted to a vector using :meth:`Vec`: >>> Q = pari('Qfb(1, 2, 3)') >>> tuple(Q) (1, 2, 3) >>> Q.Vec() [1, 2, 3] We get an error for "scalar" types or for types which cannot be converted to a PARI vector: >>> iter(pari(42)) Traceback (most recent call last): ... TypeError: PARI object of type 't_INT' is not iterable >>> iter(pari("x->x")) Traceback (most recent call last): ... PariError: incorrect type in gtovec (t_CLOSURE) For ``t_VECSMALL``, the items are Python integers: >>> v = pari("Vecsmall([1,2,3,4,5,6])") >>> list(v) [1, 2, 3, 4, 5, 6] >>> type(list(v)[0]).__name__ 'int' For ``t_STR``, the items are Python strings: >>> v = pari('"hello"') >>> list(v) ['h', 'e', 'l', 'l', 'o'] Test some deprecations: >>> import warnings >>> with warnings.catch_warnings(record=True) as w: ... warnings.simplefilter('always') ... tuple(pari('3/5')) ... tuple(pari('1 + 5*I')) ... assert len(w) == 2 ... assert all(issubclass(u.category, DeprecationWarning) for u in w) (3, 5) (1, 5) """ cdef long i cdef long t = typ(self.g) cdef GEN x # First convert self to a vector type cdef Gen v if t == t_VEC or t == t_COL or t == t_MAT: # These are vector-like and can be iterated over directly v = self elif t == t_POL: v = self.Vecrev() elif t == t_FRAC or t == t_RFRAC or t == t_COMPLEX: # Also treat as vector # Deprecated, make this an error in the future from warnings import warn warn(f"iterating a PARI {self.type()!r} is deprecated", DeprecationWarning) v = self elif is_scalar_t(t): raise TypeError(f"PARI object of type {self.type()!r} is not iterable") elif t == t_VECSMALL: # Special case: items of type int x = self.g return (x[i] for i in range(1, lg(x))) elif t == t_STR: # Special case: convert to str # CHANGED return iter(to_string(GSTR(self.g))) else: v = self.Vec() # Now iterate over the vector v x = v.g return (v.new_ref(gel(x, i)) for i in range(1, lg(x))) def list(self): """ Convert ``self`` to a Python list with :class:`Gen` components. Examples: A PARI vector becomes a Python list: >>> from cypari2 import Pari >>> pari = Pari() >>> L = pari("vector(10,i,i^2)").list() >>> L [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] >>> type(L) <... 'list'> >>> type(L[0]) <... 'cypari2.gen.Gen'> For polynomials, list() returns the list of coefficients: >>> pol = pari("x^3 + 5/3*x"); pol.list() [0, 5/3, 0, 1] For power series or Laurent series, we get all coefficients starting from the lowest degree term. This includes trailing zeros: >>> pari('x^2 + O(x^8)').list() [1, 0, 0, 0, 0, 0] >>> pari('x^-2 + O(x^0)').list() [1, 0] For matrices, we get a list of columns: >>> M = pari.matrix(3,2,[1,4,2,5,3,6]); M [1, 4; 2, 5; 3, 6] >>> M.list() [[1, 2, 3]~, [4, 5, 6]~] Tests: For "scalar" types, this is deprecated. Currently, we get a 1-element list containing ``self``: >>> import warnings >>> with warnings.catch_warnings(record=True) as w: ... warnings.simplefilter('always') ... pari(42).list() ... assert len(w) == 1 ... assert issubclass(w[0].category, DeprecationWarning) [42] """ if is_scalar_t(typ(self.g)): # Deprecated, make this an error in the future from warnings import warn warn("calling list() on scalar PARI types is deprecated", DeprecationWarning) return [self] return [x for x in self] def __reduce__(self): """ Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> from pickle import loads, dumps >>> f = pari('x^3 - 3') >>> loads(dumps(f)) == f True >>> f = pari('"hello world"') >>> loads(dumps(f)) == f True """ s = repr(self) return (objtogen, (s,)) def __add__(left, right): """ Return ``left`` plus ``right``. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(15) + pari(6) 21 >>> pari("x^3+x^2+x+1") + pari("x^2") x^3 + 2*x^2 + x + 1 >>> 2e20 + pari("1e20") 3.00000000000000 E20 >>> -2 + pari(3) 1 """ cdef Gen t0, t1 try: t0 = objtogen(left) t1 = objtogen(right) except Exception: return NotImplemented sig_on() return new_gen(gadd(t0.g, t1.g)) def __sub__(left, right): """ Return ``left`` minus ``right``. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(15) - pari(6) 9 >>> pari("x^3+x^2+x+1") - pari("x^2") x^3 + x + 1 >>> 2e20 - pari("1e20") 1.00000000000000 E20 >>> -2 - pari(3) -5 """ cdef Gen t0, t1 try: t0 = objtogen(left) t1 = objtogen(right) except Exception: return NotImplemented sig_on() return new_gen(gsub(t0.g, t1.g)) def __mul__(left, right): cdef Gen t0, t1 try: t0 = objtogen(left) t1 = objtogen(right) except Exception: return NotImplemented sig_on() return new_gen(gmul(t0.g, t1.g)) def __div__(left, right): cdef Gen t0, t1 try: t0 = objtogen(left) t1 = objtogen(right) except Exception: return NotImplemented sig_on() return new_gen(gdiv(t0.g, t1.g)) def __truediv__(left, right): cdef Gen t0, t1 try: t0 = objtogen(left) t1 = objtogen(right) except Exception: return NotImplemented sig_on() return new_gen(gdiv(t0.g, t1.g)) def _add_one(self): """ Return self + 1. OUTPUT: pari gen Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> n = pari(5) >>> n._add_one() 6 >>> n = pari('x^3') >>> n._add_one() x^3 + 1 """ sig_on() return new_gen(gaddsg(1, self.g)) def __mod__(left, right): """ Return ``left`` modulo ``right``. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(15) % pari(6) 3 >>> pari("x^3+x^2+x+1") % pari("x^2") x + 1 >>> pari(-2) % 3 1 >>> -2 % pari(3) 1 """ cdef Gen t0, t1 try: t0 = objtogen(left) t1 = objtogen(right) except Exception: return NotImplemented sig_on() return new_gen(gmod(t0.g, t1.g)) def __pow__(left, right, m): """ Return ``left`` to the power ``right`` (if ``m`` is ``None``) or ``Mod(left, m)^right`` if ``m`` is not ``None``. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(5) ** pari(3) 125 >>> pari("x-1") ** 3 x^3 - 3*x^2 + 3*x - 1 >>> pow(pari(5), pari(28), int(29)) Mod(1, 29) >>> 2 ** pari(-5) 1/32 >>> pari(2) ** -5 1/32 """ cdef Gen t0, t1 try: t0 = objtogen(left) t1 = objtogen(right) except Exception: return NotImplemented if m is not None: t0 = t0.Mod(m) sig_on() return new_gen(gpow(t0.g, t1.g, prec_bits_to_words(0))) def __neg__(self): sig_on() return new_gen(gneg(self.g)) def __rshift__(self, long n): """ Divide ``self`` by `2^n` (truncating or not, depending on the input type). Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(25) >> 3 3 >>> pari('25/2') >> 2 25/8 >>> pari("x") >> 3 1/8*x >>> pari(1.0) >> 100 7.88860905221012 E-31 >>> 33 >> pari(2) 8 """ cdef Gen t0 = objtogen(self) sig_on() return new_gen(gshift(t0.g, -n)) def __lshift__(self, long n): """ Multiply ``self`` by `2^n`. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(25) << 3 200 >>> pari("25/32") << 2 25/8 >>> pari("x") << 3 8*x >>> pari(1.0) << 100 1.26765060022823 E30 >>> 33 << pari(2) 132 """ cdef Gen t0 = objtogen(self) sig_on() return new_gen(gshift(t0.g, n)) def __invert__(self): sig_on() return new_gen(ginv(self.g)) def getattr(self, attr): """ Return the PARI attribute with the given name. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> K = pari("nfinit(x^2 - x - 1)") >>> K.getattr("pol") x^2 - x - 1 >>> K.getattr("disc") 5 >>> K.getattr("reg") Traceback (most recent call last): ... PariError: _.reg: incorrect type in reg (t_VEC) >>> K.getattr("zzz") Traceback (most recent call last): ... PariError: not a function in function call """ attr = to_bytes(attr) t = b"_." + attr sig_on() return new_gen(closure_callgen1(strtofunction(t), self.g)) def mod(self): """ Given an INTMOD or POLMOD ``Mod(a,m)``, return the modulus `m`. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(4).Mod(5).mod() 5 >>> pari("Mod(x, x*y)").mod() y*x >>> pari("[Mod(4,5)]").mod() Traceback (most recent call last): ... TypeError: Not an INTMOD or POLMOD in mod() """ if typ(self.g) != t_INTMOD and typ(self.g) != t_POLMOD: raise TypeError("Not an INTMOD or POLMOD in mod()") sig_on() # The hardcoded 1 below refers to the position in the internal # representation of a INTMOD or POLDMOD where the modulus is # stored. return new_gen(gel(self.g, 1)) # Special case: SageMath uses polred(), so mark it as not # obsolete: https://trac.sagemath.org/ticket/22165 def polred(self, *args, **kwds): r''' This function is :emphasis:`deprecated`, use :meth:`.polredbest` instead. ''' import warnings with warnings.catch_warnings(): warnings.simplefilter("ignore") return super(Gen, self).polred(*args, **kwds) def nf_get_pol(self): """ Returns the defining polynomial of this number field. INPUT: - ``self`` -- A PARI number field being the output of ``nfinit()``, ``bnfinit()`` or ``bnrinit()``. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> x = pari('x') >>> K = (x**4 - 4*x**2 + 1).bnfinit() >>> bnr = K.bnrinit(2*x) >>> bnr.nf_get_pol() x^4 - 4*x^2 + 1 For relative number fields, this returns the relative polynomial: >>> y = pari.varhigher('y') >>> L = K.rnfinit(y**2 - 5) >>> L.nf_get_pol() y^2 - 5 An error is raised for invalid input: >>> pari("[0]").nf_get_pol() Traceback (most recent call last): ... PariError: incorrect type in pol (t_VEC) """ sig_on() return new_gen(member_pol(self.g)) def nf_get_diff(self): """ Returns the different of this number field as a PARI ideal. INPUT: - ``self`` -- A PARI number field being the output of ``nfinit()``, ``bnfinit()`` or ``bnrinit()``. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> x = pari('x') >>> K = (x**4 - 4*x**2 + 1).nfinit() >>> K.nf_get_diff() [12, 0, 0, 0; 0, 12, 8, 0; 0, 0, 4, 0; 0, 0, 0, 4] """ sig_on() return new_gen(member_diff(self.g)) def nf_get_sign(self): """ Returns a Python list ``[r1, r2]``, where ``r1`` and ``r2`` are Python ints representing the number of real embeddings and pairs of complex embeddings of this number field, respectively. INPUT: - ``self`` -- A PARI number field being the output of ``nfinit()``, ``bnfinit()`` or ``bnrinit()``. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> x = pari('x') >>> K = (x**4 - 4*x**2 + 1).nfinit() >>> s = K.nf_get_sign(); s [4, 0] >>> type(s); type(s[0]) <... 'list'> <... 'int'> >>> pari.polcyclo(15).nfinit().nf_get_sign() [0, 4] """ cdef long r1 cdef long r2 cdef GEN sign sig_on() sign = member_sign(self.g) r1 = itos(gel(sign, 1)) r2 = itos(gel(sign, 2)) sig_off() return [r1, r2] def nf_get_zk(self): """ Returns a vector with a `\ZZ`-basis for the ring of integers of this number field. The first element is always `1`. INPUT: - ``self`` -- A PARI number field being the output of ``nfinit()``, ``bnfinit()`` or ``bnrinit()``. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> x = pari('x') >>> K = (x**4 - 4*x**2 + 1).nfinit() >>> K.nf_get_zk() [1, x, x^3 - 4*x, x^2 - 2] """ sig_on() return new_gen(member_zk(self.g)) def bnf_get_no(self): """ Returns the class number of ``self``, a "big number field" (``bnf``). Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> x = pari('x') >>> K = (x**2 + 65).bnfinit() >>> K.bnf_get_no() 8 """ sig_on() return new_gen(bnf_get_no(self.g)) def bnf_get_cyc(self): """ Returns the structure of the class group of this number field as a vector of SNF invariants. NOTE: ``self`` must be a "big number field" (``bnf``). Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> x = pari('x') >>> K = (x**2 + 65).bnfinit() >>> K.bnf_get_cyc() [4, 2] """ sig_on() return new_gen(bnf_get_cyc(self.g)) def bnf_get_gen(self): """ Returns a vector of generators of the class group of this number field. NOTE: ``self`` must be a "big number field" (``bnf``). Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> x = pari('x') >>> K = (x**2 + 65).bnfinit() >>> G = K.bnf_get_gen(); G [[3, 2; 0, 1], [2, 1; 0, 1]] """ sig_on() return new_gen(bnf_get_gen(self.g)) def bnf_get_reg(self): """ Returns the regulator of this number field. NOTE: ``self`` must be a "big number field" (``bnf``). Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> x = pari('x') >>> K = (x**4 - 4*x**2 + 1).bnfinit() >>> K.bnf_get_reg() 2.66089858019037... """ sig_on() return new_gen(bnf_get_reg(self.g)) def bnfunit(self): sig_on() return new_gen(bnf_get_fu(self.g)) def idealmoddivisor(self, Gen ideal): """ Return a 'small' ideal equivalent to ``ideal`` in the ray class group that the bnr structure ``self`` encodes. INPUT: - ``self`` -- a bnr structure as outputted from bnrinit. - ``ideal`` -- an ideal in the underlying number field of the bnr structure. OUTPUT: An ideal representing the same ray class as ``ideal`` but with 'small' generators. If ``ideal`` is not coprime to the modulus of the bnr, this results in an error. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> i = pari('i') >>> K = (i**4 - 2).bnfinit() >>> R = K.bnrinit(5,1) >>> R.idealmoddivisor(K[6][6][1]) [2, 0, 0, 0; 0, 1, 0, 0; 0, 0, 1, 0; 0, 0, 0, 1] >>> R.idealmoddivisor(K.idealhnf(5)) Traceback (most recent call last): ... PariError: elements not coprime in idealaddtoone: [5, 0, 0, 0; 0, 5, 0, 0; 0, 0, 5, 0; 0, 0, 0, 5] [5, 0, 0, 0; 0, 5, 0, 0; 0, 0, 5, 0; 0, 0, 0, 5] """ sig_on() return new_gen(idealmoddivisor(self.g, ideal.g)) def pr_get_p(self): """ Returns the prime of `\ZZ` lying below this prime ideal. NOTE: ``self`` must be a PARI prime ideal (as returned by ``idealprimedec`` for example). Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> i = pari('i') >>> K = (i**2 + 1).nfinit() >>> F = K.idealprimedec(5); F [[5, [-2, 1]~, 1, 1, [2, -1; 1, 2]], [5, [2, 1]~, 1, 1, [-2, -1; 1, -2]]] >>> F[0].pr_get_p() 5 """ sig_on() return new_gen(pr_get_p(self.g)) def pr_get_e(self): """ Returns the ramification index (over `\QQ`) of this prime ideal. NOTE: ``self`` must be a PARI prime ideal (as returned by ``idealprimedec`` for example). Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> i = pari('i') >>> K = (i**2 + 1).nfinit() >>> K.idealprimedec(2)[0].pr_get_e() 2 >>> K.idealprimedec(3)[0].pr_get_e() 1 >>> K.idealprimedec(5)[0].pr_get_e() 1 """ cdef long e sig_on() e = pr_get_e(self.g) sig_off() return e def pr_get_f(self): """ Returns the residue class degree (over `\QQ`) of this prime ideal. NOTE: ``self`` must be a PARI prime ideal (as returned by ``idealprimedec`` for example). Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> i = pari('i') >>> K = (i**2 + 1).nfinit() >>> K.idealprimedec(2)[0].pr_get_f() 1 >>> K.idealprimedec(3)[0].pr_get_f() 2 >>> K.idealprimedec(5)[0].pr_get_f() 1 """ cdef long f sig_on() f = pr_get_f(self.g) sig_off() return f def pr_get_gen(self): """ Returns the second generator of this PARI prime ideal, where the first generator is ``self.pr_get_p()``. NOTE: ``self`` must be a PARI prime ideal (as returned by ``idealprimedec`` for example). Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> i = pari('i') >>> K = (i**2 + 1).nfinit() >>> g = K.idealprimedec(2)[0].pr_get_gen(); g [1, 1]~ >>> g = K.idealprimedec(3)[0].pr_get_gen(); g [3, 0]~ >>> g = K.idealprimedec(5)[0].pr_get_gen(); g [-2, 1]~ """ sig_on() return new_gen(pr_get_gen(self.g)) def bid_get_cyc(self): """ Returns the structure of the group `(O_K/I)^*`, where `I` is the ideal represented by ``self``. NOTE: ``self`` must be a "big ideal" (``bid``) as returned by ``idealstar`` for example. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> i = pari('i') >>> K = (i**2 + 1).bnfinit() >>> J = K.idealstar(4*i + 2) >>> J.bid_get_cyc() [4, 2] """ sig_on() return new_gen(bid_get_cyc(self.g)) def bid_get_gen(self): """ Returns a vector of generators of the group `(O_K/I)^*`, where `I` is the ideal represented by ``self``. NOTE: ``self`` must be a "big ideal" (``bid``) with generators, as returned by ``idealstar`` with ``flag`` = 2. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> i = pari('i') >>> K = (i**2 + 1).bnfinit() >>> J = K.idealstar(4*i + 2, 2) >>> J.bid_get_gen() [7, [-2, -1]~] We get an exception if we do not supply ``flag = 2`` to ``idealstar``: >>> J = K.idealstar(3) >>> J.bid_get_gen() Traceback (most recent call last): ... PariError: missing bid generators. Use idealstar(,,2) """ sig_on() return new_gen(bid_get_gen(self.g)) def __getitem__(self, n): """ Return the nth entry of self. The indexing is 0-based, like in Python. Note that this is *different* than the default behavior of the PARI/GP interpreter. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> p = pari('1 + 2*x + 3*x^2') >>> p[0] 1 >>> p[2] 3 >>> p[100] 0 >>> p[-1] 0 >>> q = pari('x^2 + 3*x^3 + O(x^6)') >>> q[3] 3 >>> q[5] 0 >>> q[6] Traceback (most recent call last): ... IndexError: index out of range >>> m = pari('[1,2;3,4]') >>> m[0] [1, 3]~ >>> m[1,0] 3 >>> l = pari('List([1,2,3])') >>> l[1] 2 >>> s = pari('"hello, world!"') >>> s[0] 'h' >>> s[4] 'o' >>> s[12] '!' >>> s[13] Traceback (most recent call last): ... IndexError: index out of range >>> v = pari('[1,2,3]') >>> v[0] 1 >>> c = pari('Col([1,2,3])') >>> c[1] 2 >>> sv = pari('Vecsmall([1,2,3])') >>> sv[2] 3 >>> type(sv[2]) <... 'int'> >>> [pari('3/5')[i] for i in range(2)] [3, 5] >>> [pari('1 + 5*I')[i] for i in range(2)] [1, 5] >>> [pari('Qfb(1, 2, 3)')[i] for i in range(3)] [1, 2, 3] >>> pari(57)[0] Traceback (most recent call last): ... TypeError: PARI object of type 't_INT' cannot be indexed >>> m = pari("[[1,2;3,4],5]") ; m[0][1,0] 3 >>> v = pari(range(20)) >>> v[2:5] [2, 3, 4] >>> v[:] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] >>> v[10:] [10, 11, 12, 13, 14, 15, 16, 17, 18, 19] >>> v[:5] [0, 1, 2, 3, 4] >>> v[5:5] [] >>> v [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] >>> v[-1] Traceback (most recent call last): ... IndexError: index out of range >>> v[:-3] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] >>> v[5:] [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] >>> pari([])[::] [] """ cdef Py_ssize_t i, j, k cdef object ind cdef int pari_type pari_type = typ(self.g) if isinstance(n, tuple): if pari_type != t_MAT: raise TypeError("self must be of pari type t_MAT") i, j = n if i < 0 or i >= glength(gel(self.g, 1)): raise IndexError("row index out of range") if j < 0 or j >= glength(self.g): raise IndexError("column index out of range") ind = (i, j) if self.itemcache is not None and ind in self.itemcache: return self.itemcache[ind] else: # Create a new Gen as child of self # and store it in itemcache val = self.new_ref(gmael(self.g, j+1, i+1)) self.cache(ind, val) return val elif isinstance(n, slice): l = glength(self.g) start, stop, step = n.indices(l) inds = xrange(start, stop, step) k = len(inds) # fast exit for empty vector if k == 0: sig_on() return new_gen(zerovec(0)) # fast call, beware pari is one based if pari_type == t_VEC: if step==1: return self.vecextract('"'+str(start+1)+".."+str(stop)+'"') if step==-1: return self.vecextract('"'+str(start+1)+".."+str(stop+2)+'"') # slow call return objtogen(self[i] for i in inds) # Index is not a tuple or slice, convert to integer i = n ## there are no "out of bounds" problems ## for a polynomial or power series, so these go before ## bounds testing if pari_type == t_POL: return self.polcoeff(i) elif pari_type == t_SER: bound = valp(self.g) + lg(self.g) - 2 if i >= bound: raise IndexError("index out of range") return self.polcoeff(i) elif pari_type in (t_INT, t_REAL, t_PADIC, t_QUAD, t_FFELT, t_INTMOD, t_POLMOD): # these are definitely scalar! raise TypeError("PARI object of type %r cannot be indexed" % self.type()) elif i < 0 or i >= glength(self.g): raise IndexError("index out of range") elif pari_type == t_VEC or pari_type == t_MAT: #t_VEC : row vector [ code ] [ x_1 ] ... [ x_k ] #t_MAT : matrix [ code ] [ col_1 ] ... [ col_k ] ind = i if self.itemcache is not None and ind in self.itemcache: return self.itemcache[ind] else: # Create a new Gen as child of self # and store it in itemcache val = self.new_ref(gel(self.g, i+1)) self.cache(ind, val) return val elif pari_type == t_VECSMALL: #t_VECSMALL: vec. small ints [ code ] [ x_1 ] ... [ x_k ] return self.g[i+1] elif pari_type == t_STR: #t_STR : string [ code ] [ man_1 ] ... [ man_k ] return chr(GSTR(self.g)[i]) elif pari_type == t_LIST: return self.component(i+1) #elif pari_type in (t_FRAC, t_RFRAC): # generic code gives us: # [0] = numerator # [1] = denominator #elif pari_type == t_COMPLEX: # generic code gives us # [0] = real part # [1] = imag part #elif type(self.g) in (t_QFR, t_QFI): # generic code works ok else: ## generic code, which currently handles cases ## as mentioned above return self.new_ref(gel(self.g, i+1)) def __setitem__(self, n, y): r""" Set the nth entry to a reference to y. - The indexing is 0-based, like everywhere else in Python, but *unlike* in PARI/GP. - Assignment sets the nth entry to a reference to y, assuming y is an object of type gen. This is the same as in Python, but *different* than what happens in the gp interpreter, where assignment makes a copy of y. - Because setting creates references it is *possible* to make circular references, unlike in GP. Do *not* do this (see the example below). If you need circular references, work at the Python level (where they work well), not the PARI object level. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> v = pari(range(10)) >>> v [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> v[0] = 10 >>> w = pari([5,8,-20]) >>> v [10, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> v[1] = w >>> v [10, [5, 8, -20], 2, 3, 4, 5, 6, 7, 8, 9] >>> w[0] = -30 >>> v [10, [-30, 8, -20], 2, 3, 4, 5, 6, 7, 8, 9] >>> t = v[1]; t[1] = 10 ; v [10, [-30, 10, -20], 2, 3, 4, 5, 6, 7, 8, 9] >>> v[1][0] = 54321 ; v [10, [54321, 10, -20], 2, 3, 4, 5, 6, 7, 8, 9] >>> w [54321, 10, -20] >>> v = pari([[[[0,1],2],3],4]) ; v[0][0][0][1] = 12 ; v [[[[0, 12], 2], 3], 4] >>> m = pari.matrix(2,2,range(4)) ; l = pari([5,6]) ; n = pari.matrix(2,2,[7,8,9,0]) ; m[1,0] = l ; l[1] = n ; m[1,0][1][1,1] = 1111 ; m [0, 1; [5, [7, 8; 9, 1111]], 3] >>> m = pari("[[1,2;3,4],5,6]") ; m[0][1,1] = 11 ; m [[1, 2; 3, 11], 5, 6] Finally, we create a circular reference: >>> v = pari([0]) >>> w = pari([v]) >>> v [0] >>> w [[0]] >>> v[0] = w Now there is a circular reference. Accessing v[0] will crash Python. >>> s = pari.vector(2,[0,0]) >>> s[:1] [0] >>> s[:1]=[1] >>> s [1, 0] >>> type(s[0]) <... 'cypari2.gen.Gen'> >>> s = pari(range(20)) ; s [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] >>> s[0:10:2] = range(50,55) ; s [50, 1, 51, 3, 52, 5, 53, 7, 54, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] >>> s[10:20:3] = range(100,150) ; s [50, 1, 51, 3, 52, 5, 53, 7, 54, 9, 100, 11, 12, 101, 14, 15, 102, 17, 18, 103] Tests: >>> v = pari(range(10)) ; v [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> v[:] = range(20, 30) >>> v [20, 21, 22, 23, 24, 25, 26, 27, 28, 29] >>> type(v[0]) <... 'cypari2.gen.Gen'> """ cdef Py_ssize_t i, j, step cdef Gen x = objtogen(y) cdef long l if isinstance(n, tuple): if typ(self.g) != t_MAT: raise TypeError("cannot index PARI type %s by tuple" % typ(self.g)) i, j = n if i < 0 or i >= glength(gel(self.g, 1)): raise IndexError("row i(=%s) must be between 0 and %s" % (i, self.nrows()-1)) if j < 0 or j >= glength(self.g): raise IndexError("column j(=%s) must be between 0 and %s" % (j, self.ncols()-1)) self.cache((i,j), x) set_gcoeff(self.g, i+1, j+1, x.g) return elif isinstance(n, slice): l = glength(self.g) inds = xrange(*n.indices(l)) k = len(inds) if k > len(y): raise ValueError("attempt to assign sequence of size %s to slice of size %s" % (len(y), k)) # actually set the values for a, b in enumerate(inds): sig_check() self[b] = y[a] return # Index is not a tuple or slice, convert to integer i = n if i < 0 or i >= glength(self.g): raise IndexError("index (%s) must be between 0 and %s" % (i, glength(self.g)-1)) # Add a reference to x to prevent Python from garbage # collecting x. self.cache(i, x) # Correct indexing for t_POLs if typ(self.g) == t_POL: i += 1 # Actually set the value set_gel(self.g, i+1, x.g) return def __len__(self): return glength(self.g) def __richcmp__(left, right, int op): """ Compare ``left`` and ``right`` using ``op``. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> a = pari(5) >>> b = 10 >>> a < b True >>> a <= b True >>> a <= 5 True >>> a > b False >>> a >= b False >>> a >= pari(10) False >>> a == 5 True >>> a is 5 False >>> pari(2.5) > None True >>> pari(3) == pari(3) True >>> pari('x^2 + 1') == pari('I-1') False >>> pari(I) == pari(I) True This does not define a total order. An error is raised when applying inequality operators to non-ordered types: >>> pari("Mod(1,3)") <= pari("Mod(2,3)") Traceback (most recent call last): ... PariError: forbidden comparison t_INTMOD , t_INTMOD >>> pari("[0]") <= pari("0") Traceback (most recent call last): ... PariError: forbidden comparison t_VEC (1 elts) , t_INT Tests: Check that :trac:`16127` has been fixed: >>> pari('1/2') < pari('1/3') False >>> pari(1) < pari('1/2') False >>> pari('O(x)') == 0 True >>> pari('O(2)') == 0 True """ cdef Gen t0, t1 try: t0 = objtogen(left) t1 = objtogen(right) except Exception: return NotImplemented cdef bint r cdef GEN x = t0.g cdef GEN y = t1.g sig_on() if op == Py_EQ: r = (gequal(x, y) != 0) elif op == Py_NE: r = (gequal(x, y) == 0) elif op == Py_LE: r = (gcmp(x, y) <= 0) elif op == Py_GE: r = (gcmp(x, y) >= 0) elif op == Py_LT: r = (gcmp(x, y) < 0) else: # Py_GT r = (gcmp(x, y) > 0) sig_off() return r def __cmp__(self, Gen other): """ Compare ``left`` and ``right``. This uses PARI's ``cmp_universal()`` routine, which defines a total ordering on the set of all PARI objects (up to the indistinguishability relation given by ``gidentical()``). .. WARNING:: This comparison is only mathematically meaningful when comparing 2 integers. In particular, when comparing rationals or reals, this does not correspond to the natural ordering. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> import sys >>> if sys.version_info.major == 2: ... assert cmp(pari(5), 5) == 0 ... assert cmp(pari(5), 10) == -1 ... assert cmp(pari(2.5), None) == 1 ... assert cmp(pari(3), pari(3)) == 0 ... assert cmp(pari('x^2 + 1'), pari('I-1')) == 1 ... I = pari('I') ... assert cmp(I, I) == 0 ... assert cmp(pari('2/3'), pari('2/5')) == -1 ... two = pari('2.000000000000000000000000') ... assert cmp(two, pari(1.0)) == 1 ... assert cmp(two, pari(2.0)) == 1 ... assert cmp(two, pari(3.0)) == 1 ... a = pari(0) ... b = pari("0*ffgen(ffinit(29, 10))") ... assert cmp(a, b) == -1 ... x = pari("x") ... y = pari("ffgen(ffinit(3, 5))") ... assert cmp(x, y) == 1 """ sig_on() cdef int r = cmp_universal(self.g, other.g) sig_off() return r def __copy__(self): sig_on() return new_gen(self.g) def __oct__(self): """ Return the octal digits of self in lower case. """ cdef GEN x cdef long lx cdef long *xp cdef long w cdef char *s cdef char *sp cdef char *octdigits = "01234567" cdef int i, j cdef int size x = self.g if typ(x) != t_INT: raise TypeError("gen must be of PARI type t_INT") if not signe(x): return "0" lx = lgefint(x) - 2 # number of words size = lx * 4 * sizeof(long) s = check_malloc(size+3) # 1 char for sign, 1 char for 0, 1 char for '\0' sp = s + size + 3 - 1 # last character sp[0] = 0 xp = int_LSW(x) for i from 0 <= i < lx: w = xp[0] for j in range(4*sizeof(long)): sp -= 1 sp[0] = octdigits[w & 7] w >>= 3 xp = int_nextW(xp) # remove leading zeros! while sp[0] == c'0': sp += 1 sp -= 1 sp[0] = c'0' if signe(x) < 0: sp -= 1 sp[0] = c'-' k = sp sig_free(s) return k def __hex__(self): """ Return the hexadecimal digits of self in lower case. """ cdef GEN x cdef long lx cdef long *xp cdef long w cdef char *s cdef char *sp cdef char *hexdigits = "0123456789abcdef" cdef int i, j cdef int size x = self.g if typ(x) != t_INT: raise TypeError("gen must be of PARI type t_INT") if not signe(x): return "0x0" lx = lgefint(x) - 2 # number of words size = lx*2*sizeof(long) s = check_malloc(size+4) # 1 char for sign, 2 chars for 0x, 1 char for '\0' sp = s + size + 4 - 1 # last character sp[0] = 0 xp = int_LSW(x) for i from 0 <= i < lx: w = xp[0] for j in range(2*sizeof(long)): sp -= 1 sp[0] = hexdigits[w & 15] w >>= 4 xp = int_nextW(xp) # remove leading zeros! while sp[0] == c'0': sp = sp + 1 sp -= 1 sp[0] = 'x' sp -= 1 sp[0] = '0' if signe(x) < 0: sp -= 1 sp[0] = c'-' k = sp sig_free(s) return k def __int__(self): """ Convert ``self`` to a Python integer. If the number is too large to fit into a Python ``int``, a Python ``long`` is returned instead. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> int(pari(0)) 0 >>> int(pari(10)) 10 >>> int(pari(-10)) -10 >>> int(pari(123456789012345678901234567890)) == 123456789012345678901234567890 True >>> int(pari(-123456789012345678901234567890)) == -123456789012345678901234567890 True >>> int(pari(2**31-1)) 2147483647 >>> int(pari(-2**31)) -2147483648 >>> int(pari("Pol(10)")) 10 >>> int(pari("Mod(2, 7)")) 2 >>> int(pari(2**63-1)) == 9223372036854775807 True >>> int(pari(2**63+2)) == 9223372036854775810 True """ return gen_to_integer(self) def __index__(self): """ Coerce ``self`` (which must be a :class:`Gen` of type ``t_INT``) to a Python integer. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> from operator import index >>> i = pari(2) >>> index(i) 2 >>> L = [0, 1, 2, 3, 4] >>> L[i] 2 >>> print(index(pari("2^100"))) 1267650600228229401496703205376 >>> index(pari("2.5")) Traceback (most recent call last): ... TypeError: cannot coerce 2.50000000000000 (type t_REAL) to integer >>> for i in [0,1,2,15,16,17,1213051238]: ... assert bin(pari(i)) == bin(i) ... assert bin(pari(-i)) == bin(-i) ... assert oct(pari(i)) == oct(i) ... assert oct(pari(-i)) == oct(-i) ... assert hex(pari(i)) == hex(i) ... assert hex(pari(-i)) == hex(-i) """ if typ(self.g) != t_INT: raise TypeError(f"cannot coerce {self!r} (type {self.type()}) to integer") return gen_to_integer(self) def python_list_small(self): """ Return a Python list of the PARI gens. This object must be of type t_VECSMALL, and the resulting list contains python 'int's. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> v=pari([1,2,3,10,102,10]).Vecsmall() >>> w = v.python_list_small() >>> w [1, 2, 3, 10, 102, 10] >>> type(w[0]) <... 'int'> """ cdef long n if typ(self.g) != t_VECSMALL: raise TypeError("Object (=%s) must be of type t_VECSMALL." % self) return [self.g[n+1] for n in range(glength(self.g))] def python_list(self): """ Return a Python list of the PARI gens. This object must be of type t_VEC or t_COL. INPUT: None OUTPUT: - ``list`` - Python list whose elements are the elements of the input gen. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> v = pari([1,2,3,10,102,10]) >>> w = v.python_list() >>> w [1, 2, 3, 10, 102, 10] >>> type(w[0]) <... 'cypari2.gen.Gen'> >>> pari("[1,2,3]").python_list() [1, 2, 3] >>> pari("[1,2,3]~").python_list() [1, 2, 3] """ cdef long n cdef Gen t if typ(self.g) != t_VEC and typ(self.g) != t_COL: raise TypeError("Object (=%s) must be of type t_VEC or t_COL." % self) return [self[n] for n in range(glength(self.g))] def python(self): """ Return the closest Python equivalent of the given PARI object. See :func:`~sage.libs.cypari.convert.gen_to_python` for more informations. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari('1.2').python() 1.2 >>> pari('389/17').python() Fraction(389, 17) """ from .convert import gen_to_python return gen_to_python(self) def sage(self, locals=None): r""" Return the closest SageMath equivalent of the given PARI object. INPUT: - ``locals`` -- optional dictionary used in fallback cases that involve ``sage_eval`` See :func:`~sage.libs.pari.convert_sage.gen_to_sage` for more information. """ from sage.libs.pari.convert_sage import gen_to_sage return gen_to_sage(self, locals) def __long__(self): """ Convert ``self`` to a Python ``long``. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> import sys >>> if sys.version_info.major == 3: ... long = int >>> assert isinstance(long(pari(0)), long) >>> assert long(pari(0)) == 0 >>> assert long(pari(10)) == 10 >>> assert long(pari(-10)) == -10 >>> assert long(pari(123456789012345678901234567890)) == 123456789012345678901234567890 >>> assert long(pari(-123456789012345678901234567890)) == -123456789012345678901234567890 >>> assert long(pari(2**31-1)) == 2147483647 >>> assert long(pari(-2**31)) == -2147483648 >>> assert long(pari("Pol(10)")) == 10 >>> assert long(pari("Mod(2, 7)")) == 2 """ x = gen_to_integer(self) if isinstance(x, long): return x else: return long(x) def __float__(self): """ Return Python float. """ cdef double d sig_on() d = gtodouble(self.g) sig_off() return d def __complex__(self): r""" Return ``self`` as a Python ``complex`` value. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> g = pari(-1.0)**(0.2); g 0.809016994374947 + 0.587785252292473*I >>> g.__complex__() (0.8090169943749475+0.5877852522924731j) >>> complex(g) (0.8090169943749475+0.5877852522924731j) >>> g = pari('Mod(3,5)'); g Mod(3, 5) >>> complex(g) Traceback (most recent call last): ... PariError: incorrect type in greal/gimag (t_INTMOD) """ cdef double re, im sig_on() re = gtodouble(greal(self.g)) im = gtodouble(gimag(self.g)) sig_off() return complex(re, im) def __nonzero__(self): """ Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari('1').__nonzero__() True >>> pari('x').__nonzero__() True >>> bool(pari(0)) False >>> a = pari('Mod(0,3)') >>> a.__nonzero__() False """ return not gequal0(self.g) def gequal(a, b): r""" Check whether `a` and `b` are equal using PARI's ``gequal``. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> a = pari(1); b = pari(1.0); c = pari('"some_string"') >>> a.gequal(a) True >>> b.gequal(b) True >>> c.gequal(c) True >>> a.gequal(b) True >>> a.gequal(c) False WARNING: this relation is not transitive: >>> a = pari('[0]'); b = pari(0); c = pari('[0,0]') >>> a.gequal(b) True >>> b.gequal(c) True >>> a.gequal(c) False """ cdef Gen t0 = objtogen(b) sig_on() cdef int ret = gequal(a.g, t0.g) sig_off() return ret != 0 def gequal0(a): r""" Check whether `a` is equal to zero. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(0).gequal0() True >>> pari(1).gequal0() False >>> pari(1e-100).gequal0() False >>> pari("0.0 + 0.0*I").gequal0() True >>> (pari('ffgen(3^20)')*0).gequal0() True """ sig_on() cdef int ret = gequal0(a.g) sig_off() return ret != 0 def gequal_long(a, long b): r""" Check whether `a` is equal to the ``long int`` `b` using PARI's ``gequalsg``. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> a = pari(1); b = pari(2.0); c = pari('3*matid(3)') >>> a.gequal_long(1) True >>> a.gequal_long(-1) False >>> a.gequal_long(0) False >>> b.gequal_long(2) True >>> b.gequal_long(-2) False >>> c.gequal_long(3) True >>> c.gequal_long(-3) False """ sig_on() cdef int ret = gequalsg(b, a.g) sig_off() return ret != 0 def isprime(self, long flag=0): """ isprime(x, flag=0): Returns True if x is a PROVEN prime number, and False otherwise. INPUT: - ``flag`` - int 0 (default): use a combination of algorithms. 1: certify primality using the Pocklington-Lehmer Test. 2: certify primality using the APRCL test. OUTPUT: - ``bool`` - True or False Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(9).isprime() False >>> pari(17).isprime() True >>> n = pari(561) # smallest Carmichael number >>> n.isprime() # not just a pseudo-primality test! False >>> n.isprime(1) False >>> n.isprime(2) False >>> n = pari(2**31-1) >>> n.isprime(1) (True, [2, 3, 1; 3, 5, 1; 7, 3, 1; 11, 3, 1; 31, 2, 1; 151, 3, 1; 331, 3, 1]) """ cdef GEN x sig_on() x = gisprime(self.g, flag) if typ(x) != t_INT: # case flag=1 with prime input: x is the certificate return True, new_gen(x) else: sig_off() return signe(x) != 0 def ispseudoprime(self, long flag=0): """ ispseudoprime(x, flag=0): Returns True if x is a pseudo-prime number, and False otherwise. INPUT: - ``flag`` - int 0 (default): checks whether x is a Baillie-Pomerance-Selfridge-Wagstaff pseudo prime (strong Rabin-Miller pseudo prime for base 2, followed by strong Lucas test for the sequence (P,-1), P smallest positive integer such that `P^2 - 4` is not a square mod x). 0: checks whether x is a strong Miller-Rabin pseudo prime for flag randomly chosen bases (with end-matching to catch square roots of -1). OUTPUT: - ``bool`` - True or False, or when flag=1, either False or a tuple (True, cert) where ``cert`` is a primality certificate. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(9).ispseudoprime() False >>> pari(17).ispseudoprime() True >>> n = pari(561) # smallest Carmichael number >>> n.ispseudoprime(2) False """ sig_on() cdef long t = ispseudoprime(self.g, flag) sig_off() return t != 0 def ispower(self, k=None): r""" Determine whether or not self is a perfect k-th power. If k is not specified, find the largest k so that self is a k-th power. INPUT: - ``k`` - int (optional) OUTPUT: - ``power`` - int, what power it is - ``g`` - what it is a power of Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(9).ispower() (2, 3) >>> pari(17).ispower() (1, 17) >>> pari(17).ispower(2) (False, None) >>> pari(17).ispower(1) (1, 17) >>> pari(2).ispower() (1, 2) """ cdef int n cdef GEN x cdef Gen t0 if k is None: sig_on() n = gisanypower(self.g, &x) if n == 0: sig_off() return 1, self else: return n, new_gen(x) else: t0 = objtogen(k) sig_on() n = ispower(self.g, t0.g, &x) if n == 0: sig_off() return False, None else: return k, new_gen(x) def isprimepower(self): r""" Check whether ``self`` is a prime power (with an exponent >= 1). INPUT: - ``self`` - A PARI integer OUTPUT: A tuple ``(k, p)`` where `k` is a Python integer and `p` a PARI integer. - If the input was a prime power, `p` is the prime and `k` the power. - Otherwise, `k = 0` and `p` is ``self``. .. SEEALSO:: If you don't need a proof that `p` is prime, you can use :meth:`ispseudoprimepower` instead. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(9).isprimepower() (2, 3) >>> pari(17).isprimepower() (1, 17) >>> pari(18).isprimepower() (0, 18) >>> pari(3**12345).isprimepower() (12345, 3) """ cdef GEN x cdef long n sig_on() n = isprimepower(self.g, &x) if n == 0: sig_off() return 0, self else: return n, new_gen(x) def ispseudoprimepower(self): r""" Check whether ``self`` is the power (with an exponent >= 1) of a pseudo-prime. INPUT: - ``self`` - A PARI integer OUTPUT: A tuple ``(k, p)`` where `k` is a Python integer and `p` a PARI integer. - If the input was a pseudoprime power, `p` is the pseudoprime and `k` the power. - Otherwise, `k = 0` and `p` is ``self``. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(3**12345).ispseudoprimepower() (12345, 3) >>> p = pari(2**1500 + 1465) # nextprime(2^1500) >>> (p**11).ispseudoprimepower()[0] # very fast 11 """ cdef GEN x cdef long n sig_on() n = ispseudoprimepower(self.g, &x) if n == 0: sig_off() return 0, self else: return n, new_gen(x) def vecmax(x): """ Return the maximum of the elements of the vector/matrix `x`. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari([1, '-5/3', 8.0]).vecmax() 8.00000000000000 """ sig_on() return new_gen(vecmax(x.g)) def vecmin(x): """ Return the minimum of the elements of the vector/matrix `x`. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari([1, '-5/3', 8.0]).vecmin() -5/3 """ sig_on() return new_gen(vecmin(x.g)) def Col(x, long n = 0): """ Transform the object `x` into a column vector with minimal size `|n|`. INPUT: - ``x`` -- gen - ``n`` -- Make the column vector of minimal length `|n|`. If `n > 0`, append zeros; if `n < 0`, prepend zeros. OUTPUT: A PARI column vector (type ``t_COL``) Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(1.5).Col() [1.50000000000000]~ >>> pari([1,2,3,4]).Col() [1, 2, 3, 4]~ >>> pari('[1,2; 3,4]').Col() [[1, 2], [3, 4]]~ >>> pari('"CyPari"').Col() ["C", "y", "P", "a", "r", "i"]~ >>> pari('x + 3*x^3').Col() [3, 0, 1, 0]~ >>> pari('x + 3*x^3 + O(x^5)').Col() [1, 0, 3, 0]~ We demonstate the `n` argument: >>> pari([1,2,3,4]).Col(2) [1, 2, 3, 4]~ >>> pari([1,2,3,4]).Col(-2) [1, 2, 3, 4]~ >>> pari([1,2,3,4]).Col(6) [1, 2, 3, 4, 0, 0]~ >>> pari([1,2,3,4]).Col(-6) [0, 0, 1, 2, 3, 4]~ See also :meth:`Vec` (create a row vector) for more examples and :meth:`Colrev` (create a column in reversed order). """ sig_on() return new_gen(_Vec_append(gtocol(x.g), gen_0, n)) def Colrev(x, long n = 0): """ Transform the object `x` into a column vector with minimal size `|n|`. The order of the resulting vector is reversed compared to :meth:`Col`. INPUT: - ``x`` -- gen - ``n`` -- Make the vector of minimal length `|n|`. If `n > 0`, prepend zeros; if `n < 0`, append zeros. OUTPUT: A PARI column vector (type ``t_COL``) Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(1.5).Colrev() [1.50000000000000]~ >>> pari([1,2,3,4]).Colrev() [4, 3, 2, 1]~ >>> pari('[1,2; 3,4]').Colrev() [[3, 4], [1, 2]]~ >>> pari('x + 3*x^3').Colrev() [0, 1, 0, 3]~ We demonstate the `n` argument: >>> pari([1,2,3,4]).Colrev(2) [4, 3, 2, 1]~ >>> pari([1,2,3,4]).Colrev(-2) [4, 3, 2, 1]~ >>> pari([1,2,3,4]).Colrev(6) [0, 0, 4, 3, 2, 1]~ >>> pari([1,2,3,4]).Colrev(-6) [4, 3, 2, 1, 0, 0]~ """ sig_on() # Create a non-reversed column vector cdef GEN v = _Vec_append(gtocol(x.g), gen_0, n) # Reverse it in-place cdef GEN L = v + 1 cdef GEN R = v + (lg(v)-1) cdef long t while (L < R): t = L[0] L[0] = R[0] R[0] = t L += 1 R -= 1 return new_gen(v) def Ser(f, v=None, long precision=-1): """ Return a power series or Laurent series in the variable `v` constructed from the object `f`. INPUT: - ``f`` -- PARI gen - ``v`` -- PARI variable (default: `x`) - ``precision`` -- the desired relative precision (default: the value returned by ``pari.get_series_precision()``). This is the absolute precision minus the `v`-adic valuation. OUTPUT: - PARI object of type ``t_SER`` The series is constructed from `f` in the following way: - If `f` is a scalar, a constant power series is returned. - If `f` is a polynomial, it is converted into a power series in the obvious way. - If `f` is a rational function, it will be expanded in a Laurent series around `v = 0`. - If `f` is a vector, its coefficients become the coefficients of the power series, starting from the constant term. This is the convention used by the function ``Polrev()``, and the reverse of that used by ``Pol()``. .. warning:: This function will not transform objects containing variables of higher priority than `v`. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(2).Ser() 2 + O(x^16) >>> pari('Mod(0, 7)').Ser() Mod(0, 7)*x^15 + O(x^16) >>> x = pari([1, 2, 3, 4, 5]) >>> x.Ser() 1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 + O(x^16) >>> f = x.Ser('v'); print(f) 1 + 2*v + 3*v^2 + 4*v^3 + 5*v^4 + O(v^16) >>> pari(1)/f 1 - 2*v + v^2 + 6*v^5 - 17*v^6 + 16*v^7 - 5*v^8 + 36*v^10 - 132*v^11 + 181*v^12 - 110*v^13 + 25*v^14 + 216*v^15 + O(v^16) >>> pari('x^5').Ser(precision=20) x^5 + O(x^25) >>> pari('1/x').Ser(precision=1) x^-1 + O(x^0) """ if precision < 0: precision = precdl # Global PARI series precision sig_on() cdef long vn = get_var(v) if typ(f.g) == t_VEC: # The precision flag is ignored for vectors, so we first # convert the vector to a polynomial. return new_gen(gtoser(gtopolyrev(f.g, vn), vn, precision)) else: return new_gen(gtoser(f.g, vn, precision)) def Str(self): """ Str(self): Return the print representation of self as a PARI object. INPUT: - ``self`` - gen OUTPUT: - ``gen`` - a PARI Gen of type t_STR, i.e., a PARI string Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari([1,2,['abc',1]]).Str() "[1, 2, [abc, 1]]" >>> pari([1,1, 1.54]).Str() "[1, 1, 1.54000000000000]" >>> pari(1).Str() # 1 is automatically converted to string rep "1" >>> x = pari('x') # PARI variable "x" >>> x.Str() # is converted to string rep. "x" >>> x.Str().type() 't_STR' """ cdef char* c sig_on() # Use sig_block(), which is needed because GENtostr() uses # malloc(), which is dangerous inside sig_on() sig_block() c = GENtostr(self.g) sig_unblock() v = new_gen(strtoGENstr(c)) pari_free(c) return v def Strexpand(x): """ Concatenate the entries of the vector `x` into a single string, then perform tilde expansion and environment variable expansion similar to shells. INPUT: - ``x`` -- PARI gen. Either a vector or an element which is then treated like `[x]`. OUTPUT: - PARI string (type ``t_STR``) Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari('"~/subdir"').Strexpand() "..." >>> pari('"$SHELL"').Strexpand() "..." Tests: >>> a = pari('"$HOME"') >>> a.Strexpand() != a True """ if typ(x.g) != t_VEC: x = list_of_Gens_to_Gen([x]) sig_on() return new_gen(Strexpand(x.g)) def Strtex(x): r""" Strtex(x): Translates the vector x of PARI gens to TeX format and returns the resulting concatenated strings as a PARI t_STR. INPUT: - ``x`` -- PARI gen. Either a vector or an element which is then treated like `[x]`. OUTPUT: - PARI string (type ``t_STR``) Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> v = pari('x^2') >>> v.Strtex() "x^2" >>> v = pari(['1/x^2','x']) >>> v.Strtex() "\\frac{1}{x^2}x" >>> v = pari(['1 + 1/x + 1/(y+1)','x-1']) >>> v.Strtex() "\\frac{ \\left(y\n + 2\\right) \\*x\n + \\left(y\n + 1\\right) }{ \\left(y\n + 1\\right) \\*x}x\n - 1" """ if typ(x.g) != t_VEC: x = list_of_Gens_to_Gen([x]) sig_on() return new_gen(Strtex(x.g)) def Vec(x, long n = 0): """ Transform the object `x` into a vector with minimal size `|n|`. INPUT: - ``x`` -- gen - ``n`` -- Make the vector of minimal length `|n|`. If `n > 0`, append zeros; if `n < 0`, prepend zeros. OUTPUT: A PARI vector (type ``t_VEC``) Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(1).Vec() [1] >>> pari('x^3').Vec() [1, 0, 0, 0] >>> pari('x^3 + 3*x - 2').Vec() [1, 0, 3, -2] >>> pari([1,2,3]).Vec() [1, 2, 3] >>> pari('[1, 2; 3, 4]').Vec() [[1, 3]~, [2, 4]~] >>> pari('"CyPari"').Vec() ["C", "y", "P", "a", "r", "i"] >>> pari('2*x^2 + 3*x^3 + O(x^5)').Vec() [2, 3, 0] >>> pari('2*x^-2 + 3*x^3 + O(x^5)').Vec() [2, 0, 0, 0, 0, 3, 0] Note the different term ordering for polynomials and series: >>> pari('1 + x + 3*x^3 + O(x^5)').Vec() [1, 1, 0, 3, 0] >>> pari('1 + x + 3*x^3').Vec() [3, 0, 1, 1] We demonstate the `n` argument: >>> pari([1,2,3,4]).Vec(2) [1, 2, 3, 4] >>> pari([1,2,3,4]).Vec(-2) [1, 2, 3, 4] >>> pari([1,2,3,4]).Vec(6) [1, 2, 3, 4, 0, 0] >>> pari([1,2,3,4]).Vec(-6) [0, 0, 1, 2, 3, 4] See also :meth:`Col` (create a column vector) and :meth:`Vecrev` (create a vector in reversed order). """ sig_on() return new_gen(_Vec_append(gtovec(x.g), gen_0, n)) def Vecrev(x, long n = 0): """ Transform the object `x` into a vector with minimal size `|n|`. The order of the resulting vector is reversed compared to :meth:`Vec`. INPUT: - ``x`` -- gen - ``n`` -- Make the vector of minimal length `|n|`. If `n > 0`, prepend zeros; if `n < 0`, append zeros. OUTPUT: A PARI vector (type ``t_VEC``) Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(1).Vecrev() [1] >>> pari('x^3').Vecrev() [0, 0, 0, 1] >>> pari('x^3 + 3*x - 2').Vecrev() [-2, 3, 0, 1] >>> pari([1, 2, 3]).Vecrev() [3, 2, 1] >>> pari('Col([1, 2, 3])').Vecrev() [3, 2, 1] >>> pari('[1, 2; 3, 4]').Vecrev() [[2, 4]~, [1, 3]~] >>> pari('"CyPari"').Vecrev() ["i", "r", "a", "P", "y", "C"] We demonstate the `n` argument: >>> pari([1,2,3,4]).Vecrev(2) [4, 3, 2, 1] >>> pari([1,2,3,4]).Vecrev(-2) [4, 3, 2, 1] >>> pari([1,2,3,4]).Vecrev(6) [0, 0, 4, 3, 2, 1] >>> pari([1,2,3,4]).Vecrev(-6) [4, 3, 2, 1, 0, 0] """ sig_on() return new_gen(_Vec_append(gtovecrev(x.g), gen_0, -n)) def Vecsmall(x, long n = 0): """ Transform the object `x` into a ``t_VECSMALL`` with minimal size `|n|`. INPUT: - ``x`` -- gen - ``n`` -- Make the vector of minimal length `|n|`. If `n > 0`, append zeros; if `n < 0`, prepend zeros. OUTPUT: A PARI vector of small integers (type ``t_VECSMALL``) Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari([1,2,3]).Vecsmall() Vecsmall([1, 2, 3]) >>> pari('"CyPari"').Vecsmall() Vecsmall([67, 121, 80, 97, 114, 105]) >>> pari(1234).Vecsmall() Vecsmall([1234]) >>> pari('x^2 + 2*x + 3').Vecsmall() Vecsmall([1, 2, 3]) We demonstate the `n` argument: >>> pari([1,2,3]).Vecsmall(2) Vecsmall([1, 2, 3]) >>> pari([1,2,3]).Vecsmall(-2) Vecsmall([1, 2, 3]) >>> pari([1,2,3]).Vecsmall(6) Vecsmall([1, 2, 3, 0, 0, 0]) >>> pari([1,2,3]).Vecsmall(-6) Vecsmall([0, 0, 0, 1, 2, 3]) """ sig_on() return new_gen(_Vec_append(gtovecsmall(x.g), 0, n)) def bittest(x, long n): """ bittest(x, long n): Returns bit number n (coefficient of `2^n` in binary) of the integer x. Negative numbers behave as if modulo a big power of 2. INPUT: - ``x`` - Gen (pari integer) OUTPUT: - ``bool`` - a Python bool Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> x = pari(6) >>> x.bittest(0) False >>> x.bittest(1) True >>> x.bittest(2) True >>> x.bittest(3) False >>> pari(-3).bittest(0) True >>> pari(-3).bittest(1) False >>> [pari(-3).bittest(n) for n in range(10)] [True, False, True, True, True, True, True, True, True, True] """ sig_on() cdef long b = bittest(x.g, n) sig_off() return b != 0 lift_centered = Gen_auto.centerlift def padicprime(x): """ The uniformizer of the p-adic ring this element lies in, as a t_INT. INPUT: - ``x`` - gen, of type t_PADIC OUTPUT: - ``p`` - gen, of type t_INT Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> y = pari('11^-10 + 5*11^-7 + 11^-6 + O(11)') >>> y.padicprime() 11 >>> y.padicprime().type() 't_INT' """ sig_on() return new_gen(gel(x.g, 2)) def precision(x, long n=-1): """ Change the precision of `x` to be `n`, where `n` is an integer. If `n` is omitted, output the real precision of `x`. INPUT: - ``x`` - gen - ``n`` - (optional) int OUTPUT: gen """ if n <= 0: return precision(x.g) sig_on() return new_gen(precision0(x.g, n)) def round(x, estimate=False): """ round(x,estimate=False): If x is a real number, returns x rounded to the nearest integer (rounding up). If the optional argument estimate is True, also returns the binary exponent e of the difference between the original and the rounded value (the "fractional part") (this is the integer ceiling of log_2(error)). When x is a general PARI object, this function returns the result of rounding every coefficient at every level of PARI object. Note that this is different than what the truncate function does (see the example below). One use of round is to get exact results after a long approximate computation, when theory tells you that the coefficients must be integers. INPUT: - ``x`` - gen - ``estimate`` - (optional) bool, False by default OUTPUT: - if estimate is False, return a single gen. - if estimate is True, return rounded version of x and error estimate in bits, both as gens. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari('1.5').round() 2 >>> pari('1.5').round(True) (2, -1) >>> pari('1.5 + 2.1*I').round() 2 + 2*I >>> pari('1.0001').round(True) (1, -14) >>> pari('(2.4*x^2 - 1.7)/x').round() (2*x^2 - 2)/x >>> pari('(2.4*x^2 - 1.7)/x').truncate() 2.40000000000000*x """ cdef int n cdef long e cdef Gen y sig_on() if not estimate: return new_gen(ground(x.g)) y = new_gen(grndtoi(x.g, &e)) return y, e def sizeword(x): """ Return the total number of machine words occupied by the complete tree of the object x. A machine word is 32 or 64 bits, depending on the computer. INPUT: - ``x`` - gen OUTPUT: int (a Python int) Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari('0').sizeword() 2 >>> pari('1').sizeword() 3 >>> pari('1000000').sizeword() 3 >>> import sys >>> bitness = '64' if sys.maxsize > (1 << 32) else '32' >>> pari('10^100').sizeword() == (13 if bitness == '32' else 8) True >>> pari(1.0).sizeword() == (4 if bitness == '32' else 3) True >>> pari('x + 1').sizeword() 10 >>> pari('[x + 1, 1]').sizeword() 16 """ return gsizeword(x.g) def sizebyte(x): """ Return the total number of bytes occupied by the complete tree of the object x. Note that this number depends on whether the computer is 32-bit or 64-bit. INPUT: - ``x`` - gen OUTPUT: int (a Python int) Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> import sys >>> bitness = '64' if sys.maxsize > (1 << 32) else '32' >>> pari('1').sizebyte() == (12 if bitness == '32' else 24) True """ return gsizebyte(x.g) def truncate(x, estimate=False): """ truncate(x,estimate=False): Return the truncation of x. If estimate is True, also return the number of error bits. When x is in the real numbers, this means that the part after the decimal point is chopped away, e is the binary exponent of the difference between the original and truncated value (the "fractional part"). If x is a rational function, the result is the integer part (Euclidean quotient of numerator by denominator) and if requested the error estimate is 0. When truncate is applied to a power series (in X), it transforms it into a polynomial or a rational function with denominator a power of X, by chopping away the `O(X^k)`. Similarly, when applied to a p-adic number, it transforms it into an integer or a rational number by chopping away the `O(p^k)`. INPUT: - ``x`` - gen - ``estimate`` - (optional) bool, which is False by default OUTPUT: - if estimate is False, return a single gen. - if estimate is True, return rounded version of x and error estimate in bits, both as gens. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari('(x^2+1)/x').round() (x^2 + 1)/x >>> pari('(x^2+1)/x').truncate() x >>> pari('1.043').truncate() 1 >>> pari('1.043').truncate(True) (1, -5) >>> pari('1.6').truncate() 1 >>> pari('1.6').round() 2 >>> pari('1/3 + 2 + 3^2 + O(3^3)').truncate() 34/3 >>> pari('sin(x+O(x^10))').truncate() 1/362880*x^9 - 1/5040*x^7 + 1/120*x^5 - 1/6*x^3 + x >>> pari('sin(x+O(x^10))').round() # each coefficient has abs < 1 x + O(x^10) """ cdef long e cdef Gen y sig_on() if not estimate: return new_gen(gtrunc(x.g)) y = new_gen(gcvtoi(x.g, &e)) return y, e def _valp(x): """ Return the valuation of x where x is a p-adic number (t_PADIC) or a Laurent series (t_SER). If x is a different type, this will give a bogus number. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari('1/x^2 + O(x^10)')._valp() -2 >>> pari('O(x^10)')._valp() 10 >>> pari('(1145234796 + O(3^10))/771966234')._valp() -2 >>> pari('O(2^10)')._valp() 10 """ # This is a simple macro, so we don't need sig_on() return valp(x.g) def bernfrac(self): r""" The Bernoulli number `B_x`, where `B_0 = 1`, `B_1 = -1/2`, `B_2 = 1/6,\ldots,` expressed as a rational number. The argument `x` should be of type integer. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(18).bernfrac() 43867/798 >>> [pari(n).bernfrac() for n in range(10)] [1, -1/2, 1/6, 0, -1/30, 0, 1/42, 0, -1/30, 0] """ sig_on() return new_gen(bernfrac(self)) def bernreal(self, unsigned long precision=0): r""" The Bernoulli number `B_x`, as for the function bernfrac, but `B_x` is returned as a real number (with the current precision). Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(18).bernreal() 54.9711779448622 """ sig_on() return new_gen(bernreal(self, prec_bits_to_words(precision))) def besselk(nu, x, unsigned long precision=0): """ nu.besselk(x): K-Bessel function (modified Bessel function of the second kind) of index nu, which can be complex, and argument x. If `nu` or `x` is an exact argument, it is first converted to a real or complex number using the optional parameter precision (in bits). If the arguments are inexact (e.g. real), the smallest of their precisions is used in the computation, and the parameter precision is ignored. INPUT: - ``nu`` - a complex number - ``x`` - real number (positive or negative) Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(complex(2, 1)).besselk(3) 0.0455907718407551 + 0.0289192946582081*I >>> pari(complex(2, 1)).besselk(-3) -4.34870874986752 - 5.38744882697109*I >>> pari(complex(2, 1)).besselk(300) 3.74224603319728 E-132 + 2.49071062641525 E-134*I """ cdef Gen t0 = objtogen(x) sig_on() return new_gen(kbessel(nu.g, t0.g, prec_bits_to_words(precision))) def eint1(x, long n=0, unsigned long precision=0): r""" x.eint1(n): exponential integral E1(x): .. MATH:: \int_{x}^{\infty} \frac{e^{-t}}{t} dt If n is present, output the vector [eint1(x), eint1(2\*x), ..., eint1(n\*x)]. This is faster than repeatedly calling eint1(i\*x). If `x` is an exact argument, it is first converted to a real or complex number using the optional parameter precision (in bits). If `x` is inexact (e.g. real), its own precision is used in the computation, and the parameter precision is ignored. REFERENCE: - See page 262, Prop 5.6.12, of Cohen's book "A Course in Computational Algebraic Number Theory". Examples: """ sig_on() if n <= 0: return new_gen(eint1(x.g, prec_bits_to_words(precision))) else: return new_gen(veceint1(x.g, stoi(n), prec_bits_to_words(precision))) log_gamma = Gen_auto.lngamma def polylog(x, long m, long flag=0, unsigned long precision=0): """ x.polylog(m,flag=0): m-th polylogarithm of x. flag is optional, and can be 0: default, 1: D_m -modified m-th polylog of x, 2: D_m-modified m-th polylog of x, 3: P_m-modified m-th polylog of x. If `x` is an exact argument, it is first converted to a real or complex number using the optional parameter precision (in bits). If `x` is inexact (e.g. real), its own precision is used in the computation, and the parameter precision is ignored. TODO: Add more explanation, copied from the PARI manual. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(10).polylog(3) 5.64181141475134 - 8.32820207698027*I >>> pari(10).polylog(3,0) 5.64181141475134 - 8.32820207698027*I >>> pari(10).polylog(3,1) 0.523778453502411 >>> pari(10).polylog(3,2) -0.400459056163451 """ sig_on() return new_gen(polylog0(m, x.g, flag, prec_bits_to_words(precision))) def sqrtn(x, n, unsigned long precision=0): r""" x.sqrtn(n): return the principal branch of the n-th root of x, i.e., the one such that `\arg(\sqrt(x)) \in ]-\pi/n, \pi/n]`. Also returns a second argument which is a suitable root of unity allowing one to recover all the other roots. If it was not possible to find such a number, then this second return value is 0. If the argument is present and no square root exists, return 0 instead of raising an error. If `x` is an exact argument, it is first converted to a real or complex number using the optional parameter precision (in bits). If `x` is inexact (e.g. real), its own precision is used in the computation, and the parameter precision is ignored. .. NOTE:: intmods (modulo a prime) and `p`-adic numbers are allowed as arguments. INPUT: - ``x`` - gen - ``n`` - integer OUTPUT: - ``gen`` - principal n-th root of x - ``gen`` - root of unity z that gives the other roots Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> s, z = pari(2).sqrtn(5) >>> z 0.309016994374947 + 0.951056516295154*I >>> s 1.14869835499704 >>> s**5 2.00000000000000 >>> (s*z)**5 2.00000000000000 + 0.E-19*I >>> import sys >>> bitness = '64' if sys.maxsize > (1 << 32) else '32' >>> s = str(z**5) >>> s == ('1.00000000000000 - 2.710505431 E-20*I' if bitness == '32' else '1.00000000000000 - 2.71050543121376 E-20*I') True """ cdef GEN zetan cdef Gen t0 = objtogen(n) sig_on() ans = new_gen_noclear(gsqrtn(x.g, t0.g, &zetan, prec_bits_to_words(precision))) return ans, new_gen(zetan) def ffprimroot(self): r""" Return a primitive root of the multiplicative group of the definition field of the given finite field element. INPUT: - ``self`` -- a PARI finite field element (``FFELT``) OUTPUT: - A generator of the multiplicative group of the finite field generated by ``self``. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> b = pari(9).ffgen().ffprimroot() >>> b.fforder() 8 """ sig_on() return new_gen(ffprimroot(self.g, NULL)) def fibonacci(self): r""" Return the Fibonacci number of index x. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(18).fibonacci() 2584 >>> [pari(n).fibonacci() for n in range(10)] [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] """ sig_on() return new_gen(fibo(self)) def issquare(x, find_root=False): """ issquare(x,n): ``True`` if x is a square, ``False`` if not. If ``find_root`` is given, also returns the exact square root. """ cdef GEN G cdef long t cdef Gen g sig_on() if find_root: t = itos(gissquareall(x.g, &G)) if t: return True, new_gen(G) else: clear_stack() return False, None else: t = itos(gissquare(x.g)) sig_off() return t != 0 def issquarefree(self): """ Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(10).issquarefree() True >>> pari(20).issquarefree() False """ sig_on() cdef long t = issquarefree(self.g) sig_off() return t != 0 def sumdiv(n): """ Return the sum of the divisors of `n`. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(10).sumdiv() 18 """ sig_on() return new_gen(sumdiv(n.g)) def sumdivk(n, long k): """ Return the sum of the k-th powers of the divisors of n. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(10).sumdivk(2) 130 """ sig_on() return new_gen(sumdivk(n.g, k)) def Zn_issquare(self, n): """ Return ``True`` if ``self`` is a square modulo `n`, ``False`` if not. INPUT: - ``self`` -- integer - ``n`` -- integer or factorisation matrix Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(3).Zn_issquare(4) False >>> pari(4).Zn_issquare(pari(30).factor()) True """ cdef Gen t0 = objtogen(n) sig_on() cdef long t = Zn_issquare(self.g, t0.g) sig_off() return t != 0 def Zn_sqrt(self, n): """ Return a square root of ``self`` modulo `n`, if such a square root exists; otherwise, raise a ``ValueError``. INPUT: - ``self`` -- integer - ``n`` -- integer or factorisation matrix Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(3).Zn_sqrt(4) Traceback (most recent call last): ... ValueError: 3 is not a square modulo 4 >>> pari(4).Zn_sqrt(pari(30).factor()) 22 """ cdef Gen t0 = objtogen(n) cdef GEN s sig_on() s = Zn_sqrt(self.g, t0.g) if s == NULL: sig_off() raise ValueError("%s is not a square modulo %s" % (self, n)) return new_gen(s) def ellan(self, long n, python_ints=False): """ Return the first `n` Fourier coefficients of the modular form attached to this elliptic curve. See ellak for more details. INPUT: - ``n`` - a long integer - ``python_ints`` - bool (default is False); if True, return a list of Python ints instead of a PARI Gen wrapper. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> e = pari([0, -1, 1, -10, -20]).ellinit() >>> e.ellan(3) [1, -2, -1] >>> e.ellan(20) [1, -2, -1, 2, 1, 2, -2, 0, -2, -2, 1, -2, 4, 4, -1, -4, -2, 4, 0, 2] >>> e.ellan(-1) [] >>> v = e.ellan(10, python_ints=True); v [1, -2, -1, 2, 1, 2, -2, 0, -2, -2] >>> type(v) <... 'list'> >>> type(v[0]) <... 'int'> """ sig_on() cdef GEN g = ellan(self.g, n) if python_ints: v = [gtolong(gel(g, i+1)) for i in range(glength(g))] clear_stack() return v else: return new_gen(g) def ellaplist(self, long n, python_ints=False): r""" e.ellaplist(n): Returns a PARI list of all the prime-indexed coefficients `a_p` (up to n) of the `L`-function of the elliptic curve `e`, i.e. the Fourier coefficients of the newform attached to `e`. INPUT: - ``self`` -- an elliptic curve - ``n`` -- a long integer - ``python_ints`` -- bool (default is False); if True, return a list of Python ints instead of a PARI Gen wrapper. .. WARNING:: The curve e must be a medium or long vector of the type given by ellinit. For this function to work for every n and not just those prime to the conductor, e must be a minimal Weierstrass equation. If this is not the case, use the function ellminimalmodel first before using ellaplist (or you will get INCORRECT RESULTS!) Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> e = pari([0, -1, 1, -10, -20]).ellinit() >>> v = e.ellaplist(10); v [-2, -1, 1, -2] >>> type(v) <... 'cypari2.gen.Gen'> >>> v.type() 't_VEC' >>> e.ellan(10) [1, -2, -1, 2, 1, 2, -2, 0, -2, -2] >>> v = e.ellaplist(10, python_ints=True); v [-2, -1, 1, -2] >>> type(v) <... 'list'> >>> type(v[0]) <... 'int'> Tests: >>> v = e.ellaplist(1) >>> v, type(v) ([], <... 'cypari2.gen.Gen'>) >>> v = e.ellaplist(1, python_ints=True) >>> v, type(v) ([], <... 'list'>) """ if python_ints: return [int(x) for x in self.ellaplist(n)] sig_on() if n < 2: return new_gen(zerovec(0)) # Make a table of primes up to n: this returns a t_VECSMALL # that we artificially change to a t_VEC cdef GEN g = primes_upto_zv(n) settyp(g, t_VEC) # Replace each prime in the table by ellap of it cdef long i cdef GEN curve = self.g for i in range(1, lg(g)): set_gel(g, i, ellap(curve, utoi(g[i]))) return new_gen(g) def ellisoncurve(self, x): """ e.ellisoncurve(x): return True if the point x is on the elliptic curve e, False otherwise. If the point or the curve have inexact coefficients, an attempt is made to take this into account. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> e = pari([0,1,1,-2,0]).ellinit() >>> e.ellisoncurve([1,0]) True >>> e.ellisoncurve([1,1]) False >>> e.ellisoncurve([1,0.00000000000000001]) False >>> e.ellisoncurve([1,0.000000000000000001]) True >>> e.ellisoncurve([0]) True """ cdef Gen t0 = objtogen(x) sig_on() cdef int t = oncurve(self.g, t0.g) sig_off() return t != 0 def ellminimalmodel(self): """ ellminimalmodel(e): return the standard minimal integral model of the rational elliptic curve e and the corresponding change of variables. INPUT: - ``e`` - Gen (that defines an elliptic curve) OUTPUT: - ``gen`` - minimal model - ``gen`` - change of coordinates Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> e = pari([1,2,3,4,5]).ellinit() >>> F, ch = e.ellminimalmodel() >>> F[:5] [1, -1, 0, 4, 3] >>> ch [1, -1, 0, -1] >>> e.ellchangecurve(ch)[:5] [1, -1, 0, 4, 3] """ cdef GEN x, y cdef Gen model, change cdef pari_sp t sig_on() x = ellminimalmodel(self.g, &y) change = new_gen_noclear(y) model = new_gen(x) return model, change def elltors(self): """ Return information about the torsion subgroup of the given elliptic curve. INPUT: - ``e`` - elliptic curve over `\QQ` OUTPUT: - ``gen`` - the order of the torsion subgroup, a.k.a. the number of points of finite order - ``gen`` - vector giving the structure of the torsion subgroup as a product of cyclic groups, sorted in non-increasing order - ``gen`` - vector giving points on e generating these cyclic groups Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> e = pari([1,0,1,-19,26]).ellinit() >>> e.elltors() [12, [6, 2], [[1, 2], [3, -2]]] """ sig_on() return new_gen(elltors(self.g)) def omega(self, unsigned long precision=0): """ Return the basis for the period lattice of this elliptic curve. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> e = pari([0, -1, 1, -10, -20]).ellinit() >>> e.omega() [1.26920930427955, 0.634604652139777 - 1.45881661693850*I] """ sig_on() return new_gen(ellR_omega(self.g, prec_bits_to_words(precision))) def disc(self): """ Return the discriminant of this object. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> e = pari([0, -1, 1, -10, -20]).ellinit() >>> e.disc() -161051 >>> _.factor() [-1, 1; 11, 5] """ sig_on() return new_gen(member_disc(self.g)) def j(self): """ Return the j-invariant of this object. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> e = pari([0, -1, 1, -10, -20]).ellinit() >>> e.j() -122023936/161051 >>> _.factor() [-1, 1; 2, 12; 11, -5; 31, 3] """ sig_on() return new_gen(member_j(self.g)) def _eltabstorel(self, x): """ Return the relative number field element corresponding to `x`. The result is a ``t_POLMOD`` with ``t_POLMOD`` coefficients. .. WARNING:: This is a low-level version of :meth:`rnfeltabstorel` that only needs the output of :meth:`_nf_rnfeq`, not a full PARI ``rnf`` structure. This method may raise errors or return undefined results if called with invalid arguments. Tests: >>> from cypari2 import Pari >>> pari = Pari() >>> K = pari('y^2 + 1').nfinit() >>> rnfeq = K._nf_rnfeq('x^2 + 2') >>> f_abs = rnfeq[0]; f_abs x^4 + 6*x^2 + 1 >>> x_rel = rnfeq._eltabstorel('x'); x_rel Mod(x + Mod(-y, y^2 + 1), x^2 + 2) >>> f_abs(x_rel) Mod(0, x^2 + 2) """ cdef Gen t0 = objtogen(x) sig_on() return new_gen(eltabstorel(self.g, t0.g)) def _eltabstorel_lift(self, x): """ Return the relative number field element corresponding to `x`. The result is a ``t_POL`` with ``t_POLMOD`` coefficients. .. WARNING:: This is a low-level version of :meth:`rnfeltabstorel` that only needs the output of :meth:`_nf_rnfeq`, not a full PARI ``rnf`` structure. This method may raise errors or return undefined results if called with invalid arguments. Tests: >>> from cypari2 import Pari >>> pari = Pari() >>> K = pari('y^2 + 1').nfinit() >>> rnfeq = K._nf_rnfeq('x^2 + 2') >>> rnfeq._eltabstorel_lift('x') x + Mod(-y, y^2 + 1) """ cdef Gen t0 = objtogen(x) sig_on() return new_gen(eltabstorel_lift(self.g, t0.g)) def _eltreltoabs(self, x): """ Return the absolute number field element corresponding to `x`. The result is a ``t_POL``. .. WARNING:: This is a low-level version of :meth:`rnfeltreltoabs` that only needs the output of :meth:`_nf_rnfeq`, not a full PARI ``rnf`` structure. This method may raise errors or return undefined results if called with invalid arguments. Tests: >>> from cypari2 import Pari >>> pari = Pari() >>> K = pari('y^2 + 1').nfinit() >>> rnfeq = K._nf_rnfeq('x^2 + 2') >>> rnfeq._eltreltoabs('x') 1/2*x^3 + 7/2*x >>> rnfeq._eltreltoabs('y') 1/2*x^3 + 5/2*x """ cdef Gen t0 = objtogen(x) sig_on() return new_gen(eltreltoabs(self.g, t0.g)) def galoissubfields(self, long flag=0, v=None): """ List all subfields of the Galois group ``self``. This wraps the `galoissubfields`_ function from PARI. This method is essentially the same as applying :meth:`galoisfixedfield` to each group returned by :meth:`galoissubgroups`. INPUT: - ``self`` -- A Galois group as generated by :meth:`galoisinit`. - ``flag`` -- Has the same meaning as in :meth:`galoisfixedfield`. - ``v`` -- Has the same meaning as in :meth:`galoisfixedfield`. OUTPUT: A vector of all subfields of this group. Each entry is as described in the :meth:`galoisfixedfield` method. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> G = pari('x^6 + 108').galoisinit() >>> G.galoissubfields(flag=1) [x, x^2 + 972, x^3 + 54, x^3 + 864, x^3 - 54, x^6 + 108] >>> G = pari('x^4 + 1').galoisinit() >>> G.galoissubfields(flag=2, v='z')[3] [...^2 + 2, Mod(x^3 + x, x^4 + 1), [x^2 - z*x - 1, x^2 + z*x - 1]] .. _galoissubfields: http://pari.math.u-bordeaux.fr/dochtml/html.stable/Functions_related_to_general_number_fields.html#galoissubfields """ sig_on() return new_gen(galoissubfields(self.g, flag, get_var(v))) def nfeltval(self, x, p): """ Return the valuation of the number field element `x` at the prime `p`. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> nf = pari('x^2 + 1').nfinit() >>> p = nf.idealprimedec(5)[0] >>> nf.nfeltval('50 - 25*x', p) 3 """ cdef Gen t0 = objtogen(x) cdef Gen t1 = objtogen(p) sig_on() v = nfval(self.g, t0.g, t1.g) sig_off() return v def nfbasis(self, long flag=0, fa=None): """ Integral basis of the field `\QQ[a]`, where ``a`` is a root of the polynomial x. INPUT: - ``flag``: if set to 1 and ``fa`` is not given: assume that no square of a prime > 500000 divides the discriminant of ``x``. - ``fa``: If present, encodes a subset of primes at which to check for maximality. This must be one of the three following things: - an integer: check all primes up to ``fa`` using trial division. - a vector: a list of primes to check. - a matrix: a partial factorization of the discriminant of ``x``. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari('x^3 - 17').nfbasis() [1, x, 1/3*x^2 - 1/3*x + 1/3] We test ``flag`` = 1, noting it gives a wrong result when the discriminant (-4 * `p`^2 * `q` in the example below) has a big square factor: >>> p = pari(10**10).nextprime(); q = (p+1).nextprime() >>> x = pari('x'); f = x**2 + p**2*q >>> pari(f).nfbasis(1) # Wrong result [1, x] >>> pari(f).nfbasis() # Correct result [1, 1/10000000019*x] >>> pari(f).nfbasis(fa=10**6) # Check primes up to 10^6: wrong result [1, x] >>> pari(f).nfbasis(fa="[2,2; %s,2]"%p) # Correct result and faster [1, 1/10000000019*x] >>> pari(f).nfbasis(fa=[2,p]) # Equivalent with the above [1, 1/10000000019*x] """ cdef Gen t0 cdef GEN g0 if fa is not None: t0 = objtogen(fa) g0 = t0.g elif flag: g0 = utoi(500000) else: g0 = NULL sig_on() return new_gen(nfbasis(self.g, NULL, g0)) def nfbasis_d(self, long flag=0, fa=None): """ Like :meth:`nfbasis`, but return a tuple ``(B, D)`` where `B` is the integral basis and `D` the discriminant. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> F = pari('x^3 - 2').nfinit() >>> F[0].nfbasis_d() ([1, x, x^2], -108) >>> G = pari('x^5 - 11').nfinit() >>> G[0].nfbasis_d() ([1, x, x^2, x^3, x^4], 45753125) >>> pari([-2,0,0,1]).Polrev().nfbasis_d() ([1, x, x^2], -108) """ cdef Gen t0 cdef GEN g0 cdef GEN disc if fa is not None: t0 = objtogen(fa) g0 = t0.g elif flag & 1: g0 = utoi(500000) else: g0 = NULL sig_on() B = new_gen_noclear(nfbasis(self.g, &disc, g0)) D = new_gen(disc) return B, D def nfbasistoalg_lift(nf, x): r""" Transforms the column vector ``x`` on the integral basis into a polynomial representing the algebraic number. INPUT: - ``nf`` -- a number field - ``x`` -- a column of rational numbers of length equal to the degree of ``nf`` or a single rational number OUTPUT: - ``nf.nfbasistoalg(x).lift()`` Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> K = pari('x^3 - 17').nfinit() >>> K.nf_get_zk() [1, 1/3*x^2 - 1/3*x + 1/3, x] >>> K.nfbasistoalg_lift(42) 42 >>> K.nfbasistoalg_lift("[3/2, -5, 0]~") -5/3*x^2 + 5/3*x - 1/6 >>> K.nf_get_zk() * pari("[3/2, -5, 0]~") -5/3*x^2 + 5/3*x - 1/6 """ cdef Gen t0 = objtogen(x) sig_on() return new_gen(gel(basistoalg(nf.g, t0.g), 2)) def nfgenerator(self): f = self[0] x = f.variable() return x.Mod(f) def _nf_rnfeq(self, relpol): """ Return data for converting number field elements between absolute and relative representation. .. NOTE:: The output of this method is suitable for the methods :meth:`_eltabstorel`, :meth:`_eltabstorel_lift` and :meth:`_eltreltoabs`. Tests: >>> from cypari2 import Pari >>> pari = Pari() >>> K = pari('y^2 + 1').nfinit() >>> K._nf_rnfeq('x^2 + 2') [x^4 + 6*x^2 + 1, 1/2*x^3 + 5/2*x, -1, y^2 + 1, x^2 + 2] """ cdef Gen t0 = objtogen(relpol) sig_on() return new_gen(nf_rnfeq(self.g, t0.g)) def _nf_nfzk(self, rnfeq): """ Return data for constructing relative number field elements from elements of the base field. INPUT: - ``rnfeq`` -- relative number field data as returned by :meth:`_nf_rnfeq` .. NOTE:: The output of this method is suitable for the method :meth:`_nfeltup`. Tests: >>> from cypari2 import Pari >>> pari = Pari() >>> nf = pari('y^2 - 2').nfinit() >>> nf._nf_nfzk(nf._nf_rnfeq('x^2 - 3')) ([2, -x^3 + 9*x], 1/2) """ cdef GEN zknf, czknf cdef Gen t0 = objtogen(rnfeq) cdef Gen zk, czk sig_on() nf_nfzk(self.g, t0.g, &zknf, &czknf) zk = new_gen_noclear(zknf) czk = new_gen(czknf) return zk, czk def _nfeltup(self, x, zk, czk): """ Construct a relative number field element from an element of the base field. INPUT: - ``x`` -- element of the base field - ``zk``, ``czk`` -- relative number field data as returned by :meth:`_nf_nfzk` .. WARNING:: This is a low-level version of :meth:`rnfeltup` that only needs the output of :meth:`_nf_nfzk`, not a full PARI ``rnf`` structure. This method may raise errors or return undefined results if called with invalid arguments. Tests: >>> from cypari2 import Pari >>> pari = Pari() >>> nf = pari('nfinit(y^2 - 2)') >>> zk, czk = nf._nf_nfzk(nf._nf_rnfeq('x^2 - 3')) >>> nf._nfeltup('y', zk, czk) -1/2*x^3 + 9/2*x """ cdef Gen t0 = objtogen(x) cdef Gen t1 = objtogen(zk) cdef Gen t2 = objtogen(czk) sig_on() return new_gen(nfeltup(self.g, t0.g, t1.g, t2.g)) def eval(self, *args, **kwds): """ Evaluate ``self`` with the given arguments. This is currently implemented in 3 cases: - univariate polynomials, rational functions, power series and Laurent series (using a single unnamed argument or keyword arguments), - any PARI object supporting the PARI function :pari:`substvec` (in particular, multivariate polynomials) using keyword arguments, - objects of type ``t_CLOSURE`` (functions in GP bytecode form) using unnamed arguments. In no case is mixing unnamed and keyword arguments allowed. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> f = pari('x^2 + 1') >>> f.type() 't_POL' >>> f.eval(pari('I')) 0 >>> f.eval(x=2) 5 >>> (1/f).eval(x=1) 1/2 The notation ``f(x)`` is an alternative for ``f.eval(x)``: >>> f(3) == f.eval(3) True Evaluating power series: >>> f = pari('1 + x + x^3 + O(x^7)') >>> f(2*pari('y')**2) 1 + 2*y^2 + 8*y^6 + O(y^14) Substituting zero is sometimes possible, and trying to do so in illegal cases can raise various errors: >>> pari('1 + O(x^3)').eval(0) 1 >>> pari('1/x').eval(0) Traceback (most recent call last): ... PariError: impossible inverse in gdiv: 0 >>> pari('1/x + O(x^2)').eval(0) Traceback (most recent call last): ... PariError: impossible inverse in gsubst: 0 >>> pari('1/x + O(x^2)').eval(pari('O(x^3)')) Traceback (most recent call last): ... PariError: impossible inverse in gdiv: O(x^3) >>> pari('O(x^0)').eval(0) Traceback (most recent call last): ... PariError: forbidden substitution t_SER , t_INT Evaluating multivariate polynomials: >>> f = pari('y^2 + x^3') >>> f(1) # Dangerous, depends on PARI variable ordering y^2 + 1 >>> f(x=1) # Safe y^2 + 1 >>> f(y=1) x^3 + 1 >>> f(1, 2) Traceback (most recent call last): ... TypeError: evaluating PARI t_POL takes exactly 1 argument (2 given) >>> f(y='x', x='2*y') x^2 + 8*y^3 >>> f() x^3 + y^2 It's not an error to substitute variables which do not appear: >>> f.eval(z=37) x^3 + y^2 >>> pari(42).eval(t=0) 42 We can define and evaluate closures as follows: >>> T = pari('n -> n + 2') >>> T.type() 't_CLOSURE' >>> T.eval(3) 5 >>> T = pari('() -> 42') >>> T() 42 >>> pr = pari('s -> print(s)') >>> pr.eval('"hello world"') hello world >>> f = pari('myfunc(x,y) = x*y') >>> f.eval(5, 6) 30 Default arguments work, missing arguments are treated as zero (like in GP): >>> f = pari("(x, y, z=1.0) -> [x, y, z]") >>> f(1, 2, 3) [1, 2, 3] >>> f(1, 2) [1, 2, 1.00000000000000] >>> f(1) [1, 0, 1.00000000000000] >>> f() [0, 0, 1.00000000000000] Variadic closures are supported as well (:trac:`18623`): >>> f = pari("(v[..])->length(v)") >>> f('a', f) 2 >>> g = pari("(x,y,z[..])->[x,y,z]") >>> g(), g(1), g(1,2), g(1,2,3), g(1,2,3,4) ([0, 0, []], [1, 0, []], [1, 2, []], [1, 2, [3]], [1, 2, [3, 4]]) Using keyword arguments, we can substitute in more complicated objects, for example a number field: >>> nf = pari('x^2 + 1').nfinit() >>> nf [x^2 + 1, [0, 1], -4, 1, [Mat([1, 0.E-38 + 1.00000000000000*I]), [1, 1.00000000000000; 1, -1.00000000000000], [1, 1; 1, -1], [2, 0; 0, -2], [2, 0; 0, 2], [1, 0; 0, -1], [1, [0, -1; 1, 0]], [2]], [0.E-38 + 1.00000000000000*I], [1, x], [1, 0; 0, 1], [1, 0, 0, -1; 0, 1, 1, 0]] >>> nf(x='y') [y^2 + 1, [0, 1], -4, 1, [Mat([1, 0.E-38 + 1.00000000000000*I]), [1, 1.00000000000000; 1, -1.00000000000000], [1, 1; 1, -1], [2, 0; 0, -2], [2, 0; 0, 2], [1, 0; 0, -1], [1, [0, -1; 1, 0]], [2]], [0.E-38 + 1.00000000000000*I], [1, y], [1, 0; 0, 1], [1, 0, 0, -1; 0, 1, 1, 0]] """ cdef long t = typ(self.g) cdef Gen t0 cdef GEN result cdef long arity cdef long nargs = len(args) cdef long nkwds = len(kwds) # Closure must be evaluated using *args if t == t_CLOSURE: if nkwds > 0: raise TypeError("cannot evaluate a PARI closure using keyword arguments") if closure_is_variadic(self.g): arity = closure_arity(self.g) - 1 args = list(args[:arity]) + [0]*(arity-nargs) + [args[arity:]] t0 = objtogen(args) sig_on() result = closure_callgenvec(self.g, t0.g) if result == gnil: clear_stack() return None return new_gen(result) # Evaluate univariate polynomials, rational functions and # series using *args if nargs > 0: if nkwds > 0: raise TypeError("mixing unnamed and keyword arguments not allowed when evaluating a PARI object") if not (t == t_POL or t == t_RFRAC or t == t_SER): raise TypeError("cannot evaluate PARI %s using unnamed arguments" % self.type()) if nargs != 1: raise TypeError("evaluating PARI %s takes exactly 1 argument (%d given)" % (self.type(), nargs)) t0 = objtogen(args[0]) sig_on() if t == t_POL or t == t_RFRAC: return new_gen(poleval(self.g, t0.g)) else: # t == t_SER return new_gen(gsubst(self.g, varn(self.g), t0.g)) # Call substvec() using **kwds vstr = iter(kwds.iterkeys()) # Variables as Python strings t0 = objtogen(kwds.values()) # Replacements sig_on() cdef GEN v = cgetg(nkwds+1, t_VEC) # Variables as PARI polynomials cdef long i for i in range(nkwds): set_gel(v, i+1, pol_x(get_var(next(vstr)))) return new_gen(gsubstvec(self.g, v, t0.g)) def __call__(self, *args, **kwds): """ Evaluate ``self`` with the given arguments. This has the same effect as :meth:`eval`. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> f = pari('Mod(x^2 + x + 1, 3)') >>> f.type() 't_POL' >>> f(2) Mod(1, 3) Tests: >>> T = pari('n -> 1/n') >>> T.type() 't_CLOSURE' >>> T(0) Traceback (most recent call last): ... PariError: _/_: impossible inverse in gdiv: 0 >>> pari('() -> 42')(1,2,3) Traceback (most recent call last): ... PariError: too many parameters in user-defined function call >>> pari('n -> n')(n=2) Traceback (most recent call last): ... TypeError: cannot evaluate a PARI closure using keyword arguments >>> pari('x + y')(4, y=1) Traceback (most recent call last): ... TypeError: mixing unnamed and keyword arguments not allowed when evaluating a PARI object >>> pari("12345")(4) Traceback (most recent call last): ... TypeError: cannot evaluate PARI t_INT using unnamed arguments """ return self.eval(*args, **kwds) def factorpadic(self, p, long r=20): """ p-adic factorization of the polynomial ``pol`` to precision ``r``. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pol = pari('x^2 - 1')**2 >>> pari(pol).factorpadic(5) [(1 + O(5^20))*x + (1 + O(5^20)), 2; (1 + O(5^20))*x + (4 + 4*5 + 4*5^2 + 4*5^3 + 4*5^4 + 4*5^5 + 4*5^6 + 4*5^7 + 4*5^8 + 4*5^9 + 4*5^10 + 4*5^11 + 4*5^12 + 4*5^13 + 4*5^14 + 4*5^15 + 4*5^16 + 4*5^17 + 4*5^18 + 4*5^19 + O(5^20)), 2] >>> pari(pol).factorpadic(5,3) [(1 + O(5^3))*x + (1 + O(5^3)), 2; (1 + O(5^3))*x + (4 + 4*5 + 4*5^2 + O(5^3)), 2] """ cdef Gen t0 = objtogen(p) sig_on() return new_gen(factorpadic(self.g, t0.g, r)) def poldegree(self, var=None): """ Return the degree of this polynomial. """ sig_on() n = poldegree(self.g, get_var(var)) sig_off() return n def polisirreducible(self): """ f.polisirreducible(): Returns True if f is an irreducible non-constant polynomial, or False if f is reducible or constant. """ sig_on() t = isirreducible(self.g) clear_stack() return t != 0 def polroots(self, unsigned long precision=0): """ Complex roots of the given polynomial using Schonhage's method, as modified by Gourdon. """ sig_on() return new_gen(cleanroots(self.g, prec_bits_to_words(precision))) def rnfisnorm(self, T, long flag=0): cdef Gen t0 = objtogen(T) sig_on() return new_gen(rnfisnorm(t0.g, self.g, flag)) def ncols(self): """ Return the number of columns of self. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari('matrix(19,8)').ncols() 8 """ cdef long n sig_on() n = glength(self.g) sig_off() return n def nrows(self): """ Return the number of rows of self. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari('matrix(19,8)').nrows() 19 """ cdef long n sig_on() # if this matrix has no columns # then it has no rows. if self.ncols() == 0: sig_off() return 0 n = glength(gel(self.g, 1)) sig_off() return n def mattranspose(self): """ Transpose of the matrix self. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari('[1,2,3; 4,5,6; 7,8,9]').mattranspose() [1, 4, 7; 2, 5, 8; 3, 6, 9] Unlike PARI, this always returns a matrix: >>> pari('[1,2,3]').mattranspose() [1; 2; 3] >>> pari('[1,2,3]~').mattranspose() Mat([1, 2, 3]) """ sig_on() return new_gen(gtrans(self.g)).Mat() def lllgram(self): return self.qflllgram(0) def lllgramint(self): return self.qflllgram(1) def qfrep(self, B, long flag=0): """ Vector of (half) the number of vectors of norms from 1 to `B` for the integral and definite quadratic form ``self``. Binary digits of flag mean 1: count vectors of even norm from 1 to `2B`, 2: return a ``t_VECSMALL`` instead of a ``t_VEC`` (which is faster). Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> M = pari("[5,1,1;1,3,1;1,1,1]") >>> M.qfrep(20) [1, 1, 2, 2, 2, 4, 4, 3, 3, 4, 2, 4, 6, 0, 4, 6, 4, 5, 6, 4] >>> M.qfrep(20, flag=1) [1, 2, 4, 3, 4, 4, 0, 6, 5, 4, 12, 4, 4, 8, 0, 3, 8, 6, 12, 12] >>> M.qfrep(20, flag=2) Vecsmall([1, 1, 2, 2, 2, 4, 4, 3, 3, 4, 2, 4, 6, 0, 4, 6, 4, 5, 6, 4]) """ # PARI 2.7 always returns a t_VECSMALL, but for backwards # compatibility, we keep returning a t_VEC (unless flag & 2) cdef Gen t0 = objtogen(B) cdef GEN r sig_on() r = qfrep0(self.g, t0.g, flag & 1) if (flag & 2) == 0: r = vecsmall_to_vec(r) return new_gen(r) def matkerint(self, long flag=0): """ Return the integer kernel of a matrix. This is the LLL-reduced Z-basis of the kernel of the matrix x with integral entries. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari('[2,1;2,1]').matker() [-1/2; 1] >>> pari('[2,1;2,1]').matkerint() [1; -2] >>> import warnings >>> with warnings.catch_warnings(record=True) as w: ... warnings.simplefilter('always') ... pari('[2,1;2,1]').matkerint(1) ... assert len(w) == 1 ... assert issubclass(w[0].category, DeprecationWarning) [1; -2] """ if flag: # Keep this deprecation warning as long as PARI supports # this deprecated flag from warnings import warn warn("the 'flag' argument of the PARI/GP function matkerint is obsolete", DeprecationWarning) sig_on() return new_gen(matkerint0(self.g, flag)) def factor(self, long limit=-1, proof=None): """ Return the factorization of x. INPUT: - ``limit`` -- (default: -1) is optional and can be set whenever x is of (possibly recursive) rational type. If limit is set, return partial factorization, using primes up to limit. - ``proof`` -- optional flag. If ``False`` (not the default), returned factors larger than `2^{64}` may only be pseudoprimes. If ``True``, always check primality. If not given, use the global PARI default ``factor_proven`` which is ``True`` by default in cypari. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari('x^10-1').factor() [x - 1, 1; x + 1, 1; x^4 - x^3 + x^2 - x + 1, 1; x^4 + x^3 + x^2 + x + 1, 1] >>> pari(2**100-1).factor() [3, 1; 5, 3; 11, 1; 31, 1; 41, 1; 101, 1; 251, 1; 601, 1; 1801, 1; 4051, 1; 8101, 1; 268501, 1] >>> pari(2**100-1).factor(proof=True) [3, 1; 5, 3; 11, 1; 31, 1; 41, 1; 101, 1; 251, 1; 601, 1; 1801, 1; 4051, 1; 8101, 1; 268501, 1] >>> pari(2**100-1).factor(proof=False) [3, 1; 5, 3; 11, 1; 31, 1; 41, 1; 101, 1; 251, 1; 601, 1; 1801, 1; 4051, 1; 8101, 1; 268501, 1] We illustrate setting a limit: >>> pari(pari(10**50).nextprime()*pari(10**60).nextprime()*pari(10**4).nextprime()).factor(10**5) [10007, 1; 100000000000000000000000000000000000000000000000151000000000700000000000000000000000000000000000000000000001057, 1] Setting a limit is invalid when factoring polynomials: >>> pari('x^11 + 1').factor(limit=17) Traceback (most recent call last): ... PariError: incorrect type in boundfact (t_POL) """ cdef GEN g global factor_proven cdef int saved_factor_proven = factor_proven try: if proof is not None: factor_proven = 1 if proof else 0 sig_on() if limit >= 0: g = boundfact(self.g, limit) else: g = factor(self.g) return new_gen(g) finally: factor_proven = saved_factor_proven # Standard name for SageMath multiplicative_order = Gen_auto.znorder def __abs__(self): return self.abs() def nextprime(self, bint add_one=0): """ nextprime(x): smallest pseudoprime greater than or equal to `x`. If ``add_one`` is non-zero, return the smallest pseudoprime strictly greater than `x`. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(1).nextprime() 2 >>> pari(2).nextprime() 2 >>> pari(2).nextprime(add_one = 1) 3 >>> pari(2**100).nextprime() 1267650600228229401496703205653 """ sig_on() if add_one: return new_gen(nextprime(gaddsg(1, self.g))) return new_gen(nextprime(self.g)) def change_variable_name(self, var): """ In ``self``, which must be a ``t_POL`` or ``t_SER``, set the variable to ``var``. If the variable of ``self`` is already ``var``, then return ``self``. .. WARNING:: You should be careful with variable priorities when applying this on a polynomial or series of which the coefficients have polynomial components. To be safe, only use this function on polynomials with integer or rational coefficients. For a safer alternative, use :meth:`subst`. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> f = pari('x^3 + 17*x + 3') >>> f.change_variable_name("y") y^3 + 17*y + 3 >>> f = pari('1 + 2*y + O(y^10)') >>> f.change_variable_name("q") 1 + 2*q + O(q^10) >>> f.change_variable_name("y") is f True In PARI, ``I`` refers to the square root of -1, so it cannot be used as variable name. Note the difference with :meth:`subst`: >>> f = pari('x^2 + 1') >>> f.change_variable_name("I") Traceback (most recent call last): ... PariError: I already exists with incompatible valence >>> f.subst("x", "I") 0 """ cdef long n = get_var(var) if varn(self.g) == n: return self if typ(self.g) != t_POL and typ(self.g) != t_SER: raise TypeError("set_variable() only works for polynomials or power series") # Copy self and then change the variable in place cdef Gen newg = new_gen_noclear(self.g) setvarn(newg.g, n) return newg def nf_subst(self, z): """ Given a PARI number field ``self``, return the same PARI number field but in the variable ``z``. INPUT: - ``self`` -- A PARI number field being the output of ``nfinit()``, ``bnfinit()`` or ``bnrinit()``. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> K = pari('y^2 + 5').nfinit() We can substitute in a PARI ``nf`` structure: >>> K.nf_get_pol() y^2 + 5 >>> L = K.nf_subst('a') >>> L.nf_get_pol() a^2 + 5 We can also substitute in a PARI ``bnf`` structure: >>> K = pari('y^2 + 5').bnfinit() >>> K.nf_get_pol() y^2 + 5 >>> K.bnf_get_cyc() # Structure of class group [2] >>> L = K.nf_subst('a') >>> L.nf_get_pol() a^2 + 5 >>> L.bnf_get_cyc() # We still have a bnf after substituting [2] """ cdef Gen t0 = objtogen(z) sig_on() return new_gen(gsubst(self.g, gvar(self.g), t0.g)) def type(self): """ Return the PARI type of self as a string. .. NOTE:: In Cython, it is much faster to simply use typ(self.g) for checking PARI types. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(7).type() 't_INT' >>> pari('x').type() 't_POL' >>> pari('oo').type() 't_INFINITY' """ return to_string(type_name(typ(self.g))) def polinterpolate(self, ya, x): """ self.polinterpolate(ya,x,e): polynomial interpolation at x according to data vectors self, ya (i.e. return P such that P(self[i]) = ya[i] for all i). Also return an error estimate on the returned value. """ cdef Gen t0 = objtogen(ya) cdef Gen t1 = objtogen(x) cdef GEN dy, g sig_on() g = polint(self.g, t0.g, t1.g, &dy) dif = new_gen_noclear(dy) return new_gen(g), dif def ellwp(self, z='z', long n=20, long flag=0, unsigned long precision=0): """ Return the value or the series expansion of the Weierstrass `P`-function at `z` on the lattice `self` (or the lattice defined by the elliptic curve `self`). INPUT: - ``self`` -- an elliptic curve created using ``ellinit`` or a list ``[om1, om2]`` representing generators for a lattice. - ``z`` -- (default: 'z') a complex number or a variable name (as string or PARI variable). - ``n`` -- (default: 20) if 'z' is a variable, compute the series expansion up to at least `O(z^n)`. - ``flag`` -- (default = 0): If ``flag`` is 0, compute only `P(z)`. If ``flag`` is 1, compute `[P(z), P'(z)]`. OUTPUT: - `P(z)` (if ``flag`` is 0) or `[P(z), P'(z)]` (if ``flag`` is 1). numbers Examples: We first define the elliptic curve X_0(11): >>> from cypari2 import Pari >>> pari = Pari() >>> E = pari([0,-1,1,-10,-20]).ellinit() Compute P(1): >>> E.ellwp(1) 13.9658695257485 Compute P(1+i), where i = sqrt(-1): >>> E.ellwp(pari(complex(1, 1))) -1.11510682565555 + 2.33419052307470*I >>> E.ellwp(complex(1, 1)) -1.11510682565555 + 2.33419052307470*I The series expansion, to the default `O(z^20)` precision: >>> E.ellwp() 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) Compute the series for wp to lower precision: >>> E.ellwp(n=4) z^-2 + 31/15*z^2 + O(z^4) Next we use the version where the input is generators for a lattice: >>> pari([1.2692, complex(0.63, 1.45)]).ellwp(1) 13.9656146936689 + 0.000644829272810...*I With flag=1, compute the pair P(z) and P'(z): >>> E.ellwp(1, flag=1) [13.9658695257485, 101.123860176015] """ cdef Gen t0 = objtogen(z) cdef GEN g0 = t0.g sig_on() # Polynomial or rational function as input: # emulate toser_i() but with given precision if typ(g0) == t_POL: g0 = RgX_to_ser(g0, n+4) elif typ(g0) == t_RFRAC: g0 = rfrac_to_ser(g0, n+4) cdef GEN r = ellwp0(self.g, g0, flag, prec_bits_to_words(precision)) if flag == 1 and have_ellwp_flag1_bug(): # Work around ellwp() bug: double the second element set_gel(r, 2, gmulgs(gel(r, 2), 2)) return new_gen(r) def debug(self, long depth = -1): r""" Show the internal structure of self (like the ``\x`` command in gp). Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari('[1/2, 1 + 1.0*I]').debug() [&=...] VEC(lg=3):... 1st component = [&=...] FRAC(lg=3):... num = [&=...] INT(lg=3):... (+,lgefint=3):... den = [&=...] INT(lg=3):... (+,lgefint=3):... 2nd component = [&=...] COMPLEX(lg=3):... real = [&=...] INT(lg=3):... (+,lgefint=3):... imag = [&=...] REAL(lg=...):... (+,expo=0):... """ sig_on() dbgGEN(self.g, depth) sig_off() return def bernvec(x): r""" Creates a vector containing, as rational numbers, the Bernoulli numbers `B_0, B_2,\ldots, B_{2x}`. This routine is obsolete. Use bernfrac instead each time you need a Bernoulli number in exact form. Note: this routine is implemented using repeated independent calls to bernfrac, which is faster than the standard recursion in exact arithmetic. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> import warnings >>> with warnings.catch_warnings(record=True) as w: ... warnings.simplefilter('always') ... pari(8).bernvec() ... assert len(w) == 1 ... assert issubclass(w[0].category, DeprecationWarning) [1, 1/6, -1/30, 1/42, -1/30, 5/66, -691/2730, 7/6, -3617/510] >>> [pari(2*n).bernfrac() for n in range(9)] [1, 1/6, -1/30, 1/42, -1/30, 5/66, -691/2730, 7/6, -3617/510] """ from warnings import warn warn('the PARI/GP function bernvec() is obsolete: use repeated calls to bernfrac() instead', DeprecationWarning) sig_on() return new_gen(bernvec(x)) def allocatemem(self, *args): """ Do not use this. Use ``pari.allocatemem()`` instead. Tests: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(2**10).allocatemem(2**20) Traceback (most recent call last): ... NotImplementedError: the method allocatemem() should not be used; use pari.allocatemem() instead """ raise NotImplementedError("the method allocatemem() should not be used; use pari.allocatemem() instead") @cython.boundscheck(False) @cython.wraparound(False) cdef Gen list_of_Gens_to_Gen(list s): """ Convert a Python list whole elements are all :class:`Gen` objects (this is not checked!) to a single PARI :class:`Gen` of type ``t_VEC``. This is called from :func:`objtogen` to convert iterables to PARI. Tests: >>> from six.moves import range >>> from cypari2.gen import objtogen >>> from cypari2 import Pari >>> pari = Pari() >>> objtogen(range(10)) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> objtogen(i**2 for i in range(5)) [0, 1, 4, 9, 16] >>> objtogen([pari("Mod(x, x^2+1)")]) [Mod(x, x^2 + 1)] >>> objtogen([]) [] """ cdef Py_ssize_t length = len(s) sig_on() cdef GEN g = cgetg(length+1, t_VEC) cdef Py_ssize_t i for i in range(length): set_gel(g, i+1, (s[i]).g) return new_gen(g) cpdef Gen objtogen(s): """ Convert any SageMath/Python object to a PARI :class:`Gen`. For SageMath types, this uses the ``__pari__()`` method on the object. Basic Python types like ``int`` are converted directly. For other types, the string representation is used. Examples: >>> from cypari2 import Pari >>> pari = Pari() >>> pari(0) 0 >>> pari([2,3,5]) [2, 3, 5] >>> a = pari(1) >>> a, a.type() (1, 't_INT') >>> from fractions import Fraction >>> a = pari(Fraction('1/2')) >>> a, a.type() (1/2, 't_FRAC') Conversion from reals uses the real's own precision: >>> a = pari(1.2); a, a.type() (1.20000000000000, 't_REAL') >>> import sys >>> bitness = '64' if sys.maxsize > (1 << 32) else '32' >>> a.precision() == (4 if bitness == '32' else 3) True Conversion from strings uses the current PARI real precision. By default, this is 64 bits: >>> a = pari('1.2'); a, a.type() (1.20000000000000, 't_REAL') >>> a.precision() == (4 if bitness == '32' else 3) True Unicode and bytes work fine: >>> pari(b"zeta(3)") 1.20205690315959 >>> pari(u"zeta(3)") 1.20205690315959 But we can change this precision: >>> pari.set_real_precision(35) # precision in decimal digits 15 >>> a = pari('1.2'); a, a.type() (1.2000000000000000000000000000000000, 't_REAL') >>> bitness = '64' if sys.maxsize > (1 << 32) else '32' >>> a.precision() == (6 if bitness == '32' else 4) True Set the precision to 15 digits for the remaining tests: >>> pari.set_real_precision(15) 35 Conversion from basic Python types: >>> pari(int(-5)) -5 >>> pari(2**150) 1427247692705959881058285969449495136382746624 >>> import math >>> pari(math.pi) 3.14159265358979 >>> one = pari(complex(1,0)); one, one.type() (1.00000000000000, 't_COMPLEX') >>> pari(complex(0, 1)) 1.00000000000000*I >>> pari(complex(0.3, 1.7)) 0.300000000000000 + 1.70000000000000*I >>> pari(False) 0 >>> pari(True) 1 Some commands are just executed without returning a value: >>> pari("dummy = 0; kill(dummy)") >>> type(pari("dummy = 0; kill(dummy)")) <... 'NoneType'> Tests: >>> pari(None) Traceback (most recent call last): ... ValueError: Cannot convert None to pari >>> class OldStylePari: ... def _pari_(self): ... return pari(42) >>> import warnings >>> with warnings.catch_warnings(record=True) as w: ... warnings.simplefilter('always') ... pari(OldStylePari()) ... assert len(w) == 1 ... assert issubclass(w[0].category, DeprecationWarning) 42 """ cdef GEN g cdef list L if isinstance(s, Gen): return s try: m = s.__pari__ except AttributeError: pass else: return m() try: m = s._pari_ except AttributeError: pass else: from warnings import warn warn("the _pari_ method is deprecated, use __pari__ instead", DeprecationWarning) return m() # Check basic Python types. Start with strings, which are a very # common case. # This generates slightly more efficient code than # isinstance(s, (unicode, bytes)) if PyUnicode_Check(s) | PyBytes_Check(s): sig_on() g = gp_read_str(to_bytes(s)) if g == gnil: clear_stack() return None return new_gen(g) if PyInt_Check(s) | PyLong_Check(s): return integer_to_gen(s) if isinstance(s, float): return new_gen_from_double(PyFloat_AS_DOUBLE(s)) if isinstance(s, complex): return new_t_COMPLEX_from_double(PyComplex_RealAsDouble(s), PyComplex_ImagAsDouble(s)) # A list is iterable, but we handle the common case of a list # separately as an optimization if isinstance(s, list): L = [objtogen(x) for x in s] return list_of_Gens_to_Gen(L) # Check for iterable object s try: L = [objtogen(x) for x in s] except TypeError: pass else: return list_of_Gens_to_Gen(L) if callable(s): return objtoclosure(s) if s is None: raise ValueError("Cannot convert None to pari") # Simply use the string representation return objtogen(str(s)) cdef GEN _Vec_append(GEN v, GEN a, long n): """ This implements appending zeros (or another constant GEN ``a``) to the result of :meth:`Vec` and similar functions. This is a shallow function, copying ``a`` and entries of ``v`` to the result. The result is simply stored on the PARI stack. INPUT: - ``v`` -- GEN of type ``t_VEC`` or ``t_COL`` - ``a`` -- GEN which will be used for the added entries. Normally, this would be ``gen_0``. - ``n`` -- Make the vector of minimal length `|n|`. If `n > 0`, append zeros; if `n < 0`, prepend zeros. OUTPUT: A GEN of the same type as ``v``. """ cdef long lenv = lg(v)-1 cdef GEN w cdef long i # Do we need to extend the vector with zeros? if n > lenv: w = cgetg(n+1, typ(v)) for i from 1 <= i <= lenv: set_gel(w, i, gel(v, i)) for i from 1 <= i <= n-lenv: set_gel(w, i+lenv, a) return w elif n < -lenv: n = -n # Make n positive w = cgetg(n+1, typ(v)) for i from 1 <= i <= lenv: set_gel(w, i+(n-lenv), gel(v, i)) for i from 1 <= i <= n-lenv: set_gel(w, i, a) return w else: return v cypari2-1.1.4/cypari2/paripriv.pxd0000644000201600020160000000175113160215735020441 0ustar jdemeyerjdemeyer00000000000000# distutils: libraries = gmp pari """ Declarations for private functions from PARI Ideally, we shouldn't use these, but for technical reasons, we have to. """ from .types cimport * cdef extern from "pari/paripriv.h": int t_FF_FpXQ, t_FF_Flxq, t_FF_F2xq int gpd_QUIET, gpd_TEST, gpd_EMACS, gpd_TEXMACS struct pariout_t: char format # e,f,g long fieldw # 0 (ignored) or field width long sigd # -1 (all) or number of significant digits printed int sp # 0 = suppress whitespace from output int prettyp # output style: raw, prettyprint, etc int TeXstyle struct gp_data: pariout_t *fmt unsigned long flags extern gp_data* GP_DATA # In older versions of PARI, this is declared in the private # non-installed PARI header file "anal.h". More recently, this is # declared in "paripriv.h". Since a double declaration does not hurt, # we declare it here regardless. cdef extern const char* closure_func_err() cypari2-1.1.4/cypari2/convert.pxd0000644000201600020160000000060313236012275020256 0ustar jdemeyerjdemeyer00000000000000from .types cimport GEN from .gen cimport Gen cpdef integer_to_gen(x) cpdef gen_to_integer(Gen x) cpdef gen_to_python(Gen z) cdef GEN gtoi(GEN g0) except NULL cdef GEN PyLong_AsGEN(x) cdef PyLong_FromGEN(GEN g) cdef Gen new_t_POL_from_int_star(int* vals, unsigned long length, long varnum) cdef Gen new_gen_from_double(double) cdef Gen new_t_COMPLEX_from_double(double re, double im) cypari2-1.1.4/cypari2/stack.pyx0000644000201600020160000000415013236012275017731 0ustar jdemeyerjdemeyer00000000000000""" Utility functions to handle the PARI stack and copy objects from it ******************************************************************* NOTE: nothing in this module is accessible from Python (only Cython), so it is not included in the documentation. """ #***************************************************************************** # Copyright (C) 2016 Luca De Feo # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** from __future__ import absolute_import, division, print_function cdef extern from *: int sig_on_count "cysigs.sig_on_count" from cysignals.signals cimport sig_off from cysignals.memory cimport check_malloc from .paridecl cimport pari_mainstack, avma, paristack_setsize, gsizebyte, gcopy_avma, gnil cdef inline void clear_stack(): """ Call ``sig_off()``. If we are leaving the outermost ``sig_on() ... sig_off()`` block, then clear the PARI stack. """ global avma if sig_on_count <= 1: avma = pari_mainstack.top sig_off() cdef inline GEN deepcopy_to_python_heap(GEN x, void** address) except NULL: cdef size_t s = gsizebyte(x) cdef void* tmp_bot = check_malloc(s) address[0] = tmp_bot cdef pari_sp tmp_top = tmp_bot + s return gcopy_avma(x, &tmp_top) cdef inline Gen new_gen(GEN x): """ Create a new Gen wrapping `x`, then call ``clear_stack()``. Except if `x` is ``gnil``, then we return ``None`` instead. """ cdef Gen g if x is gnil: g = None else: g = new_gen_noclear(x) clear_stack() return g cdef inline Gen new_gen_noclear(GEN x): """ Create a new gen, but don't free any memory on the stack and don't call sig_off(). """ cdef Gen y = Gen.__new__(Gen) y.g = deepcopy_to_python_heap(x, &y.chunk) return y cypari2-1.1.4/cypari2/string_utils.pyx0000644000201600020160000000271113136574652021366 0ustar jdemeyerjdemeyer00000000000000# -*- coding: utf-8 -*- r""" Conversion functions for bytes/unicode """ import sys encoding = sys.getfilesystemencoding() cpdef bytes to_bytes(s): """ Converts bytes and unicode ``s`` to bytes. Examples: >>> from cypari2.string_utils import to_bytes >>> s1 = to_bytes(b'hello') >>> s2 = to_bytes('hello') >>> s3 = to_bytes(u'hello') >>> type(s1) is type(s2) is type(s3) is bytes True >>> s1 == s2 == s3 == b'hello' True >>> type(to_bytes(1234)) is bytes True >>> int(to_bytes(1234)) 1234 """ cdef int convert for convert in range(2): if convert: s = str(s) if isinstance(s, bytes): return s elif isinstance(s, unicode): return ( s).encode(encoding) raise AssertionError(f"str() returned {type(s)}") cpdef unicode to_unicode(s): r""" Converts bytes and unicode ``s`` to unicode. Examples: >>> from cypari2.string_utils import to_unicode >>> s1 = to_unicode(b'hello') >>> s2 = to_unicode('hello') >>> s3 = to_unicode(u'hello') >>> type(s1) is type(s2) is type(s3) is type(u"") True >>> s1 == s2 == s3 == u'hello' True >>> print(to_unicode(1234)) 1234 >>> type(to_unicode(1234)) is type(u"") True """ if isinstance(s, bytes): return ( s).decode(encoding) elif isinstance(s, unicode): return s return unicode(s) cypari2-1.1.4/cypari2/cypari.h0000644000201600020160000000065013136354561017531 0ustar jdemeyerjdemeyer00000000000000/* * Additional macros and fixes for the PARI headers. This is meant to * be included after including */ #undef coeff /* Conflicts with NTL (which is used by SageMath) */ /* Array element assignment */ #define set_gel(x, n, z) (gel(x,n) = z) #define set_gmael(x, i, j, z) (gmael(x,i,j) = z) #define set_gcoeff(x, i, j, z) (gcoeff(x,i,j) = z) #define set_uel(x, n, z) (uel(x,n) = z) cypari2-1.1.4/cypari2/convert.pyx0000644000201600020160000004406513236012275020315 0ustar jdemeyerjdemeyer00000000000000# cython: cdivision = True """ Convert PARI objects to/from Python/C native types ************************************************** This modules contains the following conversion routines: - integers, long integers <-> PARI integers - list of integegers -> PARI polynomials - doubles -> PARI reals - pairs of doubles -> PARI complex numbers PARI integers are stored as an array of limbs of type ``pari_ulong`` (which are 32-bit or 64-bit integers). Depending on the kernel (GMP or native), this array is stored little-endian or big-endian. This is encapsulated in macros like ``int_W()``: see section 4.5.1 of the `PARI library manual `_. Python integers of type ``int`` are just C longs. Python integers of type ``long`` are stored as a little-endian array of type ``digit`` with 15 or 30 bits used per digit. The internal format of a ``long`` is not documented, but there is some information in `longintrepr.h `_. Because of this difference in bit lengths, converting integers involves some bit shuffling. """ #***************************************************************************** # Copyright (C) 2016 Jeroen Demeyer # Copyright (C) 2016 Luca De Feo # Copyright (C) 2016 Vincent Delecroix # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** from __future__ import absolute_import, division, print_function from cysignals.signals cimport sig_on, sig_off, sig_error from cpython.object cimport Py_SIZE from cpython.int cimport PyInt_AS_LONG from cpython.longintrepr cimport (_PyLong_New, PyLongObject, digit, PyLong_SHIFT, PyLong_MASK) from libc.limits cimport LONG_MIN, LONG_MAX from libc.math cimport INFINITY from .paridecl cimport * from .stack cimport new_gen from .string_utils cimport to_string cdef extern from *: Py_ssize_t* Py_SIZE_PTR "&Py_SIZE"(object) #################################### # Integers #################################### cpdef integer_to_gen(x): """ Convert a Python ``int`` or ``long`` to a PARI ``gen`` of type ``t_INT``. Examples: >>> from cypari2.convert import integer_to_gen >>> from cypari2 import Pari >>> pari = Pari() >>> a = integer_to_gen(int(12345)); a; type(a) 12345 <... 'cypari2.gen.Gen'> >>> integer_to_gen(float(12345)) Traceback (most recent call last): ... TypeError: integer_to_gen() needs an int or long argument, not float >>> integer_to_gen(2**100) 1267650600228229401496703205376 Tests: >>> import sys >>> if sys.version_info.major == 3: ... long = int >>> assert integer_to_gen(long(12345)) == 12345 >>> for i in range(10000): ... x = 3**i ... if pari(long(x)) != pari(x) or pari(int(x)) != pari(x): ... print(x) """ if isinstance(x, long): sig_on() return new_gen(PyLong_AsGEN(x)) elif isinstance(x, int): sig_on() return new_gen(stoi(PyInt_AS_LONG(x))) else: raise TypeError("integer_to_gen() needs an int or long argument, not {}".format(type(x).__name__)) cpdef gen_to_integer(Gen x): """ Convert a PARI ``gen`` to a Python ``int`` or ``long``. INPUT: - ``x`` -- a PARI ``t_INT``, ``t_FRAC``, ``t_REAL``, a purely real ``t_COMPLEX``, a ``t_INTMOD`` or ``t_PADIC`` (which are lifted). Examples: >>> from cypari2.convert import gen_to_integer >>> from cypari2 import Pari >>> pari = Pari() >>> a = gen_to_integer(pari("12345")); a; type(a) 12345 <... 'int'> >>> gen_to_integer(pari("10^30")) == 10**30 True >>> gen_to_integer(pari("19/5")) 3 >>> gen_to_integer(pari("1 + 0.0*I")) 1 >>> gen_to_integer(pari("3/2 + 0.0*I")) 1 >>> gen_to_integer(pari("Mod(-1, 11)")) 10 >>> gen_to_integer(pari("5 + O(5^10)")) 5 >>> gen_to_integer(pari("Pol(42)")) 42 >>> gen_to_integer(pari("u")) Traceback (most recent call last): ... TypeError: unable to convert PARI object u of type t_POL to an integer >>> s = pari("x + O(x^2)") >>> s x + O(x^2) >>> gen_to_integer(s) Traceback (most recent call last): ... TypeError: unable to convert PARI object x + O(x^2) of type t_SER to an integer >>> gen_to_integer(pari("1 + I")) Traceback (most recent call last): ... TypeError: unable to convert PARI object 1 + I of type t_COMPLEX to an integer Tests: >>> gen_to_integer(pari("1.0 - 2^64")) == -18446744073709551615 True >>> gen_to_integer(pari("1 - 2^64")) == -18446744073709551615 True >>> import sys >>> if sys.version_info.major == 3: ... long = int >>> for i in range(10000): ... x = 3**i ... if long(pari(x)) != long(x) or int(pari(x)) != x: ... print(x) Check some corner cases: >>> for s in [1, -1]: ... for a in [1, 2**31, 2**32, 2**63, 2**64]: ... for b in [-1, 0, 1]: ... Nstr = str(s * (a + b)) ... N1 = gen_to_integer(pari(Nstr)) # Convert via PARI ... N2 = int(Nstr) # Convert via Python ... if N1 != N2: ... print(Nstr, N1, N2) ... if type(N1) is not type(N2): ... print(N1, type(N1), N2, type(N2)) """ # First convert the input to a t_INT cdef GEN g = gtoi(x.g) if not signe(g): return 0 # Try converting to a C long first. Note that we cannot use itos() # from PARI since that does not deal with LONG_MIN correctly. cdef ulong u if lgefint(g) == 3: # abs(x) fits in a ulong u = g[2] # u = abs(x) # Check that (u) or (-u) does not overflow if signe(g) >= 0: if u <= LONG_MAX: return (u) else: if u <= -LONG_MIN: return (-u) # Result does not fit in a C long return PyLong_FromGEN(g) cdef GEN gtoi(GEN g0) except NULL: """ Convert a PARI object to a PARI integer. This function is shallow and not stack-clean. """ if typ(g0) == t_INT: return g0 cdef GEN g try: sig_on() g = simplify_shallow(g0) if typ(g) == t_COMPLEX: if gequal0(gel(g,2)): g = gel(g,1) if typ(g) == t_INTMOD: g = gel(g,2) g = trunc_safe(g) if typ(g) != t_INT: sig_error() sig_off() except RuntimeError: s = to_string(stack_sprintf( "unable to convert PARI object %Ps of type %s to an integer", g0, type_name(typ(g0)))) raise TypeError(s) return g cdef GEN PyLong_AsGEN(x): cdef const digit* D = (x).ob_digit # Size of the input cdef size_t sizedigits cdef long sgn if Py_SIZE(x) == 0: return gen_0 elif Py_SIZE(x) > 0: sizedigits = Py_SIZE(x) sgn = evalsigne(1) else: sizedigits = -Py_SIZE(x) sgn = evalsigne(-1) # Size of the output, in bits and in words cdef size_t sizebits = sizedigits * PyLong_SHIFT cdef size_t sizewords = (sizebits + BITS_IN_LONG - 1) // BITS_IN_LONG # Compute the most significant word of the output. # This is a special case because we need to be careful not to # overflow the ob_digit array. We also need to check for zero, # in which case we need to decrease sizewords. # See the loop below for an explanation of this code. cdef size_t bit = (sizewords - 1) * BITS_IN_LONG cdef size_t dgt = bit // PyLong_SHIFT bit = bit % PyLong_SHIFT cdef ulong w = (D[dgt]) >> bit if 1*PyLong_SHIFT - bit < BITS_IN_LONG and dgt+1 < sizedigits: w += (D[dgt+1]) << (1*PyLong_SHIFT - bit) if 2*PyLong_SHIFT - bit < BITS_IN_LONG and dgt+2 < sizedigits: w += (D[dgt+2]) << (2*PyLong_SHIFT - bit) if 3*PyLong_SHIFT - bit < BITS_IN_LONG and dgt+3 < sizedigits: w += (D[dgt+3]) << (3*PyLong_SHIFT - bit) if 4*PyLong_SHIFT - bit < BITS_IN_LONG and dgt+4 < sizedigits: w += (D[dgt+4]) << (4*PyLong_SHIFT - bit) if 5*PyLong_SHIFT - bit < BITS_IN_LONG and dgt+5 < sizedigits: w += (D[dgt+5]) << (5*PyLong_SHIFT - bit) # Effective size in words plus 2 special codewords cdef pariwords = sizewords+2 if w else sizewords+1 cdef GEN g = cgeti(pariwords) g[1] = sgn + evallgefint(pariwords) if w: int_MSW(g)[0] = w # Fill all words cdef GEN ptr = int_LSW(g) cdef size_t i for i in range(sizewords - 1): # The least significant bit of word number i of the output # integer is bit number "bit" of Python digit "dgt". bit = i * BITS_IN_LONG dgt = bit // PyLong_SHIFT bit = bit % PyLong_SHIFT # Now construct the output word from the Python digits: # 6 digits are enough assuming that PyLong_SHIFT >= 15 and # BITS_IN_LONG <= 76. The compiler should optimize away all # but one of the "if" statements below. w = (D[dgt]) >> bit if 1*PyLong_SHIFT - bit < BITS_IN_LONG: w += (D[dgt+1]) << (1*PyLong_SHIFT - bit) if 2*PyLong_SHIFT - bit < BITS_IN_LONG: w += (D[dgt+2]) << (2*PyLong_SHIFT - bit) if 3*PyLong_SHIFT - bit < BITS_IN_LONG: w += (D[dgt+3]) << (3*PyLong_SHIFT - bit) if 4*PyLong_SHIFT - bit < BITS_IN_LONG: w += (D[dgt+4]) << (4*PyLong_SHIFT - bit) if 5*PyLong_SHIFT - bit < BITS_IN_LONG: w += (D[dgt+5]) << (5*PyLong_SHIFT - bit) ptr[0] = w ptr = int_nextW(ptr) return g cdef PyLong_FromGEN(GEN g): # Size of input in words, bits and Python digits. The size in # digits might be a small over-estimation, but that is not a # problem. cdef size_t sizewords = (lgefint(g) - 2) cdef size_t sizebits = sizewords * BITS_IN_LONG cdef size_t sizedigits = (sizebits + PyLong_SHIFT - 1) // PyLong_SHIFT # Actual correct computed size cdef Py_ssize_t sizedigits_final = 0 x = _PyLong_New(sizedigits) cdef digit* D = (x).ob_digit cdef digit d cdef ulong w cdef size_t i, j, bit for i in range(sizedigits): # The least significant bit of digit number i of the output # integer is bit number "bit" of word "j". bit = i * PyLong_SHIFT j = bit // BITS_IN_LONG bit = bit % BITS_IN_LONG w = int_W(g, j)[0] d = w >> bit # Do we need bits from the next word too? if BITS_IN_LONG - bit < PyLong_SHIFT and j+1 < sizewords: w = int_W(g, j+1)[0] d += w << (BITS_IN_LONG - bit) d = d & PyLong_MASK D[i] = d # Keep track of last non-zero digit if d: sizedigits_final = i+1 # Set correct size (use a pointer to hack around Cython's # non-support for lvalues). cdef Py_ssize_t* sizeptr = Py_SIZE_PTR(x) if signe(g) > 0: sizeptr[0] = sizedigits_final else: sizeptr[0] = -sizedigits_final return x #################################### # Other basic types #################################### cdef Gen new_t_POL_from_int_star(int* vals, unsigned long length, long varnum): """ Note that degree + 1 = length, so that recognizing 0 is easier. varnum = 0 is the general choice (creates a variable in x). """ cdef GEN z cdef unsigned long i sig_on() z = cgetg(length + 2, t_POL) if length == 0: # Polynomial is zero z[1] = evalvarn(varnum) + evalsigne(0) else: z[1] = evalvarn(varnum) + evalsigne(1) for i in range(length): set_gel(z, i+2, stoi(vals[i])) return new_gen(z) cdef Gen new_gen_from_double(double x): # Pari has an odd concept where it attempts to track the accuracy # of floating-point 0; a floating-point zero might be 0.0e-20 # (meaning roughly that it might represent any number in the # range -1e-20 <= x <= 1e20). # Pari's dbltor converts a floating-point 0 into the Pari real # 0.0e-307; Pari treats this as an extremely precise 0. This # can cause problems; for instance, the Pari incgam() function can # be very slow if the first argument is very precise. # So we translate 0 into a floating-point 0 with 53 bits # of precision (that's the number of mantissa bits in an IEEE # double). cdef GEN g sig_on() if x == 0: g = real_0_bit(-53) else: g = dbltor(x) return new_gen(g) cdef Gen new_t_COMPLEX_from_double(double re, double im): sig_on() cdef GEN g = cgetg(3, t_COMPLEX) if re == 0: set_gel(g, 1, gen_0) else: set_gel(g, 1, dbltor(re)) if im == 0: set_gel(g, 2, gen_0) else: set_gel(g, 2, dbltor(im)) return new_gen(g) #################################### # Conversion of Gen to Python type # #################################### cpdef gen_to_python(Gen z): r""" Convert the PARI element ``z`` to a Python object. OUTPUT: - a Python integer for integers (type ``t_INT``) - a ``Fraction`` (``fractions`` module) for rationals (type ``t_FRAC``) - a ``float`` for real numbers (type ``t_REAL``) - a ``complex`` for complex numbers (type ``t_COMPLEX``) - a ``list`` for vectors (type ``t_VEC`` or ``t_COL``). The function ``gen_to_python`` is then recursively applied on the entries. - a ``list`` of Python integers for small vectors (type ``t_VECSMALL``) - a ``list`` of ``list``s for matrices (type ``t_MAT``). The function ``gen_to_python`` is then recursively applied on the entries. - the floating point ``inf`` or ``-inf`` for infinities (type ``t_INFINITY``) - a string for strings (type ``t_STR``) - other PARI types are not supported and the function will raise a ``NotImplementedError`` Examples: >>> from cypari2 import Pari >>> from cypari2.convert import gen_to_python >>> pari = Pari() Converting integers: >>> z = pari('42'); z 42 >>> a = gen_to_python(z); a 42 >>> type(a) <... 'int'> >>> gen_to_python(pari('3^50')) == 3**50 True >>> type(gen_to_python(pari('3^50'))) == type(3**50) True Converting rational numbers: >>> z = pari('2/3'); z 2/3 >>> a = gen_to_python(z); a Fraction(2, 3) >>> type(a) Converting real numbers (and infinities): >>> z = pari('1.2'); z 1.20000000000000 >>> a = gen_to_python(z); a 1.2 >>> type(a) <... 'float'> >>> z = pari('oo'); z +oo >>> a = gen_to_python(z); a inf >>> type(a) <... 'float'> >>> z = pari('-oo'); z -oo >>> a = gen_to_python(z); a -inf >>> type(a) <... 'float'> Converting complex numbers: >>> z = pari('1 + I'); z 1 + I >>> a = gen_to_python(z); a (1+1j) >>> type(a) <... 'complex'> >>> z = pari('2.1 + 3.03*I'); z 2.10000000000000 + 3.03000000000000*I >>> a = gen_to_python(z); a (2.1+3.03j) Converting vectors: >>> z1 = pari('Vecsmall([1,2,3])'); z1 Vecsmall([1, 2, 3]) >>> z2 = pari('[1, 3.4, [-5, 2], oo]'); z2 [1, 3.40000000000000, [-5, 2], +oo] >>> z3 = pari('[1, 5.2]~'); z3 [1, 5.20000000000000]~ >>> z1.type(), z2.type(), z3.type() ('t_VECSMALL', 't_VEC', 't_COL') >>> a1 = gen_to_python(z1); a1 [1, 2, 3] >>> type(a1) <... 'list'> >>> [type(x) for x in a1] [<... 'int'>, <... 'int'>, <... 'int'>] >>> a2 = gen_to_python(z2); a2 [1, 3.4, [-5, 2], inf] >>> type(a2) <... 'list'> >>> [type(x) for x in a2] [<... 'int'>, <... 'float'>, <... 'list'>, <... 'float'>] >>> a3 = gen_to_python(z3); a3 [1, 5.2] >>> type(a3) <... 'list'> >>> [type(x) for x in a3] [<... 'int'>, <... 'float'>] Converting matrices: >>> z = pari('[1,2;3,4]') >>> gen_to_python(z) [[1, 2], [3, 4]] >>> z = pari('[[1, 3], [[2]]; 3, [4, [5, 6]]]') >>> gen_to_python(z) [[[1, 3], [[2]]], [3, [4, [5, 6]]]] Converting strings: >>> z = pari('"Hello"') >>> a = gen_to_python(z); a 'Hello' >>> type(a) <... 'str'> Some currently unsupported types: >>> z = pari('x') >>> z.type() 't_POL' >>> gen_to_python(z) Traceback (most recent call last): ... NotImplementedError: conversion not implemented for t_POL >>> z = pari('12 + O(2^13)') >>> z.type() 't_PADIC' >>> gen_to_python(z) Traceback (most recent call last): ... NotImplementedError: conversion not implemented for t_PADIC """ cdef GEN g = z.g cdef long t = typ(g) cdef Py_ssize_t i, j, nr, nc if t == t_INT: return gen_to_integer(z) elif t == t_FRAC: from fractions import Fraction num = gen_to_integer(z.numerator()) den = gen_to_integer(z.denominator()) return Fraction(num, den) elif t == t_REAL: return rtodbl(g) elif t == t_COMPLEX: return complex(gen_to_python(z.real()), gen_to_python(z.imag())) elif t == t_VEC or t == t_COL: return [gen_to_python(x) for x in z.python_list()] elif t == t_VECSMALL: return z.python_list_small() elif t == t_MAT: nc = lg(g)-1 nr = 0 if nc == 0 else lg(gel(g,1))-1 return [[gen_to_python(z[i,j]) for j in range(nc)] for i in range(nr)] elif t == t_INFINITY: if inf_get_sign(g) >= 0: return INFINITY else: return -INFINITY elif t == t_STR: return to_string(GSTR(g)) else: raise NotImplementedError("conversion not implemented for {}".format(z.type())) cypari2-1.1.4/cypari2/stack.pxd0000644000201600020160000000031413136354561017710 0ustar jdemeyerjdemeyer00000000000000from .types cimport GEN, pari_sp from .gen cimport Gen cdef void clear_stack() cdef GEN deepcopy_to_python_heap(GEN x, void** address) except NULL cdef Gen new_gen(GEN x) cdef Gen new_gen_noclear(GEN x) cypari2-1.1.4/cypari2/pari_instance.pxd0000644000201600020160000000066113136354561021427 0ustar jdemeyerjdemeyer00000000000000from .types cimport * cimport cython from .gen cimport Gen cpdef long prec_bits_to_words(unsigned long prec_in_bits) cpdef long prec_words_to_bits(long prec_in_words) cpdef long default_bitprec() cdef class Pari_auto: pass cdef class Pari(Pari_auto): cdef readonly Gen PARI_ZERO, PARI_ONE, PARI_TWO cpdef Gen zero(self) cpdef Gen one(self) cdef Gen _empty_vector(self, long n) cdef long get_var(v) except -2 cypari2-1.1.4/cypari2/closure.pyx0000644000201600020160000001275013227353445020314 0ustar jdemeyerjdemeyer00000000000000""" Convert Python functions to PARI closures ***************************************** AUTHORS: - Jeroen Demeyer (2015-04-10): initial version, :trac:`18052`. Examples: >>> def the_answer(): ... return 42 >>> import cypari2 >>> pari = cypari2.Pari() >>> f = pari(the_answer) >>> f() 42 >>> cube = pari(lambda i: i**3) >>> cube.apply(range(10)) [0, 1, 8, 27, 64, 125, 216, 343, 512, 729] """ #***************************************************************************** # Copyright (C) 2015 Jeroen Demeyer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** from __future__ import absolute_import, division, print_function from cysignals.signals cimport sig_on, sig_off, sig_block, sig_unblock, sig_error from cpython.tuple cimport * from cpython.object cimport PyObject_Call from cpython.ref cimport Py_INCREF from .paridecl cimport * from .stack cimport new_gen, new_gen_noclear from .gen cimport objtogen cdef inline GEN call_python_func_impl "call_python_func"(GEN* args, object py_func) except NULL: """ Call ``py_func(*args)`` where ``py_func`` is a Python function and ``args`` is an array of ``GEN``s terminated by ``NULL``. The arguments are converted from ``GEN`` to a cypari ``gen`` before calling ``py_func``. The result is converted back to a PARI ``GEN``. """ # How many arguments are there? cdef Py_ssize_t n = 0 while args[n] != NULL: n += 1 # Construct a Python tuple for args cdef tuple t = PyTuple_New(n) cdef Py_ssize_t i for i in range(n): a = new_gen_noclear(args[i]) Py_INCREF(a) # Need to increase refcount because the tuple steals it PyTuple_SET_ITEM(t, i, a) # Call the Python function r = PyObject_Call(py_func, t, NULL) # Convert the result to a GEN and copy it to the PARI stack # (with a special case for None) if r is None: return gnil return gcopy(objtogen(r).g) # We rename this function to be able to call it with a different # signature. In particular, we want manual exception handling and we # implicitly convert py_func from a PyObject* to an object. cdef extern from *: GEN call_python_func(GEN* args, PyObject* py_func) cdef GEN call_python(GEN arg1, GEN arg2, GEN arg3, GEN arg4, GEN arg5, ulong py_func): """ This function, which will be installed in PARI, is a front-end for ``call_python_func_impl``. It has 5 optional ``GEN``s as argument and one ``ulong``. This last argument is actually a Python callable object cast to ``ulong``. """ # Convert arguments to a NULL-terminated array. From PARI's point # of view, all these arguments are optional: if an argument is not # given, PARI will pass NULL as argument and the array will # terminate sooner. cdef GEN args[6] args[0] = arg1 args[1] = arg2 args[2] = arg3 args[3] = arg4 args[4] = arg5 args[5] = NULL sig_block() # Disallow interrupts during the Python code inside # call_python_func_impl(). We need to do this because this function # is very likely called within sig_on() and interrupting arbitrary # Python code is bad. cdef GEN r = call_python_func(args, py_func) sig_unblock() if not r: # An exception was raised sig_error() return r # Install the function "call_python" for use in the PARI library. cdef entree* ep_call_python cdef void _pari_init_closure(): global ep_call_python ep_call_python = install(call_python, "call_python", "DGDGDGDGDGU") cpdef Gen objtoclosure(f): """ Convert a Python function (more generally, any callable) to a PARI ``t_CLOSURE``. .. NOTE:: With the current implementation, the function can be called with at most 5 arguments. .. WARNING:: The function ``f`` which is called through the closure cannot be interrupted. Therefore, it is advised to use this only for simple functions which do not take a long time. Examples: >>> from cypari2.closure import objtoclosure >>> def pymul(i,j): return i*j >>> mul = objtoclosure(pymul) >>> mul (v1,v2,v3,v4,v5)->call_python(v1,v2,v3,v4,v5,...) >>> mul.type() 't_CLOSURE' >>> mul(6,9) 54 >>> def printme(x): ... print(x) >>> objtoclosure(printme)('matid(2)') [1, 0; 0, 1] Test various kinds of errors: >>> mul(4) Traceback (most recent call last): ... TypeError: pymul() ... >>> mul(None, None) Traceback (most recent call last): ... ValueError: Cannot convert None to pari >>> mul(*range(100)) Traceback (most recent call last): ... PariError: call_python: too many parameters in user-defined function call >>> mul([1], [2]) Traceback (most recent call last): ... PariError: call_python: forbidden multiplication t_VEC (1 elts) * t_VEC (1 elts) """ sig_on() # Convert f to a t_INT containing the address of f cdef GEN f_int = utoi(f) # Create a t_CLOSURE which calls call_python() with py_func equal to f cdef Gen c = new_gen(snm_closure(ep_call_python, mkvec(f_int))) c.cache(0, f) # c needs to keep a reference to f return c cypari2-1.1.4/cypari2/__init__.py0000644000201600020160000000013113136354561020174 0ustar jdemeyerjdemeyer00000000000000from .pari_instance import Pari from .handle_error import PariError from .gen import Gen cypari2-1.1.4/cypari2/paridecl.pxd0000644000201600020160000061404513234322135020371 0ustar jdemeyerjdemeyer00000000000000# distutils: libraries = gmp pari """ Declarations for non-inline functions from PARI. This file contains all declarations from headers/paridecl.h from the PARI distribution, except the inline functions which are in declinl.pxi (that file is automatically included by this file). AUTHORS: - (unknown authors before 2010) - Robert Bradshaw, Jeroen Demeyer, William Stein (2010-08-15): Upgrade to PARI 2.4.3 (:trac:`9343`) - Jeroen Demeyer (2010-08-15): big clean up (:trac:`9898`) - Jeroen Demeyer (2014-02-09): upgrade to PARI 2.7 (:trac:`15767`) - Jeroen Demeyer (2014-09-19): upgrade to PARI 2.8 (:trac:`16997`) """ #***************************************************************************** # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** from __future__ import print_function from libc.stdio cimport FILE from cpython.getargs cimport va_list from .types cimport * cdef extern from *: # PARI headers already included by types.pxd char* PARIVERSION # parierr.h enum err_list: e_SYNTAX, e_BUG e_ALARM, e_FILE e_MISC, e_FLAG, e_IMPL, e_ARCH, e_PACKAGE, e_NOTFUNC e_PREC, e_TYPE, e_DIM, e_VAR, e_PRIORITY, e_USER e_STACK, e_OVERFLOW, e_DOMAIN, e_COMPONENT e_MAXPRIME e_CONSTPOL, e_IRREDPOL, e_COPRIME, e_PRIME, e_MODULUS, e_ROOTS0 e_OP, e_TYPE2, e_INV e_MEM e_SQRTN e_NONE int warner, warnprec, warnfile, warnmem, warnuser # paricast.h long mael2(GEN, long, long) long mael3(GEN, long, long, long) long mael4(GEN, long, long, long, long) long mael5(GEN, long, long, long, long, long) long mael(GEN, long, long) GEN gmael1(GEN, long) GEN gmael2(GEN, long, long) GEN gmael3(GEN, long, long, long) GEN gmael4(GEN, long, long, long, long) GEN gmael5(GEN, long, long, long, long, long) GEN gmael(GEN, long, long) GEN gel(GEN, long) GEN gcoeff(GEN, long, long) long coeff(GEN, long, long) char* GSTR(GEN) # paricom.h GEN gen_1 GEN gen_m1 GEN gen_2 GEN gen_m2 GEN ghalf GEN gen_0 GEN gnil int PARI_SIGINT_block, PARI_SIGINT_pending void NEXT_PRIME_VIADIFF(long, byteptr) void PREC_PRIME_VIADIFF(long, byteptr) int INIT_JMPm, INIT_SIGm, INIT_DFTm, INIT_noPRIMEm, INIT_noIMTm int new_galois_format, factor_add_primes, factor_proven int precdl # The "except 0" here is to ensure compatibility with # _pari_err_handle() in handle_error.pyx int (*cb_pari_err_handle)(GEN) except 0 int (*cb_pari_handle_exception)(long) except 0 void (*cb_pari_err_recover)(long) # kernel/gmp/int.h GEN int_MSW(GEN z) GEN int_LSW(GEN z) GEN int_W(GEN z, long i) GEN int_W_lg(GEN z, long i, long lz) GEN int_precW(GEN z) GEN int_nextW(GEN z) # paristio.h extern pari_sp avma struct _pari_mainstack "pari_mainstack": pari_sp top, bot, vbot size_t size, rsize, vsize, memused extern _pari_mainstack* pari_mainstack struct PariOUT: void (*putch)(char) void (*puts)(char*) void (*flush)() extern PariOUT* pariOut extern PariOUT* pariErr extern byteptr diffptr ############################################### # # # All declarations below come from paridecl.h # # # ############################################### # OBSOLETE GEN bernvec(long nomb) # F2x.c GEN F2c_to_ZC(GEN x) GEN F2c_to_mod(GEN x) GEN F2m_rowslice(GEN x, long a, long b) GEN F2m_to_Flm(GEN z) GEN F2m_to_ZM(GEN z) GEN F2m_to_mod(GEN z) void F2v_add_inplace(GEN x, GEN y) ulong F2v_dotproduct(GEN x, GEN y) GEN F2v_slice(GEN x, long a, long b) GEN F2v_to_Flv(GEN x) GEN F2x_F2xq_eval(GEN Q, GEN x, GEN T) GEN F2x_F2xqV_eval(GEN P, GEN V, GEN T) GEN F2x_Frobenius(GEN T) GEN F2x_1_add(GEN y) GEN F2x_add(GEN x, GEN y) GEN F2x_deflate(GEN x0, long d) long F2x_degree(GEN x) GEN F2x_deriv(GEN x) GEN F2x_divrem(GEN x, GEN y, GEN *pr) ulong F2x_eval(GEN P, ulong x) void F2x_even_odd(GEN p, GEN *pe, GEN *po) GEN F2x_extgcd(GEN a, GEN b, GEN *ptu, GEN *ptv) GEN F2x_gcd(GEN a, GEN b) GEN F2x_halfgcd(GEN a, GEN b) int F2x_issquare(GEN a) GEN F2x_matFrobenius(GEN T) GEN F2x_mul(GEN x, GEN y) GEN F2x_rem(GEN x, GEN y) GEN F2x_shift(GEN y, long d) GEN F2x_sqr(GEN x) GEN F2x_sqrt(GEN x) GEN F2x_to_F2v(GEN x, long n) GEN F2x_to_Flx(GEN x) GEN F2x_to_ZX(GEN x) long F2x_valrem(GEN x, GEN *Z) GEN F2xC_to_FlxC(GEN v) GEN F2xC_to_ZXC(GEN x) GEN F2xV_to_F2m(GEN v, long n) GEN F2xX_F2x_mul(GEN P, GEN U) GEN F2xX_add(GEN x, GEN y) GEN F2xX_deriv(GEN z) GEN F2xX_renormalize(GEN x, long lx) GEN F2xX_to_Kronecker(GEN P, long d) GEN F2xX_to_ZXX(GEN B) GEN F2xY_F2xq_evalx(GEN P, GEN x, GEN T) GEN F2xY_F2xqV_evalx(GEN P, GEN x, GEN T) long F2xY_degreex(GEN b) GEN F2xq_Artin_Schreier(GEN a, GEN T) GEN F2xq_autpow(GEN x, long n, GEN T) GEN F2xq_conjvec(GEN x, GEN T) GEN F2xq_div(GEN x, GEN y, GEN T) GEN F2xq_inv(GEN x, GEN T) GEN F2xq_invsafe(GEN x, GEN T) GEN F2xq_log(GEN a, GEN g, GEN ord, GEN T) GEN F2xq_matrix_pow(GEN y, long n, long m, GEN P) GEN F2xq_mul(GEN x, GEN y, GEN pol) GEN F2xq_order(GEN a, GEN ord, GEN T) GEN F2xq_pow(GEN x, GEN n, GEN pol) GEN F2xq_powu(GEN x, ulong n, GEN pol) GEN F2xq_powers(GEN x, long l, GEN T) GEN F2xq_sqr(GEN x, GEN pol) GEN F2xq_sqrt(GEN a, GEN T) GEN F2xq_sqrt_fast(GEN c, GEN sqx, GEN T) GEN F2xq_sqrtn(GEN a, GEN n, GEN T, GEN *zeta) ulong F2xq_trace(GEN x, GEN T) GEN F2xqX_F2xq_mul(GEN P, GEN U, GEN T) GEN F2xqX_F2xq_mul_to_monic(GEN P, GEN U, GEN T) GEN F2xqX_F2xqXQ_eval(GEN Q, GEN x, GEN S, GEN T) GEN F2xqX_F2xqXQV_eval(GEN P, GEN V, GEN S, GEN T) GEN F2xqX_divrem(GEN x, GEN y, GEN T, GEN *pr) GEN F2xqX_gcd(GEN a, GEN b, GEN T) GEN F2xqX_mul(GEN x, GEN y, GEN T) GEN F2xqX_normalize(GEN z, GEN T) GEN F2xqX_red(GEN z, GEN T) GEN F2xqX_rem(GEN x, GEN S, GEN T) GEN F2xqX_sqr(GEN x, GEN T) GEN F2xqXQ_mul(GEN x, GEN y, GEN S, GEN T) GEN F2xqXQ_sqr(GEN x, GEN S, GEN T) GEN F2xqXQ_pow(GEN x, GEN n, GEN S, GEN T) GEN F2xqXQ_powers(GEN x, long l, GEN S, GEN T) GEN F2xqXQV_autpow(GEN aut, long n, GEN S, GEN T) GEN F2xqXQV_auttrace(GEN aut, long n, GEN S, GEN T) GEN Flm_to_F2m(GEN x) GEN Flv_to_F2v(GEN x) GEN Flx_to_F2x(GEN x) GEN FlxC_to_F2xC(GEN x) GEN FlxX_to_F2xX(GEN B) GEN Kronecker_to_F2xqX(GEN z, GEN T) GEN Rg_to_F2xq(GEN x, GEN T) GEN RgM_to_F2m(GEN x) GEN RgV_to_F2v(GEN x) GEN RgX_to_F2x(GEN x) GEN Z_to_F2x(GEN x, long v) GEN ZM_to_F2m(GEN x) GEN ZV_to_F2v(GEN x) GEN ZX_to_F2x(GEN x) GEN ZXX_to_F2xX(GEN B, long v) GEN const_F2v(long m) GEN gener_F2xq(GEN T, GEN *po) const bb_field *get_F2xq_field(void **E, GEN T) GEN monomial_F2x(long d, long vs) GEN pol1_F2xX(long v, long sv) GEN polx_F2xX(long v, long sv) GEN random_F2x(long d, long vs) GEN random_F2xqX(long d1, long v, GEN T) # F2xqE.c GEN F2xq_ellcard(GEN a2, GEN a6, GEN T) GEN F2xq_ellgens(GEN a2, GEN a6, GEN ch, GEN D, GEN m, GEN T) GEN F2xq_ellgroup(GEN a2, GEN a6, GEN N, GEN T, GEN *pt_m) void F2xq_elltwist(GEN a, GEN a6, GEN T, GEN *pt_a, GEN *pt_a6) GEN F2xqE_add(GEN P, GEN Q, GEN a2, GEN T) GEN F2xqE_changepoint(GEN x, GEN ch, GEN T) GEN F2xqE_changepointinv(GEN x, GEN ch, GEN T) GEN F2xqE_dbl(GEN P, GEN a2, GEN T) GEN F2xqE_log(GEN a, GEN b, GEN o, GEN a2, GEN T) GEN F2xqE_mul(GEN P, GEN n, GEN a2, GEN T) GEN F2xqE_neg(GEN P, GEN a2, GEN T) GEN F2xqE_order(GEN z, GEN o, GEN a2, GEN T) GEN F2xqE_sub(GEN P, GEN Q, GEN a2, GEN T) GEN F2xqE_tatepairing(GEN t, GEN s, GEN m, GEN a2, GEN T) GEN F2xqE_weilpairing(GEN t, GEN s, GEN m, GEN a2, GEN T) const bb_group * get_F2xqE_group(void **E, GEN a2, GEN a6, GEN T) GEN RgE_to_F2xqE(GEN x, GEN T) GEN random_F2xqE(GEN a2, GEN a6, GEN T) # Fle.c ulong Fl_elldisc(ulong a4, ulong a6, ulong p) ulong Fl_elldisc_pre(ulong a4, ulong a6, ulong p, ulong pi) ulong Fl_ellj(ulong a4, ulong a6, ulong p) void Fl_ellj_to_a4a6(ulong j, ulong p, ulong *pt_a4, ulong *pt_a6) void Fl_elltwist(ulong a4, ulong a6, ulong p, ulong *pt_a4, ulong *pt_a6) void Fl_elltwist_disc(ulong a4, ulong a6, ulong D, ulong p, ulong *pt_a4, ulong *pt_a6) GEN Fle_add(GEN P, GEN Q, ulong a4, ulong p) GEN Fle_dbl(GEN P, ulong a4, ulong p) GEN Fle_changepoint(GEN x, GEN ch, ulong p) GEN Fle_changepointinv(GEN x, GEN ch, ulong p) GEN Fle_log(GEN a, GEN b, GEN o, ulong a4, ulong p) GEN Fle_mul(GEN P, GEN n, ulong a4, ulong p) GEN Fle_mulu(GEN P, ulong n, ulong a4, ulong p) GEN Fle_order(GEN z, GEN o, ulong a4, ulong p) GEN Fle_sub(GEN P, GEN Q, ulong a4, ulong p) GEN Fle_to_Flj(GEN P) GEN Flj_add_pre(GEN P, GEN Q, ulong a4, ulong p, ulong pi) GEN Flj_dbl_pre(GEN P, ulong a4, ulong p, ulong pi) GEN Flj_mulu_pre(GEN P, ulong n, ulong a4, ulong p, ulong pi) GEN Flj_neg(GEN Q, ulong p) GEN Flj_to_Fle_pre(GEN P, ulong p, ulong pi) GEN random_Fle(ulong a4, ulong a6, ulong p) GEN random_Fle_pre(ulong a4, ulong a6, ulong p, ulong pi) GEN random_Flj_pre(ulong a4, ulong a6, ulong p, ulong pi) # Flx.c GEN Fl_to_Flx(ulong x, long sv) int Fl2_equal1(GEN x) GEN Fl2_inv_pre(GEN x, ulong D, ulong p, ulong pi) GEN Fl2_mul_pre(GEN x, GEN y, ulong D, ulong p, ulong pi) ulong Fl2_norm_pre(GEN x, ulong D, ulong p, ulong pi) GEN Fl2_pow_pre(GEN x, GEN n, ulong D, ulong p, ulong pi) GEN Fl2_sqr_pre(GEN x, ulong D, ulong p, ulong pi) GEN Fl2_sqrtn_pre(GEN a, GEN n, ulong D, ulong p, ulong pi, GEN *zeta) GEN Flc_to_ZC(GEN z) GEN Flm_to_FlxV(GEN x, long sv) GEN Flm_to_FlxX(GEN x, long v, long w) GEN Flm_to_ZM(GEN z) GEN Flv_Flm_polint(GEN xa, GEN ya, ulong p, long vs) GEN Flv_inv(GEN x, ulong p) void Flv_inv_inplace(GEN x, ulong p) void Flv_inv_pre_inplace(GEN x, ulong p, ulong pi) GEN Flv_inv_pre(GEN x, ulong p, ulong pi) GEN Flv_polint(GEN xa, GEN ya, ulong p, long vs) ulong Flv_prod(GEN v, ulong p) ulong Flv_prod_pre(GEN x, ulong p, ulong pi) GEN Flv_roots_to_pol(GEN a, ulong p, long vs) GEN Flv_to_Flx(GEN x, long vs) GEN Fly_to_FlxY(GEN B, long v) GEN Flv_to_ZV(GEN z) GEN Flx_Fl_add(GEN y, ulong x, ulong p) GEN Flx_Fl_mul(GEN y, ulong x, ulong p) GEN Flx_Fl_mul_to_monic(GEN y, ulong x, ulong p) GEN Flx_Fl2_eval_pre(GEN x, GEN y, ulong D, ulong p, ulong pi) GEN Flx_Flv_multieval(GEN P, GEN v, ulong p) GEN Flx_Flxq_eval(GEN f, GEN x, GEN T, ulong p) GEN Flx_FlxqV_eval(GEN f, GEN x, GEN T, ulong p) GEN Flx_Frobenius(GEN T, ulong p) GEN Flx_add(GEN x, GEN y, ulong p) GEN Flx_deflate(GEN x0, long d) GEN Flx_deriv(GEN z, ulong p) GEN Flx_double(GEN y, ulong p) GEN Flx_div_by_X_x(GEN a, ulong x, ulong p, ulong *rem) GEN Flx_divrem(GEN x, GEN y, ulong p, GEN *pr) int Flx_equal(GEN V, GEN W) ulong Flx_eval(GEN x, ulong y, ulong p) ulong Flx_eval_powers_pre(GEN x, GEN y, ulong p, ulong pi) ulong Flx_eval_pre(GEN x, ulong y, ulong p, ulong pi) GEN Flx_extgcd(GEN a, GEN b, ulong p, GEN *ptu, GEN *ptv) ulong Flx_extresultant(GEN a, GEN b, ulong p, GEN *ptU, GEN *ptV) GEN Flx_gcd(GEN a, GEN b, ulong p) GEN Flx_get_red(GEN T, ulong p) GEN Flx_halfgcd(GEN a, GEN b, ulong p) GEN Flx_halve(GEN y, ulong p) GEN Flx_inflate(GEN x0, long d) GEN Flx_invBarrett(GEN T, ulong p) int Flx_is_squarefree(GEN z, ulong p) int Flx_is_smooth(GEN g, long r, ulong p) GEN Flx_matFrobenius(GEN T, ulong p) GEN Flx_mod_Xn1(GEN T, ulong n, ulong p) GEN Flx_mod_Xnm1(GEN T, ulong n, ulong p) GEN Flx_mul(GEN x, GEN y, ulong p) GEN Flx_neg(GEN x, ulong p) GEN Flx_neg_inplace(GEN x, ulong p) GEN Flx_normalize(GEN z, ulong p) GEN Flx_powu(GEN x, ulong n, ulong p) GEN Flx_recip(GEN x) GEN Flx_red(GEN z, ulong p) GEN Flx_rem(GEN x, GEN y, ulong p) GEN Flx_renormalize(GEN x, long l) GEN Flx_rescale(GEN P, ulong h, ulong p) ulong Flx_resultant(GEN a, GEN b, ulong p) GEN Flx_shift(GEN a, long n) GEN Flx_splitting(GEN p, long k) GEN Flx_sqr(GEN x, ulong p) GEN Flx_sub(GEN x, GEN y, ulong p) GEN Flx_to_Flv(GEN x, long N) GEN Flx_to_FlxX(GEN z, long v) GEN Flx_to_ZX(GEN z) GEN Flx_to_ZX_inplace(GEN z) GEN Flx_triple(GEN y, ulong p) long Flx_val(GEN x) long Flx_valrem(GEN x, GEN *Z) GEN FlxC_to_ZXC(GEN x) GEN FlxM_Flx_add_shallow(GEN x, GEN y, ulong p) GEN FlxM_to_ZXM(GEN z) GEN FlxT_red(GEN z, ulong p) GEN FlxV_Flc_mul(GEN V, GEN W, ulong p) GEN FlxV_prod(GEN V, ulong p) GEN FlxV_red(GEN z, ulong p) GEN FlxV_to_Flm(GEN v, long n) GEN FlxV_to_ZXV(GEN x) GEN FlxX_Fl_mul(GEN x, ulong y, ulong p) GEN FlxX_Flx_add(GEN y, GEN x, ulong p) GEN FlxX_Flx_mul(GEN x, GEN y, ulong p) GEN FlxX_add(GEN P, GEN Q, ulong p) GEN FlxX_deriv(GEN z, ulong p) GEN FlxX_double(GEN x, ulong p) GEN FlxX_neg(GEN x, ulong p) GEN FlxX_sub(GEN P, GEN Q, ulong p) GEN FlxX_swap(GEN x, long n, long ws) GEN FlxX_renormalize(GEN x, long lx) GEN FlxX_shift(GEN a, long n) GEN FlxX_to_Flm(GEN v, long n) GEN FlxX_to_FlxC(GEN x, long N, long sv) GEN FlxX_to_ZXX(GEN B) GEN FlxX_triple(GEN x, ulong p) GEN FlxXC_to_ZXXC(GEN B) GEN FlxXM_to_ZXXM(GEN B) GEN FlxXV_to_FlxM(GEN v, long n, long sv) GEN FlxY_Flx_div(GEN x, GEN y, ulong p) GEN FlxY_Flx_translate(GEN P, GEN c, ulong p) GEN FlxY_Flxq_evalx(GEN P, GEN x, GEN T, ulong p) GEN FlxY_FlxqV_evalx(GEN P, GEN x, GEN T, ulong p) ulong FlxY_eval_powers_pre(GEN pol, GEN ypowers, GEN xpowers, ulong p, ulong pi) GEN FlxY_evalx(GEN Q, ulong x, ulong p) GEN FlxY_evalx_powers_pre(GEN pol, GEN ypowers, ulong p, ulong pi) GEN FlxYqq_pow(GEN x, GEN n, GEN S, GEN T, ulong p) GEN Flxq_autpow(GEN x, ulong n, GEN T, ulong p) GEN Flxq_autsum(GEN x, ulong n, GEN T, ulong p) GEN Flxq_auttrace(GEN x, ulong n, GEN T, ulong p) GEN Flxq_charpoly(GEN x, GEN T, ulong p) GEN Flxq_conjvec(GEN x, GEN T, ulong p) GEN Flxq_div(GEN x, GEN y, GEN T, ulong p) GEN Flxq_inv(GEN x, GEN T, ulong p) GEN Flxq_invsafe(GEN x, GEN T, ulong p) int Flxq_issquare(GEN x, GEN T, ulong p) int Flxq_is2npower(GEN x, long n, GEN T, ulong p) GEN Flxq_log(GEN a, GEN g, GEN ord, GEN T, ulong p) GEN Flxq_lroot(GEN a, GEN T, long p) GEN Flxq_lroot_fast(GEN a, GEN sqx, GEN T, long p) GEN Flxq_matrix_pow(GEN y, long n, long m, GEN P, ulong l) GEN Flxq_minpoly(GEN x, GEN T, ulong p) GEN Flxq_mul(GEN x, GEN y, GEN T, ulong p) ulong Flxq_norm(GEN x, GEN T, ulong p) GEN Flxq_order(GEN a, GEN ord, GEN T, ulong p) GEN Flxq_pow(GEN x, GEN n, GEN T, ulong p) GEN Flxq_powu(GEN x, ulong n, GEN T, ulong p) GEN Flxq_powers(GEN x, long l, GEN T, ulong p) GEN Flxq_sqr(GEN y, GEN T, ulong p) GEN Flxq_sqrt(GEN a, GEN T, ulong p) GEN Flxq_sqrtn(GEN a, GEN n, GEN T, ulong p, GEN *zetan) ulong Flxq_trace(GEN x, GEN T, ulong p) GEN FlxqV_dotproduct(GEN x, GEN y, GEN T, ulong p) GEN FlxqV_roots_to_pol(GEN V, GEN T, ulong p, long v) GEN FlxqX_FlxqXQ_eval(GEN Q, GEN x, GEN S, GEN T, ulong p) GEN FlxqX_FlxqXQV_eval(GEN P, GEN V, GEN S, GEN T, ulong p) GEN FlxqX_Flxq_mul(GEN P, GEN U, GEN T, ulong p) GEN FlxqX_Flxq_mul_to_monic(GEN P, GEN U, GEN T, ulong p) GEN FlxqX_divrem(GEN x, GEN y, GEN T, ulong p, GEN *pr) GEN FlxqX_extgcd(GEN a, GEN b, GEN T, ulong p, GEN *ptu, GEN *ptv) GEN FlxqX_gcd(GEN P, GEN Q, GEN T, ulong p) GEN FlxqX_get_red(GEN S, GEN T, ulong p) GEN FlxqX_halfgcd(GEN x, GEN y, GEN T, ulong p) GEN FlxqX_invBarrett(GEN T, GEN Q, ulong p) GEN FlxqX_mul(GEN x, GEN y, GEN T, ulong p) GEN FlxqX_normalize(GEN z, GEN T, ulong p) GEN FlxqX_pow(GEN V, long n, GEN T, ulong p) GEN FlxqX_red(GEN z, GEN T, ulong p) GEN FlxqX_rem(GEN x, GEN y, GEN T, ulong p) GEN FlxqX_safegcd(GEN P, GEN Q, GEN T, ulong p) GEN FlxqX_sqr(GEN x, GEN T, ulong p) GEN FlxqXQ_div(GEN x, GEN y, GEN S, GEN T, ulong p) GEN FlxqXQ_inv(GEN x, GEN S, GEN T, ulong p) GEN FlxqXQ_invsafe(GEN x, GEN S, GEN T, ulong p) GEN FlxqXQ_matrix_pow(GEN x, long n, long m, GEN S, GEN T, ulong p) GEN FlxqXQ_mul(GEN x, GEN y, GEN S, GEN T, ulong p) GEN FlxqXQ_pow(GEN x, GEN n, GEN S, GEN T, ulong p) GEN FlxqXQ_powu(GEN x, ulong n, GEN S, GEN T, ulong p) GEN FlxqXQ_powers(GEN x, long n, GEN S, GEN T, ulong p) GEN FlxqXQ_sqr(GEN x, GEN S, GEN T, ulong p) GEN FlxqXQV_autpow(GEN x, long n, GEN S, GEN T, ulong p) GEN FlxqXQV_autsum(GEN aut, long n, GEN S, GEN T, ulong p) GEN FlxqXV_prod(GEN V, GEN T, ulong p) GEN Kronecker_to_FlxqX(GEN z, GEN T, ulong p) ulong Rg_to_F2(GEN x) ulong Rg_to_Fl(GEN x, ulong p) GEN Rg_to_Flxq(GEN x, GEN T, ulong p) GEN RgX_to_Flx(GEN x, ulong p) GEN Z_to_Flx(GEN x, ulong p, long sv) GEN ZX_to_Flx(GEN x, ulong p) GEN ZXV_to_FlxV(GEN v, ulong p) GEN ZXT_to_FlxT(GEN z, ulong p) GEN ZXX_to_FlxX(GEN B, ulong p, long v) GEN ZXXT_to_FlxXT(GEN z, ulong p, long v) GEN ZXXV_to_FlxXV(GEN V, ulong p, long v) GEN gener_Flxq(GEN T, ulong p, GEN *o) long get_Flx_degree(GEN T) GEN get_Flx_mod(GEN T) long get_Flx_var(GEN T) long get_FlxqX_degree(GEN T) GEN get_FlxqX_mod(GEN T) long get_FlxqX_var(GEN T) const bb_field *get_Flxq_field(void **E, GEN T, ulong p) const bb_group *get_Flxq_star(void **E, GEN T, ulong p) GEN monomial_Flx(ulong a, long d, long vs) GEN pol1_FlxX(long v, long sv) GEN polx_FlxX(long v, long sv) GEN random_Flx(long d1, long v, ulong p) GEN random_FlxqX(long d1, long v, GEN T, ulong p) GEN zx_to_Flx(GEN x, ulong p) GEN zxX_to_FlxX(GEN B, ulong p) GEN zxX_to_Kronecker(GEN P, GEN Q) # FlxqE.c GEN Flxq_ellcard(GEN a4, GEN a6, GEN T, ulong p) GEN Flxq_ellgens(GEN a4, GEN a6, GEN ch, GEN D, GEN m, GEN T, ulong p) GEN Flxq_ellgroup(GEN a4, GEN a6, GEN N, GEN T, ulong p, GEN *pt_m) void Flxq_elltwist(GEN a, GEN a6, GEN T, ulong p, GEN *pt_a, GEN *pt_a6) GEN Flxq_ellj(GEN a4, GEN a6, GEN T, ulong p) void Flxq_ellj_to_a4a6(GEN j, GEN T, ulong p, GEN *pt_a4, GEN *pt_a6) GEN FlxqE_add(GEN P, GEN Q, GEN a4, GEN T, ulong p) GEN FlxqE_changepoint(GEN x, GEN ch, GEN T, ulong p) GEN FlxqE_changepointinv(GEN x, GEN ch, GEN T, ulong p) GEN FlxqE_dbl(GEN P, GEN a4, GEN T, ulong p) GEN FlxqE_log(GEN a, GEN b, GEN o, GEN a4, GEN T, ulong p) GEN FlxqE_mul(GEN P, GEN n, GEN a4, GEN T, ulong p) GEN FlxqE_neg(GEN P, GEN T, ulong p) GEN FlxqE_order(GEN z, GEN o, GEN a4, GEN T, ulong p) GEN FlxqE_sub(GEN P, GEN Q, GEN a4, GEN T, ulong p) GEN FlxqE_tatepairing(GEN t, GEN s, GEN m, GEN a4, GEN T, ulong p) GEN FlxqE_weilpairing(GEN t, GEN s, GEN m, GEN a4, GEN T, ulong p) const bb_group * get_FlxqE_group(void **E, GEN a4, GEN a6, GEN T, ulong p) GEN RgE_to_FlxqE(GEN x, GEN T, ulong p) GEN random_FlxqE(GEN a4, GEN a6, GEN T, ulong p) # FpE.c long Fl_elltrace(ulong a4, ulong a6, ulong p) long Fl_elltrace_CM(long CM, ulong a4, ulong a6, ulong p) GEN Fp_ellcard(GEN a4, GEN a6, GEN p) GEN Fp_elldivpol(GEN a4, GEN a6, long n, GEN p) GEN Fp_ellgens(GEN a4, GEN a6, GEN ch, GEN D, GEN m, GEN p) GEN Fp_ellgroup(GEN a4, GEN a6, GEN N, GEN p, GEN *pt_m) GEN Fp_ellj(GEN a4, GEN a6, GEN p) int Fp_elljissupersingular(GEN j, GEN p) void Fp_elltwist(GEN a4, GEN a6, GEN p, GEN *pt_a4, GEN *pt_a6) GEN Fp_ffellcard(GEN a4, GEN a6, GEN q, long n, GEN p) GEN FpE_add(GEN P, GEN Q, GEN a4, GEN p) GEN FpE_changepoint(GEN x, GEN ch, GEN p) GEN FpE_changepointinv(GEN x, GEN ch, GEN p) GEN FpE_dbl(GEN P, GEN a4, GEN p) GEN FpE_log(GEN a, GEN b, GEN o, GEN a4, GEN p) GEN FpE_mul(GEN P, GEN n, GEN a4, GEN p) GEN FpE_neg(GEN P, GEN p) GEN FpE_order(GEN z, GEN o, GEN a4, GEN p) GEN FpE_sub(GEN P, GEN Q, GEN a4, GEN p) GEN FpE_to_mod(GEN P, GEN p) GEN FpE_tatepairing(GEN t, GEN s, GEN m, GEN a4, GEN p) GEN FpE_weilpairing(GEN t, GEN s, GEN m, GEN a4, GEN p) GEN FpXQ_ellcard(GEN a4, GEN a6, GEN T, GEN p) GEN FpXQ_elldivpol(GEN a4, GEN a6, long n, GEN T, GEN p) GEN FpXQ_ellgens(GEN a4, GEN a6, GEN ch, GEN D, GEN m, GEN T, GEN p) GEN FpXQ_ellgroup(GEN a4, GEN a6, GEN N, GEN T, GEN p, GEN *pt_m) GEN FpXQ_ellj(GEN a4, GEN a6, GEN T, GEN p) int FpXQ_elljissupersingular(GEN j, GEN T, GEN p) void FpXQ_elltwist(GEN a4, GEN a6, GEN T, GEN p, GEN *pt_a4, GEN *pt_a6) GEN FpXQE_add(GEN P, GEN Q, GEN a4, GEN T, GEN p) GEN FpXQE_changepoint(GEN x, GEN ch, GEN T, GEN p) GEN FpXQE_changepointinv(GEN x, GEN ch, GEN T, GEN p) GEN FpXQE_dbl(GEN P, GEN a4, GEN T, GEN p) GEN FpXQE_log(GEN a, GEN b, GEN o, GEN a4, GEN T, GEN p) GEN FpXQE_mul(GEN P, GEN n, GEN a4, GEN T, GEN p) GEN FpXQE_neg(GEN P, GEN T, GEN p) GEN FpXQE_order(GEN z, GEN o, GEN a4, GEN T, GEN p) GEN FpXQE_sub(GEN P, GEN Q, GEN a4, GEN T, GEN p) GEN FpXQE_tatepairing(GEN t, GEN s, GEN m, GEN a4, GEN T, GEN p) GEN FpXQE_weilpairing(GEN t, GEN s, GEN m, GEN a4, GEN T, GEN p) GEN Fq_elldivpolmod(GEN a4, GEN a6, long n, GEN h, GEN T, GEN p) GEN RgE_to_FpE(GEN x, GEN p) GEN RgE_to_FpXQE(GEN x, GEN T, GEN p) const bb_group * get_FpE_group(void **E, GEN a4, GEN a6, GEN p) const bb_group * get_FpXQE_group(void **E, GEN a4, GEN a6, GEN T, GEN p) GEN elltrace_extension(GEN t, long n, GEN p) GEN random_FpE(GEN a4, GEN a6, GEN p) GEN random_FpXQE(GEN a4, GEN a6, GEN T, GEN p) # FpX.c int Fp_issquare(GEN x, GEN p) GEN Fp_FpX_sub(GEN x, GEN y, GEN p) GEN Fp_FpXQ_log(GEN a, GEN g, GEN ord, GEN T, GEN p) GEN FpV_FpM_polint(GEN xa, GEN ya, GEN p, long vs) GEN FpV_inv(GEN x, GEN p) GEN FpV_invVandermonde(GEN L, GEN den, GEN p) GEN FpV_polint(GEN xa, GEN ya, GEN p, long v) GEN FpV_roots_to_pol(GEN V, GEN p, long v) GEN FpX_Fp_add(GEN x, GEN y, GEN p) GEN FpX_Fp_add_shallow(GEN y, GEN x, GEN p) GEN FpX_Fp_mul(GEN x, GEN y, GEN p) GEN FpX_Fp_mul_to_monic(GEN y, GEN x, GEN p) GEN FpX_Fp_mulspec(GEN y, GEN x, GEN p, long ly) GEN FpX_Fp_sub(GEN x, GEN y, GEN p) GEN FpX_Fp_sub_shallow(GEN y, GEN x, GEN p) GEN FpX_FpV_multieval(GEN P, GEN xa, GEN p) GEN FpX_FpXQ_eval(GEN f, GEN x, GEN T, GEN p) GEN FpX_FpXQV_eval(GEN f, GEN x, GEN T, GEN p) GEN FpX_Frobenius(GEN T, GEN p) GEN FpX_add(GEN x, GEN y, GEN p) GEN FpX_center(GEN x, GEN p, GEN pov2) GEN FpX_chinese_coprime(GEN x, GEN y, GEN Tx, GEN Ty, GEN Tz, GEN p) GEN FpX_deriv(GEN x, GEN p) GEN FpX_digits(GEN x, GEN y, GEN p) GEN FpX_disc(GEN x, GEN p) GEN FpX_div_by_X_x(GEN a, GEN x, GEN p, GEN *r) GEN FpX_divrem(GEN x, GEN y, GEN p, GEN *pr) GEN FpX_dotproduct(GEN x, GEN y, GEN p) GEN FpX_eval(GEN x, GEN y, GEN p) GEN FpX_extgcd(GEN x, GEN y, GEN p, GEN *ptu, GEN *ptv) GEN FpX_fromdigits(GEN x, GEN T, GEN p) GEN FpX_gcd(GEN x, GEN y, GEN p) GEN FpX_get_red(GEN T, GEN p) GEN FpX_halve(GEN y, GEN p) GEN FpX_halfgcd(GEN x, GEN y, GEN p) GEN FpX_invBarrett(GEN T, GEN p) int FpX_is_squarefree(GEN f, GEN p) GEN FpX_matFrobenius(GEN T, GEN p) GEN FpX_mul(GEN x, GEN y, GEN p) GEN FpX_mulspec(GEN a, GEN b, GEN p, long na, long nb) GEN FpX_mulu(GEN x, ulong y, GEN p) GEN FpX_neg(GEN x, GEN p) GEN FpX_normalize(GEN z, GEN p) GEN FpX_powu(GEN x, ulong n, GEN p) GEN FpX_red(GEN z, GEN p) GEN FpX_rem(GEN x, GEN y, GEN p) GEN FpX_rescale(GEN P, GEN h, GEN p) GEN FpX_resultant(GEN a, GEN b, GEN p) GEN FpX_sqr(GEN x, GEN p) GEN FpX_sub(GEN x, GEN y, GEN p) long FpX_valrem(GEN x0, GEN t, GEN p, GEN *py) GEN FpXC_FpXQV_eval(GEN Q, GEN x, GEN T, GEN p) GEN FpXM_FpXQV_eval(GEN Q, GEN x, GEN T, GEN p) GEN FpXQ_autpow(GEN x, ulong n, GEN T, GEN p) GEN FpXQ_autpowers(GEN aut, long f, GEN T, GEN p) GEN FpXQ_autsum(GEN x, ulong n, GEN T, GEN p) GEN FpXQ_auttrace(GEN x, ulong n, GEN T, GEN p) GEN FpXQ_charpoly(GEN x, GEN T, GEN p) GEN FpXQ_conjvec(GEN x, GEN T, GEN p) GEN FpXQ_div(GEN x, GEN y, GEN T, GEN p) GEN FpXQ_inv(GEN x, GEN T, GEN p) GEN FpXQ_invsafe(GEN x, GEN T, GEN p) int FpXQ_issquare(GEN x, GEN T, GEN p) GEN FpXQ_log(GEN a, GEN g, GEN ord, GEN T, GEN p) GEN FpXQ_matrix_pow(GEN y, long n, long m, GEN P, GEN l) GEN FpXQ_minpoly(GEN x, GEN T, GEN p) GEN FpXQ_mul(GEN y, GEN x, GEN T, GEN p) GEN FpXQ_norm(GEN x, GEN T, GEN p) GEN FpXQ_order(GEN a, GEN ord, GEN T, GEN p) GEN FpXQ_pow(GEN x, GEN n, GEN T, GEN p) GEN FpXQ_powu(GEN x, ulong n, GEN T, GEN p) GEN FpXQ_powers(GEN x, long l, GEN T, GEN p) GEN FpXQ_red(GEN x, GEN T, GEN p) GEN FpXQ_sqr(GEN y, GEN T, GEN p) GEN FpXQ_sqrt(GEN a, GEN T, GEN p) GEN FpXQ_sqrtn(GEN a, GEN n, GEN T, GEN p, GEN *zetan) GEN FpXQ_trace(GEN x, GEN T, GEN p) GEN FpXQC_to_mod(GEN z, GEN T, GEN p) GEN FpXQM_autsum(GEN x, ulong n, GEN T, GEN p) GEN FpXT_red(GEN z, GEN p) GEN FpXV_prod(GEN V, GEN p) GEN FpXV_red(GEN z, GEN p) int Fq_issquare(GEN x, GEN T, GEN p) long Fq_ispower(GEN x, GEN K, GEN T, GEN p) GEN Fq_log(GEN a, GEN g, GEN ord, GEN T, GEN p) GEN Fq_sqrtn(GEN a, GEN n, GEN T, GEN p, GEN *z) GEN Fq_sqrt(GEN a, GEN T, GEN p) long FqX_ispower(GEN f, ulong k, GEN T, GEN p, GEN *pt) GEN FqV_inv(GEN x, GEN T, GEN p) GEN Z_to_FpX(GEN a, GEN p, long v) GEN gener_FpXQ(GEN T, GEN p, GEN *o) GEN gener_FpXQ_local(GEN T, GEN p, GEN L) long get_FpX_degree(GEN T) GEN get_FpX_mod(GEN T) long get_FpX_var(GEN T) const bb_group *get_FpXQ_star(void **E, GEN T, GEN p) GEN random_FpX(long d, long v, GEN p) # FpX_factor.c GEN F2x_factor(GEN f) int F2x_is_irred(GEN f) void F2xV_to_FlxV_inplace(GEN v) void F2xV_to_ZXV_inplace(GEN v) int Flx_is_irred(GEN f, ulong p) GEN Flx_degfact(GEN f, ulong p) GEN Flx_factor(GEN f, ulong p) long Flx_nbfact(GEN z, ulong p) long Flx_nbfact_Frobenius(GEN T, GEN XP, ulong p) GEN Flx_nbfact_by_degree(GEN z, long *nb, ulong p) long Flx_nbroots(GEN f, ulong p) ulong Flx_oneroot(GEN f, ulong p) ulong Flx_oneroot_split(GEN f, ulong p) GEN Flx_roots(GEN f, ulong p) GEN Flx_rootsff(GEN P, GEN T, ulong p) void FlxV_to_ZXV_inplace(GEN v) GEN FpX_degfact(GEN f, GEN p) int FpX_is_irred(GEN f, GEN p) int FpX_is_totally_split(GEN f, GEN p) GEN FpX_factor(GEN f, GEN p) GEN FpX_factorff(GEN P, GEN T, GEN p) long FpX_nbfact(GEN f, GEN p) long FpX_nbfact_Frobenius(GEN T, GEN XP, GEN p) long FpX_nbroots(GEN f, GEN p) GEN FpX_oneroot(GEN f, GEN p) GEN FpX_roots(GEN f, GEN p) GEN FpX_rootsff(GEN P, GEN T, GEN p) GEN FpX_split_part(GEN f, GEN p) GEN factcantor(GEN x, GEN p) GEN factormod0(GEN f, GEN p, long flag) GEN rootmod0(GEN f, GEN p, long flag) # FpXQX_factor.c GEN F2xqX_roots(GEN x, GEN T) GEN FlxqX_Frobenius(GEN S, GEN T, ulong p) GEN FlxqXQ_halfFrobenius(GEN a, GEN S, GEN T, ulong p) GEN FlxqX_roots(GEN S, GEN T, ulong p) long FlxqX_nbroots(GEN f, GEN T, ulong p) GEN FpXQX_Frobenius(GEN S, GEN T, GEN p) GEN FpXQX_factor(GEN x, GEN T, GEN p) long FpXQX_nbfact(GEN u, GEN T, GEN p) long FpXQX_nbroots(GEN f, GEN T, GEN p) GEN FpXQX_roots(GEN f, GEN T, GEN p) GEN FpXQXQ_halfFrobenius(GEN a, GEN S, GEN T, GEN p) long FqX_is_squarefree(GEN P, GEN T, GEN p) long FqX_nbfact(GEN u, GEN T, GEN p) long FqX_nbroots(GEN f, GEN T, GEN p) GEN factorff(GEN f, GEN p, GEN a) GEN polrootsff(GEN f, GEN p, GEN T) # FpXX.c GEN FpXQX_FpXQ_mul(GEN P, GEN U, GEN T, GEN p) GEN FpXQX_FpXQXQV_eval(GEN P, GEN V, GEN S, GEN T, GEN p) GEN FpXQX_FpXQXQ_eval(GEN P, GEN x, GEN S, GEN T, GEN p) GEN FpXQX_div_by_X_x(GEN a, GEN x, GEN T, GEN p, GEN *pr) GEN FpXQX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *pr) GEN FpXQX_digits(GEN x, GEN B, GEN T, GEN p) GEN FpXQX_extgcd(GEN x, GEN y, GEN T, GEN p, GEN *ptu, GEN *ptv) GEN FpXQX_fromdigits(GEN x, GEN B, GEN T, GEN p) GEN FpXQX_gcd(GEN P, GEN Q, GEN T, GEN p) GEN FpXQX_get_red(GEN S, GEN T, GEN p) GEN FpXQX_halfgcd(GEN x, GEN y, GEN T, GEN p) GEN FpXQX_invBarrett(GEN S, GEN T, GEN p) GEN FpXQX_mul(GEN x, GEN y, GEN T, GEN p) GEN FpXQX_powu(GEN x, ulong n, GEN T, GEN p) GEN FpXQX_red(GEN z, GEN T, GEN p) GEN FpXQX_rem(GEN x, GEN S, GEN T, GEN p) GEN FpXQX_sqr(GEN x, GEN T, GEN p) GEN FpXQXQ_div(GEN x, GEN y, GEN S, GEN T, GEN p) GEN FpXQXQ_inv(GEN x, GEN S, GEN T, GEN p) GEN FpXQXQ_invsafe(GEN x, GEN S, GEN T, GEN p) GEN FpXQXQ_matrix_pow(GEN y, long n, long m, GEN S, GEN T, GEN p) GEN FpXQXQ_mul(GEN x, GEN y, GEN S, GEN T, GEN p) GEN FpXQXQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p) GEN FpXQXQ_powers(GEN x, long n, GEN S, GEN T, GEN p) GEN FpXQXQ_sqr(GEN x, GEN S, GEN T, GEN p) GEN FpXQXQV_autpow(GEN aut, long n, GEN S, GEN T, GEN p) GEN FpXQXQV_autsum(GEN aut, long n, GEN S, GEN T, GEN p) GEN FpXQXQV_auttrace(GEN aut, long n, GEN S, GEN T, GEN p) GEN FpXQXV_prod(GEN V, GEN Tp, GEN p) GEN FpXX_Fp_mul(GEN x, GEN y, GEN p) GEN FpXX_FpX_mul(GEN x, GEN y, GEN p) GEN FpXX_add(GEN x, GEN y, GEN p) GEN FpXX_deriv(GEN P, GEN p) GEN FpXX_mulu(GEN P, ulong u, GEN p) GEN FpXX_neg(GEN x, GEN p) GEN FpXX_red(GEN z, GEN p) GEN FpXX_sub(GEN x, GEN y, GEN p) GEN FpXY_FpXQ_evalx(GEN P, GEN x, GEN T, GEN p) GEN FpXY_FpXQV_evalx(GEN P, GEN x, GEN T, GEN p) GEN FpXY_eval(GEN Q, GEN y, GEN x, GEN p) GEN FpXY_evalx(GEN Q, GEN x, GEN p) GEN FpXY_evaly(GEN Q, GEN y, GEN p, long vy) GEN FpXYQQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p) GEN Kronecker_to_FpXQX(GEN z, GEN pol, GEN p) GEN Kronecker_to_ZXX(GEN z, long N, long v) GEN ZXX_mul_Kronecker(GEN x, GEN y, long n) GEN ZXX_sqr_Kronecker(GEN x, long n) long get_FpXQX_degree(GEN T) GEN get_FpXQX_mod(GEN T) long get_FpXQX_var(GEN T) GEN random_FpXQX(long d1, long v, GEN T, GEN p) # FpV.c GEN F2m_F2c_mul(GEN x, GEN y) GEN F2m_mul(GEN x, GEN y) GEN F2m_powu(GEN x, ulong n) GEN Flc_to_mod(GEN z, ulong pp) GEN Flm_Fl_add(GEN x, ulong y, ulong p) GEN Flm_Fl_mul(GEN y, ulong x, ulong p) void Flm_Fl_mul_inplace(GEN y, ulong x, ulong p) GEN Flm_Flc_mul(GEN x, GEN y, ulong p) GEN Flm_Flc_mul_pre(GEN x, GEN y, ulong p, ulong pi) GEN Flm_add(GEN x, GEN y, ulong p) GEN Flm_center(GEN z, ulong p, ulong ps2) GEN Flm_mul(GEN x, GEN y, ulong p) GEN Flm_neg(GEN y, ulong p) GEN Flm_powu(GEN x, ulong n, ulong p) GEN Flm_sub(GEN x, GEN y, ulong p) GEN Flm_to_mod(GEN z, ulong pp) GEN Flm_transpose(GEN x) GEN Flv_Fl_div(GEN x, ulong y, ulong p) void Flv_Fl_div_inplace(GEN x, ulong y, ulong p) GEN Flv_Fl_mul(GEN x, ulong y, ulong p) void Flv_Fl_mul_inplace(GEN x, ulong y, ulong p) void Flv_Fl_mul_part_inplace(GEN x, ulong y, ulong p, long l) GEN Flv_add(GEN x, GEN y, ulong p) void Flv_add_inplace(GEN x, GEN y, ulong p) GEN Flv_center(GEN z, ulong p, ulong ps2) ulong Flv_dotproduct(GEN x, GEN y, ulong p) ulong Flv_dotproduct_pre(GEN x, GEN y, ulong p, ulong pi) GEN Flv_neg(GEN v, ulong p) void Flv_neg_inplace(GEN v, ulong p) GEN Flv_sub(GEN x, GEN y, ulong p) void Flv_sub_inplace(GEN x, GEN y, ulong p) ulong Flv_sum(GEN x, ulong p) ulong Flx_dotproduct(GEN x, GEN y, ulong p) GEN Fp_to_mod(GEN z, GEN p) GEN FpC_FpV_mul(GEN x, GEN y, GEN p) GEN FpC_Fp_mul(GEN x, GEN y, GEN p) GEN FpC_center(GEN z, GEN p, GEN pov2) void FpC_center_inplace(GEN z, GEN p, GEN pov2) GEN FpC_red(GEN z, GEN p) GEN FpC_to_mod(GEN z, GEN p) GEN FpM_add(GEN x, GEN y, GEN p) GEN FpM_Fp_mul(GEN X, GEN c, GEN p) GEN FpM_FpC_mul(GEN x, GEN y, GEN p) GEN FpM_FpC_mul_FpX(GEN x, GEN y, GEN p, long v) GEN FpM_center(GEN z, GEN p, GEN pov2) void FpM_center_inplace(GEN z, GEN p, GEN pov2) GEN FpM_mul(GEN x, GEN y, GEN p) GEN FpM_powu(GEN x, ulong n, GEN p) GEN FpM_red(GEN z, GEN p) GEN FpM_sub(GEN x, GEN y, GEN p) GEN FpM_to_mod(GEN z, GEN p) GEN FpMs_FpC_mul(GEN M, GEN B, GEN p) GEN FpMs_FpCs_solve(GEN M, GEN B, long nbrow, GEN p) GEN FpMs_FpCs_solve_safe(GEN M, GEN A, long nbrow, GEN p) GEN FpMs_leftkernel_elt(GEN M, long nbrow, GEN p) GEN FpC_add(GEN x, GEN y, GEN p) GEN FpC_sub(GEN x, GEN y, GEN p) GEN FpV_FpMs_mul(GEN B, GEN M, GEN p) GEN FpV_add(GEN x, GEN y, GEN p) GEN FpV_sub(GEN x, GEN y, GEN p) GEN FpV_dotproduct(GEN x, GEN y, GEN p) GEN FpV_dotsquare(GEN x, GEN p) GEN FpV_red(GEN z, GEN p) GEN FpV_to_mod(GEN z, GEN p) GEN FpVV_to_mod(GEN z, GEN p) GEN FpX_to_mod(GEN z, GEN p) GEN ZV_zMs_mul(GEN B, GEN M) GEN ZpMs_ZpCs_solve(GEN M, GEN B, long nbrow, GEN p, long e) GEN gen_FpM_Wiedemann(void *E, GEN (*f)(void*, GEN), GEN B, GEN p) GEN gen_ZpM_Dixon(void *E, GEN (*f)(void*, GEN), GEN B, GEN p, long e) GEN gen_matid(long n, void *E, const bb_field *S) GEN matid_F2m(long n) GEN matid_Flm(long n) GEN matid_F2xqM(long n, GEN T) GEN matid_FlxqM(long n, GEN T, ulong p) GEN scalar_Flm(long s, long n) GEN zCs_to_ZC(GEN C, long nbrow) GEN zMs_to_ZM(GEN M, long nbrow) GEN zMs_ZC_mul(GEN M, GEN B) GEN ZMV_to_FlmV(GEN z, ulong m) # Hensel.c GEN Z2_sqrt(GEN x, long e) GEN Zp_sqrt(GEN x, GEN p, long e) GEN Zp_sqrtlift(GEN b, GEN a, GEN p, long e) GEN Zp_sqrtnlift(GEN b, GEN n, GEN a, GEN p, long e) GEN ZpX_Frobenius(GEN T, GEN p, long e) GEN ZpX_ZpXQ_liftroot(GEN P, GEN S, GEN T, GEN p, long e) GEN ZpX_ZpXQ_liftroot_ea(GEN P, GEN S, GEN T, GEN p, long n, void *E, int early(void *E, GEN x, GEN q)) GEN ZpX_liftfact(GEN pol, GEN Q, GEN T, GEN p, long e, GEN pe) GEN ZpX_liftroot(GEN f, GEN a, GEN p, long e) GEN ZpX_liftroots(GEN f, GEN S, GEN p, long e) GEN ZpX_roots(GEN f, GEN p, long e) GEN ZpXQ_inv(GEN a, GEN T, GEN p, long e) GEN ZpXQ_invlift(GEN b, GEN a, GEN T, GEN p, long e) GEN ZpXQ_log(GEN a, GEN T, GEN p, long N) GEN ZpXQ_sqrt(GEN a, GEN T, GEN p, long e) GEN ZpXQ_sqrtnlift(GEN b, GEN n, GEN a, GEN T, GEN p, long e) GEN ZpXQM_prodFrobenius(GEN M, GEN T, GEN p, long e) GEN ZpXQX_liftroot(GEN f, GEN a, GEN T, GEN p, long e) GEN ZpXQX_liftroot_vald(GEN f, GEN a, long v, GEN T, GEN p, long e) GEN gen_ZpX_Dixon(GEN F, GEN V, GEN q, GEN p, long N, void *E, GEN lin(void *E, GEN F, GEN d, GEN q), GEN invl(void *E, GEN d)) GEN gen_ZpX_Newton(GEN x, GEN p, long n, void *E, GEN eval(void *E, GEN f, GEN q), GEN invd(void *E, GEN V, GEN v, GEN q, long M)) GEN polhensellift(GEN pol, GEN fct, GEN p, long exp) ulong quadratic_prec_mask(long n) # QX_factor.c GEN QX_factor(GEN x) GEN ZX_factor(GEN x) long ZX_is_irred(GEN x) GEN ZX_squff(GEN f, GEN *ex) GEN polcyclofactors(GEN f) long poliscyclo(GEN f) long poliscycloprod(GEN f) # RgV.c GEN RgC_Rg_add(GEN x, GEN y) GEN RgC_Rg_div(GEN x, GEN y) GEN RgC_Rg_mul(GEN x, GEN y) GEN RgC_RgM_mul(GEN x, GEN y) GEN RgC_RgV_mul(GEN x, GEN y) GEN RgC_add(GEN x, GEN y) long RgC_is_ei(GEN x) GEN RgC_neg(GEN x) GEN RgC_sub(GEN x, GEN y) GEN RgM_Rg_add(GEN x, GEN y) GEN RgM_Rg_add_shallow(GEN x, GEN y) GEN RgM_Rg_div(GEN x, GEN y) GEN RgM_Rg_mul(GEN x, GEN y) GEN RgM_Rg_sub(GEN x, GEN y) GEN RgM_Rg_sub_shallow(GEN x, GEN y) GEN RgM_RgC_mul(GEN x, GEN y) GEN RgM_RgV_mul(GEN x, GEN y) GEN RgM_add(GEN x, GEN y) GEN RgM_det_triangular(GEN x) int RgM_is_ZM(GEN x) int RgM_isdiagonal(GEN x) int RgM_isidentity(GEN x) int RgM_isscalar(GEN x, GEN s) GEN RgM_mul(GEN x, GEN y) GEN RgM_multosym(GEN x, GEN y) GEN RgM_neg(GEN x) GEN RgM_powers(GEN x, long l) GEN RgM_sqr(GEN x) GEN RgM_sub(GEN x, GEN y) GEN RgM_sumcol(GEN A) GEN RgM_transmul(GEN x, GEN y) GEN RgM_transmultosym(GEN x, GEN y) GEN RgM_zc_mul(GEN x, GEN y) GEN RgM_zm_mul(GEN x, GEN y) GEN RgMrow_RgC_mul(GEN x, GEN y, long i) GEN RgV_RgM_mul(GEN x, GEN y) GEN RgV_RgC_mul(GEN x, GEN y) GEN RgV_Rg_mul(GEN x, GEN y) GEN RgV_add(GEN x, GEN y) GEN RgV_dotproduct(GEN x, GEN y) GEN RgV_dotsquare(GEN x) int RgV_is_ZMV(GEN V) long RgV_isin(GEN v, GEN x) GEN RgV_kill0(GEN v) GEN RgV_neg(GEN x) GEN RgV_prod(GEN v) GEN RgV_sub(GEN x, GEN y) GEN RgV_sum(GEN v) GEN RgV_sumpart(GEN v, long n) GEN RgV_sumpart2(GEN v, long m, long n) GEN RgV_zc_mul(GEN x, GEN y) GEN RgV_zm_mul(GEN x, GEN y) GEN RgX_RgM_eval(GEN x, GEN y) GEN RgX_RgMV_eval(GEN x, GEN y) int isdiagonal(GEN x) GEN matid(long n) GEN scalarcol(GEN x, long n) GEN scalarcol_shallow(GEN x, long n) GEN scalarmat(GEN x, long n) GEN scalarmat_shallow(GEN x, long n) GEN scalarmat_s(long x, long n) # RgX.c GEN Kronecker_to_mod(GEN z, GEN pol) GEN QX_ZXQV_eval(GEN P, GEN V, GEN dV) GEN QXQ_charpoly(GEN A, GEN T, long v) GEN QXQ_powers(GEN a, long n, GEN T) GEN QXQX_to_mod_shallow(GEN z, GEN T) GEN QXQV_to_mod(GEN V, GEN T) GEN QXQXV_to_mod(GEN V, GEN T) GEN QXV_QXQ_eval(GEN v, GEN a, GEN T) GEN QXX_QXQ_eval(GEN v, GEN a, GEN T) GEN Rg_RgX_sub(GEN x, GEN y) GEN Rg_to_RgC(GEN x, long N) GEN RgM_to_RgXV(GEN x, long v) GEN RgM_to_RgXX(GEN x, long v, long w) GEN RgV_to_RgX(GEN x, long v) GEN RgV_to_RgM(GEN v, long n) GEN RgV_to_RgX_reverse(GEN x, long v) GEN RgX_RgXQ_eval(GEN f, GEN x, GEN T) GEN RgX_RgXQV_eval(GEN P, GEN V, GEN T) GEN RgX_RgXn_eval(GEN Q, GEN x, long n) GEN RgX_RgXnV_eval(GEN Q, GEN x, long n) GEN RgX_Rg_add(GEN y, GEN x) GEN RgX_Rg_add_shallow(GEN y, GEN x) GEN RgX_Rg_div(GEN y, GEN x) GEN RgX_Rg_divexact(GEN x, GEN y) GEN RgX_Rg_eval_bk(GEN Q, GEN x) GEN RgX_Rg_mul(GEN y, GEN x) GEN RgX_Rg_sub(GEN y, GEN x) GEN RgX_RgV_eval(GEN Q, GEN x) GEN RgX_add(GEN x, GEN y) GEN RgX_blocks(GEN P, long n, long m) GEN RgX_deflate(GEN x0, long d) GEN RgX_deriv(GEN x) GEN RgX_div_by_X_x(GEN a, GEN x, GEN *r) GEN RgX_divrem(GEN x, GEN y, GEN *r) GEN RgX_divs(GEN y, long x) long RgX_equal(GEN x, GEN y) void RgX_even_odd(GEN p, GEN *pe, GEN *po) GEN RgX_get_0(GEN x) GEN RgX_get_1(GEN x) GEN RgX_inflate(GEN x0, long d) GEN RgX_mul(GEN x, GEN y) GEN RgX_mul_normalized(GEN A, long a, GEN B, long b) GEN RgX_mulXn(GEN x, long d) GEN RgX_muls(GEN y, long x) GEN RgX_mulspec(GEN a, GEN b, long na, long nb) GEN RgX_neg(GEN x) GEN RgX_normalize(GEN x) GEN RgX_pseudodivrem(GEN x, GEN y, GEN *ptr) GEN RgX_pseudorem(GEN x, GEN y) GEN RgX_recip(GEN x) GEN RgX_recip_shallow(GEN x) GEN RgX_renormalize_lg(GEN x, long lx) GEN RgX_rescale(GEN P, GEN h) GEN RgX_rotate_shallow(GEN P, long k, long p) GEN RgX_shift(GEN a, long n) GEN RgX_shift_shallow(GEN x, long n) GEN RgX_splitting(GEN p, long k) GEN RgX_sqr(GEN x) GEN RgX_sqrspec(GEN a, long na) GEN RgX_sub(GEN x, GEN y) GEN RgX_to_RgC(GEN x, long N) GEN RgX_translate(GEN P, GEN c) GEN RgX_unscale(GEN P, GEN h) GEN RgXQ_matrix_pow(GEN y, long n, long m, GEN P) GEN RgXQ_norm(GEN x, GEN T) GEN RgXQ_pow(GEN x, GEN n, GEN T) GEN RgXQ_powers(GEN x, long l, GEN T) GEN RgXQ_powu(GEN x, ulong n, GEN T) GEN RgXQC_red(GEN P, GEN T) GEN RgXQV_RgXQ_mul(GEN v, GEN x, GEN T) GEN RgXQV_red(GEN P, GEN T) GEN RgXQX_RgXQ_mul(GEN x, GEN y, GEN T) GEN RgXQX_divrem(GEN x, GEN y, GEN T, GEN *r) GEN RgXQX_mul(GEN x, GEN y, GEN T) GEN RgXQX_pseudodivrem(GEN x, GEN y, GEN T, GEN *ptr) GEN RgXQX_pseudorem(GEN x, GEN y, GEN T) GEN RgXQX_red(GEN P, GEN T) GEN RgXQX_sqr(GEN x, GEN T) GEN RgXQX_translate(GEN P, GEN c, GEN T) GEN RgXV_RgV_eval(GEN Q, GEN x) GEN RgXV_to_RgM(GEN v, long n) GEN RgXV_unscale(GEN v, GEN h) GEN RgXX_to_RgM(GEN v, long n) long RgXY_degreex(GEN bpol) GEN RgXY_swap(GEN x, long n, long w) GEN RgXY_swapspec(GEN x, long n, long w, long nx) GEN RgXn_eval(GEN Q, GEN x, long n) GEN RgXn_exp(GEN f, long e) GEN RgXn_inv(GEN f, long e) GEN RgXn_mul(GEN f, GEN g, long n) GEN RgXn_powers(GEN f, long m, long n) GEN RgXn_red_shallow(GEN a, long n) GEN RgXn_reverse(GEN f, long e) GEN RgXn_sqr(GEN f, long n) GEN RgXnV_red_shallow(GEN P, long n) GEN RgXn_powu(GEN x, ulong m, long n) GEN RgXn_powu_i(GEN x, ulong m, long n) GEN ZX_translate(GEN P, GEN c) GEN ZX_unscale2n(GEN P, long n) GEN ZX_unscale(GEN P, GEN h) GEN ZX_unscale_div(GEN P, GEN h) int ZXQX_dvd(GEN x, GEN y, GEN T) long brent_kung_optpow(long d, long n, long m) GEN gen_bkeval(GEN Q, long d, GEN x, int use_sqr, void *E, const bb_algebra *ff, GEN cmul(void *E, GEN P, long a, GEN x)) GEN gen_bkeval_powers(GEN P, long d, GEN V, void *E, const bb_algebra *ff, GEN cmul(void *E, GEN P, long a, GEN x)) const bb_algebra * get_Rg_algebra() # ZG.c void ZGC_G_mul_inplace(GEN v, GEN x) void ZGC_add_inplace(GEN x, GEN y) GEN ZGC_add_sparse(GEN x, GEN y) void ZGM_add_inplace(GEN x, GEN y) GEN ZGM_add_sparse(GEN x, GEN y) GEN G_ZGC_mul(GEN x, GEN v) GEN G_ZG_mul(GEN x, GEN y) GEN ZGC_G_mul(GEN v, GEN x) GEN ZGC_Z_mul(GEN v, GEN x) GEN ZG_G_mul(GEN x, GEN y) GEN ZG_Z_mul(GEN x, GEN c) GEN ZG_add(GEN x, GEN y) GEN ZG_mul(GEN x, GEN y) GEN ZG_neg(GEN x) GEN ZG_normalize(GEN x) GEN ZG_sub(GEN x, GEN y) # ZV.c void Flc_lincomb1_inplace(GEN X, GEN Y, ulong v, ulong q) void RgM_check_ZM(GEN A, const char *s) void RgV_check_ZV(GEN A, const char *s) GEN ZV_zc_mul(GEN x, GEN y) GEN ZC_ZV_mul(GEN x, GEN y) GEN ZC_Z_add(GEN x, GEN y) GEN ZC_Z_divexact(GEN X, GEN c) GEN ZC_Z_mul(GEN X, GEN c) GEN ZC_Z_sub(GEN x, GEN y) GEN ZC_add(GEN x, GEN y) GEN ZC_copy(GEN x) GEN ZC_hnfremdiv(GEN x, GEN y, GEN *Q) long ZC_is_ei(GEN x) GEN ZC_lincomb(GEN u, GEN v, GEN X, GEN Y) void ZC_lincomb1_inplace(GEN X, GEN Y, GEN v) GEN ZC_neg(GEN M) GEN ZC_reducemodlll(GEN x, GEN y) GEN ZC_reducemodmatrix(GEN v, GEN y) GEN ZC_sub(GEN x, GEN y) GEN ZC_z_mul(GEN X, long c) GEN ZM_ZC_mul(GEN x, GEN y) GEN ZM_Z_div(GEN X, GEN c) GEN ZM_Z_divexact(GEN X, GEN c) GEN ZM_Z_mul(GEN X, GEN c) GEN ZM_add(GEN x, GEN y) GEN ZM_copy(GEN x) GEN ZM_det_triangular(GEN mat) GEN ZM_diag_mul(GEN m, GEN d) int ZM_equal(GEN A, GEN B) GEN ZM_hnfdivrem(GEN x, GEN y, GEN *Q) int ZM_ishnf(GEN x) int ZM_isidentity(GEN x) int ZM_isscalar(GEN x, GEN s) long ZM_max_lg(GEN x) GEN ZM_mul(GEN x, GEN y) GEN ZM_mul_diag(GEN m, GEN d) GEN ZM_multosym(GEN x, GEN y) GEN ZM_neg(GEN x) GEN ZM_nm_mul(GEN x, GEN y) GEN ZM_pow(GEN x, GEN n) GEN ZM_powu(GEN x, ulong n) GEN ZM_reducemodlll(GEN x, GEN y) GEN ZM_reducemodmatrix(GEN v, GEN y) GEN ZM_sqr(GEN x) GEN ZM_sub(GEN x, GEN y) GEN ZM_supnorm(GEN x) GEN ZM_to_Flm(GEN x, ulong p) GEN ZM_to_zm(GEN z) GEN ZM_transmul(GEN x, GEN y) GEN ZM_transmultosym(GEN x, GEN y) GEN ZMV_to_zmV(GEN z) void ZM_togglesign(GEN M) GEN ZM_zc_mul(GEN x, GEN y) GEN ZM_zm_mul(GEN x, GEN y) GEN ZMrow_ZC_mul(GEN x, GEN y, long i) GEN ZV_ZM_mul(GEN x, GEN y) int ZV_abscmp(GEN x, GEN y) int ZV_cmp(GEN x, GEN y) GEN ZV_content(GEN x) GEN ZV_dotproduct(GEN x, GEN y) GEN ZV_dotsquare(GEN x) int ZV_equal(GEN V, GEN W) int ZV_equal0(GEN V) long ZV_max_lg(GEN x) void ZV_neg_inplace(GEN M) GEN ZV_prod(GEN v) GEN ZV_sum(GEN v) GEN ZV_to_Flv(GEN x, ulong p) GEN ZV_to_nv(GEN z) void ZV_togglesign(GEN M) GEN gram_matrix(GEN M) GEN nm_Z_mul(GEN X, GEN c) GEN zm_mul(GEN x, GEN y) GEN zm_to_Flm(GEN z, ulong p) GEN zm_to_ZM(GEN z) GEN zm_zc_mul(GEN x, GEN y) GEN zmV_to_ZMV(GEN z) long zv_content(GEN x) long zv_dotproduct(GEN x, GEN y) int zv_equal(GEN V, GEN W) int zv_equal0(GEN V) GEN zv_neg(GEN x) GEN zv_neg_inplace(GEN M) long zv_prod(GEN v) GEN zv_prod_Z(GEN v) long zv_sum(GEN v) GEN zv_to_Flv(GEN z, ulong p) GEN zv_z_mul(GEN v, long n) GEN zv_ZM_mul(GEN x, GEN y) int zvV_equal(GEN V, GEN W) # ZX.c void RgX_check_QX(GEN x, const char *s) void RgX_check_ZX(GEN x, const char *s) void RgX_check_ZXX(GEN x, const char *s) GEN Z_ZX_sub(GEN x, GEN y) GEN ZX_Z_add(GEN y, GEN x) GEN ZX_Z_add_shallow(GEN y, GEN x) GEN ZX_Z_divexact(GEN y, GEN x) GEN ZX_Z_mul(GEN y, GEN x) GEN ZX_Z_sub(GEN y, GEN x) GEN ZX_add(GEN x, GEN y) GEN ZX_copy(GEN x) GEN ZX_deriv(GEN x) GEN ZX_div_by_X_1(GEN a, GEN *r) int ZX_equal(GEN V, GEN W) GEN ZX_eval1(GEN x) long ZX_max_lg(GEN x) GEN ZX_mod_Xnm1(GEN T, ulong n) GEN ZX_mul(GEN x, GEN y) GEN ZX_mulspec(GEN a, GEN b, long na, long nb) GEN ZX_mulu(GEN y, ulong x) GEN ZX_neg(GEN x) GEN ZX_rem(GEN x, GEN y) GEN ZX_remi2n(GEN y, long n) GEN ZX_rescale2n(GEN P, long n) GEN ZX_rescale(GEN P, GEN h) GEN ZX_rescale_lt(GEN P) GEN ZX_shifti(GEN x, long n) GEN ZX_sqr(GEN x) GEN ZX_sqrspec(GEN a, long na) GEN ZX_sub(GEN x, GEN y) long ZX_val(GEN x) long ZX_valrem(GEN x, GEN *Z) GEN ZXT_remi2n(GEN z, long n) GEN ZXV_Z_mul(GEN y, GEN x) GEN ZXV_dotproduct(GEN V, GEN W) int ZXV_equal(GEN V, GEN W) GEN ZXV_remi2n(GEN x, long n) GEN ZXX_Z_divexact(GEN y, GEN x) GEN ZXX_Z_mul(GEN y, GEN x) GEN ZXX_Z_add_shallow(GEN x, GEN y) long ZXX_max_lg(GEN x) GEN ZXX_renormalize(GEN x, long lx) GEN ZXX_to_Kronecker(GEN P, long n) GEN ZXX_to_Kronecker_spec(GEN P, long lP, long n) GEN scalar_ZX(GEN x, long v) GEN scalar_ZX_shallow(GEN x, long v) GEN zx_to_ZX(GEN z) # algebras.c GEN alg_centralproj(GEN al, GEN z, int maps) GEN alg_change_overorder_shallow(GEN al, GEN ord) GEN alg_complete(GEN rnf, GEN aut, GEN hi, GEN hf, long maxord) GEN alg_csa_table(GEN nf, GEN mt, long v, long maxord) GEN alg_cyclic(GEN rnf, GEN aut, GEN b, long maxord) GEN alg_decomposition(GEN al) long alg_get_absdim(GEN al) long algabsdim(GEN al) GEN alg_get_abssplitting(GEN al) GEN alg_get_aut(GEN al) GEN algaut(GEN al) GEN alg_get_auts(GEN al) GEN alg_get_b(GEN al) GEN algb(GEN al) GEN algcenter(GEN al) GEN alg_get_center(GEN al) GEN alg_get_char(GEN al) GEN algchar(GEN al) long alg_get_degree(GEN al) long algdegree(GEN al) long alg_get_dim(GEN al) long algdim(GEN al) GEN alg_get_hasse_f(GEN al) GEN alghassef(GEN al) GEN alg_get_hasse_i(GEN al) GEN alghassei(GEN al) GEN alg_get_invbasis(GEN al) GEN alginvbasis(GEN al) GEN alg_get_multable(GEN al) GEN alg_get_basis(GEN al) GEN algbasis(GEN al) GEN alg_get_relmultable(GEN al) GEN algrelmultable(GEN al) GEN alg_get_splitpol(GEN al) GEN alg_get_splittingfield(GEN al) GEN algsplittingfield(GEN al) GEN alg_get_splittingbasis(GEN al) GEN alg_get_splittingbasisinv(GEN al) GEN alg_get_splittingdata(GEN al) GEN algsplittingdata(GEN al) GEN alg_get_tracebasis(GEN al) GEN alg_hasse(GEN nf, long n, GEN hi, GEN hf, long var, long flag) GEN alg_hilbert(GEN nf, GEN a, GEN b, long v, long flag) GEN alg_matrix(GEN nf, long n, long v, GEN L, long flag) long alg_model(GEN al, GEN x) GEN alg_ordermodp(GEN al, GEN p) GEN alg_quotient(GEN al, GEN I, int maps) GEN algradical(GEN al) GEN algsimpledec(GEN al, int maps) GEN algsubalg(GEN al, GEN basis) long alg_type(GEN al) GEN algadd(GEN al, GEN x, GEN y) GEN algalgtobasis(GEN al, GEN x) GEN algbasischarpoly(GEN al, GEN x, long v) GEN algbasismul(GEN al, GEN x, GEN y) GEN algbasismultable(GEN al, GEN x) GEN algbasismultable_Flm(GEN mt, GEN x, ulong m) GEN algbasistoalg(GEN al, GEN x) GEN algcharpoly(GEN al, GEN x, long v) GEN algdisc(GEN al) GEN algdivl(GEN al, GEN x, GEN y) GEN algdivr(GEN al, GEN x, GEN y) GEN alggroup(GEN gal, GEN p) GEN alghasse(GEN al, GEN pl) GEN alginit(GEN A, GEN B, long v, long flag) long algindex(GEN al, GEN pl) GEN alginv(GEN al, GEN x) int algisassociative(GEN mt0, GEN p) int algiscommutative(GEN al) int algisdivision(GEN al, GEN pl) int algisramified(GEN al, GEN pl) int algissemisimple(GEN al) int algissimple(GEN al, long ss) int algissplit(GEN al, GEN pl) int algisdivl(GEN al, GEN x, GEN y, GEN* ptz) int algisinv(GEN al, GEN x, GEN* ptix) GEN algleftordermodp(GEN al, GEN Ip, GEN p) GEN algmul(GEN al, GEN x, GEN y) GEN algmultable(GEN al) GEN alglathnf(GEN al, GEN m) GEN algleftmultable(GEN al, GEN x) GEN algneg(GEN al, GEN x) GEN algnorm(GEN al, GEN x) GEN algpoleval(GEN al, GEN pol, GEN x) GEN algpow(GEN al, GEN x, GEN n) GEN algprimesubalg(GEN al) GEN algramifiedplaces(GEN al) GEN algrandom(GEN al, GEN b) GEN algsplittingmatrix(GEN al, GEN x) GEN algsqr(GEN al, GEN x) GEN algsub(GEN al, GEN x, GEN y) GEN algtableinit(GEN mt, GEN p) GEN algtensor(GEN al1, GEN al2, long maxord) GEN algtrace(GEN al, GEN x) long algtype(GEN al) GEN bnfgwgeneric(GEN bnf, GEN Lpr, GEN Ld, GEN pl, long var) GEN bnrgwsearch(GEN bnr, GEN Lpr, GEN Ld, GEN pl) void checkalg(GEN x) void checkhasse(GEN nf, GEN hi, GEN hf, long n) long cyclicrelfrob(GEN rnf, GEN auts, GEN pr) GEN hassecoprime(GEN hi, GEN hf, long n) GEN hassedown(GEN nf, long n, GEN hi, GEN hf) GEN hassewedderburn(GEN hi, GEN hf, long n) long localhasse(GEN rnf, GEN cnd, GEN pl, GEN auts, GEN b, long k) GEN nfgrunwaldwang(GEN nf0, GEN Lpr, GEN Ld, GEN pl, long var) GEN nfgwkummer(GEN nf, GEN Lpr, GEN Ld, GEN pl, long var) # alglin1.c GEN F2m_F2c_gauss(GEN a, GEN b) GEN F2m_F2c_invimage(GEN A, GEN y) GEN F2m_deplin(GEN x) ulong F2m_det(GEN x) ulong F2m_det_sp(GEN x) GEN F2m_gauss(GEN a, GEN b) GEN F2m_image(GEN x) GEN F2m_indexrank(GEN x) GEN F2m_inv(GEN x) GEN F2m_invimage(GEN A, GEN B) GEN F2m_ker(GEN x) GEN F2m_ker_sp(GEN x, long deplin) long F2m_rank(GEN x) GEN F2m_suppl(GEN x) GEN F2xqM_F2xqC_mul(GEN a, GEN b, GEN T) GEN F2xqM_det(GEN a, GEN T) GEN F2xqM_ker(GEN x, GEN T) GEN F2xqM_image(GEN x, GEN T) GEN F2xqM_inv(GEN a, GEN T) GEN F2xqM_mul(GEN a, GEN b, GEN T) long F2xqM_rank(GEN x, GEN T) GEN Flm_Flc_gauss(GEN a, GEN b, ulong p) GEN Flm_Flc_invimage(GEN mat, GEN y, ulong p) GEN Flm_deplin(GEN x, ulong p) ulong Flm_det(GEN x, ulong p) ulong Flm_det_sp(GEN x, ulong p) GEN Flm_gauss(GEN a, GEN b, ulong p) GEN Flm_image(GEN x, ulong p) GEN Flm_invimage(GEN m, GEN v, ulong p) GEN Flm_indexrank(GEN x, ulong p) GEN Flm_intersect(GEN x, GEN y, ulong p) GEN Flm_inv(GEN x, ulong p) GEN Flm_ker(GEN x, ulong p) GEN Flm_ker_sp(GEN x, ulong p, long deplin) long Flm_rank(GEN x, ulong p) GEN Flm_suppl(GEN x, ulong p) GEN FlxqM_FlxqC_gauss(GEN a, GEN b, GEN T, ulong p) GEN FlxqM_FlxqC_mul(GEN a, GEN b, GEN T, ulong p) GEN FlxqM_det(GEN a, GEN T, ulong p) GEN FlxqM_gauss(GEN a, GEN b, GEN T, ulong p) GEN FlxqM_ker(GEN x, GEN T, ulong p) GEN FlxqM_image(GEN x, GEN T, ulong p) GEN FlxqM_inv(GEN x, GEN T, ulong p) GEN FlxqM_mul(GEN a, GEN b, GEN T, ulong p) long FlxqM_rank(GEN x, GEN T, ulong p) GEN FpM_FpC_gauss(GEN a, GEN b, GEN p) GEN FpM_FpC_invimage(GEN m, GEN v, GEN p) GEN FpM_deplin(GEN x, GEN p) GEN FpM_det(GEN x, GEN p) GEN FpM_gauss(GEN a, GEN b, GEN p) GEN FpM_image(GEN x, GEN p) GEN FpM_indexrank(GEN x, GEN p) GEN FpM_intersect(GEN x, GEN y, GEN p) GEN FpM_inv(GEN x, GEN p) GEN FpM_invimage(GEN m, GEN v, GEN p) GEN FpM_ker(GEN x, GEN p) long FpM_rank(GEN x, GEN p) GEN FpM_suppl(GEN x, GEN p) GEN FqM_FqC_gauss(GEN a, GEN b, GEN T, GEN p) GEN FqM_FqC_mul(GEN a, GEN b, GEN T, GEN p) GEN FqM_deplin(GEN x, GEN T, GEN p) GEN FqM_det(GEN x, GEN T, GEN p) GEN FqM_gauss(GEN a, GEN b, GEN T, GEN p) GEN FqM_ker(GEN x, GEN T, GEN p) GEN FqM_image(GEN x, GEN T, GEN p) GEN FqM_inv(GEN x, GEN T, GEN p) GEN FqM_mul(GEN a, GEN b, GEN T, GEN p) long FqM_rank(GEN a, GEN T, GEN p) GEN FqM_suppl(GEN x, GEN T, GEN p) GEN QM_inv(GEN M, GEN dM) GEN RgM_Fp_init(GEN a, GEN p, ulong *pp) GEN RgM_RgC_invimage(GEN A, GEN B) GEN RgM_diagonal(GEN m) GEN RgM_diagonal_shallow(GEN m) GEN RgM_Hadamard(GEN a) GEN RgM_inv_upper(GEN a) GEN RgM_invimage(GEN A, GEN B) GEN RgM_solve(GEN a, GEN b) GEN RgM_solve_realimag(GEN x, GEN y) void RgMs_structelim(GEN M, long nbrow, GEN A, GEN *p_col, GEN *p_lin) GEN ZM_det(GEN a) GEN ZM_detmult(GEN A) GEN ZM_gauss(GEN a, GEN b) GEN ZM_imagecompl(GEN x) GEN ZM_indeximage(GEN x) GEN ZM_indexrank(GEN x) GEN ZM_inv(GEN M, GEN dM) GEN ZM_inv_ratlift(GEN M, GEN *pden) long ZM_rank(GEN x) GEN ZlM_gauss(GEN a, GEN b, ulong p, long e, GEN C) GEN closemodinvertible(GEN x, GEN y) GEN deplin(GEN x) GEN det(GEN a) GEN det0(GEN a, long flag) GEN det2(GEN a) GEN detint(GEN x) GEN eigen(GEN x, long prec) GEN gauss(GEN a, GEN b) GEN gaussmodulo(GEN M, GEN D, GEN Y) GEN gaussmodulo2(GEN M, GEN D, GEN Y) GEN gen_Gauss(GEN a, GEN b, void *E, const bb_field *ff) GEN gen_Gauss_pivot(GEN x, long *rr, void *E, const bb_field *ff) GEN gen_det(GEN a, void *E, const bb_field *ff) GEN gen_ker(GEN x, long deplin, void *E, const bb_field *ff) GEN gen_matcolmul(GEN a, GEN b, void *E, const bb_field *ff) GEN gen_matmul(GEN a, GEN b, void *E, const bb_field *ff) GEN image(GEN x) GEN image2(GEN x) GEN imagecompl(GEN x) GEN indexrank(GEN x) GEN inverseimage(GEN mat, GEN y) GEN ker(GEN x) GEN keri(GEN x) GEN mateigen(GEN x, long flag, long prec) GEN matimage0(GEN x, long flag) GEN matker0(GEN x, long flag) GEN matsolvemod0(GEN M, GEN D, GEN Y, long flag) long rank(GEN x) GEN reducemodinvertible(GEN x, GEN y) GEN reducemodlll(GEN x, GEN y) GEN split_realimag(GEN x, long r1, long r2) GEN suppl(GEN x) # alglin2.c GEN Flm_charpoly(GEN x, ulong p) GEN Flm_hess(GEN x, ulong p) GEN FpM_charpoly(GEN x, GEN p) GEN FpM_hess(GEN x, GEN p) GEN Frobeniusform(GEN V, long n) GEN QM_minors_coprime(GEN x, GEN pp) GEN QM_ImZ_hnf(GEN x) GEN QM_ImQ_hnf(GEN x) GEN QM_charpoly_ZX(GEN M) GEN QM_charpoly_ZX_bound(GEN M, long bit) GEN QM_charpoly_ZX2_bound(GEN M, GEN M2, long bit) GEN ZM_charpoly(GEN x) GEN adj(GEN x) GEN adjsafe(GEN x) GEN caract(GEN x, long v) GEN caradj(GEN x, long v, GEN *py) GEN carberkowitz(GEN x, long v) GEN carhess(GEN x, long v) GEN charpoly(GEN x, long v) GEN charpoly0(GEN x, long v, long flag) GEN gnorm(GEN x) GEN gnorml1(GEN x, long prec) GEN gnorml1_fake(GEN x) GEN gnormlp(GEN x, GEN p, long prec) GEN gnorml2(GEN x) GEN gsupnorm(GEN x, long prec) void gsupnorm_aux(GEN x, GEN *m, GEN *msq, long prec) GEN gtrace(GEN x) GEN hess(GEN x) GEN intersect(GEN x, GEN y) GEN jacobi(GEN a, long prec) GEN matadjoint0(GEN x, long flag) GEN matcompanion(GEN x) GEN matrixqz0(GEN x, GEN pp) GEN minpoly(GEN x, long v) GEN qfgaussred(GEN a) GEN qfgaussred_positive(GEN a) GEN qfsign(GEN a) # alglin3.c GEN apply0(GEN f, GEN A) GEN diagonal(GEN x) GEN diagonal_shallow(GEN x) GEN extract0(GEN x, GEN l1, GEN l2) GEN fold0(GEN f, GEN A) GEN genapply(void *E, GEN (*f)(void *E, GEN x), GEN A) GEN genfold(void *E, GEN (*f)(void *E, GEN x, GEN y), GEN A) GEN genindexselect(void *E, long (*f)(void *E, GEN x), GEN A) GEN genselect(void *E, long (*f)(void *E, GEN x), GEN A) GEN gtomat(GEN x) GEN gtrans(GEN x) GEN matmuldiagonal(GEN x, GEN d) GEN matmultodiagonal(GEN x, GEN y) GEN matslice0(GEN A, long x1, long x2, long y1, long y2) GEN parapply(GEN V, GEN C) void parfor(GEN a, GEN b, GEN code, void *E, long call(void*, GEN, GEN)) void parforprime(GEN a, GEN b, GEN code, void *E, long call(void*, GEN, GEN)) void parforvec(GEN x, GEN code, long flag, void *E, long call(void*, GEN, GEN)) GEN parselect(GEN C, GEN D, long flag) GEN select0(GEN A, GEN f, long flag) GEN shallowextract(GEN x, GEN L) GEN shallowtrans(GEN x) GEN vecapply(void *E, GEN (*f)(void* E, GEN x), GEN x) GEN veccatapply(void *E, GEN (*f)(void* E, GEN x), GEN x) GEN veccatselapply(void *Epred, long (*pred)(void* E, GEN x), void *Efun, GEN (*fun)(void* E, GEN x), GEN A) GEN vecrange(GEN a, GEN b) GEN vecrangess(long a, long b) GEN vecselapply(void *Epred, long (*pred)(void* E, GEN x), void *Efun, GEN (*fun)(void* E, GEN x), GEN A) GEN vecselect(void *E, long (*f)(void* E, GEN x), GEN A) GEN vecslice0(GEN A, long y1, long y2) GEN vecsum(GEN v) # anal.c void addhelp(const char *e, char *s) void alias0(const char *s, const char *old) GEN compile_str(const char *s) GEN chartoGENstr(char c) long delete_var() long fetch_user_var(const char *s) long fetch_var() long fetch_var_higher() GEN fetch_var_value(long vx, GEN t) char * gp_embedded(const char *s) void gp_embedded_init(long rsize, long vsize) GEN gp_read_str(const char *t) entree* install(void *f, const char *name, const char *code) entree* is_entry(const char *s) void kill0(const char *e) void pari_var_close() void pari_var_init() long pari_var_next() long pari_var_next_temp() long pari_var_create(entree *ep) void name_var(long n, const char *s) GEN readseq(char *t) GEN* safegel(GEN x, long l) long* safeel(GEN x, long l) GEN* safelistel(GEN x, long l) GEN* safegcoeff(GEN x, long a, long b) GEN strntoGENstr(const char *s, long n0) GEN strtoGENstr(const char *s) GEN strtoi(const char *s) GEN strtor(const char *s, long prec) GEN type0(GEN x) GEN varhigher(const char *s, long v) GEN varlower(const char *s, long v) # aprcl.c long isprimeAPRCL(GEN N) # Qfb.c GEN Qfb0(GEN x, GEN y, GEN z, GEN d, long prec) void check_quaddisc(GEN x, long *s, long *r, const char *f) void check_quaddisc_imag(GEN x, long *r, const char *f) void check_quaddisc_real(GEN x, long *r, const char *f) long cornacchia(GEN d, GEN p, GEN *px, GEN *py) long cornacchia2(GEN d, GEN p, GEN *px, GEN *py) GEN nucomp(GEN x, GEN y, GEN L) GEN nudupl(GEN x, GEN L) GEN nupow(GEN x, GEN n, GEN L) GEN primeform(GEN x, GEN p, long prec) GEN primeform_u(GEN x, ulong p) int qfb_equal1(GEN f) GEN qfbcompraw(GEN x, GEN y) GEN qfbpowraw(GEN x, long n) GEN qfbred0(GEN x, long flag, GEN D, GEN isqrtD, GEN sqrtD) GEN qfbredsl2(GEN q, GEN S) GEN qfbsolve(GEN Q, GEN n) GEN qfi(GEN x, GEN y, GEN z) GEN qfi_1(GEN x) GEN qfi_Shanks(GEN a, GEN g, long n) GEN qfi_log(GEN a, GEN g, GEN o) GEN qfi_order(GEN q, GEN o) GEN qficomp(GEN x, GEN y) GEN qficompraw(GEN x, GEN y) GEN qfipowraw(GEN x, long n) GEN qfisolvep(GEN Q, GEN p) GEN qfisqr(GEN x) GEN qfisqrraw(GEN x) GEN qfr(GEN x, GEN y, GEN z, GEN d) GEN qfr3_comp(GEN x, GEN y, qfr_data *S) GEN qfr3_pow(GEN x, GEN n, qfr_data *S) GEN qfr3_red(GEN x, qfr_data *S) GEN qfr3_rho(GEN x, qfr_data *S) GEN qfr3_to_qfr(GEN x, GEN z) GEN qfr5_comp(GEN x, GEN y, qfr_data *S) GEN qfr5_dist(GEN e, GEN d, long prec) GEN qfr5_pow(GEN x, GEN n, qfr_data *S) GEN qfr5_red(GEN x, qfr_data *S) GEN qfr5_rho(GEN x, qfr_data *S) GEN qfr5_to_qfr(GEN x, GEN d0) GEN qfr_1(GEN x) void qfr_data_init(GEN D, long prec, qfr_data *S) GEN qfr_to_qfr5(GEN x, long prec) GEN qfrcomp(GEN x, GEN y) GEN qfrcompraw(GEN x, GEN y) GEN qfrpow(GEN x, GEN n) GEN qfrpowraw(GEN x, long n) GEN qfrsolvep(GEN Q, GEN p) GEN qfrsqr(GEN x) GEN qfrsqrraw(GEN x) GEN quadgen(GEN x) GEN quadpoly(GEN x) GEN quadpoly0(GEN x, long v) GEN redimag(GEN x) GEN redreal(GEN x) GEN redrealnod(GEN x, GEN isqrtD) GEN rhoreal(GEN x) GEN rhorealnod(GEN x, GEN isqrtD) # arith1.c ulong Fl_order(ulong a, ulong o, ulong p) GEN Fl_powers(ulong x, long n, ulong p) GEN Fl_powers_pre(ulong x, long n, ulong p, ulong pi) ulong Fl_powu(ulong x, ulong n, ulong p) ulong Fl_powu_pre(ulong x, ulong n, ulong p, ulong pi) ulong Fl_sqrt(ulong a, ulong p) ulong Fl_sqrt_pre(ulong a, ulong p, ulong pi) ulong Fl_sqrtl(ulong a, ulong l, ulong p) ulong Fl_sqrtl_pre(ulong a, ulong l, ulong p, ulong pi) GEN Fp_factored_order(GEN a, GEN o, GEN p) int Fp_ispower(GEN x, GEN K, GEN p) GEN Fp_log(GEN a, GEN g, GEN ord, GEN p) GEN Fp_order(GEN a, GEN o, GEN p) GEN Fp_pow(GEN a, GEN n, GEN m) GEN Fp_powers(GEN x, long n, GEN p) GEN Fp_pows(GEN A, long k, GEN N) GEN Fp_powu(GEN x, ulong k, GEN p) GEN Fp_sqrt(GEN a, GEN p) GEN Fp_sqrtn(GEN a, GEN n, GEN p, GEN *zetan) GEN Z_ZV_mod(GEN P, GEN xa) GEN Z_chinese(GEN a, GEN b, GEN A, GEN B) GEN Z_chinese_all(GEN a, GEN b, GEN A, GEN B, GEN *pC) GEN Z_chinese_coprime(GEN a, GEN b, GEN A, GEN B, GEN C) GEN Z_chinese_post(GEN a, GEN b, GEN C, GEN U, GEN d) void Z_chinese_pre(GEN A, GEN B, GEN *pC, GEN *pU, GEN *pd) GEN Z_factor_listP(GEN N, GEN L) long Z_isanypower(GEN x, GEN *y) long Z_isfundamental(GEN x) long Z_ispow2(GEN x) long Z_ispowerall(GEN x, ulong k, GEN *pt) long Z_issquareall(GEN x, GEN *pt) GEN Z_nv_mod(GEN P, GEN xa) GEN ZV_allpnqn(GEN x) GEN ZV_chinese(GEN A, GEN P, GEN *pt_mod) GEN ZV_chinese_tree(GEN A, GEN P, GEN tree, GEN *pt_mod) GEN ZV_producttree(GEN xa) GEN ZX_nv_mod_tree(GEN P, GEN xa, GEN T) GEN Zideallog(GEN bid, GEN x) long Zp_issquare(GEN a, GEN p) GEN bestappr(GEN x, GEN k) GEN bestapprPade(GEN x, long B) long cgcd(long a, long b) GEN chinese(GEN x, GEN y) GEN chinese1(GEN x) GEN chinese1_coprime_Z(GEN x) GEN classno(GEN x) GEN classno2(GEN x) long clcm(long a, long b) GEN contfrac0(GEN x, GEN b, long flag) GEN contfracpnqn(GEN x, long n) GEN fibo(long n) GEN gboundcf(GEN x, long k) GEN gcf(GEN x) GEN gcf2(GEN b, GEN x) const bb_field *get_Fp_field(void **E, GEN p) ulong pgener_Fl(ulong p) ulong pgener_Fl_local(ulong p, GEN L) GEN pgener_Fp(GEN p) GEN pgener_Fp_local(GEN p, GEN L) ulong pgener_Zl(ulong p) GEN pgener_Zp(GEN p) long gisanypower(GEN x, GEN *pty) GEN gissquare(GEN x) GEN gissquareall(GEN x, GEN *pt) GEN hclassno(GEN x) long hilbert(GEN x, GEN y, GEN p) long hilbertii(GEN x, GEN y, GEN p) long isfundamental(GEN x) long ispolygonal(GEN x, GEN S, GEN *N) long ispower(GEN x, GEN k, GEN *pty) long isprimepower(GEN x, GEN *pty) long ispseudoprimepower(GEN n, GEN *pt) long issquare(GEN x) long issquareall(GEN x, GEN *pt) long krois(GEN x, long y) long kroiu(GEN x, ulong y) long kronecker(GEN x, GEN y) long krosi(long s, GEN x) long kross(long x, long y) long kroui(ulong x, GEN y) long krouu(ulong x, ulong y) GEN lcmii(GEN a, GEN b) long logint0(GEN B, GEN y, GEN *ptq) GEN mpfact(long n) GEN muls_interval(long a, long b) GEN mulu_interval(ulong a, ulong b) GEN ncV_chinese_center(GEN A, GEN P, GEN *pt_mod) GEN nmV_chinese_center(GEN A, GEN P, GEN *pt_mod) GEN odd_prime_divisors(GEN q) GEN order(GEN x) GEN pnqn(GEN x) GEN qfbclassno0(GEN x, long flag) GEN quaddisc(GEN x) GEN quadregulator(GEN x, long prec) GEN quadunit(GEN x) ulong rootsof1_Fl(ulong n, ulong p) GEN rootsof1_Fp(GEN n, GEN p) GEN rootsof1u_Fp(ulong n, GEN p) long sisfundamental(long x) GEN sqrtint(GEN a) GEN ramanujantau(GEN n) ulong ugcd(ulong a, ulong b) long uisprimepower(ulong n, ulong *p) long uissquare(ulong A) long uissquareall(ulong A, ulong *sqrtA) long unegisfundamental(ulong x) long uposisfundamental(ulong x) GEN znlog(GEN x, GEN g, GEN o) GEN znorder(GEN x, GEN o) GEN znprimroot(GEN m) GEN znstar(GEN x) GEN znstar0(GEN N, long flag) # arith2.c GEN Z_smoothen(GEN N, GEN L, GEN *pP, GEN *pe) GEN boundfact(GEN n, ulong lim) GEN check_arith_pos(GEN n, const char *f) GEN check_arith_non0(GEN n, const char *f) GEN check_arith_all(GEN n, const char *f) GEN clean_Z_factor(GEN f) GEN corepartial(GEN n, long l) GEN core0(GEN n, long flag) GEN core2(GEN n) GEN core2partial(GEN n, long l) GEN coredisc(GEN n) GEN coredisc0(GEN n, long flag) GEN coredisc2(GEN n) long corediscs(long D, ulong *f) GEN digits(GEN N, GEN B) GEN divisors(GEN n) GEN divisorsu(ulong n) GEN divisorsu_fact(GEN P, GEN e) GEN factor_pn_1(GEN p, ulong n) GEN factor_pn_1_limit(GEN p, long n, ulong lim) GEN factoru_pow(ulong n) GEN fromdigits(GEN x, GEN B) GEN fuse_Z_factor(GEN f, GEN B) GEN gen_digits(GEN x, GEN B, long n, void *E, bb_ring *r, GEN (*div)(void *E, GEN x, GEN y, GEN *r)) GEN gen_fromdigits(GEN x, GEN B, void *E, bb_ring *r) byteptr initprimes(ulong maxnum, long *lenp, ulong *lastp) void initprimetable(ulong maxnum) ulong init_primepointer_geq(ulong a, byteptr *pd) ulong init_primepointer_gt(ulong a, byteptr *pd) ulong init_primepointer_leq(ulong a, byteptr *pd) ulong init_primepointer_lt(ulong a, byteptr *pd) int is_Z_factor(GEN f) int is_Z_factornon0(GEN f) int is_Z_factorpos(GEN f) ulong maxprime() void maxprime_check(ulong c) GEN sumdigits(GEN n) GEN sumdigits0(GEN n, GEN B) ulong sumdigitsu(ulong n) GEN usumdiv_fact(GEN f) GEN usumdivk_fact(GEN f, ulong k) # base1.c GEN FpX_FpC_nfpoleval(GEN nf, GEN pol, GEN a, GEN p) GEN embed_T2(GEN x, long r1) GEN embednorm_T2(GEN x, long r1) GEN embed_norm(GEN x, long r1) void check_ZKmodule(GEN x, const char *s) void checkbid(GEN bid) GEN checkbnf(GEN bnf) void checkbnr(GEN bnr) void checkbnrgen(GEN bnr) void checkabgrp(GEN v) void checksqmat(GEN x, long N) GEN checknf(GEN nf) GEN checknfelt_mod(GEN nf, GEN x, const char *s) void checkprid(GEN bid) void checkrnf(GEN rnf) GEN factoredpolred(GEN x, GEN fa) GEN factoredpolred2(GEN x, GEN fa) GEN galoisapply(GEN nf, GEN aut, GEN x) GEN get_bnf(GEN x, long *t) GEN get_bnfpol(GEN x, GEN *bnf, GEN *nf) GEN get_nf(GEN x, long *t) GEN get_nfpol(GEN x, GEN *nf) GEN get_prid(GEN x) GEN idealfrobenius(GEN nf, GEN gal, GEN pr) GEN idealfrobenius_aut(GEN nf, GEN gal, GEN pr, GEN aut) GEN idealramfrobenius(GEN nf, GEN gal, GEN pr, GEN ram) GEN idealramgroups(GEN nf, GEN gal, GEN pr) GEN nf_get_allroots(GEN nf) long nf_get_prec(GEN x) GEN nfcertify(GEN x) GEN nfgaloismatrix(GEN nf, GEN s) GEN nfgaloispermtobasis(GEN nf, GEN gal) void nfinit_step1(nfbasic_t *T, GEN x, long flag) GEN nfinit_step2(nfbasic_t *T, long flag, long prec) GEN nfinit(GEN x, long prec) GEN nfinit0(GEN x, long flag, long prec) GEN nfinitall(GEN x, long flag, long prec) GEN nfinitred(GEN x, long prec) GEN nfinitred2(GEN x, long prec) GEN nfisincl(GEN a, GEN b) GEN nfisisom(GEN a, GEN b) GEN nfnewprec(GEN nf, long prec) GEN nfnewprec_shallow(GEN nf, long prec) GEN nfpoleval(GEN nf, GEN pol, GEN a) long nftyp(GEN x) GEN polredord(GEN x) GEN polgalois(GEN x, long prec) GEN polred(GEN x) GEN polred0(GEN x, long flag, GEN fa) GEN polred2(GEN x) GEN polredabs(GEN x) GEN polredabs0(GEN x, long flag) GEN polredabs2(GEN x) GEN polredabsall(GEN x, long flun) GEN polredbest(GEN x, long flag) GEN rnfpolredabs(GEN nf, GEN pol, long flag) GEN rnfpolredbest(GEN nf, GEN relpol, long flag) GEN smallpolred(GEN x) GEN smallpolred2(GEN x) GEN tschirnhaus(GEN x) GEN ZX_Q_normalize(GEN pol, GEN *ptlc) GEN ZX_Z_normalize(GEN pol, GEN *ptk) GEN ZX_to_monic(GEN pol, GEN *lead) GEN ZX_primitive_to_monic(GEN pol, GEN *lead) # base2.c GEN Fq_to_nf(GEN x, GEN modpr) GEN FqM_to_nfM(GEN z, GEN modpr) GEN FqV_to_nfV(GEN z, GEN modpr) GEN FqX_to_nfX(GEN x, GEN modpr) GEN Rg_nffix(const char *f, GEN T, GEN c, int lift) GEN RgV_nffix(const char *f, GEN T, GEN P, int lift) GEN RgX_nffix(const char *s, GEN nf, GEN x, int lift) long ZpX_disc_val(GEN f, GEN p) GEN ZpX_gcd(GEN f1, GEN f2, GEN p, GEN pm) GEN ZpX_reduced_resultant(GEN x, GEN y, GEN p, GEN pm) GEN ZpX_reduced_resultant_fast(GEN f, GEN g, GEN p, long M) long ZpX_resultant_val(GEN f, GEN g, GEN p, long M) void checkmodpr(GEN modpr) GEN ZX_compositum_disjoint(GEN A, GEN B) GEN compositum(GEN P, GEN Q) GEN compositum2(GEN P, GEN Q) GEN nfdisc(GEN x) GEN get_modpr(GEN x) GEN indexpartial(GEN P, GEN DP) GEN modpr_genFq(GEN modpr) GEN nf_to_Fq_init(GEN nf, GEN *pr, GEN *T, GEN *p) GEN nf_to_Fq(GEN nf, GEN x, GEN modpr) GEN nfM_to_FqM(GEN z, GEN nf, GEN modpr) GEN nfV_to_FqV(GEN z, GEN nf, GEN modpr) GEN nfX_to_FqX(GEN x, GEN nf, GEN modpr) GEN nfbasis(GEN x, GEN *y, GEN p) GEN nfcompositum(GEN nf, GEN A, GEN B, long flag) void nfmaxord(nfmaxord_t *S, GEN T, long flag) GEN nfmodprinit(GEN nf, GEN pr) GEN nfreducemodpr(GEN nf, GEN x, GEN modpr) GEN nfsplitting(GEN T, GEN D) GEN polcompositum0(GEN P, GEN Q, long flag) GEN idealprimedec(GEN nf, GEN p) GEN idealprimedec_limit_f(GEN nf, GEN p, long f) GEN idealprimedec_limit_norm(GEN nf, GEN p, GEN B) GEN rnfbasis(GEN bnf, GEN order) GEN rnfdedekind(GEN nf, GEN T, GEN pr, long flag) GEN rnfdet(GEN nf, GEN order) GEN rnfdiscf(GEN nf, GEN pol) GEN rnfequation(GEN nf, GEN pol) GEN rnfequation0(GEN nf, GEN pol, long flall) GEN rnfequation2(GEN nf, GEN pol) GEN nf_rnfeq(GEN nf, GEN relpol) GEN nf_rnfeqsimple(GEN nf, GEN relpol) GEN rnfequationall(GEN A, GEN B, long *pk, GEN *pLPRS) GEN rnfhnfbasis(GEN bnf, GEN order) long rnfisfree(GEN bnf, GEN order) GEN rnflllgram(GEN nf, GEN pol, GEN order, long prec) GEN rnfpolred(GEN nf, GEN pol, long prec) GEN rnfpseudobasis(GEN nf, GEN pol) GEN rnfsimplifybasis(GEN bnf, GEN order) GEN rnfsteinitz(GEN nf, GEN order) long factorial_lval(ulong n, ulong p) GEN zk_to_Fq_init(GEN nf, GEN *pr, GEN *T, GEN *p) GEN zk_to_Fq(GEN x, GEN modpr) GEN zkmodprinit(GEN nf, GEN pr) # base3.c GEN Idealstar(GEN nf, GEN x, long flun) GEN RgC_to_nfC(GEN nf, GEN x) GEN RgM_to_nfM(GEN nf, GEN x) GEN RgX_to_nfX(GEN nf, GEN pol) GEN algtobasis(GEN nf, GEN x) GEN basistoalg(GEN nf, GEN x) GEN gpnfvalrem(GEN nf, GEN x, GEN pr, GEN *py) GEN ideallist(GEN nf, long bound) GEN ideallist0(GEN nf, long bound, long flag) GEN ideallistarch(GEN nf, GEN list, GEN arch) GEN idealprincipalunits(GEN nf, GEN pr, long e) GEN idealstar0(GEN nf, GEN x, long flag) GEN indices_to_vec01(GEN archp, long r) GEN matalgtobasis(GEN nf, GEN x) GEN matbasistoalg(GEN nf, GEN x) GEN nf_to_scalar_or_alg(GEN nf, GEN x) GEN nf_to_scalar_or_basis(GEN nf, GEN x) GEN nfadd(GEN nf, GEN x, GEN y) GEN nfarchstar(GEN nf, GEN x, GEN arch) GEN nfdiv(GEN nf, GEN x, GEN y) GEN nfdiveuc(GEN nf, GEN a, GEN b) GEN nfdivrem(GEN nf, GEN a, GEN b) GEN nfembed(GEN nf, GEN x, long k) GEN nfinv(GEN nf, GEN x) GEN nfinvmodideal(GEN nf, GEN x, GEN ideal) int nfchecksigns(GEN nf, GEN x, GEN pl) GEN nfmod(GEN nf, GEN a, GEN b) GEN nfmul(GEN nf, GEN x, GEN y) GEN nfmuli(GEN nf, GEN x, GEN y) GEN nfnorm(GEN nf, GEN x) GEN nfpow(GEN nf, GEN x, GEN k) GEN nfpow_u(GEN nf, GEN z, ulong n) GEN nfpowmodideal(GEN nf, GEN x, GEN k, GEN ideal) GEN nfsign(GEN nf, GEN alpha) GEN nfsign_arch(GEN nf, GEN alpha, GEN arch) GEN nfsign_from_logarch(GEN Larch, GEN invpi, GEN archp) GEN nfsqr(GEN nf, GEN x) GEN nfsqri(GEN nf, GEN x) GEN nftrace(GEN nf, GEN x) long nfval(GEN nf, GEN x, GEN vp) long nfvalrem(GEN nf, GEN x, GEN pr, GEN *py) GEN polmod_nffix(const char *f, GEN rnf, GEN x, int lift) GEN polmod_nffix2(const char *f, GEN T, GEN relpol, GEN x, int lift) int pr_equal(GEN nf, GEN P, GEN Q) GEN rnfalgtobasis(GEN rnf, GEN x) GEN rnfbasistoalg(GEN rnf, GEN x) GEN rnfeltnorm(GEN rnf, GEN x) GEN rnfelttrace(GEN rnf, GEN x) GEN set_sign_mod_divisor(GEN nf, GEN x, GEN y, GEN idele, GEN sarch) GEN vec01_to_indices(GEN arch) GEN vecsmall01_to_indices(GEN v) GEN vecmodii(GEN a, GEN b) GEN ideallog(GEN nf, GEN x, GEN bigideal) GEN multable(GEN nf, GEN x) GEN tablemul(GEN TAB, GEN x, GEN y) GEN tablemul_ei(GEN M, GEN x, long i) GEN tablemul_ei_ej(GEN M, long i, long j) GEN tablemulvec(GEN M, GEN x, GEN v) GEN tablesqr(GEN tab, GEN x) GEN ei_multable(GEN nf, long i) long ZC_nfval(GEN nf, GEN x, GEN P) long ZC_nfvalrem(GEN nf, GEN x, GEN P, GEN *t) GEN zk_multable(GEN nf, GEN x) GEN zk_scalar_or_multable(GEN, GEN x) int ZC_prdvd(GEN nf, GEN x, GEN P) # base4.c GEN RM_round_maxrank(GEN G) GEN ZM_famat_limit(GEN fa, GEN limit) GEN famat_Z_gcd(GEN M, GEN n) GEN famat_inv(GEN f) GEN famat_inv_shallow(GEN f) GEN famat_makecoprime(GEN nf, GEN g, GEN e, GEN pr, GEN prk, GEN EX) GEN famat_mul(GEN f, GEN g) GEN famat_pow(GEN f, GEN n) GEN famat_sqr(GEN f) GEN famat_reduce(GEN fa) GEN famat_to_nf(GEN nf, GEN f) GEN famat_to_nf_modideal_coprime(GEN nf, GEN g, GEN e, GEN id, GEN EX) GEN famat_to_nf_moddivisor(GEN nf, GEN g, GEN e, GEN bid) GEN famatsmall_reduce(GEN fa) GEN gpidealval(GEN nf, GEN ix, GEN P) GEN idealtwoelt(GEN nf, GEN ix) GEN idealtwoelt0(GEN nf, GEN ix, GEN a) GEN idealtwoelt2(GEN nf, GEN x, GEN a) GEN idealadd(GEN nf, GEN x, GEN y) GEN idealaddmultoone(GEN nf, GEN list) GEN idealaddtoone(GEN nf, GEN x, GEN y) GEN idealaddtoone_i(GEN nf, GEN x, GEN y) GEN idealaddtoone0(GEN nf, GEN x, GEN y) GEN idealappr(GEN nf, GEN x) GEN idealappr0(GEN nf, GEN x, long fl) GEN idealapprfact(GEN nf, GEN x) GEN idealchinese(GEN nf, GEN x, GEN y) GEN idealcoprime(GEN nf, GEN x, GEN y) GEN idealcoprimefact(GEN nf, GEN x, GEN fy) GEN idealdiv(GEN nf, GEN x, GEN y) GEN idealdiv0(GEN nf, GEN x, GEN y, long flag) GEN idealdivexact(GEN nf, GEN x, GEN y) GEN idealdivpowprime(GEN nf, GEN x, GEN vp, GEN n) GEN idealmulpowprime(GEN nf, GEN x, GEN vp, GEN n) GEN idealfactor(GEN nf, GEN x) GEN idealhnf(GEN nf, GEN x) GEN idealhnf_principal(GEN nf, GEN x) GEN idealhnf_shallow(GEN nf, GEN x) GEN idealhnf_two(GEN nf, GEN vp) GEN idealhnf0(GEN nf, GEN a, GEN b) GEN idealintersect(GEN nf, GEN x, GEN y) GEN idealinv(GEN nf, GEN ix) GEN idealinv_HNF(GEN nf, GEN I) GEN idealred0(GEN nf, GEN I, GEN vdir) GEN idealmul(GEN nf, GEN ix, GEN iy) GEN idealmul0(GEN nf, GEN ix, GEN iy, long flag) GEN idealmul_HNF(GEN nf, GEN ix, GEN iy) GEN idealmulred(GEN nf, GEN ix, GEN iy) GEN idealnorm(GEN nf, GEN x) GEN idealnumden(GEN nf, GEN x) GEN idealpow(GEN nf, GEN ix, GEN n) GEN idealpow0(GEN nf, GEN ix, GEN n, long flag) GEN idealpowred(GEN nf, GEN ix, GEN n) GEN idealpows(GEN nf, GEN ideal, long iexp) GEN idealprodprime(GEN nf, GEN L) GEN idealsqr(GEN nf, GEN x) long idealtyp(GEN *ideal, GEN *arch) long idealval(GEN nf, GEN ix, GEN vp) long isideal(GEN nf, GEN x) GEN idealmin(GEN nf, GEN ix, GEN vdir) GEN nf_get_Gtwist(GEN nf, GEN vdir) GEN nf_get_Gtwist1(GEN nf, long i) GEN nfC_nf_mul(GEN nf, GEN v, GEN x) GEN nfdetint(GEN nf, GEN pseudo) GEN nfdivmodpr(GEN nf, GEN x, GEN y, GEN modpr) GEN nfhnf(GEN nf, GEN x) GEN nfhnf0(GEN nf, GEN x, long flag) GEN nfhnfmod(GEN nf, GEN x, GEN d) GEN nfkermodpr(GEN nf, GEN x, GEN modpr) GEN nfmulmodpr(GEN nf, GEN x, GEN y, GEN modpr) GEN nfpowmodpr(GEN nf, GEN x, GEN k, GEN modpr) GEN nfreduce(GEN nf, GEN x, GEN ideal) GEN nfsnf(GEN nf, GEN x) GEN nfsnf0(GEN nf, GEN x, long flag) GEN nfsolvemodpr(GEN nf, GEN a, GEN b, GEN modpr) GEN to_famat(GEN x, GEN y) GEN to_famat_shallow(GEN x, GEN y) GEN vecdiv(GEN x, GEN y) GEN vecinv(GEN x) GEN vecmul(GEN x, GEN y) GEN vecpow(GEN x, GEN n) # base5.c GEN eltreltoabs(GEN rnfeq, GEN x) GEN eltabstorel(GEN eq, GEN P) GEN eltabstorel_lift(GEN rnfeq, GEN P) void nf_nfzk(GEN nf, GEN rnfeq, GEN *zknf, GEN *czknf) GEN nfeltup(GEN nf, GEN x, GEN zknf, GEN czknf) GEN rnfeltabstorel(GEN rnf, GEN x) GEN rnfeltdown(GEN rnf, GEN x) GEN rnfeltdown0(GEN rnf, GEN x, long flag) GEN rnfeltreltoabs(GEN rnf, GEN x) GEN rnfeltup(GEN rnf, GEN x) GEN rnfeltup0(GEN rnf, GEN x, long flag) GEN rnfidealabstorel(GEN rnf, GEN x) GEN rnfidealdown(GEN rnf, GEN x) GEN rnfidealhnf(GEN rnf, GEN x) GEN rnfidealmul(GEN rnf, GEN x, GEN y) GEN rnfidealnormabs(GEN rnf, GEN x) GEN rnfidealnormrel(GEN rnf, GEN x) GEN rnfidealprimedec(GEN rnf, GEN pr) GEN rnfidealreltoabs(GEN rnf, GEN x) GEN rnfidealreltoabs0(GEN rnf, GEN x, long flag) GEN rnfidealtwoelement(GEN rnf, GEN x) GEN rnfidealup(GEN rnf, GEN x) GEN rnfidealup0(GEN rnf, GEN x, long flag) GEN rnfinit(GEN nf, GEN pol) GEN rnfinit0(GEN nf, GEN pol, long flag) # bb_group.c GEN dlog_get_ordfa(GEN o) GEN dlog_get_ord(GEN o) GEN gen_PH_log(GEN a, GEN g, GEN ord, void *E, const bb_group *grp) GEN gen_Shanks_init(GEN g, long n, void *E, const bb_group *grp) GEN gen_Shanks(GEN T, GEN x, ulong N, void *E, const bb_group *grp) GEN gen_Shanks_sqrtn(GEN a, GEN n, GEN q, GEN *zetan, void *E, const bb_group *grp) GEN gen_gener(GEN o, void *E, const bb_group *grp) GEN gen_ellgens(GEN d1, GEN d2, GEN m, void *E, const bb_group *grp, GEN pairorder(void *E, GEN P, GEN Q, GEN m, GEN F)) GEN gen_ellgroup(GEN N, GEN F, GEN *pt_m, void *E, const bb_group *grp, GEN pairorder(void *E, GEN P, GEN Q, GEN m, GEN F)) GEN gen_factored_order(GEN a, GEN o, void *E, const bb_group *grp) GEN gen_order(GEN x, GEN o, void *E, const bb_group *grp) GEN gen_select_order(GEN o, void *E, const bb_group *grp) GEN gen_plog(GEN x, GEN g0, GEN q, void *E, const bb_group *grp) GEN gen_pow(GEN x, GEN n, void *E, GEN (*sqr)(void*, GEN), GEN (*mul)(void*, GEN, GEN)) GEN gen_pow_i(GEN x, GEN n, void *E, GEN (*sqr)(void*, GEN), GEN (*mul)(void*, GEN, GEN)) GEN gen_pow_fold(GEN x, GEN n, void *E, GEN (*sqr)(void*, GEN), GEN (*msqr)(void*, GEN)) GEN gen_pow_fold_i(GEN x, GEN n, void *E, GEN (*sqr)(void*, GEN), GEN (*msqr)(void*, GEN)) GEN gen_powers(GEN x, long l, int use_sqr, void *E, GEN (*sqr)(void*, GEN), GEN (*mul)(void*, GEN, GEN), GEN (*one)(void*)) GEN gen_powu(GEN x, ulong n, void *E, GEN (*sqr)(void*, GEN), GEN (*mul)(void*, GEN, GEN)) GEN gen_powu_i(GEN x, ulong n, void *E, GEN (*sqr)(void*, GEN), GEN (*mul)(void*, GEN, GEN)) GEN gen_powu_fold(GEN x, ulong n, void *E, GEN (*sqr)(void*, GEN), GEN (*msqr)(void*, GEN)) GEN gen_powu_fold_i(GEN x, ulong n, void *E, GEN (*sqr)(void*, GEN), GEN (*msqr)(void*, GEN)) GEN gen_product(GEN x, void *data, GEN (*mul)(void*, GEN, GEN)) # bibli1.c int QR_init(GEN x, GEN *pB, GEN *pQ, GEN *pL, long prec) GEN R_from_QR(GEN x, long prec) GEN RgM_Babai(GEN B, GEN t) int RgM_QR_init(GEN x, GEN *pB, GEN *pQ, GEN *pL, long prec) GEN RgM_gram_schmidt(GEN e, GEN *ptB) GEN Xadic_lindep(GEN x) GEN algdep(GEN x, long n) GEN algdep0(GEN x, long n, long bit) void forqfvec(void *E, long (*fun)(void *, GEN, GEN, double), GEN a, GEN BORNE) void forqfvec0(GEN a, GEN BORNE, GEN code) GEN gaussred_from_QR(GEN x, long prec) GEN lindep0(GEN x, long flag) GEN lindep(GEN x) GEN lindep2(GEN x, long bit) GEN mathouseholder(GEN Q, GEN v) GEN matqr(GEN x, long flag, long prec) GEN minim(GEN a, GEN borne, GEN stockmax) GEN minim_raw(GEN a, GEN borne, GEN stockmax) GEN minim2(GEN a, GEN borne, GEN stockmax) GEN padic_lindep(GEN x) GEN perf(GEN a) GEN qfrep0(GEN a, GEN borne, long flag) GEN qfminim0(GEN a, GEN borne, GEN stockmax, long flag, long prec) GEN seralgdep(GEN s, long p, long r) GEN zncoppersmith(GEN P0, GEN N, GEN X, GEN B) # bibli2.c GEN QXQ_reverse(GEN a, GEN T) GEN RgV_polint(GEN X, GEN Y, long v) GEN RgXQ_reverse(GEN a, GEN T) GEN ZV_indexsort(GEN L) long ZV_search(GEN x, GEN y) GEN ZV_sort(GEN L) GEN ZV_sort_uniq(GEN L) GEN ZV_union_shallow(GEN x, GEN y) GEN binomial(GEN x, long k) GEN binomialuu(ulong n, ulong k) int cmp_Flx(GEN x, GEN y) int cmp_RgX(GEN x, GEN y) int cmp_nodata(void *data, GEN x, GEN y) int cmp_prime_ideal(GEN x, GEN y) int cmp_prime_over_p(GEN x, GEN y) int cmp_universal(GEN x, GEN y) GEN convol(GEN x, GEN y) int gen_cmp_RgX(void *data, GEN x, GEN y) GEN polcyclo(long n, long v) GEN polcyclo_eval(long n, GEN x) GEN dirdiv(GEN x, GEN y) GEN dirmul(GEN x, GEN y) GEN gen_indexsort(GEN x, void *E, int (*cmp)(void*, GEN, GEN)) GEN gen_indexsort_uniq(GEN x, void *E, int (*cmp)(void*, GEN, GEN)) long gen_search(GEN x, GEN y, long flag, void *data, int (*cmp)(void*, GEN, GEN)) GEN gen_setminus(GEN set1, GEN set2, int (*cmp)(GEN, GEN)) GEN gen_sort(GEN x, void *E, int (*cmp)(void*, GEN, GEN)) void gen_sort_inplace(GEN x, void *E, int (*cmp)(void*, GEN, GEN), GEN *perm) GEN gen_sort_uniq(GEN x, void *E, int (*cmp)(void*, GEN, GEN)) long getstack() long gettime() long getabstime() GEN getwalltime() GEN gprec(GEN x, long l) GEN gprec_wtrunc(GEN x, long pr) GEN gprec_w(GEN x, long pr) GEN gtoset(GEN x) GEN indexlexsort(GEN x) GEN indexsort(GEN x) GEN indexvecsort(GEN x, GEN k) GEN laplace(GEN x) GEN lexsort(GEN x) GEN mathilbert(long n) GEN matqpascal(long n, GEN q) GEN merge_factor(GEN fx, GEN fy, void *data, int (*cmp)(void *, GEN, GEN)) GEN merge_sort_uniq(GEN x, GEN y, void *data, int (*cmp)(void *, GEN, GEN)) GEN modreverse(GEN x) GEN numtoperm(long n, GEN x) GEN permtonum(GEN x) GEN polhermite(long n, long v) GEN polhermite_eval(long n, GEN x) GEN pollegendre(long n, long v) GEN pollegendre_eval(long n, GEN x) GEN polint(GEN xa, GEN ya, GEN x, GEN *dy) GEN polchebyshev(long n, long kind, long v) GEN polchebyshev_eval(long n, long kind, GEN x) GEN polchebyshev1(long n, long v) GEN polchebyshev2(long n, long v) GEN polrecip(GEN x) GEN setbinop(GEN f, GEN x, GEN y) GEN setintersect(GEN x, GEN y) long setisset(GEN x) GEN setminus(GEN x, GEN y) long setsearch(GEN x, GEN y, long flag) GEN setunion(GEN x, GEN y) GEN sort(GEN x) GEN sort_factor(GEN y, void *data, int (*cmp)(void*, GEN, GEN)) GEN stirling(long n, long m, long flag) GEN stirling1(ulong n, ulong m) GEN stirling2(ulong n, ulong m) long tablesearch(GEN T, GEN x, int (*cmp)(GEN, GEN)) GEN vecbinome(long n) long vecsearch(GEN v, GEN x, GEN k) GEN vecsort(GEN x, GEN k) GEN vecsort0(GEN x, GEN k, long flag) long zv_search(GEN x, long y) # bit.c GEN bits_to_int(GEN x, long l) ulong bits_to_u(GEN v, long l) GEN binaire(GEN x) GEN binary_2k(GEN x, long k) GEN binary_2k_nv(GEN x, long k) GEN binary_zv(GEN x) long bittest(GEN x, long n) GEN fromdigits_2k(GEN x, long k) GEN gbitand(GEN x, GEN y) GEN gbitneg(GEN x, long n) GEN gbitnegimply(GEN x, GEN y) GEN gbitor(GEN x, GEN y) GEN gbittest(GEN x, long n) GEN gbitxor(GEN x, GEN y) long hammingweight(GEN n) GEN ibitand(GEN x, GEN y) GEN ibitnegimply(GEN x, GEN y) GEN ibitor(GEN x, GEN y) GEN ibitxor(GEN x, GEN y) GEN nv_fromdigits_2k(GEN x, long k) # buch1.c GEN Buchquad(GEN D, double c1, double c2, long prec) GEN quadclassunit0(GEN x, long flag, GEN data, long prec) GEN quadhilbert(GEN D, long prec) GEN quadray(GEN bnf, GEN f, long prec) # buch2.c GEN Buchall(GEN P, long flag, long prec) GEN Buchall_param(GEN P, double bach, double bach2, long nbrelpid, long flun, long prec) GEN bnfcompress(GEN bnf) GEN bnfinit0(GEN P, long flag, GEN data, long prec) GEN bnfisprincipal0(GEN bnf, GEN x, long flall) GEN bnfisunit(GEN bignf, GEN x) GEN bnfnewprec(GEN nf, long prec) GEN bnfnewprec_shallow(GEN nf, long prec) GEN bnrnewprec(GEN bnr, long prec) GEN bnrnewprec_shallow(GEN bnr, long prec) GEN isprincipalfact(GEN bnf, GEN C, GEN L, GEN f, long flag) GEN isprincipalfact_or_fail(GEN bnf, GEN C, GEN P, GEN e) GEN isprincipal(GEN bnf, GEN x) GEN nfcyclotomicunits(GEN nf, GEN zu) GEN nfsign_units(GEN bnf, GEN archp, int add_zu) GEN signunits(GEN bignf) # buch3.c GEN ABC_to_bnr(GEN A, GEN B, GEN C, GEN *H, int gen) GEN Buchray(GEN bnf, GEN module, long flag) GEN bnrautmatrix(GEN bnr, GEN aut) GEN bnrchar(GEN bnr, GEN g, GEN v) GEN bnrchar_primitive(GEN bnr, GEN chi, GEN bnrc) GEN bnrclassno(GEN bignf, GEN ideal) GEN bnrclassno0(GEN A, GEN B, GEN C) GEN bnrclassnolist(GEN bnf, GEN listes) GEN bnrconductor0(GEN A, GEN B, GEN C, long flag) GEN bnrconductor(GEN bnr, GEN H0, long flag) GEN bnrconductor_i(GEN bnr, GEN H0, long flag) GEN bnrconductorofchar(GEN bnr, GEN chi) GEN bnrdisc0(GEN A, GEN B, GEN C, long flag) GEN bnrdisc(GEN bnr, GEN H, long flag) GEN bnrdisclist0(GEN bnf, GEN borne, GEN arch) GEN bnrgaloismatrix(GEN bnr, GEN aut) GEN bnrgaloisapply(GEN bnr, GEN mat, GEN x) GEN bnrinit0(GEN bignf, GEN ideal, long flag) long bnrisconductor0(GEN A, GEN B, GEN C) long bnrisconductor(GEN bnr, GEN H) long bnrisgalois(GEN bnr, GEN M, GEN H) GEN bnrisprincipal(GEN bnf, GEN x, long flag) GEN bnrsurjection(GEN bnr1, GEN bnr2) GEN buchnarrow(GEN bignf) long bnfcertify(GEN bnf) long bnfcertify0(GEN bnf, long flag) GEN decodemodule(GEN nf, GEN fa) GEN discrayabslist(GEN bnf, GEN listes) GEN discrayabslistarch(GEN bnf, GEN arch, ulong bound) GEN discrayabslistlong(GEN bnf, ulong bound) GEN idealmoddivisor(GEN bnr, GEN x) GEN isprincipalray(GEN bnf, GEN x) GEN isprincipalraygen(GEN bnf, GEN x) GEN rnfconductor(GEN bnf, GEN polrel) long rnfisabelian(GEN nf, GEN pol) GEN rnfnormgroup(GEN bnr, GEN polrel) GEN subgrouplist0(GEN bnr, GEN indexbound, long all) # buch4.c GEN bnfisnorm(GEN bnf, GEN x, long flag) GEN rnfisnorm(GEN S, GEN x, long flag) GEN rnfisnorminit(GEN bnf, GEN relpol, int galois) GEN bnfissunit(GEN bnf, GEN suni, GEN x) GEN bnfsunit(GEN bnf, GEN s, long PREC) long nfhilbert(GEN bnf, GEN a, GEN b) long nfhilbert0(GEN bnf, GEN a, GEN b, GEN p) long hyperell_locally_soluble(GEN pol, GEN p) long nf_hyperell_locally_soluble(GEN nf, GEN pol, GEN p) # char.c int char_check(GEN cyc, GEN chi) GEN charconj(GEN cyc, GEN chi) GEN charconj0(GEN cyc, GEN chi) GEN chardiv(GEN x, GEN a, GEN b) GEN chardiv0(GEN x, GEN a, GEN b) GEN chareval(GEN G, GEN chi, GEN n, GEN z) GEN charker(GEN cyc, GEN chi) GEN charker0(GEN cyc, GEN chi) GEN charmul(GEN x, GEN a, GEN b) GEN charmul0(GEN x, GEN a, GEN b) GEN charorder(GEN cyc, GEN x) GEN charorder0(GEN x, GEN chi) GEN char_denormalize(GEN cyc, GEN D, GEN chic) GEN char_normalize(GEN chi, GEN ncyc) GEN char_rootof1(GEN d, long prec) GEN char_rootof1_u(ulong d, long prec) GEN char_simplify(GEN D, GEN C) GEN cyc_normalize(GEN c) int zncharcheck(GEN G, GEN chi) GEN zncharconj(GEN G, GEN chi) GEN znchardiv(GEN G, GEN a, GEN b) GEN zncharker(GEN G, GEN chi) GEN znchareval(GEN G, GEN chi, GEN n, GEN z) GEN zncharinduce(GEN G, GEN chi, GEN N) long zncharisodd(GEN G, GEN chi) GEN zncharmul(GEN G, GEN a, GEN b) GEN zncharorder(GEN G, GEN chi) int znconrey_check(GEN cyc, GEN chi) GEN znconrey_normalized(GEN G, GEN chi) GEN znconreychar(GEN bid, GEN m) GEN znconreyfromchar_normalized(GEN bid, GEN chi) GEN znconreyconductor(GEN bid, GEN co, GEN *pm) GEN znconreyexp(GEN bid, GEN x) GEN znconreyfromchar(GEN bid, GEN chi) GEN znconreylog(GEN bid, GEN x) GEN znconreylog_normalize(GEN G, GEN m) # compile.c GEN closure_deriv(GEN G) long localvars_find(GEN pack, entree *ep) GEN localvars_read_str(const char *str, GEN pack) GEN snm_closure(entree *ep, GEN data) GEN strtoclosure(const char *s, long n, ...) GEN strtofunction(const char *s) # concat.c GEN gconcat(GEN x, GEN y) GEN gconcat1(GEN x) GEN matconcat(GEN v) GEN shallowconcat(GEN x, GEN y) GEN shallowconcat1(GEN x) GEN shallowmatconcat(GEN v) GEN vconcat(GEN A, GEN B) # default.c extern int d_SILENT, d_ACKNOWLEDGE, d_INITRC, d_RETURN GEN default0(const char *a, const char *b) long getrealprecision() entree *pari_is_default(const char *s) GEN sd_TeXstyle(const char *v, long flag) GEN sd_colors(const char *v, long flag) GEN sd_compatible(const char *v, long flag) GEN sd_datadir(const char *v, long flag) GEN sd_debug(const char *v, long flag) GEN sd_debugfiles(const char *v, long flag) GEN sd_debugmem(const char *v, long flag) GEN sd_factor_add_primes(const char *v, long flag) GEN sd_factor_proven(const char *v, long flag) GEN sd_format(const char *v, long flag) GEN sd_histsize(const char *v, long flag) GEN sd_log(const char *v, long flag) GEN sd_logfile(const char *v, long flag) GEN sd_nbthreads(const char *v, long flag) GEN sd_new_galois_format(const char *v, long flag) GEN sd_output(const char *v, long flag) GEN sd_parisize(const char *v, long flag) GEN sd_parisizemax(const char *v, long flag) GEN sd_path(const char *v, long flag) GEN sd_prettyprinter(const char *v, long flag) GEN sd_primelimit(const char *v, long flag) GEN sd_realbitprecision(const char *v, long flag) GEN sd_realprecision(const char *v, long flag) GEN sd_secure(const char *v, long flag) GEN sd_seriesprecision(const char *v, long flag) GEN sd_simplify(const char *v, long flag) GEN sd_sopath(char *v, int flag) GEN sd_strictargs(const char *v, long flag) GEN sd_strictmatch(const char *v, long flag) GEN sd_string(const char *v, long flag, const char *s, char **f) GEN sd_threadsize(const char *v, long flag) GEN sd_threadsizemax(const char *v, long flag) GEN sd_toggle(const char *v, long flag, const char *s, int *ptn) GEN sd_ulong(const char *v, long flag, const char *s, ulong *ptn, ulong Min, ulong Max, const char **msg) GEN setdefault(const char *s, const char *v, long flag) long setrealprecision(long n, long *prec) # gplib.c GEN sd_breakloop(const char *v, long flag) GEN sd_echo(const char *v, long flag) GEN sd_graphcolormap(const char *v, long flag) GEN sd_graphcolors(const char *v, long flag) GEN sd_help(const char *v, long flag) GEN sd_histfile(const char *v, long flag) GEN sd_lines(const char *v, long flag) GEN sd_linewrap(const char *v, long flag) GEN sd_prompt(const char *v, long flag) GEN sd_prompt_cont(const char *v, long flag) GEN sd_psfile(const char *v, long flag) GEN sd_readline(const char *v, long flag) GEN sd_recover(const char *v, long flag) GEN sd_timer(const char *v, long flag) void pari_hit_return() void gp_load_gprc() int gp_meta(const char *buf, int ismain) const char **gphelp_keyword_list() void pari_center(const char *s) void pari_print_version() const char *gp_format_time(long delay) const char *gp_format_prompt(const char *p) void pari_alarm(long s) GEN gp_alarm(long s, GEN code) GEN gp_input() void gp_allocatemem(GEN z) int gp_handle_exception(long numerr) void gp_alarm_handler(int sig) void gp_sigint_fun() extern int h_REGULAR, h_LONG, h_APROPOS, h_RL void gp_help(const char *s, long flag) void gp_echo_and_log(const char *prompt, const char *s) void print_fun_list(char **list, long nbli) # dirichlet.c GEN direxpand(GEN a, long L) GEN direuler(void *E, GEN (*eval)(void *, GEN), GEN a, GEN b, GEN c) # ellanal.c GEN ellanalyticrank(GEN e, GEN eps, long prec) GEN ellanalyticrank_bitprec(GEN e, GEN eps, long bitprec) GEN ellanal_globalred_all(GEN e, GEN *N, GEN *cb, GEN *tam) GEN ellheegner(GEN e) GEN ellL1(GEN E, long r, long prec) GEN ellL1_bitprec(GEN E, long r, long bitprec) # elldata.c GEN ellconvertname(GEN s) GEN elldatagenerators(GEN E) GEN ellidentify(GEN E) GEN ellsearch(GEN A) GEN ellsearchcurve(GEN name) void forell(void *E, long call(void*, GEN), long a, long b, long flag) # ellfromeqn.c GEN ellfromeqn(GEN s) # elliptic.c extern int t_ELL_Rg, t_ELL_Q, t_ELL_Qp, t_ELL_Fp, t_ELL_Fq, t_ELL_NF long ellQ_get_CM(GEN e) int ell_is_integral(GEN E) GEN ellbasechar(GEN E) GEN akell(GEN e, GEN n) GEN anell(GEN e, long n) GEN anellsmall(GEN e, long n) GEN bilhell(GEN e, GEN z1, GEN z2, long prec) void checkell(GEN e) void checkell_Fq(GEN e) void checkell_Q(GEN e) void checkell_Qp(GEN e) void checkellisog(GEN v) void checkellpt(GEN z) void checkell5(GEN e) GEN ec_bmodel(GEN e) GEN ec_f_evalx(GEN E, GEN x) GEN ec_h_evalx(GEN e, GEN x) GEN ec_dFdx_evalQ(GEN E, GEN Q) GEN ec_dFdy_evalQ(GEN E, GEN Q) GEN ec_dmFdy_evalQ(GEN e, GEN Q) GEN ec_2divpol_evalx(GEN E, GEN x) GEN ec_half_deriv_2divpol_evalx(GEN E, GEN x) GEN ellanal_globalred(GEN e, GEN *gr) GEN ellQ_get_N(GEN e) void ellQ_get_Nfa(GEN e, GEN *N, GEN *faN) GEN ellQp_Tate_uniformization(GEN E, long prec) GEN ellQp_u(GEN E, long prec) GEN ellQp_u2(GEN E, long prec) GEN ellQp_q(GEN E, long prec) GEN ellQp_ab(GEN E, long prec) GEN ellQp_root(GEN E, long prec) GEN ellR_ab(GEN E, long prec) GEN ellR_eta(GEN E, long prec) GEN ellR_omega(GEN x, long prec) GEN ellR_roots(GEN E, long prec) GEN elladd(GEN e, GEN z1, GEN z2) GEN ellap(GEN e, GEN p) long ellap_CM_fast(GEN E, ulong p, long CM) GEN ellcard(GEN E, GEN p) GEN ellchangecurve(GEN e, GEN ch) GEN ellchangeinvert(GEN w) GEN ellchangepoint(GEN x, GEN ch) GEN ellchangepointinv(GEN x, GEN ch) GEN elldivpol(GEN e, long n, long v) GEN elleisnum(GEN om, long k, long flag, long prec) GEN elleta(GEN om, long prec) GEN ellff_get_card(GEN E) GEN ellff_get_gens(GEN E) GEN ellff_get_group(GEN E) GEN ellff_get_o(GEN x) GEN ellff_get_p(GEN E) GEN ellfromj(GEN j) GEN ellformaldifferential(GEN e, long n, long v) GEN ellformalexp(GEN e, long n, long v) GEN ellformallog(GEN e, long n, long v) GEN ellformalpoint(GEN e, long n, long v) GEN ellformalw(GEN e, long n, long v) GEN ellgenerators(GEN E) GEN ellglobalred(GEN e1) GEN ellgroup(GEN E, GEN p) GEN ellgroup0(GEN E, GEN p, long flag) GEN ellheight0(GEN e, GEN a, GEN b, long prec) GEN ellheight(GEN e, GEN a, long prec) GEN ellheightmatrix(GEN E, GEN x, long n) GEN ellheightoo(GEN e, GEN z, long prec) GEN ellinit(GEN x, GEN p, long prec) GEN ellintegralmodel(GEN e, GEN *pv) GEN ellisoncurve(GEN e, GEN z) int ellissupersingular(GEN x, GEN p) int elljissupersingular(GEN x) GEN elllseries(GEN e, GEN s, GEN A, long prec) GEN elllocalred(GEN e, GEN p1) GEN elllog(GEN e, GEN a, GEN g, GEN o) GEN ellminimalmodel(GEN E, GEN *ptv) GEN ellminimaltwist(GEN e) GEN ellminimaltwist0(GEN e, long fl) GEN ellminimaltwistcond(GEN e) GEN ellmul(GEN e, GEN z, GEN n) GEN ellnonsingularmultiple(GEN e, GEN P) GEN ellneg(GEN e, GEN z) GEN ellorder(GEN e, GEN p, GEN o) long ellorder_Q(GEN E, GEN P) GEN ellordinate(GEN e, GEN x, long prec) GEN ellpadicfrobenius(GEN E, ulong p, long n) GEN ellpadicheight(GEN e, GEN p, long n, GEN P) GEN ellpadicheight0(GEN e, GEN p, long n, GEN P, GEN Q) GEN ellpadicheightmatrix(GEN e, GEN p, long n, GEN P) GEN ellpadiclog(GEN E, GEN p, long n, GEN P) GEN ellpadics2(GEN E, GEN p, long n) GEN ellperiods(GEN w, long flag, long prec) GEN elltwist(GEN E, GEN D) GEN ellrandom(GEN e) long ellrootno(GEN e, GEN p) long ellrootno_global(GEN e) GEN ellsea(GEN E, ulong smallfact) GEN ellsigma(GEN om, GEN z, long flag, long prec) GEN ellsub(GEN e, GEN z1, GEN z2) GEN elltaniyama(GEN e, long prec) GEN elltatepairing(GEN E, GEN t, GEN s, GEN m) GEN elltors(GEN e) GEN elltors0(GEN e, long flag) GEN ellweilpairing(GEN E, GEN t, GEN s, GEN m) GEN ellwp(GEN w, GEN z, long prec) GEN ellwp0(GEN w, GEN z, long flag, long prec) GEN ellwpseries(GEN e, long v, long PRECDL) GEN ellxn(GEN e, long n, long v) GEN ellzeta(GEN om, GEN z, long prec) GEN expIxy(GEN x, GEN y, long prec) int oncurve(GEN e, GEN z) GEN orderell(GEN e, GEN p) GEN pointell(GEN e, GEN z, long prec) GEN point_to_a4a6(GEN E, GEN P, GEN p, GEN *pa4) GEN point_to_a4a6_Fl(GEN E, GEN P, ulong p, ulong *pa4) GEN zell(GEN e, GEN z, long prec) # elltors.c long ellisdivisible(GEN E, GEN P, GEN n, GEN *Q) # ellisogeny.c GEN ellisogenyapply(GEN f, GEN P) GEN ellisogeny(GEN e, GEN G, long only_image, long vx, long vy) GEN ellisomat(GEN E, long flag) # ellsea.c GEN Fp_ellcard_SEA(GEN a4, GEN a6, GEN p, long early_abort) GEN Fq_ellcard_SEA(GEN a4, GEN a6, GEN q, GEN T, GEN p, long early_abort) GEN ellmodulareqn(long l, long vx, long vy) # es.c GEN externstr(const char *cmd) char *gp_filter(const char *s) GEN gpextern(const char *cmd) void gpsystem(const char *s) GEN readstr(const char *s) GEN GENtoGENstr_nospace(GEN x) GEN GENtoGENstr(GEN x) char* GENtoTeXstr(GEN x) char* GENtostr(GEN x) char* GENtostr_raw(GEN x) char* GENtostr_unquoted(GEN x) GEN Str(GEN g) GEN Strchr(GEN g) GEN Strexpand(GEN g) GEN Strtex(GEN g) void brute(GEN g, char format, long dec) void dbgGEN(GEN x, long nb) void error0(GEN g) void dbg_pari_heap() int file_is_binary(FILE *f) void err_flush() void err_printf(const char* pat, ...) GEN gp_getenv(const char *s) GEN gp_read_file(const char *s) GEN gp_read_str_multiline(const char *s, char *last) GEN gp_read_stream(FILE *f) GEN gp_readvec_file(char *s) GEN gp_readvec_stream(FILE *f) void gpinstall(const char *s, const char *code, const char *gpname, const char *lib) GEN gsprintf(const char *fmt, ...) GEN gvsprintf(const char *fmt, va_list ap) char* itostr(GEN x) void matbrute(GEN g, char format, long dec) char* os_getenv(const char *s) void (*os_signal(int sig, void (*f)(int)))(int) void outmat(GEN x) void output(GEN x) char* RgV_to_str(GEN g, long flag) void pari_add_hist(GEN z, long t) void pari_ask_confirm(const char *s) void pari_fclose(pariFILE *f) void pari_flush() pariFILE* pari_fopen(const char *s, const char *mode) pariFILE* pari_fopen_or_fail(const char *s, const char *mode) pariFILE* pari_fopengz(const char *s) void pari_fprintf(FILE *file, const char *fmt, ...) void pari_fread_chars(void *b, size_t n, FILE *f) GEN pari_get_hist(long p) long pari_get_histtime(long p) char* pari_get_homedir(const char *user) int pari_is_dir(const char *name) int pari_is_file(const char *name) int pari_last_was_newline() void pari_set_last_newline(int last) ulong pari_nb_hist() void pari_printf(const char *fmt, ...) void pari_putc(char c) void pari_puts(const char *s) pariFILE* pari_safefopen(const char *s, const char *mode) char* pari_sprintf(const char *fmt, ...) int pari_stdin_isatty() char* pari_strdup(const char *s) char* pari_strndup(const char *s, long n) char* pari_unique_dir(const char *s) char* pari_unique_filename(const char *s) void pari_unlink(const char *s) void pari_vfprintf(FILE *file, const char *fmt, va_list ap) void pari_vprintf(const char *fmt, va_list ap) char* pari_vsprintf(const char *fmt, va_list ap) char* path_expand(const char *s) void out_print0(PariOUT *out, const char *sep, GEN g, long flag) void out_printf(PariOUT *out, const char *fmt, ...) void out_putc(PariOUT *out, char c) void out_puts(PariOUT *out, const char *s) void out_term_color(PariOUT *out, long c) void out_vprintf(PariOUT *out, const char *fmt, va_list ap) char* pari_sprint0(const char *msg, GEN g, long flag) void print(GEN g) extern int f_RAW, f_PRETTYMAT, f_PRETTY, f_TEX void print0(GEN g, long flag) void print1(GEN g) void printf0(const char *fmt, GEN args) void printsep(const char *s, GEN g) void printsep1(const char *s, GEN g) void printtex(GEN g) char* stack_sprintf(const char *fmt, ...) char* stack_strcat(const char *s, const char *t) char* stack_strdup(const char *s) void strftime_expand(const char *s, char *buf, long max) GEN Strprintf(const char *fmt, GEN args) FILE* switchin(const char *name) void switchout(const char *name) void term_color(long c) char* term_get_color(char *s, long c) void texe(GEN g, char format, long dec) const char* type_name(long t) void warning0(GEN g) void write0(const char *s, GEN g) void write1(const char *s, GEN g) void writebin(const char *name, GEN x) void writetex(const char *s, GEN g) # eval.c extern int br_NONE, br_BREAK, br_NEXT, br_MULTINEXT, br_RETURN void bincopy_relink(GEN C, GEN vi) GEN break0(long n) GEN call0(GEN fun, GEN args) GEN closure_callgen1(GEN C, GEN x) GEN closure_callgen1prec(GEN C, GEN x, long prec) GEN closure_callgen2(GEN C, GEN x, GEN y) GEN closure_callgenall(GEN C, long n, ...) GEN closure_callgenvec(GEN C, GEN args) GEN closure_callgenvecprec(GEN C, GEN args, long prec) void closure_callvoid1(GEN C, GEN x) long closure_context(long start, long level) void closure_disassemble(GEN n) void closure_err(long level) GEN closure_evalbrk(GEN C, long *status) GEN closure_evalgen(GEN C) GEN closure_evalnobrk(GEN C) GEN closure_evalres(GEN C) void closure_evalvoid(GEN C) GEN closure_trapgen(GEN C, long numerr) GEN copybin_unlink(GEN C) GEN get_lex(long vn) long get_localprec() long get_localbitprec() GEN gp_call(void *E, GEN x) GEN gp_callprec(void *E, GEN x, long prec) GEN gp_call2(void *E, GEN x, GEN y) long gp_callbool(void *E, GEN x) long gp_callvoid(void *E, GEN x) GEN gp_eval(void *E, GEN x) long gp_evalbool(void *E, GEN x) GEN gp_evalprec(void *E, GEN x, long prec) GEN gp_evalupto(void *E, GEN x) long gp_evalvoid(void *E, GEN x) void localprec(long p) void localbitprec(long p) long loop_break() GEN next0(long n) GEN pareval(GEN C) GEN pari_self() GEN parsum(GEN a, GEN b, GEN code, GEN x) GEN parvector(long n, GEN code) void pop_lex(long n) void pop_localprec() void push_lex(GEN a, GEN C) void push_localbitprec(long p) void push_localprec(long p) GEN return0(GEN x) void set_lex(long vn, GEN x) # FF.c GEN FF_1(GEN a) GEN FF_Z_Z_muldiv(GEN x, GEN y, GEN z) GEN FF_Q_add(GEN x, GEN y) GEN FF_Z_add(GEN a, GEN b) GEN FF_Z_mul(GEN a, GEN b) GEN FF_add(GEN a, GEN b) GEN FF_charpoly(GEN x) GEN FF_conjvec(GEN x) GEN FF_div(GEN a, GEN b) GEN FF_ellcard(GEN E) GEN FF_ellcard_SEA(GEN E, long smallfact) GEN FF_ellgens(GEN E) GEN FF_ellgroup(GEN E) GEN FF_elllog(GEN E, GEN P, GEN Q, GEN o) GEN FF_ellmul(GEN E, GEN P, GEN n) GEN FF_ellorder(GEN E, GEN P, GEN o) GEN FF_elltwist(GEN E) GEN FF_ellrandom(GEN E) GEN FF_elltatepairing(GEN E, GEN P, GEN Q, GEN m) GEN FF_ellweilpairing(GEN E, GEN P, GEN Q, GEN m) int FF_equal(GEN a, GEN b) int FF_equal0(GEN x) int FF_equal1(GEN x) int FF_equalm1(GEN x) long FF_f(GEN x) GEN FF_inv(GEN a) long FF_issquare(GEN x) long FF_issquareall(GEN x, GEN *pt) long FF_ispower(GEN x, GEN K, GEN *pt) GEN FF_log(GEN a, GEN b, GEN o) GEN FF_minpoly(GEN x) GEN FF_mod(GEN x) GEN FF_mul(GEN a, GEN b) GEN FF_mul2n(GEN a, long n) GEN FF_neg(GEN a) GEN FF_neg_i(GEN a) GEN FF_norm(GEN x) GEN FF_order(GEN x, GEN o) GEN FF_p(GEN x) GEN FF_p_i(GEN x) GEN FF_pow(GEN x, GEN n) GEN FF_primroot(GEN x, GEN *o) GEN FF_q(GEN x) int FF_samefield(GEN x, GEN y) GEN FF_sqr(GEN a) GEN FF_sqrt(GEN a) GEN FF_sqrtn(GEN x, GEN n, GEN *zetan) GEN FF_sub(GEN x, GEN y) GEN FF_to_F2xq(GEN x) GEN FF_to_F2xq_i(GEN x) GEN FF_to_Flxq(GEN x) GEN FF_to_Flxq_i(GEN x) GEN FF_to_FpXQ(GEN x) GEN FF_to_FpXQ_i(GEN x) GEN FF_trace(GEN x) GEN FF_zero(GEN a) GEN FFM_FFC_mul(GEN M, GEN C, GEN ff) GEN FFM_det(GEN M, GEN ff) GEN FFM_image(GEN M, GEN ff) GEN FFM_inv(GEN M, GEN ff) GEN FFM_ker(GEN M, GEN ff) GEN FFM_mul(GEN M, GEN N, GEN ff) long FFM_rank(GEN M, GEN ff) GEN FFX_factor(GEN f, GEN x) GEN FFX_roots(GEN f, GEN x) GEN FqX_to_FFX(GEN x, GEN ff) GEN Fq_to_FF(GEN x, GEN ff) GEN Z_FF_div(GEN a, GEN b) GEN ffgen(GEN T, long v) GEN fflog(GEN x, GEN g, GEN o) GEN fforder(GEN x, GEN o) GEN ffprimroot(GEN x, GEN *o) GEN ffrandom(GEN ff) int Rg_is_FF(GEN c, GEN *ff) int RgC_is_FFC(GEN x, GEN *ff) int RgM_is_FFM(GEN x, GEN *ff) GEN p_to_FF(GEN p, long v) GEN Tp_to_FF(GEN T, GEN p) # galconj.c GEN checkgal(GEN gal) GEN checkgroup(GEN g, GEN *S) GEN embed_disc(GEN r, long r1, long prec) GEN embed_roots(GEN r, long r1) GEN galois_group(GEN gal) GEN galoisconj(GEN nf, GEN d) GEN galoisconj0(GEN nf, long flag, GEN d, long prec) GEN galoisexport(GEN gal, long format) GEN galoisfixedfield(GEN gal, GEN v, long flag, long y) GEN galoisidentify(GEN gal) GEN galoisinit(GEN nf, GEN den) GEN galoisisabelian(GEN gal, long flag) long galoisisnormal(GEN gal, GEN sub) GEN galoispermtopol(GEN gal, GEN perm) GEN galoissubgroups(GEN G) GEN galoissubfields(GEN G, long flag, long v) long numberofconjugates(GEN T, long pdepart) GEN vandermondeinverse(GEN L, GEN T, GEN den, GEN prep) # galpol.c GEN galoisnbpol(long a) GEN galoisgetpol(long a, long b, long s) # gen1.c GEN conjvec(GEN x, long prec) GEN gadd(GEN x, GEN y) GEN gaddsg(long x, GEN y) GEN gconj(GEN x) GEN gdiv(GEN x, GEN y) GEN gdivgs(GEN x, long s) GEN ginv(GEN x) GEN gmul(GEN x, GEN y) GEN gmul2n(GEN x, long n) GEN gmulsg(long s, GEN y) GEN gsqr(GEN x) GEN gsub(GEN x, GEN y) GEN gsubsg(long x, GEN y) GEN inv_ser(GEN b) GEN mulcxI(GEN x) GEN mulcxmI(GEN x) GEN ser_normalize(GEN x) # gen2.c GEN gassoc_proto(GEN f(GEN, GEN), GEN, GEN) GEN map_proto_G(GEN f(GEN), GEN x) GEN map_proto_lG(long f(GEN), GEN x) GEN map_proto_lGL(long f(GEN, long), GEN x, long y) long Q_pval(GEN x, GEN p) long Q_pvalrem(GEN x, GEN p, GEN *y) long RgX_val(GEN x) long RgX_valrem(GEN x, GEN *z) long RgX_valrem_inexact(GEN x, GEN *Z) int ZV_Z_dvd(GEN v, GEN p) long ZV_pval(GEN x, GEN p) long ZV_pvalrem(GEN x, GEN p, GEN *px) long ZV_lval(GEN x, ulong p) long ZV_lvalrem(GEN x, ulong p, GEN *px) long ZX_lvalrem(GEN x, ulong p, GEN *px) long ZX_lval(GEN x, ulong p) long ZX_pval(GEN x, GEN p) long ZX_pvalrem(GEN x, GEN p, GEN *px) long Z_lval(GEN n, ulong p) long Z_lvalrem(GEN n, ulong p, GEN *py) long Z_lvalrem_stop(GEN *n, ulong p, int *stop) long Z_pval(GEN n, GEN p) long Z_pvalrem(GEN x, GEN p, GEN *py) GEN cgetp(GEN x) GEN cvstop2(long s, GEN y) GEN cvtop(GEN x, GEN p, long l) GEN cvtop2(GEN x, GEN y) GEN gabs(GEN x, long prec) void gaffect(GEN x, GEN y) void gaffsg(long s, GEN x) int gcmp(GEN x, GEN y) int gequal0(GEN x) int gequal1(GEN x) int gequalX(GEN x) int gequalm1(GEN x) int gcmpsg(long x, GEN y) GEN gcvtop(GEN x, GEN p, long r) int gequal(GEN x, GEN y) int gequalsg(long s, GEN x) long gexpo(GEN x) GEN gpvaluation(GEN x, GEN p) long gvaluation(GEN x, GEN p) int gidentical(GEN x, GEN y) long glength(GEN x) GEN gmax(GEN x, GEN y) GEN gmaxgs(GEN x, long y) GEN gmin(GEN x, GEN y) GEN gmings(GEN x, long y) GEN gneg(GEN x) GEN gneg_i(GEN x) GEN RgX_to_ser(GEN x, long l) GEN RgX_to_ser_inexact(GEN x, long l) int gsigne(GEN x) GEN gtolist(GEN x) long gtolong(GEN x) int lexcmp(GEN x, GEN y) GEN listcreate_typ(long t) GEN listcreate() GEN listinsert(GEN list, GEN object, long index) void listpop(GEN L, long index) void listpop0(GEN L, long index) GEN listput(GEN list, GEN object, long index) GEN listput0(GEN list, GEN object, long index) void listsort(GEN list, long flag) GEN matsize(GEN x) GEN mklist() GEN mklistcopy(GEN x) GEN normalize(GEN x) GEN normalizepol(GEN x) GEN normalizepol_approx(GEN x, long lx) GEN normalizepol_lg(GEN x, long lx) ulong padic_to_Fl(GEN x, ulong p) GEN padic_to_Fp(GEN x, GEN Y) GEN quadtofp(GEN x, long l) GEN rfrac_to_ser(GEN x, long l) long sizedigit(GEN x) long u_lval(ulong x, ulong p) long u_lvalrem(ulong x, ulong p, ulong *py) long u_lvalrem_stop(ulong *n, ulong p, int *stop) long u_pval(ulong x, GEN p) long u_pvalrem(ulong x, GEN p, ulong *py) long vecindexmax(GEN x) long vecindexmin(GEN x) GEN vecmax0(GEN x, GEN *pv) GEN vecmax(GEN x) GEN vecmin0(GEN x, GEN *pv) GEN vecmin(GEN x) long z_lval(long s, ulong p) long z_lvalrem(long s, ulong p, long *py) long z_pval(long n, GEN p) long z_pvalrem(long n, GEN p, long *py) # gen3.c GEN padic_to_Q(GEN x) GEN padic_to_Q_shallow(GEN x) GEN QpV_to_QV(GEN v) GEN RgM_mulreal(GEN x, GEN y) GEN RgX_cxeval(GEN T, GEN u, GEN ui) GEN RgX_deflate_max(GEN x0, long *m) long RgX_deflate_order(GEN x) long ZX_deflate_order(GEN x) GEN ZX_deflate_max(GEN x, long *m) long RgX_degree(GEN x, long v) GEN RgX_integ(GEN x) GEN bitprecision0(GEN x, long n) GEN ceil_safe(GEN x) GEN ceilr(GEN x) GEN centerlift(GEN x) GEN centerlift0(GEN x, long v) GEN compo(GEN x, long n) GEN deg1pol(GEN x1, GEN x0, long v) GEN deg1pol_shallow(GEN x1, GEN x0, long v) long degree(GEN x) GEN denom(GEN x) GEN deriv(GEN x, long v) GEN derivser(GEN x) GEN diffop(GEN x, GEN v, GEN dv) GEN diffop0(GEN x, GEN v, GEN dv, long n) GEN diviiround(GEN x, GEN y) GEN divrem(GEN x, GEN y, long v) GEN floor_safe(GEN x) GEN gceil(GEN x) GEN gcvtoi(GEN x, long *e) GEN gdeflate(GEN x, long v, long d) GEN gdivent(GEN x, GEN y) GEN gdiventgs(GEN x, long y) GEN gdiventsg(long x, GEN y) GEN gdiventres(GEN x, GEN y) GEN gdivmod(GEN x, GEN y, GEN *pr) GEN gdivround(GEN x, GEN y) int gdvd(GEN x, GEN y) GEN geq(GEN x, GEN y) GEN geval(GEN x) GEN gfloor(GEN x) GEN gtrunc2n(GEN x, long s) GEN gfrac(GEN x) GEN gge(GEN x, GEN y) GEN ggrando(GEN x, long n) GEN ggt(GEN x, GEN y) GEN gimag(GEN x) GEN gisexactzero(GEN g) GEN gle(GEN x, GEN y) GEN glt(GEN x, GEN y) GEN gmod(GEN x, GEN y) GEN gmodgs(GEN x, long y) GEN gmodsg(long x, GEN y) GEN gmodulo(GEN x, GEN y) GEN gmodulsg(long x, GEN y) GEN gmodulss(long x, long y) GEN gne(GEN x, GEN y) GEN gnot(GEN x) GEN gpolvar(GEN y) GEN gppadicprec(GEN x, GEN p) GEN gppoldegree(GEN x, long v) long gprecision(GEN x) GEN gpserprec(GEN x, long v) GEN greal(GEN x) GEN grndtoi(GEN x, long *e) GEN ground(GEN x) GEN gshift(GEN x, long n) GEN gsubst(GEN x, long v, GEN y) GEN gsubstpol(GEN x, GEN v, GEN y) GEN gsubstvec(GEN x, GEN v, GEN y) GEN gtocol(GEN x) GEN gtocol0(GEN x, long n) GEN gtocolrev(GEN x) GEN gtocolrev0(GEN x, long n) GEN gtopoly(GEN x, long v) GEN gtopolyrev(GEN x, long v) GEN gtoser(GEN x, long v, long precdl) GEN gtovec(GEN x) GEN gtovec0(GEN x, long n) GEN gtovecrev(GEN x) GEN gtovecrev0(GEN x, long n) GEN gtovecsmall(GEN x) GEN gtovecsmall0(GEN x, long n) GEN gtrunc(GEN x) long gvar(GEN x) long gvar2(GEN x) GEN hqfeval(GEN q, GEN x) GEN imag_i(GEN x) GEN integ(GEN x, long v) GEN integser(GEN x) GEN inv_ser(GEN b) int iscomplex(GEN x) int isexactzero(GEN g) int isrationalzeroscalar(GEN g) int isinexact(GEN x) int isinexactreal(GEN x) int isint(GEN n, GEN *ptk) int isrationalzero(GEN g) int issmall(GEN n, long *ptk) GEN lift(GEN x) GEN lift0(GEN x, long v) GEN liftall(GEN x) GEN liftall_shallow(GEN x) GEN liftint(GEN x) GEN liftint_shallow(GEN x) GEN liftpol(GEN x) GEN liftpol_shallow(GEN x) GEN mkcoln(long n, ...) GEN mkintn(long n, ...) GEN mkpoln(long n, ...) GEN mkvecn(long n, ...) GEN mkvecsmalln(long n, ...) GEN mulreal(GEN x, GEN y) GEN numer(GEN x) long padicprec(GEN x, GEN p) long padicprec_relative(GEN x) GEN polcoeff0(GEN x, long n, long v) GEN polcoeff_i(GEN x, long n, long v) long poldegree(GEN x, long v) GEN poleval(GEN x, GEN y) GEN pollead(GEN x, long v) long precision(GEN x) GEN precision0(GEN x, long n) GEN qf_apply_RgM(GEN q, GEN M) GEN qf_apply_ZM(GEN q, GEN M) GEN qfbil(GEN x, GEN y, GEN q) GEN qfeval(GEN q, GEN x) GEN qfevalb(GEN q, GEN x, GEN y) GEN qfnorm(GEN x, GEN q) GEN real_i(GEN x) GEN round0(GEN x, GEN *pte) GEN roundr(GEN x) GEN roundr_safe(GEN x) GEN scalarpol(GEN x, long v) GEN scalarpol_shallow(GEN x, long v) GEN scalarser(GEN x, long v, long prec) GEN ser_unscale(GEN P, GEN h) long serprec(GEN x, long v) GEN serreverse(GEN x) GEN sertoser(GEN x, long prec) GEN simplify(GEN x) GEN simplify_shallow(GEN x) GEN tayl(GEN x, long v, long precdl) GEN toser_i(GEN x) GEN trunc0(GEN x, GEN *pte) GEN uu32toi(ulong a, ulong b) GEN vars_sort_inplace(GEN z) GEN vars_to_RgXV(GEN h) GEN variables_vecsmall(GEN x) GEN variables_vec(GEN x) # genus2red.c GEN genus2red(GEN PQ, GEN p) # groupid.c long group_ident(GEN G, GEN S) long group_ident_trans(GEN G, GEN S) # hash.c hashtable *hash_create_ulong(ulong s, long stack) hashtable *hash_create_str(ulong s, long stack) hashtable *hash_create(ulong minsize, ulong (*hash)(void*), int (*eq)(void*, void*), int use_stack) void hash_insert(hashtable *h, void *k, void *v) void hash_insert2(hashtable *h, void *k, void *v, ulong hash) GEN hash_keys(hashtable *h) GEN hash_values(hashtable *h) hashentry *hash_search(hashtable *h, void *k) hashentry *hash_search2(hashtable *h, void *k, ulong hash) hashentry *hash_select(hashtable *h, void *k, void *E, int(*select)(void *, hashentry *)) hashentry *hash_remove(hashtable *h, void *k) hashentry *hash_remove_select(hashtable *h, void *k, void *E, int (*select)(void*, hashentry*)) void hash_destroy(hashtable *h) ulong hash_str(const char *str) ulong hash_str2(const char *s) ulong hash_GEN(GEN x) # hyperell.c GEN hyperellpadicfrobenius(GEN x, ulong p, long e) GEN hyperellcharpoly(GEN x) GEN nfhyperellpadicfrobenius(GEN H, GEN T, ulong p, long n) # hnf_snf.c GEN RgM_hnfall(GEN A, GEN *pB, long remove) GEN ZM_hnf(GEN x) GEN ZM_hnfall(GEN A, GEN *ptB, long remove) GEN ZM_hnfcenter(GEN M) GEN ZM_hnflll(GEN A, GEN *ptB, int remove) GEN ZV_extgcd(GEN A) GEN ZV_snfall(GEN D, GEN *pU, GEN *pV) GEN ZV_snf_group(GEN d, GEN *newU, GEN *newUi) GEN ZM_hnfmod(GEN x, GEN d) GEN ZM_hnfmodall(GEN x, GEN dm, long flag) GEN ZM_hnfmodid(GEN x, GEN d) GEN ZM_hnfperm(GEN A, GEN *ptU, GEN *ptperm) void ZM_snfclean(GEN d, GEN u, GEN v) GEN ZM_snf(GEN x) GEN ZM_snf_group(GEN H, GEN *newU, GEN *newUi) GEN ZM_snfall(GEN x, GEN *ptU, GEN *ptV) GEN ZM_snfall_i(GEN x, GEN *ptU, GEN *ptV, int return_vec) GEN zlm_echelon(GEN x, long early_abort, ulong p, ulong pm) GEN ZpM_echelon(GEN x, long early_abort, GEN p, GEN pm) GEN gsmith(GEN x) GEN gsmithall(GEN x) GEN hnf(GEN x) GEN hnf_divscale(GEN A, GEN B, GEN t) GEN hnf_solve(GEN A, GEN B) GEN hnf_invimage(GEN A, GEN b) GEN hnfall(GEN x) int hnfdivide(GEN A, GEN B) GEN hnflll(GEN x) GEN hnfmerge_get_1(GEN A, GEN B) GEN hnfmod(GEN x, GEN d) GEN hnfmodid(GEN x, GEN p) GEN hnfperm(GEN x) GEN matfrobenius(GEN M, long flag, long v) GEN mathnf0(GEN x, long flag) GEN matsnf0(GEN x, long flag) GEN smith(GEN x) GEN smithall(GEN x) GEN smithclean(GEN z) # ifactor1.c GEN Z_factor(GEN n) GEN Z_factor_limit(GEN n, ulong all) GEN Z_factor_until(GEN n, GEN limit) long Z_issmooth(GEN m, ulong lim) GEN Z_issmooth_fact(GEN m, ulong lim) long Z_issquarefree(GEN x) GEN absi_factor(GEN n) GEN absi_factor_limit(GEN n, ulong all) long bigomega(GEN n) long bigomegau(ulong n) GEN core(GEN n) ulong coreu(ulong n) GEN eulerphi(GEN n) ulong eulerphiu(ulong n) ulong eulerphiu_fact(GEN f) GEN factorint(GEN n, long flag) GEN factoru(ulong n) int ifac_isprime(GEN x) int ifac_next(GEN *part, GEN *p, long *e) int ifac_read(GEN part, GEN *p, long *e) void ifac_skip(GEN part) GEN ifac_start(GEN n, int moebius) int is_357_power(GEN x, GEN *pt, ulong *mask) int is_pth_power(GEN x, GEN *pt, forprime_t *T, ulong cutoffbits) long ispowerful(GEN n) long issquarefree(GEN x) long istotient(GEN n, GEN *px) long moebius(GEN n) long moebiusu(ulong n) GEN nextprime(GEN n) GEN numdiv(GEN n) long omega(GEN n) long omegau(ulong n) GEN precprime(GEN n) GEN sumdiv(GEN n) GEN sumdivk(GEN n, long k) ulong tridiv_bound(GEN n) int uis_357_power(ulong x, ulong *pt, ulong *mask) int uis_357_powermod(ulong x, ulong *mask) long uissquarefree(ulong n) long uissquarefree_fact(GEN f) ulong unextprime(ulong n) ulong uprecprime(ulong n) GEN usumdivkvec(ulong n, GEN K) # init.c long timer_delay(pari_timer *T) long timer_get(pari_timer *T) void timer_start(pari_timer *T) int chk_gerepileupto(GEN x) GENbin* copy_bin(GEN x) GENbin* copy_bin_canon(GEN x) void dbg_gerepile(pari_sp av) void dbg_gerepileupto(GEN q) GEN errname(GEN err) GEN gclone(GEN x) GEN gcloneref(GEN x) void gclone_refc(GEN x) GEN gcopy(GEN x) GEN gcopy_avma(GEN x, pari_sp *AVMA) GEN gcopy_lg(GEN x, long lx) GEN gerepile(pari_sp ltop, pari_sp lbot, GEN q) void gerepileallsp(pari_sp av, pari_sp tetpil, int n, ...) void gerepilecoeffssp(pari_sp av, pari_sp tetpil, long *g, int n) void gerepilemanysp(pari_sp av, pari_sp tetpil, GEN* g[], int n) GEN getheap() void gp_context_save(gp_context* rec) void gp_context_restore(gp_context* rec) long gsizeword(GEN x) long gsizebyte(GEN x) void gunclone(GEN x) void gunclone_deep(GEN x) GEN listcopy(GEN x) void timer_printf(pari_timer *T, const char *format, ...) void msgtimer(const char *format, ...) long name_numerr(const char *s) void new_chunk_resize(size_t x) GEN newblock(size_t n) const char * numerr_name(long errnum) GEN obj_check(GEN S, long K) GEN obj_checkbuild(GEN S, long tag, GEN (*build)(GEN)) GEN obj_checkbuild_padicprec(GEN S, long tag, GEN (*build)(GEN, long), long prec) GEN obj_checkbuild_realprec(GEN S, long tag, GEN (*build)(GEN, long), long prec) GEN obj_checkbuild_prec(GEN S, long tag, GEN (*build)(GEN, long), long (*pr)(GEN), long prec) void obj_free(GEN S) GEN obj_init(long d, long n) GEN obj_insert(GEN S, long K, GEN O) GEN obj_insert_shallow(GEN S, long K, GEN O) void pari_add_function(entree *ep) void pari_add_module(entree *ep) void pari_add_defaults_module(entree *ep) void pari_close() void pari_close_opts(ulong init_opts) GEN pari_compile_str(const char *lex) int pari_daemon() void pari_err(int numerr, ...) GEN pari_err_last() char * pari_err2str(GEN err) void pari_init_opts(size_t parisize, ulong maxprime, ulong init_opts) void pari_init(size_t parisize, ulong maxprime) void pari_stackcheck_init(void *pari_stack_base) void pari_sighandler(int sig) void pari_sig_init(void (*f)(int)) void pari_thread_alloc(pari_thread *t, size_t s, GEN arg) void pari_thread_close() void pari_thread_free(pari_thread *t) void pari_thread_init() GEN pari_thread_start(pari_thread *t) void pari_thread_valloc(pari_thread *t, size_t s, size_t v, GEN arg) GEN pari_version() void pari_warn(int numerr, ...) void paristack_newrsize(ulong newsize) void paristack_resize(ulong newsize) void paristack_setsize(size_t rsize, size_t vsize) void parivstack_resize(ulong newsize) void parivstack_reset() GEN trap0(const char *e, GEN f, GEN r) void shiftaddress(GEN x, long dec) void shiftaddress_canon(GEN x, long dec) long timer() long timer2() void traverseheap( void(*f)(GEN, void *), void *data ) # intnum.c GEN contfraceval(GEN CF, GEN t, long nlim) GEN contfracinit(GEN M, long lim) GEN intcirc(void *E, GEN (*eval) (void *, GEN), GEN a, GEN R, GEN tab, long prec) GEN intfuncinit(void *E, GEN (*eval) (void *, GEN), GEN a, GEN b, long m, long prec) GEN intnum(void *E, GEN (*eval) (void *, GEN), GEN a, GEN b, GEN tab, long prec) GEN intnumgauss(void *E, GEN (*eval)(void*, GEN), GEN a, GEN b, GEN tab, long prec) GEN intnumgaussinit(long n, long prec) GEN intnuminit(GEN a, GEN b, long m, long prec) GEN intnumromb(void *E, GEN (*eval)(void *, GEN), GEN a, GEN b, long flag, long prec) GEN intnumromb_bitprec(void *E, GEN (*eval)(void *, GEN), GEN a, GEN b, long flag, long bit) GEN sumnum(void *E, GEN (*eval)(void*, GEN), GEN a, GEN tab, long prec) GEN sumnuminit(GEN fast, long prec) GEN sumnummonien(void *E, GEN (*eval)(void*, GEN), GEN a, GEN tab, long prec) GEN sumnummonieninit(GEN asymp, GEN w, GEN n0, long prec) # krasner.c GEN padicfields0(GEN p, GEN n, long flag) GEN padicfields(GEN p, long m, long d, long flag) # kummer.c GEN rnfkummer(GEN bnr, GEN subgroup, long all, long prec) # lfun.c long is_linit(GEN data) GEN ldata_get_an(GEN ldata) GEN ldata_get_dual(GEN ldata) GEN ldata_get_gammavec(GEN ldata) long ldata_get_degree(GEN ldata) long ldata_get_k(GEN ldata) GEN ldata_get_conductor(GEN ldata) GEN ldata_get_rootno(GEN ldata) GEN ldata_get_residue(GEN ldata) long ldata_get_type(GEN ldata) long ldata_isreal(GEN ldata) GEN ldata_vecan(GEN ldata, long L, long prec) long linit_get_type(GEN linit) GEN linit_get_ldata(GEN linit) GEN linit_get_tech(GEN linit) GEN lfun_get_domain(GEN tech) GEN lfun_get_dom(GEN tech) long lfun_get_bitprec(GEN tech) GEN lfun_get_factgammavec(GEN tech) GEN lfun_get_step(GEN tech) GEN lfun_get_pol(GEN tech) GEN lfun_get_Residue(GEN tech) GEN lfun_get_k2(GEN tech) GEN lfun_get_w2(GEN tech) GEN lfun_get_expot(GEN tech) long lfun_get_der(GEN tech) long lfun_get_bitprec(GEN tech) GEN lfun(GEN ldata, GEN s, long bitprec) GEN lfun0(GEN ldata, GEN s, long der, long bitprec) long lfuncheckfeq(GEN data, GEN t0, long bitprec) GEN lfunconductor(GEN data, GEN maxcond, long flag, long bitprec) GEN lfuncost(GEN lmisc, GEN dom, long der, long bitprec) GEN lfuncost0(GEN L, GEN dom, long der, long bitprec) GEN lfuncreate(GEN obj) GEN lfunan(GEN ldata, long L, long prec) GEN lfunhardy(GEN ldata, GEN t, long bitprec) GEN lfuninit(GEN ldata, GEN dom, long der, long bitprec) GEN lfuninit0(GEN ldata, GEN dom, long der, long bitprec) GEN lfuninit_make(long t, GEN ldata, GEN molin, GEN domain) long lfunisvgaell(GEN Vga, long flag) GEN lfunlambda(GEN ldata, GEN s, long bitprec) GEN lfunlambda0(GEN ldata, GEN s, long der, long bitprec) GEN lfunmisc_to_ldata(GEN ldata) GEN lfunmisc_to_ldata_shallow(GEN ldata) long lfunorderzero(GEN ldata, long m, long bitprec) GEN lfunprod_get_fact(GEN tech) GEN lfunrootno(GEN data, long bitprec) GEN lfunrootres(GEN data, long bitprec) GEN lfunrtopoles(GEN r) GEN lfuntheta(GEN data, GEN t, long m, long bitprec) long lfunthetacost0(GEN L, GEN tdom, long m, long bitprec) long lfunthetacost(GEN ldata, GEN tdom, long m, long bitprec) GEN lfunthetainit(GEN ldata, GEN tdom, long m, long bitprec) GEN lfunthetacheckinit(GEN data, GEN tinf, long m, long *ptbitprec, long fl) GEN lfunzeros(GEN ldata, GEN lim, long divz, long bitprec) int sdomain_isincl(long k, GEN dom, GEN dom0) GEN theta_get_an(GEN tdata) GEN theta_get_K(GEN tdata) GEN theta_get_R(GEN tdata) long theta_get_bitprec(GEN tdata) long theta_get_m(GEN tdata) GEN theta_get_tdom(GEN tdata) GEN theta_get_sqrtN(GEN tdata) # lfunutils.c GEN dirzetak(GEN nf, GEN b) GEN ellmoddegree(GEN e, long bitprec) GEN lfunabelianrelinit(GEN bnfabs, GEN bnf, GEN polrel, GEN dom, long der, long bitprec) GEN lfunartin(GEN N, GEN G, GEN M, long o) GEN lfundiv(GEN ldata1, GEN ldata2, long bitprec) GEN lfunellmfpeters(GEN E, long bitprec) GEN lfunetaquo(GEN eta) GEN lfungenus2(GEN PS) GEN lfunmfspec(GEN lmisc, long bitprec) GEN lfunmfpeters(GEN ldata, long bitprec) GEN lfunmul(GEN ldata1, GEN ldata2, long bitprec) GEN lfunqf(GEN ldata, long prec) GEN lfunsymsq(GEN ldata, GEN known, long prec) GEN lfunsymsqspec(GEN lmisc, long bitprec) GEN lfunzetakinit(GEN pol, GEN dom, long der, long flag, long bitprec) # lll.c GEN ZM_lll_norms(GEN x, double D, long flag, GEN *B) GEN kerint(GEN x) GEN lll(GEN x) GEN lllfp(GEN x, double D, long flag) GEN lllgen(GEN x) GEN lllgram(GEN x) GEN lllgramgen(GEN x) GEN lllgramint(GEN x) GEN lllgramkerim(GEN x) GEN lllgramkerimgen(GEN x) GEN lllint(GEN x) GEN lllintpartial(GEN mat) GEN lllintpartial_inplace(GEN mat) GEN lllkerim(GEN x) GEN lllkerimgen(GEN x) GEN matkerint0(GEN x, long flag) GEN qflll0(GEN x, long flag) GEN qflllgram0(GEN x, long flag) # map.c GEN gtomap(GEN M) void mapdelete(GEN T, GEN a) GEN mapdomain(GEN T) GEN mapdomain_shallow(GEN T) GEN mapget(GEN T, GEN a) int mapisdefined(GEN T, GEN a, GEN *pt_z) void mapput(GEN T, GEN a, GEN b) GEN maptomat(GEN T) GEN maptomat_shallow(GEN T) # mellininv.c double dbllambertW0(double a) double dbllambertW_1(double a) double dbllemma526(double a, double b, double c, double B) double dblcoro526(double a, double c, double B) GEN gammamellininv(GEN Vga, GEN s, long m, long bitprec) GEN gammamellininvasymp(GEN Vga, long nlimmax, long m) GEN gammamellininvinit(GEN Vga, long m, long bitprec) GEN gammamellininvrt(GEN K, GEN s, long bitprec) # members.c GEN member_a1(GEN x) GEN member_a2(GEN x) GEN member_a3(GEN x) GEN member_a4(GEN x) GEN member_a6(GEN x) GEN member_area(GEN x) GEN member_b2(GEN x) GEN member_b4(GEN x) GEN member_b6(GEN x) GEN member_b8(GEN x) GEN member_bid(GEN x) GEN member_bnf(GEN x) GEN member_c4(GEN x) GEN member_c6(GEN x) GEN member_clgp(GEN x) GEN member_codiff(GEN x) GEN member_cyc(GEN clg) GEN member_diff(GEN x) GEN member_disc(GEN x) GEN member_e(GEN x) GEN member_eta(GEN x) GEN member_f(GEN x) GEN member_fu(GEN x) GEN member_futu(GEN x) GEN member_gen(GEN x) GEN member_group(GEN x) GEN member_index(GEN x) GEN member_j(GEN x) GEN member_mod(GEN x) GEN member_nf(GEN x) GEN member_no(GEN clg) GEN member_omega(GEN x) GEN member_orders(GEN x) GEN member_p(GEN x) GEN member_pol(GEN x) GEN member_polabs(GEN x) GEN member_reg(GEN x) GEN member_r1(GEN x) GEN member_r2(GEN x) GEN member_roots(GEN x) GEN member_sign(GEN x) GEN member_t2(GEN x) GEN member_tate(GEN x) GEN member_tufu(GEN x) GEN member_tu(GEN x) GEN member_zk(GEN x) GEN member_zkst(GEN bid) # mp.c GEN addmulii(GEN x, GEN y, GEN z) GEN addmulii_inplace(GEN x, GEN y, GEN z) ulong Fl_inv(ulong x, ulong p) ulong Fl_invgen(ulong x, ulong p, ulong *pg) ulong Fl_invsafe(ulong x, ulong p) int Fp_ratlift(GEN x, GEN m, GEN amax, GEN bmax, GEN *a, GEN *b) int absi_cmp(GEN x, GEN y) int absi_equal(GEN x, GEN y) int absr_cmp(GEN x, GEN y) GEN addii_sign(GEN x, long sx, GEN y, long sy) GEN addir_sign(GEN x, long sx, GEN y, long sy) GEN addrr_sign(GEN x, long sx, GEN y, long sy) GEN addsi_sign(long x, GEN y, long sy) GEN addui_sign(ulong x, GEN y, long sy) GEN addsr(long x, GEN y) GEN addumului(ulong a, ulong b, GEN Y) void affir(GEN x, GEN y) void affrr(GEN x, GEN y) GEN bezout(GEN a, GEN b, GEN *u, GEN *v) long cbezout(long a, long b, long *uu, long *vv) GEN cbrtr_abs(GEN x) int cmpii(GEN x, GEN y) int cmprr(GEN x, GEN y) long dblexpo(double x) ulong dblmantissa(double x) GEN dbltor(double x) GEN diviiexact(GEN x, GEN y) GEN divir(GEN x, GEN y) GEN divis(GEN y, long x) GEN divis_rem(GEN x, long y, long *rem) GEN diviu_rem(GEN y, ulong x, ulong *rem) GEN diviuuexact(GEN x, ulong y, ulong z) GEN diviuexact(GEN x, ulong y) GEN divri(GEN x, GEN y) GEN divrr(GEN x, GEN y) GEN divrs(GEN x, long y) GEN divru(GEN x, ulong y) GEN divsi(long x, GEN y) GEN divsr(long x, GEN y) GEN divur(ulong x, GEN y) GEN dvmdii(GEN x, GEN y, GEN *z) int equalii(GEN x, GEN y) int equalrr(GEN x, GEN y) GEN floorr(GEN x) GEN gcdii(GEN x, GEN y) GEN int2n(long n) GEN int2u(ulong n) GEN int_normalize(GEN x, long known_zero_words) int invmod(GEN a, GEN b, GEN *res) ulong invmod2BIL(ulong b) GEN invr(GEN b) GEN mantissa_real(GEN x, long *e) GEN modii(GEN x, GEN y) void modiiz(GEN x, GEN y, GEN z) GEN mulii(GEN x, GEN y) GEN mulir(GEN x, GEN y) GEN mulrr(GEN x, GEN y) GEN mulsi(long x, GEN y) GEN mulsr(long x, GEN y) GEN mulss(long x, long y) GEN mului(ulong x, GEN y) GEN mulur(ulong x, GEN y) GEN muluu(ulong x, ulong y) GEN muluui(ulong x, ulong y, GEN z) GEN remi2n(GEN x, long n) double rtodbl(GEN x) GEN shifti(GEN x, long n) GEN sqri(GEN x) GEN sqrr(GEN x) GEN sqrs(long x) GEN sqrtr_abs(GEN x) GEN sqrtremi(GEN S, GEN *R) GEN sqru(ulong x) GEN subsr(long x, GEN y) GEN truedvmdii(GEN x, GEN y, GEN *z) GEN truedvmdis(GEN x, long y, GEN *z) GEN truedvmdsi(long x, GEN y, GEN *z) GEN trunc2nr(GEN x, long n) GEN mantissa2nr(GEN x, long n) GEN truncr(GEN x) ulong umodiu(GEN y, ulong x) long vals(ulong x) # nffactor.c GEN FpC_ratlift(GEN P, GEN mod, GEN amax, GEN bmax, GEN denom) GEN FpM_ratlift(GEN M, GEN mod, GEN amax, GEN bmax, GEN denom) GEN FpX_ratlift(GEN P, GEN mod, GEN amax, GEN bmax, GEN denom) GEN nffactor(GEN nf, GEN x) GEN nffactormod(GEN nf, GEN pol, GEN pr) GEN nfgcd(GEN P, GEN Q, GEN nf, GEN den) GEN nfgcd_all(GEN P, GEN Q, GEN T, GEN den, GEN *Pnew) int nfissquarefree(GEN nf, GEN x) GEN nfroots(GEN nf, GEN pol) GEN polfnf(GEN a, GEN t) GEN rootsof1(GEN x) GEN rootsof1_kannan(GEN nf) # paricfg.c extern const char *paricfg_datadir extern const char *paricfg_version extern const char *paricfg_buildinfo extern const long paricfg_version_code extern const char *paricfg_vcsversion extern const char *paricfg_compiledate extern const char *paricfg_mt_engine # part.c void forpart(void *E, long call(void*, GEN), long k, GEN nbound, GEN abound) void forpart_init(forpart_t *T, long k, GEN abound, GEN nbound) GEN forpart_next(forpart_t *T) GEN forpart_prev(forpart_t *T) GEN numbpart(GEN x) GEN partitions(long k, GEN nbound, GEN abound) # perm.c GEN abelian_group(GEN G) GEN cyclicgroup(GEN g, long s) GEN cyc_pow(GEN cyc, long exp) GEN cyc_pow_perm(GEN cyc, long exp) GEN dicyclicgroup(GEN g1, GEN g2, long s1, long s2) GEN group_abelianHNF(GEN G, GEN L) GEN group_abelianSNF(GEN G, GEN L) long group_domain(GEN G) GEN group_elts(GEN G, long n) GEN group_export(GEN G, long format) long group_isA4S4(GEN G) long group_isabelian(GEN G) GEN group_leftcoset(GEN G, GEN g) long group_order(GEN G) long group_perm_normalize(GEN N, GEN g) GEN group_quotient(GEN G, GEN H) GEN group_rightcoset(GEN G, GEN g) GEN group_set(GEN G, long n) long group_subgroup_isnormal(GEN G, GEN H) GEN group_subgroups(GEN G) GEN groupelts_abelian_group(GEN S) GEN groupelts_center(GEN S) GEN groupelts_set(GEN G, long n) int perm_commute(GEN p, GEN q) GEN perm_cycles(GEN v) long perm_order(GEN perm) GEN perm_pow(GEN perm, long exp) GEN quotient_group(GEN C, GEN G) GEN quotient_perm(GEN C, GEN p) GEN quotient_subgroup_lift(GEN C, GEN H, GEN S) GEN subgroups_tableset(GEN S, long n) long tableset_find_index(GEN tbl, GEN set) GEN trivialgroup() GEN vecperm_orbits(GEN v, long n) GEN vec_insert(GEN v, long n, GEN x) int vec_is1to1(GEN v) int vec_isconst(GEN v) long vecsmall_duplicate(GEN x) long vecsmall_duplicate_sorted(GEN x) GEN vecsmall_indexsort(GEN V) void vecsmall_sort(GEN V) GEN vecsmall_uniq(GEN V) GEN vecsmall_uniq_sorted(GEN V) GEN vecvecsmall_indexsort(GEN x) long vecvecsmall_search(GEN x, GEN y, long flag) GEN vecvecsmall_sort(GEN x) GEN vecvecsmall_sort_uniq(GEN x) # mt.c void mt_broadcast(GEN code) void mt_sigint_block() void mt_sigint_unblock() void mt_queue_end(pari_mt *pt) GEN mt_queue_get(pari_mt *pt, long *jobid, long *pending) void mt_queue_start(pari_mt *pt, GEN worker) void mt_queue_submit(pari_mt *pt, long jobid, GEN work) void pari_mt_init() void pari_mt_close() # plotport.c void color_to_rgb(GEN c, int *r, int *g, int *b) void colorname_to_rgb(const char *s, int *r, int *g, int *b) void pari_plot_by_file(const char *env, const char *suf, const char *img) void pari_set_plot_engine(void (*plot)(PARI_plot *)) void pari_kill_plot_engine() void plotbox(long ne, GEN gx2, GEN gy2) void plotclip(long rect) void plotcolor(long ne, long color) void plotcopy(long source, long dest, GEN xoff, GEN yoff, long flag) GEN plotcursor(long ne) void plotdraw(GEN list, long flag) GEN ploth(void *E, GEN(*f)(void*, GEN), GEN a, GEN b, long flags, long n, long prec) GEN plothraw(GEN listx, GEN listy, long flag) GEN plothsizes(long flag) void plotinit(long ne, GEN x, GEN y, long flag) void plotkill(long ne) void plotline(long ne, GEN gx2, GEN gy2) void plotlines(long ne, GEN listx, GEN listy, long flag) void plotlinetype(long ne, long t) void plotmove(long ne, GEN x, GEN y) void plotpoints(long ne, GEN listx, GEN listy) void plotpointsize(long ne, GEN size) void plotpointtype(long ne, long t) void plotrbox(long ne, GEN x2, GEN y2) GEN plotrecth(void *E, GEN(*f)(void*, GEN), long ne, GEN a, GEN b, ulong flags, long n, long prec) GEN plotrecthraw(long ne, GEN data, long flags) void plotrline(long ne, GEN x2, GEN y2) void plotrmove(long ne, GEN x, GEN y) void plotrpoint(long ne, GEN x, GEN y) void plotscale(long ne, GEN x1, GEN x2, GEN y1, GEN y2) void plotstring(long ne, char *x, long dir) void psdraw(GEN list, long flag) GEN psploth(void *E, GEN(*f)(void*, GEN), GEN a, GEN b, long flags, long n, long prec) GEN psplothraw(GEN listx, GEN listy, long flag) char* rect2ps(GEN w, GEN x, GEN y, PARI_plot *T) char* rect2ps_i(GEN w, GEN x, GEN y, PARI_plot *T, int plotps) char* rect2svg(GEN w, GEN x, GEN y, PARI_plot *T) # polarit1.c GEN ZX_Zp_root(GEN f, GEN a, GEN p, long prec) GEN Zp_appr(GEN f, GEN a) GEN factorpadic(GEN x, GEN p, long r) GEN gdeuc(GEN x, GEN y) GEN grem(GEN x, GEN y) GEN padicappr(GEN f, GEN a) GEN poldivrem(GEN x, GEN y, GEN *pr) GEN rootpadic(GEN f, GEN p, long r) # polarit2.c GEN FpV_factorback(GEN L, GEN e, GEN p) GEN Q_content(GEN x) GEN Q_denom(GEN x) GEN Q_div_to_int(GEN x, GEN c) GEN Q_gcd(GEN x, GEN y) GEN Q_mul_to_int(GEN x, GEN c) GEN Q_muli_to_int(GEN x, GEN d) GEN Q_primitive_part(GEN x, GEN *ptc) GEN Q_primpart(GEN x) GEN Q_remove_denom(GEN x, GEN *ptd) GEN RgXQ_charpoly(GEN x, GEN T, long v) GEN RgXQ_inv(GEN x, GEN y) GEN RgX_disc(GEN x) GEN RgX_extgcd(GEN x, GEN y, GEN *U, GEN *V) GEN RgX_extgcd_simple(GEN a, GEN b, GEN *pu, GEN *pv) GEN RgX_gcd(GEN x, GEN y) GEN RgX_gcd_simple(GEN x, GEN y) int RgXQ_ratlift(GEN y, GEN x, long amax, long bmax, GEN *P, GEN *Q) GEN RgX_resultant_all(GEN P, GEN Q, GEN *sol) long RgX_sturmpart(GEN x, GEN ab) long RgX_type(GEN x, GEN *ptp, GEN *ptpol, long *ptpa) void RgX_type_decode(long x, long *t1, long *t2) int RgX_type_is_composite(long t) GEN ZX_content(GEN x) GEN centermod(GEN x, GEN p) GEN centermod_i(GEN x, GEN p, GEN ps2) GEN centermodii(GEN x, GEN p, GEN po2) GEN content(GEN x) GEN deg1_from_roots(GEN L, long v) GEN factor(GEN x) GEN factor0(GEN x, long flag) GEN factorback(GEN fa) GEN factorback2(GEN fa, GEN e) GEN famat_mul_shallow(GEN f, GEN g) GEN gbezout(GEN x, GEN y, GEN *u, GEN *v) GEN gdivexact(GEN x, GEN y) GEN gen_factorback(GEN L, GEN e, GEN (*_mul)(void*, GEN, GEN), GEN (*_pow)(void*, GEN, GEN), void *data) GEN ggcd(GEN x, GEN y) GEN ggcd0(GEN x, GEN y) GEN ginvmod(GEN x, GEN y) GEN glcm(GEN x, GEN y) GEN glcm0(GEN x, GEN y) GEN gp_factor0(GEN x, GEN flag) GEN idealfactorback(GEN nf, GEN L, GEN e, int red) long isirreducible(GEN x) GEN newtonpoly(GEN x, GEN p) GEN nffactorback(GEN nf, GEN L, GEN e) GEN nfrootsQ(GEN x) GEN poldisc0(GEN x, long v) GEN polresultant0(GEN x, GEN y, long v, long flag) GEN polsym(GEN x, long n) GEN primitive_part(GEN x, GEN *c) GEN primpart(GEN x) GEN reduceddiscsmith(GEN pol) GEN resultant2(GEN x, GEN y) GEN resultant_all(GEN u, GEN v, GEN *sol) GEN rnfcharpoly(GEN nf, GEN T, GEN alpha, long v) GEN roots_from_deg1(GEN x) GEN roots_to_pol(GEN a, long v) GEN roots_to_pol_r1(GEN a, long v, long r1) long sturmpart(GEN x, GEN a, GEN b) GEN subresext(GEN x, GEN y, GEN *U, GEN *V) GEN sylvestermatrix(GEN x, GEN y) GEN trivial_fact() GEN gcdext0(GEN x, GEN y) GEN polresultantext0(GEN x, GEN y, long v) GEN polresultantext(GEN x, GEN y) GEN prime_fact(GEN x) # polarit3.c GEN Flx_FlxY_resultant(GEN a, GEN b, ulong pp) GEN Flx_factorff_irred(GEN P, GEN Q, ulong p) void Flx_ffintersect(GEN P, GEN Q, long n, ulong l, GEN *SP, GEN *SQ, GEN MA, GEN MB) GEN Flx_ffisom(GEN P, GEN Q, ulong l) GEN Flx_roots_naive(GEN f, ulong p) GEN FlxX_resultant(GEN u, GEN v, ulong p, long sx) GEN Flxq_ffisom_inv(GEN S, GEN Tp, ulong p) GEN FpX_FpXY_resultant(GEN a, GEN b0, GEN p) GEN FpX_factorff_irred(GEN P, GEN Q, GEN p) void FpX_ffintersect(GEN P, GEN Q, long n, GEN l, GEN *SP, GEN *SQ, GEN MA, GEN MB) GEN FpX_ffisom(GEN P, GEN Q, GEN l) GEN FpX_translate(GEN P, GEN c, GEN p) GEN FpXQ_ffisom_inv(GEN S, GEN Tp, GEN p) GEN FpXQX_normalize(GEN z, GEN T, GEN p) GEN FpXV_FpC_mul(GEN V, GEN W, GEN p) GEN FpXY_Fq_evaly(GEN Q, GEN y, GEN T, GEN p, long vx) GEN Fq_Fp_mul(GEN x, GEN y, GEN T, GEN p) GEN Fq_add(GEN x, GEN y, GEN T, GEN p) GEN Fq_div(GEN x, GEN y, GEN T, GEN p) GEN Fq_halve(GEN x, GEN T, GEN p) GEN Fq_inv(GEN x, GEN T, GEN p) GEN Fq_invsafe(GEN x, GEN T, GEN p) GEN Fq_mul(GEN x, GEN y, GEN T, GEN p) GEN Fq_mulu(GEN x, ulong y, GEN T, GEN p) GEN Fq_neg(GEN x, GEN T, GEN p) GEN Fq_neg_inv(GEN x, GEN T, GEN p) GEN Fq_pow(GEN x, GEN n, GEN T, GEN p) GEN Fq_powu(GEN x, ulong n, GEN pol, GEN p) GEN Fq_sub(GEN x, GEN y, GEN T, GEN p) GEN Fq_sqr(GEN x, GEN T, GEN p) GEN Fq_sqrt(GEN x, GEN T, GEN p) GEN Fq_sqrtn(GEN x, GEN n, GEN T, GEN p, GEN *zeta) GEN FqC_add(GEN x, GEN y, GEN T, GEN p) GEN FqC_sub(GEN x, GEN y, GEN T, GEN p) GEN FqC_Fq_mul(GEN x, GEN y, GEN T, GEN p) GEN FqC_to_FlxC(GEN v, GEN T, GEN pp) GEN FqM_to_FlxM(GEN x, GEN T, GEN pp) GEN FqV_roots_to_pol(GEN V, GEN T, GEN p, long v) GEN FqV_red(GEN z, GEN T, GEN p) GEN FqV_to_FlxV(GEN v, GEN T, GEN pp) GEN FqX_Fq_add(GEN y, GEN x, GEN T, GEN p) GEN FqX_Fq_mul_to_monic(GEN P, GEN U, GEN T, GEN p) GEN FqX_eval(GEN x, GEN y, GEN T, GEN p) GEN FqX_translate(GEN P, GEN c, GEN T, GEN p) GEN FqXQ_powers(GEN x, long l, GEN S, GEN T, GEN p) GEN FqXQ_matrix_pow(GEN y, long n, long m, GEN S, GEN T, GEN p) GEN FqXY_eval(GEN Q, GEN y, GEN x, GEN T, GEN p) GEN FqXY_evalx(GEN Q, GEN x, GEN T, GEN p) GEN QX_disc(GEN x) GEN QX_gcd(GEN a, GEN b) GEN QX_resultant(GEN A, GEN B) GEN QXQ_intnorm(GEN A, GEN B) GEN QXQ_inv(GEN A, GEN B) GEN QXQ_norm(GEN A, GEN B) int Rg_is_Fp(GEN x, GEN *p) int Rg_is_FpXQ(GEN x, GEN *pT, GEN *pp) GEN Rg_to_Fp(GEN x, GEN p) GEN Rg_to_FpXQ(GEN x, GEN T, GEN p) GEN RgC_to_FpC(GEN x, GEN p) int RgM_is_FpM(GEN x, GEN *p) GEN RgM_to_Flm(GEN x, ulong p) GEN RgM_to_FpM(GEN x, GEN p) int RgV_is_FpV(GEN x, GEN *p) GEN RgV_to_Flv(GEN x, ulong p) GEN RgV_to_FpV(GEN x, GEN p) int RgX_is_FpX(GEN x, GEN *p) GEN RgX_to_FpX(GEN x, GEN p) int RgX_is_FpXQX(GEN x, GEN *pT, GEN *pp) GEN RgX_to_FpXQX(GEN x, GEN T, GEN p) GEN RgX_to_FqX(GEN x, GEN T, GEN p) GEN ZX_ZXY_rnfequation(GEN A, GEN B, long *Lambda) GEN ZXQ_charpoly(GEN A, GEN T, long v) GEN ZX_disc(GEN x) int ZX_is_squarefree(GEN x) GEN ZX_gcd(GEN A, GEN B) GEN ZX_gcd_all(GEN A, GEN B, GEN *Anew) GEN ZX_resultant(GEN A, GEN B) int Z_incremental_CRT(GEN *H, ulong Hp, GEN *q, ulong p) GEN Z_init_CRT(ulong Hp, ulong p) int ZM_incremental_CRT(GEN *H, GEN Hp, GEN *q, ulong p) GEN ZM_init_CRT(GEN Hp, ulong p) int ZX_incremental_CRT(GEN *ptH, GEN Hp, GEN *q, ulong p) GEN ZX_init_CRT(GEN Hp, ulong p, long v) GEN characteristic(GEN x) GEN ffinit(GEN p, long n, long v) GEN ffnbirred(GEN p, long n) GEN ffnbirred0(GEN p, long n, long flag) GEN ffsumnbirred(GEN p, long n) const bb_field *get_Fq_field(void **E, GEN T, GEN p) GEN init_Fq(GEN p, long n, long v) GEN pol_x_powers(long N, long v) GEN residual_characteristic(GEN x) # polclass.c GEN polclass(GEN D, long inv, long xvar) # polmodular.c GEN Flm_Fl_polmodular_evalx(GEN phi, long L, ulong j, ulong p, ulong pi) GEN Fp_polmodular_evalx(long L, long inv, GEN J, GEN P, long v, int compute_derivs) GEN polmodular(long L, long inv, GEN x, long yvar, long compute_derivs) GEN polmodular_ZM(long L, long inv) GEN polmodular_ZXX(long L, long inv, long xvar, long yvar) # prime.c long BPSW_isprime(GEN x) long BPSW_psp(GEN N) GEN addprimes(GEN primes) GEN gisprime(GEN x, long flag) GEN gispseudoprime(GEN x, long flag) GEN gprimepi_upper_bound(GEN x) GEN gprimepi_lower_bound(GEN x) long isprime(GEN x) long ispseudoprime(GEN x, long flag) long millerrabin(GEN n, long k) GEN prime(long n) GEN primepi(GEN x) double primepi_upper_bound(double x) double primepi_lower_bound(double x) GEN primes(long n) GEN primes_interval(GEN a, GEN b) GEN primes_interval_zv(ulong a, ulong b) GEN primes_upto_zv(ulong b) GEN primes0(GEN n) GEN primes_zv(long m) GEN randomprime(GEN N) GEN removeprimes(GEN primes) int uislucaspsp(ulong n) int uisprime(ulong n) ulong uprime(long n) ulong uprimepi(ulong n) # qfisom.c GEN qfauto(GEN g, GEN flags) GEN qfauto0(GEN g, GEN flags) GEN qfautoexport(GEN g, long flag) GEN qfisom(GEN g, GEN h, GEN flags) GEN qfisom0(GEN g, GEN h, GEN flags) GEN qfisominit(GEN g, GEN flags, GEN minvec) GEN qfisominit0(GEN g, GEN flags, GEN minvec) GEN qforbits(GEN G, GEN V) # qfparam.c GEN qfsolve(GEN G) GEN qfparam(GEN G, GEN sol, long fl) # random.c GEN genrand(GEN N) GEN getrand() ulong pari_rand() GEN randomi(GEN x) GEN randomr(long prec) ulong random_Fl(ulong n) long random_bits(long k) void setrand(GEN seed) # rootpol.c GEN QX_complex_roots(GEN p, long l) GEN ZX_graeffe(GEN p) GEN cleanroots(GEN x, long l) double fujiwara_bound(GEN p) double fujiwara_bound_real(GEN p, long sign) int isrealappr(GEN x, long l) GEN polgraeffe(GEN p) GEN polmod_to_embed(GEN x, long prec) GEN roots(GEN x, long l) GEN realroots(GEN P, GEN ab, long prec) long ZX_sturm(GEN P) long ZX_sturmpart(GEN P, GEN ab) GEN ZX_Uspensky(GEN P, GEN ab, long flag, long prec) # subcyclo.c GEN factor_Aurifeuille(GEN p, long n) GEN factor_Aurifeuille_prime(GEN p, long n) GEN galoissubcyclo(GEN N, GEN sg, long flag, long v) GEN polsubcyclo(long n, long d, long v) # subfield.c GEN nfsubfields(GEN nf, long d) # subgroup.c GEN subgrouplist(GEN cyc, GEN bound) void forsubgroup(void *E, long fun(void*, GEN), GEN cyc, GEN B) # stark.c GEN bnrL1(GEN bnr, GEN sbgrp, long flag, long prec) GEN bnrrootnumber(GEN bnr, GEN chi, long flag, long prec) GEN bnrstark(GEN bnr, GEN subgroup, long prec) GEN cyc2elts(GEN cyc) # sumiter.c GEN asympnum(void *E, GEN (*f)(void *, GEN, long), long muli, GEN alpha, long prec) GEN derivnum(void *E, GEN (*eval)(void *, GEN, long prec), GEN x, long prec) GEN derivfun(void *E, GEN (*eval)(void *, GEN, long prec), GEN x, long prec) int forcomposite_init(forcomposite_t *C, GEN a, GEN b) GEN forcomposite_next(forcomposite_t *C) GEN forprime_next(forprime_t *T) int forprime_init(forprime_t *T, GEN a, GEN b) int forvec_init(forvec_t *T, GEN x, long flag) GEN forvec_next(forvec_t *T) GEN limitnum(void *E, GEN (*f)(void *, GEN, long), long muli, GEN alpha, long prec) GEN polzag(long n, long m) GEN prodeuler(void *E, GEN (*eval)(void *, GEN), GEN ga, GEN gb, long prec) GEN prodinf(void *E, GEN (*eval)(void *, GEN), GEN a, long prec) GEN prodinf1(void *E, GEN (*eval)(void *, GEN), GEN a, long prec) GEN sumalt(void *E, GEN (*eval)(void *, GEN), GEN a, long prec) GEN sumalt2(void *E, GEN (*eval)(void *, GEN), GEN a, long prec) GEN sumpos(void *E, GEN (*eval)(void *, GEN), GEN a, long prec) GEN sumpos2(void *E, GEN (*eval)(void *, GEN), GEN a, long prec) GEN suminf(void *E, GEN (*eval)(void *, GEN), GEN a, long prec) ulong u_forprime_next(forprime_t *T) int u_forprime_init(forprime_t *T, ulong a, ulong b) void u_forprime_restrict(forprime_t *T, ulong c) int u_forprime_arith_init(forprime_t *T, ulong a, ulong b, ulong c, ulong q) GEN zbrent(void *E, GEN (*eval)(void *, GEN), GEN a, GEN b, long prec) GEN solvestep(void *E, GEN (*eval)(void *, GEN), GEN a, GEN b, GEN step, long flag, long prec) # thue.c GEN bnfisintnorm(GEN x, GEN y) GEN bnfisintnormabs(GEN bnf, GEN a) GEN thue(GEN thueres, GEN rhs, GEN ne) GEN thueinit(GEN pol, long flag, long prec) # trans1.c GEN Pi2n(long n, long prec) GEN PiI2(long prec) GEN PiI2n(long n, long prec) GEN Qp_exp(GEN x) GEN Qp_log(GEN x) GEN Qp_sqrt(GEN x) GEN Qp_sqrtn(GEN x, GEN n, GEN *zetan) long Zn_ispower(GEN a, GEN q, GEN K, GEN *pt) long Zn_issquare(GEN x, GEN n) GEN Zn_sqrt(GEN x, GEN n) GEN Zp_teichmuller(GEN x, GEN p, long n, GEN q) GEN agm(GEN x, GEN y, long prec) GEN constcatalan(long prec) GEN consteuler(long prec) GEN constlog2(long prec) GEN constpi(long prec) GEN cxexpm1(GEN z, long prec) GEN expIr(GEN x) GEN exp1r_abs(GEN x) GEN gcos(GEN x, long prec) GEN gcotan(GEN x, long prec) GEN gcotanh(GEN x, long prec) GEN gexp(GEN x, long prec) GEN gexpm1(GEN x, long prec) GEN glog(GEN x, long prec) GEN gpow(GEN x, GEN n, long prec) GEN gpowers(GEN x, long n) GEN gpowers0(GEN x, long n, GEN x0) GEN gpowgs(GEN x, long n) GEN grootsof1(long N, long prec) GEN gsin(GEN x, long prec) GEN gsinc(GEN x, long prec) void gsincos(GEN x, GEN *s, GEN *c, long prec) GEN gsqrpowers(GEN q, long n) GEN gsqrt(GEN x, long prec) GEN gsqrtn(GEN x, GEN n, GEN *zetan, long prec) GEN gtan(GEN x, long prec) GEN logr_abs(GEN x) GEN mpcos(GEN x) GEN mpeuler(long prec) GEN mpcatalan(long prec) void mpsincosm1(GEN x, GEN *s, GEN *c) GEN mpexp(GEN x) GEN mpexpm1(GEN x) GEN mplog(GEN x) GEN mplog2(long prec) GEN mppi(long prec) GEN mpsin(GEN x) void mpsincos(GEN x, GEN *s, GEN *c) GEN powersr(GEN a, long n) GEN powis(GEN x, long n) GEN powiu(GEN p, ulong k) GEN powrfrac(GEN x, long n, long d) GEN powrs(GEN x, long n) GEN powrshalf(GEN x, long s) GEN powru(GEN x, ulong n) GEN powruhalf(GEN x, ulong s) GEN powuu(ulong p, ulong k) GEN powgi(GEN x, GEN n) GEN serchop0(GEN s) GEN sqrtnint(GEN a, long n) GEN teich(GEN x) GEN teichmullerinit(long p, long n) GEN teichmuller(GEN x, GEN tab) GEN trans_eval(const char *fun, GEN (*f) (GEN, long), GEN x, long prec) ulong upowuu(ulong p, ulong k) ulong usqrtn(ulong a, ulong n) ulong usqrt(ulong a) # trans2.c GEN Qp_gamma(GEN x) GEN bernfrac(long n) GEN bernpol(long k, long v) GEN bernreal(long n, long prec) GEN gacosh(GEN x, long prec) GEN gacos(GEN x, long prec) GEN garg(GEN x, long prec) GEN gasinh(GEN x, long prec) GEN gasin(GEN x, long prec) GEN gatan(GEN x, long prec) GEN gatanh(GEN x, long prec) GEN gcosh(GEN x, long prec) GEN ggammah(GEN x, long prec) GEN ggamma(GEN x, long prec) GEN ggamma1m1(GEN x, long prec) GEN glngamma(GEN x, long prec) GEN gpsi(GEN x, long prec) GEN gsinh(GEN x, long prec) GEN gtanh(GEN x, long prec) void mpbern(long nomb, long prec) GEN mpfactr(long n, long prec) GEN sumformal(GEN T, long v) # trans3.c double dblmodulus(GEN x) GEN dilog(GEN x, long prec) GEN eint1(GEN x, long prec) GEN eta(GEN x, long prec) GEN eta0(GEN x, long flag, long prec) GEN gerfc(GEN x, long prec) GEN glambertW(GEN y, long prec) GEN gpolylog(long m, GEN x, long prec) GEN gzeta(GEN x, long prec) GEN hbessel1(GEN n, GEN z, long prec) GEN hbessel2(GEN n, GEN z, long prec) GEN hyperu(GEN a, GEN b, GEN gx, long prec) GEN ibessel(GEN n, GEN z, long prec) GEN incgam(GEN a, GEN x, long prec) GEN incgam0(GEN a, GEN x, GEN z, long prec) GEN incgamc(GEN a, GEN x, long prec) GEN jbessel(GEN n, GEN z, long prec) GEN jbesselh(GEN n, GEN z, long prec) GEN jell(GEN x, long prec) GEN kbessel(GEN nu, GEN gx, long prec) GEN mpeint1(GEN x, GEN expx) GEN mplambertW(GEN y) GEN mpveceint1(GEN C, GEN eC, long n) GEN nbessel(GEN n, GEN z, long prec) GEN polylog0(long m, GEN x, long flag, long prec) GEN sumdedekind(GEN h, GEN k) GEN sumdedekind_coprime(GEN h, GEN k) GEN szeta(long x, long prec) GEN theta(GEN q, GEN z, long prec) GEN thetanullk(GEN q, long k, long prec) GEN trueeta(GEN x, long prec) GEN u_sumdedekind_coprime(long h, long k) GEN veceint1(GEN nmax, GEN C, long prec) GEN vecthetanullk(GEN q, long k, long prec) GEN vecthetanullk_tau(GEN tau, long k, long prec) GEN veczeta(GEN a, GEN b, long N, long prec) GEN weber0(GEN x, long flag, long prec) GEN weberf(GEN x, long prec) GEN weberf1(GEN x, long prec) GEN weberf2(GEN x, long prec) # modsym.c GEN Qevproj_apply(GEN T, GEN pro) GEN Qevproj_apply_vecei(GEN T, GEN pro, long k) GEN Qevproj_init(GEN M) GEN RgX_act_Gl2Q(GEN g, long k) GEN RgX_act_ZGl2Q(GEN z, long k) void checkms(GEN W) void checkmspadic(GEN W) GEN ellpadicL(GEN E, GEN p, long n, GEN s, long r, GEN D) GEN msfromcusp(GEN W, GEN c) GEN msfromell(GEN E, long signe) GEN msfromhecke(GEN W, GEN v, GEN H) long msgetlevel(GEN W) long msgetsign(GEN W) long msgetweight(GEN W) GEN msatkinlehner(GEN W, long Q, GEN) GEN mscuspidal(GEN W, long flag) GEN mseisenstein(GEN W) GEN mseval(GEN W, GEN s, GEN p) GEN mshecke(GEN W, long p, GEN H) GEN msinit(GEN N, GEN k, long sign) long msissymbol(GEN W, GEN s) GEN msomseval(GEN W, GEN phi, GEN path) GEN mspadicinit(GEN W, long p, long n, long flag) GEN mspadicL(GEN oms, GEN s, long r) GEN mspadicmoments(GEN W, GEN phi, long D) GEN mspadicseries(GEN M, long teichi) GEN mspathgens(GEN W) GEN mspathlog(GEN W, GEN path) GEN msnew(GEN W) GEN msstar(GEN W, GEN) GEN msqexpansion(GEN W, GEN proV, ulong B) GEN mssplit(GEN W, GEN H, long deglim) GEN mstooms(GEN W, GEN phi) # zetamult.c GEN zetamult(GEN avec, long prec) # level1.h ulong Fl_add(ulong a, ulong b, ulong p) ulong Fl_addmul_pre(ulong x0, ulong x1, ulong y0, ulong p, ulong pi) ulong Fl_addmulmul_pre(ulong x0, ulong y0, ulong x1, ulong y1, ulong p, ulong pi) long Fl_center(ulong u, ulong p, ulong ps2) ulong Fl_div(ulong a, ulong b, ulong p) ulong Fl_double(ulong a, ulong p) ulong Fl_ellj_pre(ulong a4, ulong a6, ulong p, ulong pi) ulong Fl_halve(ulong y, ulong p) ulong Fl_mul(ulong a, ulong b, ulong p) ulong Fl_mul_pre(ulong a, ulong b, ulong p, ulong pi) ulong Fl_neg(ulong x, ulong p) ulong Fl_sqr(ulong a, ulong p) ulong Fl_sqr_pre(ulong a, ulong p, ulong pi) ulong Fl_sub(ulong a, ulong b, ulong p) ulong Fl_triple(ulong a, ulong p) ulong Mod2(GEN x) ulong Mod4(GEN x) ulong Mod8(GEN x) ulong Mod16(GEN x) ulong Mod32(GEN x) ulong Mod64(GEN x) int abscmpiu(GEN x, ulong y) int abscmpui(ulong x, GEN y) int absequaliu(GEN x, ulong y) GEN absi(GEN x) GEN absi_shallow(GEN x) GEN absr(GEN x) int absrnz_equal1(GEN x) int absrnz_equal2n(GEN x) GEN addii(GEN x, GEN y) void addiiz(GEN x, GEN y, GEN z) GEN addir(GEN x, GEN y) void addirz(GEN x, GEN y, GEN z) GEN addis(GEN x, long s) GEN addri(GEN x, GEN y) void addriz(GEN x, GEN y, GEN z) GEN addrr(GEN x, GEN y) void addrrz(GEN x, GEN y, GEN z) GEN addrs(GEN x, long s) GEN addsi(long x, GEN y) void addsiz(long s, GEN y, GEN z) void addsrz(long s, GEN y, GEN z) GEN addss(long x, long y) void addssz(long s, long y, GEN z) GEN adduu(ulong x, ulong y) void affgr(GEN x, GEN y) void affii(GEN x, GEN y) void affiz(GEN x, GEN y) void affrr_fixlg(GEN y, GEN z) void affsi(long s, GEN x) void affsr(long s, GEN x) void affsz(long x, GEN y) void affui(ulong s, GEN x) void affur(ulong s, GEN x) GEN cgetg(long x, long y) GEN cgetg_block(long x, long y) GEN cgetg_copy(GEN x, long *plx) GEN cgeti(long x) GEN cgetineg(long x) GEN cgetipos(long x) GEN cgetr(long x) GEN cgetr_block(long prec) int cmpir(GEN x, GEN y) int cmpis(GEN x, long y) int cmpri(GEN x, GEN y) int cmprs(GEN x, long y) int cmpsi(long x, GEN y) int cmpsr(long x, GEN y) GEN cxtofp(GEN x, long prec) GEN divii(GEN a, GEN b) void diviiz(GEN x, GEN y, GEN z) void divirz(GEN x, GEN y, GEN z) void divisz(GEN x, long s, GEN z) void divriz(GEN x, GEN y, GEN z) void divrrz(GEN x, GEN y, GEN z) void divrsz(GEN y, long s, GEN z) GEN divsi_rem(long x, GEN y, long *rem) void divsiz(long x, GEN y, GEN z) void divsrz(long s, GEN y, GEN z) GEN divss(long x, long y) GEN divss_rem(long x, long y, long *rem) void divssz(long x, long y, GEN z) int dvdii(GEN x, GEN y) int dvdiiz(GEN x, GEN y, GEN z) int dvdis(GEN x, long y) int dvdisz(GEN x, long y, GEN z) int dvdiu(GEN x, ulong y) int dvdiuz(GEN x, ulong y, GEN z) int dvdsi(long x, GEN y) int dvdui(ulong x, GEN y) void dvmdiiz(GEN x, GEN y, GEN z, GEN t) GEN dvmdis(GEN x, long y, GEN *z) void dvmdisz(GEN x, long y, GEN z, GEN t) long dvmdsBIL(long n, long *r) GEN dvmdsi(long x, GEN y, GEN *z) void dvmdsiz(long x, GEN y, GEN z, GEN t) GEN dvmdss(long x, long y, GEN *z) void dvmdssz(long x, long y, GEN z, GEN t) ulong dvmduBIL(ulong n, ulong *r) int equalis(GEN x, long y) int equalsi(long x, GEN y) int absequalui(ulong x, GEN y) ulong ceildivuu(ulong a, ulong b) long evalexpo(long x) long evallg(long x) long evalprecp(long x) long evalvalp(long x) long expi(GEN x) long expu(ulong x) void fixlg(GEN z, long ly) GEN fractor(GEN x, long prec) GEN icopy(GEN x) GEN icopyspec(GEN x, long nx) GEN icopy_avma(GEN x, pari_sp av) ulong int_bit(GEN x, long n) GEN itor(GEN x, long prec) long itos(GEN x) long itos_or_0(GEN x) ulong itou(GEN x) ulong itou_or_0(GEN x) GEN leafcopy(GEN x) GEN leafcopy_avma(GEN x, pari_sp av) double maxdd(double x, double y) long maxss(long x, long y) long maxuu(ulong x, ulong y) double mindd(double x, double y) long minss(long x, long y) long minuu(ulong x, ulong y) long mod16(GEN x) long mod2(GEN x) ulong mod2BIL(GEN x) long mod32(GEN x) long mod4(GEN x) long mod64(GEN x) long mod8(GEN x) GEN modis(GEN x, long y) void modisz(GEN y, long s, GEN z) GEN modsi(long x, GEN y) void modsiz(long s, GEN y, GEN z) GEN modss(long x, long y) void modssz(long s, long y, GEN z) GEN mpabs(GEN x) GEN mpabs_shallow(GEN x) GEN mpadd(GEN x, GEN y) void mpaddz(GEN x, GEN y, GEN z) void mpaff(GEN x, GEN y) GEN mpceil(GEN x) int mpcmp(GEN x, GEN y) GEN mpcopy(GEN x) GEN mpdiv(GEN x, GEN y) long mpexpo(GEN x) GEN mpfloor(GEN x) GEN mpmul(GEN x, GEN y) void mpmulz(GEN x, GEN y, GEN z) GEN mpneg(GEN x) int mpodd(GEN x) GEN mpround(GEN x) GEN mpshift(GEN x, long s) GEN mpsqr(GEN x) GEN mpsub(GEN x, GEN y) void mpsubz(GEN x, GEN y, GEN z) GEN mptrunc(GEN x) void muliiz(GEN x, GEN y, GEN z) void mulirz(GEN x, GEN y, GEN z) GEN mulis(GEN x, long s) GEN muliu(GEN x, ulong s) GEN mulri(GEN x, GEN s) void mulriz(GEN x, GEN y, GEN z) void mulrrz(GEN x, GEN y, GEN z) GEN mulrs(GEN x, long s) GEN mulru(GEN x, ulong s) void mulsiz(long s, GEN y, GEN z) void mulsrz(long s, GEN y, GEN z) void mulssz(long s, long y, GEN z) GEN negi(GEN x) GEN negr(GEN x) GEN new_chunk(size_t x) GEN rcopy(GEN x) GEN rdivii(GEN x, GEN y, long prec) void rdiviiz(GEN x, GEN y, GEN z) GEN rdivis(GEN x, long y, long prec) GEN rdivsi(long x, GEN y, long prec) GEN rdivss(long x, long y, long prec) GEN real2n(long n, long prec) GEN real_m2n(long n, long prec) GEN real_0(long prec) GEN real_0_bit(long bitprec) GEN real_1(long prec) GEN real_1_bit(long bit) GEN real_m1(long prec) GEN remii(GEN a, GEN b) void remiiz(GEN x, GEN y, GEN z) GEN remis(GEN x, long y) void remisz(GEN y, long s, GEN z) ulong remlll_pre(ulong u2, ulong u1, ulong u0, ulong p, ulong pi) GEN remsi(long x, GEN y) void remsiz(long s, GEN y, GEN z) GEN remss(long x, long y) void remssz(long s, long y, GEN z) GEN rtor(GEN x, long prec) long sdivsi(long x, GEN y) long sdivsi_rem(long x, GEN y, long *rem) long sdivss_rem(long x, long y, long *rem) ulong udiviu_rem(GEN n, ulong d, ulong *r) ulong udivuu_rem(ulong x, ulong y, ulong *r) ulong umodi2n(GEN x, long n) void setabssign(GEN x) void shift_left(GEN z2, GEN z1, long min, long M, ulong f, ulong sh) void shift_right(GEN z2, GEN z1, long min, long M, ulong f, ulong sh) ulong shiftl(ulong x, ulong y) ulong shiftlr(ulong x, ulong y) GEN shiftr(GEN x, long n) void shiftr_inplace(GEN z, long d) long smodis(GEN x, long y) long smodss(long x, long y) void stackdummy(pari_sp av, pari_sp ltop) char *stack_malloc(size_t N) char *stack_malloc_align(size_t N, long k) char *stack_calloc(size_t N) GEN stoi(long x) GEN stor(long x, long prec) GEN subii(GEN x, GEN y) void subiiz(GEN x, GEN y, GEN z) GEN subir(GEN x, GEN y) void subirz(GEN x, GEN y, GEN z) GEN subis(GEN x, long y) void subisz(GEN y, long s, GEN z) GEN subri(GEN x, GEN y) void subriz(GEN x, GEN y, GEN z) GEN subrr(GEN x, GEN y) void subrrz(GEN x, GEN y, GEN z) GEN subrs(GEN x, long y) void subrsz(GEN y, long s, GEN z) GEN subsi(long x, GEN y) void subsiz(long s, GEN y, GEN z) void subsrz(long s, GEN y, GEN z) GEN subss(long x, long y) void subssz(long x, long y, GEN z) GEN subuu(ulong x, ulong y) void togglesign(GEN x) void togglesign_safe(GEN *px) void affectsign(GEN x, GEN y) void affectsign_safe(GEN x, GEN *py) GEN truedivii(GEN a, GEN b) GEN truedivis(GEN a, long b) GEN truedivsi(long a, GEN b) ulong udivui_rem(ulong x, GEN y, ulong *rem) ulong umodsu(long x, ulong y) ulong umodui(ulong x, GEN y) ulong umuluu_or_0(ulong x, ulong y) GEN utoi(ulong x) GEN utoineg(ulong x) GEN utoipos(ulong x) GEN utor(ulong s, long prec) GEN uutoi(ulong x, ulong y) GEN uutoineg(ulong x, ulong y) long vali(GEN x) int varncmp(long x, long y) long varnmax(long x, long y) long varnmin(long x, long y) # pariinl.h GEN abgrp_get_cyc(GEN x) GEN abgrp_get_gen(GEN x) GEN abgrp_get_no(GEN x) GEN bid_get_arch(GEN bid) GEN bid_get_archp(GEN bid) GEN bid_get_cyc(GEN bid) GEN bid_get_fact(GEN bid) GEN bid_get_gen(GEN bid) GEN bid_get_gen_nocheck(GEN bid) GEN bid_get_grp(GEN bid) GEN bid_get_ideal(GEN bid) GEN bid_get_mod(GEN bid) GEN bid_get_no(GEN bid) GEN bid_get_sarch(GEN bid) GEN bid_get_sprk(GEN bid) GEN bid_get_U(GEN bid) GEN bnf_get_clgp(GEN bnf) GEN bnf_get_cyc(GEN bnf) GEN bnf_get_fu(GEN bnf) GEN bnf_get_fu_nocheck(GEN bnf) GEN bnf_get_gen(GEN bnf) GEN bnf_get_logfu(GEN bnf) GEN bnf_get_nf(GEN bnf) GEN bnf_get_no(GEN bnf) GEN bnf_get_reg(GEN bnf) GEN bnf_get_tuU(GEN bnf) long bnf_get_tuN(GEN bnf) GEN bnr_get_bnf(GEN bnr) GEN bnr_get_clgp(GEN bnr) GEN bnr_get_cyc(GEN bnr) GEN bnr_get_gen(GEN bnr) GEN bnr_get_gen_nocheck(GEN bnr) GEN bnr_get_no(GEN bnr) GEN bnr_get_bid(GEN bnr) GEN bnr_get_mod(GEN bnr) GEN bnr_get_nf(GEN bnr) GEN ell_get_a1(GEN e) GEN ell_get_a2(GEN e) GEN ell_get_a3(GEN e) GEN ell_get_a4(GEN e) GEN ell_get_a6(GEN e) GEN ell_get_b2(GEN e) GEN ell_get_b4(GEN e) GEN ell_get_b6(GEN e) GEN ell_get_b8(GEN e) GEN ell_get_c4(GEN e) GEN ell_get_c6(GEN e) GEN ell_get_disc(GEN e) GEN ell_get_j(GEN e) long ell_get_type(GEN e) int ell_is_inf(GEN z) GEN ellinf() GEN ellff_get_field(GEN x) GEN ellff_get_a4a6(GEN x) GEN ellnf_get_nf(GEN x) GEN ellQp_get_p(GEN E) long ellQp_get_prec(GEN E) GEN ellQp_get_zero(GEN x) long ellR_get_prec(GEN x) long ellR_get_sign(GEN x) GEN gal_get_pol(GEN gal) GEN gal_get_p(GEN gal) GEN gal_get_e(GEN gal) GEN gal_get_mod(GEN gal) GEN gal_get_roots(GEN gal) GEN gal_get_invvdm(GEN gal) GEN gal_get_den(GEN gal) GEN gal_get_group(GEN gal) GEN gal_get_gen(GEN gal) GEN gal_get_orders(GEN gal) GEN idealchineseinit(GEN nf, GEN x) GEN idealpseudomin(GEN I, GEN G) GEN idealpseudomin_nonscalar(GEN I, GEN G) GEN idealpseudored(GEN I, GEN G) GEN idealred_elt(GEN nf, GEN I) GEN idealred(GEN nf, GEN I) long logint(GEN B, GEN y) ulong ulogint(ulong B, ulong y) GEN modpr_get_pr(GEN x) GEN modpr_get_p(GEN x) GEN modpr_get_T(GEN x) GEN nf_get_M(GEN nf) GEN nf_get_G(GEN nf) GEN nf_get_Tr(GEN nf) GEN nf_get_diff(GEN nf) long nf_get_degree(GEN nf) GEN nf_get_disc(GEN nf) GEN nf_get_index(GEN nf) GEN nf_get_invzk(GEN nf) GEN nf_get_pol(GEN nf) long nf_get_r1(GEN nf) long nf_get_r2(GEN nf) GEN nf_get_ramified_primes(GEN nf) GEN nf_get_roots(GEN nf) GEN nf_get_roundG(GEN nf) void nf_get_sign(GEN nf, long *r1, long *r2) long nf_get_varn(GEN nf) GEN nf_get_zk(GEN nf) GEN nf_get_zkden(GEN nf) GEN nf_get_zkprimpart(GEN nf) long pr_get_e(GEN pr) long pr_get_f(GEN pr) GEN pr_get_gen(GEN pr) GEN pr_get_p(GEN pr) GEN pr_get_tau(GEN pr) int pr_is_inert(GEN P) GEN pr_norm(GEN pr) GEN rnf_get_alpha(GEN rnf) long rnf_get_absdegree(GEN rnf) long rnf_get_degree(GEN rnf) GEN rnf_get_idealdisc(GEN rnf) GEN rnf_get_invzk(GEN rnf) GEN rnf_get_k(GEN rnf) GEN rnf_get_map(GEN rnf) GEN rnf_get_nf(GEN rnf) long rnf_get_nfdegree(GEN rnf) GEN rnf_get_nfpol(GEN rnf) long rnf_get_nfvarn(GEN rnf) GEN rnf_get_pol(GEN rnf) GEN rnf_get_polabs(GEN rnf) GEN rnf_get_zk(GEN nf) void rnf_get_nfzk(GEN rnf, GEN *b, GEN *cb) long rnf_get_varn(GEN rnf) ulong upr_norm(GEN pr) GEN znstar_get_N(GEN G) GEN znstar_get_conreycyc(GEN G) GEN znstar_get_conreygen(GEN G) GEN znstar_get_faN(GEN G) GEN znstar_get_no(GEN G) GEN znstar_get_pe(GEN G) GEN znstar_get_Ui(GEN G) long closure_arity(GEN C) const char * closure_codestr(GEN C) GEN closure_get_code(GEN C) GEN closure_get_oper(GEN C) GEN closure_get_data(GEN C) GEN closure_get_dbg(GEN C) GEN closure_get_text(GEN C) GEN closure_get_frame(GEN C) long closure_is_variadic(GEN C) GEN addmuliu(GEN x, GEN y, ulong u) GEN addmuliu_inplace(GEN x, GEN y, ulong u) GEN lincombii(GEN u, GEN v, GEN x, GEN y) GEN mulsubii(GEN y, GEN z, GEN x) GEN submulii(GEN x, GEN y, GEN z) GEN submuliu(GEN x, GEN y, ulong u) GEN submuliu_inplace(GEN x, GEN y, ulong u) GEN FpXQ_add(GEN x, GEN y, GEN T, GEN p) GEN FpXQ_sub(GEN x, GEN y, GEN T, GEN p) GEN Flxq_add(GEN x, GEN y, GEN T, ulong p) GEN Flxq_sub(GEN x, GEN y, GEN T, ulong p) GEN FpXQX_div(GEN x, GEN y, GEN T, GEN p) GEN FlxqX_div(GEN x, GEN y, GEN T, ulong p) GEN F2xqX_div(GEN x, GEN y, GEN T) GEN Fq_red(GEN x, GEN T, GEN p) GEN Fq_to_FpXQ(GEN x, GEN T, GEN p) GEN gener_Fq_local(GEN T, GEN p, GEN L) GEN FqX_Fp_mul(GEN P, GEN U, GEN T, GEN p) GEN FqX_Fq_mul(GEN P, GEN U, GEN T, GEN p) GEN FqX_add(GEN x, GEN y, GEN T, GEN p) GEN FqX_deriv(GEN f, GEN T, GEN p) GEN FqX_div(GEN x, GEN y, GEN T, GEN p) GEN FqX_div_by_X_x(GEN x, GEN y, GEN T, GEN p, GEN *z) GEN FqX_divrem(GEN x, GEN y, GEN T, GEN p, GEN *z) GEN FqX_extgcd(GEN P, GEN Q, GEN T, GEN p, GEN *U, GEN *V) GEN FqX_factor(GEN f, GEN T, GEN p) GEN FqX_gcd(GEN P, GEN Q, GEN T, GEN p) GEN FqX_get_red(GEN S, GEN T, GEN p) GEN FqX_halfgcd(GEN P, GEN Q, GEN T, GEN p) GEN FqX_mul(GEN x, GEN y, GEN T, GEN p) GEN FqX_mulu(GEN x, ulong y, GEN T, GEN p) GEN FqX_neg(GEN x, GEN T, GEN p) GEN FqX_normalize(GEN z, GEN T, GEN p) GEN FqX_powu(GEN x, ulong n, GEN T, GEN p) GEN FqX_red(GEN z, GEN T, GEN p) GEN FqX_rem(GEN x, GEN y, GEN T, GEN p) GEN FqX_roots(GEN f, GEN T, GEN p) GEN FqX_sqr(GEN x, GEN T, GEN p) GEN FqX_sub(GEN x, GEN y, GEN T, GEN p) GEN FqXQ_add(GEN x, GEN y, GEN S, GEN T, GEN p) GEN FqXQ_div(GEN x, GEN y, GEN S, GEN T, GEN p) GEN FqXQ_inv(GEN x, GEN S, GEN T, GEN p) GEN FqXQ_invsafe(GEN x, GEN S, GEN T, GEN p) GEN FqXQ_mul(GEN x, GEN y, GEN S, GEN T, GEN p) GEN FqXQ_pow(GEN x, GEN n, GEN S, GEN T, GEN p) GEN FqXQ_sqr(GEN x, GEN S, GEN T, GEN p) GEN FqXQ_sub(GEN x, GEN y, GEN S, GEN T, GEN p) long get_F2x_degree(GEN T) GEN get_F2x_mod(GEN T) long get_F2x_var(GEN T) long get_F2xqX_degree(GEN T) GEN get_F2xqX_mod(GEN T) long get_F2xqX_var(GEN T) long get_Flx_degree(GEN T) GEN get_Flx_mod(GEN T) long get_Flx_var(GEN T) long get_FlxqX_degree(GEN T) GEN get_FlxqX_mod(GEN T) long get_FlxqX_var(GEN T) long get_FpX_degree(GEN T) GEN get_FpX_mod(GEN T) long get_FpX_var(GEN T) long get_FpXQX_degree(GEN T) GEN get_FpXQX_mod(GEN T) long get_FpXQX_var(GEN T) ulong F2m_coeff(GEN x, long a, long b) void F2m_clear(GEN x, long a, long b) void F2m_flip(GEN x, long a, long b) void F2m_set(GEN x, long a, long b) void F2v_clear(GEN x, long v) ulong F2v_coeff(GEN x, long v) void F2v_flip(GEN x, long v) GEN F2v_to_F2x(GEN x, long sv) void F2v_set(GEN x, long v) void F2x_clear(GEN x, long v) ulong F2x_coeff(GEN x, long v) void F2x_flip(GEN x, long v) void F2x_set(GEN x, long v) int F2x_equal1(GEN x) int F2x_equal(GEN V, GEN W) GEN F2x_div(GEN x, GEN y) GEN F2x_renormalize(GEN x, long lx) GEN F2m_copy(GEN x) GEN F2v_copy(GEN x) GEN F2x_copy(GEN x) GEN F2v_ei(long n, long i) GEN Flm_copy(GEN x) GEN Flv_copy(GEN x) int Flx_equal1(GEN x) GEN Flx_copy(GEN x) GEN Flx_div(GEN x, GEN y, ulong p) ulong Flx_lead(GEN x) GEN Flx_mulu(GEN x, ulong a, ulong p) GEN FpV_FpC_mul(GEN x, GEN y, GEN p) GEN FpXQX_renormalize(GEN x, long lx) GEN FpXX_renormalize(GEN x, long lx) GEN FpX_div(GEN x, GEN y, GEN p) GEN FpX_renormalize(GEN x, long lx) GEN Fp_add(GEN a, GEN b, GEN m) GEN Fp_addmul(GEN x, GEN y, GEN z, GEN p) GEN Fp_center(GEN u, GEN p, GEN ps2) GEN Fp_div(GEN a, GEN b, GEN m) GEN Fp_halve(GEN y, GEN p) GEN Fp_inv(GEN a, GEN m) GEN Fp_invsafe(GEN a, GEN m) GEN Fp_mul(GEN a, GEN b, GEN m) GEN Fp_muls(GEN a, long b, GEN m) GEN Fp_mulu(GEN a, ulong b, GEN m) GEN Fp_neg(GEN b, GEN m) GEN Fp_red(GEN x, GEN p) GEN Fp_sqr(GEN a, GEN m) GEN Fp_sub(GEN a, GEN b, GEN m) GEN GENbinbase(GENbin *p) GEN Q_abs(GEN x) GEN Q_abs_shallow(GEN x) int QV_isscalar(GEN x) void Qtoss(GEN q, long *n, long *d) GEN R_abs(GEN x) GEN R_abs_shallow(GEN x) GEN RgC_fpnorml2(GEN x, long prec) GEN RgC_gtofp(GEN x, long prec) GEN RgC_gtomp(GEN x, long prec) void RgM_dimensions(GEN x, long *m, long *n) GEN RgM_fpnorml2(GEN x, long prec) GEN RgM_gtofp(GEN x, long prec) GEN RgM_gtomp(GEN x, long prec) GEN RgM_inv(GEN a) GEN RgM_minor(GEN a, long i, long j) GEN RgM_shallowcopy(GEN x) GEN RgV_gtofp(GEN x, long prec) int RgV_isscalar(GEN x) int RgV_is_ZV(GEN x) int RgV_is_QV(GEN x) long RgX_equal_var(GEN x, GEN y) int RgX_is_monomial(GEN x) int RgX_is_rational(GEN x) int RgX_is_QX(GEN x) int RgX_is_ZX(GEN x) int RgX_isscalar(GEN x) GEN RgX_shift_inplace(GEN x, long v) void RgX_shift_inplace_init(long v) GEN RgXQ_mul(GEN x, GEN y, GEN T) GEN RgXQ_sqr(GEN x, GEN T) GEN RgXQX_div(GEN x, GEN y, GEN T) GEN RgXQX_rem(GEN x, GEN y, GEN T) GEN RgX_coeff(GEN x, long n) GEN RgX_copy(GEN x) GEN RgX_div(GEN x, GEN y) GEN RgX_fpnorml2(GEN x, long prec) GEN RgX_gtofp(GEN x, long prec) GEN RgX_rem(GEN x, GEN y) GEN RgX_renormalize(GEN x) GEN Rg_col_ei(GEN x, long n, long i) GEN ZC_hnfrem(GEN x, GEN y) GEN ZM_hnfrem(GEN x, GEN y) GEN ZM_lll(GEN x, double D, long f) int ZV_dvd(GEN x, GEN y) int ZV_isscalar(GEN x) GEN ZV_to_zv(GEN x) int ZX_equal1(GEN x) GEN ZX_renormalize(GEN x, long lx) GEN ZXQ_mul(GEN x, GEN y, GEN T) GEN ZXQ_sqr(GEN x, GEN T) long Z_ispower(GEN x, ulong k) long Z_issquare(GEN x) GEN absfrac(GEN x) GEN absfrac_shallow(GEN x) GEN affc_fixlg(GEN x, GEN res) GEN bin_copy(GENbin *p) long bit_accuracy(long x) double bit_accuracy_mul(long x, double y) long bit_prec(GEN x) int both_odd(long x, long y) GEN cbrtr(GEN x) GEN cbrtr_abs(GEN x) GEN cgetc(long x) GEN cgetalloc(long t, size_t l) GEN cxcompotor(GEN z, long prec) void cgiv(GEN x) GEN col_ei(long n, long i) GEN const_col(long n, GEN x) GEN const_vec(long n, GEN x) GEN const_vecsmall(long n, long c) GEN constant_coeff(GEN x) GEN cxnorm(GEN x) GEN cyclic_perm(long l, long d) double dbllog2r(GEN x) long degpol(GEN x) long divsBIL(long n) void gabsz(GEN x, long prec, GEN z) GEN gaddgs(GEN y, long s) void gaddz(GEN x, GEN y, GEN z) int gcmpgs(GEN y, long s) void gdiventz(GEN x, GEN y, GEN z) GEN gdivsg(long s, GEN y) void gdivz(GEN x, GEN y, GEN z) GEN gen_I() void gerepileall(pari_sp av, int n, ...) void gerepilecoeffs(pari_sp av, GEN x, int n) GEN gerepilecopy(pari_sp av, GEN x) void gerepilemany(pari_sp av, GEN* g[], int n) int gequalgs(GEN y, long s) GEN gerepileupto(pari_sp av, GEN q) GEN gerepileuptoint(pari_sp av, GEN q) GEN gerepileuptoleaf(pari_sp av, GEN q) GEN gmaxsg(long s, GEN y) GEN gminsg(long s, GEN y) void gmodz(GEN x, GEN y, GEN z) void gmul2nz(GEN x, long s, GEN z) GEN gmulgs(GEN y, long s) void gmulz(GEN x, GEN y, GEN z) void gnegz(GEN x, GEN z) void gshiftz(GEN x, long s, GEN z) GEN gsubgs(GEN y, long s) void gsubz(GEN x, GEN y, GEN z) double gtodouble(GEN x) GEN gtofp(GEN z, long prec) GEN gtomp(GEN z, long prec) long gtos(GEN x) long gval(GEN x, long v) GEN identity_perm(long l) int equali1(GEN n) int equalim1(GEN n) long inf_get_sign(GEN x) int is_bigint(GEN n) int is_const_t(long t) int is_extscalar_t(long t) int is_intreal_t(long t) int is_matvec_t(long t) int is_noncalc_t(long tx) int is_pm1(GEN n) int is_rational_t(long t) int is_real_t(long t) int is_recursive_t(long t) int is_scalar_t(long t) int is_universal_constant(GEN x) int is_vec_t(long t) int isint1(GEN x) int isintm1(GEN x) int isintzero(GEN x) int ismpzero(GEN x) int isonstack(GEN x) void killblock(GEN x) GEN leading_coeff(GEN x) void lg_increase(GEN x) long lgcols(GEN x) long lgpol(GEN x) GEN matpascal(long n) GEN matslice(GEN A, long x1, long x2, long y1, long y2) GEN mkcol(GEN x) GEN mkcol2(GEN x, GEN y) GEN mkcol2s(long x, long y) GEN mkcol3(GEN x, GEN y, GEN z) GEN mkcol3s(long x, long y, long z) GEN mkcol4(GEN x, GEN y, GEN z, GEN t) GEN mkcol4s(long x, long y, long z, long t) GEN mkcol5(GEN x, GEN y, GEN z, GEN t, GEN u) GEN mkcol6(GEN x, GEN y, GEN z, GEN t, GEN u, GEN v) GEN mkcolcopy(GEN x) GEN mkcols(long x) GEN mkcomplex(GEN x, GEN y) GEN mkerr(long n) GEN mkmoo() GEN mkoo() GEN mkfrac(GEN x, GEN y) GEN mkfracss(long x, long y) GEN mkfraccopy(GEN x, GEN y) GEN mkintmod(GEN x, GEN y) GEN mkintmodu(ulong x, ulong y) GEN mkmat(GEN x) GEN mkmat2(GEN x, GEN y) GEN mkmat3(GEN x, GEN y, GEN z) GEN mkmat4(GEN x, GEN y, GEN z, GEN t) GEN mkmat5(GEN x, GEN y, GEN z, GEN t, GEN u) GEN mkmatcopy(GEN x) GEN mkpolmod(GEN x, GEN y) GEN mkqfi(GEN x, GEN y, GEN z) GEN mkquad(GEN n, GEN x, GEN y) GEN mkrfrac(GEN x, GEN y) GEN mkrfraccopy(GEN x, GEN y) GEN mkvec(GEN x) GEN mkvec2(GEN x, GEN y) GEN mkvec2copy(GEN x, GEN y) GEN mkvec2s(long x, long y) GEN mkvec3(GEN x, GEN y, GEN z) GEN mkvec3s(long x, long y, long z) GEN mkvec4(GEN x, GEN y, GEN z, GEN t) GEN mkvec4s(long x, long y, long z, long t) GEN mkvec5(GEN x, GEN y, GEN z, GEN t, GEN u) GEN mkveccopy(GEN x) GEN mkvecs(long x) GEN mkvecsmall(long x) GEN mkvecsmall2(long x, long y) GEN mkvecsmall3(long x, long y, long z) GEN mkvecsmall4(long x, long y, long z, long t) void mpcosz(GEN x, GEN z) void mpexpz(GEN x, GEN z) void mplogz(GEN x, GEN z) void mpsinz(GEN x, GEN z) GEN mul_content(GEN cx, GEN cy) GEN mul_denom(GEN cx, GEN cy) long nbits2nlong(long x) long nbits2extraprec(long x) long nbits2ndec(long x) long nbits2prec(long x) long nbits2lg(long x) long nbrows(GEN x) long nchar2nlong(long x) long ndec2nbits(long x) long ndec2nlong(long x) long ndec2prec(long x) void normalize_frac(GEN z) int odd(long x) void pari_free(void *pointer) void* pari_calloc(size_t size) void* pari_malloc(size_t bytes) void* pari_realloc(void *pointer, size_t size) GEN perm_conj(GEN s, GEN t) GEN perm_inv(GEN x) GEN perm_mul(GEN s, GEN t) GEN pol_0(long v) GEN pol_1(long v) GEN pol_x(long v) GEN pol_xn(long n, long v) GEN pol_xnall(long n, long v) GEN pol0_F2x(long sv) GEN pol1_F2x(long sv) GEN polx_F2x(long sv) GEN pol0_Flx(long sv) GEN pol1_Flx(long sv) GEN polx_Flx(long sv) GEN polx_zx(long sv) GEN powii(GEN x, GEN n) GEN powIs(long n) long prec2nbits(long x) double prec2nbits_mul(long x, double y) long prec2ndec(long x) long precdbl(long x) GEN quad_disc(GEN x) GEN qfb_disc(GEN x) GEN qfb_disc3(GEN x, GEN y, GEN z) GEN quadnorm(GEN q) long remsBIL(long n) GEN row(GEN A, long x1) GEN Flm_row(GEN A, long x0) GEN row_i(GEN A, long x0, long x1, long x2) GEN zm_row(GEN x, long i) GEN rowcopy(GEN A, long x0) GEN rowpermute(GEN A, GEN p) GEN rowslice(GEN A, long x1, long x2) GEN rowslicepermute(GEN A, GEN p, long x1, long x2) GEN rowsplice(GEN a, long j) int ser_isexactzero(GEN x) GEN shallowcopy(GEN x) GEN sqrfrac(GEN x) GEN sqrti(GEN x) GEN sqrtnr(GEN x, long n) GEN sqrtr(GEN x) GEN sstoQ(long n, long d) void pari_stack_alloc(pari_stack *s, long nb) void** pari_stack_base(pari_stack *s) void pari_stack_delete(pari_stack *s) void pari_stack_init(pari_stack *s, size_t size, void **data) long pari_stack_new(pari_stack *s) void pari_stack_pushp(pari_stack *s, void *u) long sturm(GEN x) GEN truecoeff(GEN x, long n) GEN trunc_safe(GEN x) GEN vec_ei(long n, long i) GEN vec_append(GEN v, GEN s) GEN vec_lengthen(GEN v, long n) GEN vec_setconst(GEN v, GEN x) GEN vec_shorten(GEN v, long n) GEN vec_to_vecsmall(GEN z) GEN vecpermute(GEN A, GEN p) GEN vecreverse(GEN A) void vecreverse_inplace(GEN y) GEN vecsmallpermute(GEN A, GEN p) GEN vecslice(GEN A, long y1, long y2) GEN vecslicepermute(GEN A, GEN p, long y1, long y2) GEN vecsplice(GEN a, long j) GEN vecsmall_append(GEN V, long s) long vecsmall_coincidence(GEN u, GEN v) GEN vecsmall_concat(GEN u, GEN v) GEN vecsmall_copy(GEN x) GEN vecsmall_ei(long n, long i) long vecsmall_indexmax(GEN x) long vecsmall_indexmin(GEN x) long vecsmall_isin(GEN v, long x) GEN vecsmall_lengthen(GEN v, long n) int vecsmall_lexcmp(GEN x, GEN y) long vecsmall_max(GEN v) long vecsmall_min(GEN v) long vecsmall_pack(GEN V, long base, long mod) int vecsmall_prefixcmp(GEN x, GEN y) GEN vecsmall_prepend(GEN V, long s) GEN vecsmall_reverse(GEN A) GEN vecsmall_shorten(GEN v, long n) GEN vecsmall_to_col(GEN z) GEN vecsmall_to_vec(GEN z) GEN vecsmall_to_vec_inplace(GEN z) void vecsmalltrunc_append(GEN x, long t) GEN vecsmalltrunc_init(long l) void vectrunc_append(GEN x, GEN t) void vectrunc_append_batch(GEN x, GEN y) GEN vectrunc_init(long l) GEN zc_to_ZC(GEN x) GEN zero_F2m(long n, long m) GEN zero_F2m_copy(long n, long m) GEN zero_F2v(long m) GEN zero_F2x(long sv) GEN zero_Flm(long m, long n) GEN zero_Flm_copy(long m, long n) GEN zero_Flv(long n) GEN zero_Flx(long sv) GEN zero_zm(long x, long y) GEN zero_zv(long x) GEN zero_zx(long sv) GEN zerocol(long n) GEN zeromat(long m, long n) GEN zeromatcopy(long m, long n) GEN zeropadic(GEN p, long e) GEN zeropadic_shallow(GEN p, long e) GEN zeropol(long v) GEN zeroser(long v, long e) GEN zerovec(long n) GEN zerovec_block(long len) GEN zm_copy(GEN x) GEN zm_to_zxV(GEN x, long sv) GEN zm_transpose(GEN x) GEN zv_copy(GEN x) GEN zv_to_ZV(GEN x) GEN zv_to_zx(GEN x, long sv) GEN zx_renormalize(GEN x, long l) GEN zx_shift(GEN x, long n) GEN zx_to_zv(GEN x, long N) GEN err_get_compo(GEN e, long i) long err_get_num(GEN e) void pari_err_BUG(const char *f) void pari_err_COMPONENT(const char *f, const char *op, GEN l, GEN x) void pari_err_CONSTPOL(const char *f) void pari_err_COPRIME(const char *f, GEN x, GEN y) void pari_err_DIM(const char *f) void pari_err_DOMAIN(const char *f, const char *v, const char *op, GEN l, GEN x) void pari_err_FILE(const char *f, const char *g) void pari_err_FLAG(const char *f) void pari_err_IMPL(const char *f) void pari_err_INV(const char *f, GEN x) void pari_err_IRREDPOL(const char *f, GEN x) void pari_err_MAXPRIME(ulong c) void pari_err_MODULUS(const char *f, GEN x, GEN y) void pari_err_OP(const char *f, GEN x, GEN y) void pari_err_OVERFLOW(const char *f) void pari_err_PACKAGE(const char *f) void pari_err_PREC(const char *f) void pari_err_PRIME(const char *f, GEN x) void pari_err_PRIORITY(const char *f, GEN x, const char *op, long v) void pari_err_SQRTN(const char *f, GEN x) void pari_err_TYPE(const char *f, GEN x) void pari_err_TYPE2(const char *f, GEN x, GEN y) void pari_err_VAR(const char *f, GEN x, GEN y) void pari_err_ROOTS0(const char *f) # Auto-generated declarations. There are taken from the PARI version # on the system, so they more up-to-date than the above. In case of # conflicting declarations, auto_paridecl should have priority. from .auto_paridecl cimport * cypari2-1.1.4/cypari2/closure.pxd0000644000201600020160000000011713136354561020260 0ustar jdemeyerjdemeyer00000000000000from .gen cimport Gen cpdef Gen objtoclosure(f) cdef void _pari_init_closure() cypari2-1.1.4/requirements.txt0000644000201600020160000000005013136574565020006 0ustar jdemeyerjdemeyer00000000000000setuptools Cython cysignals Sphinx>=1.6 cypari2-1.1.4/setup.py0000755000201600020160000000570413136631317016237 0ustar jdemeyerjdemeyer00000000000000#!/usr/bin/env python import os import sys if "READTHEDOCS" in os.environ: # When building with readthedocs, install the dependencies too. # See https://github.com/rtfd/readthedocs.org/issues/2776 for reqs in ["requirements.txt"]: if os.path.isfile(reqs): from subprocess import check_call check_call([sys.executable, "-m", "pip", "install", "-r", reqs]) # Print PARI/GP defaults and environment variables for debugging from subprocess import Popen, PIPE Popen(["gp", "-f", "-q"], stdin=PIPE).communicate("default()") for item in os.environ.items(): print("%s=%r" % item) from setuptools import setup from distutils.command.build_ext import build_ext as _build_ext from setuptools.command.bdist_egg import bdist_egg as _bdist_egg from setuptools.extension import Extension from autogen import rebuild from autogen.paths import include_dirs, library_dirs # Adapted from Cython's new_build_ext class build_ext(_build_ext): def finalize_options(self): # Check dependencies try: from Cython.Build.Dependencies import cythonize except ImportError as E: sys.stderr.write("Error: {0}\n".format(E)) sys.stderr.write("The installation of cypari2 requires Cython\n") sys.exit(1) try: # We need the header files for cysignals at compile-time import cysignals except ImportError as E: sys.stderr.write("Error: {0}\n".format(E)) sys.stderr.write("The installation of cypari2 requires cysignals\n") sys.exit(1) # Generate auto-generated sources from pari.desc rebuild() self.directives = { "autotestdict.cdef": True, "binding": True, } self.distribution.ext_modules[:] = cythonize( self.distribution.ext_modules, compiler_directives=self.directives) _build_ext.finalize_options(self) class no_egg(_bdist_egg): def run(self): from distutils.errors import DistutilsOptionError raise DistutilsOptionError("The package cypari2 will not function correctly when built as egg. Therefore, it cannot be installed using 'python setup.py install' or 'easy_install'. Instead, use 'pip install' to install cypari2.") setup( name='cypari2', version=open("VERSION").read().strip(), description='An interface to the number theory library libpari', url='https://github.com/defeo/cypari2', author='Many people', author_email="sage-devel@googlegroups.com", license='GNU General Public License, version 2 or later', ext_modules=[Extension("*", ["cypari2/*.pyx"], include_dirs=include_dirs(), library_dirs=library_dirs())], keywords='PARI/GP number theory', packages=['cypari2'], package_dir={'cypari2': 'cypari2'}, package_data={'cypari2': ['declinl.pxi', '*.pxd', '*.h']}, cmdclass=dict(build_ext=build_ext, bdist_egg=no_egg) ) cypari2-1.1.4/setup.cfg0000644000201600020160000000004613236012501016322 0ustar jdemeyerjdemeyer00000000000000[egg_info] tag_build = tag_date = 0 cypari2-1.1.4/cypari2.egg-info/0000755000201600020160000000000013236012500017543 5ustar jdemeyerjdemeyer00000000000000cypari2-1.1.4/cypari2.egg-info/dependency_links.txt0000644000201600020160000000000113236012411023612 0ustar jdemeyerjdemeyer00000000000000 cypari2-1.1.4/cypari2.egg-info/PKG-INFO0000644000201600020160000000057113236012411020644 0ustar jdemeyerjdemeyer00000000000000Metadata-Version: 1.0 Name: cypari2 Version: 1.1.4 Summary: An interface to the number theory library libpari Home-page: https://github.com/defeo/cypari2 Author: Many people Author-email: sage-devel@googlegroups.com License: GNU General Public License, version 2 or later Description-Content-Type: UNKNOWN Description: UNKNOWN Keywords: PARI/GP number theory Platform: UNKNOWN cypari2-1.1.4/cypari2.egg-info/SOURCES.txt0000644000201600020160000000162713236012500021435 0ustar jdemeyerjdemeyer00000000000000LICENSE MANIFEST.in Makefile README.rst VERSION requirements.txt setup.py autogen/__init__.py autogen/args.py autogen/doc.py autogen/generator.py autogen/parser.py autogen/paths.py autogen/ret.py cypari2/__init__.py cypari2/closure.pxd cypari2/closure.pyx cypari2/convert.pxd cypari2/convert.pyx cypari2/cypari.h cypari2/gen.pxd cypari2/gen.pyx cypari2/handle_error.pxd cypari2/handle_error.pyx cypari2/pari_instance.pxd cypari2/pari_instance.pyx cypari2/paridecl.pxd cypari2/paripriv.pxd cypari2/stack.pxd cypari2/stack.pyx cypari2/string_utils.pxd cypari2/string_utils.pyx cypari2/types.pxd cypari2.egg-info/PKG-INFO cypari2.egg-info/SOURCES.txt cypari2.egg-info/dependency_links.txt cypari2.egg-info/top_level.txt docs/Makefile docs/source/closure.rst docs/source/conf.py docs/source/convert.rst docs/source/gen.rst docs/source/handle_error.rst docs/source/index.rst docs/source/pari_instance.rst tests/rundoctest.pycypari2-1.1.4/cypari2.egg-info/top_level.txt0000644000201600020160000000001213236012411022267 0ustar jdemeyerjdemeyer00000000000000* cypari2 cypari2-1.1.4/docs/0000755000201600020160000000000013236012500015430 5ustar jdemeyerjdemeyer00000000000000cypari2-1.1.4/docs/Makefile0000644000201600020160000000114313136354561017106 0ustar jdemeyerjdemeyer00000000000000# Minimal makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = python -msphinx SPHINXPROJ = CyPari2 SOURCEDIR = source BUILDDIR = build # Put it first so that "make" without argument is like "make help". help: @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) .PHONY: help Makefile # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: Makefile @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)cypari2-1.1.4/docs/source/0000755000201600020160000000000013236012500016730 5ustar jdemeyerjdemeyer00000000000000cypari2-1.1.4/docs/source/closure.rst0000644000201600020160000000005613136354561021156 0ustar jdemeyerjdemeyer00000000000000.. automodule:: cypari2.closure :members: cypari2-1.1.4/docs/source/convert.rst0000644000201600020160000000005613136354561021162 0ustar jdemeyerjdemeyer00000000000000.. automodule:: cypari2.convert :members: cypari2-1.1.4/docs/source/pari_instance.rst0000644000201600020160000000006413136354561022320 0ustar jdemeyerjdemeyer00000000000000.. automodule:: cypari2.pari_instance :members: cypari2-1.1.4/docs/source/index.rst0000644000201600020160000000076313136354561020616 0ustar jdemeyerjdemeyer00000000000000.. CyPari2 documentation master file, created by sphinx-quickstart on Thu May 18 16:07:32 2017. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. Welcome to CyPari2's documentation! =================================== .. toctree:: :maxdepth: 2 :caption: Contents: pari_instance gen closure handle_error convert Indices and tables ================== * :ref:`genindex` * :ref:`modindex` * :ref:`search` cypari2-1.1.4/docs/source/handle_error.rst0000644000201600020160000000006313136354561022144 0ustar jdemeyerjdemeyer00000000000000.. automodule:: cypari2.handle_error :members: cypari2-1.1.4/docs/source/conf.py0000644000201600020160000001250513146532161020244 0ustar jdemeyerjdemeyer00000000000000# -*- coding: utf-8 -*- # # CyPari2 documentation build configuration file, created by # sphinx-quickstart on Thu May 18 16:07:32 2017. # # This file is execfile()d with the current directory set to its # containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # # import os # import sys # sys.path.insert(0, os.path.abspath('.')) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. # needs_sphinx = '1.6' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.mathjax', 'sphinx.ext.extlinks', ] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] source_suffix = '.rst' # The master toctree document. master_doc = 'index' # General information about the project. project = u'CyPari2' copyright = u'2017, Many people' author = u'Many people' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. version = open("../../VERSION").read().strip() # The full version, including alpha/beta/rc tags. release = version # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. language = None # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path exclude_patterns = [] # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # html_theme = 'alabaster' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. # # html_theme_options = {} # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # -- Options for HTMLHelp output ------------------------------------------ # Output file base name for HTML help builder. htmlhelp_basename = 'CyPari2doc' # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). # # 'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). # # 'pointsize': '10pt', # Additional stuff for the LaTeX preamble. # # 'preamble': '', # Latex figure (float) alignment # # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ (master_doc, 'CyPari2.tex', u'CyPari2 Documentation', u'Many People', 'manual'), ] # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ (master_doc, 'cypari2', u'CyPari2 Documentation', [author], 1) ] # -- Options for Texinfo output ------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ (master_doc, 'CyPari2', u'CyPari2 Documentation', author, 'CyPari2', 'One line description of project.', 'Miscellaneous'), ] # Links to external resources (copied from Sage) extlinks = { 'trac': ('https://trac.sagemath.org/%s', 'Sage ticket #'), 'wikipedia': ('https://en.wikipedia.org/wiki/%s', 'Wikipedia article '), 'arxiv': ('http://arxiv.org/abs/%s', 'Arxiv '), 'oeis': ('https://oeis.org/%s', 'OEIS sequence '), 'doi': ('https://dx.doi.org/%s', 'doi:'), 'pari': ('http://pari.math.u-bordeaux.fr/dochtml/help/%s', 'pari:'), 'mathscinet': ('http://www.ams.org/mathscinet-getitem?mr=%s', 'MathSciNet ') } # Monkey-patch inspect with Cython support def isfunction(obj): return hasattr(type(obj), "__code__") import inspect inspect.isfunction = isfunction cypari2-1.1.4/docs/source/gen.rst0000644000201600020160000000005213136354561020247 0ustar jdemeyerjdemeyer00000000000000.. automodule:: cypari2.gen :members: cypari2-1.1.4/README.rst0000644000201600020160000000643313165140630016204 0ustar jdemeyerjdemeyer00000000000000CyPari 2 ======== .. image:: https://travis-ci.org/defeo/cypari2.svg?branch=master A Python interface to the number theory library `libpari `_. This library supports both Python 2 and Python 3. Installation ------------ GNU/Linux ^^^^^^^^^ A package `python-cypari2` or `python2-cypari2` or `python3-cypari2` might be available in your package manager. Using pip ^^^^^^^^^ Requirements: - PARI/GP >= 2.8.1 (header files and library) - python >= 2.7 - pip - `cysignals `_ Install cypari2 via the Python Package Index (PyPI) via :: $ pip install cypari2 [--user] (the optional option *--user* allows to install cypari2 for a single user and avoids using pip with administrator rights). Depending on your operating system the pip command might also be called pip2 or pip3. If you want to try the development version use :: $ pip install git+https://github.com/defeo/cypari2.git [--user] If you have an error saying libpari-gmp*.so* is missing and have all requirements already installed, try to reinstall cysignals and cypari2 :: $ pip install cysignals --upgrade [--user] $ pip install cypari2 --upgrade [--user] Other ^^^^^ Any other way to install cypari2 is not supported. In particular, ``python setup.py install`` will produce an error. Usage ----- The interface as been kept as close as possible from PARI/GP. The following computation in GP :: ? zeta(2) %1 = 1.6449340668482264364724151666460251892 ? p = x^3 + x^2 + x - 1; ? modulus = t^3 + t^2 + t - 1; ? fq = factorff(p, 3, modulus); ? centerlift(lift(fq)) %5 = [ x - t 1] [x + (t^2 + t - 1) 1] [ x + (-t^2 - 1) 1] translates into :: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari(2).zeta() 1.64493406684823 >>> p = pari("x^3 + x^2 + x - 1") >>> modulus = pari("t^3 + t^2 + t - 1") >>> fq = p.factorff(3, modulus) >>> fq.lift().centerlift() [x - t, 1; x + (t^2 + t - 1), 1; x + (-t^2 - 1), 1] The object **pari** above is the object for the interface and acts as a constructor. It can be called with basic Python objects like integer or floating point. When called with a string as in the last example the corresponding string is interpreted as if it was executed in a GP shell. Beyond the interface object **pari** of type **Pari**, any object you get a handle on is of type **Gen** (that is a wrapper around the **GEN** type from libpari). All PARI/GP functions are then available in their original names as *methods* like **zeta**, **factorff**, **lift** or **centerlift** above. Alternatively, the pari functions are accessible as methods of **pari**. The same computations be done via :: >>> import cypari2 >>> pari = cypari2.Pari() >>> pari.zeta(2) 1.64493406684823 >>> p = pari("x^3 + x^2 + x - 1") >>> modulus = pari("t^3 + t^2 + t - 1") >>> fq = pari.factorff(p, 3, modulus) >>> pari.centerlift(pari.lift(fq)) [x - t, 1; x + (t^2 + t - 1), 1; x + (-t^2 - 1), 1] The complete documentation of cypari2 is available at http://cypari2.readthedocs.io and the PARI/GP documentation at http://pari.math.u-bordeaux.fr/doc.html Contributing ------------ Submit pull request or get in contact with `Luca De Feo `_. cypari2-1.1.4/MANIFEST.in0000644000201600020160000000025313147236314016252 0ustar jdemeyerjdemeyer00000000000000include LICENSE README.rst VERSION global-include *.py *.pyx *.pxd *.pxi recursive-exclude cypari2 auto_* global-exclude *.c .gitignore .travis* readthedocs* prune dist cypari2-1.1.4/autogen/0000755000201600020160000000000013236012500016142 5ustar jdemeyerjdemeyer00000000000000cypari2-1.1.4/autogen/doc.py0000644000201600020160000003436113227220776017310 0ustar jdemeyerjdemeyer00000000000000# -*- coding: utf-8 -*- """ Handle PARI documentation """ from __future__ import unicode_literals import re import subprocess leading_ws = re.compile("^( +)", re.MULTILINE) trailing_ws = re.compile("( +)$", re.MULTILINE) double_space = re.compile(" +") end_space = re.compile(r"(@\[end[a-z]*\])([A-Za-z])") begin_verb = re.compile(r"@1") end_verb = re.compile(r"@[23] *@\[endcode\]") verb_loop = re.compile("^( .*)@\[[a-z]*\]", re.MULTILINE) dollars = re.compile(r"@\[dollar\]\s*(.*?)\s*@\[dollar\]", re.DOTALL) doubledollars = re.compile(r"@\[doubledollar\]\s*(.*?)\s*@\[doubledollar\]", re.DOTALL) math_loop = re.compile(r"(@\[start[A-Z]*MATH\][^@]*)@\[[a-z]*\]") math_backslash = re.compile(r"(@\[start[A-Z]*MATH\][^@]*)=BACKSLASH=") prototype = re.compile("^[^\n]*\n\n") library_syntax = re.compile("The library syntax is.*", re.DOTALL) newlines = re.compile("\n\n\n\n*") bullet_loop = re.compile("(@BULLET( [^\n]*\n)*)([^ \n])") indent_math = re.compile("(@\\[startDISPLAYMATH\\].*\n(.+\n)*)(\\S)") escape_backslash = re.compile(r"^(\S.*)[\\]", re.MULTILINE) escape_mid = re.compile(r"^(\S.*)[|]", re.MULTILINE) escape_percent = re.compile(r"^(\S.*)[%]", re.MULTILINE) escape_hash = re.compile(r"^(\S.*)[#]", re.MULTILINE) label_define = re.compile(r"@\[label [a-zA-Z0-9:]*\]") label_ref = re.compile(r"(Section *)?@\[startref\](se:)?([^@]*)@\[endref\]") def sub_loop(regex, repl, text): """ In ``text``, substitute ``regex`` by ``repl`` recursively. As long as substitution is possible, ``regex`` is substituted. INPUT: - ``regex`` -- a compiled regular expression - ``repl`` -- replacement text - ``text`` -- input text OUTPUT: substituted text EXAMPLES: Ensure there a space between any 2 letters ``x``:: >>> from autogen.doc import sub_loop >>> import re >>> print(sub_loop(re.compile("xx"), "x x", "xxx_xx")) x x x_x x """ while True: text, n = regex.subn(repl, text) if not n: return text def raw_to_rest(doc): r""" Convert raw PARI documentation (with ``@``-codes) to reST syntax. INPUT: - ``doc`` -- the raw PARI documentation OUTPUT: a unicode string EXAMPLES:: >>> from autogen.doc import raw_to_rest >>> print(raw_to_rest(b"@[startbold]hello world@[endbold]")) :strong:`hello world` TESTS:: >>> raw_to_rest(b"@[invalid]") Traceback (most recent call last): ... SyntaxError: @ found: @[invalid] >>> s = b'@3@[startbold]*@[endbold] snip @[dollar]0@[dollar]\ndividing @[dollar]#E@[dollar].' >>> print(raw_to_rest(s)) - snip :math:`0` dividing :math:`\#E`. """ doc = doc.decode("utf-8") # Work around a specific problem with doc of "component" doc = doc.replace("[@[dollar]@[dollar]]", "[]") # Work around a specific problem with doc of "algdivl" doc = doc.replace(r"\y@", r"\backslash y@") # Special characters doc = doc.replace("@[lt]", "<") doc = doc.replace("@[gt]", ">") doc = doc.replace("@[pm]", "±") doc = doc.replace("@[nbrk]", "\xa0") doc = doc.replace("@[agrave]", "à") doc = doc.replace("@[aacute]", "á") doc = doc.replace("@[eacute]", "é") doc = doc.replace("@[ouml]", "ö") doc = doc.replace("@[uuml]", "ü") doc = doc.replace("\\'{a}", "á") # Remove leading and trailing whitespace from every line doc = leading_ws.sub("", doc) doc = trailing_ws.sub("", doc) # Remove multiple spaces doc = double_space.sub(" ", doc) # Sphinx dislikes inline markup immediately followed by a letter: # insert a non-breaking space doc = end_space.sub("\\1\xa0\\2", doc) # Fix labels and references doc = label_define.sub("", doc) doc = label_ref.sub("``\\3`` (in the PARI manual)", doc) # Bullet items doc = doc.replace("@3@[startbold]*@[endbold] ", "@BULLET ") doc = sub_loop(bullet_loop, "\\1 \\3", doc) doc = doc.replace("@BULLET ", "- ") # Add =VOID= in front of all leading whitespace (which was # intentionally added) to avoid confusion with verbatim blocks. doc = leading_ws.sub(r"=VOID=\1", doc) # Verbatim blocks doc = begin_verb.sub("::\n\n@0", doc) doc = end_verb.sub("", doc) doc = doc.replace("@0", " ") doc = doc.replace("@3", "") # Remove all further markup from within verbatim blocks doc = sub_loop(verb_loop, "\\1", doc) # Pair dollars -> beginmath/endmath doc = doc.replace("@[dollar]@[dollar]", "@[doubledollar]") doc = dollars.sub(r"@[startMATH]\1@[endMATH]", doc) doc = doubledollars.sub(r"@[startDISPLAYMATH]\1@[endDISPLAYMATH]", doc) # Replace special characters (except in verbatim blocks) # \ -> =BACKSLASH= # | -> =MID= # % -> =PERCENT= # # -> =HASH= doc = sub_loop(escape_backslash, "\\1=BACKSLASH=", doc) doc = sub_loop(escape_mid, "\\1=MID=", doc) doc = sub_loop(escape_percent, "\\1=PERCENT=", doc) doc = sub_loop(escape_hash, "\\1=HASH=", doc) # Math markup doc = doc.replace("@[obr]", "{") doc = doc.replace("@[cbr]", "}") doc = doc.replace("@[startword]", "\\") doc = doc.replace("@[endword]", "") # (special rules for Hom and Frob, see trac ticket 21005) doc = doc.replace("@[startlword]Hom@[endlword]", "\\text{Hom}") doc = doc.replace("@[startlword]Frob@[endlword]", "\\text{Frob}") doc = doc.replace("@[startlword]", "\\") doc = doc.replace("@[endlword]", "") doc = doc.replace("@[startbi]", "\\mathbb{") doc = doc.replace("@[endbi]", "}") # PARI TeX macros doc = doc.replace(r"\Cl", r"\mathrm{Cl}") doc = doc.replace(r"\Id", r"\mathrm{Id}") doc = doc.replace(r"\Norm", r"\mathrm{Norm}") doc = doc.replace(r"\disc", r"\mathrm{disc}") doc = doc.replace(r"\gcd", r"\mathrm{gcd}") doc = doc.replace(r"\lcm", r"\mathrm{lcm}") # Remove extra markup inside math blocks doc = sub_loop(math_loop, "\\1", doc) # Replace special characters by escape sequences # Note that =BACKSLASH= becomes an unescaped backslash in math mode # but an escaped backslash otherwise. doc = sub_loop(math_backslash, r"\1\\", doc) doc = doc.replace("=BACKSLASH=", r"\\") doc = doc.replace("=MID=", r"\|") doc = doc.replace("=PERCENT=", r"\%") doc = doc.replace("=HASH=", r"\#") doc = doc.replace("=VOID=", "") # Handle DISPLAYMATH doc = doc.replace("@[endDISPLAYMATH]", "\n\n") doc = sub_loop(indent_math, "\\1 \\3", doc) doc = doc.replace("@[startDISPLAYMATH]", "\n\n.. MATH::\n\n ") # Inline markup. We do use the more verbose :foo:`text` style since # those nest more easily. doc = doc.replace("@[startMATH]", ":math:`") doc = doc.replace("@[endMATH]", "`") doc = doc.replace("@[startpodcode]", "``") doc = doc.replace("@[endpodcode]", "``") doc = doc.replace("@[startcode]", ":literal:`") doc = doc.replace("@[endcode]", "`") doc = doc.replace("@[startit]", ":emphasis:`") doc = doc.replace("@[endit]", "`") doc = doc.replace("@[startbold]", ":strong:`") doc = doc.replace("@[endbold]", "`") # Remove prototype doc = prototype.sub("", doc) # Remove everything starting with "The library syntax is" # (this is not relevant for Python) doc = library_syntax.sub("", doc) # Allow at most 2 consecutive newlines doc = newlines.sub("\n\n", doc) # Strip result doc = doc.strip() # Ensure no more @ remains try: i = doc.index("@") except ValueError: return doc ilow = max(0, i-30) ihigh = min(len(doc), i+30) raise SyntaxError("@ found: " + doc[ilow:ihigh]) def get_raw_doc(function): r""" Get the raw documentation of PARI function ``function``. INPUT: - ``function`` -- name of a PARI function EXAMPLES:: >>> from autogen.doc import get_raw_doc >>> print(get_raw_doc("cos").decode()) @[startbold]cos@[dollar](x)@[dollar]:@[endbold] @[label se:cos] Cosine of @[dollar]x@[dollar]. The library syntax is @[startcode]GEN @[startbold]gcos@[endbold](GEN x, long prec)@[endcode]. >>> get_raw_doc("abcde") Traceback (most recent call last): ... RuntimeError: no help found for 'abcde' """ doc = subprocess.check_output(["gphelp", "-raw", function]) if doc.endswith(b"""' not found !\n"""): raise RuntimeError("no help found for '{}'".format(function)) return doc def get_rest_doc(function): r""" Get the documentation of the PARI function ``function`` in reST syntax. INPUT: - ``function`` -- name of a PARI function EXAMPLES:: >>> from autogen.doc import get_rest_doc >>> print(get_rest_doc("teichmuller")) Teichmüller character of the :math:`p`-adic number :math:`x`, i.e. the unique :math:`(p-1)`-th root of unity congruent to :math:`x / p^{v_p(x)}` modulo :math:`p`... :: >>> print(get_rest_doc("weber")) One of Weber's three :math:`f` functions. If :math:`flag = 0`, returns .. MATH:: f(x) = \exp(-i\pi/24).\eta((x+1)/2)/\eta(x) {such that} j = (f^{24}-16)^3/f^{24}, where :math:`j` is the elliptic :math:`j`-invariant (see the function :literal:`ellj`). If :math:`flag = 1`, returns .. MATH:: f_1(x) = \eta(x/2)/\eta(x) {such that} j = (f_1^{24}+16)^3/f_1^{24}. Finally, if :math:`flag = 2`, returns .. MATH:: f_2(x) = \sqrt{2}\eta(2x)/\eta(x) {such that} j = (f_2^{24}+16)^3/f_2^{24}. Note the identities :math:`f^8 = f_1^8+f_2^8` and :math:`ff_1f_2 = \sqrt2`. :: >>> print(get_rest_doc("ellap")) Let :math:`E` be an :literal:`ell` structure as output by :literal:`ellinit`, defined over a number field...computes the trace of Frobenius :math:`t` for the elliptic curve :math:`E`, defined by the equation :math:`\#E(\mathbb{F}_q) = q+1 - t` (for primes of good reduction). When the characteristic of the finite field is large, the availability of the :literal:`seadata` package will speed the computation. If the curve is defined over :math:`\mathbb{Q}`, :math:`p` must be explicitly given and the function computes the trace of the reduction over :math:`\mathbb{F}_p`. The trace of Frobenius is also the :math:`a_p` coefficient in the curve :math:`L`-series :math:`L(E,s) = \sum_n a_n n^{-s}`, whence the function name. The equation must be integral at :math:`p` but need not be minimal at :math:`p`; of course, a minimal model will be more efficient. ... :: ? E = ellinit([0,1]); \\ y^2 = x^3 + 0.x + 1, defined over Q ? ellap(E, 7) \\ 7 necessary here %2 = -4 \\ #E(F_7) = 7+1-(-4) = 12 ? ellcard(E, 7) %3 = 12 \\ OK ? E = ellinit([0,1], 11); \\ defined over F_11 ? ellap(E) \\ no need to repeat 11 %4 = 0 ? ellap(E, 11) \\ ... but it also works %5 = 0 ? ellgroup(E, 13) \\ ouch, inconsistent input! *** at top-level: ellap(E,13) *** ^----------- *** ellap: inconsistent moduli in Rg_to_Fp: 11 13... ? Fq = ffgen(ffinit(11,3), 'a); \\ defines F_q := F_{11^3} ? E = ellinit([a+1,a], Fq); \\ y^2 = x^3 + (a+1)x + a, defined over F_q ? ellap(E) %8 = -3 If the curve is defined over a more general number field than :math:`\mathbb{Q}`, the maximal ideal :math:`p` must be explicitly given in :literal:`idealprimedec` format... :: ? K = nfinit(a^2+1); E = ellinit([1+a,0,1,0,0], K); ? fa = idealfactor(K, E.disc) %2 = [ [5, [-2, 1]~, 1, 1, [2, -1; 1, 2]] 1] [[13, [5, 1]~, 1, 1, [-5, -1; 1, -5]] 2] ? ellap(E, fa[1,1]) %3 = -1 \\ non-split multiplicative reduction ? ellap(E, fa[2,1]) %4 = 1 \\ split multiplicative reduction ? P17 = idealprimedec(K,17)[1]; ? ellap(E, P17) %6 = 6 \\ good reduction ? E2 = ellchangecurve(E, [17,0,0,0]); ? ellap(E2, P17) %8 = 6 \\ same, starting from a non-miminal model ? P3 = idealprimedec(K,3)[1]; ? E3 = ellchangecurve(E, [3,0,0,0]); ? ellap(E, P3) \\ OK: E is minimal at P3 %11 = -2 ? ellap(E3, P3) \\ junk: E3 is not minimal at P3 | 3 %12 = 0 :strong:`Algorithms used.` If :math:`E/\mathbb{F}_q` has CM by a principal imaginary quadratic order we use a fast explicit formula (involving essentially Kronecker symbols and Cornacchia's algorithm), in :math:`O(\log q)^2`. Otherwise, we use Shanks-Mestre's baby-step/giant-step method, which runs in time :math:`~{O}(q^{1/4})` using :math:`~{O}(q^{1/4})` storage, hence becomes unreasonable when :math:`q` has about 30 digits. Above this range, the :literal:`SEA` algorithm becomes available, heuristically in :math:`~{O}(\log q)^4`, and primes of the order of 200 digits become feasible. In small characteristic we use Mestre's (p = 2), Kohel's (p = 3,5,7,13), Satoh-Harley (all in :math:`~{O}(p^{2} n^2)`) or Kedlaya's (in :math:`~{O}(p n^3)`) algorithms. :: >>> print(get_rest_doc("bitor")) bitwise (inclusive) :literal:`or` of two integers :math:`x` and :math:`y`, that is the integer .. MATH:: \sum (x_i or y_i) 2^i See ``bitand`` (in the PARI manual) for the behavior for negative arguments. """ raw = get_raw_doc(function) return raw_to_rest(raw) cypari2-1.1.4/autogen/parser.py0000644000201600020160000001344213151535061020024 0ustar jdemeyerjdemeyer00000000000000""" Read and parse the file pari.desc """ #***************************************************************************** # Copyright (C) 2015 Jeroen Demeyer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** from __future__ import absolute_import, unicode_literals import os, re, io from .args import pari_arg_types from .ret import pari_ret_types from .paths import pari_share paren_re = re.compile(r"[(](.*)[)]") argname_re = re.compile(r"[ {]*([A-Za-z_][A-Za-z0-9_]*)") def read_pari_desc(): """ Read and parse the file ``pari.desc``. The output is a dictionary where the keys are GP function names and the corresponding values are dictionaries containing the ``(key, value)`` pairs from ``pari.desc``. EXAMPLES:: >>> from autogen.parser import read_pari_desc >>> D = read_pari_desc() >>> D["cos"] == { 'class': 'basic', ... 'cname': 'gcos', ... 'doc': 'cosine of $x$.', ... 'function': 'cos', ... 'help': 'cos(x): cosine of x.', ... 'prototype': 'Gp', ... 'section': 'transcendental'} True """ pari_desc = os.path.join(pari_share(), 'pari.desc') with io.open(pari_desc, encoding="utf-8") as f: lines = f.readlines() n = 0 N = len(lines) functions = {} while n < N: fun = {} while True: L = lines[n]; n += 1 if L == "\n": break # As long as the next lines start with a space, append them while lines[n].startswith(" "): L += (lines[n])[1:]; n += 1 key, value = L.split(":", 1) # Change key to an allowed identifier name key = key.lower().replace("-", "") fun[key] = value.strip() name = fun["function"] functions[name] = fun return functions def parse_prototype(proto, help, initial_args=[]): """ Parse arguments and return type of a PARI function. INPUT: - ``proto`` -- a PARI prototype like ``"GD0,L,DGDGDG"`` - ``help`` -- a PARI help string like ``"qfbred(x,{flag=0},{d},{isd},{sd})"`` - ``initial_args`` -- other arguments to this function which come before the PARI arguments, for example a ``self`` argument. OUTPUT: a tuple ``(args, ret)`` where - ``args`` is a list consisting of ``initial_args`` followed by :class:`PariArgument` instances with all arguments of this function. - ``ret`` is a :class:`PariReturn` instance with the return type of this function. EXAMPLES:: >>> from autogen.parser import parse_prototype >>> proto = 'GD0,L,DGDGDG' >>> help = 'qfbred(x,{flag=0},{d},{isd},{sd})' >>> parse_prototype(proto, help) ([GEN x, long flag=0, GEN d=NULL, GEN isd=NULL, GEN sd=NULL], GEN) >>> parse_prototype("lp", "foo()", [str("TEST")]) (['TEST', prec precision=0], long) """ # Use the help string just for the argument names. # "names" should be an iterator over the argument names. m = paren_re.search(help) if m is None: names = iter([]) else: s = m.groups()[0] matches = [argname_re.match(x) for x in s.split(",")] names = (m.groups()[0] for m in matches if m is not None) # First, handle the return type try: c = proto[0] t = pari_ret_types[c] n = 1 # index in proto except (IndexError, KeyError): t = pari_ret_types[""] n = 0 # index in proto ret = t() # Go over the prototype characters and build up the arguments args = list(initial_args) have_default = False # Have we seen any default argument? while n < len(proto): c = proto[n]; n += 1 # Parse default value if c == "D": default = "" if proto[n] not in pari_arg_types: while True: c = proto[n]; n += 1 if c == ",": break default += c c = proto[n]; n += 1 else: default = None try: t = pari_arg_types[c] if t is None: raise NotImplementedError('unsupported prototype character %r' % c) except KeyError: if c == ",": continue # Just skip additional commas else: raise ValueError('unknown prototype character %r' % c) arg = t(names, default, index=len(args)) if arg.default is not None: have_default = True elif have_default: # We have a non-default argument following a default # argument, which means trouble... # # A syntactical wart of Python is that it does not allow # that: something like def foo(x=None, y) is a SyntaxError # (at least with Python-2.7.13, Python-3.6.1 and Cython-0.25.2) # # A small number of GP functions (nfroots() for example) # wants to do this anyway. Luckily, this seems to occur only # for arguments of type GEN (prototype code "G") # # To work around this, we add a "fake" default value and # then raise an error if it was not given... if c != "G": raise NotImplementedError("non-default argument after default argument is only implemented for GEN arguments") arg.default = False args.append(arg) return (args, ret) cypari2-1.1.4/autogen/paths.py0000644000201600020160000000466413152004515017651 0ustar jdemeyerjdemeyer00000000000000""" Find out installation paths of PARI/GP """ #***************************************************************************** # Copyright (C) 2017 Jeroen Demeyer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** from __future__ import absolute_import, unicode_literals import os from glob import glob from distutils.spawn import find_executable # find_executable() returns None if nothing was found gppath = find_executable("gp") if gppath is None: # This almost certainly won't work, but we need to put something here prefix = "." else: # Assume gppath is ${prefix}/bin/gp prefix = os.path.dirname(os.path.dirname(gppath)) def pari_share(): r""" Return the directory where the PARI data files are stored. EXAMPLES:: >>> from autogen.parser import pari_share >>> pari_share().endswith('/share/pari') True """ from subprocess import Popen, PIPE if not gppath: raise EnvironmentError("cannot find an installation of PARI/GP: make sure that the 'gp' program is in your $PATH") gp = Popen([gppath, "-f", "-q"], stdin=PIPE, stdout=PIPE) out = gp.communicate(b"print(default(datadir))")[0] # Convert out to str if needed if not isinstance(out, str): from sys import getfilesystemencoding out = out.decode(getfilesystemencoding(), "surrogateescape") datadir = out.strip() if not os.path.isdir(datadir): # As a fallback, try a path relative to the prefix datadir = os.path.join(prefix, "share", "pari") if not os.path.isdir(datadir): raise EnvironmentError("PARI data directory {!r} does not exist".format(datadir)) return datadir def include_dirs(): """ Return the directory containing PARI include files. """ dirs = [os.path.join(prefix, "include")] return [d for d in dirs if os.path.isdir(os.path.join(d, "pari"))] def library_dirs(): """ Return the directory containing PARI library files. """ dirs = [os.path.join(prefix, s) for s in ("lib", "lib32", "lib64")] return [d for d in dirs if glob(os.path.join(d, "libpari*"))] cypari2-1.1.4/autogen/generator.py0000644000201600020160000003073713236012275020525 0ustar jdemeyerjdemeyer00000000000000""" Auto-generate methods for PARI functions. """ #***************************************************************************** # Copyright (C) 2015 Jeroen Demeyer # 2017 Vincent Delecroix # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** from __future__ import absolute_import, print_function, unicode_literals import os, re, sys, io from .args import PariArgumentGEN, PariInstanceArgument from .parser import read_pari_desc, parse_prototype from .doc import get_rest_doc autogen_top = "# This file is auto-generated by {}\n".format( os.path.relpath(__file__)) gen_banner = autogen_top + ''' cdef class Gen_auto: """ Part of the :class:`Gen` class containing auto-generated functions. This class is not meant to be used directly, use the derived class :class:`Gen` instead. """ ''' instance_banner = autogen_top + ''' cdef class Pari_auto: """ Part of the :class:`Pari` class containing auto-generated functions. You must never use this class directly (in fact, Python may crash if you do), use the derived class :class:`Pari` instead. """ ''' decl_banner = autogen_top + ''' from .types cimport * cdef extern from *: ''' function_re = re.compile(r"^[A-Za-z][A-Za-z0-9_]*$") function_blacklist = {"O", # O(p^e) needs special parser support "alias", # Not needed and difficult documentation "listcreate", # "redundant and obsolete" according to PARI "allocatemem", # Better hand-written support in Pari class "global", # Invalid in Python (and obsolete) "inline", # Total confusion "uninline", # idem "local", # idem "my", # idem } class PariFunctionGenerator(object): """ Class to auto-generate ``auto_gen.pxi`` and ``auto_instance.pxi``. The PARI file ``pari.desc`` is read and all suitable PARI functions are written as methods of either :class:`Gen` or :class:`Pari`. """ def __init__(self): self.gen_filename = os.path.join('cypari2', 'auto_gen.pxi') self.instance_filename = os.path.join('cypari2', 'auto_instance.pxi') self.decl_filename = os.path.join('cypari2', 'auto_paridecl.pxd') def can_handle_function(self, function, cname="", **kwds): """ Can we actually handle this function? EXAMPLES:: >>> from autogen.generator import PariFunctionGenerator >>> G = PariFunctionGenerator() >>> G.can_handle_function("bnfinit", "bnfinit0", **{"class":"basic"}) True >>> G.can_handle_function("_bnfinit", "bnfinit0", **{"class":"basic"}) False >>> G.can_handle_function("bnfinit", "bnfinit0", **{"class":"hard"}) False """ if function in function_blacklist: # Blacklist specific troublesome functions return False if not function_re.match(function): # Not a legal function name, like "!_" return False cls = kwds.get("class", "unknown") sec = kwds.get("section", "unknown") if cls != "basic": # Different class: probably something technical or # specific to gp or gp2c return False if sec == "programming/control": # Skip if, return, break, ... return False return True def handle_pari_function(self, function, cname, prototype="", help="", obsolete=None, **kwds): r""" Handle one PARI function: decide whether or not to add the function, in which file (as method of :class:`Gen` or of :class:`Pari`?) and call :meth:`write_method` to actually write the code. EXAMPLES:: >>> from autogen.parser import read_pari_desc >>> from autogen.generator import PariFunctionGenerator >>> G = PariFunctionGenerator() >>> G.gen_file = sys.stdout >>> G.instance_file = sys.stdout >>> G.decl_file = sys.stdout >>> G.handle_pari_function("bnfinit", ... cname="bnfinit0", prototype="GD0,L,DGp", ... help=r"bnfinit(P,{flag=0},{tech=[]}): compute...", ... **{"class":"basic", "section":"number_fields"}) GEN bnfinit0(GEN, long, GEN, long) def bnfinit(P, long flag=0, tech=None, long precision=0): ... cdef GEN _P = P.g cdef GEN _tech = NULL if tech is not None: tech = objtogen(tech) _tech = (tech).g precision = prec_bits_to_words(precision) sig_on() cdef GEN _ret = bnfinit0(_P, flag, _tech, precision) return new_gen(_ret) ... >>> G.handle_pari_function("ellmodulareqn", ... cname="ellmodulareqn", prototype="LDnDn", ... help=r"ellmodulareqn(N,{x},{y}): return...", ... **{"class":"basic", "section":"elliptic_curves"}) GEN ellmodulareqn(long, long, long) def ellmodulareqn(self, long N, x=None, y=None): ... cdef long _x = -1 if x is not None: _x = get_var(x) cdef long _y = -1 if y is not None: _y = get_var(y) sig_on() cdef GEN _ret = ellmodulareqn(N, _x, _y) return new_gen(_ret) >>> G.handle_pari_function("setrand", ... cname="setrand", prototype="vG", ... help=r"setrand(n): reset the seed...", ... doc=r"reseeds the random number generator...", ... **{"class":"basic", "section":"programming/specific"}) void setrand(GEN) def setrand(n): r''' Reseeds the random number generator... ''' cdef GEN _n = n.g sig_on() setrand(_n) clear_stack() def setrand(self, n): r''' Reseeds the random number generator... ''' n = objtogen(n) cdef GEN _n = (n).g sig_on() setrand(_n) clear_stack() >>> G.handle_pari_function("bernvec", ... cname="bernvec", prototype="L", ... help="bernvec(x): this routine is obsolete, use bernfrac repeatedly.", ... obsolete="2007-03-30", ... **{"class":"basic", "section":"transcendental"}) GEN bernvec(long) def bernvec(self, long x): r''' This routine is obsolete, kept for backward compatibility only. ''' from warnings import warn warn('the PARI/GP function bernvec is obsolete (2007-03-30)', DeprecationWarning) sig_on() cdef GEN _ret = bernvec(x) return new_gen(_ret) """ try: args, ret = parse_prototype(prototype, help) except NotImplementedError: return # Skip unsupported prototype codes doc = get_rest_doc(function) self.write_declaration(cname, args, ret, self.decl_file) if len(args) > 0 and isinstance(args[0], PariArgumentGEN): # If the first argument is a GEN, write a method of the # Gen class. self.write_method(function, cname, args, ret, args, self.gen_file, doc, obsolete) # In any case, write a method of the Pari class. # Parse again with an extra "self" argument. args, ret = parse_prototype(prototype, help, [PariInstanceArgument()]) self.write_method(function, cname, args, ret, args[1:], self.instance_file, doc, obsolete) def write_declaration(self, cname, args, ret, file): """ Write a .pxd declaration of a PARI library function. INPUT: - ``cname`` -- name of the PARI C library call - ``args``, ``ret`` -- output from ``parse_prototype`` - ``file`` -- a file object where the declaration should be written to """ args = ", ".join(a.ctype() for a in args) s = ' {ret} {function}({args})'.format(ret=ret.ctype(), function=cname, args=args) print(s, file=file) def write_method(self, function, cname, args, ret, cargs, file, doc, obsolete): """ Write Cython code with a method to call one PARI function. INPUT: - ``function`` -- name for the method - ``cname`` -- name of the PARI C library call - ``args``, ``ret`` -- output from ``parse_prototype``, including the initial args like ``self`` - ``cargs`` -- like ``args`` but excluding the initial args - ``file`` -- a file object where the code should be written to - ``doc`` -- the docstring for the method - ``obsolete`` -- if ``True``, a deprecation warning will be given whenever this method is called """ doc = doc.replace("\n", "\n ") # Indent doc protoargs = ", ".join(a.prototype_code() for a in args) callargs = ", ".join(a.call_code() for a in cargs) s = " def {function}({protoargs}):\n" if doc: # Use triple single quotes to make it easier to doctest # this within triply double quoted docstrings. s += " r'''\n {doc}\n '''\n" # Warning for obsolete functions if obsolete: s += " from warnings import warn\n" s += " warn('the PARI/GP function {function} is obsolete ({obsolete})', DeprecationWarning)\n" # Warning for undocumented arguments for a in args: s += a.deprecation_warning_code(function) for a in args: s += a.convert_code() s += " sig_on()\n" s += ret.assign_code("{cname}({callargs})") s += ret.return_code() s = s.format(function=function, protoargs=protoargs, cname=cname, callargs=callargs, doc=doc, obsolete=obsolete) print(s, file=file) def __call__(self): """ Top-level function to generate the auto-generated files. """ D = read_pari_desc() D = sorted(D.values(), key=lambda d: d['function']) sys.stdout.write("Generating PARI functions:") self.gen_file = io.open(self.gen_filename + '.tmp', 'w', encoding='utf-8') self.gen_file.write(gen_banner) self.instance_file = io.open(self.instance_filename + '.tmp', 'w', encoding='utf-8') self.instance_file.write(instance_banner) self.decl_file = io.open(self.decl_filename + '.tmp', 'w', encoding='utf-8') self.decl_file.write(decl_banner) # Check for availability of hi-res SVG plotting. This requires # PARI-2.10 or later. have_plot_svg = False for v in D: func = v["function"] if self.can_handle_function(**v): sys.stdout.write(" %s" % func) sys.stdout.flush() self.handle_pari_function(**v) if func == "plothraw": have_plot_svg = True else: sys.stdout.write(" (%s)" % func) sys.stdout.write("\n") self.instance_file.write("DEF HAVE_PLOT_SVG = {}".format(have_plot_svg)) self.gen_file.close() self.instance_file.close() self.decl_file.close() # All done? Let's commit. os.rename(self.gen_filename + '.tmp', self.gen_filename) os.rename(self.instance_filename + '.tmp', self.instance_filename) os.rename(self.decl_filename + '.tmp', self.decl_filename) cypari2-1.1.4/autogen/args.py0000644000201600020160000002623213147552000017462 0ustar jdemeyerjdemeyer00000000000000""" Arguments for PARI calls """ #***************************************************************************** # Copyright (C) 2015 Jeroen Demeyer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** from __future__ import unicode_literals # Some replacements for reserved words replacements = {'char': 'character'} class PariArgument(object): """ This class represents one argument in a PARI call. """ def __init__(self, namesiter, default, index): """ Create a new argument for a PARI call. INPUT: - ``namesiter`` -- iterator over all names of the arguments. Usually, the next name from this iterator is used as argument name. - ``default`` -- default value for this argument (``None`` means that the argument is not optional). - ``index`` -- (integer >= 0). Index of this argument in the list of arguments. Index 0 means a ``"self"`` argument which is treated specially. For a function which is not a method, start counting at 1. """ self.index = index try: self.name = self.get_argument_name(namesiter) except StopIteration: # No more names available, use something default. # This is used in listcreate() and polsturm() for example # which have deprecated arguments which are not listed in # the help. self.name = "_arg%s" % index self.undocumented = True else: self.undocumented = False if self.index == 0: # "self" argument can never have a default self.default = None elif default is None: self.default = self.always_default() elif default == "": self.default = self.default_default() else: self.default = default def __repr__(self): s = self._typerepr() + " " + self.name if self.default is not None: s += "=" + self.default return s def _typerepr(self): """ Return a string representing the type of this argument. """ return "(generic)" def ctype(self): """ The corresponding C type. This is used for auto-generating the declarations of the C function. In some cases, this is also used for passing the argument from Python to Cython. """ raise NotImplementedError def always_default(self): """ If this returns not ``None``, it is a value which is always the default for this argument, which is then automatically optional. """ return None def default_default(self): """ The default value for an optional argument if no other default was specified in the prototype. """ return "NULL" def get_argument_name(self, namesiter): """ Return the name for this argument, given ``namesiter`` which is an iterator over the argument names given by the help string. """ n = next(namesiter) try: return replacements[n] except KeyError: return n def prototype_code(self): """ Return code to appear in the prototype of the Cython wrapper. """ raise NotImplementedError def deprecation_warning_code(self, function): """ Return code to appear in the function body to give a deprecation warning for this argument, if applicable. ``function`` is the function name to appear in the message. """ if not self.undocumented: return "" s = " if {name} is not None:\n" s += " from warnings import warn\n" s += " warn('argument {index} of the PARI/GP function {function} is undocumented and deprecated', DeprecationWarning)\n" return s.format(name=self.name, index=self.index, function=function) def convert_code(self): """ Return code to appear in the function body to convert this argument to something that PARI understand. This code can also contain extra checks. """ return "" def call_code(self): """ Return code to put this argument in a PARI function call. """ return self.name class PariArgumentObject(PariArgument): """ Class for arguments which are passed as generic Python ``object``. """ def __init__(self, *args, **kwds): super(PariArgumentObject, self).__init__(*args, **kwds) self.tmpname = "_" + self.name def prototype_code(self): """ Return code to appear in the prototype of the Cython wrapper. """ s = self.name if self.default is not None: # Default corresponds to None, actual default value should # be handled in convert_code() s += "=None" return s class PariArgumentClass(PariArgument): """ Class for arguments which are passed as a specific C/Cython class. The C/Cython type is given by ``self.ctype()``. """ def prototype_code(self): """ Return code to appear in the prototype of the Cython wrapper. """ s = self.ctype() + " " + self.name if self.default is not None: s += "=" + self.default return s class PariInstanceArgument(PariArgumentObject): """ ``self`` argument for ``Pari`` object. This argument is never actually used. """ def __init__(self): PariArgument.__init__(self, iter(["self"]), None, 0) def _typerepr(self): return "Pari" def ctype(self): return "GEN" class PariArgumentGEN(PariArgumentObject): def _typerepr(self): return "GEN" def ctype(self): return "GEN" def convert_code(self): if self.index == 0: # "self" is always of type Gen, we skip the conversion s = " cdef GEN {tmp} = {name}.g\n" elif self.default is None: s = " {name} = objtogen({name})\n" s += " cdef GEN {tmp} = ({name}).g\n" elif self.default is False: # This is actually a required argument # See parse_prototype() in parser.py why we need this s = " if {name} is None:\n" s += " raise TypeError(\"missing required argument: '{name}'\")\n" s += " {name} = objtogen({name})\n" s += " cdef GEN {tmp} = ({name}).g\n" elif self.default == "NULL": s = " cdef GEN {tmp} = {default}\n" s += " if {name} is not None:\n" s += " {name} = objtogen({name})\n" s += " {tmp} = ({name}).g\n" elif self.default == "0": s = " cdef GEN {tmp}\n" s += " if {name} is None:\n" s += " {tmp} = gen_0\n" s += " else:\n" s += " {name} = objtogen({name})\n" s += " {tmp} = ({name}).g\n" else: raise ValueError("default value %r for GEN argument %r is not supported" % (self.default, self.name)) return s.format(name=self.name, tmp=self.tmpname, default=self.default) def call_code(self): return self.tmpname class PariArgumentString(PariArgumentObject): def _typerepr(self): return "str" def ctype(self): return "char *" def convert_code(self): if self.default is None: s = " {name} = to_bytes({name})\n" s += " cdef char* {tmp} = {name}\n" else: s = " cdef char* {tmp}\n" s += " if {name} is None:\n" s += " {tmp} = {default}\n" s += " else:\n" s += " {name} = to_bytes({name})\n" s += " {tmp} = {name}\n" return s.format(name=self.name, tmp=self.tmpname, default=self.default) def call_code(self): return self.tmpname class PariArgumentVariable(PariArgumentObject): def _typerepr(self): return "var" def ctype(self): return "long" def default_default(self): return "-1" def convert_code(self): if self.default is None: s = " cdef long {tmp} = get_var({name})\n" else: s = " cdef long {tmp} = {default}\n" s += " if {name} is not None:\n" s += " {tmp} = get_var({name})\n" return s.format(name=self.name, tmp=self.tmpname, default=self.default) def call_code(self): return self.tmpname class PariArgumentLong(PariArgumentClass): def _typerepr(self): return "long" def ctype(self): return "long" def default_default(self): return "0" class PariArgumentULong(PariArgumentClass): def _typerepr(self): return "unsigned long" def ctype(self): return "unsigned long" def default_default(self): return "0" class PariArgumentPrec(PariArgumentClass): def _typerepr(self): return "prec" def ctype(self): return "long" def always_default(self): return "0" def get_argument_name(self, namesiter): return "precision" def convert_code(self): s = " {name} = prec_bits_to_words({name})\n" return s.format(name=self.name) class PariArgumentBitprec(PariArgumentClass): def _typerepr(self): return "bitprec" def ctype(self): return "long" def always_default(self): return "0" def get_argument_name(self, namesiter): return "precision" def convert_code(self): s = " if not {name}:\n" s += " {name} = default_bitprec()\n" return s.format(name=self.name) class PariArgumentSeriesPrec(PariArgumentClass): def _typerepr(self): return "serprec" def ctype(self): return "long" def default_default(self): return "-1" def get_argument_name(self, namesiter): return "serprec" def convert_code(self): s = " if {name} < 0:\n" s += " {name} = precdl # Global PARI series precision\n" return s.format(name=self.name) pari_arg_types = { 'G': PariArgumentGEN, 'W': PariArgumentGEN, 'r': PariArgumentString, 's': PariArgumentString, 'L': PariArgumentLong, 'U': PariArgumentULong, 'n': PariArgumentVariable, 'p': PariArgumentPrec, 'b': PariArgumentBitprec, 'P': PariArgumentSeriesPrec, # Codes which are known but not actually supported yet '&': None, 'V': None, 'I': None, 'E': None, 'J': None, 'C': None, '*': None, '=': None} cypari2-1.1.4/autogen/__init__.py0000644000201600020160000000133313151535041020261 0ustar jdemeyerjdemeyer00000000000000from __future__ import absolute_import import glob import os from os.path import join, getmtime, exists from .generator import PariFunctionGenerator from .paths import pari_share def rebuild(force=False): pari_module_path = 'cypari2' src_files = [join(pari_share(), 'pari.desc')] + \ glob.glob(join('autogen', '*.py')) gen_files = [join(pari_module_path, 'auto_paridecl.pxd'), join(pari_module_path, 'auto_gen.pxi')] if not force and all(exists(f) for f in gen_files): src_mtime = max(getmtime(f) for f in src_files) gen_mtime = min(getmtime(f) for f in gen_files) if gen_mtime > src_mtime: return G = PariFunctionGenerator() G() cypari2-1.1.4/autogen/ret.py0000644000201600020160000000446613147552061017334 0ustar jdemeyerjdemeyer00000000000000""" Return types for PARI calls """ #***************************************************************************** # Copyright (C) 2015 Jeroen Demeyer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # http://www.gnu.org/licenses/ #***************************************************************************** from __future__ import unicode_literals class PariReturn(object): """ This class represents the return value of a PARI call. """ def __init__(self): self.name = "_ret" def __repr__(self): return self.ctype() def ctype(self): """ Return the C type of the result of the PARI call. """ raise NotImplementedError def assign_code(self, value): """ Return code to assign the result of the PARI call in ``value`` to the variable named ``self.name``. """ s = " cdef {ctype} {name} = {value}\n" return s.format(ctype=self.ctype(), name=self.name, value=value) def return_code(self): """ Return code to return from the Cython wrapper. """ s = " clear_stack()\n" s += " return {name}\n" return s.format(name=self.name) class PariReturnGEN(PariReturn): def ctype(self): return "GEN" def return_code(self): s = " return new_gen({name})\n" return s.format(name=self.name) class PariReturnInt(PariReturn): def ctype(self): return "int" class PariReturnLong(PariReturn): def ctype(self): return "long" class PariReturnULong(PariReturn): def ctype(self): return "unsigned long" class PariReturnVoid(PariReturn): def ctype(self): return "void" def assign_code(self, value): return " {value}\n".format(value=value) def return_code(self): s = " clear_stack()\n" return s pari_ret_types = { '': PariReturnGEN, 'm': PariReturnGEN, 'i': PariReturnInt, 'l': PariReturnLong, 'u': PariReturnULong, 'v': PariReturnVoid, }