Skip to content

Implement Shor's factorization algorithm #1070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 7, 2022
Merged

Conversation

raklaptudirm
Copy link
Member

Implemented the classical version of Shor's quantum algorithm for factorizing integers.

github-actions and others added 5 commits July 27, 2022 12:12
* Fix GetEuclidGCD

Implement the actual Euclidean Algorithm

* Replace == with ===

* Lua > JS

* Standard sucks

* Oops

* Update GetEuclidGCD.js

* Updated Documentation in README.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>

Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com>
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
@raklaptudirm raklaptudirm added the algorithm Adds or improves an algorithm label Jul 27, 2022
@raklaptudirm raklaptudirm requested a review from appgurueu as a code owner July 27, 2022 15:12
*/
function isValidP (A, B, p) {
// A^p = mB + 1 => A^p - 1 = 0 (mod B)
return (A ** p - 1n) % B === 0n
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A ** p may grow rather large (thus being inefficient to compute). Couldn't you rewrite this using integer exponentiation and applying % B after every operation (modular arithmetics!), then subtracting 1n at the end, and finally taking that mod B again?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of subtracting, I can just check if it is 1 (mod B).

Copy link
Collaborator

@appgurueu appgurueu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is an opportunity for optimization, but it's definitely fine in its current form.

@raklaptudirm
Copy link
Member Author

Any suggestions?

@appgurueu
Copy link
Collaborator

Any suggestions?

See my review comment above: Leverage modular arithmetics to keep your numbers small. Example from my Lua implementation of the Miller-Rabin primality test.

@raklaptudirm
Copy link
Member Author

Any suggestions?

See my review comment above: Leverage modular arithmetics to keep your numbers small. Example from my Lua implementation of the Miller-Rabin primality test.

That could be an interesting idea. But my worry is that is could make the algorithm slower, i will check though.

@raklaptudirm raklaptudirm changed the title Algorithm shor Implement Shor's factorization algorithm Aug 7, 2022
@raklaptudirm raklaptudirm merged commit e9b8b13 into master Aug 7, 2022
@raklaptudirm raklaptudirm deleted the algorithm-shor branch August 7, 2022 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
algorithm Adds or improves an algorithm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants