Average Error: 31.0 → 13.2
Time: 9.1s
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 r34444294 = x;
        double r34444295 = r34444294 * r34444294;
        double r34444296 = y;
        double r34444297 = 4.0;
        double r34444298 = r34444296 * r34444297;
        double r34444299 = r34444298 * r34444296;
        double r34444300 = r34444295 - r34444299;
        double r34444301 = r34444295 + r34444299;
        double r34444302 = r34444300 / r34444301;
        return r34444302;
}

double f(double x, double y) {
        double r34444303 = y;
        double r34444304 = -1.7605595017089978e+165;
        bool r34444305 = r34444303 <= r34444304;
        double r34444306 = -1.0;
        double r34444307 = -2.145414165595919e-133;
        bool r34444308 = r34444303 <= r34444307;
        double r34444309 = x;
        double r34444310 = r34444309 * r34444309;
        double r34444311 = 4.0;
        double r34444312 = r34444303 * r34444311;
        double r34444313 = r34444312 * r34444303;
        double r34444314 = r34444310 + r34444313;
        double r34444315 = r34444310 / r34444314;
        double r34444316 = r34444313 / r34444314;
        double r34444317 = r34444315 - r34444316;
        double r34444318 = r34444317 * r34444317;
        double r34444319 = r34444318 * r34444317;
        double r34444320 = cbrt(r34444319);
        double r34444321 = 1.047103978369638e-54;
        bool r34444322 = r34444303 <= r34444321;
        double r34444323 = 1.0;
        double r34444324 = 6.692635626773783e+153;
        bool r34444325 = r34444303 <= r34444324;
        double r34444326 = r34444325 ? r34444317 : r34444306;
        double r34444327 = r34444322 ? r34444323 : r34444326;
        double r34444328 = r34444308 ? r34444320 : r34444327;
        double r34444329 = r34444305 ? r34444306 : r34444328;
        return r34444329;
}

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))))