Average Error: 31.1 → 12.2
Time: 4.0s
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 8.48677548777607887 \cdot 10^{-264}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 2.1340718332425224 \cdot 10^{-245}:\\ \;\;\;\;\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 2.7325230911480087 \cdot 10^{-173}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 4.68601800110195913 \cdot 10^{264}:\\ \;\;\;\;\frac{x \cdot x - \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 8.48677548777607887 \cdot 10^{-264}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \le 2.1340718332425224 \cdot 10^{-245}:\\
\;\;\;\;\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 2.7325230911480087 \cdot 10^{-173}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \cdot x \le 4.68601800110195913 \cdot 10^{264}:\\
\;\;\;\;\frac{x \cdot x - \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 r782128 = x;
        double r782129 = r782128 * r782128;
        double r782130 = y;
        double r782131 = 4.0;
        double r782132 = r782130 * r782131;
        double r782133 = r782132 * r782130;
        double r782134 = r782129 - r782133;
        double r782135 = r782129 + r782133;
        double r782136 = r782134 / r782135;
        return r782136;
}

double f(double x, double y) {
        double r782137 = x;
        double r782138 = r782137 * r782137;
        double r782139 = 8.486775487776079e-264;
        bool r782140 = r782138 <= r782139;
        double r782141 = -1.0;
        double r782142 = 2.1340718332425224e-245;
        bool r782143 = r782138 <= r782142;
        double r782144 = y;
        double r782145 = 4.0;
        double r782146 = r782144 * r782145;
        double r782147 = r782146 * r782144;
        double r782148 = r782138 - r782147;
        double r782149 = r782138 + r782147;
        double r782150 = r782148 / r782149;
        double r782151 = 2.7325230911480087e-173;
        bool r782152 = r782138 <= r782151;
        double r782153 = 4.686018001101959e+264;
        bool r782154 = r782138 <= r782153;
        double r782155 = 1.0;
        double r782156 = r782154 ? r782150 : r782155;
        double r782157 = r782152 ? r782141 : r782156;
        double r782158 = r782143 ? r782150 : r782157;
        double r782159 = r782140 ? r782141 : r782158;
        return r782159;
}

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.1
Target30.8
Herbie12.2
\[\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 (* x x) < 8.486775487776079e-264 or 2.1340718332425224e-245 < (* x x) < 2.7325230911480087e-173

    1. Initial program 26.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 11.1

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

    if 8.486775487776079e-264 < (* x x) < 2.1340718332425224e-245 or 2.7325230911480087e-173 < (* x x) < 4.686018001101959e+264

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

    if 4.686018001101959e+264 < (* x x)

    1. Initial program 57.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 inf 9.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \le 8.48677548777607887 \cdot 10^{-264}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 2.1340718332425224 \cdot 10^{-245}:\\ \;\;\;\;\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 2.7325230911480087 \cdot 10^{-173}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \cdot x \le 4.68601800110195913 \cdot 10^{264}:\\ \;\;\;\;\frac{x \cdot x - \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 2020045 
(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))))