
(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 11 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 (exp (* (- -1.0 eps) x)))
(t_1 (+ 1.0 (pow eps -1.0)))
(t_2 (exp (- x))))
(if (<=
(/
(- (* t_1 (exp (* (+ -1.0 eps) x))) (* (- (pow eps -1.0) 1.0) t_0))
2.0)
1.1)
(* (fma t_2 (- (+ 1.0 x) -1.0) (* t_2 x)) 0.5)
(/ (- (* t_1 (exp (* x eps))) (* -1.0 t_0)) 2.0))))
double code(double x, double eps) {
double t_0 = exp(((-1.0 - eps) * x));
double t_1 = 1.0 + pow(eps, -1.0);
double t_2 = exp(-x);
double tmp;
if ((((t_1 * exp(((-1.0 + eps) * x))) - ((pow(eps, -1.0) - 1.0) * t_0)) / 2.0) <= 1.1) {
tmp = fma(t_2, ((1.0 + x) - -1.0), (t_2 * x)) * 0.5;
} else {
tmp = ((t_1 * exp((x * eps))) - (-1.0 * t_0)) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = exp(Float64(Float64(-1.0 - eps) * x)) t_1 = Float64(1.0 + (eps ^ -1.0)) t_2 = exp(Float64(-x)) tmp = 0.0 if (Float64(Float64(Float64(t_1 * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(Float64((eps ^ -1.0) - 1.0) * t_0)) / 2.0) <= 1.1) 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(x * eps))) - Float64(-1.0 * t_0)) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[Power[eps, -1.0], $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[(N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 1.1], 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[(x * eps), $MachinePrecision]], $MachinePrecision]), $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}\\
t_1 := 1 + {\varepsilon}^{-1}\\
t_2 := e^{-x}\\
\mathbf{if}\;\frac{t\_1 \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - \left({\varepsilon}^{-1} - 1\right) \cdot t\_0}{2} \leq 1.1:\\
\;\;\;\;\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} - -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)) < 1.1000000000000001Initial program 54.0%
Taylor expanded in eps around inf
Applied rewrites50.2%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
if 1.1000000000000001 < (/.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 eps around inf
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (exp (- x))))
(if (<=
(/
(-
(* (+ 1.0 (pow eps -1.0)) (exp (* (+ -1.0 eps) x)))
(* (- (pow eps -1.0) 1.0) (exp (* (- -1.0 eps) x))))
2.0)
2.0)
(* (fma t_0 (- (+ 1.0 x) -1.0) (* t_0 x)) 0.5)
(/
(fma (/ (* (+ eps 1.0) (fma eps eps -1.0)) (+ eps 1.0)) (* x x) 2.0)
2.0))))
double code(double x, double eps) {
double t_0 = exp(-x);
double tmp;
if (((((1.0 + pow(eps, -1.0)) * exp(((-1.0 + eps) * x))) - ((pow(eps, -1.0) - 1.0) * exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0) {
tmp = fma(t_0, ((1.0 + x) - -1.0), (t_0 * x)) * 0.5;
} else {
tmp = fma((((eps + 1.0) * fma(eps, eps, -1.0)) / (eps + 1.0)), (x * x), 2.0) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = exp(Float64(-x)) tmp = 0.0 if (Float64(Float64(Float64(Float64(1.0 + (eps ^ -1.0)) * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(Float64((eps ^ -1.0) - 1.0) * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0) <= 2.0) tmp = Float64(fma(t_0, Float64(Float64(1.0 + x) - -1.0), Float64(t_0 * x)) * 0.5); else tmp = Float64(fma(Float64(Float64(Float64(eps + 1.0) * fma(eps, eps, -1.0)) / Float64(eps + 1.0)), Float64(x * x), 2.0) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, If[LessEqual[N[(N[(N[(N[(1.0 + N[Power[eps, -1.0], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 2.0], N[(N[(t$95$0 * N[(N[(1.0 + x), $MachinePrecision] - -1.0), $MachinePrecision] + N[(t$95$0 * x), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(N[(N[(eps + 1.0), $MachinePrecision] * N[(eps * eps + -1.0), $MachinePrecision]), $MachinePrecision] / N[(eps + 1.0), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-x}\\
\mathbf{if}\;\frac{\left(1 + {\varepsilon}^{-1}\right) \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - \left({\varepsilon}^{-1} - 1\right) \cdot e^{\left(-1 - \varepsilon\right) \cdot x}}{2} \leq 2:\\
\;\;\;\;\mathsf{fma}\left(t\_0, \left(1 + x\right) - -1, t\_0 \cdot x\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{\left(\varepsilon + 1\right) \cdot \mathsf{fma}\left(\varepsilon, \varepsilon, -1\right)}{\varepsilon + 1}, x \cdot x, 2\right)}{2}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) < 2Initial program 54.3%
Taylor expanded in eps around inf
Applied rewrites50.5%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.4%
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 100.0%
Taylor expanded in eps around 0
Applied rewrites11.8%
Taylor expanded in x around 0
Applied rewrites79.8%
Applied rewrites85.6%
Final simplification93.3%
(FPCore (x eps)
:precision binary64
(if (<=
(/
(-
(* (+ 1.0 (pow eps -1.0)) (exp (* (+ -1.0 eps) x)))
(* (- (pow eps -1.0) 1.0) (exp (* (- -1.0 eps) x))))
2.0)
2.0)
1.0
(/ (* (* (* eps eps) x) x) 2.0)))
double code(double x, double eps) {
double tmp;
if (((((1.0 + pow(eps, -1.0)) * exp(((-1.0 + eps) * x))) - ((pow(eps, -1.0) - 1.0) * exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0) {
tmp = 1.0;
} else {
tmp = (((eps * eps) * x) * 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 + (eps ** (-1.0d0))) * exp((((-1.0d0) + eps) * x))) - (((eps ** (-1.0d0)) - 1.0d0) * exp((((-1.0d0) - eps) * x)))) / 2.0d0) <= 2.0d0) then
tmp = 1.0d0
else
tmp = (((eps * eps) * x) * x) / 2.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (((((1.0 + Math.pow(eps, -1.0)) * Math.exp(((-1.0 + eps) * x))) - ((Math.pow(eps, -1.0) - 1.0) * Math.exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0) {
tmp = 1.0;
} else {
tmp = (((eps * eps) * x) * x) / 2.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if ((((1.0 + math.pow(eps, -1.0)) * math.exp(((-1.0 + eps) * x))) - ((math.pow(eps, -1.0) - 1.0) * math.exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0: tmp = 1.0 else: tmp = (((eps * eps) * x) * x) / 2.0 return tmp
function code(x, eps) tmp = 0.0 if (Float64(Float64(Float64(Float64(1.0 + (eps ^ -1.0)) * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(Float64((eps ^ -1.0) - 1.0) * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0) <= 2.0) tmp = 1.0; else tmp = Float64(Float64(Float64(Float64(eps * eps) * x) * x) / 2.0); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (((((1.0 + (eps ^ -1.0)) * exp(((-1.0 + eps) * x))) - (((eps ^ -1.0) - 1.0) * exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0) tmp = 1.0; else tmp = (((eps * eps) * x) * x) / 2.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(N[(N[(N[(1.0 + N[Power[eps, -1.0], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 2.0], 1.0, N[(N[(N[(N[(eps * eps), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left(1 + {\varepsilon}^{-1}\right) \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - \left({\varepsilon}^{-1} - 1\right) \cdot e^{\left(-1 - \varepsilon\right) \cdot x}}{2} \leq 2:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(\varepsilon \cdot \varepsilon\right) \cdot x\right) \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 54.3%
Taylor expanded in x around 0
Applied rewrites73.7%
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 100.0%
Taylor expanded in eps around 0
Applied rewrites11.8%
Taylor expanded in x around 0
Applied rewrites79.8%
Taylor expanded in eps around inf
Applied rewrites84.2%
Final simplification78.4%
(FPCore (x eps)
:precision binary64
(if (<=
(/
(-
(* (+ 1.0 (pow eps -1.0)) (exp (* (+ -1.0 eps) x)))
(* (- (pow eps -1.0) 1.0) (exp (* (- -1.0 eps) x))))
2.0)
2.0)
1.0
(/ (* (* x eps) (* x eps)) 2.0)))
double code(double x, double eps) {
double tmp;
if (((((1.0 + pow(eps, -1.0)) * exp(((-1.0 + eps) * x))) - ((pow(eps, -1.0) - 1.0) * exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0) {
tmp = 1.0;
} else {
tmp = ((x * eps) * (x * eps)) / 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 + (eps ** (-1.0d0))) * exp((((-1.0d0) + eps) * x))) - (((eps ** (-1.0d0)) - 1.0d0) * exp((((-1.0d0) - eps) * x)))) / 2.0d0) <= 2.0d0) then
tmp = 1.0d0
else
tmp = ((x * eps) * (x * eps)) / 2.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (((((1.0 + Math.pow(eps, -1.0)) * Math.exp(((-1.0 + eps) * x))) - ((Math.pow(eps, -1.0) - 1.0) * Math.exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0) {
tmp = 1.0;
} else {
tmp = ((x * eps) * (x * eps)) / 2.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if ((((1.0 + math.pow(eps, -1.0)) * math.exp(((-1.0 + eps) * x))) - ((math.pow(eps, -1.0) - 1.0) * math.exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0: tmp = 1.0 else: tmp = ((x * eps) * (x * eps)) / 2.0 return tmp
function code(x, eps) tmp = 0.0 if (Float64(Float64(Float64(Float64(1.0 + (eps ^ -1.0)) * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(Float64((eps ^ -1.0) - 1.0) * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0) <= 2.0) tmp = 1.0; else tmp = Float64(Float64(Float64(x * eps) * Float64(x * eps)) / 2.0); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (((((1.0 + (eps ^ -1.0)) * exp(((-1.0 + eps) * x))) - (((eps ^ -1.0) - 1.0) * exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0) tmp = 1.0; else tmp = ((x * eps) * (x * eps)) / 2.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(N[(N[(N[(1.0 + N[Power[eps, -1.0], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 2.0], 1.0, N[(N[(N[(x * eps), $MachinePrecision] * N[(x * eps), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left(1 + {\varepsilon}^{-1}\right) \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - \left({\varepsilon}^{-1} - 1\right) \cdot e^{\left(-1 - \varepsilon\right) \cdot x}}{2} \leq 2:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(x \cdot \varepsilon\right) \cdot \left(x \cdot \varepsilon\right)}{2}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) < 2Initial program 54.3%
Taylor expanded in x around 0
Applied rewrites73.7%
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 100.0%
Taylor expanded in eps around 0
Applied rewrites11.8%
Taylor expanded in x around 0
Applied rewrites79.8%
Applied rewrites84.2%
Taylor expanded in eps around inf
Applied rewrites75.0%
Final simplification74.3%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (fma 0.08333333333333333 (* eps eps) 0.16666666666666666)))
(if (<= x -2.35e-132)
(/
(fma
(fma
(fma
(- (* t_0 (* eps eps)) 0.25)
x
(fma -0.6666666666666666 (* eps eps) 0.6666666666666666))
x
(- (* eps eps) 1.0))
(* x x)
2.0)
2.0)
(if (<= x 1.02e-156)
(/ (fma (* (* x x) (+ eps 1.0)) (- eps 1.0) 2.0) 2.0)
(if (<= x 125000000000.0)
(/
(-
(fma
(fma
(fma
(- (* x t_0) 0.6666666666666666)
(* eps eps)
(fma -0.125 x 0.3333333333333333))
x
(- (* eps eps) 0.5))
(* x x)
1.0)
(/ (fma -1.0 x -1.0) (exp x)))
2.0)
(/ (* (* (* eps eps) x) x) 2.0))))))
double code(double x, double eps) {
double t_0 = fma(0.08333333333333333, (eps * eps), 0.16666666666666666);
double tmp;
if (x <= -2.35e-132) {
tmp = fma(fma(fma(((t_0 * (eps * eps)) - 0.25), x, fma(-0.6666666666666666, (eps * eps), 0.6666666666666666)), x, ((eps * eps) - 1.0)), (x * x), 2.0) / 2.0;
} else if (x <= 1.02e-156) {
tmp = fma(((x * x) * (eps + 1.0)), (eps - 1.0), 2.0) / 2.0;
} else if (x <= 125000000000.0) {
tmp = (fma(fma(fma(((x * t_0) - 0.6666666666666666), (eps * eps), fma(-0.125, x, 0.3333333333333333)), x, ((eps * eps) - 0.5)), (x * x), 1.0) - (fma(-1.0, x, -1.0) / exp(x))) / 2.0;
} else {
tmp = (((eps * eps) * x) * x) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = fma(0.08333333333333333, Float64(eps * eps), 0.16666666666666666) tmp = 0.0 if (x <= -2.35e-132) tmp = Float64(fma(fma(fma(Float64(Float64(t_0 * Float64(eps * eps)) - 0.25), x, fma(-0.6666666666666666, Float64(eps * eps), 0.6666666666666666)), x, Float64(Float64(eps * eps) - 1.0)), Float64(x * x), 2.0) / 2.0); elseif (x <= 1.02e-156) tmp = Float64(fma(Float64(Float64(x * x) * Float64(eps + 1.0)), Float64(eps - 1.0), 2.0) / 2.0); elseif (x <= 125000000000.0) tmp = Float64(Float64(fma(fma(fma(Float64(Float64(x * t_0) - 0.6666666666666666), Float64(eps * eps), fma(-0.125, x, 0.3333333333333333)), x, Float64(Float64(eps * eps) - 0.5)), Float64(x * x), 1.0) - Float64(fma(-1.0, x, -1.0) / exp(x))) / 2.0); else tmp = Float64(Float64(Float64(Float64(eps * eps) * x) * x) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(0.08333333333333333 * N[(eps * eps), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]}, If[LessEqual[x, -2.35e-132], N[(N[(N[(N[(N[(N[(t$95$0 * N[(eps * eps), $MachinePrecision]), $MachinePrecision] - 0.25), $MachinePrecision] * x + N[(-0.6666666666666666 * N[(eps * eps), $MachinePrecision] + 0.6666666666666666), $MachinePrecision]), $MachinePrecision] * x + N[(N[(eps * eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.02e-156], N[(N[(N[(N[(x * x), $MachinePrecision] * N[(eps + 1.0), $MachinePrecision]), $MachinePrecision] * N[(eps - 1.0), $MachinePrecision] + 2.0), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 125000000000.0], N[(N[(N[(N[(N[(N[(N[(x * t$95$0), $MachinePrecision] - 0.6666666666666666), $MachinePrecision] * N[(eps * eps), $MachinePrecision] + N[(-0.125 * x + 0.3333333333333333), $MachinePrecision]), $MachinePrecision] * x + N[(N[(eps * eps), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] - N[(N[(-1.0 * x + -1.0), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(N[(eps * eps), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] / 2.0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(0.08333333333333333, \varepsilon \cdot \varepsilon, 0.16666666666666666\right)\\
\mathbf{if}\;x \leq -2.35 \cdot 10^{-132}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(t\_0 \cdot \left(\varepsilon \cdot \varepsilon\right) - 0.25, x, \mathsf{fma}\left(-0.6666666666666666, \varepsilon \cdot \varepsilon, 0.6666666666666666\right)\right), x, \varepsilon \cdot \varepsilon - 1\right), x \cdot x, 2\right)}{2}\\
\mathbf{elif}\;x \leq 1.02 \cdot 10^{-156}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(\varepsilon + 1\right), \varepsilon - 1, 2\right)}{2}\\
\mathbf{elif}\;x \leq 125000000000:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot t\_0 - 0.6666666666666666, \varepsilon \cdot \varepsilon, \mathsf{fma}\left(-0.125, x, 0.3333333333333333\right)\right), x, \varepsilon \cdot \varepsilon - 0.5\right), x \cdot x, 1\right) - \frac{\mathsf{fma}\left(-1, x, -1\right)}{e^{x}}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(\varepsilon \cdot \varepsilon\right) \cdot x\right) \cdot x}{2}\\
\end{array}
\end{array}
if x < -2.3500000000000001e-132Initial program 79.8%
Taylor expanded in eps around 0
Applied rewrites29.2%
Taylor expanded in x around 0
Applied rewrites95.3%
if -2.3500000000000001e-132 < x < 1.02e-156Initial program 51.6%
Taylor expanded in eps around 0
Applied rewrites76.4%
Taylor expanded in x around 0
Applied rewrites79.2%
Applied rewrites92.0%
if 1.02e-156 < x < 1.25e11Initial program 63.4%
Taylor expanded in eps around 0
Applied rewrites76.0%
Taylor expanded in x around 0
Applied rewrites60.0%
Taylor expanded in eps around 0
Applied rewrites93.3%
if 1.25e11 < x Initial program 100.0%
Taylor expanded in eps around 0
Applied rewrites8.4%
Taylor expanded in x around 0
Applied rewrites47.0%
Taylor expanded in eps around inf
Applied rewrites67.7%
(FPCore (x eps)
:precision binary64
(if (<= x -2.35e-132)
(/
(fma
(fma
(fma
(-
(*
(fma 0.08333333333333333 (* eps eps) 0.16666666666666666)
(* eps eps))
0.25)
x
(fma -0.6666666666666666 (* eps eps) 0.6666666666666666))
x
(- (* eps eps) 1.0))
(* x x)
2.0)
2.0)
(if (<= x 1.02e-156)
(/ (fma (* (* x x) (+ eps 1.0)) (- eps 1.0) 2.0) 2.0)
(if (<= x 38.0)
(/
(fma (/ (* (+ eps 1.0) (fma eps eps -1.0)) (+ eps 1.0)) (* x x) 2.0)
2.0)
(/ (* (* (* eps eps) x) x) 2.0)))))
double code(double x, double eps) {
double tmp;
if (x <= -2.35e-132) {
tmp = fma(fma(fma(((fma(0.08333333333333333, (eps * eps), 0.16666666666666666) * (eps * eps)) - 0.25), x, fma(-0.6666666666666666, (eps * eps), 0.6666666666666666)), x, ((eps * eps) - 1.0)), (x * x), 2.0) / 2.0;
} else if (x <= 1.02e-156) {
tmp = fma(((x * x) * (eps + 1.0)), (eps - 1.0), 2.0) / 2.0;
} else if (x <= 38.0) {
tmp = fma((((eps + 1.0) * fma(eps, eps, -1.0)) / (eps + 1.0)), (x * x), 2.0) / 2.0;
} else {
tmp = (((eps * eps) * x) * x) / 2.0;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -2.35e-132) tmp = Float64(fma(fma(fma(Float64(Float64(fma(0.08333333333333333, Float64(eps * eps), 0.16666666666666666) * Float64(eps * eps)) - 0.25), x, fma(-0.6666666666666666, Float64(eps * eps), 0.6666666666666666)), x, Float64(Float64(eps * eps) - 1.0)), Float64(x * x), 2.0) / 2.0); elseif (x <= 1.02e-156) tmp = Float64(fma(Float64(Float64(x * x) * Float64(eps + 1.0)), Float64(eps - 1.0), 2.0) / 2.0); elseif (x <= 38.0) tmp = Float64(fma(Float64(Float64(Float64(eps + 1.0) * fma(eps, eps, -1.0)) / Float64(eps + 1.0)), Float64(x * x), 2.0) / 2.0); else tmp = Float64(Float64(Float64(Float64(eps * eps) * x) * x) / 2.0); end return tmp end
code[x_, eps_] := If[LessEqual[x, -2.35e-132], N[(N[(N[(N[(N[(N[(N[(0.08333333333333333 * N[(eps * eps), $MachinePrecision] + 0.16666666666666666), $MachinePrecision] * N[(eps * eps), $MachinePrecision]), $MachinePrecision] - 0.25), $MachinePrecision] * x + N[(-0.6666666666666666 * N[(eps * eps), $MachinePrecision] + 0.6666666666666666), $MachinePrecision]), $MachinePrecision] * x + N[(N[(eps * eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.02e-156], N[(N[(N[(N[(x * x), $MachinePrecision] * N[(eps + 1.0), $MachinePrecision]), $MachinePrecision] * N[(eps - 1.0), $MachinePrecision] + 2.0), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 38.0], N[(N[(N[(N[(N[(eps + 1.0), $MachinePrecision] * N[(eps * eps + -1.0), $MachinePrecision]), $MachinePrecision] / N[(eps + 1.0), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(N[(eps * eps), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] / 2.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.35 \cdot 10^{-132}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.08333333333333333, \varepsilon \cdot \varepsilon, 0.16666666666666666\right) \cdot \left(\varepsilon \cdot \varepsilon\right) - 0.25, x, \mathsf{fma}\left(-0.6666666666666666, \varepsilon \cdot \varepsilon, 0.6666666666666666\right)\right), x, \varepsilon \cdot \varepsilon - 1\right), x \cdot x, 2\right)}{2}\\
\mathbf{elif}\;x \leq 1.02 \cdot 10^{-156}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(\varepsilon + 1\right), \varepsilon - 1, 2\right)}{2}\\
\mathbf{elif}\;x \leq 38:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{\left(\varepsilon + 1\right) \cdot \mathsf{fma}\left(\varepsilon, \varepsilon, -1\right)}{\varepsilon + 1}, x \cdot x, 2\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(\varepsilon \cdot \varepsilon\right) \cdot x\right) \cdot x}{2}\\
\end{array}
\end{array}
if x < -2.3500000000000001e-132Initial program 79.8%
Taylor expanded in eps around 0
Applied rewrites29.2%
Taylor expanded in x around 0
Applied rewrites95.3%
if -2.3500000000000001e-132 < x < 1.02e-156Initial program 51.6%
Taylor expanded in eps around 0
Applied rewrites76.4%
Taylor expanded in x around 0
Applied rewrites79.2%
Applied rewrites92.0%
if 1.02e-156 < x < 38Initial program 61.7%
Taylor expanded in eps around 0
Applied rewrites79.4%
Taylor expanded in x around 0
Applied rewrites88.0%
Applied rewrites94.5%
if 38 < x Initial program 100.0%
Taylor expanded in eps around 0
Applied rewrites8.2%
Taylor expanded in x around 0
Applied rewrites45.9%
Taylor expanded in eps around inf
Applied rewrites66.0%
(FPCore (x eps)
:precision binary64
(let* ((t_0
(/
(fma (/ (* (+ eps 1.0) (fma eps eps -1.0)) (+ eps 1.0)) (* x x) 2.0)
2.0)))
(if (<= x -2.3e-132)
t_0
(if (<= x 1.02e-156)
(/ (fma (* (* x x) (+ eps 1.0)) (- eps 1.0) 2.0) 2.0)
(if (<= x 38.0) t_0 (/ (* (* (* eps eps) x) x) 2.0))))))
double code(double x, double eps) {
double t_0 = fma((((eps + 1.0) * fma(eps, eps, -1.0)) / (eps + 1.0)), (x * x), 2.0) / 2.0;
double tmp;
if (x <= -2.3e-132) {
tmp = t_0;
} else if (x <= 1.02e-156) {
tmp = fma(((x * x) * (eps + 1.0)), (eps - 1.0), 2.0) / 2.0;
} else if (x <= 38.0) {
tmp = t_0;
} else {
tmp = (((eps * eps) * x) * x) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(fma(Float64(Float64(Float64(eps + 1.0) * fma(eps, eps, -1.0)) / Float64(eps + 1.0)), Float64(x * x), 2.0) / 2.0) tmp = 0.0 if (x <= -2.3e-132) tmp = t_0; elseif (x <= 1.02e-156) tmp = Float64(fma(Float64(Float64(x * x) * Float64(eps + 1.0)), Float64(eps - 1.0), 2.0) / 2.0); elseif (x <= 38.0) tmp = t_0; else tmp = Float64(Float64(Float64(Float64(eps * eps) * x) * x) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(N[(N[(N[(eps + 1.0), $MachinePrecision] * N[(eps * eps + -1.0), $MachinePrecision]), $MachinePrecision] / N[(eps + 1.0), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision] / 2.0), $MachinePrecision]}, If[LessEqual[x, -2.3e-132], t$95$0, If[LessEqual[x, 1.02e-156], N[(N[(N[(N[(x * x), $MachinePrecision] * N[(eps + 1.0), $MachinePrecision]), $MachinePrecision] * N[(eps - 1.0), $MachinePrecision] + 2.0), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 38.0], t$95$0, N[(N[(N[(N[(eps * eps), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] / 2.0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(\frac{\left(\varepsilon + 1\right) \cdot \mathsf{fma}\left(\varepsilon, \varepsilon, -1\right)}{\varepsilon + 1}, x \cdot x, 2\right)}{2}\\
\mathbf{if}\;x \leq -2.3 \cdot 10^{-132}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.02 \cdot 10^{-156}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(\varepsilon + 1\right), \varepsilon - 1, 2\right)}{2}\\
\mathbf{elif}\;x \leq 38:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(\varepsilon \cdot \varepsilon\right) \cdot x\right) \cdot x}{2}\\
\end{array}
\end{array}
if x < -2.30000000000000003e-132 or 1.02e-156 < x < 38Initial program 72.7%
Taylor expanded in eps around 0
Applied rewrites48.8%
Taylor expanded in x around 0
Applied rewrites86.1%
Applied rewrites91.8%
if -2.30000000000000003e-132 < x < 1.02e-156Initial program 51.6%
Taylor expanded in eps around 0
Applied rewrites76.4%
Taylor expanded in x around 0
Applied rewrites79.2%
Applied rewrites92.0%
if 38 < x Initial program 100.0%
Taylor expanded in eps around 0
Applied rewrites8.2%
Taylor expanded in x around 0
Applied rewrites45.9%
Taylor expanded in eps around inf
Applied rewrites66.0%
(FPCore (x eps)
:precision binary64
(if (<= x 5e-231)
(/ (fma (* (* x x) (+ eps 1.0)) (- eps 1.0) 2.0) 2.0)
(if (<= x 1.4)
(/ (fma (* (fma eps eps -1.0) x) x 2.0) 2.0)
(/ (* (* (* eps eps) x) x) 2.0))))
double code(double x, double eps) {
double tmp;
if (x <= 5e-231) {
tmp = fma(((x * x) * (eps + 1.0)), (eps - 1.0), 2.0) / 2.0;
} else if (x <= 1.4) {
tmp = fma((fma(eps, eps, -1.0) * x), x, 2.0) / 2.0;
} else {
tmp = (((eps * eps) * x) * x) / 2.0;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 5e-231) tmp = Float64(fma(Float64(Float64(x * x) * Float64(eps + 1.0)), Float64(eps - 1.0), 2.0) / 2.0); elseif (x <= 1.4) tmp = Float64(fma(Float64(fma(eps, eps, -1.0) * x), x, 2.0) / 2.0); else tmp = Float64(Float64(Float64(Float64(eps * eps) * x) * x) / 2.0); end return tmp end
code[x_, eps_] := If[LessEqual[x, 5e-231], N[(N[(N[(N[(x * x), $MachinePrecision] * N[(eps + 1.0), $MachinePrecision]), $MachinePrecision] * N[(eps - 1.0), $MachinePrecision] + 2.0), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.4], N[(N[(N[(N[(eps * eps + -1.0), $MachinePrecision] * x), $MachinePrecision] * x + 2.0), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(N[(eps * eps), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5 \cdot 10^{-231}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\left(x \cdot x\right) \cdot \left(\varepsilon + 1\right), \varepsilon - 1, 2\right)}{2}\\
\mathbf{elif}\;x \leq 1.4:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(\varepsilon, \varepsilon, -1\right) \cdot x, x, 2\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(\varepsilon \cdot \varepsilon\right) \cdot x\right) \cdot x}{2}\\
\end{array}
\end{array}
if x < 5.00000000000000023e-231Initial program 65.7%
Taylor expanded in eps around 0
Applied rewrites52.4%
Taylor expanded in x around 0
Applied rewrites83.3%
Applied rewrites89.0%
if 5.00000000000000023e-231 < x < 1.3999999999999999Initial program 61.3%
Taylor expanded in eps around 0
Applied rewrites76.6%
Taylor expanded in x around 0
Applied rewrites83.3%
Applied rewrites88.8%
if 1.3999999999999999 < x Initial program 100.0%
Taylor expanded in eps around 0
Applied rewrites8.2%
Taylor expanded in x around 0
Applied rewrites45.9%
Taylor expanded in eps around inf
Applied rewrites66.0%
(FPCore (x eps) :precision binary64 (if (<= x 1.4) (/ (fma (* (fma eps eps -1.0) x) x 2.0) 2.0) (/ (* (* (* eps eps) x) x) 2.0)))
double code(double x, double eps) {
double tmp;
if (x <= 1.4) {
tmp = fma((fma(eps, eps, -1.0) * x), x, 2.0) / 2.0;
} else {
tmp = (((eps * eps) * x) * x) / 2.0;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 1.4) tmp = Float64(fma(Float64(fma(eps, eps, -1.0) * x), x, 2.0) / 2.0); else tmp = Float64(Float64(Float64(Float64(eps * eps) * x) * x) / 2.0); end return tmp end
code[x_, eps_] := If[LessEqual[x, 1.4], N[(N[(N[(N[(eps * eps + -1.0), $MachinePrecision] * x), $MachinePrecision] * x + 2.0), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(N[(eps * eps), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.4:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(\varepsilon, \varepsilon, -1\right) \cdot x, x, 2\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\left(\varepsilon \cdot \varepsilon\right) \cdot x\right) \cdot x}{2}\\
\end{array}
\end{array}
if x < 1.3999999999999999Initial program 64.3%
Taylor expanded in eps around 0
Applied rewrites59.7%
Taylor expanded in x around 0
Applied rewrites83.3%
Applied rewrites86.3%
if 1.3999999999999999 < x Initial program 100.0%
Taylor expanded in eps around 0
Applied rewrites8.2%
Taylor expanded in x around 0
Applied rewrites45.9%
Taylor expanded in eps around inf
Applied rewrites66.0%
(FPCore (x eps) :precision binary64 (let* ((t_0 (* (* eps eps) x))) (if (<= x 44.0) (/ (fma t_0 x 2.0) 2.0) (/ (* t_0 x) 2.0))))
double code(double x, double eps) {
double t_0 = (eps * eps) * x;
double tmp;
if (x <= 44.0) {
tmp = fma(t_0, x, 2.0) / 2.0;
} else {
tmp = (t_0 * x) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(eps * eps) * x) tmp = 0.0 if (x <= 44.0) tmp = Float64(fma(t_0, x, 2.0) / 2.0); else tmp = Float64(Float64(t_0 * x) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(eps * eps), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, 44.0], N[(N[(t$95$0 * x + 2.0), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(t$95$0 * x), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\varepsilon \cdot \varepsilon\right) \cdot x\\
\mathbf{if}\;x \leq 44:\\
\;\;\;\;\frac{\mathsf{fma}\left(t\_0, x, 2\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 \cdot x}{2}\\
\end{array}
\end{array}
if x < 44Initial program 64.3%
Taylor expanded in eps around 0
Applied rewrites59.7%
Taylor expanded in x around 0
Applied rewrites83.3%
Applied rewrites86.3%
Taylor expanded in eps around inf
Applied rewrites86.0%
if 44 < x Initial program 100.0%
Taylor expanded in eps around 0
Applied rewrites8.2%
Taylor expanded in x around 0
Applied rewrites45.9%
Taylor expanded in eps around inf
Applied rewrites66.0%
(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 74.6%
Taylor expanded in x around 0
Applied rewrites42.3%
herbie shell --seed 2024351
(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))