11
$\begingroup$

The following is the code and output of a Mathematica command

How do I get Mathematica to remove $g(y)$ outside the integral?

$\endgroup$
4
  • $\begingroup$ Interestingly Integrate knows there is no dependency, g[y] Integrate[1/g[y]] -> x . Anyone try to tackle this through Simplify[ .. ComplexityFunction .. ] ?? $\endgroup$
    – george2079
    Dec 2, 2013 at 16:02
  • $\begingroup$ @Micheal E2 Actually, this is not a duplicate, but a more general question that opens up ways different from replacement rules to solve the problem, as the answer by george2079 shows. I wonder if it would be possible to merge posts so that the more general question can be posed along with special cases... $\endgroup$
    – Peltio
    Dec 3, 2013 at 16:15
  • $\begingroup$ Oops. It was @Michael E2, not Micheal. Sorry. (Somehow autocompletion of "@" names is no longer working on this PC...) $\endgroup$
    – Peltio
    Dec 3, 2013 at 17:37
  • 2
    $\begingroup$ @Dilaton - I'm extremely interested. Its just what I've been looking for. Thanks. $\endgroup$
    – Prahar
    Apr 1, 2014 at 12:57

3 Answers 3

9
$\begingroup$

This is some code I adapted from a package I wrote to manipulate Sums, instead of integrals. But it should work in bringing out expression that do not depend on the integration variable too. After all, integrals are sums pushed to the limit. EDIT: cleaned up code, there is no need to separate rules here.

outrules = {
           Integrate[f_ + g_, it:{x_Symbol, __}] :> Integrate[f, it] + Integrate[g, it],
           Integrate[c_ f_, it:{x_Symbol, __}] :> c Integrate[f, it] /; FreeQ[c, x],
           Integrate[c_, it:{x_Symbol, __}] :> c Integrate[1, it] /; FreeQ[c, x]
           };

(You could apply the rules directly as in expr //. outrules, but I like to define an ordinary procedure like BringOut - or PullOut if you prefer)

BringOut[s_] := s //. outrules

It works in your simple example

g[y] Integrate[f[x1, y]/g[y], {x1, 0, x}] // BringOut

    (* Integrate[f[x1, y], {x1, 0, x}] *)

and it also works with more complex integrands (basically, it exploits the linear property of the integral)

Integrate[y(f[x1, y]/(1 + g[y]) - h[y]), {x1, 0, x}] // BringOut

    (* y (Integrate[f[x1, y], {x1,0,x}]/(1 + g[y]) - x h[y]) *)

Sometimes you might want to wrap and Expand, or an Apart or some other expression manipulation procedure to the integrand. Since the action usually depends on the expression, I found no use into incorporating this into BringOut. It's cleaner to apply the desired simplification where you need it and only when you need it, usually after BringOut has done its work:

BringOut[Integrate[y(f[x1, y]/(1 + g[y]) - h[y]), {x1, 0, x}]] // Factor

    (* (Integrate[f[x1, y], {x1,0,x}] - x h[y] + x g[y] h[y]) y / (1 + g[y]) *)

Caveat emptor: the original code worked on a user defined and unevaluated version of Sum, and I have not tested it thoroughly with a built-in procedure like Integrate. But I do not see why it shouldn't work.

$\endgroup$
3
  • $\begingroup$ (+1) Nice Answer. You have an extra semi-colon at the end of outrules list after FreeQ. $\endgroup$ Mar 24, 2016 at 20:18
  • 1
    $\begingroup$ @H.R., thanks. Fixed. $\endgroup$
    – Peltio
    Mar 26, 2016 at 4:29
  • $\begingroup$ Do you have a way to match the pattern when there are several integration variables? So you would need to match several instances of {x_Symbol, __} but also track the symbol names x so that they can be used in FreeQ $\endgroup$
    – Luca
    Nov 27 at 16:22
2
$\begingroup$

Based on this solution (replacement rule to pull independent expression outside of Integrate) You can solve it the following way:

g[y]*Integrate[f[x1, y]/g[y], {x1, 0, x}] /.Integrate[q_/r_, {v_, l_, h_}] 
/; FreeQ[r, v] :> 1/r*Integrate[q, {v, l, h}]

Integral[f[x1, y],{x1,0,x}]

$\endgroup$
0
$\begingroup$

Here is a stab at the problem using TransformationFunctions:

ClearAll[xx]
xx[exp_Integrate /; 
       Head[integrand = (First@(List @@ exp))] == Times ] := Module[{dep,indep},
    indep = 
      Select[(List @@ integrand), (FreeQ[#, First@(Last@(List @@ exp))]) &] ;
    dep = Complement[(List @@ integrand), indep];
    ((Times @@ indep ) Integrate[Times @@ dep, (Last@(List @@ exp))])];
xx[exp_] := exp
Simplify[g[y] Integrate[ g[x]/g[y] , {x, 0, 1}],  TransformationFunctions -> {xx}]

(*  Integrate[ g[x] , {x, 0, 1}] *)

Big UNTESTED warning.. I only checked that it works for the given example..

Also adding Automatic to TransformationFunctions breaks it for some reason I havent explored

$\endgroup$

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