ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 31 May 2017 22:56:10 +0200Getting the denominator takes ages...https://ask.sagemath.org/question/37750/getting-the-denominator-takes-ages/Hi,
I am trying to run the following code (I am including the full code, this is about representation theory but my question is much simpler):
B2 = WeylCharacterRing(['B', 2])
b2 = WeightRing(B2)
Weyl = B2(2, 2)
l = B2.rank()
z = [var('z0')]
for k in range(1, l):
z.append(var('z' + str(k)))
u = var('u')
def toPoly(v):
return prod([z[k]^v[k] for k in range(0, l)])
Molien = 1
W = Weyl.weight_multiplicities()
for w in W:
T = toPoly(-w)
Molien *= 1/(1-u*T)^W[w]
Molien = factor(Molien)
WeylDenom = prod(1-toPoly(-alpha) for alpha in b2.positive_roots())
MolienInt = factor(Molien*WeylDenom/prod(z[k] for k in range(0, l)))
DEN = MolienInt.denominator()
(...)
Everything works fine except for the very last line that seems to run forever. Yet it is pretty straightforward to get the denominator of **MolienInt**.
I made some tests using **PolynomialRing** but it also seems not to end and has also the drawback that the denominator is expanded while I need it to remain factored.
Can you help me?Wed, 31 May 2017 17:10:20 +0200https://ask.sagemath.org/question/37750/getting-the-denominator-takes-ages/Answer by dan_fulea for <p>Hi,</p>
<p>I am trying to run the following code (I am including the full code, this is about representation theory but my question is much simpler):</p>
<pre><code>B2 = WeylCharacterRing(['B', 2])
b2 = WeightRing(B2)
Weyl = B2(2, 2)
l = B2.rank()
z = [var('z0')]
for k in range(1, l):
z.append(var('z' + str(k)))
u = var('u')
def toPoly(v):
return prod([z[k]^v[k] for k in range(0, l)])
Molien = 1
W = Weyl.weight_multiplicities()
for w in W:
T = toPoly(-w)
Molien *= 1/(1-u*T)^W[w]
Molien = factor(Molien)
WeylDenom = prod(1-toPoly(-alpha) for alpha in b2.positive_roots())
MolienInt = factor(Molien*WeylDenom/prod(z[k] for k in range(0, l)))
DEN = MolienInt.denominator()
(...)
</code></pre>
<p>Everything works fine except for the very last line that seems to run forever. Yet it is pretty straightforward to get the denominator of <strong>MolienInt</strong>.</p>
<p>I made some tests using <strong>PolynomialRing</strong> but it also seems not to end and has also the drawback that the denominator is expanded while I need it to remain factored.</p>
<p>Can you help me?</p>
https://ask.sagemath.org/question/37750/getting-the-denominator-takes-ages/?answer=37751#post-id-37751Getting the denominator takes sage...
# rootType = 'B2'
# weight = (2,2)
rootType = 'B3'
weight = (3,3,3)
# the rootType is e.g. 'B2', or ['B', 2], or RootSystem('B2')
# The weight is a corresponding dominant weight...
B = WeylCharacterRing( rootType )
b = WeightRing( B )
bpr = b.positive_roots()
Weyl = B( weight )
W = Weyl.weight_multiplicities()
r = B.rank()
print "%s :: rank=%s weight=%s" % (rootType, r, weight)
R = range(r)
names = [ 'z%s' % k for k in R ] + [ 'u', ]
ring = PolynomialRing( QQ, names=names )
gens = ring.gens()
z = gens[:-1]
u = gens[-1]
def denomPart( z, u, w ):
"""z, v should be a vectors of length r..."""
return ( prod( [ z[k]^( - w[k] ) for k in R if w[k] < 0 ] )
- u * prod( [ z[k]^ w[k] for k in R if w[k] > 0 ] ) )
def nomPart( z, u, w ):
"""z, v should be a vectors of length r..."""
return ( prod( [ z[k]^( - w[k] ) for k in R if w[k] < 0 ] ) )
MolienDenom = Factorization( [ ( denomPart( z, u, -w ), W[w] ) for w in W ], cr=True )
MolienNom = Factorization( [ ( nomPart( z, u, -w ), W[w] ) for w in W ], cr=True )
WeylDenom = Factorization( [ ( denomPart( z, 1, -w ), W[w] ) for w in bpr ], cr=True )
WeylNom = Factorization( [ ( nomPart( z, 1, -w ), W[w] ) for w in bpr ], cr=True )
DEN = MolienDenom \
* WeylDenom \
* ( MolienNom * WeylNom / prod( z ) ).value().denominator().factor()
# print DEN # this is not humanly readable
print "DEN has the following factors:"
for f in DEN:
print f
...not too much time, if we isolate and use the factorization we have.
Note: The main improvement is to not expand, than (re)factor.
(Since there are too many terms to be recollected after expansion.)
This is obtained by explicitly using the `Factorization` constructor. The code was carefully typed, hope that the denominator contribution from the original post were correctly collected. The code was typed so that it is easy to isolate a function `getDen( rootType, weight )` .
The `DEN` may have no contribution from the third factor (which is a monomial in the `z` components.)
Since the complexity of `DEN` grows with the one of `W`, the results are omitted.
Wed, 31 May 2017 21:41:56 +0200https://ask.sagemath.org/question/37750/getting-the-denominator-takes-ages/?answer=37751#post-id-37751Comment by Roro for <p>Getting the denominator takes sage...</p>
<pre><code># rootType = 'B2'
# weight = (2,2)
rootType = 'B3'
weight = (3,3,3)
# the rootType is e.g. 'B2', or ['B', 2], or RootSystem('B2')
# The weight is a corresponding dominant weight...
B = WeylCharacterRing( rootType )
b = WeightRing( B )
bpr = b.positive_roots()
Weyl = B( weight )
W = Weyl.weight_multiplicities()
r = B.rank()
print "%s :: rank=%s weight=%s" % (rootType, r, weight)
R = range(r)
names = [ 'z%s' % k for k in R ] + [ 'u', ]
ring = PolynomialRing( QQ, names=names )
gens = ring.gens()
z = gens[:-1]
u = gens[-1]
def denomPart( z, u, w ):
"""z, v should be a vectors of length r..."""
return ( prod( [ z[k]^( - w[k] ) for k in R if w[k] < 0 ] )
- u * prod( [ z[k]^ w[k] for k in R if w[k] > 0 ] ) )
def nomPart( z, u, w ):
"""z, v should be a vectors of length r..."""
return ( prod( [ z[k]^( - w[k] ) for k in R if w[k] < 0 ] ) )
MolienDenom = Factorization( [ ( denomPart( z, u, -w ), W[w] ) for w in W ], cr=True )
MolienNom = Factorization( [ ( nomPart( z, u, -w ), W[w] ) for w in W ], cr=True )
WeylDenom = Factorization( [ ( denomPart( z, 1, -w ), W[w] ) for w in bpr ], cr=True )
WeylNom = Factorization( [ ( nomPart( z, 1, -w ), W[w] ) for w in bpr ], cr=True )
DEN = MolienDenom \
* WeylDenom \
* ( MolienNom * WeylNom / prod( z ) ).value().denominator().factor()
# print DEN # this is not humanly readable
print "DEN has the following factors:"
for f in DEN:
print f
</code></pre>
<p>...not too much time, if we isolate and use the factorization we have.</p>
<p>Note: The main improvement is to not expand, than (re)factor. </p>
<p>(Since there are too many terms to be recollected after expansion.) </p>
<p>This is obtained by explicitly using the <code>Factorization</code> constructor. The code was carefully typed, hope that the denominator contribution from the original post were correctly collected. The code was typed so that it is easy to isolate a function <code>getDen( rootType, weight )</code> .</p>
<p>The <code>DEN</code> may have no contribution from the third factor (which is a monomial in the <code>z</code> components.)
Since the complexity of <code>DEN</code> grows with the one of <code>W</code>, the results are omitted.</p>
https://ask.sagemath.org/question/37750/getting-the-denominator-takes-ages/?comment=37753#post-id-37753This solution also works:
DEN = prod(d.denominator() for d in list(MolienInt.op))Wed, 31 May 2017 22:56:10 +0200https://ask.sagemath.org/question/37750/getting-the-denominator-takes-ages/?comment=37753#post-id-37753Comment by Roro for <p>Getting the denominator takes sage...</p>
<pre><code># rootType = 'B2'
# weight = (2,2)
rootType = 'B3'
weight = (3,3,3)
# the rootType is e.g. 'B2', or ['B', 2], or RootSystem('B2')
# The weight is a corresponding dominant weight...
B = WeylCharacterRing( rootType )
b = WeightRing( B )
bpr = b.positive_roots()
Weyl = B( weight )
W = Weyl.weight_multiplicities()
r = B.rank()
print "%s :: rank=%s weight=%s" % (rootType, r, weight)
R = range(r)
names = [ 'z%s' % k for k in R ] + [ 'u', ]
ring = PolynomialRing( QQ, names=names )
gens = ring.gens()
z = gens[:-1]
u = gens[-1]
def denomPart( z, u, w ):
"""z, v should be a vectors of length r..."""
return ( prod( [ z[k]^( - w[k] ) for k in R if w[k] < 0 ] )
- u * prod( [ z[k]^ w[k] for k in R if w[k] > 0 ] ) )
def nomPart( z, u, w ):
"""z, v should be a vectors of length r..."""
return ( prod( [ z[k]^( - w[k] ) for k in R if w[k] < 0 ] ) )
MolienDenom = Factorization( [ ( denomPart( z, u, -w ), W[w] ) for w in W ], cr=True )
MolienNom = Factorization( [ ( nomPart( z, u, -w ), W[w] ) for w in W ], cr=True )
WeylDenom = Factorization( [ ( denomPart( z, 1, -w ), W[w] ) for w in bpr ], cr=True )
WeylNom = Factorization( [ ( nomPart( z, 1, -w ), W[w] ) for w in bpr ], cr=True )
DEN = MolienDenom \
* WeylDenom \
* ( MolienNom * WeylNom / prod( z ) ).value().denominator().factor()
# print DEN # this is not humanly readable
print "DEN has the following factors:"
for f in DEN:
print f
</code></pre>
<p>...not too much time, if we isolate and use the factorization we have.</p>
<p>Note: The main improvement is to not expand, than (re)factor. </p>
<p>(Since there are too many terms to be recollected after expansion.) </p>
<p>This is obtained by explicitly using the <code>Factorization</code> constructor. The code was carefully typed, hope that the denominator contribution from the original post were correctly collected. The code was typed so that it is easy to isolate a function <code>getDen( rootType, weight )</code> .</p>
<p>The <code>DEN</code> may have no contribution from the third factor (which is a monomial in the <code>z</code> components.)
Since the complexity of <code>DEN</code> grows with the one of <code>W</code>, the results are omitted.</p>
https://ask.sagemath.org/question/37750/getting-the-denominator-takes-ages/?comment=37752#post-id-37752Wow! Once again I thank you very much!
I will hopefully try this code tomorrow.Wed, 31 May 2017 22:43:10 +0200https://ask.sagemath.org/question/37750/getting-the-denominator-takes-ages/?comment=37752#post-id-37752