Average Error: 31.0 → 14.7
Time: 9.5s
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 -9.850726757232304656097215039461175225007 \cdot 10^{116}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -213283511644709824:\\ \;\;\;\;\left(\sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}}\right) \cdot \sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}}\\ \mathbf{elif}\;x \le -3.478057257589816580751045492937248447757 \cdot 10^{-17}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -5.393824270148449076708054055498132792438 \cdot 10^{-74}:\\ \;\;\;\;\left(\sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}}\right) \cdot \sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}}\\ \mathbf{elif}\;x \le -8.64767432764635258433792673669348312331 \cdot 10^{-129}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -1.23992860779612800616268155128852493615 \cdot 10^{-180}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le 6.823576610928471937518681293595906800826 \cdot 10^{-152}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 6.357559912396233893317957556288536407725 \cdot 10^{53}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(4 \cdot y\right)}{\mathsf{fma}\left(x, x, y \cdot \left(4 \cdot y\right)\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 -9.850726757232304656097215039461175225007 \cdot 10^{116}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -213283511644709824:\\
\;\;\;\;\left(\sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}}\right) \cdot \sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}}\\

\mathbf{elif}\;x \le -3.478057257589816580751045492937248447757 \cdot 10^{-17}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le -5.393824270148449076708054055498132792438 \cdot 10^{-74}:\\
\;\;\;\;\left(\sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}}\right) \cdot \sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}}\\

\mathbf{elif}\;x \le -8.64767432764635258433792673669348312331 \cdot 10^{-129}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le -1.23992860779612800616268155128852493615 \cdot 10^{-180}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le 6.823576610928471937518681293595906800826 \cdot 10^{-152}:\\
\;\;\;\;-1\\

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

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

\end{array}
double f(double x, double y) {
        double r1414714 = x;
        double r1414715 = r1414714 * r1414714;
        double r1414716 = y;
        double r1414717 = 4.0;
        double r1414718 = r1414716 * r1414717;
        double r1414719 = r1414718 * r1414716;
        double r1414720 = r1414715 - r1414719;
        double r1414721 = r1414715 + r1414719;
        double r1414722 = r1414720 / r1414721;
        return r1414722;
}

double f(double x, double y) {
        double r1414723 = x;
        double r1414724 = -9.850726757232305e+116;
        bool r1414725 = r1414723 <= r1414724;
        double r1414726 = 1.0;
        double r1414727 = -2.1328351164470982e+17;
        bool r1414728 = r1414723 <= r1414727;
        double r1414729 = 4.0;
        double r1414730 = y;
        double r1414731 = r1414729 * r1414730;
        double r1414732 = -r1414730;
        double r1414733 = r1414723 * r1414723;
        double r1414734 = fma(r1414731, r1414732, r1414733);
        double r1414735 = fma(r1414730, r1414731, r1414733);
        double r1414736 = r1414734 / r1414735;
        double r1414737 = cbrt(r1414736);
        double r1414738 = r1414737 * r1414737;
        double r1414739 = r1414738 * r1414737;
        double r1414740 = -3.4780572575898166e-17;
        bool r1414741 = r1414723 <= r1414740;
        double r1414742 = -1.0;
        double r1414743 = -5.393824270148449e-74;
        bool r1414744 = r1414723 <= r1414743;
        double r1414745 = -8.647674327646353e-129;
        bool r1414746 = r1414723 <= r1414745;
        double r1414747 = -1.239928607796128e-180;
        bool r1414748 = r1414723 <= r1414747;
        double r1414749 = 6.823576610928472e-152;
        bool r1414750 = r1414723 <= r1414749;
        double r1414751 = 6.357559912396234e+53;
        bool r1414752 = r1414723 <= r1414751;
        double r1414753 = r1414730 * r1414731;
        double r1414754 = r1414733 - r1414753;
        double r1414755 = fma(r1414723, r1414723, r1414753);
        double r1414756 = r1414754 / r1414755;
        double r1414757 = r1414752 ? r1414756 : r1414726;
        double r1414758 = r1414750 ? r1414742 : r1414757;
        double r1414759 = r1414748 ? r1414726 : r1414758;
        double r1414760 = r1414746 ? r1414742 : r1414759;
        double r1414761 = r1414744 ? r1414739 : r1414760;
        double r1414762 = r1414741 ? r1414742 : r1414761;
        double r1414763 = r1414728 ? r1414739 : r1414762;
        double r1414764 = r1414725 ? r1414726 : r1414763;
        return r1414764;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.0
Target30.7
Herbie14.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.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 4 regimes
  2. if x < -9.850726757232305e+116 or -8.647674327646353e-129 < x < -1.239928607796128e-180 or 6.357559912396234e+53 < x

    1. Initial program 45.8

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

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

    if -9.850726757232305e+116 < x < -2.1328351164470982e+17 or -3.4780572575898166e-17 < x < -5.393824270148449e-74

    1. Initial program 15.0

      \[\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 add-cube-cbrt15.0

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

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

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

    if -2.1328351164470982e+17 < x < -3.4780572575898166e-17 or -5.393824270148449e-74 < x < -8.647674327646353e-129 or -1.239928607796128e-180 < x < 6.823576610928472e-152

    1. Initial program 26.0

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

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

    if 6.823576610928472e-152 < x < 6.357559912396234e+53

    1. Initial program 16.3

      \[\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 fma-def16.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -9.850726757232304656097215039461175225007 \cdot 10^{116}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -213283511644709824:\\ \;\;\;\;\left(\sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}}\right) \cdot \sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}}\\ \mathbf{elif}\;x \le -3.478057257589816580751045492937248447757 \cdot 10^{-17}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -5.393824270148449076708054055498132792438 \cdot 10^{-74}:\\ \;\;\;\;\left(\sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}} \cdot \sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}}\right) \cdot \sqrt[3]{\frac{\mathsf{fma}\left(4 \cdot y, -y, x \cdot x\right)}{\mathsf{fma}\left(y, 4 \cdot y, x \cdot x\right)}}\\ \mathbf{elif}\;x \le -8.64767432764635258433792673669348312331 \cdot 10^{-129}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -1.23992860779612800616268155128852493615 \cdot 10^{-180}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le 6.823576610928471937518681293595906800826 \cdot 10^{-152}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 6.357559912396233893317957556288536407725 \cdot 10^{53}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(4 \cdot y\right)}{\mathsf{fma}\left(x, x, y \cdot \left(4 \cdot y\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

herbie shell --seed 2019194 +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.0) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))))

  (/ (- (* x x) (* (* y 4.0) y)) (+ (* x x) (* (* y 4.0) y))))