
(FPCore (x) :precision binary64 (asinh x))
double code(double x) {
return asinh(x);
}
def code(x): return math.asinh(x)
function code(x) return asinh(x) end
function tmp = code(x) tmp = asinh(x); end
code[x_] := N[ArcSinh[x], $MachinePrecision]
\begin{array}{l}
\\
\sinh^{-1} x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x))
double code(double x) {
return copysign(log((fabs(x) + sqrt(((x * x) + 1.0)))), x);
}
public static double code(double x) {
return Math.copySign(Math.log((Math.abs(x) + Math.sqrt(((x * x) + 1.0)))), x);
}
def code(x): return math.copysign(math.log((math.fabs(x) + math.sqrt(((x * x) + 1.0)))), x)
function code(x) return copysign(log(Float64(abs(x) + sqrt(Float64(Float64(x * x) + 1.0)))), x) end
function tmp = code(x) tmp = sign(x) * abs(log((abs(x) + sqrt(((x * x) + 1.0))))); end
code[x_] := N[With[{TMP1 = Abs[N[Log[N[(N[Abs[x], $MachinePrecision] + N[Sqrt[N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right)
\end{array}
(FPCore (x)
:precision binary64
(if (<= (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x) 4e-6)
(copysign (log1p (fabs x)) x)
(copysign
(/
(+ (pow (log x) 3.0) (pow (log 2.0) 3.0))
(fma (log x) (log x) (* (log 2.0) (- (log 2.0) (log x)))))
x)))
double code(double x) {
double tmp;
if (copysign(log((fabs(x) + sqrt(((x * x) + 1.0)))), x) <= 4e-6) {
tmp = copysign(log1p(fabs(x)), x);
} else {
tmp = copysign(((pow(log(x), 3.0) + pow(log(2.0), 3.0)) / fma(log(x), log(x), (log(2.0) * (log(2.0) - log(x))))), x);
}
return tmp;
}
function code(x) tmp = 0.0 if (copysign(log(Float64(abs(x) + sqrt(Float64(Float64(x * x) + 1.0)))), x) <= 4e-6) tmp = copysign(log1p(abs(x)), x); else tmp = copysign(Float64(Float64((log(x) ^ 3.0) + (log(2.0) ^ 3.0)) / fma(log(x), log(x), Float64(log(2.0) * Float64(log(2.0) - log(x))))), x); end return tmp end
code[x_] := If[LessEqual[N[With[{TMP1 = Abs[N[Log[N[(N[Abs[x], $MachinePrecision] + N[Sqrt[N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], 4e-6], N[With[{TMP1 = Abs[N[Log[1 + N[Abs[x], $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], N[With[{TMP1 = Abs[N[(N[(N[Power[N[Log[x], $MachinePrecision], 3.0], $MachinePrecision] + N[Power[N[Log[2.0], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] / N[(N[Log[x], $MachinePrecision] * N[Log[x], $MachinePrecision] + N[(N[Log[2.0], $MachinePrecision] * N[(N[Log[2.0], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \leq 4 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right|\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\frac{{\log x}^{3} + {\log 2}^{3}}{\mathsf{fma}\left(\log x, \log x, \log 2 \cdot \left(\log 2 - \log x\right)\right)}, x\right)\\
\end{array}
\end{array}
if (copysign.f64 (log.f64 (+.f64 (fabs.f64 x) (sqrt.f64 (+.f64 (*.f64 x x) #s(literal 1 binary64))))) x) < 3.99999999999999982e-6Initial program 23.1%
+-commutative23.1%
hypot-1-def35.8%
Simplified35.8%
Taylor expanded in x around 0 14.4%
log1p-define78.1%
Simplified78.1%
if 3.99999999999999982e-6 < (copysign.f64 (log.f64 (+.f64 (fabs.f64 x) (sqrt.f64 (+.f64 (*.f64 x x) #s(literal 1 binary64))))) x) Initial program 53.1%
+-commutative53.1%
hypot-1-def98.5%
Simplified98.5%
Taylor expanded in x around inf 97.6%
rem-square-sqrt97.6%
fabs-sqr97.6%
rem-square-sqrt97.6%
Simplified97.6%
log-prod98.8%
flip3-+98.2%
*-inverses98.2%
metadata-eval98.2%
fma-define98.2%
*-inverses98.2%
metadata-eval98.2%
*-inverses98.2%
metadata-eval98.2%
*-inverses98.2%
metadata-eval98.2%
Applied egg-rr98.2%
distribute-rgt-out--98.2%
Simplified98.2%
Final simplification83.1%
(FPCore (x)
:precision binary64
(if (<= (copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x) -10.0)
(copysign (log (/ -0.5 x)) x)
(copysign
(fma
(pow x 2.0)
(+
(* (pow x 2.0) (+ (/ -0.125 (+ x 1.0)) (/ -0.125 (pow (+ x 1.0) 2.0))))
(/ 0.5 (+ x 1.0)))
(log1p x))
x)))
double code(double x) {
double tmp;
if (copysign(log((fabs(x) + sqrt(((x * x) + 1.0)))), x) <= -10.0) {
tmp = copysign(log((-0.5 / x)), x);
} else {
tmp = copysign(fma(pow(x, 2.0), ((pow(x, 2.0) * ((-0.125 / (x + 1.0)) + (-0.125 / pow((x + 1.0), 2.0)))) + (0.5 / (x + 1.0))), log1p(x)), x);
}
return tmp;
}
function code(x) tmp = 0.0 if (copysign(log(Float64(abs(x) + sqrt(Float64(Float64(x * x) + 1.0)))), x) <= -10.0) tmp = copysign(log(Float64(-0.5 / x)), x); else tmp = copysign(fma((x ^ 2.0), Float64(Float64((x ^ 2.0) * Float64(Float64(-0.125 / Float64(x + 1.0)) + Float64(-0.125 / (Float64(x + 1.0) ^ 2.0)))) + Float64(0.5 / Float64(x + 1.0))), log1p(x)), x); end return tmp end
code[x_] := If[LessEqual[N[With[{TMP1 = Abs[N[Log[N[(N[Abs[x], $MachinePrecision] + N[Sqrt[N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], -10.0], N[With[{TMP1 = Abs[N[Log[N[(-0.5 / x), $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], N[With[{TMP1 = Abs[N[(N[Power[x, 2.0], $MachinePrecision] * N[(N[(N[Power[x, 2.0], $MachinePrecision] * N[(N[(-0.125 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] + N[(-0.125 / N[Power[N[(x + 1.0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Log[1 + x], $MachinePrecision]), $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(\log \left(\left|x\right| + \sqrt{x \cdot x + 1}\right), x\right) \leq -10:\\
\;\;\;\;\mathsf{copysign}\left(\log \left(\frac{-0.5}{x}\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{copysign}\left(\mathsf{fma}\left({x}^{2}, {x}^{2} \cdot \left(\frac{-0.125}{x + 1} + \frac{-0.125}{{\left(x + 1\right)}^{2}}\right) + \frac{0.5}{x + 1}, \mathsf{log1p}\left(x\right)\right), x\right)\\
\end{array}
\end{array}
if (copysign.f64 (log.f64 (+.f64 (fabs.f64 x) (sqrt.f64 (+.f64 (*.f64 x x) #s(literal 1 binary64))))) x) < -10Initial program 58.3%
+-commutative58.3%
hypot-1-def100.0%
Simplified100.0%
*-un-lft-identity100.0%
*-commutative100.0%
log-prod100.0%
add-sqr-sqrt0.0%
fabs-sqr0.0%
add-sqr-sqrt3.7%
metadata-eval3.7%
Applied egg-rr3.7%
+-rgt-identity3.7%
Simplified3.7%
Taylor expanded in x around -inf 100.0%
if -10 < (copysign.f64 (log.f64 (+.f64 (fabs.f64 x) (sqrt.f64 (+.f64 (*.f64 x x) #s(literal 1 binary64))))) x) Initial program 22.5%
+-commutative22.5%
hypot-1-def37.2%
Simplified37.2%
Taylor expanded in x around 0 7.3%
+-commutative7.3%
fma-define7.3%
Simplified68.9%
Final simplification76.0%
(FPCore (x) :precision binary64 (copysign (log1p (fabs x)) x))
double code(double x) {
return copysign(log1p(fabs(x)), x);
}
public static double code(double x) {
return Math.copySign(Math.log1p(Math.abs(x)), x);
}
def code(x): return math.copysign(math.log1p(math.fabs(x)), x)
function code(x) return copysign(log1p(abs(x)), x) end
code[x_] := N[With[{TMP1 = Abs[N[Log[1 + N[Abs[x], $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right|\right), x\right)
\end{array}
Initial program 30.6%
+-commutative30.6%
hypot-1-def51.4%
Simplified51.4%
Taylor expanded in x around 0 18.6%
log1p-define66.4%
Simplified66.4%
Final simplification66.4%
(FPCore (x) :precision binary64 (copysign (log1p x) x))
double code(double x) {
return copysign(log1p(x), x);
}
public static double code(double x) {
return Math.copySign(Math.log1p(x), x);
}
def code(x): return math.copysign(math.log1p(x), x)
function code(x) return copysign(log1p(x), x) end
code[x_] := N[With[{TMP1 = Abs[N[Log[1 + x], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{copysign}\left(\mathsf{log1p}\left(x\right), x\right)
\end{array}
Initial program 30.6%
+-commutative30.6%
hypot-1-def51.4%
Simplified51.4%
Taylor expanded in x around 0 18.6%
log1p-define66.4%
rem-square-sqrt33.9%
fabs-sqr33.9%
rem-square-sqrt59.2%
Simplified59.2%
Final simplification59.2%
(FPCore (x) :precision binary64 (copysign x x))
double code(double x) {
return copysign(x, x);
}
public static double code(double x) {
return Math.copySign(x, x);
}
def code(x): return math.copysign(x, x)
function code(x) return copysign(x, x) end
function tmp = code(x) tmp = sign(x) * abs(x); end
code[x_] := N[With[{TMP1 = Abs[x], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{copysign}\left(x, x\right)
\end{array}
Initial program 30.6%
+-commutative30.6%
hypot-1-def51.4%
Simplified51.4%
*-un-lft-identity51.4%
*-commutative51.4%
log-prod51.4%
add-sqr-sqrt26.5%
fabs-sqr26.5%
add-sqr-sqrt29.6%
metadata-eval29.6%
Applied egg-rr29.6%
+-rgt-identity29.6%
Simplified29.6%
Taylor expanded in x around 0 54.4%
Final simplification54.4%
(FPCore (x) :precision binary64 (let* ((t_0 (/ 1.0 (fabs x)))) (copysign (log1p (+ (fabs x) (/ (fabs x) (+ (hypot 1.0 t_0) t_0)))) x)))
double code(double x) {
double t_0 = 1.0 / fabs(x);
return copysign(log1p((fabs(x) + (fabs(x) / (hypot(1.0, t_0) + t_0)))), x);
}
public static double code(double x) {
double t_0 = 1.0 / Math.abs(x);
return Math.copySign(Math.log1p((Math.abs(x) + (Math.abs(x) / (Math.hypot(1.0, t_0) + t_0)))), x);
}
def code(x): t_0 = 1.0 / math.fabs(x) return math.copysign(math.log1p((math.fabs(x) + (math.fabs(x) / (math.hypot(1.0, t_0) + t_0)))), x)
function code(x) t_0 = Float64(1.0 / abs(x)) return copysign(log1p(Float64(abs(x) + Float64(abs(x) / Float64(hypot(1.0, t_0) + t_0)))), x) end
code[x_] := Block[{t$95$0 = N[(1.0 / N[Abs[x], $MachinePrecision]), $MachinePrecision]}, N[With[{TMP1 = Abs[N[Log[1 + N[(N[Abs[x], $MachinePrecision] + N[(N[Abs[x], $MachinePrecision] / N[(N[Sqrt[1.0 ^ 2 + t$95$0 ^ 2], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\left|x\right|}\\
\mathsf{copysign}\left(\mathsf{log1p}\left(\left|x\right| + \frac{\left|x\right|}{\mathsf{hypot}\left(1, t\_0\right) + t\_0}\right), x\right)
\end{array}
\end{array}
herbie shell --seed 2024066
(FPCore (x)
:name "Rust f64::asinh"
:precision binary64
:alt
(copysign (log1p (+ (fabs x) (/ (fabs x) (+ (hypot 1.0 (/ 1.0 (fabs x))) (/ 1.0 (fabs x)))))) x)
(copysign (log (+ (fabs x) (sqrt (+ (* x x) 1.0)))) x))