
(FPCore (x) :precision binary64 (log (/ (sinh x) x)))
double code(double x) {
return log((sinh(x) / x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = log((sinh(x) / x))
end function
public static double code(double x) {
return Math.log((Math.sinh(x) / x));
}
def code(x): return math.log((math.sinh(x) / x))
function code(x) return log(Float64(sinh(x) / x)) end
function tmp = code(x) tmp = log((sinh(x) / x)); end
code[x_] := N[Log[N[(N[Sinh[x], $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(\frac{\sinh x}{x}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (log (/ (sinh x) x)))
double code(double x) {
return log((sinh(x) / x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = log((sinh(x) / x))
end function
public static double code(double x) {
return Math.log((Math.sinh(x) / x));
}
def code(x): return math.log((math.sinh(x) / x))
function code(x) return log(Float64(sinh(x) / x)) end
function tmp = code(x) tmp = log((sinh(x) / x)); end
code[x_] := N[Log[N[(N[Sinh[x], $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(\frac{\sinh x}{x}\right)
\end{array}
x_m = (fabs.f64 x)
(FPCore (x_m)
:precision binary64
(if (<= x_m 0.094)
(*
(pow x_m 2.0)
(+
0.16666666666666666
(*
(* x_m x_m)
(-
(*
(* x_m x_m)
(+ 0.0003527336860670194 (* (* x_m x_m) -2.6455026455026456e-5)))
0.005555555555555556))))
(+ (+ 1.0 (log (/ (sinh x_m) x_m))) -1.0)))x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 0.094) {
tmp = pow(x_m, 2.0) * (0.16666666666666666 + ((x_m * x_m) * (((x_m * x_m) * (0.0003527336860670194 + ((x_m * x_m) * -2.6455026455026456e-5))) - 0.005555555555555556)));
} else {
tmp = (1.0 + log((sinh(x_m) / x_m))) + -1.0;
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 0.094d0) then
tmp = (x_m ** 2.0d0) * (0.16666666666666666d0 + ((x_m * x_m) * (((x_m * x_m) * (0.0003527336860670194d0 + ((x_m * x_m) * (-2.6455026455026456d-5)))) - 0.005555555555555556d0)))
else
tmp = (1.0d0 + log((sinh(x_m) / x_m))) + (-1.0d0)
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 0.094) {
tmp = Math.pow(x_m, 2.0) * (0.16666666666666666 + ((x_m * x_m) * (((x_m * x_m) * (0.0003527336860670194 + ((x_m * x_m) * -2.6455026455026456e-5))) - 0.005555555555555556)));
} else {
tmp = (1.0 + Math.log((Math.sinh(x_m) / x_m))) + -1.0;
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 0.094: tmp = math.pow(x_m, 2.0) * (0.16666666666666666 + ((x_m * x_m) * (((x_m * x_m) * (0.0003527336860670194 + ((x_m * x_m) * -2.6455026455026456e-5))) - 0.005555555555555556))) else: tmp = (1.0 + math.log((math.sinh(x_m) / x_m))) + -1.0 return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 0.094) tmp = Float64((x_m ^ 2.0) * Float64(0.16666666666666666 + Float64(Float64(x_m * x_m) * Float64(Float64(Float64(x_m * x_m) * Float64(0.0003527336860670194 + Float64(Float64(x_m * x_m) * -2.6455026455026456e-5))) - 0.005555555555555556)))); else tmp = Float64(Float64(1.0 + log(Float64(sinh(x_m) / x_m))) + -1.0); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 0.094) tmp = (x_m ^ 2.0) * (0.16666666666666666 + ((x_m * x_m) * (((x_m * x_m) * (0.0003527336860670194 + ((x_m * x_m) * -2.6455026455026456e-5))) - 0.005555555555555556))); else tmp = (1.0 + log((sinh(x_m) / x_m))) + -1.0; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 0.094], N[(N[Power[x$95$m, 2.0], $MachinePrecision] * N[(0.16666666666666666 + N[(N[(x$95$m * x$95$m), $MachinePrecision] * N[(N[(N[(x$95$m * x$95$m), $MachinePrecision] * N[(0.0003527336860670194 + N[(N[(x$95$m * x$95$m), $MachinePrecision] * -2.6455026455026456e-5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 0.005555555555555556), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[Log[N[(N[Sinh[x$95$m], $MachinePrecision] / x$95$m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 0.094:\\
\;\;\;\;{x\_m}^{2} \cdot \left(0.16666666666666666 + \left(x\_m \cdot x\_m\right) \cdot \left(\left(x\_m \cdot x\_m\right) \cdot \left(0.0003527336860670194 + \left(x\_m \cdot x\_m\right) \cdot -2.6455026455026456 \cdot 10^{-5}\right) - 0.005555555555555556\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \log \left(\frac{\sinh x\_m}{x\_m}\right)\right) + -1\\
\end{array}
\end{array}
if x < 0.094Initial program 53.3%
Taylor expanded in x around 0 96.9%
unpow296.9%
Applied egg-rr96.9%
unpow296.9%
Applied egg-rr96.9%
unpow296.9%
Applied egg-rr96.9%
if 0.094 < x Initial program 49.4%
expm1-log1p-u49.4%
expm1-undefine48.9%
log1p-undefine48.9%
rem-exp-log48.9%
Applied egg-rr48.9%
Final simplification96.1%
x_m = (fabs.f64 x)
(FPCore (x_m)
:precision binary64
(if (<= x_m 0.09)
(*
(pow x_m 2.0)
(+
0.16666666666666666
(*
(* x_m x_m)
(-
(*
(* x_m x_m)
(+ 0.0003527336860670194 (* (* x_m x_m) -2.6455026455026456e-5)))
0.005555555555555556))))
(log (/ (sinh x_m) x_m))))x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 0.09) {
tmp = pow(x_m, 2.0) * (0.16666666666666666 + ((x_m * x_m) * (((x_m * x_m) * (0.0003527336860670194 + ((x_m * x_m) * -2.6455026455026456e-5))) - 0.005555555555555556)));
} else {
tmp = log((sinh(x_m) / x_m));
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 0.09d0) then
tmp = (x_m ** 2.0d0) * (0.16666666666666666d0 + ((x_m * x_m) * (((x_m * x_m) * (0.0003527336860670194d0 + ((x_m * x_m) * (-2.6455026455026456d-5)))) - 0.005555555555555556d0)))
else
tmp = log((sinh(x_m) / x_m))
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 0.09) {
tmp = Math.pow(x_m, 2.0) * (0.16666666666666666 + ((x_m * x_m) * (((x_m * x_m) * (0.0003527336860670194 + ((x_m * x_m) * -2.6455026455026456e-5))) - 0.005555555555555556)));
} else {
tmp = Math.log((Math.sinh(x_m) / x_m));
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 0.09: tmp = math.pow(x_m, 2.0) * (0.16666666666666666 + ((x_m * x_m) * (((x_m * x_m) * (0.0003527336860670194 + ((x_m * x_m) * -2.6455026455026456e-5))) - 0.005555555555555556))) else: tmp = math.log((math.sinh(x_m) / x_m)) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 0.09) tmp = Float64((x_m ^ 2.0) * Float64(0.16666666666666666 + Float64(Float64(x_m * x_m) * Float64(Float64(Float64(x_m * x_m) * Float64(0.0003527336860670194 + Float64(Float64(x_m * x_m) * -2.6455026455026456e-5))) - 0.005555555555555556)))); else tmp = log(Float64(sinh(x_m) / x_m)); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 0.09) tmp = (x_m ^ 2.0) * (0.16666666666666666 + ((x_m * x_m) * (((x_m * x_m) * (0.0003527336860670194 + ((x_m * x_m) * -2.6455026455026456e-5))) - 0.005555555555555556))); else tmp = log((sinh(x_m) / x_m)); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 0.09], N[(N[Power[x$95$m, 2.0], $MachinePrecision] * N[(0.16666666666666666 + N[(N[(x$95$m * x$95$m), $MachinePrecision] * N[(N[(N[(x$95$m * x$95$m), $MachinePrecision] * N[(0.0003527336860670194 + N[(N[(x$95$m * x$95$m), $MachinePrecision] * -2.6455026455026456e-5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 0.005555555555555556), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[N[(N[Sinh[x$95$m], $MachinePrecision] / x$95$m), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 0.09:\\
\;\;\;\;{x\_m}^{2} \cdot \left(0.16666666666666666 + \left(x\_m \cdot x\_m\right) \cdot \left(\left(x\_m \cdot x\_m\right) \cdot \left(0.0003527336860670194 + \left(x\_m \cdot x\_m\right) \cdot -2.6455026455026456 \cdot 10^{-5}\right) - 0.005555555555555556\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(\frac{\sinh x\_m}{x\_m}\right)\\
\end{array}
\end{array}
if x < 0.089999999999999997Initial program 53.3%
Taylor expanded in x around 0 96.9%
unpow296.9%
Applied egg-rr96.9%
unpow296.9%
Applied egg-rr96.9%
unpow296.9%
Applied egg-rr96.9%
if 0.089999999999999997 < x Initial program 49.4%
Final simplification96.1%
x_m = (fabs.f64 x)
(FPCore (x_m)
:precision binary64
(*
(pow x_m 2.0)
(+
0.16666666666666666
(*
(* x_m x_m)
(-
(*
(* x_m x_m)
(+ 0.0003527336860670194 (* (* x_m x_m) -2.6455026455026456e-5)))
0.005555555555555556)))))x_m = fabs(x);
double code(double x_m) {
return pow(x_m, 2.0) * (0.16666666666666666 + ((x_m * x_m) * (((x_m * x_m) * (0.0003527336860670194 + ((x_m * x_m) * -2.6455026455026456e-5))) - 0.005555555555555556)));
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = (x_m ** 2.0d0) * (0.16666666666666666d0 + ((x_m * x_m) * (((x_m * x_m) * (0.0003527336860670194d0 + ((x_m * x_m) * (-2.6455026455026456d-5)))) - 0.005555555555555556d0)))
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return Math.pow(x_m, 2.0) * (0.16666666666666666 + ((x_m * x_m) * (((x_m * x_m) * (0.0003527336860670194 + ((x_m * x_m) * -2.6455026455026456e-5))) - 0.005555555555555556)));
}
x_m = math.fabs(x) def code(x_m): return math.pow(x_m, 2.0) * (0.16666666666666666 + ((x_m * x_m) * (((x_m * x_m) * (0.0003527336860670194 + ((x_m * x_m) * -2.6455026455026456e-5))) - 0.005555555555555556)))
x_m = abs(x) function code(x_m) return Float64((x_m ^ 2.0) * Float64(0.16666666666666666 + Float64(Float64(x_m * x_m) * Float64(Float64(Float64(x_m * x_m) * Float64(0.0003527336860670194 + Float64(Float64(x_m * x_m) * -2.6455026455026456e-5))) - 0.005555555555555556)))) end
x_m = abs(x); function tmp = code(x_m) tmp = (x_m ^ 2.0) * (0.16666666666666666 + ((x_m * x_m) * (((x_m * x_m) * (0.0003527336860670194 + ((x_m * x_m) * -2.6455026455026456e-5))) - 0.005555555555555556))); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(N[Power[x$95$m, 2.0], $MachinePrecision] * N[(0.16666666666666666 + N[(N[(x$95$m * x$95$m), $MachinePrecision] * N[(N[(N[(x$95$m * x$95$m), $MachinePrecision] * N[(0.0003527336860670194 + N[(N[(x$95$m * x$95$m), $MachinePrecision] * -2.6455026455026456e-5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 0.005555555555555556), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
{x\_m}^{2} \cdot \left(0.16666666666666666 + \left(x\_m \cdot x\_m\right) \cdot \left(\left(x\_m \cdot x\_m\right) \cdot \left(0.0003527336860670194 + \left(x\_m \cdot x\_m\right) \cdot -2.6455026455026456 \cdot 10^{-5}\right) - 0.005555555555555556\right)\right)
\end{array}
Initial program 53.2%
Taylor expanded in x around 0 95.8%
unpow295.8%
Applied egg-rr95.8%
unpow295.8%
Applied egg-rr95.8%
unpow295.8%
Applied egg-rr95.8%
Final simplification95.8%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* 0.3333333333333333 (* (pow x_m 2.0) (+ 0.5 (* (* x_m x_m) -0.016666666666666666)))))
x_m = fabs(x);
double code(double x_m) {
return 0.3333333333333333 * (pow(x_m, 2.0) * (0.5 + ((x_m * x_m) * -0.016666666666666666)));
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = 0.3333333333333333d0 * ((x_m ** 2.0d0) * (0.5d0 + ((x_m * x_m) * (-0.016666666666666666d0))))
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return 0.3333333333333333 * (Math.pow(x_m, 2.0) * (0.5 + ((x_m * x_m) * -0.016666666666666666)));
}
x_m = math.fabs(x) def code(x_m): return 0.3333333333333333 * (math.pow(x_m, 2.0) * (0.5 + ((x_m * x_m) * -0.016666666666666666)))
x_m = abs(x) function code(x_m) return Float64(0.3333333333333333 * Float64((x_m ^ 2.0) * Float64(0.5 + Float64(Float64(x_m * x_m) * -0.016666666666666666)))) end
x_m = abs(x); function tmp = code(x_m) tmp = 0.3333333333333333 * ((x_m ^ 2.0) * (0.5 + ((x_m * x_m) * -0.016666666666666666))); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(0.3333333333333333 * N[(N[Power[x$95$m, 2.0], $MachinePrecision] * N[(0.5 + N[(N[(x$95$m * x$95$m), $MachinePrecision] * -0.016666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
0.3333333333333333 \cdot \left({x\_m}^{2} \cdot \left(0.5 + \left(x\_m \cdot x\_m\right) \cdot -0.016666666666666666\right)\right)
\end{array}
Initial program 53.2%
add-cbrt-cube52.7%
pow1/352.8%
log-pow52.8%
pow352.8%
log-pow53.2%
Applied egg-rr53.2%
Taylor expanded in x around 0 95.0%
*-commutative95.0%
Simplified95.0%
unpow295.8%
Applied egg-rr95.0%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* 0.16666666666666666 (* x_m x_m)))
x_m = fabs(x);
double code(double x_m) {
return 0.16666666666666666 * (x_m * x_m);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = 0.16666666666666666d0 * (x_m * x_m)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return 0.16666666666666666 * (x_m * x_m);
}
x_m = math.fabs(x) def code(x_m): return 0.16666666666666666 * (x_m * x_m)
x_m = abs(x) function code(x_m) return Float64(0.16666666666666666 * Float64(x_m * x_m)) end
x_m = abs(x); function tmp = code(x_m) tmp = 0.16666666666666666 * (x_m * x_m); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(0.16666666666666666 * N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
0.16666666666666666 \cdot \left(x\_m \cdot x\_m\right)
\end{array}
Initial program 53.2%
add-cbrt-cube52.7%
pow1/352.8%
log-pow52.8%
pow352.8%
log-pow53.2%
Applied egg-rr53.2%
Taylor expanded in x around 0 94.3%
*-commutative94.3%
Simplified94.3%
unpow295.8%
Applied egg-rr94.3%
Final simplification94.3%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 0.0)
x_m = fabs(x);
double code(double x_m) {
return 0.0;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = 0.0d0
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return 0.0;
}
x_m = math.fabs(x) def code(x_m): return 0.0
x_m = abs(x) function code(x_m) return 0.0 end
x_m = abs(x); function tmp = code(x_m) tmp = 0.0; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := 0.0
\begin{array}{l}
x_m = \left|x\right|
\\
0
\end{array}
Initial program 53.2%
Taylor expanded in x around 0 48.1%
metadata-eval48.1%
Applied egg-rr48.1%
(FPCore (x)
:precision binary64
(if (< (fabs x) 0.085)
(*
(* x x)
(fma
(fma
(fma -2.6455026455026456e-5 (* x x) 0.0003527336860670194)
(* x x)
-0.005555555555555556)
(* x x)
0.16666666666666666))
(log (/ (sinh x) x))))
double code(double x) {
double tmp;
if (fabs(x) < 0.085) {
tmp = (x * x) * fma(fma(fma(-2.6455026455026456e-5, (x * x), 0.0003527336860670194), (x * x), -0.005555555555555556), (x * x), 0.16666666666666666);
} else {
tmp = log((sinh(x) / x));
}
return tmp;
}
function code(x) tmp = 0.0 if (abs(x) < 0.085) tmp = Float64(Float64(x * x) * fma(fma(fma(-2.6455026455026456e-5, Float64(x * x), 0.0003527336860670194), Float64(x * x), -0.005555555555555556), Float64(x * x), 0.16666666666666666)); else tmp = log(Float64(sinh(x) / x)); end return tmp end
code[x_] := If[Less[N[Abs[x], $MachinePrecision], 0.085], N[(N[(x * x), $MachinePrecision] * N[(N[(N[(-2.6455026455026456e-5 * N[(x * x), $MachinePrecision] + 0.0003527336860670194), $MachinePrecision] * N[(x * x), $MachinePrecision] + -0.005555555555555556), $MachinePrecision] * N[(x * x), $MachinePrecision] + 0.16666666666666666), $MachinePrecision]), $MachinePrecision], N[Log[N[(N[Sinh[x], $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| < 0.085:\\
\;\;\;\;\left(x \cdot x\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-2.6455026455026456 \cdot 10^{-5}, x \cdot x, 0.0003527336860670194\right), x \cdot x, -0.005555555555555556\right), x \cdot x, 0.16666666666666666\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(\frac{\sinh x}{x}\right)\\
\end{array}
\end{array}
herbie shell --seed 2024150
(FPCore (x)
:name "bug500, discussion (missed optimization)"
:precision binary64
:alt
(! :herbie-platform default (if (< (fabs x) 17/200) (let ((x2 (* x x))) (* x2 (fma (fma (fma -1/37800 x2 1/2835) x2 -1/180) x2 1/6))) (log (/ (sinh x) x))))
(log (/ (sinh x) x)))