Ask Your Question
0

.is_real() function provides wrong answer

asked 2025-02-12 02:29:11 +0100

updated 2025-02-12 23:14:20 +0100

Max Alekseyev gravatar image

I was trying to find the inflection points of a function by finding the zeros of its second derivative:

f(x) = e^x/(x^2+1)
ddf = diff(df, x, 2)
inflection_points = solve(ddf == 0, x)
show(inflection_points[2])
inflection_points[2].rhs().is_real()

The first two zeros are complex roots. The third root is a real one, and the function .is_real() returns a 'false', as can be seen by executing the above code. The fourth root is correctly found to be real. Is this an error of the function? If no, is there another test that can be performed in order to determine if a number is real?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2025-02-12 23:19:06 +0100

Max Alekseyev gravatar image

updated 2025-02-12 23:25:56 +0100

It's a known issue that .is_real() can produce wrong result for symbolic expression.

When the expression represents an algebraic number, a workaround is to convert it to QQbar and compare its imaginary part to zero - in your example:

QQbar(inflection_points[2].rhs()).imag() == 0

Alternatively, you can test if it belongs to AA:

inflection_points[2].rhs() in AA
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2025-02-12 02:29:11 +0100

Seen: 103 times

Last updated: Feb 12