Fast Library for Number Theory
Total Page:16
File Type:pdf, Size:1020Kb
FLINT Fast Library for Number Theory Version 2.3.0 1 July 2012 William Hart∗, Fredrik Johanssony, Sebastian Pancratzz ∗ Supported by EPSRC Grant EP/G004870/1 y Supported by Austrian Science Foundation (FWF) Grant Y464-N18 z Supported by European Research Council Grant 204083 Contents 1 Introduction1 2 Building and using FLINT3 3 Test code5 4 Reporting bugs7 5 Contributors9 6 Tuning FLINT 11 7 Example programs 13 8 FLINT macros 15 9 fmpz 17 9.1 Introduction.................................. 17 9.2 Simple example................................ 18 9.3 Memory management ............................ 18 9.4 Random generation.............................. 18 9.5 Conversion .................................. 19 9.6 Input and output............................... 21 9.7 Basic properties and manipulation ..................... 22 9.8 Comparison.................................. 23 9.9 Basic arithmetic ............................... 24 9.10 Greatest common divisor .......................... 28 9.11 Modular arithmetic.............................. 28 9.12 Bit packing and unpacking ......................... 29 9.13 Logic Operations............................... 29 9.14 Chinese remaindering ............................ 30 10 fmpz vec 33 10.1 Memory management ............................ 33 10.2 Randomisation ................................ 33 10.3 Bit sizes and norms.............................. 33 10.4 Input and output............................... 34 10.5 Conversions.................................. 34 10.6 Assignment and basic manipulation .................... 35 10.7 Comparison.................................. 35 10.8 Sorting..................................... 35 10.9 Addition and subtraction .......................... 36 10.10 Scalar multiplication and division...................... 36 10.11 Sums and products.............................. 38 10.12 Reduction mod p ............................... 38 Contents iii 10.13 Gaussian content............................... 38 11 fmpz factor 39 11.1 Factoring integers .............................. 39 12 fmpz mat 41 12.1 Introduction.................................. 41 12.2 Simple example................................ 41 12.3 Memory management ............................ 42 12.4 Basic assignment and manipulation..................... 42 12.5 Random matrix generation ......................... 42 12.6 Input and output............................... 44 12.7 Comparison.................................. 45 12.8 Transpose................................... 45 12.9 Modular reduction and reconstruction ................... 45 12.10 Addition and subtraction .......................... 46 12.11 Matrix-scalar arithmetic........................... 47 12.12 Matrix multiplication ............................ 48 12.13 Inverse..................................... 48 12.14 Trace ..................................... 48 12.15 Determinant ................................. 49 12.16 Rank...................................... 50 12.17 Nonsingular solving ............................. 50 12.18 Row reduction ................................ 51 12.19 Nullspace ................................... 52 12.20 Echelon form ................................. 52 13 fmpz poly 53 13.1 Introduction.................................. 53 13.2 Simple example................................ 53 13.3 Definition of the fmpz poly t type ..................... 54 13.4 Memory management ............................ 54 13.5 Polynomial parameters............................ 55 13.6 Assignment and basic manipulation .................... 55 13.7 Randomisation ................................ 56 13.8 Getting and setting coefficients....................... 57 13.9 Comparison.................................. 58 13.10 Addition and subtraction .......................... 58 13.11 Scalar multiplication and division...................... 59 13.12 Bit packing.................................. 60 13.13 Multiplication................................. 61 13.14 Squaring.................................... 64 13.15 Powering ................................... 66 13.16 Shifting .................................... 67 13.17 Bit sizes and norms.............................. 68 13.18 Greatest common divisor .......................... 68 13.19 Gaussian content............................... 71 13.20 Euclidean division .............................. 72 13.21 Divisibility testing .............................. 75 13.22 Power series division............................. 75 13.23 Pseudo division................................ 76 13.24 Derivative................................... 78 13.25 Evaluation................................... 78 13.26 Newton basis................................. 79 iv Contents 13.27 Interpolation ................................. 80 13.28 Composition ................................. 80 13.29 Taylor shift.................................. 81 13.30 Power series composition........................... 81 13.31 Power series reversion ............................ 82 13.32 Square root.................................. 84 13.33 Signature ................................... 84 13.34 Hensel lifting ................................. 84 13.35 Input and output............................... 87 13.36 Modular reduction and reconstruction ................... 89 13.37 Products.................................... 90 13.38 Newton basis conversion........................... 90 14 fmpz poly factor 93 14.1 Memory management ............................ 93 14.2 Manipulating factors............................. 93 14.3 Input and output............................... 94 14.4 Factoring algorithms............................. 94 15 fmpq 97 15.1 Introduction.................................. 97 15.2 Memory management ............................ 97 15.3 Canonicalisation ............................... 98 15.4 Basic assignment............................... 98 15.5 Comparison.................................. 98 15.6 Conversion .................................. 99 15.7 Input and output...............................100 15.8 Random number generation.........................101 15.9 Arithmetic ..................................101 15.10 Modular reduction and rational reconstruction . 103 15.11 Rational enumeration ............................104 15.12 Continued fractions..............................105 15.13 Summation ..................................106 16 fmpq mat 107 16.1 Introduction..................................107 16.2 Memory management ............................107 16.3 Entry access..................................107 16.4 Basic assignment...............................108 16.5 Addition, scalar multiplication .......................108 16.6 Input and output...............................108 16.7 Random matrix generation .........................109 16.8 Special matrices ...............................109 16.9 Basic comparison and properties ......................109 16.10 Integer matrix conversion ..........................109 16.11 Modular reduction and rational reconstruction . 110 16.12 Matrix multiplication ............................110 16.13 Trace .....................................111 16.14 Determinant .................................111 16.15 Nonsingular solving .............................111 16.16 Inverse.....................................112 16.17 Echelon form .................................112 17 fmpq poly 113 17.1 Introduction..................................113 Contents v 17.2 Memory management ............................113 17.3 Polynomial parameters............................115 17.4 Accessing the numerator and denominator . 115 17.5 Random testing................................115 17.6 Assignment, swap, negation.........................116 17.7 Getting and setting coefficients.......................117 17.8 Comparison..................................118 17.9 Addition and subtraction ..........................119 17.10 Scalar multiplication and division......................119 17.11 Multiplication.................................121 17.12 Powering ...................................122 17.13 Shifting ....................................122 17.14 Euclidean division ..............................122 17.15 Power series division.............................123 17.16 Greatest common divisor ..........................124 17.17 Derivative and integral............................125 17.18 Square roots .................................126 17.19 Transcendental functions...........................126 17.20 Evaluation...................................129 17.21 Interpolation .................................129 17.22 Composition .................................130 17.23 Power series composition...........................130 17.24 Power series reversion ............................131 17.25 Gaussian content...............................133 17.26 Square-free ..................................134 17.27 Input and output...............................134 18 fmpz poly q 137 18.1 Introduction..................................137 18.2 Simple example................................137 18.3 Memory management ............................138 18.4 Randomisation ................................138 18.5 Assignment..................................139 18.6 Comparison..................................139 18.7 Addition and subtraction ..........................139 18.8 Scalar multiplication and division......................140 18.9 Multiplication and division .........................140 18.10 Powering ...................................141