1 | initial version |
I think the .operands() method should do what you want:
sage: var('z,t')
(z, t)
sage: f = function('u',z,t)
sage: f.variables()
(t, z)
sage: f.operands()
[z, t]
We should probably add a reference to operands() in variables()/arguments(). Interested in working up a documentation patch?
We can sanity-check this using a variant of jdc's suggestion:
import random as rnd
def test_one(f):
ops = f.operands()
fops = list(str(op) for op in ops)
sf = str(f)
sops = sf[sf.find('(')+1:sf.find(')')].split(',')
sops = list(sop.strip() for sop in sops)
assert fops == sops
def test_lots():
for c in range(50):
for w in range(1,10):
vv = tuple(var(rnd.choice(string.ascii_letters) + str(randint(0,10))) for _ in range(w))
f = function(*(('u',) + vv))
print f
test_one(f)
return 'hooray!'
produces
sage: test_lots()
[...]
u(J8)
u(H5, M5)
u(g7, H1, B5)
u(f5, I2, i0, A10)
u(c4, B0, i5, g4, T0)
u(e6, R9, B0, T9, i6, n8)
u(T0, V5, c10, T5, X7, B9, Y4)
u(F8, d9, j6, k10, U0, r6, I10, p3)
u(V5, Q10, z6, n10, V6, f3, J7, o4, F0)
'hooray!'
2 | No.2 Revision |
I think the .operands() method should do what you want:
sage: var('z,t')
(z, t)
sage: f = function('u',z,t)
sage: f.variables()
(t, z)
sage: f.operands()
[z, t]
We should probably add a reference to operands() in variables()/arguments(). Interested in working up a documentation patch?
We can sanity-check this using a variant of jdc's suggestion:
import string
import random as rnd
def test_one(f):
ops = f.operands()
fops = list(str(op) for op in ops)
sf = str(f)
sops = sf[sf.find('(')+1:sf.find(')')].split(',')
sops = list(sop.strip() for sop in sops)
assert fops == sops
def test_lots():
for c in range(50):
for w in range(1,10):
vv = tuple(var(rnd.choice(string.ascii_letters) + str(randint(0,10))) for _ in range(w))
f = function(*(('u',) + vv))
print f
test_one(f)
return 'hooray!'
produces
sage: test_lots()
[...]
u(J8)
u(H5, M5)
u(g7, H1, B5)
u(f5, I2, i0, A10)
u(c4, B0, i5, g4, T0)
u(e6, R9, B0, T9, i6, n8)
u(T0, V5, c10, T5, X7, B9, Y4)
u(F8, d9, j6, k10, U0, r6, I10, p3)
u(V5, Q10, z6, n10, V6, f3, J7, o4, F0)
'hooray!'