Average Error: 31.3 → 0.0
Time: 16.6s
Precision: binary64
\[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
\[{\left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2} - \frac{y}{\mathsf{fma}\left(0.25, x \cdot \frac{x}{y}, y\right)} \]
(FPCore (x y)
 :precision binary64
 (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))
(FPCore (x y)
 :precision binary64
 (- (pow (/ x (hypot x (* y 2.0))) 2.0) (/ y (fma 0.25 (* x (/ x y)) y))))
double code(double x, double y) {
	return ((x * x) - ((y * 4.0) * y)) / ((x * x) + ((y * 4.0) * y));
}
double code(double x, double y) {
	return pow((x / hypot(x, (y * 2.0))), 2.0) - (y / fma(0.25, (x * (x / y)), y));
}
function code(x, y)
	return Float64(Float64(Float64(x * x) - Float64(Float64(y * 4.0) * y)) / Float64(Float64(x * x) + Float64(Float64(y * 4.0) * y)))
end
function code(x, y)
	return Float64((Float64(x / hypot(x, Float64(y * 2.0))) ^ 2.0) - Float64(y / fma(0.25, Float64(x * Float64(x / y)), y)))
end
code[x_, y_] := N[(N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] / N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[(N[Power[N[(x / N[Sqrt[x ^ 2 + N[(y * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] - N[(y / N[(0.25 * N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
{\left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2} - \frac{y}{\mathsf{fma}\left(0.25, x \cdot \frac{x}{y}, y\right)}

Error

Target

Original31.3
Target31.0
Herbie0.0
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} < 0.9743233849626781:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot y\right) \cdot 4} - \frac{\left(y \cdot y\right) \cdot 4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x}{\sqrt{x \cdot x + \left(y \cdot y\right) \cdot 4}}\right)}^{2} - \frac{\left(y \cdot y\right) \cdot 4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\\ \end{array} \]

Derivation

  1. Initial program 31.3

    \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
  2. Applied egg-rr18.7

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{\mathsf{hypot}\left(x, \sqrt{y \cdot \left(y \cdot 4\right)}\right)}, \frac{x}{\mathsf{hypot}\left(x, \sqrt{y \cdot \left(y \cdot 4\right)}\right)}, -\frac{y}{\frac{\mathsf{fma}\left(x, x, y \cdot \left(y \cdot 4\right)\right)}{y \cdot 4}}\right)} \]
  3. Taylor expanded in x around 0 7.4

    \[\leadsto \mathsf{fma}\left(\frac{x}{\mathsf{hypot}\left(x, \sqrt{y \cdot \left(y \cdot 4\right)}\right)}, \frac{x}{\mathsf{hypot}\left(x, \sqrt{y \cdot \left(y \cdot 4\right)}\right)}, -\frac{y}{\color{blue}{0.25 \cdot \frac{{x}^{2}}{y} + y}}\right) \]
  4. Simplified3.8

    \[\leadsto \mathsf{fma}\left(\frac{x}{\mathsf{hypot}\left(x, \sqrt{y \cdot \left(y \cdot 4\right)}\right)}, \frac{x}{\mathsf{hypot}\left(x, \sqrt{y \cdot \left(y \cdot 4\right)}\right)}, -\frac{y}{\color{blue}{\mathsf{fma}\left(0.25, \frac{x}{\frac{y}{x}}, y\right)}}\right) \]
  5. Applied egg-rr0.0

    \[\leadsto \color{blue}{{\left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2} - \frac{y}{\mathsf{fma}\left(0.25, x \cdot \frac{x}{y}, y\right)}} \]
  6. Final simplification0.0

    \[\leadsto {\left(\frac{x}{\mathsf{hypot}\left(x, y \cdot 2\right)}\right)}^{2} - \frac{y}{\mathsf{fma}\left(0.25, x \cdot \frac{x}{y}, y\right)} \]

Reproduce

herbie shell --seed 2022211 
(FPCore (x y)
  :name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))) 0.9743233849626781) (- (/ (* x x) (+ (* x x) (* (* y y) 4.0))) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))) (- (pow (/ x (sqrt (+ (* x x) (* (* y y) 4.0)))) 2.0) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))))

  (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))