Average Error: 31.3 → 12.6
Time: 2.2s
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 1.39704938829847655 \cdot 10^{-295}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.1671138564200652 \cdot 10^{-220}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) - \frac{\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 3.5288292903463466 \cdot 10^{-176}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.0279595671644782 \cdot 10^{-143}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) - \frac{\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 5.991118504563713 \cdot 10^{-125}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.90466818245601162 \cdot 10^{196}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) - \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}\;\left(y \cdot 4\right) \cdot y \le 1.39704938829847655 \cdot 10^{-295}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.1671138564200652 \cdot 10^{-220}:\\
\;\;\;\;\log \left(e^{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) - \frac{\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 3.5288292903463466 \cdot 10^{-176}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.0279595671644782 \cdot 10^{-143}:\\
\;\;\;\;\log \left(e^{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) - \frac{\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 5.991118504563713 \cdot 10^{-125}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.90466818245601162 \cdot 10^{196}:\\
\;\;\;\;\log \left(e^{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) - \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 r777006 = x;
        double r777007 = r777006 * r777006;
        double r777008 = y;
        double r777009 = 4.0;
        double r777010 = r777008 * r777009;
        double r777011 = r777010 * r777008;
        double r777012 = r777007 - r777011;
        double r777013 = r777007 + r777011;
        double r777014 = r777012 / r777013;
        return r777014;
}

double f(double x, double y) {
        double r777015 = y;
        double r777016 = 4.0;
        double r777017 = r777015 * r777016;
        double r777018 = r777017 * r777015;
        double r777019 = 1.3970493882984765e-295;
        bool r777020 = r777018 <= r777019;
        double r777021 = 1.0;
        double r777022 = 1.1671138564200652e-220;
        bool r777023 = r777018 <= r777022;
        double r777024 = x;
        double r777025 = r777024 * r777024;
        double r777026 = r777025 + r777018;
        double r777027 = r777025 / r777026;
        double r777028 = exp(r777027);
        double r777029 = log(r777028);
        double r777030 = r777018 / r777026;
        double r777031 = r777029 - r777030;
        double r777032 = 3.5288292903463466e-176;
        bool r777033 = r777018 <= r777032;
        double r777034 = 2.0279595671644782e-143;
        bool r777035 = r777018 <= r777034;
        double r777036 = 5.991118504563713e-125;
        bool r777037 = r777018 <= r777036;
        double r777038 = 1.9046681824560116e+196;
        bool r777039 = r777018 <= r777038;
        double r777040 = -1.0;
        double r777041 = r777039 ? r777031 : r777040;
        double r777042 = r777037 ? r777021 : r777041;
        double r777043 = r777035 ? r777031 : r777042;
        double r777044 = r777033 ? r777021 : r777043;
        double r777045 = r777023 ? r777031 : r777044;
        double r777046 = r777020 ? r777021 : r777045;
        return r777046;
}

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 (* (* y 4.0) y) < 1.3970493882984765e-295 or 1.1671138564200652e-220 < (* (* y 4.0) y) < 3.5288292903463466e-176 or 2.0279595671644782e-143 < (* (* y 4.0) y) < 5.991118504563713e-125

    1. Initial program 28.1

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

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

    if 1.3970493882984765e-295 < (* (* y 4.0) y) < 1.1671138564200652e-220 or 3.5288292903463466e-176 < (* (* y 4.0) y) < 2.0279595671644782e-143 or 5.991118504563713e-125 < (* (* y 4.0) y) < 1.9046681824560116e+196

    1. Initial program 14.3

      \[\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-sub14.3

      \[\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}}\]
    4. Using strategy rm
    5. Applied add-log-exp14.3

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

    if 1.9046681824560116e+196 < (* (* y 4.0) y)

    1. Initial program 51.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 1.39704938829847655 \cdot 10^{-295}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.1671138564200652 \cdot 10^{-220}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) - \frac{\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 3.5288292903463466 \cdot 10^{-176}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 2.0279595671644782 \cdot 10^{-143}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) - \frac{\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 5.991118504563713 \cdot 10^{-125}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 1.90466818245601162 \cdot 10^{196}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) - \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 2020065 
(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))))