1 | initial version |
Yeah that's quite hacky. Try this instead:
N = 2
R = PolynomialRing(QQ, names=['h_{}'.format(k) for k in range(2*N)] + ['e_{}'.format(k) for k in range(2*N)])
H = R.gens()[0:2*N]
E = R.gens()[2*N:]
M = Matrix(R.fraction_field(), N, lambda i, j: H[i+j]/E[i+j])
Sym = SymmetricFunctions(QQ)
e = Sym.elementary()
h = Sym.homogeneous()
m = Sym.monomial()
he_subs = dict(zip(R.gens(), [h[k] for k in range(2*N)] + [e[k] for k in range(2*N)]))
print m(M.det().numerator().subs(he_subs))
2 | No.2 Revision |
Yeah that's quite hacky. Try this instead:
N = 2
R = PolynomialRing(QQ, names=['h_{}'.format(k) for k in range(2*N)] + ['e_{}'.format(k) for k in range(2*N)])
H = R.gens()[0:2*N]
E = R.gens()[2*N:]
M = Matrix(R.fraction_field(), N, lambda i, j: H[i+j]/E[i+j])
Sym = SymmetricFunctions(QQ)
e = Sym.elementary()
h = Sym.homogeneous()
m = Sym.monomial()
he_subs = dict(zip(R.gens(), [h[k] for k in range(2*N)] + [e[k] for k in range(2*N)]))
print m(M.det().numerator().subs(he_subs))
print(m(M.det().numerator().subs(he_subs)))
A symbolic alternative (basically, a cleaner version of what you did):
N = 4
Sym = SymmetricFunctions(QQ)
e = Sym.elementary()
h = Sym.homogeneous()
m = Sym.monomial()
H = function('H', nargs=1, print_func=lambda self, *args: 'h[{}]'.format(args[0]))
E = function('E', nargs=1, print_func=lambda self, *args: 'e[{}]'.format(args[0]))
M = Matrix(SR, N, lambda i, j: H(i+j)/E(i+j))
print(m(sage_eval(str(M.det().numerator()), locals={'h': h, 'e': e})))