0

Consider the following two lines of code:

For t a dictionary, t = {1: (1, 0, 0, 0, 0, 0, 0, 0, 0), 2: (1, 1, 1, 1, 1, 1, 1, 1, 0)}, when I try to do: list(t[1]) to convert the tuple to a list, it gives me the output [(0,1)]. But when I do list(1,0,0,0), it gives me (as it should) [1,0,0,0]. What is going wrong here?

Entire Transcript

# given a prime p, return all A_n representations of dimension = p^2
def rankrep(p):
    bound = p*p
    s = SymmetricFunctions(QQ).schur()
    Sym_p = s[p]
    A = lambda i: WeylCharacterRing("A{0}".format(i))
    deg = []
    index = []
    L = []
    for i in xrange(bound):
        deg.append([])
        fw = A(i+1).fundamental_weights()
        temp = A(i+1)
        for j in fw.keys():
            deg[i].append(temp(fw[j]).degree())
            if temp(fw[j]).degree() == bound:
                index.append('A'+str(i+1)+'(fw['+str(j)+'])')
                L.append(fw[j])
    return index, deg, L
def make_vars2(L):
    return dict(enumerate(L, start=1))

[index, deg, L] = rankrep(3)
t = make_vars2(L)
print(t[1])
print t
list(t[1])

gives me

(1, 0, 0, 0, 0, 0, 0, 0, 0)
{1: (1, 0, 0, 0, 0, 0, 0, 0, 0), 2: (1, 1, 1, 1, 1, 1, 1, 1, 0)}
[(0, 1)]
DSM
  • 342,061
  • 65
  • 592
  • 494
Moderat
  • 1,462
  • 4
  • 17
  • 21
  • @DSM I've added my transcript, that is indeed strange that it works for you. And I'm not sure I understand your second comment i.e., I'm not sure what to type for your "`print list is _builtin_.list`" – Moderat May 31 '13 at 15:22
  • 1
    Thanks for the update -- it makes clear what's going on. Your code is very different than your original example suggested, because `t[1]` isn't a `tuple`, it's an `AmbientSpace_with_category.element_class`. – DSM May 31 '13 at 15:25

1 Answers1

1

Even though your t looks like it's a dictionary with integer keys and tuples of integer values, that's not what it is:

sage: t
{1: (1, 0, 0, 0, 0, 0, 0, 0, 0), 2: (1, 1, 1, 1, 1, 1, 1, 1, 0)}
sage: map(type, t)
[int, int]
sage: map(type, t.values())
[sage.combinat.root_system.ambient_space.AmbientSpace_with_category.element_class,
 sage.combinat.root_system.ambient_space.AmbientSpace_with_category.element_class]
sage: parent(t[1])
Ambient space of the Root system of type ['A', 8]

If you want to get at the vector of coefficients, you can use .to_vector(). For example, we have

sage: t[1]
(1, 0, 0, 0, 0, 0, 0, 0, 0)
sage: type(t[1])
<class 'sage.combinat.root_system.ambient_space.AmbientSpace_with_category.element_class'>
sage: list(t[1])
[(0, 1)]

but

sage: t[1].to_vector()
(1, 0, 0, 0, 0, 0, 0, 0, 0)
sage: type(t[1].to_vector())
<type 'sage.modules.vector_rational_dense.Vector_rational_dense'>
sage: list(t[1].to_vector())
[1, 0, 0, 0, 0, 0, 0, 0, 0]
DSM
  • 342,061
  • 65
  • 592
  • 494