Average Error: 31.9 → 14.0
Time: 1.6s
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.00186750331876538 \cdot 10^{143}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -6.5918067244508319 \cdot 10^{-138}:\\ \;\;\;\;\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 1.9631464787281808 \cdot 10^{68}:\\ \;\;\;\;-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.00186750331876538 \cdot 10^{143}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -6.5918067244508319 \cdot 10^{-138}:\\
\;\;\;\;\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 1.9631464787281808 \cdot 10^{68}:\\
\;\;\;\;-1\\

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

\end{array}
double f(double x, double y) {
        double r873033 = x;
        double r873034 = r873033 * r873033;
        double r873035 = y;
        double r873036 = 4.0;
        double r873037 = r873035 * r873036;
        double r873038 = r873037 * r873035;
        double r873039 = r873034 - r873038;
        double r873040 = r873034 + r873038;
        double r873041 = r873039 / r873040;
        return r873041;
}

double f(double x, double y) {
        double r873042 = x;
        double r873043 = -3.0018675033187654e+143;
        bool r873044 = r873042 <= r873043;
        double r873045 = 1.0;
        double r873046 = -6.591806724450832e-138;
        bool r873047 = r873042 <= r873046;
        double r873048 = r873042 * r873042;
        double r873049 = y;
        double r873050 = 4.0;
        double r873051 = r873049 * r873050;
        double r873052 = r873051 * r873049;
        double r873053 = r873048 - r873052;
        double r873054 = r873048 + r873052;
        double r873055 = r873053 / r873054;
        double r873056 = 1.9631464787281808e+68;
        bool r873057 = r873042 <= r873056;
        double r873058 = -1.0;
        double r873059 = r873057 ? r873058 : r873045;
        double r873060 = r873047 ? r873055 : r873059;
        double r873061 = r873044 ? r873045 : r873060;
        return r873061;
}

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
Herbie14.0
\[\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 3 regimes
  2. if x < -3.0018675033187654e+143 or 1.9631464787281808e+68 < x

    1. Initial program 53.1

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

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

    if -3.0018675033187654e+143 < x < -6.591806724450832e-138

    1. Initial program 14.1

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

    if -6.591806724450832e-138 < x < 1.9631464787281808e+68

    1. Initial program 24.7

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.00186750331876538 \cdot 10^{143}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -6.5918067244508319 \cdot 10^{-138}:\\ \;\;\;\;\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 1.9631464787281808 \cdot 10^{68}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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