  We show that arbitrary functions of continuous variables, e.g. position and
momentum, can be used to generate tests that distinguish quantum theory from
local hidden variable theories. By optimising these functions, we obtain more
robust violations of local causality than obtained previously. We analytically
calculate the optimal function and include the effect of nonideal detectors and
noise, revealing that optimized functional inequalities are resistant to
standard forms of decoherence. These inequalities could allow a loophole-free
Bell test with efficient homodyne detection.
