
(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 4 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 (/ x (/ 1.0 (* (fma -2.0 x 3.0) x))))
double code(double x) {
return x / (1.0 / (fma(-2.0, x, 3.0) * x));
}
function code(x) return Float64(x / Float64(1.0 / Float64(fma(-2.0, x, 3.0) * x))) end
code[x_] := N[(x / N[(1.0 / N[(N[(-2.0 * x + 3.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{\frac{1}{\mathsf{fma}\left(-2, x, 3\right) \cdot x}}
\end{array}
Initial program 99.8%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift--.f64N/A
flip--N/A
associate-*r/N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
clear-numN/A
associate-*r/N/A
flip--N/A
lift--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
(FPCore (x) :precision binary64 (let* ((t_0 (* (- 3.0 (* 2.0 x)) (* x x))) (t_1 (* (* -2.0 x) (* x x)))) (if (<= t_0 -1e+17) t_1 (if (<= t_0 1e-6) (* (* 3.0 x) x) t_1))))
double code(double x) {
double t_0 = (3.0 - (2.0 * x)) * (x * x);
double t_1 = (-2.0 * x) * (x * x);
double tmp;
if (t_0 <= -1e+17) {
tmp = t_1;
} else if (t_0 <= 1e-6) {
tmp = (3.0 * x) * x;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (3.0d0 - (2.0d0 * x)) * (x * x)
t_1 = ((-2.0d0) * x) * (x * x)
if (t_0 <= (-1d+17)) then
tmp = t_1
else if (t_0 <= 1d-6) then
tmp = (3.0d0 * x) * x
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x) {
double t_0 = (3.0 - (2.0 * x)) * (x * x);
double t_1 = (-2.0 * x) * (x * x);
double tmp;
if (t_0 <= -1e+17) {
tmp = t_1;
} else if (t_0 <= 1e-6) {
tmp = (3.0 * x) * x;
} else {
tmp = t_1;
}
return tmp;
}
def code(x): t_0 = (3.0 - (2.0 * x)) * (x * x) t_1 = (-2.0 * x) * (x * x) tmp = 0 if t_0 <= -1e+17: tmp = t_1 elif t_0 <= 1e-6: tmp = (3.0 * x) * x else: tmp = t_1 return tmp
function code(x) t_0 = Float64(Float64(3.0 - Float64(2.0 * x)) * Float64(x * x)) t_1 = Float64(Float64(-2.0 * x) * Float64(x * x)) tmp = 0.0 if (t_0 <= -1e+17) tmp = t_1; elseif (t_0 <= 1e-6) tmp = Float64(Float64(3.0 * x) * x); else tmp = t_1; end return tmp end
function tmp_2 = code(x) t_0 = (3.0 - (2.0 * x)) * (x * x); t_1 = (-2.0 * x) * (x * x); tmp = 0.0; if (t_0 <= -1e+17) tmp = t_1; elseif (t_0 <= 1e-6) tmp = (3.0 * x) * x; else tmp = t_1; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[(3.0 - N[(2.0 * x), $MachinePrecision]), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(-2.0 * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+17], t$95$1, If[LessEqual[t$95$0, 1e-6], N[(N[(3.0 * x), $MachinePrecision] * x), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(3 - 2 \cdot x\right) \cdot \left(x \cdot x\right)\\
t_1 := \left(-2 \cdot x\right) \cdot \left(x \cdot x\right)\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{+17}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 10^{-6}:\\
\;\;\;\;\left(3 \cdot x\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) < -1e17 or 9.99999999999999955e-7 < (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) Initial program 99.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f6497.3
Applied rewrites97.3%
if -1e17 < (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) < 9.99999999999999955e-7Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
metadata-evalN/A
lft-mult-inverseN/A
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites97.7%
Final simplification97.5%
(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 2024230
(FPCore (x)
:name "Data.Spline.Key:interpolateKeys from smoothie-0.4.0.2"
:precision binary64
:alt
(! :herbie-platform default (* x (* x (- 3 (* x 2)))))
(* (* x x) (- 3.0 (* x 2.0))))