
(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
(let* ((t_0
(/
(-
(* (+ 1.0 (pow eps -1.0)) (exp (* (+ -1.0 eps) x)))
(* (- (pow eps -1.0) 1.0) (exp (* (- -1.0 eps) x))))
2.0)))
(if (<= t_0 0.0) (* (* (exp (- x)) (+ (- (+ 1.0 x) -1.0) x)) 0.5) t_0)))
double code(double x, double eps) {
double t_0 = (((1.0 + pow(eps, -1.0)) * exp(((-1.0 + eps) * x))) - ((pow(eps, -1.0) - 1.0) * exp(((-1.0 - eps) * x)))) / 2.0;
double tmp;
if (t_0 <= 0.0) {
tmp = (exp(-x) * (((1.0 + x) - -1.0) + x)) * 0.5;
} else {
tmp = t_0;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, eps)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = (((1.0d0 + (eps ** (-1.0d0))) * exp((((-1.0d0) + eps) * x))) - (((eps ** (-1.0d0)) - 1.0d0) * exp((((-1.0d0) - eps) * x)))) / 2.0d0
if (t_0 <= 0.0d0) then
tmp = (exp(-x) * (((1.0d0 + x) - (-1.0d0)) + x)) * 0.5d0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = (((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;
double tmp;
if (t_0 <= 0.0) {
tmp = (Math.exp(-x) * (((1.0 + x) - -1.0) + x)) * 0.5;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, eps): t_0 = (((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 tmp = 0 if t_0 <= 0.0: tmp = (math.exp(-x) * (((1.0 + x) - -1.0) + x)) * 0.5 else: tmp = t_0 return tmp
function code(x, eps) t_0 = 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) tmp = 0.0 if (t_0 <= 0.0) tmp = Float64(Float64(exp(Float64(-x)) * Float64(Float64(Float64(1.0 + x) - -1.0) + x)) * 0.5); else tmp = t_0; end return tmp end
function tmp_2 = code(x, eps) t_0 = (((1.0 + (eps ^ -1.0)) * exp(((-1.0 + eps) * x))) - (((eps ^ -1.0) - 1.0) * exp(((-1.0 - eps) * x)))) / 2.0; tmp = 0.0; if (t_0 <= 0.0) tmp = (exp(-x) * (((1.0 + x) - -1.0) + x)) * 0.5; else tmp = t_0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = 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]}, If[LessEqual[t$95$0, 0.0], N[(N[(N[Exp[(-x)], $MachinePrecision] * N[(N[(N[(1.0 + x), $MachinePrecision] - -1.0), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \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}\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\left(e^{-x} \cdot \left(\left(\left(1 + x\right) - -1\right) + x\right)\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) < 0.0Initial program 41.5%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
if 0.0 < (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) Initial program 100.0%
Final simplification100.0%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (pow eps -1.0) 1.0)) (t_1 (+ 1.0 (pow eps -1.0))))
(if (<=
(/
(- (* t_1 (exp (* (+ -1.0 eps) x))) (* t_0 (exp (* (- -1.0 eps) x))))
2.0)
2.0)
(* (* (exp (- x)) (+ (- (+ 1.0 x) -1.0) x)) 0.5)
(/ (- (* t_1 (exp (- (* (- eps) x)))) t_0) 2.0))))
double code(double x, double eps) {
double t_0 = pow(eps, -1.0) - 1.0;
double t_1 = 1.0 + pow(eps, -1.0);
double tmp;
if ((((t_1 * exp(((-1.0 + eps) * x))) - (t_0 * exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0) {
tmp = (exp(-x) * (((1.0 + x) - -1.0) + x)) * 0.5;
} else {
tmp = ((t_1 * exp(-(-eps * x))) - t_0) / 2.0;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, eps)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (eps ** (-1.0d0)) - 1.0d0
t_1 = 1.0d0 + (eps ** (-1.0d0))
if ((((t_1 * exp((((-1.0d0) + eps) * x))) - (t_0 * exp((((-1.0d0) - eps) * x)))) / 2.0d0) <= 2.0d0) then
tmp = (exp(-x) * (((1.0d0 + x) - (-1.0d0)) + x)) * 0.5d0
else
tmp = ((t_1 * exp(-(-eps * x))) - t_0) / 2.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.pow(eps, -1.0) - 1.0;
double t_1 = 1.0 + Math.pow(eps, -1.0);
double tmp;
if ((((t_1 * Math.exp(((-1.0 + eps) * x))) - (t_0 * Math.exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0) {
tmp = (Math.exp(-x) * (((1.0 + x) - -1.0) + x)) * 0.5;
} else {
tmp = ((t_1 * Math.exp(-(-eps * x))) - t_0) / 2.0;
}
return tmp;
}
def code(x, eps): t_0 = math.pow(eps, -1.0) - 1.0 t_1 = 1.0 + math.pow(eps, -1.0) tmp = 0 if (((t_1 * math.exp(((-1.0 + eps) * x))) - (t_0 * math.exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0: tmp = (math.exp(-x) * (((1.0 + x) - -1.0) + x)) * 0.5 else: tmp = ((t_1 * math.exp(-(-eps * x))) - t_0) / 2.0 return tmp
function code(x, eps) t_0 = Float64((eps ^ -1.0) - 1.0) t_1 = Float64(1.0 + (eps ^ -1.0)) tmp = 0.0 if (Float64(Float64(Float64(t_1 * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(t_0 * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0) <= 2.0) tmp = Float64(Float64(exp(Float64(-x)) * Float64(Float64(Float64(1.0 + x) - -1.0) + x)) * 0.5); else tmp = Float64(Float64(Float64(t_1 * exp(Float64(-Float64(Float64(-eps) * x)))) - t_0) / 2.0); end return tmp end
function tmp_2 = code(x, eps) t_0 = (eps ^ -1.0) - 1.0; t_1 = 1.0 + (eps ^ -1.0); tmp = 0.0; if ((((t_1 * exp(((-1.0 + eps) * x))) - (t_0 * exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0) tmp = (exp(-x) * (((1.0 + x) - -1.0) + x)) * 0.5; else tmp = ((t_1 * exp(-(-eps * x))) - t_0) / 2.0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[Power[eps, -1.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[(t$95$1 * N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(t$95$0 * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 2.0], N[(N[(N[Exp[(-x)], $MachinePrecision] * N[(N[(N[(1.0 + x), $MachinePrecision] - -1.0), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(t$95$1 * N[Exp[(-N[((-eps) * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision] / 2.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\varepsilon}^{-1} - 1\\
t_1 := 1 + {\varepsilon}^{-1}\\
\mathbf{if}\;\frac{t\_1 \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - t\_0 \cdot e^{\left(-1 - \varepsilon\right) \cdot x}}{2} \leq 2:\\
\;\;\;\;\left(e^{-x} \cdot \left(\left(\left(1 + x\right) - -1\right) + x\right)\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_1 \cdot e^{-\left(-\varepsilon\right) \cdot x} - t\_0}{2}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) < 2Initial program 59.2%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
if 2 < (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) Initial program 100.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6458.1
Applied rewrites58.1%
Taylor expanded in eps around inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f6458.1
Applied rewrites58.1%
Final simplification81.8%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (pow eps -1.0) 1.0)))
(if (<=
(/
(-
(* (+ 1.0 (pow eps -1.0)) (exp (* (+ -1.0 eps) x)))
(* t_0 (exp (* (- -1.0 eps) x))))
2.0)
2.0)
(* (* (exp (- x)) (+ (- (+ 1.0 x) -1.0) x)) 0.5)
(/ (- (* (exp (- (* x eps) x)) (- (pow eps -1.0) -1.0)) t_0) 2.0))))
double code(double x, double eps) {
double t_0 = pow(eps, -1.0) - 1.0;
double tmp;
if (((((1.0 + pow(eps, -1.0)) * exp(((-1.0 + eps) * x))) - (t_0 * exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0) {
tmp = (exp(-x) * (((1.0 + x) - -1.0) + x)) * 0.5;
} else {
tmp = ((exp(((x * eps) - x)) * (pow(eps, -1.0) - -1.0)) - t_0) / 2.0;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, eps)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = (eps ** (-1.0d0)) - 1.0d0
if (((((1.0d0 + (eps ** (-1.0d0))) * exp((((-1.0d0) + eps) * x))) - (t_0 * exp((((-1.0d0) - eps) * x)))) / 2.0d0) <= 2.0d0) then
tmp = (exp(-x) * (((1.0d0 + x) - (-1.0d0)) + x)) * 0.5d0
else
tmp = ((exp(((x * eps) - x)) * ((eps ** (-1.0d0)) - (-1.0d0))) - t_0) / 2.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.pow(eps, -1.0) - 1.0;
double tmp;
if (((((1.0 + Math.pow(eps, -1.0)) * Math.exp(((-1.0 + eps) * x))) - (t_0 * Math.exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0) {
tmp = (Math.exp(-x) * (((1.0 + x) - -1.0) + x)) * 0.5;
} else {
tmp = ((Math.exp(((x * eps) - x)) * (Math.pow(eps, -1.0) - -1.0)) - t_0) / 2.0;
}
return tmp;
}
def code(x, eps): t_0 = math.pow(eps, -1.0) - 1.0 tmp = 0 if ((((1.0 + math.pow(eps, -1.0)) * math.exp(((-1.0 + eps) * x))) - (t_0 * math.exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0: tmp = (math.exp(-x) * (((1.0 + x) - -1.0) + x)) * 0.5 else: tmp = ((math.exp(((x * eps) - x)) * (math.pow(eps, -1.0) - -1.0)) - t_0) / 2.0 return tmp
function code(x, eps) t_0 = Float64((eps ^ -1.0) - 1.0) tmp = 0.0 if (Float64(Float64(Float64(Float64(1.0 + (eps ^ -1.0)) * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(t_0 * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0) <= 2.0) tmp = Float64(Float64(exp(Float64(-x)) * Float64(Float64(Float64(1.0 + x) - -1.0) + x)) * 0.5); else tmp = Float64(Float64(Float64(exp(Float64(Float64(x * eps) - x)) * Float64((eps ^ -1.0) - -1.0)) - t_0) / 2.0); end return tmp end
function tmp_2 = code(x, eps) t_0 = (eps ^ -1.0) - 1.0; tmp = 0.0; if (((((1.0 + (eps ^ -1.0)) * exp(((-1.0 + eps) * x))) - (t_0 * exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0) tmp = (exp(-x) * (((1.0 + x) - -1.0) + x)) * 0.5; else tmp = ((exp(((x * eps) - x)) * ((eps ^ -1.0) - -1.0)) - t_0) / 2.0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $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[(t$95$0 * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 2.0], N[(N[(N[Exp[(-x)], $MachinePrecision] * N[(N[(N[(1.0 + x), $MachinePrecision] - -1.0), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(N[Exp[N[(N[(x * eps), $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision] * N[(N[Power[eps, -1.0], $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\varepsilon}^{-1} - 1\\
\mathbf{if}\;\frac{\left(1 + {\varepsilon}^{-1}\right) \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - t\_0 \cdot e^{\left(-1 - \varepsilon\right) \cdot x}}{2} \leq 2:\\
\;\;\;\;\left(e^{-x} \cdot \left(\left(\left(1 + x\right) - -1\right) + x\right)\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{x \cdot \varepsilon - x} \cdot \left({\varepsilon}^{-1} - -1\right) - t\_0}{2}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) < 2Initial program 59.2%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
if 2 < (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) Initial program 100.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6458.1
Applied rewrites58.1%
Taylor expanded in x around 0
*-inversesN/A
div-addN/A
+-commutativeN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
div-subN/A
mul-1-negN/A
*-lft-identityN/A
times-fracN/A
metadata-evalN/A
*-inversesN/A
metadata-evalN/A
lower--.f64N/A
lower-/.f643.1
Applied rewrites3.1%
Taylor expanded in eps around 0
Applied rewrites3.1%
Taylor expanded in x around inf
lower-*.f64N/A
lower-exp.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-inversesN/A
div-addN/A
+-commutativeN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
div-subN/A
mul-1-negN/A
*-lft-identityN/A
times-fracN/A
metadata-evalN/A
*-inversesN/A
metadata-evalN/A
lower--.f64N/A
lower-/.f6458.1
Applied rewrites58.1%
Final simplification81.8%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (- (pow eps -1.0) 1.0) (exp (* (- -1.0 eps) x)))))
(if (<=
(/ (- (* (+ 1.0 (pow eps -1.0)) (exp (* (+ -1.0 eps) x))) t_0) 2.0)
1.0)
(* (* (exp (- x)) (+ (- (+ 1.0 x) -1.0) x)) 0.5)
(/ (- (- (* eps x) -1.0) t_0) 2.0))))
double code(double x, double eps) {
double t_0 = (pow(eps, -1.0) - 1.0) * exp(((-1.0 - eps) * x));
double tmp;
if (((((1.0 + pow(eps, -1.0)) * exp(((-1.0 + eps) * x))) - t_0) / 2.0) <= 1.0) {
tmp = (exp(-x) * (((1.0 + x) - -1.0) + x)) * 0.5;
} else {
tmp = (((eps * x) - -1.0) - t_0) / 2.0;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, eps)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = ((eps ** (-1.0d0)) - 1.0d0) * exp((((-1.0d0) - eps) * x))
if (((((1.0d0 + (eps ** (-1.0d0))) * exp((((-1.0d0) + eps) * x))) - t_0) / 2.0d0) <= 1.0d0) then
tmp = (exp(-x) * (((1.0d0 + x) - (-1.0d0)) + x)) * 0.5d0
else
tmp = (((eps * x) - (-1.0d0)) - t_0) / 2.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = (Math.pow(eps, -1.0) - 1.0) * Math.exp(((-1.0 - eps) * x));
double tmp;
if (((((1.0 + Math.pow(eps, -1.0)) * Math.exp(((-1.0 + eps) * x))) - t_0) / 2.0) <= 1.0) {
tmp = (Math.exp(-x) * (((1.0 + x) - -1.0) + x)) * 0.5;
} else {
tmp = (((eps * x) - -1.0) - t_0) / 2.0;
}
return tmp;
}
def code(x, eps): t_0 = (math.pow(eps, -1.0) - 1.0) * math.exp(((-1.0 - eps) * x)) tmp = 0 if ((((1.0 + math.pow(eps, -1.0)) * math.exp(((-1.0 + eps) * x))) - t_0) / 2.0) <= 1.0: tmp = (math.exp(-x) * (((1.0 + x) - -1.0) + x)) * 0.5 else: tmp = (((eps * x) - -1.0) - t_0) / 2.0 return tmp
function code(x, eps) t_0 = Float64(Float64((eps ^ -1.0) - 1.0) * exp(Float64(Float64(-1.0 - eps) * x))) tmp = 0.0 if (Float64(Float64(Float64(Float64(1.0 + (eps ^ -1.0)) * exp(Float64(Float64(-1.0 + eps) * x))) - t_0) / 2.0) <= 1.0) tmp = Float64(Float64(exp(Float64(-x)) * Float64(Float64(Float64(1.0 + x) - -1.0) + x)) * 0.5); else tmp = Float64(Float64(Float64(Float64(eps * x) - -1.0) - t_0) / 2.0); end return tmp end
function tmp_2 = code(x, eps) t_0 = ((eps ^ -1.0) - 1.0) * exp(((-1.0 - eps) * x)); tmp = 0.0; if (((((1.0 + (eps ^ -1.0)) * exp(((-1.0 + eps) * x))) - t_0) / 2.0) <= 1.0) tmp = (exp(-x) * (((1.0 + x) - -1.0) + x)) * 0.5; else tmp = (((eps * x) - -1.0) - t_0) / 2.0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $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] - t$95$0), $MachinePrecision] / 2.0), $MachinePrecision], 1.0], N[(N[(N[Exp[(-x)], $MachinePrecision] * N[(N[(N[(1.0 + x), $MachinePrecision] - -1.0), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(N[(eps * x), $MachinePrecision] - -1.0), $MachinePrecision] - t$95$0), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left({\varepsilon}^{-1} - 1\right) \cdot e^{\left(-1 - \varepsilon\right) \cdot x}\\
\mathbf{if}\;\frac{\left(1 + {\varepsilon}^{-1}\right) \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - t\_0}{2} \leq 1:\\
\;\;\;\;\left(e^{-x} \cdot \left(\left(\left(1 + x\right) - -1\right) + x\right)\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\varepsilon \cdot x - -1\right) - 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)) < 1Initial program 59.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
if 1 < (/.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 x around 0
+-commutativeN/A
associate-+l+N/A
associate-*r*N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
lower-/.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f6447.2
Applied rewrites47.2%
Taylor expanded in eps around inf
Applied rewrites47.2%
Final simplification76.9%
(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)
0.0)
(* (* (exp (- x)) (+ (- (+ 1.0 x) -1.0) x)) 0.5)
(fma (- (fabs (* 0.3333333333333333 x)) 0.5) (* x x) 1.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) <= 0.0) {
tmp = (exp(-x) * (((1.0 + x) - -1.0) + x)) * 0.5;
} else {
tmp = fma((fabs((0.3333333333333333 * x)) - 0.5), (x * x), 1.0);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(Float64(Float64(Float64(1.0 + (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) <= 0.0) tmp = Float64(Float64(exp(Float64(-x)) * Float64(Float64(Float64(1.0 + x) - -1.0) + x)) * 0.5); else tmp = fma(Float64(abs(Float64(0.3333333333333333 * x)) - 0.5), Float64(x * x), 1.0); end return tmp end
code[x_, eps_] := If[LessEqual[N[(N[(N[(N[(1.0 + N[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], 0.0], N[(N[(N[Exp[(-x)], $MachinePrecision] * N[(N[(N[(1.0 + x), $MachinePrecision] - -1.0), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[Abs[N[(0.3333333333333333 * x), $MachinePrecision]], $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.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 0:\\
\;\;\;\;\left(e^{-x} \cdot \left(\left(\left(1 + x\right) - -1\right) + x\right)\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left|0.3333333333333333 \cdot x\right| - 0.5, x \cdot x, 1\right)\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) < 0.0Initial program 41.5%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
if 0.0 < (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites29.4%
Taylor expanded in x around 0
Applied rewrites44.3%
Taylor expanded in x around 0
Applied rewrites44.3%
Applied rewrites61.7%
Final simplification76.8%
(FPCore (x eps)
:precision binary64
(if (<= x 40000000000.0)
(fma (- (fabs (* 0.3333333333333333 x)) 0.5) (* x x) 1.0)
(if (<= x 3.6e+212)
(/ (- (- (pow eps -1.0) -1.0) (- (pow eps -1.0) 1.0)) 2.0)
(fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0))))
double code(double x, double eps) {
double tmp;
if (x <= 40000000000.0) {
tmp = fma((fabs((0.3333333333333333 * x)) - 0.5), (x * x), 1.0);
} else if (x <= 3.6e+212) {
tmp = ((pow(eps, -1.0) - -1.0) - (pow(eps, -1.0) - 1.0)) / 2.0;
} else {
tmp = fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 40000000000.0) tmp = fma(Float64(abs(Float64(0.3333333333333333 * x)) - 0.5), Float64(x * x), 1.0); elseif (x <= 3.6e+212) tmp = Float64(Float64(Float64((eps ^ -1.0) - -1.0) - Float64((eps ^ -1.0) - 1.0)) / 2.0); else tmp = fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0); end return tmp end
code[x_, eps_] := If[LessEqual[x, 40000000000.0], N[(N[(N[Abs[N[(0.3333333333333333 * x), $MachinePrecision]], $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[x, 3.6e+212], N[(N[(N[(N[Power[eps, -1.0], $MachinePrecision] - -1.0), $MachinePrecision] - N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 40000000000:\\
\;\;\;\;\mathsf{fma}\left(\left|0.3333333333333333 \cdot x\right| - 0.5, x \cdot x, 1\right)\\
\mathbf{elif}\;x \leq 3.6 \cdot 10^{+212}:\\
\;\;\;\;\frac{\left({\varepsilon}^{-1} - -1\right) - \left({\varepsilon}^{-1} - 1\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)\\
\end{array}
\end{array}
if x < 4e10Initial program 67.9%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites57.7%
Taylor expanded in x around 0
Applied rewrites57.7%
Taylor expanded in x around 0
Applied rewrites57.7%
Applied rewrites72.4%
if 4e10 < x < 3.6e212Initial program 100.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6422.3
Applied rewrites22.3%
Taylor expanded in x around 0
*-inversesN/A
div-addN/A
+-commutativeN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
div-subN/A
mul-1-negN/A
*-lft-identityN/A
times-fracN/A
metadata-evalN/A
*-inversesN/A
metadata-evalN/A
lower--.f64N/A
lower-/.f6466.4
Applied rewrites66.4%
if 3.6e212 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites35.8%
Taylor expanded in x around 0
Applied rewrites65.8%
Taylor expanded in x around 0
Applied rewrites65.8%
Final simplification70.6%
(FPCore (x eps)
:precision binary64
(if (<= x 40000000000.0)
(fma (- (fabs (* 0.3333333333333333 x)) 0.5) (* x x) 1.0)
(if (<= x 3.6e+212)
(/ (- (pow eps -1.0) (- (pow eps -1.0) 1.0)) 2.0)
(fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0))))
double code(double x, double eps) {
double tmp;
if (x <= 40000000000.0) {
tmp = fma((fabs((0.3333333333333333 * x)) - 0.5), (x * x), 1.0);
} else if (x <= 3.6e+212) {
tmp = (pow(eps, -1.0) - (pow(eps, -1.0) - 1.0)) / 2.0;
} else {
tmp = fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 40000000000.0) tmp = fma(Float64(abs(Float64(0.3333333333333333 * x)) - 0.5), Float64(x * x), 1.0); elseif (x <= 3.6e+212) tmp = Float64(Float64((eps ^ -1.0) - Float64((eps ^ -1.0) - 1.0)) / 2.0); else tmp = fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0); end return tmp end
code[x_, eps_] := If[LessEqual[x, 40000000000.0], N[(N[(N[Abs[N[(0.3333333333333333 * x), $MachinePrecision]], $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[x, 3.6e+212], N[(N[(N[Power[eps, -1.0], $MachinePrecision] - N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 40000000000:\\
\;\;\;\;\mathsf{fma}\left(\left|0.3333333333333333 \cdot x\right| - 0.5, x \cdot x, 1\right)\\
\mathbf{elif}\;x \leq 3.6 \cdot 10^{+212}:\\
\;\;\;\;\frac{{\varepsilon}^{-1} - \left({\varepsilon}^{-1} - 1\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)\\
\end{array}
\end{array}
if x < 4e10Initial program 67.9%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites57.7%
Taylor expanded in x around 0
Applied rewrites57.7%
Taylor expanded in x around 0
Applied rewrites57.7%
Applied rewrites72.4%
if 4e10 < x < 3.6e212Initial program 100.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6422.3
Applied rewrites22.3%
Taylor expanded in x around 0
*-inversesN/A
div-addN/A
+-commutativeN/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sub-sign-invN/A
mul-1-negN/A
div-subN/A
mul-1-negN/A
*-lft-identityN/A
times-fracN/A
metadata-evalN/A
*-inversesN/A
metadata-evalN/A
lower--.f64N/A
lower-/.f6466.4
Applied rewrites66.4%
Taylor expanded in eps around 0
Applied rewrites66.4%
if 3.6e212 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites35.8%
Taylor expanded in x around 0
Applied rewrites65.8%
Taylor expanded in x around 0
Applied rewrites65.8%
Final simplification70.6%
(FPCore (x eps) :precision binary64 (fma (- (fabs (* 0.3333333333333333 x)) 0.5) (* x x) 1.0))
double code(double x, double eps) {
return fma((fabs((0.3333333333333333 * x)) - 0.5), (x * x), 1.0);
}
function code(x, eps) return fma(Float64(abs(Float64(0.3333333333333333 * x)) - 0.5), Float64(x * x), 1.0) end
code[x_, eps_] := N[(N[(N[Abs[N[(0.3333333333333333 * x), $MachinePrecision]], $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left|0.3333333333333333 \cdot x\right| - 0.5, x \cdot x, 1\right)
\end{array}
Initial program 76.9%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites57.3%
Taylor expanded in x around 0
Applied rewrites51.0%
Taylor expanded in x around 0
Applied rewrites51.0%
Applied rewrites61.5%
(FPCore (x eps) :precision binary64 (fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0))
double code(double x, double eps) {
return fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
}
function code(x, eps) return fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0) end
code[x_, eps_] := N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)
\end{array}
Initial program 76.9%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites57.3%
Taylor expanded in x around 0
Applied rewrites51.0%
Taylor expanded in x around 0
Applied rewrites51.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 76.9%
Taylor expanded in x around 0
Applied rewrites42.9%
herbie shell --seed 2024359
(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))