Implementation of "IsPrime", "Factors", "NextPr", "PrevPr"#1632
Implementation of "IsPrime", "Factors", "NextPr", "PrevPr"#1632
Conversation
|
Tests OK (thanks Claude again). Next step is to add range check in functions. M127 seems a limit for available memory. And test that remultiplying factors gives original number. I have to know, too, how to check if this is db48x ou db50x, or to check available memory; to set different limits for each hardware? With reflexion, instead of a range check, is there a graceful detection of stack or RAM overflow to abort a command ? Raw implementation => SEGV in SIM (stack overflow) |
|
I have enhanced the tests. M73 & M83 fails for unclear reasons, since manually testing them in sim is perfectly OK. Maybe for memory or CPU reasons in a test context ? I have good confidence with the algorithms now. |
|
Wow @jcbenoist, this is rather ambitious and looks both pretty useful and pretty good. I'll review in depth, but of course this has good chances of being accepted. |
| @@ -0,0 +1,827 @@ | |||
| // **************************************************************************** | |||
There was a problem hiding this comment.
Thanks a lot @jcbenoist.
I will need to do some reformatting of the commit message (to avoid parler en français in the middle of un bout de code qui est principalement in English).
Yes, but this requires a bit of additional effort. Essentially, you need to check at every step, typically return null on failure, and have most of the code be null-safe. This is how things are done today. |
src/factor.h
Outdated
| // ============================================================================ | ||
|
|
||
| // Modular arithmetic on bignums | ||
| bignum_g bn_gcd(bignum_g a, bignum_g b); |
There was a problem hiding this comment.
I will make these static members of the bignum class instead of using a bn_ prefix, and I will move these functions to bignum.h.
There was a problem hiding this comment.
Note that gcd is already implemented in fraction.cc, but needs to be be moved to bignum.h as well.
@c3d Is it rt.available() to check free memory ? Is this sufficient ? What is a typical free memory margin to allow safe operation ? (4 Kbytes ?) I have programmed rt.available() < 4Kbytes => rt.out_of_memory_error() at strategic places, but now M63+ tests fails, with "out of memory", despite they pass very well without. Is this test pertinent ? Note : pass with 512 bytes margin. Hope this is safe and memory is well tested this way. |
0cf1991 to
7819972
Compare
|
@c3d I wonder if this is better to test rt.available(MIN_MEM) < MIN_MEM rather that rt.available() < MIN_MEM. Calling gc at each iteration risk to slow down the algorithm, or is this negligeable ? |
|
@c3d Do you wish I resolve the conflicts, or do you want to resolve them yourself ? |
|
Sorry @jcbenoist, I thought that you had seen that I had already done most of the work on The problem with your force-push now is that it conflicts with a number of unrelated changes. So I'm manually lifting:
|
|
For now, since the feature is currently implemented, let me close this, and I will finish the integration work with your most recent branch, as indicated in previous comment. Sorry for the duplicate effort, @jcbenoist, I hope that I will not get it wrong. I was in the middle of cutting out 0.9.16, and your recent changes caught me a bit by surprise. |
|
Hey @jcbenoist, reviewing the Consider for example: @@ -316,6 +319,12 @@ bignum_p pollard_rho_brent(bignum_r n)
for (unsigned c_val = 1; c_val <= 20; c_val++)
{
+ if (rt.available() < MIN_FACTOR_MEM)
+ {
+ rt.out_of_memory_error();
+ return nullptr;
+ }
+
bignum_g c = bignum::make(c_val);
if (!c)
return nullptr;The So that change is not necessary and most likely harmful. |
Implementation of "IsPrime", "Factors", "NextPr", "PrevPr". Tested on sim. I admit the core code is mostly generated by Claude Opus 4.6. I've done the integration to db48. If this PR is accepted, I'll do a test and will update the help files. I want to know first if this code have a chance to be integrated.
Hold on.. I'll develop tests right now, I have some suspiscions. Meanwhile, you can do comments or observations.
No, all seems OK. I'll publish tests soon.