Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
898c3ad
Jacobi Theta functions
evanmiller Jul 7, 2020
c78dcd7
[CI SKIP] Jacobi theta: Add special-value tests and more
evanmiller Jul 7, 2020
10fc561
Jacobi theta: Test two more of Watson's identities [CI SKIP]
evanmiller Jul 7, 2020
4b6701d
Improve precision of Jacobi theta functions [CI SKIP]
evanmiller Jul 8, 2020
9c68c11
Jacobi theta: Make changes suggested in #394 [CI SKIP]
evanmiller Jul 8, 2020
aa382f5
Add quadrature tests to Jacobi theta functions [CI SKIP]
evanmiller Jul 8, 2020
45e8ab9
Test Jacobi thetas against elliptic functions and elliptic integrals …
evanmiller Jul 9, 2020
0d3bc43
Test Jacobi Thetas against their Laplace transforms [CI SKIP]
evanmiller Jul 9, 2020
c293d48
Add a note on using log1p with Jacobi theta functions [CI SKIP]
evanmiller Jul 9, 2020
6b8dd5a
Merge branch 'develop' into jacobi-theta [CI SKIP]
evanmiller Jul 9, 2020
08391cd
Add random data tests to Jacobi Theta functions [CI SKIP]
evanmiller Jul 9, 2020
d73472e
Add small-tau tests and simplify Jacobi Theta code [CI SKIP]
evanmiller Jul 10, 2020
78fc9e2
Merge branch 'develop' into jacobi-theta [CI SKIP]
evanmiller Jul 13, 2020
98bc16c
Merge branch 'develop' into jacobi-theta [CI SKIP]
evanmiller Jul 17, 2020
2ecdf32
Merge branch 'develop' into jacobi-theta [CI SKIP]
evanmiller Jul 23, 2020
32a4d73
Merge branch 'develop' into jacobi-theta [CI SKIP]
evanmiller Jul 27, 2020
a2499bb
Add user documentation for Jacobi Theta functions [CI SKIP]
evanmiller Jul 29, 2020
041ca09
Add function graphs to Jacobi Theta docs [CI SKIP]
evanmiller Jul 30, 2020
3a0e3f3
Define Jacobi Theta test tolerances [CI SKIP]
evanmiller Jul 31, 2020
4630855
Merge branch 'develop' into jacobi-theta [CI SKIP]
evanmiller Jul 31, 2020
cf7ff40
Add implementation note on Jacobi theta functions [CI SKIP]
evanmiller Jul 31, 2020
b116c75
Consolidate Jacobi Theta ULPs plotting programs [CI SKIP]
evanmiller Aug 1, 2020
9fab61b
Fix q domain checking of jacobi_theta4 [CI SKIP]
evanmiller Aug 1, 2020
fb8d3f3
Add ULPs plots to Jacobi Theta docs [CI SKIP]
evanmiller Aug 1, 2020
dd2fcd1
Add missing Jacobi Theta ULPs plots [CI SKIP]
evanmiller Aug 1, 2020
d629f80
Add LaTeX source for Jacobi Theta equations [CI SKIP]
evanmiller Aug 1, 2020
ef39393
Remove unused Jacobi Theta PNG equations [CI SKIP]
evanmiller Aug 1, 2020
7ecda0f
Add Jacobi Theta performance script [CI SKIP]
evanmiller Aug 2, 2020
8cea3e9
Remove vestigial eps*eps check from jacobi_theta3 [CI SKIP]
evanmiller Aug 2, 2020
2902061
Update Jacobi Theta docs per code review comments [CI SKIP]
evanmiller Aug 2, 2020
5bea1e5
Enable arg promotion for Jacobi Theta functions [CI SKIP]
evanmiller Aug 3, 2020
46c59f8
Fix Jacobi Theta plotting script [CI SKIP]
evanmiller Aug 3, 2020
c9ac3a6
Change Jacobi Theta convergence criterion [CI SKIP]
evanmiller Aug 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add small-tau tests and simplify Jacobi Theta code [CI SKIP]
Add tests for small tau (i.e. large q). The tests are failing with mean
~ 200 EPS and max ~ 800 EPS. These look like worst-case input, and
should be the focus of future accuracy improvements.

This commit also simplifies the _IMAGINARY code by abstracting all of
the loops into a single svelte function.
  • Loading branch information
evanmiller committed Jul 10, 2020
commit d73472ec95c1f110a26bf8b1dca4f350ec3ff3d9
159 changes: 48 additions & 111 deletions include/boost/math/special_functions/jacobi_theta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,20 @@ _jacobi_theta_converged(RealType result, RealType delta, RealType eps) {
return abs(delta) < eps && (abs(result) == 0.0 || abs(delta/result) < eps);
}

template <class RealType>
inline RealType
_jacobi_theta_sum(RealType tau, RealType z_n, RealType z_increment, RealType eps) {
RealType delta, partial_result = 0;

do {
delta = exp(-tau*z_n*z_n/constants::pi<RealType>());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe precompute tau/constants::pi<RealType>() so that there isn't a division on each iteration.

People don't realize that elementary special function evaluations are in the same complexity class as division!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to squeeze out divisions like that, it might make sense to divide tau by pi further up the call stack.

partial_result += delta;
z_n += z_increment;
} while (!_jacobi_theta_converged(partial_result, delta, eps));

return partial_result;
}

// The following _IMAGINARY theta functions assume imaginary z and are for
// internal use only. They are designed to increase accuracy and reduce the
// number of iterations required for convergence for large |q|. The z argument
Expand All @@ -196,42 +210,17 @@ template <class RealType, class Policy>
inline RealType
_IMAGINARY_jacobi_theta1tau(RealType z, RealType tau, const Policy& pol) {
BOOST_MATH_STD_USING
unsigned n = 0;
RealType eps = policies::get_epsilon<RealType, Policy>();
RealType delta, result = RealType(0);

RealType result1 = RealType(0);
RealType result2 = RealType(0);

RealType z_n = z + constants::half_pi<RealType>();
n = 0;

do {
delta = exp(-tau*z_n*z_n/constants::pi<RealType>());
if (n%2) {
result1 -= delta;
} else {
result1 += delta;
}
z_n += constants::pi<RealType>();
n++;
} while (!_jacobi_theta_converged(result1, delta, eps));

z_n = z - constants::half_pi<RealType>();
n = 1;

do {
delta = exp(-tau*z_n*z_n/constants::pi<RealType>());
if (n%2) {
result2 -= delta;
} else {
result2 += delta;
}
z_n -= constants::pi<RealType>();
n++;
} while (!_jacobi_theta_converged(result2, delta, eps));
RealType result = RealType(0);

result -= result1 + result2;
// n>=0 even
result -= _jacobi_theta_sum(tau, z + constants::half_pi<RealType>(), constants::two_pi<RealType>(), eps);
// n>0 odd
result += _jacobi_theta_sum(tau, z + constants::half_pi<RealType>() + constants::pi<RealType>(), constants::two_pi<RealType>(), eps);
// n<0 odd
result += _jacobi_theta_sum(tau, z - constants::half_pi<RealType>(), -constants::two_pi<RealType>(), eps);
// n<0 even
result -= _jacobi_theta_sum(tau, z - constants::half_pi<RealType>() - constants::pi<RealType>(), -constants::two_pi<RealType>(), eps);

return result * sqrt(tau);
}
Expand All @@ -241,28 +230,12 @@ inline RealType
_IMAGINARY_jacobi_theta2tau(RealType z, RealType tau, const Policy& pol) {
BOOST_MATH_STD_USING
RealType eps = policies::get_epsilon<RealType, Policy>();
RealType delta, result = RealType(0);

RealType result1 = RealType(0);
RealType result2 = RealType(0);
RealType result = RealType(0);

RealType z_n = z + constants::half_pi<RealType>();

do {
delta = exp(-tau*z_n*z_n/constants::pi<RealType>());
result1 += delta;
z_n += constants::pi<RealType>();
} while (!_jacobi_theta_converged(result1, delta, eps));

z_n = z - constants::half_pi<RealType>();

do {
delta = exp(-tau*z_n*z_n/constants::pi<RealType>());
result2 += delta;
z_n -= constants::pi<RealType>();
} while (!_jacobi_theta_converged(result2, delta, eps));

result += result1 + result2;
// n>=0
result += _jacobi_theta_sum(tau, z + constants::half_pi<RealType>(), constants::pi<RealType>(), eps);
// n<0
result += _jacobi_theta_sum(tau, z - constants::half_pi<RealType>(), -constants::pi<RealType>(), eps);

return result * sqrt(tau);
}
Expand All @@ -272,28 +245,14 @@ inline RealType
_IMAGINARY_jacobi_theta3tau(RealType z, RealType tau, const Policy& pol) {
BOOST_MATH_STD_USING
RealType eps = policies::get_epsilon<RealType, Policy>();
RealType delta, result = exp(-z*z*tau/constants::pi<RealType>());

RealType result1 = RealType(0);
RealType result2 = RealType(0);

RealType z_n = z + constants::pi<RealType>();

do {
delta = exp(-tau*z_n*z_n/constants::pi<RealType>());
result1 += delta;
z_n += constants::pi<RealType>();
} while (!_jacobi_theta_converged(result1, delta, eps));

z_n = z - constants::pi<RealType>();
RealType result = 0;

do {
delta = exp(-tau*z_n*z_n/constants::pi<RealType>());
result2 += delta;
z_n -= constants::pi<RealType>();
} while (!_jacobi_theta_converged(result2, delta, eps));

result += result1 + result2;
// n=0
result += exp(-z*z*tau/constants::pi<RealType>());
// n>0
result += _jacobi_theta_sum(tau, z + constants::pi<RealType>(), constants::pi<RealType>(), eps);
// n<0
result += _jacobi_theta_sum(tau, z - constants::pi<RealType>(), -constants::pi<RealType>(), eps);

return result * sqrt(tau);
}
Expand All @@ -302,42 +261,20 @@ template <class RealType, class Policy>
inline RealType
_IMAGINARY_jacobi_theta4tau(RealType z, RealType tau, const Policy& pol) {
BOOST_MATH_STD_USING
unsigned n = 1;
RealType eps = policies::get_epsilon<RealType, Policy>();
RealType delta, result = exp(-z*z*tau/constants::pi<RealType>());

RealType result1 = RealType(0);
RealType result2 = RealType(0);

RealType z_n = z + constants::pi<RealType>();
n = 1;

do {
delta = exp(-tau*z_n*z_n/constants::pi<RealType>());
if (n%2) {
result1 -= delta;
} else {
result1 += delta;
}
z_n += constants::pi<RealType>();
n++;
} while (!_jacobi_theta_converged(result1, delta, eps));

z_n = z - constants::pi<RealType>();
n = 1;

do {
delta = exp(-tau*z_n*z_n/constants::pi<RealType>());
if (n%2) {
result2 -= delta;
} else {
result2 += delta;
}
z_n -= constants::pi<RealType>();
n++;
} while (!_jacobi_theta_converged(result2, delta, eps));

result += result1 + result2;
RealType result = 0;

// n = 0
result += exp(-z*z*tau/constants::pi<RealType>());

// n > 0 odd
result -= _jacobi_theta_sum(tau, z + constants::pi<RealType>(), constants::two_pi<RealType>(), eps);
// n < 0 odd
result -= _jacobi_theta_sum(tau, z - constants::pi<RealType>(), -constants::two_pi<RealType>(), eps);
// n > 0 even
result += _jacobi_theta_sum(tau, z + constants::two_pi<RealType>(), constants::two_pi<RealType>(), eps);
// n < 0 even
result += _jacobi_theta_sum(tau, z - constants::two_pi<RealType>(), -constants::two_pi<RealType>(), eps);

return result * sqrt(tau);
}
Expand Down
Loading