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.Mon, 05 Aug 2019 17:29:55 +0200Substituting symbolic expressions for mixed differential forms.https://ask.sagemath.org/question/47397/substituting-symbolic-expressions-for-mixed-differential-forms/I'm doing some computations with matrices differential forms, and the run times are extremely long. So in an attempt to
keep run times down, I'm attempting to do matrix computations with symbolic terms, and then later replacing them with the mixed forms I want.
However, there's the coercion from mixed forms into the symbolic ring, and this is presenting a problem for me.
As a toy example of what I'm trying to do, I have the set up (say)
Sage: p=1
Sage: q=2
Sage: M = Manifold((2*p*q), 'M', field='complex')
Sage: U = M.open_subset('U')
Sage: x = U.chart(names=tuple('x_%d' % i for i in range(2*p*q)))
Sage: eU = x.frame()
Sage: d = [M.diff_form(1) for i in range(q)]
Sage: for i in range(q):
Sage: d[i][i] = x[i]
Sage: D = [M.mixed_form(comp=([0, d[i], 0, 0, 0])) for i in range(q)]
Sage: c = {(i): var("c_{}".format(i)) for i in range(q)}
Sage: exp = 0
Sage: for i in range(q):
Sage: for j in range(q):
Sage: exp = exp + c[i]*c[j]
Now, in my actual project I will have many of these variables, so it's not feasible to manually type them into one substitution at once, so I need to do it with a for loop, so I try
Sage: for i in range(q):
Sage: exp.subs({c[i] : D[i]})
But this is where I get the coercion error.
As mentioned, the actual computations I'm dealing with involve large matrices of mixed forms, and the run times would be WAY shorter if I can do it all in symbolic matrices, and then transfer the expressions I get out (which come from taking a trace). How might I be able to achieve this? sum8tionMon, 05 Aug 2019 17:29:55 +0200https://ask.sagemath.org/question/47397/