Average Error: 31.9 → 13.2
Time: 9.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}\;y \le -1.301374440507404895907194560242418600608 \cdot 10^{46}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.325487455469303882090057398488652321276 \cdot 10^{-118}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot \left(4 \cdot y\right)}{x \cdot x - y \cdot \left(4 \cdot y\right)}}\\ \mathbf{elif}\;y \le 4.25620766706611866924466504395368552162 \cdot 10^{-88}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 224508924829977781598467292686974976:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot \left(4 \cdot y\right)}{x \cdot x - y \cdot \left(4 \cdot y\right)}}\\ \mathbf{elif}\;y \le 1.385619300047896001176212011534409289571 \cdot 10^{55}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.721661522519145467939207901613782215678 \cdot 10^{119}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot \left(4 \cdot y\right)}{x \cdot x - y \cdot \left(4 \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 -1.301374440507404895907194560242418600608 \cdot 10^{46}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.325487455469303882090057398488652321276 \cdot 10^{-118}:\\
\;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot \left(4 \cdot y\right)}{x \cdot x - y \cdot \left(4 \cdot y\right)}}\\

\mathbf{elif}\;y \le 4.25620766706611866924466504395368552162 \cdot 10^{-88}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 224508924829977781598467292686974976:\\
\;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot \left(4 \cdot y\right)}{x \cdot x - y \cdot \left(4 \cdot y\right)}}\\

\mathbf{elif}\;y \le 1.385619300047896001176212011534409289571 \cdot 10^{55}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 1.721661522519145467939207901613782215678 \cdot 10^{119}:\\
\;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot \left(4 \cdot y\right)}{x \cdot x - y \cdot \left(4 \cdot y\right)}}\\

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

\end{array}
double f(double x, double y) {
        double r27584442 = x;
        double r27584443 = r27584442 * r27584442;
        double r27584444 = y;
        double r27584445 = 4.0;
        double r27584446 = r27584444 * r27584445;
        double r27584447 = r27584446 * r27584444;
        double r27584448 = r27584443 - r27584447;
        double r27584449 = r27584443 + r27584447;
        double r27584450 = r27584448 / r27584449;
        return r27584450;
}

double f(double x, double y) {
        double r27584451 = y;
        double r27584452 = -1.301374440507405e+46;
        bool r27584453 = r27584451 <= r27584452;
        double r27584454 = -1.0;
        double r27584455 = -1.3254874554693039e-118;
        bool r27584456 = r27584451 <= r27584455;
        double r27584457 = 1.0;
        double r27584458 = x;
        double r27584459 = r27584458 * r27584458;
        double r27584460 = 4.0;
        double r27584461 = r27584460 * r27584451;
        double r27584462 = r27584451 * r27584461;
        double r27584463 = r27584459 + r27584462;
        double r27584464 = r27584459 - r27584462;
        double r27584465 = r27584463 / r27584464;
        double r27584466 = r27584457 / r27584465;
        double r27584467 = 4.2562076670661187e-88;
        bool r27584468 = r27584451 <= r27584467;
        double r27584469 = 2.245089248299778e+35;
        bool r27584470 = r27584451 <= r27584469;
        double r27584471 = 1.385619300047896e+55;
        bool r27584472 = r27584451 <= r27584471;
        double r27584473 = 1.7216615225191455e+119;
        bool r27584474 = r27584451 <= r27584473;
        double r27584475 = r27584474 ? r27584466 : r27584454;
        double r27584476 = r27584472 ? r27584457 : r27584475;
        double r27584477 = r27584470 ? r27584466 : r27584476;
        double r27584478 = r27584468 ? r27584457 : r27584477;
        double r27584479 = r27584456 ? r27584466 : r27584478;
        double r27584480 = r27584453 ? r27584454 : r27584479;
        return r27584480;
}

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
Herbie13.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.9743233849626781184483093056769575923681:\\ \;\;\;\;\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 < -1.301374440507405e+46 or 1.7216615225191455e+119 < y

    1. Initial program 48.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 0 11.9

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

    if -1.301374440507405e+46 < y < -1.3254874554693039e-118 or 4.2562076670661187e-88 < y < 2.245089248299778e+35 or 1.385619300047896e+55 < y < 1.7216615225191455e+119

    1. Initial program 16.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 clear-num16.0

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

    if -1.3254874554693039e-118 < y < 4.2562076670661187e-88 or 2.245089248299778e+35 < y < 1.385619300047896e+55

    1. Initial program 27.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.301374440507404895907194560242418600608 \cdot 10^{46}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.325487455469303882090057398488652321276 \cdot 10^{-118}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot \left(4 \cdot y\right)}{x \cdot x - y \cdot \left(4 \cdot y\right)}}\\ \mathbf{elif}\;y \le 4.25620766706611866924466504395368552162 \cdot 10^{-88}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 224508924829977781598467292686974976:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot \left(4 \cdot y\right)}{x \cdot x - y \cdot \left(4 \cdot y\right)}}\\ \mathbf{elif}\;y \le 1.385619300047896001176212011534409289571 \cdot 10^{55}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.721661522519145467939207901613782215678 \cdot 10^{119}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + y \cdot \left(4 \cdot y\right)}{x \cdot x - y \cdot \left(4 \cdot y\right)}}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

herbie shell --seed 2019169 +o rules:numerics
(FPCore (x y)
  :name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"

  :herbie-target
  (if (< (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))) 0.9743233849626781) (- (/ (* x x) (+ (* x x) (* (* y y) 4.0))) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))) (- (pow (/ x (sqrt (+ (* x x) (* (* y y) 4.0)))) 2.0) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))))

  (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))