Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
positr0nium committed May 9, 2024
2 parents 5da8d4e + 3d6f7ff commit 6217455
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/qrisp/qtypes/quantum_modulus.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from qrisp.qtypes.quantum_float import QuantumFloat
from qrisp.environments import invert
from qrisp.misc import gate_wrap

def comparison_wrapper(func):

Expand Down Expand Up @@ -193,7 +194,8 @@ def encoder(self, i):
return np.nan

return montgomery_encoder(i, 2**self.m, self.modulus)


@gate_wrap(permeability="args", is_qfree=True)
def __mul__(self, other):
from qrisp.arithmetic.modular_arithmetic import montgomery_mod_mul, montgomery_mod_semi_mul

Expand All @@ -205,7 +207,8 @@ def __mul__(self, other):
raise Exception("Quantum modular multiplication with type {type(other)} not implemented")

__rmul__ = __mul__


@gate_wrap(permeability=[1], is_qfree=True)
def __imul__(self, other):
if isinstance(other, int):

Expand All @@ -219,7 +222,8 @@ def __imul__(self, other):
return semi_cl_inpl_mult(self, other%self.modulus)
else:
raise Exception("Quantum modular multiplication with type {type(other)} not implemented")


@gate_wrap(permeability="args", is_qfree=True)
def __add__(self, other):
if isinstance(other, int):
other = self.encoder(other)
Expand All @@ -240,8 +244,8 @@ def __add__(self, other):
return res

__radd__ = __mul__


@gate_wrap(permeability=[1], is_qfree=True)
def __iadd__(self, other):
if isinstance(other, int):
other = self.encoder(other)
Expand All @@ -256,8 +260,8 @@ def __iadd__(self, other):

beauregard_adder(self, other, self.modulus)
return self


@gate_wrap(permeability="args", is_qfree=True)
def __sub__(self, other):
if isinstance(other, int):
other = self.encoder(other)
Expand All @@ -276,7 +280,8 @@ def __sub__(self, other):
beauregard_adder(res, other, self.modulus)

return res


@gate_wrap(permeability="args", is_qfree=True)
def __rsub__(self, other):
if isinstance(other, int):
other = self.encoder(other)
Expand All @@ -295,8 +300,8 @@ def __rsub__(self, other):
beauregard_adder(res, other, self.modulus)

return res


@gate_wrap(permeability=[1], is_qfree=True)
def __isub__(self, other):
if isinstance(other, int):
other = self.encoder(other)
Expand Down

0 comments on commit 6217455

Please sign in to comment.