Average Error: 31.0 → 13.2
Time: 10.4s
Precision: 64
\[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -1.7605595017089978 \cdot 10^{+165}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;y \le -2.145414165595919 \cdot 10^{-133}:\\ \;\;\;\;\sqrt[3]{\left(\left(\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\right) \cdot \left(\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\right)\right) \cdot \left(\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\right)}\\ \mathbf{elif}\;y \le 1.047103978369638 \cdot 10^{-54}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 6.692635626773783 \cdot 10^{+153}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\\ \mathbf{else}:\\ \;\;\;\;-1.0\\ \end{array}\]
\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}
\begin{array}{l}
\mathbf{if}\;y \le -1.7605595017089978 \cdot 10^{+165}:\\
\;\;\;\;-1.0\\

\mathbf{elif}\;y \le -2.145414165595919 \cdot 10^{-133}:\\
\;\;\;\;\sqrt[3]{\left(\left(\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\right) \cdot \left(\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\right)\right) \cdot \left(\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\right)}\\

\mathbf{elif}\;y \le 1.047103978369638 \cdot 10^{-54}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 6.692635626773783 \cdot 10^{+153}:\\
\;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r35446306 = x;
        double r35446307 = r35446306 * r35446306;
        double r35446308 = y;
        double r35446309 = 4.0;
        double r35446310 = r35446308 * r35446309;
        double r35446311 = r35446310 * r35446308;
        double r35446312 = r35446307 - r35446311;
        double r35446313 = r35446307 + r35446311;
        double r35446314 = r35446312 / r35446313;
        return r35446314;
}

double f(double x, double y) {
        double r35446315 = y;
        double r35446316 = -1.7605595017089978e+165;
        bool r35446317 = r35446315 <= r35446316;
        double r35446318 = -1.0;
        double r35446319 = -2.145414165595919e-133;
        bool r35446320 = r35446315 <= r35446319;
        double r35446321 = x;
        double r35446322 = r35446321 * r35446321;
        double r35446323 = 4.0;
        double r35446324 = r35446315 * r35446323;
        double r35446325 = r35446324 * r35446315;
        double r35446326 = r35446322 + r35446325;
        double r35446327 = r35446322 / r35446326;
        double r35446328 = r35446325 / r35446326;
        double r35446329 = r35446327 - r35446328;
        double r35446330 = r35446329 * r35446329;
        double r35446331 = r35446330 * r35446329;
        double r35446332 = cbrt(r35446331);
        double r35446333 = 1.047103978369638e-54;
        bool r35446334 = r35446315 <= r35446333;
        double r35446335 = 1.0;
        double r35446336 = 6.692635626773783e+153;
        bool r35446337 = r35446315 <= r35446336;
        double r35446338 = r35446337 ? r35446329 : r35446318;
        double r35446339 = r35446334 ? r35446335 : r35446338;
        double r35446340 = r35446320 ? r35446332 : r35446339;
        double r35446341 = r35446317 ? r35446318 : r35446340;
        return r35446341;
}

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
Target31.1
Herbie13.2
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} \lt 0.9743233849626781:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot y\right) \cdot 4.0} - \frac{\left(y \cdot y\right) \cdot 4.0}{x \cdot x + \left(y \cdot y\right) \cdot 4.0}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x}{\sqrt{x \cdot x + \left(y \cdot y\right) \cdot 4.0}}\right)}^{2} - \frac{\left(y \cdot y\right) \cdot 4.0}{x \cdot x + \left(y \cdot y\right) \cdot 4.0}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if y < -1.7605595017089978e+165 or 6.692635626773783e+153 < y

    1. Initial program 63.4

      \[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
    2. Taylor expanded around 0 7.8

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

    if -1.7605595017089978e+165 < y < -2.145414165595919e-133

    1. Initial program 17.9

      \[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
    2. Using strategy rm
    3. Applied div-sub17.9

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}}\]
    4. Using strategy rm
    5. Applied add-cbrt-cube17.9

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

    if -2.145414165595919e-133 < y < 1.047103978369638e-54

    1. Initial program 25.7

      \[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
    2. Taylor expanded around inf 12.0

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

    if 1.047103978369638e-54 < y < 6.692635626773783e+153

    1. Initial program 16.2

      \[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
    2. Using strategy rm
    3. Applied div-sub16.2

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification13.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.7605595017089978 \cdot 10^{+165}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;y \le -2.145414165595919 \cdot 10^{-133}:\\ \;\;\;\;\sqrt[3]{\left(\left(\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\right) \cdot \left(\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\right)\right) \cdot \left(\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\right)}\\ \mathbf{elif}\;y \le 1.047103978369638 \cdot 10^{-54}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 6.692635626773783 \cdot 10^{+153}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\\ \mathbf{else}:\\ \;\;\;\;-1.0\\ \end{array}\]

Reproduce

herbie shell --seed 2019162 
(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) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))))

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