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
|
[/
Copyright (c) 2020 Evan Miller
Use, modification and distribution are subject to the
Boost Software License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
]
[section:jacobi_theta Jacobi Theta Functions]
[section:jacobi_theta_overview Overview of the Jacobi Theta Functions]
The Jacobi Theta functions are a set of four inter-related periodic functions of /x/ which are expressed in terms of a parameter /q/ (also called the nome), or a closely related value, [tau]
[footnote [@https://en.wikipedia.org/wiki/Theta_function Wikipedia: Theta function]]
[footnote [@https://mathworld.wolfram.com/JacobiThetaFunctions.html Weisstein, Eric W. "Jacobi Theta Functions." From MathWorld - A Wolfram Web Resource.]]
[footnote [@https://dlmf.nist.gov/20 Digital Library of Mathematical Functions: Theta Functions, Reinhardt, W. P., Walker, P. L.]].
They are
[equation jacobi_theta1] [/ \theta_1(x, q) := 2 \sum_{n=0}^\infty (-1)^n q^{(n+\frac{1}{2})^2} \sin((2n+1)x) ]
[equation jacobi_theta2] [/ \theta_2(x, q) := 2 \sum_{n=0}^\infty q^{(n+\frac{1}{2})^2} \cos((2n+1)x) ]
[equation jacobi_theta3] [/ \theta_3(x, q) := 1 + 2 \sum_{n=1}^\infty q^{n^2} \cos(2nx) ]
[equation jacobi_theta4] [/ \theta_4(x, q) := 1 + 2 \sum_{n=1}^\infty (-1)^n q^{n^2} \cos(2nx) ]
[graph jacobi_theta]
Plots of the four theta functions for /q/=0.15.
Appropriately multiplied and divided, these four theta functions can be used
to implement the [link math_toolkit.jacobi.jac_over Jacobi elliptic functions]; but this is not really
recommended, as the existing Boost implementations are likely faster and
more accurate.
Most applications will want to use the /q/ parameterization of the functions: `__jacobi_theta1`, `__jacobi_theta2`, `__jacobi_theta3`, and `__jacobi_theta4`, where /q/ is restricted to the domain (0, 1).
These four functions are equivalent to Mathematica's [@https://reference.wolfram.com/language/ref/EllipticTheta.html EllipticTheta] function (whose first argument is the function number).
A second [tau] parameterization is also provided for all four functions, where
[equation jacobi_theta_nome] [/ q = \exp(i\pi\tau) ]
Note that there is a slight difference between [tau] in the equation above and the `tau` in the Boost function signatures.
The mathematical [tau] is assumed to be a purely imaginary number, but the Boost argument is real-valued.
Boost treats its real-valued argument as an imaginary number; that is, it implicitly multiplies the argument by /i/.
This assumption of [tau]'s imaginarity is not required by the mathematics, but it does cover the most common application domains.
[heading Accuracy considerations]
The purpose of the [tau] parameterization is to provide increased accuracy either when /q/ is expressible as an exponential or is very close to unity.
For example, instead of:
jacobi_theta1(x, exp(-a));
A more accurate computation will take advantage of [tau]:
jacobi_theta1tau(x, a / boost::math::constants::pi<T>());
Internally, Boost implements the /q/ parameterization by taking the logarithm of /q/ and passing it to the [tau] parameterization; as such, using the [tau] parameterization directly will generally yield greater precision.
As another example, if the complement of /q/ is known with great accuracy, then instead of:
jacobi_theta1(x, 1-q_complement);
It is more accurate to use `__log1p` and pass in the result to the [tau] version:
jacobi_theta1tau(x, -boost::math::log1p(-q_complement) / boost::math::constants::pi<T>());
Additional "minus 1" versions of the third and fourth theta functions are provided. Similar in spirit to `__expm1`, these functions return one less than the evaluated function, and yield increased accuracy when /q/ is small.
[heading Testing]
Results of the theta functions are tested against Wolfram Alpha data, as well as random values computed at high precision.
In addition, the tests verify the majority of the identities described in [@https://dlmf.nist.gov/20.7 DLMF Chapter 20.7].
[endsect] [/section:jacobi_theta_overview Overview of the Jacobi Theta Functions]
[section:jacobi_theta1 Jacobi Theta Function [theta][sub 1]]
[heading Synopsis]
``
#include <boost/math/special_functions/jacobi_theta.hpp>
``
namespace boost { namespace math {
template <class T, class U>
``__sf_result`` jacobi_theta1(T x, U q);
template <class T, class U, class Policy>
``__sf_result`` jacobi_theta1(T x, U q, const Policy&);
template <class T, class U>
``__sf_result`` jacobi_theta1tau(T x, U tau);
template <class T, class U, class Policy>
``__sf_result`` jacobi_theta1tau(T x, U tau, const Policy&);
}} // namespaces
[heading Description]
The functions calculate the value of first [link math_toolkit.jacobi_theta.jacobi_theta_overview Jacobi Theta function], parameterized either in terms of the nome /q/:
[equation jacobi_theta1] [/ \theta_1(x, q) := 2 \sum_{n=0}^\infty (-1)^n q^{(n+\frac{1}{2})^2} \sin((2n+1)x) ]
Or in terms of an imaginary [tau]:
[equation jacobi_theta1tau] [/ \theta_1(x|\tau) := 2 \sum_{n=0}^\infty (-1)^n \exp(i\pi\tau{(n+0.5)^2}) \sin((2n+1)x) ]
The nome /q/ is restricted to the domain (0, 1), returning the result of __domain_error otherwise. The following graph shows the theta function at various values of /q/:
[graph jacobi_theta1]
[optional_policy]
[heading Accuracy]
The following [link math_toolkit.ulps_plots ULPs plot] is representative, fixing /q/=0.5 and varying /x/ from 0 to 2[pi]:
[graph jacobi_theta1_float]
The envelope represents the function's [@https://en.wikipedia.org/wiki/Condition_number#One_variable condition number].
Note that relative accuracy degenerates periodically near [theta][sub 1]=0.
Fixing /x/=5 and varying /q/, the ULPs plot looks like:
[graph jacobi_theta1q_float]
Accuracy tends to degenerate near /q/=1 (small [tau]).
[heading Implementation]
The /q/ parameterization is implemented using the [tau] parameterization, where [tau]=-log(/q/)/[pi].
If [tau] is greater than or equal to 1, the summation above is used as-is.
However if [tau] < 1, the following identity [@https://dlmf.nist.gov/20.7#viii DLMF 20.7.30] is used, defining [tau]'=-1/[tau]:
[equation jacobi_theta1_imaginary] [/ (-i\tau)^{1/2}\theta_1(x|\tau)=-i\exp(i\tau'x^2/\pi)\theta_1(x\tau'|\tau') ]
This transformation of variables ensures that the function will always converge in a small number of iterations.
[endsect] [/section:jacobi_theta1 Jacobi Theta Function [theta][sub 1]]
[section:jacobi_theta2 Jacobi Theta Function [theta][sub 2]]
[heading Synopsis]
``
#include <boost/math/special_functions/jacobi_theta.hpp>
``
namespace boost { namespace math {
template <class T, class U>
``__sf_result`` jacobi_theta2(T x, U q);
template <class T, class U, class Policy>
``__sf_result`` jacobi_theta2(T x, U q, const Policy&);
template <class T, class U>
``__sf_result`` jacobi_theta2tau(T x, U tau);
template <class T, class U, class Policy>
``__sf_result`` jacobi_theta2tau(T x, U tau, const Policy&);
}} // namespaces
[heading Description]
The functions calculate the value of second [link math_toolkit.jacobi_theta.jacobi_theta_overview Jacobi Theta function], parameterized either in terms of the nome /q/:
[equation jacobi_theta2] [/ \theta_2(x, q) := 2 \sum_{n=0}^\infty q^{(n+\frac{1}{2})^2} \cos((2n+1)x) ]
Or in terms of an imaginary [tau]:
[equation jacobi_theta2tau] [/ \theta_2(x|\tau) := 2 \sum_{n=0}^\infty \exp(i\pi\tau{(n+0.5)^2}) \cos((2n+1)x) ]
The nome /q/ is restricted to the domain (0, 1), returning the result of __domain_error otherwise.
The following graph shows the theta function at various values of /q/:
[graph jacobi_theta2]
[optional_policy]
[heading Accuracy]
The following [link math_toolkit.ulps_plots ULPs plot] is representative, fixing /q/=0.5 and varying /x/ from 0 to 2[pi]:
[graph jacobi_theta2_float]
The envelope represents the function's [@https://en.wikipedia.org/wiki/Condition_number#One_variable condition number].
Note that relative accuracy degenerates periodically near [theta][sub 2]=0.
Fixing /x/=0.4 and varying /q/, the ULPs plot looks like:
[graph jacobi_theta2q_float]
Accuracy tends to degenerate near /q/=1 (small [tau]).
[heading Implementation]
The /q/ parameterization is implemented using the [tau] parameterization, where [tau]=-log(/q/)/[pi].
If [tau] is greater than or equal to 1, the summation above is used as-is.
However if [tau] < 1, the following identity [@https://dlmf.nist.gov/20.7#viii DLMF 20.7.31] is used, defining [tau]'=-1/[tau]:
[equation jacobi_theta2_imaginary] [/ (-i\tau)^{1/2}\theta_2(x|\tau)=\exp(i\tau'x^2/\pi)\theta_4(x\tau'|\tau') ]
This transformation of variables ensures that the function will always converge in a small number of iterations.
[endsect] [/section:jacobi_theta2 Jacobi Theta Function [theta][sub 2]]
[section:jacobi_theta3 Jacobi Theta Function [theta][sub 3]]
[heading Synopsis]
``
#include <boost/math/special_functions/jacobi_theta.hpp>
``
namespace boost { namespace math {
template <class T, class U>
``__sf_result`` jacobi_theta3(T x, U q);
template <class T, class U, class Policy>
``__sf_result`` jacobi_theta3(T x, U q, const Policy&);
template <class T, class U>
``__sf_result`` jacobi_theta3tau(T x, U tau);
template <class T, class U, class Policy>
``__sf_result`` jacobi_theta3tau(T x, U tau, const Policy&);
template <class T, class U>
``__sf_result`` jacobi_theta3m1(T x, U q);
template <class T, class U, class Policy>
``__sf_result`` jacobi_theta3m1(T x, U q, const Policy&);
template <class T, class U>
``__sf_result`` jacobi_theta3m1tau(T x, U tau);
template <class T, class U, class Policy>
``__sf_result`` jacobi_theta3m1tau(T x, U tau, const Policy&);
}} // namespaces
[heading Description]
The functions calculate the value of third [link math_toolkit.jacobi_theta.jacobi_theta_overview Jacobi Theta function], parameterized either in terms of the nome /q/:
[equation jacobi_theta3] [/ \theta_3(x, q) := 1 + 2 \sum_{n=1}^\infty q^{n^2} \cos(2nx) ]
Or in terms of an imaginary [tau]:
[equation jacobi_theta3tau] [/ \theta_3(x|\tau) := 1 + 2 \sum_{n=1}^\infty \exp(i\pi\tau{n^2}) \cos(2nx) ]
The nome /q/ is restricted to the domain (0, 1), returning the result of __domain_error otherwise.
The following graph shows the theta function at various values of /q/:
[graph jacobi_theta3]
[optional_policy]
A second quartet of functions (functions containing `m1`) compute one less than the value of the third theta function.
These versions of the functions provide increased accuracy when the result is close to unity.
[heading Accuracy]
The following [link math_toolkit.ulps_plots ULPs plot] is representative, fixing /q/=0.5 and varying /x/ from 0 to 2[pi]:
[graph jacobi_theta3_float]
The envelope represents the function's [@https://en.wikipedia.org/wiki/Condition_number#One_variable condition number].
Note that relative accuracy degenerates periodically near [theta][sub 3]=1.
Fixing /x/=0.4 and varying /q/, the ULPs plot looks like:
[graph jacobi_theta3q_float]
Accuracy tends to degenerate near /q/=1 (small [tau]).
[heading Implementation]
The /q/ parameterization is implemented using the [tau] parameterization, where [tau]=-log(/q/)/[pi].
If [tau] is greater than or equal to 1, the summation above is used as-is.
However if [tau] < 1, the following identity [@https://dlmf.nist.gov/20.7#viii DLMF 20.7.32] is used, defining [tau]'=-1/[tau]:
[equation jacobi_theta3_imaginary] [/ (-i\tau)^{1/2}\theta_3(x|\tau)=\exp(i\tau'x^2/\pi)\theta_3(x\tau'|\tau') ]
This transformation of variables ensures that the function will always converge in a small number of iterations.
[endsect] [/section:jacobi_theta3 Jacobi Theta Function [theta][sub 3]]
[section:jacobi_theta4 Jacobi Theta Function [theta][sub 4]]
[heading Synopsis]
``
#include <boost/math/special_functions/jacobi_theta.hpp>
``
namespace boost { namespace math {
template <class T, class U>
``__sf_result`` jacobi_theta4(T x, U q);
template <class T, class U, class Policy>
``__sf_result`` jacobi_theta4(T x, U q, const Policy&);
template <class T, class U>
``__sf_result`` jacobi_theta4tau(T x, U tau);
template <class T, class U, class Policy>
``__sf_result`` jacobi_theta4tau(T x, U tau, const Policy&);
template <class T, class U>
``__sf_result`` jacobi_theta4m1(T x, U q);
template <class T, class U, class Policy>
``__sf_result`` jacobi_theta4m1(T x, U q, const Policy&);
template <class T, class U>
``__sf_result`` jacobi_theta4m1tau(T x, U tau);
template <class T, class U, class Policy>
``__sf_result`` jacobi_theta4m1tau(T x, U tau, const Policy&);
}} // namespaces
[heading Description]
The functions calculate the value of fourth [link math_toolkit.jacobi_theta.jacobi_theta_overview Jacobi Theta function], parameterized either in terms of the nome /q/:
[equation jacobi_theta4] [/ \theta_4(x, q) := 1 + 2 \sum_{n=1}^\infty (-1)^n q^{n^2} \cos(2nx) ]
Or in terms of an imaginary [tau]:
[equation jacobi_theta4tau] [/ \theta_4(x|\tau) := 1 + 2 \sum_{n=1}^\infty (-1)^n \exp(i\pi\tau{n^2}) \cos(2nx) ]
The nome /q/ is restricted to the domain (0, 1), returning the result of __domain_error otherwise.
The following graph shows the theta function at various values of /q/:
[graph jacobi_theta4]
[optional_policy]
A second quartet of functions (functions containing `m1`) compute one less than the value of the fourth theta function.
These versions of the functions provide increased accuracy when the result is close to unity.
[heading Accuracy]
The following [link math_toolkit.ulps_plots ULPs plot] is representative, fixing /q/=0.5 and varying /x/ from 0 to 2[pi]:
[graph jacobi_theta4_float]
The envelope represents the function's [@https://en.wikipedia.org/wiki/Condition_number#One_variable condition number].
Note that relative accuracy degenerates periodically near [theta][sub 4]=1.
Fixing /x/=5 and varying /q/, the ULPs plot looks like:
[graph jacobi_theta4q_float]
Accuracy tends to degenerate near /q/=1 (small [tau]).
[heading Implementation]
The /q/ parameterization is implemented using the [tau] parameterization, where [tau]=-log(/q/)/[pi].
If [tau] is greater than or equal to 1, the summation above is used as-is.
However if [tau] < 1, the following identity [@https://dlmf.nist.gov/20.7#viii DLMF 20.7.33] is used, defining [tau]'=-1/[tau]:
[equation jacobi_theta4_imaginary] [/ (-i\tau)^{1/2}\theta_4(x|\tau)=\exp(i\tau'x^2/\pi)\theta_2(x\tau'|\tau') ]
This transformation of variables ensures that the function will always converge in a small number of iterations.
[endsect] [/section:jacobi_theta4 Jacobi Theta Function [theta][sub 4]]
[endsect] [/section:jacobi_theta Jacobi Theta Functions]
|