Average Error: 31.1 → 12.6
Time: 14.6s
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 r29049056 = x;
        double r29049057 = r29049056 * r29049056;
        double r29049058 = y;
        double r29049059 = 4.0;
        double r29049060 = r29049058 * r29049059;
        double r29049061 = r29049060 * r29049058;
        double r29049062 = r29049057 - r29049061;
        double r29049063 = r29049057 + r29049061;
        double r29049064 = r29049062 / r29049063;
        return r29049064;
}

double f(double x, double y) {
        double r29049065 = x;
        double r29049066 = r29049065 * r29049065;
        double r29049067 = 7.1088010196971e-314;
        bool r29049068 = r29049066 <= r29049067;
        double r29049069 = -1.0;
        double r29049070 = 9.758857908001147e+18;
        bool r29049071 = r29049066 <= r29049070;
        double r29049072 = 1.0;
        double r29049073 = y;
        double r29049074 = 4.0;
        double r29049075 = r29049074 * r29049073;
        double r29049076 = r29049073 * r29049075;
        double r29049077 = r29049076 + r29049066;
        double r29049078 = r29049066 - r29049076;
        double r29049079 = r29049077 / r29049078;
        double r29049080 = r29049072 / r29049079;
        double r29049081 = 6.296502919195928e+44;
        bool r29049082 = r29049066 <= r29049081;
        double r29049083 = 3.1031769081973586e+257;
        bool r29049084 = r29049066 <= r29049083;
        double r29049085 = r29049084 ? r29049080 : r29049072;
        double r29049086 = r29049082 ? r29049069 : r29049085;
        double r29049087 = r29049071 ? r29049080 : r29049086;
        double r29049088 = r29049068 ? r29049069 : r29049087;
        return r29049088;
}

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