Average Error: 30.8 → 12.9
Time: 8.2s
Precision: 64
\[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \cdot x \le 2.6679544875427 \cdot 10^{-322}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 1.859966789631152 \cdot 10^{-181}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{\sqrt{x \cdot x + \left(y \cdot 4.0\right) \cdot y} \cdot \sqrt{x \cdot x + \left(y \cdot 4.0\right) \cdot y}}\\ \mathbf{elif}\;x \cdot x \le 8.000234299940421 \cdot 10^{-78}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 9.482092415813315 \cdot 10^{+188}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{\sqrt{x \cdot x + \left(y \cdot 4.0\right) \cdot y} \cdot \sqrt{x \cdot x + \left(y \cdot 4.0\right) \cdot y}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}
\begin{array}{l}
\mathbf{if}\;x \cdot x \le 2.6679544875427 \cdot 10^{-322}:\\
\;\;\;\;-1.0\\

\mathbf{elif}\;x \cdot x \le 1.859966789631152 \cdot 10^{-181}:\\
\;\;\;\;\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{\sqrt{x \cdot x + \left(y \cdot 4.0\right) \cdot y} \cdot \sqrt{x \cdot x + \left(y \cdot 4.0\right) \cdot y}}\\

\mathbf{elif}\;x \cdot x \le 8.000234299940421 \cdot 10^{-78}:\\
\;\;\;\;-1.0\\

\mathbf{elif}\;x \cdot x \le 9.482092415813315 \cdot 10^{+188}:\\
\;\;\;\;\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{\sqrt{x \cdot x + \left(y \cdot 4.0\right) \cdot y} \cdot \sqrt{x \cdot x + \left(y \cdot 4.0\right) \cdot y}}\\

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

\end{array}
double f(double x, double y) {
        double r36596014 = x;
        double r36596015 = r36596014 * r36596014;
        double r36596016 = y;
        double r36596017 = 4.0;
        double r36596018 = r36596016 * r36596017;
        double r36596019 = r36596018 * r36596016;
        double r36596020 = r36596015 - r36596019;
        double r36596021 = r36596015 + r36596019;
        double r36596022 = r36596020 / r36596021;
        return r36596022;
}

double f(double x, double y) {
        double r36596023 = x;
        double r36596024 = r36596023 * r36596023;
        double r36596025 = 2.6679544875427e-322;
        bool r36596026 = r36596024 <= r36596025;
        double r36596027 = -1.0;
        double r36596028 = 1.859966789631152e-181;
        bool r36596029 = r36596024 <= r36596028;
        double r36596030 = y;
        double r36596031 = 4.0;
        double r36596032 = r36596030 * r36596031;
        double r36596033 = r36596032 * r36596030;
        double r36596034 = r36596024 - r36596033;
        double r36596035 = r36596024 + r36596033;
        double r36596036 = sqrt(r36596035);
        double r36596037 = r36596036 * r36596036;
        double r36596038 = r36596034 / r36596037;
        double r36596039 = 8.000234299940421e-78;
        bool r36596040 = r36596024 <= r36596039;
        double r36596041 = 9.482092415813315e+188;
        bool r36596042 = r36596024 <= r36596041;
        double r36596043 = 1.0;
        double r36596044 = r36596042 ? r36596038 : r36596043;
        double r36596045 = r36596040 ? r36596027 : r36596044;
        double r36596046 = r36596029 ? r36596038 : r36596045;
        double r36596047 = r36596026 ? r36596027 : r36596046;
        return r36596047;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original30.8
Target30.9
Herbie12.9
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} \lt 0.9743233849626781:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot y\right) \cdot 4.0} - \frac{\left(y \cdot y\right) \cdot 4.0}{x \cdot x + \left(y \cdot y\right) \cdot 4.0}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x}{\sqrt{x \cdot x + \left(y \cdot y\right) \cdot 4.0}}\right)}^{2} - \frac{\left(y \cdot y\right) \cdot 4.0}{x \cdot x + \left(y \cdot y\right) \cdot 4.0}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if (* x x) < 2.6679544875427e-322 or 1.859966789631152e-181 < (* x x) < 8.000234299940421e-78

    1. Initial program 26.0

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

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

    if 2.6679544875427e-322 < (* x x) < 1.859966789631152e-181 or 8.000234299940421e-78 < (* x x) < 9.482092415813315e+188

    1. Initial program 16.2

      \[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt16.2

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

    if 9.482092415813315e+188 < (* x x)

    1. Initial program 49.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \le 2.6679544875427 \cdot 10^{-322}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 1.859966789631152 \cdot 10^{-181}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{\sqrt{x \cdot x + \left(y \cdot 4.0\right) \cdot y} \cdot \sqrt{x \cdot x + \left(y \cdot 4.0\right) \cdot y}}\\ \mathbf{elif}\;x \cdot x \le 8.000234299940421 \cdot 10^{-78}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 9.482092415813315 \cdot 10^{+188}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{\sqrt{x \cdot x + \left(y \cdot 4.0\right) \cdot y} \cdot \sqrt{x \cdot x + \left(y \cdot 4.0\right) \cdot y}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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

  :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) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))))

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