Operator-Valued Generating Functions for Classical-Quantum Programs
Quantum loops may execute arbitrarily many iterations, and quantitative properties such as almost-sure termination and expected running time are often analyzed using different techniques. We ask whether a single finite symbolic representation of a quantum loop can support multiple quantitative analyses. For probabilistic programs, generating functions provide a way to analyze distributions over classical variables, including counters that record loop iterations. In quantum programs, however, classical outcomes may be correlated with quantum states, so classical output distributions alone are insufficient. We introduce operator-valued formal power series (OFPSs) to represent joint classical-quantum outputs and develop a compositional semantics. Although an OFPS may contain infinitely many coefficients, certain loops have finite control structures that allow exact symbolic analysis. We identify classical-quantum homogeneous-bounded loops and prove that their outputs admit rational representations, computable exactly using finite linear algebra without user-supplied invariants or assuming almost-sure termination. A single representation determines probabilities, moments, and conditional quantum states. For more general loops, we develop sound superinvariant bounds.