Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/tensor/coordinate_patch.py
4036 views
1
r"""
2
Open subset of Euclidian space with coordinates
3
4
An open subset of Euclidian space with a specific set of coordinates. This
5
is the background on which differential forms can be defined.
6
7
AUTHORS:
8
9
- Joris Vankerschaver (2010-07-25)
10
11
EXAMPLES::
12
13
sage: x, y, z = var('x, y, z')
14
sage: S = CoordinatePatch((x, y, z)); S
15
Open subset of R^3 with coordinates x, y, z
16
17
::
18
19
sage: u, v = var('u, v')
20
sage: S = CoordinatePatch((u, v)); S
21
Open subset of R^2 with coordinates u, v
22
23
TODO:
24
25
- Add functionality for metric tensors
26
27
"""
28
29
#*****************************************************************************
30
# Copyright (C) 2010 Joris Vankerschaver <[email protected]>
31
#
32
# Distributed under the terms of the GNU General Public License (GPL)
33
#
34
# This code is distributed in the hope that it will be useful,
35
# but WITHOUT ANY WARRANTY; without even the implied warranty of
36
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
37
# General Public License for more details.
38
#
39
# The full text of the GPL is available at:
40
#
41
# http://www.gnu.org/licenses/
42
#*****************************************************************************
43
44
45
from sage.structure.parent import Parent
46
47
class CoordinatePatch(Parent):
48
"""
49
Construct a coordinate patch, i.e. an open subset of
50
Euclidian space with a given set of coordinates.
51
52
EXAMPLES::
53
54
sage: x, y, z = var('x, y, z')
55
sage: S = CoordinatePatch((x, y, z)); S
56
Open subset of R^3 with coordinates x, y, z
57
58
sage: u, v = var('u, v')
59
sage: T = CoordinatePatch((u, v)); T
60
Open subset of R^2 with coordinates u, v
61
sage: loads(T.dumps()) == T
62
True
63
64
In a future release, it will be possible to specify a
65
metric tensor on a coordinate patch. For now, providing
66
any kind of metric raises an exception::
67
68
sage: x, y, z = var('x, y, z')
69
sage: m = matrix(SR, 3)
70
sage: S = CoordinatePatch((x, y, z), metric=m)
71
Traceback (most recent call last):
72
...
73
NotImplementedError: Metric geometry not supported yet.
74
75
"""
76
def __init__(self, coordinates, metric = None):
77
"""
78
An open subset of Euclidian space with a specific set of
79
coordinates. See ``CoordinatePatch`` for details.
80
81
INPUT::
82
83
- ``coordinates`` -- a set of symbolic variables that serve
84
as coordinates on this space.
85
86
- ``metric`` (default: None) -- a metric tensor on this
87
coordinate patch. Providing anything other than ``None``
88
is currently not defined.
89
90
91
EXAMPLES::
92
93
sage: x, y, z = var('x, y, z')
94
sage: S = CoordinatePatch((x, y, z)); S
95
Open subset of R^3 with coordinates x, y, z
96
97
"""
98
99
from sage.symbolic.ring import is_SymbolicVariable
100
101
if not all(is_SymbolicVariable(c) for c in coordinates):
102
raise TypeError, "%s is not a valid vector of coordinates." % \
103
coordinates
104
105
self._coordinates = tuple(coordinates)
106
dim = len(self._coordinates)
107
108
if metric is not None:
109
raise NotImplementedError, "Metric geometry not supported yet."
110
111
112
113
def __eq__(self, other):
114
"""
115
Return equality if and only if other has the same coordinates
116
as self, in the same order.
117
118
EXAMPLES::
119
120
sage: x, y, z = var('x, y, z')
121
sage: S = CoordinatePatch((x, y, z)); S
122
Open subset of R^3 with coordinates x, y, z
123
sage: u, v = var('u, v')
124
sage: T = CoordinatePatch((u, v)); T
125
Open subset of R^2 with coordinates u, v
126
sage: U = CoordinatePatch((x, y, z)); U
127
Open subset of R^3 with coordinates x, y, z
128
sage: U == S
129
True
130
sage: U == U
131
True
132
sage: U == T
133
False
134
135
Note that the order of the coordinates matters::
136
137
sage: x, y, z = var('x, y, z')
138
sage: S = CoordinatePatch((x, y, z)); S
139
Open subset of R^3 with coordinates x, y, z
140
sage: T = CoordinatePatch((x, z, y)); T
141
Open subset of R^3 with coordinates x, z, y
142
sage: S == T
143
False
144
"""
145
146
return str(self._coordinates) == str(other._coordinates)
147
148
149
def __ne__(self, other):
150
"""
151
Test whether two coordinate patches are not equal.
152
153
EXAMPLES::
154
155
sage: x, y, z = var('x, y, z')
156
sage: S = CoordinatePatch((x, y, z)); S
157
Open subset of R^3 with coordinates x, y, z
158
sage: u, v = var('u, v')
159
sage: T = CoordinatePatch((u, v)); T
160
Open subset of R^2 with coordinates u, v
161
sage: S != T
162
True
163
"""
164
165
return not self.__eq__(other)
166
167
168
169
def coordinates(self):
170
"""
171
Return coordinates on this coordinate patch.
172
173
OUTPUT:
174
175
- list - a list of coordinates on this space.
176
177
EXAMPLES::
178
179
sage: x, y, z = var('x, y, z')
180
sage: S = CoordinatePatch((x, y, z)); S
181
Open subset of R^3 with coordinates x, y, z
182
sage: S.coordinates()
183
(x, y, z)
184
185
"""
186
return self._coordinates
187
188
189
def coordinate(self, i=0):
190
"""
191
Return the `i^{th}` coordinate on ``self``
192
193
INPUT:
194
195
- ``i`` - integer (optional, default 0)
196
197
198
EXAMPLES::
199
200
sage: x, y, z = var('x, y, z')
201
sage: S = CoordinatePatch((x, y, z)); S
202
Open subset of R^3 with coordinates x, y, z
203
sage: S.coordinate(0)
204
x
205
sage: S.coordinate(1)
206
y
207
sage: S.coordinate(2)
208
z
209
210
"""
211
return self._coordinates[i]
212
213
214
def dim(self):
215
"""
216
Return the dimension of this coordinate patch, i.e. the dimension
217
of the Euclidian space of which this coordinate patch is an open
218
subset.
219
220
EXAMPLES::
221
222
sage: a, b, c, d, e = var('a, b, c, d, e')
223
sage: U = CoordinatePatch((a, b, c, d, e)); U
224
Open subset of R^5 with coordinates a, b, c, d, e
225
sage: U.dim()
226
5
227
"""
228
return len(self._coordinates)
229
230
231
def _repr_(self):
232
r"""
233
Return string representation of this coordinate patch.
234
235
EXAMPLES::
236
237
sage: x, y, z = var('x, y, z')
238
sage: S = CoordinatePatch((x, y, z)); S
239
Open subset of R^3 with coordinates x, y, z
240
sage: S._repr_()
241
'Open subset of R^3 with coordinates x, y, z'
242
sage: S.rename('coordinate patch'); S
243
coordinate patch
244
sage: S.rename(); S
245
Open subset of R^3 with coordinates x, y, z
246
"""
247
return r"Open subset of R^%s with coordinates %s" % \
248
(self.dim(), ', '.join([x._latex_() for x in self._coordinates]))
249
250
251
def _latex_(self):
252
r"""
253
Return latex representation of this coordinate patch.
254
255
EXAMPLES::
256
257
sage: x, y, z = var('x, y, z')
258
sage: S = CoordinatePatch((x, y, z)); S
259
Open subset of R^3 with coordinates x, y, z
260
sage: latex(S)
261
\mathbb{\RR}^3
262
sage: latex(S) == S._latex_()
263
True
264
"""
265
return "\\mathbb{\RR}^%s" % self.dim()
266
267
268
269