another "how to simplify" question

35 views
Skip to first unread message

Fernando Q. Gouvea

unread,
Dec 8, 2021, 1:06:53 PM12/8/21
to sage-s...@googlegroups.com

I was showing my students a famous calculus example of an integral that can be computed in one order of the variables but not in the other. Knowing that SageMath can compute anything, the students suggested trying the integral the "wrong" way.

The "right" way is

sage: integrate(integrate(sin(x^2),y,0,x),x,0,1)
-1/2*cos(1) + 1/2

The "wrong" way is

sage: integrate(integrate(sin(x^2),x,y,1),y,0,1)

-1/16*(-1)^(3/4)*((sqrt(2) + 4*(-1)^(1/4))*e^I - sqrt(-I)*((I + 
1)*sqrt(2)*(-1)^(1/4)*e^(2*I) - (I + 1)*sqrt(2)*(-1)^(1/4)*e^I) + 
I*sqrt(2)*e^I - 2*(-1)^(1/4)*e^(2*I) - (I + 1)*sqrt(2) - 
2*(-1)^(1/4))*e^(-I)

Is there any way to get Sage to check that these are equal?

The obvious thing does not seem to work:

sage: -1/16*(-1)^(3/4)*((sqrt(2) + 4*(-1)^(1/4))*e^I - sqrt(-I)*((I + 1)*sqrt(2)
....: *(-1)^(1/4)*e^(2*I) - (I + 1)*sqrt(2)*(-1)^(1/4)*e^I) + I*sqrt(2)*e^I - 2*
....: (-1)^(1/4)*e^(2*I) - (I + 1)*sqrt(2) - 2*(-1)^(1/4))*e^(-I) == -1/2*cos(1)
....: +1/2

-1/16*(-1)^(3/4)*((sqrt(2) + 4*(-1)^(1/4))*e^I - sqrt(-I)*((I + 1)*sqrt(2)*(-1)^(1/4)*e^(2*I) 
- (I + 1)*sqrt(2)*(-1)^(1/4)*e^I) + I*sqrt(2)*e^I - 2*(-1)^(1/4)*e^(2*I) - (I + 1)*sqrt(2) 
- 2*(-1)^(1/4))*e^(-I) == -1/2*cos(1) + 1/2

Thanks,

Fernando

-- 
==================================================================
Fernando Q. Gouvea                
Carter Professor of Mathematics  
Colby College                    
Mayflower Hill 5836        
Waterville, ME 04901	   
fqgo...@colby.edu	   http://www.colby.edu/~fqgouvea

I have had a perfectly wonderful evening, but this wasn't it.
  --Groucho Marx

William Stein

unread,
Dec 8, 2021, 1:24:33 PM12/8/21
to sage-support
You can compare the real and imaginary parts directly.


sage: bool(wrong.real() == right)
True
sage: wrong.imag()
0

--
You received this message because you are subscribed to the Google Groups "sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/9557c1a9-bd1c-69e1-358f-4ab02a058c3a%40colby.edu.


--

Fernando Q. Gouvea

unread,
Dec 8, 2021, 3:21:51 PM12/8/21
to sage-s...@googlegroups.com

Thank you, that works. What is strange is that this does not:

sage: right=integrate(integrate(sin(x^2),y,0,x),x,0,1)
sage: wrong=integrate(integrate(sin(x^2),x,y,1),y,0,1)
sage: real(wrong)==right
-1/2*cos(1) + 1/2 == -1/2*cos(1) + 1/2

Is Sage seeing a difference there that I don't?

I think I don't understand the difference between real(wrong)==right and bool(real(wrong)==right).

Fernando

-- 
==================================================================
Fernando Q. Gouvea                
Carter Professor of Mathematics  
Colby College                    
Mayflower Hill 5836        
Waterville, ME 04901	   
fqgo...@colby.edu	   http://www.colby.edu/~fqgouvea

What is socialism?

The painful transition from capitalism to capitalism.

William Stein

unread,
Dec 8, 2021, 3:38:24 PM12/8/21
to sage-support
On Wed, Dec 8, 2021 at 12:22 PM Fernando Q. Gouvea <fqgo...@colby.edu> wrote:

Thank you, that works. What is strange is that this does not:

sage: right=integrate(integrate(sin(x^2),y,0,x),x,0,1)
sage: wrong=integrate(integrate(sin(x^2),x,y,1),y,0,1)
sage: real(wrong)==right
-1/2*cos(1) + 1/2 == -1/2*cos(1) + 1/2

Is Sage seeing a difference there that I don't? 


I think I don't understand the difference between real(wrong)==right and bool(real(wrong)==right).

In Sage "[symbol thing] == [symbolic thing]" is a constructor for a symbolic equation.

sage: SR(2) == SR(2)
2 == 2
sage: parent(SR(2) == SR(2))
Symbolic Ring
sage: bool(SR(2) == SR(2))
True # only because Sage can *prove* they are equal -- it's false if it can't prove they are equal, even if they are equal...




 

Fernando Q. Gouvea

unread,
Dec 8, 2021, 4:02:00 PM12/8/21
to sage-s...@googlegroups.com

I see. So the difference between this and, say, 1+1==2 (which returns True) is that 1+1 and 2 are numbers, not symbolic things.

Fernando

-- 
==================================================================
Fernando Q. Gouvea                
Carter Professor of Mathematics  
Colby College                    
Mayflower Hill 5836        
Waterville, ME 04901	   
fqgo...@colby.edu	   http://www.colby.edu/~fqgouvea

Being powerful is like being a lady. If you have to tell people you
are, you aren't.
  -- Margaret Thatcher

Daniel Volinski

unread,
Dec 9, 2021, 4:37:11 AM12/9/21
to sage-s...@googlegroups.com
Hi All,

In Maxima (embedded in SageMath) you can use:

expand(trigrat(integrate(integrate(sin(x^2),x,y,1),y,0,1)));

in order to get exactly the same result in both cases.

Daniel



Emmanuel Charpentier

unread,
Dec 9, 2021, 3:52:41 PM12/9/21
to sage-support

In Sage, this can be written wrong.maxima_methods().trigrat().expand().

HTH,

Reply all
Reply to author
Forward
0 new messages