Skip to main content

flagrs

Parts of my flagmining library rewritten as CPython extension code in Rust.

Due to some lacking functionality in rust-cpython==0.6.0 it depends on my own fork of said project.

ZZ

The integers.

n.inv_mod(m) -> r : Returns $1/n \pmod m$.

Arithmetic Operations

x+y, x-y, x*y : Addition, subtraction, and multiplication.

x//y -> q, x%y -> r, divmod(x,y) -> (q,r) : Euclidean integer division.

x**e, pow(x,e) : Exponentiation. e must be positive.

pow(x,e,m) : Exponentiation under a modulus. e can be negative if gcd(x,m) == 1.

x.__bool__() -> bool : True if x != 0.

n.sqrt() -> (w,r) : Floored integer square root with remainder. w*w + r == n.

n.root(d) -> (w,r) : Floored integer dth root with remainder. w**d + r == n.

Sign

-x : Negation.

abs(x) : Absolute value.

x.sign() -> s : The sign of x (-1, 0, or 1).

Bitwise Operations

x|y, x&y, x^y : Bitwise OR, AND, and XOR.

~x : Bitwise negation, acting as if the integer had infinite width. : Equivalent to -x-1.

x<<i, x>>i : Bit shifts (can be negative).

n.nbits() -> c : Number of bits needed to represent the absolute value of n. : Equivalent to n.bit_length().

n.weight() -> c : Number of bits set in the absolute value of n.

n.truncate(bits, [signed=False]) : Truncate n to the given number of bits. Negative numbers are treated as if they're in two's-complement form for the given bit width. : If signed is True the resulting bits will be re-interpreted as a signed value and so the result might be negative.

n.next_bit() -> b : Next power-of-two bigger than n.

Integers also function implicitly as a list of bits:

n[i] -> bool : Checks bit i (0-indexed).

n[i:j] -> v : Returns a number with the bits set in the slice. : Morally equivalent to (n>>i) % (1<<j-i) but supports full slice syntax, including negative numbers.

Representation

str(x) -> str, x.__repr__() : Number in base-10 as a text string.

x.nbytes() -> l : Number of bytes needed to represent the number. For positive numbers this is equivalent to (x.nbits() + 7)//8. Negative numbers might require an extra bit (see x.bytes()).

x.bytes([order='big']) -> bytes : Interprets the number as base-256 and returns the digits as a bytestring. : Negative numbers are treated as if they're in two's complement representation of the minimum bit width that will successfully represent them, so -128 gives b'\x80' and -129 gives b'\xff\x7f'.

x.digits(base) -> [d...] : Yields a list of digits in base base. The base can be negative, but must have a magnitude of 2 or more.

Factors

n.gcd(m...) -> g : Returns the GCD of n with all arguments.

n.egcd(m) -> (g,x,y) : Extended GCD yielding Bézout coefficients. x*n + m*y == g.

n.lcm(m...) -> m : Returns the LCM of n with all arguments.

n.is_prime([reps=25]) -> bool : Trivial divisors, then Baille-PSW, then $(reps-24)$ sounds of Miller-Rabin.

n.next_prime() -> p : Returns the next prime larger than n.

n.make_odd() -> (q,e) : Returns the odd part and exponent of 2 in n. 2**e * q == n

n.small_factors([upto=0x100000]) -> (q,[(p,e)...]) : Factors out all primes smaller than upto. : Returns the remaining factor q and a list of primes and their multiplicity.

x.factor_pollard(upto) : ... x.factor_fermat(s, e) : ...

Metadata

Release files for flagrs 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for flagrs 0.1.2
File Interpreter ABI Platform
flagrs-0.1.2-cp39-cp39-manylinux_2_24_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.24+ x86-64 Details
flagrs-0.1.2-cp38-cp38-manylinux_2_24_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.24+ x86-64 Details
flagrs-0.1.2-cp37-cp37m-manylinux_2_24_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.24+ x86-64 Details

Total release size: 1.2 MB

Release files / flagrs-0.1.2-cp39-cp39-manylinux_2_24_x86_64.whl

Download URL flagrs-0.1.2-cp39-cp39-manylinux_2_24_x86_64.whl
Size 391.1 kB
Tags CPython 3.9 Linux glibc 2.24+ x86-64
SHA-256 checksum
How to use checksums
b384e51012a356ec0d6e10f975a998e6a27ebde63297adb48037ab65d48f92c4
BLAKE2b-256 checksum
How to use checksums
887727628d8e9d49502a3352cd2829bca8d523a27abc9b302b74227f4da47916
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.11.3

Release files / flagrs-0.1.2-cp38-cp38-manylinux_2_24_x86_64.whl

Download URL flagrs-0.1.2-cp38-cp38-manylinux_2_24_x86_64.whl
Size 391.1 kB
Tags CPython 3.8 Linux glibc 2.24+ x86-64
SHA-256 checksum
How to use checksums
8b8299d83ea30c98a30bdb1682cb7133f1e23bb500e9a91b37039a0b35dc1235
BLAKE2b-256 checksum
How to use checksums
27277a39ab043d7c0105b67c4ee86da441ee9360cf9c9b980fc4e42be0a461ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.11.3

Release files / flagrs-0.1.2-cp37-cp37m-manylinux_2_24_x86_64.whl

Download URL flagrs-0.1.2-cp37-cp37m-manylinux_2_24_x86_64.whl
Size 391.1 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.24+ x86-64
SHA-256 checksum
How to use checksums
4a9171987fd0dbdbea8b7229f768454d4e487e81cb36fd550a335405031200e9
BLAKE2b-256 checksum
How to use checksums
9c6af35f1584acad8b94fc3e713e7aedb1a830c3f0ac7a20b4a338e657f6bb54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/0.11.3

Release history Release notifications | RSS feed

0.1.4

3 release files

This release

0.1.2 This release

3 release files

0.1.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page