?

Average Error: 0.1 → 0.1
Time: 1.3min
Precision: binary64
Cost: 6848

?

\[\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y \]
\[\mathsf{fma}\left(x, x, y \cdot \left(3 \cdot y\right)\right) \]
(FPCore (x y) :precision binary64 (+ (+ (+ (* x x) (* y y)) (* y y)) (* y y)))
(FPCore (x y) :precision binary64 (fma x x (* y (* 3.0 y))))
double code(double x, double y) {
	return (((x * x) + (y * y)) + (y * y)) + (y * y);
}
double code(double x, double y) {
	return fma(x, x, (y * (3.0 * y)));
}
function code(x, y)
	return Float64(Float64(Float64(Float64(x * x) + Float64(y * y)) + Float64(y * y)) + Float64(y * y))
end
function code(x, y)
	return fma(x, x, Float64(y * Float64(3.0 * y)))
end
code[x_, y_] := N[(N[(N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[(x * x + N[(y * N[(3.0 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y
\mathsf{fma}\left(x, x, y \cdot \left(3 \cdot y\right)\right)

Error?

Target

Original0.1
Target0.1
Herbie0.1
\[x \cdot x + y \cdot \left(y + \left(y + y\right)\right) \]

Derivation?

  1. Initial program 0.1

    \[\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y \]
  2. Simplified0.1

    \[\leadsto \color{blue}{{x}^{2} + {y}^{2} \cdot 3} \]
    Proof
  3. Applied egg-rr0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, y \cdot \left(3 \cdot y\right)\right)} \]

Alternatives

Alternative 1
Error0.1
Cost960
\[\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y \]
Alternative 2
Error12.4
Cost584
\[\begin{array}{l} t_0 := 3 \cdot \left(y \cdot y\right)\\ \mathbf{if}\;y \leq -2.1 \cdot 10^{-87}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 3.2 \cdot 10^{-46}:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error12.4
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -1.98 \cdot 10^{-87}:\\ \;\;\;\;3 \cdot \left(y \cdot y\right)\\ \mathbf{elif}\;y \leq 4.6 \cdot 10^{-45}:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(3 \cdot y\right) \cdot y\\ \end{array} \]
Alternative 4
Error27.7
Cost192
\[x \cdot x \]

Error

Reproduce?

herbie shell --seed 2023033 
(FPCore (x y)
  :name "Linear.Quaternion:$c/ from linear-1.19.1.3, E"
  :precision binary64

  :herbie-target
  (+ (* x x) (* y (+ y (+ y y))))

  (+ (+ (+ (* x x) (* y y)) (* y y)) (* y y)))