Average Error: 0.1 → 0.1
Time: 7.7s
Precision: binary64
Cost: 13376
\[\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y \]
\[\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, \left(y \cdot y\right) \cdot 2\right)\right) \]
(FPCore (x y) :precision binary64 (+ (+ (+ (* x x) (* y y)) (* y y)) (* y y)))
(FPCore (x y) :precision binary64 (fma x x (fma y y (* (* y y) 2.0))))
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, fma(y, y, ((y * y) * 2.0)));
}
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, fma(y, y, Float64(Float64(y * y) * 2.0)))
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 * y + N[(N[(y * y), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y
\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, \left(y \cdot y\right) \cdot 2\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. Applied egg-rr0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, \mathsf{fma}\left(y, y, \left(y \cdot y\right) \cdot 2\right)\right)} \]
  3. Final simplification0.1

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

Alternatives

Alternative 1
Error0.1
Cost6848
\[\mathsf{fma}\left(3, y \cdot y, x \cdot x\right) \]
Alternative 2
Error14.8
Cost848
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 3\right)\\ \mathbf{if}\;x \leq -5.969033232305403 \cdot 10^{+50}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq -1.004179558203747 \cdot 10^{-52}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.984687235023785 \cdot 10^{-130}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 9.526597027225746 \cdot 10^{-60}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 3
Error14.8
Cost848
\[\begin{array}{l} \mathbf{if}\;x \leq -5.969033232305403 \cdot 10^{+50}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq -1.004179558203747 \cdot 10^{-52}:\\ \;\;\;\;\left(y \cdot y\right) \cdot 3\\ \mathbf{elif}\;x \leq -1.984687235023785 \cdot 10^{-130}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 9.526597027225746 \cdot 10^{-60}:\\ \;\;\;\;y \cdot \left(y \cdot 3\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 4
Error0.1
Cost576
\[x \cdot x + \left(y \cdot y\right) \cdot 3 \]
Alternative 5
Error27.7
Cost192
\[x \cdot x \]

Error

Reproduce

herbie shell --seed 2022294 
(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)))