Skip to content

Commit bb83da3

Browse files
Switch SubtractFrom to use BitwiseNot (#1164)
* Switch `SubtractFrom` to use `BitwiseNot` * Update notebook
1 parent 22b3d5e commit bb83da3

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

qualtran/bloqs/arithmetic/multiplication.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,7 @@
813813
" - `a`: `bitsize`-sized input register.\n",
814814
" - `result`: `bitsize`-sized output register. \n",
815815
" - `References`: \n",
816-
" - `[Quantum Algorithms and Circuits for Scientific Computing](`: \n",
817-
" - `https`: //arxiv.org/pdf/1511.08253). Section 2.1.\n"
816+
" - `[Quantum Algorithms and Circuits for Scientific Computing](https`: //arxiv.org/pdf/1511.08253). Section 2.1.\n"
818817
]
819818
},
820819
{

qualtran/bloqs/arithmetic/subtraction.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
SoquetT,
3232
)
3333
from qualtran.bloqs.arithmetic.addition import Add
34+
from qualtran.bloqs.arithmetic.bitwise import BitwiseNot
3435
from qualtran.bloqs.arithmetic.negate import Negate
3536
from qualtran.drawing import Text
3637

@@ -219,11 +220,12 @@ def wire_symbol(
219220
raise ValueError()
220221

221222
def build_call_graph(self, ssa: 'SympySymbolAllocator') -> Set['BloqCountT']:
222-
return {(Negate(self.dtype), 1), (Subtract(self.dtype, self.dtype), 1)}
223+
return {(BitwiseNot(self.dtype), 2), (Add(self.dtype, self.dtype), 1)}
223224

224225
def build_composite_bloq(self, bb: 'BloqBuilder', a: Soquet, b: Soquet) -> Dict[str, 'SoquetT']:
225-
a, b = bb.add_t(Subtract(self.dtype, self.dtype), a=a, b=b) # a, a - b
226-
b = bb.add(Negate(self.dtype), x=b) # a, b - a
226+
b = bb.add(BitwiseNot(self.dtype), x=b) # a, -1 - b
227+
a, b = bb.add_t(Add(self.dtype, self.dtype), a=a, b=b) # a, a - 1 - b
228+
b = bb.add(BitwiseNot(self.dtype), x=b) # a, -1 - (a - 1 - b) = a, -a + b
227229
return {'a': a, 'b': b}
228230

229231

0 commit comments

Comments
 (0)