
(FPCore (x) :precision binary64 (/ 2.0 (+ (exp x) (exp (- x)))))
double code(double x) {
return 2.0 / (exp(x) + exp(-x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / (exp(x) + exp(-x))
end function
public static double code(double x) {
return 2.0 / (Math.exp(x) + Math.exp(-x));
}
def code(x): return 2.0 / (math.exp(x) + math.exp(-x))
function code(x) return Float64(2.0 / Float64(exp(x) + exp(Float64(-x)))) end
function tmp = code(x) tmp = 2.0 / (exp(x) + exp(-x)); end
code[x_] := N[(2.0 / N[(N[Exp[x], $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{e^{x} + e^{-x}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ 2.0 (+ (exp x) (exp (- x)))))
double code(double x) {
return 2.0 / (exp(x) + exp(-x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / (exp(x) + exp(-x))
end function
public static double code(double x) {
return 2.0 / (Math.exp(x) + Math.exp(-x));
}
def code(x): return 2.0 / (math.exp(x) + math.exp(-x))
function code(x) return Float64(2.0 / Float64(exp(x) + exp(Float64(-x)))) end
function tmp = code(x) tmp = 2.0 / (exp(x) + exp(-x)); end
code[x_] := N[(2.0 / N[(N[Exp[x], $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{e^{x} + e^{-x}}
\end{array}
(FPCore (x) :precision binary64 (/ 2.0 (+ (exp x) (exp (- x)))))
double code(double x) {
return 2.0 / (exp(x) + exp(-x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / (exp(x) + exp(-x))
end function
public static double code(double x) {
return 2.0 / (Math.exp(x) + Math.exp(-x));
}
def code(x): return 2.0 / (math.exp(x) + math.exp(-x))
function code(x) return Float64(2.0 / Float64(exp(x) + exp(Float64(-x)))) end
function tmp = code(x) tmp = 2.0 / (exp(x) + exp(-x)); end
code[x_] := N[(2.0 / N[(N[Exp[x], $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{e^{x} + e^{-x}}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (+ (+ 1.0 (/ 2.0 (fma x x 2.0))) -1.0))
double code(double x) {
return (1.0 + (2.0 / fma(x, x, 2.0))) + -1.0;
}
function code(x) return Float64(Float64(1.0 + Float64(2.0 / fma(x, x, 2.0))) + -1.0) end
code[x_] := N[(N[(1.0 + N[(2.0 / N[(x * x + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(1 + \frac{2}{\mathsf{fma}\left(x, x, 2\right)}\right) + -1
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 76.6%
unpow276.6%
Simplified76.6%
expm1-log1p-u76.6%
expm1-udef98.7%
log1p-udef98.7%
add-exp-log98.7%
+-commutative98.7%
fma-def98.7%
Applied egg-rr98.7%
Final simplification98.7%
(FPCore (x) :precision binary64 (if (<= x 3.5) (/ 2.0 (+ 2.0 (* x x))) (* 4.0 (pow x -4.0))))
double code(double x) {
double tmp;
if (x <= 3.5) {
tmp = 2.0 / (2.0 + (x * x));
} else {
tmp = 4.0 * pow(x, -4.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 3.5d0) then
tmp = 2.0d0 / (2.0d0 + (x * x))
else
tmp = 4.0d0 * (x ** (-4.0d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 3.5) {
tmp = 2.0 / (2.0 + (x * x));
} else {
tmp = 4.0 * Math.pow(x, -4.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= 3.5: tmp = 2.0 / (2.0 + (x * x)) else: tmp = 4.0 * math.pow(x, -4.0) return tmp
function code(x) tmp = 0.0 if (x <= 3.5) tmp = Float64(2.0 / Float64(2.0 + Float64(x * x))); else tmp = Float64(4.0 * (x ^ -4.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 3.5) tmp = 2.0 / (2.0 + (x * x)); else tmp = 4.0 * (x ^ -4.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 3.5], N[(2.0 / N[(2.0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(4.0 * N[Power[x, -4.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.5:\\
\;\;\;\;\frac{2}{2 + x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;4 \cdot {x}^{-4}\\
\end{array}
\end{array}
if x < 3.5Initial program 100.0%
Taylor expanded in x around 0 83.6%
unpow283.6%
Simplified83.6%
if 3.5 < x Initial program 100.0%
Taylor expanded in x around 0 55.7%
unpow255.7%
Simplified55.7%
Taylor expanded in x around inf 55.7%
associate-*r/55.7%
metadata-eval55.7%
unpow255.7%
associate-*r/55.7%
metadata-eval55.7%
Simplified55.7%
Taylor expanded in x around 0 76.2%
metadata-eval76.2%
pow-sqr76.2%
pow-prod-down76.2%
pow276.2%
associate-/r*74.5%
metadata-eval74.5%
add-sqr-sqrt74.5%
sqrt-unprod74.5%
sqr-neg74.5%
sqrt-unprod0.0%
add-sqr-sqrt74.6%
frac-times74.6%
metadata-eval74.6%
frac-2neg74.6%
sqr-neg74.6%
frac-times74.6%
div-inv74.6%
associate-*l*74.6%
Applied egg-rr74.6%
associate-*r*74.6%
metadata-eval74.6%
associate-*r/74.6%
associate-*r*74.6%
unpow-174.6%
unpow-174.6%
pow-sqr74.6%
metadata-eval74.6%
swap-sqr74.6%
metadata-eval74.6%
pow-sqr74.6%
metadata-eval74.6%
Simplified74.6%
Final simplification81.4%
(FPCore (x) :precision binary64 (if (<= x 700.0) (/ 2.0 (+ 2.0 (* x x))) (/ -4.0 (pow x 4.0))))
double code(double x) {
double tmp;
if (x <= 700.0) {
tmp = 2.0 / (2.0 + (x * x));
} else {
tmp = -4.0 / pow(x, 4.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 700.0d0) then
tmp = 2.0d0 / (2.0d0 + (x * x))
else
tmp = (-4.0d0) / (x ** 4.0d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 700.0) {
tmp = 2.0 / (2.0 + (x * x));
} else {
tmp = -4.0 / Math.pow(x, 4.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= 700.0: tmp = 2.0 / (2.0 + (x * x)) else: tmp = -4.0 / math.pow(x, 4.0) return tmp
function code(x) tmp = 0.0 if (x <= 700.0) tmp = Float64(2.0 / Float64(2.0 + Float64(x * x))); else tmp = Float64(-4.0 / (x ^ 4.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 700.0) tmp = 2.0 / (2.0 + (x * x)); else tmp = -4.0 / (x ^ 4.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 700.0], N[(2.0 / N[(2.0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-4.0 / N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 700:\\
\;\;\;\;\frac{2}{2 + x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{-4}{{x}^{4}}\\
\end{array}
\end{array}
if x < 700Initial program 100.0%
Taylor expanded in x around 0 83.2%
unpow283.2%
Simplified83.2%
if 700 < x Initial program 100.0%
Taylor expanded in x around 0 56.4%
unpow256.4%
Simplified56.4%
Taylor expanded in x around inf 56.4%
associate-*r/56.4%
metadata-eval56.4%
unpow256.4%
associate-*r/56.4%
metadata-eval56.4%
Simplified56.4%
Taylor expanded in x around 0 77.4%
Final simplification81.8%
(FPCore (x) :precision binary64 (if (<= x 1.42) 1.0 (/ 2.0 (* x x))))
double code(double x) {
double tmp;
if (x <= 1.42) {
tmp = 1.0;
} else {
tmp = 2.0 / (x * x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.42d0) then
tmp = 1.0d0
else
tmp = 2.0d0 / (x * x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.42) {
tmp = 1.0;
} else {
tmp = 2.0 / (x * x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.42: tmp = 1.0 else: tmp = 2.0 / (x * x) return tmp
function code(x) tmp = 0.0 if (x <= 1.42) tmp = 1.0; else tmp = Float64(2.0 / Float64(x * x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.42) tmp = 1.0; else tmp = 2.0 / (x * x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.42], 1.0, N[(2.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.42:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{x \cdot x}\\
\end{array}
\end{array}
if x < 1.4199999999999999Initial program 100.0%
Taylor expanded in x around 0 66.6%
if 1.4199999999999999 < x Initial program 100.0%
Taylor expanded in x around 0 55.7%
unpow255.7%
Simplified55.7%
Taylor expanded in x around inf 55.7%
unpow255.7%
Simplified55.7%
Final simplification63.9%
(FPCore (x) :precision binary64 (/ 2.0 (+ 2.0 (* x x))))
double code(double x) {
return 2.0 / (2.0 + (x * x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 2.0d0 / (2.0d0 + (x * x))
end function
public static double code(double x) {
return 2.0 / (2.0 + (x * x));
}
def code(x): return 2.0 / (2.0 + (x * x))
function code(x) return Float64(2.0 / Float64(2.0 + Float64(x * x))) end
function tmp = code(x) tmp = 2.0 / (2.0 + (x * x)); end
code[x_] := N[(2.0 / N[(2.0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{2}{2 + x \cdot x}
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 76.6%
unpow276.6%
Simplified76.6%
Final simplification76.6%
(FPCore (x) :precision binary64 1.0)
double code(double x) {
return 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0
end function
public static double code(double x) {
return 1.0;
}
def code(x): return 1.0
function code(x) return 1.0 end
function tmp = code(x) tmp = 1.0; end
code[x_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 50.8%
Final simplification50.8%
herbie shell --seed 2023278
(FPCore (x)
:name "Hyperbolic secant"
:precision binary64
(/ 2.0 (+ (exp x) (exp (- x)))))