Average Error: 31.1 → 12.7
Time: 7.3s
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 3.222607567780329 \cdot 10^{-289}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 6.835592550358748 \cdot 10^{+96}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\\ \mathbf{elif}\;x \cdot x \le 7.775826278762702 \cdot 10^{+132}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 1.4214205983410313 \cdot 10^{+194}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} - \frac{\left(y \cdot 4.0\right) \cdot y}{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 3.222607567780329 \cdot 10^{-289}:\\
\;\;\;\;-1.0\\

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

\mathbf{elif}\;x \cdot x \le 7.775826278762702 \cdot 10^{+132}:\\
\;\;\;\;-1.0\\

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

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

\end{array}
double f(double x, double y) {
        double r34032188 = x;
        double r34032189 = r34032188 * r34032188;
        double r34032190 = y;
        double r34032191 = 4.0;
        double r34032192 = r34032190 * r34032191;
        double r34032193 = r34032192 * r34032190;
        double r34032194 = r34032189 - r34032193;
        double r34032195 = r34032189 + r34032193;
        double r34032196 = r34032194 / r34032195;
        return r34032196;
}

double f(double x, double y) {
        double r34032197 = x;
        double r34032198 = r34032197 * r34032197;
        double r34032199 = 3.222607567780329e-289;
        bool r34032200 = r34032198 <= r34032199;
        double r34032201 = -1.0;
        double r34032202 = 6.835592550358748e+96;
        bool r34032203 = r34032198 <= r34032202;
        double r34032204 = y;
        double r34032205 = 4.0;
        double r34032206 = r34032204 * r34032205;
        double r34032207 = r34032206 * r34032204;
        double r34032208 = r34032198 - r34032207;
        double r34032209 = r34032198 + r34032207;
        double r34032210 = r34032208 / r34032209;
        double r34032211 = 7.775826278762702e+132;
        bool r34032212 = r34032198 <= r34032211;
        double r34032213 = 1.4214205983410313e+194;
        bool r34032214 = r34032198 <= r34032213;
        double r34032215 = r34032198 / r34032209;
        double r34032216 = r34032207 / r34032209;
        double r34032217 = r34032215 - r34032216;
        double r34032218 = 1.0;
        double r34032219 = r34032214 ? r34032217 : r34032218;
        double r34032220 = r34032212 ? r34032201 : r34032219;
        double r34032221 = r34032203 ? r34032210 : r34032220;
        double r34032222 = r34032200 ? r34032201 : r34032221;
        return r34032222;
}

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.1
Target31.1
Herbie12.7
\[\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} - \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) < 3.222607567780329e-289 or 6.835592550358748e+96 < (* x x) < 7.775826278762702e+132

    1. Initial program 29.0

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

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

    if 3.222607567780329e-289 < (* x x) < 6.835592550358748e+96

    1. Initial program 15.6

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

    if 7.775826278762702e+132 < (* x x) < 1.4214205983410313e+194

    1. Initial program 17.4

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

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

    if 1.4214205983410313e+194 < (* x x)

    1. Initial program 49.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \le 3.222607567780329 \cdot 10^{-289}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 6.835592550358748 \cdot 10^{+96}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\\ \mathbf{elif}\;x \cdot x \le 7.775826278762702 \cdot 10^{+132}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 1.4214205983410313 \cdot 10^{+194}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4.0\right) \cdot y} - \frac{\left(y \cdot 4.0\right) \cdot y}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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

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