Average Error: 31.4 → 12.2
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}\;x \le -8.785978400076085017966068453698854654375 \cdot 10^{123}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -5.31960586782750077819292973445156907452 \cdot 10^{-138}:\\ \;\;\;\;\left(\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}} + \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) \cdot \left(\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}} - \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{elif}\;x \le 6.492432921720208528877157624509279301342 \cdot 10^{-45}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 2.779617689568547339288402953421560212757 \cdot 10^{95}:\\ \;\;\;\;\left(\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}} + \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) \cdot \left(\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}} - \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot 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}\;x \le -8.785978400076085017966068453698854654375 \cdot 10^{123}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -5.31960586782750077819292973445156907452 \cdot 10^{-138}:\\
\;\;\;\;\left(\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}} + \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) \cdot \left(\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}} - \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\

\mathbf{elif}\;x \le 6.492432921720208528877157624509279301342 \cdot 10^{-45}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 2.779617689568547339288402953421560212757 \cdot 10^{95}:\\
\;\;\;\;\left(\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}} + \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) \cdot \left(\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}} - \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\

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

\end{array}
double f(double x, double y) {
        double r186795623 = x;
        double r186795624 = r186795623 * r186795623;
        double r186795625 = y;
        double r186795626 = 4.0;
        double r186795627 = r186795625 * r186795626;
        double r186795628 = r186795627 * r186795625;
        double r186795629 = r186795624 - r186795628;
        double r186795630 = r186795624 + r186795628;
        double r186795631 = r186795629 / r186795630;
        return r186795631;
}

double f(double x, double y) {
        double r186795632 = x;
        double r186795633 = -8.785978400076085e+123;
        bool r186795634 = r186795632 <= r186795633;
        double r186795635 = 1.0;
        double r186795636 = -5.319605867827501e-138;
        bool r186795637 = r186795632 <= r186795636;
        double r186795638 = r186795632 * r186795632;
        double r186795639 = y;
        double r186795640 = 4.0;
        double r186795641 = r186795639 * r186795640;
        double r186795642 = r186795641 * r186795639;
        double r186795643 = r186795638 + r186795642;
        double r186795644 = r186795638 / r186795643;
        double r186795645 = sqrt(r186795644);
        double r186795646 = r186795642 / r186795643;
        double r186795647 = sqrt(r186795646);
        double r186795648 = r186795645 + r186795647;
        double r186795649 = r186795645 - r186795647;
        double r186795650 = r186795648 * r186795649;
        double r186795651 = 6.492432921720209e-45;
        bool r186795652 = r186795632 <= r186795651;
        double r186795653 = -1.0;
        double r186795654 = 2.7796176895685473e+95;
        bool r186795655 = r186795632 <= r186795654;
        double r186795656 = r186795655 ? r186795650 : r186795635;
        double r186795657 = r186795652 ? r186795653 : r186795656;
        double r186795658 = r186795637 ? r186795650 : r186795657;
        double r186795659 = r186795634 ? r186795635 : r186795658;
        return r186795659;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original31.4
Target31.1
Herbie12.2
\[\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 < -8.785978400076085e+123 or 2.7796176895685473e+95 < x

    1. Initial program 52.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 inf 10.0

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

    if -8.785978400076085e+123 < x < -5.319605867827501e-138 or 6.492432921720209e-45 < x < 2.7796176895685473e+95

    1. Initial program 15.2

      \[\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.2

      \[\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. Using strategy rm
    5. Applied add-sqr-sqrt15.2

      \[\leadsto \frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \color{blue}{\sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}}\]
    6. Applied add-sqr-sqrt15.2

      \[\leadsto \color{blue}{\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}}} - \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}} \cdot \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\]
    7. Applied difference-of-squares15.2

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

    if -5.319605867827501e-138 < x < 6.492432921720209e-45

    1. Initial program 26.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -8.785978400076085017966068453698854654375 \cdot 10^{123}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -5.31960586782750077819292973445156907452 \cdot 10^{-138}:\\ \;\;\;\;\left(\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}} + \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) \cdot \left(\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}} - \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{elif}\;x \le 6.492432921720208528877157624509279301342 \cdot 10^{-45}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 2.779617689568547339288402953421560212757 \cdot 10^{95}:\\ \;\;\;\;\left(\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}} + \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right) \cdot \left(\sqrt{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y}} - \sqrt{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

herbie shell --seed 2019173 
(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))))