
(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 4 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 2.5e-14)
(log (/ (sinh x_m) x_m))
(fma
0.16666666666666666
(pow x_m 2.0)
(fma
-0.005555555555555556
(pow x_m 4.0)
(* 0.0003527336860670194 (pow x_m 6.0))))))x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 2.5e-14) {
tmp = log((sinh(x_m) / x_m));
} else {
tmp = fma(0.16666666666666666, pow(x_m, 2.0), fma(-0.005555555555555556, pow(x_m, 4.0), (0.0003527336860670194 * pow(x_m, 6.0))));
}
return tmp;
}
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 2.5e-14) tmp = log(Float64(sinh(x_m) / x_m)); else tmp = fma(0.16666666666666666, (x_m ^ 2.0), fma(-0.005555555555555556, (x_m ^ 4.0), Float64(0.0003527336860670194 * (x_m ^ 6.0)))); end return tmp end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 2.5e-14], N[Log[N[(N[Sinh[x$95$m], $MachinePrecision] / x$95$m), $MachinePrecision]], $MachinePrecision], N[(0.16666666666666666 * N[Power[x$95$m, 2.0], $MachinePrecision] + N[(-0.005555555555555556 * N[Power[x$95$m, 4.0], $MachinePrecision] + N[(0.0003527336860670194 * N[Power[x$95$m, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 2.5 \cdot 10^{-14}:\\
\;\;\;\;\log \left(\frac{\sinh x\_m}{x\_m}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.16666666666666666, {x\_m}^{2}, \mathsf{fma}\left(-0.005555555555555556, {x\_m}^{4}, 0.0003527336860670194 \cdot {x\_m}^{6}\right)\right)\\
\end{array}
\end{array}
if x < 2.5000000000000001e-14Initial program 98.3%
if 2.5000000000000001e-14 < x Initial program 3.2%
Taylor expanded in x around 0 54.0%
associate-+r+54.0%
+-commutative54.0%
fma-def54.0%
fma-def54.0%
Simplified54.0%
Final simplification97.2%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 2.5e-14) (log (/ (sinh x_m) x_m)) (* x_m (* x_m 0.16666666666666666))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 2.5e-14) {
tmp = log((sinh(x_m) / x_m));
} else {
tmp = x_m * (x_m * 0.16666666666666666);
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 2.5d-14) then
tmp = log((sinh(x_m) / x_m))
else
tmp = x_m * (x_m * 0.16666666666666666d0)
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 2.5e-14) {
tmp = Math.log((Math.sinh(x_m) / x_m));
} else {
tmp = x_m * (x_m * 0.16666666666666666);
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 2.5e-14: tmp = math.log((math.sinh(x_m) / x_m)) else: tmp = x_m * (x_m * 0.16666666666666666) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 2.5e-14) tmp = log(Float64(sinh(x_m) / x_m)); else tmp = Float64(x_m * Float64(x_m * 0.16666666666666666)); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 2.5e-14) tmp = log((sinh(x_m) / x_m)); else tmp = x_m * (x_m * 0.16666666666666666); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 2.5e-14], N[Log[N[(N[Sinh[x$95$m], $MachinePrecision] / x$95$m), $MachinePrecision]], $MachinePrecision], N[(x$95$m * N[(x$95$m * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 2.5 \cdot 10^{-14}:\\
\;\;\;\;\log \left(\frac{\sinh x\_m}{x\_m}\right)\\
\mathbf{else}:\\
\;\;\;\;x\_m \cdot \left(x\_m \cdot 0.16666666666666666\right)\\
\end{array}
\end{array}
if x < 2.5000000000000001e-14Initial program 98.3%
if 2.5000000000000001e-14 < x Initial program 3.2%
Taylor expanded in x around 0 55.8%
add-cbrt-cube55.7%
pow1/353.2%
pow353.2%
*-commutative53.2%
unpow-prod-down53.2%
unpow253.2%
pow-prod-down53.2%
pow-sqr53.1%
metadata-eval53.1%
metadata-eval53.1%
Applied egg-rr53.1%
unpow-prod-down53.1%
pow-pow56.1%
metadata-eval56.1%
unpow1/355.8%
metadata-eval55.8%
metadata-eval55.8%
rem-square-sqrt55.8%
pow255.8%
rem-square-sqrt55.8%
pow255.8%
rem-square-sqrt55.8%
pow255.8%
add-cbrt-cube55.8%
unpow-prod-down56.1%
unpow256.1%
*-commutative56.1%
*-commutative56.1%
swap-sqr55.8%
rem-square-sqrt55.8%
associate-*l*56.1%
*-commutative56.1%
Applied egg-rr56.1%
Final simplification97.3%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (if (<= x_m 2.5e-14) (* 0.0003527336860670194 (pow x_m 6.0)) (* x_m (* x_m 0.16666666666666666))))
x_m = fabs(x);
double code(double x_m) {
double tmp;
if (x_m <= 2.5e-14) {
tmp = 0.0003527336860670194 * pow(x_m, 6.0);
} else {
tmp = x_m * (x_m * 0.16666666666666666);
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
real(8) :: tmp
if (x_m <= 2.5d-14) then
tmp = 0.0003527336860670194d0 * (x_m ** 6.0d0)
else
tmp = x_m * (x_m * 0.16666666666666666d0)
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m) {
double tmp;
if (x_m <= 2.5e-14) {
tmp = 0.0003527336860670194 * Math.pow(x_m, 6.0);
} else {
tmp = x_m * (x_m * 0.16666666666666666);
}
return tmp;
}
x_m = math.fabs(x) def code(x_m): tmp = 0 if x_m <= 2.5e-14: tmp = 0.0003527336860670194 * math.pow(x_m, 6.0) else: tmp = x_m * (x_m * 0.16666666666666666) return tmp
x_m = abs(x) function code(x_m) tmp = 0.0 if (x_m <= 2.5e-14) tmp = Float64(0.0003527336860670194 * (x_m ^ 6.0)); else tmp = Float64(x_m * Float64(x_m * 0.16666666666666666)); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m) tmp = 0.0; if (x_m <= 2.5e-14) tmp = 0.0003527336860670194 * (x_m ^ 6.0); else tmp = x_m * (x_m * 0.16666666666666666); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := If[LessEqual[x$95$m, 2.5e-14], N[(0.0003527336860670194 * N[Power[x$95$m, 6.0], $MachinePrecision]), $MachinePrecision], N[(x$95$m * N[(x$95$m * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 2.5 \cdot 10^{-14}:\\
\;\;\;\;0.0003527336860670194 \cdot {x\_m}^{6}\\
\mathbf{else}:\\
\;\;\;\;x\_m \cdot \left(x\_m \cdot 0.16666666666666666\right)\\
\end{array}
\end{array}
if x < 2.5000000000000001e-14Initial program 98.3%
Taylor expanded in x around 0 51.5%
associate-+r+51.5%
+-commutative51.5%
fma-def51.5%
fma-def51.5%
Simplified51.5%
Taylor expanded in x around inf 82.3%
if 2.5000000000000001e-14 < x Initial program 3.2%
Taylor expanded in x around 0 55.8%
add-cbrt-cube55.7%
pow1/353.2%
pow353.2%
*-commutative53.2%
unpow-prod-down53.2%
unpow253.2%
pow-prod-down53.2%
pow-sqr53.1%
metadata-eval53.1%
metadata-eval53.1%
Applied egg-rr53.1%
unpow-prod-down53.1%
pow-pow56.1%
metadata-eval56.1%
unpow1/355.8%
metadata-eval55.8%
metadata-eval55.8%
rem-square-sqrt55.8%
pow255.8%
rem-square-sqrt55.8%
pow255.8%
rem-square-sqrt55.8%
pow255.8%
add-cbrt-cube55.8%
unpow-prod-down56.1%
unpow256.1%
*-commutative56.1%
*-commutative56.1%
swap-sqr55.8%
rem-square-sqrt55.8%
associate-*l*56.1%
*-commutative56.1%
Applied egg-rr56.1%
Final simplification81.6%
x_m = (fabs.f64 x) (FPCore (x_m) :precision binary64 (* x_m (* x_m 0.16666666666666666)))
x_m = fabs(x);
double code(double x_m) {
return x_m * (x_m * 0.16666666666666666);
}
x_m = abs(x)
real(8) function code(x_m)
real(8), intent (in) :: x_m
code = x_m * (x_m * 0.16666666666666666d0)
end function
x_m = Math.abs(x);
public static double code(double x_m) {
return x_m * (x_m * 0.16666666666666666);
}
x_m = math.fabs(x) def code(x_m): return x_m * (x_m * 0.16666666666666666)
x_m = abs(x) function code(x_m) return Float64(x_m * Float64(x_m * 0.16666666666666666)) end
x_m = abs(x); function tmp = code(x_m) tmp = x_m * (x_m * 0.16666666666666666); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_] := N[(x$95$m * N[(x$95$m * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x\_m \cdot \left(x\_m \cdot 0.16666666666666666\right)
\end{array}
Initial program 96.0%
Taylor expanded in x around 0 51.5%
add-cbrt-cube80.9%
pow1/380.8%
pow380.8%
*-commutative80.8%
unpow-prod-down80.8%
unpow280.8%
pow-prod-down80.8%
pow-sqr80.8%
metadata-eval80.8%
metadata-eval80.8%
Applied egg-rr80.8%
unpow-prod-down80.4%
pow-pow51.5%
metadata-eval51.5%
unpow1/351.5%
metadata-eval51.5%
metadata-eval51.5%
rem-square-sqrt51.5%
pow251.5%
rem-square-sqrt51.5%
pow251.5%
rem-square-sqrt51.5%
pow251.5%
add-cbrt-cube51.5%
unpow-prod-down51.6%
unpow251.6%
*-commutative51.6%
*-commutative51.6%
swap-sqr51.5%
rem-square-sqrt51.5%
associate-*l*51.6%
*-commutative51.6%
Applied egg-rr51.6%
Final simplification51.6%
(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 2024031
(FPCore (x)
:name "bug500, discussion (missed optimization)"
:precision binary64
:herbie-target
(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)))
(log (/ (sinh x) x)))