Average Error: 31.9 → 14.3
Time: 1.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}\;\left(y \cdot 4\right) \cdot y \le 4.6888524311529329 \cdot 10^{-150}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 3.03257274616522845 \cdot 10^{-117}:\\ \;\;\;\;\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}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 3.80478009492825009 \cdot 10^{-5}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 7.769551355955981 \cdot 10^{204}:\\ \;\;\;\;\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}\;\left(y \cdot 4\right) \cdot y \le 4.6888524311529329 \cdot 10^{-150}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 3.03257274616522845 \cdot 10^{-117}:\\
\;\;\;\;\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}\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 3.80478009492825009 \cdot 10^{-5}:\\
\;\;\;\;1\\

\mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 7.769551355955981 \cdot 10^{204}:\\
\;\;\;\;\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 r707267 = x;
        double r707268 = r707267 * r707267;
        double r707269 = y;
        double r707270 = 4.0;
        double r707271 = r707269 * r707270;
        double r707272 = r707271 * r707269;
        double r707273 = r707268 - r707272;
        double r707274 = r707268 + r707272;
        double r707275 = r707273 / r707274;
        return r707275;
}

double f(double x, double y) {
        double r707276 = y;
        double r707277 = 4.0;
        double r707278 = r707276 * r707277;
        double r707279 = r707278 * r707276;
        double r707280 = 4.688852431152933e-150;
        bool r707281 = r707279 <= r707280;
        double r707282 = 1.0;
        double r707283 = 3.0325727461652284e-117;
        bool r707284 = r707279 <= r707283;
        double r707285 = x;
        double r707286 = r707285 * r707285;
        double r707287 = r707286 + r707279;
        double r707288 = r707286 / r707287;
        double r707289 = r707279 / r707287;
        double r707290 = r707288 - r707289;
        double r707291 = 3.80478009492825e-05;
        bool r707292 = r707279 <= r707291;
        double r707293 = 7.769551355955981e+204;
        bool r707294 = r707279 <= r707293;
        double r707295 = r707286 - r707279;
        double r707296 = r707295 / r707287;
        double r707297 = -1.0;
        double r707298 = r707294 ? r707296 : r707297;
        double r707299 = r707292 ? r707282 : r707298;
        double r707300 = r707284 ? r707290 : r707299;
        double r707301 = r707281 ? r707282 : r707300;
        return r707301;
}

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.9
Target31.6
Herbie14.3
\[\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.688852431152933e-150 or 3.0325727461652284e-117 < (* (* y 4.0) y) < 3.80478009492825e-05

    1. Initial program 24.3

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

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

    if 4.688852431152933e-150 < (* (* y 4.0) y) < 3.0325727461652284e-117

    1. Initial program 12.2

      \[\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-sub12.2

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

    if 3.80478009492825e-05 < (* (* y 4.0) y) < 7.769551355955981e+204

    1. Initial program 16.4

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

    if 7.769551355955981e+204 < (* (* y 4.0) y)

    1. Initial program 52.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 0 11.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(y \cdot 4\right) \cdot y \le 4.6888524311529329 \cdot 10^{-150}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 3.03257274616522845 \cdot 10^{-117}:\\ \;\;\;\;\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}\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 3.80478009492825009 \cdot 10^{-5}:\\ \;\;\;\;1\\ \mathbf{elif}\;\left(y \cdot 4\right) \cdot y \le 7.769551355955981 \cdot 10^{204}:\\ \;\;\;\;\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 2020039 
(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))))