Average Error: 31.2 → 12.6
Time: 3.4s
Precision: 64
\[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;y \cdot \left(y \cdot 4.0\right) \le 5.256606017817734 \cdot 10^{-308}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4.0\right) \le 1.6350568935112376 \cdot 10^{+269}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4.0\right)}{x \cdot x + y \cdot \left(y \cdot 4.0\right)}\\ \mathbf{elif}\;y \cdot \left(y \cdot 4.0\right) \le 2.4786518810190947 \cdot 10^{+298}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1.0\\ \end{array}\]
\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}
\begin{array}{l}
\mathbf{if}\;y \cdot \left(y \cdot 4.0\right) \le 5.256606017817734 \cdot 10^{-308}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \cdot \left(y \cdot 4.0\right) \le 1.6350568935112376 \cdot 10^{+269}:\\
\;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4.0\right)}{x \cdot x + y \cdot \left(y \cdot 4.0\right)}\\

\mathbf{elif}\;y \cdot \left(y \cdot 4.0\right) \le 2.4786518810190947 \cdot 10^{+298}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r12888584 = x;
        double r12888585 = r12888584 * r12888584;
        double r12888586 = y;
        double r12888587 = 4.0;
        double r12888588 = r12888586 * r12888587;
        double r12888589 = r12888588 * r12888586;
        double r12888590 = r12888585 - r12888589;
        double r12888591 = r12888585 + r12888589;
        double r12888592 = r12888590 / r12888591;
        return r12888592;
}

double f(double x, double y) {
        double r12888593 = y;
        double r12888594 = 4.0;
        double r12888595 = r12888593 * r12888594;
        double r12888596 = r12888593 * r12888595;
        double r12888597 = 5.256606017817734e-308;
        bool r12888598 = r12888596 <= r12888597;
        double r12888599 = 1.0;
        double r12888600 = 1.6350568935112376e+269;
        bool r12888601 = r12888596 <= r12888600;
        double r12888602 = x;
        double r12888603 = r12888602 * r12888602;
        double r12888604 = r12888603 - r12888596;
        double r12888605 = r12888603 + r12888596;
        double r12888606 = r12888604 / r12888605;
        double r12888607 = 2.4786518810190947e+298;
        bool r12888608 = r12888596 <= r12888607;
        double r12888609 = -1.0;
        double r12888610 = r12888608 ? r12888599 : r12888609;
        double r12888611 = r12888601 ? r12888606 : r12888610;
        double r12888612 = r12888598 ? r12888599 : r12888611;
        return r12888612;
}

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.2
Target31.2
Herbie12.6
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} \lt 0.9743233849626781:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot y\right) \cdot 4.0} - \frac{\left(y \cdot y\right) \cdot 4.0}{x \cdot x + \left(y \cdot y\right) \cdot 4.0}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x}{\sqrt{x \cdot x + \left(y \cdot y\right) \cdot 4.0}}\right)}^{2} - \frac{\left(y \cdot y\right) \cdot 4.0}{x \cdot x + \left(y \cdot y\right) \cdot 4.0}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if (* (* y 4.0) y) < 5.256606017817734e-308 or 1.6350568935112376e+269 < (* (* y 4.0) y) < 2.4786518810190947e+298

    1. Initial program 29.5

      \[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
    2. Taylor expanded around inf 11.5

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

    if 5.256606017817734e-308 < (* (* y 4.0) y) < 1.6350568935112376e+269

    1. Initial program 15.5

      \[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]

    if 2.4786518810190947e+298 < (* (* y 4.0) y)

    1. Initial program 61.7

      \[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
    2. Taylor expanded around 0 8.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot \left(y \cdot 4.0\right) \le 5.256606017817734 \cdot 10^{-308}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4.0\right) \le 1.6350568935112376 \cdot 10^{+269}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4.0\right)}{x \cdot x + y \cdot \left(y \cdot 4.0\right)}\\ \mathbf{elif}\;y \cdot \left(y \cdot 4.0\right) \le 2.4786518810190947 \cdot 10^{+298}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1.0\\ \end{array}\]

Reproduce

herbie shell --seed 2019156 +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) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))))

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