  We study a general class of first-order iterative algorithms which includes
power iteration, belief propagation and Approximate Message Passing (AMP), and
many forms of gradient descent. When the input is a random matrix with i.i.d.
entries, we present a new way to analyze these algorithms using combinatorial
diagrams. Each diagram is a small graph, and the operations of the algorithm
correspond to simple combinatorial operations on these graphs.
  We prove a fundamental property of the diagrams: asymptotically, we can
discard all of the diagrams except for the trees. The mechanics of first-order
algorithms simplify dramatically as the algorithmic operations have
particularly simple and interpretable effects on the trees. We further show
that the tree-shaped diagrams are essentially a basis of asymptotically
independent Gaussian vectors.
  The tree approximation mirrors the assumption of the cavity method, a
40-year-old non-rigorous technique in statistical physics which has served as
one of the most fundamental techniques in the field. We demonstrate the
connection with the replica symmetric cavity method by "implementing" heuristic
physics derivations into rigorous proofs. We rigorously establish that belief
propagation is asymptotically equal to its associated AMP algorithm and we give
a new simple proof of the state evolution formula for AMP.
  These results apply when the iterative algorithm runs for constantly many
iterations. We then push the diagram analysis to a number of iterations that
scales with the dimension $n$ of the input matrix. We prove that for debiased
power iteration, the tree diagram representation accurately describes the
dynamic all the way up to $n^{\Omega(1)}$ iterations. We conjecture that this
can be extended up to $n^{1/2}$ iterations but no further. Our proofs use
straightforward combinatorial arguments akin to the trace method from random
matrix theory.
