mydefint2



mydefint2 does 2d integration using integrate twice.

Calls separate and mydefint1.

An attempt to define functions which result in minimal
questions about the variables of integration.

Of course, questions may be asked about unbound
parameters in the integrand.

Example of use:
----------------------------
(%i1) load(mydefint);
(%o1) "c:/work2/mydefint.mac"

(%i2) mydefint2(x*y,[x,0,1],[y,0,1]);
(%o2) 1/4

(%i3) mydefint2 (log(x+y),[x,0,1],[y,0,1]);
(%o3) (4*log(2)-3)/2

(%i4) mydefint2 (1/sqrt(x+y),[x,0,1],[y,0,1]);
(%o4) (2^(7/2)-8)/3

(%i5) mydefint2(sqrt(x^2 - 2*x*y + y^2),[x,-1,1],[y,-1,1]);
(%o5) 8/3

(%i6) mydefint2(sqrt(x^2 - 2*x*y + y^2),[x,-1,1],[y,-x,x]);
(%o6) 0

----------------------------------
code file mydefint.mac:

-----------------------------------
/* mydefint.mac */

/* separate(aL,x) returns a list of two
   lists, the first being the elements of aL
   which contain x, the second being the elements
   of aL which do not contain x  */


separate(a11L,xx11) :=
block([t11,t11L:[],t22L:[]],
   for t11 in a11L do
     if length(t11) < 2 then t22L : cons(t11,t22L)
     else if (part(t11,1) = xx11 or part(t11,2) = xx11) then
           t11L : cons(t11,t11L)
     else t22L : cons(t11,t22L),
   [t11L,t22L])$


/****  mydefint1
     calls separate.
     forgets those global facts
     which involve the integration variable.
     before creating local facts.
     After doing the integral the
     the forgotten facts are re-assumed. *********/


mydefint1 (e78, x78, a78, b78) :=
block( [domain : complex,forgetL,ignoreL, res1,  loc_assume,e781],
        [forgetL,ignoreL] : separate(facts(),x78),
        if debug then display (forgetL,ignoreL),
        apply('forget,forgetL),
        loc_assume : apply('assume, [x78 > min(a78,b78), x78 < 
max(a78,b78)] ),
        e781 : expand (e78,0,0),
        res1 : ratsimp (integrate (e781, x78, a78, b78 ) ),
        apply ('forget, loc_assume),
        apply ('assume, forgetL),
        res1)$


/********  mydefint2
    calls separate and mydefint1  ************/


mydefint2(qe,qxL,qyL) :=
block([forget2L,ignore2L,locx_assume,qe79,
         qxmin,qxmax,res79,res791,res792,xsign],

    qxmin : min(qxL[2],qxL[3]),
    qxmax : max(qxL[2],qxL[3]),
    if qxmin = qxL[3] then xsign:-1 else xsign:1,

    [forget2L,ignore2L] : separate(facts(),qxL[1]),
    apply('forget,forget2L),

    /* case x doesn't change sign  */

    if (qxmin >= 0 or qxmax <= 0) then
         (locx_assume : apply('assume, [qxL[1] > qxmin,
                                 qxL[1] < qxmax] ),
          qe79 : expand (qe,0,0),
          res79 : apply('integrate,
               [apply('mydefint1,flatten([qe79,qyL])),qxL[1],qxmin,qxmax]),
          res79 : xsign*ratsimp(res79),
          apply ('forget, locx_assume))

    else  /* case x does change sign */

        (locx_assume : apply('assume, [qxL[1] > qxmin,qxL[1] < 0] ),
          qe79 : expand (qe,0,0),
          res791 : apply('integrate,
               [apply('mydefint1,flatten([qe79,qyL])),qxL[1],qxmin,0]),
          apply('forget,locx_assume),

          locx_assume : apply('assume, [qxL[1] > 0,qxL[1] < qxmax] ),
          qe79 : expand (qe,0,0),
          res792 : apply('integrate,
               [apply('mydefint1,flatten([qe79,qyL])),qxL[1],0,qxmax]),
          res79 : xsign*ratsimp(res791 + res792),
          apply('forget,locx_assume)),
    apply ('assume, forget2L),
    res79)$

display2d:false$
ratprint:false$
----------------------------------------------