Average Error: 31.5 → 13.4
Time: 36.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 1.3643855637695705 \cdot 10^{-229}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 1.0463855970660416 \cdot 10^{+213}:\\ \;\;\;\;\frac{1}{\sqrt{y \cdot \left(4.0 \cdot y\right) + x \cdot x}} \cdot \frac{x \cdot x - y \cdot \left(4.0 \cdot y\right)}{\sqrt{y \cdot \left(4.0 \cdot y\right) + x \cdot x}}\\ \mathbf{elif}\;x \cdot x \le 1.761554774712835 \cdot 10^{+268}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 5.112886449152387 \cdot 10^{+290}:\\ \;\;\;\;\frac{\sqrt{x \cdot x - y \cdot \left(4.0 \cdot y\right)}}{\frac{y \cdot \left(4.0 \cdot y\right) + x \cdot x}{\sqrt{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 1.3643855637695705 \cdot 10^{-229}:\\
\;\;\;\;-1.0\\

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

\mathbf{elif}\;x \cdot x \le 1.761554774712835 \cdot 10^{+268}:\\
\;\;\;\;-1.0\\

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

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

\end{array}
double f(double x, double y) {
        double r31787972 = x;
        double r31787973 = r31787972 * r31787972;
        double r31787974 = y;
        double r31787975 = 4.0;
        double r31787976 = r31787974 * r31787975;
        double r31787977 = r31787976 * r31787974;
        double r31787978 = r31787973 - r31787977;
        double r31787979 = r31787973 + r31787977;
        double r31787980 = r31787978 / r31787979;
        return r31787980;
}

double f(double x, double y) {
        double r31787981 = x;
        double r31787982 = r31787981 * r31787981;
        double r31787983 = 1.3643855637695705e-229;
        bool r31787984 = r31787982 <= r31787983;
        double r31787985 = -1.0;
        double r31787986 = 1.0463855970660416e+213;
        bool r31787987 = r31787982 <= r31787986;
        double r31787988 = 1.0;
        double r31787989 = y;
        double r31787990 = 4.0;
        double r31787991 = r31787990 * r31787989;
        double r31787992 = r31787989 * r31787991;
        double r31787993 = r31787992 + r31787982;
        double r31787994 = sqrt(r31787993);
        double r31787995 = r31787988 / r31787994;
        double r31787996 = r31787982 - r31787992;
        double r31787997 = r31787996 / r31787994;
        double r31787998 = r31787995 * r31787997;
        double r31787999 = 1.761554774712835e+268;
        bool r31788000 = r31787982 <= r31787999;
        double r31788001 = 5.112886449152387e+290;
        bool r31788002 = r31787982 <= r31788001;
        double r31788003 = sqrt(r31787996);
        double r31788004 = r31787993 / r31788003;
        double r31788005 = r31788003 / r31788004;
        double r31788006 = r31788002 ? r31788005 : r31787988;
        double r31788007 = r31788000 ? r31787985 : r31788006;
        double r31788008 = r31787987 ? r31787998 : r31788007;
        double r31788009 = r31787984 ? r31787985 : r31788008;
        return r31788009;
}

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.5
Target31.2
Herbie13.4
\[\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.0} - \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) < 1.3643855637695705e-229 or 1.0463855970660416e+213 < (* x x) < 1.761554774712835e+268

    1. Initial program 25.9

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

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

    if 1.3643855637695705e-229 < (* x x) < 1.0463855970660416e+213

    1. Initial program 15.7

      \[\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 add-sqr-sqrt15.7

      \[\leadsto \frac{x \cdot x - \left(y \cdot 4.0\right) \cdot y}{\color{blue}{\sqrt{x \cdot x + \left(y \cdot 4.0\right) \cdot y} \cdot \sqrt{x \cdot x + \left(y \cdot 4.0\right) \cdot y}}}\]
    4. Applied *-un-lft-identity15.7

      \[\leadsto \frac{\color{blue}{1 \cdot \left(x \cdot x - \left(y \cdot 4.0\right) \cdot y\right)}}{\sqrt{x \cdot x + \left(y \cdot 4.0\right) \cdot y} \cdot \sqrt{x \cdot x + \left(y \cdot 4.0\right) \cdot y}}\]
    5. Applied times-frac15.9

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

    if 1.761554774712835e+268 < (* x x) < 5.112886449152387e+290

    1. Initial program 14.7

      \[\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 add-sqr-sqrt16.5

      \[\leadsto \frac{\color{blue}{\sqrt{x \cdot x - \left(y \cdot 4.0\right) \cdot y} \cdot \sqrt{x \cdot x - \left(y \cdot 4.0\right) \cdot y}}}{x \cdot x + \left(y \cdot 4.0\right) \cdot y}\]
    4. Applied associate-/l*16.5

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

    if 5.112886449152387e+290 < (* x x)

    1. Initial program 61.2

      \[\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 4 regimes into one program.
  4. Final simplification13.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \le 1.3643855637695705 \cdot 10^{-229}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 1.0463855970660416 \cdot 10^{+213}:\\ \;\;\;\;\frac{1}{\sqrt{y \cdot \left(4.0 \cdot y\right) + x \cdot x}} \cdot \frac{x \cdot x - y \cdot \left(4.0 \cdot y\right)}{\sqrt{y \cdot \left(4.0 \cdot y\right) + x \cdot x}}\\ \mathbf{elif}\;x \cdot x \le 1.761554774712835 \cdot 10^{+268}:\\ \;\;\;\;-1.0\\ \mathbf{elif}\;x \cdot x \le 5.112886449152387 \cdot 10^{+290}:\\ \;\;\;\;\frac{\sqrt{x \cdot x - y \cdot \left(4.0 \cdot y\right)}}{\frac{y \cdot \left(4.0 \cdot y\right) + x \cdot x}{\sqrt{x \cdot x - y \cdot \left(4.0 \cdot y\right)}}}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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

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