
(FPCore (x) :precision binary64 (* (* x x) (- 3.0 (* x 2.0))))
double code(double x) {
return (x * x) * (3.0 - (x * 2.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * x) * (3.0d0 - (x * 2.0d0))
end function
public static double code(double x) {
return (x * x) * (3.0 - (x * 2.0));
}
def code(x): return (x * x) * (3.0 - (x * 2.0))
function code(x) return Float64(Float64(x * x) * Float64(3.0 - Float64(x * 2.0))) end
function tmp = code(x) tmp = (x * x) * (3.0 - (x * 2.0)); end
code[x_] := N[(N[(x * x), $MachinePrecision] * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (* (* x x) (- 3.0 (* x 2.0))))
double code(double x) {
return (x * x) * (3.0 - (x * 2.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * x) * (3.0d0 - (x * 2.0d0))
end function
public static double code(double x) {
return (x * x) * (3.0 - (x * 2.0));
}
def code(x): return (x * x) * (3.0 - (x * 2.0))
function code(x) return Float64(Float64(x * x) * Float64(3.0 - Float64(x * 2.0))) end
function tmp = code(x) tmp = (x * x) * (3.0 - (x * 2.0)); end
code[x_] := N[(N[(x * x), $MachinePrecision] * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)
\end{array}
(FPCore (x) :precision binary64 (fma (* x 3.0) x (* -2.0 (pow x 3.0))))
double code(double x) {
return fma((x * 3.0), x, (-2.0 * pow(x, 3.0)));
}
function code(x) return fma(Float64(x * 3.0), x, Float64(-2.0 * (x ^ 3.0))) end
code[x_] := N[(N[(x * 3.0), $MachinePrecision] * x + N[(-2.0 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x \cdot 3, x, -2 \cdot {x}^{3}\right)
\end{array}
Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 88.2%
add-exp-log72.2%
fma-def72.2%
Applied egg-rr72.2%
rem-exp-log88.2%
fma-udef88.2%
+-commutative88.2%
*-commutative88.2%
metadata-eval88.2%
div-inv88.1%
unpow288.1%
associate-*r/88.1%
*-commutative88.1%
fma-def99.9%
div-inv99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (* x (fma 3.0 x (* -2.0 (pow x 2.0)))))
double code(double x) {
return x * fma(3.0, x, (-2.0 * pow(x, 2.0)));
}
function code(x) return Float64(x * fma(3.0, x, Float64(-2.0 * (x ^ 2.0)))) end
code[x_] := N[(x * N[(3.0 * x + N[(-2.0 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \mathsf{fma}\left(3, x, -2 \cdot {x}^{2}\right)
\end{array}
Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
flip--99.8%
*-commutative99.8%
metadata-eval99.8%
cancel-sign-sub-inv99.8%
*-commutative99.8%
associate-*r/99.8%
Applied egg-rr51.7%
associate-/l*51.7%
Simplified51.7%
Taylor expanded in x around 0 99.8%
+-commutative99.8%
fma-def99.8%
*-commutative99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (if (<= x 1.5) (* x (* x 3.0)) (* x (* x -3.0))))
double code(double x) {
double tmp;
if (x <= 1.5) {
tmp = x * (x * 3.0);
} else {
tmp = x * (x * -3.0);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.5d0) then
tmp = x * (x * 3.0d0)
else
tmp = x * (x * (-3.0d0))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.5) {
tmp = x * (x * 3.0);
} else {
tmp = x * (x * -3.0);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.5: tmp = x * (x * 3.0) else: tmp = x * (x * -3.0) return tmp
function code(x) tmp = 0.0 if (x <= 1.5) tmp = Float64(x * Float64(x * 3.0)); else tmp = Float64(x * Float64(x * -3.0)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.5) tmp = x * (x * 3.0); else tmp = x * (x * -3.0); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.5], N[(x * N[(x * 3.0), $MachinePrecision]), $MachinePrecision], N[(x * N[(x * -3.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.5:\\
\;\;\;\;x \cdot \left(x \cdot 3\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(x \cdot -3\right)\\
\end{array}
\end{array}
if x < 1.5Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 83.1%
if 1.5 < x Initial program 99.9%
associate-*l*99.9%
Simplified99.9%
flip--99.9%
*-commutative99.9%
metadata-eval99.9%
cancel-sign-sub-inv99.9%
*-commutative99.9%
associate-*r/99.9%
Applied egg-rr0.2%
associate-/l*0.2%
Simplified0.2%
Taylor expanded in x around 0 0.2%
clear-num0.2%
un-div-inv0.2%
Applied egg-rr0.2%
frac-2neg0.2%
metadata-eval0.2%
associate-/l*0.2%
*-commutative0.2%
div-inv0.2%
*-commutative0.2%
associate-*l*0.2%
add-sqr-sqrt0.0%
sqrt-unprod50.9%
sqr-neg50.9%
sqrt-prod50.9%
add-sqr-sqrt50.9%
metadata-eval50.9%
Applied egg-rr50.9%
Final simplification75.1%
(FPCore (x) :precision binary64 (* x (* x (- 3.0 (* x 2.0)))))
double code(double x) {
return x * (x * (3.0 - (x * 2.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (x * (3.0d0 - (x * 2.0d0)))
end function
public static double code(double x) {
return x * (x * (3.0 - (x * 2.0)));
}
def code(x): return x * (x * (3.0 - (x * 2.0)))
function code(x) return Float64(x * Float64(x * Float64(3.0 - Float64(x * 2.0)))) end
function tmp = code(x) tmp = x * (x * (3.0 - (x * 2.0))); end
code[x_] := N[(x * N[(x * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot \left(3 - x \cdot 2\right)\right)
\end{array}
Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (* x (* x 3.0)))
double code(double x) {
return x * (x * 3.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (x * 3.0d0)
end function
public static double code(double x) {
return x * (x * 3.0);
}
def code(x): return x * (x * 3.0)
function code(x) return Float64(x * Float64(x * 3.0)) end
function tmp = code(x) tmp = x * (x * 3.0); end
code[x_] := N[(x * N[(x * 3.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot 3\right)
\end{array}
Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 62.4%
Final simplification62.4%
(FPCore (x) :precision binary64 (* x (* x (- 3.0 (* x 2.0)))))
double code(double x) {
return x * (x * (3.0 - (x * 2.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (x * (3.0d0 - (x * 2.0d0)))
end function
public static double code(double x) {
return x * (x * (3.0 - (x * 2.0)));
}
def code(x): return x * (x * (3.0 - (x * 2.0)))
function code(x) return Float64(x * Float64(x * Float64(3.0 - Float64(x * 2.0)))) end
function tmp = code(x) tmp = x * (x * (3.0 - (x * 2.0))); end
code[x_] := N[(x * N[(x * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot \left(3 - x \cdot 2\right)\right)
\end{array}
herbie shell --seed 2024029
(FPCore (x)
:name "Data.Spline.Key:interpolateKeys from smoothie-0.4.0.2"
:precision binary64
:herbie-target
(* x (* x (- 3.0 (* x 2.0))))
(* (* x x) (- 3.0 (* x 2.0))))