definite_integral of max function [closed]
The following code returns 1/2, however it can be easily verified that
$$\int_0^1 \max(x,\ 1-x)\,{\rm d}x = \frac34.$$
What's wrong?
from sage.symbolic.integration.integral import definite_integral
var('x')
definite_integral(max(x,1-x),x,0,1)
use
max_symbolicThanks!
max_symbolicdoes lead to the correct answer, but I worry that usingmaxsilently produces an incorrect answer - should Sage give an error or a warning about the issue at least?This is a common pitfall. You could have tried to see what
max(x,1-x)answers.This is weird - both
max(x,1-x)andmin(x,1-x)returnx. At very least this breaks the identity $\max(x,1-x) + \min(x,1-x) = 1$.With symbolic arguments,
maxandminreturn the first argument. Hence:However,