-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGRUtils.wl
75 lines (49 loc) · 1.39 KB
/
GRUtils.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
(* ::Package:: *)
(* ::Title:: *)
(*GRUtils*)
(* ::Subtitle:: *)
(*For an up-to-date version, go to https://github.com/bryango/Physica*)
(* ::Item:: *)
(*Pretty-differentials:*)
(* ::Subitem:: *)
(*The pretty-printing is tagged to `MakeBoxes`, not `Dt`*)
(* ::Subitem:: *)
(*... because `Dt` is a Protected Symbol*)
ClearAll[DifferentialD]
MakeBoxes[Dt[x_], StandardForm] := RowBox @ {"\[DifferentialD]", ToBoxes[x]}
DifferentialD := Dt
(*?? MakeBoxes*)
(* ::Item:: *)
(*Experimental: Make \[TensorWedge] work for abstract tensors:*)
(*
TensorWedge; (*(*(* trigger system default autoload *)*)*)
Unprotect[TensorWedge];
TensorWedge[x_ + y_, z_] := TensorWedge[x, z] + TensorWedge[y, z]
TensorWedge /: TensorWedge[x_, y_] + TensorWedge[y_, x_] := 0
(* SetAttributes[TensorWedge, ReadProtected]; *)
Protect[TensorWedge];
*)
lengthToMetric = Function[ {quadraticForm, coord},
Table[
(1/2) D[quadraticForm, Dt[i], Dt[j]],
{i, coord}, {j, coord}
]
];
metricToLength = Function[ {metric, coord},
Dt[coord] . metric . Dt[coord]
];
jacobianFromMap = Function[ {upByDownMap, downCoord},
Grad @@ (
{ upByDownMap @@ #, # } & @ downCoord
)
];
jacobian := jacobianFromMap;
ClearAll @ labelContract
labelContract[indices__] := Function[tensor,
Fold[
Sum[#1, {#2, 1, dim}] &
, tensor
, {indices}
]
];
(* vim: set ts=4 sw=4: *)