-
Notifications
You must be signed in to change notification settings - Fork 82
Optimized implementation of GF2Inverse
#1459
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
Conversation
| References: | ||
| [Efficient quantum circuits for binary elliptic curve arithmetic: | ||
| reducing T -gate complexity](https://arxiv.org/abs/1209.6348) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| section 2.3 |
| result = new_result | ||
| x = bb.add(GF2Square(self.bitsize), x=x) | ||
| return {'x': x, 'result': result} | ({'junk': np.array(junk)} if junk else {}) | ||
| beta = bb.allocate(dtype=self.qgf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| beta = bb.allocate(dtype=self.qgf) | |
| # The algorithm is descriped on page 4 and 5 of https://arxiv.org/abs/1209.6348 and resembles binary exponentiation. | |
| # The inverse is computed as (B_{n-1})^2. Where B_1 = x and B_{i+j} = B_i B_j^{2^i}. | |
| beta = bb.allocate(dtype=self.qgf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, yeah. I'd see if this could make its way to the class docstring so it shows up in the docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to the class docstring and regenerated the docs
| bloq = GF2Inverse(m) | ||
| GFM = GF(2**m) | ||
| assert_consistent_classical_action(bloq, x=GFM.elements[1:]) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a test for symbolic cost?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test for symbolic cost exists above in test_gf2_inverse_symbolic_toffoli_complexity
NoureldinYosri
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM%comments
mpharrigan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm modulo nits and nour's nits
| $$ | ||
| Thus, the inverse can be obtained via $m - 1$ squaring and multiplication operations. | ||
| The exponential $a^{2^m - 2}$ using $\mathcal{O}(m)$ squaring and $\mathcal{O}(\log_2(m))$ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is no longer a sentence. I think you're missing a verb of some sort
| results from intermediate multiplications. | ||
| References: | ||
| [Efficient quantum circuits for binary elliptic curve arithmetic: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you keep these links on one line? https://qualtran.readthedocs.io/en/latest/Autodoc.html#references
| result = new_result | ||
| x = bb.add(GF2Square(self.bitsize), x=x) | ||
| return {'x': x, 'result': result} | ({'junk': np.array(junk)} if junk else {}) | ||
| beta = bb.allocate(dtype=self.qgf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, yeah. I'd see if this could make its way to the class docstring so it shows up in the docs
|
Addressed all nits. Merging now |
This PR improves the T complexity of
GF2Inversefrom O(m^3) to O(m^2log(m)) following construction from https://arxiv.org/pdf/1209.6348Updates the tests and adds references.