
(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.6%
sqr-neg99.6%
*-rgt-identity99.6%
metadata-eval99.6%
associate-*l/99.6%
associate-/l*99.6%
sqr-neg99.6%
fma-neg99.6%
metadata-eval99.6%
metadata-eval99.6%
metadata-eval99.6%
Simplified99.6%
metadata-eval99.6%
fma-neg99.6%
metadata-eval99.6%
div-inv99.6%
div-sub99.6%
associate-/l*99.9%
fma-neg99.9%
metadata-eval99.9%
metadata-eval99.9%
Applied egg-rr99.9%
(FPCore (x) :precision binary64 (if (<= (* x x) 5e-15) -0.5 (/ x (/ 6.0 x))))
double code(double x) {
double tmp;
if ((x * x) <= 5e-15) {
tmp = -0.5;
} else {
tmp = x / (6.0 / x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x * x) <= 5d-15) then
tmp = -0.5d0
else
tmp = x / (6.0d0 / x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x * x) <= 5e-15) {
tmp = -0.5;
} else {
tmp = x / (6.0 / x);
}
return tmp;
}
def code(x): tmp = 0 if (x * x) <= 5e-15: tmp = -0.5 else: tmp = x / (6.0 / x) return tmp
function code(x) tmp = 0.0 if (Float64(x * x) <= 5e-15) tmp = -0.5; else tmp = Float64(x / Float64(6.0 / x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x * x) <= 5e-15) tmp = -0.5; else tmp = x / (6.0 / x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(x * x), $MachinePrecision], 5e-15], -0.5, N[(x / N[(6.0 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-15}:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{6}{x}}\\
\end{array}
\end{array}
if (*.f64 x x) < 4.99999999999999999e-15Initial program 100.0%
sqr-neg100.0%
*-rgt-identity100.0%
metadata-eval100.0%
associate-*l/100.0%
associate-/l*100.0%
sqr-neg100.0%
fma-neg100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
if 4.99999999999999999e-15 < (*.f64 x x) Initial program 99.2%
sqr-neg99.2%
*-rgt-identity99.2%
metadata-eval99.2%
associate-*l/99.2%
associate-/l*99.2%
sqr-neg99.2%
fma-neg99.2%
metadata-eval99.2%
metadata-eval99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in x around inf 97.6%
unpow297.6%
associate-*r*98.2%
metadata-eval98.2%
div-inv98.2%
clear-num98.2%
un-div-inv98.3%
Applied egg-rr98.3%
(FPCore (x) :precision binary64 (if (<= (* x x) 3.0) -0.5 (* (* x x) 0.16666666666666666)))
double code(double x) {
double tmp;
if ((x * x) <= 3.0) {
tmp = -0.5;
} else {
tmp = (x * x) * 0.16666666666666666;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x * x) <= 3.0d0) then
tmp = -0.5d0
else
tmp = (x * x) * 0.16666666666666666d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x * x) <= 3.0) {
tmp = -0.5;
} else {
tmp = (x * x) * 0.16666666666666666;
}
return tmp;
}
def code(x): tmp = 0 if (x * x) <= 3.0: tmp = -0.5 else: tmp = (x * x) * 0.16666666666666666 return tmp
function code(x) tmp = 0.0 if (Float64(x * x) <= 3.0) tmp = -0.5; else tmp = Float64(Float64(x * x) * 0.16666666666666666); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x * x) <= 3.0) tmp = -0.5; else tmp = (x * x) * 0.16666666666666666; end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(x * x), $MachinePrecision], 3.0], -0.5, N[(N[(x * x), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 3:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot x\right) \cdot 0.16666666666666666\\
\end{array}
\end{array}
if (*.f64 x x) < 3Initial program 100.0%
sqr-neg100.0%
*-rgt-identity100.0%
metadata-eval100.0%
associate-*l/100.0%
associate-/l*100.0%
sqr-neg100.0%
fma-neg100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 100.0%
if 3 < (*.f64 x x) Initial program 99.2%
sqr-neg99.2%
*-rgt-identity99.2%
metadata-eval99.2%
associate-*l/99.2%
associate-/l*99.2%
sqr-neg99.2%
fma-neg99.2%
metadata-eval99.2%
metadata-eval99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in x around inf 97.6%
unpow297.6%
Applied egg-rr97.6%
(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.6%
(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.6%
sqr-neg99.6%
*-rgt-identity99.6%
metadata-eval99.6%
associate-*l/99.6%
associate-/l*99.6%
sqr-neg99.6%
fma-neg99.6%
metadata-eval99.6%
metadata-eval99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in x around 0 51.9%
herbie shell --seed 2024145
(FPCore (x)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, H"
:precision binary64
(/ (- (* x x) 3.0) 6.0))