-
Notifications
You must be signed in to change notification settings - Fork 6
/
xTerior.wl
2438 lines (1707 loc) · 89.6 KB
/
xTerior.wl
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
(* ::Package:: *)
(*
xTerior
Exterior Calculus for xAct
Alfonso Garc\[IAcute]a-Parrado
Universidad de C\[OAcute]rdoba, Spain
Leo C. Stein
U of MS, MS, United States
(c) 2013-2019, under GPL
http://www.xAct.es/
http://groups.google.com/group/xAct
https://github.com/xAct-contrib
xTerior is a package for exterior calculus in xAct.
xTerior is distributed under the GNU General Public License, and runs on top of xTensor and xCoba which are free packages for fast
manipulation of abstract and component tensor expressions. All packages can be downloaded from http://www.xact.es/
*)
(* ::Input::Initialization:: *)
xAct`xTerior`$xTensorVersionExpected = {"1.1.2", {2015, 8, 23}};
xAct`xTerior`$Version = {"0.9.1", {2019, 5, 17}};
(******************************************************************************)
(********************* 1. Initialization **************************************)
(******************************************************************************)
(************************ 1.1 GPL *********************************************)
(* xTerior: exterior calculus in Differential Geometry *)
(* Copyright (C) 2013-2019 Alfonso Garcia-Parrado Gomez-Lobo and Leo C. Stein *)
(* 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.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place-Suite 330, Boston, MA 02111-1307, USA.
*)
(*********************** 1.2 Info Package ************************************)
(* :Title: xTerior *)
(* :Author: Alfonso Garcia-Parrado Gomez-Lobo and Leo C. Stein *)
(* :Summary: exterior calculus in Differential Geometry *)
(* :Brief Discussion:
- xTerior extends xAct to work with differentiable forms in general manifolds.
- Introduces the exterior algebra, the exterior derivative, the Hodge dual, the connection and curvature forms for\.07\.14\.07 an arbitrary connection, the exterior covariant derivative.
*)
(* :Context: xAct`xTerior` *)
(* :Package Version: 0.9.1 *)
(* :Copyright: Alfonso Garcia-Parrado Gomez-Lobo and Leo C. Stein (2013-2019) *)
(* :History: See xTerior.History *)
(* :Keywords: *)
(* :Source: xTerior.nb *)
(* :Warning: *)
(* :Mathematica Version: 9.0 and later *)
(* :Limitations:
- ?? *)
(*********************** 1.3 BeginPackage *********************************)
With[{
xAct`xTerior`Private`xTeriorSymbols =
DeleteCases[
Join[
Names[
"xAct`xTerior`*"
],
Names[
"xAct`xTerior`Private`*"
]
], "$Version" | "xAct`xTerior`$Version" | "$xTensorVersionExpected" | "xAct`xTerior`$xTensorVersionExpected"
]
},
Unprotect /@ xAct`xTerior`Private`xTeriorSymbols;
Clear /@ xAct`xTerior`Private`xTeriorSymbols;
]
If[Unevaluated[xAct`xCore`Private`$LastPackage] === xAct`xCore`Private`$LastPackage, xAct`xCore`Private`$LastPackage = "xAct`xTerior`"];
(* Temporary fix for the conflicts with Wolfram 14.1 *)
xAct`xTerior`Diff;
(* Explicit (not hidden) import of xTensor, xPerm and xCore: Alfonso: do we need xCoba ? *)
BeginPackage["xAct`xTerior`", {"xAct`xCoba`", "xAct`xTensor`", "xAct`xPerm`", "xAct`xCore`"}]
If[Not @ OrderedQ @ Map[
Last, {
xAct`xTerior`$xTensorVersionExpected, xAct`xTensor`$Version
}
],
Throw @ Message[
General::versions, "xTensor", xAct`xTensor`$Version, xAct`xTerior`$xTensorVersionExpected
]
]
Print[xAct`xCore`Private`bars]
Print["Package xAct`xTerior` version ", xAct`xTerior`$Version[[1]], ", ", xAct`xTerior`$Version[[2]]];
Print["Copyright (C) 2013-2019, Alfonso Garcia-Parrado Gomez-Lobo and Leo C. Stein, under the General Public License."];
Off[General::shdw]
xAct`xTerior`Disclaimer[] := Print["These are points 11 and 12 of the General Public License:\n\n
BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM `AS IS\.b4
WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.
SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO
MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM
TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES."]
On[General::shdw]
(* If xTerior is not being called from other package then write this GPL short disclaimer: *)
If[xAct`xCore`Private`$LastPackage === "xAct`xTerior`",
Unset[
xAct`xCore`Private`$LastPackage
];
Print[
xAct`xCore`Private`bars
];
Print[
"These packages come with ABSOLUTELY NO WARRANTY; for details type Disclaimer[]. This is free software, and you are welcome to redistribute it under certain conditions. See the General Public License for details."
];
Print[
xAct`xCore`Private`bars
]
]
(************************* 1.4. Non-standard setup ***********************************)
(* Screen all dollar indices: *)
$PrePrint = ScreenDollarIndices;
(* Switch off messages issued by ManifoldOfCovD acting on PD. *)
Unprotect @ PD;
PD /: ManifoldOfCovD @ PD = .
Protect @ PD;
(***************************** 1.5. Usage messages ********************************************)
(* Definition and undefinition of a differential form (just a wrapper for DefTensor with the option GradeOfTensor\[Rule]{Wedge})*)
DefDiffForm::usage = "DefDiffForm[form[inds], mani, Deg] defines a tensor valued differential form of degree deg on the manifold mani";
UndefDiffForm::usage = "UndefDiffForm[form] undefines the differential form form";
(* Grade of a differential form *)
Deg::usage = "Deg[form] returns the grade of a differential form";
DiffFormQ::usage = "DiffFormQ is an option for LieToCovD which specifies whether the expression which is acted
upon should be regarded as a differential form or not. This is an option added by xTerior and it is not present any other package using LieToCovD.";
(* Exterior derivative and exterior covariant derivative *)
Diff::usage="Diff[form] computes the exterior derivative of form. Diff[form,covd] computes the exterior
covariant derivative of form with respect to the covariant derivative covd.";
FindPotential::usage = "FindPotential[form, point, chart] uses the Poincar\[EAcute]
lemma to compute a potential for a closed form form (no checks are carried out to ensure that the form is actually closed).
The form must be written in some explicit coordinates belonging to chart
and the argument point is the point, assumed to be in the same coordinate chart as form, which defines a star-shaped region
where the potential is differentiable. A change in the point will give
in general a different potential";
(* Computation of the exterior covariant derivative *)
ChangeExtD::usage = "ChangeExtD[expr, cd1, cd2] expresses the exterior covariant derivative taken
with respect to the connection defined by the covariant derivative cd1 in terms of the exterior
covariant derivative taken with respect to the connection defined by the covariant derivative cd2";
(* Computation of the generalized (index-free) covariant derivative *)
ChangeGenCovD::usage = "ChangeGenCovD[expr,cd1,cd2] expresses the generalized covariant derivative taken with respect
to the connection defined by the covariant derivative cd1 in terms of the
generalized covariant derivative taken with respect to the connection defined by the covariant derivative cd2";
(* Hodge dual *)
Hodge::usage = "Hodge[metric][expr] is the Hodge dual of expr defined with respect to metric";
ExpandHodgeDual::usage="ExpandHodgeDual[expr,Coframe[mani],g] expands out all the Hodge duals of the exterior powers of Coframe[mani],
defined with respect to the metric g. If the manifold tag
mani is dropped, then all the instances of Coframe are expanded. The Coframe label can be replaced by dx if we are using the holonomic coframe.";
(* Co-differential *)
Codiff::usage = "Codiff[metric][form] is the co-differential of form computed with respect to metric";
(* Expansion of the co-differential *)
CodiffToDiff::usage = "CodiffToDiff[expr] replaces all the instances of the co-differential in expr by their expansion in terms of the exterior derivative.";
(* Interior contraction *)
Int::usage = "Int[v][form] is the interior contraction of form with the vector (rank 1-tensor) v";
(* Lie derivative on forms *)
CartanD::usage = "CartanD[v][form] is the Cartan derivative of form with respect to the vector (rank 1-tensor) v. CartanD[v][form,covd] is the Cartan derivative with respect to the covariant derivative covd.";
(* Cartan formula for Lie derivatives *)
CartanDToDiff::usage = "CartanDToDiff[expr] replaces the Cartan derivative of all the differential forms in expr by their expansion obtained by means of the Cartan formula";
(* Put derivations into canonical order *)
SortDerivations::usage = "SortDerivations[expr] brings expr into a new expression where all the derivations
(exterior derivative, Lie derivative and interior contraction) are written in a canonical order. The default left-to-right order is defined by the variable $DerivationSortOrder";
$DerivationSortOrder::usage="$DerivationSortOrder is a global variable which encodes the default ordering of the three derivatives Int, LieD and Diff. The default is {LieD, Int, Diff}";
(* Variational derivative on forms *)
FormVarD::usage = "FormVarD[form,metric][expr] computes the variational derivative of expr, which must be a n-form with n the manifold dimension, with respect to form.
In the computation, exterior derivatives are transformed into co-differentials taken with respect of metric.";
(* Canonical forms on the frame bundle *)
Coframe::usage = "Coframe[mani] is the set of canonical 1-forms defined in the frame bundle arising from the manifold mani";
dx::usage = "dx[mani] represents a holonomic co-frame in the manifold mani.";
(* Holonomic & anholonomic frames *)
PDFrame::usage = "PDFrame[mani] represents a holonomic frame in the manifold mani.";
eFrame::usage = "eFrame[mani] represents a frame in the manifold mani.";
(* Koszul connection *)
Koszul::usage = "Koszul is the head used to introduce the Koszul operator. The latter is constructed by prepending this head to the xTensor symbol used to represent a covariant derivative";
ExpandKoszul::usage="ExpandKoszul[expr,cd1,cd2] expands Koszul derivations of frame or co-frame elements with respect to cd1 into Christoffel tensors relating the covariant
derivatives cd1 and cd2";
ExpandCovD::usage="ExpandCovD[expr,cd,chart] expands all the generalized covariant derivatives of rank 1 tensors in terms of the Koszul derivatives with respect to elements
of a holonomic frame associated to a coordinate chart";
(* The connection 1-form *)
ConnectionForm::usage = "ConnectionForm[cd,vbundle] represents the connection 1-form associated
to the covariant derivatives cd defined in the bundle vbundle. If vbundle is the tangent bundle of a differentiable manifold then ConnectionForm is automatically
replaced by ChristoffelForm (see
the on-line help of ChristoffelForm for further details).";
(* The curvature 2-form *)
CurvatureForm::usage = "CurvatureForm[cd,vbundle] represents the curvature 2-form associated to the covariant derivative cd. If vbundle is the tangent bundle of a differentiable manifold then
CurvatureForm is replaced by RiemannForm";
(* Connection 2-form for a connection in a frame bundle*)
ChristoffelForm::usage="ChristoffelForm[cd] is the connection 1-form associated to the covariant derivative cd which is a covariant derivative in the tangent bundle of a manifold";
(* Curvature 2-form for a connection in a frame bundle *)
RiemannForm::usage = "RiemannForm[cd] is the curvature 2-form associated to the covariant derivative cd which is a covariant derivative in the frame bundle of a manifold";
(* Transformation of the connection form to the connection tensor *)
ConnectionFormToTensor::usage = "ConnectionFormToTensor[expr,covd,frame] transforms all instances of the connection form into the (A)Christoffel tensor which relates the covariant derivative
defining the connection form and covd. The variable frame can take the value of either Coframe or dx. If the (A)Christoffel tensor does not exist it is created automatically.";
CurvatureFormToTensor::usage="CurvatureFormToTensor[expr,frame] transforms all the instances of the curvature form into the related Riemann or FRiemann tensor, inserting the corresponding frame
(either Coframe or dx).";
ChangeCurvatureForm::usage = "ChangeCurvatureForm[curvature, cd1, cd2] writes the curvature 2-form curvature[cd1, vbundle] in terms of the curvature 2-form curvature[cd2, vbundle]";
(* The torsion 2-form *)
TorsionForm::usage = "TorsionForm[cd] represents the torsion 2-form arising from the covariant derivative cd (cd must be defined on the tangent bundle of a manifold)";
(* Cartan structure equations *)
UseCartan::usage = "UseCartan[expr, covd] expands all the instances of the Diff using the Cartan structure equations for the connection arising from covd.
In this way it is possible to expand the exterior derivative of a co-frame, a torsion 2-form and the curvature 2-form. If covd is the Levi-Civita connection of a metric, then the exterior
derivatives of that metric and its volume element are expanded too. UseCartan[expr,PD] expands all instances of the exterior derivative in terms of partial derivatives defined in the list of
manifolds returned by ManifoldsOf[expr]. It is possible to specify a custom list of manifolds as a third argument in the form UseCartan[expr,PD,{M1,M2,..}]";
(* Zero forms *)
ZeroDegQ::usage = "ZeroDegQ[expr] returns True if the degree of expr is zero";
UseDimensionStart::usage = "UseDimensionStart[] is an instruction that, when issued,
makes any expression with degree greater than the manifold dimension equal to zero.";
UseDimensionStop::usage = "UseDimensionStop[] cancels the action of UseDimensionStart[]";
(* Integration of differential forms over manifolds with boundary *)
FormIntegrate::usage = "FormIntegrate[form, M] represents the integration of the given differential form, of degree n, over the n-dimensional manifold M with boundary.";
UseStokes::usage="UseStokes[expr, M] converts subexpressions FormIntegrate[Diff[form], M] in expr into FormIntegrate[form, ManifoldBoundary[M]],
reducing n-dimensional integration to (n-1)-
integration. UseStokes[expr, form] converts subexpressions FormIntegrate[form, ManifoldBoundary[M]] in expr into FormIntegrate[Diff[form], M]. UseStokes[expr] performs UseStokes[expr, M] wherever
possible in expr, to reduce dimensionality of integration.";
(************************************** 1.6 BeginPrivate *********************************)
Begin["`Private`"]
(******************************************************************************)
(********************* 2. Basic structures ************************************)
(******************************************************************************)
(***************** 2.1 Definition of the wedge product ************************)
(*
The wedge product is an associative, anticommutative (actually supercommutative) graded product with identity 1.
The scalars are those objects of grade 0, including the identity 1, so that the scalars are actually
in this case true elements of the algebra. The product by scalar and the product of scalars are both Times,
so we do not need to specify them.
*)
DefProduct[Wedge,
AssociativeProductQ -> True,
CommutativityOfProduct -> "SuperCommutative",
GradedProductQ -> True,
IdentityElementOfProduct -> 1,
ScalarsOfProduct -> (SameQ[Grade[#, Wedge], 0]&),
DefInfo -> Null
];
(* Relation between Wedge and Times. *)
Wedge /: GradeOfProduct[Times, Wedge] = 0;
(* When working with the exterior algebra the grade is typically called degree: *)
Deg[expr_] := Grade[expr, Wedge];
(* Behavior of the wedge product with respect to Dagger *)
Unprotect @ Dagger;
Dagger @ expr_Wedge := Dagger /@ expr;
Protect @ Dagger;
(* Vanishing of forms whose degree is higher than the manifold(s) dimension. *)
(*Code added by Jos\[EAcute]*)
$UseDimensionsQ=False;
$DimensionsZeroForms = {};
SetZeroForm[form_] :=
If[GradeOfTensor[form, Wedge] > Plus@@ (DimOfManifold/@DependenciesOfTensor[form]),
form[___] = 0;
AppendTo[$DimensionsZeroForms, form]
];
UnsetZeroForm[form_]:=Unset[form[___]];
UseDimensionStart[] :=
Module[{},
If[$UseDimensionsQ,
Return[]
];
$UseDimensionsQ = True;
(*Forms whose degree is greater than the dimension*)
SetZeroForm /@ $Tensors;
(*Expressions which are wedge products*)
HoldPattern @ Wedge[expr__] :=
0 /; (Plus @@ (Grade[#, Wedge]& /@ {expr}) > (Plus @@ (DimOfManifold /@ Union @ Flatten[DependenciesOf /@ {expr}])));
(*Expressions which are exterior derivatives*)
HoldPattern @ Diff[expr_, PD] :=
0 /; (1 + Plus @@ (Grade[#, Wedge]& /@ {expr}) > (Plus @@ (DimOfManifold /@ DependenciesOf[expr])));
HoldPattern @ Diff[expr_, covd_] :=
0 /; (1 + Plus @@ (Grade[#, Wedge]& /@ {expr}) > (Plus @@ (DimOfManifold /@ DependenciesOf[expr])));
]
UseDimensionStop[] :=
Module[{},
If[!$UseDimensionsQ,
Return[]
];
$UseDimensionsQ = False;
UnsetZeroForm /@ Union @ $DimensionsZeroForms;
HoldPattern @ Wedge[expr__] = .;
HoldPattern @ Diff[expr_, PD] = .;
HoldPattern @ Diff[expr_, covd_] = .;
]
(* xTensions *)
xTension["xTerior`", DefTensor, "End"] :=
DefTensorUseDimensions;
DefTensorUseDimensions[tensor_[inds___], __] :=
If[$UseDimensionsQ,
SetZeroForm[tensor]
];
xTension["xTerior`", UndefTensor, "Beginning"] :=
UndefTensorUseDimensions;
UndefTensorUseDimensions[tensor_] :=
If[$UseDimensionsQ,
UnsetZeroForm[tensor]
];
(********************* 2.2 Integration of CTensor in Wedge **************************************)
(*
In this section we implement the Wedge product of CTensor objects. This code has been supplied by Jos\[EAcute] Mart\[IAcute]n-Garc\[IAcute]a.
*)
(* Grade of a CTensor with respect to Wedge *)
CTensor /: Grade[expr_CTensor, Wedge] :=
Module[{list, grades, comps = First @ expr},
list = Flatten[{comps}];
grades = Grade[#, Wedge]& /@ list;
If[Length @ Tally[grades] == 1,
grades[[1]],
$Failed
]
];
(* Contracted wedge product of CTensor objects *)
Wedge[ctensor1_CTensor[left1___, a_, right1___], ctensor2_CTensor[left2___, -a_, right2___]] :=
Module[{n1 = Length[{left1, a}], n2 = Length[{left2, -a}], res},
res = xAct`xCoba`Private`CTensorContract[ctensor1, ctensor2, {n1, n2}, Wedge];
res[left1, right1, left2, right2] /; FreeQ[res, $Failed]
];
Wedge[ctensor1_CTensor[left1___, -a_, right1___], ctensor2_CTensor[left2___, a_, right2___]] :=
Module[{n1 = Length[{left1, a}], n2 = Length[{left2, -a}], res},
res = xAct`xCoba`Private`CTensorContract[ctensor1, ctensor2, {n1, n2}, Wedge];
res[left1, right1, left2, right2] /; FreeQ[res, $Failed]
];
(* ::Input::Initialization:: *)
(*signatureOrZero[indices_]:=If[DuplicateFreeQ[indices],Signature[Ordering[indices]],0];*)
simplifyBasisWedge[expr_] :=
expr /. wed_Wedge :> simplifyBasisWedge1[wed];
(*simplifyBasisWedge1[HoldPattern[Wedge[factors:((head:((xAct`xTerior`Coframe|xAct`xTerior`dx)[_]))[_]..)]]]:=With[{indices=First/@{factors}},signatureOrZero[indices] Wedge@@(head/@Sort[indices])];*)
simplifyBasisWedge1[HoldPattern[expr:Wedge[factors:Blank[]..]]] :=
Module[{indices = FindFreeIndices[expr]},
If[indices === IndexList[],
expr,
$Failed
]
];
(* Wedge product of general CTensor objects *)
CTensorWedge[] :=1;
CTensorWedge[ctensors__CTensor] :=
CTensor[simplifyBasisWedge[xAct`xCoba`Private`tensorproduct[Wedge] @@ #1], Join @@ #2, Plus @@ #3]& @@ Transpose[List @@@ {ctensors}];
CTensorWedge[___, Zero, ___] :=Zero;
Wedge[ctensor1_CTensor[inds1___], ctensor2_CTensor[inds2___]] :=
CTensorWedge[ctensor1, ctensor2][inds1, inds2] /; xAct`xTensor`Private`TakePairs[
{inds1, inds2}] === {}
Wedge[ctensor1_CTensor, ctensor2_CTensor] := CTensorWedge[ctensor1, ctensor2]
(* Wedge product of frame and co-frame with CTensor objects. We first have a definition for Coframe with c - indices, avoiding the use of ToCTensor : *)
Wedge[basis: (Coframe | dx)[_][_?CIndexQ], CTensor[array_, bases_List, addweight_][b__]] :=
CTensor[Wedge[basis, array], bases, addweight][b]
Wedge[CTensor[array_, bases_List, addweight_][b__], basis:(Coframe | dx)[_][_?CIndexQ]] :=
CTensor[Wedge[array, basis], bases, addweight][b]
(* Then we have another definition for the general case of Wedge, in which the Coframes inside the CTensor uniquely identify the frame to use in ToCTensor : *)
FormBases[CTensor[array_, __]] :=
DeleteDuplicates[xAct`xPerm`Private`nosign /@ Cases[array, (Coframe | dx)[_][{_, frame_}] :> frame, {0, Infinity}]]
Wedge[(basis:(Coframe | dx)[_])[ind_], ctensor_CTensor[inds___]] :=
With[{frames = FormBases[ctensor]},
Wedge[ToCTensor[basis, frames][ind], ctensor[inds]] /; Length[frames] === 1
]
Wedge[ctensor_CTensor[inds___], (basis:(Coframe | dx)[_])[ind_]] :=
With[{frames = FormBases[ctensor]},
Wedge[ctensor[inds], ToCTensor[basis, frames][ind]] /; Length[frames] === 1
]
(* Finally we need another definition for the case in which the CTensor is a 0 - form : *)
CTensor /: (basis:(Coframe | dx)[_])[a_] (ctensor:CTensor[_, bases_List, _][l___, -a_, ___]) :=
ToCTensor[basis, {-bases[[Length[{l, -a}]]]}][a] ctensor
CTensor /: HoldPattern[Wedge[lw___, (basis:(Coframe | dx)[_])[a_], rw___] (ctensor:CTensor[_, bases_List, _][l___, -a_, ___])] :=
Wedge[lw, ToCTensor[basis, {-bases[[Length[{l, -a}]]]}][a], rw] ctensor
(* Wedge product of index free quantities with CTensor objects: *)
Wedge[ten_, CTensor[array_, bases_List, addweight_][b__]] :=
CTensor[Wedge[ten, array], bases, addweight][b] /; FindFreeIndices @ ten === IndexList[]
Wedge[CTensor[array_, bases_List, addweight_][b__], ten_] :=
CTensor[Wedge[array, ten], bases, addweight][b] /; FindFreeIndices @ ten === IndexList[]
(************************** 2.3 Definition of the CircleTimes product ****************************)
(* By default we define the CircleTimes "\[CircleTimes]" product. *)
$DefInfoQ = False;
DefProduct[
CircleTimes,
AssociativeProductQ -> True,
IdentityElementOfProduct -> 1,
GradedProductQ -> True,
ScalarsOfProduct -> (
SameQ[Grade[#,CircleTimes],0]&
),
PrintAs -> "\[CircleTimes]"
]
$DefInfoQ = True;
(* Grade of CircleTimes with respect to Times *)
CircleTimes /: GradeOfProduct[Times, CircleTimes] = 0;
(* Exterior algebra grade and tensor grade should coincide on elementary objects: *)
CircleTimes /: GradeOfTensor[head_, CircleTimes] := GradeOfTensor[head, Wedge];
(* We also need to specify the Grade of the inert - head expressions : *)
CircleTimes /: Grade[Diff[expr_, _], CircleTimes] := Grade[expr, CircleTimes] + 1;
CircleTimes /: Grade[Hodge[metricg_][expr_], CircleTimes] := DimOfVBundle[VBundleOfMetric[metricg]] - Grade[expr, CircleTimes];
(* Behavior with respect to Dagger *)
Unprotect @ Dagger;
Dagger @ expr_CircleTimes := Dagger /@ expr;
Protect @ Dagger;
(*
The CircleTimes - grade of a form coincides with the Wedge - grade of that form.
However, the Wedge - grade is not well defined for generic expressions having positive CircleTimes - grade unless they are forms.
That is why we have given CircleTimes - grade in terms of Wedge - grade and not viceversa.There is no general way in which we can know
the relations between the grades of a given expression in several products.The user must define carefully the relations.
Usually it is safer to declare independently the grades in each product.
Recall that objects for which a grade has not been given are taken to have degree 0.
*)
(********************** 2.4 Integration of CTensor in CircleTimes **************************************)
(* Grade of a CTensor with respect to CircleTimes *)
CTensor /: Grade[expr_CTensor, CircleTimes] :=
Module[{list, grades, comps = First @ expr},
list = Flatten[{comps}];
grades = Grade[#, CircleTimes]& /@ list;
If[Length @ Tally[grades] == 1,
grades[[1]],
$Failed
]
];
(* Algebra with unit element *)
xAct`xCoba`Private`tensorproduct[CircleTimes][] = 1;
(* Contracted CircleTimes product of CTensor objects *)
CircleTimes[ctensor1_CTensor[left1___, a_, right1___], ctensor2_CTensor[left2___, -a_, right2___]] :=
Module[{n1 = Length[{left1, a}], n2 = Length[{left2, -a}], res},
res = xAct`xCoba`Private`CTensorContract[ctensor1, ctensor2, {n1, n2}, CircleTimes];
res[left1, right1, left2, right2] /; FreeQ[res, $Failed]
];
CircleTimes[ctensor1_CTensor[left1___, -a_, right1___], ctensor2_CTensor[left2___, a_, right2___]] :=
Module[{n1 = Length[{left1, a}], n2 = Length[{left2, -a}], res},
res = xAct`xCoba`Private`CTensorContract[ctensor1, ctensor2, {n1, n2}, CircleTimes];
res[left1, right1, left2, right2] /; FreeQ[res, $Failed]
];
(* CircleTimes product of General CTensor objects *)
simplifyBasisCircleTimes[expr_] :=
expr /. wed_CircleTimes :> simplifyBasisCircleTimes1[wed];
simplifyBasisCircleTimes1[HoldPattern[expr:CircleTimes[factors:Blank[]..]]] :=
Module[{indices = FindFreeIndices[expr]},
If[indices === IndexList[],
expr,
$Failed
]
];
(* CircelTimes product of general CTensor objects *)
CTensorCircleTimes[] :=1;
CTensorCircleTimes[ctensors__CTensor] :=
CTensor[simplifyBasisCircleTimes[xAct`xCoba`Private`tensorproduct[CircleTimes] @@ #1], Join @@ #2, Plus @@ #3]& @@ Transpose[List @@@ {ctensors}];
CTensorCircleTimes[___, Zero, ___] :=Zero;
CircleTimes[ctensor1_CTensor[inds1___], ctensor2_CTensor[inds2___]] :=
CTensorCircleTimes[ctensor1, ctensor2][inds1, inds2] /; xAct`xTensor`Private`TakePairs[{inds1, inds2}] === {}
CircleTimes[ctensor1_CTensor, ctensor2_CTensor] :=
CTensorCircleTimes[ctensor1, ctensor2]
(* CircleTimes product of index free quantities with CTensor objects: *)
CircleTimes[ten_, CTensor[array_, bases_List, addweight_][b__]] := CTensor[CircleTimes[ten, array], bases, addweight][b] /; FindFreeIndices @ ten === IndexList[]
CircleTimes[CTensor[array_, bases_List, addweight_][b__], ten_] := CTensor[CircleTimes[array, ten], bases, addweight][b] /; FindFreeIndices @ ten === IndexList[]
(**************** 2.5 Definition and undefinition of differential forms *****************************)
(* Definition and undefinition of differential forms. This is simply DefTensor with the appropriate options *)
DefDiffForm[form_, mani_, deg_, options___?OptionQ] :=
(
DefTensor[form, mani, GradeOfTensor -> {Wedge -> deg}, options];
)
DefDiffForm[form_, mani_, deg_, sym_, options___?OptionQ] :=
(
DefTensor[form, mani, sym, GradeOfTensor -> {Wedge -> deg}, options
];
)
Options @ DefDiffForm := Options @ DefTensor;
UndefDiffForm := UndefTensor;
Protect[DefDiffForm, UndefDiffForm];
(****************** 2.6 Graded derivations *************************)
(* This function will be used to declare the three derivations we need, namely diff, Int[v] and lie[v]. *)
Options[DefGradedDerivation] = {PrintAs -> Identity, Master -> Null};
GradeOfDerivation[head_[v_, rest___], prod_] := GradeOfDerivation[head, prod] + Grade[v, prod];
DefGradedDerivation[der_, prod_?ProductQ, dergrade_:0, options:OptionsPattern[]] :=
With[{head = SubHead[der]},
Module[{pa},
{pa} = OptionValue[{PrintAs}];
(* DefInertHead will take care of scalar-homogeneity and linearity *)
DefInertHead[der, LinearQ -> True, ContractThrough -> {delta}, PrintAs-> pa, DefInfo -> Null];
(* Other properties of a derivation *)
MakeDerivation[head, der, NoPattern[der], prod, dergrade];(* Nonatomic derivation *)
If[der =!= head,
(* additivity in the vector slot (but not homogeneity!) *)
head[0][__] := 0;
head[v_Plus][args__] := head[#][args]& /@ v;
(* Subscript vector argument for formatting *)
If[pa === Identity,
pa = PrintAs[head]
];
head /: MakeBoxes[head[v_][form_], StandardForm] :=
xAct`xTensor`Private`interpretbox[
head[v][form],
RowBox[{SubscriptBox[pa, MakeBoxes[v, StandardForm]], "[", MakeBoxes[form, StandardForm], "]"}]
];
]
]
];
(* This part is separated in order to avoid renaming confusion between derL and derR: *)
MakeDerivation[head_, derL_, derR_, prod_, dergrade_] :=
With[
{grade = GradeOfDerivation[derR, prod]},
(* Addition of grades in algebra *)
head /: GradeOfDerivation[head, prod] := dergrade;
head /: Grade[derL[expr_, ___], prod] := Grade[expr, prod] + grade;
(* The (graded) Leibniz rule *)
derL[expr_prod, rest___] :=
With[{sumgrades = FoldList[Plus, 0, Grade[#, Wedge]& /@ List @@ expr]},
Sum[(-1)^(grade * sumgrades[[i]]) MapAt[derR[#, rest]&, expr, i],
{i, 1, Length[expr]}]
];
(* QUESTION: Agreement with a regular derivative when acting on scalar functions?? *)
derL[func_?ScalarFunctionQ[args__], rest___] :=
xAct`xTensor`Private`multiD[derR[#, rest]&, func[args]];
(* Dependencies *)
If[!AtomQ[derR],
head /: DependenciesOfInertHead[derL] := DependenciesOf[First[derR]]
]
];
(*************** 2.7 Exterior differentiation ********************)
(* The second key ingredient for exterior algebra is the differential operator.
This a concept defined per manifold, or equivalently per tangent-bundle,
though in this notebook we create only one differential operator. *)
DefGradedDerivation[Diff, Wedge, +1, PrintAs -> "d"];
(* We always have PD as the covariant derivative. *)
Diff[expr_] := Diff[expr, PD]
(* Superscript formatting for covariant exterior derivatives *)
Diff /: MakeBoxes[Diff[form_, PD?CovDQ], StandardForm] :=
xAct`xTensor`Private`interpretbox[Diff[form, PD], RowBox[{PrintAs[Diff], "[", MakeBoxes[form, StandardForm], "]"}]];
Diff /: MakeBoxes[Diff[form_, cd_?CovDQ], StandardForm] :=
xAct`xTensor`Private`interpretbox[
Diff[form, cd], RowBox[{SuperscriptBox[PrintAs[Diff], Last @ SymbolOfCovD[cd]], "[", MakeBoxes[form, StandardForm], "]"}]
];
(* Thread over lists and equal *)
Diff[expr_?ArrayQ, cd_] := Diff[#, cd]& /@ expr;
Diff[expr_Equal, cd_] := Diff[#, cd]& /@ expr;
(* The exterior derivative applied twice is zero: *)
Diff[expr_Diff, PD] := 0
(* Exterior derivative of basis objects is zero. TODO: This is not correct. *)
Diff[_Basis, PD] := 0;
(* We still need definition when acting on Times *)
(* This produces expanded expressions and is much faster when there are many scalars *)
notZero = 0 =!= #&
Diff[expr_Times, cd_] :=
Module[{grades = Grade[#, Wedge]& /@ List @@ expr, pos, scalar, form
},
pos = Position[grades, _?notZero, 1, Heads -> False];
Which[
Length[pos] > 1,
Throw[
Message[Diff::error1, "Found Times product of nonscalar forms: ", expr]
],
Length[pos] === 1,
pos = pos[[1, 1]];
scalar = Delete[expr, {pos}];
form = expr[[pos]];
scalar Diff[form, cd] + diff0[scalar, cd, form],
Length[pos] === 0,
diff0[expr, cd]
]
];
(* Only scalars *)
diff0[scalar_Times, cd_] :=
Sum[MapAt[Diff[#, cd]&, scalar, i], {i, 1, Length[scalar]}];
diff0[scalar_, cd_] :=
Diff[scalar, cd];
(* Scalars and a form *)
diff0[scalar_Times, cd_, form_] :=
Sum[MapAt[diff0[#, cd, form]&, scalar, i], {i, 1, Length[scalar]}];
diff0[scalar_, cd_, form_] :=
Wedge[Diff[scalar, cd], form];
(* Exterior derivative of constants vanish *)
Diff[x_?ConstantQ, cd_] := 0;
(* Behavior with respect to Dagger. *)
Diff /: HoldPattern[Dagger[Diff[expr_, cd_]]] := Diff[Dagger[expr], cd];
(* Behaviour with respect to CTensor *)
Diff[CTensor[array_, bases_List, weight_][inds__], cd_] := CTensor[Diff[array, cd], bases, weight][inds];
(************ Introduction of co-frame, eFrame and PDFrame *************************)
(*
We create the non-atomic tensor \[Theta][M] representing a co-frame.
Note that the formatting does not contain the manifold as this information is already
visible in the abstract index. The abstract index may belong to the tangent space of the manifold "M" or
to any other vector bundle with base M. In the case of the abstract index belonging to TangentM we can think of
\[Theta][M] as the set of "canonical 1-forms".
*)
xTensorQ @ Coframe[mani_?ManifoldQ] ^= True;
SlotsOfTensor[Coframe[mani_?ManifoldQ]] ^:={Tangent @ mani};
Coframe /: GradeOfTensor[Coframe[mani_?ManifoldQ], Wedge] = 1;
SymmetryGroupOfTensor[Coframe[mani_?ManifoldQ]] ^= StrongGenSet[{}, GenSet[]];
DefInfo[Coframe[mani_?ManifoldQ]] ^= {"General co-frame", ""};
DependenciesOfTensor[Coframe[mani_?ManifoldQ]] ^:={mani};
HostsOf[Coframe[mani_?ManifoldQ]] ^= {};
TensorID[Coframe[mani_?ManifoldQ]] ^= {};
PrintAs[Coframe[mani_?ManifoldQ]] ^= "\[Theta]";
(* Holonomic Co-frame *)
xTensorQ @ dx[mani_?ManifoldQ] ^= True;
SlotsOfTensor[dx[mani_?ManifoldQ]] ^:={Tangent @ mani};
dx /: GradeOfTensor[dx[mani_?ManifoldQ], Wedge] = 1;
SymmetryGroupOfTensor[dx[mani_?ManifoldQ]] ^= StrongGenSet[{}, GenSet[]];
DefInfo[dx[mani_?ManifoldQ]] ^= {"General co-frame", ""};
DependenciesOfTensor[dx[mani_?ManifoldQ]] ^:={mani};
HostsOf[dx[mani_?ManifoldQ]] ^= {};
TensorID[dx[mani_?ManifoldQ]] ^= {};
PrintAs[dx[mani_?ManifoldQ]] ^= "dx";
(* Condition of the co-frame being holonomic. *)
Diff[dx[mani_?ManifoldQ][ind_], PD] := 0;
(* General frame: *)
xTensorQ @ eFrame[mani_?ManifoldQ] ^= True;
SlotsOfTensor[eFrame[mani_?ManifoldQ]] ^:= {-Tangent @ mani};
eFrame /: GradeOfTensor[eFrame[mani_?ManifoldQ], CircleTimes] = 1;
SymmetryGroupOfTensor[eFrame[mani_?ManifoldQ]] ^= StrongGenSet[{}, GenSet[]];
DefInfo[eFrame[mani_?ManifoldQ]] ^= {"General frame", ""};
DependenciesOfTensor[eFrame[mani_?ManifoldQ]] ^:= {mani};
HostsOf[eFrame[mani_?ManifoldQ]] ^= {};
TensorID[eFrame[mani_?ManifoldQ]] ^= {};
PrintAs[eFrame[mani_?ManifoldQ]] ^= "e";
(* General holonomic frame: *)
xTensorQ @ PDFrame[mani_?ManifoldQ] ^= True;
SlotsOfTensor[PDFrame[mani_?ManifoldQ]] ^:= {-Tangent @ mani};
PDFrame /: GradeOfTensor[PDFrame[mani_?ManifoldQ], CircleTimes] = 1;
SymmetryGroupOfTensor[PDFrame[mani_?ManifoldQ]] ^= StrongGenSet[{}, GenSet[]];
DefInfo[PDFrame[mani_?ManifoldQ]] ^= {"General frame", ""};
DependenciesOfTensor[PDFrame[mani_?ManifoldQ]] ^:= {mani};
HostsOf[PDFrame[mani_?ManifoldQ]] ^= {};
TensorID[PDFrame[mani_?ManifoldQ]] ^= {};
PrintAs[PDFrame[mani_?ManifoldQ]] ^= "\!\(\*FractionBox[\(\[PartialD]\),\(\[PartialD]x\)]\)";
(* xTensions *)
xTension["xTerior`",DefChart,"End"]:=setdiffs;
setdiffs[chartname_,__]:=Thread[ComponentValue[dx[ManifoldOfChart@chartname][{#,chartname}]&/@CNumbersOf@chartname,Diff/@ScalarsOfChart@chartname]];
xTension["xTerior`", DefChart, "End"] :=
defFreeAlgebraChart;
defFreeAlgebraChart[basis_, __] :=
With[{scalars = ScalarsOfChart[basis], numbers = CNumbersOf @ basis, mani = ManifoldOfChart @ basis},
(* Define the algebra elements forming the basis of the free algebra *)
MapThread[
DefTensor[
GiveSymbol[basis, Abs @ #1][],
mani,
PrintAs -> ColorString["\!\(\*FractionBox[\(\[PartialD]\), \(\[PartialD]" <> PrintAs[Evaluate @ (Head @ #2)] <> "\)]\)", BasisColor @ basis],
GradeOfTensor -> {CircleTimes -> 1},
Master -> basis
]&, {numbers, scalars}
];
(* Assign values *)
Thread[ComponentValue[dx[ManifoldOfChart @ basis][{#, basis}]& /@ CNumbersOf @ basis, Diff /@ ScalarsOfChart @ basis]];
Thread[ComponentValue[PDFrame[mani][{#, -basis}]& /@ numbers, GiveSymbol[basis, #][]& /@ numbers]]
]
xTension["xTerior`", DefBasis, "End"] :=
defFreeAlgebraBasis;
defFreeAlgebraBasis[basis_, __] :=
With[{numbers = CNumbersOf @ basis, mani = BaseOfVBundle @ VBundleOfBasis
@ basis},
If[Not @ ChartQ @ basis,
(* Define the algebra elements forming the basis of the free algebra*)
DefTensor[GiveSymbol[basis, Abs @ #][], mani, GradeOfTensor -> {CircleTimes-> 1}, Master -> basis]& /@ numbers;
(* Assign values *)
Thread[ComponentValue[eFrame[mani][{#, -basis}]& /@ numbers, GiveSymbol[basis, #][]& /@ numbers]]
]
]
(**************************** 2.8 The Hodge dual *********************************)
(* The third basic ingredient of exterior algebra is Hodge duality, which requires the presence of a metric. *)
DefInertHead[Hodge[metric_], LinearQ -> True, ContractThrough -> {delta}, DefInfo -> Null]
Hodge /: PrintAs @ Hodge[metric_] :=
If[Head[metric] === CTensor,
"*",
"\!\(\*SubscriptBox[\(*\), \(" <> PrintAs[metric] <> "\)]\)"
];
(* Thread over lists and equal *)
Hodge[metric_][expr_List] :=
Hodge[metric][#]& /@ expr;
Hodge[metric_][expr_Equal] :=
Hodge[metric][#]& /@ expr;
(* Hodge of a CTensor object *)
Hodge[metric_][CTensor[array_, bases_List, weight_][inds__]] :=
CTensor[Hodge[metric][array], bases, weight][inds];
(* Hodge of the product of two objects *)
Hodge[metric_][x_ y_] :=
x Hodge[metric][y] /; Grade[x, Wedge] === 0
(* [Jose: This previous definition overlaps with LinearQ->True, so we might want to rethink that option in relation with the products and ScalarsOfProduct.] *)
DimOfMetric[metric_] :=
DimOfVBundle[VBundleOfMetric[metric]]
Hodge /: Grade[Hodge[metric_][expr_], Wedge] :=
DimOfMetric[metric] - Grade[expr, Wedge]
Hodge[metric_] @ Hodge[metric_][expr_] :=
(-1)^(Grade[expr, Wedge] (DimOfMetric[metric] - 1) + SignatureOfMetric[metric][[2]]) expr
(* This function converts Hodge duals of product of the coframe basis (either holonomic or non-holonomic): *)
(* Expand dual of differentials of coordinate elements *)
ExpandHodgeDual[expr_, dx[mani_?ManifoldQ], met_] :=
ExpandHodgeDual1[(expr /. Reverse /@ Flatten[List @@ TensorValues @ dx[mani]]), dx[mani], met];
(* Expand of the wedge product of canonical 1-forms *)
ExpandHodgeDual[expr_, (coframe:(Coframe | dx))[mani_?ManifoldQ], met_] :=