1
$\begingroup$

I am trying to force some integrales in the form $\int \mathrm{d}x f(x)+g(x)$ into $\int \mathrm{d}x f(x)+\int \mathrm{d}x g(x)$. My first naive solution was

Integrate[f@x + g@x, x] /. Integrate[x__Plus, ks__] :> Distribute@Integrate[x, ks]

however the funny issue is that the first integral in the rule is directly evaluated to

ks__ x__Plus

which cannot indeed match the expression. So I'd need a way to stop evaluating not only the right-hand side of the rule with :> but also the left-hand side. I've cursorily tried with combinations of Hold, Unevaluated and such, but with no luck.

I understand that I could apply Distribute, but I would rather like to have a rule, because it fits better into my workflow, and let's say also for exercise.

$\endgroup$
  • 1
    $\begingroup$ Look up HoldPattern $\endgroup$ – Carl Woll Mar 10 '17 at 14:28
  • $\begingroup$ @CarlWoll Thank you, I'd accept the answer. $\endgroup$ – Lorenzo Pistone Mar 10 '17 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.