
(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 3.0 x (* (pow x 2.0) -2.0))))
double code(double x) {
return x * fma(3.0, x, (pow(x, 2.0) * -2.0));
}
function code(x) return Float64(x * fma(3.0, x, Float64((x ^ 2.0) * -2.0))) end
code[x_] := N[(x * N[(3.0 * x + N[(N[Power[x, 2.0], $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \mathsf{fma}\left(3, x, {x}^{2} \cdot -2\right)
\end{array}
Initial program 99.8%
associate-*l*99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
+-commutative99.8%
fma-define99.9%
*-commutative99.9%
Simplified99.9%
Final simplification99.9%
(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 61.8%
Final simplification61.8%
(FPCore (x) :precision binary64 (* x 4.5))
double code(double x) {
return x * 4.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * 4.5d0
end function
public static double code(double x) {
return x * 4.5;
}
def code(x): return x * 4.5
function code(x) return Float64(x * 4.5) end
function tmp = code(x) tmp = x * 4.5; end
code[x_] := N[(x * 4.5), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 4.5
\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-rr46.8%
*-commutative46.8%
associate-/l*46.8%
Simplified46.8%
associate-*r*46.8%
associate-*r/46.8%
+-commutative46.8%
fma-define46.8%
Applied egg-rr46.8%
Taylor expanded in x around 0 46.9%
*-commutative46.9%
Simplified46.9%
Taylor expanded in x around inf 3.0%
*-commutative3.0%
Simplified3.0%
Final simplification3.0%
(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 2024044
(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))))