In mathematics, Lentz's algorithm is an algorithm to evaluate continued fractions and compute tables of spherical Bessel functions.
 The version usually employed now is due to Thompson and Barnett.
 The idea was introduced in 1973 by William J. Lentz and was simplified by him in 1982. Lentz suggested that calculating ratios of spherical Bessel functions of complex arguments can be difficult. He developed a new continued fraction technique for calculating the ratios of spherical Bessel functions of consecutive order. This method was an improvement compared to other methods because it started from the beginning of the continued fraction rather than the tail, had a built-in check for convergence, and was numerically stable.  The original algorithm uses algebra to bypass a zero in either the numerator or denominator.  Simpler Improvements to overcome unwanted zero terms include an altered recurrence relation suggested by Jaaskelainen and Ruuskanen  in 1981 or a simple shift of the denominator by a very small number as suggested by Thompson and Barnett in 1986.
 This theory was initially motivated by Lentz's need for accurate calculation of ratios of spherical Bessel function necessary for Mie scattering. He created a new continued fraction algorithm that starts from the beginning of the continued fraction and not at the tail-end. This eliminates guessing how many terms of the continued fraction are needed for convergence.  In addition, continued fraction representations for both ratios of Bessel functions and spherical Bessel functions of consecutive order themselves can be computed with Lentz's algorithm. The algorithm suggested that it is possible to terminate the evaluation of continued fractions when 
  
    
      
        
          |
        
        
          f
          
            j
          
        
        −
        
          f
          
            j
            −
            1
          
        
        
          |
        
      
    
    {\displaystyle |f_{j}-f_{j-1}|}
  
 is relatively small.
 Lentz's algorithm is based on the Wallis-Euler relations. If
 etc., or using the big-K notation, if
 is the 
  
    
      
        n
      
    
    {\displaystyle n}
  
th convergent to 
  
    
      
        f
      
    
    {\displaystyle f}
  
 then
 where 
  
    
      
        
          
            A
          
          
            n
          
        
      
    
    {\displaystyle {A}_{n}}
  
 and 
  
    
      
        
          
            B
          
          
            n
          
        
      
    
    {\displaystyle {B}_{n}}
  
 are given by the Wallis-Euler recurrence relations
 Lentz's method defines
 so that the 
  
    
      
        n
      
    
    {\displaystyle n}
  
th convergent is
 and uses the recurrence relations
 When the product 
  
    
      
        
          
            C
          
          
            n
          
        
        
          
            D
          
          
            n
          
        
      
    
    {\displaystyle {C}_{n}{D}_{n}}
  
 approaches unity with increasing 
  
    
      
        n
      
    
    {\displaystyle n}
  
, it is hoped that 
  
    
      
        
          
            f
          
          
            n
          
        
      
    
    {\displaystyle {f}_{n}}
  
 has converged to 
  
    
      
        f
      
    
    {\displaystyle f}
  
.
 Lentz's algorithm was used widely in the late twentieth century. It was suggested that it doesn't have any rigorous analysis of error propagation. However, a few empirical tests suggest that it's at least as good as the other methods. As an example, it was applied to evaluate exponential integral functions. This application was then called modified Lentz algorithm. It's also stated that the Lentz algorithm is not applicable for every calculation, and convergence can be quite rapid for some continued fractions and vice versa for others.