  Decomposition theorems in classical Fourier analysis enable us to express a
bounded function in terms of few linear phases with large Fourier coefficients
plus a part that is pseudorandom with respect to linear phases. The
Goldreich-Levin algorithm can be viewed as an algorithmic analogue of such a
decomposition as it gives a way to efficiently find the linear phases
associated with large Fourier coefficients.
  In the study of "quadratic Fourier analysis", higher-degree analogues of such
decompositions have been developed in which the pseudorandomness property is
stronger but the structured part correspondingly weaker. For example, it has
previously been shown that it is possible to express a bounded function as a
sum of a few quadratic phases plus a part that is small in the $U^3$ norm,
defined by Gowers for the purpose of counting arithmetic progressions of length
4. We give a polynomial time algorithm for computing such a decomposition.
  A key part of the algorithm is a local self-correction procedure for
Reed-Muller codes of order 2 (over $\F_2^n$) for a function at distance
$1/2-\epsilon$ from a codeword. Given a function $f:\F_2^n \to \{-1,1\}$ at
fractional Hamming distance $1/2-\epsilon$ from a quadratic phase (which is a
codeword of Reed-Muller code of order 2), we give an algorithm that runs in
time polynomial in $n$ and finds a codeword at distance at most $1/2-\eta$ for
$\eta = \eta(\epsilon)$. This is an algorithmic analogue of Samorodnitsky's
result, which gave a tester for the above problem. To our knowledge, it
represents the first instance of a correction procedure for any class of codes,
beyond the list-decoding radius.
  In the process, we give algorithmic versions of results from additive
combinatorics used in Samorodnitsky's proof and a refined version of the
inverse theorem for the Gowers $U^3$ norm over $\F_2^n$.
