Average Error: 32.2 → 14.6
Time: 10.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 -4.219332295965777137041720193068407814529 \cdot 10^{82}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -9.032916470641929520628535786544615007503 \cdot 10^{-57}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, x, -y \cdot \left(y \cdot 4\right)\right)}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\ \mathbf{elif}\;x \le 10274298981.3873691558837890625:\\ \;\;\;\;-1\\ \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 -4.219332295965777137041720193068407814529 \cdot 10^{82}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;x \le 10274298981.3873691558837890625:\\
\;\;\;\;-1\\

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

\end{array}
double f(double x, double y) {
        double r453034 = x;
        double r453035 = r453034 * r453034;
        double r453036 = y;
        double r453037 = 4.0;
        double r453038 = r453036 * r453037;
        double r453039 = r453038 * r453036;
        double r453040 = r453035 - r453039;
        double r453041 = r453035 + r453039;
        double r453042 = r453040 / r453041;
        return r453042;
}

double f(double x, double y) {
        double r453043 = x;
        double r453044 = -4.219332295965777e+82;
        bool r453045 = r453043 <= r453044;
        double r453046 = 1.0;
        double r453047 = -9.03291647064193e-57;
        bool r453048 = r453043 <= r453047;
        double r453049 = y;
        double r453050 = 4.0;
        double r453051 = r453049 * r453050;
        double r453052 = r453049 * r453051;
        double r453053 = -r453052;
        double r453054 = fma(r453043, r453043, r453053);
        double r453055 = r453051 * r453049;
        double r453056 = fma(r453043, r453043, r453055);
        double r453057 = r453054 / r453056;
        double r453058 = 10274298981.38737;
        bool r453059 = r453043 <= r453058;
        double r453060 = -1.0;
        double r453061 = r453059 ? r453060 : r453046;
        double r453062 = r453048 ? r453057 : r453061;
        double r453063 = r453045 ? r453046 : r453062;
        return r453063;
}

Error

Bits error versus x

Bits error versus y

Target

Original32.2
Target31.9
Herbie14.6
\[\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.9743233849626781184483093056769575923681:\\ \;\;\;\;\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 < -4.219332295965777e+82 or 10274298981.38737 < x

    1. Initial program 44.2

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

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

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

    if -4.219332295965777e+82 < x < -9.03291647064193e-57

    1. Initial program 16.2

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

      \[\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. Using strategy rm
    4. Applied *-un-lft-identity16.2

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\color{blue}{1 \cdot \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}}\]
    5. Applied associate-/r*16.2

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

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

    if -9.03291647064193e-57 < x < 10274298981.38737

    1. Initial program 24.8

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Simplified24.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)}}\]
    3. Taylor expanded around 0 14.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.219332295965777137041720193068407814529 \cdot 10^{82}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -9.032916470641929520628535786544615007503 \cdot 10^{-57}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, x, -y \cdot \left(y \cdot 4\right)\right)}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}\\ \mathbf{elif}\;x \le 10274298981.3873691558837890625:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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