Skip to content

Conversation

@tanujkhattar
Copy link
Collaborator

This PR improves the T complexity of GF2Inverse from O(m^3) to O(m^2log(m)) following construction from https://arxiv.org/pdf/1209.6348

Updates the tests and adds references.

References:
[Efficient quantum circuits for binary elliptic curve arithmetic:
reducing T -gate complexity](https://arxiv.org/abs/1209.6348)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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)

Copy link
Collaborator

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

Copy link
Collaborator Author

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:])

Copy link
Contributor

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?

Copy link
Collaborator Author

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

Copy link
Contributor

@NoureldinYosri NoureldinYosri left a comment

Choose a reason for hiding this comment

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

LGTM%comments

Copy link
Collaborator

@mpharrigan mpharrigan left a 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))$
Copy link
Collaborator

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:
Copy link
Collaborator

Choose a reason for hiding this comment

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

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)
Copy link
Collaborator

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

@tanujkhattar
Copy link
Collaborator Author

Addressed all nits. Merging now

@tanujkhattar tanujkhattar enabled auto-merge (squash) October 16, 2024 20:43
@tanujkhattar tanujkhattar merged commit 0ef9f1d into quantumlib:main Oct 16, 2024
8 checks passed
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.

3 participants