logo资料库

gmpy2使用手册英文版.pdf

第1页 / 共57页
第2页 / 共57页
第3页 / 共57页
第4页 / 共57页
第5页 / 共57页
第6页 / 共57页
第7页 / 共57页
第8页 / 共57页
资料共57页,剩余部分请下载后查看
Introduction to gmpy2
gmpy2 Versions
Enhancements in gmpy2 2.1
Changes in gmpy2 2.1.0a1
Installation
Installing gmpy2 on Windows
Installing gmpy2 on Unix/Linux
Overview of gmpy2
Tutorial
Miscellaneous gmpy2 Functions
Multiple-precision Integers
Examples
mpz Methods
mpz Functions
Multiple-precision Integers (Advanced topics)
The xmpz type
Advanced Number Theory Functions
Multiple-precision Rationals
mpq Methods
mpq Attributes
mpq Functions
Multiple-precision Reals
Contexts
Context Attributes
Context Methods
Contexts and the with statement
mpfr Methods
mpfr Attributes
mpfr Functions
mpfr Formatting
Multiple-precision Complex
mpc Methods
mpc Attributes
mpc Functions
mpc Formatting
Cython usage
Initialization
Types
Object creation
Access to the underlying C type
Compilation
Changes for gmpy2 releases
Changes in gmpy2 2.1.0a1
Changes in gmpy2 2.0.4
Changes in gmpy2 2.0.3
Changes in gmpy2 2.0.2
Changes in gmpy2 2.0.1
Changes in gmpy2 2.0.0
Known issues in gmpy2 2.0.0
Changes in gmpy2 2.0.0b4
Known issues in gmpy2 2.0.0b4
Changes in gmpy2 2.0.0b3
Changes in gmpy2 2.0.0b2
Changes in gmpy2 2.0.0b1 and earlier
Indices and tables
gmpy2 Documentation Release 2.1.0a1 Case Van Horsen Nov 12, 2017
Contents 1 Introduction to gmpy2 gmpy2 Versions . Enhancements in gmpy2 2.1 . Changes in gmpy2 2.1.0a1 . . 1.1 1.2 1.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Installation 2.1 2.2 Installing gmpy2 on Windows . . Installing gmpy2 on Unix/Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Overview of gmpy2 . Tutorial . 3.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.2 Miscellaneous gmpy2 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Multiple-precision Integers . . . . . . . 4.1 . 4.2 mpz Methods . . 4.3 mpz Functions . Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Multiple-precision Integers (Advanced topics) The xmpz type . 5.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2 Advanced Number Theory Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Multiple-precision Rationals . . . 6.1 mpq Methods . . 6.2 mpq Attributes . 6.3 mpq Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Multiple-precision Reals . . . . . . . . . . . . . . . . . . . . 7.1 7.2 7.3 7.4 7.5 mpfr Methods . . 7.6 mpfr Attributes . . 7.7 mpfr Functions . . 7.8 mpfr Formatting . Contexts . . Context Attributes . . Context Methods . . . Contexts and the with statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 3 4 4 5 5 5 9 9 11 13 13 13 14 19 19 21 25 25 25 25 27 27 28 30 30 31 31 31 35 i
37 38 38 38 40 43 43 43 43 44 44 47 47 47 48 48 48 48 48 48 49 49 49 50 53 8 Multiple-precision Complex . . . . . 8.1 mpc Methods . . . 8.2 mpc Attributes . 8.3 mpc Functions . . 8.4 mpc Formatting . . . . . 9 Cython usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Initialization . Types . . . 9.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.3 Object creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.4 Access to the underlying C type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Changes for gmpy2 releases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.1 Changes in gmpy2 2.1.0a1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.2 Changes in gmpy2 2.0.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.3 Changes in gmpy2 2.0.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.4 Changes in gmpy2 2.0.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.5 Changes in gmpy2 2.0.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.6 Changes in gmpy2 2.0.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.7 Known issues in gmpy2 2.0.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.8 Changes in gmpy2 2.0.0b4 . . 10.9 Known issues in gmpy2 2.0.0b4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.10 Changes in gmpy2 2.0.0b3 . 10.11 Changes in gmpy2 2.0.0b2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.12 Changes in gmpy2 2.0.0b1 and earlier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Indices and tables ii
Contents: gmpy2 Documentation, Release 2.1.0a1 Contents 1
gmpy2 Documentation, Release 2.1.0a1 2 Contents
CHAPTER 1 Introduction to gmpy2 gmpy2 is a C-coded Python extension module that supports multiple-precision arithmetic. gmpy2 is the successor to the original gmpy module. The gmpy module only supported the GMP multiple-precision library. gmpy2 adds support for the MPFR (correctly rounded real floating-point arithmetic) and MPC (correctly rounded complex floating-point arithmetic) libraries. gmpy2 also updates the API and naming conventions to be more consistent and support the additional functionality. The following libraries are supported: • GMP for integer and rational arithmetic Home page: http://gmplib.org • MPIR is based on the GMP library but adds support for Microsoft’s Visual Studio compiler. It is used to create the Windows binaries. Home page: http://www.mpir.org • MPFR for correctly rounded real floating-point arithmetic Home page: http://www.mpfr.org • MPC for correctly rounded complex floating-point arithmetic Home page: http://mpc.multiprecision.org • Generalized Lucas sequences and primality tests are based on the following code: mpz_lucas: http://sourceforge.net/projects/mpzlucas/ mpz_prp: http://sourceforge.net/projects/mpzprp/ 1.1 gmpy2 Versions This manual documents the two major versions of gmpy2. Sections that are specific to a particular version will be identified as such. 3
gmpy2 Documentation, Release 2.1.0a1 There are two versions of gmpy2. The 2.0 version is the stable release that only receives bug fixes and very minor updates. Version 2.1 is currently under active development and includes several new capabilities. Most gmpy2 2.0 code should run unchanged with gmpy2 2.1 1.2 Enhancements in gmpy2 2.1 The most significant changes in gmpy2 2.1 are: 1.3 Changes in gmpy2 2.1.0a1 • Thread-safe contexts are now supported. Properly integrating thread-safe contexts required an extensive rewrite of almost all internal functions. Changing the active context in one thread will no longer change the behavior in other threads. • MPFR and MPC are now required. It is no longer possible to build a version of gmpy2 that only supports the GMP library. • The function inverse() now raises an exception if the inverse does not exist. • Context methods have been added for MPFR/MPC related functions. • A new context option (rational_division) has been added that changes the behavior of integer division involving mpz instances to return a rational result instead of a floating point result. • gmpy2 types are now registered in the numeric tower. • In previous versions of gmpy2, gmpy2.mpz was a factory function that returned an mpz instance. gmpy2.mpz is now an actual type. The same is true for the other gmpy2 types. • If a Python object has an __mpz__ method, it will be called by mpz() to allow an unrecognized type to be converted to an mpz instance. The same is true for the other gmpy2 types. • Support for Cython via the addition of a C-API and a gmpy2.pxd file. 4 Chapter 1. Introduction to gmpy2
分享到:
收藏