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

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

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

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

\end{array}
double f(double x, double y) {
        double r431091 = x;
        double r431092 = r431091 * r431091;
        double r431093 = y;
        double r431094 = 4.0;
        double r431095 = r431093 * r431094;
        double r431096 = r431095 * r431093;
        double r431097 = r431092 - r431096;
        double r431098 = r431092 + r431096;
        double r431099 = r431097 / r431098;
        return r431099;
}

double f(double x, double y) {
        double r431100 = y;
        double r431101 = -2.0417989825890665e+153;
        bool r431102 = r431100 <= r431101;
        double r431103 = -1.0;
        double r431104 = -3.379561403631359e-65;
        bool r431105 = r431100 <= r431104;
        double r431106 = x;
        double r431107 = r431106 * r431106;
        double r431108 = r431100 * r431100;
        double r431109 = 4.0;
        double r431110 = r431108 * r431109;
        double r431111 = r431107 - r431110;
        double r431112 = r431107 + r431110;
        double r431113 = r431111 / r431112;
        double r431114 = 9.959621465941043e-80;
        bool r431115 = r431100 <= r431114;
        double r431116 = 1.0;
        double r431117 = 2.371593609881423e+60;
        bool r431118 = r431100 <= r431117;
        double r431119 = r431118 ? r431113 : r431103;
        double r431120 = r431115 ? r431116 : r431119;
        double r431121 = r431105 ? r431113 : r431120;
        double r431122 = r431102 ? r431103 : r431121;
        return r431122;
}

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. Simplified52.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 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. Simplified16.1

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

    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. Simplified25.5

      \[\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 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 - \left(y \cdot y\right) \cdot 4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\\ \mathbf{elif}\;y \le 9.959621465941042556551382638800450476793 \cdot 10^{-80}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 2.371593609881423098610405616408534144725 \cdot 10^{60}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot y\right) \cdot 4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\\ \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))))