-
Notifications
You must be signed in to change notification settings - Fork 0
/
fdg.scm
155 lines (112 loc) · 3.53 KB
/
fdg.scm
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
;
; Functional Differential Geometry
; Prologue
(define
( (Lagrange-equations Lagrangian) w )
(- (D (compose ((partial 2) Lagrangian) (Gamma w)))
(compose ((partial 1) Lagrangian) (Gamma w))))
(define
( (Gamma w) t )
(up t (w t) ((D w) t)) )
(define
( (L-harmonic m k) local )
(let
( (q (coordinate local))
(v (velocity local)) )
(- (* 1/2 m (square v))
(* 1/2 k (square q)) ) ) )
(define
(proposed-solution t)
(* 'a (cos (+ (* 'omega t) 'phi))) )
(define demo0a
(((Lagrange-equations (L-harmonic 'm 'k)) proposed-solution) 't) )
(define demo0b
( ( (Lagrange-equations (L-harmonic 'm 'k))
(literal-function 'x) )
't ) )
;(show-expression demo0a)
;(show-expression demo0b)
; Chapter 1
(define
( (Lfree mass) state )
(* 1/2 mass (square (velocity state))) )
(define
( (sphere->R3 R) state )
(let
( (q (coordinate state)))
(let
( (theta (ref q 0))
(phi (ref q 1)) )
(up
(* R (sin theta) (cos phi))
(* R (sin theta) (sin phi))
(* R (cos theta)) ) ) ) )
(define
( (F->C F) state )
(up
(time state)
(F state)
(+ (((partial 0) F) state)
(* (((partial 1) F) state)
(velocity state) ) ) ) )
(define
(Lsphere m R)
(compose (Lfree m) (F->C (sphere->R3 R))) )
(define demo1a (up 't (up 'theta 'phi) (up 'thetadot 'phidot)))
(define temp1a (((partial 1) (sphere->R3 'R)) demo1a))
(define temp1b (* temp1a (velocity demo1a)))
(define temp1c (square temp1b))
(define demo1b ((Lsphere 'm 'R) demo1a))
;(print-expression demo1b)
(define
((L2 mass metric) place velocity)
(* 1/2 mass ((metric velocity velocity) place)) )
(define
( (Lc mass metric coordsys) state )
(let
( (x (coordinates state))
(v (velocities state))
(e (coordinate-system->vector-basis coordsys)) )
( (L2 mass metric)
((point coordsys) x)
(* e v) ) ) )
(define the-metric (literal-metric 'g R2-rect))
(define L (Lc 'm the-metric R2-rect))
(define demo1c (L (up 't (up 'x 'y) (up 'vx 'vy))))
;(print-expression demo1c)
(define gamma (literal-manifold-map 'q R1-rect R2-rect))
(define demo1d
( (chart R2-rect)
(gamma ((point R1-rect) 't)) ) )
;(print-expression demo1d)
(define coordinate-path
(compose
(chart R2-rect)
gamma
(point R1-rect) ) )
(define demo1e (coordinate-path 't))
;(print-expression demo1e)
(define Lagrange-residuals
(((Lagrange-equations L) coordinate-path) 't) )
(define-coordinates t R1-rect)
(define Cartan
(Christoffel->Cartan (metric->Christoffel-2 the-metric (coordinate-system->basis R2-rect))) )
(define geodesic-equation-residuals
( ( ( ((covariant-derivative Cartan gamma) d/dt)
((differential gamma) d/dt) )
(chart R2-rect) )
( (point R1-rect) 't) ) )
(define metric-components
(metric->components the-metric (coordinate-system->basis R2-rect)) )
(define demo1f
(- Lagrange-residuals
(* (* 'm (metric-components (gamma ((point R1-rect) 't)))) geodesic-equation-residuals) ) )
; Chapter 2
(define R2 (make-manifold R^n 2))
(define U (patch 'origin R2))
(define R2-rect (coordinate-system 'rectangular U))
(define R2-polar (coordinate-system 'polar/cylindrical U))
(define R2-rect-chi (chart R2-rect))
(define R2-rect-chi-inverse (point R2-rect))
(define R2-polar-chi (chart R2-polar))
(define R2-polar-chi-inverse (point R2-polar))