Average Error: 31.5 → 13.2
Time: 9.3s
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 -4.542162861981963339451786530680392909626 \cdot 10^{56}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -5.780522729495912693679807571274083237549 \cdot 10^{-162}:\\ \;\;\;\;\left(\sqrt[3]{\frac{x \cdot x - \left(4 \cdot y\right) \cdot y}{\left(4 \cdot y\right) \cdot y + x \cdot x}} \cdot \sqrt[3]{\frac{x \cdot x - \left(4 \cdot y\right) \cdot y}{\left(4 \cdot y\right) \cdot y + x \cdot x}}\right) \cdot \sqrt[3]{\frac{x \cdot x - \left(4 \cdot y\right) \cdot y}{\left(4 \cdot y\right) \cdot y + x \cdot x}}\\ \mathbf{elif}\;x \le 5.430501749338192800539606964665669060352 \cdot 10^{-128}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 6.680131771318429129718732452803437555736 \cdot 10^{54}:\\ \;\;\;\;\left(\sqrt[3]{\frac{x \cdot x - \left(4 \cdot y\right) \cdot y}{\left(4 \cdot y\right) \cdot y + x \cdot x}} \cdot \sqrt[3]{\frac{x \cdot x - \left(4 \cdot y\right) \cdot y}{\left(4 \cdot y\right) \cdot y + x \cdot x}}\right) \cdot \sqrt[3]{\frac{x \cdot x - \left(4 \cdot y\right) \cdot y}{\left(4 \cdot y\right) \cdot y + x \cdot x}}\\ \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 -4.542162861981963339451786530680392909626 \cdot 10^{56}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -5.780522729495912693679807571274083237549 \cdot 10^{-162}:\\
\;\;\;\;\left(\sqrt[3]{\frac{x \cdot x - \left(4 \cdot y\right) \cdot y}{\left(4 \cdot y\right) \cdot y + x \cdot x}} \cdot \sqrt[3]{\frac{x \cdot x - \left(4 \cdot y\right) \cdot y}{\left(4 \cdot y\right) \cdot y + x \cdot x}}\right) \cdot \sqrt[3]{\frac{x \cdot x - \left(4 \cdot y\right) \cdot y}{\left(4 \cdot y\right) \cdot y + x \cdot x}}\\

\mathbf{elif}\;x \le 5.430501749338192800539606964665669060352 \cdot 10^{-128}:\\
\;\;\;\;-1\\

\mathbf{elif}\;x \le 6.680131771318429129718732452803437555736 \cdot 10^{54}:\\
\;\;\;\;\left(\sqrt[3]{\frac{x \cdot x - \left(4 \cdot y\right) \cdot y}{\left(4 \cdot y\right) \cdot y + x \cdot x}} \cdot \sqrt[3]{\frac{x \cdot x - \left(4 \cdot y\right) \cdot y}{\left(4 \cdot y\right) \cdot y + x \cdot x}}\right) \cdot \sqrt[3]{\frac{x \cdot x - \left(4 \cdot y\right) \cdot y}{\left(4 \cdot y\right) \cdot y + x \cdot x}}\\

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

\end{array}
double f(double x, double y) {
        double r392169 = x;
        double r392170 = r392169 * r392169;
        double r392171 = y;
        double r392172 = 4.0;
        double r392173 = r392171 * r392172;
        double r392174 = r392173 * r392171;
        double r392175 = r392170 - r392174;
        double r392176 = r392170 + r392174;
        double r392177 = r392175 / r392176;
        return r392177;
}

double f(double x, double y) {
        double r392178 = x;
        double r392179 = -4.542162861981963e+56;
        bool r392180 = r392178 <= r392179;
        double r392181 = 1.0;
        double r392182 = -5.780522729495913e-162;
        bool r392183 = r392178 <= r392182;
        double r392184 = r392178 * r392178;
        double r392185 = 4.0;
        double r392186 = y;
        double r392187 = r392185 * r392186;
        double r392188 = r392187 * r392186;
        double r392189 = r392184 - r392188;
        double r392190 = r392188 + r392184;
        double r392191 = r392189 / r392190;
        double r392192 = cbrt(r392191);
        double r392193 = r392192 * r392192;
        double r392194 = r392193 * r392192;
        double r392195 = 5.430501749338193e-128;
        bool r392196 = r392178 <= r392195;
        double r392197 = -1.0;
        double r392198 = 6.680131771318429e+54;
        bool r392199 = r392178 <= r392198;
        double r392200 = r392199 ? r392194 : r392181;
        double r392201 = r392196 ? r392197 : r392200;
        double r392202 = r392183 ? r392194 : r392201;
        double r392203 = r392180 ? r392181 : r392202;
        return r392203;
}

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.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 < -4.542162861981963e+56 or 6.680131771318429e+54 < x

    1. Initial program 45.6

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

      \[\leadsto \color{blue}{\frac{x \cdot x - 4 \cdot \left(y \cdot y\right)}{x \cdot x + 4 \cdot \left(y \cdot y\right)}}\]
    3. Taylor expanded around inf 13.9

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

    if -4.542162861981963e+56 < x < -5.780522729495913e-162 or 5.430501749338193e-128 < x < 6.680131771318429e+54

    1. Initial program 15.6

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

      \[\leadsto \color{blue}{\frac{x \cdot x - 4 \cdot \left(y \cdot y\right)}{x \cdot x + 4 \cdot \left(y \cdot y\right)}}\]
    3. Using strategy rm
    4. Applied add-cube-cbrt15.6

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

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

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

    if -5.780522729495913e-162 < x < 5.430501749338193e-128

    1. Initial program 29.3

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

      \[\leadsto \color{blue}{\frac{x \cdot x - 4 \cdot \left(y \cdot y\right)}{x \cdot x + 4 \cdot \left(y \cdot y\right)}}\]
    3. Taylor expanded around 0 9.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.542162861981963339451786530680392909626 \cdot 10^{56}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -5.780522729495912693679807571274083237549 \cdot 10^{-162}:\\ \;\;\;\;\left(\sqrt[3]{\frac{x \cdot x - \left(4 \cdot y\right) \cdot y}{\left(4 \cdot y\right) \cdot y + x \cdot x}} \cdot \sqrt[3]{\frac{x \cdot x - \left(4 \cdot y\right) \cdot y}{\left(4 \cdot y\right) \cdot y + x \cdot x}}\right) \cdot \sqrt[3]{\frac{x \cdot x - \left(4 \cdot y\right) \cdot y}{\left(4 \cdot y\right) \cdot y + x \cdot x}}\\ \mathbf{elif}\;x \le 5.430501749338192800539606964665669060352 \cdot 10^{-128}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 6.680131771318429129718732452803437555736 \cdot 10^{54}:\\ \;\;\;\;\left(\sqrt[3]{\frac{x \cdot x - \left(4 \cdot y\right) \cdot y}{\left(4 \cdot y\right) \cdot y + x \cdot x}} \cdot \sqrt[3]{\frac{x \cdot x - \left(4 \cdot y\right) \cdot y}{\left(4 \cdot y\right) \cdot y + x \cdot x}}\right) \cdot \sqrt[3]{\frac{x \cdot x - \left(4 \cdot y\right) \cdot y}{\left(4 \cdot y\right) \cdot y + x \cdot x}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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