
(FPCore (x eps) :precision binary64 (/ (- (* (+ 1.0 (/ 1.0 eps)) (exp (- (* (- 1.0 eps) x)))) (* (- (/ 1.0 eps) 1.0) (exp (- (* (+ 1.0 eps) x))))) 2.0))
double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.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, eps)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (((1.0d0 + (1.0d0 / eps)) * exp(-((1.0d0 - eps) * x))) - (((1.0d0 / eps) - 1.0d0) * exp(-((1.0d0 + eps) * x)))) / 2.0d0
end function
public static double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * Math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * Math.exp(-((1.0 + eps) * x)))) / 2.0;
}
def code(x, eps): return (((1.0 + (1.0 / eps)) * math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * math.exp(-((1.0 + eps) * x)))) / 2.0
function code(x, eps) return Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(-Float64(Float64(1.0 - eps) * x)))) - Float64(Float64(Float64(1.0 / eps) - 1.0) * exp(Float64(-Float64(Float64(1.0 + eps) * x))))) / 2.0) end
function tmp = code(x, eps) tmp = (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0; end
code[x_, eps_] := N[(N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[(-N[(N[(1.0 - eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[(-N[(N[(1.0 + eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (/ (- (* (+ 1.0 (/ 1.0 eps)) (exp (- (* (- 1.0 eps) x)))) (* (- (/ 1.0 eps) 1.0) (exp (- (* (+ 1.0 eps) x))))) 2.0))
double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.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, eps)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (((1.0d0 + (1.0d0 / eps)) * exp(-((1.0d0 - eps) * x))) - (((1.0d0 / eps) - 1.0d0) * exp(-((1.0d0 + eps) * x)))) / 2.0d0
end function
public static double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * Math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * Math.exp(-((1.0 + eps) * x)))) / 2.0;
}
def code(x, eps): return (((1.0 + (1.0 / eps)) * math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * math.exp(-((1.0 + eps) * x)))) / 2.0
function code(x, eps) return Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(-Float64(Float64(1.0 - eps) * x)))) - Float64(Float64(Float64(1.0 / eps) - 1.0) * exp(Float64(-Float64(Float64(1.0 + eps) * x))))) / 2.0) end
function tmp = code(x, eps) tmp = (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0; end
code[x_, eps_] := N[(N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[(-N[(N[(1.0 - eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[(-N[(N[(1.0 + eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2}
\end{array}
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ 1.0 (pow eps -1.0))))
(if (<=
(/
(-
(* t_0 (exp (* (+ -1.0 eps) x)))
(* (- (pow eps -1.0) 1.0) (exp (* (- -1.0 eps) x))))
2.0)
1.0)
(* (fma (+ x 2.0) (exp (- x)) (/ x (exp x))) 0.5)
(/ (- (* t_0 (exp (- (* x eps) x))) (/ -1.0 (exp (fma x eps x)))) 2.0))))
double code(double x, double eps) {
double t_0 = 1.0 + pow(eps, -1.0);
double tmp;
if ((((t_0 * exp(((-1.0 + eps) * x))) - ((pow(eps, -1.0) - 1.0) * exp(((-1.0 - eps) * x)))) / 2.0) <= 1.0) {
tmp = fma((x + 2.0), exp(-x), (x / exp(x))) * 0.5;
} else {
tmp = ((t_0 * exp(((x * eps) - x))) - (-1.0 / exp(fma(x, eps, x)))) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(1.0 + (eps ^ -1.0)) tmp = 0.0 if (Float64(Float64(Float64(t_0 * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(Float64((eps ^ -1.0) - 1.0) * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0) <= 1.0) tmp = Float64(fma(Float64(x + 2.0), exp(Float64(-x)), Float64(x / exp(x))) * 0.5); else tmp = Float64(Float64(Float64(t_0 * exp(Float64(Float64(x * eps) - x))) - Float64(-1.0 / exp(fma(x, eps, x)))) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(1.0 + N[Power[eps, -1.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[(t$95$0 * N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 1.0], N[(N[(N[(x + 2.0), $MachinePrecision] * N[Exp[(-x)], $MachinePrecision] + N[(x / N[Exp[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(t$95$0 * N[Exp[N[(N[(x * eps), $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(-1.0 / N[Exp[N[(x * eps + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + {\varepsilon}^{-1}\\
\mathbf{if}\;\frac{t\_0 \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - \left({\varepsilon}^{-1} - 1\right) \cdot e^{\left(-1 - \varepsilon\right) \cdot x}}{2} \leq 1:\\
\;\;\;\;\mathsf{fma}\left(x + 2, e^{-x}, \frac{x}{e^{x}}\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 \cdot e^{x \cdot \varepsilon - x} - \frac{-1}{e^{\mathsf{fma}\left(x, \varepsilon, x\right)}}}{2}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) < 1Initial program 57.2%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Applied rewrites100.0%
if 1 < (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) Initial program 99.1%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6499.1
Applied rewrites99.1%
Taylor expanded in x around inf
lower-exp.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6499.1
Applied rewrites99.1%
Final simplification99.6%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (- (pow eps -1.0) 1.0) (exp (* (- -1.0 eps) x)))))
(if (<=
(/ (- (* (+ 1.0 (pow eps -1.0)) (exp (* (+ -1.0 eps) x))) t_0) 2.0)
1.2)
(* (fma (+ x 2.0) (exp (- x)) (/ x (exp x))) 0.5)
(/ (- (+ (pow eps -1.0) 1.0) t_0) 2.0))))
double code(double x, double eps) {
double t_0 = (pow(eps, -1.0) - 1.0) * exp(((-1.0 - eps) * x));
double tmp;
if (((((1.0 + pow(eps, -1.0)) * exp(((-1.0 + eps) * x))) - t_0) / 2.0) <= 1.2) {
tmp = fma((x + 2.0), exp(-x), (x / exp(x))) * 0.5;
} else {
tmp = ((pow(eps, -1.0) + 1.0) - t_0) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64((eps ^ -1.0) - 1.0) * exp(Float64(Float64(-1.0 - eps) * x))) tmp = 0.0 if (Float64(Float64(Float64(Float64(1.0 + (eps ^ -1.0)) * exp(Float64(Float64(-1.0 + eps) * x))) - t_0) / 2.0) <= 1.2) tmp = Float64(fma(Float64(x + 2.0), exp(Float64(-x)), Float64(x / exp(x))) * 0.5); else tmp = Float64(Float64(Float64((eps ^ -1.0) + 1.0) - t_0) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[(N[(1.0 + N[Power[eps, -1.0], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision] / 2.0), $MachinePrecision], 1.2], N[(N[(N[(x + 2.0), $MachinePrecision] * N[Exp[(-x)], $MachinePrecision] + N[(x / N[Exp[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(N[Power[eps, -1.0], $MachinePrecision] + 1.0), $MachinePrecision] - t$95$0), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left({\varepsilon}^{-1} - 1\right) \cdot e^{\left(-1 - \varepsilon\right) \cdot x}\\
\mathbf{if}\;\frac{\left(1 + {\varepsilon}^{-1}\right) \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - t\_0}{2} \leq 1.2:\\
\;\;\;\;\mathsf{fma}\left(x + 2, e^{-x}, \frac{x}{e^{x}}\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\left({\varepsilon}^{-1} + 1\right) - t\_0}{2}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) < 1.19999999999999996Initial program 57.8%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.4%
Applied rewrites99.4%
if 1.19999999999999996 < (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) Initial program 99.1%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6462.8
Applied rewrites62.8%
Final simplification83.8%
(FPCore (x eps)
:precision binary64
(if (<= x -0.1)
(/
(-
(+ (pow eps -1.0) 1.0)
(* (- (pow eps -1.0) 1.0) (exp (* (- -1.0 eps) x))))
2.0)
(if (<= x 1.45)
(fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0)
(if (<= x 4e+243) (/ x (exp x)) (* (fma (- (* 0.5 x) 1.0) x 1.0) x)))))
double code(double x, double eps) {
double tmp;
if (x <= -0.1) {
tmp = ((pow(eps, -1.0) + 1.0) - ((pow(eps, -1.0) - 1.0) * exp(((-1.0 - eps) * x)))) / 2.0;
} else if (x <= 1.45) {
tmp = fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
} else if (x <= 4e+243) {
tmp = x / exp(x);
} else {
tmp = fma(((0.5 * x) - 1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -0.1) tmp = Float64(Float64(Float64((eps ^ -1.0) + 1.0) - Float64(Float64((eps ^ -1.0) - 1.0) * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0); elseif (x <= 1.45) tmp = fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0); elseif (x <= 4e+243) tmp = Float64(x / exp(x)); else tmp = Float64(fma(Float64(Float64(0.5 * x) - 1.0), x, 1.0) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, -0.1], N[(N[(N[(N[Power[eps, -1.0], $MachinePrecision] + 1.0), $MachinePrecision] - N[(N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.45], N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[x, 4e+243], N[(x / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(0.5 * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.1:\\
\;\;\;\;\frac{\left({\varepsilon}^{-1} + 1\right) - \left({\varepsilon}^{-1} - 1\right) \cdot e^{\left(-1 - \varepsilon\right) \cdot x}}{2}\\
\mathbf{elif}\;x \leq 1.45:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)\\
\mathbf{elif}\;x \leq 4 \cdot 10^{+243}:\\
\;\;\;\;\frac{x}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x - 1, x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < -0.10000000000000001Initial program 97.4%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6469.4
Applied rewrites69.4%
if -0.10000000000000001 < x < 1.44999999999999996Initial program 53.8%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites73.1%
Taylor expanded in x around 0
Applied rewrites73.1%
if 1.44999999999999996 < x < 4.0000000000000003e243Initial program 98.5%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites68.7%
Taylor expanded in x around inf
Applied rewrites67.5%
if 4.0000000000000003e243 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites31.1%
Taylor expanded in x around inf
Applied rewrites31.1%
Taylor expanded in x around 0
Applied rewrites70.5%
Final simplification70.9%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (pow eps -1.0) 1.0)))
(if (<= x -195.0)
(/ (- (pow eps -1.0) (* t_0 (fma (- -1.0 eps) x 1.0))) 2.0)
(if (<= x 370.0)
(fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0)
(if (<= x 3.6e+252)
(/ (- (+ (pow eps -1.0) 1.0) t_0) 2.0)
(* (fma (- (* 0.5 x) 1.0) x 1.0) x))))))
double code(double x, double eps) {
double t_0 = pow(eps, -1.0) - 1.0;
double tmp;
if (x <= -195.0) {
tmp = (pow(eps, -1.0) - (t_0 * fma((-1.0 - eps), x, 1.0))) / 2.0;
} else if (x <= 370.0) {
tmp = fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
} else if (x <= 3.6e+252) {
tmp = ((pow(eps, -1.0) + 1.0) - t_0) / 2.0;
} else {
tmp = fma(((0.5 * x) - 1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, eps) t_0 = Float64((eps ^ -1.0) - 1.0) tmp = 0.0 if (x <= -195.0) tmp = Float64(Float64((eps ^ -1.0) - Float64(t_0 * fma(Float64(-1.0 - eps), x, 1.0))) / 2.0); elseif (x <= 370.0) tmp = fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0); elseif (x <= 3.6e+252) tmp = Float64(Float64(Float64((eps ^ -1.0) + 1.0) - t_0) / 2.0); else tmp = Float64(fma(Float64(Float64(0.5 * x) - 1.0), x, 1.0) * x); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]}, If[LessEqual[x, -195.0], N[(N[(N[Power[eps, -1.0], $MachinePrecision] - N[(t$95$0 * N[(N[(-1.0 - eps), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 370.0], N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[x, 3.6e+252], N[(N[(N[(N[Power[eps, -1.0], $MachinePrecision] + 1.0), $MachinePrecision] - t$95$0), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(N[(0.5 * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\varepsilon}^{-1} - 1\\
\mathbf{if}\;x \leq -195:\\
\;\;\;\;\frac{{\varepsilon}^{-1} - t\_0 \cdot \mathsf{fma}\left(-1 - \varepsilon, x, 1\right)}{2}\\
\mathbf{elif}\;x \leq 370:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)\\
\mathbf{elif}\;x \leq 3.6 \cdot 10^{+252}:\\
\;\;\;\;\frac{\left({\varepsilon}^{-1} + 1\right) - t\_0}{2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x - 1, x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < -195Initial program 97.4%
Taylor expanded in x around 0
mul-1-negN/A
+-commutativeN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
distribute-lft-inN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6451.8
Applied rewrites51.8%
Taylor expanded in x around 0
*-inversesN/A
div-addN/A
+-commutativeN/A
lower-/.f64N/A
lower-+.f6438.9
Applied rewrites38.9%
Taylor expanded in eps around 0
Applied rewrites38.9%
if -195 < x < 370Initial program 53.4%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites73.3%
Taylor expanded in x around 0
Applied rewrites72.6%
if 370 < x < 3.5999999999999999e252Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6421.3
Applied rewrites21.3%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6463.9
Applied rewrites63.9%
if 3.5999999999999999e252 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites28.9%
Taylor expanded in x around inf
Applied rewrites28.9%
Taylor expanded in x around 0
Applied rewrites72.7%
Final simplification65.3%
(FPCore (x eps)
:precision binary64
(if (<= x -195.0)
(/
(- (pow eps -1.0) (* (- (pow eps -1.0) 1.0) (fma (- -1.0 eps) x 1.0)))
2.0)
(if (<= x 1.45)
(fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0)
(if (<= x 4e+243) (/ x (exp x)) (* (fma (- (* 0.5 x) 1.0) x 1.0) x)))))
double code(double x, double eps) {
double tmp;
if (x <= -195.0) {
tmp = (pow(eps, -1.0) - ((pow(eps, -1.0) - 1.0) * fma((-1.0 - eps), x, 1.0))) / 2.0;
} else if (x <= 1.45) {
tmp = fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
} else if (x <= 4e+243) {
tmp = x / exp(x);
} else {
tmp = fma(((0.5 * x) - 1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -195.0) tmp = Float64(Float64((eps ^ -1.0) - Float64(Float64((eps ^ -1.0) - 1.0) * fma(Float64(-1.0 - eps), x, 1.0))) / 2.0); elseif (x <= 1.45) tmp = fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0); elseif (x <= 4e+243) tmp = Float64(x / exp(x)); else tmp = Float64(fma(Float64(Float64(0.5 * x) - 1.0), x, 1.0) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, -195.0], N[(N[(N[Power[eps, -1.0], $MachinePrecision] - N[(N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision] * N[(N[(-1.0 - eps), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.45], N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[x, 4e+243], N[(x / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(0.5 * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -195:\\
\;\;\;\;\frac{{\varepsilon}^{-1} - \left({\varepsilon}^{-1} - 1\right) \cdot \mathsf{fma}\left(-1 - \varepsilon, x, 1\right)}{2}\\
\mathbf{elif}\;x \leq 1.45:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)\\
\mathbf{elif}\;x \leq 4 \cdot 10^{+243}:\\
\;\;\;\;\frac{x}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x - 1, x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < -195Initial program 97.4%
Taylor expanded in x around 0
mul-1-negN/A
+-commutativeN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
distribute-lft-inN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6451.8
Applied rewrites51.8%
Taylor expanded in x around 0
*-inversesN/A
div-addN/A
+-commutativeN/A
lower-/.f64N/A
lower-+.f6438.9
Applied rewrites38.9%
Taylor expanded in eps around 0
Applied rewrites38.9%
if -195 < x < 1.44999999999999996Initial program 53.8%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites73.1%
Taylor expanded in x around 0
Applied rewrites73.1%
if 1.44999999999999996 < x < 4.0000000000000003e243Initial program 98.5%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites68.7%
Taylor expanded in x around inf
Applied rewrites67.5%
if 4.0000000000000003e243 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites31.1%
Taylor expanded in x around inf
Applied rewrites31.1%
Taylor expanded in x around 0
Applied rewrites70.5%
Final simplification66.4%
(FPCore (x eps)
:precision binary64
(if (<= x -16500000.0)
(/ (- (pow eps -1.0) (/ -1.0 (exp (fma x eps x)))) 2.0)
(if (<= x 1.5)
(fma (- (* (fma -0.125 x 0.3333333333333333) x) 0.5) (* x x) 1.0)
(if (<= x 4e+243) (/ x (exp x)) (* (fma (- (* 0.5 x) 1.0) x 1.0) x)))))
double code(double x, double eps) {
double tmp;
if (x <= -16500000.0) {
tmp = (pow(eps, -1.0) - (-1.0 / exp(fma(x, eps, x)))) / 2.0;
} else if (x <= 1.5) {
tmp = fma(((fma(-0.125, x, 0.3333333333333333) * x) - 0.5), (x * x), 1.0);
} else if (x <= 4e+243) {
tmp = x / exp(x);
} else {
tmp = fma(((0.5 * x) - 1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -16500000.0) tmp = Float64(Float64((eps ^ -1.0) - Float64(-1.0 / exp(fma(x, eps, x)))) / 2.0); elseif (x <= 1.5) tmp = fma(Float64(Float64(fma(-0.125, x, 0.3333333333333333) * x) - 0.5), Float64(x * x), 1.0); elseif (x <= 4e+243) tmp = Float64(x / exp(x)); else tmp = Float64(fma(Float64(Float64(0.5 * x) - 1.0), x, 1.0) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, -16500000.0], N[(N[(N[Power[eps, -1.0], $MachinePrecision] - N[(-1.0 / N[Exp[N[(x * eps + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.5], N[(N[(N[(N[(-0.125 * x + 0.3333333333333333), $MachinePrecision] * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[x, 4e+243], N[(x / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(0.5 * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -16500000:\\
\;\;\;\;\frac{{\varepsilon}^{-1} - \frac{-1}{e^{\mathsf{fma}\left(x, \varepsilon, x\right)}}}{2}\\
\mathbf{elif}\;x \leq 1.5:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.125, x, 0.3333333333333333\right) \cdot x - 0.5, x \cdot x, 1\right)\\
\mathbf{elif}\;x \leq 4 \cdot 10^{+243}:\\
\;\;\;\;\frac{x}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x - 1, x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < -1.65e7Initial program 100.0%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
*-inversesN/A
div-addN/A
+-commutativeN/A
lower-/.f64N/A
lower-+.f6468.6
Applied rewrites68.6%
Taylor expanded in eps around 0
Applied rewrites67.9%
if -1.65e7 < x < 1.5Initial program 53.4%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites73.3%
Taylor expanded in x around 0
Applied rewrites72.5%
if 1.5 < x < 4.0000000000000003e243Initial program 98.5%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites68.7%
Taylor expanded in x around inf
Applied rewrites67.5%
if 4.0000000000000003e243 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites31.1%
Taylor expanded in x around inf
Applied rewrites31.1%
Taylor expanded in x around 0
Applied rewrites70.5%
Final simplification70.4%
(FPCore (x eps)
:precision binary64
(if (<= x 350.0)
1.0
(if (<= x 3.6e+252)
(/ (- (+ (pow eps -1.0) 1.0) (- (pow eps -1.0) 1.0)) 2.0)
(* (fma (- (* 0.5 x) 1.0) x 1.0) x))))
double code(double x, double eps) {
double tmp;
if (x <= 350.0) {
tmp = 1.0;
} else if (x <= 3.6e+252) {
tmp = ((pow(eps, -1.0) + 1.0) - (pow(eps, -1.0) - 1.0)) / 2.0;
} else {
tmp = fma(((0.5 * x) - 1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 350.0) tmp = 1.0; elseif (x <= 3.6e+252) tmp = Float64(Float64(Float64((eps ^ -1.0) + 1.0) - Float64((eps ^ -1.0) - 1.0)) / 2.0); else tmp = Float64(fma(Float64(Float64(0.5 * x) - 1.0), x, 1.0) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, 350.0], 1.0, If[LessEqual[x, 3.6e+252], N[(N[(N[(N[Power[eps, -1.0], $MachinePrecision] + 1.0), $MachinePrecision] - N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(N[(0.5 * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 350:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 3.6 \cdot 10^{+252}:\\
\;\;\;\;\frac{\left({\varepsilon}^{-1} + 1\right) - \left({\varepsilon}^{-1} - 1\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x - 1, x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < 350Initial program 63.2%
Taylor expanded in x around 0
Applied rewrites56.9%
if 350 < x < 3.5999999999999999e252Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6421.3
Applied rewrites21.3%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6463.9
Applied rewrites63.9%
if 3.5999999999999999e252 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites28.9%
Taylor expanded in x around inf
Applied rewrites28.9%
Taylor expanded in x around 0
Applied rewrites72.7%
Final simplification59.8%
(FPCore (x eps)
:precision binary64
(if (<= x -16500000.0)
(/ (- (/ (+ 1.0 eps) eps) (/ -1.0 (exp (fma x eps x)))) 2.0)
(if (<= x 1.5)
(fma (- (* (fma -0.125 x 0.3333333333333333) x) 0.5) (* x x) 1.0)
(if (<= x 4e+243) (/ x (exp x)) (* (fma (- (* 0.5 x) 1.0) x 1.0) x)))))
double code(double x, double eps) {
double tmp;
if (x <= -16500000.0) {
tmp = (((1.0 + eps) / eps) - (-1.0 / exp(fma(x, eps, x)))) / 2.0;
} else if (x <= 1.5) {
tmp = fma(((fma(-0.125, x, 0.3333333333333333) * x) - 0.5), (x * x), 1.0);
} else if (x <= 4e+243) {
tmp = x / exp(x);
} else {
tmp = fma(((0.5 * x) - 1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -16500000.0) tmp = Float64(Float64(Float64(Float64(1.0 + eps) / eps) - Float64(-1.0 / exp(fma(x, eps, x)))) / 2.0); elseif (x <= 1.5) tmp = fma(Float64(Float64(fma(-0.125, x, 0.3333333333333333) * x) - 0.5), Float64(x * x), 1.0); elseif (x <= 4e+243) tmp = Float64(x / exp(x)); else tmp = Float64(fma(Float64(Float64(0.5 * x) - 1.0), x, 1.0) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, -16500000.0], N[(N[(N[(N[(1.0 + eps), $MachinePrecision] / eps), $MachinePrecision] - N[(-1.0 / N[Exp[N[(x * eps + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.5], N[(N[(N[(N[(-0.125 * x + 0.3333333333333333), $MachinePrecision] * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[x, 4e+243], N[(x / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(0.5 * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -16500000:\\
\;\;\;\;\frac{\frac{1 + \varepsilon}{\varepsilon} - \frac{-1}{e^{\mathsf{fma}\left(x, \varepsilon, x\right)}}}{2}\\
\mathbf{elif}\;x \leq 1.5:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.125, x, 0.3333333333333333\right) \cdot x - 0.5, x \cdot x, 1\right)\\
\mathbf{elif}\;x \leq 4 \cdot 10^{+243}:\\
\;\;\;\;\frac{x}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x - 1, x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < -1.65e7Initial program 100.0%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
*-inversesN/A
div-addN/A
+-commutativeN/A
lower-/.f64N/A
lower-+.f6468.6
Applied rewrites68.6%
if -1.65e7 < x < 1.5Initial program 53.4%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites73.3%
Taylor expanded in x around 0
Applied rewrites72.5%
if 1.5 < x < 4.0000000000000003e243Initial program 98.5%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites68.7%
Taylor expanded in x around inf
Applied rewrites67.5%
if 4.0000000000000003e243 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites31.1%
Taylor expanded in x around inf
Applied rewrites31.1%
Taylor expanded in x around 0
Applied rewrites70.5%
(FPCore (x eps)
:precision binary64
(if (<= x 4e+142)
(fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0)
(if (<= x 5e+252)
(/ x (fma (fma (fma 0.16666666666666666 x 0.5) x 1.0) x 1.0))
(* (fma (- (* 0.5 x) 1.0) x 1.0) x))))
double code(double x, double eps) {
double tmp;
if (x <= 4e+142) {
tmp = fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
} else if (x <= 5e+252) {
tmp = x / fma(fma(fma(0.16666666666666666, x, 0.5), x, 1.0), x, 1.0);
} else {
tmp = fma(((0.5 * x) - 1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 4e+142) tmp = fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0); elseif (x <= 5e+252) tmp = Float64(x / fma(fma(fma(0.16666666666666666, x, 0.5), x, 1.0), x, 1.0)); else tmp = Float64(fma(Float64(Float64(0.5 * x) - 1.0), x, 1.0) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, 4e+142], N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[x, 5e+252], N[(x / N[(N[(N[(0.16666666666666666 * x + 0.5), $MachinePrecision] * x + 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(0.5 * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4 \cdot 10^{+142}:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)\\
\mathbf{elif}\;x \leq 5 \cdot 10^{+252}:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, x, 0.5\right), x, 1\right), x, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x - 1, x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < 4.0000000000000002e142Initial program 68.8%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites58.7%
Taylor expanded in x around 0
Applied rewrites50.2%
if 4.0000000000000002e142 < x < 4.9999999999999997e252Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites69.9%
Taylor expanded in x around inf
Applied rewrites69.9%
Taylor expanded in x around 0
Applied rewrites69.9%
if 4.9999999999999997e252 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites28.9%
Taylor expanded in x around inf
Applied rewrites28.9%
Taylor expanded in x around 0
Applied rewrites72.7%
(FPCore (x eps)
:precision binary64
(if (<= x 4.9e+166)
(fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0)
(if (<= x 5e+252)
(/ x (fma (fma 0.5 x 1.0) x 1.0))
(* (fma (- (* 0.5 x) 1.0) x 1.0) x))))
double code(double x, double eps) {
double tmp;
if (x <= 4.9e+166) {
tmp = fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
} else if (x <= 5e+252) {
tmp = x / fma(fma(0.5, x, 1.0), x, 1.0);
} else {
tmp = fma(((0.5 * x) - 1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 4.9e+166) tmp = fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0); elseif (x <= 5e+252) tmp = Float64(x / fma(fma(0.5, x, 1.0), x, 1.0)); else tmp = Float64(fma(Float64(Float64(0.5 * x) - 1.0), x, 1.0) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, 4.9e+166], N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[x, 5e+252], N[(x / N[(N[(0.5 * x + 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(0.5 * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.9 \cdot 10^{+166}:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)\\
\mathbf{elif}\;x \leq 5 \cdot 10^{+252}:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(\mathsf{fma}\left(0.5, x, 1\right), x, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x - 1, x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < 4.89999999999999969e166Initial program 69.3%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites58.8%
Taylor expanded in x around 0
Applied rewrites50.0%
if 4.89999999999999969e166 < x < 4.9999999999999997e252Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites70.2%
Taylor expanded in x around inf
Applied rewrites70.2%
Taylor expanded in x around 0
Applied rewrites70.2%
if 4.9999999999999997e252 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites28.9%
Taylor expanded in x around inf
Applied rewrites28.9%
Taylor expanded in x around 0
Applied rewrites72.7%
(FPCore (x eps) :precision binary64 (if (<= x 3.55e+114) 1.0 (* (fma (- (* 0.5 x) 1.0) x 1.0) x)))
double code(double x, double eps) {
double tmp;
if (x <= 3.55e+114) {
tmp = 1.0;
} else {
tmp = fma(((0.5 * x) - 1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 3.55e+114) tmp = 1.0; else tmp = Float64(fma(Float64(Float64(0.5 * x) - 1.0), x, 1.0) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, 3.55e+114], 1.0, N[(N[(N[(N[(0.5 * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.55 \cdot 10^{+114}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x - 1, x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < 3.5500000000000001e114Initial program 68.2%
Taylor expanded in x around 0
Applied rewrites49.6%
if 3.5500000000000001e114 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites52.5%
Taylor expanded in x around inf
Applied rewrites52.5%
Taylor expanded in x around 0
Applied rewrites49.1%
(FPCore (x eps) :precision binary64 (fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0))
double code(double x, double eps) {
return fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
}
function code(x, eps) return fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0) end
code[x_, eps_] := N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)
\end{array}
Initial program 75.4%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites58.2%
Taylor expanded in x around 0
Applied rewrites49.2%
(FPCore (x eps) :precision binary64 1.0)
double code(double x, double eps) {
return 1.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, eps)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = 1.0d0
end function
public static double code(double x, double eps) {
return 1.0;
}
def code(x, eps): return 1.0
function code(x, eps) return 1.0 end
function tmp = code(x, eps) tmp = 1.0; end
code[x_, eps_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 75.4%
Taylor expanded in x around 0
Applied rewrites39.1%
herbie shell --seed 2024364
(FPCore (x eps)
:name "NMSE Section 6.1 mentioned, A"
:precision binary64
(/ (- (* (+ 1.0 (/ 1.0 eps)) (exp (- (* (- 1.0 eps) x)))) (* (- (/ 1.0 eps) 1.0) (exp (- (* (+ 1.0 eps) x))))) 2.0))