Average Error: 31.1 → 12.4
Time: 13.9s
Precision: 64
\[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \cdot x \le 7.1088010196971 \cdot 10^{-314}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 9.758857908001147 \cdot 10^{+18}:\\ \;\;\;\;\sqrt[3]{\left(\left(\frac{x \cdot x}{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)} - \frac{y}{\frac{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)}{y \cdot 4.0}}\right) \cdot \left(\frac{x \cdot x}{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)} - \frac{y}{\frac{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)}{y \cdot 4.0}}\right)\right) \cdot \left(\frac{x \cdot x}{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)} - \frac{y}{\frac{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)}{y \cdot 4.0}}\right)}\\ \mathbf{elif}\;x \cdot x \le 6.296502919195928 \cdot 10^{+44}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 2.524624859163763 \cdot 10^{+295}:\\ \;\;\;\;\sqrt[3]{\left(\left(\frac{x \cdot x}{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)} - \frac{y}{\frac{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)}{y \cdot 4.0}}\right) \cdot \left(\frac{x \cdot x}{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)} - \frac{y}{\frac{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)}{y \cdot 4.0}}\right)\right) \cdot \left(\frac{x \cdot x}{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)} - \frac{y}{\frac{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)}{y \cdot 4.0}}\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}
\begin{array}{l}
\mathbf{if}\;x \cdot x \le 7.1088010196971 \cdot 10^{-314}:\\
\;\;\;\;-1.0\\

\mathbf{elif}\;x \cdot x \le 9.758857908001147 \cdot 10^{+18}:\\
\;\;\;\;\sqrt[3]{\left(\left(\frac{x \cdot x}{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)} - \frac{y}{\frac{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)}{y \cdot 4.0}}\right) \cdot \left(\frac{x \cdot x}{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)} - \frac{y}{\frac{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)}{y \cdot 4.0}}\right)\right) \cdot \left(\frac{x \cdot x}{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)} - \frac{y}{\frac{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)}{y \cdot 4.0}}\right)}\\

\mathbf{elif}\;x \cdot x \le 6.296502919195928 \cdot 10^{+44}:\\
\;\;\;\;-1.0\\

\mathbf{elif}\;x \cdot x \le 2.524624859163763 \cdot 10^{+295}:\\
\;\;\;\;\sqrt[3]{\left(\left(\frac{x \cdot x}{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)} - \frac{y}{\frac{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)}{y \cdot 4.0}}\right) \cdot \left(\frac{x \cdot x}{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)} - \frac{y}{\frac{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)}{y \cdot 4.0}}\right)\right) \cdot \left(\frac{x \cdot x}{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)} - \frac{y}{\frac{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)}{y \cdot 4.0}}\right)}\\

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

\end{array}
double f(double x, double y) {
        double r29521659 = x;
        double r29521660 = r29521659 * r29521659;
        double r29521661 = y;
        double r29521662 = 4.0;
        double r29521663 = r29521661 * r29521662;
        double r29521664 = r29521663 * r29521661;
        double r29521665 = r29521660 - r29521664;
        double r29521666 = r29521660 + r29521664;
        double r29521667 = r29521665 / r29521666;
        return r29521667;
}

double f(double x, double y) {
        double r29521668 = x;
        double r29521669 = r29521668 * r29521668;
        double r29521670 = 7.1088010196971e-314;
        bool r29521671 = r29521669 <= r29521670;
        double r29521672 = -1.0;
        double r29521673 = 9.758857908001147e+18;
        bool r29521674 = r29521669 <= r29521673;
        double r29521675 = y;
        double r29521676 = 4.0;
        double r29521677 = r29521675 * r29521676;
        double r29521678 = fma(r29521675, r29521677, r29521669);
        double r29521679 = r29521669 / r29521678;
        double r29521680 = r29521678 / r29521677;
        double r29521681 = r29521675 / r29521680;
        double r29521682 = r29521679 - r29521681;
        double r29521683 = r29521682 * r29521682;
        double r29521684 = r29521683 * r29521682;
        double r29521685 = cbrt(r29521684);
        double r29521686 = 6.296502919195928e+44;
        bool r29521687 = r29521669 <= r29521686;
        double r29521688 = 2.524624859163763e+295;
        bool r29521689 = r29521669 <= r29521688;
        double r29521690 = 1.0;
        double r29521691 = r29521689 ? r29521685 : r29521690;
        double r29521692 = r29521687 ? r29521672 : r29521691;
        double r29521693 = r29521674 ? r29521685 : r29521692;
        double r29521694 = r29521671 ? r29521672 : r29521693;
        return r29521694;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.1
Target31.2
Herbie12.4
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} \lt 0.9743233849626781:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot y\right) \cdot 4.0} - \frac{\left(y \cdot y\right) \cdot 4.0}{x \cdot x + \left(y \cdot y\right) \cdot 4.0}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x}{\sqrt{x \cdot x + \left(y \cdot y\right) \cdot 4.0}}\right)}^{2} - \frac{\left(y \cdot y\right) \cdot 4.0}{x \cdot x + \left(y \cdot y\right) \cdot 4.0}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if (* x x) < 7.1088010196971e-314 or 9.758857908001147e+18 < (* x x) < 6.296502919195928e+44

    1. Initial program 29.3

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

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

    if 7.1088010196971e-314 < (* x x) < 9.758857908001147e+18 or 6.296502919195928e+44 < (* x x) < 2.524624859163763e+295

    1. Initial program 16.3

      \[\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
    2. Using strategy rm
    3. Applied add-cbrt-cube46.9

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{\color{blue}{\sqrt[3]{\left(\left(x \cdot x + \left(y \cdot 4.0\right) \cdot y\right) \cdot \left(x \cdot x + \left(y \cdot 4.0\right) \cdot y\right)\right) \cdot \left(x \cdot x + \left(y \cdot 4.0\right) \cdot y\right)}}}\]
    4. Applied add-cbrt-cube47.0

      \[\leadsto \frac{\color{blue}{\sqrt[3]{\left(\left(x \cdot x - \left(y \cdot 4.0\right) \cdot y\right) \cdot \left(x \cdot x - \left(y \cdot 4.0\right) \cdot y\right)\right) \cdot \left(x \cdot x - \left(y \cdot 4.0\right) \cdot y\right)}}}{\sqrt[3]{\left(\left(x \cdot x + \left(y \cdot 4.0\right) \cdot y\right) \cdot \left(x \cdot x + \left(y \cdot 4.0\right) \cdot y\right)\right) \cdot \left(x \cdot x + \left(y \cdot 4.0\right) \cdot y\right)}}\]
    5. Applied cbrt-undiv47.0

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

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

    if 2.524624859163763e+295 < (* x x)

    1. Initial program 60.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \le 7.1088010196971 \cdot 10^{-314}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 9.758857908001147 \cdot 10^{+18}:\\ \;\;\;\;\sqrt[3]{\left(\left(\frac{x \cdot x}{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)} - \frac{y}{\frac{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)}{y \cdot 4.0}}\right) \cdot \left(\frac{x \cdot x}{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)} - \frac{y}{\frac{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)}{y \cdot 4.0}}\right)\right) \cdot \left(\frac{x \cdot x}{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)} - \frac{y}{\frac{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)}{y \cdot 4.0}}\right)}\\ \mathbf{elif}\;x \cdot x \le 6.296502919195928 \cdot 10^{+44}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 2.524624859163763 \cdot 10^{+295}:\\ \;\;\;\;\sqrt[3]{\left(\left(\frac{x \cdot x}{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)} - \frac{y}{\frac{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)}{y \cdot 4.0}}\right) \cdot \left(\frac{x \cdot x}{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)} - \frac{y}{\frac{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)}{y \cdot 4.0}}\right)\right) \cdot \left(\frac{x \cdot x}{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)} - \frac{y}{\frac{\mathsf{fma}\left(y, y \cdot 4.0, x \cdot x\right)}{y \cdot 4.0}}\right)}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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

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