Ask Your Question
0

Help with subs

asked 2023-03-03 15:24:48 +0100

zaz gravatar image

updated 2023-03-04 18:39:12 +0100

Max Alekseyev gravatar image

This minimal non-working example returns an output of 'z'. I want 'z^3'! Any help?

B = FunctionField(QQ,'z')
B.inject_variables()
g = z
g.subs(z=z^3)
edit retag flag offensive close merge delete

Comments

The minimal non-working example would probably skip the line defining g and just do z.subs(z=z^3).

John Palmieri gravatar imageJohn Palmieri ( 2023-03-04 20:59:45 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-03-04 21:02:37 +0100

updated 2023-03-04 22:57:09 +0100

Edit: this is not an answer to the question, but together with the comments below, it may be useful, so I will leave it here.

sage: B = FunctionField(QQ,'z')
sage: B.inject_variables()
Defining z
sage: g = z
sage: g.subs(z=z^3)
z
sage: g(z) = z
sage: g.subs(z=z^3)
z |--> z^3
sage: g = z
sage: g.subs(z=z^3)
z^3

This also "works":

sage: B = FunctionField(QQ,'z')
sage: B.inject_variables()
Defining z
sage: h(z) = z
sage: g = z
sage: g.subs(z=z^3)
z^3
edit flag offensive delete link more

Comments

1

It's because g(z) = z redefines z as a symbolic expression and g as a callable symbolic expression:

sage: preparse('g(z) = z')
'__tmp__=var("z"); g = symbolic_expression(z).function(z)'
eric_g gravatar imageeric_g ( 2023-03-04 21:47:25 +0100 )edit

@eric_g: you're right, h(z) = z completely destroys the old meaning of z. I think I might prefer g(z) = ... to raise an error unless I explicitly do var('z') first, but that's not the default behavior.

John Palmieri gravatar imageJohn Palmieri ( 2023-03-04 22:56:18 +0100 )edit

The problem is similar to the one in this question, and amenable to similar answers.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2023-03-05 09:52:03 +0100 )edit

@john-palmieri: I agree, having h(z) = z silently injecting z in the global namespace is not desirable; I guess that this is a kind of convenience feature that was introduced at the beginning of Sage, but the side effects are too severe IMHO.

eric_g gravatar imageeric_g ( 2023-03-05 11:59:16 +0100 )edit

@emmanuel-charpentier: it's too bad that subs works with generators of a polynomial ring but not apparently with the named generator of a function field.

John Palmieri gravatar imageJohn Palmieri ( 2023-03-05 18:17:04 +0100 )edit

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: 2023-03-03 15:24:48 +0100

Seen: 181 times

Last updated: Mar 04 '23