Average Error: 31.3 → 12.6
Time: 1.7s
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 \cdot x \le 1.04662384361210072 \cdot 10^{-202}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 1.3005275433696336 \cdot 10^{250}:\\ \;\;\;\;\log \left(\frac{e^{\frac{x}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x}}}}{e^{\frac{y \cdot 4}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{y}}}}\right)\\ \mathbf{elif}\;x \cdot x \le 2.97717800904674578 \cdot 10^{272}:\\ \;\;\;\;-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 \cdot x \le 1.04662384361210072 \cdot 10^{-202}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \le 1.3005275433696336 \cdot 10^{250}:\\
\;\;\;\;\log \left(\frac{e^{\frac{x}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x}}}}{e^{\frac{y \cdot 4}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{y}}}}\right)\\

\mathbf{elif}\;x \cdot x \le 2.97717800904674578 \cdot 10^{272}:\\
\;\;\;\;-1\\

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

\end{array}
double f(double x, double y) {
        double r597119 = x;
        double r597120 = r597119 * r597119;
        double r597121 = y;
        double r597122 = 4.0;
        double r597123 = r597121 * r597122;
        double r597124 = r597123 * r597121;
        double r597125 = r597120 - r597124;
        double r597126 = r597120 + r597124;
        double r597127 = r597125 / r597126;
        return r597127;
}

double f(double x, double y) {
        double r597128 = x;
        double r597129 = r597128 * r597128;
        double r597130 = 1.0466238436121007e-202;
        bool r597131 = r597129 <= r597130;
        double r597132 = -1.0;
        double r597133 = 1.3005275433696336e+250;
        bool r597134 = r597129 <= r597133;
        double r597135 = y;
        double r597136 = 4.0;
        double r597137 = r597135 * r597136;
        double r597138 = r597137 * r597135;
        double r597139 = r597129 + r597138;
        double r597140 = r597139 / r597128;
        double r597141 = r597128 / r597140;
        double r597142 = exp(r597141);
        double r597143 = r597139 / r597135;
        double r597144 = r597137 / r597143;
        double r597145 = exp(r597144);
        double r597146 = r597142 / r597145;
        double r597147 = log(r597146);
        double r597148 = 2.977178009046746e+272;
        bool r597149 = r597129 <= r597148;
        double r597150 = 1.0;
        double r597151 = r597149 ? r597132 : r597150;
        double r597152 = r597134 ? r597147 : r597151;
        double r597153 = r597131 ? r597132 : r597152;
        return r597153;
}

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.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.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 x) < 1.0466238436121007e-202 or 1.3005275433696336e+250 < (* x x) < 2.977178009046746e+272

    1. Initial program 25.6

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

    if 1.0466238436121007e-202 < (* x x) < 1.3005275433696336e+250

    1. Initial program 15.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 add-sqr-sqrt15.7

      \[\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. Using strategy rm
    5. Applied add-log-exp15.7

      \[\leadsto \color{blue}{\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y} \cdot \sqrt{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\right)}\]
    6. Simplified15.2

      \[\leadsto \log \color{blue}{\left(\frac{e^{\frac{x}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x}}}}{e^{\frac{y \cdot 4}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{y}}}}\right)}\]

    if 2.977178009046746e+272 < (* x x)

    1. Initial program 59.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 8.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \le 1.04662384361210072 \cdot 10^{-202}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 1.3005275433696336 \cdot 10^{250}:\\ \;\;\;\;\log \left(\frac{e^{\frac{x}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x}}}}{e^{\frac{y \cdot 4}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{y}}}}\right)\\ \mathbf{elif}\;x \cdot x \le 2.97717800904674578 \cdot 10^{272}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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