Optimist  0.0.0
A C++ library for optimization
Loading...
Searching...
No Matches
Halley.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
2 * Copyright (c) 2025, Davide Stocco and Enrico Bertolazzi. *
3 * *
4 * The Optimist project is distributed under the BSD 2-Clause License. *
5 * *
6 * Davide Stocco Enrico Bertolazzi *
7 * University of Trento University of Trento *
8 * davide.stocco@unitn.it enrico.bertolazzi@unitn.it *
9\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
10
11#pragma once
12
13#ifndef OPTIMIST_ROOTFINDER_HALLEY_HH
14#define OPTIMIST_ROOTFINDER_HALLEY_HH
15
17
18namespace Optimist {
19
20 namespace RootFinder {
21
29 template <typename Scalar>
30 requires TypeTrait<Scalar>::IsScalar
31 class Halley : public OpenMethod<Scalar, Halley<Scalar>> {
32 public:
33 static constexpr bool RequiresFunction{true};
34 static constexpr bool RequiresFirstDerivative{true};
35 static constexpr bool RequiresSecondDerivative{true};
36
38
39
42 Halley() {}
43
48 constexpr std::string name_impl() const {
49 return "Halley";
50 }
51
64 template <typename FunctionLambda>
65 Scalar step_impl([[maybe_unused]] FunctionLambda &function,
66 [[maybe_unused]] const Scalar x,
67 const Scalar f,
68 const Scalar df,
69 [[maybe_unused]] const Scalar ddf) const {
70 const Scalar newton{-f / df};
71 const Scalar L{f * ddf / (df * df)};
72 return std::abs(L) < 1 ? newton / (1 - L / 2) : newton;
73 }
74
75 }; // class Halley
76
77 } // namespace RootFinder
78
79} // namespace Optimist
80
81#endif // OPTIMIST_ROOTFINDER_HALLEY_HH
#define OPTIMIST_BASIC_CONSTANTS(Scalar)
Definition Optimist.hh:70
Scalar step_impl(FunctionLambda &function, const Scalar x, const Scalar f, const Scalar df, const Scalar ddf) const
Definition Halley.hh:65
static constexpr bool RequiresFunction
Definition Halley.hh:33
static constexpr bool RequiresFirstDerivative
Definition Halley.hh:34
constexpr std::string name_impl() const
Definition Halley.hh:48
Halley()
Definition Halley.hh:42
static constexpr bool RequiresSecondDerivative
Definition Halley.hh:35
Base class for the open (i.e., non-bracketing) one-dimensional root finders of Newton type.
Definition OpenMethod.hh:46
typename TypeTrait< Scalar >::Scalar Scalar
Definition RootFinder.hh:47
Namespace for the Optimist library.
Definition Optimist.hh:90