# Copyright 2018-2026 Xanadu Quantum Technologies Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Contains the SignedOutMultiplier template.
"""
from collections import defaultdict
from jax import numpy as jnp
from pennylane import capture, compiler, math
from pennylane.control_flow import for_loop
from pennylane.core.operator import Operator2
from pennylane.decomposition import (
add_decomps,
register_condition,
register_resources,
)
from pennylane.ops import CNOT, ctrl
from pennylane.typing import Wire
from pennylane.wires import Wires, WiresLike, is_abstract_qubit, validate_no_wire_overlaps
from .incrementer import Incrementer
from .out_multiplier import OutMultiplier
from .semi_adder import SemiAdder
[docs]
class SignedOutMultiplier(Operator2):
r"""
Implements signed out-place multiplication
This operator performs the modular multiplication of integers x and y modulo the two to the size of the output register
in the computational basis:
.. math::
|x,y,z\rangle \mapsto |x,y,(z + xy) \mod 2^{|z|}\rangle
Args:
x_wires (Sequence[int]): wires that store the signed integer :math:`x`
y_wires (Sequence[int]): wires that store the signed integer :math:`y`
output_wires (Sequence[int]): wires that store the multiplication result. If the
register is in a non-zero state :math:`z`, the product :math:`xy` will be added to this value
work_wires (Sequence[int]): auxiliary wires to use for the multiplication. The needed
number of work wires depends on the decomposition, the register sizes and
``output_wires_zeroed``. If the output wires are zeroed, we only need 2 work wires.
Otherwise, we need ``2*len(output_wires) + 1`` work wires.
output_wires_zeroed (bool): Whether the ``output_wires`` are guaranteed to be in state
:math:`|0\rangle` initially. Setting this argument to ``True`` reduces the cost of
the operation.
**Example**
This example performs the multiplication of two integers :math:`x=-3` and :math:`y=3`.
We'll let :math:`z=0`.
.. code-block:: python
x = -3
y = 3
x_wires = [0, 1, 2]
y_wires = [3, 4, 5]
output_wires = [6, 7, 8, 9, 10, 11]
work_wires = [12, 13, 14, 15]
dev = qp.device("default.qubit")
@qp.qnode(dev, shots=1)
def circuit():
x_bin = qp.math.int_to_binary(x, len(x_wires))
y_bin = qp.math.int_to_binary(y, len(y_wires))
qp.BasisState(x_bin, wires=x_wires)
qp.BasisState(y_bin, wires=y_wires)
qp.SignedOutMultiplier(
x_wires,
y_wires,
output_wires,
work_wires,
output_wires_zeroed=True,
)
return qp.sample(wires=output_wires)
>>> print(circuit())
[[1 1 0 1 1 1]]
The result :math:`[[1 1 0 1 1 1]]`, is the binary representation of
:math:`-3 \cdot 3 \; = -9` in 2s complement form. We can tell it is negative since the first bit is 1.
Then we can find the magnitude by flipping the bits and adding 1. This gives us :math:`[[0 0 1 0 0 1]]`.
The sum of these bits is :math:`2^3 + 2^0 = 9` for :math:`k=6`.
>>> print(qp.draw(qp.transforms._tape_decompose(circuit, gate_set=qp.gate_sets.ROTATIONS_PLUS_CNOT, max_expansion=1), max_length=170)())
0: ──X─╭●────╭X───────╭Incrementer───────────────────────╭OutMultiplier───────────────────────────────────╭X───────╭Incrementer───────────────────────╭●────┤
1: ────│─────│──╭X────├Incrementer───────────────────────├OutMultiplier───────────────────────────────────│──╭X────├Incrementer───────────────────────│─────┤
2: ──X─│─────│──│──╭X─├Incrementer───────────────────────├OutMultiplier───────────────────────────────────│──│──╭X─├Incrementer───────────────────────│─────┤
3: ────│──╭●─│──│──│──│────────────╭X───────╭Incrementer─├OutMultiplier───────────────────────────────────│──│──│──│────────────╭X───────╭Incrementer─│──╭●─┤
4: ──X─│──│──│──│──│──│────────────│──╭X────├Incrementer─├OutMultiplier───────────────────────────────────│──│──│──│────────────│──╭X────├Incrementer─│──│──┤
5: ──X─│──│──│──│──│──│────────────│──│──╭X─├Incrementer─├OutMultiplier───────────────────────────────────│──│──│──│────────────│──│──╭X─├Incrementer─│──│──┤
6: ────│──│──│──│──│──│────────────│──│──│──│────────────│──────────────╭X─╭X─╭●─╭●─╭●─╭●─╭●─╭●───────────│──│──│──│────────────│──│──│──│────────────│──│──┤ ╭Sample
7: ────│──│──│──│──│──│────────────│──│──│──│────────────├OutMultiplier─│──│──╰X─│──│──│──│──├Incrementer─│──│──│──│────────────│──│──│──│────────────│──│──┤ ├Sample
8: ────│──│──│──│──│──│────────────│──│──│──│────────────├OutMultiplier─│──│─────╰X─│──│──│──├Incrementer─│──│──│──│────────────│──│──│──│────────────│──│──┤ ├Sample
9: ────│──│──│──│──│──│────────────│──│──│──│────────────├OutMultiplier─│──│────────╰X─│──│──├Incrementer─│──│──│──│────────────│──│──│──│────────────│──│──┤ ├Sample
10: ────│──│──│──│──│──│────────────│──│──│──│────────────├OutMultiplier─│──│───────────╰X─│──├Incrementer─│──│──│──│────────────│──│──│──│────────────│──│──┤ ├Sample
11: ────│──│──│──│──│──│────────────│──│──│──│────────────├OutMultiplier─│──│──────────────╰X─├Incrementer─│──│──│──│────────────│──│──│──│────────────│──│──┤ ╰Sample
12: ────╰X─│──╰●─╰●─╰●─├●───────────│──│──│──│────────────│──────────────╰●─│─────────────────│────────────╰●─╰●─╰●─├●───────────│──│──│──│────────────╰X─│──┤
13: ───────╰X──────────│────────────╰●─╰●─╰●─├●───────────│─────────────────╰●────────────────│─────────────────────│────────────╰●─╰●─╰●─├●──────────────╰X─┤
14: ───────────────────├Incrementer──────────├Incrementer─├OutMultiplier──────────────────────├Incrementer──────────├Incrementer──────────├Incrementer───────┤
15: ───────────────────╰Incrementer──────────╰Incrementer─╰OutMultiplier──────────────────────╰Incrementer──────────╰Incrementer──────────╰Incrementer───────┤
.. details::
:title: Available decompositions
.. decomposition-table:: qp.SignedOutMultiplier
:stacked:
:symbols: :math:`n` ``x_wires``, :math:`m` ``y_wires``, :math:`k` ``output_wires`` and
:math:`w` ``work_wires``
:example: :math:`n=m=1`, :math:`k=2`
.. decomposition-rule:: borrowed
:image: /_static/decomposition_thumbnails/signed_out_multiplier_not_zeroed.svg
:requires: ``output_wires_zeroed=False`` and :math:`w \geq 2k + 1` work wires
:class:`~.SignedOutMultiplier` with ``output_wires_zeroed=True`` | :math:`1` | 1
:class:`~.SemiAdder` | :math:`1` | 1
.. decomposition-rule:: zeroed
:image: /_static/decomposition_thumbnails/signed_out_multiplier_zeroed.svg
:requires: ``output_wires_zeroed=True`` and :math:`w \geq 2` work wires
:class:`~.CNOT` | :math:`2(n + m) + k + 5` | 11
:class:`~.Incrementer` with 1 control | :math:`5` | 5
:class:`~.OutMultiplier` | :math:`1` | 1
.. details::
:title: Theoretical background
:href: theory
The inputs and output are given in `2s complement <https://en.wikipedia.org/wiki/Two%27s_complement>`__.
Specifically, the values :math:`x`, :math:`y` and :math:`z` are encoded in big-endian 2s complement.
Wire :math:`0` stores the sign bit and wire :math:`i` stores the bit with weight :math:`2^{n-1-i}`
for a register of length :math:`n`. For example, the value :math:`x` encoded by a bitstring
:math:`x_0 x_1\dots x_{n-1}` is given by the following.
.. math::
\begin{align}
x &= - 2^{n-1} x_0 + \sum_{j=1}^{n-1} x_j 2^{n-1-j}, \\
y &= - 2^{m-1} y_0 + \sum_{j=1}^{m-1} y_j 2^{m-1-j}, \\
z &= - 2^{k-1} z_0 + \sum_{j=1}^{k-1} z_j 2^{k-1-j}.
\end{align}
The first bit of each encoded bitstring gives the sign of the encoded number. :math:`1 \mapsto -`, :math:`0 \mapsto +`.
This is however not a sign-magnitude encoding. Iff the encoded number is negative, the rest of the bits do not give the
magnitude. Instead, the magnitude can be found by calculating e.g. :math:`\bar{x}=(-1)^{x_0}x`. This is done by flipping the bits of
:math:`x` and adding 1. E.g., :math:`6=(0110)_2` but :math:`-6 = (1010)_2` because :math:`-(1010)_2 \oplus 1 = (0101)_2 \oplus 1 = (0110)_2`.
Therefore, to get the magnitude of the signed integers, we do the following.
Both steps controlled on the sign bit (:math:`x_0` for :math:`x` and :math:`y_0` for :math:`y`). For :math:`x`,
.. math::
\begin{align}
\bar{x}&=(1-x_0)x+x_0\left(1 + \sum_{j=0}^{n-1} (1-x_j) 2^{n-1-j}\right)\\
% &=2^n-x_u\\
&=(x-x_0 x) + x_0 (1 + \sum_{j=0}^{n-1} 2^{n-1-j} - \sum_{j=0}^{n-1} x_j 2^{n-1-j}) \\
&=(x-x_0 x) + x_0 (1 + \sum_{j=0}^{n-1} 2^{n-1-j} - (2^{n-1}x_0 + \sum_{j=1}^{n-1} x_j 2^{n-1-j})) \\
&=(x-x_0 x) + x_0 (1 + \sum_{j=0}^{n-1} 2^{n-1-j} - (2^n x_0 - 2^{n-1}x_0 + \sum_{j=1}^{n-1} x_j 2^{n-1-j})) \\
&=(x-x_0 x) + x_0 (1 + (2^n - 1) - (x + 2^n x_0)) \\
&=(x-x_0 x)+x_02^n-x_0(x+2^nx_0)\\
&=x-2x_0x+2^nx_0(1-x_0)\\
&=(1-2x_0)x + 2^n x_0 - 2^n x_0^2 \\
&=(1-2x_0)x\\
&=(-1)^{x_0}x.
\end{align}
The first step is to copy the sign bit of :math:`x` and :math:`y` to one auxiliary qubit each, and to compute the magnitude of the respective integer, as just described.
.. code-block::
|-Cache Signs-| |--- Compute Absolute Magnitude (In-Place) --|
┌───────┐
|x_bits⟩ [n-1] ──────────────────────X────────────────────┤ ├───────── --> |x_abs⟩
│ │ +1 │
|x_sign⟩ [1] ──────●───────────────X────────────────────┤ ├─────────
│ │ └───┬───┘
|0⟩ ──────X───────────────●────────────────────────●───────────── --> |cache_x⟩
┌───────┐
|y_bits⟩ [m-1] ─────────────────────────────X─────────────┤ ├───────── --> |y_abs⟩
│ │ +1 │
|y_sign⟩ [1] ──────●──────────────────────X─────────────┤ ├─────────
│ │ └───┬───┘
|0⟩ ──────X──────────────────────●─────────────────●───────────── --> |cache_y⟩
At this point we have the state:
.. math::
\begin{align}
|\bar{x}\rangle |x_0\rangle |\bar{y}\rangle |y_0\rangle |0\rangle_s |0\rangle,
\end{align}
where we interleaved the two auxiliary qubits with the input registers and the output register, and wrote the sign bit of the output register as a separate qubit, marked with an :math:`s` for clarity.
Next, we multiply the magnitude registers into the output register, obtaining
.. math::
\begin{align}
|\bar{x}\rangle |x_0\rangle |\bar{y}\rangle |y_0\rangle |0\rangle_s |\bar{x}\bar{y}\rangle.
\end{align}
.. code-block::
|x̄⟩ ─────────────[n]───────────■───────────
│
|x_0⟩ ───────────────────────────┼───────────
│
|ȳ⟩ ─────────────[m]───────────■───────────
│
|y_0⟩ ───────────────────────────┼───────────
│
|0⟩_s ───────────────────────────┼───────────
┌────┴────┐
|0⟩ ──────────────[k-1]────┤ Unsigned├──────
│ Mult x*y│
└─────────┘
Then, we flip the sign bit of the output register controlled on the (cached) sign bits of each input, respectively:
.. math::
\begin{align}
|\bar{x}\rangle |x_0\rangle |\bar{y}\rangle |y_0\rangle |x_0+y_0 \rangle_s |\bar{x}\bar{y}\rangle.
\end{align}
.. code-block::
|x̄⟩ ─────────────────────────────────
|x_0⟩ ───────────────●─────────────────
│
|ȳ⟩ ───────────────┼─────────────────
│
|y_0⟩ ───────────────┼────────●────────
│ │
|0⟩_s ───────────────X────────X──────── --> Becomes |z_s⟩_s
|x̄ȳ⟩ ─────────────────────────────────
From here on we write :math:`z_s = z_0 = x_0+y_0`.
Then, we flip and increment the (non-sign) bits of the output register controlled on the output sign bit to get (where :math:`k` is the size of the output register including the sign bit):
.. math::
\begin{align}
|\bar{x}\rangle |x_0\rangle |\bar{y}\rangle |y_0\rangle |z_s \rangle_s |(-1)^{z_s}\bar{x}\bar{y}+2^{k - 1} z_s\rangle.
\end{align}
Arrived at by the following arithmetic.
.. math::
\begin{align}
&(1 - z_s) \bar{x}\bar{y} + z_s (1 + \sum_{j=0}^{k-2} (1 - \bar{x}\bar{y}_j)2^{k-2-j}) \\
&=(1 - z_s) \bar{x}\bar{y} + z_s(1 + \sum_{j=0}^{k-2}2^{k-2-j} - \sum_{j=0}^{k-2} \bar{x}\bar{y}_j2^{k-2-j}) \\
&=(1 - z_s) \bar{x}\bar{y} + z_s(1 + 2^{k-1} - 1 - \bar{x}\bar{y}) \\
&=(1 - z_s) \bar{x}\bar{y} + z_s (2^{k-1} - \bar{x}\bar{y}) \\\
&=(-1)^{z_s}\bar{x}\bar{y}+2^{k - 1} z_s
\end{align}
.. code-block::
|z_s⟩_s ───────────────●────────●────────
┌─┴─┐ ┌──┴──┐
|x̄ȳ⟩ ─────────────┤NOT├───┤ +1 ├─────
└───┘ └─────┘
Then we uncompute the magnitudes and the copied sign bits of the input registers, arriving at
.. math::
\begin{align}
|x\rangle |0\rangle |y\rangle |0\rangle |z_s \rangle_s |(-1)^{z_s}\bar{x}\bar{y}+2^{k-1} z_s\rangle.
\end{align}
Interpreting the output register as signed integer, we find that we computed
.. math::
\begin{align}
z &= (-1)^{z_0}\bar{x}\bar{y}+2^{k-1}z_0 - 2^{k-1} z_0\\
&=(-1)^{z_0} \bar{x}\bar{y} \\
&=(-1)^{x_0}\bar{x} (-1)^{y_0}\bar{y}\\
&= x y.
\end{align}
So we correctly arrive at the product of :math:`x` and :math:`y`.
**Non-zero initial state of output wires**
If we have a non-zero initial state :math:`z_i` in the output register, we will end up with :math:`xy + z_i` in the
output register once the template has executed. This requires more work wires and a more costly decomposition.
Basically, we use auxiliary registers to first 1) compute the multiplication of the operands into a zeroed register,
2) use an Adder to add :math:`z_i` to this result.
.. code-block::
|x⟩ ───────────[n]─────────■────────────────────────────────────────────────────────
│
|y⟩ ───────────[m]─────────■────────────────────────────────────────────────────────
┌───┴───┐
|0⟩ ───────────[k]─────┤Signed ├─────|x·y⟩ ───────■─────────────────────────────────
│ Mult │ │
└───────┘ │
|z_s⟩ ─────────[1]────────────────────────────────┼─────────────────────────────────
│
┌─┴─┐
|z_i⟩ ─────────[k]──────────────────────────────┤ + ├──────|x·y + z_i⟩──────────────
└───┘
"""
wire_argnames = ("x_wires", "y_wires", "output_wires", "work_wires")
compilable_argnames = ("output_wires_zeroed",)
arg_specs = {
"x_wires": Wire[-1],
"y_wires": Wire[-1],
"output_wires": Wire[-1],
"work_wires": Wire[-1],
}
def __init__(
self,
x_wires: WiresLike,
y_wires: WiresLike,
output_wires: WiresLike,
work_wires: WiresLike,
output_wires_zeroed: bool = False,
):
x_wires = Wires(x_wires)
y_wires = Wires(y_wires)
output_wires = Wires(output_wires)
work_wires = Wires(work_wires)
wire_args = {
"x_wires": x_wires,
"y_wires": y_wires,
"output_wires": output_wires,
"work_wires": work_wires,
}
validate_no_wire_overlaps(wire_args)
super().__init__(
x_wires,
y_wires,
output_wires,
work_wires,
output_wires_zeroed=output_wires_zeroed,
)
@property
def wires(self):
"""All wires involved in the operation."""
return self.x_wires + self.y_wires + self.output_wires + self.work_wires
def _signed_out_multiplier_zeroed_resources( # pylint: disable=unused-argument
x_wires,
y_wires,
output_wires,
work_wires,
output_wires_zeroed=False,
):
"""
Computes the resources for the SignedOutMultiplier.
"""
num_x_wires = len(x_wires)
num_y_wires = len(y_wires)
num_output_wires = len(output_wires)
num_work_wires = len(work_wires)
resources = defaultdict(int)
resources[
ctrl(Incrementer(Wire[num_x_wires], work_wires=Wire[num_work_wires - 2]), Wire[1])
] += 2
resources[
OutMultiplier(
Wire[num_x_wires],
Wire[num_y_wires],
Wire[num_output_wires - 1],
mod=2 ** (num_output_wires - 1),
work_wires=Wire[num_work_wires - 2],
output_wires_zeroed=True,
)
] += 1
resources[
ctrl(Incrementer(Wire[num_output_wires - 1], work_wires=Wire[num_work_wires - 2]), Wire[1])
] += 1
resources[
ctrl(Incrementer(Wire[num_y_wires], work_wires=Wire[num_work_wires - 2]), Wire[1])
] += 2
resources[CNOT] = 6 + (num_x_wires + num_y_wires) * 2 + (num_output_wires - 1)
# Convert to a builtin dict so downstream lookups of missing gates
# don't accidentally insert them with a value of 0
return dict(resources)
def _signed_out_multiplier_borrowed_resources( # pylint: disable=unused-argument
x_wires,
y_wires,
output_wires,
work_wires,
output_wires_zeroed=False,
):
"""
Computes the resources for the SignedOutMultiplier.
"""
num_x_wires = len(x_wires)
num_y_wires = len(y_wires)
num_output_wires = len(output_wires)
num_work_wires = len(work_wires)
resources = {}
resources[
SignedOutMultiplier(
Wire[num_x_wires],
Wire[num_y_wires],
Wire[num_output_wires],
work_wires=Wire[2 + num_work_wires - (2 * num_output_wires + 1)],
output_wires_zeroed=True,
)
] = 1
resources[
SemiAdder(Wire[num_output_wires], Wire[num_output_wires], Wire[num_output_wires - 1])
] = 1
return resources
def _twos_complement_helper(input_reg, aux_wire, work_wires):
# Dynamically-allocated wires (``AbstractQubit``) cannot be
# stacked into a numeric array for ``for_loop``-based dynamic indexing, so unroll instead.
# Remove this fallback once dynamic-wire indexing is supported (shortcut.com/story/129521).
if any(is_abstract_qubit(w) for w in input_reg):
for wire in input_reg:
CNOT([aux_wire, wire])
else:
if compiler.active() or capture.enabled():
input_reg_arr = math.array(input_reg, like="jax")
else:
input_reg_arr = input_reg
# Invert all bits
@for_loop(len(input_reg_arr))
def invert(w):
# sign bit of 1 indicates a negative value
CNOT([aux_wire, input_reg_arr[w]])
invert() # pylint: disable=no-value-for-parameter
# Add one
ctrl(
Incrementer(
wires=Wires(input_reg),
work_wires=Wires(
work_wires
), # we can use the work wires since they are returned in a clean state
),
control=aux_wire,
control_values=(1,),
)
def _not_zeroed_work_wire_condition( # pylint: disable=unused-argument
x_wires,
y_wires,
output_wires,
work_wires,
output_wires_zeroed=False,
):
return len(work_wires) >= 2 * len(output_wires) + 1
def _zeroed_work_wire_condition( # pylint: disable=unused-argument
x_wires,
y_wires,
output_wires,
work_wires,
output_wires_zeroed=False,
):
return len(work_wires) >= 2
# pylint: disable-next=unused-argument
def _zeroed_condition(x_wires, y_wires, output_wires, work_wires, output_wires_zeroed=False):
return output_wires_zeroed
# pylint: disable-next=unused-argument
def _not_zeroed_condition(x_wires, y_wires, output_wires, work_wires, output_wires_zeroed=False):
return not output_wires_zeroed
@register_condition(_zeroed_condition)
@register_condition(_zeroed_work_wire_condition)
@register_resources(_signed_out_multiplier_zeroed_resources, name="zeroed")
def _signed_out_multiplier_zeroed( # pylint: disable=unused-argument
x_wires: WiresLike,
y_wires: WiresLike,
output_wires: WiresLike,
work_wires: WiresLike,
output_wires_zeroed=False,
):
"""Computes the decomposition of the operator as a product of other operators when the output wires are zeroed."""
if capture.enabled():
x_wires, y_wires, work_wires, output_wires = (
math.array(x_wires, like="jax"),
math.array(y_wires, like="jax"),
math.array(work_wires, like="jax"),
math.array(output_wires, like="jax"),
)
x_aux = work_wires[0]
y_aux = work_wires[1]
# Sign extension
CNOT([x_wires[0], x_aux])
CNOT([y_wires[0], y_aux])
# Take 2s complements if necessary
_twos_complement_helper(x_wires, x_aux, work_wires[2:])
_twos_complement_helper(y_wires, y_aux, work_wires[2:])
# at this point the sign is only kept in the auxiliary qubits' states
# Multiply the magnitudes
OutMultiplier(
x_wires,
y_wires,
output_wires[1:],
work_wires=work_wires[2:],
output_wires_zeroed=True,
)
# Compute the sign
CNOT([x_aux, output_wires[0]])
CNOT([y_aux, output_wires[0]])
# Encode the output
_twos_complement_helper(output_wires[1:], output_wires[0], work_wires[2:])
# Return inputs to original state
_twos_complement_helper(x_wires, x_aux, work_wires[2:])
_twos_complement_helper(y_wires, y_aux, work_wires[2:])
# Uncompute sign extension
CNOT([x_wires[0], x_aux])
CNOT([y_wires[0], y_aux])
@register_condition(_not_zeroed_condition)
@register_condition(_not_zeroed_work_wire_condition)
@register_resources(_signed_out_multiplier_borrowed_resources, name="borrowed")
def _signed_out_multiplier_borrowed( # pylint: disable=unused-argument
x_wires: WiresLike,
y_wires: WiresLike,
output_wires: WiresLike,
work_wires: WiresLike,
output_wires_zeroed=False,
):
"""Computes the decomposition of the operator as a product of other operators."""
if capture.enabled():
x_wires, y_wires, work_wires, output_wires = (
math.array(x_wires, like="jax"),
math.array(y_wires, like="jax"),
math.array(work_wires, like="jax"),
math.array(output_wires, like="jax"),
)
x_aux = work_wires[0]
y_aux = work_wires[1]
# Temp output register for multiplication output
mult_temp = work_wires[2 : len(output_wires) + 2]
if capture.enabled():
signed_work_wires = work_wires[2 * len(output_wires) + 1 :]
signed_work_wires = jnp.concatenate([jnp.atleast_1d(y_aux), signed_work_wires])
signed_work_wires = jnp.concatenate([jnp.atleast_1d(x_aux), signed_work_wires])
else:
signed_work_wires = [x_aux] + [y_aux] + work_wires[2 * len(output_wires) + 1 :]
SignedOutMultiplier(x_wires, y_wires, mult_temp, signed_work_wires, True)
# Add any initial value in the output register
SemiAdder(
mult_temp,
output_wires,
work_wires=work_wires[len(output_wires) + 2 : 2 * len(output_wires) + 1],
)
add_decomps(SignedOutMultiplier, _signed_out_multiplier_borrowed)
add_decomps(SignedOutMultiplier, _signed_out_multiplier_zeroed)