
(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 15 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (/ (- (* (+ 1.0 (/ 1.0 eps)) (exp (- (* (- 1.0 eps) x)))) (* (- (/ 1.0 eps) 1.0) (exp (- (* (+ 1.0 eps) x))))) 2.0))
double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, eps)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (((1.0d0 + (1.0d0 / eps)) * exp(-((1.0d0 - eps) * x))) - (((1.0d0 / eps) - 1.0d0) * exp(-((1.0d0 + eps) * x)))) / 2.0d0
end function
public static double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * Math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * Math.exp(-((1.0 + eps) * x)))) / 2.0;
}
def code(x, eps): return (((1.0 + (1.0 / eps)) * math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * math.exp(-((1.0 + eps) * x)))) / 2.0
function code(x, eps) return Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(-Float64(Float64(1.0 - eps) * x)))) - Float64(Float64(Float64(1.0 / eps) - 1.0) * exp(Float64(-Float64(Float64(1.0 + eps) * x))))) / 2.0) end
function tmp = code(x, eps) tmp = (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0; end
code[x_, eps_] := N[(N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[(-N[(N[(1.0 - eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[(-N[(N[(1.0 + eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2}
\end{array}
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (pow eps -1.0) 1.0))
(t_1 (* (+ 1.0 (pow eps -1.0)) (exp (* (+ -1.0 eps) x)))))
(if (<= (/ (- t_1 (* t_0 (exp (* (- -1.0 eps) x)))) 2.0) 0.0)
(* (fma (exp (- x)) (- (+ 1.0 x) -1.0) (/ x (exp x))) 0.5)
(/ (- t_1 (* t_0 (exp (- (* x eps))))) 2.0))))
double code(double x, double eps) {
double t_0 = pow(eps, -1.0) - 1.0;
double t_1 = (1.0 + pow(eps, -1.0)) * exp(((-1.0 + eps) * x));
double tmp;
if (((t_1 - (t_0 * exp(((-1.0 - eps) * x)))) / 2.0) <= 0.0) {
tmp = fma(exp(-x), ((1.0 + x) - -1.0), (x / exp(x))) * 0.5;
} else {
tmp = (t_1 - (t_0 * exp(-(x * eps)))) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64((eps ^ -1.0) - 1.0) t_1 = Float64(Float64(1.0 + (eps ^ -1.0)) * exp(Float64(Float64(-1.0 + eps) * x))) tmp = 0.0 if (Float64(Float64(t_1 - Float64(t_0 * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0) <= 0.0) tmp = Float64(fma(exp(Float64(-x)), Float64(Float64(1.0 + x) - -1.0), Float64(x / exp(x))) * 0.5); else tmp = Float64(Float64(t_1 - Float64(t_0 * exp(Float64(-Float64(x * eps))))) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(N[(1.0 + N[Power[eps, -1.0], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(t$95$1 - N[(t$95$0 * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 0.0], N[(N[(N[Exp[(-x)], $MachinePrecision] * N[(N[(1.0 + x), $MachinePrecision] - -1.0), $MachinePrecision] + N[(x / N[Exp[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(t$95$1 - N[(t$95$0 * N[Exp[(-N[(x * eps), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\varepsilon}^{-1} - 1\\
t_1 := \left(1 + {\varepsilon}^{-1}\right) \cdot e^{\left(-1 + \varepsilon\right) \cdot x}\\
\mathbf{if}\;\frac{t\_1 - t\_0 \cdot e^{\left(-1 - \varepsilon\right) \cdot x}}{2} \leq 0:\\
\;\;\;\;\mathsf{fma}\left(e^{-x}, \left(1 + x\right) - -1, \frac{x}{e^{x}}\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_1 - t\_0 \cdot e^{-x \cdot \varepsilon}}{2}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) < 0.0Initial program 38.9%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
if 0.0 < (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) Initial program 98.7%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f6498.7
Applied rewrites98.7%
Final simplification99.2%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (pow eps -1.0) 1.0)) (t_1 (- eps (pow eps -1.0))))
(if (<=
(/
(-
(* (+ 1.0 (pow eps -1.0)) (exp (* (+ -1.0 eps) x)))
(* t_0 (exp (* (- -1.0 eps) x))))
2.0)
1.0004)
(* (fma (exp (- x)) (- (+ 1.0 x) -1.0) (/ x (exp x))) 0.5)
(fma
(* 0.5 x)
(fma
(* 0.5 x)
(fma t_1 (- eps 1.0) (* (pow (+ 1.0 eps) 2.0) (- (/ -1.0 eps) -1.0)))
(fma (+ 1.0 eps) t_0 t_1))
1.0))))
double code(double x, double eps) {
double t_0 = pow(eps, -1.0) - 1.0;
double t_1 = eps - pow(eps, -1.0);
double tmp;
if (((((1.0 + pow(eps, -1.0)) * exp(((-1.0 + eps) * x))) - (t_0 * exp(((-1.0 - eps) * x)))) / 2.0) <= 1.0004) {
tmp = fma(exp(-x), ((1.0 + x) - -1.0), (x / exp(x))) * 0.5;
} else {
tmp = fma((0.5 * x), fma((0.5 * x), fma(t_1, (eps - 1.0), (pow((1.0 + eps), 2.0) * ((-1.0 / eps) - -1.0))), fma((1.0 + eps), t_0, t_1)), 1.0);
}
return tmp;
}
function code(x, eps) t_0 = Float64((eps ^ -1.0) - 1.0) t_1 = Float64(eps - (eps ^ -1.0)) tmp = 0.0 if (Float64(Float64(Float64(Float64(1.0 + (eps ^ -1.0)) * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(t_0 * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0) <= 1.0004) tmp = Float64(fma(exp(Float64(-x)), Float64(Float64(1.0 + x) - -1.0), Float64(x / exp(x))) * 0.5); else tmp = fma(Float64(0.5 * x), fma(Float64(0.5 * x), fma(t_1, Float64(eps - 1.0), Float64((Float64(1.0 + eps) ^ 2.0) * Float64(Float64(-1.0 / eps) - -1.0))), fma(Float64(1.0 + eps), t_0, t_1)), 1.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(eps - N[Power[eps, -1.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[(N[(1.0 + N[Power[eps, -1.0], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(t$95$0 * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 1.0004], N[(N[(N[Exp[(-x)], $MachinePrecision] * N[(N[(1.0 + x), $MachinePrecision] - -1.0), $MachinePrecision] + N[(x / N[Exp[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(0.5 * x), $MachinePrecision] * N[(N[(0.5 * x), $MachinePrecision] * N[(t$95$1 * N[(eps - 1.0), $MachinePrecision] + N[(N[Power[N[(1.0 + eps), $MachinePrecision], 2.0], $MachinePrecision] * N[(N[(-1.0 / eps), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 + eps), $MachinePrecision] * t$95$0 + t$95$1), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\varepsilon}^{-1} - 1\\
t_1 := \varepsilon - {\varepsilon}^{-1}\\
\mathbf{if}\;\frac{\left(1 + {\varepsilon}^{-1}\right) \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - t\_0 \cdot e^{\left(-1 - \varepsilon\right) \cdot x}}{2} \leq 1.0004:\\
\;\;\;\;\mathsf{fma}\left(e^{-x}, \left(1 + x\right) - -1, \frac{x}{e^{x}}\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x, \mathsf{fma}\left(0.5 \cdot x, \mathsf{fma}\left(t\_1, \varepsilon - 1, {\left(1 + \varepsilon\right)}^{2} \cdot \left(\frac{-1}{\varepsilon} - -1\right)\right), \mathsf{fma}\left(1 + \varepsilon, t\_0, t\_1\right)\right), 1\right)\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) < 1.0004Initial program 53.9%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites98.9%
if 1.0004 < (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) Initial program 98.4%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6498.4
Applied rewrites98.4%
Taylor expanded in x around inf
lower-exp.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6498.4
Applied rewrites98.4%
Applied rewrites98.4%
Taylor expanded in x around 0
Applied rewrites76.3%
Final simplification87.1%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (pow eps -1.0) 1.0)) (t_1 (- eps (pow eps -1.0))))
(if (<=
(/
(-
(* (+ 1.0 (pow eps -1.0)) (exp (* (+ -1.0 eps) x)))
(* t_0 (exp (* (- -1.0 eps) x))))
2.0)
1.0004)
1.0
(fma
(* 0.5 x)
(fma
(* 0.5 x)
(fma t_1 (- eps 1.0) (* (pow (+ 1.0 eps) 2.0) (- (/ -1.0 eps) -1.0)))
(fma (+ 1.0 eps) t_0 t_1))
1.0))))
double code(double x, double eps) {
double t_0 = pow(eps, -1.0) - 1.0;
double t_1 = eps - pow(eps, -1.0);
double tmp;
if (((((1.0 + pow(eps, -1.0)) * exp(((-1.0 + eps) * x))) - (t_0 * exp(((-1.0 - eps) * x)))) / 2.0) <= 1.0004) {
tmp = 1.0;
} else {
tmp = fma((0.5 * x), fma((0.5 * x), fma(t_1, (eps - 1.0), (pow((1.0 + eps), 2.0) * ((-1.0 / eps) - -1.0))), fma((1.0 + eps), t_0, t_1)), 1.0);
}
return tmp;
}
function code(x, eps) t_0 = Float64((eps ^ -1.0) - 1.0) t_1 = Float64(eps - (eps ^ -1.0)) tmp = 0.0 if (Float64(Float64(Float64(Float64(1.0 + (eps ^ -1.0)) * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(t_0 * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0) <= 1.0004) tmp = 1.0; else tmp = fma(Float64(0.5 * x), fma(Float64(0.5 * x), fma(t_1, Float64(eps - 1.0), Float64((Float64(1.0 + eps) ^ 2.0) * Float64(Float64(-1.0 / eps) - -1.0))), fma(Float64(1.0 + eps), t_0, t_1)), 1.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(eps - N[Power[eps, -1.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[(N[(1.0 + N[Power[eps, -1.0], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(t$95$0 * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 1.0004], 1.0, N[(N[(0.5 * x), $MachinePrecision] * N[(N[(0.5 * x), $MachinePrecision] * N[(t$95$1 * N[(eps - 1.0), $MachinePrecision] + N[(N[Power[N[(1.0 + eps), $MachinePrecision], 2.0], $MachinePrecision] * N[(N[(-1.0 / eps), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 + eps), $MachinePrecision] * t$95$0 + t$95$1), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\varepsilon}^{-1} - 1\\
t_1 := \varepsilon - {\varepsilon}^{-1}\\
\mathbf{if}\;\frac{\left(1 + {\varepsilon}^{-1}\right) \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - t\_0 \cdot e^{\left(-1 - \varepsilon\right) \cdot x}}{2} \leq 1.0004:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x, \mathsf{fma}\left(0.5 \cdot x, \mathsf{fma}\left(t\_1, \varepsilon - 1, {\left(1 + \varepsilon\right)}^{2} \cdot \left(\frac{-1}{\varepsilon} - -1\right)\right), \mathsf{fma}\left(1 + \varepsilon, t\_0, t\_1\right)\right), 1\right)\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) < 1.0004Initial program 53.9%
Taylor expanded in x around 0
Applied rewrites70.8%
if 1.0004 < (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) Initial program 98.4%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6498.4
Applied rewrites98.4%
Taylor expanded in x around inf
lower-exp.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6498.4
Applied rewrites98.4%
Applied rewrites98.4%
Taylor expanded in x around 0
Applied rewrites76.3%
Final simplification73.7%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ 1.0 (pow eps -1.0))))
(if (<=
(/
(-
(* t_0 (exp (* (+ -1.0 eps) x)))
(* (- (pow eps -1.0) 1.0) (exp (* (- -1.0 eps) x))))
2.0)
1.0)
(* (fma (exp (- x)) (- (+ 1.0 x) -1.0) (/ x (exp x))) 0.5)
(/
(- (* t_0 (exp (- (* x eps) x))) (/ -1.0 (pow (E) (fma x eps x))))
2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + {\varepsilon}^{-1}\\
\mathbf{if}\;\frac{t\_0 \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - \left({\varepsilon}^{-1} - 1\right) \cdot e^{\left(-1 - \varepsilon\right) \cdot x}}{2} \leq 1:\\
\;\;\;\;\mathsf{fma}\left(e^{-x}, \left(1 + x\right) - -1, \frac{x}{e^{x}}\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 \cdot e^{x \cdot \varepsilon - x} - \frac{-1}{{\mathsf{E}\left(\right)}^{\left(\mathsf{fma}\left(x, \varepsilon, x\right)\right)}}}{2}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) < 1Initial program 52.8%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
if 1 < (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) Initial program 98.5%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6498.4
Applied rewrites98.4%
Taylor expanded in x around inf
lower-exp.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6498.4
Applied rewrites98.4%
Applied rewrites98.5%
Applied rewrites98.5%
Final simplification99.2%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ 1.0 (pow eps -1.0))))
(if (<=
(/
(-
(* t_0 (exp (* (+ -1.0 eps) x)))
(* (- (pow eps -1.0) 1.0) (exp (* (- -1.0 eps) x))))
2.0)
1.0)
(* (fma (exp (- x)) (- (+ 1.0 x) -1.0) (/ x (exp x))) 0.5)
(/ (- (* t_0 (exp (- (* x eps) x))) (/ -1.0 (exp (fma x eps x)))) 2.0))))
double code(double x, double eps) {
double t_0 = 1.0 + pow(eps, -1.0);
double tmp;
if ((((t_0 * exp(((-1.0 + eps) * x))) - ((pow(eps, -1.0) - 1.0) * exp(((-1.0 - eps) * x)))) / 2.0) <= 1.0) {
tmp = fma(exp(-x), ((1.0 + x) - -1.0), (x / exp(x))) * 0.5;
} else {
tmp = ((t_0 * exp(((x * eps) - x))) - (-1.0 / exp(fma(x, eps, x)))) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(1.0 + (eps ^ -1.0)) tmp = 0.0 if (Float64(Float64(Float64(t_0 * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(Float64((eps ^ -1.0) - 1.0) * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0) <= 1.0) tmp = Float64(fma(exp(Float64(-x)), Float64(Float64(1.0 + x) - -1.0), Float64(x / exp(x))) * 0.5); else tmp = Float64(Float64(Float64(t_0 * exp(Float64(Float64(x * eps) - x))) - Float64(-1.0 / exp(fma(x, eps, x)))) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(1.0 + N[Power[eps, -1.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[(t$95$0 * N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 1.0], N[(N[(N[Exp[(-x)], $MachinePrecision] * N[(N[(1.0 + x), $MachinePrecision] - -1.0), $MachinePrecision] + N[(x / N[Exp[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(t$95$0 * N[Exp[N[(N[(x * eps), $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(-1.0 / N[Exp[N[(x * eps + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + {\varepsilon}^{-1}\\
\mathbf{if}\;\frac{t\_0 \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - \left({\varepsilon}^{-1} - 1\right) \cdot e^{\left(-1 - \varepsilon\right) \cdot x}}{2} \leq 1:\\
\;\;\;\;\mathsf{fma}\left(e^{-x}, \left(1 + x\right) - -1, \frac{x}{e^{x}}\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 \cdot e^{x \cdot \varepsilon - x} - \frac{-1}{e^{\mathsf{fma}\left(x, \varepsilon, x\right)}}}{2}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) < 1Initial program 52.8%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
if 1 < (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) Initial program 98.5%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6498.4
Applied rewrites98.4%
Taylor expanded in x around inf
lower-exp.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6498.4
Applied rewrites98.4%
Final simplification99.2%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (pow eps -1.0) 1.0)) (t_1 (+ 1.0 (pow eps -1.0))))
(if (<=
(/
(- (* t_1 (exp (* (+ -1.0 eps) x))) (* t_0 (exp (* (- -1.0 eps) x))))
2.0)
20.0)
1.0
(/ (- (* t_1 (exp (- (* x eps) x))) t_0) 2.0))))
double code(double x, double eps) {
double t_0 = pow(eps, -1.0) - 1.0;
double t_1 = 1.0 + pow(eps, -1.0);
double tmp;
if ((((t_1 * exp(((-1.0 + eps) * x))) - (t_0 * exp(((-1.0 - eps) * x)))) / 2.0) <= 20.0) {
tmp = 1.0;
} else {
tmp = ((t_1 * exp(((x * eps) - x))) - t_0) / 2.0;
}
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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (eps ** (-1.0d0)) - 1.0d0
t_1 = 1.0d0 + (eps ** (-1.0d0))
if ((((t_1 * exp((((-1.0d0) + eps) * x))) - (t_0 * exp((((-1.0d0) - eps) * x)))) / 2.0d0) <= 20.0d0) then
tmp = 1.0d0
else
tmp = ((t_1 * exp(((x * eps) - x))) - t_0) / 2.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.pow(eps, -1.0) - 1.0;
double t_1 = 1.0 + Math.pow(eps, -1.0);
double tmp;
if ((((t_1 * Math.exp(((-1.0 + eps) * x))) - (t_0 * Math.exp(((-1.0 - eps) * x)))) / 2.0) <= 20.0) {
tmp = 1.0;
} else {
tmp = ((t_1 * Math.exp(((x * eps) - x))) - t_0) / 2.0;
}
return tmp;
}
def code(x, eps): t_0 = math.pow(eps, -1.0) - 1.0 t_1 = 1.0 + math.pow(eps, -1.0) tmp = 0 if (((t_1 * math.exp(((-1.0 + eps) * x))) - (t_0 * math.exp(((-1.0 - eps) * x)))) / 2.0) <= 20.0: tmp = 1.0 else: tmp = ((t_1 * math.exp(((x * eps) - x))) - t_0) / 2.0 return tmp
function code(x, eps) t_0 = Float64((eps ^ -1.0) - 1.0) t_1 = Float64(1.0 + (eps ^ -1.0)) tmp = 0.0 if (Float64(Float64(Float64(t_1 * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(t_0 * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0) <= 20.0) tmp = 1.0; else tmp = Float64(Float64(Float64(t_1 * exp(Float64(Float64(x * eps) - x))) - t_0) / 2.0); end return tmp end
function tmp_2 = code(x, eps) t_0 = (eps ^ -1.0) - 1.0; t_1 = 1.0 + (eps ^ -1.0); tmp = 0.0; if ((((t_1 * exp(((-1.0 + eps) * x))) - (t_0 * exp(((-1.0 - eps) * x)))) / 2.0) <= 20.0) tmp = 1.0; else tmp = ((t_1 * exp(((x * eps) - x))) - t_0) / 2.0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[Power[eps, -1.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[(t$95$1 * N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(t$95$0 * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 20.0], 1.0, N[(N[(N[(t$95$1 * N[Exp[N[(N[(x * eps), $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision] / 2.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\varepsilon}^{-1} - 1\\
t_1 := 1 + {\varepsilon}^{-1}\\
\mathbf{if}\;\frac{t\_1 \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - t\_0 \cdot e^{\left(-1 - \varepsilon\right) \cdot x}}{2} \leq 20:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_1 \cdot e^{x \cdot \varepsilon - x} - t\_0}{2}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) < 20Initial program 54.7%
Taylor expanded in x around 0
Applied rewrites70.1%
if 20 < (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) Initial program 98.4%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6498.4
Applied rewrites98.4%
Taylor expanded in x around inf
lower-exp.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6498.4
Applied rewrites98.4%
Applied rewrites98.4%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6453.6
Applied rewrites53.6%
Final simplification61.6%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (pow eps -1.0) 1.0)))
(if (<=
(/
(-
(* (+ 1.0 (pow eps -1.0)) (exp (* (+ -1.0 eps) x)))
(* t_0 (exp (* (- -1.0 eps) x))))
2.0)
2.0)
1.0
(/ (- (+ (pow eps -1.0) 1.0) (* t_0 (exp (- (fma x eps x))))) 2.0))))
double code(double x, double eps) {
double t_0 = pow(eps, -1.0) - 1.0;
double tmp;
if (((((1.0 + pow(eps, -1.0)) * exp(((-1.0 + eps) * x))) - (t_0 * exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0) {
tmp = 1.0;
} else {
tmp = ((pow(eps, -1.0) + 1.0) - (t_0 * exp(-fma(x, eps, x)))) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64((eps ^ -1.0) - 1.0) tmp = 0.0 if (Float64(Float64(Float64(Float64(1.0 + (eps ^ -1.0)) * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(t_0 * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0) <= 2.0) tmp = 1.0; else tmp = Float64(Float64(Float64((eps ^ -1.0) + 1.0) - Float64(t_0 * exp(Float64(-fma(x, eps, x))))) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]}, If[LessEqual[N[(N[(N[(N[(1.0 + N[Power[eps, -1.0], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(t$95$0 * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 2.0], 1.0, N[(N[(N[(N[Power[eps, -1.0], $MachinePrecision] + 1.0), $MachinePrecision] - N[(t$95$0 * N[Exp[(-N[(x * eps + x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\varepsilon}^{-1} - 1\\
\mathbf{if}\;\frac{\left(1 + {\varepsilon}^{-1}\right) \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - t\_0 \cdot e^{\left(-1 - \varepsilon\right) \cdot x}}{2} \leq 2:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{\left({\varepsilon}^{-1} + 1\right) - t\_0 \cdot e^{-\mathsf{fma}\left(x, \varepsilon, x\right)}}{2}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) < 2Initial program 54.3%
Taylor expanded in x around 0
Applied rewrites70.6%
if 2 < (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) Initial program 98.4%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6449.2
Applied rewrites49.2%
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-lft1-inN/A
*-commutativeN/A
lift-fma.f6449.2
Applied rewrites49.2%
Final simplification59.5%
(FPCore (x eps)
:precision binary64
(if (<=
(/
(-
(* (+ 1.0 (pow eps -1.0)) (exp (* (+ -1.0 eps) x)))
(* (- (pow eps -1.0) 1.0) (exp (* (- -1.0 eps) x))))
2.0)
2.0)
1.0
(/ (- (pow eps -1.0) (/ -1.0 (exp (fma x eps x)))) 2.0)))
double code(double x, double eps) {
double tmp;
if (((((1.0 + pow(eps, -1.0)) * exp(((-1.0 + eps) * x))) - ((pow(eps, -1.0) - 1.0) * exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0) {
tmp = 1.0;
} else {
tmp = (pow(eps, -1.0) - (-1.0 / exp(fma(x, eps, x)))) / 2.0;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(Float64(Float64(Float64(1.0 + (eps ^ -1.0)) * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(Float64((eps ^ -1.0) - 1.0) * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0) <= 2.0) tmp = 1.0; else tmp = Float64(Float64((eps ^ -1.0) - Float64(-1.0 / exp(fma(x, eps, x)))) / 2.0); end return tmp end
code[x_, eps_] := If[LessEqual[N[(N[(N[(N[(1.0 + N[Power[eps, -1.0], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 2.0], 1.0, N[(N[(N[Power[eps, -1.0], $MachinePrecision] - N[(-1.0 / N[Exp[N[(x * eps + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left(1 + {\varepsilon}^{-1}\right) \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - \left({\varepsilon}^{-1} - 1\right) \cdot e^{\left(-1 - \varepsilon\right) \cdot x}}{2} \leq 2:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{{\varepsilon}^{-1} - \frac{-1}{e^{\mathsf{fma}\left(x, \varepsilon, x\right)}}}{2}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) < 2Initial program 54.3%
Taylor expanded in x around 0
Applied rewrites70.6%
if 2 < (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) Initial program 98.4%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6498.4
Applied rewrites98.4%
Taylor expanded in eps around 0
lower-/.f64N/A
lower-exp.f64N/A
lower-neg.f6446.7
Applied rewrites46.7%
Taylor expanded in x around 0
Applied rewrites47.0%
Final simplification58.3%
(FPCore (x eps)
:precision binary64
(if (<=
(/
(-
(* (+ 1.0 (pow eps -1.0)) (exp (* (+ -1.0 eps) x)))
(* (- (pow eps -1.0) 1.0) (exp (* (- -1.0 eps) x))))
2.0)
2.0)
1.0
(/ (- (/ (+ 1.0 eps) eps) (/ -1.0 (exp (fma x eps x)))) 2.0)))
double code(double x, double eps) {
double tmp;
if (((((1.0 + pow(eps, -1.0)) * exp(((-1.0 + eps) * x))) - ((pow(eps, -1.0) - 1.0) * exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0) {
tmp = 1.0;
} else {
tmp = (((1.0 + eps) / eps) - (-1.0 / exp(fma(x, eps, x)))) / 2.0;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(Float64(Float64(Float64(1.0 + (eps ^ -1.0)) * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(Float64((eps ^ -1.0) - 1.0) * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0) <= 2.0) tmp = 1.0; else tmp = Float64(Float64(Float64(Float64(1.0 + eps) / eps) - Float64(-1.0 / exp(fma(x, eps, x)))) / 2.0); end return tmp end
code[x_, eps_] := If[LessEqual[N[(N[(N[(N[(1.0 + N[Power[eps, -1.0], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 2.0], 1.0, N[(N[(N[(N[(1.0 + eps), $MachinePrecision] / eps), $MachinePrecision] - N[(-1.0 / N[Exp[N[(x * eps + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left(1 + {\varepsilon}^{-1}\right) \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - \left({\varepsilon}^{-1} - 1\right) \cdot e^{\left(-1 - \varepsilon\right) \cdot x}}{2} \leq 2:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1 + \varepsilon}{\varepsilon} - \frac{-1}{e^{\mathsf{fma}\left(x, \varepsilon, x\right)}}}{2}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) < 2Initial program 54.3%
Taylor expanded in x around 0
Applied rewrites70.6%
if 2 < (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) Initial program 98.4%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6498.4
Applied rewrites98.4%
Taylor expanded in x around 0
*-inversesN/A
div-addN/A
+-commutativeN/A
lower-/.f64N/A
lower-+.f6447.7
Applied rewrites47.7%
Final simplification58.7%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (pow eps -1.0) 1.0)) (t_1 (+ 1.0 (pow eps -1.0))))
(if (<= eps -15000.0)
(/ (- (* t_1 (exp (- (* x eps) x))) t_0) 2.0)
(if (<= eps 2e-32)
(fma (* 0.5 x) (fma (+ 1.0 eps) t_0 (/ -1.0 eps)) 1.0)
(if (<= eps 2.95e+72)
(/ (- (+ (pow eps -1.0) 1.0) (* t_0 (exp (- (fma x eps x))))) 2.0)
(/
(+
(* t_1 (exp (* (+ -1.0 eps) x)))
(* (- (/ -1.0 eps) -1.0) (fma (- -1.0 eps) x 1.0)))
2.0))))))
double code(double x, double eps) {
double t_0 = pow(eps, -1.0) - 1.0;
double t_1 = 1.0 + pow(eps, -1.0);
double tmp;
if (eps <= -15000.0) {
tmp = ((t_1 * exp(((x * eps) - x))) - t_0) / 2.0;
} else if (eps <= 2e-32) {
tmp = fma((0.5 * x), fma((1.0 + eps), t_0, (-1.0 / eps)), 1.0);
} else if (eps <= 2.95e+72) {
tmp = ((pow(eps, -1.0) + 1.0) - (t_0 * exp(-fma(x, eps, x)))) / 2.0;
} else {
tmp = ((t_1 * exp(((-1.0 + eps) * x))) + (((-1.0 / eps) - -1.0) * fma((-1.0 - eps), x, 1.0))) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64((eps ^ -1.0) - 1.0) t_1 = Float64(1.0 + (eps ^ -1.0)) tmp = 0.0 if (eps <= -15000.0) tmp = Float64(Float64(Float64(t_1 * exp(Float64(Float64(x * eps) - x))) - t_0) / 2.0); elseif (eps <= 2e-32) tmp = fma(Float64(0.5 * x), fma(Float64(1.0 + eps), t_0, Float64(-1.0 / eps)), 1.0); elseif (eps <= 2.95e+72) tmp = Float64(Float64(Float64((eps ^ -1.0) + 1.0) - Float64(t_0 * exp(Float64(-fma(x, eps, x))))) / 2.0); else tmp = Float64(Float64(Float64(t_1 * exp(Float64(Float64(-1.0 + eps) * x))) + Float64(Float64(Float64(-1.0 / eps) - -1.0) * fma(Float64(-1.0 - eps), x, 1.0))) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[Power[eps, -1.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -15000.0], N[(N[(N[(t$95$1 * N[Exp[N[(N[(x * eps), $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[eps, 2e-32], N[(N[(0.5 * x), $MachinePrecision] * N[(N[(1.0 + eps), $MachinePrecision] * t$95$0 + N[(-1.0 / eps), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[eps, 2.95e+72], N[(N[(N[(N[Power[eps, -1.0], $MachinePrecision] + 1.0), $MachinePrecision] - N[(t$95$0 * N[Exp[(-N[(x * eps + x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(t$95$1 * N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(-1.0 / eps), $MachinePrecision] - -1.0), $MachinePrecision] * N[(N[(-1.0 - eps), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\varepsilon}^{-1} - 1\\
t_1 := 1 + {\varepsilon}^{-1}\\
\mathbf{if}\;\varepsilon \leq -15000:\\
\;\;\;\;\frac{t\_1 \cdot e^{x \cdot \varepsilon - x} - t\_0}{2}\\
\mathbf{elif}\;\varepsilon \leq 2 \cdot 10^{-32}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x, \mathsf{fma}\left(1 + \varepsilon, t\_0, \frac{-1}{\varepsilon}\right), 1\right)\\
\mathbf{elif}\;\varepsilon \leq 2.95 \cdot 10^{+72}:\\
\;\;\;\;\frac{\left({\varepsilon}^{-1} + 1\right) - t\_0 \cdot e^{-\mathsf{fma}\left(x, \varepsilon, x\right)}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_1 \cdot e^{\left(-1 + \varepsilon\right) \cdot x} + \left(\frac{-1}{\varepsilon} - -1\right) \cdot \mathsf{fma}\left(-1 - \varepsilon, x, 1\right)}{2}\\
\end{array}
\end{array}
if eps < -15000Initial program 100.0%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6499.9
Applied rewrites99.9%
Taylor expanded in x around inf
lower-exp.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6499.9
Applied rewrites99.9%
Applied rewrites99.9%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6464.7
Applied rewrites64.7%
if -15000 < eps < 2.00000000000000011e-32Initial program 39.2%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6437.3
Applied rewrites37.3%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites63.5%
Taylor expanded in eps around 0
Applied rewrites63.6%
if 2.00000000000000011e-32 < eps < 2.9500000000000001e72Initial program 95.2%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6473.5
Applied rewrites73.5%
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-lft1-inN/A
*-commutativeN/A
lift-fma.f6473.5
Applied rewrites73.5%
if 2.9500000000000001e72 < eps Initial program 99.8%
Taylor expanded in x around 0
mul-1-negN/A
+-commutativeN/A
distribute-rgt-neg-inN/A
mul-1-negN/A
*-commutativeN/A
lower-fma.f64N/A
distribute-lft-inN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6467.1
Applied rewrites67.1%
Final simplification65.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (pow eps -1.0) 1.0)))
(if (<= x -1100.0)
(/ (- (/ (exp (- x)) eps) t_0) 2.0)
(if (<= x 220.0)
(fma (* 0.5 x) (fma (+ 1.0 eps) t_0 (/ (- (* eps eps) 1.0) eps)) 1.0)
(/ (- (+ (pow eps -1.0) 1.0) t_0) 2.0)))))
double code(double x, double eps) {
double t_0 = pow(eps, -1.0) - 1.0;
double tmp;
if (x <= -1100.0) {
tmp = ((exp(-x) / eps) - t_0) / 2.0;
} else if (x <= 220.0) {
tmp = fma((0.5 * x), fma((1.0 + eps), t_0, (((eps * eps) - 1.0) / eps)), 1.0);
} else {
tmp = ((pow(eps, -1.0) + 1.0) - t_0) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64((eps ^ -1.0) - 1.0) tmp = 0.0 if (x <= -1100.0) tmp = Float64(Float64(Float64(exp(Float64(-x)) / eps) - t_0) / 2.0); elseif (x <= 220.0) tmp = fma(Float64(0.5 * x), fma(Float64(1.0 + eps), t_0, Float64(Float64(Float64(eps * eps) - 1.0) / eps)), 1.0); else tmp = Float64(Float64(Float64((eps ^ -1.0) + 1.0) - t_0) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]}, If[LessEqual[x, -1100.0], N[(N[(N[(N[Exp[(-x)], $MachinePrecision] / eps), $MachinePrecision] - t$95$0), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 220.0], N[(N[(0.5 * x), $MachinePrecision] * N[(N[(1.0 + eps), $MachinePrecision] * t$95$0 + N[(N[(N[(eps * eps), $MachinePrecision] - 1.0), $MachinePrecision] / eps), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(N[(N[Power[eps, -1.0], $MachinePrecision] + 1.0), $MachinePrecision] - t$95$0), $MachinePrecision] / 2.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\varepsilon}^{-1} - 1\\
\mathbf{if}\;x \leq -1100:\\
\;\;\;\;\frac{\frac{e^{-x}}{\varepsilon} - t\_0}{2}\\
\mathbf{elif}\;x \leq 220:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x, \mathsf{fma}\left(1 + \varepsilon, t\_0, \frac{\varepsilon \cdot \varepsilon - 1}{\varepsilon}\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left({\varepsilon}^{-1} + 1\right) - t\_0}{2}\\
\end{array}
\end{array}
if x < -1100Initial program 97.8%
Taylor expanded in eps around 0
lower-/.f64N/A
lower-exp.f64N/A
lower-neg.f6445.7
Applied rewrites45.7%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6445.7
Applied rewrites45.7%
if -1100 < x < 220Initial program 58.8%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6457.4
Applied rewrites57.4%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites62.9%
Applied rewrites70.7%
if 220 < x Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6432.7
Applied rewrites32.7%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6445.4
Applied rewrites45.4%
Final simplification59.2%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (pow eps -1.0) 1.0)))
(if (<= x 220.0)
(fma (* 0.5 x) (fma (+ 1.0 eps) t_0 (/ (- (* eps eps) 1.0) eps)) 1.0)
(/ (- (+ (pow eps -1.0) 1.0) t_0) 2.0))))
double code(double x, double eps) {
double t_0 = pow(eps, -1.0) - 1.0;
double tmp;
if (x <= 220.0) {
tmp = fma((0.5 * x), fma((1.0 + eps), t_0, (((eps * eps) - 1.0) / eps)), 1.0);
} else {
tmp = ((pow(eps, -1.0) + 1.0) - t_0) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64((eps ^ -1.0) - 1.0) tmp = 0.0 if (x <= 220.0) tmp = fma(Float64(0.5 * x), fma(Float64(1.0 + eps), t_0, Float64(Float64(Float64(eps * eps) - 1.0) / eps)), 1.0); else tmp = Float64(Float64(Float64((eps ^ -1.0) + 1.0) - t_0) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]}, If[LessEqual[x, 220.0], N[(N[(0.5 * x), $MachinePrecision] * N[(N[(1.0 + eps), $MachinePrecision] * t$95$0 + N[(N[(N[(eps * eps), $MachinePrecision] - 1.0), $MachinePrecision] / eps), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(N[(N[Power[eps, -1.0], $MachinePrecision] + 1.0), $MachinePrecision] - t$95$0), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\varepsilon}^{-1} - 1\\
\mathbf{if}\;x \leq 220:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x, \mathsf{fma}\left(1 + \varepsilon, t\_0, \frac{\varepsilon \cdot \varepsilon - 1}{\varepsilon}\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left({\varepsilon}^{-1} + 1\right) - t\_0}{2}\\
\end{array}
\end{array}
if x < 220Initial program 68.5%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6467.4
Applied rewrites67.4%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites48.1%
Applied rewrites60.5%
if 220 < x Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6432.7
Applied rewrites32.7%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6445.4
Applied rewrites45.4%
Final simplification56.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (pow eps -1.0) 1.0)))
(if (<= x 220000.0)
(fma (* 0.5 x) (fma (+ 1.0 eps) t_0 (/ -1.0 eps)) 1.0)
(/ (- (+ (pow eps -1.0) 1.0) t_0) 2.0))))
double code(double x, double eps) {
double t_0 = pow(eps, -1.0) - 1.0;
double tmp;
if (x <= 220000.0) {
tmp = fma((0.5 * x), fma((1.0 + eps), t_0, (-1.0 / eps)), 1.0);
} else {
tmp = ((pow(eps, -1.0) + 1.0) - t_0) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64((eps ^ -1.0) - 1.0) tmp = 0.0 if (x <= 220000.0) tmp = fma(Float64(0.5 * x), fma(Float64(1.0 + eps), t_0, Float64(-1.0 / eps)), 1.0); else tmp = Float64(Float64(Float64((eps ^ -1.0) + 1.0) - t_0) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]}, If[LessEqual[x, 220000.0], N[(N[(0.5 * x), $MachinePrecision] * N[(N[(1.0 + eps), $MachinePrecision] * t$95$0 + N[(-1.0 / eps), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(N[(N[Power[eps, -1.0], $MachinePrecision] + 1.0), $MachinePrecision] - t$95$0), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\varepsilon}^{-1} - 1\\
\mathbf{if}\;x \leq 220000:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x, \mathsf{fma}\left(1 + \varepsilon, t\_0, \frac{-1}{\varepsilon}\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left({\varepsilon}^{-1} + 1\right) - t\_0}{2}\\
\end{array}
\end{array}
if x < 2.2e5Initial program 68.8%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6467.8
Applied rewrites67.8%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites47.6%
Taylor expanded in eps around 0
Applied rewrites52.3%
if 2.2e5 < x Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6430.7
Applied rewrites30.7%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6446.6
Applied rewrites46.6%
Final simplification50.8%
(FPCore (x eps) :precision binary64 (if (<= x 220.0) 1.0 (/ (- (+ (pow eps -1.0) 1.0) (- (pow eps -1.0) 1.0)) 2.0)))
double code(double x, double eps) {
double tmp;
if (x <= 220.0) {
tmp = 1.0;
} else {
tmp = ((pow(eps, -1.0) + 1.0) - (pow(eps, -1.0) - 1.0)) / 2.0;
}
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 <= 220.0d0) then
tmp = 1.0d0
else
tmp = (((eps ** (-1.0d0)) + 1.0d0) - ((eps ** (-1.0d0)) - 1.0d0)) / 2.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= 220.0) {
tmp = 1.0;
} else {
tmp = ((Math.pow(eps, -1.0) + 1.0) - (Math.pow(eps, -1.0) - 1.0)) / 2.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 220.0: tmp = 1.0 else: tmp = ((math.pow(eps, -1.0) + 1.0) - (math.pow(eps, -1.0) - 1.0)) / 2.0 return tmp
function code(x, eps) tmp = 0.0 if (x <= 220.0) tmp = 1.0; else tmp = Float64(Float64(Float64((eps ^ -1.0) + 1.0) - Float64((eps ^ -1.0) - 1.0)) / 2.0); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 220.0) tmp = 1.0; else tmp = (((eps ^ -1.0) + 1.0) - ((eps ^ -1.0) - 1.0)) / 2.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, 220.0], 1.0, N[(N[(N[(N[Power[eps, -1.0], $MachinePrecision] + 1.0), $MachinePrecision] - N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 220:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{\left({\varepsilon}^{-1} + 1\right) - \left({\varepsilon}^{-1} - 1\right)}{2}\\
\end{array}
\end{array}
if x < 220Initial program 68.5%
Taylor expanded in x around 0
Applied rewrites48.0%
if 220 < x Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6432.7
Applied rewrites32.7%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6445.4
Applied rewrites45.4%
Final simplification47.3%
(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 77.2%
Taylor expanded in x around 0
Applied rewrites35.6%
herbie shell --seed 2024354
(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))