Average Error: 22.7 → 0.2
Time: 18.9s
Precision: 64
\[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
\[\begin{array}{l} \mathbf{if}\;y \le -179455656.4260170757770538330078125:\\ \;\;\;\;x + \left(\frac{1}{y} - 1 \cdot \frac{x}{y}\right)\\ \mathbf{elif}\;y \le 186709514.105293214321136474609375:\\ \;\;\;\;1 - \frac{1}{y + 1} \cdot \left(\left(1 - x\right) \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(\frac{1}{y} - 1 \cdot \frac{x}{y}\right)\\ \end{array}\]
1 - \frac{\left(1 - x\right) \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;y \le -179455656.4260170757770538330078125:\\
\;\;\;\;x + \left(\frac{1}{y} - 1 \cdot \frac{x}{y}\right)\\

\mathbf{elif}\;y \le 186709514.105293214321136474609375:\\
\;\;\;\;1 - \frac{1}{y + 1} \cdot \left(\left(1 - x\right) \cdot y\right)\\

\mathbf{else}:\\
\;\;\;\;x + \left(\frac{1}{y} - 1 \cdot \frac{x}{y}\right)\\

\end{array}
double f(double x, double y) {
        double r49392016 = 1.0;
        double r49392017 = x;
        double r49392018 = r49392016 - r49392017;
        double r49392019 = y;
        double r49392020 = r49392018 * r49392019;
        double r49392021 = r49392019 + r49392016;
        double r49392022 = r49392020 / r49392021;
        double r49392023 = r49392016 - r49392022;
        return r49392023;
}

double f(double x, double y) {
        double r49392024 = y;
        double r49392025 = -179455656.42601708;
        bool r49392026 = r49392024 <= r49392025;
        double r49392027 = x;
        double r49392028 = 1.0;
        double r49392029 = r49392028 / r49392024;
        double r49392030 = r49392027 / r49392024;
        double r49392031 = r49392028 * r49392030;
        double r49392032 = r49392029 - r49392031;
        double r49392033 = r49392027 + r49392032;
        double r49392034 = 186709514.1052932;
        bool r49392035 = r49392024 <= r49392034;
        double r49392036 = 1.0;
        double r49392037 = r49392024 + r49392028;
        double r49392038 = r49392036 / r49392037;
        double r49392039 = r49392028 - r49392027;
        double r49392040 = r49392039 * r49392024;
        double r49392041 = r49392038 * r49392040;
        double r49392042 = r49392028 - r49392041;
        double r49392043 = r49392035 ? r49392042 : r49392033;
        double r49392044 = r49392026 ? r49392033 : r49392043;
        return r49392044;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original22.7
Target0.2
Herbie0.2
\[\begin{array}{l} \mathbf{if}\;y \lt -3693.848278829724677052581682801246643066:\\ \;\;\;\;\frac{1}{y} - \left(\frac{x}{y} - x\right)\\ \mathbf{elif}\;y \lt 6799310503.41891002655029296875:\\ \;\;\;\;1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{y} - \left(\frac{x}{y} - x\right)\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if y < -179455656.42601708 or 186709514.1052932 < y

    1. Initial program 46.3

      \[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
    2. Taylor expanded around inf 0.1

      \[\leadsto \color{blue}{\left(x + 1 \cdot \frac{1}{y}\right) - 1 \cdot \frac{x}{y}}\]
    3. Simplified0.1

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

    if -179455656.42601708 < y < 186709514.1052932

    1. Initial program 0.2

      \[1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\]
    2. Using strategy rm
    3. Applied associate-/l*0.3

      \[\leadsto 1 - \color{blue}{\frac{1 - x}{\frac{y + 1}{y}}}\]
    4. Using strategy rm
    5. Applied div-inv0.3

      \[\leadsto 1 - \frac{1 - x}{\color{blue}{\left(y + 1\right) \cdot \frac{1}{y}}}\]
    6. Applied *-un-lft-identity0.3

      \[\leadsto 1 - \frac{\color{blue}{1 \cdot \left(1 - x\right)}}{\left(y + 1\right) \cdot \frac{1}{y}}\]
    7. Applied times-frac0.3

      \[\leadsto 1 - \color{blue}{\frac{1}{y + 1} \cdot \frac{1 - x}{\frac{1}{y}}}\]
    8. Simplified0.2

      \[\leadsto 1 - \frac{1}{y + 1} \cdot \color{blue}{\left(\left(1 - x\right) \cdot y\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -179455656.4260170757770538330078125:\\ \;\;\;\;x + \left(\frac{1}{y} - 1 \cdot \frac{x}{y}\right)\\ \mathbf{elif}\;y \le 186709514.105293214321136474609375:\\ \;\;\;\;1 - \frac{1}{y + 1} \cdot \left(\left(1 - x\right) \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(\frac{1}{y} - 1 \cdot \frac{x}{y}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019174 
(FPCore (x y)
  :name "Diagrams.Trail:splitAtParam  from diagrams-lib-1.3.0.3, D"

  :herbie-target
  (if (< y -3693.8482788297247) (- (/ 1.0 y) (- (/ x y) x)) (if (< y 6799310503.41891) (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))) (- (/ 1.0 y) (- (/ x y) x))))

  (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))