
(FPCore (x) :precision binary64 (log (+ x (sqrt (+ (* x x) 1.0)))))
double code(double x) {
return log((x + sqrt(((x * x) + 1.0))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = log((x + sqrt(((x * x) + 1.0d0))))
end function
public static double code(double x) {
return Math.log((x + Math.sqrt(((x * x) + 1.0))));
}
def code(x): return math.log((x + math.sqrt(((x * x) + 1.0))))
function code(x) return log(Float64(x + sqrt(Float64(Float64(x * x) + 1.0)))) end
function tmp = code(x) tmp = log((x + sqrt(((x * x) + 1.0)))); end
code[x_] := N[Log[N[(x + N[Sqrt[N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(x + \sqrt{x \cdot x + 1}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (log (+ x (sqrt (+ (* x x) 1.0)))))
double code(double x) {
return log((x + sqrt(((x * x) + 1.0))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = log((x + sqrt(((x * x) + 1.0d0))))
end function
public static double code(double x) {
return Math.log((x + Math.sqrt(((x * x) + 1.0))));
}
def code(x): return math.log((x + math.sqrt(((x * x) + 1.0))))
function code(x) return log(Float64(x + sqrt(Float64(Float64(x * x) + 1.0)))) end
function tmp = code(x) tmp = log((x + sqrt(((x * x) + 1.0)))); end
code[x_] := N[Log[N[(x + N[Sqrt[N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(x + \sqrt{x \cdot x + 1}\right)
\end{array}
(FPCore (x) :precision binary64 (if (<= x 8.8e-6) x (- (log (/ 1.0 (+ x (hypot 1.0 x)))))))
double code(double x) {
double tmp;
if (x <= 8.8e-6) {
tmp = x;
} else {
tmp = -log((1.0 / (x + hypot(1.0, x))));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 8.8e-6) {
tmp = x;
} else {
tmp = -Math.log((1.0 / (x + Math.hypot(1.0, x))));
}
return tmp;
}
def code(x): tmp = 0 if x <= 8.8e-6: tmp = x else: tmp = -math.log((1.0 / (x + math.hypot(1.0, x)))) return tmp
function code(x) tmp = 0.0 if (x <= 8.8e-6) tmp = x; else tmp = Float64(-log(Float64(1.0 / Float64(x + hypot(1.0, x))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 8.8e-6) tmp = x; else tmp = -log((1.0 / (x + hypot(1.0, x)))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 8.8e-6], x, (-N[Log[N[(1.0 / N[(x + N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 8.8 \cdot 10^{-6}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;-\log \left(\frac{1}{x + \mathsf{hypot}\left(1, x\right)}\right)\\
\end{array}
\end{array}
if x < 8.8000000000000004e-6Initial program 7.0%
sqr-neg7.0%
+-commutative7.0%
sqr-neg7.0%
hypot-1-def7.5%
Simplified7.5%
Taylor expanded in x around 0 64.9%
if 8.8000000000000004e-6 < x Initial program 46.0%
sqr-neg46.0%
+-commutative46.0%
sqr-neg46.0%
hypot-1-def100.0%
Simplified100.0%
flip-+2.5%
clear-num2.5%
log-div2.5%
metadata-eval2.5%
pow22.5%
hypot-1-def2.5%
hypot-1-def2.5%
add-sqr-sqrt2.5%
+-commutative2.5%
fma-define2.5%
Applied egg-rr2.5%
neg-sub02.5%
div-sub2.5%
fma-undefine2.5%
unpow22.5%
associate--r+2.5%
+-inverses2.5%
metadata-eval2.5%
*-rgt-identity2.5%
associate-/l*2.5%
metadata-eval2.5%
fma-undefine2.5%
unpow22.5%
associate--r+3.8%
+-inverses5.5%
metadata-eval5.5%
*-rgt-identity5.5%
associate-/l*5.5%
metadata-eval5.5%
*-commutative5.5%
neg-mul-15.5%
Simplified5.5%
flip--3.8%
+-commutative3.8%
expm1-log1p-u3.8%
div-inv3.8%
hypot-1-def4.1%
hypot-1-def3.8%
add-sqr-sqrt4.1%
+-commutative4.1%
fma-define4.1%
pow24.1%
expm1-log1p-u4.2%
Applied egg-rr4.2%
associate-*r/4.2%
*-rgt-identity4.2%
remove-double-neg4.2%
distribute-neg-frac24.2%
distribute-frac-neg4.2%
neg-mul-14.2%
associate-/r*4.2%
Simplified100.0%
Final simplification74.5%
(FPCore (x) :precision binary64 (if (<= x 8.8e-6) x (log (expm1 (log1p (+ x (hypot 1.0 x)))))))
double code(double x) {
double tmp;
if (x <= 8.8e-6) {
tmp = x;
} else {
tmp = log(expm1(log1p((x + hypot(1.0, x)))));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 8.8e-6) {
tmp = x;
} else {
tmp = Math.log(Math.expm1(Math.log1p((x + Math.hypot(1.0, x)))));
}
return tmp;
}
def code(x): tmp = 0 if x <= 8.8e-6: tmp = x else: tmp = math.log(math.expm1(math.log1p((x + math.hypot(1.0, x))))) return tmp
function code(x) tmp = 0.0 if (x <= 8.8e-6) tmp = x; else tmp = log(expm1(log1p(Float64(x + hypot(1.0, x))))); end return tmp end
code[x_] := If[LessEqual[x, 8.8e-6], x, N[Log[N[(Exp[N[Log[1 + N[(x + N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 8.8 \cdot 10^{-6}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\log \left(\mathsf{expm1}\left(\mathsf{log1p}\left(x + \mathsf{hypot}\left(1, x\right)\right)\right)\right)\\
\end{array}
\end{array}
if x < 8.8000000000000004e-6Initial program 7.0%
sqr-neg7.0%
+-commutative7.0%
sqr-neg7.0%
hypot-1-def7.5%
Simplified7.5%
Taylor expanded in x around 0 64.9%
if 8.8000000000000004e-6 < x Initial program 46.0%
sqr-neg46.0%
+-commutative46.0%
sqr-neg46.0%
hypot-1-def100.0%
Simplified100.0%
expm1-log1p-u100.0%
Applied egg-rr100.0%
Final simplification74.5%
(FPCore (x) :precision binary64 (if (<= x 8.8e-6) x (+ (+ 1.0 (log (+ x (hypot 1.0 x)))) -1.0)))
double code(double x) {
double tmp;
if (x <= 8.8e-6) {
tmp = x;
} else {
tmp = (1.0 + log((x + hypot(1.0, x)))) + -1.0;
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 8.8e-6) {
tmp = x;
} else {
tmp = (1.0 + Math.log((x + Math.hypot(1.0, x)))) + -1.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= 8.8e-6: tmp = x else: tmp = (1.0 + math.log((x + math.hypot(1.0, x)))) + -1.0 return tmp
function code(x) tmp = 0.0 if (x <= 8.8e-6) tmp = x; else tmp = Float64(Float64(1.0 + log(Float64(x + hypot(1.0, x)))) + -1.0); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 8.8e-6) tmp = x; else tmp = (1.0 + log((x + hypot(1.0, x)))) + -1.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 8.8e-6], x, N[(N[(1.0 + N[Log[N[(x + N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 8.8 \cdot 10^{-6}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \log \left(x + \mathsf{hypot}\left(1, x\right)\right)\right) + -1\\
\end{array}
\end{array}
if x < 8.8000000000000004e-6Initial program 7.0%
sqr-neg7.0%
+-commutative7.0%
sqr-neg7.0%
hypot-1-def7.5%
Simplified7.5%
Taylor expanded in x around 0 64.9%
if 8.8000000000000004e-6 < x Initial program 46.0%
sqr-neg46.0%
+-commutative46.0%
sqr-neg46.0%
hypot-1-def100.0%
Simplified100.0%
expm1-log1p-u98.3%
expm1-undefine98.2%
log1p-undefine98.2%
rem-exp-log100.0%
Applied egg-rr100.0%
Final simplification74.5%
(FPCore (x) :precision binary64 (if (<= x 8.8e-6) x (log (+ x (sqrt (+ 1.0 (* x x)))))))
double code(double x) {
double tmp;
if (x <= 8.8e-6) {
tmp = x;
} else {
tmp = log((x + sqrt((1.0 + (x * x)))));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 8.8d-6) then
tmp = x
else
tmp = log((x + sqrt((1.0d0 + (x * x)))))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 8.8e-6) {
tmp = x;
} else {
tmp = Math.log((x + Math.sqrt((1.0 + (x * x)))));
}
return tmp;
}
def code(x): tmp = 0 if x <= 8.8e-6: tmp = x else: tmp = math.log((x + math.sqrt((1.0 + (x * x))))) return tmp
function code(x) tmp = 0.0 if (x <= 8.8e-6) tmp = x; else tmp = log(Float64(x + sqrt(Float64(1.0 + Float64(x * x))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 8.8e-6) tmp = x; else tmp = log((x + sqrt((1.0 + (x * x))))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 8.8e-6], x, N[Log[N[(x + N[Sqrt[N[(1.0 + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 8.8 \cdot 10^{-6}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\log \left(x + \sqrt{1 + x \cdot x}\right)\\
\end{array}
\end{array}
if x < 8.8000000000000004e-6Initial program 7.0%
sqr-neg7.0%
+-commutative7.0%
sqr-neg7.0%
hypot-1-def7.5%
Simplified7.5%
Taylor expanded in x around 0 64.9%
if 8.8000000000000004e-6 < x Initial program 46.0%
Final simplification59.7%
(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 17.7%
sqr-neg17.7%
+-commutative17.7%
sqr-neg17.7%
hypot-1-def32.8%
Simplified32.8%
Taylor expanded in x around 0 48.6%
Final simplification48.6%
(FPCore (x) :precision binary64 (let* ((t_0 (sqrt (+ (* x x) 1.0)))) (if (< x 0.0) (log (/ -1.0 (- x t_0))) (log (+ x t_0)))))
double code(double x) {
double t_0 = sqrt(((x * x) + 1.0));
double tmp;
if (x < 0.0) {
tmp = log((-1.0 / (x - t_0)));
} else {
tmp = log((x + t_0));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((x * x) + 1.0d0))
if (x < 0.0d0) then
tmp = log(((-1.0d0) / (x - t_0)))
else
tmp = log((x + t_0))
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt(((x * x) + 1.0));
double tmp;
if (x < 0.0) {
tmp = Math.log((-1.0 / (x - t_0)));
} else {
tmp = Math.log((x + t_0));
}
return tmp;
}
def code(x): t_0 = math.sqrt(((x * x) + 1.0)) tmp = 0 if x < 0.0: tmp = math.log((-1.0 / (x - t_0))) else: tmp = math.log((x + t_0)) return tmp
function code(x) t_0 = sqrt(Float64(Float64(x * x) + 1.0)) tmp = 0.0 if (x < 0.0) tmp = log(Float64(-1.0 / Float64(x - t_0))); else tmp = log(Float64(x + t_0)); end return tmp end
function tmp_2 = code(x) t_0 = sqrt(((x * x) + 1.0)); tmp = 0.0; if (x < 0.0) tmp = log((-1.0 / (x - t_0))); else tmp = log((x + t_0)); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]], $MachinePrecision]}, If[Less[x, 0.0], N[Log[N[(-1.0 / N[(x - t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Log[N[(x + t$95$0), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{x \cdot x + 1}\\
\mathbf{if}\;x < 0:\\
\;\;\;\;\log \left(\frac{-1}{x - t\_0}\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(x + t\_0\right)\\
\end{array}
\end{array}
herbie shell --seed 2024066
(FPCore (x)
:name "Hyperbolic arcsine"
:precision binary64
:alt
(if (< x 0.0) (log (/ -1.0 (- x (sqrt (+ (* x x) 1.0))))) (log (+ x (sqrt (+ (* x x) 1.0)))))
(log (+ x (sqrt (+ (* x x) 1.0)))))