Average Error: 31.6 → 12.8
Time: 10.4s
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.04179898258906648865287012115961201463 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.379561403631358792480741892956065284459 \cdot 10^{-65}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{\left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;y \le 9.959621465941042556551382638800450476793 \cdot 10^{-80}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 2.371593609881423098610405616408534144725 \cdot 10^{60}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{\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}\;y \le -2.04179898258906648865287012115961201463 \cdot 10^{153}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;y \le 9.959621465941042556551382638800450476793 \cdot 10^{-80}:\\
\;\;\;\;1\\

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

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

\end{array}
double f(double x, double y) {
        double r35828548 = x;
        double r35828549 = r35828548 * r35828548;
        double r35828550 = y;
        double r35828551 = 4.0;
        double r35828552 = r35828550 * r35828551;
        double r35828553 = r35828552 * r35828550;
        double r35828554 = r35828549 - r35828553;
        double r35828555 = r35828549 + r35828553;
        double r35828556 = r35828554 / r35828555;
        return r35828556;
}

double f(double x, double y) {
        double r35828557 = y;
        double r35828558 = -2.0417989825890665e+153;
        bool r35828559 = r35828557 <= r35828558;
        double r35828560 = -1.0;
        double r35828561 = -3.379561403631359e-65;
        bool r35828562 = r35828557 <= r35828561;
        double r35828563 = x;
        double r35828564 = r35828563 * r35828563;
        double r35828565 = 4.0;
        double r35828566 = r35828557 * r35828565;
        double r35828567 = r35828566 * r35828557;
        double r35828568 = r35828564 + r35828567;
        double r35828569 = r35828564 / r35828568;
        double r35828570 = 1.0;
        double r35828571 = r35828568 / r35828567;
        double r35828572 = r35828570 / r35828571;
        double r35828573 = r35828569 - r35828572;
        double r35828574 = 9.959621465941043e-80;
        bool r35828575 = r35828557 <= r35828574;
        double r35828576 = 2.371593609881423e+60;
        bool r35828577 = r35828557 <= r35828576;
        double r35828578 = r35828577 ? r35828573 : r35828560;
        double r35828579 = r35828575 ? r35828570 : r35828578;
        double r35828580 = r35828562 ? r35828573 : r35828579;
        double r35828581 = r35828559 ? r35828560 : r35828580;
        return r35828581;
}

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.6
Target31.3
Herbie12.8
\[\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.0417989825890665e+153 or 2.371593609881423e+60 < y

    1. Initial program 52.9

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

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

    if -2.0417989825890665e+153 < y < -3.379561403631359e-65 or 9.959621465941043e-80 < y < 2.371593609881423e+60

    1. Initial program 16.1

      \[\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-sub16.1

      \[\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}}\]
    4. Using strategy rm
    5. Applied clear-num16.1

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

    if -3.379561403631359e-65 < y < 9.959621465941043e-80

    1. Initial program 25.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.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2.04179898258906648865287012115961201463 \cdot 10^{153}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -3.379561403631358792480741892956065284459 \cdot 10^{-65}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{\left(y \cdot 4\right) \cdot y}}\\ \mathbf{elif}\;y \le 9.959621465941042556551382638800450476793 \cdot 10^{-80}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 2.371593609881423098610405616408534144725 \cdot 10^{60}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{\left(y \cdot 4\right) \cdot y}}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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