Compute arithmetic–geometric mean (AGM)
using the given arithmetic mean a and geometric mean g.
This function provides a lightweight AGM computation
that returns only the final converged value
without storing iteration history.
For applications that need to analyze the convergence process,
use the type-bound subroutine compute_kernel_real64 instead,
which preserves the full iteration history.
Warning
Note
Convergence criterion
See is_not_converged
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=real64), | intent(in) | :: | a |
arithmetic mean |
||
| real(kind=real64), | intent(in) | :: | g |
geometric mean |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| real(kind=real64), | private | :: | next_a |
next arithmetic mean |
|||
| real(kind=real64), | private | :: | next_g |
next geometric mean |
|||
| real(kind=real64), | private | :: | prev_a |
previous arithmetic mean |
|||
| real(kind=real64), | private | :: | prev_g |
previous geometric mean |
elemental function arithmetic_geometric_mean_kernel_real64(a, g) result(agm) !! Compute arithmetic–geometric mean (AGM) !! using the given arithmetic mean `a` and geometric mean `g`. !! !! This function provides a lightweight AGM computation !! that returns only the final converged value !! without storing iteration history. !! For applications that need to analyze the convergence process, !! use the type-bound subroutine [[compute_kernel_real64]] instead, !! which preserves the full iteration history. !! !! @warning !! - This function assumes both inputs are positive. !! - No validation is performed on inputs. !! @endwarning !! !! @note !! **Convergence criterion** !! See [[is_not_converged]] !! @endnote real(real64), intent(in) :: a !! arithmetic mean real(real64), intent(in) :: g !! geometric mean real(real64) :: agm ! return value real(real64) :: prev_a !! previous arithmetic mean real(real64) :: prev_g !! previous geometric mean real(real64) :: next_a !! next arithmetic mean real(real64) :: next_g !! next geometric mean prev_a = a prev_g = g do call compute_step( &! prev_a = prev_a , &! prev_g = prev_g , &! next_a = next_a , &! next_g = next_g &! ) if ( is_not_converged(next_a, next_g) ) then prev_a = next_a prev_g = next_g cycle else agm = max(next_a, next_g) return end if end do end function arithmetic_geometric_mean_kernel_real64