Average Error: 31.1 → 12.3
Time: 1.8s
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 r671575 = x;
        double r671576 = r671575 * r671575;
        double r671577 = y;
        double r671578 = 4.0;
        double r671579 = r671577 * r671578;
        double r671580 = r671579 * r671577;
        double r671581 = r671576 - r671580;
        double r671582 = r671576 + r671580;
        double r671583 = r671581 / r671582;
        return r671583;
}

double f(double x, double y) {
        double r671584 = x;
        double r671585 = -7.011466568761976e+150;
        bool r671586 = r671584 <= r671585;
        double r671587 = 1.0;
        double r671588 = -2.6395470821417425e-162;
        bool r671589 = r671584 <= r671588;
        double r671590 = r671584 * r671584;
        double r671591 = y;
        double r671592 = 4.0;
        double r671593 = r671591 * r671592;
        double r671594 = r671593 * r671591;
        double r671595 = r671590 - r671594;
        double r671596 = fma(r671584, r671584, r671594);
        double r671597 = r671595 / r671596;
        double r671598 = 2.9825574787203653e-86;
        bool r671599 = r671584 <= r671598;
        double r671600 = -1.0;
        double r671601 = 2.756542813676069e+103;
        bool r671602 = r671584 <= r671601;
        double r671603 = r671602 ? r671597 : r671587;
        double r671604 = r671599 ? r671600 : r671603;
        double r671605 = r671589 ? r671597 : r671604;
        double r671606 = r671586 ? r671587 : r671605;
        return r671606;
}

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