Average Error: 32.3 → 13.6
Time: 5.3s
Precision: 64
\[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -7.71073899284975746 \cdot 10^{142}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.38415960656676321 \cdot 10^{-97}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \log \left(e^{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{elif}\;y \le 1.1196094733529732 \cdot 10^{-55}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 28161126.972837694:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \log \left(e^{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{elif}\;y \le 4.01162503157803517 \cdot 10^{38}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 2.16201455188241352 \cdot 10^{107}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \log \left(e^{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{elif}\;y \le 4.36744780112662469 \cdot 10^{128}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]
\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}
\begin{array}{l}
\mathbf{if}\;y \le -7.71073899284975746 \cdot 10^{142}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.38415960656676321 \cdot 10^{-97}:\\
\;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \log \left(e^{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\

\mathbf{elif}\;y \le 1.1196094733529732 \cdot 10^{-55}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 28161126.972837694:\\
\;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \log \left(e^{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\

\mathbf{elif}\;y \le 4.01162503157803517 \cdot 10^{38}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 2.16201455188241352 \cdot 10^{107}:\\
\;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \log \left(e^{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\

\mathbf{elif}\;y \le 4.36744780112662469 \cdot 10^{128}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r721828 = x;
        double r721829 = r721828 * r721828;
        double r721830 = y;
        double r721831 = 4.0;
        double r721832 = r721830 * r721831;
        double r721833 = r721832 * r721830;
        double r721834 = r721829 - r721833;
        double r721835 = r721829 + r721833;
        double r721836 = r721834 / r721835;
        return r721836;
}

double f(double x, double y) {
        double r721837 = y;
        double r721838 = -7.710738992849757e+142;
        bool r721839 = r721837 <= r721838;
        double r721840 = -1.0;
        double r721841 = -1.3841596065667632e-97;
        bool r721842 = r721837 <= r721841;
        double r721843 = x;
        double r721844 = r721843 * r721843;
        double r721845 = 4.0;
        double r721846 = r721837 * r721845;
        double r721847 = r721846 * r721837;
        double r721848 = r721844 + r721847;
        double r721849 = r721844 / r721848;
        double r721850 = r721847 / r721848;
        double r721851 = exp(r721850);
        double r721852 = log(r721851);
        double r721853 = r721849 - r721852;
        double r721854 = 1.1196094733529732e-55;
        bool r721855 = r721837 <= r721854;
        double r721856 = 1.0;
        double r721857 = 28161126.972837694;
        bool r721858 = r721837 <= r721857;
        double r721859 = 4.011625031578035e+38;
        bool r721860 = r721837 <= r721859;
        double r721861 = 2.1620145518824135e+107;
        bool r721862 = r721837 <= r721861;
        double r721863 = 4.367447801126625e+128;
        bool r721864 = r721837 <= r721863;
        double r721865 = r721864 ? r721856 : r721840;
        double r721866 = r721862 ? r721853 : r721865;
        double r721867 = r721860 ? r721856 : r721866;
        double r721868 = r721858 ? r721853 : r721867;
        double r721869 = r721855 ? r721856 : r721868;
        double r721870 = r721842 ? r721853 : r721869;
        double r721871 = r721839 ? r721840 : r721870;
        return r721871;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original32.3
Target32.0
Herbie13.6
\[\begin{array}{l} \mathbf{if}\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y} \lt 0.974323384962678118:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot y\right) \cdot 4} - \frac{\left(y \cdot y\right) \cdot 4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{x}{\sqrt{x \cdot x + \left(y \cdot y\right) \cdot 4}}\right)}^{2} - \frac{\left(y \cdot y\right) \cdot 4}{x \cdot x + \left(y \cdot y\right) \cdot 4}\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if y < -7.710738992849757e+142 or 4.367447801126625e+128 < y

    1. Initial program 59.1

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Taylor expanded around 0 8.6

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

    if -7.710738992849757e+142 < y < -1.3841596065667632e-97 or 1.1196094733529732e-55 < y < 28161126.972837694 or 4.011625031578035e+38 < y < 2.1620145518824135e+107

    1. Initial program 16.7

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Using strategy rm
    3. Applied div-sub16.7

      \[\leadsto \color{blue}{\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\]
    4. Using strategy rm
    5. Applied add-log-exp16.7

      \[\leadsto \frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \color{blue}{\log \left(e^{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)}\]

    if -1.3841596065667632e-97 < y < 1.1196094733529732e-55 or 28161126.972837694 < y < 4.011625031578035e+38 or 2.1620145518824135e+107 < y < 4.367447801126625e+128

    1. Initial program 25.0

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]
    2. Taylor expanded around inf 14.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -7.71073899284975746 \cdot 10^{142}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.38415960656676321 \cdot 10^{-97}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \log \left(e^{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{elif}\;y \le 1.1196094733529732 \cdot 10^{-55}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 28161126.972837694:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \log \left(e^{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{elif}\;y \le 4.01162503157803517 \cdot 10^{38}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 2.16201455188241352 \cdot 10^{107}:\\ \;\;\;\;\frac{x \cdot x}{x \cdot x + \left(y \cdot 4\right) \cdot y} - \log \left(e^{\frac{\left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{elif}\;y \le 4.36744780112662469 \cdot 10^{128}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

herbie shell --seed 2020047 
(FPCore (x y)
  :name "Diagrams.TwoD.Arc:arcBetween from diagrams-lib-1.3.0.3"
  :precision binary64

  :herbie-target
  (if (< (/ (- (* x x) (* (* y 4) y)) (+ (* x x) (* (* y 4) y))) 0.9743233849626781) (- (/ (* x x) (+ (* x x) (* (* y y) 4))) (/ (* (* y y) 4) (+ (* x x) (* (* y y) 4)))) (- (pow (/ x (sqrt (+ (* x x) (* (* y y) 4)))) 2) (/ (* (* y y) 4) (+ (* x x) (* (* y y) 4)))))

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