Ask Your Question
0

.is_real() function provides wrong answer

asked 0 years ago

updated 0 years ago

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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 0 years ago

Max Alekseyev gravatar image

updated 0 years ago

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
Preview: (hide)
link

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: 0 years ago

Seen: 111 times

Last updated: Feb 12