Skip to content

Implement Shor's factorization algorithm - #1070

Merged
raklaptudirm merged 6 commits into
masterfrom
algorithm-shor
Aug 7, 2022
Merged

Implement Shor's factorization algorithm#1070
raklaptudirm merged 6 commits into
masterfrom
algorithm-shor

Conversation

@raklaptudirm

Copy link
Copy Markdown
Member

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

github-actionsand 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>
@raklaptudirmraklaptudirm added the algorithm Adds or improves an algorithm label Jul 27, 2022
*/
function isValidP (A, B, p) {
// A^p = mB + 1 => A^p - 1 = 0 (mod B)
return (A ** p - 1n) % B === 0n

Copy link
Copy Markdown
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
Copy Markdown
MemberAuthor

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).

@appgurueuappgurueu left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
MemberAuthor

Any suggestions?

@appgurueu

Copy link
Copy Markdown
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
Copy Markdown
MemberAuthor

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.

@raklaptudirmraklaptudirm changed the title Algorithm shorImplement Shor's factorization algorithmAug 7, 2022
@raklaptudirm
raklaptudirm merged commit e9b8b13 into masterAug 7, 2022
@raklaptudirm
raklaptudirm deleted the algorithm-shor branch August 7, 2022 07:03
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

algorithmAdds or improves an algorithm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@raklaptudirm@appgurueu