
(FPCore (x eps) :precision binary64 (/ (- (* (+ 1.0 (/ 1.0 eps)) (exp (- (* (- 1.0 eps) x)))) (* (- (/ 1.0 eps) 1.0) (exp (- (* (+ 1.0 eps) x))))) 2.0))
double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, eps)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (((1.0d0 + (1.0d0 / eps)) * exp(-((1.0d0 - eps) * x))) - (((1.0d0 / eps) - 1.0d0) * exp(-((1.0d0 + eps) * x)))) / 2.0d0
end function
public static double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * Math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * Math.exp(-((1.0 + eps) * x)))) / 2.0;
}
def code(x, eps): return (((1.0 + (1.0 / eps)) * math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * math.exp(-((1.0 + eps) * x)))) / 2.0
function code(x, eps) return Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(-Float64(Float64(1.0 - eps) * x)))) - Float64(Float64(Float64(1.0 / eps) - 1.0) * exp(Float64(-Float64(Float64(1.0 + eps) * x))))) / 2.0) end
function tmp = code(x, eps) tmp = (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0; end
code[x_, eps_] := N[(N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[(-N[(N[(1.0 - eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[(-N[(N[(1.0 + eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 16 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (/ (- (* (+ 1.0 (/ 1.0 eps)) (exp (- (* (- 1.0 eps) x)))) (* (- (/ 1.0 eps) 1.0) (exp (- (* (+ 1.0 eps) x))))) 2.0))
double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, eps)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (((1.0d0 + (1.0d0 / eps)) * exp(-((1.0d0 - eps) * x))) - (((1.0d0 / eps) - 1.0d0) * exp(-((1.0d0 + eps) * x)))) / 2.0d0
end function
public static double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * Math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * Math.exp(-((1.0 + eps) * x)))) / 2.0;
}
def code(x, eps): return (((1.0 + (1.0 / eps)) * math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * math.exp(-((1.0 + eps) * x)))) / 2.0
function code(x, eps) return Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(-Float64(Float64(1.0 - eps) * x)))) - Float64(Float64(Float64(1.0 / eps) - 1.0) * exp(Float64(-Float64(Float64(1.0 + eps) * x))))) / 2.0) end
function tmp = code(x, eps) tmp = (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0; end
code[x_, eps_] := N[(N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[(-N[(N[(1.0 - eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[(-N[(N[(1.0 + eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2}
\end{array}
(FPCore (x eps)
:precision binary64
(let* ((t_0
(/
(-
(* (+ 1.0 (/ 1.0 eps)) (exp (* (+ -1.0 eps) x)))
(* (- (/ 1.0 eps) 1.0) (exp (* (- -1.0 eps) x))))
2.0)))
(if (<= t_0 0.0) (* (/ (fma 2.0 x 2.0) (exp x)) 0.5) t_0)))
double code(double x, double eps) {
double t_0 = (((1.0 + (1.0 / eps)) * exp(((-1.0 + eps) * x))) - (((1.0 / eps) - 1.0) * exp(((-1.0 - eps) * x)))) / 2.0;
double tmp;
if (t_0 <= 0.0) {
tmp = (fma(2.0, x, 2.0) / exp(x)) * 0.5;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, eps) t_0 = 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) tmp = 0.0 if (t_0 <= 0.0) tmp = Float64(Float64(fma(2.0, x, 2.0) / exp(x)) * 0.5); else tmp = t_0; end return tmp end
code[x_, eps_] := Block[{t$95$0 = 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]}, If[LessEqual[t$95$0, 0.0], N[(N[(N[(2.0 * x + 2.0), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \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}\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\frac{\mathsf{fma}\left(2, x, 2\right)}{e^{x}} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\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 35.1%
Taylor expanded in eps around inf
Applied rewrites34.8%
Taylor expanded in eps around inf
Applied rewrites10.0%
Taylor expanded in eps around 0
Applied rewrites100.0%
Taylor expanded in x around 0
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.6%
Final simplification99.2%
(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)
0.0)
(* (/ (fma 2.0 x 2.0) (exp x)) 0.5)
(/ (- (* 1.0 (exp (* x eps))) (/ -1.0 (exp (fma x 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) <= 0.0) {
tmp = (fma(2.0, x, 2.0) / exp(x)) * 0.5;
} else {
tmp = ((1.0 * exp((x * 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 + 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) <= 0.0) tmp = Float64(Float64(fma(2.0, x, 2.0) / exp(x)) * 0.5); else tmp = Float64(Float64(Float64(1.0 * exp(Float64(x * 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[(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], 0.0], N[(N[(N[(2.0 * x + 2.0), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(1.0 * N[Exp[N[(x * eps), $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}
\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 0:\\
\;\;\;\;\frac{\mathsf{fma}\left(2, x, 2\right)}{e^{x}} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{1 \cdot e^{x \cdot \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)) < 0.0Initial program 35.1%
Taylor expanded in eps around inf
Applied rewrites34.8%
Taylor expanded in eps around inf
Applied rewrites10.0%
Taylor expanded in eps around 0
Applied rewrites100.0%
Taylor expanded in x around 0
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.6%
Taylor expanded in eps around inf
Applied rewrites95.7%
Taylor expanded in eps around inf
Applied rewrites95.7%
Taylor expanded in eps around inf
Applied rewrites98.6%
Final simplification99.2%
(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)
0.0)
(* (/ (+ (- x -1.0) (- x -1.0)) (fma (fma 0.5 x 1.0) x 1.0)) 0.5)
(fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.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) <= 0.0) {
tmp = (((x - -1.0) + (x - -1.0)) / fma(fma(0.5, x, 1.0), x, 1.0)) * 0.5;
} else {
tmp = fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (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) <= 0.0) tmp = Float64(Float64(Float64(Float64(x - -1.0) + Float64(x - -1.0)) / fma(fma(0.5, x, 1.0), x, 1.0)) * 0.5); else tmp = fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0); end return tmp end
code[x_, eps_] := If[LessEqual[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], 0.0], N[(N[(N[(N[(x - -1.0), $MachinePrecision] + N[(x - -1.0), $MachinePrecision]), $MachinePrecision] / N[(N[(0.5 * x + 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\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 0:\\
\;\;\;\;\frac{\left(x - -1\right) + \left(x - -1\right)}{\mathsf{fma}\left(\mathsf{fma}\left(0.5, x, 1\right), x, 1\right)} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)\\
\end{array}
\end{array}
if (/.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 35.1%
Taylor expanded in eps around inf
Applied rewrites34.8%
Taylor expanded in eps around inf
Applied rewrites10.0%
Taylor expanded in eps around 0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites82.4%
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.6%
Taylor expanded in eps around inf
Applied rewrites95.7%
Taylor expanded in eps around inf
Applied rewrites95.7%
Taylor expanded in eps around 0
Applied rewrites31.8%
Taylor expanded in x around 0
Applied rewrites37.9%
Final simplification55.8%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (/ 1.0 eps) 1.0)) (t_1 (+ 1.0 (/ 1.0 eps))))
(if (<= eps -1.0)
(/
(- (* t_1 (fma (- eps 1.0) x 1.0)) (* t_0 (exp (* (- -1.0 eps) x))))
2.0)
(if (<= eps 1.0)
(* (/ (fma 2.0 x 2.0) (exp x)) 0.5)
(if (<= eps 1.35e+90)
(/ (fma 1.0 (exp (- x)) (/ (+ 1.0 x) 1.0)) 2.0)
(/
(- (* t_1 (exp (* (+ -1.0 eps) x))) (* t_0 (- 1.0 (fma x eps x))))
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 (eps <= -1.0) {
tmp = ((t_1 * fma((eps - 1.0), x, 1.0)) - (t_0 * exp(((-1.0 - eps) * x)))) / 2.0;
} else if (eps <= 1.0) {
tmp = (fma(2.0, x, 2.0) / exp(x)) * 0.5;
} else if (eps <= 1.35e+90) {
tmp = fma(1.0, exp(-x), ((1.0 + x) / 1.0)) / 2.0;
} else {
tmp = ((t_1 * exp(((-1.0 + eps) * x))) - (t_0 * (1.0 - fma(x, eps, x)))) / 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 (eps <= -1.0) tmp = Float64(Float64(Float64(t_1 * fma(Float64(eps - 1.0), x, 1.0)) - Float64(t_0 * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0); elseif (eps <= 1.0) tmp = Float64(Float64(fma(2.0, x, 2.0) / exp(x)) * 0.5); elseif (eps <= 1.35e+90) tmp = Float64(fma(1.0, exp(Float64(-x)), Float64(Float64(1.0 + x) / 1.0)) / 2.0); else tmp = Float64(Float64(Float64(t_1 * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(t_0 * Float64(1.0 - fma(x, eps, x)))) / 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[eps, -1.0], N[(N[(N[(t$95$1 * N[(N[(eps - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(t$95$0 * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[eps, 1.0], N[(N[(N[(2.0 * x + 2.0), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[eps, 1.35e+90], N[(N[(1.0 * N[Exp[(-x)], $MachinePrecision] + N[(N[(1.0 + x), $MachinePrecision] / 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(t$95$1 * N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(t$95$0 * N[(1.0 - N[(x * eps + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\varepsilon} - 1\\
t_1 := 1 + \frac{1}{\varepsilon}\\
\mathbf{if}\;\varepsilon \leq -1:\\
\;\;\;\;\frac{t\_1 \cdot \mathsf{fma}\left(\varepsilon - 1, x, 1\right) - t\_0 \cdot e^{\left(-1 - \varepsilon\right) \cdot x}}{2}\\
\mathbf{elif}\;\varepsilon \leq 1:\\
\;\;\;\;\frac{\mathsf{fma}\left(2, x, 2\right)}{e^{x}} \cdot 0.5\\
\mathbf{elif}\;\varepsilon \leq 1.35 \cdot 10^{+90}:\\
\;\;\;\;\frac{\mathsf{fma}\left(1, e^{-x}, \frac{1 + x}{1}\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_1 \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - t\_0 \cdot \left(1 - \mathsf{fma}\left(x, \varepsilon, x\right)\right)}{2}\\
\end{array}
\end{array}
if eps < -1Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites70.8%
if -1 < eps < 1Initial program 36.3%
Taylor expanded in eps around inf
Applied rewrites33.2%
Taylor expanded in eps around inf
Applied rewrites9.6%
Taylor expanded in eps around 0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
if 1 < eps < 1.35e90Initial program 100.0%
Taylor expanded in eps around 0
Applied rewrites50.4%
Taylor expanded in x around 0
Applied rewrites51.0%
Taylor expanded in x around 0
Applied rewrites85.8%
if 1.35e90 < eps Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites68.3%
Final simplification84.0%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (exp (* x eps)))
(t_1 (+ 1.0 (/ 1.0 eps)))
(t_2 (- (/ 1.0 eps) 1.0)))
(if (<= x -700.0)
(/ (- (* t_1 (exp (- x))) t_2) 2.0)
(if (<= x 1.42)
(/ (- (* 1.0 t_0) (/ -1.0 1.0)) 2.0)
(if (<= x 2e+133) (/ (- (* t_1 t_0) t_2) 2.0) (/ x (exp x)))))))
double code(double x, double eps) {
double t_0 = exp((x * eps));
double t_1 = 1.0 + (1.0 / eps);
double t_2 = (1.0 / eps) - 1.0;
double tmp;
if (x <= -700.0) {
tmp = ((t_1 * exp(-x)) - t_2) / 2.0;
} else if (x <= 1.42) {
tmp = ((1.0 * t_0) - (-1.0 / 1.0)) / 2.0;
} else if (x <= 2e+133) {
tmp = ((t_1 * t_0) - t_2) / 2.0;
} else {
tmp = x / exp(x);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, eps)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = exp((x * eps))
t_1 = 1.0d0 + (1.0d0 / eps)
t_2 = (1.0d0 / eps) - 1.0d0
if (x <= (-700.0d0)) then
tmp = ((t_1 * exp(-x)) - t_2) / 2.0d0
else if (x <= 1.42d0) then
tmp = ((1.0d0 * t_0) - ((-1.0d0) / 1.0d0)) / 2.0d0
else if (x <= 2d+133) then
tmp = ((t_1 * t_0) - t_2) / 2.0d0
else
tmp = x / exp(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.exp((x * eps));
double t_1 = 1.0 + (1.0 / eps);
double t_2 = (1.0 / eps) - 1.0;
double tmp;
if (x <= -700.0) {
tmp = ((t_1 * Math.exp(-x)) - t_2) / 2.0;
} else if (x <= 1.42) {
tmp = ((1.0 * t_0) - (-1.0 / 1.0)) / 2.0;
} else if (x <= 2e+133) {
tmp = ((t_1 * t_0) - t_2) / 2.0;
} else {
tmp = x / Math.exp(x);
}
return tmp;
}
def code(x, eps): t_0 = math.exp((x * eps)) t_1 = 1.0 + (1.0 / eps) t_2 = (1.0 / eps) - 1.0 tmp = 0 if x <= -700.0: tmp = ((t_1 * math.exp(-x)) - t_2) / 2.0 elif x <= 1.42: tmp = ((1.0 * t_0) - (-1.0 / 1.0)) / 2.0 elif x <= 2e+133: tmp = ((t_1 * t_0) - t_2) / 2.0 else: tmp = x / math.exp(x) return tmp
function code(x, eps) t_0 = exp(Float64(x * eps)) t_1 = Float64(1.0 + Float64(1.0 / eps)) t_2 = Float64(Float64(1.0 / eps) - 1.0) tmp = 0.0 if (x <= -700.0) tmp = Float64(Float64(Float64(t_1 * exp(Float64(-x))) - t_2) / 2.0); elseif (x <= 1.42) tmp = Float64(Float64(Float64(1.0 * t_0) - Float64(-1.0 / 1.0)) / 2.0); elseif (x <= 2e+133) tmp = Float64(Float64(Float64(t_1 * t_0) - t_2) / 2.0); else tmp = Float64(x / exp(x)); end return tmp end
function tmp_2 = code(x, eps) t_0 = exp((x * eps)); t_1 = 1.0 + (1.0 / eps); t_2 = (1.0 / eps) - 1.0; tmp = 0.0; if (x <= -700.0) tmp = ((t_1 * exp(-x)) - t_2) / 2.0; elseif (x <= 1.42) tmp = ((1.0 * t_0) - (-1.0 / 1.0)) / 2.0; elseif (x <= 2e+133) tmp = ((t_1 * t_0) - t_2) / 2.0; else tmp = x / exp(x); end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Exp[N[(x * eps), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]}, If[LessEqual[x, -700.0], N[(N[(N[(t$95$1 * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] - t$95$2), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.42], N[(N[(N[(1.0 * t$95$0), $MachinePrecision] - N[(-1.0 / 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 2e+133], N[(N[(N[(t$95$1 * t$95$0), $MachinePrecision] - t$95$2), $MachinePrecision] / 2.0), $MachinePrecision], N[(x / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{x \cdot \varepsilon}\\
t_1 := 1 + \frac{1}{\varepsilon}\\
t_2 := \frac{1}{\varepsilon} - 1\\
\mathbf{if}\;x \leq -700:\\
\;\;\;\;\frac{t\_1 \cdot e^{-x} - t\_2}{2}\\
\mathbf{elif}\;x \leq 1.42:\\
\;\;\;\;\frac{1 \cdot t\_0 - \frac{-1}{1}}{2}\\
\mathbf{elif}\;x \leq 2 \cdot 10^{+133}:\\
\;\;\;\;\frac{t\_1 \cdot t\_0 - t\_2}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{e^{x}}\\
\end{array}
\end{array}
if x < -700Initial program 95.2%
Taylor expanded in x around 0
Applied rewrites51.5%
Taylor expanded in eps around 0
Applied rewrites97.6%
if -700 < x < 1.4199999999999999Initial program 56.5%
Taylor expanded in eps around inf
Applied rewrites53.4%
Taylor expanded in eps around inf
Applied rewrites53.4%
Taylor expanded in eps around inf
Applied rewrites96.8%
Taylor expanded in x around 0
Applied rewrites85.2%
if 1.4199999999999999 < x < 2e133Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites30.0%
Taylor expanded in eps around inf
Applied rewrites60.6%
if 2e133 < x Initial program 100.0%
Taylor expanded in eps around inf
Applied rewrites100.0%
Taylor expanded in eps around inf
Applied rewrites50.9%
Taylor expanded in eps around 0
Applied rewrites75.4%
Taylor expanded in x around inf
Applied rewrites75.4%
(FPCore (x eps)
:precision binary64
(if (<= eps -1.0)
(/ (- (* 1.0 (exp (* x eps))) (/ -1.0 1.0)) 2.0)
(if (<= eps 2.15e+15)
(* (/ (fma 2.0 x 2.0) (exp x)) 0.5)
(/ (- (- (/ 1.0 eps) -1.0) (/ -1.0 (exp (fma x eps x)))) 2.0))))
double code(double x, double eps) {
double tmp;
if (eps <= -1.0) {
tmp = ((1.0 * exp((x * eps))) - (-1.0 / 1.0)) / 2.0;
} else if (eps <= 2.15e+15) {
tmp = (fma(2.0, x, 2.0) / exp(x)) * 0.5;
} else {
tmp = (((1.0 / eps) - -1.0) - (-1.0 / exp(fma(x, eps, x)))) / 2.0;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -1.0) tmp = Float64(Float64(Float64(1.0 * exp(Float64(x * eps))) - Float64(-1.0 / 1.0)) / 2.0); elseif (eps <= 2.15e+15) tmp = Float64(Float64(fma(2.0, x, 2.0) / exp(x)) * 0.5); else tmp = Float64(Float64(Float64(Float64(1.0 / eps) - -1.0) - Float64(-1.0 / exp(fma(x, eps, x)))) / 2.0); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -1.0], N[(N[(N[(1.0 * N[Exp[N[(x * eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(-1.0 / 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[eps, 2.15e+15], N[(N[(N[(2.0 * x + 2.0), $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[(x * eps + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1:\\
\;\;\;\;\frac{1 \cdot e^{x \cdot \varepsilon} - \frac{-1}{1}}{2}\\
\mathbf{elif}\;\varepsilon \leq 2.15 \cdot 10^{+15}:\\
\;\;\;\;\frac{\mathsf{fma}\left(2, x, 2\right)}{e^{x}} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\frac{1}{\varepsilon} - -1\right) - \frac{-1}{e^{\mathsf{fma}\left(x, \varepsilon, x\right)}}}{2}\\
\end{array}
\end{array}
if eps < -1Initial program 99.9%
Taylor expanded in eps around inf
Applied rewrites99.6%
Taylor expanded in eps around inf
Applied rewrites99.6%
Taylor expanded in eps around inf
Applied rewrites99.9%
Taylor expanded in x around 0
Applied rewrites69.9%
if -1 < eps < 2.15e15Initial program 38.5%
Taylor expanded in eps around inf
Applied rewrites34.4%
Taylor expanded in eps around inf
Applied rewrites11.6%
Taylor expanded in eps around 0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites100.0%
if 2.15e15 < eps Initial program 100.0%
Taylor expanded in eps around inf
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites61.7%
Final simplification80.8%
(FPCore (x eps)
:precision binary64
(if (<= x -700.0)
(/ (- (* (+ 1.0 (/ 1.0 eps)) (exp (- x))) (- (/ 1.0 eps) 1.0)) 2.0)
(if (<= x 750.0)
(/ (- (* 1.0 (exp (* x eps))) (/ -1.0 1.0)) 2.0)
(/ x (exp x)))))
double code(double x, double eps) {
double tmp;
if (x <= -700.0) {
tmp = (((1.0 + (1.0 / eps)) * exp(-x)) - ((1.0 / eps) - 1.0)) / 2.0;
} else if (x <= 750.0) {
tmp = ((1.0 * exp((x * eps))) - (-1.0 / 1.0)) / 2.0;
} else {
tmp = x / exp(x);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, eps)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= (-700.0d0)) then
tmp = (((1.0d0 + (1.0d0 / eps)) * exp(-x)) - ((1.0d0 / eps) - 1.0d0)) / 2.0d0
else if (x <= 750.0d0) then
tmp = ((1.0d0 * exp((x * eps))) - ((-1.0d0) / 1.0d0)) / 2.0d0
else
tmp = x / exp(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= -700.0) {
tmp = (((1.0 + (1.0 / eps)) * Math.exp(-x)) - ((1.0 / eps) - 1.0)) / 2.0;
} else if (x <= 750.0) {
tmp = ((1.0 * Math.exp((x * eps))) - (-1.0 / 1.0)) / 2.0;
} else {
tmp = x / Math.exp(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= -700.0: tmp = (((1.0 + (1.0 / eps)) * math.exp(-x)) - ((1.0 / eps) - 1.0)) / 2.0 elif x <= 750.0: tmp = ((1.0 * math.exp((x * eps))) - (-1.0 / 1.0)) / 2.0 else: tmp = x / math.exp(x) return tmp
function code(x, eps) tmp = 0.0 if (x <= -700.0) tmp = Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(-x))) - Float64(Float64(1.0 / eps) - 1.0)) / 2.0); elseif (x <= 750.0) tmp = Float64(Float64(Float64(1.0 * exp(Float64(x * eps))) - Float64(-1.0 / 1.0)) / 2.0); else tmp = Float64(x / exp(x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= -700.0) tmp = (((1.0 + (1.0 / eps)) * exp(-x)) - ((1.0 / eps) - 1.0)) / 2.0; elseif (x <= 750.0) tmp = ((1.0 * exp((x * eps))) - (-1.0 / 1.0)) / 2.0; else tmp = x / exp(x); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, -700.0], N[(N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] - N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 750.0], N[(N[(N[(1.0 * N[Exp[N[(x * eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(-1.0 / 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(x / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -700:\\
\;\;\;\;\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-x} - \left(\frac{1}{\varepsilon} - 1\right)}{2}\\
\mathbf{elif}\;x \leq 750:\\
\;\;\;\;\frac{1 \cdot e^{x \cdot \varepsilon} - \frac{-1}{1}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{e^{x}}\\
\end{array}
\end{array}
if x < -700Initial program 95.2%
Taylor expanded in x around 0
Applied rewrites51.5%
Taylor expanded in eps around 0
Applied rewrites97.6%
if -700 < x < 750Initial program 57.1%
Taylor expanded in eps around inf
Applied rewrites54.0%
Taylor expanded in eps around inf
Applied rewrites54.0%
Taylor expanded in eps around inf
Applied rewrites96.9%
Taylor expanded in x around 0
Applied rewrites84.7%
if 750 < x Initial program 100.0%
Taylor expanded in eps around inf
Applied rewrites100.0%
Taylor expanded in eps around inf
Applied rewrites56.1%
Taylor expanded in eps around 0
Applied rewrites59.3%
Taylor expanded in x around inf
Applied rewrites59.3%
(FPCore (x eps)
:precision binary64
(if (<= x -700.0)
(* (/ 2.0 (exp x)) 0.5)
(if (<= x 750.0)
(/ (- (* 1.0 (exp (* x eps))) (/ -1.0 1.0)) 2.0)
(/ x (exp x)))))
double code(double x, double eps) {
double tmp;
if (x <= -700.0) {
tmp = (2.0 / exp(x)) * 0.5;
} else if (x <= 750.0) {
tmp = ((1.0 * exp((x * eps))) - (-1.0 / 1.0)) / 2.0;
} else {
tmp = x / exp(x);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, eps)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= (-700.0d0)) then
tmp = (2.0d0 / exp(x)) * 0.5d0
else if (x <= 750.0d0) then
tmp = ((1.0d0 * exp((x * eps))) - ((-1.0d0) / 1.0d0)) / 2.0d0
else
tmp = x / exp(x)
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= -700.0) {
tmp = (2.0 / Math.exp(x)) * 0.5;
} else if (x <= 750.0) {
tmp = ((1.0 * Math.exp((x * eps))) - (-1.0 / 1.0)) / 2.0;
} else {
tmp = x / Math.exp(x);
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= -700.0: tmp = (2.0 / math.exp(x)) * 0.5 elif x <= 750.0: tmp = ((1.0 * math.exp((x * eps))) - (-1.0 / 1.0)) / 2.0 else: tmp = x / math.exp(x) return tmp
function code(x, eps) tmp = 0.0 if (x <= -700.0) tmp = Float64(Float64(2.0 / exp(x)) * 0.5); elseif (x <= 750.0) tmp = Float64(Float64(Float64(1.0 * exp(Float64(x * eps))) - Float64(-1.0 / 1.0)) / 2.0); else tmp = Float64(x / exp(x)); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= -700.0) tmp = (2.0 / exp(x)) * 0.5; elseif (x <= 750.0) tmp = ((1.0 * exp((x * eps))) - (-1.0 / 1.0)) / 2.0; else tmp = x / exp(x); end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, -700.0], N[(N[(2.0 / N[Exp[x], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 750.0], N[(N[(N[(1.0 * N[Exp[N[(x * eps), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(-1.0 / 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(x / N[Exp[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -700:\\
\;\;\;\;\frac{2}{e^{x}} \cdot 0.5\\
\mathbf{elif}\;x \leq 750:\\
\;\;\;\;\frac{1 \cdot e^{x \cdot \varepsilon} - \frac{-1}{1}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{e^{x}}\\
\end{array}
\end{array}
if x < -700Initial program 95.2%
Taylor expanded in eps around inf
Applied rewrites95.2%
Taylor expanded in eps around inf
Applied rewrites95.2%
Taylor expanded in eps around 0
Applied rewrites4.8%
Taylor expanded in x around 0
Applied rewrites95.2%
if -700 < x < 750Initial program 57.1%
Taylor expanded in eps around inf
Applied rewrites54.0%
Taylor expanded in eps around inf
Applied rewrites54.0%
Taylor expanded in eps around inf
Applied rewrites96.9%
Taylor expanded in x around 0
Applied rewrites84.7%
if 750 < x Initial program 100.0%
Taylor expanded in eps around inf
Applied rewrites100.0%
Taylor expanded in eps around inf
Applied rewrites56.1%
Taylor expanded in eps around 0
Applied rewrites59.3%
Taylor expanded in x around inf
Applied rewrites59.3%
(FPCore (x eps) :precision binary64 (if (<= x -2000000.0) (* (/ 2.0 (exp x)) 0.5) (* (/ (fma 2.0 x 2.0) (exp x)) 0.5)))
double code(double x, double eps) {
double tmp;
if (x <= -2000000.0) {
tmp = (2.0 / exp(x)) * 0.5;
} else {
tmp = (fma(2.0, x, 2.0) / exp(x)) * 0.5;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -2000000.0) tmp = Float64(Float64(2.0 / exp(x)) * 0.5); else tmp = Float64(Float64(fma(2.0, x, 2.0) / exp(x)) * 0.5); end return tmp end
code[x_, eps_] := If[LessEqual[x, -2000000.0], N[(N[(2.0 / N[Exp[x], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(2.0 * x + 2.0), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2000000:\\
\;\;\;\;\frac{2}{e^{x}} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(2, x, 2\right)}{e^{x}} \cdot 0.5\\
\end{array}
\end{array}
if x < -2e6Initial program 100.0%
Taylor expanded in eps around inf
Applied rewrites100.0%
Taylor expanded in eps around inf
Applied rewrites100.0%
Taylor expanded in eps around 0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites100.0%
if -2e6 < x Initial program 68.2%
Taylor expanded in eps around inf
Applied rewrites66.0%
Taylor expanded in eps around inf
Applied rewrites54.3%
Taylor expanded in eps around 0
Applied rewrites69.8%
Taylor expanded in x around 0
Applied rewrites69.8%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (/ 1.0 eps) 1.0)))
(if (<= x -200.0)
(/ (- (/ (+ 1.0 eps) eps) (fma (- (fma x eps x)) t_0 t_0)) 2.0)
(if (<= x 1.55)
(fma (- (* (fma -0.125 x 0.3333333333333333) x) 0.5) (* x x) 1.0)
(/ x (exp x))))))
double code(double x, double eps) {
double t_0 = (1.0 / eps) - 1.0;
double tmp;
if (x <= -200.0) {
tmp = (((1.0 + eps) / eps) - fma(-fma(x, eps, x), t_0, t_0)) / 2.0;
} else if (x <= 1.55) {
tmp = fma(((fma(-0.125, x, 0.3333333333333333) * x) - 0.5), (x * x), 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 <= -200.0) tmp = Float64(Float64(Float64(Float64(1.0 + eps) / eps) - fma(Float64(-fma(x, eps, x)), t_0, t_0)) / 2.0); elseif (x <= 1.55) tmp = fma(Float64(Float64(fma(-0.125, x, 0.3333333333333333) * x) - 0.5), Float64(x * x), 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, -200.0], N[(N[(N[(N[(1.0 + eps), $MachinePrecision] / eps), $MachinePrecision] - N[((-N[(x * eps + x), $MachinePrecision]) * t$95$0 + t$95$0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.55], N[(N[(N[(N[(-0.125 * x + 0.3333333333333333), $MachinePrecision] * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $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 -200:\\
\;\;\;\;\frac{\frac{1 + \varepsilon}{\varepsilon} - \mathsf{fma}\left(-\mathsf{fma}\left(x, \varepsilon, x\right), t\_0, t\_0\right)}{2}\\
\mathbf{elif}\;x \leq 1.55:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.125, x, 0.3333333333333333\right) \cdot x - 0.5, x \cdot x, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{e^{x}}\\
\end{array}
\end{array}
if x < -200Initial program 95.2%
Taylor expanded in eps around inf
Applied rewrites95.2%
Taylor expanded in eps around inf
Applied rewrites95.2%
Taylor expanded in x around 0
Applied rewrites49.1%
Taylor expanded in x around 0
Applied rewrites20.7%
if -200 < x < 1.55000000000000004Initial program 56.8%
Taylor expanded in eps around inf
Applied rewrites53.7%
Taylor expanded in eps around inf
Applied rewrites53.7%
Taylor expanded in eps around 0
Applied rewrites74.3%
Taylor expanded in x around 0
Applied rewrites73.5%
if 1.55000000000000004 < x Initial program 100.0%
Taylor expanded in eps around inf
Applied rewrites100.0%
Taylor expanded in eps around inf
Applied rewrites56.8%
Taylor expanded in eps around 0
Applied rewrites58.3%
Taylor expanded in x around inf
Applied rewrites58.3%
(FPCore (x eps) :precision binary64 (* (/ 2.0 (exp x)) 0.5))
double code(double x, double eps) {
return (2.0 / exp(x)) * 0.5;
}
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 = (2.0d0 / exp(x)) * 0.5d0
end function
public static double code(double x, double eps) {
return (2.0 / Math.exp(x)) * 0.5;
}
def code(x, eps): return (2.0 / math.exp(x)) * 0.5
function code(x, eps) return Float64(Float64(2.0 / exp(x)) * 0.5) end
function tmp = code(x, eps) tmp = (2.0 / exp(x)) * 0.5; end
code[x_, eps_] := N[(N[(2.0 / N[Exp[x], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{e^{x}} \cdot 0.5
\end{array}
Initial program 73.1%
Taylor expanded in eps around inf
Applied rewrites71.2%
Taylor expanded in eps around inf
Applied rewrites61.2%
Taylor expanded in eps around 0
Applied rewrites59.2%
Taylor expanded in x around 0
Applied rewrites72.1%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (/ 1.0 eps) 1.0)))
(if (<= x -200.0)
(/ (- (/ (+ 1.0 eps) eps) (fma (- (fma x eps x)) t_0 t_0)) 2.0)
(if (<= x 1.42)
(fma (- (* (fma -0.125 x 0.3333333333333333) x) 0.5) (* x x) 1.0)
(/ (- (- (/ 1.0 eps) -1.0) t_0) 2.0)))))
double code(double x, double eps) {
double t_0 = (1.0 / eps) - 1.0;
double tmp;
if (x <= -200.0) {
tmp = (((1.0 + eps) / eps) - fma(-fma(x, eps, x), t_0, t_0)) / 2.0;
} else if (x <= 1.42) {
tmp = fma(((fma(-0.125, x, 0.3333333333333333) * x) - 0.5), (x * x), 1.0);
} else {
tmp = (((1.0 / eps) - -1.0) - t_0) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(1.0 / eps) - 1.0) tmp = 0.0 if (x <= -200.0) tmp = Float64(Float64(Float64(Float64(1.0 + eps) / eps) - fma(Float64(-fma(x, eps, x)), t_0, t_0)) / 2.0); elseif (x <= 1.42) tmp = fma(Float64(Float64(fma(-0.125, x, 0.3333333333333333) * x) - 0.5), Float64(x * x), 1.0); else tmp = Float64(Float64(Float64(Float64(1.0 / eps) - -1.0) - t_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, -200.0], N[(N[(N[(N[(1.0 + eps), $MachinePrecision] / eps), $MachinePrecision] - N[((-N[(x * eps + x), $MachinePrecision]) * t$95$0 + t$95$0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.42], N[(N[(N[(N[(-0.125 * x + 0.3333333333333333), $MachinePrecision] * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(N[(N[(1.0 / eps), $MachinePrecision] - -1.0), $MachinePrecision] - t$95$0), $MachinePrecision] / 2.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\varepsilon} - 1\\
\mathbf{if}\;x \leq -200:\\
\;\;\;\;\frac{\frac{1 + \varepsilon}{\varepsilon} - \mathsf{fma}\left(-\mathsf{fma}\left(x, \varepsilon, x\right), t\_0, t\_0\right)}{2}\\
\mathbf{elif}\;x \leq 1.42:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.125, x, 0.3333333333333333\right) \cdot x - 0.5, x \cdot x, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\frac{1}{\varepsilon} - -1\right) - t\_0}{2}\\
\end{array}
\end{array}
if x < -200Initial program 95.2%
Taylor expanded in eps around inf
Applied rewrites95.2%
Taylor expanded in eps around inf
Applied rewrites95.2%
Taylor expanded in x around 0
Applied rewrites49.1%
Taylor expanded in x around 0
Applied rewrites20.7%
if -200 < x < 1.4199999999999999Initial program 56.5%
Taylor expanded in eps around inf
Applied rewrites53.4%
Taylor expanded in eps around inf
Applied rewrites53.4%
Taylor expanded in eps around 0
Applied rewrites74.8%
Taylor expanded in x around 0
Applied rewrites74.0%
if 1.4199999999999999 < x Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites23.6%
Taylor expanded in x around 0
Applied rewrites56.4%
Final simplification61.1%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (/ 1.0 eps) 1.0)))
(if (<= x -3700.0)
(/ (- (* (+ 1.0 (/ 1.0 eps)) (fma (- eps 1.0) x 1.0)) t_0) 2.0)
(if (<= x 1.42)
(fma (- (* (fma -0.125 x 0.3333333333333333) x) 0.5) (* x x) 1.0)
(/ (- (- (/ 1.0 eps) -1.0) t_0) 2.0)))))
double code(double x, double eps) {
double t_0 = (1.0 / eps) - 1.0;
double tmp;
if (x <= -3700.0) {
tmp = (((1.0 + (1.0 / eps)) * fma((eps - 1.0), x, 1.0)) - t_0) / 2.0;
} else if (x <= 1.42) {
tmp = fma(((fma(-0.125, x, 0.3333333333333333) * x) - 0.5), (x * x), 1.0);
} else {
tmp = (((1.0 / eps) - -1.0) - t_0) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(1.0 / eps) - 1.0) tmp = 0.0 if (x <= -3700.0) tmp = Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * fma(Float64(eps - 1.0), x, 1.0)) - t_0) / 2.0); elseif (x <= 1.42) tmp = fma(Float64(Float64(fma(-0.125, x, 0.3333333333333333) * x) - 0.5), Float64(x * x), 1.0); else tmp = Float64(Float64(Float64(Float64(1.0 / eps) - -1.0) - t_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, -3700.0], N[(N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[(N[(eps - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.42], N[(N[(N[(N[(-0.125 * x + 0.3333333333333333), $MachinePrecision] * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(N[(N[(1.0 / eps), $MachinePrecision] - -1.0), $MachinePrecision] - t$95$0), $MachinePrecision] / 2.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\varepsilon} - 1\\
\mathbf{if}\;x \leq -3700:\\
\;\;\;\;\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot \mathsf{fma}\left(\varepsilon - 1, x, 1\right) - t\_0}{2}\\
\mathbf{elif}\;x \leq 1.42:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.125, x, 0.3333333333333333\right) \cdot x - 0.5, x \cdot x, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\frac{1}{\varepsilon} - -1\right) - t\_0}{2}\\
\end{array}
\end{array}
if x < -3700Initial program 97.5%
Taylor expanded in x around 0
Applied rewrites47.1%
Taylor expanded in x around 0
Applied rewrites19.8%
if -3700 < x < 1.4199999999999999Initial program 56.5%
Taylor expanded in eps around inf
Applied rewrites53.4%
Taylor expanded in eps around inf
Applied rewrites53.4%
Taylor expanded in eps around 0
Applied rewrites74.4%
Taylor expanded in x around 0
Applied rewrites73.1%
if 1.4199999999999999 < x Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites23.6%
Taylor expanded in x around 0
Applied rewrites56.4%
Final simplification60.9%
(FPCore (x eps) :precision binary64 (if (<= x 1.42) (fma (- (* (fma -0.125 x 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 <= 1.42) {
tmp = fma(((fma(-0.125, x, 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 <= 1.42) tmp = fma(Float64(Float64(fma(-0.125, x, 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, 1.42], N[(N[(N[(N[(-0.125 * x + 0.3333333333333333), $MachinePrecision] * 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 1.42:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.125, x, 0.3333333333333333\right) \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 < 1.4199999999999999Initial program 64.8%
Taylor expanded in eps around inf
Applied rewrites62.4%
Taylor expanded in eps around inf
Applied rewrites62.4%
Taylor expanded in eps around 0
Applied rewrites59.8%
Taylor expanded in x around 0
Applied rewrites58.2%
if 1.4199999999999999 < x Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites23.6%
Taylor expanded in x around 0
Applied rewrites56.4%
Final simplification57.8%
(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 73.1%
Taylor expanded in eps around inf
Applied rewrites71.2%
Taylor expanded in eps around inf
Applied rewrites61.2%
Taylor expanded in eps around 0
Applied rewrites59.2%
Taylor expanded in x around 0
Applied rewrites49.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 73.1%
Taylor expanded in eps around inf
Applied rewrites71.2%
Taylor expanded in x around 0
Applied rewrites45.1%
herbie shell --seed 2025019
(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))