Commit graph

149 commits

Author SHA1 Message Date
Sylvestre Ledru
f37284129e new release 0.0.6 to address the cat issue 2021-04-03 16:06:58 +02:00
Sylvestre Ledru
ac031dffa4 new release 0.0.5 2021-04-03 10:30:07 +02:00
Sylvestre Ledru
4d7ad77433 rustfmt the recent change 2021-04-02 23:31:22 +02:00
est31
14a49edd1c
Use Iterator::copied() in sieve.rs (#1774) 2021-04-02 23:30:07 +02:00
nicoo
8b9ac0c7c3
Revert #1571 “perf/factor ~ deduplicate divisors” (#1842)
It was a draft PR, not ready for merging, and its premature inclusion
caused repeated issues, see 368f47381b & friends.

Close #1841.

This reverts commits 3743a3e1e7,
                     ce218e01b6, and
                     b7b0c76b8e.
2021-03-20 11:46:58 +01:00
nicoo
955fa74a42
factor::tests: Check that powers of known-factorization numbers are factored correctly (#1831)
* factor::tests::recombines_factors: Minor refactor (skip useless bool)

* factor::tests: Check factorizations of powers of factored numbers

* factor::Factors: Add debug assertions to (Factor ^ Exponent)

* factor::tests: Drop obsoleted tests

`factor_correctly_recombines_prior_test_failures` was replaced with
`factor_2044854919485649` as this was the only test not subsumed.

* factor::tests::2044854919485649: Check the expected factorisation
2021-03-17 13:58:53 +01:00
Sylvestre Ledru
6ad8528b99 update of the uucore dep to 0.0.7 2021-03-07 11:29:38 +01:00
Sylvestre Ledru
6481c5a247 Prepare version 0.0.4 2021-03-07 11:29:38 +01:00
Alex Lyon
7e5d9ee32d
factor, stdbuf, timeout, uname, uptime: update dependencies (#1746) 2021-02-22 15:07:51 +01:00
Sylvestre Ledru
262b508b89 update the dep to uucore 0.0.6 2021-02-01 23:55:43 +01:00
Sylvestre Ledru
a807fc623a Update to version 0.0.3 2021-01-22 09:40:38 +01:00
nicoo
ea20b22d12 factor::numeric::gcd: Refactor divisor test
Should be clearer; does not handle the `gcd(0, 0)` case, which is already
covered by the `zero` test.
2021-01-21 15:28:28 +01:00
nicoo
42b048d316
factor: Get rid of the custom OverflowingAdd trait (#1697)
* factor: Confine knowledge of num_traits to numeric::traits

This should make it easier to deal with API changes of num_traits,
or eventually switching to an abstraction provided in the stdlib.
2021-01-21 15:27:22 +01:00
Sylvestre Ledru
b8e886ad1a bump the minimal version of uucore & uucore_procs 2021-01-10 18:27:20 +01:00
Sylvestre Ledru
d9ae043a05
update of the version 0.0.1 => 0.0.2 (#1686) 2021-01-10 18:16:04 +01:00
Sylvestre Ledru
7942a64231 Remove 'extern crate'
Not necessary anymore. See:
https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html#no-more-extern-crate
2020-12-31 15:44:00 +01:00
Roy Ivy III
6539b8c6b9 maint/deps ~ change version specification for dependencies between sub-packages
- refactor internal version specifications to be ">=M.m.p" (where M.m.p is *already published*)

## [why]

Loosening internal version dependencies decreases the coupling between packages such
that packages can be published in a looser order. It allows the packages to be version
updated and published in tandem (ie, by using `cargo workspace ...`). Once published,
the internal versions can then be updated (again, to an *already published* package
version), as needed.
2020-11-08 20:26:46 -06:00
Roy Ivy III
c17307c757 fix ~ update workspace pointers to 'uucore' and 'uucore_procs' 2020-11-08 20:26:46 -06:00
Roy Ivy III
114fda0519 tests ~ (sub-crate factor) refactor divisor() test for improved readability 2020-10-26 15:06:29 -05:00
Roy Ivy III
ae06368cd8 polish/factor ~ correct spelling 2020-10-26 15:06:29 -05:00
Roy Ivy III
6a525c950d perf/factor ~ tune number of stack inlined decomposition values (~1% time improvement) 2020-10-26 15:06:29 -05:00
Roy Ivy III
6eea8c5f30 perf/factor ~ improve factor() quotient and loop comparison (~6% time improvement) 2020-10-26 15:06:28 -05:00
Roy Ivy III
368f47381b fix/factor ~ fix fault when factoring number composed of a squared factor 2020-10-26 15:06:28 -05:00
Roy Ivy III
8593b4c46c tests ~ (sub-crate/factor) add tests for known prior factorization failures 2020-10-26 15:06:28 -05:00
Roy Ivy III
3bb3080170 factor/refactor ~ fix cargo clippy complaints (allow many_single_char_names) 2020-10-26 15:06:28 -05:00
nicoo
0d39732300 factor::Decomposition: Inline a small number (4) of factors
This avoids allocating on the heap when factoring most numbers,
without using much space on the stack.

This is ~3.5% faster than the previous commit, and ~8.3% faster than “master”.
2020-10-26 15:06:28 -05:00
nicoo
78ae0cca31 factor: Slightly refactor main loop, fix bug 2020-10-26 15:06:28 -05:00
nicoo
b7b0c76b8e factor::Decomposition: Optimise as a factor is never added twice
The invariant is checked by a debug_assert!, and follows from the previous
commit, as `dec` and `factors` only ever contains coprime numbers:
  - true at the start: factor = ∅ and dec = { n¹ } ;
  - on every loop iteration, we pull out an element `f` from `dec` and either:
    - discover it is prime, and add it to `factors` ;
    - split it into a number of coprime factors, that get reinserted into `dec`;
      the invariant is maintained, as all divisors of `f` are coprime with all
      numbers in `dec` and `factors` (as `f` itself is coprime with them.

As we only add elements to `Decomposition` objects that are coprime with the
existing ones, they are distinct.
2020-10-26 15:06:28 -05:00
nicoo
ce218e01b6 factor: Ensure we only need to find every single factor once [WiP]
~17% faster, many optimisation opportunities still missed  >:)
2020-10-26 15:06:28 -05:00
nicoo
3743a3e1e7 factor: Derecursify and refactor
~7% slowdown, paves the way for upcoming improvements
2020-10-26 15:06:28 -05:00
nicoo
8643489096 factor::Factors: Use a RefCell rather than copy data when printing
~2.9% faster than the previous commit, ~11% faster than “master” overall.
2020-10-26 15:06:28 -05:00
nicoo
30f9cf32f2 factor::Decomposition: Use a flat vector representation
~18% faster than BTreeMap, and ~5% faster than 'master'
2020-10-26 15:06:27 -05:00
nicoo
b8ef58c002 factor::Factors: Split off a Decomposition type
The new type can be used to represent in-progress factorisations,
which contain non-prime factors.
2020-10-26 15:06:27 -05:00
nicoo
6158cd5714 factor: Introduce a type alias for exponents
This way, we can easily replace u8 with a larger type when moving to support
larger integers.
2020-10-26 15:06:27 -05:00
Roy Ivy III
92075c7d14 refactor/polish ~ (factor) fix cargo clippy complaint (unused_imports) 2020-10-16 20:25:49 -05:00
nicoo
9a1c560aba
factor: Refactor and optimise the Factors datastructure (#1572)
* factor: Introduce a type alias for exponents

This way, we can easily replace u8 with a larger type when moving to support
larger integers.

* factor::Factors: Split off a Decomposition type

The new type can be used to represent in-progress factorisations,
which contain non-prime factors.

* factor::Decomposition: Use a flat vector representation

~18% faster than BTreeMap, and ~5% faster than “master”.

* factor::Factors: Use a RefCell rather than copy data when printing

~2.9% faster than the previous commit, ~11% faster than “master” overall.
2020-09-21 21:44:50 +02:00
Roy Ivy III
c33284f38b factor::numeric::gcd: modify divisor() test to return correct true/false results for all possible inputs 2020-09-03 14:56:14 -05:00
nicoo
07eaa7fe5a factor::numeric::gcd: Add explicit test for the 0 case 2020-09-03 14:56:14 -05:00
nicoo
c11cebc4d3 factor::numeric::gcd: Exclude the 0 case from test divisor 2020-09-03 14:56:10 -05:00
Roy Ivy III
2a50dc42c1 tests ~ (sub-crate/factor) fix divisor(0,0) test of factor::numeric::gcd() with early value check and return (fixes #1587) 2020-08-19 09:13:09 -05:00
nicoo
dc6b9a8d62
CI: Improve annotations (#1584)
* CI: Only run rustfmt in one environment

- This displays clippy warnings even when rustfmt fails.
- This avoids displaying 3 copies of the same rustfmt warning as Github
  annotations.
- Avoids duplicated work.

* CI: Suppress warnings when building for the oldest toolchain version

We had cases of warnings emitted due to `rustc` bugs that were fixed
in non-obsolete versions.

* factor: Remove a workaround for warnings on obsolete rustc
2020-08-10 16:53:32 +02:00
nicoo
d9be24e354 factor: Make the implementation of GCD more readable (#1576)
* factor::numeric::gcd: Switch variable names to be more consistent

* factor::numeric::gcd: Improve comments

* factor::numeric::gcd: Extend loop invariant to v
2020-08-08 22:26:49 -05:00
nicoo
37f717f5e3 factor: Add tests against (random) numbers with known factorisations (#1573) (#1578)
* factor::Factors: Derive implementations of Eq and PartialEq

* factors::Factors: Implement quickcheck::Arbitrary

This generates uniformly-distributed integers with known factorisations,
and will enable further testing.

* factor: Test against random numbers with known factorisations

* factor::Factors::arbitrary: Simplify method signature
2020-08-08 22:26:25 -05:00
nicoo
34a5941ee9
factor::numeric: Add more property-based tests (#1577)
* factor::numeric::gcd: Rename test against the Euclidean algorithm

* factor::numeric::gcd: Add various property-based tests

* factor::numeric::modular_inverse: Rename test

* factor::numeric::modular_inverse: Add test on random values
2020-08-03 14:00:34 +02:00
nicoo
70828329ba
factor::miller_rabin: Deduplicate parametrized_check macro (#1575)
* factor::miller_rabin::tests::first_composite: Drop useless generic

* factor::miller_rabin::tests: Reuse parametrized_check macro
2020-08-03 13:58:09 +02:00
nicoo
1eabda91cf
factor: Split numeric.rs into multiple modules (#1567)
* factor::numeric: Start refactoring into multiple submodules

No change to the module's interface, but it should make it much easier to
keep the tests right next to the code they are related to.

Moreover, build.rs' dependency is now limited to numeric::{modular_inverse,
traits}, meaning that the rest of it can use build-time generated tables etc.

* factor::numeric: Move gcd (and its test) to a submodule

* factor::numeric: Move Montgomery arithmetic to its own module

Finally hollowed-out numeric.rs

* factor: Move numeric.rs to numeric/mod.rs

* factor::numeric: Fix an erroneous lint on obsolete Rust versions
2020-08-02 20:28:00 +02:00
nicoo
645e9a24bd factor::miller_rabin: Add missing copyright header in source file 2020-07-26 14:59:30 +02:00
Roy Ivy III
a6d7379b97
Merge pull request #1563 from nbraud/factor/faster/gcd
factor/perf ~ speed up factor::numeric::gcd
2020-07-25 11:07:57 -05:00
nicoo
6bef6306c0 factor::numeric::gcd: Avoid redundant u64::trailing_zeros and shifts
7 to 10% faster, according to criterion.
2020-07-25 15:04:57 +02:00
nicoo
3e55139c13 factor::miller_rabbin::Result: Mark as #[must_use]
Ignoring a value of that type is a bug: they are only produced by
`miller_rabbin::test`, which is a pure, but expensive, function.

As such, an ignored value is always either a mistake, or an easy
optimisation opportunity (just remove the useless call to `test`).
2020-07-24 23:06:08 +02:00