
(FPCore (x)
:precision binary64
(let* ((t_0 (* (* (fabs x) (fabs x)) (fabs x)))
(t_1 (* (* t_0 (fabs x)) (fabs x))))
(fabs
(*
(/ 1.0 (sqrt (PI)))
(+
(+ (+ (* 2.0 (fabs x)) (* (/ 2.0 3.0) t_0)) (* (/ 1.0 5.0) t_1))
(* (/ 1.0 21.0) (* (* t_1 (fabs x)) (fabs x))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\\
t_1 := \left(t\_0 \cdot \left|x\right|\right) \cdot \left|x\right|\\
\left|\frac{1}{\sqrt{\mathsf{PI}\left(\right)}} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot t\_0\right) + \frac{1}{5} \cdot t\_1\right) + \frac{1}{21} \cdot \left(\left(t\_1 \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right|
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x)
:precision binary64
(let* ((t_0 (* (* (fabs x) (fabs x)) (fabs x)))
(t_1 (* (* t_0 (fabs x)) (fabs x))))
(fabs
(*
(/ 1.0 (sqrt (PI)))
(+
(+ (+ (* 2.0 (fabs x)) (* (/ 2.0 3.0) t_0)) (* (/ 1.0 5.0) t_1))
(* (/ 1.0 21.0) (* (* t_1 (fabs x)) (fabs x))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\\
t_1 := \left(t\_0 \cdot \left|x\right|\right) \cdot \left|x\right|\\
\left|\frac{1}{\sqrt{\mathsf{PI}\left(\right)}} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot t\_0\right) + \frac{1}{5} \cdot t\_1\right) + \frac{1}{21} \cdot \left(\left(t\_1 \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right|
\end{array}
\end{array}
(FPCore (x)
:precision binary64
(let* ((t_0 (pow (PI) -0.5)))
(fabs
(fma
(fma 0.2 (pow x 5.0) (fma 0.6666666666666666 (pow x 3.0) (* 2.0 x)))
t_0
(* (* t_0 0.047619047619047616) (pow x 7.0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\mathsf{PI}\left(\right)}^{-0.5}\\
\left|\mathsf{fma}\left(\mathsf{fma}\left(0.2, {x}^{5}, \mathsf{fma}\left(0.6666666666666666, {x}^{3}, 2 \cdot x\right)\right), t\_0, \left(t\_0 \cdot 0.047619047619047616\right) \cdot {x}^{7}\right)\right|
\end{array}
\end{array}
Initial program 99.9%
Applied rewrites99.9%
(FPCore (x)
:precision binary64
(fabs
(*
(pow (sqrt (PI)) -1.0)
(+
(+
(+ (* 2.0 (fabs x)) (* (/ 2.0 3.0) (* (* x x) (fabs x))))
(* (pow 5.0 -1.0) (fabs (* (* (* (* x x) x) x) x))))
(* (pow 21.0 -1.0) (* (* (pow x 5.0) x) (fabs x)))))))\begin{array}{l}
\\
\left|{\left(\sqrt{\mathsf{PI}\left(\right)}\right)}^{-1} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot \left(\left(x \cdot x\right) \cdot \left|x\right|\right)\right) + {5}^{-1} \cdot \left|\left(\left(\left(x \cdot x\right) \cdot x\right) \cdot x\right) \cdot x\right|\right) + {21}^{-1} \cdot \left(\left({x}^{5} \cdot x\right) \cdot \left|x\right|\right)\right)\right|
\end{array}
Initial program 99.9%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
lift-*.f64N/A
pow3N/A
pow2N/A
pow-prod-upN/A
metadata-evalN/A
lower-pow.f6499.9
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt78.1
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt99.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (* (* x x) (* x x))))
(fabs
(*
(pow (sqrt (PI)) -1.0)
(+
(+
(+ (* 2.0 (fabs x)) (* (* x x) (* x 0.6666666666666666)))
(* (pow 5.0 -1.0) (* t_0 (fabs x))))
(* (pow 21.0 -1.0) (* (fabs (* (* t_0 x) x)) (fabs x))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot x\right) \cdot \left(x \cdot x\right)\\
\left|{\left(\sqrt{\mathsf{PI}\left(\right)}\right)}^{-1} \cdot \left(\left(\left(2 \cdot \left|x\right| + \left(x \cdot x\right) \cdot \left(x \cdot 0.6666666666666666\right)\right) + {5}^{-1} \cdot \left(t\_0 \cdot \left|x\right|\right)\right) + {21}^{-1} \cdot \left(\left|\left(t\_0 \cdot x\right) \cdot x\right| \cdot \left|x\right|\right)\right)\right|
\end{array}
\end{array}
Initial program 99.9%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
lower-*.f6499.9
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt81.2
lift-/.f64N/A
metadata-eval81.2
Applied rewrites81.2%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-abs-revN/A
lift-*.f64N/A
associate-*l*N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-abs-revN/A
lift-*.f64N/A
lower-*.f6481.2
Applied rewrites81.2%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-abs-revN/A
lift-*.f64N/A
associate-*l*N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-abs-revN/A
lift-*.f64N/A
lift-*.f6481.2
Applied rewrites81.2%
Final simplification81.2%
(FPCore (x)
:precision binary64
(fabs
(*
(pow (sqrt (PI)) -1.0)
(fma
(pow x 5.0)
0.2
(fma
x
(fma 0.6666666666666666 (* x x) 2.0)
(* (pow x 7.0) 0.047619047619047616))))))\begin{array}{l}
\\
\left|{\left(\sqrt{\mathsf{PI}\left(\right)}\right)}^{-1} \cdot \mathsf{fma}\left({x}^{5}, 0.2, \mathsf{fma}\left(x, \mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right), {x}^{7} \cdot 0.047619047619047616\right)\right)\right|
\end{array}
Initial program 99.9%
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (<= x 2.2) (fabs (* (* (fma (* x x) 0.6666666666666666 2.0) x) (sqrt (pow (PI) -1.0)))) (* (pow x 7.0) (/ 0.047619047619047616 (sqrt (PI))))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.2:\\
\;\;\;\;\left|\left(\mathsf{fma}\left(x \cdot x, 0.6666666666666666, 2\right) \cdot x\right) \cdot \sqrt{{\mathsf{PI}\left(\right)}^{-1}}\right|\\
\mathbf{else}:\\
\;\;\;\;{x}^{7} \cdot \frac{0.047619047619047616}{\sqrt{\mathsf{PI}\left(\right)}}\\
\end{array}
\end{array}
if x < 2.2000000000000002Initial program 99.9%
Applied rewrites99.9%
Taylor expanded in x around 0
Applied rewrites91.7%
if 2.2000000000000002 < x Initial program 99.9%
Applied rewrites99.9%
Taylor expanded in x around 0
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
rem-square-sqrtN/A
lower-sqrt.f64N/A
rem-square-sqrtN/A
lower-/.f64N/A
lower-PI.f6474.2
Applied rewrites74.2%
Taylor expanded in x around inf
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
rem-square-sqrtN/A
lower-sqrt.f64N/A
rem-square-sqrtN/A
lower-/.f64N/A
lower-PI.f6430.7
Applied rewrites30.7%
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt4.0
Applied rewrites4.0%
Final simplification91.7%
(FPCore (x) :precision binary64 (fabs (* (* (fma (* x x) 0.6666666666666666 2.0) x) (sqrt (pow (PI) -1.0)))))
\begin{array}{l}
\\
\left|\left(\mathsf{fma}\left(x \cdot x, 0.6666666666666666, 2\right) \cdot x\right) \cdot \sqrt{{\mathsf{PI}\left(\right)}^{-1}}\right|
\end{array}
Initial program 99.9%
Applied rewrites99.9%
Taylor expanded in x around 0
Applied rewrites91.7%
Final simplification91.7%
(FPCore (x) :precision binary64 (if (<= x 1.75) (fabs (* (+ x x) (sqrt (pow (PI) -1.0)))) (fabs (* x (* (* x x) (/ 0.6666666666666666 (sqrt (PI))))))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.75:\\
\;\;\;\;\left|\left(x + x\right) \cdot \sqrt{{\mathsf{PI}\left(\right)}^{-1}}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|x \cdot \left(\left(x \cdot x\right) \cdot \frac{0.6666666666666666}{\sqrt{\mathsf{PI}\left(\right)}}\right)\right|\\
\end{array}
\end{array}
if x < 1.75Initial program 99.9%
Applied rewrites99.9%
Taylor expanded in x around 0
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
rem-square-sqrtN/A
lower-sqrt.f64N/A
rem-square-sqrtN/A
lower-/.f64N/A
lower-PI.f6474.2
Applied rewrites74.2%
Applied rewrites74.2%
if 1.75 < x Initial program 99.9%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
lower-*.f6499.9
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt81.2
lift-/.f64N/A
metadata-eval81.2
Applied rewrites81.2%
Taylor expanded in x around inf
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
rem-square-sqrtN/A
lower-sqrt.f64N/A
rem-square-sqrtN/A
lower-/.f64N/A
lower-PI.f6423.5
Applied rewrites23.5%
Applied rewrites23.5%
Final simplification74.2%
(FPCore (x) :precision binary64 (fabs (* (+ x x) (sqrt (pow (PI) -1.0)))))
\begin{array}{l}
\\
\left|\left(x + x\right) \cdot \sqrt{{\mathsf{PI}\left(\right)}^{-1}}\right|
\end{array}
Initial program 99.9%
Applied rewrites99.9%
Taylor expanded in x around 0
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
rem-square-sqrtN/A
lower-sqrt.f64N/A
rem-square-sqrtN/A
lower-/.f64N/A
lower-PI.f6474.2
Applied rewrites74.2%
Applied rewrites74.2%
Final simplification74.2%
(FPCore (x) :precision binary64 0.0)
double code(double x) {
return 0.0;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = 0.0d0
end function
public static double code(double x) {
return 0.0;
}
def code(x): return 0.0
function code(x) return 0.0 end
function tmp = code(x) tmp = 0.0; end
code[x_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 99.9%
Applied rewrites99.9%
Taylor expanded in x around 0
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
rem-square-sqrtN/A
lower-sqrt.f64N/A
rem-square-sqrtN/A
lower-/.f64N/A
lower-PI.f6474.2
Applied rewrites74.2%
Applied rewrites74.2%
Applied rewrites4.3%
Final simplification4.3%
herbie shell --seed 2024354
(FPCore (x)
:name "Jmat.Real.erfi, branch x less than or equal to 0.5"
:precision binary64
:pre (<= x 0.5)
(fabs (* (/ 1.0 (sqrt (PI))) (+ (+ (+ (* 2.0 (fabs x)) (* (/ 2.0 3.0) (* (* (fabs x) (fabs x)) (fabs x)))) (* (/ 1.0 5.0) (* (* (* (* (fabs x) (fabs x)) (fabs x)) (fabs x)) (fabs x)))) (* (/ 1.0 21.0) (* (* (* (* (* (* (fabs x) (fabs x)) (fabs x)) (fabs x)) (fabs x)) (fabs x)) (fabs x)))))))