
(FPCore (x y) :precision binary64 (+ (- (* 9.0 (pow x 4.0)) (pow y 4.0)) (* 2.0 (* y y))))
double code(double x, double y) {
return ((9.0 * pow(x, 4.0)) - pow(y, 4.0)) + (2.0 * (y * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((9.0d0 * (x ** 4.0d0)) - (y ** 4.0d0)) + (2.0d0 * (y * y))
end function
public static double code(double x, double y) {
return ((9.0 * Math.pow(x, 4.0)) - Math.pow(y, 4.0)) + (2.0 * (y * y));
}
def code(x, y): return ((9.0 * math.pow(x, 4.0)) - math.pow(y, 4.0)) + (2.0 * (y * y))
function code(x, y) return Float64(Float64(Float64(9.0 * (x ^ 4.0)) - (y ^ 4.0)) + Float64(2.0 * Float64(y * y))) end
function tmp = code(x, y) tmp = ((9.0 * (x ^ 4.0)) - (y ^ 4.0)) + (2.0 * (y * y)); end
code[x_, y_] := N[(N[(N[(9.0 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] - N[Power[y, 4.0], $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(9 \cdot {x}^{4} - {y}^{4}\right) + 2 \cdot \left(y \cdot y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ (- (* 9.0 (pow x 4.0)) (pow y 4.0)) (* 2.0 (* y y))))
double code(double x, double y) {
return ((9.0 * pow(x, 4.0)) - pow(y, 4.0)) + (2.0 * (y * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((9.0d0 * (x ** 4.0d0)) - (y ** 4.0d0)) + (2.0d0 * (y * y))
end function
public static double code(double x, double y) {
return ((9.0 * Math.pow(x, 4.0)) - Math.pow(y, 4.0)) + (2.0 * (y * y));
}
def code(x, y): return ((9.0 * math.pow(x, 4.0)) - math.pow(y, 4.0)) + (2.0 * (y * y))
function code(x, y) return Float64(Float64(Float64(9.0 * (x ^ 4.0)) - (y ^ 4.0)) + Float64(2.0 * Float64(y * y))) end
function tmp = code(x, y) tmp = ((9.0 * (x ^ 4.0)) - (y ^ 4.0)) + (2.0 * (y * y)); end
code[x_, y_] := N[(N[(N[(9.0 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] - N[Power[y, 4.0], $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(9 \cdot {x}^{4} - {y}^{4}\right) + 2 \cdot \left(y \cdot y\right)
\end{array}
(FPCore (x y) :precision binary64 (fma (- 2.0 (* y y)) (* y y) (* (* x x) (* 9.0 (* x x)))))
double code(double x, double y) {
return fma((2.0 - (y * y)), (y * y), ((x * x) * (9.0 * (x * x))));
}
function code(x, y) return fma(Float64(2.0 - Float64(y * y)), Float64(y * y), Float64(Float64(x * x) * Float64(9.0 * Float64(x * x)))) end
code[x_, y_] := N[(N[(2.0 - N[(y * y), $MachinePrecision]), $MachinePrecision] * N[(y * y), $MachinePrecision] + N[(N[(x * x), $MachinePrecision] * N[(9.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(2 - y \cdot y, y \cdot y, \left(x \cdot x\right) \cdot \left(9 \cdot \left(x \cdot x\right)\right)\right)
\end{array}
Initial program 18.8%
sub-negN/A
+-commutativeN/A
metadata-evalN/A
pow-sqrN/A
pow-prod-downN/A
pow2N/A
distribute-lft-neg-inN/A
fma-defineN/A
fma-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
sqr-powN/A
associate-*l*N/A
metadata-evalN/A
unpow2N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
metadata-evalN/A
unpow2N/A
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f64100.0%
Applied egg-rr100.0%
+-commutativeN/A
sub0-negN/A
cancel-sign-sub-invN/A
associate-*r*N/A
+-commutativeN/A
sub-negN/A
+-commutativeN/A
associate-+r+N/A
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y y)))
(t_1 (* y t_0))
(t_2 (* (* x x) (* 9.0 (* x x))))
(t_3 (* x (* x (* x x)))))
(/
(+ (* t_1 4.0) (* (- t_2 t_1) (- t_1 t_2)))
(+
(* 2.0 (* y y))
(/ (- (* y (* t_0 t_1)) (* 81.0 (* t_3 t_3))) (+ t_1 (* 9.0 t_3)))))))
double code(double x, double y) {
double t_0 = y * (y * y);
double t_1 = y * t_0;
double t_2 = (x * x) * (9.0 * (x * x));
double t_3 = x * (x * (x * x));
return ((t_1 * 4.0) + ((t_2 - t_1) * (t_1 - t_2))) / ((2.0 * (y * y)) + (((y * (t_0 * t_1)) - (81.0 * (t_3 * t_3))) / (t_1 + (9.0 * t_3))));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: t_3
t_0 = y * (y * y)
t_1 = y * t_0
t_2 = (x * x) * (9.0d0 * (x * x))
t_3 = x * (x * (x * x))
code = ((t_1 * 4.0d0) + ((t_2 - t_1) * (t_1 - t_2))) / ((2.0d0 * (y * y)) + (((y * (t_0 * t_1)) - (81.0d0 * (t_3 * t_3))) / (t_1 + (9.0d0 * t_3))))
end function
public static double code(double x, double y) {
double t_0 = y * (y * y);
double t_1 = y * t_0;
double t_2 = (x * x) * (9.0 * (x * x));
double t_3 = x * (x * (x * x));
return ((t_1 * 4.0) + ((t_2 - t_1) * (t_1 - t_2))) / ((2.0 * (y * y)) + (((y * (t_0 * t_1)) - (81.0 * (t_3 * t_3))) / (t_1 + (9.0 * t_3))));
}
def code(x, y): t_0 = y * (y * y) t_1 = y * t_0 t_2 = (x * x) * (9.0 * (x * x)) t_3 = x * (x * (x * x)) return ((t_1 * 4.0) + ((t_2 - t_1) * (t_1 - t_2))) / ((2.0 * (y * y)) + (((y * (t_0 * t_1)) - (81.0 * (t_3 * t_3))) / (t_1 + (9.0 * t_3))))
function code(x, y) t_0 = Float64(y * Float64(y * y)) t_1 = Float64(y * t_0) t_2 = Float64(Float64(x * x) * Float64(9.0 * Float64(x * x))) t_3 = Float64(x * Float64(x * Float64(x * x))) return Float64(Float64(Float64(t_1 * 4.0) + Float64(Float64(t_2 - t_1) * Float64(t_1 - t_2))) / Float64(Float64(2.0 * Float64(y * y)) + Float64(Float64(Float64(y * Float64(t_0 * t_1)) - Float64(81.0 * Float64(t_3 * t_3))) / Float64(t_1 + Float64(9.0 * t_3))))) end
function tmp = code(x, y) t_0 = y * (y * y); t_1 = y * t_0; t_2 = (x * x) * (9.0 * (x * x)); t_3 = x * (x * (x * x)); tmp = ((t_1 * 4.0) + ((t_2 - t_1) * (t_1 - t_2))) / ((2.0 * (y * y)) + (((y * (t_0 * t_1)) - (81.0 * (t_3 * t_3))) / (t_1 + (9.0 * t_3)))); end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y * t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * x), $MachinePrecision] * N[(9.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(x * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[(t$95$1 * 4.0), $MachinePrecision] + N[(N[(t$95$2 - t$95$1), $MachinePrecision] * N[(t$95$1 - t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(2.0 * N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(y * N[(t$95$0 * t$95$1), $MachinePrecision]), $MachinePrecision] - N[(81.0 * N[(t$95$3 * t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$1 + N[(9.0 * t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot y\right)\\
t_1 := y \cdot t\_0\\
t_2 := \left(x \cdot x\right) \cdot \left(9 \cdot \left(x \cdot x\right)\right)\\
t_3 := x \cdot \left(x \cdot \left(x \cdot x\right)\right)\\
\frac{t\_1 \cdot 4 + \left(t\_2 - t\_1\right) \cdot \left(t\_1 - t\_2\right)}{2 \cdot \left(y \cdot y\right) + \frac{y \cdot \left(t\_0 \cdot t\_1\right) - 81 \cdot \left(t\_3 \cdot t\_3\right)}{t\_1 + 9 \cdot t\_3}}
\end{array}
\end{array}
Initial program 18.8%
sub-negN/A
+-commutativeN/A
metadata-evalN/A
pow-sqrN/A
pow-prod-downN/A
pow2N/A
distribute-lft-neg-inN/A
fma-defineN/A
fma-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
sqr-powN/A
associate-*l*N/A
metadata-evalN/A
unpow2N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
metadata-evalN/A
unpow2N/A
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f64100.0%
Applied egg-rr100.0%
+-commutativeN/A
flip-+N/A
+-commutativeN/A
sub0-negN/A
cancel-sign-sub-invN/A
associate-*r*N/A
Applied egg-rr18.8%
flip--N/A
/-lowering-/.f64N/A
Applied egg-rr18.8%
Final simplification18.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* y (* y (* y y))))
(t_1 (* (* x x) (* 9.0 (* x x))))
(t_2 (- t_0 t_1)))
(/ (+ (* t_0 4.0) (* (- t_1 t_0) t_2)) (+ (* 2.0 (* y y)) t_2))))
double code(double x, double y) {
double t_0 = y * (y * (y * y));
double t_1 = (x * x) * (9.0 * (x * x));
double t_2 = t_0 - t_1;
return ((t_0 * 4.0) + ((t_1 - t_0) * t_2)) / ((2.0 * (y * y)) + t_2);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
t_0 = y * (y * (y * y))
t_1 = (x * x) * (9.0d0 * (x * x))
t_2 = t_0 - t_1
code = ((t_0 * 4.0d0) + ((t_1 - t_0) * t_2)) / ((2.0d0 * (y * y)) + t_2)
end function
public static double code(double x, double y) {
double t_0 = y * (y * (y * y));
double t_1 = (x * x) * (9.0 * (x * x));
double t_2 = t_0 - t_1;
return ((t_0 * 4.0) + ((t_1 - t_0) * t_2)) / ((2.0 * (y * y)) + t_2);
}
def code(x, y): t_0 = y * (y * (y * y)) t_1 = (x * x) * (9.0 * (x * x)) t_2 = t_0 - t_1 return ((t_0 * 4.0) + ((t_1 - t_0) * t_2)) / ((2.0 * (y * y)) + t_2)
function code(x, y) t_0 = Float64(y * Float64(y * Float64(y * y))) t_1 = Float64(Float64(x * x) * Float64(9.0 * Float64(x * x))) t_2 = Float64(t_0 - t_1) return Float64(Float64(Float64(t_0 * 4.0) + Float64(Float64(t_1 - t_0) * t_2)) / Float64(Float64(2.0 * Float64(y * y)) + t_2)) end
function tmp = code(x, y) t_0 = y * (y * (y * y)); t_1 = (x * x) * (9.0 * (x * x)); t_2 = t_0 - t_1; tmp = ((t_0 * 4.0) + ((t_1 - t_0) * t_2)) / ((2.0 * (y * y)) + t_2); end
code[x_, y_] := Block[{t$95$0 = N[(y * N[(y * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] * N[(9.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 - t$95$1), $MachinePrecision]}, N[(N[(N[(t$95$0 * 4.0), $MachinePrecision] + N[(N[(t$95$1 - t$95$0), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision] / N[(N[(2.0 * N[(y * y), $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(y \cdot \left(y \cdot y\right)\right)\\
t_1 := \left(x \cdot x\right) \cdot \left(9 \cdot \left(x \cdot x\right)\right)\\
t_2 := t\_0 - t\_1\\
\frac{t\_0 \cdot 4 + \left(t\_1 - t\_0\right) \cdot t\_2}{2 \cdot \left(y \cdot y\right) + t\_2}
\end{array}
\end{array}
Initial program 18.8%
sub-negN/A
+-commutativeN/A
metadata-evalN/A
pow-sqrN/A
pow-prod-downN/A
pow2N/A
distribute-lft-neg-inN/A
fma-defineN/A
fma-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
sqr-powN/A
associate-*l*N/A
metadata-evalN/A
unpow2N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
metadata-evalN/A
unpow2N/A
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f64100.0%
Applied egg-rr100.0%
+-commutativeN/A
flip-+N/A
+-commutativeN/A
sub0-negN/A
cancel-sign-sub-invN/A
associate-*r*N/A
Applied egg-rr18.8%
Final simplification18.8%
(FPCore (x y) :precision binary64 (- (- (* x (* x (* x (* 9.0 x)))) (* y (* y (* y y)))) (* (* y y) -2.0)))
double code(double x, double y) {
return ((x * (x * (x * (9.0 * x)))) - (y * (y * (y * y)))) - ((y * y) * -2.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * (x * (x * (9.0d0 * x)))) - (y * (y * (y * y)))) - ((y * y) * (-2.0d0))
end function
public static double code(double x, double y) {
return ((x * (x * (x * (9.0 * x)))) - (y * (y * (y * y)))) - ((y * y) * -2.0);
}
def code(x, y): return ((x * (x * (x * (9.0 * x)))) - (y * (y * (y * y)))) - ((y * y) * -2.0)
function code(x, y) return Float64(Float64(Float64(x * Float64(x * Float64(x * Float64(9.0 * x)))) - Float64(y * Float64(y * Float64(y * y)))) - Float64(Float64(y * y) * -2.0)) end
function tmp = code(x, y) tmp = ((x * (x * (x * (9.0 * x)))) - (y * (y * (y * y)))) - ((y * y) * -2.0); end
code[x_, y_] := N[(N[(N[(x * N[(x * N[(x * N[(9.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(y * N[(y * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(y * y), $MachinePrecision] * -2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot \left(x \cdot \left(x \cdot \left(9 \cdot x\right)\right)\right) - y \cdot \left(y \cdot \left(y \cdot y\right)\right)\right) - \left(y \cdot y\right) \cdot -2
\end{array}
Initial program 18.8%
associate-+l-N/A
sub-negN/A
associate--r+N/A
--lowering--.f64N/A
Applied egg-rr18.8%
Final simplification18.8%
(FPCore (x y) :precision binary64 (* y (* 2.0 y)))
double code(double x, double y) {
return y * (2.0 * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y * (2.0d0 * y)
end function
public static double code(double x, double y) {
return y * (2.0 * y);
}
def code(x, y): return y * (2.0 * y)
function code(x, y) return Float64(y * Float64(2.0 * y)) end
function tmp = code(x, y) tmp = y * (2.0 * y); end
code[x_, y_] := N[(y * N[(2.0 * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(2 \cdot y\right)
\end{array}
Initial program 18.8%
Taylor expanded in x around 0
metadata-evalN/A
pow-sqrN/A
distribute-rgt-out--N/A
unsub-negN/A
mul-1-negN/A
metadata-evalN/A
lft-mult-inverseN/A
associate-*l*N/A
distribute-rgt-inN/A
metadata-evalN/A
sub-negN/A
associate-*l*N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
*-lowering-*.f64N/A
Simplified1.5%
Taylor expanded in y around 0
Simplified11.1%
Final simplification11.1%
herbie shell --seed 2024148
(FPCore (x y)
:name "From Rump in a 1983 paper"
:precision binary64
:pre (and (== x 10864.0) (== y 18817.0))
(+ (- (* 9.0 (pow x 4.0)) (pow y 4.0)) (* 2.0 (* y y))))