Average Error: 31.9 → 15.7
Time: 3.6s
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 -3.9547679581202103 \cdot 10^{27}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -7.8905969189111263 \cdot 10^{-23}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -3.246960260390424 \cdot 10^{-67}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{y}}\\ \mathbf{elif}\;x \le -4.3884605229815477 \cdot 10^{-101}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -3.49297723193740726 \cdot 10^{-162}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)\\ \mathbf{elif}\;x \le 1.9844193705891298 \cdot 10^{-132}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 9.97051040847491787 \cdot 10^{-75}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)\\ \mathbf{elif}\;x \le 3.09444041521077753 \cdot 10^{89}:\\ \;\;\;\;-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 -3.9547679581202103 \cdot 10^{27}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -7.8905969189111263 \cdot 10^{-23}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;x \le -4.3884605229815477 \cdot 10^{-101}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le -3.49297723193740726 \cdot 10^{-162}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)\\

\mathbf{elif}\;x \le 1.9844193705891298 \cdot 10^{-132}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 9.97051040847491787 \cdot 10^{-75}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)\\

\mathbf{elif}\;x \le 3.09444041521077753 \cdot 10^{89}:\\
\;\;\;\;-1\\

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

\end{array}
double f(double x, double y) {
        double r661787 = x;
        double r661788 = r661787 * r661787;
        double r661789 = y;
        double r661790 = 4.0;
        double r661791 = r661789 * r661790;
        double r661792 = r661791 * r661789;
        double r661793 = r661788 - r661792;
        double r661794 = r661788 + r661792;
        double r661795 = r661793 / r661794;
        return r661795;
}

double f(double x, double y) {
        double r661796 = x;
        double r661797 = -3.9547679581202103e+27;
        bool r661798 = r661796 <= r661797;
        double r661799 = 1.0;
        double r661800 = -7.890596918911126e-23;
        bool r661801 = r661796 <= r661800;
        double r661802 = -1.0;
        double r661803 = -3.2469602603904245e-67;
        bool r661804 = r661796 <= r661803;
        double r661805 = y;
        double r661806 = 4.0;
        double r661807 = r661805 * r661806;
        double r661808 = r661807 * r661805;
        double r661809 = fma(r661796, r661796, r661808);
        double r661810 = r661809 / r661796;
        double r661811 = r661796 / r661810;
        double r661812 = r661809 / r661805;
        double r661813 = r661807 / r661812;
        double r661814 = r661811 - r661813;
        double r661815 = -4.388460522981548e-101;
        bool r661816 = r661796 <= r661815;
        double r661817 = -3.4929772319374073e-162;
        bool r661818 = r661796 <= r661817;
        double r661819 = r661796 * r661796;
        double r661820 = r661819 - r661808;
        double r661821 = r661819 + r661808;
        double r661822 = r661820 / r661821;
        double r661823 = log1p(r661822);
        double r661824 = expm1(r661823);
        double r661825 = 1.98441937058913e-132;
        bool r661826 = r661796 <= r661825;
        double r661827 = 9.970510408474918e-75;
        bool r661828 = r661796 <= r661827;
        double r661829 = 3.0944404152107775e+89;
        bool r661830 = r661796 <= r661829;
        double r661831 = r661830 ? r661802 : r661799;
        double r661832 = r661828 ? r661824 : r661831;
        double r661833 = r661826 ? r661802 : r661832;
        double r661834 = r661818 ? r661824 : r661833;
        double r661835 = r661816 ? r661802 : r661834;
        double r661836 = r661804 ? r661814 : r661835;
        double r661837 = r661801 ? r661802 : r661836;
        double r661838 = r661798 ? r661799 : r661837;
        return r661838;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.9
Target31.6
Herbie15.7
\[\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 4 regimes
  2. if x < -3.9547679581202103e+27 or 3.0944404152107775e+89 < x

    1. Initial program 46.6

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Taylor expanded around inf 13.1

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

    if -3.9547679581202103e+27 < x < -7.890596918911126e-23 or -3.2469602603904245e-67 < x < -4.388460522981548e-101 or -3.4929772319374073e-162 < x < 1.98441937058913e-132 or 9.970510408474918e-75 < x < 3.0944404152107775e+89

    1. Initial program 23.9

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Taylor expanded around 0 18.7

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

    if -7.890596918911126e-23 < x < -3.2469602603904245e-67

    1. Initial program 15.1

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Using strategy rm
    3. Applied div-sub15.1

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

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

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

    if -4.388460522981548e-101 < x < -3.4929772319374073e-162 or 1.98441937058913e-132 < x < 9.970510408474918e-75

    1. Initial program 13.4

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Using strategy rm
    3. Applied expm1-log1p-u13.4

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification15.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.9547679581202103 \cdot 10^{27}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -7.8905969189111263 \cdot 10^{-23}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -3.246960260390424 \cdot 10^{-67}:\\ \;\;\;\;\frac{x}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{x}} - \frac{y \cdot 4}{\frac{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot y\right)}{y}}\\ \mathbf{elif}\;x \le -4.3884605229815477 \cdot 10^{-101}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -3.49297723193740726 \cdot 10^{-162}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)\\ \mathbf{elif}\;x \le 1.9844193705891298 \cdot 10^{-132}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 9.97051040847491787 \cdot 10^{-75}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)\\ \mathbf{elif}\;x \le 3.09444041521077753 \cdot 10^{89}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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