What is a variable?

124 views
Skip to first unread message

Michael Orlitzky

unread,
Aug 27, 2026, 12:00:53 PMAug 27
to sage-...@googlegroups.com
Rings have several methods that refer to "variables" and their names,

* R.variable_name()
* R.variable_names()
* R.variable_names_recursive()
* R._assign_names()
* R._names
* sage.structure.category_object.normalize_names()

In https://github.com/sagemath/sage/pull/40518 we made
R.variable_names() return the empty tuple for R in [ZZ,QQ,AA]. It
seems reasonable to do the same for GF(p) and Zmod(n) which still
return ('x',).

But then we have examples like,

sage: CC.variable_names()
('I',)

Is this correct? It depends on the definition of "variable." If I were
to make one up on the spot, I would limit it to the usual polynomial
sense, i.e. we can adjoin 'X' to the reals and call it a variable, but
imposing the relation X^2 = -1 goes too far. And before we adjoin it,
'X' is not the name of a "variable to be." (It's possible to intrepret
these lightly documented methods as a list of names that would be used
to construct a polynomial ring -- requiring a name -- out of a base
ring.)

There may be unintended consequences to whatever we choose. Is anyone
aware of an existing consistent (non ad-hoc) approach?

Martin R

unread,
Aug 29, 2026, 4:31:15 AMAug 29
to sage-devel
Perhaps: a variable is something that's allowed on the left hand side of a substitution?

Martin

Michael Orlitzky

unread,
Aug 31, 2026, 12:34:21 PMAug 31
to sage-...@googlegroups.com
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.

Martin R

unread,
Sep 1, 2026, 4:20:49 AMSep 1
to sage-devel
I think that (ab)using keyword syntax for substitution is morally wrong.

Michael Orlitzky

unread,
Sep 3, 2026, 5:20:35 PMSep 3
to 'Martin R' via sage-devel
On 2026-09-01 01:20:49, 'Martin R' via sage-devel wrote:
> I think that (ab)using keyword syntax for substitution is morally wrong.

We have to live with this though, don't we? In python, the keyword
syntax performs "variable" substitution within the body of a function:

>>> f = lambda x: 3*x
>>> f(x=10)
30

"Variable" has a broader meaning in this context, but it's not obvious
(for the sake of the user interface and documentation) how the x above
differs from the x in the polynomial 3*x. If we are to disallow
substitutions in the lambda-calculus sense, then we have a problem at
level n+1: what is a substitition?

So long as no one puts forth a proposal that would make 'I' a variable
in CC, we can however proceed to clean up the existing variable lists.
Reply all
Reply to author
Forward
0 new messages