Commit Graph

950 Commits

Author SHA1 Message Date
Mateusz Pusz
f0885f8027 feat: scaled units are now enclosed in parenthesis (...) instead of brackets [...] 2024-11-29 12:17:53 +01:00
Mateusz Pusz
52e95f9b2e test: a few more natural units tests added 2024-11-29 11:11:13 +01:00
Mateusz Pusz
a223c08a39 refactor: multiplication and division by scalars was a bad idea for Complex and Vector 2024-11-28 23:02:11 +01:00
Mateusz Pusz
465f88d500 refactor: 💥 is_XXX customization points for representation types removed 2024-11-26 14:48:08 +01:00
Mateusz Pusz
b77aa52355 refactor: absolute renamed to point
Resolves #645
2024-11-24 14:19:16 +01:00
Mateusz Pusz
9a0f7a25dd test: tests for dimensionless quantities static data members 2024-11-23 19:35:59 +01:00
Mateusz Pusz
0c09008671 fix: clang is too stupid to provide a deprecation warning for text_encoding 2024-11-21 11:25:57 +01:00
Mateusz Pusz
16e816d4cb refactor: 💥 Magnitude renamed to UnitMagnitude and magnitude to unit_magnitude 2024-11-21 08:58:18 +01:00
Mateusz Pusz
8ae21ffcc9 refactor: 💥 text_encoding renamed to character_set 2024-11-19 14:44:59 +01:00
Mateusz Pusz
623930ccee refactor: convertible_impl refactored to convertible + results caching 2024-11-16 22:11:59 +01:00
Mateusz Pusz
4f8e959b5c fix(test): shadowing warnings on gcc fixed 2024-11-16 08:28:39 +01:00
Mateusz Pusz
4aaebb9426 Merge branch 'master' of github.com:mpusz/units 2024-11-16 08:07:33 +01:00
Chip Hogg
de68b3a9f1 Replace old factoring with Baillie-PSW 2024-11-15 13:30:05 -05:00
Chip Hogg
3b586a685f Implement Baillie-PSW 2024-11-15 13:30:05 -05:00
Chip Hogg
9e8dfec265 Add the Strong Lucas Probable Prime test
This is more involved than the Miller-Rabin test, but we can tame the
complexity by breaking it down into helper functions, performing tasks
such as:

- Increment the index of the (U_k, V_k) sequence elements by one.
- Double the index of the (U_k, V_k) sequence elements.
- Find an appropriate D parameter.

etc.

With these helpers, the algorithm becomes straightforward (see, for
instance,
https://en.wikipedia.org/wiki/Lucas_pseudoprime#Strong_Lucas_pseudoprimes).
We start by ruling out perfect squares (because if we don't, then the
search for `D` will never terminate).  Then we find our `D`, and
decompose `n + 1` into `s` and `d` parameters (exactly as we did for
Miller-Rabin, except there we used `n - 1`).  At this point, the strong
test is easy: check whether `U_d` is 0, then check `V_d`, as well as `V`
for all successive doublings of the index less than `s`.

A similar testing strategy as for the Miller Rabin gives us sufficient
confidence.

1. Test that we get small primes right.
2. Test that we get known pseudoprimes "correctly wrong".
3. Test some really big primes.

(Remember, a probable prime test must mark every actual prime as
"probably prime".)

Helps #509.
2024-11-15 10:53:26 -05:00
Mateusz Pusz
c901b73ee5 Merge pull request #639 from chiphogg/chiphogg/jacobi#509
Add utilities to make Strong Lucas tests easier
2024-11-15 15:57:09 +01:00
Chip Hogg
26639dab34 Add some more 2024-11-15 09:39:39 -05:00
Mateusz Pusz
08e94171cb test: vector quantities unit tests addded 2024-11-15 12:59:18 +01:00
Chip Hogg
d56ffc08b8 Add utilities to make Strong Lucas tests easier
The Strong Lucas test coming in the next PR will already be complicated
enough.  It'll be convenient, and less distracting, if we already have
functions for certain operations we'll need.

One thing we'll need to do is detect inputs that are perfect squares.
Fortunately, this is pretty easy to do robustly and quickly, with
Newton's method.  We _don't_ want to use `std::sqrt`, because that takes
us into the floating point domain for no good reason, which could give
us wrong answers for larger integers.

The other thing we need is Jacobi symbols.  These are a lot more
obscure, but thankfully, still resonably straightforward to compute.
The Wikipedia page (https://en.wikipedia.org/wiki/Jacobi_symbol) has a
good explanation, and in particular, good instructions for computing
values.

With these utilities in place, the Strong Lucas code should be easier to
review.
2024-11-14 20:14:20 -05:00
Mateusz Pusz
1581fa59ad test: extend concepts tests with cartesian_vector as a representation 2024-11-14 20:42:21 +01:00
Mateusz Pusz
2cf64f20c5 fix: cartesian_vector convertibility tests fixed 2024-11-14 20:40:08 +01:00
Mateusz Pusz
a7cf015a3e feat: add compound assignment operators to cartesian_vector 2024-11-14 20:38:50 +01:00
Mateusz Pusz
4b5d37e83e feat: constructors of cartesian_vector refactored 2024-11-14 20:30:12 +01:00
Chip Hogg
cfd9ddb675 Add Miller-Rabin probable prime test
This can mark a number as either "probably prime", or "definitely
composite".  The first parameter is the base, and the second is the
number to test.

Future PRs will build up the Strong Lucas test which complements this,
and then form the Baillie-PSW test by composing the two.

Helps #506.
2024-11-13 19:56:05 -05:00
Mateusz Pusz
2590aa4b80 refactor: MP_UNITS_NONCONST_TYPE introduced to benefit from the C++23 feature 2024-11-13 21:13:22 +01:00
Chip Hogg
b99faf051b Merge branch 'master' into chiphogg/mod#509 2024-11-13 08:41:52 -05:00
Mateusz Pusz
420ffef6c5 fix(test): missing header files added 2024-11-12 18:12:36 +01:00
Mateusz Pusz
73ad1f08d4 fix: fmt_test fixed to use delta to create a quantity of thermodynamic_temperature 2024-11-12 16:20:51 +01:00
Mateusz Pusz
520610ab2f test: cartesian_vector used in cgs_test 2024-11-12 14:39:04 +01:00
Mateusz Pusz
5a206c3ef1 test: cartesian_vector used in fmt_test 2024-11-12 14:38:51 +01:00
Mateusz Pusz
6c3c1fe5f7 feat: cartesian_vector added 2024-11-12 14:34:18 +01:00
Mateusz Pusz
d8574022f1 test: _surface tension_ replaced with _entropy_ in an fmt test 2024-11-12 14:21:36 +01:00
Mateusz Pusz
c6344c26ee style: missing empty line at the end of the file added 2024-11-12 11:31:26 +01:00
Mateusz Pusz
78204c7e5f test: runtime unit tests refactored to have a bigger granularity (less top level tests) 2024-11-12 11:27:52 +01:00
Mateusz Pusz
0e7314e3a6 fix: math tests for inverse fixed after change in make_reference 2024-11-12 08:50:11 +01:00
Mateusz Pusz
8ec2f94ae2 fix: make_reference should skip only the exact kinds deduced from a unit 2024-11-11 23:36:58 +01:00
Chip Hogg
8a7483f7ea Add helpers for modular arithmetic
The prime-testing techniques we will use (Miller-Rabin, Strong Lucas)
all make heavy usage of modular arithmetic.  Therefore, we lay those
foundations here, adding utilities to perform the basic arithmetic
operations robustly.

Since these are internal-only helper functions, we don't bother checking
the preconditions, although we state them clearly in the contract
comment for each utility.  After C++26, we could add contracts for
these.

Helps #509.
2024-11-11 12:55:41 -05:00
Mateusz Pusz
b4810089ec fix: gcc-12 compilation fixed
Resolves #632
2024-11-09 23:02:12 +01:00
Mateusz Pusz
06853b7aeb fix: const was leaking to some SymbolicConstants 2024-11-08 12:57:29 +01:00
Mateusz Pusz
5097096915 test: lots of tests for complex quantities 2024-11-07 18:42:20 +01:00
Mateusz Pusz
da50348115 feat: 💥 RepresentationOf concept now also accepts a QuantitySpec and accepts any representation character for quantity kinds 2024-11-07 18:39:32 +01:00
Mateusz Pusz
75b50b8d2c feat: complex.h added 2024-11-07 10:58:51 +01:00
Mateusz Pusz
6896d8e086 fix: velocity is now defined in terms of displacement instead of position_vector 2024-11-06 18:46:01 +01:00
Mateusz Pusz
c7303cc5fb refactor: representation concepts refactored + some quantities switched to complex 2024-11-05 19:09:16 +01:00
Mateusz Pusz
2892fd83b0 test: more get_common_quantity_spec tests added 2024-11-05 08:06:45 +01:00
Mateusz Pusz
cc25f9b0de refactor: get_complexity refactored to returned maximum complexity of an element (instead of the sum of elements) 2024-11-04 19:13:48 +01:00
Mateusz Pusz
467d9a5558 refactor: get_complexity refactored to be 0-based and not account for a number of arguments in a list 2024-11-04 18:04:01 +01:00
Mateusz Pusz
73a003d0ef test: additional kind to quantity spec convertibility test added 2024-11-04 18:02:37 +01:00
Mateusz Pusz
f461cf479b test: test for lack of consitency between op+ and op+= for quantity_point 2024-11-04 09:41:11 +01:00
Mateusz Pusz
5810420277 refactor: 💥 tag types should not expose their members 2024-11-04 09:40:25 +01:00