Average Error: 31.9 → 15.8
Time: 1.9s
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 r675969 = x;
        double r675970 = r675969 * r675969;
        double r675971 = y;
        double r675972 = 4.0;
        double r675973 = r675971 * r675972;
        double r675974 = r675973 * r675971;
        double r675975 = r675970 - r675974;
        double r675976 = r675970 + r675974;
        double r675977 = r675975 / r675976;
        return r675977;
}

double f(double x, double y) {
        double r675978 = x;
        double r675979 = -3.9547679581202103e+27;
        bool r675980 = r675978 <= r675979;
        double r675981 = 1.0;
        double r675982 = -2.5044449303367806e-25;
        bool r675983 = r675978 <= r675982;
        double r675984 = -1.0;
        double r675985 = -3.2469602603904245e-67;
        bool r675986 = r675978 <= r675985;
        double r675987 = r675978 * r675978;
        double r675988 = y;
        double r675989 = 4.0;
        double r675990 = r675988 * r675989;
        double r675991 = r675990 * r675988;
        double r675992 = r675987 - r675991;
        double r675993 = r675987 + r675991;
        double r675994 = r675992 / r675993;
        double r675995 = -4.388460522981548e-101;
        bool r675996 = r675978 <= r675995;
        double r675997 = -3.4929772319374073e-162;
        bool r675998 = r675978 <= r675997;
        double r675999 = exp(r675994);
        double r676000 = log(r675999);
        double r676001 = 1.98441937058913e-132;
        bool r676002 = r675978 <= r676001;
        double r676003 = 9.970510408474918e-75;
        bool r676004 = r675978 <= r676003;
        double r676005 = 3.0944404152107775e+89;
        bool r676006 = r675978 <= r676005;
        double r676007 = r676006 ? r675984 : r675981;
        double r676008 = r676004 ? r675994 : r676007;
        double r676009 = r676002 ? r675984 : r676008;
        double r676010 = r675998 ? r676000 : r676009;
        double r676011 = r675996 ? r675984 : r676010;
        double r676012 = r675986 ? r675994 : r676011;
        double r676013 = r675983 ? r675984 : r676012;
        double r676014 = r675980 ? r675981 : r676013;
        return r676014;
}

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))))