SquareI operation


This documentation refers to the Classic QDK, which has been replaced by the Modern QDK.

Please see https://aka.ms/qdk.api for the API documentation for the Modern QDK.

Namespace: Microsoft.Quantum.Arithmetic

Package: Microsoft.Quantum.Numerics

Computes the square of the integer xs into result, which must be zero initially.

operation SquareI (xs : Microsoft.Quantum.Arithmetic.LittleEndian, result : Microsoft.Quantum.Arithmetic.LittleEndian) : Unit is Adj + Ctl


xs : LittleEndian

𝑛-bit number to square

result : LittleEndian

2𝑛-bit result, must be in state |0⟩ initially.

Output : Unit


Uses a standard shift-and-add approach to compute the square. Saves 𝑛-1 qubits compared to the straight-forward solution which first copies out xs before applying a regular multiplier and then undoing the copy operation.