Average Error: 31.5 → 13.4
Time: 33.5s
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 1.3643855637695705 \cdot 10^{-229}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 1.0463855970660416 \cdot 10^{+213}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}}\right)\\ \mathbf{elif}\;x \cdot x \le 1.761554774712835 \cdot 10^{+268}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 5.112886449152387 \cdot 10^{+290}:\\ \;\;\;\;\frac{\sqrt{x \cdot x - \left(y \cdot 4.0\right) \cdot y}}{\frac{x \cdot x + \left(y \cdot 4.0\right) \cdot y}{\sqrt{x \cdot x - \left(y \cdot 4.0\right) \cdot y}}}\\ \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 1.3643855637695705 \cdot 10^{-229}:\\
\;\;\;\;-1.0\\

\mathbf{elif}\;x \cdot x \le 1.0463855970660416 \cdot 10^{+213}:\\
\;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}}\right)\\

\mathbf{elif}\;x \cdot x \le 1.761554774712835 \cdot 10^{+268}:\\
\;\;\;\;-1.0\\

\mathbf{elif}\;x \cdot x \le 5.112886449152387 \cdot 10^{+290}:\\
\;\;\;\;\frac{\sqrt{x \cdot x - \left(y \cdot 4.0\right) \cdot y}}{\frac{x \cdot x + \left(y \cdot 4.0\right) \cdot y}{\sqrt{x \cdot x - \left(y \cdot 4.0\right) \cdot y}}}\\

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

\end{array}
double f(double x, double y) {
        double r23007916 = x;
        double r23007917 = r23007916 * r23007916;
        double r23007918 = y;
        double r23007919 = 4.0;
        double r23007920 = r23007918 * r23007919;
        double r23007921 = r23007920 * r23007918;
        double r23007922 = r23007917 - r23007921;
        double r23007923 = r23007917 + r23007921;
        double r23007924 = r23007922 / r23007923;
        return r23007924;
}

double f(double x, double y) {
        double r23007925 = x;
        double r23007926 = r23007925 * r23007925;
        double r23007927 = 1.3643855637695705e-229;
        bool r23007928 = r23007926 <= r23007927;
        double r23007929 = -1.0;
        double r23007930 = 1.0463855970660416e+213;
        bool r23007931 = r23007926 <= r23007930;
        double r23007932 = y;
        double r23007933 = 4.0;
        double r23007934 = r23007932 * r23007933;
        double r23007935 = r23007934 * r23007932;
        double r23007936 = r23007926 - r23007935;
        double r23007937 = r23007926 + r23007935;
        double r23007938 = r23007936 / r23007937;
        double r23007939 = exp(r23007938);
        double r23007940 = log(r23007939);
        double r23007941 = 1.761554774712835e+268;
        bool r23007942 = r23007926 <= r23007941;
        double r23007943 = 5.112886449152387e+290;
        bool r23007944 = r23007926 <= r23007943;
        double r23007945 = sqrt(r23007936);
        double r23007946 = r23007937 / r23007945;
        double r23007947 = r23007945 / r23007946;
        double r23007948 = 1.0;
        double r23007949 = r23007944 ? r23007947 : r23007948;
        double r23007950 = r23007942 ? r23007929 : r23007949;
        double r23007951 = r23007931 ? r23007940 : r23007950;
        double r23007952 = r23007928 ? r23007929 : r23007951;
        return r23007952;
}

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.5
Target31.2
Herbie13.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.0} - \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 4 regimes
  2. if (* x x) < 1.3643855637695705e-229 or 1.0463855970660416e+213 < (* x x) < 1.761554774712835e+268

    1. Initial program 25.9

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

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

    if 1.3643855637695705e-229 < (* x x) < 1.0463855970660416e+213

    1. Initial program 15.7

      \[\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-log-exp15.7

      \[\leadsto \color{blue}{\log \left(e^{\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}}\right)}\]

    if 1.761554774712835e+268 < (* x x) < 5.112886449152387e+290

    1. Initial program 14.7

      \[\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-sqr-sqrt16.5

      \[\leadsto \frac{\color{blue}{\sqrt{x \cdot x - \left(y \cdot 4.0\right) \cdot y} \cdot \sqrt{x \cdot x - \left(y \cdot 4.0\right) \cdot y}}}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
    4. Applied associate-/l*16.5

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

    if 5.112886449152387e+290 < (* x x)

    1. Initial program 61.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 9.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \le 1.3643855637695705 \cdot 10^{-229}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 1.0463855970660416 \cdot 10^{+213}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}}\right)\\ \mathbf{elif}\;x \cdot x \le 1.761554774712835 \cdot 10^{+268}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 5.112886449152387 \cdot 10^{+290}:\\ \;\;\;\;\frac{\sqrt{x \cdot x - \left(y \cdot 4.0\right) \cdot y}}{\frac{x \cdot x + \left(y \cdot 4.0\right) \cdot y}{\sqrt{x \cdot x - \left(y \cdot 4.0\right) \cdot y}}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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

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