Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

The following is the code and output of a Mathematica command

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

share|improve this question
    
Interestingly Integrate knows there is no dependency, g[y] Integrate[1/g[y]] -> x . Anyone try to tackle this through Simplify[ .. ComplexityFunction .. ] ?? –  george2079 Dec 2 '13 at 16:02
    
@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... –  Peltio Dec 3 '13 at 16:15
    
Oops. It was @Michael E2, not Micheal. Sorry. (Somehow autocompletion of "@" names is no longer working on this PC...) –  Peltio Dec 3 '13 at 17:37
1  
Hi @Prahar, if you are interested at the end of the week, a new higher-level physics site outside the SE network with the intention to some kind of revive the closed Theoretical Physics SE with a slightly broadend scope and lowered bar to ask questions (graduate-level upward) will go online. The content of the former theoretical physics site is successfully imported into the new site, called PhysicsOverflow. You can access it and see what we are doing here. In case of technical problems you can mail to admin@physicsoverflow.org. –  Dilaton Apr 1 at 11:24
2  
@Dilaton - I'm extremely interested. Its just what I've been looking for. Thanks. –  Prahar Apr 1 at 12:57
add comment

marked as duplicate by Michael E2, Sjoerd C. de Vries, rm -rf Dec 3 '13 at 5:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3 Answers

up vote 4 down vote accepted

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.

share|improve this answer
add comment

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}]

share|improve this answer
add comment

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

share|improve this answer
add comment

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