
(FPCore (x) :precision binary64 (/ (- (exp x) (exp (- x))) 2.0))
double code(double x) {
return (exp(x) - exp(-x)) / 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (exp(x) - exp(-x)) / 2.0d0
end function
public static double code(double x) {
return (Math.exp(x) - Math.exp(-x)) / 2.0;
}
def code(x): return (math.exp(x) - math.exp(-x)) / 2.0
function code(x) return Float64(Float64(exp(x) - exp(Float64(-x))) / 2.0) end
function tmp = code(x) tmp = (exp(x) - exp(-x)) / 2.0; end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{x} - e^{-x}}{2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ (- (exp x) (exp (- x))) 2.0))
double code(double x) {
return (exp(x) - exp(-x)) / 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (exp(x) - exp(-x)) / 2.0d0
end function
public static double code(double x) {
return (Math.exp(x) - Math.exp(-x)) / 2.0;
}
def code(x): return (math.exp(x) - math.exp(-x)) / 2.0
function code(x) return Float64(Float64(exp(x) - exp(Float64(-x))) / 2.0) end
function tmp = code(x) tmp = (exp(x) - exp(-x)) / 2.0; end
code[x_] := N[(N[(N[Exp[x], $MachinePrecision] - N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{x} - e^{-x}}{2}
\end{array}
(FPCore (x) :precision binary64 (log1p (expm1 x)))
double code(double x) {
return log1p(expm1(x));
}
public static double code(double x) {
return Math.log1p(Math.expm1(x));
}
def code(x): return math.log1p(math.expm1(x))
function code(x) return log1p(expm1(x)) end
code[x_] := N[Log[1 + N[(Exp[x] - 1), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{log1p}\left(\mathsf{expm1}\left(x\right)\right)
\end{array}
Initial program 52.6%
Taylor expanded in x around 0 54.4%
associate-/l*53.9%
associate-/r/54.1%
metadata-eval54.1%
*-un-lft-identity54.1%
log1p-expm1-u99.4%
Applied egg-rr99.4%
Final simplification99.4%
(FPCore (x) :precision binary64 (if (or (<= x -5.0) (not (<= x 4.8))) (/ (* 0.016666666666666666 (pow x 5.0)) 2.0) (+ x (* 0.16666666666666666 (pow x 3.0)))))
double code(double x) {
double tmp;
if ((x <= -5.0) || !(x <= 4.8)) {
tmp = (0.016666666666666666 * pow(x, 5.0)) / 2.0;
} else {
tmp = x + (0.16666666666666666 * pow(x, 3.0));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-5.0d0)) .or. (.not. (x <= 4.8d0))) then
tmp = (0.016666666666666666d0 * (x ** 5.0d0)) / 2.0d0
else
tmp = x + (0.16666666666666666d0 * (x ** 3.0d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -5.0) || !(x <= 4.8)) {
tmp = (0.016666666666666666 * Math.pow(x, 5.0)) / 2.0;
} else {
tmp = x + (0.16666666666666666 * Math.pow(x, 3.0));
}
return tmp;
}
def code(x): tmp = 0 if (x <= -5.0) or not (x <= 4.8): tmp = (0.016666666666666666 * math.pow(x, 5.0)) / 2.0 else: tmp = x + (0.16666666666666666 * math.pow(x, 3.0)) return tmp
function code(x) tmp = 0.0 if ((x <= -5.0) || !(x <= 4.8)) tmp = Float64(Float64(0.016666666666666666 * (x ^ 5.0)) / 2.0); else tmp = Float64(x + Float64(0.16666666666666666 * (x ^ 3.0))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -5.0) || ~((x <= 4.8))) tmp = (0.016666666666666666 * (x ^ 5.0)) / 2.0; else tmp = x + (0.16666666666666666 * (x ^ 3.0)); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -5.0], N[Not[LessEqual[x, 4.8]], $MachinePrecision]], N[(N[(0.016666666666666666 * N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(x + N[(0.16666666666666666 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \lor \neg \left(x \leq 4.8\right):\\
\;\;\;\;\frac{0.016666666666666666 \cdot {x}^{5}}{2}\\
\mathbf{else}:\\
\;\;\;\;x + 0.16666666666666666 \cdot {x}^{3}\\
\end{array}
\end{array}
if x < -5 or 4.79999999999999982 < x Initial program 100.0%
Taylor expanded in x around 0 84.6%
Taylor expanded in x around inf 84.6%
if -5 < x < 4.79999999999999982Initial program 8.9%
Taylor expanded in x around 0 99.6%
Taylor expanded in x around 0 99.6%
Final simplification92.4%
(FPCore (x) :precision binary64 (if (or (<= x -2.5) (not (<= x 2.4))) (* 0.16666666666666666 (pow x 3.0)) x))
double code(double x) {
double tmp;
if ((x <= -2.5) || !(x <= 2.4)) {
tmp = 0.16666666666666666 * pow(x, 3.0);
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-2.5d0)) .or. (.not. (x <= 2.4d0))) then
tmp = 0.16666666666666666d0 * (x ** 3.0d0)
else
tmp = x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -2.5) || !(x <= 2.4)) {
tmp = 0.16666666666666666 * Math.pow(x, 3.0);
} else {
tmp = x;
}
return tmp;
}
def code(x): tmp = 0 if (x <= -2.5) or not (x <= 2.4): tmp = 0.16666666666666666 * math.pow(x, 3.0) else: tmp = x return tmp
function code(x) tmp = 0.0 if ((x <= -2.5) || !(x <= 2.4)) tmp = Float64(0.16666666666666666 * (x ^ 3.0)); else tmp = x; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -2.5) || ~((x <= 2.4))) tmp = 0.16666666666666666 * (x ^ 3.0); else tmp = x; end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -2.5], N[Not[LessEqual[x, 2.4]], $MachinePrecision]], N[(0.16666666666666666 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \lor \neg \left(x \leq 2.4\right):\\
\;\;\;\;0.16666666666666666 \cdot {x}^{3}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -2.5 or 2.39999999999999991 < x Initial program 100.0%
Taylor expanded in x around 0 74.7%
Taylor expanded in x around inf 74.7%
if -2.5 < x < 2.39999999999999991Initial program 8.9%
Taylor expanded in x around 0 98.9%
Taylor expanded in x around 0 98.9%
Final simplification87.3%
(FPCore (x) :precision binary64 (+ x (* 0.16666666666666666 (pow x 3.0))))
double code(double x) {
return x + (0.16666666666666666 * pow(x, 3.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x + (0.16666666666666666d0 * (x ** 3.0d0))
end function
public static double code(double x) {
return x + (0.16666666666666666 * Math.pow(x, 3.0));
}
def code(x): return x + (0.16666666666666666 * math.pow(x, 3.0))
function code(x) return Float64(x + Float64(0.16666666666666666 * (x ^ 3.0))) end
function tmp = code(x) tmp = x + (0.16666666666666666 * (x ^ 3.0)); end
code[x_] := N[(x + N[(0.16666666666666666 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + 0.16666666666666666 \cdot {x}^{3}
\end{array}
Initial program 52.6%
Taylor expanded in x around 0 87.6%
Taylor expanded in x around 0 87.6%
Final simplification87.6%
(FPCore (x) :precision binary64 (/ (* x 2.0) 2.0))
double code(double x) {
return (x * 2.0) / 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * 2.0d0) / 2.0d0
end function
public static double code(double x) {
return (x * 2.0) / 2.0;
}
def code(x): return (x * 2.0) / 2.0
function code(x) return Float64(Float64(x * 2.0) / 2.0) end
function tmp = code(x) tmp = (x * 2.0) / 2.0; end
code[x_] := N[(N[(x * 2.0), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot 2}{2}
\end{array}
Initial program 52.6%
Taylor expanded in x around 0 54.4%
Final simplification54.4%
(FPCore (x) :precision binary64 x)
double code(double x) {
return x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x
end function
public static double code(double x) {
return x;
}
def code(x): return x
function code(x) return x end
function tmp = code(x) tmp = x; end
code[x_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 52.6%
Taylor expanded in x around 0 54.4%
Taylor expanded in x around 0 54.1%
Final simplification54.1%
herbie shell --seed 2023310
(FPCore (x)
:name "Hyperbolic sine"
:precision binary64
(/ (- (exp x) (exp (- x))) 2.0))