|
ADS
Algorithms and Data Structures
|
The arithmetic on integers of \( n \) bits, vectors of bits from the least significant one, of section 2.6: More...
#include "ADS/Contract.h"#include "ADS/numeric/Polynomial.h"#include <algorithm>#include <cstddef>#include <cstdint>#include <vector>#include "ADS/numeric/impl/BinaryInteger.tpp"Go to the source code of this file.
Namespaces | |
| namespace | ADS |
Typedefs | |
| using | ADS::Bits = std::vector< int > |
| the bits, the least significant first | |
Functions | |
| Bits | ADS::toBits (std::uint64_t x, std::size_t n=0) |
| the bits of \( x \), at least \( n \) of them | |
| std::uint64_t | ADS::fromBits (const Bits &b) |
| the value \( \sum_i b_i 2^i \) of the bits, which must be at most 64 | |
| Bits | ADS::carry (const std::vector< long > &c) |
| the coefficients \( c_i \), possibly larger than 1 or negative, made bits of the same value \( \sum_i c_i 2^i \) by the carries | |
| Bits | ADS::binaryAdd (const Bits &X, const Bits &Y) |
| the sum \( X + Y \), \( \Theta( n ) \) | |
| std::vector< long > | ADS::widen (const Bits &X) |
| the bits of \( X \) as the coefficients of a polynomial in \( x = 2 \) | |
| Bits | ADS::multiplyBinarySchool (const Bits &X, const Bits &Y, long *mults=nullptr) |
| the product \( X Y \) by the method of the school, \( \Theta( n^2 ) \); the products of two bits added to *mults, if given | |
| Bits | ADS::multiplyBinaryFour (const Bits &X, const Bits &Y, long *mults=nullptr) |
| the product \( X Y \) by four products of half size, \( \Theta( n^2 ) \); the products of two bits added to *mults, if given | |
| Bits | ADS::multiplyBinaryKaratsuba (const Bits &X, const Bits &Y, long *mults=nullptr) |
| the product \( X Y \) by the three products of Karatsuba, \( O( n^{1.59} ) \); the products of two bits added to *mults, if given | |
| std::uint64_t | ADS::ahmes (std::uint64_t a, std::uint64_t b, long *steps=nullptr) |
| the product \( a b \) by the multiplication of Ahmes; the halvings added to *steps, if given | |
The arithmetic on integers of \( n \) bits, vectors of bits from the least significant one, of section 2.6:
The contracts [see Contract.h]: a vector of bits holds only 0 and 1, an audit on the inputs of the sums and of the products, and fromBits() needs at most 64 of them; toBits() gives at least \( n \) bits whose value is \( x \), and ahmes() gives the product modulo \( 2^{64} \). The functions are defined in BinaryInteger.tpp.