Average Error: 31.9 → 14.5
Time: 3.4min
Precision: binary64
Cost: 3076
\[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \cdot x \leq 0:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 20744661527.68968:\\ \;\;\;\;\frac{\sqrt[3]{1}}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{\left(x \cdot x - y \cdot \left(y \cdot 4\right)\right) \cdot \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right)}}\\ \mathbf{elif}\;x \cdot x \leq 2.7895917333309595 \cdot 10^{+118}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 2.928184284468576 \cdot 10^{+240}:\\ \;\;\;\;\frac{\sqrt[3]{1}}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{\left(x \cdot x - y \cdot \left(y \cdot 4\right)\right) \cdot \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right)}}\\ \mathbf{elif}\;x \cdot x \leq 2.661347435828539 \cdot 10^{+286}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 0:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \leq 20744661527.68968:\\
\;\;\;\;\frac{\sqrt[3]{1}}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{\left(x \cdot x - y \cdot \left(y \cdot 4\right)\right) \cdot \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right)}}\\

\mathbf{elif}\;x \cdot x \leq 2.7895917333309595 \cdot 10^{+118}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \leq 2.928184284468576 \cdot 10^{+240}:\\
\;\;\;\;\frac{\sqrt[3]{1}}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{\left(x \cdot x - y \cdot \left(y \cdot 4\right)\right) \cdot \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right)}}\\

\mathbf{elif}\;x \cdot x \leq 2.661347435828539 \cdot 10^{+286}:\\
\;\;\;\;-1\\

\mathbf{else}:\\
\;\;\;\;1\\

\end{array}
(FPCore (x y)
 :precision binary64
 (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))
(FPCore (x y)
 :precision binary64
 (if (<= (* x x) 0.0)
   -1.0
   (if (<= (* x x) 20744661527.68968)
     (/
      (cbrt 1.0)
      (/
       (+ (* x x) (* y (* y 4.0)))
       (* (- (* x x) (* y (* y 4.0))) (* (cbrt 1.0) (cbrt 1.0)))))
     (if (<= (* x x) 2.7895917333309595e+118)
       -1.0
       (if (<= (* x x) 2.928184284468576e+240)
         (/
          (cbrt 1.0)
          (/
           (+ (* x x) (* y (* y 4.0)))
           (* (- (* x x) (* y (* y 4.0))) (* (cbrt 1.0) (cbrt 1.0)))))
         (if (<= (* x x) 2.661347435828539e+286) -1.0 1.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) {
	double tmp;
	if ((x * x) <= 0.0) {
		tmp = -1.0;
	} else if ((x * x) <= 20744661527.68968) {
		tmp = cbrt(1.0) / (((x * x) + (y * (y * 4.0))) / (((x * x) - (y * (y * 4.0))) * (cbrt(1.0) * cbrt(1.0))));
	} else if ((x * x) <= 2.7895917333309595e+118) {
		tmp = -1.0;
	} else if ((x * x) <= 2.928184284468576e+240) {
		tmp = cbrt(1.0) / (((x * x) + (y * (y * 4.0))) / (((x * x) - (y * (y * 4.0))) * (cbrt(1.0) * cbrt(1.0))));
	} else if ((x * x) <= 2.661347435828539e+286) {
		tmp = -1.0;
	} else {
		tmp = 1.0;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original31.9
Target31.6
Herbie14.5
\[\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}\]
Alternative 1
Accuracy15.5
Cost3137
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)} \leq 0.9999999999992286:\\ \;\;\;\;\frac{\sqrt[3]{1}}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{\left(x \cdot x - y \cdot \left(y \cdot 4\right)\right) \cdot \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right)}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 2
Accuracy31.9
Cost1792
\[\frac{\sqrt[3]{1}}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{\left(x \cdot x - y \cdot \left(y \cdot 4\right)\right) \cdot \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right)}}\]
Alternative 3
Accuracy31.9
Cost4992
\[\frac{\sqrt[3]{1}}{\sqrt[3]{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{\sqrt[3]{1} \cdot \left(y \cdot \left(y \cdot 4\right) - x \cdot x\right)}} \cdot \sqrt[3]{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{\sqrt[3]{1} \cdot \left(y \cdot \left(y \cdot 4\right) - x \cdot x\right)}}} \cdot \frac{-\sqrt[3]{1}}{\sqrt[3]{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{\sqrt[3]{1} \cdot \left(y \cdot \left(y \cdot 4\right) - x \cdot x\right)}}}\]
Alternative 4
Accuracy31.9
Cost4096
\[\frac{1}{\sqrt[3]{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{x \cdot x - y \cdot \left(y \cdot 4\right)}} \cdot \left(\sqrt[3]{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{x \cdot x - y \cdot \left(y \cdot 4\right)}} \cdot \sqrt[3]{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{x \cdot x - y \cdot \left(y \cdot 4\right)}}\right)}\]

Derivation

  1. Split input into 3 regimes
  2. if (*.f64 x x) < 0.0 or 20744661527.6896782 < (*.f64 x x) < 2.78959173333095949e118 or 2.928184284468576e240 < (*.f64 x x) < 2.6613474358285388e286

    1. Initial program 26.5

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Using strategy rm
    3. Applied clear-num_binary64_1815026.5

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x \cdot x - \left(y \cdot 4\right) \cdot y}}}\]
    4. Simplified26.5

      \[\leadsto \frac{1}{\color{blue}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{x \cdot x - y \cdot \left(y \cdot 4\right)}}}\]
    5. Taylor expanded around 0 18.3

      \[\leadsto \frac{1}{\color{blue}{-1}}\]

    if 0.0 < (*.f64 x x) < 20744661527.6896782 or 2.78959173333095949e118 < (*.f64 x x) < 2.928184284468576e240

    1. Initial program 15.6

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Using strategy rm
    3. Applied clear-num_binary64_1815015.6

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x \cdot x - \left(y \cdot 4\right) \cdot y}}}\]
    4. Simplified15.6

      \[\leadsto \frac{1}{\color{blue}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{x \cdot x - y \cdot \left(y \cdot 4\right)}}}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt_binary64_1818615.6

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{x \cdot x - y \cdot \left(y \cdot 4\right)}}\]
    7. Applied associate-/l*_binary64_1809615.6

      \[\leadsto \color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\frac{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{x \cdot x - y \cdot \left(y \cdot 4\right)}}{\sqrt[3]{1}}}}\]
    8. Simplified15.6

      \[\leadsto \frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\color{blue}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{\left(x \cdot x - y \cdot \left(y \cdot 4\right)\right) \cdot \sqrt[3]{1}}}}\]
    9. Using strategy rm
    10. Applied associate-/l*_binary64_1809615.6

      \[\leadsto \color{blue}{\frac{\sqrt[3]{1}}{\frac{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{\left(x \cdot x - y \cdot \left(y \cdot 4\right)\right) \cdot \sqrt[3]{1}}}{\sqrt[3]{1}}}}\]
    11. Simplified15.6

      \[\leadsto \frac{\sqrt[3]{1}}{\color{blue}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{\left(x \cdot x - y \cdot \left(y \cdot 4\right)\right) \cdot \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right)}}}\]

    if 2.6613474358285388e286 < (*.f64 x x)

    1. Initial program 61.2

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Using strategy rm
    3. Applied clear-num_binary64_1815061.2

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x \cdot x - \left(y \cdot 4\right) \cdot y}}}\]
    4. Simplified61.2

      \[\leadsto \frac{1}{\color{blue}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{x \cdot x - y \cdot \left(y \cdot 4\right)}}}\]
    5. Taylor expanded around inf 8.1

      \[\leadsto \frac{1}{\color{blue}{1}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification14.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 0:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 20744661527.68968:\\ \;\;\;\;\frac{\sqrt[3]{1}}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{\left(x \cdot x - y \cdot \left(y \cdot 4\right)\right) \cdot \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right)}}\\ \mathbf{elif}\;x \cdot x \leq 2.7895917333309595 \cdot 10^{+118}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 2.928184284468576 \cdot 10^{+240}:\\ \;\;\;\;\frac{\sqrt[3]{1}}{\frac{x \cdot x + y \cdot \left(y \cdot 4\right)}{\left(x \cdot x - y \cdot \left(y \cdot 4\right)\right) \cdot \left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right)}}\\ \mathbf{elif}\;x \cdot x \leq 2.661347435828539 \cdot 10^{+286}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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