  Efficient synthesis of arbitrary quantum states and unitaries from a
universal fault-tolerant gate-set e.g. Clifford+T is a key subroutine in
quantum computation. As large quantum algorithms feature many qubits that
encode coherent quantum information but remain idle for parts of the
computation, these should be used if it minimizes overall gate counts,
especially that of the expensive T-gates. We present a quantum algorithm for
preparing any dimension-$N$ pure quantum state specified by a list of $N$
classical numbers, that realizes a trade-off between space and T-gates. Our
scheme uses $\mathcal{O}(\log{(N/\epsilon)})$ clean qubits and a tunable number
of $\sim(\lambda\log{(\frac{\log{N}}{\epsilon})})$ dirty qubits, to reduce the
T-gate cost to
$\mathcal{O}(\frac{N}{\lambda}+\lambda\log{\frac{N}{\epsilon}}\log{\frac{\log{N}}{\epsilon}})$.
This trade-off is optimal up to logarithmic factors, proven through an
unconditional gate counting lower bound, and is, in the best case, a quadratic
improvement in T-count over prior ancillary-free approaches. We prove similar
statements for unitary synthesis by reduction to state preparation. Underlying
our constructions is a T-efficient circuit implementation of a quantum oracle
for arbitrary classical data.
