Say we have

Integrate[a f[x],{x,-Infinity,Infinity}]

And want Mathmatica to factor out a to get

a Integrate[f[x],{x,-Infinity,Infinity}]

This works automatically for the indefinite integral

Integrate[a f[x],x]

but I need it to work for the definite one in order to further simplify long expressions. Just applying Factor doesn't do it and FullSimplify even with assumption Element[a,Reals] doesn't either.

Am I missing some obvious assumption that makes it work? Or do I have to write some pattern matching expression?

Quite possibly related is the fact that Mathematica doesn't see an equality here:

 Integrate[a f[x], {x, -Infinity, Infinity}] == 
  a Integrate[f[x], {x, -Infinity, Infinity}], Element[a, Reals]]

This just returns the input expression again:

Integrate[a f[x], {x, -Infinity, Infinity}] == 
 a Integrate[f[x], {x, -Infinity, Infinity}]

Edit: I just checked and this is even true if we make replace a by a natural number directly! Again the unaltered expression is returned.

I am on Mathematica

  • 1
    $\begingroup$ Integrate[a f[x], {x, -Infinity, Infinity}] /. Integrate[a_, b_] :> Integrate[a, x] /. Integrate[a_, b_] :> Integrate[a, {x, -Infinity, Infinity}]? $\endgroup$
    – kglr
    Aug 20 '19 at 13:37
  • $\begingroup$ @kglr This works if x is the actual integration variable while a can be replaced by another symbol in this expression. I guess I was expecting something that would do it at once for integrals over any variable but for my current purpose this is actually enough. $\endgroup$
    – tortortor
    Aug 20 '19 at 14:12
  • $\begingroup$ @WeavingBird1917 Yes! Thanks! This is close enough for a duplicate for me. The provided solution does what I want and is more general than klgr's suggestion. $\endgroup$
    – tortortor
    Aug 20 '19 at 14:44

How about this

    factorConstant[integral_] := 
   "Integrate[" ~~ x_ -> x ~~ "*Integrate["]]


factorConstant[Integrate[a f[x], {x, -Infinity, Infinity}]]
(*a Integrate[f[x],{x,-Infinity,Infinity}]*)
  • $\begingroup$ The problem is that I have a long expression with many integrals (and some non-integral terms) in it. So threading this into the right places is unfeasible. $\endgroup$
    – tortortor
    Aug 20 '19 at 14:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.