E.V.E
v2023.02.15
 
Loading...
Searching...
No Matches

◆ lentz_a

auto eve::lentz_a = functor<lentz_a_t>
inlineconstexpr

Defined in header

#include <eve/module/math.hpp>

Callable Signatures

namespace eve
{
template< typename Gen, eve::scalar_value T> auto lentz_a(Gen g, const T& tol, size_t & max_terms) noexcept;
}
constexpr auto lentz_a
Implement the lentz scheme to evaluate continued fractions.
Definition lentz_a.hpp:74
EVE Main Namespace.
Definition abi.hpp:18

Parameters

  • g : generator function.
  • tol : tolerance value. If negative the effective tolerance will be abs(tol)*eveeps(as(< u_t>) where u_t is the underlying floating type associated to the return type of the invocable g.
  • max_terms : no more than max_terms calls to the generator will be made,

The generator type should be an invocable which supports the following operations:

  • The call to g() returns a floating value or a pair (kumi::tuple) of such. Each time this operator is called then the next pair of a and b values has to be returned, or, if result_type is not a pair type, then the next b value has to be returned and all the a values are assumed to be equal to one.
  • In all the continued fraction evaluation functions the effective tol parameter is the relative precision desired in the result, The evaluation of the fraction will continue until the last term evaluated leaves the relative error in the result less than tolerance or the max_terms iteration is reached.

Return value

The value of the continued fraction is returned. \(\displaystyle \frac{a_0}{b_0+\frac{a_1}{b_1+\frac{a_2}{b_2+\cdots\vphantom{\frac{1}{1}} }}}\)

Example

// revision 1
#include <eve/module/math.hpp>
#include <iostream>
template <class T>
struct const_fraction
{
typedef T result_type;
result_type operator()()
{
return T{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0};
}
};
int main()
{
eve::wide z{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0};
auto ref = (-z+eve::sqrt(eve::sqr(z)+4))/2;
std::cout << "ref constant fracs are: " << ref << std::endl;
const_fraction<decltype(z)> func;
auto gr = eve::lentz_a(func,eve::eps(eve::as<double>()), 100);
std::cout << " constant fracs are: " << gr << std::endl;
}
constexpr auto sqr
Computes the square of the parameter.
Definition sqr.hpp:92
constexpr auto sqrt
Computes the square root of the parameter.
Definition sqrt.hpp:80
constexpr auto eps
Computes a constant to the machine epsilon.
Definition eps.hpp:73
Lightweight type-wrapper.
Definition as.hpp:29
Wrapper for SIMD registers.
Definition wide.hpp:86