
(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 4 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 (- (* x (* x 0.16666666666666666)) 0.5))
double code(double x) {
return (x * (x * 0.16666666666666666)) - 0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * (x * 0.16666666666666666d0)) - 0.5d0
end function
public static double code(double x) {
return (x * (x * 0.16666666666666666)) - 0.5;
}
def code(x): return (x * (x * 0.16666666666666666)) - 0.5
function code(x) return Float64(Float64(x * Float64(x * 0.16666666666666666)) - 0.5) end
function tmp = code(x) tmp = (x * (x * 0.16666666666666666)) - 0.5; end
code[x_] := N[(N[(x * N[(x * 0.16666666666666666), $MachinePrecision]), $MachinePrecision] - 0.5), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot 0.16666666666666666\right) - 0.5
\end{array}
Initial program 99.6%
div-sub99.6%
div-inv99.5%
metadata-eval99.5%
associate-*l*99.8%
metadata-eval99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (<= (* x x) 3.0) -0.5 (* 0.16666666666666666 (* x x))))
double code(double x) {
double tmp;
if ((x * x) <= 3.0) {
tmp = -0.5;
} else {
tmp = 0.16666666666666666 * (x * x);
}
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 = 0.16666666666666666d0 * (x * x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x * x) <= 3.0) {
tmp = -0.5;
} else {
tmp = 0.16666666666666666 * (x * x);
}
return tmp;
}
def code(x): tmp = 0 if (x * x) <= 3.0: tmp = -0.5 else: tmp = 0.16666666666666666 * (x * x) return tmp
function code(x) tmp = 0.0 if (Float64(x * x) <= 3.0) tmp = -0.5; else tmp = Float64(0.16666666666666666 * Float64(x * x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x * x) <= 3.0) tmp = -0.5; else tmp = 0.16666666666666666 * (x * x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(x * x), $MachinePrecision], 3.0], -0.5, N[(0.16666666666666666 * N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 3:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;0.16666666666666666 \cdot \left(x \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 3Initial program 100.0%
Taylor expanded in x around 0 98.5%
if 3 < (*.f64 x x) Initial program 99.1%
Taylor expanded in x around inf 97.4%
unpow297.4%
Simplified97.4%
Final simplification97.9%
(FPCore (x) :precision binary64 (if (<= (* x x) 0.002) -0.5 (* x (/ x 6.0))))
double code(double x) {
double tmp;
if ((x * x) <= 0.002) {
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) <= 0.002d0) 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) <= 0.002) {
tmp = -0.5;
} else {
tmp = x * (x / 6.0);
}
return tmp;
}
def code(x): tmp = 0 if (x * x) <= 0.002: tmp = -0.5 else: tmp = x * (x / 6.0) return tmp
function code(x) tmp = 0.0 if (Float64(x * x) <= 0.002) 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) <= 0.002) tmp = -0.5; else tmp = x * (x / 6.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(x * x), $MachinePrecision], 0.002], -0.5, N[(x * N[(x / 6.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 0.002:\\
\;\;\;\;-0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{x}{6}\\
\end{array}
\end{array}
if (*.f64 x x) < 2e-3Initial program 100.0%
Taylor expanded in x around 0 98.5%
if 2e-3 < (*.f64 x x) Initial program 99.1%
sqr-neg99.1%
div-sub99.2%
*-lft-identity99.2%
metadata-eval99.2%
associate-*r/99.2%
associate-/l*99.0%
associate-/r/99.1%
*-commutative99.1%
fma-neg99.1%
sqr-neg99.1%
metadata-eval99.1%
metadata-eval99.1%
metadata-eval99.1%
metadata-eval99.1%
Simplified99.1%
metadata-eval99.1%
metadata-eval99.1%
fma-neg99.1%
metadata-eval99.1%
div-inv99.2%
div-sub99.1%
clear-num99.0%
fma-neg99.0%
metadata-eval99.0%
Applied egg-rr99.0%
Taylor expanded in x around inf 97.3%
unpow297.3%
Simplified97.3%
Taylor expanded in x around 0 97.4%
metadata-eval97.4%
unpow297.4%
associate-/r/97.3%
associate-/r*97.8%
metadata-eval97.8%
associate-*l/97.8%
associate-/l*97.9%
rem-square-sqrt40.9%
associate-*l/40.8%
associate-/r/40.9%
remove-double-div40.9%
associate-*l/40.9%
rem-square-sqrt98.0%
Simplified98.0%
Final simplification98.2%
(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%
Taylor expanded in x around 0 49.3%
Final simplification49.3%
herbie shell --seed 2023275
(FPCore (x)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, H"
:precision binary64
(/ (- (* x x) 3.0) 6.0))