# Expansion / simplification under integral

GROUPS:
 Is there a way to ask Mathematica to simplify an expression like (Integrate[(h[p1]*Subscript[C, p1])/E^(I*p1*x), {p1, -Infinity, Infinity}] + Integrate[E^(I*p1*x)*hDag[p1]*Subscript[C, p1], {p1, -Infinity, Infinity}])* (Integrate[(h[p2]*Subscript[C, p2])/E^(I*p2*x), {p2, -Infinity, Infinity}] + Integrate[E^(I*p2*x)*hDag[p2]*Subscript[C, p2], {p2, -Infinity, Infinity}]) such that the result is of the form Integrate[E^(I*(-p1 + p2)*x)*Subscript[C, p1]*Subscript[C, p2], {p1, -Infinity, Infinity}, {p2, -Infinity, Infinity}] and so on...?
 I don't think there's a built-in way, but you can do it with patterns and rule replacements. Here is a way to extend Simplify with TransformationFunctions and the transformations in intXF. Sometimes it may help to penalize an expression for having extra Integrate terms. In that case, use the option ComplexityFunction with intCF. intXF = { # /. Verbatim[Integrate][f1_, x1 : PatternSequence[{_, _, _} ..]] * Verbatim[Integrate][f2_, x2 : PatternSequence[{_, _, _} ..]] :> Integrate[f1*f2, x1, x2] &, # /. (c1_: 1) Verbatim[Integrate][f1_, x : PatternSequence[{_, _, _} ..]] + (c2_: 1) Verbatim[Integrate][f2_, x : PatternSequence[{_, _, _} ..]] :> Integrate[c1*f1 + c2*f2, x] & }; intCF = SimplifySimplifyCount[#] + 5 Count[#, Integrate, Infinity] &; Simplify[i0 , TransformationFunctions -> {Automatic, Sequence @@ intXF} (*,ComplexityFunction\[Rule]intCF*)] (* Out[]= Integrate[((h[p1] + E^((2*I)*p1*x)*hDag[p1])*(h[p2] + E^((2*I)*p2*x)*hDag[p2])*Subscript[C, p1]*Subscript[C, p2]) / E^(I*(p1 + p2)*x), {p1, -Infinity, Infinity}, {p2, -Infinity, Infinity}] *) For general use, it would be good to put some checks in the transformation functions to make sure that the application of Fubini's rule is at least formally valid (such as that f1 is independent of the variables in x2, etc.).