  We develop a framework for analyzing layered quantum algorithms such as
quantum alternating operator ans\"atze. Our framework relates quantum cost
gradient operators, derived from the cost and mixing Hamiltonians, to classical
cost difference functions that reflect cost function neighborhood structure. By
considering QAOA circuits from the Heisenberg picture, we derive exact general
expressions for expectation values as series expansions in the algorithm
parameters, cost gradient operators, and cost difference functions. This
enables novel interpretability and insight into QAOA behavior in various
parameter regimes. For single-level QAOA1 we show the leading-order changes in
the output probabilities and cost expectation value explicitly in terms of
classical cost differences, for arbitrary cost functions. This demonstrates
that, for sufficiently small positive parameters, probability flows from lower
to higher cost states on average. By selecting signs of the parameters, we can
control the direction of flow. We use these results to derive a classical
random algorithm emulating QAOA1 in the small-parameter regime, i.e., that
produces bitstring samples with the same probabilities as QAOA1 up to small
error. For deeper QAOAp circuits we apply our framework to derive analogous and
additional results in several settings. In particular we show QAOA always beats
random guessing. We describe how our framework incorporates cost Hamiltonian
locality for specific problem classes, including causal cone approaches, and
applies to QAOA performance analysis with arbitrary parameters. We illuminate
our results with a number of examples including applications to QUBO problems,
MaxCut, and variants of MaxSat. We illustrate the application to QAOA circuits
using mixing unitaries beyond the transverse-field mixer through two examples
of constrained optimization, Max Independent Set and Graph Coloring.
