# Double-integration and logs

I am running into various odd problems while trying to compute a double integral. My code is as follows:

x, y = var('x y')
##### Two different ways of generating random polynomials F(x,y) to test double-integration ########
#F = ZZ['x','y'].random_element(4, 1000)
F = randint(-1000, 1000)*x**4*y**4 + randint(-1000, 1000)*x**3*y + randint(-1000, 1000)*x**2*y**3 +randint(-1000, 1000)*x  + randint(-1000, 1000)*y**2
G = randint(0, 1000)*x**4*y + randint(0, 1000)*x**3 + randint(0, 1000)*x**2*y**2 +randint(0, 1000)*x  + randint(0, 1000)*y**4
###### Defining the function we want to integrate over dx dy ##########
f =  log(F)
####### Double integration  #####
g= integrate(f, x, 1, 2)
print 'after integration dx:', g
assume(y>0)
print n(g.integral(y, 1, 2))


Problems: 1) If I use the random polynomial F generated by .random_element, the integration generates the following error : TypeError: integral() takes exactly one argument (3 given). However, if I use the other one I manually generate, then it integrates okay. If I copy from the terminal the .random_element() polynomial and explicitly write it in my code, then it will also work. Why not directly from the .random_element() function then ?

2) If I set f = F or even f = FG, then the double integral works fine. However, as soon as I introduce the *log function, the calculation never terminates (if I work with an example in the terminal with a log function, then it does integrate properly).

Any idea what might cause these weird bugs ? Thanks!

edit retag close merge delete

Let us try to get a random F...

sage: F = ZZ['x','y'].random_element(4, 1000)
sage: F
-x^4 - 34*x^3*y + x^2*y^2 + x*y^3 - 4*y^4 + x^3 - x^2*y + 3*x*y^2 - y^3 - 3*y^2 - x + y + 1
sage: F(1,1)
-37


And now we take the logarithm...

Best, please fix for us some polynomial F making sense till the end of the computations, so that we have a common question with a (mathematically) unique answer. Moreover, there is no problem with:

sage: R = ZZ['x','y']
sage: f = R( ( 1+(x-1)^2) * (1+(y-1)^2 )  )
sage: F = log(f)
sage: integrate( F, x, 1, 2 ).integrate( y, 1, 2 )
pi + 2*log(4) - 2*log(2) - 4

( 2017-06-28 08:06:46 -0500 )edit

Thank you. I tried copying your example and I run into the error :

ValueError: Computation failed since Maxima requested additional constraints; using the 'assume' command before evaluation may help (example of legal syntax is 'assume(y^2-2y+2>0)', see assume? for more details) Is y^2-2y+2 positive or negative?

( 2017-06-28 09:17:35 -0500 )edit

This is an example for which the double integration of log(F) never ends: F = -2x^4 - x^2y^2 - 2xy^3 + x^3 + 5x^2y + 5xy^2 + 5y^3 + 2y^2 - 3*x + y - 21

( 2017-06-28 09:47:54 -0500 )edit

Sorry, yes, in the session with the computation of the integral there was an assume for each of the variables. The comments do not provide to much room for a post:

sage: R = ZZ['x','y']
sage: assume( x>1 )
sage: assume( y>1 )
sage: F = log( ( 1+(x-1)^2) * (1+(y-1)^2 ) )
sage: F.integral(x,1,2).integral(y,1,2)
pi + 2*log(4) - 2*log(2) - 4


This makes no problems.

( 2017-06-28 20:58:55 -0500 )edit
1

The never ending story is related to a function which is hard to integrate. Note that the logarithm is taken over a function with negative values on a subdomain of $[0,1]^2$. For instance:

sage: f = -2*x^4 - x^2*y^2 - 2*x*y^3 + x^3 + 5*x^2*y + 5*x*y^2 + 5*y^3 + 2*y^2 - 3*x + y - 21
sage: f(1,1)
-10
sage: f(2,1)
-21


Which is then the meaning of $\log f$ ?

Even if we know to get a branch of the logarithm and consider a corresponding complex valued function $\log f:[1,2]^2\to\mathbb C$, the first integral (w.r.t. the variable $x$) explicitly asks for an exact value (and the interpreter does not look further to see that we need only a numerical value). This value is "hard to compute" in general.

( 2017-06-28 21:09:39 -0500 )edit