Average Error: 31.7 → 11.9
Time: 1.5s
Precision: binary64
\[\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 9.35173104322283 \cdot 10^{-269}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 3.1402604854661807 \cdot 10^{-16}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\right)}^{3}}\\ \mathbf{elif}\;x \cdot x \leq 7.0633851876318 \cdot 10^{-09}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 3.783379702185256 \cdot 10^{+232}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\right)}^{3}}\\ \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 9.35173104322283 \cdot 10^{-269}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;x \cdot x \leq 7.0633851876318 \cdot 10^{-09}:\\
\;\;\;\;-1\\

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

\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) 9.35173104322283e-269)
   -1.0
   (if (<= (* x x) 3.1402604854661807e-16)
     (cbrt
      (pow (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0)))) 3.0))
     (if (<= (* x x) 7.0633851876318e-09)
       -1.0
       (if (<= (* x x) 3.783379702185256e+232)
         (cbrt
          (pow
           (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0))))
           3.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) <= 9.35173104322283e-269) {
		tmp = -1.0;
	} else if ((x * x) <= 3.1402604854661807e-16) {
		tmp = cbrt(pow((((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0)))), 3.0));
	} else if ((x * x) <= 7.0633851876318e-09) {
		tmp = -1.0;
	} else if ((x * x) <= 3.783379702185256e+232) {
		tmp = cbrt(pow((((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0)))), 3.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.7
Target31.4
Herbie11.9
\[\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. Split input into 3 regimes
  2. if (*.f64 x x) < 9.35173104322283019e-269 or 3.1402604854661807e-16 < (*.f64 x x) < 7.06338518763179992e-9

    1. Initial program 29.5

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Taylor expanded around 0 9.1

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

    if 9.35173104322283019e-269 < (*.f64 x x) < 3.1402604854661807e-16 or 7.06338518763179992e-9 < (*.f64 x x) < 3.7833797021852558e232

    1. Initial program 15.4

      \[\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 add-cbrt-cube_binary6444.6

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

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

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

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

    if 3.7833797021852558e232 < (*.f64 x x)

    1. Initial program 54.9

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Taylor expanded around inf 10.0

      \[\leadsto \color{blue}{1}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification11.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 9.35173104322283 \cdot 10^{-269}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 3.1402604854661807 \cdot 10^{-16}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\right)}^{3}}\\ \mathbf{elif}\;x \cdot x \leq 7.0633851876318 \cdot 10^{-09}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \leq 3.783379702185256 \cdot 10^{+232}:\\ \;\;\;\;\sqrt[3]{{\left(\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\right)}^{3}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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