
(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 4 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 8e-7) (- (log (- (hypot 1.0 x) x))) (log (+ x (hypot 1.0 x)))))
double code(double x) {
double tmp;
if (x <= 8e-7) {
tmp = -log((hypot(1.0, x) - x));
} else {
tmp = log((x + hypot(1.0, x)));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 8e-7) {
tmp = -Math.log((Math.hypot(1.0, x) - x));
} else {
tmp = Math.log((x + Math.hypot(1.0, x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 8e-7: tmp = -math.log((math.hypot(1.0, x) - x)) else: tmp = math.log((x + math.hypot(1.0, x))) return tmp
function code(x) tmp = 0.0 if (x <= 8e-7) tmp = Float64(-log(Float64(hypot(1.0, x) - x))); else tmp = log(Float64(x + hypot(1.0, x))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 8e-7) tmp = -log((hypot(1.0, x) - x)); else tmp = log((x + hypot(1.0, x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 8e-7], (-N[Log[N[(N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision]), N[Log[N[(x + N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 8 \cdot 10^{-7}:\\
\;\;\;\;-\log \left(\mathsf{hypot}\left(1, x\right) - x\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(x + \mathsf{hypot}\left(1, x\right)\right)\\
\end{array}
\end{array}
if x < 7.9999999999999996e-7Initial program 87.9%
sqr-neg87.9%
+-commutative87.9%
sqr-neg87.9%
hypot-1-def88.0%
Simplified88.0%
flip-+88.1%
frac-2neg88.1%
log-div88.1%
pow288.1%
hypot-1-def88.1%
hypot-1-def88.1%
add-sqr-sqrt88.1%
+-commutative88.1%
fma-define88.1%
Applied egg-rr88.1%
neg-sub088.1%
associate--r-88.1%
neg-sub088.1%
+-commutative88.1%
sub-neg88.1%
fma-undefine88.1%
unpow288.1%
+-commutative88.1%
associate--l+92.6%
+-inverses97.7%
metadata-eval97.7%
metadata-eval97.7%
neg-sub097.7%
associate--r-97.7%
neg-sub097.7%
+-commutative97.7%
sub-neg97.7%
neg-sub097.7%
Simplified97.7%
if 7.9999999999999996e-7 < x Initial program 49.2%
sqr-neg49.2%
+-commutative49.2%
sqr-neg49.2%
hypot-1-def99.4%
Simplified99.4%
Final simplification98.2%
(FPCore (x) :precision binary64 (log (+ x (hypot 1.0 x))))
double code(double x) {
return log((x + hypot(1.0, x)));
}
public static double code(double x) {
return Math.log((x + Math.hypot(1.0, x)));
}
def code(x): return math.log((x + math.hypot(1.0, x)))
function code(x) return log(Float64(x + hypot(1.0, x))) end
function tmp = code(x) tmp = log((x + hypot(1.0, x))); end
code[x_] := N[Log[N[(x + N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(x + \mathsf{hypot}\left(1, x\right)\right)
\end{array}
Initial program 75.6%
sqr-neg75.6%
+-commutative75.6%
sqr-neg75.6%
hypot-1-def91.6%
Simplified91.6%
Final simplification91.6%
(FPCore (x) :precision binary64 (if (<= x 1.25) x (log (* x 2.0))))
double code(double x) {
double tmp;
if (x <= 1.25) {
tmp = x;
} else {
tmp = log((x * 2.0));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.25d0) then
tmp = x
else
tmp = log((x * 2.0d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.25) {
tmp = x;
} else {
tmp = Math.log((x * 2.0));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.25: tmp = x else: tmp = math.log((x * 2.0)) return tmp
function code(x) tmp = 0.0 if (x <= 1.25) tmp = x; else tmp = log(Float64(x * 2.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.25) tmp = x; else tmp = log((x * 2.0)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.25], x, N[Log[N[(x * 2.0), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.25:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\log \left(x \cdot 2\right)\\
\end{array}
\end{array}
if x < 1.25Initial program 87.7%
sqr-neg87.7%
+-commutative87.7%
sqr-neg87.7%
hypot-1-def87.9%
Simplified87.9%
Taylor expanded in x around 0 8.7%
if 1.25 < x Initial program 48.5%
sqr-neg48.5%
+-commutative48.5%
sqr-neg48.5%
hypot-1-def100.0%
Simplified100.0%
Taylor expanded in x around inf 98.8%
mul-1-neg98.8%
log-rec98.8%
remove-double-neg98.8%
Simplified98.8%
Taylor expanded in x around inf 98.8%
mul-1-neg98.8%
log-rec98.8%
remove-double-neg98.8%
log-prod99.1%
*-commutative99.1%
Simplified99.1%
Final simplification36.6%
(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 75.6%
sqr-neg75.6%
+-commutative75.6%
sqr-neg75.6%
hypot-1-def91.6%
Simplified91.6%
Taylor expanded in x around 0 7.6%
Final simplification7.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 2024046
(FPCore (x)
:name "Hyperbolic arcsine"
:precision binary64
:herbie-target
(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)))))