root/qd-theta.lisp @ 8ade177a0ce9bbb89b963ff29e46f38f377e9530

Revision 8ade177a0ce9bbb89b963ff29e46f38f377e9530, 4.7 KB (checked in by Raymond Toy <toy.raymond@…>, 3 years ago)

Add Elliptic theta functions and tests.

oct.asd:
o Add qd-theta.

qd-theta.lisp:
o New file with Elliptic theta functions and elliptic nome function.

rt-tests.lisp:
o Tests for theta functions.
o Relax accuracy requirements for some of the tests os that they can

pass.

  • Property mode set to 100644
Line 
1;;;; -*- Mode: lisp -*-
2;;;;
3;;;; Copyright (c) 2011 Raymond Toy
4;;;; Permission is hereby granted, free of charge, to any person
5;;;; obtaining a copy of this software and associated documentation
6;;;; files (the "Software"), to deal in the Software without
7;;;; restriction, including without limitation the rights to use,
8;;;; copy, modify, merge, publish, distribute, sublicense, and/or sell
9;;;; copies of the Software, and to permit persons to whom the
10;;;; Software is furnished to do so, subject to the following
11;;;; conditions:
12;;;;
13;;;; The above copyright notice and this permission notice shall be
14;;;; included in all copies or substantial portions of the Software.
15;;;;
16;;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17;;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18;;;; OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19;;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20;;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21;;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22;;;; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23;;;; OTHER DEALINGS IN THE SOFTWARE.
24
25(in-package #:oct)
26
27(eval-when (:compile-toplevel :load-toplevel :execute)
28  (setf *readtable* *oct-readtable*))
29
30;; Theta functions
31;;
32;; theta[1](z,q) = 2*sum((-1)^n*q^((n+1/2)^2)*sin((2*n+1)*z), n, 0, inf)
33;;
34;; theta[2](z,q) = 2*sum(q^((n+1/2)^2)*cos((2*n+1)*z), n, 0, inf)
35;;
36;; theta[3](z,q) = 1+2*sum(q^(n*n)*cos(2*n*z), n, 1, inf)
37;;
38;; theta[4](z,q) = 1+2*sum((-1)^n*q^(n*n)*cos(2*n*z), n, 1, inf)
39;;
40;; where q is the nome, related to parameter tau by q =
41;; exp(%i*%pi*tau), or %pi*tau = log(q)/%i.
42;;
43;; In all cases |q| < 1.
44
45
46;; The algorithms for computing the theta functions were given to me
47;; by Richard Gosper (yes, that Richard Gosper).  These came from
48;; package for maxima for the theta functions.
49
50;; e1 M[1,3] + e2 M[2,3] + e3, where M = prod(mat(a11 ... a23 0 0 1))
51;; where fun(k,matfn) supplies the upper six a[ij](k) to matfn.
52;;
53;; This is clearer if you look at the formulas below for the theta functions.
54(defun 3by3rec (e1 e2 e3 fun)
55  (do ((k 0 (+ k 1)))
56      ((= e3 (funcall fun k
57                      #'(lambda (a11 a12 a13 a21 a22 a23) ;&opt (a31 0) (a32 0) (a33 1)
58                          (psetf e1 (+ (* a11 e1) (* a21 e2))
59                                 e2 (+ (* a12 e1) (* a22 e2))
60                                 e3 (+ (* a13 e1) (* a23 e2) e3))
61                          (+ e3 (abs e1) (abs e2)))))
62       e3)))
63
64;;                     inf  [      2 n                 1/4 ]
65;;                    /===\ [ - 2 q    cos(2 z)  1  2 q    ]
66;;                     | |  [                              ]
67;;[sin(z), sin(z), 0]  | |  [       4 n - 2                ] = [0, 0, theta (z, q)]
68;;                     | |  [    - q             0    0    ]               1
69;;                    n = 1 [                              ]
70;;                          [         0          0    1    ]
71
72(defun elliptic-theta-1 (z q)
73  (let* ((precision (float-contagion z q))
74         (z (apply-contagion z precision))
75         (q (apply-contagion q precision))
76         (s (sin z))
77         (q^2 (* q q))
78         (q^4 (* q^2 q^2))
79         (-q^4n-2 (/ -1 q^2))
80         (-2q^2ncos (* -2 (cos (* 2 z))))
81         (2q^1/4 (* 2 (sqrt (sqrt q)))))
82    (3by3rec s s 0
83             #'(lambda (k matfun)
84                 (funcall matfun
85                          (setf -2q^2ncos (* q^2 -2q^2ncos))
86                          1
87                          2q^1/4
88                          (setf -q^4n-2 (* q^4 -q^4n-2))
89                          0
90                          0)))))
91
92;;                    inf  [    2 k + 1                ]
93;;                   /===\ [ 2 q        cos(2 z)  1  2 ]
94;;                    | |  [                           ]
95;;[q cos(2 z), 1, 1]  | |  [          4 k              ] = [0, 0, theta (z)]
96;;                    | |  [       - q            0  0 ]               3
97;;                   k = 1 [                           ]
98;;                         [          0           0  1 ]
99(defun elliptic-theta-3 (z q)
100  (let* ((precision (float-contagion z q))
101         (z (apply-contagion z precision))
102         (q (apply-contagion q precision))
103         (q^2 (* q q))
104         (q^2k 1.0)
105         (cos (cos (* 2 z))))
106    (3by3rec (* q cos) 1 1
107             #'(lambda (k matfun)
108                 (funcall matfun
109                          (* 2 (* (setf q^2k (* q^2 q^2k)) q cos))
110                          1
111                          2
112                          (- (* q^2k q^2k))
113                          0
114                          0)))))
115
116;; theta[2](z,q) = theta[1](z+%pi/2, q)
117(defun elliptic-theta-2 (z q)
118  (let* ((precision (float-contagion z q))
119         (z (apply-contagion z precision))
120         (q (apply-contagion q precision)))
121    (elliptic-theta-1 (+ z (/ (float-pi z) 2)) q)))
122
123;; theta[4](z,q) = theta[3](z+%pi/2,q)
124(defun elliptic-theta-4 (z q)
125  (let* ((precision (float-contagion z q))
126         (z (apply-contagion z precision))
127         (q (apply-contagion q precision)))
128    (elliptic-theta-3 (+ z (/ (float-pi z) 2)) q)))
129
130;; The nome, q, is given by q = exp(-%pi*K'/K) where K and %i*K' are
131;; the quarter periods.
132(defun elliptic-nome (m)
133  (exp (- (/ (* (float-pi m) (elliptic-k (- 1 m)))
134             (elliptic-k m)))))
135
Note: See TracBrowser for help on using the browser.