
(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 12 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 (- x))))
(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)
(* (+ t_0 t_0) 0.5)
(* (+ (exp (* x eps)) (exp (* (- eps) x))) 0.5))))
double code(double x, double eps) {
double t_0 = exp(-x);
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 = (t_0 + t_0) * 0.5;
} else {
tmp = (exp((x * eps)) + exp((-eps * x))) * 0.5;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, eps)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = exp(-x)
if (((((1.0d0 + (1.0d0 / eps)) * exp((((-1.0d0) + eps) * x))) - (((1.0d0 / eps) - 1.0d0) * exp((((-1.0d0) - eps) * x)))) / 2.0d0) <= 0.0d0) then
tmp = (t_0 + t_0) * 0.5d0
else
tmp = (exp((x * eps)) + exp((-eps * x))) * 0.5d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.exp(-x);
double tmp;
if (((((1.0 + (1.0 / eps)) * Math.exp(((-1.0 + eps) * x))) - (((1.0 / eps) - 1.0) * Math.exp(((-1.0 - eps) * x)))) / 2.0) <= 0.0) {
tmp = (t_0 + t_0) * 0.5;
} else {
tmp = (Math.exp((x * eps)) + Math.exp((-eps * x))) * 0.5;
}
return tmp;
}
def code(x, eps): t_0 = math.exp(-x) tmp = 0 if ((((1.0 + (1.0 / eps)) * math.exp(((-1.0 + eps) * x))) - (((1.0 / eps) - 1.0) * math.exp(((-1.0 - eps) * x)))) / 2.0) <= 0.0: tmp = (t_0 + t_0) * 0.5 else: tmp = (math.exp((x * eps)) + math.exp((-eps * x))) * 0.5 return tmp
function code(x, eps) t_0 = exp(Float64(-x)) tmp = 0.0 if (Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(Float64(Float64(1.0 / eps) - 1.0) * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0) <= 0.0) tmp = Float64(Float64(t_0 + t_0) * 0.5); else tmp = Float64(Float64(exp(Float64(x * eps)) + exp(Float64(Float64(-eps) * x))) * 0.5); end return tmp end
function tmp_2 = code(x, eps) t_0 = exp(-x); tmp = 0.0; if (((((1.0 + (1.0 / eps)) * exp(((-1.0 + eps) * x))) - (((1.0 / eps) - 1.0) * exp(((-1.0 - eps) * x)))) / 2.0) <= 0.0) tmp = (t_0 + t_0) * 0.5; else tmp = (exp((x * eps)) + exp((-eps * x))) * 0.5; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, If[LessEqual[N[(N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 0.0], N[(N[(t$95$0 + t$95$0), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[Exp[N[(x * eps), $MachinePrecision]], $MachinePrecision] + N[Exp[N[((-eps) * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-x}\\
\mathbf{if}\;\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{\left(-1 - \varepsilon\right) \cdot x}}{2} \leq 0:\\
\;\;\;\;\left(t\_0 + t\_0\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(e^{x \cdot \varepsilon} + e^{\left(-\varepsilon\right) \cdot x}\right) \cdot 0.5\\
\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 42.6%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.6%
Taylor expanded in eps around 0
mul-1-negN/A
lower-+.f64N/A
lower-exp.f64N/A
lift-neg.f64N/A
lower-exp.f64N/A
lift-neg.f6499.6
Applied rewrites99.6%
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.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites98.7%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f6498.7
Applied rewrites98.7%
Taylor expanded in eps around inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f6498.7
Applied rewrites98.7%
Final simplification99.1%
(FPCore (x eps) :precision binary64 (* (+ (exp (* x (+ -1.0 eps))) (exp (- (fma x eps x)))) 0.5))
double code(double x, double eps) {
return (exp((x * (-1.0 + eps))) + exp(-fma(x, eps, x))) * 0.5;
}
function code(x, eps) return Float64(Float64(exp(Float64(x * Float64(-1.0 + eps))) + exp(Float64(-fma(x, eps, x)))) * 0.5) end
code[x_, eps_] := N[(N[(N[Exp[N[(x * N[(-1.0 + eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[Exp[(-N[(x * eps + x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
\\
\left(e^{x \cdot \left(-1 + \varepsilon\right)} + e^{-\mathsf{fma}\left(x, \varepsilon, x\right)}\right) \cdot 0.5
\end{array}
Initial program 75.7%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.0%
Final simplification99.0%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ 1.0 (/ 1.0 eps))))
(if (<= x -7.5e-250)
(* (+ 1.0 (exp (* (- eps) x))) 0.5)
(if (<= x 0.00039)
(* (- (exp (* x eps)) (- (* x eps) 1.0)) 0.5)
(if (<= x 3.2e+137)
(/
(+
(* t_0 (exp (* (- eps) (- x))))
(* (- (/ -1.0 eps) -1.0) (fma -1.0 (* x eps) 1.0)))
2.0)
(/
(-
(* t_0 (fma (- eps 1.0) x 1.0))
(* (- (/ 1.0 eps) 1.0) (fma -1.0 x 1.0)))
2.0))))))
double code(double x, double eps) {
double t_0 = 1.0 + (1.0 / eps);
double tmp;
if (x <= -7.5e-250) {
tmp = (1.0 + exp((-eps * x))) * 0.5;
} else if (x <= 0.00039) {
tmp = (exp((x * eps)) - ((x * eps) - 1.0)) * 0.5;
} else if (x <= 3.2e+137) {
tmp = ((t_0 * exp((-eps * -x))) + (((-1.0 / eps) - -1.0) * fma(-1.0, (x * eps), 1.0))) / 2.0;
} else {
tmp = ((t_0 * fma((eps - 1.0), x, 1.0)) - (((1.0 / eps) - 1.0) * fma(-1.0, x, 1.0))) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(1.0 + Float64(1.0 / eps)) tmp = 0.0 if (x <= -7.5e-250) tmp = Float64(Float64(1.0 + exp(Float64(Float64(-eps) * x))) * 0.5); elseif (x <= 0.00039) tmp = Float64(Float64(exp(Float64(x * eps)) - Float64(Float64(x * eps) - 1.0)) * 0.5); elseif (x <= 3.2e+137) tmp = Float64(Float64(Float64(t_0 * exp(Float64(Float64(-eps) * Float64(-x)))) + Float64(Float64(Float64(-1.0 / eps) - -1.0) * fma(-1.0, Float64(x * eps), 1.0))) / 2.0); else tmp = Float64(Float64(Float64(t_0 * fma(Float64(eps - 1.0), x, 1.0)) - Float64(Float64(Float64(1.0 / eps) - 1.0) * fma(-1.0, x, 1.0))) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -7.5e-250], N[(N[(1.0 + N[Exp[N[((-eps) * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 0.00039], N[(N[(N[Exp[N[(x * eps), $MachinePrecision]], $MachinePrecision] - N[(N[(x * eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 3.2e+137], N[(N[(N[(t$95$0 * N[Exp[N[((-eps) * (-x)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(-1.0 / eps), $MachinePrecision] - -1.0), $MachinePrecision] * N[(-1.0 * N[(x * eps), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(t$95$0 * N[(N[(eps - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision] * N[(-1.0 * x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{1}{\varepsilon}\\
\mathbf{if}\;x \leq -7.5 \cdot 10^{-250}:\\
\;\;\;\;\left(1 + e^{\left(-\varepsilon\right) \cdot x}\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 0.00039:\\
\;\;\;\;\left(e^{x \cdot \varepsilon} - \left(x \cdot \varepsilon - 1\right)\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{+137}:\\
\;\;\;\;\frac{t\_0 \cdot e^{\left(-\varepsilon\right) \cdot \left(-x\right)} + \left(\frac{-1}{\varepsilon} - -1\right) \cdot \mathsf{fma}\left(-1, x \cdot \varepsilon, 1\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 \cdot \mathsf{fma}\left(\varepsilon - 1, x, 1\right) - \left(\frac{1}{\varepsilon} - 1\right) \cdot \mathsf{fma}\left(-1, x, 1\right)}{2}\\
\end{array}
\end{array}
if x < -7.50000000000000009e-250Initial program 74.3%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites97.7%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f6497.7
Applied rewrites97.7%
Taylor expanded in eps around inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f6497.8
Applied rewrites97.8%
Taylor expanded in x around 0
Applied rewrites61.0%
if -7.50000000000000009e-250 < x < 3.89999999999999993e-4Initial program 52.7%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.5%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f6499.5
Applied rewrites99.5%
Taylor expanded in x around 0
*-commutativeN/A
+-commutativeN/A
distribute-rgt1-inN/A
+-commutativeN/A
*-commutativeN/A
lower--.f64N/A
lift-fma.f6494.8
Applied rewrites94.8%
Taylor expanded in eps around inf
*-commutativeN/A
lift-*.f6495.2
Applied rewrites95.2%
if 3.89999999999999993e-4 < x < 3.20000000000000019e137Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
distribute-rgt1-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6416.7
Applied rewrites16.7%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f6416.8
Applied rewrites16.8%
Taylor expanded in eps around inf
mul-1-negN/A
lower-neg.f6457.4
Applied rewrites57.4%
if 3.20000000000000019e137 < x Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
distribute-rgt1-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6432.3
Applied rewrites32.3%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6414.4
Applied rewrites14.4%
Taylor expanded in eps around 0
Applied rewrites31.3%
Final simplification66.5%
(FPCore (x eps)
:precision binary64
(if (<= x -2.35e+21)
(* (- (exp (* (- x) 1.0)) -1.0) 0.5)
(if (<= x -6.2e-183)
(* (fma (fma -1.0 (/ (- (* eps eps) 1.0) (- eps 1.0)) eps) x 2.0) 0.5)
(* (- (exp (* x eps)) -1.0) 0.5))))
double code(double x, double eps) {
double tmp;
if (x <= -2.35e+21) {
tmp = (exp((-x * 1.0)) - -1.0) * 0.5;
} else if (x <= -6.2e-183) {
tmp = fma(fma(-1.0, (((eps * eps) - 1.0) / (eps - 1.0)), eps), x, 2.0) * 0.5;
} else {
tmp = (exp((x * eps)) - -1.0) * 0.5;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -2.35e+21) tmp = Float64(Float64(exp(Float64(Float64(-x) * 1.0)) - -1.0) * 0.5); elseif (x <= -6.2e-183) tmp = Float64(fma(fma(-1.0, Float64(Float64(Float64(eps * eps) - 1.0) / Float64(eps - 1.0)), eps), x, 2.0) * 0.5); else tmp = Float64(Float64(exp(Float64(x * eps)) - -1.0) * 0.5); end return tmp end
code[x_, eps_] := If[LessEqual[x, -2.35e+21], N[(N[(N[Exp[N[((-x) * 1.0), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, -6.2e-183], N[(N[(N[(-1.0 * N[(N[(N[(eps * eps), $MachinePrecision] - 1.0), $MachinePrecision] / N[(eps - 1.0), $MachinePrecision]), $MachinePrecision] + eps), $MachinePrecision] * x + 2.0), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[Exp[N[(x * eps), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision] * 0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.35 \cdot 10^{+21}:\\
\;\;\;\;\left(e^{\left(-x\right) \cdot 1} - -1\right) \cdot 0.5\\
\mathbf{elif}\;x \leq -6.2 \cdot 10^{-183}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-1, \frac{\varepsilon \cdot \varepsilon - 1}{\varepsilon - 1}, \varepsilon\right), x, 2\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(e^{x \cdot \varepsilon} - -1\right) \cdot 0.5\\
\end{array}
\end{array}
if x < -2.35e21Initial program 100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites50.3%
Taylor expanded in eps around 0
Applied rewrites100.0%
if -2.35e21 < x < -6.19999999999999999e-183Initial program 66.6%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites94.6%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6439.2
Applied rewrites39.2%
lift-+.f64N/A
flip-+N/A
lower-/.f64N/A
unpow2N/A
metadata-evalN/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
lower--.f6451.4
Applied rewrites51.4%
Taylor expanded in eps around inf
Applied rewrites51.4%
if -6.19999999999999999e-183 < x Initial program 72.7%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.8%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f6482.0
Applied rewrites82.0%
Taylor expanded in x around 0
*-commutativeN/A
+-commutativeN/A
distribute-rgt1-inN/A
+-commutativeN/A
*-commutativeN/A
lower--.f64N/A
lift-fma.f6462.7
Applied rewrites62.7%
Taylor expanded in x around 0
Applied rewrites61.7%
(FPCore (x eps) :precision binary64 (if (<= x -6.5e-250) (* (+ 1.0 (exp (* (- eps) x))) 0.5) (* (- (exp (* x eps)) -1.0) 0.5)))
double code(double x, double eps) {
double tmp;
if (x <= -6.5e-250) {
tmp = (1.0 + exp((-eps * x))) * 0.5;
} else {
tmp = (exp((x * eps)) - -1.0) * 0.5;
}
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 <= (-6.5d-250)) then
tmp = (1.0d0 + exp((-eps * x))) * 0.5d0
else
tmp = (exp((x * eps)) - (-1.0d0)) * 0.5d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= -6.5e-250) {
tmp = (1.0 + Math.exp((-eps * x))) * 0.5;
} else {
tmp = (Math.exp((x * eps)) - -1.0) * 0.5;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= -6.5e-250: tmp = (1.0 + math.exp((-eps * x))) * 0.5 else: tmp = (math.exp((x * eps)) - -1.0) * 0.5 return tmp
function code(x, eps) tmp = 0.0 if (x <= -6.5e-250) tmp = Float64(Float64(1.0 + exp(Float64(Float64(-eps) * x))) * 0.5); else tmp = Float64(Float64(exp(Float64(x * eps)) - -1.0) * 0.5); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= -6.5e-250) tmp = (1.0 + exp((-eps * x))) * 0.5; else tmp = (exp((x * eps)) - -1.0) * 0.5; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, -6.5e-250], N[(N[(1.0 + N[Exp[N[((-eps) * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[Exp[N[(x * eps), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{-250}:\\
\;\;\;\;\left(1 + e^{\left(-\varepsilon\right) \cdot x}\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(e^{x \cdot \varepsilon} - -1\right) \cdot 0.5\\
\end{array}
\end{array}
if x < -6.49999999999999942e-250Initial program 74.3%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites97.7%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f6497.7
Applied rewrites97.7%
Taylor expanded in eps around inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f6497.8
Applied rewrites97.8%
Taylor expanded in x around 0
Applied rewrites61.0%
if -6.49999999999999942e-250 < x Initial program 76.5%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.7%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f6480.3
Applied rewrites80.3%
Taylor expanded in x around 0
*-commutativeN/A
+-commutativeN/A
distribute-rgt1-inN/A
+-commutativeN/A
*-commutativeN/A
lower--.f64N/A
lift-fma.f6459.6
Applied rewrites59.6%
Taylor expanded in x around 0
Applied rewrites58.5%
Final simplification59.4%
(FPCore (x eps) :precision binary64 (if (<= x -6.2e-183) (* (fma (fma -1.0 (/ (- (* eps eps) 1.0) (- eps 1.0)) eps) x 2.0) 0.5) (* (- (exp (* x eps)) -1.0) 0.5)))
double code(double x, double eps) {
double tmp;
if (x <= -6.2e-183) {
tmp = fma(fma(-1.0, (((eps * eps) - 1.0) / (eps - 1.0)), eps), x, 2.0) * 0.5;
} else {
tmp = (exp((x * eps)) - -1.0) * 0.5;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -6.2e-183) tmp = Float64(fma(fma(-1.0, Float64(Float64(Float64(eps * eps) - 1.0) / Float64(eps - 1.0)), eps), x, 2.0) * 0.5); else tmp = Float64(Float64(exp(Float64(x * eps)) - -1.0) * 0.5); end return tmp end
code[x_, eps_] := If[LessEqual[x, -6.2e-183], N[(N[(N[(-1.0 * N[(N[(N[(eps * eps), $MachinePrecision] - 1.0), $MachinePrecision] / N[(eps - 1.0), $MachinePrecision]), $MachinePrecision] + eps), $MachinePrecision] * x + 2.0), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[Exp[N[(x * eps), $MachinePrecision]], $MachinePrecision] - -1.0), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{-183}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-1, \frac{\varepsilon \cdot \varepsilon - 1}{\varepsilon - 1}, \varepsilon\right), x, 2\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(e^{x \cdot \varepsilon} - -1\right) \cdot 0.5\\
\end{array}
\end{array}
if x < -6.19999999999999999e-183Initial program 83.1%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites97.2%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6421.6
Applied rewrites21.6%
lift-+.f64N/A
flip-+N/A
lower-/.f64N/A
unpow2N/A
metadata-evalN/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
lower--.f6443.0
Applied rewrites43.0%
Taylor expanded in eps around inf
Applied rewrites43.0%
if -6.19999999999999999e-183 < x Initial program 72.7%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.8%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f6482.0
Applied rewrites82.0%
Taylor expanded in x around 0
*-commutativeN/A
+-commutativeN/A
distribute-rgt1-inN/A
+-commutativeN/A
*-commutativeN/A
lower--.f64N/A
lift-fma.f6462.7
Applied rewrites62.7%
Taylor expanded in x around 0
Applied rewrites61.7%
(FPCore (x eps)
:precision binary64
(if (<= x -6.2e-183)
(* (fma (fma -1.0 (/ (- (* eps eps) 1.0) (- eps 1.0)) eps) x 2.0) 0.5)
(if (<= x 1.9e-248)
(* (- 1.0 (- (fma x eps x) 1.0)) 0.5)
(if (<= x 820.0)
(*
(fma
(fma -1.0 (- eps -1.0) (/ (+ -1.0 (* eps eps)) (- eps -1.0)))
x
2.0)
0.5)
(/
(-
(* (+ 1.0 (/ 1.0 eps)) (fma (- eps 1.0) x 1.0))
(* (- (/ 1.0 eps) 1.0) (fma -1.0 x 1.0)))
2.0)))))
double code(double x, double eps) {
double tmp;
if (x <= -6.2e-183) {
tmp = fma(fma(-1.0, (((eps * eps) - 1.0) / (eps - 1.0)), eps), x, 2.0) * 0.5;
} else if (x <= 1.9e-248) {
tmp = (1.0 - (fma(x, eps, x) - 1.0)) * 0.5;
} else if (x <= 820.0) {
tmp = fma(fma(-1.0, (eps - -1.0), ((-1.0 + (eps * eps)) / (eps - -1.0))), x, 2.0) * 0.5;
} else {
tmp = (((1.0 + (1.0 / eps)) * fma((eps - 1.0), x, 1.0)) - (((1.0 / eps) - 1.0) * fma(-1.0, x, 1.0))) / 2.0;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -6.2e-183) tmp = Float64(fma(fma(-1.0, Float64(Float64(Float64(eps * eps) - 1.0) / Float64(eps - 1.0)), eps), x, 2.0) * 0.5); elseif (x <= 1.9e-248) tmp = Float64(Float64(1.0 - Float64(fma(x, eps, x) - 1.0)) * 0.5); elseif (x <= 820.0) tmp = Float64(fma(fma(-1.0, Float64(eps - -1.0), Float64(Float64(-1.0 + Float64(eps * eps)) / Float64(eps - -1.0))), x, 2.0) * 0.5); else tmp = Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * fma(Float64(eps - 1.0), x, 1.0)) - Float64(Float64(Float64(1.0 / eps) - 1.0) * fma(-1.0, x, 1.0))) / 2.0); end return tmp end
code[x_, eps_] := If[LessEqual[x, -6.2e-183], N[(N[(N[(-1.0 * N[(N[(N[(eps * eps), $MachinePrecision] - 1.0), $MachinePrecision] / N[(eps - 1.0), $MachinePrecision]), $MachinePrecision] + eps), $MachinePrecision] * x + 2.0), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 1.9e-248], N[(N[(1.0 - N[(N[(x * eps + x), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 820.0], N[(N[(N[(-1.0 * N[(eps - -1.0), $MachinePrecision] + N[(N[(-1.0 + N[(eps * eps), $MachinePrecision]), $MachinePrecision] / N[(eps - -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x + 2.0), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[(N[(eps - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision] * N[(-1.0 * x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{-183}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-1, \frac{\varepsilon \cdot \varepsilon - 1}{\varepsilon - 1}, \varepsilon\right), x, 2\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{-248}:\\
\;\;\;\;\left(1 - \left(\mathsf{fma}\left(x, \varepsilon, x\right) - 1\right)\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 820:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-1, \varepsilon - -1, \frac{-1 + \varepsilon \cdot \varepsilon}{\varepsilon - -1}\right), x, 2\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot \mathsf{fma}\left(\varepsilon - 1, x, 1\right) - \left(\frac{1}{\varepsilon} - 1\right) \cdot \mathsf{fma}\left(-1, x, 1\right)}{2}\\
\end{array}
\end{array}
if x < -6.19999999999999999e-183Initial program 83.1%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites97.2%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6421.6
Applied rewrites21.6%
lift-+.f64N/A
flip-+N/A
lower-/.f64N/A
unpow2N/A
metadata-evalN/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
lower--.f6443.0
Applied rewrites43.0%
Taylor expanded in eps around inf
Applied rewrites43.0%
if -6.19999999999999999e-183 < x < 1.8999999999999999e-248Initial program 52.6%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
*-commutativeN/A
+-commutativeN/A
distribute-rgt1-inN/A
+-commutativeN/A
*-commutativeN/A
lower--.f64N/A
lift-fma.f6498.4
Applied rewrites98.4%
Taylor expanded in x around 0
Applied rewrites96.3%
if 1.8999999999999999e-248 < x < 820Initial program 47.8%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.2%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6478.6
Applied rewrites78.6%
lift--.f64N/A
flip--N/A
lower-/.f64N/A
metadata-evalN/A
unpow2N/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
+-commutativeN/A
lift-+.f6487.8
Applied rewrites87.8%
if 820 < x Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
distribute-rgt1-inN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6423.7
Applied rewrites23.7%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6421.2
Applied rewrites21.2%
Taylor expanded in eps around 0
Applied rewrites33.5%
Final simplification58.9%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (* eps eps) 1.0)))
(if (<= x -6.2e-183)
(* (fma (fma -1.0 (/ t_0 (- eps 1.0)) eps) x 2.0) 0.5)
(if (<= x 8.5e-244)
(* (- 1.0 (- (fma x eps x) 1.0)) 0.5)
(* (fma (fma -1.0 (/ t_0 -1.0) (+ -1.0 eps)) x 2.0) 0.5)))))
double code(double x, double eps) {
double t_0 = (eps * eps) - 1.0;
double tmp;
if (x <= -6.2e-183) {
tmp = fma(fma(-1.0, (t_0 / (eps - 1.0)), eps), x, 2.0) * 0.5;
} else if (x <= 8.5e-244) {
tmp = (1.0 - (fma(x, eps, x) - 1.0)) * 0.5;
} else {
tmp = fma(fma(-1.0, (t_0 / -1.0), (-1.0 + eps)), x, 2.0) * 0.5;
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(eps * eps) - 1.0) tmp = 0.0 if (x <= -6.2e-183) tmp = Float64(fma(fma(-1.0, Float64(t_0 / Float64(eps - 1.0)), eps), x, 2.0) * 0.5); elseif (x <= 8.5e-244) tmp = Float64(Float64(1.0 - Float64(fma(x, eps, x) - 1.0)) * 0.5); else tmp = Float64(fma(fma(-1.0, Float64(t_0 / -1.0), Float64(-1.0 + eps)), x, 2.0) * 0.5); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(eps * eps), $MachinePrecision] - 1.0), $MachinePrecision]}, If[LessEqual[x, -6.2e-183], N[(N[(N[(-1.0 * N[(t$95$0 / N[(eps - 1.0), $MachinePrecision]), $MachinePrecision] + eps), $MachinePrecision] * x + 2.0), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[x, 8.5e-244], N[(N[(1.0 - N[(N[(x * eps + x), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(-1.0 * N[(t$95$0 / -1.0), $MachinePrecision] + N[(-1.0 + eps), $MachinePrecision]), $MachinePrecision] * x + 2.0), $MachinePrecision] * 0.5), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \varepsilon \cdot \varepsilon - 1\\
\mathbf{if}\;x \leq -6.2 \cdot 10^{-183}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-1, \frac{t\_0}{\varepsilon - 1}, \varepsilon\right), x, 2\right) \cdot 0.5\\
\mathbf{elif}\;x \leq 8.5 \cdot 10^{-244}:\\
\;\;\;\;\left(1 - \left(\mathsf{fma}\left(x, \varepsilon, x\right) - 1\right)\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-1, \frac{t\_0}{-1}, -1 + \varepsilon\right), x, 2\right) \cdot 0.5\\
\end{array}
\end{array}
if x < -6.19999999999999999e-183Initial program 83.1%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites97.2%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6421.6
Applied rewrites21.6%
lift-+.f64N/A
flip-+N/A
lower-/.f64N/A
unpow2N/A
metadata-evalN/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
lower--.f6443.0
Applied rewrites43.0%
Taylor expanded in eps around inf
Applied rewrites43.0%
if -6.19999999999999999e-183 < x < 8.4999999999999999e-244Initial program 52.6%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
*-commutativeN/A
+-commutativeN/A
distribute-rgt1-inN/A
+-commutativeN/A
*-commutativeN/A
lower--.f64N/A
lift-fma.f6498.4
Applied rewrites98.4%
Taylor expanded in x around 0
Applied rewrites96.3%
if 8.4999999999999999e-244 < x Initial program 79.8%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.7%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6432.1
Applied rewrites32.1%
lift-+.f64N/A
flip-+N/A
lower-/.f64N/A
unpow2N/A
metadata-evalN/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
lower--.f6440.4
Applied rewrites40.4%
Taylor expanded in eps around 0
Applied rewrites59.3%
Final simplification61.3%
(FPCore (x eps) :precision binary64 (if (<= x -6.2e-183) (* (fma (fma -1.0 (/ (- (* eps eps) 1.0) (- eps 1.0)) eps) x 2.0) 0.5) (* (fma (fma -1.0 1.0 (+ -1.0 eps)) x 2.0) 0.5)))
double code(double x, double eps) {
double tmp;
if (x <= -6.2e-183) {
tmp = fma(fma(-1.0, (((eps * eps) - 1.0) / (eps - 1.0)), eps), x, 2.0) * 0.5;
} else {
tmp = fma(fma(-1.0, 1.0, (-1.0 + eps)), x, 2.0) * 0.5;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -6.2e-183) tmp = Float64(fma(fma(-1.0, Float64(Float64(Float64(eps * eps) - 1.0) / Float64(eps - 1.0)), eps), x, 2.0) * 0.5); else tmp = Float64(fma(fma(-1.0, 1.0, Float64(-1.0 + eps)), x, 2.0) * 0.5); end return tmp end
code[x_, eps_] := If[LessEqual[x, -6.2e-183], N[(N[(N[(-1.0 * N[(N[(N[(eps * eps), $MachinePrecision] - 1.0), $MachinePrecision] / N[(eps - 1.0), $MachinePrecision]), $MachinePrecision] + eps), $MachinePrecision] * x + 2.0), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(-1.0 * 1.0 + N[(-1.0 + eps), $MachinePrecision]), $MachinePrecision] * x + 2.0), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{-183}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-1, \frac{\varepsilon \cdot \varepsilon - 1}{\varepsilon - 1}, \varepsilon\right), x, 2\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-1, 1, -1 + \varepsilon\right), x, 2\right) \cdot 0.5\\
\end{array}
\end{array}
if x < -6.19999999999999999e-183Initial program 83.1%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites97.2%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6421.6
Applied rewrites21.6%
lift-+.f64N/A
flip-+N/A
lower-/.f64N/A
unpow2N/A
metadata-evalN/A
lower--.f64N/A
unpow2N/A
lower-*.f64N/A
lower--.f6443.0
Applied rewrites43.0%
Taylor expanded in eps around inf
Applied rewrites43.0%
if -6.19999999999999999e-183 < x Initial program 72.7%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.8%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6448.8
Applied rewrites48.8%
Taylor expanded in eps around 0
Applied rewrites54.2%
Final simplification50.9%
(FPCore (x eps) :precision binary64 (if (<= x -6.5e-250) (* (- 1.0 (- (fma x eps x) 1.0)) 0.5) (* (fma (fma -1.0 1.0 (+ -1.0 eps)) x 2.0) 0.5)))
double code(double x, double eps) {
double tmp;
if (x <= -6.5e-250) {
tmp = (1.0 - (fma(x, eps, x) - 1.0)) * 0.5;
} else {
tmp = fma(fma(-1.0, 1.0, (-1.0 + eps)), x, 2.0) * 0.5;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -6.5e-250) tmp = Float64(Float64(1.0 - Float64(fma(x, eps, x) - 1.0)) * 0.5); else tmp = Float64(fma(fma(-1.0, 1.0, Float64(-1.0 + eps)), x, 2.0) * 0.5); end return tmp end
code[x_, eps_] := If[LessEqual[x, -6.5e-250], N[(N[(1.0 - N[(N[(x * eps + x), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(-1.0 * 1.0 + N[(-1.0 + eps), $MachinePrecision]), $MachinePrecision] * x + 2.0), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{-250}:\\
\;\;\;\;\left(1 - \left(\mathsf{fma}\left(x, \varepsilon, x\right) - 1\right)\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-1, 1, -1 + \varepsilon\right), x, 2\right) \cdot 0.5\\
\end{array}
\end{array}
if x < -6.49999999999999942e-250Initial program 74.3%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites97.7%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f6497.7
Applied rewrites97.7%
Taylor expanded in x around 0
*-commutativeN/A
+-commutativeN/A
distribute-rgt1-inN/A
+-commutativeN/A
*-commutativeN/A
lower--.f64N/A
lift-fma.f6470.9
Applied rewrites70.9%
Taylor expanded in x around 0
Applied rewrites43.0%
if -6.49999999999999942e-250 < x Initial program 76.5%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.7%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lift--.f6444.9
Applied rewrites44.9%
Taylor expanded in eps around 0
Applied rewrites50.8%
Final simplification48.0%
(FPCore (x eps) :precision binary64 (* (- 1.0 (- (fma x eps x) 1.0)) 0.5))
double code(double x, double eps) {
return (1.0 - (fma(x, eps, x) - 1.0)) * 0.5;
}
function code(x, eps) return Float64(Float64(1.0 - Float64(fma(x, eps, x) - 1.0)) * 0.5) end
code[x_, eps_] := N[(N[(1.0 - N[(N[(x * eps + x), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
\\
\left(1 - \left(\mathsf{fma}\left(x, \varepsilon, x\right) - 1\right)\right) \cdot 0.5
\end{array}
Initial program 75.7%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f6486.5
Applied rewrites86.5%
Taylor expanded in x around 0
*-commutativeN/A
+-commutativeN/A
distribute-rgt1-inN/A
+-commutativeN/A
*-commutativeN/A
lower--.f64N/A
lift-fma.f6463.6
Applied rewrites63.6%
Taylor expanded in x around 0
Applied rewrites48.9%
Final simplification48.9%
(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 75.7%
Taylor expanded in x around 0
Applied rewrites41.1%
herbie shell --seed 2025051
(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))