Average Error: 32.0 → 13.4
Time: 4.6s
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.0569493698564062 \cdot 10^{143}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.8443598935192776 \cdot 10^{-96}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;y \le 1.233109040969588 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 3.41639119234388889 \cdot 10^{22}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;y \le 1.04248377311991221 \cdot 10^{44}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.9431365563396376 \cdot 10^{50}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \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.0569493698564062 \cdot 10^{143}:\\
\;\;\;\;-1\\

\mathbf{elif}\;y \le -1.8443598935192776 \cdot 10^{-96}:\\
\;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\

\mathbf{elif}\;y \le 1.233109040969588 \cdot 10^{-162}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 3.41639119234388889 \cdot 10^{22}:\\
\;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\

\mathbf{elif}\;y \le 1.04248377311991221 \cdot 10^{44}:\\
\;\;\;\;1\\

\mathbf{elif}\;y \le 1.9431365563396376 \cdot 10^{50}:\\
\;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\

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

\end{array}
double f(double x, double y) {
        double r495485 = x;
        double r495486 = r495485 * r495485;
        double r495487 = y;
        double r495488 = 4.0;
        double r495489 = r495487 * r495488;
        double r495490 = r495489 * r495487;
        double r495491 = r495486 - r495490;
        double r495492 = r495486 + r495490;
        double r495493 = r495491 / r495492;
        return r495493;
}

double f(double x, double y) {
        double r495494 = y;
        double r495495 = -7.056949369856406e+143;
        bool r495496 = r495494 <= r495495;
        double r495497 = -1.0;
        double r495498 = -1.8443598935192776e-96;
        bool r495499 = r495494 <= r495498;
        double r495500 = x;
        double r495501 = r495500 * r495500;
        double r495502 = 4.0;
        double r495503 = r495494 * r495502;
        double r495504 = r495503 * r495494;
        double r495505 = r495501 - r495504;
        double r495506 = r495501 + r495504;
        double r495507 = r495505 / r495506;
        double r495508 = 1.2331090409695878e-162;
        bool r495509 = r495494 <= r495508;
        double r495510 = 1.0;
        double r495511 = 3.416391192343889e+22;
        bool r495512 = r495494 <= r495511;
        double r495513 = 1.0424837731199122e+44;
        bool r495514 = r495494 <= r495513;
        double r495515 = 1.9431365563396376e+50;
        bool r495516 = r495494 <= r495515;
        double r495517 = r495516 ? r495507 : r495497;
        double r495518 = r495514 ? r495510 : r495517;
        double r495519 = r495512 ? r495507 : r495518;
        double r495520 = r495509 ? r495510 : r495519;
        double r495521 = r495499 ? r495507 : r495520;
        double r495522 = r495496 ? r495497 : r495521;
        return r495522;
}

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.0
Target31.7
Herbie13.4
\[\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.056949369856406e+143 or 1.9431365563396376e+50 < y

    1. Initial program 51.9

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

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

    if -7.056949369856406e+143 < y < -1.8443598935192776e-96 or 1.2331090409695878e-162 < y < 3.416391192343889e+22 or 1.0424837731199122e+44 < y < 1.9431365563396376e+50

    1. Initial program 16.0

      \[\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\]

    if -1.8443598935192776e-96 < y < 1.2331090409695878e-162 or 3.416391192343889e+22 < y < 1.0424837731199122e+44

    1. Initial program 28.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.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -7.0569493698564062 \cdot 10^{143}:\\ \;\;\;\;-1\\ \mathbf{elif}\;y \le -1.8443598935192776 \cdot 10^{-96}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;y \le 1.233109040969588 \cdot 10^{-162}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 3.41639119234388889 \cdot 10^{22}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{elif}\;y \le 1.04248377311991221 \cdot 10^{44}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \le 1.9431365563396376 \cdot 10^{50}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{x \cdot x + \left(y \cdot 4\right) \cdot y}\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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