Average Error: 0.1 → 0.1
Time: 6.2s
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
Error13.7
Cost1112
\[\begin{array}{l} t_0 := y \cdot \left(y \cdot 3\right)\\ \mathbf{if}\;y \leq -15.43664985419118:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq -2.855288375131428 \cdot 10^{-15}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;y \leq -3.3891342064542596 \cdot 10^{-50}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 1.564277923305058 \cdot 10^{-129}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;y \leq 3.2669195610963446 \cdot 10^{-109}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2.7644074140531417 \cdot 10^{-54}:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error11.8
Cost976
\[\begin{array}{l} t_0 := y \cdot y + x \cdot x\\ t_1 := y \cdot \left(y \cdot 3\right)\\ \mathbf{if}\;x \leq -4.562478904418842 \cdot 10^{-46}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.4550457831148832 \cdot 10^{-63}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -7.926035253336066 \cdot 10^{-95}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 1.3222745975240562 \cdot 10^{-27}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error0.1
Cost576
\[x \cdot x + \left(y \cdot y\right) \cdot 3 \]
Alternative 4
Error0.1
Cost576
\[y \cdot \left(y \cdot 3\right) + x \cdot x \]
Alternative 5
Error26.0
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1.736526203875494 \cdot 10^{-126}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 4.0227748524334796 \cdot 10^{-166}:\\ \;\;\;\;y \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 6
Error50.6
Cost192
\[y \cdot y \]

Error

Reproduce

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