
(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 (+ 1.0 (/ 1.0 eps))))
(if (<=
(/
(-
(* t_0 (exp (* (+ -1.0 eps) x)))
(* (- (/ 1.0 eps) 1.0) (exp (* (- -1.0 eps) x))))
2.0)
2.0)
(/ (fma (+ 1.0 x) (exp (- x)) (/ (+ 1.0 x) (exp x))) 2.0)
(/ (- (* t_0 (exp (- (* eps x) x))) (* -1.0 (exp (- (* x eps))))) 2.0))))
double code(double x, double eps) {
double t_0 = 1.0 + (1.0 / eps);
double tmp;
if ((((t_0 * exp(((-1.0 + eps) * x))) - (((1.0 / eps) - 1.0) * exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0) {
tmp = fma((1.0 + x), exp(-x), ((1.0 + x) / exp(x))) / 2.0;
} else {
tmp = ((t_0 * exp(((eps * x) - x))) - (-1.0 * exp(-(x * eps)))) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(1.0 + Float64(1.0 / eps)) tmp = 0.0 if (Float64(Float64(Float64(t_0 * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(Float64(Float64(1.0 / eps) - 1.0) * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0) <= 2.0) tmp = Float64(fma(Float64(1.0 + x), exp(Float64(-x)), Float64(Float64(1.0 + x) / exp(x))) / 2.0); else tmp = Float64(Float64(Float64(t_0 * exp(Float64(Float64(eps * x) - x))) - Float64(-1.0 * exp(Float64(-Float64(x * eps))))) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(1.0 + N[(1.0 / eps), $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[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 2.0], N[(N[(N[(1.0 + x), $MachinePrecision] * N[Exp[(-x)], $MachinePrecision] + N[(N[(1.0 + x), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(t$95$0 * N[Exp[N[(N[(eps * x), $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(-1.0 * N[Exp[(-N[(x * eps), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{1}{\varepsilon}\\
\mathbf{if}\;\frac{t\_0 \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{\left(-1 - \varepsilon\right) \cdot x}}{2} \leq 2:\\
\;\;\;\;\frac{\mathsf{fma}\left(1 + x, e^{-x}, \frac{1 + x}{e^{x}}\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 \cdot e^{\varepsilon \cdot x - x} - -1 \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)) < 2Initial program 48.2%
Taylor expanded in eps around 0
distribute-lft-outN/A
fp-cancel-sub-sign-invN/A
distribute-rgt1-inN/A
distribute-lft-neg-inN/A
distribute-lft-outN/A
distribute-neg-inN/A
exp-negN/A
associate-*r/N/A
metadata-evalN/A
distribute-frac-negN/A
metadata-evalN/A
exp-negN/A
distribute-lft-neg-outN/A
metadata-evalN/A
*-lft-identityN/A
Applied rewrites100.0%
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 99.8%
Taylor expanded in eps around inf
Applied rewrites99.8%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in eps around 0
lower--.f64N/A
lower-*.f6499.8
Applied rewrites99.8%
Final simplification99.9%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (/ 1.0 eps) 1.0)) (t_1 (+ 1.0 (/ 1.0 eps))))
(if (<=
(/
(- (* t_1 (exp (* (+ -1.0 eps) x))) (* t_0 (exp (* (- -1.0 eps) x))))
2.0)
100.0)
(/ (fma (+ 1.0 x) (exp (- x)) (/ (+ 1.0 x) (exp x))) 2.0)
(/ (- (* t_1 (exp (- (* x eps) x))) t_0) 2.0))))
double code(double x, double eps) {
double t_0 = (1.0 / eps) - 1.0;
double t_1 = 1.0 + (1.0 / eps);
double tmp;
if ((((t_1 * exp(((-1.0 + eps) * x))) - (t_0 * exp(((-1.0 - eps) * x)))) / 2.0) <= 100.0) {
tmp = fma((1.0 + x), exp(-x), ((1.0 + x) / exp(x))) / 2.0;
} else {
tmp = ((t_1 * exp(((x * eps) - x))) - t_0) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(1.0 / eps) - 1.0) t_1 = Float64(1.0 + Float64(1.0 / eps)) 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) <= 100.0) tmp = Float64(fma(Float64(1.0 + x), exp(Float64(-x)), Float64(Float64(1.0 + x) / exp(x))) / 2.0); else tmp = Float64(Float64(Float64(t_1 * exp(Float64(Float64(x * eps) - x))) - t_0) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(1.0 / eps), $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], 100.0], N[(N[(N[(1.0 + x), $MachinePrecision] * N[Exp[(-x)], $MachinePrecision] + N[(N[(1.0 + x), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 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 := \frac{1}{\varepsilon} - 1\\
t_1 := 1 + \frac{1}{\varepsilon}\\
\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 100:\\
\;\;\;\;\frac{\mathsf{fma}\left(1 + x, e^{-x}, \frac{1 + x}{e^{x}}\right)}{2}\\
\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)) < 100Initial program 48.5%
Taylor expanded in eps around 0
distribute-lft-outN/A
fp-cancel-sub-sign-invN/A
distribute-rgt1-inN/A
distribute-lft-neg-inN/A
distribute-lft-outN/A
distribute-neg-inN/A
exp-negN/A
associate-*r/N/A
metadata-evalN/A
distribute-frac-negN/A
metadata-evalN/A
exp-negN/A
distribute-lft-neg-outN/A
metadata-evalN/A
*-lft-identityN/A
Applied rewrites99.5%
if 100 < (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) Initial program 99.8%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6456.9
Applied rewrites56.9%
Taylor expanded in x around inf
lower-exp.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6456.9
Applied rewrites56.9%
Final simplification83.2%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (/ 1.0 eps) 1.0)) (t_1 (+ 1.0 (/ 1.0 eps))) (t_2 (exp (- x))))
(if (<=
(/
(- (* t_1 (exp (* (+ -1.0 eps) x))) (* t_0 (exp (* (- -1.0 eps) x))))
2.0)
100.0)
(* (fma t_2 (- (+ 1.0 x) -1.0) (* t_2 x)) 0.5)
(/ (- (* t_1 (exp (- (* x eps) x))) t_0) 2.0))))
double code(double x, double eps) {
double t_0 = (1.0 / eps) - 1.0;
double t_1 = 1.0 + (1.0 / eps);
double t_2 = exp(-x);
double tmp;
if ((((t_1 * exp(((-1.0 + eps) * x))) - (t_0 * exp(((-1.0 - eps) * x)))) / 2.0) <= 100.0) {
tmp = fma(t_2, ((1.0 + x) - -1.0), (t_2 * x)) * 0.5;
} else {
tmp = ((t_1 * exp(((x * eps) - x))) - t_0) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(1.0 / eps) - 1.0) t_1 = Float64(1.0 + Float64(1.0 / eps)) t_2 = exp(Float64(-x)) 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) <= 100.0) tmp = Float64(fma(t_2, Float64(Float64(1.0 + x) - -1.0), Float64(t_2 * x)) * 0.5); else tmp = Float64(Float64(Float64(t_1 * exp(Float64(Float64(x * eps) - x))) - t_0) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Exp[(-x)], $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], 100.0], N[(N[(t$95$2 * N[(N[(1.0 + x), $MachinePrecision] - -1.0), $MachinePrecision] + N[(t$95$2 * x), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], 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 := \frac{1}{\varepsilon} - 1\\
t_1 := 1 + \frac{1}{\varepsilon}\\
t_2 := e^{-x}\\
\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 100:\\
\;\;\;\;\mathsf{fma}\left(t\_2, \left(1 + x\right) - -1, t\_2 \cdot x\right) \cdot 0.5\\
\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)) < 100Initial program 48.5%
Taylor expanded in eps around inf
Applied rewrites45.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.4%
if 100 < (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) Initial program 99.8%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6456.9
Applied rewrites56.9%
Taylor expanded in x around inf
lower-exp.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6456.9
Applied rewrites56.9%
Final simplification83.2%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (/ 1.0 eps) 1.0)) (t_1 (+ 1.0 (/ 1.0 eps))))
(if (<=
(/
(- (* t_1 (exp (* (+ -1.0 eps) x))) (* t_0 (exp (* (- -1.0 eps) x))))
2.0)
100.0)
(* (* (+ (+ x 2.0) x) (exp (- x))) 0.5)
(/ (- (* t_1 (exp (- (* x eps) x))) t_0) 2.0))))
double code(double x, double eps) {
double t_0 = (1.0 / eps) - 1.0;
double t_1 = 1.0 + (1.0 / eps);
double tmp;
if ((((t_1 * exp(((-1.0 + eps) * x))) - (t_0 * exp(((-1.0 - eps) * x)))) / 2.0) <= 100.0) {
tmp = (((x + 2.0) + x) * exp(-x)) * 0.5;
} 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 = (1.0d0 / eps) - 1.0d0
t_1 = 1.0d0 + (1.0d0 / eps)
if ((((t_1 * exp((((-1.0d0) + eps) * x))) - (t_0 * exp((((-1.0d0) - eps) * x)))) / 2.0d0) <= 100.0d0) then
tmp = (((x + 2.0d0) + x) * exp(-x)) * 0.5d0
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 = (1.0 / eps) - 1.0;
double t_1 = 1.0 + (1.0 / eps);
double tmp;
if ((((t_1 * Math.exp(((-1.0 + eps) * x))) - (t_0 * Math.exp(((-1.0 - eps) * x)))) / 2.0) <= 100.0) {
tmp = (((x + 2.0) + x) * Math.exp(-x)) * 0.5;
} else {
tmp = ((t_1 * Math.exp(((x * eps) - x))) - t_0) / 2.0;
}
return tmp;
}
def code(x, eps): t_0 = (1.0 / eps) - 1.0 t_1 = 1.0 + (1.0 / eps) tmp = 0 if (((t_1 * math.exp(((-1.0 + eps) * x))) - (t_0 * math.exp(((-1.0 - eps) * x)))) / 2.0) <= 100.0: tmp = (((x + 2.0) + x) * math.exp(-x)) * 0.5 else: tmp = ((t_1 * math.exp(((x * eps) - x))) - t_0) / 2.0 return tmp
function code(x, eps) t_0 = Float64(Float64(1.0 / eps) - 1.0) t_1 = Float64(1.0 + Float64(1.0 / eps)) 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) <= 100.0) tmp = Float64(Float64(Float64(Float64(x + 2.0) + x) * exp(Float64(-x))) * 0.5); 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 = (1.0 / eps) - 1.0; t_1 = 1.0 + (1.0 / eps); tmp = 0.0; if ((((t_1 * exp(((-1.0 + eps) * x))) - (t_0 * exp(((-1.0 - eps) * x)))) / 2.0) <= 100.0) tmp = (((x + 2.0) + x) * exp(-x)) * 0.5; 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[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(1.0 / eps), $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], 100.0], N[(N[(N[(N[(x + 2.0), $MachinePrecision] + x), $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], 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 := \frac{1}{\varepsilon} - 1\\
t_1 := 1 + \frac{1}{\varepsilon}\\
\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 100:\\
\;\;\;\;\left(\left(\left(x + 2\right) + x\right) \cdot e^{-x}\right) \cdot 0.5\\
\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)) < 100Initial program 48.5%
Taylor expanded in eps around inf
Applied rewrites45.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.4%
Applied rewrites99.4%
if 100 < (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) Initial program 99.8%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6456.9
Applied rewrites56.9%
Taylor expanded in x around inf
lower-exp.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6456.9
Applied rewrites56.9%
Final simplification83.2%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (exp (* (- -1.0 eps) x))))
(if (<=
(/
(-
(* (+ 1.0 (/ 1.0 eps)) (exp (* (+ -1.0 eps) x)))
(* (- (/ 1.0 eps) 1.0) t_0))
2.0)
2.0)
(* (* (+ (+ x 2.0) x) (exp (- x))) 0.5)
(/ (- (- (/ 1.0 eps) -1.0) (* -1.0 t_0)) 2.0))))
double code(double x, double eps) {
double t_0 = exp(((-1.0 - eps) * x));
double tmp;
if (((((1.0 + (1.0 / eps)) * exp(((-1.0 + eps) * x))) - (((1.0 / eps) - 1.0) * t_0)) / 2.0) <= 2.0) {
tmp = (((x + 2.0) + x) * exp(-x)) * 0.5;
} else {
tmp = (((1.0 / eps) - -1.0) - (-1.0 * 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) :: tmp
t_0 = exp((((-1.0d0) - eps) * x))
if (((((1.0d0 + (1.0d0 / eps)) * exp((((-1.0d0) + eps) * x))) - (((1.0d0 / eps) - 1.0d0) * t_0)) / 2.0d0) <= 2.0d0) then
tmp = (((x + 2.0d0) + x) * exp(-x)) * 0.5d0
else
tmp = (((1.0d0 / eps) - (-1.0d0)) - ((-1.0d0) * t_0)) / 2.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.exp(((-1.0 - eps) * x));
double tmp;
if (((((1.0 + (1.0 / eps)) * Math.exp(((-1.0 + eps) * x))) - (((1.0 / eps) - 1.0) * t_0)) / 2.0) <= 2.0) {
tmp = (((x + 2.0) + x) * Math.exp(-x)) * 0.5;
} else {
tmp = (((1.0 / eps) - -1.0) - (-1.0 * t_0)) / 2.0;
}
return tmp;
}
def code(x, eps): t_0 = math.exp(((-1.0 - eps) * x)) tmp = 0 if ((((1.0 + (1.0 / eps)) * math.exp(((-1.0 + eps) * x))) - (((1.0 / eps) - 1.0) * t_0)) / 2.0) <= 2.0: tmp = (((x + 2.0) + x) * math.exp(-x)) * 0.5 else: tmp = (((1.0 / eps) - -1.0) - (-1.0 * t_0)) / 2.0 return tmp
function code(x, eps) t_0 = exp(Float64(Float64(-1.0 - eps) * x)) tmp = 0.0 if (Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(Float64(Float64(1.0 / eps) - 1.0) * t_0)) / 2.0) <= 2.0) tmp = Float64(Float64(Float64(Float64(x + 2.0) + x) * exp(Float64(-x))) * 0.5); else tmp = Float64(Float64(Float64(Float64(1.0 / eps) - -1.0) - Float64(-1.0 * t_0)) / 2.0); end return tmp end
function tmp_2 = code(x, eps) t_0 = exp(((-1.0 - eps) * x)); tmp = 0.0; if (((((1.0 + (1.0 / eps)) * exp(((-1.0 + eps) * x))) - (((1.0 / eps) - 1.0) * t_0)) / 2.0) <= 2.0) tmp = (((x + 2.0) + x) * exp(-x)) * 0.5; else tmp = (((1.0 / eps) - -1.0) - (-1.0 * t_0)) / 2.0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[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] * t$95$0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 2.0], N[(N[(N[(N[(x + 2.0), $MachinePrecision] + x), $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(N[(1.0 / eps), $MachinePrecision] - -1.0), $MachinePrecision] - N[(-1.0 * t$95$0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\left(-1 - \varepsilon\right) \cdot x}\\
\mathbf{if}\;\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot t\_0}{2} \leq 2:\\
\;\;\;\;\left(\left(\left(x + 2\right) + x\right) \cdot e^{-x}\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\frac{1}{\varepsilon} - -1\right) - -1 \cdot 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)) < 2Initial program 48.2%
Taylor expanded in eps around inf
Applied rewrites44.6%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Applied rewrites100.0%
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 99.8%
Taylor expanded in eps around inf
Applied rewrites99.8%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6445.5
Applied rewrites45.5%
Final simplification78.9%
(FPCore (x eps)
:precision binary64
(if (<=
(/
(-
(* (+ 1.0 (/ 1.0 eps)) (exp (* (+ -1.0 eps) x)))
(* (- (/ 1.0 eps) 1.0) (exp (* (- -1.0 eps) x))))
2.0)
2.0)
(* (* (+ (+ x 2.0) x) (exp (- x))) 0.5)
(/ (- (- (/ 1.0 eps) -1.0) (* -1.0 (exp (- (* eps x))))) 2.0)))
double code(double x, double eps) {
double tmp;
if (((((1.0 + (1.0 / eps)) * exp(((-1.0 + eps) * x))) - (((1.0 / eps) - 1.0) * exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0) {
tmp = (((x + 2.0) + x) * exp(-x)) * 0.5;
} else {
tmp = (((1.0 / eps) - -1.0) - (-1.0 * exp(-(eps * x)))) / 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 (((((1.0d0 + (1.0d0 / eps)) * exp((((-1.0d0) + eps) * x))) - (((1.0d0 / eps) - 1.0d0) * exp((((-1.0d0) - eps) * x)))) / 2.0d0) <= 2.0d0) then
tmp = (((x + 2.0d0) + x) * exp(-x)) * 0.5d0
else
tmp = (((1.0d0 / eps) - (-1.0d0)) - ((-1.0d0) * exp(-(eps * x)))) / 2.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (((((1.0 + (1.0 / eps)) * Math.exp(((-1.0 + eps) * x))) - (((1.0 / eps) - 1.0) * Math.exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0) {
tmp = (((x + 2.0) + x) * Math.exp(-x)) * 0.5;
} else {
tmp = (((1.0 / eps) - -1.0) - (-1.0 * Math.exp(-(eps * x)))) / 2.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if ((((1.0 + (1.0 / eps)) * math.exp(((-1.0 + eps) * x))) - (((1.0 / eps) - 1.0) * math.exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0: tmp = (((x + 2.0) + x) * math.exp(-x)) * 0.5 else: tmp = (((1.0 / eps) - -1.0) - (-1.0 * math.exp(-(eps * x)))) / 2.0 return tmp
function code(x, eps) tmp = 0.0 if (Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(Float64(Float64(1.0 / eps) - 1.0) * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0) <= 2.0) tmp = Float64(Float64(Float64(Float64(x + 2.0) + x) * exp(Float64(-x))) * 0.5); else tmp = Float64(Float64(Float64(Float64(1.0 / eps) - -1.0) - Float64(-1.0 * exp(Float64(-Float64(eps * x))))) / 2.0); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (((((1.0 + (1.0 / eps)) * exp(((-1.0 + eps) * x))) - (((1.0 / eps) - 1.0) * exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0) tmp = (((x + 2.0) + x) * exp(-x)) * 0.5; else tmp = (((1.0 / eps) - -1.0) - (-1.0 * exp(-(eps * x)))) / 2.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[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], 2.0], N[(N[(N[(N[(x + 2.0), $MachinePrecision] + x), $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(N[(1.0 / eps), $MachinePrecision] - -1.0), $MachinePrecision] - N[(-1.0 * N[Exp[(-N[(eps * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\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} \leq 2:\\
\;\;\;\;\left(\left(\left(x + 2\right) + x\right) \cdot e^{-x}\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\frac{1}{\varepsilon} - -1\right) - -1 \cdot e^{-\varepsilon \cdot x}}{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 48.2%
Taylor expanded in eps around inf
Applied rewrites44.6%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Applied rewrites100.0%
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 99.8%
Taylor expanded in eps around inf
Applied rewrites99.8%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6445.5
Applied rewrites45.5%
Taylor expanded in eps around inf
lower-*.f6445.5
Applied rewrites45.5%
Final simplification78.9%
(FPCore (x eps)
:precision binary64
(if (<=
(/
(-
(* (+ 1.0 (/ 1.0 eps)) (exp (* (+ -1.0 eps) x)))
(* (- (/ 1.0 eps) 1.0) (exp (* (- -1.0 eps) x))))
2.0)
2e+275)
(* (* (+ (+ x 2.0) x) (exp (- x))) 0.5)
(/
(-
(- (/ 1.0 eps) -1.0)
(/ (fma (- (* (fma -0.16666666666666666 x 0.5) x) 1.0) x 1.0) eps))
2.0)))
double code(double x, double eps) {
double tmp;
if (((((1.0 + (1.0 / eps)) * exp(((-1.0 + eps) * x))) - (((1.0 / eps) - 1.0) * exp(((-1.0 - eps) * x)))) / 2.0) <= 2e+275) {
tmp = (((x + 2.0) + x) * exp(-x)) * 0.5;
} else {
tmp = (((1.0 / eps) - -1.0) - (fma(((fma(-0.16666666666666666, x, 0.5) * x) - 1.0), x, 1.0) / eps)) / 2.0;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(Float64(Float64(1.0 / eps) - 1.0) * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0) <= 2e+275) tmp = Float64(Float64(Float64(Float64(x + 2.0) + x) * exp(Float64(-x))) * 0.5); else tmp = Float64(Float64(Float64(Float64(1.0 / eps) - -1.0) - Float64(fma(Float64(Float64(fma(-0.16666666666666666, x, 0.5) * x) - 1.0), x, 1.0) / eps)) / 2.0); end return tmp end
code[x_, eps_] := If[LessEqual[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], 2e+275], N[(N[(N[(N[(x + 2.0), $MachinePrecision] + x), $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(N[(1.0 / eps), $MachinePrecision] - -1.0), $MachinePrecision] - N[(N[(N[(N[(N[(-0.16666666666666666 * x + 0.5), $MachinePrecision] * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] / eps), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\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} \leq 2 \cdot 10^{+275}:\\
\;\;\;\;\left(\left(\left(x + 2\right) + x\right) \cdot e^{-x}\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\frac{1}{\varepsilon} - -1\right) - \frac{\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, x, 0.5\right) \cdot x - 1, x, 1\right)}{\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)) < 1.99999999999999992e275Initial program 49.3%
Taylor expanded in eps around inf
Applied rewrites45.9%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites97.7%
Applied rewrites97.7%
if 1.99999999999999992e275 < (/.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 100.0%
Taylor expanded in eps around inf
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6446.0
Applied rewrites46.0%
Taylor expanded in eps around 0
lower-/.f64N/A
lower-exp.f64N/A
lower-neg.f6423.0
Applied rewrites23.0%
Taylor expanded in x around 0
Applied rewrites30.9%
Final simplification72.9%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (/ 1.0 eps) -1.0)))
(if (<= x -3.2e+117)
(/
(-
t_0
(/ (fma (- (* (fma -0.16666666666666666 x 0.5) x) 1.0) x 1.0) eps))
2.0)
(if (<= x 2.7)
(fma (* 0.5 x) (fma (- eps 1.0) t_0 (/ (- 1.0 (* eps eps)) eps)) 1.0)
(/ x (exp x))))))
double code(double x, double eps) {
double t_0 = (1.0 / eps) - -1.0;
double tmp;
if (x <= -3.2e+117) {
tmp = (t_0 - (fma(((fma(-0.16666666666666666, x, 0.5) * x) - 1.0), x, 1.0) / eps)) / 2.0;
} else if (x <= 2.7) {
tmp = fma((0.5 * x), fma((eps - 1.0), t_0, ((1.0 - (eps * eps)) / eps)), 1.0);
} else {
tmp = x / exp(x);
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(1.0 / eps) - -1.0) tmp = 0.0 if (x <= -3.2e+117) tmp = Float64(Float64(t_0 - Float64(fma(Float64(Float64(fma(-0.16666666666666666, x, 0.5) * x) - 1.0), x, 1.0) / eps)) / 2.0); elseif (x <= 2.7) tmp = fma(Float64(0.5 * x), fma(Float64(eps - 1.0), t_0, Float64(Float64(1.0 - Float64(eps * eps)) / eps)), 1.0); else tmp = Float64(x / exp(x)); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(1.0 / eps), $MachinePrecision] - -1.0), $MachinePrecision]}, If[LessEqual[x, -3.2e+117], N[(N[(t$95$0 - N[(N[(N[(N[(N[(-0.16666666666666666 * x + 0.5), $MachinePrecision] * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] / eps), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 2.7], N[(N[(0.5 * x), $MachinePrecision] * N[(N[(eps - 1.0), $MachinePrecision] * t$95$0 + N[(N[(1.0 - N[(eps * eps), $MachinePrecision]), $MachinePrecision] / eps), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], N[(x / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\varepsilon} - -1\\
\mathbf{if}\;x \leq -3.2 \cdot 10^{+117}:\\
\;\;\;\;\frac{t\_0 - \frac{\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, x, 0.5\right) \cdot x - 1, x, 1\right)}{\varepsilon}}{2}\\
\mathbf{elif}\;x \leq 2.7:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x, \mathsf{fma}\left(\varepsilon - 1, t\_0, \frac{1 - \varepsilon \cdot \varepsilon}{\varepsilon}\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{e^{x}}\\
\end{array}
\end{array}
if x < -3.20000000000000005e117Initial program 100.0%
Taylor expanded in eps around inf
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6438.4
Applied rewrites38.4%
Taylor expanded in eps around 0
lower-/.f64N/A
lower-exp.f64N/A
lower-neg.f6463.6
Applied rewrites63.6%
Taylor expanded in x around 0
Applied rewrites63.6%
if -3.20000000000000005e117 < x < 2.7000000000000002Initial program 49.3%
Taylor expanded in eps around inf
Applied rewrites45.8%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites74.4%
Taylor expanded in eps around 0
Applied rewrites76.5%
if 2.7000000000000002 < x Initial program 98.7%
Taylor expanded in eps around inf
Applied rewrites98.7%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites54.1%
Applied rewrites54.1%
Taylor expanded in x around inf
Applied rewrites53.0%
Final simplification68.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (/ 1.0 eps) -1.0)))
(if (<= x -3.2e+117)
(/
(-
t_0
(/ (fma (- (* (fma -0.16666666666666666 x 0.5) x) 1.0) x 1.0) eps))
2.0)
(if (<= x 2650000000000.0)
(fma (* 0.5 x) (fma (- eps 1.0) t_0 (/ (- 1.0 (* eps eps)) eps)) 1.0)
(/ (- t_0 (- (/ 1.0 eps) 1.0)) 2.0)))))
double code(double x, double eps) {
double t_0 = (1.0 / eps) - -1.0;
double tmp;
if (x <= -3.2e+117) {
tmp = (t_0 - (fma(((fma(-0.16666666666666666, x, 0.5) * x) - 1.0), x, 1.0) / eps)) / 2.0;
} else if (x <= 2650000000000.0) {
tmp = fma((0.5 * x), fma((eps - 1.0), t_0, ((1.0 - (eps * eps)) / eps)), 1.0);
} else {
tmp = (t_0 - ((1.0 / eps) - 1.0)) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(1.0 / eps) - -1.0) tmp = 0.0 if (x <= -3.2e+117) tmp = Float64(Float64(t_0 - Float64(fma(Float64(Float64(fma(-0.16666666666666666, x, 0.5) * x) - 1.0), x, 1.0) / eps)) / 2.0); elseif (x <= 2650000000000.0) tmp = fma(Float64(0.5 * x), fma(Float64(eps - 1.0), t_0, Float64(Float64(1.0 - Float64(eps * eps)) / eps)), 1.0); else tmp = Float64(Float64(t_0 - Float64(Float64(1.0 / eps) - 1.0)) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(1.0 / eps), $MachinePrecision] - -1.0), $MachinePrecision]}, If[LessEqual[x, -3.2e+117], N[(N[(t$95$0 - N[(N[(N[(N[(N[(-0.16666666666666666 * x + 0.5), $MachinePrecision] * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] / eps), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 2650000000000.0], N[(N[(0.5 * x), $MachinePrecision] * N[(N[(eps - 1.0), $MachinePrecision] * t$95$0 + N[(N[(1.0 - N[(eps * eps), $MachinePrecision]), $MachinePrecision] / eps), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(t$95$0 - N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\varepsilon} - -1\\
\mathbf{if}\;x \leq -3.2 \cdot 10^{+117}:\\
\;\;\;\;\frac{t\_0 - \frac{\mathsf{fma}\left(\mathsf{fma}\left(-0.16666666666666666, x, 0.5\right) \cdot x - 1, x, 1\right)}{\varepsilon}}{2}\\
\mathbf{elif}\;x \leq 2650000000000:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x, \mathsf{fma}\left(\varepsilon - 1, t\_0, \frac{1 - \varepsilon \cdot \varepsilon}{\varepsilon}\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - \left(\frac{1}{\varepsilon} - 1\right)}{2}\\
\end{array}
\end{array}
if x < -3.20000000000000005e117Initial program 100.0%
Taylor expanded in eps around inf
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6438.4
Applied rewrites38.4%
Taylor expanded in eps around 0
lower-/.f64N/A
lower-exp.f64N/A
lower-neg.f6463.6
Applied rewrites63.6%
Taylor expanded in x around 0
Applied rewrites63.6%
if -3.20000000000000005e117 < x < 2.65e12Initial program 50.2%
Taylor expanded in eps around inf
Applied rewrites46.9%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites72.3%
Taylor expanded in eps around 0
Applied rewrites74.9%
if 2.65e12 < x Initial program 100.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6426.1
Applied rewrites26.1%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6452.9
Applied rewrites52.9%
Final simplification68.0%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (/ 1.0 eps) -1.0)))
(if (<= x -7.8e+162)
(/ (- t_0 (/ (fma (- (* 0.5 x) 1.0) x 1.0) eps)) 2.0)
(if (<= x 2650000000000.0)
(fma (* 0.5 x) (fma (- eps 1.0) t_0 (/ (- 1.0 (* eps eps)) eps)) 1.0)
(/ (- t_0 (- (/ 1.0 eps) 1.0)) 2.0)))))
double code(double x, double eps) {
double t_0 = (1.0 / eps) - -1.0;
double tmp;
if (x <= -7.8e+162) {
tmp = (t_0 - (fma(((0.5 * x) - 1.0), x, 1.0) / eps)) / 2.0;
} else if (x <= 2650000000000.0) {
tmp = fma((0.5 * x), fma((eps - 1.0), t_0, ((1.0 - (eps * eps)) / eps)), 1.0);
} else {
tmp = (t_0 - ((1.0 / eps) - 1.0)) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(1.0 / eps) - -1.0) tmp = 0.0 if (x <= -7.8e+162) tmp = Float64(Float64(t_0 - Float64(fma(Float64(Float64(0.5 * x) - 1.0), x, 1.0) / eps)) / 2.0); elseif (x <= 2650000000000.0) tmp = fma(Float64(0.5 * x), fma(Float64(eps - 1.0), t_0, Float64(Float64(1.0 - Float64(eps * eps)) / eps)), 1.0); else tmp = Float64(Float64(t_0 - Float64(Float64(1.0 / eps) - 1.0)) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(1.0 / eps), $MachinePrecision] - -1.0), $MachinePrecision]}, If[LessEqual[x, -7.8e+162], N[(N[(t$95$0 - N[(N[(N[(N[(0.5 * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] / eps), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 2650000000000.0], N[(N[(0.5 * x), $MachinePrecision] * N[(N[(eps - 1.0), $MachinePrecision] * t$95$0 + N[(N[(1.0 - N[(eps * eps), $MachinePrecision]), $MachinePrecision] / eps), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(t$95$0 - N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\varepsilon} - -1\\
\mathbf{if}\;x \leq -7.8 \cdot 10^{+162}:\\
\;\;\;\;\frac{t\_0 - \frac{\mathsf{fma}\left(0.5 \cdot x - 1, x, 1\right)}{\varepsilon}}{2}\\
\mathbf{elif}\;x \leq 2650000000000:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x, \mathsf{fma}\left(\varepsilon - 1, t\_0, \frac{1 - \varepsilon \cdot \varepsilon}{\varepsilon}\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - \left(\frac{1}{\varepsilon} - 1\right)}{2}\\
\end{array}
\end{array}
if x < -7.80000000000000079e162Initial program 100.0%
Taylor expanded in eps around inf
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6438.8
Applied rewrites38.8%
Taylor expanded in eps around 0
lower-/.f64N/A
lower-exp.f64N/A
lower-neg.f6463.2
Applied rewrites63.2%
Taylor expanded in x around 0
Applied rewrites63.2%
if -7.80000000000000079e162 < x < 2.65e12Initial program 51.1%
Taylor expanded in eps around inf
Applied rewrites47.8%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites71.0%
Taylor expanded in eps around 0
Applied rewrites74.2%
if 2.65e12 < x Initial program 100.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6426.1
Applied rewrites26.1%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6452.9
Applied rewrites52.9%
Final simplification67.6%
(FPCore (x eps)
:precision binary64
(if (<= x -8e-18)
(/ (- (/ 1.0 eps) (* -1.0 (fma (- -1.0 eps) x 1.0))) 2.0)
(if (<= x 20000.0)
(fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0)
(/ (- (- (/ 1.0 eps) -1.0) (- (/ 1.0 eps) 1.0)) 2.0))))
double code(double x, double eps) {
double tmp;
if (x <= -8e-18) {
tmp = ((1.0 / eps) - (-1.0 * fma((-1.0 - eps), x, 1.0))) / 2.0;
} else if (x <= 20000.0) {
tmp = fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
} else {
tmp = (((1.0 / eps) - -1.0) - ((1.0 / eps) - 1.0)) / 2.0;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -8e-18) tmp = Float64(Float64(Float64(1.0 / eps) - Float64(-1.0 * fma(Float64(-1.0 - eps), x, 1.0))) / 2.0); elseif (x <= 20000.0) tmp = fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0); else tmp = Float64(Float64(Float64(Float64(1.0 / eps) - -1.0) - Float64(Float64(1.0 / eps) - 1.0)) / 2.0); end return tmp end
code[x_, eps_] := If[LessEqual[x, -8e-18], N[(N[(N[(1.0 / eps), $MachinePrecision] - N[(-1.0 * N[(N[(-1.0 - eps), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 20000.0], N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(N[(N[(1.0 / eps), $MachinePrecision] - -1.0), $MachinePrecision] - N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8 \cdot 10^{-18}:\\
\;\;\;\;\frac{\frac{1}{\varepsilon} - -1 \cdot \mathsf{fma}\left(-1 - \varepsilon, x, 1\right)}{2}\\
\mathbf{elif}\;x \leq 20000:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\frac{1}{\varepsilon} - -1\right) - \left(\frac{1}{\varepsilon} - 1\right)}{2}\\
\end{array}
\end{array}
if x < -8.0000000000000006e-18Initial program 100.0%
Taylor expanded in eps around inf
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6447.6
Applied rewrites47.6%
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--.f6423.2
Applied rewrites23.2%
Taylor expanded in eps around 0
Applied rewrites23.2%
if -8.0000000000000006e-18 < x < 2e4Initial program 44.5%
Taylor expanded in eps around inf
Applied rewrites40.7%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites81.0%
Applied rewrites81.0%
Taylor expanded in x around 0
Applied rewrites80.5%
if 2e4 < x Initial program 100.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6425.5
Applied rewrites25.5%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6452.9
Applied rewrites52.9%
Final simplification64.4%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (/ 1.0 eps) -1.0)))
(if (<= x 290.0)
(fma (* 0.5 x) (fma (- eps 1.0) t_0 (/ 1.0 eps)) 1.0)
(/ (- t_0 (- (/ 1.0 eps) 1.0)) 2.0))))
double code(double x, double eps) {
double t_0 = (1.0 / eps) - -1.0;
double tmp;
if (x <= 290.0) {
tmp = fma((0.5 * x), fma((eps - 1.0), t_0, (1.0 / eps)), 1.0);
} else {
tmp = (t_0 - ((1.0 / eps) - 1.0)) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(1.0 / eps) - -1.0) tmp = 0.0 if (x <= 290.0) tmp = fma(Float64(0.5 * x), fma(Float64(eps - 1.0), t_0, Float64(1.0 / eps)), 1.0); else tmp = Float64(Float64(t_0 - Float64(Float64(1.0 / eps) - 1.0)) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(1.0 / eps), $MachinePrecision] - -1.0), $MachinePrecision]}, If[LessEqual[x, 290.0], N[(N[(0.5 * x), $MachinePrecision] * N[(N[(eps - 1.0), $MachinePrecision] * t$95$0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(t$95$0 - N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\varepsilon} - -1\\
\mathbf{if}\;x \leq 290:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x, \mathsf{fma}\left(\varepsilon - 1, t\_0, \frac{1}{\varepsilon}\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - \left(\frac{1}{\varepsilon} - 1\right)}{2}\\
\end{array}
\end{array}
if x < 290Initial program 55.2%
Taylor expanded in eps around inf
Applied rewrites52.1%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites65.5%
Taylor expanded in eps around 0
Applied rewrites71.0%
if 290 < x Initial program 100.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6426.2
Applied rewrites26.2%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6451.6
Applied rewrites51.6%
Final simplification65.4%
(FPCore (x eps) :precision binary64 (if (<= x -8e-18) (/ (- (/ 1.0 eps) (* -1.0 (fma (- -1.0 eps) x 1.0))) 2.0) (fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0)))
double code(double x, double eps) {
double tmp;
if (x <= -8e-18) {
tmp = ((1.0 / eps) - (-1.0 * fma((-1.0 - eps), x, 1.0))) / 2.0;
} else {
tmp = fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -8e-18) tmp = Float64(Float64(Float64(1.0 / eps) - Float64(-1.0 * fma(Float64(-1.0 - eps), x, 1.0))) / 2.0); else tmp = fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0); end return tmp end
code[x_, eps_] := If[LessEqual[x, -8e-18], N[(N[(N[(1.0 / eps), $MachinePrecision] - N[(-1.0 * N[(N[(-1.0 - eps), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8 \cdot 10^{-18}:\\
\;\;\;\;\frac{\frac{1}{\varepsilon} - -1 \cdot \mathsf{fma}\left(-1 - \varepsilon, x, 1\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)\\
\end{array}
\end{array}
if x < -8.0000000000000006e-18Initial program 100.0%
Taylor expanded in eps around inf
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6447.6
Applied rewrites47.6%
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--.f6423.2
Applied rewrites23.2%
Taylor expanded in eps around 0
Applied rewrites23.2%
if -8.0000000000000006e-18 < x Initial program 62.7%
Taylor expanded in eps around inf
Applied rewrites60.2%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites72.4%
Applied rewrites72.4%
Taylor expanded in x around 0
Applied rewrites65.9%
(FPCore (x eps) :precision binary64 (fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0))
double code(double x, double eps) {
return fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
}
function code(x, eps) return fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0) end
code[x_, eps_] := N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)
\end{array}
Initial program 68.1%
Taylor expanded in eps around inf
Applied rewrites66.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites62.0%
Applied rewrites62.0%
Taylor expanded in x around 0
Applied rewrites56.4%
(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 68.1%
Taylor expanded in eps around inf
Applied rewrites66.0%
Taylor expanded in x around 0
Applied rewrites47.4%
herbie shell --seed 2025007
(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))