Double-integration and logs

asked 7 years ago

Sasha-dpt gravatar image

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!

Preview: (hide)

Comments

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
dan_fulea gravatar imagedan_fulea ( 7 years ago )

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?

Sasha-dpt gravatar imageSasha-dpt ( 7 years ago )

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

Sasha-dpt gravatar imageSasha-dpt ( 7 years ago )

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.

dan_fulea gravatar imagedan_fulea ( 7 years ago )
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 logf ?

Even if we know to get a branch of the logarithm and consider a corresponding complex valued function logf:[1,2]2C, 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.

dan_fulea gravatar imagedan_fulea ( 7 years ago )