Skip to content

Commit 5d5d264

Browse files
Include our own ERF
1 parent 0252acb commit 5d5d264

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Source/Fortran/FermiOperatorModule.F90

+19
Original file line numberDiff line numberDiff line change
@@ -625,5 +625,24 @@ SUBROUTINE ComputeCStep(X, A, W, pool, threshold, Out)
625625
CALL DestructMatrix(XA)
626626

627627
END SUBROUTINE ComputeCStep
628+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
629+
!> ERF is a Fortran2008 feature, and we just need a crude approximation here
630+
!! so we implement it with the Abramowitz and Stegun approximation
631+
!! (credit ChatGPT).
632+
FUNCTION ERF(x)
633+
REAL(NTREAL) :: x, erf
634+
REAL(NTREAL) :: t, z, tau
635+
REAL(NTREAL), PARAMETER :: a1 = 0.254829592_NTREAL
636+
REAL(NTREAL), PARAMETER :: a2 = -0.284496736_NTREAL
637+
REAL(NTREAL), PARAMETER :: a3 = 1.421413741_NTREAL
638+
REAL(NTREAL), PARAMETER :: a4 = -1.453152027_NTREAL
639+
REAL(NTREAL), PARAMETER :: a5 = 1.061405429_NTREAL
640+
REAL(NTREAL), PARAMETER :: p = 0.3275911_NTREAL
641+
642+
z = ABS(x)
643+
t = 1.0_NTREAL / (1.0_NTREAL + p * z)
644+
tau = t * (a1 + t * (a2 + t * (a3 + t * (a4 + t * a5))))
645+
erf = SIGN(1.0_NTREAL, x) * (1.0_NTREAL - tau * EXP(-z * z))
646+
END FUNCTION ERF
628647
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
629648
END MODULE FermiOperatorModule

0 commit comments

Comments
 (0)