f(sqrt(x)) yields sqrt(x) for f(x) = x^2

68 views
Skip to first unread message

Eric Gourgoulhon

unread,
Aug 15, 2020, 10:36:55 AM8/15/20
to sage-devel
Hi,

I know that sqrt in Sage is terribly buggy (cf. e.g. the recent thread https://groups.google.com/g/sage-devel/c/h50LZVLVQI4/m/fSWpSpYEAwAJ) , but this one seems horrible:

sage: f(x) = x^2
sage: f(sqrt(x))
sqrt(x)

The composition of f with everything else than sqrt looks OK:

sage: f(cos(x))                                                                
cos(x)^2
sage: f(x+1)                                                                   
(x + 1)^2
sage: f(x^(1/3))                                                               
x^(2/3)

This bug is there since at least Sage 8.3.  I haven't found it on the page
Shall I open a ticket?

Eric.

Eric Gourgoulhon

unread,
Aug 15, 2020, 10:49:25 AM8/15/20
to sage-devel
PS: f(sqrt(a)) with a distinct from x seems OK:

sage: f(sqrt(2))                                                               
2
sage: f(sqrt(pi))                                                              
pi
sage: y = var('y')                                                             
sage: f(sqrt(y))                                                               
y

Nils Bruin

unread,
Aug 15, 2020, 12:23:12 PM8/15/20
to sage-devel
On Saturday, August 15, 2020 at 7:49:25 AM UTC-7, Eric Gourgoulhon wrote:
PS: f(sqrt(a)) with a distinct from x seems OK:

sage: f(sqrt(2))                                                               
2
sage: f(sqrt(pi))                                                              
pi
sage: y = var('y')                                                             
sage: f(sqrt(y))                                                               
y

And if you define the function with a differently named formal parameter, the pattern persists:

sage: g(y)=y^2
sage: g(sqrt(y))
sqrt(y)
sage: g(sqrt(x))
x

so at least it's not the name of the variable itself. Callable expressions aren't the problem. The behaviour is mirrored in variable substitution already:

sage: (x^2).subs(x=sqrt(x))
sqrt(x)

and other powers don't seem to be either:

sage: (x^4).subs(x=sqrt(x))
x^2
sage: (x^(-2)).subs(x=sqrt(x))
1/x

It's most likely some silly bug in pynac. That requires tracing c-code, though.

Eric Gourgoulhon

unread,
Aug 16, 2020, 1:02:26 PM8/16/20
to sage-devel
Le samedi 15 août 2020 à 18:23:12 UTC+2, Nils Bruin a écrit :

so at least it's not the name of the variable itself. Callable expressions aren't the problem. The behaviour is mirrored in variable substitution already:

It's most likely some silly bug in pynac. That requires tracing c-code, though.

Thanks for the feedback. This is now
Reply all
Reply to author
Forward
0 new messages