Average Error: 31.0 → 4.2
Time: 10.7s
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.68161050468433770508489338078059891853 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.677786749685249256830229513777092962685 \cdot 10^{-159}:\\ \;\;\;\;\frac{x}{4 \cdot \frac{y \cdot y}{x} + x} - \frac{4 \cdot y}{\frac{x \cdot x + \left(4 \cdot y\right) \cdot y}{y}}\\ \mathbf{elif}\;y \le 4.876101206523020878134736358929559551059 \cdot 10^{-180}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 3.108823225235708388607355653893818255588 \cdot 10^{124}:\\ \;\;\;\;\frac{x}{4 \cdot \frac{y \cdot y}{x} + x} - \frac{4 \cdot y}{\frac{x \cdot x + \left(4 \cdot y\right) \cdot y}{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}\;y \le -2.68161050468433770508489338078059891853 \cdot 10^{153}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \le 4.876101206523020878134736358929559551059 \cdot 10^{-180}:\\
\;\;\;\;1\\

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

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

\end{array}
double f(double x, double y) {
        double r632488 = x;
        double r632489 = r632488 * r632488;
        double r632490 = y;
        double r632491 = 4.0;
        double r632492 = r632490 * r632491;
        double r632493 = r632492 * r632490;
        double r632494 = r632489 - r632493;
        double r632495 = r632489 + r632493;
        double r632496 = r632494 / r632495;
        return r632496;
}

double f(double x, double y) {
        double r632497 = y;
        double r632498 = -2.6816105046843377e+153;
        bool r632499 = r632497 <= r632498;
        double r632500 = -1.0;
        double r632501 = -2.6777867496852493e-159;
        bool r632502 = r632497 <= r632501;
        double r632503 = x;
        double r632504 = 4.0;
        double r632505 = r632497 * r632497;
        double r632506 = r632505 / r632503;
        double r632507 = r632504 * r632506;
        double r632508 = r632507 + r632503;
        double r632509 = r632503 / r632508;
        double r632510 = r632504 * r632497;
        double r632511 = r632503 * r632503;
        double r632512 = r632510 * r632497;
        double r632513 = r632511 + r632512;
        double r632514 = r632513 / r632497;
        double r632515 = r632510 / r632514;
        double r632516 = r632509 - r632515;
        double r632517 = 4.876101206523021e-180;
        bool r632518 = r632497 <= r632517;
        double r632519 = 1.0;
        double r632520 = 3.1088232252357084e+124;
        bool r632521 = r632497 <= r632520;
        double r632522 = r632521 ? r632516 : r632500;
        double r632523 = r632518 ? r632519 : r632522;
        double r632524 = r632502 ? r632516 : r632523;
        double r632525 = r632499 ? r632500 : r632524;
        return r632525;
}

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.0
Target30.7
Herbie4.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 < -2.6816105046843377e+153 or 3.1088232252357084e+124 < y

    1. Initial program 59.9

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

      \[\leadsto \color{blue}{\frac{x \cdot x - 4 \cdot \left(y \cdot y\right)}{x \cdot x + 4 \cdot \left(y \cdot y\right)}}\]
    3. Taylor expanded around 0 9.0

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

    if -2.6816105046843377e+153 < y < -2.6777867496852493e-159 or 4.876101206523021e-180 < y < 3.1088232252357084e+124

    1. Initial program 15.8

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

      \[\leadsto \color{blue}{\frac{x \cdot x - 4 \cdot \left(y \cdot y\right)}{x \cdot x + 4 \cdot \left(y \cdot y\right)}}\]
    3. Using strategy rm
    4. Applied div-sub15.8

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + 4 \cdot \left(y \cdot y\right)} - \frac{4 \cdot \left(y \cdot y\right)}{x \cdot x + 4 \cdot \left(y \cdot y\right)}}\]
    5. Simplified15.4

      \[\leadsto \color{blue}{\frac{x}{\frac{x \cdot x + \left(4 \cdot y\right) \cdot y}{x}}} - \frac{4 \cdot \left(y \cdot y\right)}{x \cdot x + 4 \cdot \left(y \cdot y\right)}\]
    6. Simplified15.5

      \[\leadsto \frac{x}{\frac{x \cdot x + \left(4 \cdot y\right) \cdot y}{x}} - \color{blue}{\frac{4 \cdot y}{\frac{x \cdot x + \left(4 \cdot y\right) \cdot y}{y}}}\]
    7. Taylor expanded around 0 0.5

      \[\leadsto \frac{x}{\color{blue}{x + 4 \cdot \frac{{y}^{2}}{x}}} - \frac{4 \cdot y}{\frac{x \cdot x + \left(4 \cdot y\right) \cdot y}{y}}\]
    8. Simplified0.5

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

    if -2.6777867496852493e-159 < y < 4.876101206523021e-180

    1. Initial program 31.4

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

      \[\leadsto \color{blue}{\frac{x \cdot x - 4 \cdot \left(y \cdot y\right)}{x \cdot x + 4 \cdot \left(y \cdot y\right)}}\]
    3. Using strategy rm
    4. Applied clear-num31.4

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x + 4 \cdot \left(y \cdot y\right)}{x \cdot x - 4 \cdot \left(y \cdot y\right)}}}\]
    5. Simplified31.4

      \[\leadsto \frac{1}{\color{blue}{\frac{x \cdot x + \left(4 \cdot y\right) \cdot y}{x \cdot x - \left(4 \cdot y\right) \cdot y}}}\]
    6. Taylor expanded around inf 6.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2.68161050468433770508489338078059891853 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -2.677786749685249256830229513777092962685 \cdot 10^{-159}:\\ \;\;\;\;\frac{x}{4 \cdot \frac{y \cdot y}{x} + x} - \frac{4 \cdot y}{\frac{x \cdot x + \left(4 \cdot y\right) \cdot y}{y}}\\ \mathbf{elif}\;y \le 4.876101206523020878134736358929559551059 \cdot 10^{-180}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 3.108823225235708388607355653893818255588 \cdot 10^{124}:\\ \;\;\;\;\frac{x}{4 \cdot \frac{y \cdot y}{x} + x} - \frac{4 \cdot y}{\frac{x \cdot x + \left(4 \cdot y\right) \cdot y}{y}}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

herbie shell --seed 2019194 
(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))))