canonical.scm 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. #| -*-Scheme-*-
  2. Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
  3. 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
  4. 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Massachusetts
  5. Institute of Technology
  6. This file is part of MIT/GNU Scheme.
  7. MIT/GNU Scheme is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or (at
  10. your option) any later version.
  11. MIT/GNU Scheme is distributed in the hope that it will be useful, but
  12. WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with MIT/GNU Scheme; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
  18. USA.
  19. |#
  20. (define (canonical? C H Hprime)
  21. (- (compose (Hamiltonian->state-derivative H) C)
  22. (* (D C) (Hamiltonian->state-derivative Hprime))))
  23. (define (compositional-canonical? C H)
  24. (canonical? C H (compose H C)))
  25. #|
  26. (simplify
  27. ((compositional-canonical? (F->CT p->r)
  28. (H-central 'm (literal-function 'V)))
  29. (up 't
  30. (coordinate-tuple 'r 'phi)
  31. (momentum-tuple 'p_r 'p_phi))))
  32. ;Value: (up 0 (up 0 0) (down 0 0))
  33. |#
  34. (define (J-func DHs)
  35. (assert (compatible-H-state? DHs))
  36. (up 0 (ref DHs 2) (- (ref DHs 1))))
  37. (define (T-func s)
  38. (up 1
  39. (zero-like (coordinates s))
  40. (zero-like (momenta s))))
  41. (define (canonical-H? C H)
  42. (- (compose (D-phase-space H) C)
  43. (* (D C)
  44. (D-phase-space (compose H C)))))
  45. (define (canonical-K? C K)
  46. (- (compose T-func C)
  47. (* (D C)
  48. (+ T-func (D-phase-space K)))))
  49. (define (linear-function->multiplier F argument)
  50. ((D F) argument))
  51. (define* ((Phi A) v) (* A v))
  52. (define* ((Phi* A) w) (* w A))
  53. (define* ((time-independent-canonical? C) s)
  54. ((- J-func
  55. (compose (Phi ((D C) s))
  56. J-func
  57. (Phi* ((D C) s))))
  58. (compatible-shape s)))
  59. #|
  60. (print-expression
  61. ((time-independent-canonical? (F->CT p->r))
  62. (up 't
  63. (coordinate-tuple 'r 'phi)
  64. (momentum-tuple 'p_r 'p_phi))))
  65. (up 0 (up 0 0) (down 0 0))
  66. ;;; but not all transforms are
  67. (define (a-non-canonical-transform Istate)
  68. (let ((t (time Istate))
  69. (theta (coordinate Istate))
  70. (p (momentum Istate)))
  71. (let ((x (* p (sin theta)))
  72. (p_x (* p (cos theta))))
  73. (up t x p_x))))
  74. (print-expression
  75. ((time-independent-canonical? a-non-canonical-transform)
  76. (up 't 'theta 'p)))
  77. (up 0 (+ (* -1 p x8102) x8102) (+ (* p x8101) (* -1 x8101)))
  78. |#
  79. ;;; One particularly useful canonical transform is the
  80. ;;; Poincare transform, which is good for simplifying
  81. ;;; oscillators.
  82. (define* ((polar-canonical alpha) Istate)
  83. (let ((t (time Istate))
  84. (theta (coordinate Istate))
  85. (I (momentum Istate)))
  86. (let ((x (* (sqrt (/ (* 2 I) alpha)) (sin theta)))
  87. (p_x (* (sqrt (* 2 alpha I)) (cos theta))))
  88. (up t x p_x))))
  89. (define* ((polar-canonical-inverse alpha) s)
  90. (let ((t (time s))
  91. (x (coordinate s))
  92. (p (momentum s)))
  93. (let ((I (/ (+ (* alpha (square x))
  94. (/ (square p) alpha))
  95. 2)))
  96. (let ((theta (atan (/ x (sqrt (/ (* 2 I) alpha)))
  97. (/ p (sqrt (* 2 I alpha))))))
  98. (up t theta I)))))
  99. #|
  100. (pe
  101. ((compose (polar-canonical-inverse 'alpha)
  102. (polar-canonical 'alpha))
  103. (up 't 'x 'p)))
  104. (up t x p)
  105. (print-expression
  106. ((time-independent-canonical? (polar-canonical 'alpha))
  107. (up 't 'a 'I)))
  108. (up 0 0 0)
  109. |#
  110. #|
  111. (define (Cmix H-state)
  112. (let ((t (time H-state))
  113. (q (coordinate H-state))
  114. (p (momentum H-state)))
  115. (up t
  116. (coordinate-tuple (ref q 0) (- (ref p 1)))
  117. (momentum-tuple (ref p 0) (ref q 1)))))
  118. (define a-state
  119. (up 't
  120. (coordinate-tuple 'x 'y)
  121. (momentum-tuple 'p_x 'p_y)))
  122. (print-expression
  123. ((time-independent-canonical? Cmix)
  124. a-state))
  125. (up 0 (up 0 0) (down 0 0))
  126. (define (Cmix2 H-state)
  127. (let ((t (time H-state))
  128. (q (coordinate H-state))
  129. (p (momentum H-state)))
  130. (up t
  131. (flip-outer-index p)
  132. (- (flip-outer-index q)))))
  133. (print-expression
  134. ((time-independent-canonical? Cmix2)
  135. a-state))
  136. (up 0 (up 0 0) (down 0 0))
  137. |#
  138. (define* ((two-particle-center-of-mass m0 m1) H-state)
  139. (let ((q (coordinate H-state)))
  140. (let ((x0 (ref q 0))
  141. (x1 (ref q 1)))
  142. (coordinate-tuple (/ (+ (* m0 x0) (* m1 x1)) (+ m0 m1))
  143. (- x1 x0)))))
  144. (define* ((two-particle-center-of-mass-canonical m0 m1) state)
  145. (let ((x (coordinate state))
  146. (p (momentum state)))
  147. (let ((x0 (ref x 0))
  148. (x1 (ref x 1))
  149. (p0 (ref p 0))
  150. (p1 (ref p 1)))
  151. (up (time state)
  152. (coordinate-tuple
  153. (/ (+ (* m0 x0) (* m1 x1)) (+ m0 m1))
  154. (- x1 x0))
  155. (momentum-tuple
  156. (+ p0 p1)
  157. (/ (- (* m0 p1) (* m1 p0))
  158. (+ m0 m1)))))))
  159. #|
  160. (define b-state
  161. (up 't
  162. (coordinate-tuple
  163. (coordinate-tuple 'x_1 'y_1)
  164. (coordinate-tuple 'x_2 'y_2))
  165. (momentum-tuple
  166. (momentum-tuple 'p_x_1 'p_y_1)
  167. (momentum-tuple 'p_x_2 'p_y_2))))
  168. (pe (- ((F->CT (two-particle-center-of-mass 'm0 'm1)) b-state)
  169. ((two-particle-center-of-mass-canonical 'm0 'm1) b-state)))
  170. (up 0 (up (up 0 0) (up 0 0)) (down (down 0 0) (down 0 0)))
  171. (print-expression
  172. ((time-independent-canonical?
  173. (two-particle-center-of-mass-canonical 'm1 'm2))
  174. b-state))
  175. (up 0 (up (up 0 0) (up 0 0)) (down (down 0 0) (down 0 0)))
  176. |#
  177. (define* ((multiplicative-transpose s) A)
  178. (linear-function->multiplier (transpose-function A) s))
  179. (define* ((transpose-function A) p) (* p A))
  180. #|
  181. (define (T v)
  182. (* (down (up 'a 'c) (up 'b 'd)) v))
  183. (pe (T (up 'x 'y)))
  184. (up (+ (* a x) (* b y)) (+ (* c x) (* d y)))
  185. (pe (* (* (down 'p_x 'p_y) ((D T) (up 'x 'y))) (up 'v_x 'v_y)))
  186. (+ (* a p_x v_x) (* b p_x v_y) (* c p_y v_x) (* d p_y v_y))
  187. (pe (* (down 'p_x 'p_y) (* ((D T) (up 'x 'y)) (up 'v_x 'v_y))))
  188. (+ (* a p_x v_x) (* b p_x v_y) (* c p_y v_x) (* d p_y v_y))
  189. (pe (* (* ((multiplicative-transpose (down 'p_x 'p_y)) ((D T) (up 'x 'y)))
  190. (down 'p_x 'p_y))
  191. (up 'v_x 'v_y)))
  192. (+ (* a p_x v_x) (* b p_x v_y) (* c p_y v_x) (* d p_y v_y))
  193. ;;; But strangely enough...
  194. (pe (* (* (down 'p_x 'p_y)
  195. ((multiplicative-transpose (down 'p_x 'p_y)) ((D T) (up 'x 'y))))
  196. (up 'v_x 'v_y)))
  197. (+ (* a p_x v_x) (* b p_x v_y) (* c p_y v_x) (* d p_y v_y))
  198. |#
  199. #|
  200. (define ((time-independent-canonical? C) s)
  201. (let ((s* (compatible-shape s)))
  202. (let ((J (linear-function->multiplier J-func s*)))
  203. (- J
  204. (* ((D C) s)
  205. (* J
  206. ((multiplicative-transpose s*) ((D C) s))))))))
  207. (print-expression
  208. ((time-independent-canonical? (F->CT p->r))
  209. (up 't
  210. (coordinate-tuple 'r 'phi)
  211. (momentum-tuple 'p_r 'p_phi))))
  212. (up (up 0 (up 0 0) (down 0 0))
  213. (up (up 0 (up 0 0) (down 0 0)) (up 0 (up 0 0) (down 0 0)))
  214. (down (up 0 (up 0 0) (down 0 0)) (up 0 (up 0 0) (down 0 0))))
  215. ;;; but not all transforms are
  216. (define (a-non-canonical-transform Istate)
  217. (let ((t (time Istate))
  218. (theta (coordinate Istate))
  219. (p (momentum Istate)))
  220. (let ((x (* p (sin theta)))
  221. (p_x (* p (cos theta))))
  222. (up t x p_x))))
  223. (print-expression
  224. ((time-independent-canonical? a-non-canonical-transform)
  225. (up 't 'theta 'p)))
  226. (up (up 0 0 0) (up 0 0 (+ -1 p)) (up 0 (+ 1 (* -1 p)) 0))
  227. (print-expression
  228. ((time-independent-canonical? (polar-canonical 'alpha))
  229. (up 't 'a 'I)))
  230. (up (up 0 0 0) (up 0 0 0) (up 0 0 0))
  231. |#
  232. #|
  233. (define (Cmix H-state)
  234. (let ((t (time H-state))
  235. (q (coordinate H-state))
  236. (p (momentum H-state)))
  237. (up t
  238. (coordinate-tuple (ref q 0) (- (ref p 1)))
  239. (momentum-tuple (ref p 0) (ref q 1)))))
  240. (define a-state
  241. (up 't
  242. (coordinate-tuple 'x 'y)
  243. (momentum-tuple 'p_x 'p_y)))
  244. (print-expression
  245. ((time-independent-canonical? Cmix)
  246. a-state))
  247. (up (up 0 (up 0 0) (down 0 0))
  248. (up (up 0 (up 0 0) (down 0 0)) (up 0 (up 0 0) (down 0 0)))
  249. (down (up 0 (up 0 0) (down 0 0)) (up 0 (up 0 0) (down 0 0))))
  250. (define (Cmix2 H-state)
  251. (let ((t (time H-state))
  252. (q (coordinate H-state))
  253. (p (momentum H-state)))
  254. (up t
  255. (flip-outer-index p)
  256. (- (flip-outer-index q)))))
  257. (print-expression
  258. ((time-independent-canonical? Cmix2)
  259. a-state))
  260. (up (up 0 (up 0 0) (down 0 0))
  261. (up (up 0 (up 0 0) (down 0 0)) (up 0 (up 0 0) (down 0 0)))
  262. (down (up 0 (up 0 0) (down 0 0)) (up 0 (up 0 0) (down 0 0))))
  263. |#
  264. #|
  265. (define ((C m0 m1) state)
  266. (let ((x (coordinate state))
  267. (p (momentum state)))
  268. (let ((x0 (ref x 0))
  269. (x1 (ref x 1))
  270. (p0 (ref p 0))
  271. (p1 (ref p 1)))
  272. (up
  273. (time state)
  274. (coordinate-tuple (/ (+ (* m0 x0) (* m1 x1)) (+ m0 m1))
  275. (- x1 x0))
  276. (momentum-tuple (+ p0 p1)
  277. (/ (- (* m0 p1) (* m1 p0))
  278. (+ m0 m1)))))))
  279. (define b-state
  280. (up 't
  281. (coordinate-tuple
  282. (coordinate-tuple 'x_1 'y_1)
  283. (coordinate-tuple 'x_2 'y_2))
  284. (momentum-tuple
  285. (momentum-tuple 'p_x_1 'p_y_1)
  286. (momentum-tuple 'p_x_2 'p_y_2))))
  287. (print-expression
  288. ((time-independent-canonical? (C 'm1 'm2)) b-state))
  289. (up
  290. (up 0 (up (up 0 0) (up 0 0)) (down (down 0 0) (down 0 0)))
  291. (up
  292. (up (up 0 (up (up 0 0) (up 0 0)) (down (down 0 0) (down 0 0)))
  293. (up 0 (up (up 0 0) (up 0 0)) (down (down 0 0) (down 0 0))))
  294. (up (up 0 (up (up 0 0) (up 0 0)) (down (down 0 0) (down 0 0)))
  295. (up 0 (up (up 0 0) (up 0 0)) (down (down 0 0) (down 0 0)))))
  296. (down
  297. (down (up 0 (up (up 0 0) (up 0 0)) (down (down 0 0) (down 0 0)))
  298. (up 0 (up (up 0 0) (up 0 0)) (down (down 0 0) (down 0 0))))
  299. (down (up 0 (up (up 0 0) (up 0 0)) (down (down 0 0) (down 0 0)))
  300. (up 0 (up (up 0 0) (up 0 0)) (down (down 0 0) (down 0 0))))))
  301. |#