
(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 7 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}
(FPCore (x) :precision binary64 (* (* x (+ x 2.0)) (+ 0.5 (+ (* x -0.25) (* 0.125 (pow x 2.0))))))
double code(double x) {
return (x * (x + 2.0)) * (0.5 + ((x * -0.25) + (0.125 * pow(x, 2.0))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * (x + 2.0d0)) * (0.5d0 + ((x * (-0.25d0)) + (0.125d0 * (x ** 2.0d0))))
end function
public static double code(double x) {
return (x * (x + 2.0)) * (0.5 + ((x * -0.25) + (0.125 * Math.pow(x, 2.0))));
}
def code(x): return (x * (x + 2.0)) * (0.5 + ((x * -0.25) + (0.125 * math.pow(x, 2.0))))
function code(x) return Float64(Float64(x * Float64(x + 2.0)) * Float64(0.5 + Float64(Float64(x * -0.25) + Float64(0.125 * (x ^ 2.0))))) end
function tmp = code(x) tmp = (x * (x + 2.0)) * (0.5 + ((x * -0.25) + (0.125 * (x ^ 2.0)))); end
code[x_] := N[(N[(x * N[(x + 2.0), $MachinePrecision]), $MachinePrecision] * N[(0.5 + N[(N[(x * -0.25), $MachinePrecision] + N[(0.125 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot \left(x + 2\right)\right) \cdot \left(0.5 + \left(x \cdot -0.25 + 0.125 \cdot {x}^{2}\right)\right)
\end{array}
(FPCore (x) :precision binary64 (/ (+ (* 0.3333333333333333 (pow x 3.0)) (* x 2.0)) 2.0))
double code(double x) {
return ((0.3333333333333333 * pow(x, 3.0)) + (x * 2.0)) / 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((0.3333333333333333d0 * (x ** 3.0d0)) + (x * 2.0d0)) / 2.0d0
end function
public static double code(double x) {
return ((0.3333333333333333 * Math.pow(x, 3.0)) + (x * 2.0)) / 2.0;
}
def code(x): return ((0.3333333333333333 * math.pow(x, 3.0)) + (x * 2.0)) / 2.0
function code(x) return Float64(Float64(Float64(0.3333333333333333 * (x ^ 3.0)) + Float64(x * 2.0)) / 2.0) end
function tmp = code(x) tmp = ((0.3333333333333333 * (x ^ 3.0)) + (x * 2.0)) / 2.0; end
code[x_] := N[(N[(N[(0.3333333333333333 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.3333333333333333 \cdot {x}^{3} + x \cdot 2}{2}
\end{array}
(FPCore (x) :precision binary64 (let* ((t_0 (* x (+ x 2.0)))) (if (<= x 2e+47) (/ t_0 (- (+ x 1.0) -1.0)) (/ (/ (* x t_0) x) (+ x 2.0)))))
double code(double x) {
double t_0 = x * (x + 2.0);
double tmp;
if (x <= 2e+47) {
tmp = t_0 / ((x + 1.0) - -1.0);
} else {
tmp = ((x * t_0) / x) / (x + 2.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = x * (x + 2.0d0)
if (x <= 2d+47) then
tmp = t_0 / ((x + 1.0d0) - (-1.0d0))
else
tmp = ((x * t_0) / x) / (x + 2.0d0)
end if
code = tmp
end function
public static double code(double x) {
double t_0 = x * (x + 2.0);
double tmp;
if (x <= 2e+47) {
tmp = t_0 / ((x + 1.0) - -1.0);
} else {
tmp = ((x * t_0) / x) / (x + 2.0);
}
return tmp;
}
def code(x): t_0 = x * (x + 2.0) tmp = 0 if x <= 2e+47: tmp = t_0 / ((x + 1.0) - -1.0) else: tmp = ((x * t_0) / x) / (x + 2.0) return tmp
function code(x) t_0 = Float64(x * Float64(x + 2.0)) tmp = 0.0 if (x <= 2e+47) tmp = Float64(t_0 / Float64(Float64(x + 1.0) - -1.0)); else tmp = Float64(Float64(Float64(x * t_0) / x) / Float64(x + 2.0)); end return tmp end
function tmp_2 = code(x) t_0 = x * (x + 2.0); tmp = 0.0; if (x <= 2e+47) tmp = t_0 / ((x + 1.0) - -1.0); else tmp = ((x * t_0) / x) / (x + 2.0); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(x * N[(x + 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 2e+47], N[(t$95$0 / N[(N[(x + 1.0), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * t$95$0), $MachinePrecision] / x), $MachinePrecision] / N[(x + 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(x + 2\right)\\
\mathbf{if}\;x \leq 2 \cdot 10^{+47}:\\
\;\;\;\;\frac{t_0}{\left(x + 1\right) - -1}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{x \cdot t_0}{x}}{x + 2}\\
\end{array}
\end{array}
(FPCore (x) :precision binary64 (/ (* x (+ x 2.0)) 2.0))
double code(double x) {
return (x * (x + 2.0)) / 2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * (x + 2.0d0)) / 2.0d0
end function
public static double code(double x) {
return (x * (x + 2.0)) / 2.0;
}
def code(x): return (x * (x + 2.0)) / 2.0
function code(x) return Float64(Float64(x * Float64(x + 2.0)) / 2.0) end
function tmp = code(x) tmp = (x * (x + 2.0)) / 2.0; end
code[x_] := N[(N[(x * N[(x + 2.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(x + 2\right)}{2}
\end{array}
(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}
(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}
herbie shell --seed 2023350
(FPCore (x)
:name "Hyperbolic sine"
:precision binary64
(/ (- (exp x) (exp (- x))) 2.0))