arithmetic_geometric_mean_kernel_real64 Function

private 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.

Note

Convergence criterion
See is_not_converged

Arguments

Type IntentOptional Attributes Name
real(kind=real64), intent(in) :: a

arithmetic mean

real(kind=real64), intent(in) :: g

geometric mean

Return Value real(kind=real64)


Variables

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


Source Code

    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