Average Error: 32.0 → 12.7
Time: 9.8s
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 -4.844506481309793477015811086474695118347 \cdot 10^{101}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.397641845173585116448266999843103588536 \cdot 10^{-80}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\left(y \cdot 4\right) \cdot y + x \cdot x}\\ \mathbf{elif}\;x \le 2.301536498063311661306861828114408368058 \cdot 10^{-123}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 1.131938965300101620603311598271655945714 \cdot 10^{-12}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\left(y \cdot 4\right) \cdot y + x \cdot x}\\ \mathbf{elif}\;x \le 3063448176040838:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 1.353386120696897430440169718838837769249 \cdot 10^{95}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\left(y \cdot 4\right) \cdot y + x \cdot x}\\ \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 -4.844506481309793477015811086474695118347 \cdot 10^{101}:\\
\;\;\;\;1\\

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

\mathbf{elif}\;x \le 2.301536498063311661306861828114408368058 \cdot 10^{-123}:\\
\;\;\;\;-1\\

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

\mathbf{elif}\;x \le 3063448176040838:\\
\;\;\;\;-1\\

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

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

\end{array}
double f(double x, double y) {
        double r29057283 = x;
        double r29057284 = r29057283 * r29057283;
        double r29057285 = y;
        double r29057286 = 4.0;
        double r29057287 = r29057285 * r29057286;
        double r29057288 = r29057287 * r29057285;
        double r29057289 = r29057284 - r29057288;
        double r29057290 = r29057284 + r29057288;
        double r29057291 = r29057289 / r29057290;
        return r29057291;
}

double f(double x, double y) {
        double r29057292 = x;
        double r29057293 = -4.8445064813097935e+101;
        bool r29057294 = r29057292 <= r29057293;
        double r29057295 = 1.0;
        double r29057296 = -1.3976418451735851e-80;
        bool r29057297 = r29057292 <= r29057296;
        double r29057298 = r29057292 * r29057292;
        double r29057299 = y;
        double r29057300 = 4.0;
        double r29057301 = r29057299 * r29057300;
        double r29057302 = r29057301 * r29057299;
        double r29057303 = r29057298 - r29057302;
        double r29057304 = r29057302 + r29057298;
        double r29057305 = r29057303 / r29057304;
        double r29057306 = 2.3015364980633117e-123;
        bool r29057307 = r29057292 <= r29057306;
        double r29057308 = -1.0;
        double r29057309 = 1.1319389653001016e-12;
        bool r29057310 = r29057292 <= r29057309;
        double r29057311 = 3063448176040838.0;
        bool r29057312 = r29057292 <= r29057311;
        double r29057313 = 1.3533861206968974e+95;
        bool r29057314 = r29057292 <= r29057313;
        double r29057315 = r29057314 ? r29057305 : r29057295;
        double r29057316 = r29057312 ? r29057308 : r29057315;
        double r29057317 = r29057310 ? r29057305 : r29057316;
        double r29057318 = r29057307 ? r29057308 : r29057317;
        double r29057319 = r29057297 ? r29057305 : r29057318;
        double r29057320 = r29057294 ? r29057295 : r29057319;
        return r29057320;
}

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
Herbie12.7
\[\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 < -4.8445064813097935e+101 or 1.3533861206968974e+95 < x

    1. Initial program 51.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 inf 10.3

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

    if -4.8445064813097935e+101 < x < -1.3976418451735851e-80 or 2.3015364980633117e-123 < x < 1.1319389653001016e-12 or 3063448176040838.0 < x < 1.3533861206968974e+95

    1. Initial program 16.1

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

    if -1.3976418451735851e-80 < x < 2.3015364980633117e-123 or 1.1319389653001016e-12 < x < 3063448176040838.0

    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. Taylor expanded around 0 12.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -4.844506481309793477015811086474695118347 \cdot 10^{101}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \le -1.397641845173585116448266999843103588536 \cdot 10^{-80}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\left(y \cdot 4\right) \cdot y + x \cdot x}\\ \mathbf{elif}\;x \le 2.301536498063311661306861828114408368058 \cdot 10^{-123}:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 1.131938965300101620603311598271655945714 \cdot 10^{-12}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\left(y \cdot 4\right) \cdot y + x \cdot x}\\ \mathbf{elif}\;x \le 3063448176040838:\\ \;\;\;\;-1\\ \mathbf{elif}\;x \le 1.353386120696897430440169718838837769249 \cdot 10^{95}:\\ \;\;\;\;\frac{x \cdot x - \left(y \cdot 4\right) \cdot y}{\left(y \cdot 4\right) \cdot y + x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]

Reproduce

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