Skip to content

factor_one and friends#30

Open
hvds wants to merge 6 commits intodanaj:masterfrom
hvds:factor_state
Open

factor_one and friends#30
hvds wants to merge 6 commits intodanaj:masterfrom
hvds:factor_state

Conversation

@hvds
Copy link
Copy Markdown

@hvds hvds commented May 28, 2022

Hi Dana, we've discussed this from time to time, I finally got round to having a go at implementing it - moving the core of factor() out to a new function factor_one() that returns one factor at a time. This will add a slight overhead for the additional calls, and management of the factor_state structure; but will give direct benefits for some of the functions that call factor() (is_semiprime, is_smooth, is_rough, is_powerful), and I think offers opportunities for further improvement.

  • add_factor now also takes an exponent, the two macros are removed;
  • fs_init, fs_close added to help with management of the factor_state structure;
  • removed the secondary power_factor() check; not sure how important that is, but can work on bringing it back if needed
  • the primary power_factor check no longer recurses, just sets a multiplier for exponents;
  • bonus function is_tau(n, k) returns true if tau(n) == k (should it be called has_divisors?);
  • handling 32-bit overflow on khi*khi needs more thought: maybe tlim should become mpz_t, or maybe khi should be reduced on 32-bit targets;
  • is_tau() needs more tests.

I'm not in a rush for this, I think it'd be a good idea to release what's currently in the repo before merging this, and it needs some polish in any case. In particular, I don't know which FS_LARGE tests are worth repeating after a factor is found, and which should be skipped - that could be handled either by adding more FS states or, say, by having a bitmask of tests to try (probably also copied with the pending factors onto the tofac_stack).

I'd welcome your thoughts.

hvds added 5 commits May 28, 2022 15:29
The new function returns one prime/exponent pair for each call,
using a new factor_state structure to keep track. To aid this, add_factor()
gets an additional parameter for the exponent.
is_semiprime, is_smooth, is_rough, is_powerful can all short-circuit
based on a single p^e factor.
@hvds
Copy link
Copy Markdown
Author

hvds commented May 29, 2022

Note that MPU t/26-issquarefree.t found the missing mpz_init when factorizing 815373060690029363516051578884163974. That appears to be the only test case across MPU and MPUG that reaches that point (finding a composite factor directly).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant