ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 03 Jun 2013 07:00:42 -0500How to store outputs from a function for later usehttp://ask.sagemath.org/question/10176/how-to-store-outputs-from-a-function-for-later-use/My function that I have written to compute the rank of fundamental representations is as follows:
# 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
But now if I call `rankrep` it does not let me store `index` or `deg`, it just prints them. I am wanting to also store the `L` variable I create as these are the weights that give me the desired dimension, and convert from these weights, which make up the highest weight $\Lambda = a_1 \omega_1 + \cdots + a_n \omega_n$ (here $\Lambda$ is the high weight, $\omega_i$ are the fundamental weights). The $\omega_i$ have the form $(1,1,\dots,1,0, \dots, 0)$, and I would like to express my high weight as $(a_1 + \cdots + a_{n-1}, a_2 + \cdots + a_{n-1}, \dots, a_{n-1},0)$. However, since I am only considering one of the $a_i$ nonzero, this vector will look like $(a_i, a_i, \dots, a_i, 0, \dots, 0)$. I would like to store this vector, and then pass it as a partition to a `schur` function `s` that I define in the code.
> How can I store these outputs and format them (i.e., data types, lists, dictionaries, vectors) so that I can then alter them as described and apply my schur function?
Fri, 31 May 2013 04:15:08 -0500http://ask.sagemath.org/question/10176/how-to-store-outputs-from-a-function-for-later-use/Comment by JoshIzzard for <p>My function that I have written to compute the rank of fundamental representations is as follows:</p>
<pre><code># 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
</code></pre>
<p>But now if I call <code>rankrep</code> it does not let me store <code>index</code> or <code>deg</code>, it just prints them. I am wanting to also store the <code>L</code> variable I create as these are the weights that give me the desired dimension, and convert from these weights, which make up the highest weight $Lambda = a_1 \omega_1 + \cdots + a_n \omega_n$ (here $Lambda$ is the high weight, $\omega_i$ are the fundamental weights). The $\omega_i$ have the form $(1,1,\dots,1,0, \dots, 0)$, and I would like to express my high weight as $(a_1 + \cdots + a_{n-1}, a_2 + \cdots + a_{n-1}, \dots, a_{n-1},0)$. However, since I am only considering one of the $a_i$ nonzero, this vector will look like $(a_i, a_i, \dots, a_i, 0, \dots, 0)$. I would like to store this vector, and then pass it as a partition to a <code>schur</code> function <code>s</code> that I define in the code. </p>
<blockquote>
<p>How can I store these outputs and format them (i.e., data types, lists, dictionaries, vectors) so that I can then alter them as described and apply my schur function?</p>
</blockquote>
http://ask.sagemath.org/question/10176/how-to-store-outputs-from-a-function-for-later-use/?comment=17597#post-id-17597Just figured out part of it: `[index, deg, L] = rankrep(3)`Fri, 31 May 2013 04:19:15 -0500http://ask.sagemath.org/question/10176/how-to-store-outputs-from-a-function-for-later-use/?comment=17597#post-id-17597Answer by tmonteil for <p>My function that I have written to compute the rank of fundamental representations is as follows:</p>
<pre><code># 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
</code></pre>
<p>But now if I call <code>rankrep</code> it does not let me store <code>index</code> or <code>deg</code>, it just prints them. I am wanting to also store the <code>L</code> variable I create as these are the weights that give me the desired dimension, and convert from these weights, which make up the highest weight $Lambda = a_1 \omega_1 + \cdots + a_n \omega_n$ (here $Lambda$ is the high weight, $\omega_i$ are the fundamental weights). The $\omega_i$ have the form $(1,1,\dots,1,0, \dots, 0)$, and I would like to express my high weight as $(a_1 + \cdots + a_{n-1}, a_2 + \cdots + a_{n-1}, \dots, a_{n-1},0)$. However, since I am only considering one of the $a_i$ nonzero, this vector will look like $(a_i, a_i, \dots, a_i, 0, \dots, 0)$. I would like to store this vector, and then pass it as a partition to a <code>schur</code> function <code>s</code> that I define in the code. </p>
<blockquote>
<p>How can I store these outputs and format them (i.e., data types, lists, dictionaries, vectors) so that I can then alter them as described and apply my schur function?</p>
</blockquote>
http://ask.sagemath.org/question/10176/how-to-store-outputs-from-a-function-for-later-use/?answer=15000#post-id-15000I am not sure to understand your request, but you can modify the last line of your function to return `L` as well by:
return index, deg, L
And then play with it:
sage: index, deg, L = rankrep(3)
sage: index
['A8(fw[1])', 'A8(fw[8])']
sage: deg
[[2],
[3, 3],
[4, 6, 4],
[5, 10, 10, 5],
[6, 15, 20, 15, 6],
[7, 21, 35, 35, 21, 7],
[8, 28, 56, 70, 56, 28, 8],
[9, 36, 84, 126, 126, 84, 36, 9],
[10, 45, 120, 210, 252, 210, 120, 45, 10]]
sage: deg[3]
[5, 10, 10, 5]
sage: L
[(1, 0, 0, 0, 0, 0, 0, 0, 0), (1, 1, 1, 1, 1, 1, 1, 1, 0)]
To transform the elements of `L` to a list of vectors, you can:
sage: w = [i.to_vector() for i in L]
sage: w[0]
(1, 0, 0, 0, 0, 0, 0, 0, 0)
sage: w[1]
(1, 1, 1, 1, 1, 1, 1, 1, 0)
Fri, 31 May 2013 04:27:23 -0500http://ask.sagemath.org/question/10176/how-to-store-outputs-from-a-function-for-later-use/?answer=15000#post-id-15000Comment by tmonteil for <p>I am not sure to understand your request, but you can modify the last line of your function to return <code>L</code> as well by:</p>
<pre><code>return index, deg, L
</code></pre>
<p>And then play with it:</p>
<pre><code>sage: index, deg, L = rankrep(3)
sage: index
['A8(fw[1])', 'A8(fw[8])']
sage: deg
[[2],
[3, 3],
[4, 6, 4],
[5, 10, 10, 5],
[6, 15, 20, 15, 6],
[7, 21, 35, 35, 21, 7],
[8, 28, 56, 70, 56, 28, 8],
[9, 36, 84, 126, 126, 84, 36, 9],
[10, 45, 120, 210, 252, 210, 120, 45, 10]]
sage: deg[3]
[5, 10, 10, 5]
sage: L
[(1, 0, 0, 0, 0, 0, 0, 0, 0), (1, 1, 1, 1, 1, 1, 1, 1, 0)]
</code></pre>
<p>To transform the elements of <code>L</code> to a list of vectors, you can:</p>
<pre><code>sage: w = [i.to_vector() for i in L]
sage: w[0]
(1, 0, 0, 0, 0, 0, 0, 0, 0)
sage: w[1]
(1, 1, 1, 1, 1, 1, 1, 1, 0)
</code></pre>
http://ask.sagemath.org/question/10176/how-to-store-outputs-from-a-function-for-later-use/?comment=17595#post-id-17595As i defined them, they are vectors:
sage: w[1].parent()
Vector space of dimension 9 over Rational Fiel
You can make them partitions:
sage: Partition(w[1])
[1, 1, 1, 1, 1, 1, 1, 1]
and perhaps
sage: s = SymmetricFunctions(QQ).schur()
sage: s(Partition(w[1]))
s[1, 1, 1, 1, 1, 1, 1, 1]
If you prefer lists, you can:
sage: w[1].list()
[1, 1, 1, 1, 1, 1, 1, 1, 0]
But it seems it leads to the same things:
sage: s(w[1].list()) == s(Partition(w[1]))
True
Of course, you can do everything in one step:
sage: w = [i.to_vector().list() for i in L]
sage: [s(i) for i in w]
[s[1], s[1, 1, 1, 1, 1, 1, 1, 1]]
By the way, i am not expert in Symmetric functions at all, just guessing what your needs are.
Fri, 31 May 2013 05:19:24 -0500http://ask.sagemath.org/question/10176/how-to-store-outputs-from-a-function-for-later-use/?comment=17595#post-id-17595Comment by JoshIzzard for <p>I am not sure to understand your request, but you can modify the last line of your function to return <code>L</code> as well by:</p>
<pre><code>return index, deg, L
</code></pre>
<p>And then play with it:</p>
<pre><code>sage: index, deg, L = rankrep(3)
sage: index
['A8(fw[1])', 'A8(fw[8])']
sage: deg
[[2],
[3, 3],
[4, 6, 4],
[5, 10, 10, 5],
[6, 15, 20, 15, 6],
[7, 21, 35, 35, 21, 7],
[8, 28, 56, 70, 56, 28, 8],
[9, 36, 84, 126, 126, 84, 36, 9],
[10, 45, 120, 210, 252, 210, 120, 45, 10]]
sage: deg[3]
[5, 10, 10, 5]
sage: L
[(1, 0, 0, 0, 0, 0, 0, 0, 0), (1, 1, 1, 1, 1, 1, 1, 1, 0)]
</code></pre>
<p>To transform the elements of <code>L</code> to a list of vectors, you can:</p>
<pre><code>sage: w = [i.to_vector() for i in L]
sage: w[0]
(1, 0, 0, 0, 0, 0, 0, 0, 0)
sage: w[1]
(1, 1, 1, 1, 1, 1, 1, 1, 0)
</code></pre>
http://ask.sagemath.org/question/10176/how-to-store-outputs-from-a-function-for-later-use/?comment=17579#post-id-17579Many thanks @tmontneil, I now understand. Partition is indeed useful to keep in mindMon, 03 Jun 2013 07:00:42 -0500http://ask.sagemath.org/question/10176/how-to-store-outputs-from-a-function-for-later-use/?comment=17579#post-id-17579Comment by JoshIzzard for <p>I am not sure to understand your request, but you can modify the last line of your function to return <code>L</code> as well by:</p>
<pre><code>return index, deg, L
</code></pre>
<p>And then play with it:</p>
<pre><code>sage: index, deg, L = rankrep(3)
sage: index
['A8(fw[1])', 'A8(fw[8])']
sage: deg
[[2],
[3, 3],
[4, 6, 4],
[5, 10, 10, 5],
[6, 15, 20, 15, 6],
[7, 21, 35, 35, 21, 7],
[8, 28, 56, 70, 56, 28, 8],
[9, 36, 84, 126, 126, 84, 36, 9],
[10, 45, 120, 210, 252, 210, 120, 45, 10]]
sage: deg[3]
[5, 10, 10, 5]
sage: L
[(1, 0, 0, 0, 0, 0, 0, 0, 0), (1, 1, 1, 1, 1, 1, 1, 1, 0)]
</code></pre>
<p>To transform the elements of <code>L</code> to a list of vectors, you can:</p>
<pre><code>sage: w = [i.to_vector() for i in L]
sage: w[0]
(1, 0, 0, 0, 0, 0, 0, 0, 0)
sage: w[1]
(1, 1, 1, 1, 1, 1, 1, 1, 0)
</code></pre>
http://ask.sagemath.org/question/10176/how-to-store-outputs-from-a-function-for-later-use/?comment=17596#post-id-17596@tmontneil but will the `w[i]` values now feed into a Schur function? I thought they had to be lists i.e., I think I need `w[0] = [1,0,...,0]` right?Fri, 31 May 2013 04:51:47 -0500http://ask.sagemath.org/question/10176/how-to-store-outputs-from-a-function-for-later-use/?comment=17596#post-id-17596