794 Commits

Author SHA1 Message Date
Josh Stone
089b86a513 Start the bump to 0.2 2018-02-23 17:22:12 -08:00
Josh Stone
f6568291ab
Merge pull request #21 from Robbepop/master
Add apint to README as another alternative
2018-02-15 12:19:32 -08:00
Hero Bird
07997b1989 add apint to README as another alternative
The ApInt crate is a pure rust implementation for arbitrary fixed bitwidth modulo arithmetics of integers with a focus on correctness and efficiency - especially for smaller bit widths. It features a generic signless `ApInt` as well as signed counterparts `Int` (signed int) and `UInt` (unsigned int) that are thin wrappers around it. The implementation is unfinished in some parts but that should be fixed over time.
2018-02-15 14:57:44 +01:00
bors[bot]
468a28df6d Merge #20
20: Note a few alternative crates in README.md r=cuviper a=cuviper

This presents a table of some common alternatives to this crate which may have better performance.  I'm not including any specific performance comparisons, since that will surely vary on different workloads, and will change as each crate evolves.  I want to keep this impartial, listing only simple objective facts about each.  Corrections welcome!

cc crate owners: @Aatch, @doomrobo, @fizyk20, @tspiteri
2018-02-10 02:15:13 +00:00
Josh Stone
e65c9f64a4 mention gmp-mpfr-sys only indirectly 2018-02-09 14:05:34 -08:00
Josh Stone
3abecf366e note a few alternative crates 2018-02-09 12:43:30 -08:00
bors[bot]
8de5e86ba8 Merge #19
19: Release 0.1.43 r=cuviper a=cuviper
2018-02-09 01:34:43 +00:00
Josh Stone
ef0b1041df Release 0.1.43 2018-02-08 17:32:57 -08:00
bors[bot]
9e08ee3a5b Merge #18
18: Add BigInt::modpow r=cuviper a=cuviper

This performs modular exponentiation on signed `BigInt`.  The exponent
must be positive, and the modulus must be non-zero.  The implementation
leverages `BigUint::modpow`, fixing the signs as needed afterward.

Closes #17.
2018-02-08 23:50:49 +00:00
Josh Stone
f4cc2abff1 Add BigInt::modpow
This performs modular exponentiation on signed `BigInt`.  The exponent
must be positive, and the modulus must be non-zero.  The implementation
leverages `BigUint::modpow`, fixing the signs as needed afterward.
2018-02-08 13:57:55 -08:00
Josh Stone
16fa6c94e8 chmod -x benches/gcd.rs 2018-02-07 23:24:53 -08:00
Josh Stone
2f578fc2cb add a note about rand to 0.1.42 2018-02-07 23:14:09 -08:00
bors[bot]
34bfa63f52 Merge #16
16: Release 0.1.42 r=cuviper a=cuviper
2018-02-08 06:46:06 +00:00
Josh Stone
a7bd6a0f4b Release 0.1.42 2018-02-07 22:42:51 -08:00
bors[bot]
07a2d6adbe Merge #15
15: Implement Stein's algorithm for gcd r=cuviper a=Emerentius

This implements Stein's algorithm for bigints.
Asymptotically this has the same runtime complexity as the euclidean algorithm but it's faster because it avoids division in favor of bitshifts and subtractions.
There are faster algorithms for large bigints. For small ones, [gmp uses the binary gcd too](https://gmplib.org/manual/Binary-GCD.html).

I've run some benchmarks with the code in [this repo](https://github.com/Emerentius/bigint_gcd_bench)
This iterates through the sizes of 1-10 `BigDigit`s and generates 300 uniformly distributed random bigints at each size and computes the gcd for each combination with both Euclid's and Stein's algorithm. I'm only looking at combinations of numbers with the same number of `BigDigit`s

The speed gains are sizeable. See the benchmark results below. I'm running this on an ultrabook with a 15W CPU (i5 4210u). Performance may differ on different architectures, in particular if there is no intrinsic for counting trailing zeroes.

Please run the benchmark on your machine. It's just a simple
```
git clone https://github.com/Emerentius/bigint_gcd_bench
cargo run --release
```

```
2^32n bits	euclidean gcd	binary gcd	speedup
n:  1 =>	0.3050s		0.0728s		4.19
n:  2 =>	0.6228s		0.1453s		4.29
n:  3 =>	0.9618s		0.2214s		4.34
n:  4 =>	1.3021s		0.3028s		4.30
n:  5 =>	1.6469s		0.3875s		4.25
n:  6 =>	2.0017s		0.4759s		4.21
n:  7 =>	2.3636s		0.5667s		4.17
n:  8 =>	2.7284s		0.6418s		4.25
n:  9 =>	3.0712s		0.7302s		4.21
n: 10 =>	3.4822s		0.8223s		4.23
```

The guys at gmp say these algorithms are quadratic in N, I'm not sure why they seem almost linear here.
2018-02-08 06:27:38 +00:00
Josh Stone
e45b2b7d0c reduce allocations in shr 2018-02-07 22:19:20 -08:00
Josh Stone
4714f829df small gcd cleanups 2018-02-07 21:59:31 -08:00
Josh Stone
f5c05461d7 use an iterator for trailing_zeros 2018-02-07 21:59:13 -08:00
Josh Stone
a46f422412 Remove unnecessary core import 2018-02-07 21:57:41 -08:00
Josh Stone
8893408c30 add a gcd benchmark 2018-02-07 21:56:28 -08:00
Emerentius
ba54f17366 implement Stein's algorithm for gcd
same asymptotic complexity as euclidean but faster
thanks to bitshifts and subtractions rather than division
2018-02-07 21:38:25 -08:00
Emerentius
b2ff86b6c9 allow_unused AsciiExt
the methods are implemented on the types directly since
rust 1.23
the trait's still needed for backwards compatibility
2018-02-07 21:38:25 -08:00
bors[bot]
c0ab6c3c6a Merge #11
11: Relax rand version r=cuviper a=ignatenkobrain

Signed-off-by: Igor Gnatenko <ignatenko@redhat.com>
2018-02-08 05:05:16 +00:00
Josh Stone
5a9e112e96 hack rand down for rustc 1.8 2018-02-07 18:17:42 -08:00
Igor Gnatenko
39b88b41d2 Relax rand version
Signed-off-by: Igor Gnatenko <ignatenko@redhat.com>
2018-01-01 12:13:37 +01:00
Josh Stone
5918a72299 Add [[bench]] details 2017-12-18 17:29:34 -08:00
Josh Stone
d0ea91938c ci: test serde like other features 2017-12-18 14:13:50 -08:00
Josh Stone
7c802dca67 rustup.sh: CI uses stable 2017-12-18 13:59:35 -08:00
Josh Stone
6a41eaa46f Move num-bigint to its own repo
All the prior `num` history is kept, so old `num-bigint` tags are still
valid, but future development here will be just for `num-bigint`.
2017-12-17 15:44:53 -08:00
bors[bot]
f172ef3a6b Merge #350
350: Avoid large intermediate product in LCM r=cuviper a=mhogrefe

Changed the implementation of BigUint LCM from
`((self * other) / self.gcd(other))`
to
`self / self.gcd(other) * other`

The division is exact in both cases, so the result is the same, but the new code avoids the potentially-large intermediate product, speeding things up and using less memory.

I also removed the unnecessary parentheses, because I think it's clear what order everything will be executed in. But if others think differently I can add them back.
2017-12-14 08:07:15 +00:00
bors[bot]
a0c431e270 Merge #351
351: Remove num-macros r=cuviper a=cuviper

The first commit gives a final deprecation bump to `num-macros`, and
the second removes it from the repo altogether.
2017-12-14 07:54:24 +00:00
Josh Stone
d90ae0ae8b Remove num-macros 2017-12-13 23:44:49 -08:00
Josh Stone
bd1701ded4 macros: bump to 0.1.40, deprecated 2017-12-13 23:41:50 -08:00
Mikhail Hogrefe
56a029b20f Avoid large intermediate product in LCM 2017-12-13 21:13:57 -05:00
Josh Stone
c24f76781b num: bump to 0.1.41
Syncing the metacrate to the latest of all subcrates.
2017-12-01 13:31:33 -08:00
Josh Stone
98cb815183 bigint: bump to 0.1.41
- Now uses Toom-3 multiplication for large inputs.
- `BigInt`/`BigUint` parsing now accepts `_` separating digits.
- `BigInt`/`BigUint::assign_from_slice` reinitializes the value, keeping
  the same internal buffer.
- `BigUint` now implements many `*Assign` ops.
- `BigUint::modpow(exp, mod)` performs efficient modular exponentiation.
2017-12-01 13:15:22 -08:00
Josh Stone
18b48f335e complex: bump to 0.1.41
`Complex` now implements `Num`, `Rem`, and `RemAssign`.

(Complex remainders don't have a clear mathematical basis, but we choose
to round toward zero to a gaussian integer.)
2017-12-01 13:02:13 -08:00
Josh Stone
0e1c4c8b65 traits: bump to 0.1.41
minor warning fixes
2017-12-01 12:54:48 -08:00
bors[bot]
0e31f3c6b3 Merge #345
345: Downgrade libc for Rust 1.8 CI r=cuviper a=cuviper
2017-12-01 01:30:41 +00:00
Josh Stone
a7464b2b42 Roll back libc in the ci scripts too 2017-11-30 17:01:09 -08:00
Josh Stone
d354559365 Downgrade libc for Rust 1.8 CI 2017-11-30 16:15:45 -08:00
Josh Stone
cc3be86781 rational: bump to 0.1.40 2017-11-08 14:40:10 -08:00
bors[bot]
ca7e438d77 Merge #342
342: rational: check for NaN when approximating floats r=cuviper a=cuviper

We had a test for NaN already, but thanks to undefined casts (#119) it
was only passing by luck -- on armv7hl it failed:

https://bugzilla.redhat.com/show_bug.cgi?id=1511187

Now we check for NaN explicitly.
2017-11-08 22:29:38 +00:00
Josh Stone
b67f1bd6d6 rational: check for NaN when approximating floats
We had a test for NaN already, but thanks to undefined casts (#119) it
was only passing by luck -- on armv7hl it failed:

     https://bugzilla.redhat.com/show_bug.cgi?id=1511187

Now we check for NaN explicitly.
2017-11-08 14:09:05 -08:00
bors[bot]
a203e9f9fc Merge #339
339: Implement modpow() for BigUint backed by Montgomery Multiplication r=cuviper a=str4d

Based on this Gist: https://gist.github.com/yshui/027eecdf95248ea69606

Also adds support to `BigUint.from_str_radix()` for using `_` as a visual separator.

Closes #136
2017-11-02 19:37:52 +00:00
Josh Stone
ed10d617b5 bigint: Add a modpow fallback for even modulus 2017-10-22 16:44:05 -07:00
Josh Stone
35b7187e83 bigint::monty: use infallible conversions in tests 2017-10-22 15:49:51 -07:00
Josh Stone
bb0c9324b2 bigint::monty: deduplicate mr.n and mr.p 2017-10-22 15:45:01 -07:00
Josh Stone
b380880ed3 bigint::monty: simplify modpow zero test 2017-10-22 15:38:50 -07:00
Josh Stone
96c4a26624 bigint::monty: simplify modpow parameter init 2017-10-22 15:37:48 -07:00