Average Error: 31.9 → 12.7
Time: 4.8s
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}\;y \leq -4.840441743074084 \cdot 10^{+159}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -4.569228095431844 \cdot 10^{+148}:\\ \;\;\;\;1 - 8 \cdot e^{2 \cdot \log \left(\frac{y}{x}\right)}\\ \mathbf{elif}\;y \leq -1.9184276867004103 \cdot 10^{-67}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;y \leq 1.45879755932371 \cdot 10^{-128}:\\ \;\;\;\;1 - 8 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\ \mathbf{elif}\;y \leq 1.326325169906906 \cdot 10^{+128}:\\ \;\;\;\;\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{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}\;y \leq -4.840441743074084 \cdot 10^{+159}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \leq -4.569228095431844 \cdot 10^{+148}:\\
\;\;\;\;1 - 8 \cdot e^{2 \cdot \log \left(\frac{y}{x}\right)}\\

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

\mathbf{elif}\;y \leq 1.45879755932371 \cdot 10^{-128}:\\
\;\;\;\;1 - 8 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\

\mathbf{elif}\;y \leq 1.326325169906906 \cdot 10^{+128}:\\
\;\;\;\;\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{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 (<= y -4.840441743074084e+159)
   -1.0
   (if (<= y -4.569228095431844e+148)
     (- 1.0 (* 8.0 (exp (* 2.0 (log (/ y x))))))
     (if (<= y -1.9184276867004103e-67)
       (/ (- (* x x) (* y (* y 4.0))) (+ (* x x) (* y (* y 4.0))))
       (if (<= y 1.45879755932371e-128)
         (- 1.0 (* 8.0 (* (/ y x) (/ y x))))
         (if (<= y 1.326325169906906e+128)
           (-
            (/ (* x x) (+ (* x x) (* y (* y 4.0))))
            (/ (* 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 (y <= -4.840441743074084e+159) {
		tmp = -1.0;
	} else if (y <= -4.569228095431844e+148) {
		tmp = 1.0 - (8.0 * exp(2.0 * log(y / x)));
	} else if (y <= -1.9184276867004103e-67) {
		tmp = ((x * x) - (y * (y * 4.0))) / ((x * x) + (y * (y * 4.0)));
	} else if (y <= 1.45879755932371e-128) {
		tmp = 1.0 - (8.0 * ((y / x) * (y / x)));
	} else if (y <= 1.326325169906906e+128) {
		tmp = ((x * x) / ((x * x) + (y * (y * 4.0)))) - ((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

Original31.9
Target31.6
Herbie12.7
\[\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 5 regimes
  2. if y < -4.8404417430740843e159 or 1.3263251699069059e128 < y

    1. Initial program 60.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 0 8.8

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

    if -4.8404417430740843e159 < y < -4.5692280954318441e148

    1. Initial program 35.8

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

      \[\leadsto \color{blue}{1 - 8 \cdot \frac{{y}^{2}}{{x}^{2}}}\]
    3. Simplified55.2

      \[\leadsto \color{blue}{1 - 8 \cdot \frac{y \cdot y}{x \cdot x}}\]
    4. Using strategy rm
    5. Applied add-exp-log_binary64_1512060.1

      \[\leadsto 1 - 8 \cdot \frac{y \cdot y}{x \cdot \color{blue}{e^{\log x}}}\]
    6. Applied add-exp-log_binary64_1512060.1

      \[\leadsto 1 - 8 \cdot \frac{y \cdot y}{\color{blue}{e^{\log x}} \cdot e^{\log x}}\]
    7. Applied prod-exp_binary64_1513160.1

      \[\leadsto 1 - 8 \cdot \frac{y \cdot y}{\color{blue}{e^{\log x + \log x}}}\]
    8. Applied add-exp-log_binary64_1512064.0

      \[\leadsto 1 - 8 \cdot \frac{y \cdot \color{blue}{e^{\log y}}}{e^{\log x + \log x}}\]
    9. Applied add-exp-log_binary64_1512064.0

      \[\leadsto 1 - 8 \cdot \frac{\color{blue}{e^{\log y}} \cdot e^{\log y}}{e^{\log x + \log x}}\]
    10. Applied prod-exp_binary64_1513164.0

      \[\leadsto 1 - 8 \cdot \frac{\color{blue}{e^{\log y + \log y}}}{e^{\log x + \log x}}\]
    11. Applied div-exp_binary64_1513364.0

      \[\leadsto 1 - 8 \cdot \color{blue}{e^{\left(\log y + \log y\right) - \left(\log x + \log x\right)}}\]
    12. Simplified52.3

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

    if -4.5692280954318441e148 < y < -1.9184276867004103e-67

    1. Initial program 15.7

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

    if -1.9184276867004103e-67 < y < 1.4587975593237099e-128

    1. Initial program 27.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 16.6

      \[\leadsto \color{blue}{1 - 8 \cdot \frac{{y}^{2}}{{x}^{2}}}\]
    3. Simplified16.6

      \[\leadsto \color{blue}{1 - 8 \cdot \frac{y \cdot y}{x \cdot x}}\]
    4. Using strategy rm
    5. Applied times-frac_binary64_1508810.4

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

    if 1.4587975593237099e-128 < y < 1.3263251699069059e128

    1. Initial program 16.9

      \[\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_1508716.9

      \[\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}}\]
  3. Recombined 5 regimes into one program.
  4. Final simplification12.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -4.840441743074084 \cdot 10^{+159}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \leq -4.569228095431844 \cdot 10^{+148}:\\ \;\;\;\;1 - 8 \cdot e^{2 \cdot \log \left(\frac{y}{x}\right)}\\ \mathbf{elif}\;y \leq -1.9184276867004103 \cdot 10^{-67}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;y \leq 1.45879755932371 \cdot 10^{-128}:\\ \;\;\;\;1 - 8 \cdot \left(\frac{y}{x} \cdot \frac{y}{x}\right)\\ \mathbf{elif}\;y \leq 1.326325169906906 \cdot 10^{+128}:\\ \;\;\;\;\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{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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