Average Error: 32.4 → 12.2
Time: 4.8s
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 -1.10209323570294511 \cdot 10^{154}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -7.05570383594217736 \cdot 10^{-134}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x \cdot x}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \le 3.30957855650517974 \cdot 10^{-97}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 2.70835173311075 \cdot 10^{105}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x \cdot x}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \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 -1.10209323570294511 \cdot 10^{154}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;x \le 3.30957855650517974 \cdot 10^{-97}:\\
\;\;\;\;-1\\

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

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

\end{array}
double f(double x, double y) {
        double r785025 = x;
        double r785026 = r785025 * r785025;
        double r785027 = y;
        double r785028 = 4.0;
        double r785029 = r785027 * r785028;
        double r785030 = r785029 * r785027;
        double r785031 = r785026 - r785030;
        double r785032 = r785026 + r785030;
        double r785033 = r785031 / r785032;
        return r785033;
}

double f(double x, double y) {
        double r785034 = x;
        double r785035 = -1.1020932357029451e+154;
        bool r785036 = r785034 <= r785035;
        double r785037 = 1.0;
        double r785038 = -7.055703835942177e-134;
        bool r785039 = r785034 <= r785038;
        double r785040 = r785034 * r785034;
        double r785041 = y;
        double r785042 = 4.0;
        double r785043 = r785041 * r785042;
        double r785044 = r785043 * r785041;
        double r785045 = r785040 + r785044;
        double r785046 = r785045 / r785040;
        double r785047 = r785037 / r785046;
        double r785048 = r785044 / r785045;
        double r785049 = r785047 - r785048;
        double r785050 = 3.3095785565051797e-97;
        bool r785051 = r785034 <= r785050;
        double r785052 = -1.0;
        double r785053 = 2.70835173311075e+105;
        bool r785054 = r785034 <= r785053;
        double r785055 = r785054 ? r785049 : r785037;
        double r785056 = r785051 ? r785052 : r785055;
        double r785057 = r785039 ? r785049 : r785056;
        double r785058 = r785036 ? r785037 : r785057;
        return r785058;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original32.4
Target32.1
Herbie12.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.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 < -1.1020932357029451e+154 or 2.70835173311075e+105 < x

    1. Initial program 57.5

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

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

    if -1.1020932357029451e+154 < x < -7.055703835942177e-134 or 3.3095785565051797e-97 < x < 2.70835173311075e+105

    1. Initial program 16.4

      \[\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 div-sub16.4

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\]
    4. Using strategy rm
    5. Applied clear-num16.4

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

    if -7.055703835942177e-134 < x < 3.3095785565051797e-97

    1. Initial program 28.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 10.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.10209323570294511 \cdot 10^{154}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -7.05570383594217736 \cdot 10^{-134}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x \cdot x}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;x \le 3.30957855650517974 \cdot 10^{-97}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 2.70835173311075 \cdot 10^{105}:\\ \;\;\;\;\frac{1}{\frac{x \cdot x + \left(y \cdot 4\right) \cdot y}{x \cdot x}} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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