Average Error: 32.1 → 13.1
Time: 6.6s
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 \leq -9.789826550149937 \cdot 10^{+63}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -2.0670216515310263 \cdot 10^{+33}:\\ \;\;\;\;-1 + 0.5 \cdot \frac{x \cdot x}{y \cdot y}\\ \mathbf{elif}\;x \leq -1.1530864834412767 \cdot 10^{-108}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot \left(y \cdot 4\right)} - \frac{y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \leq 2.5574576931355925 \cdot 10^{-114}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 2.3500817544996674 \cdot 10^{+80}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}}\right)\\ \mathbf{elif}\;x \leq 3.5779591776205156 \cdot 10^{+94}:\\ \;\;\;\;-1 + 0.5 \cdot \frac{x \cdot x}{y \cdot y}\\ \mathbf{elif}\;x \leq 5.789054045437359 \cdot 10^{+121}:\\ \;\;\;\;\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)\\ \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 \leq -9.789826550149937 \cdot 10^{+63}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq -2.0670216515310263 \cdot 10^{+33}:\\
\;\;\;\;-1 + 0.5 \cdot \frac{x \cdot x}{y \cdot y}\\

\mathbf{elif}\;x \leq -1.1530864834412767 \cdot 10^{-108}:\\
\;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot \left(y \cdot 4\right)} - \frac{y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\

\mathbf{elif}\;x \leq 2.5574576931355925 \cdot 10^{-114}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \leq 2.3500817544996674 \cdot 10^{+80}:\\
\;\;\;\;\log \left(e^{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}}\right)\\

\mathbf{elif}\;x \leq 3.5779591776205156 \cdot 10^{+94}:\\
\;\;\;\;-1 + 0.5 \cdot \frac{x \cdot x}{y \cdot y}\\

\mathbf{elif}\;x \leq 5.789054045437359 \cdot 10^{+121}:\\
\;\;\;\;\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)\\

\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 -9.789826550149937e+63)
   1.0
   (if (<= x -2.0670216515310263e+33)
     (+ -1.0 (* 0.5 (/ (* x x) (* y y))))
     (if (<= x -1.1530864834412767e-108)
       (-
        (/ (* x x) (+ (* x x) (* y (* y 4.0))))
        (/ (* y (* y 4.0)) (+ (* x x) (* y (* y 4.0)))))
       (if (<= x 2.5574576931355925e-114)
         -1.0
         (if (<= x 2.3500817544996674e+80)
           (log
            (exp (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0))))))
           (if (<= x 3.5779591776205156e+94)
             (+ -1.0 (* 0.5 (/ (* x x) (* y y))))
             (if (<= x 5.789054045437359e+121)
               (*
                (cbrt
                 (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0)))))
                (*
                 (cbrt
                  (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0)))))
                 (cbrt
                  (/
                   (- (* x x) (* y (* y 4.0)))
                   (+ (* x x) (* y (* y 4.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 <= -9.789826550149937e+63) {
		tmp = 1.0;
	} else if (x <= -2.0670216515310263e+33) {
		tmp = -1.0 + (0.5 * ((x * x) / (y * y)));
	} else if (x <= -1.1530864834412767e-108) {
		tmp = ((x * x) / ((x * x) + (y * (y * 4.0)))) - ((y * (y * 4.0)) / ((x * x) + (y * (y * 4.0))));
	} else if (x <= 2.5574576931355925e-114) {
		tmp = -1.0;
	} else if (x <= 2.3500817544996674e+80) {
		tmp = log(exp(((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0)))));
	} else if (x <= 3.5779591776205156e+94) {
		tmp = -1.0 + (0.5 * ((x * x) / (y * y)));
	} else if (x <= 5.789054045437359e+121) {
		tmp = cbrt(((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0)))) * (cbrt(((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0)))) * cbrt(((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.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

Original32.1
Target31.8
Herbie13.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. Split input into 6 regimes
  2. if x < -9.789826550149937e63 or 5.7890540454373593e121 < x

    1. Initial program 50.8

      \[\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-log-exp_binary64_1000650.8

      \[\leadsto \color{blue}{\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)}\]
    4. Simplified50.8

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

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

    if -9.789826550149937e63 < x < -2.06702165153102634e33 or 2.3500817544996674e80 < x < 3.57795917762051556e94

    1. Initial program 20.4

      \[\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 34.7

      \[\leadsto \color{blue}{0.5 \cdot \frac{{x}^{2}}{{y}^{2}} - 1}\]
    3. Simplified34.7

      \[\leadsto \color{blue}{-1 + 0.5 \cdot \frac{x \cdot x}{y \cdot y}}\]

    if -2.06702165153102634e33 < x < -1.15308648344127671e-108

    1. Initial program 17.1

      \[\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 div-sub_binary64_997217.1

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

    if -1.15308648344127671e-108 < x < 2.5574576931355925e-114

    1. Initial program 27.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-log-exp_binary64_1000627.4

      \[\leadsto \color{blue}{\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)}\]
    4. Simplified27.4

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

      \[\leadsto \color{blue}{\log \left(e^{-1}\right)}\]
    6. Simplified9.8

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

    if 2.5574576931355925e-114 < x < 2.3500817544996674e80

    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 add-log-exp_binary64_1000615.6

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

    if 3.57795917762051556e94 < x < 5.7890540454373593e121

    1. Initial program 15.8

      \[\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-cube-cbrt_binary64_1000215.8

      \[\leadsto \color{blue}{\left(\sqrt[3]{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \sqrt[3]{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) \cdot \sqrt[3]{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\]
  3. Recombined 6 regimes into one program.
  4. Final simplification13.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -9.789826550149937 \cdot 10^{+63}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq -2.0670216515310263 \cdot 10^{+33}:\\ \;\;\;\;-1 + 0.5 \cdot \frac{x \cdot x}{y \cdot y}\\ \mathbf{elif}\;x \leq -1.1530864834412767 \cdot 10^{-108}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + y \cdot \left(y \cdot 4\right)} - \frac{y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;x \leq 2.5574576931355925 \cdot 10^{-114}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \leq 2.3500817544996674 \cdot 10^{+80}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}}\right)\\ \mathbf{elif}\;x \leq 3.5779591776205156 \cdot 10^{+94}:\\ \;\;\;\;-1 + 0.5 \cdot \frac{x \cdot x}{y \cdot y}\\ \mathbf{elif}\;x \leq 5.789054045437359 \cdot 10^{+121}:\\ \;\;\;\;\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)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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