
(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 10 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 (/ (- (exp (- (* x (- 1.0 eps)))) (* -1.0 (exp (- (* x (+ 1.0 eps)))))) 2.0))
double code(double x, double eps) {
return (exp(-(x * (1.0 - eps))) - (-1.0 * exp(-(x * (1.0 + eps))))) / 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 = (exp(-(x * (1.0d0 - eps))) - ((-1.0d0) * exp(-(x * (1.0d0 + eps))))) / 2.0d0
end function
public static double code(double x, double eps) {
return (Math.exp(-(x * (1.0 - eps))) - (-1.0 * Math.exp(-(x * (1.0 + eps))))) / 2.0;
}
def code(x, eps): return (math.exp(-(x * (1.0 - eps))) - (-1.0 * math.exp(-(x * (1.0 + eps))))) / 2.0
function code(x, eps) return Float64(Float64(exp(Float64(-Float64(x * Float64(1.0 - eps)))) - Float64(-1.0 * exp(Float64(-Float64(x * Float64(1.0 + eps)))))) / 2.0) end
function tmp = code(x, eps) tmp = (exp(-(x * (1.0 - eps))) - (-1.0 * exp(-(x * (1.0 + eps))))) / 2.0; end
code[x_, eps_] := N[(N[(N[Exp[(-N[(x * N[(1.0 - eps), $MachinePrecision]), $MachinePrecision])], $MachinePrecision] - N[(-1.0 * N[Exp[(-N[(x * N[(1.0 + eps), $MachinePrecision]), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{-x \cdot \left(1 - \varepsilon\right)} - -1 \cdot e^{-x \cdot \left(1 + \varepsilon\right)}}{2}
\end{array}
Initial program 68.9%
Taylor expanded in eps around inf
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower-+.f6498.5
Applied rewrites98.5%
(FPCore (x eps)
:precision binary64
(if (<= eps -29.0)
(/ (- (+ 1.0 (* x (- eps 1.0))) (* -1.0 (exp (- (* x (+ 1.0 eps)))))) 2.0)
(if (<= eps 1.9e-14)
(/ (fma (exp (- x)) (- (+ x 1.0) -1.0) (/ x (exp x))) 2.0)
(if (<= eps 2.3e+203)
(/ (+ (exp (- (fma eps x x))) 1.0) 2.0)
(/
(-
(* (+ 1.0 (/ 1.0 eps)) (exp (- (* (- 1.0 eps) x))))
(- (/ 1.0 eps) 1.0))
2.0)))))
double code(double x, double eps) {
double tmp;
if (eps <= -29.0) {
tmp = ((1.0 + (x * (eps - 1.0))) - (-1.0 * exp(-(x * (1.0 + eps))))) / 2.0;
} else if (eps <= 1.9e-14) {
tmp = fma(exp(-x), ((x + 1.0) - -1.0), (x / exp(x))) / 2.0;
} else if (eps <= 2.3e+203) {
tmp = (exp(-fma(eps, x, x)) + 1.0) / 2.0;
} else {
tmp = (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - ((1.0 / eps) - 1.0)) / 2.0;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= -29.0) tmp = Float64(Float64(Float64(1.0 + Float64(x * Float64(eps - 1.0))) - Float64(-1.0 * exp(Float64(-Float64(x * Float64(1.0 + eps)))))) / 2.0); elseif (eps <= 1.9e-14) tmp = Float64(fma(exp(Float64(-x)), Float64(Float64(x + 1.0) - -1.0), Float64(x / exp(x))) / 2.0); elseif (eps <= 2.3e+203) tmp = Float64(Float64(exp(Float64(-fma(eps, x, x))) + 1.0) / 2.0); else tmp = Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(-Float64(Float64(1.0 - eps) * x)))) - Float64(Float64(1.0 / eps) - 1.0)) / 2.0); end return tmp end
code[x_, eps_] := If[LessEqual[eps, -29.0], N[(N[(N[(1.0 + N[(x * N[(eps - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(-1.0 * N[Exp[(-N[(x * N[(1.0 + eps), $MachinePrecision]), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[eps, 1.9e-14], N[(N[(N[Exp[(-x)], $MachinePrecision] * N[(N[(x + 1.0), $MachinePrecision] - -1.0), $MachinePrecision] + N[(x / N[Exp[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[eps, 2.3e+203], N[(N[(N[Exp[(-N[(eps * x + x), $MachinePrecision])], $MachinePrecision] + 1.0), $MachinePrecision] / 2.0), $MachinePrecision], 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[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -29:\\
\;\;\;\;\frac{\left(1 + x \cdot \left(\varepsilon - 1\right)\right) - -1 \cdot e^{-x \cdot \left(1 + \varepsilon\right)}}{2}\\
\mathbf{elif}\;\varepsilon \leq 1.9 \cdot 10^{-14}:\\
\;\;\;\;\frac{\mathsf{fma}\left(e^{-x}, \left(x + 1\right) - -1, \frac{x}{e^{x}}\right)}{2}\\
\mathbf{elif}\;\varepsilon \leq 2.3 \cdot 10^{+203}:\\
\;\;\;\;\frac{e^{-\mathsf{fma}\left(\varepsilon, x, x\right)} + 1}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right)}{2}\\
\end{array}
\end{array}
if eps < -29Initial program 100.0%
Taylor expanded in eps around inf
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites72.0%
if -29 < eps < 1.9000000000000001e-14Initial program 32.6%
Taylor expanded in eps around 0
lower--.f64N/A
lower-+.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-fma.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f6498.3
Applied rewrites98.3%
Applied rewrites100.0%
if 1.9000000000000001e-14 < eps < 2.2999999999999999e203Initial program 100.0%
Taylor expanded in eps around inf
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites72.7%
Taylor expanded in x around 0
Applied rewrites78.1%
Applied rewrites78.1%
if 2.2999999999999999e203 < eps Initial program 100.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6471.7
Applied rewrites71.7%
(FPCore (x eps)
:precision binary64
(if (<= x -11000000000000.0)
(/ (- 1.0 (* -1.0 (exp (* -1.0 x)))) 2.0)
(if (<= x 0.32)
(/ (- (exp (- (* x (- 1.0 eps)))) (* -1.0 1.0)) 2.0)
(/ (- (+ 1.0 (/ 1.0 eps)) (- (/ 1.0 eps) 1.0)) 2.0))))
double code(double x, double eps) {
double tmp;
if (x <= -11000000000000.0) {
tmp = (1.0 - (-1.0 * exp((-1.0 * x)))) / 2.0;
} else if (x <= 0.32) {
tmp = (exp(-(x * (1.0 - eps))) - (-1.0 * 1.0)) / 2.0;
} else {
tmp = ((1.0 + (1.0 / eps)) - ((1.0 / eps) - 1.0)) / 2.0;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, eps)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= (-11000000000000.0d0)) then
tmp = (1.0d0 - ((-1.0d0) * exp(((-1.0d0) * x)))) / 2.0d0
else if (x <= 0.32d0) then
tmp = (exp(-(x * (1.0d0 - eps))) - ((-1.0d0) * 1.0d0)) / 2.0d0
else
tmp = ((1.0d0 + (1.0d0 / eps)) - ((1.0d0 / eps) - 1.0d0)) / 2.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= -11000000000000.0) {
tmp = (1.0 - (-1.0 * Math.exp((-1.0 * x)))) / 2.0;
} else if (x <= 0.32) {
tmp = (Math.exp(-(x * (1.0 - eps))) - (-1.0 * 1.0)) / 2.0;
} else {
tmp = ((1.0 + (1.0 / eps)) - ((1.0 / eps) - 1.0)) / 2.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= -11000000000000.0: tmp = (1.0 - (-1.0 * math.exp((-1.0 * x)))) / 2.0 elif x <= 0.32: tmp = (math.exp(-(x * (1.0 - eps))) - (-1.0 * 1.0)) / 2.0 else: tmp = ((1.0 + (1.0 / eps)) - ((1.0 / eps) - 1.0)) / 2.0 return tmp
function code(x, eps) tmp = 0.0 if (x <= -11000000000000.0) tmp = Float64(Float64(1.0 - Float64(-1.0 * exp(Float64(-1.0 * x)))) / 2.0); elseif (x <= 0.32) tmp = Float64(Float64(exp(Float64(-Float64(x * Float64(1.0 - eps)))) - Float64(-1.0 * 1.0)) / 2.0); else tmp = Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) - Float64(Float64(1.0 / eps) - 1.0)) / 2.0); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= -11000000000000.0) tmp = (1.0 - (-1.0 * exp((-1.0 * x)))) / 2.0; elseif (x <= 0.32) tmp = (exp(-(x * (1.0 - eps))) - (-1.0 * 1.0)) / 2.0; else tmp = ((1.0 + (1.0 / eps)) - ((1.0 / eps) - 1.0)) / 2.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, -11000000000000.0], N[(N[(1.0 - N[(-1.0 * N[Exp[N[(-1.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 0.32], N[(N[(N[Exp[(-N[(x * N[(1.0 - eps), $MachinePrecision]), $MachinePrecision])], $MachinePrecision] - N[(-1.0 * 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] - N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -11000000000000:\\
\;\;\;\;\frac{1 - -1 \cdot e^{-1 \cdot x}}{2}\\
\mathbf{elif}\;x \leq 0.32:\\
\;\;\;\;\frac{e^{-x \cdot \left(1 - \varepsilon\right)} - -1 \cdot 1}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(1 + \frac{1}{\varepsilon}\right) - \left(\frac{1}{\varepsilon} - 1\right)}{2}\\
\end{array}
\end{array}
if x < -1.1e13Initial program 100.0%
Taylor expanded in eps around inf
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites59.3%
Taylor expanded in x around 0
Applied rewrites61.8%
Taylor expanded in eps around 0
Applied rewrites100.0%
if -1.1e13 < x < 0.320000000000000007Initial program 50.0%
Taylor expanded in eps around inf
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower-+.f6497.6
Applied rewrites97.6%
Taylor expanded in x around 0
Applied rewrites89.6%
if 0.320000000000000007 < x Initial program 100.0%
Taylor expanded in x around 0
lower-+.f64N/A
lower-/.f6422.3
Applied rewrites22.3%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6457.3
Applied rewrites57.3%
(FPCore (x eps)
:precision binary64
(if (<= x -1.95e-7)
(/ (- 1.0 (* -1.0 (exp (* -1.0 x)))) 2.0)
(if (<= x 1.22e+16)
(/ (+ (exp (- (fma eps x x))) 1.0) 2.0)
(/ (- (+ 1.0 (/ 1.0 eps)) (- (/ 1.0 eps) 1.0)) 2.0))))
double code(double x, double eps) {
double tmp;
if (x <= -1.95e-7) {
tmp = (1.0 - (-1.0 * exp((-1.0 * x)))) / 2.0;
} else if (x <= 1.22e+16) {
tmp = (exp(-fma(eps, x, x)) + 1.0) / 2.0;
} else {
tmp = ((1.0 + (1.0 / eps)) - ((1.0 / eps) - 1.0)) / 2.0;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -1.95e-7) tmp = Float64(Float64(1.0 - Float64(-1.0 * exp(Float64(-1.0 * x)))) / 2.0); elseif (x <= 1.22e+16) tmp = Float64(Float64(exp(Float64(-fma(eps, x, x))) + 1.0) / 2.0); else tmp = Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) - Float64(Float64(1.0 / eps) - 1.0)) / 2.0); end return tmp end
code[x_, eps_] := If[LessEqual[x, -1.95e-7], N[(N[(1.0 - N[(-1.0 * N[Exp[N[(-1.0 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.22e+16], N[(N[(N[Exp[(-N[(eps * x + x), $MachinePrecision])], $MachinePrecision] + 1.0), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] - N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.95 \cdot 10^{-7}:\\
\;\;\;\;\frac{1 - -1 \cdot e^{-1 \cdot x}}{2}\\
\mathbf{elif}\;x \leq 1.22 \cdot 10^{+16}:\\
\;\;\;\;\frac{e^{-\mathsf{fma}\left(\varepsilon, x, x\right)} + 1}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(1 + \frac{1}{\varepsilon}\right) - \left(\frac{1}{\varepsilon} - 1\right)}{2}\\
\end{array}
\end{array}
if x < -1.95000000000000012e-7Initial program 93.1%
Taylor expanded in eps around inf
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower-+.f6493.8
Applied rewrites93.8%
Taylor expanded in x around 0
Applied rewrites53.5%
Taylor expanded in x around 0
Applied rewrites55.6%
Taylor expanded in eps around 0
Applied rewrites91.6%
if -1.95000000000000012e-7 < x < 1.22e16Initial program 51.3%
Taylor expanded in eps around inf
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower-+.f6499.3
Applied rewrites99.3%
Taylor expanded in x around 0
Applied rewrites86.4%
Taylor expanded in x around 0
Applied rewrites86.2%
Applied rewrites86.2%
if 1.22e16 < x Initial program 100.0%
Taylor expanded in x around 0
lower-+.f64N/A
lower-/.f6419.9
Applied rewrites19.9%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6458.5
Applied rewrites58.5%
(FPCore (x eps) :precision binary64 (if (<= x 1.22e+16) (/ (+ (exp (- (fma eps x x))) 1.0) 2.0) (/ (- (+ 1.0 (/ 1.0 eps)) (- (/ 1.0 eps) 1.0)) 2.0)))
double code(double x, double eps) {
double tmp;
if (x <= 1.22e+16) {
tmp = (exp(-fma(eps, x, x)) + 1.0) / 2.0;
} else {
tmp = ((1.0 + (1.0 / eps)) - ((1.0 / eps) - 1.0)) / 2.0;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 1.22e+16) tmp = Float64(Float64(exp(Float64(-fma(eps, x, x))) + 1.0) / 2.0); else tmp = Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) - Float64(Float64(1.0 / eps) - 1.0)) / 2.0); end return tmp end
code[x_, eps_] := If[LessEqual[x, 1.22e+16], N[(N[(N[Exp[(-N[(eps * x + x), $MachinePrecision])], $MachinePrecision] + 1.0), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] - N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.22 \cdot 10^{+16}:\\
\;\;\;\;\frac{e^{-\mathsf{fma}\left(\varepsilon, x, x\right)} + 1}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(1 + \frac{1}{\varepsilon}\right) - \left(\frac{1}{\varepsilon} - 1\right)}{2}\\
\end{array}
\end{array}
if x < 1.22e16Initial program 60.3%
Taylor expanded in eps around inf
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower-+.f6498.1
Applied rewrites98.1%
Taylor expanded in x around 0
Applied rewrites79.3%
Taylor expanded in x around 0
Applied rewrites79.6%
Applied rewrites79.6%
if 1.22e16 < x Initial program 100.0%
Taylor expanded in x around 0
lower-+.f64N/A
lower-/.f6419.9
Applied rewrites19.9%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6458.5
Applied rewrites58.5%
(FPCore (x eps) :precision binary64 (if (<= x 2.0) (/ (- 1.0 (* -1.0 (+ 1.0 (* -1.0 (* x (+ 1.0 eps)))))) 2.0) (/ (- (+ 1.0 (/ 1.0 eps)) (- (/ 1.0 eps) 1.0)) 2.0)))
double code(double x, double eps) {
double tmp;
if (x <= 2.0) {
tmp = (1.0 - (-1.0 * (1.0 + (-1.0 * (x * (1.0 + eps)))))) / 2.0;
} else {
tmp = ((1.0 + (1.0 / eps)) - ((1.0 / eps) - 1.0)) / 2.0;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, eps)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= 2.0d0) then
tmp = (1.0d0 - ((-1.0d0) * (1.0d0 + ((-1.0d0) * (x * (1.0d0 + eps)))))) / 2.0d0
else
tmp = ((1.0d0 + (1.0d0 / eps)) - ((1.0d0 / eps) - 1.0d0)) / 2.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= 2.0) {
tmp = (1.0 - (-1.0 * (1.0 + (-1.0 * (x * (1.0 + eps)))))) / 2.0;
} else {
tmp = ((1.0 + (1.0 / eps)) - ((1.0 / eps) - 1.0)) / 2.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 2.0: tmp = (1.0 - (-1.0 * (1.0 + (-1.0 * (x * (1.0 + eps)))))) / 2.0 else: tmp = ((1.0 + (1.0 / eps)) - ((1.0 / eps) - 1.0)) / 2.0 return tmp
function code(x, eps) tmp = 0.0 if (x <= 2.0) tmp = Float64(Float64(1.0 - Float64(-1.0 * Float64(1.0 + Float64(-1.0 * Float64(x * Float64(1.0 + eps)))))) / 2.0); else tmp = Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) - Float64(Float64(1.0 / eps) - 1.0)) / 2.0); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 2.0) tmp = (1.0 - (-1.0 * (1.0 + (-1.0 * (x * (1.0 + eps)))))) / 2.0; else tmp = ((1.0 + (1.0 / eps)) - ((1.0 / eps) - 1.0)) / 2.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, 2.0], N[(N[(1.0 - N[(-1.0 * N[(1.0 + N[(-1.0 * N[(x * N[(1.0 + eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] - N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2:\\
\;\;\;\;\frac{1 - -1 \cdot \left(1 + -1 \cdot \left(x \cdot \left(1 + \varepsilon\right)\right)\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(1 + \frac{1}{\varepsilon}\right) - \left(\frac{1}{\varepsilon} - 1\right)}{2}\\
\end{array}
\end{array}
if x < 2Initial program 59.8%
Taylor expanded in eps around inf
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower-+.f6498.1
Applied rewrites98.1%
Taylor expanded in x around 0
Applied rewrites79.6%
Taylor expanded in x around 0
Applied rewrites79.9%
Taylor expanded in x around 0
Applied rewrites66.0%
if 2 < x Initial program 100.0%
Taylor expanded in x around 0
lower-+.f64N/A
lower-/.f6421.0
Applied rewrites21.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6458.2
Applied rewrites58.2%
(FPCore (x eps) :precision binary64 (if (<= x 2.0) (/ (- 1.0 (* -1.0 (+ 1.0 (* -1.0 (* x (+ 1.0 eps)))))) 2.0) (/ (- (/ 1.0 eps) (- (/ 1.0 eps) 1.0)) 2.0)))
double code(double x, double eps) {
double tmp;
if (x <= 2.0) {
tmp = (1.0 - (-1.0 * (1.0 + (-1.0 * (x * (1.0 + eps)))))) / 2.0;
} else {
tmp = ((1.0 / eps) - ((1.0 / eps) - 1.0)) / 2.0;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, eps)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= 2.0d0) then
tmp = (1.0d0 - ((-1.0d0) * (1.0d0 + ((-1.0d0) * (x * (1.0d0 + eps)))))) / 2.0d0
else
tmp = ((1.0d0 / eps) - ((1.0d0 / eps) - 1.0d0)) / 2.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= 2.0) {
tmp = (1.0 - (-1.0 * (1.0 + (-1.0 * (x * (1.0 + eps)))))) / 2.0;
} else {
tmp = ((1.0 / eps) - ((1.0 / eps) - 1.0)) / 2.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 2.0: tmp = (1.0 - (-1.0 * (1.0 + (-1.0 * (x * (1.0 + eps)))))) / 2.0 else: tmp = ((1.0 / eps) - ((1.0 / eps) - 1.0)) / 2.0 return tmp
function code(x, eps) tmp = 0.0 if (x <= 2.0) tmp = Float64(Float64(1.0 - Float64(-1.0 * Float64(1.0 + Float64(-1.0 * Float64(x * Float64(1.0 + eps)))))) / 2.0); else tmp = Float64(Float64(Float64(1.0 / eps) - Float64(Float64(1.0 / eps) - 1.0)) / 2.0); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 2.0) tmp = (1.0 - (-1.0 * (1.0 + (-1.0 * (x * (1.0 + eps)))))) / 2.0; else tmp = ((1.0 / eps) - ((1.0 / eps) - 1.0)) / 2.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, 2.0], N[(N[(1.0 - N[(-1.0 * N[(1.0 + N[(-1.0 * N[(x * N[(1.0 + eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(1.0 / eps), $MachinePrecision] - N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2:\\
\;\;\;\;\frac{1 - -1 \cdot \left(1 + -1 \cdot \left(x \cdot \left(1 + \varepsilon\right)\right)\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\varepsilon} - \left(\frac{1}{\varepsilon} - 1\right)}{2}\\
\end{array}
\end{array}
if x < 2Initial program 59.8%
Taylor expanded in eps around inf
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower-+.f6498.1
Applied rewrites98.1%
Taylor expanded in x around 0
Applied rewrites79.6%
Taylor expanded in x around 0
Applied rewrites79.9%
Taylor expanded in x around 0
Applied rewrites66.0%
if 2 < x Initial program 100.0%
Taylor expanded in x around 0
lower-+.f64N/A
lower-/.f6421.0
Applied rewrites21.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6458.2
Applied rewrites58.2%
Taylor expanded in eps around 0
Applied rewrites58.2%
(FPCore (x eps) :precision binary64 (if (<= eps -1.6e+122) (/ (- (+ 1.0 (* eps x)) (- (/ 1.0 eps) 1.0)) 2.0) (/ (- 1.0 (* -1.0 (+ 1.0 (* -1.0 (* x (+ 1.0 eps)))))) 2.0)))
double code(double x, double eps) {
double tmp;
if (eps <= -1.6e+122) {
tmp = ((1.0 + (eps * x)) - ((1.0 / eps) - 1.0)) / 2.0;
} else {
tmp = (1.0 - (-1.0 * (1.0 + (-1.0 * (x * (1.0 + 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 (eps <= (-1.6d+122)) then
tmp = ((1.0d0 + (eps * x)) - ((1.0d0 / eps) - 1.0d0)) / 2.0d0
else
tmp = (1.0d0 - ((-1.0d0) * (1.0d0 + ((-1.0d0) * (x * (1.0d0 + eps)))))) / 2.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (eps <= -1.6e+122) {
tmp = ((1.0 + (eps * x)) - ((1.0 / eps) - 1.0)) / 2.0;
} else {
tmp = (1.0 - (-1.0 * (1.0 + (-1.0 * (x * (1.0 + eps)))))) / 2.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if eps <= -1.6e+122: tmp = ((1.0 + (eps * x)) - ((1.0 / eps) - 1.0)) / 2.0 else: tmp = (1.0 - (-1.0 * (1.0 + (-1.0 * (x * (1.0 + eps)))))) / 2.0 return tmp
function code(x, eps) tmp = 0.0 if (eps <= -1.6e+122) tmp = Float64(Float64(Float64(1.0 + Float64(eps * x)) - Float64(Float64(1.0 / eps) - 1.0)) / 2.0); else tmp = Float64(Float64(1.0 - Float64(-1.0 * Float64(1.0 + Float64(-1.0 * Float64(x * Float64(1.0 + eps)))))) / 2.0); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= -1.6e+122) tmp = ((1.0 + (eps * x)) - ((1.0 / eps) - 1.0)) / 2.0; else tmp = (1.0 - (-1.0 * (1.0 + (-1.0 * (x * (1.0 + eps)))))) / 2.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[eps, -1.6e+122], N[(N[(N[(1.0 + N[(eps * x), $MachinePrecision]), $MachinePrecision] - N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(1.0 - N[(-1.0 * N[(1.0 + N[(-1.0 * N[(x * N[(1.0 + eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq -1.6 \cdot 10^{+122}:\\
\;\;\;\;\frac{\left(1 + \varepsilon \cdot x\right) - \left(\frac{1}{\varepsilon} - 1\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - -1 \cdot \left(1 + -1 \cdot \left(x \cdot \left(1 + \varepsilon\right)\right)\right)}{2}\\
\end{array}
\end{array}
if eps < -1.60000000000000006e122Initial program 100.0%
Taylor expanded in x around 0
lower-+.f64N/A
lower-/.f6451.0
Applied rewrites51.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6424.9
Applied rewrites24.9%
Taylor expanded in x around 0
lower-+.f64N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower-/.f6443.8
Applied rewrites43.8%
Taylor expanded in eps around inf
Applied rewrites43.8%
if -1.60000000000000006e122 < eps Initial program 63.2%
Taylor expanded in eps around inf
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower-+.f6498.2
Applied rewrites98.2%
Taylor expanded in x around 0
Applied rewrites69.0%
Taylor expanded in x around 0
Applied rewrites69.6%
Taylor expanded in x around 0
Applied rewrites57.2%
(FPCore (x eps) :precision binary64 (/ (- 1.0 (* -1.0 (+ 1.0 (* -1.0 (* x (+ 1.0 eps)))))) 2.0))
double code(double x, double eps) {
return (1.0 - (-1.0 * (1.0 + (-1.0 * (x * (1.0 + eps)))))) / 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) * (1.0d0 + ((-1.0d0) * (x * (1.0d0 + eps)))))) / 2.0d0
end function
public static double code(double x, double eps) {
return (1.0 - (-1.0 * (1.0 + (-1.0 * (x * (1.0 + eps)))))) / 2.0;
}
def code(x, eps): return (1.0 - (-1.0 * (1.0 + (-1.0 * (x * (1.0 + eps)))))) / 2.0
function code(x, eps) return Float64(Float64(1.0 - Float64(-1.0 * Float64(1.0 + Float64(-1.0 * Float64(x * Float64(1.0 + eps)))))) / 2.0) end
function tmp = code(x, eps) tmp = (1.0 - (-1.0 * (1.0 + (-1.0 * (x * (1.0 + eps)))))) / 2.0; end
code[x_, eps_] := N[(N[(1.0 - N[(-1.0 * N[(1.0 + N[(-1.0 * N[(x * N[(1.0 + eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{1 - -1 \cdot \left(1 + -1 \cdot \left(x \cdot \left(1 + \varepsilon\right)\right)\right)}{2}
\end{array}
Initial program 68.9%
Taylor expanded in eps around inf
lower--.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-*.f64N/A
lower-+.f6498.5
Applied rewrites98.5%
Taylor expanded in x around 0
Applied rewrites68.7%
Taylor expanded in x around 0
Applied rewrites66.7%
Taylor expanded in x around 0
Applied rewrites52.7%
(FPCore (x eps) :precision binary64 (/ 2.0 2.0))
double code(double x, double eps) {
return 2.0 / 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 = 2.0d0 / 2.0d0
end function
public static double code(double x, double eps) {
return 2.0 / 2.0;
}
def code(x, eps): return 2.0 / 2.0
function code(x, eps) return Float64(2.0 / 2.0) end
function tmp = code(x, eps) tmp = 2.0 / 2.0; end
code[x_, eps_] := N[(2.0 / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{2}
\end{array}
Initial program 68.9%
Taylor expanded in x around 0
Applied rewrites48.8%
herbie shell --seed 2024363 -o localize:costs -o setup:simplify -o generate:simplify
(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))