
(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 (sqrt (PI))))
(fabs
(fma
(pow t_0 -1.0)
(* x (fma 0.2 (pow x 4.0) (fma (* 0.6666666666666666 x) x 2.0)))
(* (/ 0.047619047619047616 t_0) (pow x 7.0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
\left|\mathsf{fma}\left({t\_0}^{-1}, x \cdot \mathsf{fma}\left(0.2, {x}^{4}, \mathsf{fma}\left(0.6666666666666666 \cdot x, x, 2\right)\right), \frac{0.047619047619047616}{t\_0} \cdot {x}^{7}\right)\right|
\end{array}
\end{array}
Initial program 99.9%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
lower-*.f6499.9
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt73.3
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt99.9
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt73.3
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt99.9
Applied rewrites99.9%
lift-*.f64N/A
lift-/.f64N/A
metadata-evalN/A
lift-*.f64N/A
lift-*.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-abs-revN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites77.6%
Applied rewrites99.9%
lift-pow.f64N/A
metadata-evalN/A
sqrt-pow2N/A
lift-sqrt.f64N/A
inv-powN/A
lift-/.f6499.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x)
:precision binary64
(fabs
(*
(/ -1.0 (sqrt (PI)))
(-
(+
(+ (* 2.0 (fabs x)) (* (/ 2.0 3.0) (* (* x x) (fabs x))))
(* (pow 5.0 -1.0) (fabs (* (* (* (* x x) x) x) x))))
(* (/ -1.0 21.0) (* (pow x 6.0) (fabs x)))))))\begin{array}{l}
\\
\left|\frac{-1}{\sqrt{\mathsf{PI}\left(\right)}} \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) - \frac{-1}{21} \cdot \left({x}^{6} \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
associate-*l*N/A
lift-*.f64N/A
lift-*.f64N/A
pow3N/A
lift-*.f64N/A
pow2N/A
pow-powN/A
lower-pow.f64N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
metadata-eval99.9
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (fabs (* (* (* (* x x) x) x) x))))
(fabs
(*
(/ -1.0 (sqrt (PI)))
(-
(+
(+ (* 2.0 (fabs x)) (* (* x x) (* x 0.6666666666666666)))
(* (pow 5.0 -1.0) t_0))
(* (/ -1.0 21.0) (* (* t_0 (fabs x)) (fabs x))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|\left(\left(\left(x \cdot x\right) \cdot x\right) \cdot x\right) \cdot x\right|\\
\left|\frac{-1}{\sqrt{\mathsf{PI}\left(\right)}} \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 t\_0\right) - \frac{-1}{21} \cdot \left(\left(t\_0 \cdot \left|x\right|\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-sqrt77.6
lift-/.f64N/A
metadata-eval77.6
Applied rewrites77.6%
Final simplification77.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (* (* x x) (* x x))))
(fabs
(*
(/ -1.0 (sqrt (PI)))
(-
(+
(+ (* 2.0 (fabs x)) (* (* (* 0.6666666666666666 x) x) x))
(* (pow 5.0 -1.0) (* t_0 (fabs x))))
(* (/ -1.0 21.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|\frac{-1}{\sqrt{\mathsf{PI}\left(\right)}} \cdot \left(\left(\left(2 \cdot \left|x\right| + \left(\left(0.6666666666666666 \cdot x\right) \cdot x\right) \cdot x\right) + {5}^{-1} \cdot \left(t\_0 \cdot \left|x\right|\right)\right) - \frac{-1}{21} \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
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
lower-*.f6499.9
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt73.3
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt99.9
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt73.3
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt99.9
Applied rewrites99.9%
lift-*.f64N/A
lift-/.f64N/A
metadata-evalN/A
lift-*.f64N/A
lift-*.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-abs-revN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites77.6%
lift-*.f64N/A
lift-*.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-abs-revN/A
lift-*.f64N/A
lower-*.f64N/A
associate-*l*N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-abs-revN/A
lift-*.f64N/A
lift-*.f6477.6
Applied rewrites77.6%
Final simplification77.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (pow (PI) -1.0))))
(if (<= x 1.75)
(fabs (* (+ x x) t_0))
(fabs (* t_0 (* (* (* x x) 0.6666666666666666) x))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{{\mathsf{PI}\left(\right)}^{-1}}\\
\mathbf{if}\;x \leq 1.75:\\
\;\;\;\;\left|\left(x + x\right) \cdot t\_0\right|\\
\mathbf{else}:\\
\;\;\;\;\left|t\_0 \cdot \left(\left(\left(x \cdot x\right) \cdot 0.6666666666666666\right) \cdot x\right)\right|\\
\end{array}
\end{array}
if x < 1.75Initial program 99.9%
Applied rewrites99.8%
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.f6467.4
Applied rewrites67.4%
Applied rewrites67.4%
if 1.75 < x Initial program 99.9%
Applied rewrites99.8%
Taylor expanded in x around 0
Applied rewrites88.6%
Taylor expanded in x around inf
Applied rewrites26.9%
Final simplification67.4%
(FPCore (x) :precision binary64 (fabs (* (sqrt (pow (PI) -1.0)) (* (fma (* x x) 0.6666666666666666 2.0) x))))
\begin{array}{l}
\\
\left|\sqrt{{\mathsf{PI}\left(\right)}^{-1}} \cdot \left(\mathsf{fma}\left(x \cdot x, 0.6666666666666666, 2\right) \cdot x\right)\right|
\end{array}
Initial program 99.9%
Applied rewrites99.8%
Taylor expanded in x around 0
Applied rewrites88.6%
Final simplification88.6%
(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.8%
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.f6467.4
Applied rewrites67.4%
Applied rewrites67.4%
Final simplification67.4%
(FPCore (x)
:precision binary64
(fabs
(*
(/ -1.0 (sqrt (PI)))
(-
(* (fabs x) 2.0)
(* (/ -1.0 21.0) (* (fabs (* (* (* (* x x) (* x x)) x) x)) (fabs x)))))))\begin{array}{l}
\\
\left|\frac{-1}{\sqrt{\mathsf{PI}\left(\right)}} \cdot \left(\left|x\right| \cdot 2 - \frac{-1}{21} \cdot \left(\left|\left(\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot x\right) \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
lower-*.f6499.9
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt73.3
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt99.9
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt73.3
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt99.9
Applied rewrites99.9%
lift-*.f64N/A
lift-/.f64N/A
metadata-evalN/A
lift-*.f64N/A
lift-*.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-abs-revN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites77.6%
lift-*.f64N/A
lift-*.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-abs-revN/A
lift-*.f64N/A
lower-*.f64N/A
associate-*l*N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-abs-revN/A
lift-*.f64N/A
lift-*.f6477.6
Applied rewrites77.6%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
lower-fabs.f6498.9
Applied rewrites98.9%
Final simplification98.9%
(FPCore (x) :precision binary64 (fabs 0.0))
double code(double x) {
return fabs(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 = abs(0.0d0)
end function
public static double code(double x) {
return Math.abs(0.0);
}
def code(x): return math.fabs(0.0)
function code(x) return abs(0.0) end
function tmp = code(x) tmp = abs(0.0); end
code[x_] := N[Abs[0.0], $MachinePrecision]
\begin{array}{l}
\\
\left|0\right|
\end{array}
Initial program 99.9%
Applied rewrites99.8%
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.f6467.4
Applied rewrites67.4%
Applied rewrites67.4%
Applied rewrites0.0%
Final simplification4.1%
herbie shell --seed 2024352
(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)))))))