How to do algebra on unevaluated integrals?
Similar idea to belisarius, except in V10 we can inactivate Integrate
to keep it from evaluating or even trying to evaluate:
h = Inactive[Integrate][g, {x, -Infinity, Infinity}]
It is not necessary in this example, as belisarius' answer shows, but one of its intended uses is to do algebra/calculus on integrals and derivatives. Inactive
can be removed easily with
Activate[h]
The function linearExpand
expands its argument according to linearity properties. Factors/terms that do not depend on x
are treated as constants (see update below for a more general approach).
Clear[linearExpand];
linearExpand[e_] := e //. {int : Inactive[Integrate][_Plus, _] :> Distribute[int],
Inactive[Integrate][integrand_Times, dom : {x_, _, _} | x_] :>
With[{dependencies = Internal`DependsOnQ[#, x] & /@ List @@ integrand},
Pick[integrand, dependencies, False] *
Inactive[Integrate][Pick[integrand, dependencies, True], dom]
]};
OP's sample problem:
Solve[D[h, #] == 0 & /@ cs // linearExpand, cs]
D[h, #] == 0 & /@ cs // linearExpand
For what it's worth...
...here's a general linearity expander. Considers factors that do not depend on x
, which may be a list of symbols, as constants.
linearExpand[e_, x_, head_] :=
e //. {op : head[arg_Plus, __] :> Distribute[op],
head[arg1_Times, rest__] :>
With[{dependencies = Internal`DependsOnQ[#, x] & /@ List @@ arg1},
Pick[arg1, dependencies, False] head[
Pick[arg1, dependencies, True], rest]
]};
Examples:
linearExpand[D[h, #] == 0 & /@ cs, x, Inactive[Integrate]]
(* same as above *)
linearExpand[foo[(a[x] + c b[y]) (2 a[x] - c b[y]) // Expand, randomarg], x, foo]
(* -c^2 b[y]^2 foo[1, randomarg] +
c b[y] foo[a[x], randomarg] +
2 foo[a[x]^2, randomarg] *)
linearExpand[foo[(a[x] + c b[y]) (2 a[x] - c b[y]) // Expand, randomarg], {x, y}, foo]
(* 2 foo[a[x]^2, randomarg] +
c foo[a[x] b[y], randomarg] -
c^2 foo[b[y]^2, randomarg] *)
f = a[x] + c1*b[x] + c2*c[x];
g = Expand[f*f];
(* we need to get the constants out of the integrals first*)
h = Distribute@Integrate[g, {x, -∞, ∞}] //. Integrate[q1___ r__ q2___, {v_, s__}] /;
FreeQ[{r}, v] :> r Integrate[q1 q2, {v, s}];
s= Solve[And @@ Thread[D[h, #] & /@ {c1, c2} == 0], {c1, c2}]
(* now we go to bra-ket notation *)
bkRulez = {Integrate[a_ [x] b_[x], {x, -∞, ∞}] -> AngleBracket[a, b],
Integrate[Power[a_ [x], 2], {x, -∞, ∞}] -> AngleBracket[a, a]}
Column @@ (s /. bkRulez) // TeXForm
$$\begin{array}{l} \text{c1}\to -\frac{\langle a,c\rangle \langle b,c\rangle -\langle c,c\rangle \langle a,b\rangle }{\langle b,c\rangle ^2-\langle b,b\rangle \langle c,c\rangle } \\ \text{c2}\to -\frac{\langle b,b\rangle \langle a,c\rangle -\langle a,b\rangle \langle b,c\rangle }{\langle b,b\rangle \langle c,c\rangle -\langle b,c\rangle ^2} \\ \end{array}$$