Commit Graph
1961 Commits
Author SHA1 Message Date
Mateusz Pusz 8ae21ffcc9 refactor: 💥 text_encoding renamed to character_set 2024-11-19 14:44:59 +01:00
Mateusz Pusz dcf05687cf perf: expr_projectable concept removed to improve compilation performance 2024-11-18 20:34:15 +01:00
Mateusz Pusz c1d323a91a fix: gcc-13
gcc-13 ICE on `decltype(auto(...))`
2024-11-18 09:58:01 +01:00
Mateusz Pusz 51f2539fae build: MP_UNITS_DEV_TIME_TRACE CMake option added 2024-11-17 13:35:12 +01:00
Mateusz Pusz dc847ca360 build: CheckCacheVarValues CMake module file added 2024-11-17 13:34:04 +01:00
Mateusz Pusz 79f42e8877 refactor: small detail namespace cleanup for units 2024-11-17 07:56:53 +01:00
Mateusz Pusz 623930ccee refactor: convertible_impl refactored to convertible + results caching 2024-11-16 22:11:59 +01:00
Mateusz Pusz b00d061ac8 refactor: explicit type of op/ for quantity and reference replaced with constrained placeholder
This prevents additional instantiations of inversed quantities
2024-11-16 22:10:51 +01:00
Mateusz Pusz 1be54cbc1d feat: equivalent now accept any units (even non-convertible) 2024-11-16 22:08:54 +01:00
Mateusz Pusz 5c0bfd9893 perf: get_canonical_unit result caching added 2024-11-16 22:07:13 +01:00
Mateusz Pusz 2390d4562d refactor: unneeded get_associated_quantity forward declaration removed 2024-11-16 22:04:25 +01:00
Mateusz Pusz 07497ce2c5 perf: get_kind_tree_root result caching added 2024-11-16 22:03:55 +01:00
Mateusz Pusz 049a5a434a perf: caching of get_associated_quantity results added 2024-11-16 22:01:30 +01:00
Mateusz Pusz e1b0fb7e6e refactor: first_100_primes refactored to use a varaible template for caching the result 2024-11-16 22:00:21 +01:00
Mateusz Pusz 658c0950f8 refactor: dimension_symbol and unit_symbol refactored to use a variable template for caching result 2024-11-16 21:59:40 +01:00
Mateusz Pusz daf4b1cc5c refactor: SymbolicConstant concept refactored 2024-11-16 11:53:05 +01:00
Mateusz Pusz 7b64b4b650 refactor: 💥 from now unit_symbol and dimension_symbol always returns std::string_view 2024-11-16 09:57:53 +01:00
Mateusz Pusz 2c24c61da5 perf: first_100_primes moved to the static storage 2024-11-16 09:11:52 +01:00
Chip Hogg a93a5d6d2e Add std:: prefix 2024-11-15 13:38:48 -05: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 82040c1788 Handle edge case
Subtracting from `n` doesn't work in literally every case: it fails for
`0` input.
2024-11-15 12:58:22 -05:00
Chip Hogg d963ce8f93 Apply mod to D
Looks like we were violating a precondition.
2024-11-15 11:58:49 -05:00
Chip Hogg 346a001283 Add more missing std:: prefixes 2024-11-15 10:56:53 -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 b49a4b711b Add missing std:: prefixes 2024-11-15 09:17:40 -05: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 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 f5b9288825 fix: MP_UNITS_NONCONST_TYPE disabled for gcc-12 2024-11-13 22:48:19 +01: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 1ee824423e refactor: usage of v for the function argument name changed to prevent shadowing errors 2024-11-12 16:22:14 +01:00
Mateusz Pusz 6c3c1fe5f7 feat: cartesian_vector added 2024-11-12 14:34:18 +01:00
Mateusz Pusz e4044f0e4b feat: ComplexRepresentation extended with complex operations 2024-11-12 14:20:19 +01:00
Chip Hogg 6c982d4202 Use std:: prefix and mpu's EXPECTS_DEBUG macro 2024-11-12 08:16:53 -05: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 1110e53e38 Never mind
Apparently, that's not the right approach.
2024-11-11 14:34:47 -05:00
Chip Hogg a6d34b40a6 Include <bits/types.h>
Apparently some freestanding builds need this?
2024-11-11 13:35:37 -05: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 727a898141 feat: derived_XXX are not constrained with SymbolicConstant 2024-11-09 23:03:24 +01:00
Mateusz Pusz a628f1d107 feat: per and power made final 2024-11-09 23:02:49 +01:00
Mateusz Pusz b4810089ec fix: gcc-12 compilation fixed
Resolves #632
2024-11-09 23:02:12 +01:00
Mateusz Pusz 4db913a592 fix: make_magnitude fixed for gcc-12 2024-11-09 20:42:17 +01:00
Mateusz Pusz ca4dbfa9b6 fix: extraneous semicolon removed 2024-11-08 13:39:16 +01:00
Mateusz Pusz 0c46d4ecfe refactor: type_list moved to implementation details 2024-11-08 13:36:43 +01:00
Mateusz Pusz 8423e50777 feat: SymbolicArg applied to expression templates 2024-11-08 13:30:55 +01:00
Mateusz Pusz 1702853893 refactor: SymbolicConstant moved to _expression_template.h_ 2024-11-08 13:27:25 +01:00