A fast simple algorithm for computing the potential of charges on a line
Zydrunas Gimbutas, Nicholas F. Marshall, Vladimir Rokhlin

TL;DR
This paper introduces a rapid and straightforward algorithm to efficiently compute electrostatic potentials generated by charges positioned on a line, significantly simplifying calculations in relevant physics applications.
Contribution
The paper presents a novel, simple, and fast algorithm specifically designed for calculating potentials of line charges, filling a gap in computational physics methods.
Findings
Algorithm significantly reduces computation time.
Numerical tests demonstrate high accuracy.
Applicable to various charge distributions on a line.
Abstract
We present a fast method for evaluating expressions of the form where are real numbers, and are points in a compact interval of . This expression can be viewed as representing the electrostatic potential generated by charges on a line in . While fast algorithms for computing the electrostatic potential of general distributions of charges in exist, in a number of situations in computational physics it is useful to have a simple and extremely fast method for evaluating the potential of charges on a line; we present such a method in this paper, and report numerical results for several examples.
| Label | Definition |
|---|---|
| number of points | |
| time of algorithm of §3 without precomputation in seconds | |
| time of precomputing exponentials for algorithm of §3 in seconds | |
| time of algorithm of §3 using precomputed exponentials in seconds | |
| time of direct evaluation in seconds | |
| maximum absolute relative difference defined in (32) | |
| time of FFT using precomputed exponentials (for time comparison only) |
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
A fast simple
algorithm for computing the potential of charges on a line
Zydrunas Gimbutas
National Institute of Standards and Technology, Boulder, CO 80305, USA
,
Nicholas F. Marshall
Department of Mathematics, Princeton University, Princeton, NJ 08540, USA
and
Vladimir Rokhlin
Program in Applied Mathematics, Yale University, New Haven, CT 06511, USA
Abstract.
We present a fast method for evaluating expressions of the form
[TABLE]
where are real numbers, and are points in a compact interval of . This expression can be viewed as representing the electrostatic potential generated by charges on a line in . While fast algorithms for computing the electrostatic potential of general distributions of charges in exist, in a number of situations in computational physics it is useful to have a simple and extremely fast method for evaluating the potential of charges on a line; we present such a method in this paper, and report numerical results for several examples.
Key words and phrases:
Fast multipole method, Chebyshev system, generalized Gaussian quadrature
2010 Mathematics Subject Classification:
31C20 (primary) and 41A55, 41A50 (secondary)
N.F.M. was supported in part by NSF DMS-1903015
V.R. was supported in part by AFOSR FA9550-16-1-0175 and ONR N00014-14-1-0797.
1. Introduction and motivation
1.1. Introduction
In this paper, we describe a simple fast algorithm for evaluating expressions of the form
[TABLE]
where are real numbers, and are points in a compact interval of . This expression can be viewed as representing the electrostatic potential generated by charges on a line in . We remark that fast algorithms for computing the electrostatic potential generated by general distributions of charges in exist, see for example the Fast Multipole Method [9] whose relation to the method presented in this paper is discussed in §1.2. However, in a number of situations in computational physics it is useful to have a simple and extremely fast method for evaluating the potential of charges on a line; we present such a method in this paper. Under mild assumptions the presented method involves operations and has a small constant. The method is based on writing the potential as
[TABLE]
We show that there exists a small set of quadrature nodes and weights such that for a large range of values of we have
[TABLE]
see Lemma 4.5, which is a quantitative version of (2). Numerically the nodes and weights are computed using a procedure for constructing generalized Gaussian quadratures, see §5.2. An advantage of representing as a sum of exponentials is that the translation operator
[TABLE]
can be computed by taking an inner product of the weights with a diagonal transformation of the vector . Indeed, we have
[TABLE]
The algorithm described in §3 leverages the existence of this diagonal translation operator to efficiently evaluate (1).
1.2. Relation to past work
We emphasize that fast algorithms for computing the potential generated by arbitrary distributions of charges in exist. An example of such an algorithm is the Fast Multipole Method that was introduced by [9] and has been extended by several authors including [7, 10, 16]. In this paper, we present a simple scheme for the special case where the charges are on a line, which occurs in a number of numerical calcuations, see 1.3. The presented scheme has a much smaller runtime constant compared to general methods, and is based on the diagonal form (4) of the translation operator (3). The idea of using the diagonal form of this translation operator to accelerate numerical computations has been studied by several authors; in particular, the diagonal form is used in algorithms by Dutt, Gu and Rokhlin [6], and Yavin and Rokhlin [22] and was subsequently studied in detail by Beylkin and Monzón [1, 2].
The current paper improves upon these past works by taking advantage of robust generalized Gaussian quadrature codes [4] that were not previously available; these codes construct a quadrature rule that is exact for functions in the linear span of a given Chebyshev system, and can be viewed as a constructive version of Lemma 4.2 of Kreĭn [13]. The resulting fast algorithm presented in §3 simplifies past approaches, and has a small runtime constant; in particular, its computational cost is similar to the computational cost of - Fast Fourier Transforms on data of a similar length, see 5.
1.3. Motivation
Expressions of the form (1) appear in a number of situations in computational physics. In particular, such expressions arise in connection with the Hilbert Transform
[TABLE]
For example, the computation of the projection of a function onto the first functions in a family of orthogonal polynomials can be reduced to an expression of the form (1) by using the Christoffel–Darboux formula, which is related to the Hilbert transform; we detail the reduction of to an expression of the form (1) in the following.
Let be a family of monic polynomials that are orthogonal with respect to the weight on . Consider the projection operator
[TABLE]
where . Let and be the point Gaussian quadrature nodes and weights associated with , and set
[TABLE]
By construction the polynomial that interpolates the values at the points will accurately approximate on when is sufficiently smooth, see for example §7.4.6 of Dahlquist and Björck [5]. Directly evaluating (5) would require operations. In contrast, the algorithm of this paper together with the Christoffel–Darboux Formula can be used to evaluate (5) in operations. The Christoffel-Darboux formula states that
[TABLE]
see §18.2(v) of [17]. Using (6) to rewrite (5) yields
[TABLE]
where we have used the fact that the diagonal term of the double summation is equal to . The summation in (7) can be rearranged into two expressions of the form (1), and thus the method of this paper can be used to compute a representation of in operations.
Remark 1.1**.**
Analogs of the Christoffel–Darboux formula hold for many other families of functions; for example, if is a Bessel function of the first kind, then we have
[TABLE]
see [21]. This formula can be used to write a projection operator related to Bessel functions in an analogous form to (7), and the algorithm of this paper can be similarly applied
Remark 1.2**.**
A simple modification of the algorithm presented in this paper can be used to evaluate more general expressions of the form
[TABLE]
where are source points, and are target points. For simplicity, this paper focuses on the case where the source and target points are the same, which is the case in the projection application described above.
2. Main result
2.1. Main result
Our principle analytical result is the following theorem, which provides precise accuracy and computational complexity guarantees for the algorithm presented in this paper, which is detailed in §3.
Theorem 2.1**.**
Let and be given. Set
[TABLE]
Given and , the algorithm described in §3 computes values such
[TABLE]
in operations, where
[TABLE]
The proof of Theorem 2.1 is given in §4. Under typical conditions, the presented algorithm involves operations. The following corollary describes a case of interest, where the points are Chebyshev nodes for a compact interval (we define Chebyshev nodes in §4.2).
Corollary 2.1**.**
Fix , and let the points be Chebyshev nodes on . If , then the algorithm of §3 involves operations.
The proof of Corollary 2.1 is given in §4.4. The following corollary states that a similar result holds for uniformly random points.
Corollary 2.2**.**
Fix , and suppose that are sampled uniformly at random from . If , then the algorithm of §3 involves operations with high probability.
The proof of Corollary 2.2 is immediate from standard probabilistic estimates. The following remark describes an adversarial configuration of points.
Remark 2.1**.**
Fix , and let be a collection of points such that and are evenly spaced in and , respectively, that is
[TABLE]
We claim that Theorem 2.1 cannot guarantee a complexity better than for this configuration of points. Indeed, if , then , and if , then . In either case
[TABLE]
This complexity is indicative of the performance of the algorithm for this point configuration; the reason that the algorithm performs poorly is that structures exist at two different scales. If such a configuration were encountered in practice, it would be possible to modify the algorithm of §3 to also involve two different scales to achieve evaluation in operations.
3. Algorithm
3.1. High level summary
The algorithm involves passing over the points twice. First, we pass over the points in ascending order and compute
[TABLE]
and second, we pass over the points in descending order and compute
[TABLE]
Finally, we define for such that
[TABLE]
We call the computation of the forward pass of the algorithm, and the computation of the backward pass of the algorithm. The forward pass of the algorithm computes the potential generated by all points to the left of a given point, while the backward pass of the algorithm computes the potential generated by all points to the right of a given point. In §3.2 and §3.3 we give an informal and detailed description of the forward pass of the algorithm. The backward pass of the algorithm is identical except it considers the points in reverse order.
3.2. Informal description
In the following, we give an informal description of the forward pass of the algorithm that computes
[TABLE]
Assume that a small set of nodes and weights such that
[TABLE]
where is given and fixed. The existence and computation of such nodes and weights is described in §4.4 and §5.2. We divide the sum defining into two parts:
[TABLE]
where j_{0}=\max\big{\{}i:x_{j}-x_{i}>\delta(b-a)\big{\}}. By definition, the points are all distance at least from . Therefore, by (12)
[TABLE]
If we define
[TABLE]
then it is straightforward to verify that
[TABLE]
Observe that we can update to using the following formula
[TABLE]
We can now summarize the algorithm for computing . For each , we compute by the following three steps:
Update as necessary 2. 2.
Use to evaluate the potential from such that 3. 3.
Directly evaluate the potential from such that
By (16), each update of requires operations, and we must update at most times, so we conclude that the total cost of the first step of the algorithm is operations. For each , the second and third step of the algorithm involve and operations, respectively, see (15). It follows that the total cost of the second and third step of the algorithm is operations, where is defined in (9). We conclude that can be computed in operations. In §4, we complete the proof of the computational complexity guarantees of Theorem 2.1 by showing that there exist nodes and weights that satisfy (12), where is the approximation error in (12).
3.3. Detailed description
In the following, we give a detailed description of the forward pass of the algorithm that computes . Suppose that and are given and fixed. We describe the algorithm under the assumption that we are given quadrature nodes and weights such that
[TABLE]
The existence of such weights and nodes is established in §4.4, and the computation of such nodes and weights is discussed in §5.2. To simplify the description of the algorithm, we assume that is a placeholder node that does not generate a potential.
Algorithm 3.1**.**
Input: , . Output: .
- 1:
and 2. 2: 3. 3:
main loop: 4. 4:
for 5. 5: 6. 6:
update and : 7. 7:
while 8. 8:
for i = 1,…,m 9. 9:
10. 10:
end for 11. 11:
12. 12:
end while 13. 13: 14. 14:
compute potential from such that 15. 15:
16. 16:
for 17. 17:
18. 18:
end for 19. 19: 20. 20:
compute potential from such that 21. 21:
for 22. 22:
23. 23:
end for 24. 24:
end for
Remark 3.1**.**
In some applications, it may be necessary to evaluate an expression of the form (1) for many different weights associated with a fixed set of points . For example, in the projection application described in §1.3 the weights correspond to a function that is being projected, while the points are a fixed set of quadrature nodes. In such situations, pre-computing the exponentials used in the Algorithm 3.1 will significantly improve the runtime, see §5.1.
4. Proof of Main Result
4.1. Organization
In this section we complete the proof of Theorem 2.1; the section is organized as follows. In §4.2 we give mathematical preliminaries. In §4.3 we state and prove two technical lemmas. In §4.4 we prove Lemma 4.5, which together with the analysis in §3 establishes Theorem 2.1. In §4.5 we prove Corollary 2.1, and Corollary 2.2.
4.2. Preliminaries
Let and be fixed, and suppose that , and are given. The interpolating polynomial of the function at is the unique polynomial of degree at most such that
[TABLE]
This interpolating polynomial can be explicitly defined by
[TABLE]
where is the nodal polynomial for , that is,
[TABLE]
We say are Chebyshev nodes for the interval if
[TABLE]
The following lemma is a classical result in approximation theory. It says that a smooth function on a compact interval is accurately approximated by the interpolating polynomial of the function at Chebyshev nodes, see for example §4.5.2 of Dahlquist and Björck [5].
Lemma 4.1**.**
Let , and be Chebyshev nodes for . If is the interpolating polynomial for at , then
[TABLE]
where
[TABLE]
In addition to Lemma 4.1, we require a result about the existence of generalized Gaussian quadratures for Chebyshev systems. In 1866, Gauss [8] established the existence of quadrature nodes and weights for an interval such that
[TABLE]
whenever is a polynomial of degree at most . This result was generalized from polynomials to Chebyshev systems by Kreĭn [13]. A collection of functions on is a Chebyshev system if every nonzero generalized polynomial
[TABLE]
has at most distinct zeros in . The following result of Kreĭn says that any function in the span of a Chebyshev system of functions can be integrated exactly by a quadrature with nodes and weights.
Lemma 4.2** (Kreĭn [13]).**
Let be a Chebyshev system of continuous functions on , and be a continuous positive weight function. Then, there exists unique nodes and weights such that
[TABLE]
whenever is in the span of .
4.3. Technical Lemmas
In this section, we state and prove two technical lemmas that are involved in the proof of Theorem 2.1. We remark that a similar version of Lemma 4.3 appears in [18].
Lemma 4.3**.**
Fix and , and let be Chebyshev nodes for . If is the interpolating polynomial for at , then
[TABLE]
Proof.
We have
[TABLE]
By writing the derivative of as
[TABLE]
we can deduce that the maximum of occurs at , that is,
[TABLE]
By (21) and the result of Lemma 4.1, we conclude that
[TABLE]
It remains to show that . Since is a increasing function, we have
[TABLE]
Exponentiating both sides of this inequality gives , which is a classical inequality related to Stirling’s approximation. This completes the proof. ∎
Lemma 4.4**.**
Suppose that and are given. Then, there exists
[TABLE]
values such that for all we have
[TABLE]
for some choice of coefficients that depend on .
Proof.
We construct an explicit set of points and coefficients such that (22) holds. Set . We define the points by
[TABLE]
for and , and define the coefficients by
[TABLE]
for and . We claim that
[TABLE]
Indeed, fix , and let be the unique integer such that . By the definition of the coefficients, see (24), we have
[TABLE]
We claim that the right hand side of this equation is the interpolating polynomial for at , that is,
[TABLE]
Indeed, see (18) and (19). Since the points are Chebyshev nodes for the interval , and since was chosen such that , it follows from Lemma 4.3 that
[TABLE]
Since the proof is complete. ∎
Remark 4.1**.**
The proof of Lemma 4.4 has the additional consequence that the coefficients in (22) can be chosen such that they satisfy
[TABLE]
Indeed, in (24) the coefficients are either equal zero or equal to the nodal polynomial, see (19), for Chebyshev nodes on an interval that contains . The nodal polynomials for Chebyshev nodes on an interval are bounded by on , see for example [18]. The fact that can be approximated as a linear combination of functions with small coefficients means that the approximation of Lemma 4.4 can be used in finite precision environments without any unexpected catastrophic cancellation.
4.4. Completing the proof of Theorem 2.1
Previously in §3.2, we proved that the algorithm of §3 involves operations. To complete the proof of Theorem 2.1 it remains to show that there exists
[TABLE]
points and weights that satisfy (17); we show the existence of such nodes and weights in the following lemma, and thus complete the proof of Theorem 2.1. The computation of such nodes and weights is described in §5.2.
Lemma 4.5**.**
Fix , and let and be given. Then, there exists nodes and weights such that
[TABLE]
Proof.
Fix , and let be given. By the possibility of rescaling , , and , we may assume that such that we want to establish (25) for . By Lemma 4.4 we can choose points , and coefficients depending on such that
[TABLE]
The collection of functions form a Chebyshev system of continuous functions on the interval , see for example [12]. Thus, by Lemma 4.2 there exists quadrature nodes and weights such that
[TABLE]
whenever is in the span of . By the triangle inequality
[TABLE]
Recall that we have assumed , in particular, so it follows that
[TABLE]
By (26), the function can be approximated to error in the -norm on by functions in the span of . Since our quadrature is exact for these functions, we conclude that
[TABLE]
Combining (27), (28), and (29) completes the proof. ∎
4.5. Proof of Corollary 2.1
In this section, we prove Corollary 2.1, which states that the algorithm of §3 involves operations when are Chebyshev nodes, , and .
Proof of Corollary 2.1.
By rescaling the problem we may assume that such that the Chebyshev nodes are given by
[TABLE]
By the result of Theorem 2.1, it suffices to show that , where
[TABLE]
It is straightforward to verify that the number of Chebyshev nodes within an interval of radius around the point is , that is,
[TABLE]
This estimate, together with the fact that the first and last Chebyshev node are distance at least from and , respectively, gives the estimate
[TABLE]
Let be a fixed parameter; direct calculation yields
[TABLE]
Combining this estimate with (30) yields as was to be shown. ∎
5. Numerical results and implementation details
5.1. Numerical results
We report numerical results for two different point distributions: uniformly random points in , and Chebyshev nodes in . In both cases, we choose the weights uniformly at random from , and test the algorithm for
[TABLE]
We time two different versions of the algorithm: a standard implementation, and an implementation that uses precomputed exponentials. Precomputing exponentials may be advantageous in situations where the expression
[TABLE]
must be evaluated for many different weights associated with a fixed set of points , see Remark 3.1. We find that using precomputed exponentials makes the algorithm approximately ten times faster, see Tables 1, 2, and 3. In addition to reporting timings, we report the absolute relative difference between the output of the algorithm of §3 and the output of direct evaluation; we define the absolute relative difference between the output of the algorithm of §3 and the output of direct calculation by
[TABLE]
Dividing by accounts were the fact that the calculations are performed in finite precision; any remaining loss of accuracy in the numerical results is a consequence of the large number of addition and multiplication operations that are performed. All calculations are performed in double precision, and the algorithm of §3 is run with . The parameter is set via an empirically determined heuristic. The numerical experiments were performed on a laptop with a Intel Core i5-8350U CPU and GiB of memory; the code was written in Fortran and compiled with gfortran with standard optimization flags. The results are reported in Tables 1, 2, and 3.
To put the run time of the algorithm in context, we additionally perform a time comparison to the Fast Fourier Transform (FFT), which also has complexity . Specifically, we compare the run time of the algorithm of §3 on random data using precomputed exponentials with the run time of an FFT implementation from FFTPACK [20] on random data of the same length using precomputed exponentials. We report these timings in Table 4; we find that the FFT is roughly - times faster than our implementation of the algorithm of §3; we remark that no significant effort was made to optimize our implementation, and that it may be possible to improve the run time by vectorization.
5.2. Computing nodes and weights
The algorithm of §3 is described under the assumption that nodes and weights are given such that
[TABLE]
where and are fixed parameters. As in the proof of Lemma 4.5 we note that by rescaling it suffices to find nodes and weights satisfying
[TABLE]
Indeed, if the nodes and weights satisfy (34), then the nodes and weights will satisfy (33). Thus, in order to implement the algorithm of §3 it suffices to tabulate nodes and weights that are valid for for various values of . In the implementation used in the numerical experiments in this paper, we tabulated nodes and weights valid for for
[TABLE]
For example, in Tables 5 and 6 we have listed nodes and weights such that
[TABLE]
for all .
The nodes and weights satisfying (34) can be computed by using a procedure for generating generalized Gaussian quadratures for Chebyshev systems together with the proof of Lemma 4.4. Indeed, Lemma 4.4 is constructive with the exception of the step that invokes Lemma 4.2 of Kreĭn. The procedure described in [4] is a constructive version of Lemma 4.2: given a Chebyshev system of functions, it generates the corresponding quadrature nodes and weights. We remark that generalized Gaussian quadrature generation codes are a powerful tools for numerical computation with a wide range of applications. The quadrature generation code used in this paper was an optimized version of [4] recently developed by Serkh for [19].
Acknowledgements
The authors would like to thank Jeremy Hoskins for many useful discussions. Certain commercial equipment is identified in this paper to foster understanding. Such identification does not imply recommendation or endorsement by the National Institute of Standards and Technology, nor does it imply that equipment identified is necessarily the best available for the purpose.
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1[1] Gregory Beylkin and Lucas Monzón, Approximation by exponential sums revisited , Appl. Comput. Harmon. Anal. 28 (2010), no. 2, 131–149. MR 2595881
- 2[2] Gregory Beylkin and Lucas Monzón, On approximation of functions by exponential sums , Appl. Comput. Harmon. Anal. 19 (2005), no. 1, 17–48. MR 2147060
- 3[3] Dietrich Braess, Nonlinear approximation theory , Springer Series in Computational Mathematics, vol. 7, Springer-Verlag, Berlin, 1986. MR 866667
- 4[4] James Bremer, Zydrunas Gimbutas, and Vladimir Rokhlin, A nonlinear optimization procedure for generalized Gaussian quadratures , SIAM J. Sci. Comput. 32 (2010), no. 4, 1761–1788. MR 2671296
- 5[5] Germund Dahlquist and Åke Björck, Numerical methods , Dover Publications, Inc., Mineola, NY, 2003, Translated from the Swedish by Ned Anderson, Reprint of the 1974 English translation. MR 1978058
- 6[6] A. Dutt, M. Gu, and V. Rokhlin, Fast algorithms for polynomial interpolation, integration, and differentiation , SIAM J. Numer. Anal. 33 (1996), no. 5, 1689–1711. MR 1411845
- 7[7] William Fong and Eric Darve, The black-box fast multipole method , J. Comput. Phys. 228 (2009), no. 23, 8712–8725. MR 2558773
- 8[8] C. F. Gauss. Methodus nova integralium valores per approximationen inveniendi , Werke, 3 (1866), 1630–196.
