Average Error: 31.6 → 13.4
Time: 5.7s
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 \cdot \left(y \cdot 4\right) \le 7.027808530107358188452156248527074599726 \cdot 10^{-286}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \le 3.69166379221494303097062696142672714528 \cdot 10^{-13}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \le 1.792267162890288236819749793630475002654 \cdot 10^{85}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \le 8.170638210533042102915317867916107400746 \cdot 10^{248}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \le 1.496258465901378664026516368495157364812 \cdot 10^{262}:\\ \;\;\;\;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 \cdot \left(y \cdot 4\right) \le 7.027808530107358188452156248527074599726 \cdot 10^{-286}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;y \cdot \left(y \cdot 4\right) \le 1.792267162890288236819749793630475002654 \cdot 10^{85}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;y \cdot \left(y \cdot 4\right) \le 1.496258465901378664026516368495157364812 \cdot 10^{262}:\\
\;\;\;\;1\\

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

\end{array}
double f(double x, double y) {
        double r28670482 = x;
        double r28670483 = r28670482 * r28670482;
        double r28670484 = y;
        double r28670485 = 4.0;
        double r28670486 = r28670484 * r28670485;
        double r28670487 = r28670486 * r28670484;
        double r28670488 = r28670483 - r28670487;
        double r28670489 = r28670483 + r28670487;
        double r28670490 = r28670488 / r28670489;
        return r28670490;
}

double f(double x, double y) {
        double r28670491 = y;
        double r28670492 = 4.0;
        double r28670493 = r28670491 * r28670492;
        double r28670494 = r28670491 * r28670493;
        double r28670495 = 7.027808530107358e-286;
        bool r28670496 = r28670494 <= r28670495;
        double r28670497 = 1.0;
        double r28670498 = 3.691663792214943e-13;
        bool r28670499 = r28670494 <= r28670498;
        double r28670500 = x;
        double r28670501 = r28670500 * r28670500;
        double r28670502 = r28670501 - r28670494;
        double r28670503 = r28670501 + r28670494;
        double r28670504 = r28670502 / r28670503;
        double r28670505 = 1.7922671628902882e+85;
        bool r28670506 = r28670494 <= r28670505;
        double r28670507 = 8.170638210533042e+248;
        bool r28670508 = r28670494 <= r28670507;
        double r28670509 = 1.4962584659013787e+262;
        bool r28670510 = r28670494 <= r28670509;
        double r28670511 = -1.0;
        double r28670512 = r28670510 ? r28670497 : r28670511;
        double r28670513 = r28670508 ? r28670504 : r28670512;
        double r28670514 = r28670506 ? r28670497 : r28670513;
        double r28670515 = r28670499 ? r28670504 : r28670514;
        double r28670516 = r28670496 ? r28670497 : r28670515;
        return r28670516;
}

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.6
Target31.3
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.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 (* (* y 4.0) y) < 7.027808530107358e-286 or 3.691663792214943e-13 < (* (* y 4.0) y) < 1.7922671628902882e+85 or 8.170638210533042e+248 < (* (* y 4.0) y) < 1.4962584659013787e+262

    1. Initial program 26.5

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

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

    if 7.027808530107358e-286 < (* (* y 4.0) y) < 3.691663792214943e-13 or 1.7922671628902882e+85 < (* (* y 4.0) y) < 8.170638210533042e+248

    1. Initial program 15.2

      \[\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 +-commutative15.2

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

    if 1.4962584659013787e+262 < (* (* y 4.0) y)

    1. Initial program 57.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 9.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot \left(y \cdot 4\right) \le 7.027808530107358188452156248527074599726 \cdot 10^{-286}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \le 3.69166379221494303097062696142672714528 \cdot 10^{-13}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \le 1.792267162890288236819749793630475002654 \cdot 10^{85}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \le 8.170638210533042102915317867916107400746 \cdot 10^{248}:\\ \;\;\;\;\frac{x \cdot x - y \cdot \left(y \cdot 4\right)}{x \cdot x + y \cdot \left(y \cdot 4\right)}\\ \mathbf{elif}\;y \cdot \left(y \cdot 4\right) \le 1.496258465901378664026516368495157364812 \cdot 10^{262}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array}\]

Reproduce

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