
(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 (* (+ (exp (* x (+ -1.0 eps))) (exp (- (fma x eps x)))) 0.5))
double code(double x, double eps) {
return (exp((x * (-1.0 + eps))) + exp(-fma(x, eps, x))) * 0.5;
}
function code(x, eps) return Float64(Float64(exp(Float64(x * Float64(-1.0 + eps))) + exp(Float64(-fma(x, eps, x)))) * 0.5) end
code[x_, eps_] := N[(N[(N[Exp[N[(x * N[(-1.0 + eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[Exp[(-N[(x * eps + x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
\\
\left(e^{x \cdot \left(-1 + \varepsilon\right)} + e^{-\mathsf{fma}\left(x, \varepsilon, x\right)}\right) \cdot 0.5
\end{array}
Initial program 75.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.4%
Final simplification99.4%
(FPCore (x eps) :precision binary64 (if (<= eps 0.106) (exp (- x)) (* (+ (exp (* x eps)) (exp (- (* x eps)))) 0.5)))
double code(double x, double eps) {
double tmp;
if (eps <= 0.106) {
tmp = exp(-x);
} else {
tmp = (exp((x * eps)) + exp(-(x * eps))) * 0.5;
}
return tmp;
}
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
real(8) :: tmp
if (eps <= 0.106d0) then
tmp = exp(-x)
else
tmp = (exp((x * eps)) + exp(-(x * eps))) * 0.5d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= 0.106) {
tmp = Math.exp(-x);
} else {
tmp = (Math.exp((x * eps)) + Math.exp(-(x * eps))) * 0.5;
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= 0.106: tmp = math.exp(-x) else: tmp = (math.exp((x * eps)) + math.exp(-(x * eps))) * 0.5 return tmp
function code(x, eps) tmp = 0.0 if (eps <= 0.106) tmp = exp(Float64(-x)); else tmp = Float64(Float64(exp(Float64(x * eps)) + exp(Float64(-Float64(x * eps)))) * 0.5); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= 0.106) tmp = exp(-x); else tmp = (exp((x * eps)) + exp(-(x * eps))) * 0.5; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, 0.106], N[Exp[(-x)], $MachinePrecision], N[(N[(N[Exp[N[(x * eps), $MachinePrecision]], $MachinePrecision] + N[Exp[(-N[(x * eps), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq 0.106:\\
\;\;\;\;e^{-x}\\
\mathbf{else}:\\
\;\;\;\;\left(e^{x \cdot \varepsilon} + e^{-x \cdot \varepsilon}\right) \cdot 0.5\\
\end{array}
\end{array}
if eps < 0.105999999999999997Initial program 65.4%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.2%
Taylor expanded in eps around inf
*-commutativeN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-*.f6485.0
Applied rewrites85.0%
Taylor expanded in eps around 0
lift-exp.f64N/A
lift-neg.f6478.3
Applied rewrites78.3%
if 0.105999999999999997 < eps Initial program 100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Taylor expanded in eps around inf
*-commutativeN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lift-*.f64100.0
Applied rewrites100.0%
Final simplification84.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (exp (- x))))
(if (<= x -2200.0)
t_0
(if (<= x -2.7e-247)
(*
(fma (fma -1.0 (/ (- (* eps eps) 1.0) (- eps 1.0)) (+ -1.0 eps)) x 2.0)
0.5)
(if (<= x 4.5e+228) (* (- (exp (* x eps)) -1.0) 0.5) t_0)))))
double code(double x, double eps) {
double t_0 = exp(-x);
double tmp;
if (x <= -2200.0) {
tmp = t_0;
} else if (x <= -2.7e-247) {
tmp = fma(fma(-1.0, (((eps * eps) - 1.0) / (eps - 1.0)), (-1.0 + eps)), x, 2.0) * 0.5;
} else if (x <= 4.5e+228) {
tmp = (exp((x * eps)) - -1.0) * 0.5;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, eps) t_0 = exp(Float64(-x)) tmp = 0.0 if (x <= -2200.0) tmp = t_0; elseif (x <= -2.7e-247) tmp = Float64(fma(fma(-1.0, Float64(Float64(Float64(eps * eps) - 1.0) / Float64(eps - 1.0)), Float64(-1.0 + eps)), x, 2.0) * 0.5); elseif (x <= 4.5e+228) tmp = Float64(Float64(exp(Float64(x * eps)) - -1.0) * 0.5); else tmp = t_0; end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, If[LessEqual[x, -2200.0], t$95$0, If[LessEqual[x, -2.7e-247], N[(N[(N[(-1.0 * N[(N[(N[(eps * eps), $MachinePrecision] - 1.0), $MachinePrecision] / N[(eps - 1.0), $MachinePrecision]), $MachinePrecision] + N[(-1.0 + eps), $MachinePrecision]), $MachinePrecision] * x + 2.0), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 4.5e+228], N[(N[(N[Exp[N[(x * eps), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision] * 0.5), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-x}\\
\mathbf{if}\;x \leq -2200:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -2.7 \cdot 10^{-247}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-1, \frac{\varepsilon \cdot \varepsilon - 1}{\varepsilon - 1}, -1 + \varepsilon\right), x, 2\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 4.5 \cdot 10^{+228}:\\
\;\;\;\;\left(e^{x \cdot \varepsilon} - -1\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2200 or 4.49999999999999983e228 < x Initial program 100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Taylor expanded in eps around inf
*-commutativeN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-*.f6489.1
Applied rewrites89.1%
Taylor expanded in eps around 0
lift-exp.f64N/A
lift-neg.f6487.5
Applied rewrites87.5%
if -2200 < x < -2.70000000000000008e-247Initial program 60.5%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites98.3%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6466.9
Applied rewrites66.9%
lift-+.f64N/A
flip-+N/A
lower-/.f64N/A
unpow2N/A
metadata-evalN/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
lower--.f6476.3
Applied rewrites76.3%
if -2.70000000000000008e-247 < x < 4.49999999999999983e228Initial program 69.3%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.6%
Taylor expanded in eps around inf
*-commutativeN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-*.f6485.6
Applied rewrites85.6%
Taylor expanded in x around 0
Applied rewrites66.3%
Final simplification73.6%
(FPCore (x eps) :precision binary64 (if (<= x -2.6e-247) (* (+ 1.0 (exp (- (* x eps)))) 0.5) (if (<= x 4.5e+228) (* (- (exp (* x eps)) -1.0) 0.5) (exp (- x)))))
double code(double x, double eps) {
double tmp;
if (x <= -2.6e-247) {
tmp = (1.0 + exp(-(x * eps))) * 0.5;
} else if (x <= 4.5e+228) {
tmp = (exp((x * eps)) - -1.0) * 0.5;
} else {
tmp = exp(-x);
}
return tmp;
}
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
real(8) :: tmp
if (x <= (-2.6d-247)) then
tmp = (1.0d0 + exp(-(x * eps))) * 0.5d0
else if (x <= 4.5d+228) then
tmp = (exp((x * eps)) - (-1.0d0)) * 0.5d0
else
tmp = exp(-x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= -2.6e-247) {
tmp = (1.0 + Math.exp(-(x * eps))) * 0.5;
} else if (x <= 4.5e+228) {
tmp = (Math.exp((x * eps)) - -1.0) * 0.5;
} else {
tmp = Math.exp(-x);
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= -2.6e-247: tmp = (1.0 + math.exp(-(x * eps))) * 0.5 elif x <= 4.5e+228: tmp = (math.exp((x * eps)) - -1.0) * 0.5 else: tmp = math.exp(-x) return tmp
function code(x, eps) tmp = 0.0 if (x <= -2.6e-247) tmp = Float64(Float64(1.0 + exp(Float64(-Float64(x * eps)))) * 0.5); elseif (x <= 4.5e+228) tmp = Float64(Float64(exp(Float64(x * eps)) - -1.0) * 0.5); else tmp = exp(Float64(-x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= -2.6e-247) tmp = (1.0 + exp(-(x * eps))) * 0.5; elseif (x <= 4.5e+228) tmp = (exp((x * eps)) - -1.0) * 0.5; else tmp = exp(-x); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, -2.6e-247], N[(N[(1.0 + N[Exp[(-N[(x * eps), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 4.5e+228], N[(N[(N[Exp[N[(x * eps), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision] * 0.5), $MachinePrecision], N[Exp[(-x)], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{-247}:\\
\;\;\;\;\left(1 + e^{-x \cdot \varepsilon}\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 4.5 \cdot 10^{+228}:\\
\;\;\;\;\left(e^{x \cdot \varepsilon} - -1\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;e^{-x}\\
\end{array}
\end{array}
if x < -2.6e-247Initial program 77.3%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.0%
Taylor expanded in eps around inf
*-commutativeN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-*.f6499.0
Applied rewrites99.0%
Taylor expanded in eps around inf
*-commutativeN/A
lift-*.f6499.5
Applied rewrites99.5%
Taylor expanded in x around 0
Applied rewrites69.8%
if -2.6e-247 < x < 4.49999999999999983e228Initial program 69.3%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.6%
Taylor expanded in eps around inf
*-commutativeN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-*.f6485.6
Applied rewrites85.6%
Taylor expanded in x around 0
Applied rewrites66.3%
if 4.49999999999999983e228 < x Initial program 100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Taylor expanded in eps around inf
*-commutativeN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-*.f6470.1
Applied rewrites70.1%
Taylor expanded in eps around 0
lift-exp.f64N/A
lift-neg.f6465.8
Applied rewrites65.8%
Final simplification67.5%
(FPCore (x eps) :precision binary64 (if (<= eps 8.2e+175) (exp (- x)) (* (fma (fma -1.0 (- eps -1.0) (/ (+ -1.0 (* eps eps)) 1.0)) x 2.0) 0.5)))
double code(double x, double eps) {
double tmp;
if (eps <= 8.2e+175) {
tmp = exp(-x);
} else {
tmp = fma(fma(-1.0, (eps - -1.0), ((-1.0 + (eps * eps)) / 1.0)), x, 2.0) * 0.5;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= 8.2e+175) tmp = exp(Float64(-x)); else tmp = Float64(fma(fma(-1.0, Float64(eps - -1.0), Float64(Float64(-1.0 + Float64(eps * eps)) / 1.0)), x, 2.0) * 0.5); end return tmp end
code[x_, eps_] := If[LessEqual[eps, 8.2e+175], N[Exp[(-x)], $MachinePrecision], N[(N[(N[(-1.0 * N[(eps - -1.0), $MachinePrecision] + N[(N[(-1.0 + N[(eps * eps), $MachinePrecision]), $MachinePrecision] / 1.0), $MachinePrecision]), $MachinePrecision] * x + 2.0), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq 8.2 \cdot 10^{+175}:\\
\;\;\;\;e^{-x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-1, \varepsilon - -1, \frac{-1 + \varepsilon \cdot \varepsilon}{1}\right), x, 2\right) \cdot 0.5\\
\end{array}
\end{array}
if eps < 8.19999999999999955e175Initial program 71.9%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.3%
Taylor expanded in eps around inf
*-commutativeN/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-*.f6487.8
Applied rewrites87.8%
Taylor expanded in eps around 0
lift-exp.f64N/A
lift-neg.f6478.6
Applied rewrites78.6%
if 8.19999999999999955e175 < eps Initial program 100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f643.1
Applied rewrites3.1%
lift--.f64N/A
flip--N/A
lower-/.f64N/A
metadata-evalN/A
unpow2N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
lift-+.f6457.1
Applied rewrites57.1%
Taylor expanded in eps around 0
Applied rewrites57.1%
Final simplification76.2%
(FPCore (x eps)
:precision binary64
(if (<= x -6.8e+153)
(* (/ (- (* (* x x) 4.0) 4.0) (- (* -2.0 x) 2.0)) 0.5)
(if (<= x -2.6e-247)
(* (fma (fma -1.0 (/ (- (* eps eps) 1.0) (- eps 1.0)) -1.0) x 2.0) 0.5)
(if (<= x 135000.0)
(*
(fma
(fma -1.0 (- eps -1.0) (/ (+ -1.0 (* eps eps)) (- eps -1.0)))
x
2.0)
0.5)
(if (or (<= x 9.2e+117) (not (<= x 7.1e+224)))
(/ (- (* (+ 1.0 (/ 1.0 eps)) 1.0) (/ (fma -1.0 eps 1.0) eps)) 2.0)
(fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0))))))
double code(double x, double eps) {
double tmp;
if (x <= -6.8e+153) {
tmp = ((((x * x) * 4.0) - 4.0) / ((-2.0 * x) - 2.0)) * 0.5;
} else if (x <= -2.6e-247) {
tmp = fma(fma(-1.0, (((eps * eps) - 1.0) / (eps - 1.0)), -1.0), x, 2.0) * 0.5;
} else if (x <= 135000.0) {
tmp = fma(fma(-1.0, (eps - -1.0), ((-1.0 + (eps * eps)) / (eps - -1.0))), x, 2.0) * 0.5;
} else if ((x <= 9.2e+117) || !(x <= 7.1e+224)) {
tmp = (((1.0 + (1.0 / eps)) * 1.0) - (fma(-1.0, eps, 1.0) / eps)) / 2.0;
} else {
tmp = fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -6.8e+153) tmp = Float64(Float64(Float64(Float64(Float64(x * x) * 4.0) - 4.0) / Float64(Float64(-2.0 * x) - 2.0)) * 0.5); elseif (x <= -2.6e-247) tmp = Float64(fma(fma(-1.0, Float64(Float64(Float64(eps * eps) - 1.0) / Float64(eps - 1.0)), -1.0), x, 2.0) * 0.5); elseif (x <= 135000.0) tmp = Float64(fma(fma(-1.0, Float64(eps - -1.0), Float64(Float64(-1.0 + Float64(eps * eps)) / Float64(eps - -1.0))), x, 2.0) * 0.5); elseif ((x <= 9.2e+117) || !(x <= 7.1e+224)) tmp = Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * 1.0) - Float64(fma(-1.0, eps, 1.0) / eps)) / 2.0); else tmp = fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0); end return tmp end
code[x_, eps_] := If[LessEqual[x, -6.8e+153], N[(N[(N[(N[(N[(x * x), $MachinePrecision] * 4.0), $MachinePrecision] - 4.0), $MachinePrecision] / N[(N[(-2.0 * x), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, -2.6e-247], N[(N[(N[(-1.0 * N[(N[(N[(eps * eps), $MachinePrecision] - 1.0), $MachinePrecision] / N[(eps - 1.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] * x + 2.0), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 135000.0], N[(N[(N[(-1.0 * N[(eps - -1.0), $MachinePrecision] + N[(N[(-1.0 + N[(eps * eps), $MachinePrecision]), $MachinePrecision] / N[(eps - -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x + 2.0), $MachinePrecision] * 0.5), $MachinePrecision], If[Or[LessEqual[x, 9.2e+117], N[Not[LessEqual[x, 7.1e+224]], $MachinePrecision]], N[(N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * 1.0), $MachinePrecision] - N[(N[(-1.0 * eps + 1.0), $MachinePrecision] / eps), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.8 \cdot 10^{+153}:\\
\;\;\;\;\frac{\left(x \cdot x\right) \cdot 4 - 4}{-2 \cdot x - 2} \cdot 0.5\\
\mathbf{elif}\;x \leq -2.6 \cdot 10^{-247}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-1, \frac{\varepsilon \cdot \varepsilon - 1}{\varepsilon - 1}, -1\right), x, 2\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 135000:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-1, \varepsilon - -1, \frac{-1 + \varepsilon \cdot \varepsilon}{\varepsilon - -1}\right), x, 2\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 9.2 \cdot 10^{+117} \lor \neg \left(x \leq 7.1 \cdot 10^{+224}\right):\\
\;\;\;\;\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot 1 - \frac{\mathsf{fma}\left(-1, \varepsilon, 1\right)}{\varepsilon}}{2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)\\
\end{array}
\end{array}
if x < -6.7999999999999995e153Initial program 100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f643.4
Applied rewrites3.4%
lift-fma.f64N/A
lift-+.f64N/A
lift-fma.f64N/A
lift-neg.f64N/A
lift--.f64N/A
flip-+N/A
lower-/.f64N/A
Applied rewrites7.0%
Taylor expanded in eps around 0
Applied rewrites100.0%
if -6.7999999999999995e153 < x < -2.6e-247Initial program 69.1%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites98.6%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6453.0
Applied rewrites53.0%
Taylor expanded in eps around 0
Applied rewrites56.5%
lift-+.f64N/A
flip-+N/A
lower-/.f64N/A
pow2N/A
metadata-evalN/A
lower--.f64N/A
pow2N/A
lift-*.f64N/A
lower--.f6467.0
Applied rewrites67.0%
if -2.6e-247 < x < 135000Initial program 52.6%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.3%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6480.0
Applied rewrites80.0%
lift--.f64N/A
flip--N/A
lower-/.f64N/A
metadata-evalN/A
unpow2N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
lift-+.f6479.5
Applied rewrites79.5%
if 135000 < x < 9.19999999999999951e117 or 7.0999999999999998e224 < x Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites21.6%
Taylor expanded in x around 0
lower--.f64N/A
inv-powN/A
lower-pow.f6460.1
Applied rewrites60.1%
Taylor expanded in eps around 0
lower-/.f64N/A
mul-1-negN/A
+-commutativeN/A
mul-1-negN/A
lower-fma.f6460.1
Applied rewrites60.1%
if 9.19999999999999951e117 < x < 7.0999999999999998e224Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites25.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6476.6
Applied rewrites76.6%
Final simplification74.0%
(FPCore (x eps)
:precision binary64
(if (<= x -6.8e+153)
(* (/ (- (* (* x x) 4.0) 4.0) (- (* -2.0 x) 2.0)) 0.5)
(if (<= x -2.7e-247)
(* (fma (fma -1.0 (/ (- (* eps eps) 1.0) (- eps 1.0)) -1.0) x 2.0) 0.5)
(if (<= x 9.5e-239)
1.0
(*
(fma (fma -1.0 (- eps -1.0) (/ (+ -1.0 (* eps eps)) 1.0)) x 2.0)
0.5)))))
double code(double x, double eps) {
double tmp;
if (x <= -6.8e+153) {
tmp = ((((x * x) * 4.0) - 4.0) / ((-2.0 * x) - 2.0)) * 0.5;
} else if (x <= -2.7e-247) {
tmp = fma(fma(-1.0, (((eps * eps) - 1.0) / (eps - 1.0)), -1.0), x, 2.0) * 0.5;
} else if (x <= 9.5e-239) {
tmp = 1.0;
} else {
tmp = fma(fma(-1.0, (eps - -1.0), ((-1.0 + (eps * eps)) / 1.0)), x, 2.0) * 0.5;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -6.8e+153) tmp = Float64(Float64(Float64(Float64(Float64(x * x) * 4.0) - 4.0) / Float64(Float64(-2.0 * x) - 2.0)) * 0.5); elseif (x <= -2.7e-247) tmp = Float64(fma(fma(-1.0, Float64(Float64(Float64(eps * eps) - 1.0) / Float64(eps - 1.0)), -1.0), x, 2.0) * 0.5); elseif (x <= 9.5e-239) tmp = 1.0; else tmp = Float64(fma(fma(-1.0, Float64(eps - -1.0), Float64(Float64(-1.0 + Float64(eps * eps)) / 1.0)), x, 2.0) * 0.5); end return tmp end
code[x_, eps_] := If[LessEqual[x, -6.8e+153], N[(N[(N[(N[(N[(x * x), $MachinePrecision] * 4.0), $MachinePrecision] - 4.0), $MachinePrecision] / N[(N[(-2.0 * x), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, -2.7e-247], N[(N[(N[(-1.0 * N[(N[(N[(eps * eps), $MachinePrecision] - 1.0), $MachinePrecision] / N[(eps - 1.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] * x + 2.0), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 9.5e-239], 1.0, N[(N[(N[(-1.0 * N[(eps - -1.0), $MachinePrecision] + N[(N[(-1.0 + N[(eps * eps), $MachinePrecision]), $MachinePrecision] / 1.0), $MachinePrecision]), $MachinePrecision] * x + 2.0), $MachinePrecision] * 0.5), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.8 \cdot 10^{+153}:\\
\;\;\;\;\frac{\left(x \cdot x\right) \cdot 4 - 4}{-2 \cdot x - 2} \cdot 0.5\\
\mathbf{elif}\;x \leq -2.7 \cdot 10^{-247}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-1, \frac{\varepsilon \cdot \varepsilon - 1}{\varepsilon - 1}, -1\right), x, 2\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 9.5 \cdot 10^{-239}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-1, \varepsilon - -1, \frac{-1 + \varepsilon \cdot \varepsilon}{1}\right), x, 2\right) \cdot 0.5\\
\end{array}
\end{array}
if x < -6.7999999999999995e153Initial program 100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f643.4
Applied rewrites3.4%
lift-fma.f64N/A
lift-+.f64N/A
lift-fma.f64N/A
lift-neg.f64N/A
lift--.f64N/A
flip-+N/A
lower-/.f64N/A
Applied rewrites7.0%
Taylor expanded in eps around 0
Applied rewrites100.0%
if -6.7999999999999995e153 < x < -2.70000000000000008e-247Initial program 69.1%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites98.6%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6453.0
Applied rewrites53.0%
Taylor expanded in eps around 0
Applied rewrites56.5%
lift-+.f64N/A
flip-+N/A
lower-/.f64N/A
pow2N/A
metadata-evalN/A
lower--.f64N/A
pow2N/A
lift-*.f64N/A
lower--.f6467.0
Applied rewrites67.0%
if -2.70000000000000008e-247 < x < 9.4999999999999992e-239Initial program 48.9%
Taylor expanded in x around 0
Applied rewrites97.3%
if 9.4999999999999992e-239 < x Initial program 80.8%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6430.9
Applied rewrites30.9%
lift--.f64N/A
flip--N/A
lower-/.f64N/A
metadata-evalN/A
unpow2N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
lift-+.f6441.8
Applied rewrites41.8%
Taylor expanded in eps around 0
Applied rewrites62.5%
Final simplification72.3%
(FPCore (x eps)
:precision binary64
(if (<= x -6.8e+153)
(* (/ (- (* (* x x) 4.0) 4.0) (- (* -2.0 x) 2.0)) 0.5)
(if (<= x -2.7e-247)
(* (fma (fma -1.0 (/ (- (* eps eps) 1.0) (- eps 1.0)) -1.0) x 2.0) 0.5)
(fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0))))
double code(double x, double eps) {
double tmp;
if (x <= -6.8e+153) {
tmp = ((((x * x) * 4.0) - 4.0) / ((-2.0 * x) - 2.0)) * 0.5;
} else if (x <= -2.7e-247) {
tmp = fma(fma(-1.0, (((eps * eps) - 1.0) / (eps - 1.0)), -1.0), x, 2.0) * 0.5;
} else {
tmp = fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -6.8e+153) tmp = Float64(Float64(Float64(Float64(Float64(x * x) * 4.0) - 4.0) / Float64(Float64(-2.0 * x) - 2.0)) * 0.5); elseif (x <= -2.7e-247) tmp = Float64(fma(fma(-1.0, Float64(Float64(Float64(eps * eps) - 1.0) / Float64(eps - 1.0)), -1.0), x, 2.0) * 0.5); else tmp = fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0); end return tmp end
code[x_, eps_] := If[LessEqual[x, -6.8e+153], N[(N[(N[(N[(N[(x * x), $MachinePrecision] * 4.0), $MachinePrecision] - 4.0), $MachinePrecision] / N[(N[(-2.0 * x), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, -2.7e-247], N[(N[(N[(-1.0 * N[(N[(N[(eps * eps), $MachinePrecision] - 1.0), $MachinePrecision] / N[(eps - 1.0), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] * x + 2.0), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.8 \cdot 10^{+153}:\\
\;\;\;\;\frac{\left(x \cdot x\right) \cdot 4 - 4}{-2 \cdot x - 2} \cdot 0.5\\
\mathbf{elif}\;x \leq -2.7 \cdot 10^{-247}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-1, \frac{\varepsilon \cdot \varepsilon - 1}{\varepsilon - 1}, -1\right), x, 2\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)\\
\end{array}
\end{array}
if x < -6.7999999999999995e153Initial program 100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f643.4
Applied rewrites3.4%
lift-fma.f64N/A
lift-+.f64N/A
lift-fma.f64N/A
lift-neg.f64N/A
lift--.f64N/A
flip-+N/A
lower-/.f64N/A
Applied rewrites7.0%
Taylor expanded in eps around 0
Applied rewrites100.0%
if -6.7999999999999995e153 < x < -2.70000000000000008e-247Initial program 69.1%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites98.6%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6453.0
Applied rewrites53.0%
Taylor expanded in eps around 0
Applied rewrites56.5%
lift-+.f64N/A
flip-+N/A
lower-/.f64N/A
pow2N/A
metadata-evalN/A
lower--.f64N/A
pow2N/A
lift-*.f64N/A
lower--.f6467.0
Applied rewrites67.0%
if -2.70000000000000008e-247 < x Initial program 73.7%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites67.4%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6461.0
Applied rewrites61.0%
(FPCore (x eps) :precision binary64 (if (<= x -270.0) (* (/ (- (* (* x x) 4.0) 4.0) (- (* -2.0 x) 2.0)) 0.5) (fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0)))
double code(double x, double eps) {
double tmp;
if (x <= -270.0) {
tmp = ((((x * x) * 4.0) - 4.0) / ((-2.0 * x) - 2.0)) * 0.5;
} else {
tmp = fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -270.0) tmp = Float64(Float64(Float64(Float64(Float64(x * x) * 4.0) - 4.0) / Float64(Float64(-2.0 * x) - 2.0)) * 0.5); else tmp = fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0); end return tmp end
code[x_, eps_] := If[LessEqual[x, -270.0], N[(N[(N[(N[(N[(x * x), $MachinePrecision] * 4.0), $MachinePrecision] - 4.0), $MachinePrecision] / N[(N[(-2.0 * x), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -270:\\
\;\;\;\;\frac{\left(x \cdot x\right) \cdot 4 - 4}{-2 \cdot x - 2} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)\\
\end{array}
\end{array}
if x < -270Initial program 100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f643.3
Applied rewrites3.3%
lift-fma.f64N/A
lift-+.f64N/A
lift-fma.f64N/A
lift-neg.f64N/A
lift--.f64N/A
flip-+N/A
lower-/.f64N/A
Applied rewrites5.5%
Taylor expanded in eps around 0
Applied rewrites62.4%
if -270 < x Initial program 70.3%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites68.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6463.2
Applied rewrites63.2%
(FPCore (x eps) :precision binary64 (if (<= x -230.0) (* (fma (fma -1.0 (- eps -1.0) -1.0) x 2.0) 0.5) (fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0)))
double code(double x, double eps) {
double tmp;
if (x <= -230.0) {
tmp = fma(fma(-1.0, (eps - -1.0), -1.0), x, 2.0) * 0.5;
} else {
tmp = fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -230.0) tmp = Float64(fma(fma(-1.0, Float64(eps - -1.0), -1.0), x, 2.0) * 0.5); else tmp = fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0); end return tmp end
code[x_, eps_] := If[LessEqual[x, -230.0], N[(N[(N[(-1.0 * N[(eps - -1.0), $MachinePrecision] + -1.0), $MachinePrecision] * x + 2.0), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -230:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-1, \varepsilon - -1, -1\right), x, 2\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)\\
\end{array}
\end{array}
if x < -230Initial program 100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f643.3
Applied rewrites3.3%
Taylor expanded in eps around 0
Applied rewrites26.0%
if -230 < x Initial program 70.3%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites68.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6463.2
Applied rewrites63.2%
Final simplification57.2%
(FPCore (x eps) :precision binary64 (if (<= x -230.0) (* (fma (fma -1.0 eps -1.0) x 2.0) 0.5) (fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0)))
double code(double x, double eps) {
double tmp;
if (x <= -230.0) {
tmp = fma(fma(-1.0, eps, -1.0), x, 2.0) * 0.5;
} else {
tmp = fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -230.0) tmp = Float64(fma(fma(-1.0, eps, -1.0), x, 2.0) * 0.5); else tmp = fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0); end return tmp end
code[x_, eps_] := If[LessEqual[x, -230.0], N[(N[(N[(-1.0 * eps + -1.0), $MachinePrecision] * x + 2.0), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -230:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-1, \varepsilon, -1\right), x, 2\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)\\
\end{array}
\end{array}
if x < -230Initial program 100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f643.3
Applied rewrites3.3%
Taylor expanded in eps around 0
Applied rewrites26.0%
Taylor expanded in eps around inf
Applied rewrites26.0%
if -230 < x Initial program 70.3%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites68.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6463.2
Applied rewrites63.2%
(FPCore (x eps) :precision binary64 (* (fma (fma -1.0 eps -1.0) x 2.0) 0.5))
double code(double x, double eps) {
return fma(fma(-1.0, eps, -1.0), x, 2.0) * 0.5;
}
function code(x, eps) return Float64(fma(fma(-1.0, eps, -1.0), x, 2.0) * 0.5) end
code[x_, eps_] := N[(N[(N[(-1.0 * eps + -1.0), $MachinePrecision] * x + 2.0), $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(-1, \varepsilon, -1\right), x, 2\right) \cdot 0.5
\end{array}
Initial program 75.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.4%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6443.5
Applied rewrites43.5%
Taylor expanded in eps around 0
Applied rewrites50.9%
Taylor expanded in eps around inf
Applied rewrites50.9%
(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.0%
Taylor expanded in x around 0
Applied rewrites44.0%
herbie shell --seed 2025064
(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))