qleisli 0.2.8

Experimental quantum language with linear ownership, exact contracts and independent finite IR verification
Documentation
//! Fixed two- and three-bit quantum Fourier transforms with positive phase.
//!
//! Ordinary checked .qli definitions; no general-size or approximate QFT API.
//! Basis labels are little-endian and each circuit includes output-bit reversal.
//! Contracts and finite regression status: https://github.com/MGYamada/Qleisli/blob/v0.2.7/docs/stdlib-contracts.md, F001-F002.
use std::quantum::h;
use std::quantum::t;
use std::quantum::s;
use std::quantum::id;
use std::quantum::split;
use std::quantum::join;

/// Apply F4: |x> maps to sum_y exp(2*pi*i*x*y/4)|y>/2 for every input.
/// The leftmost bit has weight 1; output reversal is part of the exact unitary.
/// Consume and return both owners without measurement or auxiliary allocation.
pub unitary fn qft2(q: Q<(Bit, Bit)>) -> Q<(Bit, Bit)> {
    let (a, b) = split(q);
    let b = h(b);
    let (a, b) = qif(a, b) { 0 => id, 1 => s };
    let a = h(a);
    join(b, a)
}

/// Apply F8: |x> maps to sum_y exp(2*pi*i*x*y/8)|y>/sqrt(8) for every input.
/// For input ((a,b),c), x = a + 2*b + 4*c; output reversal is included.
/// Consume and return all three owners with no measurement or auxiliary.
pub unitary fn qft3(q: Q<((Bit, Bit), Bit)>) -> Q<((Bit, Bit), Bit)> {
    let (ab, c) = split(q);
    let (a, b) = split(ab);
    let c = h(c);
    let (b, c) = qif(b, c) { 0 => id, 1 => s };
    let (a, c) = qif(a, c) { 0 => id, 1 => t };
    let b = h(b);
    let (a, b) = qif(a, b) { 0 => id, 1 => s };
    let a = h(a);
    join(join(c, b), a)
}