Average Error: 0.1 → 0.2
Time: 2.9s
Precision: 64
\[\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y\]
\[\mathsf{fma}\left(\sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}, 1 \cdot \mathsf{hypot}\left(x, \sqrt{2} \cdot y\right), y \cdot y\right)\]
\left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right) + y \cdot y
\mathsf{fma}\left(\sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}, 1 \cdot \mathsf{hypot}\left(x, \sqrt{2} \cdot y\right), y \cdot y\right)
double code(double x, double y) {
	return ((((x * x) + (y * y)) + (y * y)) + (y * y));
}
double code(double x, double y) {
	return fma(sqrt((((x * x) + (y * y)) + (y * y))), (1.0 * hypot(x, (sqrt(2.0) * y))), (y * y));
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original0.1
Target0.1
Herbie0.2
\[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. Using strategy rm
  3. Applied add-sqr-sqrt0.2

    \[\leadsto \color{blue}{\sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y} \cdot \sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}} + y \cdot y\]
  4. Applied fma-def0.2

    \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}, \sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}, y \cdot y\right)}\]
  5. Using strategy rm
  6. Applied *-un-lft-identity0.2

    \[\leadsto \mathsf{fma}\left(\sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}, \sqrt{\color{blue}{1 \cdot \left(\left(x \cdot x + y \cdot y\right) + y \cdot y\right)}}, y \cdot y\right)\]
  7. Applied sqrt-prod0.2

    \[\leadsto \mathsf{fma}\left(\sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}, \color{blue}{\sqrt{1} \cdot \sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}}, y \cdot y\right)\]
  8. Simplified0.2

    \[\leadsto \mathsf{fma}\left(\sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}, \color{blue}{1} \cdot \sqrt{\left(x \cdot x + y \cdot y\right) + y \cdot y}, y \cdot y\right)\]
  9. Simplified0.2

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

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

Reproduce

herbie shell --seed 2020079 +o rules:numerics
(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)))