
(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 (* 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.6%
div-inv99.5%
metadata-eval99.5%
add-exp-log45.8%
log-prod45.8%
exp-sum45.8%
add-exp-log99.3%
fma-neg99.3%
metadata-eval99.3%
Applied egg-rr99.3%
*-commutative99.3%
fma-udef99.3%
unpow299.3%
distribute-lft-in99.4%
unpow299.4%
associate-*r*99.7%
rem-exp-log99.7%
metadata-eval99.7%
metadata-eval99.7%
fma-def99.7%
rem-exp-log99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (<= x 1.72) -0.5 (* x (* 0.16666666666666666 x))))
double code(double x) {
double tmp;
if (x <= 1.72) {
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.72d0) 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.72) {
tmp = -0.5;
} else {
tmp = x * (0.16666666666666666 * x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.72: tmp = -0.5 else: tmp = x * (0.16666666666666666 * x) return tmp
function code(x) tmp = 0.0 if (x <= 1.72) tmp = -0.5; else tmp = Float64(x * Float64(0.16666666666666666 * x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.72) tmp = -0.5; else tmp = x * (0.16666666666666666 * x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.72], -0.5, N[(x * N[(0.16666666666666666 * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.72:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(0.16666666666666666 \cdot x\right)\\
\end{array}
\end{array}
if x < 1.71999999999999997Initial program 99.9%
sqr-neg99.9%
*-lft-identity99.9%
metadata-eval99.9%
associate-*r/99.9%
associate-/l*99.9%
associate-/r/99.9%
*-commutative99.9%
sqr-neg99.9%
fma-neg99.9%
metadata-eval99.9%
metadata-eval99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around 0 67.3%
if 1.71999999999999997 < x Initial program 98.4%
sqr-neg98.4%
*-lft-identity98.4%
metadata-eval98.4%
associate-*r/98.4%
associate-/l*98.4%
associate-/r/98.4%
*-commutative98.4%
sqr-neg98.4%
fma-neg98.4%
metadata-eval98.4%
metadata-eval98.4%
metadata-eval98.4%
Simplified98.4%
metadata-eval98.4%
fma-neg98.4%
metadata-eval98.4%
div-inv98.4%
clear-num98.4%
fma-neg98.4%
metadata-eval98.4%
Applied egg-rr98.4%
Taylor expanded in x around inf 98.4%
associate-/r/98.4%
metadata-eval98.4%
unpow298.4%
associate-*r*99.6%
Applied egg-rr99.6%
Final simplification75.0%
(FPCore (x) :precision binary64 (if (<= x 1.72) -0.5 (* x (/ x 6.0))))
double code(double x) {
double tmp;
if (x <= 1.72) {
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 <= 1.72d0) 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 <= 1.72) {
tmp = -0.5;
} else {
tmp = x * (x / 6.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.72: tmp = -0.5 else: tmp = x * (x / 6.0) return tmp
function code(x) tmp = 0.0 if (x <= 1.72) 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 <= 1.72) tmp = -0.5; else tmp = x * (x / 6.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.72], -0.5, N[(x * N[(x / 6.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.72:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{x}{6}\\
\end{array}
\end{array}
if x < 1.71999999999999997Initial program 99.9%
sqr-neg99.9%
*-lft-identity99.9%
metadata-eval99.9%
associate-*r/99.9%
associate-/l*99.9%
associate-/r/99.9%
*-commutative99.9%
sqr-neg99.9%
fma-neg99.9%
metadata-eval99.9%
metadata-eval99.9%
metadata-eval99.9%
Simplified99.9%
Taylor expanded in x around 0 67.3%
if 1.71999999999999997 < x Initial program 98.4%
sqr-neg98.4%
*-lft-identity98.4%
metadata-eval98.4%
associate-*r/98.4%
associate-/l*98.4%
associate-/r/98.4%
*-commutative98.4%
sqr-neg98.4%
fma-neg98.4%
metadata-eval98.4%
metadata-eval98.4%
metadata-eval98.4%
Simplified98.4%
Taylor expanded in x around inf 98.4%
rem-exp-log98.0%
add-sqr-sqrt97.9%
sqrt-unprod67.7%
*-commutative67.7%
*-commutative67.7%
swap-sqr67.7%
pow-sqr67.7%
metadata-eval67.7%
rem-exp-log67.8%
rem-exp-log67.8%
metadata-eval67.8%
Applied egg-rr67.8%
sqrt-prod67.8%
metadata-eval67.8%
sqrt-pow198.4%
metadata-eval98.4%
metadata-eval98.4%
div-inv98.4%
unpow298.4%
associate-/l*99.6%
Applied egg-rr99.6%
associate-/r/99.7%
Simplified99.7%
Final simplification75.0%
(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%
Final simplification99.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%
*-lft-identity99.6%
metadata-eval99.6%
associate-*r/99.6%
associate-/l*99.5%
associate-/r/99.5%
*-commutative99.5%
sqr-neg99.5%
fma-neg99.5%
metadata-eval99.5%
metadata-eval99.5%
metadata-eval99.5%
Simplified99.5%
Taylor expanded in x around 0 51.5%
Final simplification51.5%
herbie shell --seed 2024010
(FPCore (x)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, H"
:precision binary64
(/ (- (* x x) 3.0) 6.0))