Use this file to discover all available pages before exploring further.
View on GitHub
Open this notebook in GitHub to run it yourself
Subtraction (denoted as ’-’) is implemented by negation and addition in 2-complement representation.a−b⟷a+(−b)⟷a+∼b+lsb_valueWhere ’~’ is bitwise not and lsb_value is the least significant bit value.Note that integer and fixed-point numbers are represented in a 2-complement method during function evaluation.The binary number is extended in the case of a register size miss-match.For example, the positive signed number (110)2=6 is expressed as (00110)2 when operating with a 5-qubit register.
Similarly, the negative signed number (110)2=−2 is expressed as (11110)2.Examples:5 + 3 = 8 , 0101 + 0011 = 10005 - 3 = 5 + (-3) = 2, 0101 + 1101 = 0010-5 + -3 = -8, 1011 + 1101 = 1000
This example generates a quantum program which subtracts two argument.The left_arg is defined to be a fix point number (11.1)2 (3.5).The right_arg is defined to be a quantum register of size of three.
@qfuncdef main(a: Output[QNum], res: Output[QNum]) -> None: a |= 4 res |= a - 3.5qmod = create_model(main)