
(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 -3.0) 6.0))
double code(double x) {
return fma(x, x, -3.0) / 6.0;
}
function code(x) return Float64(fma(x, x, -3.0) / 6.0) end
code[x_] := N[(N[(x * x + -3.0), $MachinePrecision] / 6.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(x, x, -3\right)}{6}
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
rgt-mult-inverseN/A
fp-cancel-sign-sub-invN/A
associate-*r*N/A
*-commutativeN/A
unpow2N/A
*-commutativeN/A
associate-*r*N/A
rgt-mult-inverseN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
metadata-eval99.9
Applied rewrites99.9%
(FPCore (x) :precision binary64 (if (<= x 1.7) -0.5 (* (* x x) 0.16666666666666666)))
double code(double x) {
double tmp;
if (x <= 1.7) {
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 <= 1.7d0) 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 <= 1.7) {
tmp = -0.5;
} else {
tmp = (x * x) * 0.16666666666666666;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.7: tmp = -0.5 else: tmp = (x * x) * 0.16666666666666666 return tmp
function code(x) tmp = 0.0 if (x <= 1.7) 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 <= 1.7) tmp = -0.5; else tmp = (x * x) * 0.16666666666666666; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.7], -0.5, N[(N[(x * x), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.7:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot x\right) \cdot 0.16666666666666666\\
\end{array}
\end{array}
if x < 1.69999999999999996Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites64.5%
if 1.69999999999999996 < x Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6498.0
Applied rewrites98.0%
(FPCore (x) :precision binary64 (if (<= x 1.7) -0.5 (* (* x 0.16666666666666666) x)))
double code(double x) {
double tmp;
if (x <= 1.7) {
tmp = -0.5;
} else {
tmp = (x * 0.16666666666666666) * x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.7d0) then
tmp = -0.5d0
else
tmp = (x * 0.16666666666666666d0) * x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.7) {
tmp = -0.5;
} else {
tmp = (x * 0.16666666666666666) * x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.7: tmp = -0.5 else: tmp = (x * 0.16666666666666666) * x return tmp
function code(x) tmp = 0.0 if (x <= 1.7) tmp = -0.5; else tmp = Float64(Float64(x * 0.16666666666666666) * x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.7) tmp = -0.5; else tmp = (x * 0.16666666666666666) * x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.7], -0.5, N[(N[(x * 0.16666666666666666), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.7:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot 0.16666666666666666\right) \cdot x\\
\end{array}
\end{array}
if x < 1.69999999999999996Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites64.5%
if 1.69999999999999996 < x Initial program 99.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6498.0
Applied rewrites98.0%
Applied rewrites70.7%
Applied rewrites97.9%
(FPCore (x) :precision binary64 (fma (* 0.16666666666666666 x) x -0.5))
double code(double x) {
return fma((0.16666666666666666 * x), x, -0.5);
}
function code(x) return fma(Float64(0.16666666666666666 * x), x, -0.5) end
code[x_] := N[(N[(0.16666666666666666 * x), $MachinePrecision] * x + -0.5), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(0.16666666666666666 \cdot x, x, -0.5\right)
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
rgt-mult-inverseN/A
fp-cancel-sign-sub-invN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
lft-mult-inverseN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
metadata-eval99.8
Applied rewrites99.8%
(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%
Taylor expanded in x around 0
Applied rewrites47.6%
herbie shell --seed 2024338
(FPCore (x)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, H"
:precision binary64
(/ (- (* x x) 3.0) 6.0))