Average Error: 31.1 → 12.7
Time: 10.6s
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 r30470188 = x;
        double r30470189 = r30470188 * r30470188;
        double r30470190 = y;
        double r30470191 = 4.0;
        double r30470192 = r30470190 * r30470191;
        double r30470193 = r30470192 * r30470190;
        double r30470194 = r30470189 - r30470193;
        double r30470195 = r30470189 + r30470193;
        double r30470196 = r30470194 / r30470195;
        return r30470196;
}

double f(double x, double y) {
        double r30470197 = x;
        double r30470198 = r30470197 * r30470197;
        double r30470199 = 3.222607567780329e-289;
        bool r30470200 = r30470198 <= r30470199;
        double r30470201 = -1.0;
        double r30470202 = 6.835592550358748e+96;
        bool r30470203 = r30470198 <= r30470202;
        double r30470204 = y;
        double r30470205 = 4.0;
        double r30470206 = r30470204 * r30470205;
        double r30470207 = r30470206 * r30470204;
        double r30470208 = r30470198 - r30470207;
        double r30470209 = r30470198 + r30470207;
        double r30470210 = r30470208 / r30470209;
        double r30470211 = 7.775826278762702e+132;
        bool r30470212 = r30470198 <= r30470211;
        double r30470213 = 1.4214205983410313e+194;
        bool r30470214 = r30470198 <= r30470213;
        double r30470215 = r30470198 / r30470209;
        double r30470216 = r30470207 / r30470209;
        double r30470217 = r30470215 - r30470216;
        double r30470218 = 1.0;
        double r30470219 = r30470214 ? r30470217 : r30470218;
        double r30470220 = r30470212 ? r30470201 : r30470219;
        double r30470221 = r30470203 ? r30470210 : r30470220;
        double r30470222 = r30470200 ? r30470201 : r30470221;
        return r30470222;
}

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 +o rules:numerics
(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))))