Ask Your Question

WubbaLubbaDubDub's profile - activity

2019-09-09 05:13:23 -0500 commented answer Determinants of Matrices with Symmetric Functions

Many thanks! Interestingly it seems as though for n = 4 your solution takes an age to finish computing whereas my original solution returns an answer within around 90 minutes (on my not-very-good computer). I'm not sure how much I can really trust my answer though.

2019-09-09 05:13:12 -0500 received badge  Scholar (source)
2019-09-08 12:45:09 -0500 received badge  Student (source)
2019-09-08 10:21:17 -0500 asked a question Determinants of Matrices with Symmetric Functions

I'm interested in calculating the determinant of the matrix $ A = (a_{i+j})$ for $0\leq i,j\leq n$ in which $a_{k} = \frac{h_k}{e_k}$ where $h_k, e_k$ are the homogeneous (elementary, resp.) symmetric functions of degree $k$. I would like to express the numerator of $\det(A)$ in terms of monomial symmetric functions.

I have written some code that I think does the job, but it seems an incredibly hacky way of doing it in my opinion. Since I am quite new to sage I was wondering whether someone might be able to take a look at what I've done and suggest a more sage-like way to tackle this problem? My code is below.

I define a set of functions:

# set up two matrices containing symbolic functions hh(i+j), ee(i+j), which are later replaced with symmetric functions h and e

def heMatrices(N):
    hh = function('hh')
    ee = function('ee')
    H = matrix(SR,N,N,lambda i,j:hh(i+j))
    E = matrix(SR,N,N,lambda i,j:ee(i+j))
    return H,E

# Pointwise divides two matrices (a bit like Hadamard division??)

def elementwiseDivision( M, N ):

    assert( M.parent() == N.parent() )

    nc, nr = M.ncols(), M.nrows()
    A = copy( M.parent().zero() )

    for r in range(nr):
        for c in range(nc):
            A[r,c] = M[r,c] / N[r,c]

    return A

# extracts numerator of determinant

def extractNumerator(M):
    return det(M).numerator()

# extracts denominator of determinant
def extractDenominator(M):
    return det(M).denominator()

# This is dodgy - treates expression as a python string and replaces e(x) with e[x], h(x) with h[x]

def convertToSymmetricString(expr):
    st = str(expr)
    st = st.replace('(','[')
    st = st.replace(')',']')
    st = st.replace('ee','e')
    st = st.replace('hh','h')
    return st

# Puts together the above functions.

def evaluateDeterminant(N):
    h,e = heMatrices(N)
    A = elementwiseDivision(h,e)
    srExpression = extractNumerator(A)
    sageExpression = convertToSymmetricString(srExpression)
    return sageExpression

Then I open sage in the command line and type the following:

sage: Sym = SymmetricFunctions(QQ)                                       
sage: Sym.inject_shorthands(verbose=False)
sage: ee = evaluateDeterminant(2)
sage: ans = sage_eval(ee, locals=vars())
sage: ans = m(ans)

which returns

2*m[2, 1, 1] + 2*m[2, 2] + 2*m[3, 1] + m[4]

which I believe is what I'm after.