
(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 16 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}
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
:precision binary64
(let* ((t_0 (* (- x -1.0) (exp (- x)))))
(if (<= eps_m 1.0)
(* (+ t_0 t_0) 0.5)
(* (- (exp (* x eps_m)) (/ -1.0 (exp (fma x eps_m x)))) 0.5))))eps_m = fabs(eps);
double code(double x, double eps_m) {
double t_0 = (x - -1.0) * exp(-x);
double tmp;
if (eps_m <= 1.0) {
tmp = (t_0 + t_0) * 0.5;
} else {
tmp = (exp((x * eps_m)) - (-1.0 / exp(fma(x, eps_m, x)))) * 0.5;
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) t_0 = Float64(Float64(x - -1.0) * exp(Float64(-x))) tmp = 0.0 if (eps_m <= 1.0) tmp = Float64(Float64(t_0 + t_0) * 0.5); else tmp = Float64(Float64(exp(Float64(x * eps_m)) - Float64(-1.0 / exp(fma(x, eps_m, x)))) * 0.5); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision]
code[x_, eps$95$m_] := Block[{t$95$0 = N[(N[(x - -1.0), $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps$95$m, 1.0], N[(N[(t$95$0 + t$95$0), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[Exp[N[(x * eps$95$m), $MachinePrecision]], $MachinePrecision] - N[(-1.0 / N[Exp[N[(x * eps$95$m + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
t_0 := \left(x - -1\right) \cdot e^{-x}\\
\mathbf{if}\;eps\_m \leq 1:\\
\;\;\;\;\left(t\_0 + t\_0\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(e^{x \cdot eps\_m} - \frac{-1}{e^{\mathsf{fma}\left(x, eps\_m, x\right)}}\right) \cdot 0.5\\
\end{array}
\end{array}
if eps < 1Initial program 61.5%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites72.8%
distribute-rgt1-inN/A
distribute-lft-outN/A
lower--.f64N/A
lower-*.f64N/A
lower-+.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
distribute-lft-outN/A
distribute-rgt1-inN/A
mul-1-negN/A
lower-neg.f64N/A
lower-*.f64N/A
lower-+.f64N/A
lower-exp.f64N/A
lower-neg.f6472.8
Applied rewrites72.8%
if 1 < eps Initial program 100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
exp-negN/A
lower-/.f64N/A
lower-exp.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
lower-*.f64N/A
Applied rewrites100.0%
Final simplification79.9%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 (if (<= eps_m 1.0) (* (* (exp (- x)) 2.0) 0.5) (* (+ (exp (* eps_m x)) (exp (- (fma x eps_m x)))) 0.5)))
eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (eps_m <= 1.0) {
tmp = (exp(-x) * 2.0) * 0.5;
} else {
tmp = (exp((eps_m * x)) + exp(-fma(x, eps_m, x))) * 0.5;
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (eps_m <= 1.0) tmp = Float64(Float64(exp(Float64(-x)) * 2.0) * 0.5); else tmp = Float64(Float64(exp(Float64(eps_m * x)) + exp(Float64(-fma(x, eps_m, x)))) * 0.5); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[eps$95$m, 1.0], N[(N[(N[Exp[(-x)], $MachinePrecision] * 2.0), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[Exp[N[(eps$95$m * x), $MachinePrecision]], $MachinePrecision] + N[Exp[(-N[(x * eps$95$m + x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;eps\_m \leq 1:\\
\;\;\;\;\left(e^{-x} \cdot 2\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(e^{eps\_m \cdot x} + e^{-\mathsf{fma}\left(x, eps\_m, x\right)}\right) \cdot 0.5\\
\end{array}
\end{array}
if eps < 1Initial program 61.5%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites97.6%
exp-negN/A
lower-/.f64N/A
lower-exp.f64N/A
lower-fma.f6497.6
Applied rewrites97.6%
Taylor expanded in eps around 0
rec-expN/A
mul-1-negN/A
rec-expN/A
count-2-revN/A
*-commutativeN/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f6481.6
Applied rewrites81.6%
if 1 < 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
lower-*.f64100.0
Applied rewrites100.0%
Final simplification86.4%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 (* (+ (exp (* x (+ -1.0 eps_m))) (exp (- (fma x eps_m x)))) 0.5))
eps_m = fabs(eps);
double code(double x, double eps_m) {
return (exp((x * (-1.0 + eps_m))) + exp(-fma(x, eps_m, x))) * 0.5;
}
eps_m = abs(eps) function code(x, eps_m) return Float64(Float64(exp(Float64(x * Float64(-1.0 + eps_m))) + exp(Float64(-fma(x, eps_m, x)))) * 0.5) end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := N[(N[(N[Exp[N[(x * N[(-1.0 + eps$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[Exp[(-N[(x * eps$95$m + x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\left(e^{x \cdot \left(-1 + eps\_m\right)} + e^{-\mathsf{fma}\left(x, eps\_m, x\right)}\right) \cdot 0.5
\end{array}
Initial program 71.6%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites98.3%
Final simplification98.3%
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
:precision binary64
(let* ((t_0 (* (exp (- x)) 2.0)))
(if (<= x -360000000.0)
(* t_0 0.5)
(if (<= x -6e-285)
(* (- 1.0 (- (* x (/ (- 1.0 (* eps_m eps_m)) (- 1.0 eps_m))) 1.0)) 0.5)
(if (or (<= x 1.25e+103) (not (<= x 2.8e+196)))
(* (- (exp (* x eps_m)) -1.0) 0.5)
(* (* x t_0) 0.5))))))eps_m = fabs(eps);
double code(double x, double eps_m) {
double t_0 = exp(-x) * 2.0;
double tmp;
if (x <= -360000000.0) {
tmp = t_0 * 0.5;
} else if (x <= -6e-285) {
tmp = (1.0 - ((x * ((1.0 - (eps_m * eps_m)) / (1.0 - eps_m))) - 1.0)) * 0.5;
} else if ((x <= 1.25e+103) || !(x <= 2.8e+196)) {
tmp = (exp((x * eps_m)) - -1.0) * 0.5;
} else {
tmp = (x * t_0) * 0.5;
}
return tmp;
}
eps_m = private
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_m)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps_m
real(8) :: t_0
real(8) :: tmp
t_0 = exp(-x) * 2.0d0
if (x <= (-360000000.0d0)) then
tmp = t_0 * 0.5d0
else if (x <= (-6d-285)) then
tmp = (1.0d0 - ((x * ((1.0d0 - (eps_m * eps_m)) / (1.0d0 - eps_m))) - 1.0d0)) * 0.5d0
else if ((x <= 1.25d+103) .or. (.not. (x <= 2.8d+196))) then
tmp = (exp((x * eps_m)) - (-1.0d0)) * 0.5d0
else
tmp = (x * t_0) * 0.5d0
end if
code = tmp
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
double t_0 = Math.exp(-x) * 2.0;
double tmp;
if (x <= -360000000.0) {
tmp = t_0 * 0.5;
} else if (x <= -6e-285) {
tmp = (1.0 - ((x * ((1.0 - (eps_m * eps_m)) / (1.0 - eps_m))) - 1.0)) * 0.5;
} else if ((x <= 1.25e+103) || !(x <= 2.8e+196)) {
tmp = (Math.exp((x * eps_m)) - -1.0) * 0.5;
} else {
tmp = (x * t_0) * 0.5;
}
return tmp;
}
eps_m = math.fabs(eps) def code(x, eps_m): t_0 = math.exp(-x) * 2.0 tmp = 0 if x <= -360000000.0: tmp = t_0 * 0.5 elif x <= -6e-285: tmp = (1.0 - ((x * ((1.0 - (eps_m * eps_m)) / (1.0 - eps_m))) - 1.0)) * 0.5 elif (x <= 1.25e+103) or not (x <= 2.8e+196): tmp = (math.exp((x * eps_m)) - -1.0) * 0.5 else: tmp = (x * t_0) * 0.5 return tmp
eps_m = abs(eps) function code(x, eps_m) t_0 = Float64(exp(Float64(-x)) * 2.0) tmp = 0.0 if (x <= -360000000.0) tmp = Float64(t_0 * 0.5); elseif (x <= -6e-285) tmp = Float64(Float64(1.0 - Float64(Float64(x * Float64(Float64(1.0 - Float64(eps_m * eps_m)) / Float64(1.0 - eps_m))) - 1.0)) * 0.5); elseif ((x <= 1.25e+103) || !(x <= 2.8e+196)) tmp = Float64(Float64(exp(Float64(x * eps_m)) - -1.0) * 0.5); else tmp = Float64(Float64(x * t_0) * 0.5); end return tmp end
eps_m = abs(eps); function tmp_2 = code(x, eps_m) t_0 = exp(-x) * 2.0; tmp = 0.0; if (x <= -360000000.0) tmp = t_0 * 0.5; elseif (x <= -6e-285) tmp = (1.0 - ((x * ((1.0 - (eps_m * eps_m)) / (1.0 - eps_m))) - 1.0)) * 0.5; elseif ((x <= 1.25e+103) || ~((x <= 2.8e+196))) tmp = (exp((x * eps_m)) - -1.0) * 0.5; else tmp = (x * t_0) * 0.5; end tmp_2 = tmp; end
eps_m = N[Abs[eps], $MachinePrecision]
code[x_, eps$95$m_] := Block[{t$95$0 = N[(N[Exp[(-x)], $MachinePrecision] * 2.0), $MachinePrecision]}, If[LessEqual[x, -360000000.0], N[(t$95$0 * 0.5), $MachinePrecision], If[LessEqual[x, -6e-285], N[(N[(1.0 - N[(N[(x * N[(N[(1.0 - N[(eps$95$m * eps$95$m), $MachinePrecision]), $MachinePrecision] / N[(1.0 - eps$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[Or[LessEqual[x, 1.25e+103], N[Not[LessEqual[x, 2.8e+196]], $MachinePrecision]], N[(N[(N[Exp[N[(x * eps$95$m), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(x * t$95$0), $MachinePrecision] * 0.5), $MachinePrecision]]]]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
t_0 := e^{-x} \cdot 2\\
\mathbf{if}\;x \leq -360000000:\\
\;\;\;\;t\_0 \cdot 0.5\\
\mathbf{elif}\;x \leq -6 \cdot 10^{-285}:\\
\;\;\;\;\left(1 - \left(x \cdot \frac{1 - eps\_m \cdot eps\_m}{1 - eps\_m} - 1\right)\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 1.25 \cdot 10^{+103} \lor \neg \left(x \leq 2.8 \cdot 10^{+196}\right):\\
\;\;\;\;\left(e^{x \cdot eps\_m} - -1\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot t\_0\right) \cdot 0.5\\
\end{array}
\end{array}
if x < -3.6e8Initial program 100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
exp-negN/A
lower-/.f64N/A
lower-exp.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in eps around 0
rec-expN/A
mul-1-negN/A
rec-expN/A
count-2-revN/A
*-commutativeN/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
if -3.6e8 < x < -6.00000000000000007e-285Initial program 54.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites96.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-*.f64N/A
lower-+.f6481.5
Applied rewrites81.5%
Taylor expanded in x around 0
Applied rewrites65.3%
flip-+N/A
lower-/.f64N/A
metadata-evalN/A
unpow2N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
lower--.f6472.0
Applied rewrites72.0%
if -6.00000000000000007e-285 < x < 1.25e103 or 2.8000000000000002e196 < x Initial program 67.4%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites98.8%
exp-negN/A
lower-/.f64N/A
lower-exp.f64N/A
lower-fma.f6498.8
Applied rewrites98.8%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f6487.7
Applied rewrites87.7%
Taylor expanded in x around 0
rec-exp68.5
Applied rewrites68.5%
if 1.25e103 < x < 2.8000000000000002e196Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites78.9%
Taylor expanded in x around inf
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-exp.f64N/A
lower-neg.f6478.9
Applied rewrites78.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f6478.9
Applied rewrites78.9%
Final simplification75.3%
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
:precision binary64
(let* ((t_0 (* (* (exp (- x)) 2.0) 0.5)))
(if (<= x -360000000.0)
t_0
(if (<= x -6e-285)
(* (- 1.0 (- (* x (/ (- 1.0 (* eps_m eps_m)) (- 1.0 eps_m))) 1.0)) 0.5)
(if (or (<= x 1.25e+103) (not (<= x 8.5e+236)))
(* (- (exp (* x eps_m)) -1.0) 0.5)
t_0)))))eps_m = fabs(eps);
double code(double x, double eps_m) {
double t_0 = (exp(-x) * 2.0) * 0.5;
double tmp;
if (x <= -360000000.0) {
tmp = t_0;
} else if (x <= -6e-285) {
tmp = (1.0 - ((x * ((1.0 - (eps_m * eps_m)) / (1.0 - eps_m))) - 1.0)) * 0.5;
} else if ((x <= 1.25e+103) || !(x <= 8.5e+236)) {
tmp = (exp((x * eps_m)) - -1.0) * 0.5;
} else {
tmp = t_0;
}
return tmp;
}
eps_m = private
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_m)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps_m
real(8) :: t_0
real(8) :: tmp
t_0 = (exp(-x) * 2.0d0) * 0.5d0
if (x <= (-360000000.0d0)) then
tmp = t_0
else if (x <= (-6d-285)) then
tmp = (1.0d0 - ((x * ((1.0d0 - (eps_m * eps_m)) / (1.0d0 - eps_m))) - 1.0d0)) * 0.5d0
else if ((x <= 1.25d+103) .or. (.not. (x <= 8.5d+236))) then
tmp = (exp((x * eps_m)) - (-1.0d0)) * 0.5d0
else
tmp = t_0
end if
code = tmp
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
double t_0 = (Math.exp(-x) * 2.0) * 0.5;
double tmp;
if (x <= -360000000.0) {
tmp = t_0;
} else if (x <= -6e-285) {
tmp = (1.0 - ((x * ((1.0 - (eps_m * eps_m)) / (1.0 - eps_m))) - 1.0)) * 0.5;
} else if ((x <= 1.25e+103) || !(x <= 8.5e+236)) {
tmp = (Math.exp((x * eps_m)) - -1.0) * 0.5;
} else {
tmp = t_0;
}
return tmp;
}
eps_m = math.fabs(eps) def code(x, eps_m): t_0 = (math.exp(-x) * 2.0) * 0.5 tmp = 0 if x <= -360000000.0: tmp = t_0 elif x <= -6e-285: tmp = (1.0 - ((x * ((1.0 - (eps_m * eps_m)) / (1.0 - eps_m))) - 1.0)) * 0.5 elif (x <= 1.25e+103) or not (x <= 8.5e+236): tmp = (math.exp((x * eps_m)) - -1.0) * 0.5 else: tmp = t_0 return tmp
eps_m = abs(eps) function code(x, eps_m) t_0 = Float64(Float64(exp(Float64(-x)) * 2.0) * 0.5) tmp = 0.0 if (x <= -360000000.0) tmp = t_0; elseif (x <= -6e-285) tmp = Float64(Float64(1.0 - Float64(Float64(x * Float64(Float64(1.0 - Float64(eps_m * eps_m)) / Float64(1.0 - eps_m))) - 1.0)) * 0.5); elseif ((x <= 1.25e+103) || !(x <= 8.5e+236)) tmp = Float64(Float64(exp(Float64(x * eps_m)) - -1.0) * 0.5); else tmp = t_0; end return tmp end
eps_m = abs(eps); function tmp_2 = code(x, eps_m) t_0 = (exp(-x) * 2.0) * 0.5; tmp = 0.0; if (x <= -360000000.0) tmp = t_0; elseif (x <= -6e-285) tmp = (1.0 - ((x * ((1.0 - (eps_m * eps_m)) / (1.0 - eps_m))) - 1.0)) * 0.5; elseif ((x <= 1.25e+103) || ~((x <= 8.5e+236))) tmp = (exp((x * eps_m)) - -1.0) * 0.5; else tmp = t_0; end tmp_2 = tmp; end
eps_m = N[Abs[eps], $MachinePrecision]
code[x_, eps$95$m_] := Block[{t$95$0 = N[(N[(N[Exp[(-x)], $MachinePrecision] * 2.0), $MachinePrecision] * 0.5), $MachinePrecision]}, If[LessEqual[x, -360000000.0], t$95$0, If[LessEqual[x, -6e-285], N[(N[(1.0 - N[(N[(x * N[(N[(1.0 - N[(eps$95$m * eps$95$m), $MachinePrecision]), $MachinePrecision] / N[(1.0 - eps$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[Or[LessEqual[x, 1.25e+103], N[Not[LessEqual[x, 8.5e+236]], $MachinePrecision]], N[(N[(N[Exp[N[(x * eps$95$m), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision] * 0.5), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
t_0 := \left(e^{-x} \cdot 2\right) \cdot 0.5\\
\mathbf{if}\;x \leq -360000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -6 \cdot 10^{-285}:\\
\;\;\;\;\left(1 - \left(x \cdot \frac{1 - eps\_m \cdot eps\_m}{1 - eps\_m} - 1\right)\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 1.25 \cdot 10^{+103} \lor \neg \left(x \leq 8.5 \cdot 10^{+236}\right):\\
\;\;\;\;\left(e^{x \cdot eps\_m} - -1\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -3.6e8 or 1.25e103 < x < 8.5000000000000008e236Initial program 100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
exp-negN/A
lower-/.f64N/A
lower-exp.f64N/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in eps around 0
rec-expN/A
mul-1-negN/A
rec-expN/A
count-2-revN/A
*-commutativeN/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f6487.5
Applied rewrites87.5%
if -3.6e8 < x < -6.00000000000000007e-285Initial program 54.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites96.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-*.f64N/A
lower-+.f6481.5
Applied rewrites81.5%
Taylor expanded in x around 0
Applied rewrites65.3%
flip-+N/A
lower-/.f64N/A
metadata-evalN/A
unpow2N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
lower--.f6472.0
Applied rewrites72.0%
if -6.00000000000000007e-285 < x < 1.25e103 or 8.5000000000000008e236 < x Initial program 65.6%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites98.8%
exp-negN/A
lower-/.f64N/A
lower-exp.f64N/A
lower-fma.f6498.8
Applied rewrites98.8%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f6487.9
Applied rewrites87.9%
Taylor expanded in x around 0
rec-exp71.3
Applied rewrites71.3%
Final simplification76.0%
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
:precision binary64
(if (<= x -2e-288)
(* (+ 1.0 (exp (- (fma x eps_m x)))) 0.5)
(if (<= x 6.8)
(* (- (exp (* x eps_m)) (- (* x (+ 1.0 eps_m)) 1.0)) 0.5)
(if (<= x 2.8e+196)
(* (* x (* (exp (- x)) 2.0)) 0.5)
(* (- (exp (* x (+ -1.0 eps_m))) -1.0) 0.5)))))eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (x <= -2e-288) {
tmp = (1.0 + exp(-fma(x, eps_m, x))) * 0.5;
} else if (x <= 6.8) {
tmp = (exp((x * eps_m)) - ((x * (1.0 + eps_m)) - 1.0)) * 0.5;
} else if (x <= 2.8e+196) {
tmp = (x * (exp(-x) * 2.0)) * 0.5;
} else {
tmp = (exp((x * (-1.0 + eps_m))) - -1.0) * 0.5;
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (x <= -2e-288) tmp = Float64(Float64(1.0 + exp(Float64(-fma(x, eps_m, x)))) * 0.5); elseif (x <= 6.8) tmp = Float64(Float64(exp(Float64(x * eps_m)) - Float64(Float64(x * Float64(1.0 + eps_m)) - 1.0)) * 0.5); elseif (x <= 2.8e+196) tmp = Float64(Float64(x * Float64(exp(Float64(-x)) * 2.0)) * 0.5); else tmp = Float64(Float64(exp(Float64(x * Float64(-1.0 + eps_m))) - -1.0) * 0.5); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[x, -2e-288], N[(N[(1.0 + N[Exp[(-N[(x * eps$95$m + x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 6.8], N[(N[(N[Exp[N[(x * eps$95$m), $MachinePrecision]], $MachinePrecision] - N[(N[(x * N[(1.0 + eps$95$m), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 2.8e+196], N[(N[(x * N[(N[Exp[(-x)], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[Exp[N[(x * N[(-1.0 + eps$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision] * 0.5), $MachinePrecision]]]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-288}:\\
\;\;\;\;\left(1 + e^{-\mathsf{fma}\left(x, eps\_m, x\right)}\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 6.8:\\
\;\;\;\;\left(e^{x \cdot eps\_m} - \left(x \cdot \left(1 + eps\_m\right) - 1\right)\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{+196}:\\
\;\;\;\;\left(x \cdot \left(e^{-x} \cdot 2\right)\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(e^{x \cdot \left(-1 + eps\_m\right)} - -1\right) \cdot 0.5\\
\end{array}
\end{array}
if x < -2.00000000000000012e-288Initial program 68.8%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites97.3%
Taylor expanded in x around 0
distribute-lft-neg-in69.2
sinh---cosh-rev69.2
Applied rewrites69.2%
if -2.00000000000000012e-288 < x < 6.79999999999999982Initial program 49.5%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.3%
Taylor expanded in x around 0
lower--.f64N/A
lower-*.f64N/A
lower-+.f6487.0
Applied rewrites87.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f6487.1
Applied rewrites87.1%
if 6.79999999999999982 < x < 2.8000000000000002e196Initial program 97.9%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites68.6%
Taylor expanded in x around inf
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-exp.f64N/A
lower-neg.f6466.9
Applied rewrites66.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f6466.9
Applied rewrites66.9%
if 2.8000000000000002e196 < x Initial program 100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites36.8%
Final simplification70.8%
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
:precision binary64
(if (<= x -2e-296)
(* (+ 1.0 (exp (- (fma x eps_m x)))) 0.5)
(if (or (<= x 1.25e+103) (not (<= x 2.8e+196)))
(* (- (exp (* x eps_m)) -1.0) 0.5)
(* (* x (* (exp (- x)) 2.0)) 0.5))))eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (x <= -2e-296) {
tmp = (1.0 + exp(-fma(x, eps_m, x))) * 0.5;
} else if ((x <= 1.25e+103) || !(x <= 2.8e+196)) {
tmp = (exp((x * eps_m)) - -1.0) * 0.5;
} else {
tmp = (x * (exp(-x) * 2.0)) * 0.5;
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (x <= -2e-296) tmp = Float64(Float64(1.0 + exp(Float64(-fma(x, eps_m, x)))) * 0.5); elseif ((x <= 1.25e+103) || !(x <= 2.8e+196)) tmp = Float64(Float64(exp(Float64(x * eps_m)) - -1.0) * 0.5); else tmp = Float64(Float64(x * Float64(exp(Float64(-x)) * 2.0)) * 0.5); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[x, -2e-296], N[(N[(1.0 + N[Exp[(-N[(x * eps$95$m + x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[Or[LessEqual[x, 1.25e+103], N[Not[LessEqual[x, 2.8e+196]], $MachinePrecision]], N[(N[(N[Exp[N[(x * eps$95$m), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(x * N[(N[Exp[(-x)], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-296}:\\
\;\;\;\;\left(1 + e^{-\mathsf{fma}\left(x, eps\_m, x\right)}\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 1.25 \cdot 10^{+103} \lor \neg \left(x \leq 2.8 \cdot 10^{+196}\right):\\
\;\;\;\;\left(e^{x \cdot eps\_m} - -1\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot \left(e^{-x} \cdot 2\right)\right) \cdot 0.5\\
\end{array}
\end{array}
if x < -2e-296Initial program 67.4%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites97.3%
Taylor expanded in x around 0
distribute-lft-neg-in69.8
sinh---cosh-rev69.8
Applied rewrites69.8%
if -2e-296 < x < 1.25e103 or 2.8000000000000002e196 < x Initial program 68.9%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites98.8%
exp-negN/A
lower-/.f64N/A
lower-exp.f64N/A
lower-fma.f6498.8
Applied rewrites98.8%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f6487.2
Applied rewrites87.2%
Taylor expanded in x around 0
rec-exp67.8
Applied rewrites67.8%
if 1.25e103 < x < 2.8000000000000002e196Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites78.9%
Taylor expanded in x around inf
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-exp.f64N/A
lower-neg.f6478.9
Applied rewrites78.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f6478.9
Applied rewrites78.9%
Final simplification69.9%
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
:precision binary64
(if (<= x -2e-296)
(* (+ 1.0 (exp (- (fma x eps_m x)))) 0.5)
(if (<= x 1.25e+103)
(* (- (exp (* x eps_m)) -1.0) 0.5)
(if (<= x 2.8e+196)
(* (* x (* (exp (- x)) 2.0)) 0.5)
(* (- (exp (* x (+ -1.0 eps_m))) -1.0) 0.5)))))eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (x <= -2e-296) {
tmp = (1.0 + exp(-fma(x, eps_m, x))) * 0.5;
} else if (x <= 1.25e+103) {
tmp = (exp((x * eps_m)) - -1.0) * 0.5;
} else if (x <= 2.8e+196) {
tmp = (x * (exp(-x) * 2.0)) * 0.5;
} else {
tmp = (exp((x * (-1.0 + eps_m))) - -1.0) * 0.5;
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (x <= -2e-296) tmp = Float64(Float64(1.0 + exp(Float64(-fma(x, eps_m, x)))) * 0.5); elseif (x <= 1.25e+103) tmp = Float64(Float64(exp(Float64(x * eps_m)) - -1.0) * 0.5); elseif (x <= 2.8e+196) tmp = Float64(Float64(x * Float64(exp(Float64(-x)) * 2.0)) * 0.5); else tmp = Float64(Float64(exp(Float64(x * Float64(-1.0 + eps_m))) - -1.0) * 0.5); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[x, -2e-296], N[(N[(1.0 + N[Exp[(-N[(x * eps$95$m + x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 1.25e+103], N[(N[(N[Exp[N[(x * eps$95$m), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 2.8e+196], N[(N[(x * N[(N[Exp[(-x)], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[Exp[N[(x * N[(-1.0 + eps$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision] * 0.5), $MachinePrecision]]]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-296}:\\
\;\;\;\;\left(1 + e^{-\mathsf{fma}\left(x, eps\_m, x\right)}\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 1.25 \cdot 10^{+103}:\\
\;\;\;\;\left(e^{x \cdot eps\_m} - -1\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{+196}:\\
\;\;\;\;\left(x \cdot \left(e^{-x} \cdot 2\right)\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(e^{x \cdot \left(-1 + eps\_m\right)} - -1\right) \cdot 0.5\\
\end{array}
\end{array}
if x < -2e-296Initial program 67.4%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites97.3%
Taylor expanded in x around 0
distribute-lft-neg-in69.8
sinh---cosh-rev69.8
Applied rewrites69.8%
if -2e-296 < x < 1.25e103Initial program 60.6%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites98.5%
exp-negN/A
lower-/.f64N/A
lower-exp.f64N/A
lower-fma.f6498.5
Applied rewrites98.5%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f6489.5
Applied rewrites89.5%
Taylor expanded in x around 0
rec-exp76.2
Applied rewrites76.2%
if 1.25e103 < x < 2.8000000000000002e196Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites78.9%
Taylor expanded in x around inf
lower-*.f64N/A
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-exp.f64N/A
lower-neg.f6478.9
Applied rewrites78.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f6478.9
Applied rewrites78.9%
if 2.8000000000000002e196 < x Initial program 100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites36.8%
Final simplification70.0%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 (if (<= eps_m 5.2e+199) (* (* (exp (- x)) 2.0) 0.5) (* (- 1.0 (- (* x (/ (- 1.0 (* eps_m eps_m)) (- 1.0 eps_m))) 1.0)) 0.5)))
eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (eps_m <= 5.2e+199) {
tmp = (exp(-x) * 2.0) * 0.5;
} else {
tmp = (1.0 - ((x * ((1.0 - (eps_m * eps_m)) / (1.0 - eps_m))) - 1.0)) * 0.5;
}
return tmp;
}
eps_m = private
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_m)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps_m
real(8) :: tmp
if (eps_m <= 5.2d+199) then
tmp = (exp(-x) * 2.0d0) * 0.5d0
else
tmp = (1.0d0 - ((x * ((1.0d0 - (eps_m * eps_m)) / (1.0d0 - eps_m))) - 1.0d0)) * 0.5d0
end if
code = tmp
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
double tmp;
if (eps_m <= 5.2e+199) {
tmp = (Math.exp(-x) * 2.0) * 0.5;
} else {
tmp = (1.0 - ((x * ((1.0 - (eps_m * eps_m)) / (1.0 - eps_m))) - 1.0)) * 0.5;
}
return tmp;
}
eps_m = math.fabs(eps) def code(x, eps_m): tmp = 0 if eps_m <= 5.2e+199: tmp = (math.exp(-x) * 2.0) * 0.5 else: tmp = (1.0 - ((x * ((1.0 - (eps_m * eps_m)) / (1.0 - eps_m))) - 1.0)) * 0.5 return tmp
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (eps_m <= 5.2e+199) tmp = Float64(Float64(exp(Float64(-x)) * 2.0) * 0.5); else tmp = Float64(Float64(1.0 - Float64(Float64(x * Float64(Float64(1.0 - Float64(eps_m * eps_m)) / Float64(1.0 - eps_m))) - 1.0)) * 0.5); end return tmp end
eps_m = abs(eps); function tmp_2 = code(x, eps_m) tmp = 0.0; if (eps_m <= 5.2e+199) tmp = (exp(-x) * 2.0) * 0.5; else tmp = (1.0 - ((x * ((1.0 - (eps_m * eps_m)) / (1.0 - eps_m))) - 1.0)) * 0.5; end tmp_2 = tmp; end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[eps$95$m, 5.2e+199], N[(N[(N[Exp[(-x)], $MachinePrecision] * 2.0), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(1.0 - N[(N[(x * N[(N[(1.0 - N[(eps$95$m * eps$95$m), $MachinePrecision]), $MachinePrecision] / N[(1.0 - eps$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;eps\_m \leq 5.2 \cdot 10^{+199}:\\
\;\;\;\;\left(e^{-x} \cdot 2\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(1 - \left(x \cdot \frac{1 - eps\_m \cdot eps\_m}{1 - eps\_m} - 1\right)\right) \cdot 0.5\\
\end{array}
\end{array}
if eps < 5.2000000000000003e199Initial program 68.5%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites98.1%
exp-negN/A
lower-/.f64N/A
lower-exp.f64N/A
lower-fma.f6498.1
Applied rewrites98.1%
Taylor expanded in eps around 0
rec-expN/A
mul-1-negN/A
rec-expN/A
count-2-revN/A
*-commutativeN/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f6477.3
Applied rewrites77.3%
if 5.2000000000000003e199 < eps Initial program 99.9%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.9%
Taylor expanded in x around 0
lower--.f64N/A
lower-*.f64N/A
lower-+.f6444.3
Applied rewrites44.3%
Taylor expanded in x around 0
Applied rewrites31.3%
flip-+N/A
lower-/.f64N/A
metadata-evalN/A
unpow2N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
lower--.f6456.3
Applied rewrites56.3%
Final simplification75.3%
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
:precision binary64
(let* ((t_0 (* (- eps_m 1.0) x))
(t_1 (* (- (/ 1.0 eps_m) 1.0) 1.0))
(t_2 (+ 1.0 (/ 1.0 eps_m))))
(if (<= x -520000000.0)
(/ (- (* t_2 (/ (- 1.0 (* t_0 t_0)) (- 1.0 (- x)))) t_1) 2.0)
(if (<= x -2e-218)
(* (- 1.0 (- (* x (/ (- 1.0 (* eps_m eps_m)) (- 1.0 eps_m))) 1.0)) 0.5)
(if (<= x 360.0)
1.0
(if (<= x 2.4e+206)
(/ (- (* t_2 1.0) t_1) 2.0)
(fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0)))))))eps_m = fabs(eps);
double code(double x, double eps_m) {
double t_0 = (eps_m - 1.0) * x;
double t_1 = ((1.0 / eps_m) - 1.0) * 1.0;
double t_2 = 1.0 + (1.0 / eps_m);
double tmp;
if (x <= -520000000.0) {
tmp = ((t_2 * ((1.0 - (t_0 * t_0)) / (1.0 - -x))) - t_1) / 2.0;
} else if (x <= -2e-218) {
tmp = (1.0 - ((x * ((1.0 - (eps_m * eps_m)) / (1.0 - eps_m))) - 1.0)) * 0.5;
} else if (x <= 360.0) {
tmp = 1.0;
} else if (x <= 2.4e+206) {
tmp = ((t_2 * 1.0) - t_1) / 2.0;
} else {
tmp = fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) t_0 = Float64(Float64(eps_m - 1.0) * x) t_1 = Float64(Float64(Float64(1.0 / eps_m) - 1.0) * 1.0) t_2 = Float64(1.0 + Float64(1.0 / eps_m)) tmp = 0.0 if (x <= -520000000.0) tmp = Float64(Float64(Float64(t_2 * Float64(Float64(1.0 - Float64(t_0 * t_0)) / Float64(1.0 - Float64(-x)))) - t_1) / 2.0); elseif (x <= -2e-218) tmp = Float64(Float64(1.0 - Float64(Float64(x * Float64(Float64(1.0 - Float64(eps_m * eps_m)) / Float64(1.0 - eps_m))) - 1.0)) * 0.5); elseif (x <= 360.0) tmp = 1.0; elseif (x <= 2.4e+206) tmp = Float64(Float64(Float64(t_2 * 1.0) - t_1) / 2.0); else tmp = fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision]
code[x_, eps$95$m_] := Block[{t$95$0 = N[(N[(eps$95$m - 1.0), $MachinePrecision] * x), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(1.0 / eps$95$m), $MachinePrecision] - 1.0), $MachinePrecision] * 1.0), $MachinePrecision]}, Block[{t$95$2 = N[(1.0 + N[(1.0 / eps$95$m), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -520000000.0], N[(N[(N[(t$95$2 * N[(N[(1.0 - N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(1.0 - (-x)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$1), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, -2e-218], N[(N[(1.0 - N[(N[(x * N[(N[(1.0 - N[(eps$95$m * eps$95$m), $MachinePrecision]), $MachinePrecision] / N[(1.0 - eps$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 360.0], 1.0, If[LessEqual[x, 2.4e+206], N[(N[(N[(t$95$2 * 1.0), $MachinePrecision] - t$95$1), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]]]]]]]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
t_0 := \left(eps\_m - 1\right) \cdot x\\
t_1 := \left(\frac{1}{eps\_m} - 1\right) \cdot 1\\
t_2 := 1 + \frac{1}{eps\_m}\\
\mathbf{if}\;x \leq -520000000:\\
\;\;\;\;\frac{t\_2 \cdot \frac{1 - t\_0 \cdot t\_0}{1 - \left(-x\right)} - t\_1}{2}\\
\mathbf{elif}\;x \leq -2 \cdot 10^{-218}:\\
\;\;\;\;\left(1 - \left(x \cdot \frac{1 - eps\_m \cdot eps\_m}{1 - eps\_m} - 1\right)\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 360:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 2.4 \cdot 10^{+206}:\\
\;\;\;\;\frac{t\_2 \cdot 1 - t\_1}{2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)\\
\end{array}
\end{array}
if x < -5.2e8Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites55.5%
Taylor expanded in x around 0
lower-+.f64N/A
lower-*.f64N/A
lower--.f6431.6
Applied rewrites31.6%
flip-+N/A
lower-/.f64N/A
metadata-evalN/A
lower--.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6419.2
Applied rewrites19.2%
Taylor expanded in eps around 0
mul-1-negN/A
lower-neg.f6484.6
Applied rewrites84.6%
if -5.2e8 < x < -2.0000000000000001e-218Initial program 52.9%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites95.4%
Taylor expanded in x around 0
lower--.f64N/A
lower-*.f64N/A
lower-+.f6480.2
Applied rewrites80.2%
Taylor expanded in x around 0
Applied rewrites63.1%
flip-+N/A
lower-/.f64N/A
metadata-evalN/A
unpow2N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
lower--.f6472.3
Applied rewrites72.3%
if -2.0000000000000001e-218 < x < 360Initial program 50.4%
Taylor expanded in x around 0
Applied rewrites79.8%
if 360 < x < 2.4e206Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites25.8%
Taylor expanded in x around 0
Applied rewrites66.3%
if 2.4e206 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites40.1%
Taylor expanded in x around 0
lower-+.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f640.6
Applied rewrites0.6%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
pow2N/A
lower-*.f6461.5
Applied rewrites61.5%
Final simplification74.4%
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
:precision binary64
(if (<= x -2e-218)
(* (- 1.0 (- (* x (/ (- 1.0 (* eps_m eps_m)) (- 1.0 eps_m))) 1.0)) 0.5)
(if (<= x 360.0)
1.0
(if (<= x 2.4e+206)
(/ (- (* (+ 1.0 (/ 1.0 eps_m)) 1.0) (* (- (/ 1.0 eps_m) 1.0) 1.0)) 2.0)
(fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0)))))eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (x <= -2e-218) {
tmp = (1.0 - ((x * ((1.0 - (eps_m * eps_m)) / (1.0 - eps_m))) - 1.0)) * 0.5;
} else if (x <= 360.0) {
tmp = 1.0;
} else if (x <= 2.4e+206) {
tmp = (((1.0 + (1.0 / eps_m)) * 1.0) - (((1.0 / eps_m) - 1.0) * 1.0)) / 2.0;
} else {
tmp = fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (x <= -2e-218) tmp = Float64(Float64(1.0 - Float64(Float64(x * Float64(Float64(1.0 - Float64(eps_m * eps_m)) / Float64(1.0 - eps_m))) - 1.0)) * 0.5); elseif (x <= 360.0) tmp = 1.0; elseif (x <= 2.4e+206) tmp = Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps_m)) * 1.0) - Float64(Float64(Float64(1.0 / eps_m) - 1.0) * 1.0)) / 2.0); else tmp = fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[x, -2e-218], N[(N[(1.0 - N[(N[(x * N[(N[(1.0 - N[(eps$95$m * eps$95$m), $MachinePrecision]), $MachinePrecision] / N[(1.0 - eps$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 360.0], 1.0, If[LessEqual[x, 2.4e+206], N[(N[(N[(N[(1.0 + N[(1.0 / eps$95$m), $MachinePrecision]), $MachinePrecision] * 1.0), $MachinePrecision] - N[(N[(N[(1.0 / eps$95$m), $MachinePrecision] - 1.0), $MachinePrecision] * 1.0), $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}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-218}:\\
\;\;\;\;\left(1 - \left(x \cdot \frac{1 - eps\_m \cdot eps\_m}{1 - eps\_m} - 1\right)\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 360:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 2.4 \cdot 10^{+206}:\\
\;\;\;\;\frac{\left(1 + \frac{1}{eps\_m}\right) \cdot 1 - \left(\frac{1}{eps\_m} - 1\right) \cdot 1}{2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)\\
\end{array}
\end{array}
if x < -2.0000000000000001e-218Initial program 69.5%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites97.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-*.f64N/A
lower-+.f6466.8
Applied rewrites66.8%
Taylor expanded in x around 0
Applied rewrites47.2%
flip-+N/A
lower-/.f64N/A
metadata-evalN/A
unpow2N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
lower--.f6454.0
Applied rewrites54.0%
if -2.0000000000000001e-218 < x < 360Initial program 50.4%
Taylor expanded in x around 0
Applied rewrites79.8%
if 360 < x < 2.4e206Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites25.8%
Taylor expanded in x around 0
Applied rewrites66.3%
if 2.4e206 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites40.1%
Taylor expanded in x around 0
lower-+.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f640.6
Applied rewrites0.6%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
pow2N/A
lower-*.f6461.5
Applied rewrites61.5%
Final simplification65.1%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 (if (<= x -2e-218) (* (- 1.0 (- (* x (/ (- 1.0 (* eps_m eps_m)) (- 1.0 eps_m))) 1.0)) 0.5) (fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0)))
eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (x <= -2e-218) {
tmp = (1.0 - ((x * ((1.0 - (eps_m * eps_m)) / (1.0 - eps_m))) - 1.0)) * 0.5;
} else {
tmp = fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (x <= -2e-218) tmp = Float64(Float64(1.0 - Float64(Float64(x * Float64(Float64(1.0 - Float64(eps_m * eps_m)) / Float64(1.0 - eps_m))) - 1.0)) * 0.5); else tmp = fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[x, -2e-218], N[(N[(1.0 - N[(N[(x * N[(N[(1.0 - N[(eps$95$m * eps$95$m), $MachinePrecision]), $MachinePrecision] / N[(1.0 - eps$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.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}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-218}:\\
\;\;\;\;\left(1 - \left(x \cdot \frac{1 - eps\_m \cdot eps\_m}{1 - eps\_m} - 1\right)\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 < -2.0000000000000001e-218Initial program 69.5%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites97.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-*.f64N/A
lower-+.f6466.8
Applied rewrites66.8%
Taylor expanded in x around 0
Applied rewrites47.2%
flip-+N/A
lower-/.f64N/A
metadata-evalN/A
unpow2N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
lower--.f6454.0
Applied rewrites54.0%
if -2.0000000000000001e-218 < x Initial program 73.1%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites70.7%
Taylor expanded in x around 0
lower-+.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6443.8
Applied rewrites43.8%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
pow2N/A
lower-*.f6457.4
Applied rewrites57.4%
Final simplification56.0%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 (if (<= x -1.2e-179) (* (- 1.0 (- (* x eps_m) 1.0)) 0.5) (fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0)))
eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (x <= -1.2e-179) {
tmp = (1.0 - ((x * eps_m) - 1.0)) * 0.5;
} else {
tmp = fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (x <= -1.2e-179) tmp = Float64(Float64(1.0 - Float64(Float64(x * eps_m) - 1.0)) * 0.5); else tmp = fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[x, -1.2e-179], N[(N[(1.0 - N[(N[(x * eps$95$m), $MachinePrecision] - 1.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}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.2 \cdot 10^{-179}:\\
\;\;\;\;\left(1 - \left(x \cdot eps\_m - 1\right)\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 < -1.2e-179Initial program 73.6%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites96.6%
Taylor expanded in x around 0
lower--.f64N/A
lower-*.f64N/A
lower-+.f6463.4
Applied rewrites63.4%
Taylor expanded in x around 0
Applied rewrites41.3%
Taylor expanded in eps around inf
Applied rewrites42.8%
if -1.2e-179 < x Initial program 70.5%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites72.2%
Taylor expanded in x around 0
lower-+.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6447.5
Applied rewrites47.5%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f64N/A
pow2N/A
lower-*.f6460.0
Applied rewrites60.0%
Final simplification53.8%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 (if (<= x -0.48) (* (- 1.0 (* x eps_m)) 0.5) 1.0))
eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (x <= -0.48) {
tmp = (1.0 - (x * eps_m)) * 0.5;
} else {
tmp = 1.0;
}
return tmp;
}
eps_m = private
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_m)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps_m
real(8) :: tmp
if (x <= (-0.48d0)) then
tmp = (1.0d0 - (x * eps_m)) * 0.5d0
else
tmp = 1.0d0
end if
code = tmp
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
double tmp;
if (x <= -0.48) {
tmp = (1.0 - (x * eps_m)) * 0.5;
} else {
tmp = 1.0;
}
return tmp;
}
eps_m = math.fabs(eps) def code(x, eps_m): tmp = 0 if x <= -0.48: tmp = (1.0 - (x * eps_m)) * 0.5 else: tmp = 1.0 return tmp
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (x <= -0.48) tmp = Float64(Float64(1.0 - Float64(x * eps_m)) * 0.5); else tmp = 1.0; end return tmp end
eps_m = abs(eps); function tmp_2 = code(x, eps_m) tmp = 0.0; if (x <= -0.48) tmp = (1.0 - (x * eps_m)) * 0.5; else tmp = 1.0; end tmp_2 = tmp; end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[x, -0.48], N[(N[(1.0 - N[(x * eps$95$m), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], 1.0]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.48:\\
\;\;\;\;\left(1 - x \cdot eps\_m\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -0.47999999999999998Initial program 97.5%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites97.5%
Taylor expanded in x around 0
lower--.f64N/A
lower-*.f64N/A
lower-+.f6441.6
Applied rewrites41.6%
Taylor expanded in x around 0
Applied rewrites16.6%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f6416.6
Applied rewrites16.6%
if -0.47999999999999998 < x Initial program 66.8%
Taylor expanded in x around 0
Applied rewrites52.0%
Final simplification46.5%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 (* (- 1.0 (- (* x eps_m) 1.0)) 0.5))
eps_m = fabs(eps);
double code(double x, double eps_m) {
return (1.0 - ((x * eps_m) - 1.0)) * 0.5;
}
eps_m = private
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_m)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps_m
code = (1.0d0 - ((x * eps_m) - 1.0d0)) * 0.5d0
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
return (1.0 - ((x * eps_m) - 1.0)) * 0.5;
}
eps_m = math.fabs(eps) def code(x, eps_m): return (1.0 - ((x * eps_m) - 1.0)) * 0.5
eps_m = abs(eps) function code(x, eps_m) return Float64(Float64(1.0 - Float64(Float64(x * eps_m) - 1.0)) * 0.5) end
eps_m = abs(eps); function tmp = code(x, eps_m) tmp = (1.0 - ((x * eps_m) - 1.0)) * 0.5; end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := N[(N[(1.0 - N[(N[(x * eps$95$m), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\left(1 - \left(x \cdot eps\_m - 1\right)\right) \cdot 0.5
\end{array}
Initial program 71.6%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites98.3%
Taylor expanded in x around 0
lower--.f64N/A
lower-*.f64N/A
lower-+.f6461.8
Applied rewrites61.8%
Taylor expanded in x around 0
Applied rewrites47.3%
Taylor expanded in eps around inf
Applied rewrites48.1%
Final simplification48.1%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 1.0)
eps_m = fabs(eps);
double code(double x, double eps_m) {
return 1.0;
}
eps_m = private
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_m)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps_m
code = 1.0d0
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
return 1.0;
}
eps_m = math.fabs(eps) def code(x, eps_m): return 1.0
eps_m = abs(eps) function code(x, eps_m) return 1.0 end
eps_m = abs(eps); function tmp = code(x, eps_m) tmp = 1.0; end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := 1.0
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
1
\end{array}
Initial program 71.6%
Taylor expanded in x around 0
Applied rewrites44.4%
herbie shell --seed 2025044
(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))