Average Error: 31.5 → 14.2
Time: 2.1s
Precision: 64
\[\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 \le -5.810291952691062 \cdot 10^{115}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -2.9463808085280802 \cdot 10^{-149}:\\ \;\;\;\;\frac{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;x \le 9.05045019517546565 \cdot 10^{-190}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 1.3661811917011361 \cdot 10^{-63}:\\ \;\;\;\;\frac{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;x \le 4.9502099980031536 \cdot 10^{39}:\\ \;\;\;\;-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 \le -5.810291952691062 \cdot 10^{115}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -2.9463808085280802 \cdot 10^{-149}:\\
\;\;\;\;\frac{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\

\mathbf{elif}\;x \le 9.05045019517546565 \cdot 10^{-190}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 1.3661811917011361 \cdot 10^{-63}:\\
\;\;\;\;\frac{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\

\mathbf{elif}\;x \le 4.9502099980031536 \cdot 10^{39}:\\
\;\;\;\;-1\\

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

\end{array}
double f(double x, double y) {
        double r776015 = x;
        double r776016 = r776015 * r776015;
        double r776017 = y;
        double r776018 = 4.0;
        double r776019 = r776017 * r776018;
        double r776020 = r776019 * r776017;
        double r776021 = r776016 - r776020;
        double r776022 = r776016 + r776020;
        double r776023 = r776021 / r776022;
        return r776023;
}

double f(double x, double y) {
        double r776024 = x;
        double r776025 = -5.810291952691062e+115;
        bool r776026 = r776024 <= r776025;
        double r776027 = 1.0;
        double r776028 = -2.9463808085280802e-149;
        bool r776029 = r776024 <= r776028;
        double r776030 = r776024 * r776024;
        double r776031 = y;
        double r776032 = 4.0;
        double r776033 = r776031 * r776032;
        double r776034 = r776033 * r776031;
        double r776035 = r776030 - r776034;
        double r776036 = r776030 + r776034;
        double r776037 = sqrt(r776036);
        double r776038 = r776035 / r776037;
        double r776039 = r776038 / r776037;
        double r776040 = 9.050450195175466e-190;
        bool r776041 = r776024 <= r776040;
        double r776042 = -1.0;
        double r776043 = 1.366181191701136e-63;
        bool r776044 = r776024 <= r776043;
        double r776045 = 4.9502099980031536e+39;
        bool r776046 = r776024 <= r776045;
        double r776047 = r776046 ? r776042 : r776027;
        double r776048 = r776044 ? r776039 : r776047;
        double r776049 = r776041 ? r776042 : r776048;
        double r776050 = r776029 ? r776039 : r776049;
        double r776051 = r776026 ? r776027 : r776050;
        return r776051;
}

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.5
Target31.3
Herbie14.2
\[\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} \lt 0.974323384962678118:\\ \;\;\;\;\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 x < -5.810291952691062e+115 or 4.9502099980031536e+39 < x

    1. Initial program 48.0

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

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

    if -5.810291952691062e+115 < x < -2.9463808085280802e-149 or 9.050450195175466e-190 < x < 1.366181191701136e-63

    1. Initial program 17.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-sqr-sqrt17.4

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y} \cdot \sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\]
    4. Applied associate-/r*17.5

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

    if -2.9463808085280802e-149 < x < 9.050450195175466e-190 or 1.366181191701136e-63 < x < 4.9502099980031536e+39

    1. Initial program 26.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -5.810291952691062 \cdot 10^{115}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -2.9463808085280802 \cdot 10^{-149}:\\ \;\;\;\;\frac{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;x \le 9.05045019517546565 \cdot 10^{-190}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 1.3661811917011361 \cdot 10^{-63}:\\ \;\;\;\;\frac{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;x \le 4.9502099980031536 \cdot 10^{39}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

herbie shell --seed 2020021 
(FPCore (x y)
  :name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< (/ (- (* x x) (* (* y 4) y)) (+ (* x x) (* (* y 4) y))) 0.9743233849626781) (- (/ (* x x) (+ (* x x) (* (* y y) 4))) (/ (* (* y y) 4) (+ (* x x) (* (* y y) 4)))) (- (pow (/ x (sqrt (+ (* x x) (* (* y y) 4)))) 2) (/ (* (* y y) 4) (+ (* x x) (* (* y y) 4)))))

  (/ (- (* x x) (* (* y 4) y)) (+ (* x x) (* (* y 4) y))))