
(FPCore (x) :precision binary64 (/ (- (* x x) 3.0) 6.0))
double code(double x) {
return ((x * x) - 3.0) / 6.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((x * x) - 3.0d0) / 6.0d0
end function
public static double code(double x) {
return ((x * x) - 3.0) / 6.0;
}
def code(x): return ((x * x) - 3.0) / 6.0
function code(x) return Float64(Float64(Float64(x * x) - 3.0) / 6.0) end
function tmp = code(x) tmp = ((x * x) - 3.0) / 6.0; end
code[x_] := N[(N[(N[(x * x), $MachinePrecision] - 3.0), $MachinePrecision] / 6.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot x - 3}{6}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ (- (* x x) 3.0) 6.0))
double code(double x) {
return ((x * x) - 3.0) / 6.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((x * x) - 3.0d0) / 6.0d0
end function
public static double code(double x) {
return ((x * x) - 3.0) / 6.0;
}
def code(x): return ((x * x) - 3.0) / 6.0
function code(x) return Float64(Float64(Float64(x * x) - 3.0) / 6.0) end
function tmp = code(x) tmp = ((x * x) - 3.0) / 6.0; end
code[x_] := N[(N[(N[(x * x), $MachinePrecision] - 3.0), $MachinePrecision] / 6.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot x - 3}{6}
\end{array}
(FPCore (x) :precision binary64 (fma x (/ x 6.0) -0.5))
double code(double x) {
return fma(x, (x / 6.0), -0.5);
}
function code(x) return fma(x, Float64(x / 6.0), -0.5) end
code[x_] := N[(x * N[(x / 6.0), $MachinePrecision] + -0.5), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \frac{x}{6}, -0.5\right)
\end{array}
Initial program 99.9%
sqr-neg99.9%
*-rgt-identity99.9%
metadata-eval99.9%
associate-*l/99.9%
associate-/l*99.9%
sqr-neg99.9%
fmm-def99.9%
metadata-eval99.9%
metadata-eval99.9%
metadata-eval99.9%
Simplified99.9%
metadata-eval99.9%
fmm-def99.9%
metadata-eval99.9%
div-inv99.9%
div-sub99.9%
associate-/l*99.9%
fmm-def99.9%
metadata-eval99.9%
metadata-eval99.9%
Applied egg-rr99.9%
(FPCore (x) :precision binary64 (if (<= (* x x) 2e-14) -0.5 (/ (* x x) (- -6.0))))
double code(double x) {
double tmp;
if ((x * x) <= 2e-14) {
tmp = -0.5;
} else {
tmp = (x * x) / -(-6.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x * x) <= 2d-14) then
tmp = -0.5d0
else
tmp = (x * x) / -(-6.0d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x * x) <= 2e-14) {
tmp = -0.5;
} else {
tmp = (x * x) / -(-6.0);
}
return tmp;
}
def code(x): tmp = 0 if (x * x) <= 2e-14: tmp = -0.5 else: tmp = (x * x) / -(-6.0) return tmp
function code(x) tmp = 0.0 if (Float64(x * x) <= 2e-14) tmp = -0.5; else tmp = Float64(Float64(x * x) / Float64(-(-6.0))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x * x) <= 2e-14) tmp = -0.5; else tmp = (x * x) / -(-6.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(x * x), $MachinePrecision], 2e-14], -0.5, N[(N[(x * x), $MachinePrecision] / (--6.0)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-14}:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot x}{--6}\\
\end{array}
\end{array}
if (*.f64 x x) < 2e-14Initial program 100.0%
sqr-neg100.0%
*-rgt-identity100.0%
metadata-eval100.0%
associate-*l/100.0%
associate-/l*100.0%
sqr-neg100.0%
fmm-def100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 99.9%
if 2e-14 < (*.f64 x x) Initial program 99.8%
sqr-neg99.8%
*-rgt-identity99.8%
metadata-eval99.8%
associate-*l/99.8%
associate-/l*99.8%
sqr-neg99.8%
fmm-def99.8%
metadata-eval99.8%
metadata-eval99.8%
metadata-eval99.8%
Simplified99.8%
Taylor expanded in x around inf 97.7%
unpow297.7%
associate-*r*97.7%
metadata-eval97.7%
div-inv97.8%
frac-2neg97.8%
associate-*r/97.8%
metadata-eval97.8%
Applied egg-rr97.8%
Final simplification98.8%
(FPCore (x) :precision binary64 (if (<= (* x x) 2e-14) -0.5 (* x (/ x 6.0))))
double code(double x) {
double tmp;
if ((x * x) <= 2e-14) {
tmp = -0.5;
} else {
tmp = x * (x / 6.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x * x) <= 2d-14) then
tmp = -0.5d0
else
tmp = x * (x / 6.0d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x * x) <= 2e-14) {
tmp = -0.5;
} else {
tmp = x * (x / 6.0);
}
return tmp;
}
def code(x): tmp = 0 if (x * x) <= 2e-14: tmp = -0.5 else: tmp = x * (x / 6.0) return tmp
function code(x) tmp = 0.0 if (Float64(x * x) <= 2e-14) tmp = -0.5; else tmp = Float64(x * Float64(x / 6.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x * x) <= 2e-14) tmp = -0.5; else tmp = x * (x / 6.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(x * x), $MachinePrecision], 2e-14], -0.5, N[(x * N[(x / 6.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-14}:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{x}{6}\\
\end{array}
\end{array}
if (*.f64 x x) < 2e-14Initial program 100.0%
sqr-neg100.0%
*-rgt-identity100.0%
metadata-eval100.0%
associate-*l/100.0%
associate-/l*100.0%
sqr-neg100.0%
fmm-def100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 99.9%
if 2e-14 < (*.f64 x x) Initial program 99.8%
sqr-neg99.8%
*-rgt-identity99.8%
metadata-eval99.8%
associate-*l/99.8%
associate-/l*99.8%
sqr-neg99.8%
fmm-def99.8%
metadata-eval99.8%
metadata-eval99.8%
metadata-eval99.8%
Simplified99.8%
metadata-eval99.8%
fmm-def99.8%
metadata-eval99.8%
div-inv99.8%
clear-num99.8%
fmm-def99.8%
metadata-eval99.8%
Applied egg-rr99.8%
Taylor expanded in x around inf 97.8%
unpow297.8%
Applied egg-rr97.8%
clear-num97.8%
associate-/l*97.8%
Applied egg-rr97.8%
(FPCore (x) :precision binary64 (/ (- (* x x) 3.0) 6.0))
double code(double x) {
return ((x * x) - 3.0) / 6.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((x * x) - 3.0d0) / 6.0d0
end function
public static double code(double x) {
return ((x * x) - 3.0) / 6.0;
}
def code(x): return ((x * x) - 3.0) / 6.0
function code(x) return Float64(Float64(Float64(x * x) - 3.0) / 6.0) end
function tmp = code(x) tmp = ((x * x) - 3.0) / 6.0; end
code[x_] := N[(N[(N[(x * x), $MachinePrecision] - 3.0), $MachinePrecision] / 6.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot x - 3}{6}
\end{array}
Initial program 99.9%
(FPCore (x) :precision binary64 -0.5)
double code(double x) {
return -0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = -0.5d0
end function
public static double code(double x) {
return -0.5;
}
def code(x): return -0.5
function code(x) return -0.5 end
function tmp = code(x) tmp = -0.5; end
code[x_] := -0.5
\begin{array}{l}
\\
-0.5
\end{array}
Initial program 99.9%
sqr-neg99.9%
*-rgt-identity99.9%
metadata-eval99.9%
associate-*l/99.9%
associate-/l*99.9%
sqr-neg99.9%
fmm-def99.9%
metadata-eval99.9%
metadata-eval99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around 0 50.4%
herbie shell --seed 2024172
(FPCore (x)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, H"
:precision binary64
(/ (- (* x x) 3.0) 6.0))