Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/tensor/differential_forms.py
4036 views
1
r"""
2
Algebra of differential forms
3
4
Algebra of differential forms defined on a CoordinatePatch (an open subset of
5
Euclidian space, see ``CoordinatePatch`` for details).
6
7
AUTHORS:
8
9
- Joris Vankerschaver (2010-05-26)
10
11
TODO:
12
13
- Allow for forms with values in a vector space
14
15
- Incorporate Kahler differentials
16
17
REFERENCES:
18
19
- R. Abraham, J. E. Marsden, and T. S. Ratiu: Manifolds, tensor analysis,
20
and applications. Springer-Verlag 1988, texts in Applied Mathematical
21
Sciences, volume 75, 2nd edition.
22
23
- http://en.wikipedia.org/wiki/Differential_form
24
25
"""
26
27
#*****************************************************************************
28
# Copyright (C) 2010 Joris Vankerschaver ([email protected])
29
#
30
# Distributed under the terms of the GNU General Public License (GPL)
31
#
32
# This code is distributed in the hope that it will be useful,
33
# but WITHOUT ANY WARRANTY; without even the implied warranty of
34
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35
# General Public License for more details.
36
#
37
# The full text of the GPL is available at:
38
#
39
# http://www.gnu.org/licenses/
40
#*****************************************************************************
41
42
43
from sage.rings.ring import Algebra
44
from sage.tensor.coordinate_patch import CoordinatePatch
45
from sage.tensor.differential_form_element import DifferentialForm
46
from sage.symbolic.ring import SR, var
47
48
49
50
class DifferentialForms(Algebra):
51
"""
52
The algebra of all differential forms on an open subset of Euclidian space
53
of arbitrary dimension.
54
55
EXAMPLES:
56
57
To define an algebra of differential forms, first create a coordinate
58
patch::
59
60
sage: p, q = var('p, q')
61
sage: U = CoordinatePatch((p, q)); U
62
Open subset of R^2 with coordinates p, q
63
sage: F = DifferentialForms(U); F
64
Algebra of differential forms in the variables p, q
65
66
If no coordinate patch is supplied, a default one (using the variables
67
x, y, z) will be used::
68
69
sage: F = DifferentialForms(); F
70
Algebra of differential forms in the variables x, y, z
71
72
"""
73
74
Element = DifferentialForm
75
76
def __init__(self, coordinate_patch = None):
77
"""
78
Construct the algebra of differential forms on a given coordinate patch.
79
See ``DifferentialForms`` for details.
80
81
INPUT::
82
83
- ``coordinate_patch`` -- Coordinate patch where the algebra lives.
84
If no coordinate patch is given, a default coordinate patch with
85
coordinates (x, y, z) is used.
86
87
EXAMPLES::
88
89
sage: p, q = var('p, q')
90
sage: U = CoordinatePatch((p, q)); U
91
Open subset of R^2 with coordinates p, q
92
sage: F = DifferentialForms(U); F
93
Algebra of differential forms in the variables p, q
94
95
"""
96
97
from sage.categories.graded_algebras_with_basis \
98
import GradedAlgebrasWithBasis
99
from sage.structure.parent_gens import ParentWithGens
100
101
if not coordinate_patch:
102
x, y, z = var('x, y, z')
103
coordinate_patch = CoordinatePatch((x, y, z))
104
105
if not isinstance(coordinate_patch, CoordinatePatch):
106
raise TypeError, \
107
"%s not a valid Coordinate Patch" % coordinate_patch
108
self._patch = coordinate_patch
109
110
ParentWithGens.__init__(self, SR, \
111
category = GradedAlgebrasWithBasis(SR))
112
113
114
def __eq__(self, other):
115
"""
116
Return True if self is equal to other.
117
118
EXAMPLES::
119
120
sage: x, y, z = var('x, y, z')
121
sage: U = CoordinatePatch((x, y, z)); U
122
Open subset of R^3 with coordinates x, y, z
123
sage: F = DifferentialForms(U); F
124
Algebra of differential forms in the variables x, y, z
125
sage: p, q = var('p, q')
126
sage: V = CoordinatePatch((p, q)); V
127
Open subset of R^2 with coordinates p, q
128
sage: G = DifferentialForms(V); G
129
Algebra of differential forms in the variables p, q
130
sage: H = DifferentialForms(U); H
131
Algebra of differential forms in the variables x, y, z
132
sage: F == G
133
False
134
sage: F == H
135
True
136
"""
137
138
if type(other) == type(self):
139
return self._patch == other._patch
140
else:
141
return False
142
143
144
def __ne__(self, other):
145
"""
146
Return True if self is not equal to other.
147
148
EXAMPLES::
149
150
sage: x, y, z = var('x, y, z')
151
sage: U = CoordinatePatch((x, y, z)); U
152
Open subset of R^3 with coordinates x, y, z
153
sage: F = DifferentialForms(U); F
154
Algebra of differential forms in the variables x, y, z
155
sage: p, q = var('p, q')
156
sage: V = CoordinatePatch((p, q)); V
157
Open subset of R^2 with coordinates p, q
158
sage: G = DifferentialForms(V); G
159
Algebra of differential forms in the variables p, q
160
sage: F != G
161
True
162
"""
163
164
return not self.__eq__(other)
165
166
167
168
def ngens(self):
169
"""
170
Return the number of generators of this algebra.
171
172
EXAMPLES::
173
174
sage: x, y, z = var('x, y, z')
175
sage: U = CoordinatePatch((x, y, z)); U
176
Open subset of R^3 with coordinates x, y, z
177
sage: F = DifferentialForms(U); F
178
Algebra of differential forms in the variables x, y, z
179
sage: F.ngens()
180
3
181
"""
182
return len(self._patch.coordinates())
183
184
185
def gen(self, i=0):
186
"""
187
Return the `i^{th}` generator of ``self``. This is a one-form,
188
more precisely the exterior derivative of the i-th coordinate.
189
190
INPUT:
191
192
- ``i`` - integer (optional, default 0)
193
194
195
EXAMPLES::
196
197
sage: x, y, z = var('x, y, z')
198
sage: U = CoordinatePatch((x, y, z)); U
199
Open subset of R^3 with coordinates x, y, z
200
sage: F = DifferentialForms(U); F
201
Algebra of differential forms in the variables x, y, z
202
sage: F.gen(0)
203
dx
204
sage: F.gen(1)
205
dy
206
sage: F.gen(2)
207
dz
208
209
"""
210
211
form = DifferentialForm(self, 0, self._patch.coordinate(i))
212
return form.diff()
213
214
215
def gens(self):
216
"""
217
Return a list of the generators of ``self``.
218
219
EXAMPLES::
220
221
sage: x, y, z = var('x, y, z')
222
sage: U = CoordinatePatch((x, y, z)); U
223
Open subset of R^3 with coordinates x, y, z
224
sage: F = DifferentialForms(U); F
225
Algebra of differential forms in the variables x, y, z
226
sage: F.gens()
227
(dx, dy, dz)
228
229
"""
230
231
return tuple(self.gen(n) for n in xrange(0, self._patch.dim()))
232
233
234
def base_space(self):
235
"""
236
Return the coordinate patch on which this algebra is defined.
237
238
EXAMPLES::
239
240
sage: x, y, z = var('x, y, z')
241
sage: U = CoordinatePatch((x, y, z)); U
242
Open subset of R^3 with coordinates x, y, z
243
sage: F = DifferentialForms(U); F
244
Algebra of differential forms in the variables x, y, z
245
sage: F.base_space()
246
Open subset of R^3 with coordinates x, y, z
247
"""
248
return self._patch
249
250
251
def _element_constructor_(self, fun):
252
"""
253
Coerce a given function (element of the symbolic ring)
254
into a differential form of degree zero.
255
256
EXAMPLES::
257
258
sage: x, y, z = var('x, y, z')
259
sage: U = CoordinatePatch((x, y, z))
260
sage: F = DifferentialForms(U); F
261
Algebra of differential forms in the variables x, y, z
262
sage: F(sin(x*y)) # indirect doctest
263
sin(x*y)
264
265
"""
266
267
268
fun = SR(fun)
269
if fun not in self:
270
raise ValueError, \
271
"Function not an element of this algebra of differential forms."
272
273
return DifferentialForm(self, 0, fun)
274
275
276
def __contains__(self, element):
277
"""
278
Check if a given element belongs to this algebra of differential forms.
279
280
EXAMPLES::
281
282
sage: x, y, p, q = var('x, y, p, q')
283
sage: U = CoordinatePatch((x, y)); U
284
Open subset of R^2 with coordinates x, y
285
sage: F = DifferentialForms(U); F
286
Algebra of differential forms in the variables x, y
287
sage: x in F
288
True
289
sage: sin(y) in F
290
True
291
sage: p in F
292
False
293
sage: cos(q) in F
294
False
295
"""
296
297
parent = None
298
try:
299
parent = element.parent()
300
except AttributeError:
301
pass
302
303
if parent == self:
304
return True
305
306
if parent == SR:
307
for coordinate in element.variables():
308
if coordinate not in self._patch.coordinates():
309
return False
310
return True
311
312
return False
313
314
315
def _coerce_map_from_(self, S):
316
"""
317
Only the symbolic ring coerces into the algebra of differential forms.
318
319
EXAMPLES::
320
321
sage: F = DifferentialForms(); F
322
Algebra of differential forms in the variables x, y, z
323
sage: F._coerce_map_from_(SR)
324
True
325
sage: F._coerce_map_from_(F)
326
True
327
sage: F._coerce_map_from_(CC)
328
False
329
sage: F._coerce_map_from_(RR)
330
False
331
332
"""
333
return S is SR or S is self
334
335
336
def _repr_(self):
337
r"""
338
String representation of this algebra of differential forms.
339
340
EXAMPLES::
341
342
sage: x, y, z = var('x, y, z')
343
sage: U = CoordinatePatch((x, y, z)); U
344
Open subset of R^3 with coordinates x, y, z
345
sage: F = DifferentialForms(U); F
346
Algebra of differential forms in the variables x, y, z
347
sage: F._repr_()
348
'Algebra of differential forms in the variables x, y, z'
349
"""
350
351
from string import join
352
return "Algebra of differential forms in the variables " + \
353
', '.join([str(var) for var in self._patch.coordinates()])
354
355
356
def _latex_(self):
357
r"""
358
Latex representation of this algebra of differential forms.
359
360
EXAMPLES::
361
362
sage: x, y, z = var('x, y, z')
363
sage: U = CoordinatePatch((x, y, z)); U
364
Open subset of R^3 with coordinates x, y, z
365
sage: F = DifferentialForms(U); F
366
Algebra of differential forms in the variables x, y, z
367
sage: latex(F)
368
\Omega^\ast(\mathbb{\RR}^3)
369
sage: latex(F) == F._latex_()
370
True
371
"""
372
373
return "\\Omega^\\ast(\mathbb{\\RR}^%s)" % self._patch.dim()
374
375