
(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 6 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 (log (* x (- 2.0 (/ 0.5 (pow x 2.0))))))
double code(double x) {
return log((x * (2.0 - (0.5 / pow(x, 2.0)))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = log((x * (2.0d0 - (0.5d0 / (x ** 2.0d0)))))
end function
public static double code(double x) {
return Math.log((x * (2.0 - (0.5 / Math.pow(x, 2.0)))));
}
def code(x): return math.log((x * (2.0 - (0.5 / math.pow(x, 2.0)))))
function code(x) return log(Float64(x * Float64(2.0 - Float64(0.5 / (x ^ 2.0))))) end
function tmp = code(x) tmp = log((x * (2.0 - (0.5 / (x ^ 2.0))))); end
code[x_] := N[Log[N[(x * N[(2.0 - N[(0.5 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(x \cdot \left(2 - \frac{0.5}{{x}^{2}}\right)\right)
\end{array}
Initial program 47.4%
Taylor expanded in x around inf 99.2%
associate-*r/99.2%
metadata-eval99.2%
Simplified99.2%
(FPCore (x) :precision binary64 (let* ((t_0 (+ x (sqrt (+ (* x x) -1.0))))) (if (<= t_0 5e+153) (log t_0) (+ (/ 1.0 x) (log x)))))
double code(double x) {
double t_0 = x + sqrt(((x * x) + -1.0));
double tmp;
if (t_0 <= 5e+153) {
tmp = log(t_0);
} else {
tmp = (1.0 / x) + log(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = x + sqrt(((x * x) + (-1.0d0)))
if (t_0 <= 5d+153) then
tmp = log(t_0)
else
tmp = (1.0d0 / x) + log(x)
end if
code = tmp
end function
public static double code(double x) {
double t_0 = x + Math.sqrt(((x * x) + -1.0));
double tmp;
if (t_0 <= 5e+153) {
tmp = Math.log(t_0);
} else {
tmp = (1.0 / x) + Math.log(x);
}
return tmp;
}
def code(x): t_0 = x + math.sqrt(((x * x) + -1.0)) tmp = 0 if t_0 <= 5e+153: tmp = math.log(t_0) else: tmp = (1.0 / x) + math.log(x) return tmp
function code(x) t_0 = Float64(x + sqrt(Float64(Float64(x * x) + -1.0))) tmp = 0.0 if (t_0 <= 5e+153) tmp = log(t_0); else tmp = Float64(Float64(1.0 / x) + log(x)); end return tmp end
function tmp_2 = code(x) t_0 = x + sqrt(((x * x) + -1.0)); tmp = 0.0; if (t_0 <= 5e+153) tmp = log(t_0); else tmp = (1.0 / x) + log(x); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(x + N[Sqrt[N[(N[(x * x), $MachinePrecision] + -1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 5e+153], N[Log[t$95$0], $MachinePrecision], N[(N[(1.0 / x), $MachinePrecision] + N[Log[x], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + \sqrt{x \cdot x + -1}\\
\mathbf{if}\;t\_0 \leq 5 \cdot 10^{+153}:\\
\;\;\;\;\log t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x} + \log x\\
\end{array}
\end{array}
if (+.f64 x (sqrt.f64 (-.f64 (*.f64 x x) #s(literal 1 binary64)))) < 5.00000000000000018e153Initial program 100.0%
if 5.00000000000000018e153 < (+.f64 x (sqrt.f64 (-.f64 (*.f64 x x) #s(literal 1 binary64)))) Initial program 3.1%
Taylor expanded in x around 0 0.0%
Applied egg-rr33.0%
Taylor expanded in x around inf 33.0%
+-commutative33.0%
mul-1-neg33.0%
log-rec33.0%
remove-double-neg33.0%
Simplified33.0%
Final simplification63.6%
(FPCore (x) :precision binary64 (+ (/ 1.0 x) (log x)))
double code(double x) {
return (1.0 / x) + log(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / x) + log(x)
end function
public static double code(double x) {
return (1.0 / x) + Math.log(x);
}
def code(x): return (1.0 / x) + math.log(x)
function code(x) return Float64(Float64(1.0 / x) + log(x)) end
function tmp = code(x) tmp = (1.0 / x) + log(x); end
code[x_] := N[(N[(1.0 / x), $MachinePrecision] + N[Log[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x} + \log x
\end{array}
Initial program 47.4%
Taylor expanded in x around 0 0.0%
Applied egg-rr31.5%
Taylor expanded in x around inf 31.5%
+-commutative31.5%
mul-1-neg31.5%
log-rec31.5%
remove-double-neg31.5%
Simplified31.5%
(FPCore (x) :precision binary64 (log1p x))
double code(double x) {
return log1p(x);
}
public static double code(double x) {
return Math.log1p(x);
}
def code(x): return math.log1p(x)
function code(x) return log1p(x) end
code[x_] := N[Log[1 + x], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{log1p}\left(x\right)
\end{array}
Initial program 47.4%
Taylor expanded in x around 0 0.0%
Applied egg-rr31.5%
+-lft-identity31.5%
Simplified31.5%
(FPCore (x) :precision binary64 (* x (+ 1.0 (* x (- (* x 0.3333333333333333) 0.5)))))
double code(double x) {
return x * (1.0 + (x * ((x * 0.3333333333333333) - 0.5)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (1.0d0 + (x * ((x * 0.3333333333333333d0) - 0.5d0)))
end function
public static double code(double x) {
return x * (1.0 + (x * ((x * 0.3333333333333333) - 0.5)));
}
def code(x): return x * (1.0 + (x * ((x * 0.3333333333333333) - 0.5)))
function code(x) return Float64(x * Float64(1.0 + Float64(x * Float64(Float64(x * 0.3333333333333333) - 0.5)))) end
function tmp = code(x) tmp = x * (1.0 + (x * ((x * 0.3333333333333333) - 0.5))); end
code[x_] := N[(x * N[(1.0 + N[(x * N[(N[(x * 0.3333333333333333), $MachinePrecision] - 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 + x \cdot \left(x \cdot 0.3333333333333333 - 0.5\right)\right)
\end{array}
Initial program 47.4%
Taylor expanded in x around 0 0.0%
Applied egg-rr31.5%
Taylor expanded in x around 0 4.0%
Final simplification4.0%
(FPCore (x) :precision binary64 (* x (+ 1.0 (* x -0.5))))
double code(double x) {
return x * (1.0 + (x * -0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (1.0d0 + (x * (-0.5d0)))
end function
public static double code(double x) {
return x * (1.0 + (x * -0.5));
}
def code(x): return x * (1.0 + (x * -0.5))
function code(x) return Float64(x * Float64(1.0 + Float64(x * -0.5))) end
function tmp = code(x) tmp = x * (1.0 + (x * -0.5)); end
code[x_] := N[(x * N[(1.0 + N[(x * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 + x \cdot -0.5\right)
\end{array}
Initial program 47.4%
Taylor expanded in x around 0 0.0%
Applied egg-rr31.5%
Taylor expanded in x around 0 0.9%
*-commutative0.9%
Simplified0.9%
herbie shell --seed 2024179
(FPCore (x)
:name "Hyperbolic arc-cosine"
:precision binary64
(log (+ x (sqrt (- (* x x) 1.0)))))