Average Error: 31.8 → 13.6
Time: 2.6s
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}\;y \le -2.2855110788897515 \cdot 10^{145}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -4.6422537795675754 \cdot 10^{-94}:\\ \;\;\;\;\log \left(e^{\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x \cdot x - \left(y \cdot 4\right) \cdot y}}}\right)\\ \mathbf{elif}\;y \le 1.15085871997988 \cdot 10^{-152}:\\ \;\;\;\;\log \left(e^{1}\right)\\ \mathbf{elif}\;y \le 4.6225019863970643 \cdot 10^{28}:\\ \;\;\;\;\log \left(e^{\frac{1}{\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}\;y \le -2.2855110788897515 \cdot 10^{145}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \le 1.15085871997988 \cdot 10^{-152}:\\
\;\;\;\;\log \left(e^{1}\right)\\

\mathbf{elif}\;y \le 4.6225019863970643 \cdot 10^{28}:\\
\;\;\;\;\log \left(e^{\frac{1}{\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 r660725 = x;
        double r660726 = r660725 * r660725;
        double r660727 = y;
        double r660728 = 4.0;
        double r660729 = r660727 * r660728;
        double r660730 = r660729 * r660727;
        double r660731 = r660726 - r660730;
        double r660732 = r660726 + r660730;
        double r660733 = r660731 / r660732;
        return r660733;
}

double f(double x, double y) {
        double r660734 = y;
        double r660735 = -2.2855110788897515e+145;
        bool r660736 = r660734 <= r660735;
        double r660737 = -1.0;
        double r660738 = -4.6422537795675754e-94;
        bool r660739 = r660734 <= r660738;
        double r660740 = 1.0;
        double r660741 = x;
        double r660742 = r660741 * r660741;
        double r660743 = 4.0;
        double r660744 = r660734 * r660743;
        double r660745 = r660744 * r660734;
        double r660746 = r660742 + r660745;
        double r660747 = r660742 - r660745;
        double r660748 = r660746 / r660747;
        double r660749 = r660740 / r660748;
        double r660750 = exp(r660749);
        double r660751 = log(r660750);
        double r660752 = 1.15085871997988e-152;
        bool r660753 = r660734 <= r660752;
        double r660754 = exp(r660740);
        double r660755 = log(r660754);
        double r660756 = 4.622501986397064e+28;
        bool r660757 = r660734 <= r660756;
        double r660758 = r660757 ? r660751 : r660737;
        double r660759 = r660753 ? r660755 : r660758;
        double r660760 = r660739 ? r660751 : r660759;
        double r660761 = r660736 ? r660737 : r660760;
        return r660761;
}

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.8
Target31.4
Herbie13.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 y < -2.2855110788897515e+145 or 4.622501986397064e+28 < y

    1. Initial program 48.9

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

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

    if -2.2855110788897515e+145 < y < -4.6422537795675754e-94 or 1.15085871997988e-152 < y < 4.622501986397064e+28

    1. Initial program 17.0

      \[\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-exp17.0

      \[\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)}\]
    4. Using strategy rm
    5. Applied clear-num17.0

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

    if -4.6422537795675754e-94 < y < 1.15085871997988e-152

    1. Initial program 28.0

      \[\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-exp28.0

      \[\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)}\]
    4. Taylor expanded around inf 11.1

      \[\leadsto \log \left(e^{\color{blue}{1}}\right)\]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2.2855110788897515 \cdot 10^{145}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -4.6422537795675754 \cdot 10^{-94}:\\ \;\;\;\;\log \left(e^{\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x \cdot x - \left(y \cdot 4\right) \cdot y}}}\right)\\ \mathbf{elif}\;y \le 1.15085871997988 \cdot 10^{-152}:\\ \;\;\;\;\log \left(e^{1}\right)\\ \mathbf{elif}\;y \le 4.6225019863970643 \cdot 10^{28}:\\ \;\;\;\;\log \left(e^{\frac{1}{\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 2020081 
(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))))