Average Error: 31.1 → 12.3
Time: 1.9s
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}\;x \le -1.505752205836537605611230467447200313868 \cdot 10^{136}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.820637179707639667962910639720240578708 \cdot 10^{-86}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{elif}\;x \le 2.465931800714866985200607415377594631985 \cdot 10^{-148}:\\ \;\;\;\;\log \left(e^{-1}\right)\\ \mathbf{elif}\;x \le 8.439330033545885045213726212950052594665 \cdot 10^{67}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \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}\;x \le -1.505752205836537605611230467447200313868 \cdot 10^{136}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;x \le 2.465931800714866985200607415377594631985 \cdot 10^{-148}:\\
\;\;\;\;\log \left(e^{-1}\right)\\

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

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

\end{array}
double f(double x, double y) {
        double r650822 = x;
        double r650823 = r650822 * r650822;
        double r650824 = y;
        double r650825 = 4.0;
        double r650826 = r650824 * r650825;
        double r650827 = r650826 * r650824;
        double r650828 = r650823 - r650827;
        double r650829 = r650823 + r650827;
        double r650830 = r650828 / r650829;
        return r650830;
}

double f(double x, double y) {
        double r650831 = x;
        double r650832 = -1.5057522058365376e+136;
        bool r650833 = r650831 <= r650832;
        double r650834 = 1.0;
        double r650835 = -1.8206371797076397e-86;
        bool r650836 = r650831 <= r650835;
        double r650837 = r650831 * r650831;
        double r650838 = y;
        double r650839 = 4.0;
        double r650840 = r650838 * r650839;
        double r650841 = r650840 * r650838;
        double r650842 = r650837 - r650841;
        double r650843 = r650837 + r650841;
        double r650844 = r650842 / r650843;
        double r650845 = exp(r650844);
        double r650846 = log(r650845);
        double r650847 = 2.465931800714867e-148;
        bool r650848 = r650831 <= r650847;
        double r650849 = -1.0;
        double r650850 = exp(r650849);
        double r650851 = log(r650850);
        double r650852 = 8.439330033545885e+67;
        bool r650853 = r650831 <= r650852;
        double r650854 = r650853 ? r650846 : r650834;
        double r650855 = r650848 ? r650851 : r650854;
        double r650856 = r650836 ? r650846 : r650855;
        double r650857 = r650833 ? r650834 : r650856;
        return r650857;
}

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
Target30.8
Herbie12.3
\[\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.9743233849626781184483093056769575923681:\\ \;\;\;\;\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 x < -1.5057522058365376e+136 or 8.439330033545885e+67 < x

    1. Initial program 51.8

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

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

    if -1.5057522058365376e+136 < x < -1.8206371797076397e-86 or 2.465931800714867e-148 < x < 8.439330033545885e+67

    1. Initial program 15.3

      \[\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 add-log-exp15.3

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

    if -1.8206371797076397e-86 < x < 2.465931800714867e-148

    1. Initial program 26.6

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

      \[\leadsto \color{blue}{\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)}\]
    4. Taylor expanded around 0 9.6

      \[\leadsto \log \left(e^{\color{blue}{-1}}\right)\]
  3. Recombined 3 regimes into one program.
  4. Final simplification12.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -1.505752205836537605611230467447200313868 \cdot 10^{136}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.820637179707639667962910639720240578708 \cdot 10^{-86}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{elif}\;x \le 2.465931800714866985200607415377594631985 \cdot 10^{-148}:\\ \;\;\;\;\log \left(e^{-1}\right)\\ \mathbf{elif}\;x \le 8.439330033545885045213726212950052594665 \cdot 10^{67}:\\ \;\;\;\;\log \left(e^{\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}}\right)\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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