# Question:Why am I not able to get the desired integral forms?

## Question:Why am I not able to get the desired integral forms?

Maple 2015

There are things that seem simple but rapidly turn into a nightmare.

Here is an example: what I want is to the expression given at equation (4) in the attached file.

Using Int gives a wrong result.
Using int gives a right one but not of the desired form (some double integrals are nested while others are not).

TIA

 > restart
 > use Statistics in   # For more generality defina an abstract probability distribution.   AbstractDistribution := proc(N)     Distribution(       PDF = (x -> varphi(seq(x[n], n=1..N)))     )   end proc:   # Define two random variables pf AbstractDistribution type.   X__1 := RandomVariable(AbstractDistribution(2)):   X__2 := RandomVariable(AbstractDistribution(2)): end use;
 (1)
 > F := (U1, U2) -> U1/(U1+U2); T := mtaylor(F(X__1, X__2), [X__1=1, X__2=1], 2):
 (2)

Error: x[2] is droped out of the double integral in the rightmost term

 > use IntegrationTools in J := eval([op(expand(T))], [seq(X__||i=x[i], i=1..2)]); L := add(        map(          j ->            if j::numeric then            j          else            (Expand@CollapseNested)(              Int(                j * Statistics:-PDF(X__1, x)                , seq(x[i]=-infinity..+infinity, i=1..2)              )            )          end if          , J        )        ): ET := % end use;
 (3)

I want this

 > 'ET' = 1/2        +        (1/4)*(Int(Int(x[1]*varphi(x[1], x[2]), x[1] = -infinity .. infinity), x[2] = -infinity .. infinity))        -(1/4)*(Int(Int(x[2]*varphi(x[1], x[2]), x[1] = -infinity .. infinity), x[2] = -infinity .. infinity))
 (4)

With int instead of Int one integral is double the other is double-nested

 > L := add(        map(          j ->            if j::numeric then            j          else              int(                j * Statistics:-PDF(X__1, x)                , seq(x[i]=-infinity..+infinity, i=1..2)              )          end if          , J        )        ): ET := %
 (5)

As the expression of ET is now correct, I tried to use IntegrationTools to get the
form I want (equation (4)).

But as soon as I replace int by Int x[2] is again droped out.

So it's not even worth thinking about using CollapseNested!

 > use IntegrationTools in   eval(ET, int=Int);   end use;
 (6)
 >