Skip to content

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. If the inplace flag is set to True, the original register is overridden by the result. Otherwise, it is available as an output.

Syntax

Function: Negation

Parameters:

  • arg: RegisterUserInput (see RegisterUserInput)
  • output_size: Optional[PositiveInt]
  • inplace: bool = False

Register names:

  • arg: arg
  • result: negated

Example 1

{
  "functions": [
    {
      "name": "main",
      "body": [
        {
          "function": "Negation",
          "function_params": {
              "arg": {"size": 7, "fraction_places": 3, "is_signed": true},
              "inplace": true
          }
        }
      ]
    }
  ]
}
from classiq import Model, RegisterUserInput, synthesize
from classiq.builtin_functions import Negation

params = Negation(
    arg=RegisterUserInput(size=7, fraction_places=3, is_signed=True),
    inplace=True,
)
model = Model()
model.Negation(params)
quantum_program = synthesize(model.get_model())