
(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 (fma x 3.0 (* x (* x -2.0)))))
double code(double x) {
return x * fma(x, 3.0, (x * (x * -2.0)));
}
function code(x) return Float64(x * fma(x, 3.0, Float64(x * Float64(x * -2.0)))) end
code[x_] := N[(x * N[(x * 3.0 + N[(x * N[(x * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \mathsf{fma}\left(x, 3, x \cdot \left(x \cdot -2\right)\right)
\end{array}
Initial program 99.8%
lift-*.f64N/A
lift--.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6499.8
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
metadata-eval99.8
Applied rewrites99.8%
lift-*.f64N/A
+-commutativeN/A
distribute-lft-inN/A
lift-*.f64N/A
lower-fma.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x) :precision binary64 (let* ((t_0 (* (* x x) (- 3.0 (* x 2.0)))) (t_1 (* (* x x) (* x -2.0)))) (if (<= t_0 -20000.0) t_1 (if (<= t_0 4e-6) (* x (* x 3.0)) t_1))))
double code(double x) {
double t_0 = (x * x) * (3.0 - (x * 2.0));
double t_1 = (x * x) * (x * -2.0);
double tmp;
if (t_0 <= -20000.0) {
tmp = t_1;
} else if (t_0 <= 4e-6) {
tmp = x * (x * 3.0);
} 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 = (x * x) * (3.0d0 - (x * 2.0d0))
t_1 = (x * x) * (x * (-2.0d0))
if (t_0 <= (-20000.0d0)) then
tmp = t_1
else if (t_0 <= 4d-6) then
tmp = x * (x * 3.0d0)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x) {
double t_0 = (x * x) * (3.0 - (x * 2.0));
double t_1 = (x * x) * (x * -2.0);
double tmp;
if (t_0 <= -20000.0) {
tmp = t_1;
} else if (t_0 <= 4e-6) {
tmp = x * (x * 3.0);
} else {
tmp = t_1;
}
return tmp;
}
def code(x): t_0 = (x * x) * (3.0 - (x * 2.0)) t_1 = (x * x) * (x * -2.0) tmp = 0 if t_0 <= -20000.0: tmp = t_1 elif t_0 <= 4e-6: tmp = x * (x * 3.0) else: tmp = t_1 return tmp
function code(x) t_0 = Float64(Float64(x * x) * Float64(3.0 - Float64(x * 2.0))) t_1 = Float64(Float64(x * x) * Float64(x * -2.0)) tmp = 0.0 if (t_0 <= -20000.0) tmp = t_1; elseif (t_0 <= 4e-6) tmp = Float64(x * Float64(x * 3.0)); else tmp = t_1; end return tmp end
function tmp_2 = code(x) t_0 = (x * x) * (3.0 - (x * 2.0)); t_1 = (x * x) * (x * -2.0); tmp = 0.0; if (t_0 <= -20000.0) tmp = t_1; elseif (t_0 <= 4e-6) tmp = x * (x * 3.0); else tmp = t_1; end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(N[(x * x), $MachinePrecision] * N[(3.0 - N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] * N[(x * -2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -20000.0], t$95$1, If[LessEqual[t$95$0, 4e-6], N[(x * N[(x * 3.0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot x\right) \cdot \left(3 - x \cdot 2\right)\\
t_1 := \left(x \cdot x\right) \cdot \left(x \cdot -2\right)\\
\mathbf{if}\;t\_0 \leq -20000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{-6}:\\
\;\;\;\;x \cdot \left(x \cdot 3\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) < -2e4 or 3.99999999999999982e-6 < (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) Initial program 99.8%
Taylor expanded in x around inf
lower-*.f6497.0
Applied rewrites97.0%
if -2e4 < (*.f64 (*.f64 x x) (-.f64 #s(literal 3 binary64) (*.f64 x #s(literal 2 binary64)))) < 3.99999999999999982e-6Initial program 99.8%
Taylor expanded in x around 0
metadata-evalN/A
lft-mult-inverseN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
unpow2N/A
associate-*r*N/A
remove-double-negN/A
distribute-lft-neg-outN/A
*-commutativeN/A
distribute-lft-neg-outN/A
mul-1-negN/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
associate-*r*N/A
Applied rewrites97.9%
Final simplification97.5%
(FPCore (x) :precision binary64 (* x (* x (fma x -2.0 3.0))))
double code(double x) {
return x * (x * fma(x, -2.0, 3.0));
}
function code(x) return Float64(x * Float64(x * fma(x, -2.0, 3.0))) end
code[x_] := N[(x * N[(x * N[(x * -2.0 + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot \mathsf{fma}\left(x, -2, 3\right)\right)
\end{array}
Initial program 99.8%
lift-*.f64N/A
lift--.f64N/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6499.8
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-rgt-neg-inN/A
lower-fma.f64N/A
metadata-eval99.8
Applied rewrites99.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%
Taylor expanded in x around 0
metadata-evalN/A
lft-mult-inverseN/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
lower-*.f64N/A
unpow2N/A
associate-*r*N/A
remove-double-negN/A
distribute-lft-neg-outN/A
*-commutativeN/A
distribute-lft-neg-outN/A
mul-1-negN/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
associate-*r*N/A
Applied rewrites61.8%
(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 2024219
(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))))