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, 19 Aug 2019 18:55:41 +0200Defining manifolds in a systematic way.https://ask.sagemath.org/question/47115/defining-manifolds-in-a-systematic-way/ I'm working on writing an algorithm that does some specific computations with manifolds. I would like to be able to simply enter 2 numbers "p" and "q" which determine the manifold's dimension p*q, and have the algorithm run right from there. This requires having Sage set up the manifold right from those two numbers. I'm having trouble at the level of defining the chart. Below I begin a naive attempt.
Sage: p=1
Sage: q=2
Sage: M = Manifold((2*p*q), 'M', field='complex')
Sage: U = M.open_subset('U')
Sage: x = list(var('x_%d' %i) for i in range((2*p*q)))
Everything works fine up to this point. Now, I need to define variables for a chart for this manifold. I would like to do something like
Sage: c.<x[0],x[1],x[2],x[3]> = U.chart()
where I'm using the variables I've defined as my coordinates. However, Sage doesn't allow me to do this. Furthermore, even if I could, I'm not sure how I would set this up so I didn't have to type in the variables by hand, because I want to set it up so I just have to feed Sage p and q, and let it build the manifold on its own. Wed, 10 Jul 2019 18:35:45 +0200https://ask.sagemath.org/question/47115/defining-manifolds-in-a-systematic-way/Answer by rburing for <p>I'm working on writing an algorithm that does some specific computations with manifolds. I would like to be able to simply enter 2 numbers "p" and "q" which determine the manifold's dimension p*q, and have the algorithm run right from there. This requires having Sage set up the manifold right from those two numbers. I'm having trouble at the level of defining the chart. Below I begin a naive attempt. </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 = list(var('x_%d' %i) for i in range((2*p*q)))
</code></pre>
<p>Everything works fine up to this point. Now, I need to define variables for a chart for this manifold. I would like to do something like </p>
<pre><code>Sage: c.<x[0],x[1],x[2],x[3]> = U.chart()
</code></pre>
<p>where I'm using the variables I've defined as my coordinates. However, Sage doesn't allow me to do this. Furthermore, even if I could, I'm not sure how I would set this up so I didn't have to type in the variables by hand, because I want to set it up so I just have to feed Sage p and q, and let it build the manifold on its own. </p>
https://ask.sagemath.org/question/47115/defining-manifolds-in-a-systematic-way/?answer=47116#post-id-47116See the [documentation on charts](http://doc.sagemath.org/html/en/reference/manifolds/sage/manifolds/chart.html), particularly the arguments `coordinates` and `names`.
For example, you can do the following:
sage: x = U.chart(names=tuple('x_%d' % i for i in range(2*p*q)))
sage: x[:]
(x_0, x_1, x_2, x_3)
sage: x[0]
x_0
Another example, upon request:
x_indices = [(i,j,k) for i in range(2) for j in range(2) for k in range(2)]
M = Manifold(len(x_indices), 'M', field='complex')
U = M.open_subset('U')
x_names = tuple('x_{}_{}_{}'.format(i,j,k) for (i,j,k) in x_indices)
x_coords = U.chart(names=x_names)
x = dict(zip(x_indices,x_coords))
Then you can do:
sage: x[(0,0,0)]
x_0_0_0Wed, 10 Jul 2019 18:51:26 +0200https://ask.sagemath.org/question/47115/defining-manifolds-in-a-systematic-way/?answer=47116#post-id-47116Comment by sum8tion for <p>See the <a href="http://doc.sagemath.org/html/en/reference/manifolds/sage/manifolds/chart.html">documentation on charts</a>, particularly the arguments <code>coordinates</code> and <code>names</code>.</p>
<p>For example, you can do the following:</p>
<pre><code>sage: x = U.chart(names=tuple('x_%d' % i for i in range(2*p*q)))
sage: x[:]
(x_0, x_1, x_2, x_3)
sage: x[0]
x_0
</code></pre>
<p>Another example, upon request:</p>
<pre><code>x_indices = [(i,j,k) for i in range(2) for j in range(2) for k in range(2)]
M = Manifold(len(x_indices), 'M', field='complex')
U = M.open_subset('U')
x_names = tuple('x_{}_{}_{}'.format(i,j,k) for (i,j,k) in x_indices)
x_coords = U.chart(names=x_names)
x = dict(zip(x_indices,x_coords))
</code></pre>
<p>Then you can do:</p>
<pre><code>sage: x[(0,0,0)]
x_0_0_0
</code></pre>
https://ask.sagemath.org/question/47115/defining-manifolds-in-a-systematic-way/?comment=47117#post-id-47117How do I define a frame then? My naive attempt in analogy to the usual situation,
Sage: eU = x.frame()
but this doesn't work.Wed, 10 Jul 2019 19:06:07 +0200https://ask.sagemath.org/question/47115/defining-manifolds-in-a-systematic-way/?comment=47117#post-id-47117Comment by rburing for <p>See the <a href="http://doc.sagemath.org/html/en/reference/manifolds/sage/manifolds/chart.html">documentation on charts</a>, particularly the arguments <code>coordinates</code> and <code>names</code>.</p>
<p>For example, you can do the following:</p>
<pre><code>sage: x = U.chart(names=tuple('x_%d' % i for i in range(2*p*q)))
sage: x[:]
(x_0, x_1, x_2, x_3)
sage: x[0]
x_0
</code></pre>
<p>Another example, upon request:</p>
<pre><code>x_indices = [(i,j,k) for i in range(2) for j in range(2) for k in range(2)]
M = Manifold(len(x_indices), 'M', field='complex')
U = M.open_subset('U')
x_names = tuple('x_{}_{}_{}'.format(i,j,k) for (i,j,k) in x_indices)
x_coords = U.chart(names=x_names)
x = dict(zip(x_indices,x_coords))
</code></pre>
<p>Then you can do:</p>
<pre><code>sage: x[(0,0,0)]
x_0_0_0
</code></pre>
https://ask.sagemath.org/question/47115/defining-manifolds-in-a-systematic-way/?comment=47118#post-id-47118That should work (and it does for me). What version of SageMath are you running?Wed, 10 Jul 2019 20:00:34 +0200https://ask.sagemath.org/question/47115/defining-manifolds-in-a-systematic-way/?comment=47118#post-id-47118Comment by sum8tion for <p>See the <a href="http://doc.sagemath.org/html/en/reference/manifolds/sage/manifolds/chart.html">documentation on charts</a>, particularly the arguments <code>coordinates</code> and <code>names</code>.</p>
<p>For example, you can do the following:</p>
<pre><code>sage: x = U.chart(names=tuple('x_%d' % i for i in range(2*p*q)))
sage: x[:]
(x_0, x_1, x_2, x_3)
sage: x[0]
x_0
</code></pre>
<p>Another example, upon request:</p>
<pre><code>x_indices = [(i,j,k) for i in range(2) for j in range(2) for k in range(2)]
M = Manifold(len(x_indices), 'M', field='complex')
U = M.open_subset('U')
x_names = tuple('x_{}_{}_{}'.format(i,j,k) for (i,j,k) in x_indices)
x_coords = U.chart(names=x_names)
x = dict(zip(x_indices,x_coords))
</code></pre>
<p>Then you can do:</p>
<pre><code>sage: x[(0,0,0)]
x_0_0_0
</code></pre>
https://ask.sagemath.org/question/47115/defining-manifolds-in-a-systematic-way/?comment=47119#post-id-47119Oh, I just tried it again and it worked, must have made a typo the first time, thanks.Wed, 10 Jul 2019 20:06:16 +0200https://ask.sagemath.org/question/47115/defining-manifolds-in-a-systematic-way/?comment=47119#post-id-47119Comment by sum8tion for <p>See the <a href="http://doc.sagemath.org/html/en/reference/manifolds/sage/manifolds/chart.html">documentation on charts</a>, particularly the arguments <code>coordinates</code> and <code>names</code>.</p>
<p>For example, you can do the following:</p>
<pre><code>sage: x = U.chart(names=tuple('x_%d' % i for i in range(2*p*q)))
sage: x[:]
(x_0, x_1, x_2, x_3)
sage: x[0]
x_0
</code></pre>
<p>Another example, upon request:</p>
<pre><code>x_indices = [(i,j,k) for i in range(2) for j in range(2) for k in range(2)]
M = Manifold(len(x_indices), 'M', field='complex')
U = M.open_subset('U')
x_names = tuple('x_{}_{}_{}'.format(i,j,k) for (i,j,k) in x_indices)
x_coords = U.chart(names=x_names)
x = dict(zip(x_indices,x_coords))
</code></pre>
<p>Then you can do:</p>
<pre><code>sage: x[(0,0,0)]
x_0_0_0
</code></pre>
https://ask.sagemath.org/question/47115/defining-manifolds-in-a-systematic-way/?comment=47511#post-id-47511Hey, is there a way to do this in such a way that the coordinates have multiple indices, like x[(i,j,k)]?Mon, 19 Aug 2019 18:10:02 +0200https://ask.sagemath.org/question/47115/defining-manifolds-in-a-systematic-way/?comment=47511#post-id-47511Comment by rburing for <p>See the <a href="http://doc.sagemath.org/html/en/reference/manifolds/sage/manifolds/chart.html">documentation on charts</a>, particularly the arguments <code>coordinates</code> and <code>names</code>.</p>
<p>For example, you can do the following:</p>
<pre><code>sage: x = U.chart(names=tuple('x_%d' % i for i in range(2*p*q)))
sage: x[:]
(x_0, x_1, x_2, x_3)
sage: x[0]
x_0
</code></pre>
<p>Another example, upon request:</p>
<pre><code>x_indices = [(i,j,k) for i in range(2) for j in range(2) for k in range(2)]
M = Manifold(len(x_indices), 'M', field='complex')
U = M.open_subset('U')
x_names = tuple('x_{}_{}_{}'.format(i,j,k) for (i,j,k) in x_indices)
x_coords = U.chart(names=x_names)
x = dict(zip(x_indices,x_coords))
</code></pre>
<p>Then you can do:</p>
<pre><code>sage: x[(0,0,0)]
x_0_0_0
</code></pre>
https://ask.sagemath.org/question/47115/defining-manifolds-in-a-systematic-way/?comment=47512#post-id-47512Sure, I added another example.Mon, 19 Aug 2019 18:55:41 +0200https://ask.sagemath.org/question/47115/defining-manifolds-in-a-systematic-way/?comment=47512#post-id-47512