Average Error: 31.3 → 14.7
Time: 10.2s
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}\;\left(y \cdot 4\right) \cdot y \le 0.0:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 8.14624205965243804 \cdot 10^{-197}:\\ \;\;\;\;\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{1}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{\left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.89336738182365018 \cdot 10^{-164}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.080267309844611 \cdot 10^{-17}:\\ \;\;\;\;\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{1}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{\left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 5.0547066207328322 \cdot 10^{101}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.6000500965086023 \cdot 10^{199}:\\ \;\;\;\;\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\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}\;\left(y \cdot 4\right) \cdot y \le 0.0:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 8.14624205965243804 \cdot 10^{-197}:\\
\;\;\;\;\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{1}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{\left(y \cdot 4\right) \cdot y}}\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.89336738182365018 \cdot 10^{-164}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.080267309844611 \cdot 10^{-17}:\\
\;\;\;\;\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{1}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{\left(y \cdot 4\right) \cdot y}}\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 5.0547066207328322 \cdot 10^{101}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.6000500965086023 \cdot 10^{199}:\\
\;\;\;\;\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\

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

\end{array}
double f(double x, double y) {
        double r484778 = x;
        double r484779 = r484778 * r484778;
        double r484780 = y;
        double r484781 = 4.0;
        double r484782 = r484780 * r484781;
        double r484783 = r484782 * r484780;
        double r484784 = r484779 - r484783;
        double r484785 = r484779 + r484783;
        double r484786 = r484784 / r484785;
        return r484786;
}

double f(double x, double y) {
        double r484787 = y;
        double r484788 = 4.0;
        double r484789 = r484787 * r484788;
        double r484790 = r484789 * r484787;
        double r484791 = 0.0;
        bool r484792 = r484790 <= r484791;
        double r484793 = 1.0;
        double r484794 = 8.146242059652438e-197;
        bool r484795 = r484790 <= r484794;
        double r484796 = x;
        double r484797 = r484796 * r484796;
        double r484798 = fma(r484796, r484796, r484790);
        double r484799 = r484797 / r484798;
        double r484800 = r484798 / r484790;
        double r484801 = r484793 / r484800;
        double r484802 = r484799 - r484801;
        double r484803 = 1.89336738182365e-164;
        bool r484804 = r484790 <= r484803;
        double r484805 = 2.080267309844611e-17;
        bool r484806 = r484790 <= r484805;
        double r484807 = 5.054706620732832e+101;
        bool r484808 = r484790 <= r484807;
        double r484809 = 2.6000500965086023e+199;
        bool r484810 = r484790 <= r484809;
        double r484811 = r484790 / r484798;
        double r484812 = r484799 - r484811;
        double r484813 = 1.0;
        double r484814 = -r484813;
        double r484815 = r484810 ? r484812 : r484814;
        double r484816 = r484808 ? r484793 : r484815;
        double r484817 = r484806 ? r484802 : r484816;
        double r484818 = r484804 ? r484793 : r484817;
        double r484819 = r484795 ? r484802 : r484818;
        double r484820 = r484792 ? r484793 : r484819;
        return r484820;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.3
Target31.1
Herbie14.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} \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 4 regimes
  2. if (* (* y 4.0) y) < 0.0 or 8.146242059652438e-197 < (* (* y 4.0) y) < 1.89336738182365e-164 or 2.080267309844611e-17 < (* (* y 4.0) y) < 5.054706620732832e+101

    1. Initial program 25.7

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

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

    if 0.0 < (* (* y 4.0) y) < 8.146242059652438e-197 or 1.89336738182365e-164 < (* (* y 4.0) y) < 2.080267309844611e-17

    1. Initial program 16.5

      \[\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-sub16.5

      \[\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}}\]
    4. Simplified16.5

      \[\leadsto \color{blue}{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    5. Simplified16.5

      \[\leadsto \frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \color{blue}{\frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    6. Using strategy rm
    7. Applied clear-num16.5

      \[\leadsto \frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \color{blue}{\frac{1}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{\left(y \cdot 4\right) \cdot y}}}\]

    if 5.054706620732832e+101 < (* (* y 4.0) y) < 2.6000500965086023e+199

    1. Initial program 15.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-sub15.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}}\]
    4. Simplified15.1

      \[\leadsto \color{blue}{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    5. Simplified15.1

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

    if 2.6000500965086023e+199 < (* (* y 4.0) y)

    1. Initial program 50.7

      \[\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-sub50.7

      \[\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}}\]
    4. Simplified50.7

      \[\leadsto \color{blue}{\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    5. Simplified50.7

      \[\leadsto \frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \color{blue}{\frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    6. Using strategy rm
    7. Applied clear-num50.7

      \[\leadsto \frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \color{blue}{\frac{1}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{\left(y \cdot 4\right) \cdot y}}}\]
    8. Taylor expanded around 0 11.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 0.0:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 8.14624205965243804 \cdot 10^{-197}:\\ \;\;\;\;\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{1}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{\left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.89336738182365018 \cdot 10^{-164}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.080267309844611 \cdot 10^{-17}:\\ \;\;\;\;\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{1}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{\left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 5.0547066207328322 \cdot 10^{101}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.6000500965086023 \cdot 10^{199}:\\ \;\;\;\;\frac{x \cdot x}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)} - \frac{\left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

herbie shell --seed 2019198 +o rules:numerics
(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.0) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))))

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