Average Error: 31.1 → 12.6
Time: 11.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 7.1088010196971 \cdot 10^{-314}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 9.758857908001147 \cdot 10^{+18}:\\ \;\;\;\;\frac{1}{\frac{y \cdot \left(4.0 \cdot y\right) + x \cdot x}{x \cdot x - y \cdot \left(4.0 \cdot y\right)}}\\ \mathbf{elif}\;x \cdot x \le 6.296502919195928 \cdot 10^{+44}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 3.1031769081973586 \cdot 10^{+257}:\\ \;\;\;\;\frac{1}{\frac{y \cdot \left(4.0 \cdot y\right) + x \cdot x}{x \cdot x - y \cdot \left(4.0 \cdot y\right)}}\\ \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 7.1088010196971 \cdot 10^{-314}:\\
\;\;\;\;-1.0\\

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

\mathbf{elif}\;x \cdot x \le 6.296502919195928 \cdot 10^{+44}:\\
\;\;\;\;-1.0\\

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

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

\end{array}
double f(double x, double y) {
        double r30898279 = x;
        double r30898280 = r30898279 * r30898279;
        double r30898281 = y;
        double r30898282 = 4.0;
        double r30898283 = r30898281 * r30898282;
        double r30898284 = r30898283 * r30898281;
        double r30898285 = r30898280 - r30898284;
        double r30898286 = r30898280 + r30898284;
        double r30898287 = r30898285 / r30898286;
        return r30898287;
}

double f(double x, double y) {
        double r30898288 = x;
        double r30898289 = r30898288 * r30898288;
        double r30898290 = 7.1088010196971e-314;
        bool r30898291 = r30898289 <= r30898290;
        double r30898292 = -1.0;
        double r30898293 = 9.758857908001147e+18;
        bool r30898294 = r30898289 <= r30898293;
        double r30898295 = 1.0;
        double r30898296 = y;
        double r30898297 = 4.0;
        double r30898298 = r30898297 * r30898296;
        double r30898299 = r30898296 * r30898298;
        double r30898300 = r30898299 + r30898289;
        double r30898301 = r30898289 - r30898299;
        double r30898302 = r30898300 / r30898301;
        double r30898303 = r30898295 / r30898302;
        double r30898304 = 6.296502919195928e+44;
        bool r30898305 = r30898289 <= r30898304;
        double r30898306 = 3.1031769081973586e+257;
        bool r30898307 = r30898289 <= r30898306;
        double r30898308 = r30898307 ? r30898303 : r30898295;
        double r30898309 = r30898305 ? r30898292 : r30898308;
        double r30898310 = r30898294 ? r30898303 : r30898309;
        double r30898311 = r30898291 ? r30898292 : r30898310;
        return r30898311;
}

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.2
Herbie12.6
\[\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 3 regimes
  2. if (* x x) < 7.1088010196971e-314 or 9.758857908001147e+18 < (* x x) < 6.296502919195928e+44

    1. Initial program 29.3

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

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

    if 7.1088010196971e-314 < (* x x) < 9.758857908001147e+18 or 6.296502919195928e+44 < (* x x) < 3.1031769081973586e+257

    1. Initial program 16.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. Using strategy rm
    3. Applied clear-num16.1

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

    if 3.1031769081973586e+257 < (* x x)

    1. Initial program 56.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. Taylor expanded around inf 9.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \le 7.1088010196971 \cdot 10^{-314}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 9.758857908001147 \cdot 10^{+18}:\\ \;\;\;\;\frac{1}{\frac{y \cdot \left(4.0 \cdot y\right) + x \cdot x}{x \cdot x - y \cdot \left(4.0 \cdot y\right)}}\\ \mathbf{elif}\;x \cdot x \le 6.296502919195928 \cdot 10^{+44}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 3.1031769081973586 \cdot 10^{+257}:\\ \;\;\;\;\frac{1}{\frac{y \cdot \left(4.0 \cdot y\right) + x \cdot x}{x \cdot x - y \cdot \left(4.0 \cdot y\right)}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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