Average Error: 31.5 → 12.9
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}\;\left(y \cdot 4\right) \cdot y \le 4.94066 \cdot 10^{-324}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.6510033806694153 \cdot 10^{-246}:\\ \;\;\;\;\frac{x \cdot x - \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 2.00910593225652596 \cdot 10^{-105}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.23283737728315802 \cdot 10^{293}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \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 4.94066 \cdot 10^{-324}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.6510033806694153 \cdot 10^{-246}:\\
\;\;\;\;\frac{x \cdot x - \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 2.00910593225652596 \cdot 10^{-105}:\\
\;\;\;\;1\\

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

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

\end{array}
double f(double x, double y) {
        double r748648 = x;
        double r748649 = r748648 * r748648;
        double r748650 = y;
        double r748651 = 4.0;
        double r748652 = r748650 * r748651;
        double r748653 = r748652 * r748650;
        double r748654 = r748649 - r748653;
        double r748655 = r748649 + r748653;
        double r748656 = r748654 / r748655;
        return r748656;
}

double f(double x, double y) {
        double r748657 = y;
        double r748658 = 4.0;
        double r748659 = r748657 * r748658;
        double r748660 = r748659 * r748657;
        double r748661 = 4.9406564584125e-324;
        bool r748662 = r748660 <= r748661;
        double r748663 = 1.0;
        double r748664 = 2.6510033806694153e-246;
        bool r748665 = r748660 <= r748664;
        double r748666 = x;
        double r748667 = r748666 * r748666;
        double r748668 = r748667 - r748660;
        double r748669 = r748667 + r748660;
        double r748670 = r748668 / r748669;
        double r748671 = 2.009105932256526e-105;
        bool r748672 = r748660 <= r748671;
        double r748673 = 2.232837377283158e+293;
        bool r748674 = r748660 <= r748673;
        double r748675 = exp(r748670);
        double r748676 = log(r748675);
        double r748677 = -1.0;
        double r748678 = r748674 ? r748676 : r748677;
        double r748679 = r748672 ? r748663 : r748678;
        double r748680 = r748665 ? r748670 : r748679;
        double r748681 = r748662 ? r748663 : r748680;
        return r748681;
}

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.5
Target31.2
Herbie12.9
\[\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 4 regimes
  2. if (* (* y 4.0) y) < 4.9406564584125e-324 or 2.6510033806694153e-246 < (* (* y 4.0) y) < 2.009105932256526e-105

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

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

    if 4.9406564584125e-324 < (* (* y 4.0) y) < 2.6510033806694153e-246

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

    if 2.009105932256526e-105 < (* (* y 4.0) y) < 2.232837377283158e+293

    1. Initial program 15.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 add-log-exp15.5

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

    if 2.232837377283158e+293 < (* (* y 4.0) y)

    1. Initial program 61.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 9.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 4.94066 \cdot 10^{-324}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.6510033806694153 \cdot 10^{-246}:\\ \;\;\;\;\frac{x \cdot x - \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 2.00910593225652596 \cdot 10^{-105}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.23283737728315802 \cdot 10^{293}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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