1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

Tài liệu Matters Computational Ideas, Algorithms, Source CodeJ¨rg Arndt o.ii pdf

978 1,1K 1

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 978
Dung lượng 5,18 MB

Nội dung

Matters Computational Ideas, Algorithms, Source Code Jărg Arndt o ii CONTENTS iii Contents Preface xi I Low level algorithms Bit wizardry 1.1 Trivia 1.2 Operations on individual bits 1.3 Operations on low bits or blocks of a word 1.4 Extraction of ones, zeros, or blocks near transitions 1.5 Computing the index of a single set bit 1.6 Operations on high bits or blocks of a word 1.7 Functions related to the base-2 logarithm 1.8 Counting the bits and blocks of a word 1.9 Words as bitsets 1.10 Index of the i-th set bit 1.11 Avoiding branches 1.12 Bit-wise rotation of a word 1.13 Binary necklaces ‡ 1.14 Reversing the bits of a word 1.15 Bit-wise zip 1.16 Gray code and parity 1.17 Bit sequency ‡ 1.18 Powers of the Gray code ‡ 1.19 Invertible transforms on words ‡ 1.20 Scanning for zero bytes 1.21 Inverse and square root modulo 2n 1.22 Radix −2 (minus two) representation 1.23 A sparse signed binary representation 1.24 Generating bit combinations 1.25 Generating bit subsets of a given word 1.26 Binary words in lexicographic order for subsets 1.27 Fibonacci words ‡ 1.28 Binary words and parentheses strings ‡ 1.29 Permutations via primitives ‡ 1.30 CPU instructions often missed 1.31 Some space filling curves ‡ 2 11 13 14 17 18 23 25 25 27 29 33 38 41 46 48 49 55 56 58 61 62 68 70 74 78 80 82 83 Permutations and their operations 102 2.1 Basic definitions and operations 102 2.2 Representation as disjoint cycles 104 2.3 Compositions of permutations 105 iv CONTENTS 2.4 2.5 2.6 2.7 2.8 2.9 2.10 2.11 2.12 2.13 In-place methods to apply permutations Random permutations The revbin permutation The radix permutation In-place matrix transposition Rotation by triple reversal The zip permutation The XOR permutation The Gray permutation The reversed Gray permutation to data 109 111 118 121 122 123 125 127 128 131 Sorting and searching 3.1 Sorting algorithms 3.2 Binary search 3.3 Variants of sorting methods 3.4 Searching in unsorted arrays 3.5 Determination of equivalence classes 134 134 141 142 147 148 Data structures 4.1 Stack (LIFO) 4.2 Ring buffer 4.3 Queue (FIFO) 4.4 Deque (double-ended queue) 4.5 Heap and priority queue 4.6 Bit-array 4.7 Left-right array 153 153 155 156 158 160 164 166 II Combinatorial generation 171 Conventions and considerations 5.1 Representations and orders 5.2 Ranking, unranking, and counting 5.3 Characteristics of the algorithms 5.4 Optimization techniques 5.5 Implementations, demo-programs, and timings 172 172 172 173 174 174 order 176 176 177 180 182 183 186 191 Compositions 7.1 Co-lexicographic order 7.2 Co-lexicographic order for compositions into exactly 7.3 Compositions and combinations 7.4 Minimal-change orders k parts 194 194 196 198 199 Combinations 6.1 Binomial coefficients 6.2 Lexicographic and co-lexicographic order 6.3 Order by prefix shifts (cool-lex) 6.4 Minimal-change order 6.5 The Eades-McKay strong minimal-change 6.6 Two-close orderings via endo/enup moves 6.7 Recursive generation of certain orderings Subsets 202 8.1 Lexicographic order 202 8.2 Minimal-change order 204 CONTENTS 8.3 8.4 8.5 v Ordering with De Bruijn sequences 208 Shifts-order for subsets 208 k-subsets where k lies in a given range 210 Mixed radix numbers 9.1 Counting (lexicographic) order 9.2 Minimal-change (Gray code) order 9.3 gslex order 9.4 endo order 9.5 Gray code for endo order 9.6 Fixed sum of digits 217 217 220 224 226 228 229 10 Permutations 10.1 Factorial representations of permutations 10.2 Lexicographic order 10.3 Co-lexicographic order 10.4 An order from reversing prefixes 10.5 Minimal-change order (Heap’s algorithm) 10.6 Lipski’s Minimal-change orders 10.7 Strong minimal-change order (Trotter’s algorithm) 10.8 Star-transposition order 10.9 Minimal-change orders from factorial numbers 10.10 Derangement order 10.11 Orders where the smallest element always moves right 10.12 Single track orders 232 232 242 243 245 248 250 254 257 258 264 267 271 11 Permutations with special properties 11.1 The number of certain permutations 11.2 Permutations with distance restrictions 11.3 Self-inverse permutations (involutions) 11.4 Cyclic permutations 277 277 282 284 285 12 k-permutations 291 12.1 Lexicographic order 292 12.2 Minimal-change order 293 13 Multisets 295 13.1 Subsets of a multiset 295 13.2 Permutations of a multiset 296 14 Gray codes for strings with restrictions 14.1 List recursions 14.2 Fibonacci words 14.3 Generalized Fibonacci words 14.4 Run-length limited (RLL) words 14.5 Digit x followed by at least x zeros 14.6 Generalized Pell words 14.7 Sparse signed binary words 14.8 Strings with no two consecutive nonzero digits 14.9 Strings with no two consecutive zeros 14.10 Binary strings without substrings 1x1 or 1xy1 ‡ 304 304 305 307 310 311 313 315 317 318 320 15 Parentheses strings 323 15.1 Co-lexicographic order 323 15.2 Gray code via restricted growth strings 325 vi CONTENTS 15.3 Order by prefix shifts (cool-lex) 330 15.4 Catalan numbers 331 15.5 Increment-i RGS, k-ary Dyck words, and k-ary trees 333 16 Integer partitions 16.1 Solution of a generalized problem 16.2 Iterative algorithm 16.3 Partitions into m parts 16.4 The number of integer partitions 339 339 341 342 344 17 Set partitions 354 17.1 Recursive generation 354 17.2 The number of set partitions: Stirling set numbers and Bell numbers 358 17.3 Restricted growth strings 360 18 Necklaces and Lyndon words 18.1 Generating all necklaces 18.2 Lex-min De Bruijn sequence from necklaces 18.3 The number of binary necklaces 18.4 Sums of roots of unity that are zero ‡ 370 371 377 379 383 19 Hadamard and conference matrices 384 19.1 Hadamard matrices via LFSR 384 19.2 Hadamard matrices via conference matrices 386 19.3 Conference matrices via finite fields 388 20 Searching paths in directed graphs ‡ 20.1 Representation of digraphs 20.2 Searching full paths 20.3 Conditional search 20.4 Edge sorting and lucky paths 20.5 Gray codes for Lyndon words III Fast transforms 21 The Fourier transform 21.1 The discrete Fourier transform 21.2 Radix-2 FFT algorithms 21.3 Saving trigonometric computations 21.4 Higher radix FFT algorithms 21.5 Split-radix algorithm 21.6 Symmetries of the Fourier transform 21.7 Inverse FFT for free 21.8 Real-valued Fourier transforms 21.9 Multi-dimensional Fourier transforms 21.10 The matrix Fourier algorithm (MFA) 391 392 393 398 402 403 409 410 410 411 416 418 425 428 430 431 437 438 22 Convolution, correlation, and more FFT algorithms 22.1 Convolution 22.2 Correlation 22.3 Correlation, convolution, and circulant matrices ‡ 22.4 Weighted Fourier transforms and convolutions 22.5 Convolution using the MFA 22.6 The z-transform (ZT) 440 440 444 447 448 451 454 CONTENTS vii 22.7 Prime length FFTs 457 23 The Walsh transform and its relatives 23.1 Transform with Walsh-Kronecker basis 23.2 Eigenvectors of the Walsh transform ‡ 23.3 The Kronecker product 23.4 Higher radix Walsh transforms 23.5 Localized Walsh transforms 23.6 Transform with Walsh-Paley basis 23.7 Sequency-ordered Walsh transforms 23.8 XOR (dyadic) convolution 23.9 Slant transform 23.10 Arithmetic transform 23.11 Reed-Muller transform 23.12 The OR-convolution and the AND-convolution 23.13 The MAX-convolution ‡ 23.14 Weighted arithmetic transform and subset convolution 459 459 461 462 465 468 473 474 481 482 483 486 489 491 492 24 The 24.1 24.2 24.3 24.4 24.5 24.6 24.7 24.8 Haar transform The ‘standard’ Haar transform In-place Haar transform Non-normalized Haar transforms Transposed Haar transforms ‡ The reversed Haar transform ‡ Relations between Walsh and Haar transforms Prefix transform and prefix convolution Nonstandard splitting schemes ‡ 497 497 499 501 503 505 507 510 512 25 The Hartley transform 25.1 Definition and symmetries 25.2 Radix-2 FHT algorithms 25.3 Complex FFT by FHT 25.4 Complex FFT by complex FHT and vice versa 25.5 Real FFT by FHT and vice versa 25.6 Higher radix FHT algorithms 25.7 Convolution via FHT 25.8 Localized FHT algorithms 25.9 2-dimensional FHTs 25.10 Automatic generation of transform code 25.11 Eigenvectors of the Fourier and Hartley transform ‡ 515 515 515 521 522 523 524 525 529 530 531 533 26 Number theoretic transforms 26.1 Prime moduli for NTTs 26.2 Implementation of NTTs 26.3 Convolution with NTTs 27 Fast 27.1 27.2 27.3 IV (NTTs) 535 535 537 542 wavelet transforms 543 Wavelet filters 543 Implementation 544 Moment conditions 546 Fast arithmetic 28 Fast multiplication and exponentiation 549 550 viii CONTENTS 28.1 28.2 28.3 28.4 28.5 Splitting schemes for multiplication Fast multiplication via FFT Radix/precision considerations with FFT multiplication The sum-of-digits test Binary exponentiation 550 558 560 562 563 567 567 570 572 575 576 581 583 586 30 Iterations for the inversion of a function 30.1 Iterations and their rate of convergence 30.2 Schrăders formula o 30.3 Householder’s formula 30.4 Dealing with multiple roots 30.5 More iterations 30.6 Convergence improvement by the delta squared process 587 587 588 592 593 594 598 AGM, elliptic integrals, and algorithms for computing π The arithmetic-geometric mean (AGM) The elliptic integrals K and E Theta functions, eta functions, and singular values AGM-type algorithms for hypergeometric functions Computation of π 599 599 600 604 611 615 622 622 627 630 632 633 29 Root extraction 29.1 Division, square root and cube root 29.2 Root extraction for rationals 29.3 Divisionless iterations for the inverse a-th root 29.4 Initial approximations for iterations 29.5 Some applications of the matrix square root 29.6 Goldschmidt’s algorithm 29.7 Products for the a-th root ‡ 29.8 Divisionless iterations for polynomial roots 31 The 31.1 31.2 31.3 31.4 31.5 32 Logarithm and exponential function 32.1 Logarithm 32.2 Exponential function 32.3 Logarithm and exponential function of power series 32.4 Simultaneous computation of logarithms of small primes 32.5 Arctangent relations for π ‡ 33 Computing the elementary functions with limited resources 641 33.1 Shift-and-add algorithms for logb (x) and bx 641 33.2 CORDIC algorithms 646 34 Numerical evaluation of power series 651 34.1 The binary splitting algorithm for rational series 651 34.2 Rectangular schemes for evaluation of power series 658 34.3 The magic sumalt algorithm for alternating series 662 35 Recurrences and Chebyshev polynomials 666 35.1 Recurrences 666 35.2 Chebyshev polynomials 676 36 Hypergeometric series 36.1 Definition and basic operations 36.2 Transformations of hypergeometric series 36.3 Examples: elementary functions 685 685 688 694 CONTENTS ix 36.4 Transformations for elliptic integrals ‡ 700 36.5 The function xx ‡ 702 37 Cyclotomic polynomials, product forms, and continued fractions 37.1 Cyclotomic polynomials, Măbius inversion, Lambert series o 37.2 Conversion of power series to infinite products 37.3 Continued fractions 704 704 709 716 38 Synthetic Iterations ‡ 38.1 A variation of the iteration for the inverse 38.2 An iteration related to the Thue constant 38.3 An iteration related to the Golay-Rudin-Shapiro sequence 38.4 Iteration related to the ruler function 38.5 An iteration related to the period-doubling sequence 38.6 An iteration from substitution rules with sign 38.7 Iterations related to the sum of digits 38.8 Iterations related to the binary Gray code 38.9 A function encoding the Hilbert curve 38.10 Sparse power series 38.11 An iteration related to the Fibonacci numbers 38.12 Iterations related to the Pell numbers 726 726 730 731 733 734 738 739 741 747 750 753 757 V Algorithms for finite fields 39 Modular arithmetic and some number theory 39.1 Implementation of the arithmetic operations 39.2 Modular reduction with structured primes 39.3 The sieve of Eratosthenes 39.4 The Chinese Remainder Theorem (CRT) 39.5 The order of an element 39.6 Prime modulus: the field Z/pZ = Fp = GF(p) 39.7 Composite modulus: the ring Z/mZ 39.8 Quadratic residues 39.9 Computation of a square root modulo m 39.10 The Rabin-Miller test for compositeness 39.11 Proving primality 39.12 Complex modulus: the field GF(p2 ) 39.13 Solving the Pell equation 39.14 Multiplication of hypercomplex numbers ‡ 763 764 764 768 770 772 774 776 776 781 784 786 792 804 812 815 40 Binary polynomials 40.1 The basic arithmetical operations 40.2 Multiplying binary polynomials of high degree 40.3 Modular arithmetic with binary polynomials 40.4 Irreducible polynomials 40.5 Primitive polynomials 40.6 The number of irreducible and primitive polynomials 40.7 Transformations that preserve irreducibility 40.8 Self-reciprocal polynomials 40.9 Irreducible and primitive polynomials of special forms ‡ 40.10 Generating irreducible polynomials from Lyndon words 40.11 Irreducible and cyclotomic polynomials ‡ 40.12 Factorization of binary polynomials 822 822 827 832 837 841 843 845 846 848 856 857 858 x CONTENTS 41 Shift registers 41.1 Linear feedback shift registers (LFSR) 41.2 Galois and Fibonacci setup 41.3 Error detection by hashing: the CRC 41.4 Generating all revbin pairs 41.5 The number of m-sequences and De Bruijn sequences 41.6 Auto-correlation of m-sequences 41.7 Feedback carry shift registers (FCSR) 41.8 Linear hybrid cellular automata (LHCA) 41.9 Additive linear hybrid cellular automata 42 Binary finite fields: GF(2n ) 42.1 Arithmetic and basic properties 42.2 Minimal polynomials 42.3 Fast computation of the trace vector 42.4 Solving quadratic equations 42.5 Representation by matrices ‡ 42.6 Representation by normal bases 42.7 Conversion between normal and polynomial 42.8 Optimal normal bases (ONB) 42.9 Gaussian normal bases 864 864 867 868 873 873 875 876 878 882 representation 886 886 892 895 896 899 900 910 912 914 A The electronic version of the book 921 B Machine used for benchmarking 922 C The GP language 923 Bibliography 931 Index 951 952 – Fibonacci-Walsh transform, 513 – Haar transform, 498 – in-place Haar transform, 499 – Mersenne-Walsh transform, 514 – prefix transform, 511 – Reed-Muller transform, 486 – reversed arithmetic transform, 485 – reversed Haar transform, 505 – Walsh transform (Walsh-Kacmarz), 474 – Walsh transform (Walsh-Kronecker), 461 – Walsh transform (Walsh-Paley), 473 – weighted arithmetic transform, 493 Beatty sequence 756 Bell numbers 151, 358 Bell polynomials 359 Ben-Or test for irreducibility 837 Berlekamp’s Q-matrix algorithm 858 Bhaskara equation 812 big endian machine binary exponentiation 563 binary finite field 804, 886 binary GCD algorithm 767 binary heap 160 binary polynomial 822 binary powering 563 binary relation 148 binary search 141 binary splitting – for rational series, 651 – vs AGM, 656 – with continued fractions, 720 binary debruijn (C++ class) 208, 379 binary necklace (C++ class) 373 Binet form, of a recurrence 674 binomial coefficient – and type-2 ONB, 913 – modulo a prime, 914 – number of combinations, 176 bit combinations 62 bit counting 18 bit subsets, via sparse counting 68 bit-array 164 bit-array, fitting in a word 24 bit-block boundaries, determination 12 bit-reversal 34 bit-reversal permutation 118 bit-wise – reversal, 33 – rotation, 27 – zip, 38 bit fibgray (C++ class) 76 bit necklace (C++ class) 30 bit subset (C++ class) 68 bit subset gray (C++ class) 69 bitarray (C++ class) 164 Index bitrev permutation 118 BITS PER LONG bitset, testing for subset 23 blocks of bits, counting 20 blocks of bits, creation 11 blocks, swapping via quadruple reversal 124 blue code 49, 377 blue code, fixed points 53 bracelets, as equivalence classes 150 branches, avoiding them 25 bsearch 141 bswap instruction 34 built-ins, GCC 21 butterfly diagram, for radix-2 transforms 460 byte-wise Gray code and parity 42 BYTES PER LONG C C++ class XYZ see XYZ (C++ class) C2RFT see real FFT C2RFT (complex to real FFT) 431 carries with mixed radix counting 220 carry, in multiplication 558 CAT, constant amortized time 173 catalan (C++ class) 325 Catalan constant 663 Catalan numbers 331, 589 Catalan objects (combinatorial structures counted by Catalan numbers) 323 Cayley numbers 816 Cayley-Dickson construction 815 characteristic polynomial – of a matrix, 899 – of a recurrence relation, 666 – with Fourier transform, 534 characteristic, of a field 886 Chase’s sequence, for combinations 190 Chebyshev polynomials – (definition), 676 – and Pell’s equation, 814 – and products for the square root, 684 – and recurrence for subsequences, 672 – and square root approximants, 683 – as hypergeometric functions, 695 – fast computation, 680 – with accelerated summation, 663 checking pair, of arctan relations 640 Chinese Remainder Theorem (CRT) 772 Chinese Remainder Theorem, for convolution 542 chirp z-transform 455 circuit in a graph 391 circulant matrix 447, 905 Clausen’s product 691 CLHCA (cyclic LHCA) 883 clz (Count Leading Zeros), GCC built-in 21 Index co-lexicographic order – (definition), 172 – for combinations, 177 – for compositions, 194 – for permutations, 243 – for subsets of a multiset, 295 – with bit combinations, 62 colex (co-lexicographic) order 172 comb rec (C++ class) 191 combination chase (C++ class) 191 combination colex (C++ class) 178 combination emk (C++ class) 185 combination enup (C++ class) 188 combination lex (C++ class) 177 combination mod (C++ class) 186 combination pref (C++ class) 180 combination revdoor (C++ class) 183 combinations (k-subsets) of a multiset 296 combinations, Gray code, with binary words 66 combinations, of k bits 62 combinatorial Gray code 172 companion matrix 667, 899 comparison function, for sorting 145 compiler, smarter than you thought 26 complement, of a permutation 103 complement-shift sequences 397 complementary (dual) basis 908 complementing the sequency of a binary word 48 complete elliptic integral see elliptic integral complete graph 393 complex numbers, construction 804 complex numbers, mult via real mult 806 complex numbers, sorting 146 composite modulus 776 compositeness of an integer, test for 786 composition of permutations 108 composition, of permutations 105 composition colex (C++ class) 195 composition colex2 (C++ class) 195 composition ex colex (C++ class) 196 compositions 194 computation of π, AGM vs binary splitting 656 conditional search, for paths in a graph 398 conference matrix 386 conjugates of an element in GF(2n ) 892 connected permutation 103, 281 connected permutation, random 117 connection polynomial 864 constant – Catalan, 663 – CORDIC scaling, 647, 650 – Fibonacci parity, 755 – Golay-Rudin-Shapiro, 732 – Gray code, 742 – GRS, 732 953 – Komornik-Loreti, 729 – paper-folding, 744 – parity number, 726 – Pell, 758 – Pell Gray code, 762 – Pell palindromic, 759 – period-doubling, 735 – rabbit, 753 – revbin, 741 – Roth’s, 731 – ruler, 734 – sum of Gray code digits, 744 – sum-of-digits, 740 – Thue, 731 – weighted sum of Gray code digits, 747 – weighted sum-of-digits, 741 constant amortized time (CAT) 173 contiguous relations, for hypergeometric series 689 continued fraction 716 continued fractions, as matrix products 720 convergent, of a continued fraction 716 conversion, float to int conversion, of the radix (base) 656 convolution – acyclic (linear), 443 – and Chinese Remainder Theorem, 542 – and circulant matrices, 447 – and multiplication, 558 – AND-convolution, 490 – by FFT, without revbin permutations, 442 – by FHT, 525 – cyclic, 440 – cyclic, by FHT, 525 – dyadic, 481 – exact, 542 – linear, 443 – mass storage, 453 – MAX-convolution, 491 – negacyclic, 451, 528 – OR-convolution, 489 – property, of the Fourier transform, 441 – right-angle, 450 – skew circular, 451 – weighted, 449 – XOR-convolution, 481 cool-lex order see prefix shifts order Cooley-Tukey FFT algorithm 412 coprime: a coprime to b ⇐⇒ gcd(a, b) = 535 copying one bit CORDIC algorithms 646 correlation 444 and circulant matrices, 447 cosine and cosh, as hypergeometric function 697 cosine, by rectangular scheme 661 cosine, CORDIC algorithm 646 954 Index cosine, in a finite field 808 counting bits of a sparse word 20 counting bits of a word 18 counting sort 136 coupled iteration, for the square root 569 CPU instructions, often missed 82 CRC (cyclic redundancy check) 868 crc32 (C++ class) 870 crc64 (C++ class) 868 Creutzburg-Tasche primitive root 808 cross-correlation 445 CRT (Chinese Remainder Theorem) 772 ctz (Count Trailing Zeros), GCC built-in 21 cube root extraction 569 cubic convergence 587 cycle in a graph 391 cycle type, of a permutation 278 cycle-leaders – of the Gray permutation, 128, 376 cycles, of a permutation 104 cyclic convolution – (definition), 440 – computation via FFT, 442 cyclic correlation 444 cyclic distance, with binary words 32 cyclic group 778 cyclic LHCA (CLHCA) 883 cyclic period, of a binary word 30 cyclic permutation 105 cyclic permutation, random 112 cyclic permutations 285 cyclic redundancy check (CRC) 868 cyclic XOR 32 cyclic perm (C++ class) 287 cyclotomic polynomials – (definition), 704 – and primes, 802 – and primitive binary polynomials, 857 delta squared process 598 demo-programs, and timing 175 deque (C++ class) 158 deque (double-ended queue) 158 derangement 102, 280 derangement order, for permutations 264 derangement, random 115 DFT (discrete Fourier transform) 410 DIF (decimation in frequency) FFT 414 difference sets, and correlation 447 digraph 391 digraph (C++ class) 392 digraph paths (C++ class) 393 directed graph 391 discrete Fourier transform (DFT) 410 discrete Hartley transform 515 DIT (decimation in time) FFT 412 divides: d\n means “d divides n” 535 division – algorithm using only multiplication, 567 – CORDIC algorithm, 648 – exact, by C = 2k ± 1, 57 – exact, with polynomials over GF(2), 826 divisionless iterations for polynomial roots 586 divisors (C++ class) 295 divisors of n, sum of e-th powers, σe (n) 708 Dobinski’s formula, for Bell numbers 359 double buffer, for mass storage convolution 454 double-ended queue (deque) 158 dragon curve sequence 90 dual basis 908 dyadic convolution 481 Dyck words – k-ary, 333 – binary, 323 dyck gray (C++ class) 333 dyck gray2 (C++ class) 333 dyck rgs (C++ class) 333 D E Daubechies wavelets 547 De Bruijn graph 395 De Bruijn sequence – (definition), 873 – for computing bit position, 14 – lex-min DBS via necklaces, 377 – number of DBSs, 874 – with subsets, 208 De Bruijn sequence – as path in a graph, 395 debruijn (C++ class) 377 decimation in frequency (DIF) FFT 414 decimation in time (DIT) FFT 412 delta sequence 447 delta set 172 E, elliptic integral 603 Eades-McKay sequence, for combinations 183 easy case, with combinatorial generation 174 edge of a graph 391 edge sorting, with graph search 402 EGCD (extended GCD) 768, 836 EGCD, to compute Pad´ approximant 595 e EGF (exponential generating function) 173 eigenvectors of the Fourier transform 533 eight-square identity 819 element of order n 535 elementary functions, as hypergeometric f 694 elliptic E (complete elliptic integral) 603 elliptic K (complete elliptic integral) 601 elliptic integrals, as hypergeometric functions 700 Index endian-ness, of a computer endo (Even Numbers DOwn) order 186 endo order, for mixed radix numbers 226 enup (Even Numbers UP) order 187 enup order for combinations 188 enup order, with permutations 272 equivalence classes 148 equivalence relation 148 equivalence relations, number of 151 Eratosthenes, prime sieve 770 eta function (η-function) 344, 607, 711 Euclidean algorithm 767 Euler numbers 282 Euler’s identity, for hypergeometric functions 689 Euler’s totient function 776 exact convolution 542 exact division 56 exact division, by C = 2k ± 57 exact division, with polynomials over GF(2) 826 expect (with branch prediction), GCC built-in 21 exponent, of a group 776 exponential convergence 587 exponential function – as hypergeometric function, 696 – bit-wise computation, 643 – by rectangular scheme, 660 – computation via q = exp(−π K /K), 627 – iteration for, 627 – of power series, 631 exponential generating function (EGF) 173 exponentiation – algorithms, 563 – modulo m, 766 extended GCD (EGCD) 768, 836 extended GCD, to compute Pad´ approximant 595 e extension field 804, 886 external algorithms 453 extraneous fixed point, of an iteration 593 F factorial number system 232 factorial numbers, and cyclic permutations 289 factorial, binsplit algorithm for 651 factorial, rising factorial power 685 factorization of binary polynomials 858 falling factorial 176 falling factorial base 232 fast Fourier transform (FFT) 411 fast Hartley transform (FHT) 515 fcsr (C++ class) 876 FCSR (feedback carry shift register) 876 feedback carry shift register (FCSR) 876 Fermat numbers 795 Fermat primes 782 Ferrers diagram (with integer partitions) 345 955 ffs (Find First Set), GCC built-in 21 FFT – as polynomial evaluation, 559 – radix-2 DIF, 416 – radix-2 DIT, 414 – radix-4 DIF, 423 – radix-4 DIT, 420 – split-radix algorithm, 425 FFT (fast Fourier transform) 411 FFT caching 564 FFT, for multiplication 558 FFT-primes 536 FHT – convolution by, 525 – DIF step, 519 – DIF, recursive, 519 – DIT, recursive, 516 – radix-2 DIF, 520 – radix-2 DIT, 517 – radix-2 DIT step, 516 – shift operator, 516 FHT (fast Hartley transform) 515 Fibbinary numbers 62, 755 Fibonacci – k-step sequence, 309 – parity, 754 – parity constant, 755 – polynomials, 914 – representation, 754 – setup, of a shift register, 867 – words, 305 – words, Gray code, 76, 306 – words, shifts-order, 210 Fibonacci numbers 754 Fibonacci-Haar transform 512 Fibonacci-Walsh transform 513 field polynomial 886 FIFO (first-in, first-out), queue 156 filter, for wavelet transforms 544 finite field 804 finite field, binary 886 finite field, with prime modulus 776 Fisher-Yates shuffle 111 fixed point, of a function 587 fixed point, of an iteration, extraneous 593 fixed points, of the blue code 53 FKM algorithm 371 FKM algorithm, for binary words 30 four step FFT 438 four-square identity 819 Fourier shift operator 413 Fourier transform 410 Fourier transform, convolution property 441 fractional (order) Fourier transform 533 fractional Fourier transform 456 956 Index free element (normal element) 901 full path in a graph 391 G Galois field 886 Galois setup, of a shift register 867 Gauss’ transformation 690 Gaussian normal basis 914 GCC, built-ins 21 GCD (greatest common divisor), computation 767 generalized subset-lex (gslex) order 224 generating functions, for combinatorial objects 173 generator in GF(2n ) 889 generator of a group 776 generator, modulo p 457 generator, program producing programs 531 GF(2n ) (binary finite field) 886 GF2n (C++ class) 890, 910 GNB (Gaussian normal basis) 914 Golay-Rudin-Shapiro constant 732 Golay-Rudin-Shapiro sequence 44, 731 Goldschmidt algorithm 581 Gray code – and radix −2 representations, 59 – binary, reversed, 45 – combinatorial (minimal-change order), 172 – constant, 742 – for combinations, 182 – for combinations of a binary word, 66 – for Fibonacci words, 76, 306 – for Lyndon words, 403 – for mixed radix numbers, 220 – for multiset permutations, 301 – for Pell words, 313, 760 – for sparse signed binary words, 315 – for subsets of a bitset, 69 – for subsets, with shifts-order, 209 – of a binary word, 41 – powers of, 48 – single track, 403 Gray permutation 128 gray cycle leaders (C++ class) 129 greatest common divisor (GCD), computation 767 green code 50 ground field 804, 886 group, cyclic 778 GRS (Golay-Rudin-Shapiro) sequence 44, 731 GRS constant 732 gslex order, for mixed radix numbers 224 H Haar transform 497 Hadamard matrix 384, 817 Hadamard transform 459 half-trace, in GF(2n ) with n odd 898 Halley’s formula 588, 592 Hamiltonian cycle 391 Hanoi, towers of, puzzle 735 Hartley shift 516 Hartley transform 515 hashing, via CRC 868 heap 160 Heap’s algorithm for permutations 248 heapsort 141 Heighway dragon 90 hexdragon 95 high bits of a word, operations on 14 Hilbert curve – function encoding it, 747 – moves, 83 – turns, 85, 749 homogeneous moves, with combinations 183, 188 homogenous moves, with k-subsets 215 Householder’s iteration 592 Householder’s method 588 hybrid linear cellular automaton (LHCA) 878 hyperbolic sine and cosine, by CORDIC 649 hypercomplex numbers 816 hypergeometric function – (definition), 685 – AGM algorithms, 611 hypergeometric series – (definition), 685 – conversion to continued fraction, 724 – transformations, 688 I identical permutation 102 ii = exp(−π/2), computation 627 in-place routine 413 indecomposable permutation 103, 281 indecomposable permutation, random 117 index of an element modulo m 775 index of the single set bit in a word 13 index sort 142 infinite products, from series 709 inhomogeneous recurrence 670 initial approximations, for iterations 575 integer partitions 339 integer sequence – 1’s-counting seq., 739 – Beatty seq with Φ, 756 – Bell numbers, 151, 358 – Carmichael numbers, 786 – Catalan numbers, 331, 589 – connected permutations, 281 – dragon curve seq., 90 – Euler function ϕ(n), 776 – Euler numbers, 282 – F-increment RGS, 368 Index – Feigenbaum symbolic seq., 735 – Fibbinary numbers, 62, 755 – Fibonacci numbers, 309, 312, 754 – fixed points in lex-rev seq., 73 – Golay-Rudin-Shapiro seq., 44, 731 – Gray codes, 742 – GRS (Golay-Rudin-Shapiro) seq., 44, 731 – hypercomplex multiplication, 817 – indecomposable permutations, 281 – integer partitions, 345 – involutions, 279 – irreducible polynomials, 843 – irreducible self-reciprocal polynomial, 846 – irreducible trinomials, 848 – K-increment RGS, 369 – Kronecker symbol −1 , 745 n – Lyndon words, 843 – max-increment RGS, 364 – Mephisto Waltz seq., 730 – Moser – De Bruijn sequence, 59, 750 – necklaces, 380 – non-generous primes, 780 – number of XYZ, see number of, XYZ – optimal normal bases, type-1, 912 – optimal normal bases, type-2, 912 – paper-folding seq., 88, 744 – paper-folding seq., signed, 745 – paren words, 78 – partitions into distinct parts, 348 – partitions, of an integer, 345 – Pell equation not solvable, 813 – period-doubling seq., 10, 735 – primes with primitive root 2, 852, 878 – primitive roots of Mersenne primes, 373 – primitive trinomials, 848 – quadratic residues all non-prime, 784 – rabbit seq., 513, 753 – radix −2 representations, 60 – restricted growth strings, 337 – ruler function, 733 – sparse signed binary words, 315 – subfactorial numbers, 280 – subset-lex words, 71 – sum of binary digits, 739 – sum of digits of binary Gray code, 744 – swaps with revbin permutation, 119 – Thue-Morse seq., 44, 461, 726, 817 – trinomial, irreducible, 848 – type-1 optimal normal bases, 912 – type-2 optimal normal bases, 912 values of the Măbius function, 706 o – Wieferich primes, 780 integer sequence, by OEIS number – A000003, 610 – A000005, 708 957 – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – A000009, A000010, A000011, A000013, A000029, A000031, A000041, A000043, A000045, A000048, A000073, A000078, A000079, A000085, A000108, A000110, A000111, A000120, A000123, A000129, A000166, A000201, A000203, A000213, A000255, A000288, A000296, A000322, A000383, A000593, A000695, A000700, A001037, A001045, A001122, A001220, A001227, A001262, A001318, A001333, A001470, A001511, A001591, A001592, A001764, A002293, A002294, A002450, A002475, A002812, A002997, A003010, A003106, A003114, A003188, 348 776 151 151, 408 151 151, 380 345 797 309, 312, 314, 318, 320, 627, 754 408, 848 309 309 282 279 331, 337 151, 358, 368 282 493, 739 728 627, 758 280 756 352 312 280 312 360 312 312 352 59, 750 349 380, 843 315, 318 878 780 708 788 346 314, 758 280 9, 733 309 309 337 337 337 59 850 797 786 797 347 347, 350 742 958 Index – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – A003319, A003462, A003622, A003688, A003714, A003849, A004211, A004212, A004213, A005011, A005351, A005352, A005418, A005578, A005614, A005727, A005797, A005811, A006130, A006131, A006206, A006498, A006519, A006945, A007895, A008275, A008277, A008683, A010060, A011260, A014565, A014577, A014578, A015440, A015441, A015442, A015443, A015448, A015449, A016031, A019320, A020229, A020985, A022155, A022342, A025157, A025158, A025159, A025160, A025161, A025162, A027187, A027193, A027362, A028859, 281 649 754 314 62, 755, 756 754 368 368 368 368 60 60 151, 733 315 753 703 610 90, 744 318 318 710 321 789 754 277 358 706 44, 727 843 753 88, 744 731 318 318 318 318 314 315 874 802 788 44, 732 45 754 350 350 350 350 350 350 347 347 904 320 – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – A029883, A031399, A034448, A034947, A035263, A035457, A036991, A045687, A046116, A046699, A048146, A048250, A051158, A054639, A055578, A055881, A057460, A057461, A057463, A057474, A057496, A061344, A064990, A065428, A067659, A067661, A069925, A071642, A072226, A072276, A073571, A073576, A073639, A073726, A074071, A074710, A079471, A079559, A079972, A080337, A080764, A080846, A086347, A087188, A091072, A095076, A096393, A100661, A101284, A102467, A103314, A104521, A106400, A106665, A107220, 739 813 353 745 10, 735 349 78 119 390 74 353 353 740 912, 914 780 248 850 850 850 850 851 389 730 784 350 350 848 853, 912, 914 802 788 849 351 850 849, 885 731 850 73 74 322 366 758 95 320 351 88 754 373 72 914 840 383 759 726, 729 90 853 Index – A107222, 904 – A107877, 369 – A108918, 71 – A110981, 383 – A114374, 351 – A118666, 53 – A118685, 817 – A123400, 257 – A125145, 320 – A134337, 351 – A134345, 351 – A135488, 909 – A135498, 909 – A136250, 914 – A136415, 914 – A136416, 850 – A137310, 914 – A137311, 914 – A137313, 914 – A137314, 914 – A138933, 802 – A143347, 744 – A159880, 257 – A162296, 353 – A164896, 383 – A167654, 820 – A175337, 95 – A175338, 129 – A175339, 129 – A175390, 855 – A176405, 99 – A176416, 100 interleaving process – for set partitions, 354 – for Trotter’s permutations, 254 interpolation binary search 142 interpolation, linear 142 inverse – additive, modulo m, 767 – by exponentiation, 888 – cube root, iteration for, 569 – in GF(Q), 888 – iteration for, 567 – modulo 2n (2-adic), 56 – modulo m, by exponentiation, 781 – multiplicative, modulo m, 767 – of a circulant matrix, 906 – permutation, 106 – permutation, in-place computation, 106 – power series over GF(2), 826 – root, iteration for, 573 – square root, iteration for, 568 – XYZ transform, see XYZ transform inversion formula, Lagrange 590 inversion principle, Măbius 706 o 959 inversion table, of a permutation 232 invertible modulo m 767 involution (self-inverse permutation) 106, 279 involution, random 114 irreducible polynomial 837 isolated ones or zeros in a word 11 iteration – and multiple roots, 593 – divisionless, for polynomial roots, 586 – for exp, 627 – for inverse, 567 – for inverse cube root, 569 – for inverse root, 573 – for inverse square root, 568 – for logarithm, 623 – for roots modulo pn , 569 – for the zero of a function, 587 – Goldschmidt, 581 – Householder’s, 592 Schrăders, 588 o synthetic, 726 to compute π, 615 Ives’ algorithm for permutation generation 270 J Jacobi matrix 548 Jacobi’s identity 605 K K, elliptic integral 601 k-ary – Dyck words, 333 – trees, 333 k-compositions of n 194 k-permutations 291 k-subset 210 k-subsets (combinations) of a multiset 296 Karatsuba multiplication – for integers, 550 – for polynomials, 827 keys, sorting by keys 144 Knuth shue 111 Komornik-Loreti constant 729 Kănig iteration functions 592 o kperm gray (C++ class) 293 Kronecker product – (definition), 463 – of Hadamard matrices, 388 Kronecker symbol 782 ksubset gray (C++ class) 213 ksubset rec (C++ class) 210 ksubset twoclose (C++ class) 215 Kummer’s transformation 693 L Lagrange inversion formula 590 960 Lambert series 707, 738 LCM, least common multiple 768 least common multiple (LCM) 768 left inversion, of a permutation 233 left-right array 166 left-right array, with Lehmer code 235 left-to-right powering 564 left right array (C++ class) 166 Legendre symbol 782 Legendre’s relation 604, 701 Lehmer code, of a permutation 232 lex (lexicographic) order 172 lexicographic order – (definition), 172 – for bit combinations, 64 – for combinations, 177 – for multiset permutations, 296 – for subsets, 202 – for subsets of a binary word, 70 – generalized, for mixed radix numbers, 224 lfsr (C++ class) 865 LFSR (linear feedback shift register) 864 LFSR, and Hadamard matrices 384 LHCA (linear hybrid cellular automaton) 878 LIFO (last-in, first-out), stack 153 LIMB (super-digit) 560 linear convolution 443 linear correlation 444 linear feedback shift register (LFSR) 864 linear hybrid cellular automaton (LHCA) 878 linear interpolation 142 linear, function in a finite field 887 Lipski’s Gray codes for permutations 250 list recursions 304 little endian machine localized Hartley transform algorithm 529 localized Walsh transform algorithm 468 logarithm – as hypergeometric function, 696 – bit-wise computation, 641, 644 – computation by rectangular scheme, 659 – computation via AGM, 622 – computation via π/ log(q), 622 – curious series for, 626 – iteration using exp, 623 – of power series, 630 logarithmic generating function (LGF) 352 logical shift, of a binary word long division 567 long multiplication 567 loop in a graph 391 loopless algorithm 173 low bits, operations on LR-array (left-right array) 166 Lucas test, for primality 799 Index Lucas-Lehmer test, for Mersenne numbers 796 lucky path, in a graph 402 Lunnon’s Gray code for multiset permutations 301 Lyndon words – (definition), 370 – and irreducible binary polynomials, 856 – and Mersenne primes, 373 – binary, number of, 380 – number of, 380 – with even/odd weight, 382 – with fixed content, 382 – with fixed density, 382 Lyndon words, as binary word 30 lyndon gray (C++ class) 406 M m-sequence 384, 873 MAC (modular adjacent changes), Gray code 399 mass storage convolution 453 matrix Fourier algorithm (MFA) 438 matrix square root, applications 576 matrix transposition, and zip permutation 127 matrix transposition, in-place 122 MAX-convolution 491 maximal order modulo m 774 mean, arithmetic-geometric 599 median of three elements 135 Mephisto Waltz sequence 730 merge sort 138 Mersenne numbers, Lucas-Lehmer test 796 Mersenne primes – 2j -th roots, 807 – and Lyndon words, 373 – generalized, 768 – Lucas-Lehmer test, 796 Mersenne-Walsh transform 513 MFA (matrix Fourier algorithm) 438 MFA convolution algorithm 452 minimal polynomial, in GF(2n ) 892 minimal-change order see Gray code minimum, among bit-wise rotations 29 missing, CPU instructions 82 mixed radix numbers 217 mixedradix endo (C++ class) 226 mixedradix endo gray (C++ class) 228 mixedradix gray (C++ class) 220 mixedradix gslex (C++ class) 224 mixedradix gslex alt (C++ class) 226 mixedradix lex (C++ class) 217 mixedradix modular gray (C++ class) 224 mixedradix modular gray2 (C++ class) 223 mixedradix sod lex (C++ class) 229 Măbius function 705 o Măbius inversion principle 706 o mod (C++ class) 537, 809 Index 961 mod m FFTs 535 modular adjacent changes (MAC), Gray code 399 modular arithmetic 764 modular multiplication 765 modular reduction, with structured primes 768 modular square root 784 modulo, as equivalence classes 149 modulus – composite, 776 – prime, 776 – prime, with NTTs, 535 moment conditions, for wavelet filters 546 Moser – De Bruijn sequence 59, 750 moves, of the Hilbert curve 83 mpartition (C++ class) 343 mset perm gray (C++ class) 301 mset perm lex (C++ class) 298 mset perm lex rec (C++ class) 297 multi-dimensional Walsh transform 461 multi-point iteration 597 multigraph 391 multinomial coefficient 296, 383 multiple roots, iterations for 593 multiplication – by FFT, 558 – carry, 558 – integer vs float, – is convolution, 558 – Karatsuba, 550 – modulo m, 765 – of complex numbers via real mult., 806 – of hypercomplex numbers, 815 – of octonions, 818 – of polynomials, is linear convolution, 444 – of quaternions, 818 – sum-of-digits test, 562 multiplication matrix, for normal bases 901 multiplication table, of an algebra 815 multiplicative function 705, 777 multiplicative group 777 multiplicative group, with a ring 775 multiplicative inverse, modulo m 767 multisection of power series 688 multiset 295 N N-polynomial (normal polynomial) 900 n-set, a set with n elements 176 NAF (nonadjacent form) 61 NAF, Gray code 315 necklace (C++ class) 372 necklace2bitpol (C++ class) 856 necklaces – as equivalence classes, 149 – binary, 30 – binary, number of, 379 – definition, 370 – with even/odd weight, 382 – with fixed content, 382 – with fixed density, 382 necklaces, as binary words 30 negacyclic convolution 451, 528 neighbors of a node in a graph 391 Newton’s formula 895 Newton’s iteration, for vector-valued functions 548 node (vertex) of a graph 391 non-generous primes 780 non-residue (quadratic, modulo p) 781 nonadjacent form (NAF) 61 nonadjacent form (NAF), Gray code 315 normal bases, for GF(2n ) 900 normal basis, optimal 912 normal element (free element) 901 normal polynomial 900 NTT – (number theoretic transforms), 535 – radix-2 DIF, 538 – radix-2 DIT, 537 – radix-4, 540 number of – alternating permutations, 281 – aperiodic necklaces, 380 – binary necklaces, 379 – binary partitions of even numbers, 728 – binary reversible strings, 151 – binary words with at most r consecutive ones, 308 – bracelets, 150 – carries, 220 – combinations, 176 – connected permutations, 281 – cycles in De Bruijn graph, 397 – De Bruijn sequences, 874 – derangements, 280 – divisors, 708 – equivalence relations, 151 – F-increment RGS, 368 – fixed density Lyndon words, 382 – fixed density necklaces, 382 – generators modulo n, 780 – increment-i RGS, 337 – indecomposable permutations, 281 – integer partitions, 345 – integers coprime to n, 776 – inversions of a permutation, 236 – invertible circulant matrices, 905 – involutions, 279 – irreducible polynomials, 843 – irreducible SRPs, 847 – K-increment RGS, 369 962 Index – – – – – – – – – – – – – – – – – – – – – – – – – – – – Lyndon words, 380, 843 m-sequences, 873 max-increment RGS, 364 necklaces, 150, 379 necklaces with even/odd weight, 382 normal polynomials, 904, 907 ones in binary Gray code, 744 parentheses pairs, 331 partitions into distinct parts, 348 partitions of a set, 358 partitions of an integer, 345 permutations of a multiset, 296 permutations whose order divides 3, 280 permutations with m cycles, 277 primitive normal polynomials, 904 primitive polynomials, 843 primitive SRPs, 848 self-dual normal bases, 909 set partitions, 151, 358 shift register sequences, 873 sparse signed binary words, 315 strings with fixed content, 383 swaps with revbin permutation, 118 units in GF(Q), 888 units modulo m, 777 unlabeled bracelets, 150 unlabeled necklaces, 150 zero-divisors of Cayley-Dickson algebras, 820 number theoretic transforms (NTT) 535 O O(1) algorithm 173 octonions 816 OGF (ordinary generating function) 173 ONB (optimal normal basis) 912 one-point iteration 587 optimal normal basis (ONB) 912 optimization, with combinatorial generation 174 OR-convolution 489 OR-convolution, weighted 493 order – of a polynomial, 841 – of an element modulo m, 774 – of an iteration, 587 ordinary generating function (OGF) 173 out of core algorithms 453 P Pad´ approximants 595 e – for arctan, 624 – for exp, 628 – for the r-th root, 572 – for the logarithm, 623 – for the square root, 683 paper-folding sequence 88, 744 parallel assignment (with pseudocode) 414 parameters, of a hypergeometric series 685 paren (C++ class) 323 paren gray (C++ class) 329 parentheses, and binary words 78 parity – number, 726, 739 – of a binary word, 42 – of a permutation, 105 – random permutation with given parity, 112 parity (parity of a word), GCC built-in 21 Parseval’s equation 411 partial unrolling of a loop 148 partition – of a set, 354 – of an integer, 339 partition (C++ class) 341 partition gen (C++ class) 339 partitioning, for quicksort 135 Pascal’s triangle 177 path in a graph 391 pattern, length-n with p letters 361 pcrc64 (C++ class) 871 Pell – constant, 758 – equation, 812 – Gray code constant, 762 – palindromic constant, 759 Pell ruler function 760 Pell words, Gray code 313, 760 pentagonal number theorem 346 pentanomial 851 Pepin’s test, for Fermat numbers 795 period of a polynomial 841 period-doubling constant 735 period-doubling sequence 10, 735 perm colex (C++ class) 243 perm derange (C++ class) 264 perm gray ffact (C++ class) 259, 293 perm gray ffact2 (C++ class) 258 perm gray lipski (C++ class) 250 perm gray rfact (C++ class) 260 perm gray rot1 (C++ class) 263 perm gray wells (C++ class) 252 perm heap (C++ class) 249 perm heap2 (C++ class) 249 perm heap2 swaps (C++ class) 250 perm involution (C++ class) 284 perm ives (C++ class) 270 perm lex (C++ class) 242 perm mv0 (C++ class) 267 perm rec (C++ class) 285 perm restrpref (C++ class) 278 perm rev (C++ class) 245 Index perm rev2 (C++ class) 247 perm rot (C++ class) 266 perm st (C++ class) 271 perm st gray (C++ class) 274 perm star (C++ class) 257 perm star swaps (C++ class) 257 perm trotter (C++ class) 254 perm trotter lg (C++ class) 256 permutation – alternating, 281 – as path in the complete graph, 395 – composition, 105 – connected, 281 – cycle type, 278 – cycles, 104 – cyclic, random, 112 – derangement, 280 – indecomposable, 281 – inverse of, 106 – involution, 106, 279 – of a multiset, 296 – random, 111 – with m cycles, number of, 277 – with prescribed parity, random, 112 Pfaff’s reflection law 689 phi function, number theoretic 776 π, computation 615 pitfall, shifts in C pitfall, two’s complement Pocklington-Lehmer test, for primality 794 pointer sort 144 pointer, size of polar decomposition, of a matrix 578 polynomial – binary, 822 – irreducible, 837 – multiplication, is linear convolution, 444 – multiplication, splitting schemes, 827 – primitive, 841 – roots, divisionless iterations for, 586 – weight of a binary polynomial, 848 popcount (bit-count), GCC built-in 21 power series – computation of exponential function, 631 – computation of logarithm, 630 – reversion, 589 powering – left-to-right method, 564 – modulo m, 766 – of permutations, 108 – of the binary Gray code, 48 – right-to-left method, 563 Pratt’s certificate of primality 792 prefetching a memory location, GCC built-in 21 prefix convolution 511 963 prefix shifts, order for – combinations, 180 – multiset permutations, 299 – paren strings, 330 prefix transform 511 prime length FFT, Rader’s algorithm 457 primes – and cyclotomic polynomials, 802 – as modulus, 776 – as modulus, with NTTs, 535 – non-generous, 780 – sieve of Eratosthenes, 770 – structured, 768 – Wieferich, 780 – with primitive root 2, 878 primitive n-th root, modulo m 535 primitive r-th root of unity 774 primitive elements, of a group 776 primitive polynomial 841 primitive root – (definition), 776 – Creutzburg-Tasche, 808 – in GF(2n ), 889 – of Mersenne primes, 373 – with prime length FFT, 457 primitive trinomial 848, 885 priority queue 162 priority queue (C++ class) 162 product form – for a-th root, 583 – for continued fractions, 720 – for elliptic K, 602 – for power series of exp, 631 – for square root, 684 – from series, 709 products of k out of n factors 179 products, infinite, from series 709 Proth’s theorem 795 Prouhet-Thue-Morse constant 726 pseudo graph 391 pseudo-inverse, of a matrix 579 pseudoprime 786 pseudoprime, strong (SPP) 786 Q Q-matrix 858 quadratic convergence 587 quadratic equation, with binary finite fields 896 quadratic reciprocity 782 quadratic residue (square) modulo p 781 quadratic residues, and Hadamard matrices 386 quadruple reversal technique 124 quartic convergence 587 quaternions 816 queue (C++ class) 157 964 Index queue (FIFO) 156 quicksort 135 R R2CFT see real FFT R2CFT (real to complex FFT) 431 R5-dragon 95 R7-dragon 95 rabbit constant 753 rabbit sequence 513, 753 Rabin’s test for irreducibility 838 Rabin-Miller test, for compositeness 787 Rader’s algorithm, for prime length FFT 457 radix −2 (minus two) representations 58 radix (base) conversion 656 radix permutation 121 radix sort 138 radix-r DIF FFT step 419 radix-r DIT FFT step 419 random permutation 111 random selection 111 ranking, with combinatorial objects 172 rational, square root iterations 570 re-orthogonalization, of a matrix 576 real FFT – by FHT, 523 – split-radix algorithm, 434 – with wrap routines, 432 reciprocal polynomial 845 reciprocity, quadratic 782 rectangular scheme – for arctan and log, 658 – for exp, sin, and cos, 660 recurrence – (definition), 666 – inhomogeneous, 670 – relation, 666 – relation, for subsequences, 672 red code 50 reduction – modular, with structured primes, 768 – modulo x2 + x + etc., 806 Reed-Muller transform – (definition), 486 – and necklaces, 376 rejection method 117 relation, binary 148 representations, radix −2 (minus two) 58 representatives, with equivalence classes 149 residue (quadratic, modulo p) 781 restricted growth strings (RGS) – (definition), 325 – for parentheses strings, 325 – for set partitions, 357 revbin (bit-wise reversal) 33 revbin constant 741 revbin pairs, via shift registers 873 revbin permutation 118 revbin permutation, and convolution by FFT 442 reversal bit-wise 33 reversal, of a permutation 103 reversed arithmetic transform 485 reversed Gray code 45 reversed Gray permutation 131 reversed Haar transform 505 reversed Reed-Muller transform 487 reversing the bits of a word 34 reversion of power series – (definition), 589 for Schrăders formula, 591 o with k-ary Dyck words, 337 RGS (restricted growth string) 325 rgs fincr (C++ class) 366 rgs maxincr (C++ class) 364 right inversion, of a permutation 232 right-angle convolution 450 right-to-left powering 563 ring buffer 155 ringbuffer (C++ class) 155 rising factorial base 232 RLL (run-length limited) words 310 Rogers-Ramanujan identities 347 root – extraction, 572 – inverse, iteration for, 573 – modulo pn (p-adic), 569 – of a polynomial, divisionless iterations, 586 – primitive, 776 – primitive, in GF(2n ), 889 – primitive, modulo m, 535 – primitive, of Mersenne primes, 373 roots of unity, having sum zero 383 rotation, bit-wise 27 rotation, by triple reversal 123 row-column algorithm 437 ruler constant 734 ruler function 207, 733 ruler func (C++ class) 207, 283 run-length limited (RLL) words 310 S Sande-Tukey FFT algorithm 414 Sattolo’s algorithm 112 scalar multiplication 886 Schrăders formula 588 o search, binary 141 searching, with unsorted arrays 147 secant method 587 sedenions 816 selection sort 134 Index selection, of a random element 111 self-correlation 445 self-dual (basis over GF(2n )) 908 self-inverse permutation, random 114 self-reciprocal polynomial 846 sentinel element 174 sequence see integer sequence sequency 474 sequency of a binary word, complementing 48 sequency, of a binary word 46 set partition 354 setpart (C++ class) 356 setpart p rgs lex (C++ class) 361 setpart rgs gray (C++ class) 363 setpart rgs lex (C++ class) 360 shift operator, for Fourier transform 413 shift operator, for Hartley transform 516 shift register sequence (SRS) 864 shift-and-add algorithms 641 shifts in C, pitfall shifts, and division shifts-order – for bit combinations, 64 – for Fibonacci words, 210 – for subsets, 208 – Gray code, for subsets, 209 short division 567 short multiplication 567 sieve of Eratosthenes 770 sign decomposition, of a matrix 579 sign of a permutation 105 sign of the Fourier transform 410 signed binary representation 61 signed binary words, sparse, Gray code 315 simple continued fraction 717 simple path in a graph 391 simple zero-divisors 820 sine and sinh, as hypergeometric function 697 sine, CORDIC algorithm 646 sine, in a finite field 808 single track – Gray code, 403 – order for permutations, 271 – order for subsets, 208 singular value decomposition (SVD) 577 singular values, with elliptic K 609 skew circular convolution 451 slant transform 482 slant transform, sequency-ordered 483 smart, your compiler 26 sorting by keys 144 sorting, edges in a graph 402 sparse counting, and bit subsets 68 sparse signed binary representation 61 sparse signed binary words, Gray code 315 965 sparse words, bit counting 20 spectrum of a real number 756 SPI (strong pseudo-irreducible) 839 split-radix FFT algorithm 425 splitting schemes for multiplication – for integers, 550 – for polynomials over GF(2), 827 splitting, binary, for rational series 651 SPP (strong pseudoprime) 786 square modulo p 781 square of a permutation 107 square root – in GF(2n ), 888 – iteration for, 568 – modulo 2n , 57 – modulo p, 784 – of a matrix, applications, 576 square-free factorization, with polynomials 863 square-free polynomials 858 square-free, partitions into such parts 351 SRS (shift register sequence) 864 stable sort 137 stack (C++ class) 153 stack (LIFO) 153 star-transposition order, for permutations 257 Stirling numbers – of the first kind (cycle numbers), 277 – of the second kind (set numbers), 358 strings with fixed content 383 strong minimal-change order 172, 254, 329 strong minimal-change order for combinations 183 strong pseudo-irreducible (SPI) 839 strong pseudoprime (SPP) 786 structured primes 768 subdegree of a polynomial 852 subfactorial numbers 280 subsequences, recurrence relations for 672 subset convolution 493 subset of bitset, testing 23 subset debruijn (C++ class) 208 subset deltalex (C++ class) 202 subset gray (C++ class) 206 subset gray delta (C++ class) 175, 204 subset lex (C++ class) 203 subsets – of k bits (combinations), 62 – of a binary word, 68, 70 – of a multiset, 295 subtraction, modulo m 764 sum of digits, with mixed radix numbers 229 sum of Gray code digits constant 744 sum of two squares 810 sum-of-digits constant 740 sum-of-digits test, with multiplication 562 sumalt algorithm 662 966 Index sums of divisors, and partitions 352 super-linear iteration 587 SVD (singular value decomposition) 577 Swan’s theorem 850 swapping blocks via quadruple reversal 124 swapping two bits swapping variables without temporary symmetries – of the Fourier transform, 428 – of the revbin permutation, 119 synthetic iterations 726 T taps, with wavelet filter 543 tcrc64 (C++ class) 871 tensor product 463 terdragon curve 92 theta functions: Θ2 , Θ3 , and Θ4 604 Thue constant 731 Thue-Morse sequence 44, 461, 726, 817 thue morse (C++ class) 44 timing, with demo-programs 175 TMFA (transposed matrix Fourier algorithm) 438 toggle between two values Toom-Cook algorithm 551 Toom-Cook algorithm for binary polynomials 831 totient function 776 towers of Hanoi 735 trace – of a polynomial, 900 – of an element in GF(2n ), 887 – vector, fast computation, 895 – vector, in finite field, 888 trace-orthonormal basis 908 transformations, for elliptic K and E 700 transformations, of hypergeometric series 688 transforms, on binary words 49 transition count, for a Gray code 403 transposed matrix Fourier algorithm (TMFA) 438 transposition of a matrix, and zip permutation 127 transposition of a matrix, in-place 122 transpositions of a permutation 105 trigonometric recursion 417 trinomial, primitive 848, 885 triple reversal technique 123 Trotter’s algorithm for permutations 254 two’s complement, pitfall two-close order for k-subsets 215 two-close order for combinations 188 type, of a set partition 359 type-1 optimal normal basis 912 type-2 optimal normal basis 912 type-t Gaussian normal basis 914 U unitary divisor 353 units (invertible elements) 767 universal cycle (for combinatorial objects) 874 unlabeled bracelets 150 unranking, with combinatorial objects 172 unrolling, of a loop 148 unsorted arrays, searching 147 unzip permutation 126 V vertex, of a graph 391 vertical addition 21 W Walsh transform 459 Walsh transform, multi-dimensional 461 wavelet conditions 544 wavelet filter 544 wavelet transform 543 wavelet filter (C++ class) 544, 546 weight, of binary polynomial 848 weighted arithmetic transform 492 weighted convolution 449 weighted MFA convolution algorithm 452 weighted MFA convolution, mass storage 453 weighted OR-convolution 493 weighted sum of Gray code digits constant 747 weighted sum-of-digits constant 741 weighted transform 448 Wells’ Gray code for permutations 252 Whipple’s identity 690 Wieferich primes 780 X XOR permutation 127 XOR, cyclic 32 XOR-convolution 481 xx , series for 702 Y yellow code 49, 376 Young diagram (with integer partitions) 345 Z Z-order 87 z-transform 454 Zeckendorf representation 754 zero bytes, finding 55 zero divisors, of an algebra 815 zero padding, for linear convolution 444 zero-divisors of the sedenions 820 zero-one transitions in a word 12 zip permutation 125 zip, bit-wise 38 z z , series for 702 ... have exactly one bit set { ulong x = mdst; if ( msrc & a ) x = 0; // zero if source bit set x ^= mdst; // ==mdst if source bit set, else zero a &= ~mdst; // clear dest bit 10 11 12 Chapter 1:... benchmarking 922 C The GP language 923 Bibliography 931 Index 951 Preface This is a book for the computationalist, whether a working programmer or anyone interested in methods of computation The... the algorithms are given formally It is assumed that the reader is able to understand the given source code, it is considered part of the text We use the C++ programming language for low-level

Ngày đăng: 17/02/2014, 14:20

w