Average Error: 31.6 → 0.1
Time: 9.0s
Precision: binary64
Cost: 33280
\[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
\[\sqrt[3]{{\left(\frac{\mathsf{fma}\left(y, 2, x\right)}{\mathsf{hypot}\left(x, y + y\right)}\right)}^{3}} \cdot \frac{x + y \cdot -2}{\mathsf{hypot}\left(x, y \cdot 2\right)} \]
(FPCore (x y)
 :precision binary64
 (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))
(FPCore (x y)
 :precision binary64
 (*
  (cbrt (pow (/ (fma y 2.0 x) (hypot x (+ y y))) 3.0))
  (/ (+ x (* y -2.0)) (hypot x (* y 2.0)))))
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 cbrt(pow((fma(y, 2.0, x) / hypot(x, (y + y))), 3.0)) * ((x + (y * -2.0)) / hypot(x, (y * 2.0)));
}
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(cbrt((Float64(fma(y, 2.0, x) / hypot(x, Float64(y + y))) ^ 3.0)) * Float64(Float64(x + Float64(y * -2.0)) / hypot(x, Float64(y * 2.0))))
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[Power[N[(N[(y * 2.0 + x), $MachinePrecision] / N[Sqrt[x ^ 2 + N[(y + y), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision], 1/3], $MachinePrecision] * N[(N[(x + N[(y * -2.0), $MachinePrecision]), $MachinePrecision] / N[Sqrt[x ^ 2 + N[(y * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\sqrt[3]{{\left(\frac{\mathsf{fma}\left(y, 2, x\right)}{\mathsf{hypot}\left(x, y + y\right)}\right)}^{3}} \cdot \frac{x + y \cdot -2}{\mathsf{hypot}\left(x, y \cdot 2\right)}

Error

Target

Original31.6
Target31.3
Herbie0.1
\[\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.6

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

    \[\leadsto \frac{\color{blue}{\left(x + \sqrt{y \cdot \left(y \cdot 4\right)}\right) \cdot \left(x - \sqrt{y \cdot \left(y \cdot 4\right)}\right)}}{x \cdot x + \left(y \cdot 4\right) \cdot y} \]
  3. Applied egg-rr0.0

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

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

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

Alternatives

Alternative 1
Error0.0
Cost20416
\[\begin{array}{l} t_0 := \mathsf{hypot}\left(x, y \cdot 2\right)\\ \frac{x + y \cdot -2}{t_0} \cdot \frac{\mathsf{fma}\left(y, 2, x\right)}{t_0} \end{array} \]
Alternative 2
Error12.7
Cost2256
\[\begin{array}{l} t_0 := \frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ t_1 := \frac{\frac{x}{y}}{\frac{y}{x}} \cdot 0.5 + -1\\ \mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-119}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 10^{-64}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \cdot x \leq 10^{-18}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 10^{+253}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{y \cdot -4}{\frac{x}{\frac{y}{x}}}\\ \end{array} \]
Alternative 3
Error12.7
Cost2256
\[\begin{array}{l} t_0 := \frac{\frac{x}{y}}{\frac{y}{x}} \cdot 0.5 + -1\\ t_1 := x \cdot x + y \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-119}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \cdot x \leq 10^{-64}:\\ \;\;\;\;\frac{\left(x + y \cdot -2\right) \cdot \left(x - y \cdot -2\right)}{t_1}\\ \mathbf{elif}\;x \cdot x \leq 10^{-18}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \cdot x \leq 10^{+253}:\\ \;\;\;\;\frac{x \cdot x + y \cdot \left(y \cdot -4\right)}{t_1}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{y \cdot -4}{\frac{x}{\frac{y}{x}}}\\ \end{array} \]
Alternative 4
Error15.8
Cost1484
\[\begin{array}{l} \mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-116}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{-98}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+38}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{y \cdot -4}{\frac{x}{\frac{y}{x}}}\\ \end{array} \]
Alternative 5
Error15.5
Cost1484
\[\begin{array}{l} t_0 := \frac{\frac{x}{y}}{\frac{y}{x}} \cdot 0.5 + -1\\ \mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-116}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \cdot x \leq 4 \cdot 10^{-98}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \cdot x \leq 2 \cdot 10^{+38}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{y \cdot -4}{\frac{x}{\frac{y}{x}}}\\ \end{array} \]
Alternative 6
Error16.0
Cost844
\[\begin{array}{l} \mathbf{if}\;x \cdot x \leq 2 \cdot 10^{-114}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 2.6 \cdot 10^{-98}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \cdot x \leq 3.2 \cdot 10^{+38}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 7
Error31.9
Cost64
\[-1 \]

Error

Reproduce

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