Average Error: 31.9 → 15.8
Time: 2.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 -3.9547679581202103 \cdot 10^{27}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -2.50444493033678056 \cdot 10^{-25}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -3.246960260390424 \cdot 10^{-67}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \le -4.3884605229815477 \cdot 10^{-101}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le -3.49297723193740726 \cdot 10^{-162}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{elif}\;x \le 1.9844193705891298 \cdot 10^{-132}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 9.97051040847491787 \cdot 10^{-75}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \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 -2.50444493033678056 \cdot 10^{-25}:\\
\;\;\;\;-1\\

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

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

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

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

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

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

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

\end{array}
double f(double x, double y) {
        double r767283 = x;
        double r767284 = r767283 * r767283;
        double r767285 = y;
        double r767286 = 4.0;
        double r767287 = r767285 * r767286;
        double r767288 = r767287 * r767285;
        double r767289 = r767284 - r767288;
        double r767290 = r767284 + r767288;
        double r767291 = r767289 / r767290;
        return r767291;
}

double f(double x, double y) {
        double r767292 = x;
        double r767293 = -3.9547679581202103e+27;
        bool r767294 = r767292 <= r767293;
        double r767295 = 1.0;
        double r767296 = -2.5044449303367806e-25;
        bool r767297 = r767292 <= r767296;
        double r767298 = -1.0;
        double r767299 = -3.2469602603904245e-67;
        bool r767300 = r767292 <= r767299;
        double r767301 = r767292 * r767292;
        double r767302 = y;
        double r767303 = 4.0;
        double r767304 = r767302 * r767303;
        double r767305 = r767304 * r767302;
        double r767306 = r767301 - r767305;
        double r767307 = r767301 + r767305;
        double r767308 = r767306 / r767307;
        double r767309 = -4.388460522981548e-101;
        bool r767310 = r767292 <= r767309;
        double r767311 = -3.4929772319374073e-162;
        bool r767312 = r767292 <= r767311;
        double r767313 = exp(r767308);
        double r767314 = log(r767313);
        double r767315 = 1.98441937058913e-132;
        bool r767316 = r767292 <= r767315;
        double r767317 = 9.970510408474918e-75;
        bool r767318 = r767292 <= r767317;
        double r767319 = 3.0944404152107775e+89;
        bool r767320 = r767292 <= r767319;
        double r767321 = r767320 ? r767298 : r767295;
        double r767322 = r767318 ? r767308 : r767321;
        double r767323 = r767316 ? r767298 : r767322;
        double r767324 = r767312 ? r767314 : r767323;
        double r767325 = r767310 ? r767298 : r767324;
        double r767326 = r767300 ? r767308 : r767325;
        double r767327 = r767297 ? r767298 : r767326;
        double r767328 = r767294 ? r767295 : r767327;
        return r767328;
}

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.9
Target31.6
Herbie15.8
\[\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 < -2.5044449303367806e-25 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.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 0 18.8

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

    if -2.5044449303367806e-25 < x < -3.2469602603904245e-67 or 1.98441937058913e-132 < x < 9.970510408474918e-75

    1. Initial program 14.3

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

    if -4.388460522981548e-101 < x < -3.4929772319374073e-162

    1. Initial program 13.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 add-log-exp13.1

      \[\leadsto \color{blue}{\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification15.8

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

Reproduce

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