-
-
Notifications
You must be signed in to change notification settings - Fork 518
/
Copy pathmanifold.py
3089 lines (2483 loc) · 116 KB
/
manifold.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
r"""
Topological Manifolds
Given a topological field `K` (in most applications, `K = \RR` or
`K = \CC`) and a nonnegative integer `n`, a *topological manifold of
dimension* `n` *over K* is a topological space `M` such that
- `M` is a Hausdorff space,
- `M` is second countable,
- every point in `M` has a neighborhood homeomorphic to `K^n`.
Topological manifolds are implemented via the class
:class:`TopologicalManifold`. Open subsets of topological manifolds
are also implemented via :class:`TopologicalManifold`, since they are
topological manifolds by themselves.
In the current setting, topological manifolds are mostly described by
means of charts (see :class:`~sage.manifolds.chart.Chart`).
:class:`TopologicalManifold` serves as a base class for more specific
manifold classes.
The user interface is provided by the generic function
:func:`~sage.manifolds.manifold.Manifold`, with
with the argument ``structure`` set to ``'topological'``.
.. RUBRIC:: Example 1: the 2-sphere as a topological manifold of dimension
2 over `\RR`
One starts by declaring `S^2` as a 2-dimensional topological manifold::
sage: M = Manifold(2, 'S^2', structure='topological')
sage: M
2-dimensional topological manifold S^2
Since the base topological field has not been specified in the argument list
of ``Manifold``, `\RR` is assumed::
sage: M.base_field()
Real Field with 53 bits of precision
sage: dim(M)
2
Let us consider the complement of a point, the "North pole" say; this is an
open subset of `S^2`, which we call `U`::
sage: U = M.open_subset('U'); U
Open subset U of the 2-dimensional topological manifold S^2
A standard chart on `U` is provided by the stereographic projection from the
North pole to the equatorial plane::
sage: stereoN.<x,y> = U.chart(); stereoN
Chart (U, (x, y))
Thanks to the operator ``<x,y>`` on the left-hand side, the coordinates
declared in a chart (here `x` and `y`), are accessible by their names;
they are Sage's symbolic variables::
sage: y
y
sage: type(y)
<class 'sage.symbolic.expression.Expression'>
The South pole is the point of coordinates `(x, y) = (0, 0)` in the above
chart::
sage: S = U.point((0,0), chart=stereoN, name='S'); S
Point S on the 2-dimensional topological manifold S^2
Let us call `V` the open subset that is the complement of the South pole and
let us introduce on it the chart induced by the stereographic projection from
the South pole to the equatorial plane::
sage: V = M.open_subset('V'); V
Open subset V of the 2-dimensional topological manifold S^2
sage: stereoS.<u,v> = V.chart(); stereoS
Chart (V, (u, v))
The North pole is the point of coordinates `(u, v) = (0, 0)` in this chart::
sage: N = V.point((0,0), chart=stereoS, name='N'); N
Point N on the 2-dimensional topological manifold S^2
To fully construct the manifold, we declare that it is the union of `U`
and `V`::
sage: M.declare_union(U,V)
and we provide the transition map between the charts ``stereoN`` =
`(U, (x, y))` and ``stereoS`` = `(V, (u, v))`, denoting by `W` the
intersection of `U` and `V` (`W` is the subset of `U` defined by
`x^2 + y^2 \neq 0`, as well as the subset of `V` defined by
`u^2 + v^2 \neq 0`)::
sage: stereoN_to_S = stereoN.transition_map(stereoS, [x/(x^2+y^2), y/(x^2+y^2)],
....: intersection_name='W', restrictions1= x^2+y^2!=0,
....: restrictions2= u^2+v^2!=0)
sage: stereoN_to_S
Change of coordinates from Chart (W, (x, y)) to Chart (W, (u, v))
sage: stereoN_to_S.display()
u = x/(x^2 + y^2)
v = y/(x^2 + y^2)
We give the name ``W`` to the Python variable representing `W = U \cap V`::
sage: W = U.intersection(V)
The inverse of the transition map is computed by the method
:meth:`sage.manifolds.chart.CoordChange.inverse`::
sage: stereoN_to_S.inverse()
Change of coordinates from Chart (W, (u, v)) to Chart (W, (x, y))
sage: stereoN_to_S.inverse().display()
x = u/(u^2 + v^2)
y = v/(u^2 + v^2)
At this stage, we have four open subsets on `S^2`::
sage: M.subset_family()
Set {S^2, U, V, W} of open subsets of the 2-dimensional topological manifold S^2
`W` is the open subset that is the complement of the two poles::
sage: N in W or S in W
False
The North pole lies in `V` and the South pole in `U`::
sage: N in V, N in U
(True, False)
sage: S in U, S in V
(True, False)
The manifold's (user) atlas contains four charts, two of them
being restrictions of charts to a smaller domain::
sage: M.atlas()
[Chart (U, (x, y)), Chart (V, (u, v)),
Chart (W, (x, y)), Chart (W, (u, v))]
Let us consider the point of coordinates `(1, 2)` in the chart ``stereoN``::
sage: p = M.point((1,2), chart=stereoN, name='p'); p
Point p on the 2-dimensional topological manifold S^2
sage: p.parent()
2-dimensional topological manifold S^2
sage: p in W
True
The coordinates of `p` in the chart ``stereoS`` are computed by letting
the chart act on the point::
sage: stereoS(p)
(1/5, 2/5)
Given the definition of `p`, we have of course::
sage: stereoN(p)
(1, 2)
Similarly::
sage: stereoS(N)
(0, 0)
sage: stereoN(S)
(0, 0)
A continuous map `S^2 \to \RR` (scalar field)::
sage: f = M.scalar_field({stereoN: atan(x^2+y^2), stereoS: pi/2-atan(u^2+v^2)},
....: name='f')
sage: f
Scalar field f on the 2-dimensional topological manifold S^2
sage: f.display()
f: S^2 → ℝ
on U: (x, y) ↦ arctan(x^2 + y^2)
on V: (u, v) ↦ 1/2*pi - arctan(u^2 + v^2)
sage: f(p)
arctan(5)
sage: f(N)
1/2*pi
sage: f(S)
0
sage: f.parent()
Algebra of scalar fields on the 2-dimensional topological manifold S^2
sage: f.parent().category()
Join of Category of commutative algebras over Symbolic Ring and Category of homsets of topological spaces
.. RUBRIC:: Example 2: the Riemann sphere as a topological manifold of
dimension 1 over `\CC`
We declare the Riemann sphere `\CC^*` as a 1-dimensional topological manifold
over `\CC`::
sage: M = Manifold(1, 'ℂ*', structure='topological', field='complex'); M
Complex 1-dimensional topological manifold ℂ*
We introduce a first open subset, which is actually
`\CC = \CC^*\setminus\{\infty\}` if we interpret `\CC^*` as the
Alexandroff one-point compactification of `\CC`::
sage: U = M.open_subset('U')
A natural chart on `U` is then nothing but the identity map of `\CC`, hence
we denote the associated coordinate by `z`::
sage: Z.<z> = U.chart()
The origin of the complex plane is the point of coordinate `z = 0`::
sage: O = U.point((0,), chart=Z, name='O'); O
Point O on the Complex 1-dimensional topological manifold ℂ*
Another open subset of `\CC^*` is `V = \CC^*\setminus\{O\}`::
sage: V = M.open_subset('V')
We define a chart on `V` such that the point at infinity is the point of
coordinate `0` in this chart::
sage: W.<w> = V.chart(); W
Chart (V, (w,))
sage: inf = M.point((0,), chart=W, name='inf', latex_name=r'\infty')
sage: inf
Point inf on the Complex 1-dimensional topological manifold ℂ*
To fully construct the Riemann sphere, we declare that it is the union
of `U` and `V`::
sage: M.declare_union(U,V)
and we provide the transition map between the two charts as `w = 1 / z`
on `A = U \cap V`::
sage: Z_to_W = Z.transition_map(W, 1/z, intersection_name='A',
....: restrictions1= z!=0, restrictions2= w!=0)
sage: Z_to_W
Change of coordinates from Chart (A, (z,)) to Chart (A, (w,))
sage: Z_to_W.display()
w = 1/z
sage: Z_to_W.inverse()
Change of coordinates from Chart (A, (w,)) to Chart (A, (z,))
sage: Z_to_W.inverse().display()
z = 1/w
Let consider the complex number `i` as a point of the Riemann sphere::
sage: i = M((I,), chart=Z, name='i'); i
Point i on the Complex 1-dimensional topological manifold ℂ*
Its coordinates w.r.t. the charts ``Z`` and ``W`` are::
sage: Z(i)
(I,)
sage: W(i)
(-I,)
and we have::
sage: i in U
True
sage: i in V
True
The following subsets and charts have been defined::
sage: M.subset_family()
Set {A, U, V, ℂ*} of open subsets of the Complex 1-dimensional topological manifold ℂ*
sage: M.atlas()
[Chart (U, (z,)), Chart (V, (w,)), Chart (A, (z,)), Chart (A, (w,))]
A constant map `\CC^* \rightarrow \CC`::
sage: f = M.constant_scalar_field(3+2*I, name='f'); f
Scalar field f on the Complex 1-dimensional topological manifold ℂ*
sage: f.display()
f: ℂ* → ℂ
on U: z ↦ 2*I + 3
on V: w ↦ 2*I + 3
sage: f(O)
2*I + 3
sage: f(i)
2*I + 3
sage: f(inf)
2*I + 3
sage: f.parent()
Algebra of scalar fields on the Complex 1-dimensional topological
manifold ℂ*
sage: f.parent().category()
Join of Category of commutative algebras over Symbolic Ring and Category of homsets of topological spaces
AUTHORS:
- Eric Gourgoulhon (2015): initial version
- Travis Scrimshaw (2015): structure described via
:class:`~sage.manifolds.structure.TopologicalStructure` or
:class:`~sage.manifolds.structure.RealTopologicalStructure`
- Michael Jung (2020): topological vector bundles and orientability
REFERENCES:
- [Lee2011]_
- [Lee2013]_
- [KN1963]_
- [Huy2005]_
"""
# ****************************************************************************
# Copyright (C) 2015-2020 Eric Gourgoulhon <eric.gourgoulhon@obspm.fr>
# Copyright (C) 2015 Travis Scrimshaw <tscrimsh@umn.edu>
# Copyright (C) 2016 Andrew Mathas
# Copyright (C) 2018 Florentin Jaffredo
# Copyright (C) 2019 Hans Fotsing Tetsing
# Copyright (C) 2019-2020 Michael Jung
# Copyright (C) 2021 Matthias Koeppe <mkoeppe@math.ucdavis.edu>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# https://www.gnu.org/licenses/
# ****************************************************************************
from __future__ import annotations
from typing import TYPE_CHECKING, Optional, Union, overload
import sage.rings.abc
from sage.categories.fields import Fields
from sage.categories.homset import Hom
from sage.categories.manifolds import Manifolds
from sage.manifolds.structure import (
DifferentialStructure,
RealDifferentialStructure,
RealTopologicalStructure,
TopologicalStructure,
)
from sage.manifolds.subset import ManifoldSubset
from sage.misc.cachefunc import cached_method
from sage.misc.prandom import getrandbits
from sage.rings.cc import CC
from sage.rings.integer import Integer
from sage.rings.real_mpfr import RR
from sage.structure.global_options import GlobalOptions
if TYPE_CHECKING:
from sage.manifolds.chart import Chart
from sage.manifolds.continuous_map import ContinuousMap
from sage.manifolds.differentiable.diff_map import DiffMap
from sage.manifolds.differentiable.manifold import DifferentiableManifold
from sage.manifolds.scalarfield import ScalarField
#############################################################################
# Global options
#############################################################################
# Class
class TopologicalManifold(ManifoldSubset):
r"""
Topological manifold over a topological field `K`.
Given a topological field `K` (in most applications, `K = \RR` or
`K = \CC`) and a nonnegative integer `n`, a *topological manifold of
dimension* `n` *over K* is a topological space `M` such that
- `M` is a Hausdorff space,
- `M` is second countable, and
- every point in `M` has a neighborhood homeomorphic to `K^n`.
This is a Sage *parent* class, the corresponding *element*
class being :class:`~sage.manifolds.point.ManifoldPoint`.
INPUT:
- ``n`` -- positive integer; dimension of the manifold
- ``name`` -- string; name (symbol) given to the manifold
- ``field`` -- field `K` on which the manifold is
defined; allowed values are
- ``'real'`` or an object of type ``RealField`` (e.g., ``RR``) for
a manifold over `\RR`
- ``'complex'`` or an object of type ``ComplexField`` (e.g., ``CC``)
for a manifold over `\CC`
- an object in the category of topological fields (see
:class:`~sage.categories.fields.Fields` and
:class:`~sage.categories.topological_spaces.TopologicalSpaces`)
for other types of manifolds
- ``structure`` -- manifold structure (see
:class:`~sage.manifolds.structure.TopologicalStructure` or
:class:`~sage.manifolds.structure.RealTopologicalStructure`)
- ``base_manifold`` -- (default: ``None``) if not ``None``, must be a
topological manifold; the created object is then an open subset of
``base_manifold``
- ``latex_name`` -- (default: ``None``) string; LaTeX symbol to
denote the manifold; if none are provided, it is set to ``name``
- ``start_index`` -- (default: 0) integer; lower value of the range of
indices used for "indexed objects" on the manifold, e.g., coordinates
in a chart
- ``category`` -- (default: ``None``) to specify the category; if
``None``, ``Manifolds(field)`` is assumed (see the category
:class:`~sage.categories.manifolds.Manifolds`)
- ``unique_tag`` -- (default: ``None``) tag used to force the construction
of a new object when all the other arguments have been used previously
(without ``unique_tag``, the
:class:`~sage.structure.unique_representation.UniqueRepresentation`
behavior inherited from
:class:`~sage.manifolds.subset.ManifoldSubset`
would return the previously constructed object corresponding to these
arguments)
EXAMPLES:
A 4-dimensional topological manifold (over `\RR`)::
sage: M = Manifold(4, 'M', latex_name=r'\mathcal{M}', structure='topological')
sage: M
4-dimensional topological manifold M
sage: latex(M)
\mathcal{M}
sage: type(M)
<class 'sage.manifolds.manifold.TopologicalManifold_with_category'>
sage: M.base_field()
Real Field with 53 bits of precision
sage: dim(M)
4
The input parameter ``start_index`` defines the range of indices
on the manifold::
sage: M = Manifold(4, 'M', structure='topological')
sage: list(M.irange())
[0, 1, 2, 3]
sage: M = Manifold(4, 'M', structure='topological', start_index=1)
sage: list(M.irange())
[1, 2, 3, 4]
sage: list(Manifold(4, 'M', structure='topological', start_index=-2).irange())
[-2, -1, 0, 1]
A complex manifold::
sage: N = Manifold(3, 'N', structure='topological', field='complex'); N
Complex 3-dimensional topological manifold N
A manifold over `\QQ`::
sage: N = Manifold(6, 'N', structure='topological', field=QQ); N
6-dimensional topological manifold N over the Rational Field
A manifold over `\QQ_5`, the field of 5-adic numbers::
sage: N = Manifold(2, 'N', structure='topological', field=Qp(5)); N # needs sage.rings.padics
2-dimensional topological manifold N over the 5-adic Field with capped
relative precision 20
A manifold is a Sage *parent* object, in the category of topological
manifolds over a given topological field (see
:class:`~sage.categories.manifolds.Manifolds`)::
sage: isinstance(M, Parent)
True
sage: M.category()
Category of manifolds over Real Field with 53 bits of precision
sage: from sage.categories.manifolds import Manifolds
sage: M.category() is Manifolds(RR)
True
sage: M.category() is Manifolds(M.base_field())
True
sage: M in Manifolds(RR)
True
sage: N in Manifolds(Qp(5)) # needs sage.rings.padics
True
The corresponding Sage *elements* are points::
sage: X.<t, x, y, z> = M.chart()
sage: p = M.an_element(); p
Point on the 4-dimensional topological manifold M
sage: p.parent()
4-dimensional topological manifold M
sage: M.is_parent_of(p)
True
sage: p in M
True
The manifold's points are instances of class
:class:`~sage.manifolds.point.ManifoldPoint`::
sage: isinstance(p, sage.manifolds.point.ManifoldPoint)
True
Since an open subset of a topological manifold `M` is itself a
topological manifold, open subsets of `M` are instances of the class
:class:`TopologicalManifold`::
sage: U = M.open_subset('U'); U
Open subset U of the 4-dimensional topological manifold M
sage: isinstance(U, sage.manifolds.manifold.TopologicalManifold)
True
sage: U.base_field() == M.base_field()
True
sage: dim(U) == dim(M)
True
sage: U.category()
Join of Category of subobjects of sets and Category of manifolds over
Real Field with 53 bits of precision
The manifold passes all the tests of the test suite relative to its
category::
sage: TestSuite(M).run()
.. SEEALSO::
:mod:`sage.manifolds.manifold`
"""
_dim: int
def __init__(self, n, name, field, structure, base_manifold=None,
latex_name=None, start_index=0, category=None,
unique_tag=None):
r"""
Construct a topological manifold.
TESTS::
sage: M = Manifold(3, 'M', latex_name=r'\mathbb{M}',
....: structure='topological', start_index=1)
sage: M
3-dimensional topological manifold M
sage: latex(M)
\mathbb{M}
sage: dim(M)
3
sage: X.<x,y,z> = M.chart()
sage: TestSuite(M).run()
Tests for open subsets::
sage: U = M.open_subset('U', coord_def={X: x>0})
sage: TestSuite(U).run()
sage: U.category() is M.category().Subobjects()
True
"""
# Initialization of the attributes _dim, _field, _field_type:
if not isinstance(n, (int, Integer)):
raise TypeError("the manifold dimension must be an integer")
if n < 1:
raise ValueError("the manifold dimension must be strictly positive")
self._dim = n
if field == 'real':
self._field = RR
self._field_type = 'real'
elif field == 'complex':
self._field = CC
self._field_type = 'complex'
else:
if field not in Fields():
raise TypeError("the argument 'field' must be a field")
self._field = field
if isinstance(field, sage.rings.abc.RealField):
self._field_type = 'real'
elif isinstance(field, sage.rings.abc.ComplexField):
self._field_type = 'complex'
else:
self._field_type = 'neither_real_nor_complex'
# Structure and category:
self._structure = structure
if base_manifold is None:
base_manifold = self
category = Manifolds(self._field).or_subcategory(category)
category = self._structure.subcategory(category)
else:
category = base_manifold.category().Subobjects()
# Initialization as a manifold set:
ManifoldSubset.__init__(self, base_manifold, name, latex_name=latex_name,
category=category)
self._is_open = True
self._open_covers.append([self]) # list of open covers of self
if not isinstance(start_index, (int, Integer)):
raise TypeError("the starting index must be an integer")
self._sindex = start_index
self._atlas = [] # list of charts defined on subsets of self
self._top_charts = [] # list of charts defined on subsets of self
# that are not subcharts of charts on larger subsets
self._def_chart = None # default chart
self._orientation = [] # set no orientation a priori
self._charts_by_coord = {} # dictionary of charts whose domain is self
# (key: string formed by the coordinate
# symbols separated by a white space)
self._coord_changes = {} # dictionary of transition maps (key: pair of
# of charts)
# List of charts that individually cover self, i.e. whose
# domains are self (if non-empty, self is a coordinate domain):
self._covering_charts = []
# Algebra of scalar fields defined on self:
self._scalar_field_algebra = self._structure.scalar_field_algebra(self)
# The zero scalar field:
self._zero_scalar_field = self._scalar_field_algebra.zero()
# The unit scalar field:
self._one_scalar_field = self._scalar_field_algebra.one()
# The current calculus method on the manifold
# (to be changed by set_calculus_method)
self._calculus_method = 'SR'
def _repr_(self):
r"""
Return a string representation of the manifold.
TESTS::
sage: M = Manifold(3, 'M', structure='topological')
sage: M._repr_()
'3-dimensional topological manifold M'
sage: repr(M) # indirect doctest
'3-dimensional topological manifold M'
sage: M # indirect doctest
3-dimensional topological manifold M
sage: M = Manifold(3, 'M', structure='topological', field='complex')
sage: M._repr_()
'Complex 3-dimensional topological manifold M'
sage: M = Manifold(3, 'M', structure='topological', field=QQ)
sage: M._repr_()
'3-dimensional topological manifold M over the Rational Field'
If the manifold is actually an open subset of a larger manifold, the
string representation is different::
sage: U = M.open_subset('U')
sage: U._repr_()
'Open subset U of the 3-dimensional topological manifold M
over the Rational Field'
"""
if self is self._manifold:
if self._field_type == 'real':
return "{}-dimensional {} manifold {}".format(self._dim,
self._structure.name,
self._name)
elif self._field_type == 'complex':
if isinstance(self._structure, DifferentialStructure):
return "{}-dimensional complex manifold {}".format(
self._dim,
self._name)
else:
return "Complex {}-dimensional {} manifold {}".format(
self._dim,
self._structure.name,
self._name)
return "{}-dimensional {} manifold {} over the {}".format(
self._dim,
self._structure.name,
self._name,
self._field)
else:
return "Open subset {} of the {}".format(self._name, self._manifold)
def _an_element_(self):
r"""
Construct some point on the manifold.
EXAMPLES::
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: p = M._an_element_(); p
Point on the 2-dimensional topological manifold M
sage: p.coord()
(0, 0)
sage: U = M.open_subset('U', coord_def={X: y>1}); U
Open subset U of the 2-dimensional topological manifold M
sage: p = U._an_element_(); p
Point on the 2-dimensional topological manifold M
sage: p in U
True
sage: p.coord()
(0, 2)
sage: V = U.open_subset('V', coord_def={X.restrict(U): x<-pi})
sage: p = V._an_element_(); p
Point on the 2-dimensional topological manifold M
sage: p in V
True
sage: p.coord()
(-pi - 1, 2)
"""
from sage.rings.infinity import Infinity
if self._def_chart is None:
return self.element_class(self)
# Attempt to construct a point in the domain of the default chart
chart = self._def_chart
if self._field_type == 'real':
coords = []
for coord_range in chart._bounds:
xmin = coord_range[0][0]
xmax = coord_range[1][0]
if xmin == -Infinity:
if xmax == Infinity:
x = 0
else:
x = xmax - 1
else:
if xmax == Infinity:
x = xmin + 1
else:
x = (xmin + xmax)/2
coords.append(x)
else:
coords = self._dim*[0]
if not chart.valid_coordinates(*coords):
# Attempt to construct a point in the domain of other charts
if self._field_type == 'real':
for ch in self._atlas:
if ch is self._def_chart:
continue # since this case has already been attempted
coords = []
for coord_range in ch._bounds:
xmin = coord_range[0][0]
xmax = coord_range[1][0]
if xmin == -Infinity:
if xmax == Infinity:
x = 0
else:
x = xmax - 1
else:
if xmax == Infinity:
x = xmin + 1
else:
x = (xmin + xmax)/2
coords.append(x)
if ch.valid_coordinates(*coords):
chart = ch
break
else:
# A generic element with specific coordinates could not be
# automatically generated, due to too complex coordinate
# conditions. An element without any coordinate set is
# returned instead:
return self.element_class(self)
else:
# Case of manifolds over a field different from R
for ch in self._atlas:
if ch is self._def_chart:
continue # since this case has already been attempted
if ch.valid_coordinates(*coords):
chart = ch
break
else:
return self.element_class(self)
# The point is constructed with check_coords=False since the check
# has just been performed above:
return self.element_class(self, coords=coords, chart=chart,
check_coords=False)
def __contains__(self, point):
r"""
Check whether a point is contained in the manifold.
EXAMPLES::
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: p = M.point((1,2), chart=X)
sage: M.__contains__(p)
True
sage: p in M # indirect doctest
True
sage: U = M.open_subset('U', coord_def={X: x>0})
sage: U.__contains__(p)
True
sage: p in U # indirect doctest
True
sage: V = U.open_subset('V', coord_def={X.restrict(U): y<0})
sage: V.__contains__(p)
False
sage: p in V # indirect doctest
False
"""
# for efficiency, a quick test first:
if point.parent() is self:
return True
if point.parent().is_subset(self):
return True
for chart in self._atlas:
if chart in point._coordinates:
if chart.valid_coordinates( *(point._coordinates[chart]) ):
return True
for chart in point._coordinates:
for schart in chart._subcharts:
if schart in self._atlas and schart.valid_coordinates(
*(point._coordinates[chart]) ):
return True
return False
def open_subset(self, name, latex_name=None, coord_def={}, supersets=None):
r"""
Create an open subset of the manifold.
An open subset is a set that is (i) included in the manifold and (ii)
open with respect to the manifold's topology. It is a topological
manifold by itself. Hence the returned object is an instance of
:class:`TopologicalManifold`.
INPUT:
- ``name`` -- name given to the open subset
- ``latex_name`` -- (default: ``None``) LaTeX symbol to denote
the subset; if none are provided, it is set to ``name``
- ``coord_def`` -- (default: {}) definition of the subset in
terms of coordinates; ``coord_def`` must a be dictionary with keys
charts on the manifold and values the symbolic expressions formed
by the coordinates to define the subset
- ``supersets`` -- (default: only ``self``) list of sets that the
new open subset is a subset of
OUTPUT: the open subset, as an instance of :class:`TopologicalManifold`
EXAMPLES:
Creating an open subset of a 2-dimensional manifold::
sage: M = Manifold(2, 'M', structure='topological')
sage: A = M.open_subset('A'); A
Open subset A of the 2-dimensional topological manifold M
As an open subset of a topological manifold, ``A`` is itself a
topological manifold, on the same topological field and of the same
dimension as ``M``::
sage: isinstance(A, sage.manifolds.manifold.TopologicalManifold)
True
sage: A.base_field() == M.base_field()
True
sage: dim(A) == dim(M)
True
sage: A.category() is M.category().Subobjects()
True
Creating an open subset of ``A``::
sage: B = A.open_subset('B'); B
Open subset B of the 2-dimensional topological manifold M
We have then::
sage: frozenset(A.subsets()) # random (set output)
{Open subset B of the 2-dimensional topological manifold M,
Open subset A of the 2-dimensional topological manifold M}
sage: B.is_subset(A)
True
sage: B.is_subset(M)
True
Defining an open subset by some coordinate restrictions: the open
unit disk in `\RR^2`::
sage: M = Manifold(2, 'R^2', structure='topological')
sage: c_cart.<x,y> = M.chart() # Cartesian coordinates on R^2
sage: U = M.open_subset('U', coord_def={c_cart: x^2+y^2<1}); U
Open subset U of the 2-dimensional topological manifold R^2
Since the argument ``coord_def`` has been set, ``U`` is automatically
provided with a chart, which is the restriction of the Cartesian one
to ``U``::
sage: U.atlas()
[Chart (U, (x, y))]
Therefore, one can immediately check whether a point belongs
to ``U``::
sage: M.point((0,0)) in U
True
sage: M.point((1/2,1/3)) in U
True
sage: M.point((1,2)) in U
False
"""
resu = TopologicalManifold(self._dim, name, self._field,
self._structure,
base_manifold=self._manifold,
latex_name=latex_name,
start_index=self._sindex)
if supersets is None:
supersets = [self]
for superset in supersets:
superset._init_open_subset(resu, coord_def=coord_def)
return resu
def _init_open_subset(self, resu, coord_def):
r"""
Initialize ``resu`` as an open subset of ``self``.
INPUT:
- ``resu`` -- an instance of :class:`TopologicalManifold` or
a subclass
- ``coord_def`` -- (default: ``{}``) definition of the subset in
terms of coordinates; ``coord_def`` must a be dictionary with keys
charts on the manifold and values the symbolic expressions formed
by the coordinates to define the subset
EXAMPLES::
sage: M = Manifold(2, 'R^2', structure='topological')
sage: c_cart.<x,y> = M.chart() # Cartesian coordinates on R^2
sage: from sage.manifolds.manifold import TopologicalManifold
sage: U = TopologicalManifold(2, 'U', field=M._field, structure=M._structure, base_manifold=M)
sage: M._init_open_subset(U, coord_def={c_cart: x^2+y^2<1})
sage: U
Open subset U of the 2-dimensional topological manifold R^2
"""
resu._calculus_method = self._calculus_method
if self.is_empty():
self.declare_equal(resu)
else:
self.declare_superset(resu)
self._top_subsets.add(resu)
# Charts on the result from the coordinate definition:
for chart, restrictions in coord_def.items():
if chart not in self._atlas:
raise ValueError("the {} does not belong to ".format(chart) +
"the atlas of {}".format(self))
chart.restrict(resu, restrictions)
# Transition maps on the result inferred from those of self:
for chart1 in coord_def:
for chart2 in coord_def:
if chart2 != chart1 and (chart1, chart2) in self._coord_changes:
self._coord_changes[(chart1, chart2)].restrict(resu)
def get_chart(self, coordinates, domain=None):
r"""
Get a chart from its coordinates.
The chart must have been previously created by the method
:meth:`chart`.
INPUT:
- ``coordinates`` -- single string composed of the coordinate symbols
separated by a space
- ``domain`` -- (default: ``None``) string containing the name of the
chart's domain, which must be a subset of the current manifold; if
``None``, the current manifold is assumed
OUTPUT:
- instance of
:class:`~sage.manifolds.chart.Chart` (or of the subclass
:class:`~sage.manifolds.chart.RealChart`) representing the chart
corresponding to the above specifications
EXAMPLES::
sage: M = Manifold(2, 'M', structure='topological')
sage: X.<x,y> = M.chart()
sage: M.get_chart('x y')
Chart (M, (x, y))
sage: M.get_chart('x y') is X
True
sage: U = M.open_subset('U', coord_def={X: (y!=0,x<0)})
sage: Y.<r, ph> = U.chart(r'r:(0,+oo) ph:(0,2*pi):\phi')
sage: M.atlas()
[Chart (M, (x, y)), Chart (U, (x, y)), Chart (U, (r, ph))]
sage: M.get_chart('x y', domain='U')
Chart (U, (x, y))
sage: M.get_chart('x y', domain='U') is X.restrict(U)
True
sage: U.get_chart('r ph')
Chart (U, (r, ph))
sage: M.get_chart('r ph', domain='U')
Chart (U, (r, ph))
sage: M.get_chart('r ph', domain='U') is Y
True
"""
if domain is None:
dom = self
else:
dom = self.get_subset(domain)
try:
return dom._charts_by_coord[coordinates]
except KeyError:
raise KeyError("the coordinates '{}' ".format(coordinates) +
"do not correspond to any chart with " +
"the {} as domain".format(dom))
def dimension(self):
r"""
Return the dimension of the manifold over its base field.
EXAMPLES::
sage: M = Manifold(2, 'M', structure='topological')
sage: M.dimension()