Commit graph

1437 commits

Author SHA1 Message Date
nicoo
e68bb192f2 factor::numeric: Add a 32b Montgomery variant [WiP]
~32% faster
2020-07-05 00:01:21 +02:00
nicoo
43ee92c40f factor::numeric: Generalise modular inverse computation 2020-07-05 00:01:21 +02:00
Alex Lyon
9de82d92b0
Merge pull request #1557 from nbraud/factor/issue_1556
factor::miller_rabin: Fix bug #1556
2020-06-24 04:53:32 -07:00
Alex Lyon
700d51a92b
Merge pull request #1528 from sylvestre/cp-no-deref
feature(cp) implement -P/--no-deference
2020-06-23 23:05:26 -07:00
nicoo
abf579975c factor::miller_rabin: Fix bug in primality test
Introduced in 6b9585b1 (#1525: Performance improvements for `factor`).
Closes #1556
2020-06-23 16:19:16 +02:00
nicoo
c5c86b00e9 factor::miller_rabin: Add tests reproducing #1556 2020-06-23 16:14:52 +02:00
nicoo
8e040bbf1a factor::table: Optimise the size of the precomputed table
A too-large precomputed table actually slows down the program: we spend
time fetching it from disk and from memory (into the CPU's cache), and
larger prime factors are more unlikely to occur in random integers (prime p
occurs with probability ~1/p when sampling 64b numbers uniformly-at-random)

The new value was chosen after measuring the execution time (for all
integers between 2 and 10⁷) for a broad set of values:

| n    | time (s) |
|------|----------|
| 16   | 40.84    |
| 32   | 34.491   |
| 64   | 29.044   |
| 128  | 25.121   |
| 192  | 23.98    |
| 256  | 23.102   |
| 256  | 24.93    |
| 272  | 23.57    |
| 288  | 23.85    |
| 304  | 23.91    |
| 320  | 23.24    |
| 329  | 23.45    |
| 336  | 23.55    |
| 352  | 23.09    |
| 368  | 23.65    |
| 384  | 23.32    |
| 384  | 23.36    |
| 400  | 23.30    |
| 416  | 23.38    |
| 432  | 23.42    |
| 448  | 23.95    |
| 448  | 24.00    |
| 464  | 23.81    |
| 480  | 23.55    |
| 496  | 24.10    |
| 512  | 24.101   |
| 512  | 24.23    |
| 1027 | 29.864   |
2020-06-20 22:22:55 +02:00
nicoo
9d992b77b2 factor: Keep the primes table size in a single place 2020-06-20 22:22:55 +02:00
nicoo
b956e632e1 factor::table: Coalesce accesses to the factors table
~5.6% faster
2020-06-20 22:22:55 +02:00
Sylvestre Ledru
2d62097843 feature(cp): Manage -P & -R 2020-06-20 10:49:15 +02:00
nicoo
0518e06053 factor::rho: Minor refactor for readability 2020-06-20 10:39:56 +02:00
nicoo
dacee413db factor::rho: Refactor to avoid unnecessary allocations 2020-06-20 10:39:56 +02:00
nicoo
71e1c52920 factor::Factors: Rename new() to one() 2020-06-20 10:39:56 +02:00
Sylvestre Ledru
280fafed8a feature(cp) implement -P/--no-deference 2020-06-20 09:38:39 +02:00
nicoo
45a1408fb0 fixup! factor: Add test exhibiting a bug in ρ 2020-06-19 15:28:01 +02:00
nicoo
9fe3de72f2 factor::rho: Fix very-unlikely bug (resulting in assertion failure)
This bug can only be triggered when:
- the Miller-Rabin test produces a divisor `d` (rare) ;
- n / d is prime.
2020-06-19 13:51:29 +02:00
nicoo
9eb944b6b9 factor: Add test exhibiting a bug in ρ
The test is repeated 20 times to make it overwhelmingly-likely to fail
(the bug itself is only triggered rarely)
2020-06-19 13:48:00 +02:00
nicoo
3a90e31307 factor::numeric::inv_mod_u64: Provide a more-helpful error message 2020-06-19 13:39:42 +02:00
nicoo
ef12991ee7 factors: Avoid repeatedly locking and flushing stdout
By default, stdout's LineWriter results one syscall per line, i.e. a billion
syscalls when factoring a billion numbers...

Buffering the output yields a ~28% speedup.
2020-06-18 16:45:40 -07:00
nicoo
2869248318 factor::Factors: Use a tree-based map internally
This eliminate the need for sorting the prime factors for display.
25% performance improvement after the changes from factor/montgomery.
2020-06-18 16:44:08 -07:00
nicoo
4b4d11b61a
factor: Add/update copyright notices as necessary (#1546) 2020-06-18 21:38:28 +02:00
Alex Lyon
6105cce69a
Merge pull request #1529 from nbraud/factor/montgomery
factor: Faster modular arithmetic with the Montgomery transform
2020-06-18 09:19:12 -07:00
nicoo
fb08d9ff9e factor::numeric::Montgomery::add: Deal with rare overflow case 2020-06-18 14:32:58 +02:00
Alex Lyon
e02b8a60f7
hashsum: switch from getopts to clap (#1542)
* hashsum: switch from getopts to clap

Additionally, slightly refactor.  This commit will be the first of
a series of commits refactoring (at the very least) `hashsum`.
2020-06-18 11:46:00 +02:00
Sylvestre Ledru
f17a112781
feature(ln): implement -r (#1540)
* bump the minimal version of rustc to 1.32

* feature(ln): implement -r

* fix two issues

* Use cow

* rustfmt the change

* with cargo.lock 1.31

* try to unbreak windows
2020-06-18 00:54:18 -07:00
nicoo
d1470dadf8 factor::numeric::gcd: Silence the (erroneous) dead code lint 2020-06-16 15:45:10 +02:00
nicoo
334e02786d factor: Run cargo fmt 2020-06-16 15:43:25 +02:00
Alex Lyon
8377abadb6
Fix to build on Rust 1.32.0 and formatting 2020-06-16 04:08:17 -05:00
Alex Lyon
110d6844ad
Use an iterator over OsString for uumain()
Additionally, restructure `uname` so that we don't need to find the
iterator's length.
2020-06-16 03:28:02 -05:00
nicoo
f1788d9e70 fixup! factor::numeric::Montgomery: Fix overflow bug 2020-06-16 01:17:16 +02:00
nicoo
4851619d62 factor::miller_rabin: Avoid repeatedly transforming 1 and -1
Approx. 25% speedup
2020-06-15 23:05:31 +02:00
nicoo
cb6051c580 factor::numeric::Montgomery: Fix overflow bug 2020-06-15 22:40:57 +02:00
nicoo
2238065c9d factor::numeric: Simplify Montgomery (remove superfluous Wrapping) 2020-06-15 19:18:34 +02:00
nicoo
19a0645a0a factor::numeric: Simplify inv_mod_u64
Just call `u64::wrapping_{mul,sub}` instead of (de)constructing Wrapping<u64>
values.
2020-06-15 19:18:34 +02:00
nicoo
918035e01e factor: Fix for old Rust 2020-06-15 19:18:34 +02:00
nicoo
f84d0f9398 factor::Factors::add: Make the precondition check a debug_assert 2020-06-15 19:18:34 +02:00
nicoo
33e18b4cd3 factor::numeric::Montgomery: Add debug assertions
In debug mode, checks that all arithmetic operations coincide with the
plain-u64 versions, as long as the latter does not overflow.
2020-06-15 19:18:34 +02:00
nicoo
8a4d0d30ad factor::numeric: Implement Montgomery's transform
This is a facter way to perform arithmetic mod n, when n is odd and a 64b
number.
2020-06-15 19:18:29 +02:00
nicoo
e91155519a factor::factor: Add integration tests 2020-06-15 19:10:16 +02:00
nicoo
bada7530fb factor::miller_rabin: Add tests 2020-06-15 19:10:16 +02:00
Roy Ivy III
813e57d225 fix cargo clippy complaint (redundant_clone) 2020-06-14 23:38:30 -05:00
Roy Ivy III
39e3c57198 fix cargo clippy complaint (clone_on_copy) 2020-06-14 23:38:30 -05:00
Sylvestre Ledru
7b452f3bfe style(nproc): reformat with rustfmt 2020-06-09 13:38:29 +02:00
Sylvestre Ledru
ac34d136f2 refactor(global): Move from tempdir to tempfile:
* the crate has been deprecated
2020-06-09 11:30:19 +02:00
Alex Lyon
80987250d2
Merge pull request #1521 from sylvestre/nproc
Add tests for nproc + clap migration
2020-06-08 19:18:00 -07:00
Alex Lyon
49771d4fda
Merge pull request #1535 from sylvestre/1.32
Move to 1.32 as minimal supported version
2020-06-08 14:31:02 -07:00
Sylvestre Ledru
5926315507 bump the minimal version of rustc to 1.32 2020-06-08 22:54:28 +02:00
Sylvestre Ledru
d0890b72cd
Merge pull request #1522 from sylvestre/groups
groups: clap migration
2020-06-08 22:19:08 +02:00
Sylvestre Ledru
851e25d134 refactor(logname): simplify the code 2020-06-07 17:54:30 +02:00
Sylvestre Ledru
5963b15746 refactor(nproc): fix some bugs and use clap 2020-06-02 23:29:21 +02:00