Average Error: 30.9 → 13.4
Time: 8.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 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 r34475844 = x;
        double r34475845 = r34475844 * r34475844;
        double r34475846 = y;
        double r34475847 = 4.0;
        double r34475848 = r34475846 * r34475847;
        double r34475849 = r34475848 * r34475846;
        double r34475850 = r34475845 - r34475849;
        double r34475851 = r34475845 + r34475849;
        double r34475852 = r34475850 / r34475851;
        return r34475852;
}

double f(double x, double y) {
        double r34475853 = x;
        double r34475854 = r34475853 * r34475853;
        double r34475855 = 1.3643855637695705e-229;
        bool r34475856 = r34475854 <= r34475855;
        double r34475857 = -1.0;
        double r34475858 = 1.0463855970660416e+213;
        bool r34475859 = r34475854 <= r34475858;
        double r34475860 = 1.0;
        double r34475861 = y;
        double r34475862 = 4.0;
        double r34475863 = r34475862 * r34475861;
        double r34475864 = r34475861 * r34475863;
        double r34475865 = r34475864 + r34475854;
        double r34475866 = sqrt(r34475865);
        double r34475867 = r34475860 / r34475866;
        double r34475868 = r34475854 - r34475864;
        double r34475869 = r34475868 / r34475866;
        double r34475870 = r34475867 * r34475869;
        double r34475871 = 1.761554774712835e+268;
        bool r34475872 = r34475854 <= r34475871;
        double r34475873 = 5.112886449152387e+290;
        bool r34475874 = r34475854 <= r34475873;
        double r34475875 = sqrt(r34475868);
        double r34475876 = r34475865 / r34475875;
        double r34475877 = r34475875 / r34475876;
        double r34475878 = r34475874 ? r34475877 : r34475860;
        double r34475879 = r34475872 ? r34475857 : r34475878;
        double r34475880 = r34475859 ? r34475870 : r34475879;
        double r34475881 = r34475856 ? r34475857 : r34475880;
        return r34475881;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original30.9
Target30.9
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} - \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.6

      \[\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.6

      \[\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.6

      \[\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.6

      \[\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.8

      \[\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.6

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

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

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

      \[\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) (/ (* (* y y) 4.0) (+ (* x x) (* (* y y) 4.0)))))

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