Average Error: 31.9 → 13.4
Time: 10.4s
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}\;y \le -2.353923326691391034540562342524064872962 \cdot 10^{65}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -4411333192729502498209126154240:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le -8.489767143855688201825063342670990910314 \cdot 10^{-144}:\\ \;\;\;\;\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}\;y \le 1.729595114527968499219760392830536964437 \cdot 10^{-117}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 2378971864383551305063064530685104488448:\\ \;\;\;\;\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}\;y \le -2.353923326691391034540562342524064872962 \cdot 10^{65}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -4411333192729502498209126154240:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le -8.489767143855688201825063342670990910314 \cdot 10^{-144}:\\
\;\;\;\;\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}\;y \le 1.729595114527968499219760392830536964437 \cdot 10^{-117}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 2378971864383551305063064530685104488448:\\
\;\;\;\;\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 r412689 = x;
        double r412690 = r412689 * r412689;
        double r412691 = y;
        double r412692 = 4.0;
        double r412693 = r412691 * r412692;
        double r412694 = r412693 * r412691;
        double r412695 = r412690 - r412694;
        double r412696 = r412690 + r412694;
        double r412697 = r412695 / r412696;
        return r412697;
}

double f(double x, double y) {
        double r412698 = y;
        double r412699 = -2.353923326691391e+65;
        bool r412700 = r412698 <= r412699;
        double r412701 = -1.0;
        double r412702 = -4.4113331927295025e+30;
        bool r412703 = r412698 <= r412702;
        double r412704 = 1.0;
        double r412705 = -8.489767143855688e-144;
        bool r412706 = r412698 <= r412705;
        double r412707 = x;
        double r412708 = r412707 * r412707;
        double r412709 = 4.0;
        double r412710 = r412698 * r412709;
        double r412711 = r412710 * r412698;
        double r412712 = r412708 - r412711;
        double r412713 = fma(r412707, r412707, r412711);
        double r412714 = r412712 / r412713;
        double r412715 = 1.7295951145279685e-117;
        bool r412716 = r412698 <= r412715;
        double r412717 = 2.3789718643835513e+39;
        bool r412718 = r412698 <= r412717;
        double r412719 = r412718 ? r412714 : r412701;
        double r412720 = r412716 ? r412704 : r412719;
        double r412721 = r412706 ? r412714 : r412720;
        double r412722 = r412703 ? r412704 : r412721;
        double r412723 = r412700 ? r412701 : r412722;
        return r412723;
}

Error

Bits error versus x

Bits error versus y

Target

Original31.9
Target31.6
Herbie13.4
\[\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 y < -2.353923326691391e+65 or 2.3789718643835513e+39 < y

    1. Initial program 45.0

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Simplified45.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 13.0

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

    if -2.353923326691391e+65 < y < -4.4113331927295025e+30 or -8.489767143855688e-144 < y < 1.7295951145279685e-117

    1. Initial program 27.3

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

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

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

    if -4.4113331927295025e+30 < y < -8.489767143855688e-144 or 1.7295951145279685e-117 < y < 2.3789718643835513e+39

    1. Initial program 16.7

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

      \[\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. Recombined 3 regimes into one program.
  4. Final simplification13.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -2.353923326691391034540562342524064872962 \cdot 10^{65}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -4411333192729502498209126154240:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le -8.489767143855688201825063342670990910314 \cdot 10^{-144}:\\ \;\;\;\;\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}\;y \le 1.729595114527968499219760392830536964437 \cdot 10^{-117}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 2378971864383551305063064530685104488448:\\ \;\;\;\;\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 2019347 +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))))