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.Thu, 22 Aug 2019 22:18:04 +0200Setting the components of a differential form systematically.https://ask.sagemath.org/question/47567/setting-the-components-of-a-differential-form-systematically/ Suppose for some p and q we have a manifold
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()
and some differential forms
Sage: d = {(i): var("d_{}".format(i)) for i in range(2*p*q)}
Sage: for i in range(2*p*q):
Sage: d[i] = M.diff_form(i)
I want to construct and/or inspect components of these differential forms in a systematic way, which is to say I want to be able to iterate over the components. So for example, one way in which I've tried to do this is to create lists.
For example, if we let
Sage: R = [eU, 0, 1]
I would want to say
Sage: d[2]R = 1
but this gives me a syntax error.
I've also tried something like
Sage: S = [0, 1]
Sage: d[2][eU, :]S = 1
but again I get a syntax error.
Thu, 22 Aug 2019 16:13:05 +0200https://ask.sagemath.org/question/47567/setting-the-components-of-a-differential-form-systematically/Answer by eric_g for <p>Suppose for some p and q we have a manifold</p>
<pre><code>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()
</code></pre>
<p>and some differential forms</p>
<pre><code>Sage: d = {(i): var("d_{}".format(i)) for i in range(2*p*q)}
Sage: for i in range(2*p*q):
Sage: d[i] = M.diff_form(i)
</code></pre>
<p>I want to construct and/or inspect components of these differential forms in a systematic way, which is to say I want to be able to iterate over the components. So for example, one way in which I've tried to do this is to create lists. <br>
For example, if we let </p>
<pre><code>Sage: R = [eU, 0, 1]
</code></pre>
<p>I would want to say</p>
<pre><code>Sage: d[2]R = 1
</code></pre>
<p>but this gives me a syntax error. <br>
I've also tried something like </p>
<pre><code>Sage: S = [0, 1]
Sage: d[2][eU, :]S = 1
</code></pre>
<p>but again I get a syntax error. </p>
https://ask.sagemath.org/question/47567/setting-the-components-of-a-differential-form-systematically/?answer=47569#post-id-47569You should write
sage: d[2][R] = 1
Indeed, when `R` is the list `[eU, 0, 1]`, as in your example, the above is equivalent to
sage: d[2][eU, 0, 1] = 1
***Side note:*** in your example, the line
sage: d = {(i): var("d_{}".format(i)) for i in range(2*p*q)}
is useless, because the elements of the dictionary `d` are fully redefined in the two lines that follow:
sage: for i in range(2*p*q):
sage: d[i] = M.diff_form(i)
If you want to give names to the differential forms `d[i]`, you could write simply
sage: d = {i: M.diff_form(i, name="d_{}".format(i)) for i in range(2*p*q)}
Then
sage: d[2]
2-form d_2 on the 4-dimensional complex manifold M
sage: R = [eU, 0, 1]
sage: d[2][R] = 1
sage: d[2].display()
d_2 = dx_0/\dx_1Thu, 22 Aug 2019 22:18:04 +0200https://ask.sagemath.org/question/47567/setting-the-components-of-a-differential-form-systematically/?answer=47569#post-id-47569