19
$\begingroup$

The following is the code:

    In[3]:= Simplify[Integrate[f[x]*c, {x, a, b}]/c, Assumptions -> c > 0]

    Integrate[c f[x], {x, a, b}]
    ----------------------------
                c

but obviously the right answer should be:

    Integrate[f[x], {x, a, b}]

how to solve it without placing c outside the integrate function?

$\endgroup$
8
  • $\begingroup$ how about Simplify[Integrate[f[x]*c, {x, a, b}]/c/. Integrate-> int]/. int-> Integrate? $\endgroup$
    – chris
    May 16, 2012 at 2:07
  • $\begingroup$ the same problem. $\endgroup$
    – howard
    May 16, 2012 at 2:12
  • $\begingroup$ @chris If you first define int[c_Symbol*f_, dom_] := c*int[f, dom] or some such, then that should work fine. $\endgroup$ May 16, 2012 at 2:13
  • $\begingroup$ yes,it works,but we may need more code to take out the variable from the expression. $\endgroup$
    – howard
    May 16, 2012 at 2:32
  • $\begingroup$ @howard What expression?? $\endgroup$ May 16, 2012 at 2:58

3 Answers 3

17
$\begingroup$

You can tell Mathematica that it may move multiplicative constants out of the integral by defining the function

moveconst[x_]:=(x /.
  Integrate[factor_ expr_, {var_, min_, max_}] /; FreeQ[factor, var] :>
  factor Integrate[expr, {var, min, max}])

and then using

Simplify[Integrate[f[x]*c, {x, a, b}]/c, Assumptions -> c > 0,
         TransformationFunctions->{Automatic, moveconst}]
(*
==> Integrate[f[x], {x, a, b}]
*)

Note that Mathematica only uses the transformation if it really makes the expression simpler:

Simplify[Integrate[f[x]*c, {x, a, b}], Assumptions -> c > 0,
         TransformationFunctions->{Automatic, moveconst}]
(*
==> Integrate[c f[x], {x, a, b}]
*)

Here, moving the constant out of the integral would not have simplified the expression, therefore Mathematica doesn't do it.

$\endgroup$
1
  • $\begingroup$ @ celtschk,Thanks! problem solved. $\endgroup$
    – howard
    May 16, 2012 at 12:47
33
$\begingroup$

Edit for Mathematica version 9 and higher

To make this answer work with definite integrals in versions greater than 8, I added the line with SetAttributes in the definition below. Without declaring the antiderivative ff as a NumericFunction, the simplifications that were done in version 8 don't kick in, and the expressions remain unevaluated.

End edit

There is no way to do exactly what you want because an assumption can't be used to tell Mathematica that there exists an indefinite integral of the unknown function f[x]. See for example this MathGroup post.

However, you can get almost what you need if you define the indefinite integral yourself in the following way:

f /: Integrate[f[x_], x_] := ff[x]
SetAttributes[ff, {NumericFunction}]

This declares ff[x] as the anti-derivative of f[x]. Now we can get somewhere with the symbolic integration:

Simplify[Integrate[c f[x], {x, a, b}]/c]

-ff[a] + ff[b]

By using the delayed assignment (TagSetDelayed) for the indefinite integral, it's also possible to use other integration variables, as in

Simplify[Integrate[c f[t], {t, a, b}]/c]

-ff[a] + ff[b]

Edit

The advantage of this approach is that it also helps with other simplifications whose pattern you may not have foreseen at the outset. If you follow the pattern-matching micromanagement approach of the other answers, you'd have to introduce new patterns for new cases. For example, I can also simplify the integral:

Simplify[Integrate[c + f[x], {x, a, b}]]

(-a + b) c - ff[a] + ff[b]

And one could go on...

$\endgroup$
9
  • $\begingroup$ very good! Thank you! $\endgroup$
    – howard
    May 16, 2012 at 2:37
  • $\begingroup$ This seemed the most mathematically kosher way to deal with the situation. But I just noticed I should make the indefinite integral independent of the variable name x. I'll modify my answer by using a TagSetDelayed instead of TagSet. $\endgroup$
    – Jens
    May 16, 2012 at 2:55
  • 1
    $\begingroup$ I tried this in V9 and V10 and it didn't do anything. Can you please confirm that it still works? $\endgroup$
    – C. E.
    Aug 29, 2014 at 10:32
  • 1
    $\begingroup$ @Pickett Thanks for letting me know, anyway - maybe I'll report it as a bug - finding out that old code no longer works seems one of the constant battles in Mathematica. But I've had worse (recalling version 5 -> 6 and then again 6 -> 7)... $\endgroup$
    – Jens
    Aug 29, 2014 at 16:36
  • 1
    $\begingroup$ @Picket I've submitted a bug report[CASE:1477670], but I figured out a fix, see my edit. $\endgroup$
    – Jens
    Aug 29, 2014 at 17:21
2
$\begingroup$

This is quite probably ill-advised, but

Clear[mysimp];
mysimp[Integrate[c_Symbol*f_[x_], {x_, a_, b_}]] := 
  c*Integrate[f[x], {x, a, b}];
mysimp[h_[x__]] := Map[mysimp, h[x]];
mysimp[x_?AtomQ] := x;
mysimp[Integrate[c*f[x], {x, a, b}]/c] // InputForm

Integrate[f[x], {x, a, b}]

These patterns are written quite specifically for your example, though. I don't expect this to be generally useful.

$\endgroup$
1
  • $\begingroup$ ok,good,thank you! $\endgroup$
    – howard
    May 16, 2012 at 3:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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