On Sat, 2026-08-29 at 01:31 -0700, 'Martin R' via sage-devel wrote:
> Perhaps: a variable is something that's allowed on the left hand side of a
> substitution?
I like this a lot for its simplicity, but python's keyword-based
substitution ignores names that are out of scope:
sage: R = PolynomialRing(QQ, 'x')
sage: x = R.gen()
sage: f = 2*x^2 + 7
sage: f(y=12)
2*x^2 + 7
This happens even with the subs() method,
sage: f.subs(y=12)
2*x^2 + 7
If you pass a dist to subs(), the bad name can be caught, but there is
also potential for confusion between the variable name and the (python)
variable that refers to that name. Obviously you should not do this,
but just to illustrate:
sage: R = PolynomialRing(QQ, 'z')
sage: y = R.gen()
sage: f = 2*y^2 + 7
sage: R.variable_names()
('z',)
sage: f.subs({z: 12}) # doesn't work
sage: f.subs({'z': 12}) # neither does this
sage: f.subs({y: 12}) # but this does
295
The variable _name_ isn't what can be passed to subs, only a reference
to the variable itself obtained from R.gen() or a similar method.
We are already fixing methods to make them consistent so none of these
are deal-breakers, but they make the rule a lot less simple even in
what is probably the nicest setting, polynomial rings.