
(FPCore (x eps) :precision binary64 (/ (- (* (+ 1.0 (/ 1.0 eps)) (exp (- (* (- 1.0 eps) x)))) (* (- (/ 1.0 eps) 1.0) (exp (- (* (+ 1.0 eps) x))))) 2.0))
double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, eps)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (((1.0d0 + (1.0d0 / eps)) * exp(-((1.0d0 - eps) * x))) - (((1.0d0 / eps) - 1.0d0) * exp(-((1.0d0 + eps) * x)))) / 2.0d0
end function
public static double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * Math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * Math.exp(-((1.0 + eps) * x)))) / 2.0;
}
def code(x, eps): return (((1.0 + (1.0 / eps)) * math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * math.exp(-((1.0 + eps) * x)))) / 2.0
function code(x, eps) return Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(-Float64(Float64(1.0 - eps) * x)))) - Float64(Float64(Float64(1.0 / eps) - 1.0) * exp(Float64(-Float64(Float64(1.0 + eps) * x))))) / 2.0) end
function tmp = code(x, eps) tmp = (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0; end
code[x_, eps_] := N[(N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[(-N[(N[(1.0 - eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[(-N[(N[(1.0 + eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 16 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (/ (- (* (+ 1.0 (/ 1.0 eps)) (exp (- (* (- 1.0 eps) x)))) (* (- (/ 1.0 eps) 1.0) (exp (- (* (+ 1.0 eps) x))))) 2.0))
double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, eps)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (((1.0d0 + (1.0d0 / eps)) * exp(-((1.0d0 - eps) * x))) - (((1.0d0 / eps) - 1.0d0) * exp(-((1.0d0 + eps) * x)))) / 2.0d0
end function
public static double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * Math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * Math.exp(-((1.0 + eps) * x)))) / 2.0;
}
def code(x, eps): return (((1.0 + (1.0 / eps)) * math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * math.exp(-((1.0 + eps) * x)))) / 2.0
function code(x, eps) return Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(-Float64(Float64(1.0 - eps) * x)))) - Float64(Float64(Float64(1.0 / eps) - 1.0) * exp(Float64(-Float64(Float64(1.0 + eps) * x))))) / 2.0) end
function tmp = code(x, eps) tmp = (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0; end
code[x_, eps_] := N[(N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[(-N[(N[(1.0 - eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[(-N[(N[(1.0 + eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2}
\end{array}
(FPCore (x eps)
:precision binary64
(let* ((t_0
(/
(-
(* (+ 1.0 (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) (/ (* 0.5 (+ (+ x x) 2.0)) (exp x)) 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 = (0.5 * ((x + x) + 2.0)) / exp(x);
} 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 = (0.5d0 * ((x + x) + 2.0d0)) / exp(x)
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 = (0.5 * ((x + x) + 2.0)) / Math.exp(x);
} 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 = (0.5 * ((x + x) + 2.0)) / math.exp(x) 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(0.5 * Float64(Float64(x + x) + 2.0)) / exp(x)); 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 = (0.5 * ((x + x) + 2.0)) / exp(x); 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[(0.5 * N[(N[(x + x), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $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:\\
\;\;\;\;\frac{0.5 \cdot \left(\left(x + x\right) + 2\right)}{e^{x}}\\
\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 31.4%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Applied rewrites100.0%
Applied rewrites100.0%
if 0.0 < (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) Initial program 98.6%
Final simplification99.2%
(FPCore (x eps)
:precision binary64
(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)) (+ 2.0 x)) 0.5)
(/
(- (fma (fma x (pow eps -1.0) x) (- eps 1.0) (+ (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) * (2.0 + x)) * 0.5;
} else {
tmp = (fma(fma(x, pow(eps, -1.0), x), (eps - 1.0), (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(2.0 + x)) * 0.5); else tmp = Float64(Float64(fma(fma(x, (eps ^ -1.0), x), Float64(eps - 1.0), Float64((eps ^ -1.0) + 1.0)) - t_0) / 2.0); end return 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[(2.0 + x), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(N[(x * N[Power[eps, -1.0], $MachinePrecision] + x), $MachinePrecision] * N[(eps - 1.0), $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(2 + x\right)\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(x, {\varepsilon}^{-1}, x\right), \varepsilon - 1, {\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 50.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites98.9%
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 98.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6452.0
Applied rewrites52.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-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-/.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f6418.7
Applied rewrites18.7%
Final simplification67.2%
(FPCore (x eps)
:precision binary64
(if (<=
(/
(-
(* (+ 1.0 (pow eps -1.0)) (exp (* (+ -1.0 eps) x)))
(* (- (pow eps -1.0) 1.0) (exp (* (- -1.0 eps) x))))
2.0)
2.0)
(/ (* 0.5 (+ (+ x x) 2.0)) (exp x))
(/ (- (+ (pow eps -1.0) 1.0) (- (exp (- (fma eps x x))))) 2.0)))
double code(double x, double eps) {
double tmp;
if (((((1.0 + pow(eps, -1.0)) * exp(((-1.0 + eps) * x))) - ((pow(eps, -1.0) - 1.0) * exp(((-1.0 - eps) * x)))) / 2.0) <= 2.0) {
tmp = (0.5 * ((x + x) + 2.0)) / exp(x);
} else {
tmp = ((pow(eps, -1.0) + 1.0) - -exp(-fma(eps, x, x))) / 2.0;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(Float64(Float64(Float64(1.0 + (eps ^ -1.0)) * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(Float64((eps ^ -1.0) - 1.0) * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0) <= 2.0) tmp = Float64(Float64(0.5 * Float64(Float64(x + x) + 2.0)) / exp(x)); else tmp = Float64(Float64(Float64((eps ^ -1.0) + 1.0) - Float64(-exp(Float64(-fma(eps, x, x))))) / 2.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], 2.0], N[(N[(0.5 * N[(N[(x + x), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Power[eps, -1.0], $MachinePrecision] + 1.0), $MachinePrecision] - (-N[Exp[(-N[(eps * x + x), $MachinePrecision])], $MachinePrecision])), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left(1 + {\varepsilon}^{-1}\right) \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - \left({\varepsilon}^{-1} - 1\right) \cdot e^{\left(-1 - \varepsilon\right) \cdot x}}{2} \leq 2:\\
\;\;\;\;\frac{0.5 \cdot \left(\left(x + x\right) + 2\right)}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left({\varepsilon}^{-1} + 1\right) - \left(-e^{-\mathsf{fma}\left(\varepsilon, x, x\right)}\right)}{2}\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) < 2Initial program 50.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Applied rewrites100.0%
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 98.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6451.1
Applied rewrites51.1%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6449.1
Applied rewrites49.1%
Applied rewrites49.1%
Final simplification79.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)
(* (/ 2.0 (fma (fma (fma 0.16666666666666666 x 0.5) x 1.0) x 1.0)) 0.5)
(fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0)))
double code(double x, double eps) {
double tmp;
if (((((1.0 + 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 = (2.0 / fma(fma(fma(0.16666666666666666, x, 0.5), x, 1.0), x, 1.0)) * 0.5;
} else {
tmp = fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(Float64(Float64(Float64(1.0 + (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(2.0 / fma(fma(fma(0.16666666666666666, x, 0.5), x, 1.0), x, 1.0)) * 0.5); else tmp = fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0); end return tmp end
code[x_, eps_] := If[LessEqual[N[(N[(N[(N[(1.0 + N[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[(2.0 / N[(N[(N[(0.16666666666666666 * x + 0.5), $MachinePrecision] * x + 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left(1 + {\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:\\
\;\;\;\;\frac{2}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, x, 0.5\right), x, 1\right), x, 1\right)} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) < 0.0Initial program 31.4%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites98.4%
Taylor expanded in x around 0
Applied rewrites85.8%
if 0.0 < (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) Initial program 98.6%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites31.8%
Applied rewrites31.8%
Taylor expanded in x around 0
Applied rewrites42.4%
Final simplification61.6%
(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)
(* (/ 2.0 (fma (fma 0.5 x 1.0) x 1.0)) 0.5)
(fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0)))
double code(double x, double eps) {
double tmp;
if (((((1.0 + 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 = (2.0 / fma(fma(0.5, x, 1.0), x, 1.0)) * 0.5;
} else {
tmp = fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(Float64(Float64(Float64(1.0 + (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(2.0 / fma(fma(0.5, x, 1.0), x, 1.0)) * 0.5); else tmp = fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0); end return tmp end
code[x_, eps_] := If[LessEqual[N[(N[(N[(N[(1.0 + N[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[(2.0 / N[(N[(0.5 * x + 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\left(1 + {\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:\\
\;\;\;\;\frac{2}{\mathsf{fma}\left(\mathsf{fma}\left(0.5, x, 1\right), x, 1\right)} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)\\
\end{array}
\end{array}
if (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) < 0.0Initial program 31.4%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites98.4%
Taylor expanded in x around 0
Applied rewrites84.0%
if 0.0 < (/.f64 (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) #s(literal 2 binary64)) Initial program 98.6%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites31.8%
Applied rewrites31.8%
Taylor expanded in x around 0
Applied rewrites42.4%
Final simplification60.8%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (pow eps -1.0) 1.0)) (t_1 (+ (pow eps -1.0) 1.0)))
(if (<= eps -1.85e+170)
(/ (- (* (exp (- (* eps x) x)) t_1) t_0) 2.0)
(if (<= eps -29.0)
(/ (- t_1 (* t_0 (exp (* (- -1.0 eps) x)))) 2.0)
(if (<= eps 1.15e+15)
(/ (* 0.5 (+ (+ x x) 2.0)) (exp x))
(if (<= eps 3.9e+208)
(/ (- t_1 (- (exp (- (fma eps x x))))) 2.0)
(/ (- (* (pow eps -1.0) (exp (* (+ -1.0 eps) x))) t_0) 2.0)))))))
double code(double x, double eps) {
double t_0 = pow(eps, -1.0) - 1.0;
double t_1 = pow(eps, -1.0) + 1.0;
double tmp;
if (eps <= -1.85e+170) {
tmp = ((exp(((eps * x) - x)) * t_1) - t_0) / 2.0;
} else if (eps <= -29.0) {
tmp = (t_1 - (t_0 * exp(((-1.0 - eps) * x)))) / 2.0;
} else if (eps <= 1.15e+15) {
tmp = (0.5 * ((x + x) + 2.0)) / exp(x);
} else if (eps <= 3.9e+208) {
tmp = (t_1 - -exp(-fma(eps, x, x))) / 2.0;
} else {
tmp = ((pow(eps, -1.0) * exp(((-1.0 + eps) * x))) - t_0) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64((eps ^ -1.0) - 1.0) t_1 = Float64((eps ^ -1.0) + 1.0) tmp = 0.0 if (eps <= -1.85e+170) tmp = Float64(Float64(Float64(exp(Float64(Float64(eps * x) - x)) * t_1) - t_0) / 2.0); elseif (eps <= -29.0) tmp = Float64(Float64(t_1 - Float64(t_0 * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0); elseif (eps <= 1.15e+15) tmp = Float64(Float64(0.5 * Float64(Float64(x + x) + 2.0)) / exp(x)); elseif (eps <= 3.9e+208) tmp = Float64(Float64(t_1 - Float64(-exp(Float64(-fma(eps, x, x))))) / 2.0); else tmp = Float64(Float64(Float64((eps ^ -1.0) * exp(Float64(Float64(-1.0 + eps) * x))) - t_0) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[eps, -1.0], $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[eps, -1.85e+170], N[(N[(N[(N[Exp[N[(N[(eps * x), $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision] * t$95$1), $MachinePrecision] - t$95$0), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[eps, -29.0], N[(N[(t$95$1 - N[(t$95$0 * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[eps, 1.15e+15], N[(N[(0.5 * N[(N[(x + x), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 3.9e+208], N[(N[(t$95$1 - (-N[Exp[(-N[(eps * x + x), $MachinePrecision])], $MachinePrecision])), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(N[Power[eps, -1.0], $MachinePrecision] * N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision] / 2.0), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\varepsilon}^{-1} - 1\\
t_1 := {\varepsilon}^{-1} + 1\\
\mathbf{if}\;\varepsilon \leq -1.85 \cdot 10^{+170}:\\
\;\;\;\;\frac{e^{\varepsilon \cdot x - x} \cdot t\_1 - t\_0}{2}\\
\mathbf{elif}\;\varepsilon \leq -29:\\
\;\;\;\;\frac{t\_1 - t\_0 \cdot e^{\left(-1 - \varepsilon\right) \cdot x}}{2}\\
\mathbf{elif}\;\varepsilon \leq 1.15 \cdot 10^{+15}:\\
\;\;\;\;\frac{0.5 \cdot \left(\left(x + x\right) + 2\right)}{e^{x}}\\
\mathbf{elif}\;\varepsilon \leq 3.9 \cdot 10^{+208}:\\
\;\;\;\;\frac{t\_1 - \left(-e^{-\mathsf{fma}\left(\varepsilon, x, x\right)}\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{{\varepsilon}^{-1} \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - t\_0}{2}\\
\end{array}
\end{array}
if eps < -1.84999999999999994e170Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6441.2
Applied rewrites41.2%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6413.5
Applied rewrites13.5%
Taylor expanded in x around inf
lower-*.f64N/A
lower-exp.f64N/A
lower--.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f6472.3
Applied rewrites72.3%
if -1.84999999999999994e170 < eps < -29Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6481.7
Applied rewrites81.7%
if -29 < eps < 1.15e15Initial program 34.8%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Applied rewrites100.0%
Applied rewrites100.0%
if 1.15e15 < eps < 3.9000000000000001e208Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6476.7
Applied rewrites76.7%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6476.7
Applied rewrites76.7%
Applied rewrites76.7%
if 3.9000000000000001e208 < eps Initial program 100.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6470.5
Applied rewrites70.5%
Taylor expanded in eps around 0
lower-/.f6470.5
Applied rewrites70.5%
Final simplification87.4%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (pow eps -1.0) 1.0))
(t_1 (+ (pow eps -1.0) 1.0))
(t_2 (/ (- t_1 (- (exp (- (fma eps x x))))) 2.0)))
(if (<= eps -1.85e+170)
(/ (- (* (exp (- (* eps x) x)) t_1) t_0) 2.0)
(if (<= eps -4e+22)
t_2
(if (<= eps 1.15e+15)
(/ (* 0.5 (+ (+ x x) 2.0)) (exp x))
(if (<= eps 3.9e+208)
t_2
(/ (- (* (pow eps -1.0) (exp (* (+ -1.0 eps) x))) t_0) 2.0)))))))
double code(double x, double eps) {
double t_0 = pow(eps, -1.0) - 1.0;
double t_1 = pow(eps, -1.0) + 1.0;
double t_2 = (t_1 - -exp(-fma(eps, x, x))) / 2.0;
double tmp;
if (eps <= -1.85e+170) {
tmp = ((exp(((eps * x) - x)) * t_1) - t_0) / 2.0;
} else if (eps <= -4e+22) {
tmp = t_2;
} else if (eps <= 1.15e+15) {
tmp = (0.5 * ((x + x) + 2.0)) / exp(x);
} else if (eps <= 3.9e+208) {
tmp = t_2;
} else {
tmp = ((pow(eps, -1.0) * exp(((-1.0 + eps) * x))) - t_0) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64((eps ^ -1.0) - 1.0) t_1 = Float64((eps ^ -1.0) + 1.0) t_2 = Float64(Float64(t_1 - Float64(-exp(Float64(-fma(eps, x, x))))) / 2.0) tmp = 0.0 if (eps <= -1.85e+170) tmp = Float64(Float64(Float64(exp(Float64(Float64(eps * x) - x)) * t_1) - t_0) / 2.0); elseif (eps <= -4e+22) tmp = t_2; elseif (eps <= 1.15e+15) tmp = Float64(Float64(0.5 * Float64(Float64(x + x) + 2.0)) / exp(x)); elseif (eps <= 3.9e+208) tmp = t_2; else tmp = Float64(Float64(Float64((eps ^ -1.0) * exp(Float64(Float64(-1.0 + eps) * x))) - t_0) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[eps, -1.0], $MachinePrecision] + 1.0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(t$95$1 - (-N[Exp[(-N[(eps * x + x), $MachinePrecision])], $MachinePrecision])), $MachinePrecision] / 2.0), $MachinePrecision]}, If[LessEqual[eps, -1.85e+170], N[(N[(N[(N[Exp[N[(N[(eps * x), $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision] * t$95$1), $MachinePrecision] - t$95$0), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[eps, -4e+22], t$95$2, If[LessEqual[eps, 1.15e+15], N[(N[(0.5 * N[(N[(x + x), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 3.9e+208], t$95$2, N[(N[(N[(N[Power[eps, -1.0], $MachinePrecision] * N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision] / 2.0), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\varepsilon}^{-1} - 1\\
t_1 := {\varepsilon}^{-1} + 1\\
t_2 := \frac{t\_1 - \left(-e^{-\mathsf{fma}\left(\varepsilon, x, x\right)}\right)}{2}\\
\mathbf{if}\;\varepsilon \leq -1.85 \cdot 10^{+170}:\\
\;\;\;\;\frac{e^{\varepsilon \cdot x - x} \cdot t\_1 - t\_0}{2}\\
\mathbf{elif}\;\varepsilon \leq -4 \cdot 10^{+22}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;\varepsilon \leq 1.15 \cdot 10^{+15}:\\
\;\;\;\;\frac{0.5 \cdot \left(\left(x + x\right) + 2\right)}{e^{x}}\\
\mathbf{elif}\;\varepsilon \leq 3.9 \cdot 10^{+208}:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;\frac{{\varepsilon}^{-1} \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - t\_0}{2}\\
\end{array}
\end{array}
if eps < -1.84999999999999994e170Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6441.2
Applied rewrites41.2%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6413.5
Applied rewrites13.5%
Taylor expanded in x around inf
lower-*.f64N/A
lower-exp.f64N/A
lower--.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f6472.3
Applied rewrites72.3%
if -1.84999999999999994e170 < eps < -4e22 or 1.15e15 < eps < 3.9000000000000001e208Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6479.1
Applied rewrites79.1%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6479.1
Applied rewrites79.1%
Applied rewrites79.1%
if -4e22 < eps < 1.15e15Initial program 36.4%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.2%
Applied rewrites99.2%
Applied rewrites99.2%
if 3.9000000000000001e208 < eps Initial program 100.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6470.5
Applied rewrites70.5%
Taylor expanded in eps around 0
lower-/.f6470.5
Applied rewrites70.5%
Final simplification87.4%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (/ (- (+ (pow eps -1.0) 1.0) (- (exp (- (fma eps x x))))) 2.0)))
(if (<= eps -4e+22)
t_0
(if (<= eps 1.15e+15)
(/ (* 0.5 (+ (+ x x) 2.0)) (exp x))
(if (<= eps 3.9e+208)
t_0
(/
(-
(* (pow eps -1.0) (exp (* (+ -1.0 eps) x)))
(- (pow eps -1.0) 1.0))
2.0))))))
double code(double x, double eps) {
double t_0 = ((pow(eps, -1.0) + 1.0) - -exp(-fma(eps, x, x))) / 2.0;
double tmp;
if (eps <= -4e+22) {
tmp = t_0;
} else if (eps <= 1.15e+15) {
tmp = (0.5 * ((x + x) + 2.0)) / exp(x);
} else if (eps <= 3.9e+208) {
tmp = t_0;
} else {
tmp = ((pow(eps, -1.0) * exp(((-1.0 + eps) * x))) - (pow(eps, -1.0) - 1.0)) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(Float64((eps ^ -1.0) + 1.0) - Float64(-exp(Float64(-fma(eps, x, x))))) / 2.0) tmp = 0.0 if (eps <= -4e+22) tmp = t_0; elseif (eps <= 1.15e+15) tmp = Float64(Float64(0.5 * Float64(Float64(x + x) + 2.0)) / exp(x)); elseif (eps <= 3.9e+208) tmp = t_0; else tmp = Float64(Float64(Float64((eps ^ -1.0) * exp(Float64(Float64(-1.0 + eps) * x))) - Float64((eps ^ -1.0) - 1.0)) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(N[(N[Power[eps, -1.0], $MachinePrecision] + 1.0), $MachinePrecision] - (-N[Exp[(-N[(eps * x + x), $MachinePrecision])], $MachinePrecision])), $MachinePrecision] / 2.0), $MachinePrecision]}, If[LessEqual[eps, -4e+22], t$95$0, If[LessEqual[eps, 1.15e+15], N[(N[(0.5 * N[(N[(x + x), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 3.9e+208], t$95$0, N[(N[(N[(N[Power[eps, -1.0], $MachinePrecision] * N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\left({\varepsilon}^{-1} + 1\right) - \left(-e^{-\mathsf{fma}\left(\varepsilon, x, x\right)}\right)}{2}\\
\mathbf{if}\;\varepsilon \leq -4 \cdot 10^{+22}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;\varepsilon \leq 1.15 \cdot 10^{+15}:\\
\;\;\;\;\frac{0.5 \cdot \left(\left(x + x\right) + 2\right)}{e^{x}}\\
\mathbf{elif}\;\varepsilon \leq 3.9 \cdot 10^{+208}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{{\varepsilon}^{-1} \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - \left({\varepsilon}^{-1} - 1\right)}{2}\\
\end{array}
\end{array}
if eps < -4e22 or 1.15e15 < eps < 3.9000000000000001e208Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6469.3
Applied rewrites69.3%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6469.3
Applied rewrites69.3%
Applied rewrites69.3%
if -4e22 < eps < 1.15e15Initial program 36.4%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.2%
Applied rewrites99.2%
Applied rewrites99.2%
if 3.9000000000000001e208 < eps Initial program 100.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6470.5
Applied rewrites70.5%
Taylor expanded in eps around 0
lower-/.f6470.5
Applied rewrites70.5%
Final simplification84.0%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (pow eps -1.0) 1.0)))
(if (<= x -150.0)
(/ (+ t_0 (* (- (/ -1.0 eps) -1.0) (fma (- -1.0 eps) x 1.0))) 2.0)
(if (<= x 0.32)
(fma (- (* (fma -0.125 x 0.3333333333333333) x) 0.5) (* x x) 1.0)
(/ (- t_0 (- (pow eps -1.0) 1.0)) 2.0)))))
double code(double x, double eps) {
double t_0 = pow(eps, -1.0) + 1.0;
double tmp;
if (x <= -150.0) {
tmp = (t_0 + (((-1.0 / eps) - -1.0) * fma((-1.0 - eps), x, 1.0))) / 2.0;
} else if (x <= 0.32) {
tmp = fma(((fma(-0.125, x, 0.3333333333333333) * x) - 0.5), (x * x), 1.0);
} else {
tmp = (t_0 - (pow(eps, -1.0) - 1.0)) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64((eps ^ -1.0) + 1.0) tmp = 0.0 if (x <= -150.0) tmp = Float64(Float64(t_0 + Float64(Float64(Float64(-1.0 / eps) - -1.0) * fma(Float64(-1.0 - eps), x, 1.0))) / 2.0); elseif (x <= 0.32) tmp = fma(Float64(Float64(fma(-0.125, x, 0.3333333333333333) * x) - 0.5), Float64(x * x), 1.0); else tmp = Float64(Float64(t_0 - Float64((eps ^ -1.0) - 1.0)) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[eps, -1.0], $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[x, -150.0], N[(N[(t$95$0 + N[(N[(N[(-1.0 / eps), $MachinePrecision] - -1.0), $MachinePrecision] * N[(N[(-1.0 - eps), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 0.32], N[(N[(N[(N[(-0.125 * x + 0.3333333333333333), $MachinePrecision] * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(t$95$0 - N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\varepsilon}^{-1} + 1\\
\mathbf{if}\;x \leq -150:\\
\;\;\;\;\frac{t\_0 + \left(\frac{-1}{\varepsilon} - -1\right) \cdot \mathsf{fma}\left(-1 - \varepsilon, x, 1\right)}{2}\\
\mathbf{elif}\;x \leq 0.32:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.125, x, 0.3333333333333333\right) \cdot x - 0.5, x \cdot x, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - \left({\varepsilon}^{-1} - 1\right)}{2}\\
\end{array}
\end{array}
if x < -150Initial program 95.1%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6462.2
Applied rewrites62.2%
Taylor expanded in x around 0
mul-1-negN/A
+-commutativeN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
lower-fma.f64N/A
distribute-lft-inN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6424.6
Applied rewrites24.6%
if -150 < x < 0.320000000000000007Initial program 50.3%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites78.9%
Applied rewrites78.9%
Taylor expanded in x around 0
Applied rewrites78.9%
if 0.320000000000000007 < x Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6422.3
Applied rewrites22.3%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6457.3
Applied rewrites57.3%
Final simplification65.2%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (pow eps -1.0) 1.0)))
(if (<= x -11000000000000.0)
(/ (- t_0 (- (fma eps x x) 1.0)) 2.0)
(if (<= x 0.32)
(fma (- (* (fma -0.125 x 0.3333333333333333) x) 0.5) (* x x) 1.0)
(/ (- t_0 (- (pow eps -1.0) 1.0)) 2.0)))))
double code(double x, double eps) {
double t_0 = pow(eps, -1.0) + 1.0;
double tmp;
if (x <= -11000000000000.0) {
tmp = (t_0 - (fma(eps, x, x) - 1.0)) / 2.0;
} else if (x <= 0.32) {
tmp = fma(((fma(-0.125, x, 0.3333333333333333) * x) - 0.5), (x * x), 1.0);
} else {
tmp = (t_0 - (pow(eps, -1.0) - 1.0)) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64((eps ^ -1.0) + 1.0) tmp = 0.0 if (x <= -11000000000000.0) tmp = Float64(Float64(t_0 - Float64(fma(eps, x, x) - 1.0)) / 2.0); elseif (x <= 0.32) tmp = fma(Float64(Float64(fma(-0.125, x, 0.3333333333333333) * x) - 0.5), Float64(x * x), 1.0); else tmp = Float64(Float64(t_0 - Float64((eps ^ -1.0) - 1.0)) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Power[eps, -1.0], $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[x, -11000000000000.0], N[(N[(t$95$0 - N[(N[(eps * x + x), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 0.32], N[(N[(N[(N[(-0.125 * x + 0.3333333333333333), $MachinePrecision] * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(t$95$0 - N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\varepsilon}^{-1} + 1\\
\mathbf{if}\;x \leq -11000000000000:\\
\;\;\;\;\frac{t\_0 - \left(\mathsf{fma}\left(\varepsilon, x, x\right) - 1\right)}{2}\\
\mathbf{elif}\;x \leq 0.32:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.125, x, 0.3333333333333333\right) \cdot x - 0.5, x \cdot x, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - \left({\varepsilon}^{-1} - 1\right)}{2}\\
\end{array}
\end{array}
if x < -1.1e13Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6461.8
Applied rewrites61.8%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6461.8
Applied rewrites61.8%
Taylor expanded in x around 0
Applied rewrites26.2%
if -1.1e13 < x < 0.320000000000000007Initial program 50.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites78.6%
Applied rewrites78.7%
Taylor expanded in x around 0
Applied rewrites77.4%
if 0.320000000000000007 < x Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6422.3
Applied rewrites22.3%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6457.3
Applied rewrites57.3%
Final simplification65.2%
(FPCore (x eps)
:precision binary64
(if (<= x -11000000000000.0)
(/ (- (+ (pow eps -1.0) 1.0) (- (fma eps x x) 1.0)) 2.0)
(if (<= x 1.8)
(fma (- (* (fma -0.125 x 0.3333333333333333) x) 0.5) (* x x) 1.0)
(/ (- (pow eps -1.0) (- (pow eps -1.0) 1.0)) 2.0))))
double code(double x, double eps) {
double tmp;
if (x <= -11000000000000.0) {
tmp = ((pow(eps, -1.0) + 1.0) - (fma(eps, x, x) - 1.0)) / 2.0;
} else if (x <= 1.8) {
tmp = fma(((fma(-0.125, x, 0.3333333333333333) * x) - 0.5), (x * x), 1.0);
} else {
tmp = (pow(eps, -1.0) - (pow(eps, -1.0) - 1.0)) / 2.0;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -11000000000000.0) tmp = Float64(Float64(Float64((eps ^ -1.0) + 1.0) - Float64(fma(eps, x, x) - 1.0)) / 2.0); elseif (x <= 1.8) tmp = fma(Float64(Float64(fma(-0.125, x, 0.3333333333333333) * x) - 0.5), Float64(x * x), 1.0); else tmp = Float64(Float64((eps ^ -1.0) - Float64((eps ^ -1.0) - 1.0)) / 2.0); end return tmp end
code[x_, eps_] := If[LessEqual[x, -11000000000000.0], N[(N[(N[(N[Power[eps, -1.0], $MachinePrecision] + 1.0), $MachinePrecision] - N[(N[(eps * x + x), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.8], N[(N[(N[(N[(-0.125 * x + 0.3333333333333333), $MachinePrecision] * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(N[Power[eps, -1.0], $MachinePrecision] - N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -11000000000000:\\
\;\;\;\;\frac{\left({\varepsilon}^{-1} + 1\right) - \left(\mathsf{fma}\left(\varepsilon, x, x\right) - 1\right)}{2}\\
\mathbf{elif}\;x \leq 1.8:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.125, x, 0.3333333333333333\right) \cdot x - 0.5, x \cdot x, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{{\varepsilon}^{-1} - \left({\varepsilon}^{-1} - 1\right)}{2}\\
\end{array}
\end{array}
if x < -1.1e13Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6461.8
Applied rewrites61.8%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6461.8
Applied rewrites61.8%
Taylor expanded in x around 0
Applied rewrites26.2%
if -1.1e13 < x < 1.80000000000000004Initial program 50.3%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites78.2%
Applied rewrites78.2%
Taylor expanded in x around 0
Applied rewrites76.9%
if 1.80000000000000004 < x Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
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%
Final simplification65.2%
(FPCore (x eps) :precision binary64 (* (/ 2.0 (exp x)) 0.5))
double code(double x, double eps) {
return (2.0 / exp(x)) * 0.5;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x, eps)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (2.0d0 / exp(x)) * 0.5d0
end function
public static double code(double x, double eps) {
return (2.0 / Math.exp(x)) * 0.5;
}
def code(x, eps): return (2.0 / math.exp(x)) * 0.5
function code(x, eps) return Float64(Float64(2.0 / exp(x)) * 0.5) end
function tmp = code(x, eps) tmp = (2.0 / exp(x)) * 0.5; end
code[x_, eps_] := N[(N[(2.0 / N[Exp[x], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{e^{x}} \cdot 0.5
\end{array}
Initial program 68.9%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites61.9%
Applied rewrites61.9%
Taylor expanded in x around 0
Applied rewrites75.7%
(FPCore (x eps) :precision binary64 (if (<= x 2e+207) (fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0) (/ x (fma (fma 0.5 x 1.0) x 1.0))))
double code(double x, double eps) {
double tmp;
if (x <= 2e+207) {
tmp = fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
} else {
tmp = x / fma(fma(0.5, x, 1.0), x, 1.0);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 2e+207) tmp = fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0); else tmp = Float64(x / fma(fma(0.5, x, 1.0), x, 1.0)); end return tmp end
code[x_, eps_] := If[LessEqual[x, 2e+207], N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], N[(x / N[(N[(0.5 * x + 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2 \cdot 10^{+207}:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(\mathsf{fma}\left(0.5, x, 1\right), x, 1\right)}\\
\end{array}
\end{array}
if x < 2.0000000000000001e207Initial program 66.7%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites61.3%
Applied rewrites61.3%
Taylor expanded in x around 0
Applied rewrites56.8%
if 2.0000000000000001e207 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites71.0%
Applied rewrites71.0%
Taylor expanded in x around inf
Applied rewrites71.0%
Taylor expanded in x around 0
Applied rewrites71.0%
(FPCore (x eps) :precision binary64 (if (<= x 5e+55) 1.0 (* (fma (- (* 0.5 x) 1.0) x 1.0) x)))
double code(double x, double eps) {
double tmp;
if (x <= 5e+55) {
tmp = 1.0;
} else {
tmp = fma(((0.5 * x) - 1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 5e+55) tmp = 1.0; else tmp = Float64(fma(Float64(Float64(0.5 * x) - 1.0), x, 1.0) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, 5e+55], 1.0, N[(N[(N[(N[(0.5 * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5 \cdot 10^{+55}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x - 1, x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < 5.00000000000000046e55Initial program 62.1%
Taylor expanded in x around 0
Applied rewrites58.8%
if 5.00000000000000046e55 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites52.9%
Applied rewrites52.9%
Taylor expanded in x around inf
Applied rewrites52.9%
Taylor expanded in x around 0
Applied rewrites38.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 68.9%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites61.9%
Applied rewrites61.9%
Taylor expanded in x around 0
Applied rewrites55.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 68.9%
Taylor expanded in x around 0
Applied rewrites48.8%
herbie shell --seed 2024363
(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))