Average Error: 31.1 → 12.3
Time: 3.0s
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}\;x \le -7.01146656876197595 \cdot 10^{150}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -2.6395470821417425 \cdot 10^{-162}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\ \mathbf{elif}\;x \le 2.98255747872036532 \cdot 10^{-86}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 2.75654281367606914 \cdot 10^{103}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\ \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}\;x \le -7.01146656876197595 \cdot 10^{150}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -2.6395470821417425 \cdot 10^{-162}:\\
\;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\

\mathbf{elif}\;x \le 2.98255747872036532 \cdot 10^{-86}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 2.75654281367606914 \cdot 10^{103}:\\
\;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\

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

\end{array}
double f(double x, double y) {
        double r669584 = x;
        double r669585 = r669584 * r669584;
        double r669586 = y;
        double r669587 = 4.0;
        double r669588 = r669586 * r669587;
        double r669589 = r669588 * r669586;
        double r669590 = r669585 - r669589;
        double r669591 = r669585 + r669589;
        double r669592 = r669590 / r669591;
        return r669592;
}

double f(double x, double y) {
        double r669593 = x;
        double r669594 = -7.011466568761976e+150;
        bool r669595 = r669593 <= r669594;
        double r669596 = 1.0;
        double r669597 = -2.6395470821417425e-162;
        bool r669598 = r669593 <= r669597;
        double r669599 = r669593 * r669593;
        double r669600 = y;
        double r669601 = 4.0;
        double r669602 = r669600 * r669601;
        double r669603 = r669602 * r669600;
        double r669604 = r669599 - r669603;
        double r669605 = fma(r669593, r669593, r669603);
        double r669606 = r669604 / r669605;
        double r669607 = 2.9825574787203653e-86;
        bool r669608 = r669593 <= r669607;
        double r669609 = -1.0;
        double r669610 = 2.756542813676069e+103;
        bool r669611 = r669593 <= r669610;
        double r669612 = r669611 ? r669606 : r669596;
        double r669613 = r669608 ? r669609 : r669612;
        double r669614 = r669598 ? r669606 : r669613;
        double r669615 = r669595 ? r669596 : r669614;
        return r669615;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.1
Target30.8
Herbie12.3
\[\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.974323384962678118:\\ \;\;\;\;\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 3 regimes
  2. if x < -7.011466568761976e+150 or 2.756542813676069e+103 < x

    1. Initial program 55.9

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Simplified55.9

      \[\leadsto \color{blue}{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    3. Taylor expanded around inf 9.3

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

    if -7.011466568761976e+150 < x < -2.6395470821417425e-162 or 2.9825574787203653e-86 < x < 2.756542813676069e+103

    1. Initial program 15.8

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Simplified15.8

      \[\leadsto \color{blue}{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]

    if -2.6395470821417425e-162 < x < 2.9825574787203653e-86

    1. Initial program 28.0

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Simplified28.0

      \[\leadsto \color{blue}{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    3. Taylor expanded around 0 10.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -7.01146656876197595 \cdot 10^{150}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -2.6395470821417425 \cdot 10^{-162}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\ \mathbf{elif}\;x \le 2.98255747872036532 \cdot 10^{-86}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 2.75654281367606914 \cdot 10^{103}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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