docs: def _finite_well_energy(P, n=1, atol=1e-6):
      '''
      Returns the nth bound-state energy for a finite-potential quantum well
      with the given well-strength parameter, `P`.
      '''
      assert n > 0 and n <= _finite_well_states(P)
      pi_2 = pi / 2.
      r = (1 / (P + pi_2)) * (n * pi_2)
      eta = n * pi_2 - arcsin(r) - r * P
      w = 1  # relaxation parameter (for succesive relaxation)
      while True:
          assert r <= 1
          if abs(eta) < atol:
              break
          r2 = r ** 2.
          sqrt_1mr2 = sqrt(1. - r2)
          denom = (1. + P * sqrt_1mr2)
          t1 = P * sqrt_1mr2 / denom * eta
  #         t2 = -r * P / (2 * (1. + P * sqrt_1mr2) ** 3) * eta ** 2
          while True:
              next_r = (1 - w) * r + w * (r + t1)
  #             next_r = (1 - w) * r + w * (r + t1 + t2)
              next_eta = n * pi_2 - arcsin(next_r) - next_r * P
              # decrease w until eta is converging
              if abs(next_eta / eta) < 1:
                  r = next_r
                  eta = next_eta
                  break
              else:
                  w *= 0.5
  
      alpha = P * r
      E = 2 * (alpha) ** 2  # hbar**2 / (m * L**2)
      return E