Average Error: 31.0 → 13.2
Time: 14.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}:\\ \;\;\;\;\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{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}:\\
\;\;\;\;\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{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 r27688248 = x;
        double r27688249 = r27688248 * r27688248;
        double r27688250 = y;
        double r27688251 = 4.0;
        double r27688252 = r27688250 * r27688251;
        double r27688253 = r27688252 * r27688250;
        double r27688254 = r27688249 - r27688253;
        double r27688255 = r27688249 + r27688253;
        double r27688256 = r27688254 / r27688255;
        return r27688256;
}

double f(double x, double y) {
        double r27688257 = y;
        double r27688258 = -1.7605595017089978e+165;
        bool r27688259 = r27688257 <= r27688258;
        double r27688260 = -1.0;
        double r27688261 = -2.145414165595919e-133;
        bool r27688262 = r27688257 <= r27688261;
        double r27688263 = x;
        double r27688264 = r27688263 * r27688263;
        double r27688265 = 4.0;
        double r27688266 = r27688257 * r27688265;
        double r27688267 = r27688266 * r27688257;
        double r27688268 = r27688264 + r27688267;
        double r27688269 = r27688264 / r27688268;
        double r27688270 = r27688267 / r27688268;
        double r27688271 = r27688269 - r27688270;
        double r27688272 = 1.047103978369638e-54;
        bool r27688273 = r27688257 <= r27688272;
        double r27688274 = 1.0;
        double r27688275 = 6.692635626773783e+153;
        bool r27688276 = r27688257 <= r27688275;
        double r27688277 = r27688276 ? r27688271 : r27688260;
        double r27688278 = r27688273 ? r27688274 : r27688277;
        double r27688279 = r27688262 ? r27688271 : r27688278;
        double r27688280 = r27688259 ? r27688260 : r27688279;
        return r27688280;
}

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 3 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 or 1.047103978369638e-54 < y < 6.692635626773783e+153

    1. Initial program 17.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-sub17.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}}\]

    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}\]
  3. Recombined 3 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}:\\ \;\;\;\;\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{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 +o rules:numerics
(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))))