
(FPCore (x y) :precision binary64 (- (* 9.0 (pow x 4.0)) (* (* y y) (- (* y y) 2.0))))
double code(double x, double y) {
return (9.0 * pow(x, 4.0)) - ((y * y) * ((y * y) - 2.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (9.0d0 * (x ** 4.0d0)) - ((y * y) * ((y * y) - 2.0d0))
end function
public static double code(double x, double y) {
return (9.0 * Math.pow(x, 4.0)) - ((y * y) * ((y * y) - 2.0));
}
def code(x, y): return (9.0 * math.pow(x, 4.0)) - ((y * y) * ((y * y) - 2.0))
function code(x, y) return Float64(Float64(9.0 * (x ^ 4.0)) - Float64(Float64(y * y) * Float64(Float64(y * y) - 2.0))) end
function tmp = code(x, y) tmp = (9.0 * (x ^ 4.0)) - ((y * y) * ((y * y) - 2.0)); end
code[x_, y_] := N[(N[(9.0 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] - N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
9 \cdot {x}^{4} - \left(y \cdot y\right) \cdot \left(y \cdot y - 2\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 2 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- (* 9.0 (pow x 4.0)) (* (* y y) (- (* y y) 2.0))))
double code(double x, double y) {
return (9.0 * pow(x, 4.0)) - ((y * y) * ((y * y) - 2.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (9.0d0 * (x ** 4.0d0)) - ((y * y) * ((y * y) - 2.0d0))
end function
public static double code(double x, double y) {
return (9.0 * Math.pow(x, 4.0)) - ((y * y) * ((y * y) - 2.0));
}
def code(x, y): return (9.0 * math.pow(x, 4.0)) - ((y * y) * ((y * y) - 2.0))
function code(x, y) return Float64(Float64(9.0 * (x ^ 4.0)) - Float64(Float64(y * y) * Float64(Float64(y * y) - 2.0))) end
function tmp = code(x, y) tmp = (9.0 * (x ^ 4.0)) - ((y * y) * ((y * y) - 2.0)); end
code[x_, y_] := N[(N[(9.0 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] - N[(N[(y * y), $MachinePrecision] * N[(N[(y * y), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
9 \cdot {x}^{4} - \left(y \cdot y\right) \cdot \left(y \cdot y - 2\right)
\end{array}
(FPCore (x y) :precision binary64 (fma (fma (- y) y 2.0) (* y y) (* (* (* x x) (* x x)) 9.0)))
double code(double x, double y) {
return fma(fma(-y, y, 2.0), (y * y), (((x * x) * (x * x)) * 9.0));
}
function code(x, y) return fma(fma(Float64(-y), y, 2.0), Float64(y * y), Float64(Float64(Float64(x * x) * Float64(x * x)) * 9.0)) end
code[x_, y_] := N[(N[((-y) * y + 2.0), $MachinePrecision] * N[(y * y), $MachinePrecision] + N[(N[(N[(x * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision] * 9.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(-y, y, 2\right), y \cdot y, \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot 9\right)
\end{array}
Initial program 3.1%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lift--.f64N/A
sub-negN/A
distribute-neg-inN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f64N/A
lower-neg.f64100.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
lift-pow.f64N/A
metadata-evalN/A
pow-powN/A
pow2N/A
lift-*.f64N/A
pow2N/A
lower-*.f64100.0
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (* (* y y) 2.0))
double code(double x, double y) {
return (y * y) * 2.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y * y) * 2.0d0
end function
public static double code(double x, double y) {
return (y * y) * 2.0;
}
def code(x, y): return (y * y) * 2.0
function code(x, y) return Float64(Float64(y * y) * 2.0) end
function tmp = code(x, y) tmp = (y * y) * 2.0; end
code[x_, y_] := N[(N[(y * y), $MachinePrecision] * 2.0), $MachinePrecision]
\begin{array}{l}
\\
\left(y \cdot y\right) \cdot 2
\end{array}
Initial program 3.1%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
metadata-evalN/A
associate-*r*N/A
lower-fma.f64N/A
lower-pow.f64N/A
associate-*r*N/A
metadata-evalN/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f649.6
Applied rewrites9.6%
Taylor expanded in x around 0
Applied rewrites11.1%
herbie shell --seed 2024314
(FPCore (x y)
:name "From Rump in a 1983 paper, rewritten"
:precision binary64
:pre (and (== x 10864.0) (== y 18817.0))
(- (* 9.0 (pow x 4.0)) (* (* y y) (- (* y y) 2.0))))