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.Sat, 18 May 2013 10:57:42 -0500How to define multiple WeylCharacterRings at one timehttp://ask.sagemath.org/question/10131/how-to-define-multiple-weylcharacterrings-at-one-time/I am trying to use a script like the one below (to use a simplistic version)
for i in [1..4]:
B"i" = WeylCharacterRing("Bi")
to define multiple Weyl character rings at one time. I then am hoping to go through, and compute the degrees of the representation corresponding to the weight (1,1,1,...,1) depending on which B$i$ I am considering i.e., for $B4$ I would want to calculate
B4(1,1,1,1).degree()
(its $126$). How can I go about automating this in some way? Any tips or reference materials?
Thanks for your time. Fri, 17 May 2013 06:32:51 -0500http://ask.sagemath.org/question/10131/how-to-define-multiple-weylcharacterrings-at-one-time/Answer by niles for <p>I am trying to use a script like the one below (to use a simplistic version)</p>
<pre><code>for i in [1..4]:
B"i" = WeylCharacterRing("Bi")
</code></pre>
<p>to define multiple Weyl character rings at one time. I then am hoping to go through, and compute the degrees of the representation corresponding to the weight (1,1,1,...,1) depending on which B$i$ I am considering i.e., for $B4$ I would want to calculate </p>
<pre><code>B4(1,1,1,1).degree()
</code></pre>
<p>(its $126$). How can I go about automating this in some way? Any tips or reference materials? </p>
<p>Thanks for your time. </p>
http://ask.sagemath.org/question/10131/how-to-define-multiple-weylcharacterrings-at-one-time/?answer=14943#post-id-14943You could define a function or use a [list comprehension](http://docs.python.org/2/tutorial/datastructures.html#list-comprehensions) to do this. Both rely on using [string formatting](http://docs.python.org/2/library/string.html#format-string-syntax) to convert integers into strings for the `WeylCharacterRing` constructor.
Here's an example using list comprehension: I add an empty string `''` at the beginning of the list to fix indexing, because lists in Sage are always indexed starting with `0`, so you would want `B[1]` to be the *second* element in the list, etc.
sage: B = ['']+[WeylCharacterRing("B{0}".format(i)) for i in range(1,5)]
sage: B[1]
The Weyl Character Ring of Type ['B', 1] with Integer Ring coefficients
sage: B[1](1)
B1(0)
sage: B[1](1).degree()
1
sage: B[4](1,1,1,1).degree()
126
And here's a different way you could do this, using a [lambda function](http://www.secnetix.de/olli/Python/lambda_functions.hawk):
sage: B = lambda i: WeylCharacterRing("B{0}".format(i))
sage: B(2)
The Weyl Character Ring of Type ['B', 2] with Integer Ring coefficients
You can automate lots more things by defining more functions and, if you eventually need to, a new [object class](http://docs.python.org/2/tutorial/classes.html)!
Fri, 17 May 2013 08:36:55 -0500http://ask.sagemath.org/question/10131/how-to-define-multiple-weylcharacterrings-at-one-time/?answer=14943#post-id-14943Comment by JoshIzzard for <p>You could define a function or use a <a href="http://docs.python.org/2/tutorial/datastructures.html#list-comprehensions">list comprehension</a> to do this. Both rely on using <a href="http://docs.python.org/2/library/string.html#format-string-syntax">string formatting</a> to convert integers into strings for the <code>WeylCharacterRing</code> constructor.</p>
<p>Here's an example using list comprehension: I add an empty string <code>''</code> at the beginning of the list to fix indexing, because lists in Sage are always indexed starting with <code>0</code>, so you would want <code>B[1]</code> to be the <em>second</em> element in the list, etc.</p>
<pre><code>sage: B = ['']+[WeylCharacterRing("B{0}".format(i)) for i in range(1,5)]
sage: B[1]
The Weyl Character Ring of Type ['B', 1] with Integer Ring coefficients
sage: B[1](1)
B1(0)
sage: B[1](1).degree()
1
sage: B[4](1,1,1,1).degree()
126
</code></pre>
<p>And here's a different way you could do this, using a <a href="http://www.secnetix.de/olli/Python/lambda_functions.hawk">lambda function</a>:</p>
<pre><code>sage: B = lambda i: WeylCharacterRing("B{0}".format(i))
sage: B(2)
The Weyl Character Ring of Type ['B', 2] with Integer Ring coefficients
</code></pre>
<p>You can automate lots more things by defining more functions and, if you eventually need to, a new <a href="http://docs.python.org/2/tutorial/classes.html">object class</a>!</p>
http://ask.sagemath.org/question/10131/how-to-define-multiple-weylcharacterrings-at-one-time/?comment=17671#post-id-17671Thanks very much niles, I appreciate these answers. This is perfect for what I'm looking for. Sat, 18 May 2013 10:56:53 -0500http://ask.sagemath.org/question/10131/how-to-define-multiple-weylcharacterrings-at-one-time/?comment=17671#post-id-17671Answer by niles for <p>I am trying to use a script like the one below (to use a simplistic version)</p>
<pre><code>for i in [1..4]:
B"i" = WeylCharacterRing("Bi")
</code></pre>
<p>to define multiple Weyl character rings at one time. I then am hoping to go through, and compute the degrees of the representation corresponding to the weight (1,1,1,...,1) depending on which B$i$ I am considering i.e., for $B4$ I would want to calculate </p>
<pre><code>B4(1,1,1,1).degree()
</code></pre>
<p>(its $126$). How can I go about automating this in some way? Any tips or reference materials? </p>
<p>Thanks for your time. </p>
http://ask.sagemath.org/question/10131/how-to-define-multiple-weylcharacterrings-at-one-time/?answer=14944#post-id-14944Oh, I think @Volker Braun and I had different ideas about what you were looking for :) Here's another list comprehension which just computes the degrees of various elements (using the lambda function `B` defined in my other answer):
sage: [B(i)(*[1]*i).degree() for i in range(1,5)]
[1, 10, 35, 126]Fri, 17 May 2013 08:42:10 -0500http://ask.sagemath.org/question/10131/how-to-define-multiple-weylcharacterrings-at-one-time/?answer=14944#post-id-14944Answer by Volker Braun for <p>I am trying to use a script like the one below (to use a simplistic version)</p>
<pre><code>for i in [1..4]:
B"i" = WeylCharacterRing("Bi")
</code></pre>
<p>to define multiple Weyl character rings at one time. I then am hoping to go through, and compute the degrees of the representation corresponding to the weight (1,1,1,...,1) depending on which B$i$ I am considering i.e., for $B4$ I would want to calculate </p>
<pre><code>B4(1,1,1,1).degree()
</code></pre>
<p>(its $126$). How can I go about automating this in some way? Any tips or reference materials? </p>
<p>Thanks for your time. </p>
http://ask.sagemath.org/question/10131/how-to-define-multiple-weylcharacterrings-at-one-time/?answer=14942#post-id-14942Looks like you want a combination of `IntegerVectors` and the Python `*` operator to pass a list as multiple arguments:
sage: B4 = WeylCharacterRing('B4', style='coroots')
sage: l = [1,2,0,1]
sage: B4(*l).degree()
24192Fri, 17 May 2013 08:34:30 -0500http://ask.sagemath.org/question/10131/how-to-define-multiple-weylcharacterrings-at-one-time/?answer=14942#post-id-14942Comment by JoshIzzard for <p>Looks like you want a combination of <code>IntegerVectors</code> and the Python <code>*</code> operator to pass a list as multiple arguments:</p>
<pre><code>sage: B4 = WeylCharacterRing('B4', style='coroots')
sage: l = [1,2,0,1]
sage: B4(*l).degree()
24192
</code></pre>
http://ask.sagemath.org/question/10131/how-to-define-multiple-weylcharacterrings-at-one-time/?comment=17670#post-id-17670So that's how to define a vector....ha I am slowly hacking through the Sage basics. Thanks for the answer @VolkerSat, 18 May 2013 10:57:42 -0500http://ask.sagemath.org/question/10131/how-to-define-multiple-weylcharacterrings-at-one-time/?comment=17670#post-id-17670