Average Error: 31.1 → 12.6
Time: 13.7s
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}\;x \cdot x \le 7.1088010196971 \cdot 10^{-314}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 9.758857908001147 \cdot 10^{+18}:\\ \;\;\;\;\frac{1}{\frac{y \cdot \left(4.0 \cdot y\right) + x \cdot x}{x \cdot x - y \cdot \left(4.0 \cdot y\right)}}\\ \mathbf{elif}\;x \cdot x \le 6.296502919195928 \cdot 10^{+44}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 3.1031769081973586 \cdot 10^{+257}:\\ \;\;\;\;\frac{1}{\frac{y \cdot \left(4.0 \cdot y\right) + x \cdot x}{x \cdot x - y \cdot \left(4.0 \cdot y\right)}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \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}\;x \cdot x \le 7.1088010196971 \cdot 10^{-314}:\\
\;\;\;\;-1.0\\

\mathbf{elif}\;x \cdot x \le 9.758857908001147 \cdot 10^{+18}:\\
\;\;\;\;\frac{1}{\frac{y \cdot \left(4.0 \cdot y\right) + x \cdot x}{x \cdot x - y \cdot \left(4.0 \cdot y\right)}}\\

\mathbf{elif}\;x \cdot x \le 6.296502919195928 \cdot 10^{+44}:\\
\;\;\;\;-1.0\\

\mathbf{elif}\;x \cdot x \le 3.1031769081973586 \cdot 10^{+257}:\\
\;\;\;\;\frac{1}{\frac{y \cdot \left(4.0 \cdot y\right) + x \cdot x}{x \cdot x - y \cdot \left(4.0 \cdot y\right)}}\\

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

\end{array}
double f(double x, double y) {
        double r18045397 = x;
        double r18045398 = r18045397 * r18045397;
        double r18045399 = y;
        double r18045400 = 4.0;
        double r18045401 = r18045399 * r18045400;
        double r18045402 = r18045401 * r18045399;
        double r18045403 = r18045398 - r18045402;
        double r18045404 = r18045398 + r18045402;
        double r18045405 = r18045403 / r18045404;
        return r18045405;
}

double f(double x, double y) {
        double r18045406 = x;
        double r18045407 = r18045406 * r18045406;
        double r18045408 = 7.1088010196971e-314;
        bool r18045409 = r18045407 <= r18045408;
        double r18045410 = -1.0;
        double r18045411 = 9.758857908001147e+18;
        bool r18045412 = r18045407 <= r18045411;
        double r18045413 = 1.0;
        double r18045414 = y;
        double r18045415 = 4.0;
        double r18045416 = r18045415 * r18045414;
        double r18045417 = r18045414 * r18045416;
        double r18045418 = r18045417 + r18045407;
        double r18045419 = r18045407 - r18045417;
        double r18045420 = r18045418 / r18045419;
        double r18045421 = r18045413 / r18045420;
        double r18045422 = 6.296502919195928e+44;
        bool r18045423 = r18045407 <= r18045422;
        double r18045424 = 3.1031769081973586e+257;
        bool r18045425 = r18045407 <= r18045424;
        double r18045426 = r18045425 ? r18045421 : r18045413;
        double r18045427 = r18045423 ? r18045410 : r18045426;
        double r18045428 = r18045412 ? r18045421 : r18045427;
        double r18045429 = r18045409 ? r18045410 : r18045428;
        return r18045429;
}

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.1
Target31.2
Herbie12.6
\[\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 (* x x) < 7.1088010196971e-314 or 9.758857908001147e+18 < (* x x) < 6.296502919195928e+44

    1. Initial program 29.3

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

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

    if 7.1088010196971e-314 < (* x x) < 9.758857908001147e+18 or 6.296502919195928e+44 < (* x x) < 3.1031769081973586e+257

    1. Initial program 16.1

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

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

    if 3.1031769081973586e+257 < (* x x)

    1. Initial program 56.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 inf 9.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \le 7.1088010196971 \cdot 10^{-314}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 9.758857908001147 \cdot 10^{+18}:\\ \;\;\;\;\frac{1}{\frac{y \cdot \left(4.0 \cdot y\right) + x \cdot x}{x \cdot x - y \cdot \left(4.0 \cdot y\right)}}\\ \mathbf{elif}\;x \cdot x \le 6.296502919195928 \cdot 10^{+44}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 3.1031769081973586 \cdot 10^{+257}:\\ \;\;\;\;\frac{1}{\frac{y \cdot \left(4.0 \cdot y\right) + x \cdot x}{x \cdot x - y \cdot \left(4.0 \cdot y\right)}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

herbie shell --seed 2019163 +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))))