Preview:
namespace Microsoft.Quantum.Samples {
    
    open Microsoft.Quantum.Arithmetic; 
    open Microsoft.Quantum.Arrays as Array; 
    open Microsoft.Quantum.Canon;
    open Microsoft.Quantum.Convert;
    open Microsoft.Quantum.Diagnostics as Diagnostics; 
    open Microsoft.Quantum.Intrinsic;
    open Microsoft.Quantum.Math;
    open Microsoft.Quantum.Preparation; 

    operation ApplyQFT (reg : LittleEndian) : Unit 
    is Adj + Ctl {
        
        let qs = reg!;        
        SwapReverseRegister(qs);
        
        for (i in Array.IndexRange(qs)) {
            for (j in 0 .. i-1) {
                Controlled R1Frac([qs[i]], (1, i - j, qs[j]));
            }
            H(qs[i]);
        }
    }

    @EntryPoint() 
    operation RunProgram(vector : Double[]) : Unit {

        let n = Floor(Log(IntAsDouble(Length(vector))) / LogOf2());
        if (1 <<< n != Length(vector)) {
            fail "Length(vector) needs to be a power of two.";
        }

        let amps = Array.Mapped(ComplexPolar(_,0.), vector);
        use qs = Qubit[n] {
            let reg = LittleEndian(qs);

            PrepareArbitraryState(amps, reg); 
            Message("Before QFT:");
            Diagnostics.DumpRegister((), qs);

            ApplyQFT(reg); 
            Message("After QFT:");
            Diagnostics.DumpRegister((), qs);

            ResetAll(qs);
        }
    }
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter