Average Error: 32.2 → 13.6
Time: 2.6s
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 3.555296387473610131894589033479720995539 \cdot 10^{-320}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 6.796343694084571001073879733570555857418 \cdot 10^{-30}:\\ \;\;\;\;\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}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 346611751697267904479232:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 3.303575063990275761709788655917798036004 \cdot 10^{146}:\\ \;\;\;\;\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}\\ \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 3.555296387473610131894589033479720995539 \cdot 10^{-320}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 6.796343694084571001073879733570555857418 \cdot 10^{-30}:\\
\;\;\;\;\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}\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 346611751697267904479232:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 3.303575063990275761709788655917798036004 \cdot 10^{146}:\\
\;\;\;\;\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}\\

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

\end{array}
double f(double x, double y) {
        double r732832 = x;
        double r732833 = r732832 * r732832;
        double r732834 = y;
        double r732835 = 4.0;
        double r732836 = r732834 * r732835;
        double r732837 = r732836 * r732834;
        double r732838 = r732833 - r732837;
        double r732839 = r732833 + r732837;
        double r732840 = r732838 / r732839;
        return r732840;
}

double f(double x, double y) {
        double r732841 = y;
        double r732842 = 4.0;
        double r732843 = r732841 * r732842;
        double r732844 = r732843 * r732841;
        double r732845 = 3.5552963874736e-320;
        bool r732846 = r732844 <= r732845;
        double r732847 = 1.0;
        double r732848 = 6.796343694084571e-30;
        bool r732849 = r732844 <= r732848;
        double r732850 = x;
        double r732851 = r732850 * r732850;
        double r732852 = r732851 + r732844;
        double r732853 = r732851 / r732852;
        double r732854 = r732844 / r732852;
        double r732855 = r732853 - r732854;
        double r732856 = 3.466117516972679e+23;
        bool r732857 = r732844 <= r732856;
        double r732858 = 3.3035750639902758e+146;
        bool r732859 = r732844 <= r732858;
        double r732860 = -1.0;
        double r732861 = r732859 ? r732855 : r732860;
        double r732862 = r732857 ? r732847 : r732861;
        double r732863 = r732849 ? r732855 : r732862;
        double r732864 = r732846 ? r732847 : r732863;
        return r732864;
}

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.2
Target31.8
Herbie13.6
\[\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.9743233849626781184483093056769575923681:\\ \;\;\;\;\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 (* (* y 4.0) y) < 3.5552963874736e-320 or 6.796343694084571e-30 < (* (* y 4.0) y) < 3.466117516972679e+23

    1. Initial program 28.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 11.2

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

    if 3.5552963874736e-320 < (* (* y 4.0) y) < 6.796343694084571e-30 or 3.466117516972679e+23 < (* (* y 4.0) y) < 3.3035750639902758e+146

    1. Initial program 16.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 div-sub16.8

      \[\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 3.3035750639902758e+146 < (* (* y 4.0) y)

    1. Initial program 47.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 12.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 3.555296387473610131894589033479720995539 \cdot 10^{-320}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 6.796343694084571001073879733570555857418 \cdot 10^{-30}:\\ \;\;\;\;\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}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 346611751697267904479232:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 3.303575063990275761709788655917798036004 \cdot 10^{146}:\\ \;\;\;\;\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}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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