definite_integral of max function [closed]

asked 2 years ago

Max Alekseyev gravatar image

The following code returns 1/2, however it can be easily verified that 10max What's wrong?

from sage.symbolic.integration.integral import definite_integral
var('x')
definite_integral(max(x,1-x),x,0,1)
Preview: (hide)

Closed for the following reason the question is answered, right answer was accepted by Max Alekseyev
close date 2024-05-29 02:21:27.569198

Comments

1

use max_symbolic

FrédéricC gravatar imageFrédéricC ( 2 years ago )

Thanks! max_symbolic does lead to the correct answer, but I worry that using max silently produces an incorrect answer - should Sage give an error or a warning about the issue at least?

Max Alekseyev gravatar imageMax Alekseyev ( 2 years ago )

This is a common pitfall. You could have tried to see what max(x,1-x) answers.

FrédéricC gravatar imageFrédéricC ( 2 years ago )

This is weird - both max(x,1-x) and min(x,1-x) return x. At very least this breaks the identity \max(x,1-x) + \min(x,1-x) = 1.

Max Alekseyev gravatar imageMax Alekseyev ( 2 years ago )

With symbolic arguments, max and min return the first argument. Hence:

sage: max(x,1-x) + min(x,1-x)                                                   
2*x

However,

sage: max(x,1-x) + min(1-x,x)                                                   
1
Juanjo gravatar imageJuanjo ( 2 years ago )