Average Error: 31.7 → 12.8
Time: 23.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 3.222607567780329196681560572143104577428 \cdot 10^{-289}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 6.835592550358748008281275435772541106955 \cdot 10^{96}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \cdot x \le 7.775826278762702186699010750865619056054 \cdot 10^{132}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 1.421420598341031269955175034568661498389 \cdot 10^{194}:\\ \;\;\;\;\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 \cdot x \le 3.222607567780329196681560572143104577428 \cdot 10^{-289}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \le 6.835592550358748008281275435772541106955 \cdot 10^{96}:\\
\;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\

\mathbf{elif}\;x \cdot x \le 7.775826278762702186699010750865619056054 \cdot 10^{132}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \le 1.421420598341031269955175034568661498389 \cdot 10^{194}:\\
\;\;\;\;\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 r30574491 = x;
        double r30574492 = r30574491 * r30574491;
        double r30574493 = y;
        double r30574494 = 4.0;
        double r30574495 = r30574493 * r30574494;
        double r30574496 = r30574495 * r30574493;
        double r30574497 = r30574492 - r30574496;
        double r30574498 = r30574492 + r30574496;
        double r30574499 = r30574497 / r30574498;
        return r30574499;
}

double f(double x, double y) {
        double r30574500 = x;
        double r30574501 = r30574500 * r30574500;
        double r30574502 = 3.222607567780329e-289;
        bool r30574503 = r30574501 <= r30574502;
        double r30574504 = -1.0;
        double r30574505 = 6.835592550358748e+96;
        bool r30574506 = r30574501 <= r30574505;
        double r30574507 = y;
        double r30574508 = 4.0;
        double r30574509 = r30574507 * r30574508;
        double r30574510 = r30574509 * r30574507;
        double r30574511 = r30574501 - r30574510;
        double r30574512 = r30574501 + r30574510;
        double r30574513 = r30574511 / r30574512;
        double r30574514 = 7.775826278762702e+132;
        bool r30574515 = r30574501 <= r30574514;
        double r30574516 = 1.4214205983410313e+194;
        bool r30574517 = r30574501 <= r30574516;
        double r30574518 = r30574501 / r30574512;
        double r30574519 = r30574510 / r30574512;
        double r30574520 = r30574518 - r30574519;
        double r30574521 = 1.0;
        double r30574522 = r30574517 ? r30574520 : r30574521;
        double r30574523 = r30574515 ? r30574504 : r30574522;
        double r30574524 = r30574506 ? r30574513 : r30574523;
        double r30574525 = r30574503 ? r30574504 : r30574524;
        return r30574525;
}

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.7
Target31.4
Herbie12.8
\[\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 4 regimes
  2. if (* x x) < 3.222607567780329e-289 or 6.835592550358748e+96 < (* x x) < 7.775826278762702e+132

    1. Initial program 29.3

      \[\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 11.4

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

    if 3.222607567780329e-289 < (* x x) < 6.835592550358748e+96

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

    if 7.775826278762702e+132 < (* x x) < 1.4214205983410313e+194

    1. Initial program 17.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-sub17.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}}\]

    if 1.4214205983410313e+194 < (* x x)

    1. Initial program 50.4

      \[\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 10.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \le 3.222607567780329196681560572143104577428 \cdot 10^{-289}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 6.835592550358748008281275435772541106955 \cdot 10^{96}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \cdot x \le 7.775826278762702186699010750865619056054 \cdot 10^{132}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 1.421420598341031269955175034568661498389 \cdot 10^{194}:\\ \;\;\;\;\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 2019168 +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))))