Average Error: 31.9 → 14.0
Time: 2.0s
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 -3.00186750331876538 \cdot 10^{143}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -6.5918067244508319 \cdot 10^{-138}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)\\ \mathbf{elif}\;x \le 1.9631464787281808 \cdot 10^{68}:\\ \;\;\;\;-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}\;x \le -3.00186750331876538 \cdot 10^{143}:\\
\;\;\;\;1\\

\mathbf{elif}\;x \le -6.5918067244508319 \cdot 10^{-138}:\\
\;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)\\

\mathbf{elif}\;x \le 1.9631464787281808 \cdot 10^{68}:\\
\;\;\;\;-1\\

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

\end{array}
double f(double x, double y) {
        double r782765 = x;
        double r782766 = r782765 * r782765;
        double r782767 = y;
        double r782768 = 4.0;
        double r782769 = r782767 * r782768;
        double r782770 = r782769 * r782767;
        double r782771 = r782766 - r782770;
        double r782772 = r782766 + r782770;
        double r782773 = r782771 / r782772;
        return r782773;
}

double f(double x, double y) {
        double r782774 = x;
        double r782775 = -3.0018675033187654e+143;
        bool r782776 = r782774 <= r782775;
        double r782777 = 1.0;
        double r782778 = -6.591806724450832e-138;
        bool r782779 = r782774 <= r782778;
        double r782780 = r782774 * r782774;
        double r782781 = y;
        double r782782 = 4.0;
        double r782783 = r782781 * r782782;
        double r782784 = r782783 * r782781;
        double r782785 = r782780 - r782784;
        double r782786 = r782780 + r782784;
        double r782787 = r782785 / r782786;
        double r782788 = log1p(r782787);
        double r782789 = expm1(r782788);
        double r782790 = 1.9631464787281808e+68;
        bool r782791 = r782774 <= r782790;
        double r782792 = -1.0;
        double r782793 = r782791 ? r782792 : r782777;
        double r782794 = r782779 ? r782789 : r782793;
        double r782795 = r782776 ? r782777 : r782794;
        return r782795;
}

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.9
Target31.6
Herbie14.0
\[\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 x < -3.0018675033187654e+143 or 1.9631464787281808e+68 < x

    1. Initial program 53.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 inf 11.5

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

    if -3.0018675033187654e+143 < x < -6.591806724450832e-138

    1. Initial program 14.1

      \[\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 expm1-log1p-u14.1

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)}\]

    if -6.591806724450832e-138 < x < 1.9631464787281808e+68

    1. Initial program 24.7

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

      \[\leadsto \color{blue}{-1}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification14.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -3.00186750331876538 \cdot 10^{143}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -6.5918067244508319 \cdot 10^{-138}:\\ \;\;\;\;\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\right)\right)\\ \mathbf{elif}\;x \le 1.9631464787281808 \cdot 10^{68}:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

herbie shell --seed 2020056 +o rules:numerics
(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))))