Negation¶
The negation operation receives a quantum register representing some number $x$ and returns a quantum register containing $-x$. Integer and fixed point numbers are both supported.
Example¶
The following example will show negation of a signed quantum variable.
In [9]:
Copied!
from classiq import (
Output,
QArray,
QBit,
QNum,
allocate_num,
create_model,
hadamard_transform,
qfunc,
)
@qfunc
def main(a: Output[QNum], b: Output[QNum]) -> None:
allocate_num(3, True, 0, a)
hadamard_transform(a)
b |= -a
qmod = create_model(main)
from classiq import (
Output,
QArray,
QBit,
QNum,
allocate_num,
create_model,
hadamard_transform,
qfunc,
)
@qfunc
def main(a: Output[QNum], b: Output[QNum]) -> None:
allocate_num(3, True, 0, a)
hadamard_transform(a)
b |= -a
qmod = create_model(main)
In [11]:
Copied!
from classiq import execute, synthesize, write_qmod
write_qmod(qmod, "negation_example")
qprog = synthesize(qmod)
result = execute(qprog).result()[0].value
result.parsed_counts
from classiq import execute, synthesize, write_qmod
write_qmod(qmod, "negation_example")
qprog = synthesize(qmod)
result = execute(qprog).result()[0].value
result.parsed_counts
Out[11]:
[{'a': -1.0, 'b': 1.0}: 133, {'a': 1.0, 'b': -1.0}: 133, {'a': -4.0, 'b': 4.0}: 133, {'a': 0.0, 'b': 0.0}: 127, {'a': 2.0, 'b': -2.0}: 127, {'a': -3.0, 'b': 3.0}: 124, {'a': -2.0, 'b': 2.0}: 120, {'a': 3.0, 'b': -3.0}: 103]