Ask Your Question

joakim_uhlin's profile - activity

2023-08-04 15:11:29 +0200 received badge  Popular Question (source)
2021-10-26 07:50:47 +0200 received badge  Popular Question (source)
2021-04-10 17:44:32 +0200 received badge  Popular Question (source)
2021-01-22 21:36:14 +0200 received badge  Enthusiast
2021-01-21 18:37:15 +0200 answered a question Issues with Reed-Solomon encoder

Based on the help I got from FrédéricC and slelievre, I managed to create the following encoder-decoder:

F.<a> = GF(8,name='a',modulus=x^3+x+1)
Fx.<x> = F[]
C = codes.ReedSolomonCode(F, 7, 3)
E = C.encoder('EvaluationPolynomial')
M = E.message_space()
D = C.decoder('BerlekampWelch')

pa = Fx(a)
p0 = Fx.zero()
p1 = Fx.one()

m = M.random_element()
n = E.encode(m)
o = D.decode_to_message(n);
print(m)
print(o)
2021-01-21 17:03:57 +0200 commented answer Issues with Reed-Solomon encoder

I realized the code I suggested using in the above comment does not work - it seems to set $a=x$, which is not what I intended.

2021-01-21 17:03:57 +0200 received badge  Commentator
2021-01-21 10:31:32 +0200 answered a question Issues with Reed-Solomon encoder

FrédéricC's answer works for what I wanted to do! One can just write E.encode(Fx(a)) instead of what I initially did. I tried to look for a way to avoid needing to use Fx however. The following works

F = GF(8,name='a',modulus=x^3+x+1)
Fx.<x> = F[]
Fa.<a> = Fx

but I still get issues if I write E.encode(1) or E.encode(0). There is a NotImplementedError in this case. If one writes E.encode(Fx(1)) or E.encode(Fx(0)), this is circumvented.

2021-01-20 15:44:24 +0200 asked a question Issues with Reed-Solomon encoder

I am trying out the Reed-Solomon encoder in Sage and I have found it to exhibit a curious behavior. I first create an encoder for a $(7,3)$-Reed Solomon code as follows

sage: F.<a> = GF(8,name='a',modulus=x^3+x+1)
....: Fx.<x> = F[]
....: C = codes.ReedSolomonCode(F, 7, 3)
....: E = C.encoder("EvaluationPolynomial")

Now I can write

sage: E.encode(x)
(1, a, a^2, a + 1, a^2 + a, a^2 + a + 1, a^2 + 1)

Or

sage: E.encode(a*x^0+a^2*x+x^2)
(a^2 + a + 1, a^2 + 1, a, 0, a^2 + 1, 0, a^2 + a + 1)

But I get when I write the following

sage: E.encode(a)

I get the following error

"AttributeError: 'sage.rings.finite_rings.element_givaro.FiniteField_givaroElement' object has no attribute 'degree'"

If I instead write

sage: E.encode(a*x^0)

Everything works as intended. Is this how it is supposed to work? Does one always need an "$x$" to be part of a term, even when one actually has a constant term? Is there a better way to do it?

2021-01-18 10:26:26 +0200 received badge  Famous Question (source)
2020-04-23 17:02:31 +0200 received badge  Notable Question (source)
2019-11-08 18:06:58 +0200 received badge  Self-Learner (source)
2019-11-08 18:06:58 +0200 received badge  Necromancer (source)
2019-11-08 15:33:24 +0200 received badge  Popular Question (source)
2019-11-08 15:28:59 +0200 marked best answer Major index of skew-SYT

For a standard Young tableaux (SYT), I can compute the major index as follows:

T = Tableau([[1,2,3],[4,5]])
T.major_index()

Is there a way to compute the major index of a skew-SYT currently? Something like:

S = SkewTableaux().from_expr([[1,1],[[5],[3,4],[1,2]]])
S.major_index()

At the moment, it seems major_index() is not defined for the SkewTableau-class.

EDIT: The major index of a (skew) standard Young tableau $T$, denoted $\mathrm{maj}(T)$, is defined as follows. A descent of $T$ is an entry $i$ such that $i+1$ appears strictly below $i$ in $T$. Define $\mathrm{maj}(T)$ as the sum of all descents of $T$. For example, the major index of the skew standard Young tableau above is $2+4=6$.

FindStat has a definition, although they only define it for non-skew tableau. But the definition extends trivially to skew-shapes as well.

2019-11-08 15:28:53 +0200 answered a question Major index of skew-SYT

I decided to finally write this myself! Posting here as an answer for anyone that is interested. I decided to use the built-in SemistandardSkewTableaux class instead of the SkewTableaux class as it seems that the latter does not have a ''.list()'' method. It would also be easy to modify this code to make it work on more general skew SSYT.

def des(T):
    out = []
    for i in range(1,T.size()):
        if T.cells_containing(i)[0][0]<T.cells_containing(i+1)[0][0]:
            out += [i]
    return out

def maj(T):
    return sum(des(T))

def majpol(lmbda,mu):
    var('q')
    out = 0
    for T in SemistandardSkewTableaux([lmbda,mu],[1]*(sum(lmbda)-sum(mu))):
        out += q**maj(T)
    return out

So one can write for example

lmbda = [3,2]
mu = [1]
majpol(lmbda,mu)

which outputs

q^4 + q^3 + 2*q^2 + q
2019-11-05 20:04:48 +0200 commented question How to create 31-tuples with nonnegative entries that sum to 1

There are infinitely many such tuples if you do not pose additional constraints.As an example, note that $(1/n, 1-1/n,0,0, \dots, 0)$ is such a tuple for every positive integer $n$.

2019-09-22 18:16:36 +0200 commented answer Defining q-binomial coefficients $\binom{n}{k}_q$ symbolic in $n, k$

I will take a look at the documentation and try to make sense of it. What I am really looking for is a way to verify an identity of the form RHS(q,n,k)=LHS(q,n,k), involving some q-binomial coefficients that depend on n and k. Something like the q-binomial theorem. It seems to me that evalf_func evaluates a function numerically, so I could only confirm the identity for many values of q, n, k which is not exactly what I want.

2019-09-21 16:37:29 +0200 asked a question Defining q-binomial coefficients $\binom{n}{k}_q$ symbolic in $n, k$

I would like to verify certain identities involving sums of $q$-binomial coefficients $\binom{n}{k}_q$ and as such, I would like to treat the $q$-binomial coefficients as if they were symbolic in $n$ and $k$. But the version of $q$-binomial coefficients that are implemented in Sage cannot be used as a symbolic variable in $n$ and $k$ according to this thread. So, to this end I defined my own:

var('q,n,k')
qint = lambda n: sum([q^i for i in range(n)]) 
qfac = lambda n: 1 if n==0 else prod([qint(i) for i in range(1,n+1)])
qbin = lambda n,k:qfac(n)/(qfac(k)*qfac(n-k))

But if I write

sum(qbin(n,k),k,0,n)

I get the following error:

ValueError: cannot convert n + 1 to int

Is there a way to do these types of summations in Sage? I should note that, for my purposes, it would be enough to limit myself to the case when $n$ and $k$ are non-negative integers.

EDIT: As an example, I would like to prove something like the $q$-binomial theorem, which says

$$\sum_{k=0}^n q^{k(k-1)/2} \binom{n}{k}_q x^k = \prod_{k=0}^{n-1} (1+q^k x)$$

EDIT2: Fixed a typo.

2019-09-21 13:44:17 +0200 answered a question Weak positivity

It is obvious that $x \geq 0$ if and only if it is not the case that $x<0$. So, we can write

not(x.is_negative())
2019-08-30 20:05:52 +0200 commented answer How did simplify_full() manipulate this expression?

Right. As the expression obtained by writing "(LHS(n,k)-RHS(n,k)).simplify_factorial()" is quite horrible, I suspect that Sage will not be able to give me any good insight into how to prove this equality.

2019-08-30 17:48:04 +0200 asked a question How did simplify_full() manipulate this expression?

This is sort of a follow up to a previous question of mine: https://ask.sagemath.org/question/475...

I wanted to prove a certain combinatorial equality. Now, to prove this identity in Sage, I can define the two function $\text{LHS}(n,k)$ and $\text{RHS}(n,k)$ representing the left- and righthand side and make sure that $\text{LHS}(n,k)-\text{RHS}(n,k)=0$ with the following code (actually the code provides a proof of a slightly more general identity, which holds for other values of $n, k$ as well.):

var('n k')

def LHS(n,k):
    return n/2*(
        (n/2+1-k)/(n/2+1)*((n/2+1)/(k/2)*binomial(n/2-3,k-4)*2**(n/2-k+1)*1/(k/2-1)*binomial(k-4,k/2-2))+
        2*(k/2+1)/(n/2+1)*((n/2+1)/(k/2+1)*binomial(n/2-3,k-2)*2**(n/2-k-1)*1/(k/2)*binomial(k-2,k/2-1)))

def RHS(n,k):
    return (n/k)*(2**(n/2-k))*binomial(n/2-2,k-2)*binomial(k-2,k/2-1)

(LHS(n,k)-RHS(n,k)).simplify_full()

This outputs

0

which is what I want but I would like to prove this identity with pen-and-paper and this seems to be a bit tricky. I wonder if there is a way to see how exactly simplify_full() were able simplify the expressions?

2019-08-20 23:38:35 +0200 commented answer Checking identity of two combinatorial expressions

Thank you for your answer. I am still interested in the second question but if I get no other replies, I will accept your answer.

2019-08-20 23:36:07 +0200 commented answer Checking identity of two combinatorial expressions

I am currently using 8.3, using the notebook if that is of any relevance.

2019-08-20 22:42:42 +0200 asked a question Checking identity of two combinatorial expressions

I have a reason to believe that a certain combinatorial identity holds for even integers $n, k$ that satisfies $2 \leq k \leq n/2$ and $n\geq 4$. To test it in Sage, I denote the expression on the right- and lefthandside as the functions RHS$(n,k)$ and LHS$(n,k)$ respectively and check if they agree for a variety of values $n$ and $k$.

def t(n,k):
    sum=0
    for i in range(n-2*k+1):
        sum+=binomial(n-2*k,i)
    return n/k*sum*binomial(n-4,2*k-4)*catalan_number(k-2)

def LHS(n,k):
    return n/2*((n/2+1-k)/(n/2+1)*t(n/2+1,k/2)+2*(k/2+1)/(n/2+1)*t(n/2+1,k/2+1))

def RHS(n,k):
    return (n/k)*(2**(n/2-k))*binomial(n/2-2,k-2)*binomial(k-2,k/2-1)

But when run the following code

for n in range(6,12,2):
    for k in range(2,floor(n/2)+1,2):
        print("n="+str(n)+", k="+str(k))
        print(bool(LHS(n,k)==RHS(n,k)))

I get the output

n=6, k=2
True
n=8, k=2
True
n=8, k=4
True
n=10, k=2
True
n=10, k=4
False

which would indicate that the identity does not hold for $n=10$, $k=4$. However, when I write

print(bool(LHS(10,4)==RHS(10,4)))

I get the output TRUE (I also double checked this by hand, and both sides agree and are equal to $30$ in this case).

  1. Why does the code in the double loop yield the wrong answer? EDIT: answered by rburing

  2. Is there a better way to check equalities similar to this in Sage?

2019-04-14 00:01:48 +0200 received badge  Nice Question (source)
2019-04-14 00:01:34 +0200 received badge  Nice Answer (source)
2019-04-11 16:03:45 +0200 marked best answer Constructing all NE-lattice paths from $(0,0)$ to $(m,n)$

If I consider only Dyck Paths, I can do write something like this:

DWS=DyckWords(3).list()
for D in DWS:
    print(D.height())

to obtain the height of all Dyck paths of length $3$. However, I would like to do the same thing but using $NE$-lattice paths from $(0,0)$ to $(m,n)$. Is there an easy way to do this in Sage?

2019-04-11 16:03:45 +0200 received badge  Self-Learner (source)
2019-04-11 16:03:45 +0200 received badge  Teacher (source)
2019-04-11 15:42:34 +0200 marked best answer Setting t=0 in a non-symmetric E-Macdonald polynomial

Suppose I have a non-symmetric E-Macdonald polynomial indexed by, say, $\mu=(0,1,1)$. Then I can write

from sage.combinat.sf.ns_macdonald import E
E([0,1,1])

and I get a polynomial in three variables and with coefficients in $\mathbb{Q}(q,t)$:

((-t + 1)/(-q*t + 1))*x0*x1 + ((-t + 1)/(-q*t + 1))*x0*x2 + x1*x2

However, I am confused about how I can work with this polynomial. For my purposes, I would like to study the specialization $t=0$. It would be really neat if there were some way to get write something like

Epoly(x_0,x_1,x_2,q,t) =...

so I could easily specialize variables as I go along.