Average Error: 31.3 → 12.7
Time: 4.8s
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 -7.928259414816123188229698239228701594261 \cdot 10^{152}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.670806219743054366544845033863121817394 \cdot 10^{-99}:\\ \;\;\;\;\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}\;x \le 3.339425016971985733812234822017933716285 \cdot 10^{-120}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 371427111337525632:\\ \;\;\;\;\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}\;x \le -7.928259414816123188229698239228701594261 \cdot 10^{152}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -1.670806219743054366544845033863121817394 \cdot 10^{-99}:\\
\;\;\;\;\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}\;x \le 3.339425016971985733812234822017933716285 \cdot 10^{-120}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 371427111337525632:\\
\;\;\;\;\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 r706762 = x;
        double r706763 = r706762 * r706762;
        double r706764 = y;
        double r706765 = 4.0;
        double r706766 = r706764 * r706765;
        double r706767 = r706766 * r706764;
        double r706768 = r706763 - r706767;
        double r706769 = r706763 + r706767;
        double r706770 = r706768 / r706769;
        return r706770;
}

double f(double x, double y) {
        double r706771 = x;
        double r706772 = -7.928259414816123e+152;
        bool r706773 = r706771 <= r706772;
        double r706774 = 1.0;
        double r706775 = -1.6708062197430544e-99;
        bool r706776 = r706771 <= r706775;
        double r706777 = r706771 * r706771;
        double r706778 = y;
        double r706779 = 4.0;
        double r706780 = r706778 * r706779;
        double r706781 = r706780 * r706778;
        double r706782 = r706777 + r706781;
        double r706783 = r706777 / r706782;
        double r706784 = r706781 / r706782;
        double r706785 = r706783 - r706784;
        double r706786 = 3.339425016971986e-120;
        bool r706787 = r706771 <= r706786;
        double r706788 = 1.0;
        double r706789 = -r706788;
        double r706790 = 3.714271113375256e+17;
        bool r706791 = r706771 <= r706790;
        double r706792 = r706791 ? r706785 : r706774;
        double r706793 = r706787 ? r706789 : r706792;
        double r706794 = r706776 ? r706785 : r706793;
        double r706795 = r706773 ? r706774 : r706794;
        return r706795;
}

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.3
Target31.0
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} \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 x < -7.928259414816123e+152 or 3.714271113375256e+17 < x

    1. Initial program 49.2

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

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

    if -7.928259414816123e+152 < x < -1.6708062197430544e-99 or 3.339425016971986e-120 < x < 3.714271113375256e+17

    1. Initial program 15.6

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

      \[\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 -1.6708062197430544e-99 < x < 3.339425016971986e-120

    1. Initial program 26.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-sub26.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}}\]
    4. Taylor expanded around 0 10.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -7.928259414816123188229698239228701594261 \cdot 10^{152}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.670806219743054366544845033863121817394 \cdot 10^{-99}:\\ \;\;\;\;\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}\;x \le 3.339425016971985733812234822017933716285 \cdot 10^{-120}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 371427111337525632:\\ \;\;\;\;\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 2019350 
(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))))