Average Error: 31.7 → 15.7
Time: 971.0ms
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 -7.32107702472276128411193082390112739547 \cdot 10^{-18}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 1.577263682377974965666846612933656955984 \cdot 10^{51}:\\ \;\;\;\;1\\ \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 -7.32107702472276128411193082390112739547 \cdot 10^{-18}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le 1.577263682377974965666846612933656955984 \cdot 10^{51}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r597167 = x;
        double r597168 = r597167 * r597167;
        double r597169 = y;
        double r597170 = 4.0;
        double r597171 = r597169 * r597170;
        double r597172 = r597171 * r597169;
        double r597173 = r597168 - r597172;
        double r597174 = r597168 + r597172;
        double r597175 = r597173 / r597174;
        return r597175;
}

double f(double __attribute__((unused)) x, double y) {
        double r597176 = y;
        double r597177 = -7.321077024722761e-18;
        bool r597178 = r597176 <= r597177;
        double r597179 = -1.0;
        double r597180 = 1.577263682377975e+51;
        bool r597181 = r597176 <= r597180;
        double r597182 = 1.0;
        double r597183 = r597181 ? r597182 : r597179;
        double r597184 = r597178 ? r597179 : r597183;
        return r597184;
}

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.7
Target31.4
Herbie15.7
\[\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 2 regimes
  2. if y < -7.321077024722761e-18 or 1.577263682377975e+51 < y

    1. Initial program 41.5

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

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

    if -7.321077024722761e-18 < y < 1.577263682377975e+51

    1. Initial program 22.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 inf 16.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -7.32107702472276128411193082390112739547 \cdot 10^{-18}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le 1.577263682377974965666846612933656955984 \cdot 10^{51}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

herbie shell --seed 2019353 +o rules:numerics
(FPCore (x y)
  :name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< (/ (- (* x x) (* (* y 4) y)) (+ (* x x) (* (* y 4) y))) 0.9743233849626781) (- (/ (* x x) (+ (* x x) (* (* y y) 4))) (/ (* (* y y) 4) (+ (* x x) (* (* y y) 4)))) (- (pow (/ x (sqrt (+ (* x x) (* (* y y) 4)))) 2) (/ (* (* y y) 4) (+ (* x x) (* (* y y) 4)))))

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