My question involves extending the functionality of Integrate over specific integrals in the most generic manner.

Specifically, is it possible to "hack into" Integrate so as a to add to the "grammar" of analytic integration a new family of integrals which the user would have provided (in the spirit of ProbabilityDistribution which allows the user to include his own PDF into the existing tools).

The idea is that Mathematica would be able to identify when such integrals pop up and replace it by the given definition. The specific example I have in mind involves the integral of MultinormalDistribution over square subregions of the integration domain. That is to say I would like to attach to either MultiNormalDistribution, or Expectation, (or Integrate) the following rule

Expectation[Boole[(x>a)&&(y>b)], {x,y} ~Distributed~
    MultinormalDistribution[{0,0},{{1,c},{c,1}}]] = FF[a,b,c]

(where FF is a given function of a, b, and c which could be tabulated).

@JM suggested using TagSet or TagSetDelayed, but the difficulty is to decide to which function it should be associated with, and with what efficiency, given that it would be unwise to temper with build in symbols like Integrate?


As a simpler toy problem I tried

Integrate /: Integrate[f[x], {x, a_, b_}] = F[a, b] 

for which Integrate[f[x],{x,1,2}] returns F[1,2]

But for instance Integrate[2 f[x], {x, 1, 2}] is not evaluated, which suggests that my new (possibly admittedly dangerous) definition has not been taken as a global rule for integration.

More relevantly, I tried

Expectation[ Boole[x_ > a_ && y_ > b_], {x_, y_}~Distributed~
    MultinormalDistribution[{0, 0}, {{1, c_}, {c_, 1}}]] = FF[a, b, c]

so that

 Boole[x > 1 && y > 2], {x, y}~Distributed~
  MultinormalDistribution[{0, 0}, {{1, 1/3}, {1/3, 1}}]] 

returns FF[1,2,1/3]

(after a short while).


  1. What is the best way to write down the definition? Assign it to MultinormalDistribution, Expectation, Integrate?

  2. How to make sure it is "integrated" by Mathematica so that when attempting, e.g. to compute the expectation of d*Boole[x>a && y>b] it would return d*FF[a,b,c] (or the expectation of u+Boole[x>a && y>b] the Expectation of u + FF[a,b,c])? More specifically, how to make sure Mathematica tries to transform a given integral into a form which could match the new definition?


The package Rubi4 effectively extends the number of functions mathematica can integrate, though not following the path envisaged in this post.

Mathematica graphics

  • $\begingroup$ Related: forums.wolfram.com/mathgroup/archive/2008/Apr/msg00649.html $\endgroup$
    – Szabolcs
    Commented May 29, 2012 at 7:12
  • $\begingroup$ As it happens, the 2D example I give below has an "analytic" solution in terms of OwenT cf math.stackexchange.com/questions/153421/… It remains interesting to extend it e.g. to 3D. $\endgroup$
    – chris
    Commented Jun 6, 2012 at 11:45
  • 1
    $\begingroup$ Dilapidating your fortune? $\endgroup$ Commented Oct 8, 2012 at 0:56
  • 1
    $\begingroup$ @belisarius very nouveau riche isn't it? I am actually really interested in the answer! (and what's the point being virtually rich :-) $\endgroup$
    – chris
    Commented Oct 8, 2012 at 5:38

1 Answer 1


At first, overriding Integrate[] is not per-se dangerous. Nevertheless, you should make sure that it gives the correct results by implementing a few unit tests (for example check, that Integrate[2 f[x], {x,1,2}] truly results in 2F[1,2], as you'd expect.

Second, the pattern matching for Integrate[] is a bit more subtle: The rule you have given will not match 2 f[x] as argument for integrate, but only functions depending on the integration variable without any prefactors.

A rule you could use for that purpose would be Integrate[c_ f_[x_], {x_, a_, b_}] := c F[a, b] /; FreeQ[c, x], which checks whether c depends on x. You will also need a few other rules for multiplication, etc. It's important to note here that c___ does not work as a pattern, as (schematically) f[x] is not the same as (no prefactor) f[x].

  • 1
    $\begingroup$ If you change the pattern to include c_. rather than c_ you can capture more cases. $\endgroup$
    – evanb
    Commented Apr 27, 2015 at 18:01

Your Answer

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

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