Average Error: 15.1 → 0.5
Time: 10.8s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -5.01776738281857308254796379287654417567 \cdot 10^{-5}:\\ \;\;\;\;\left(y \cdot 2\right) \cdot \frac{x}{x - y}\\ \mathbf{elif}\;x \le 3.62378838658747611836253077264636734886 \cdot 10^{-110}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot 2\right) \cdot \frac{x}{x - y}\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;x \le -5.01776738281857308254796379287654417567 \cdot 10^{-5}:\\
\;\;\;\;\left(y \cdot 2\right) \cdot \frac{x}{x - y}\\

\mathbf{elif}\;x \le 3.62378838658747611836253077264636734886 \cdot 10^{-110}:\\
\;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\

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

\end{array}
double f(double x, double y) {
        double r27261185 = x;
        double r27261186 = 2.0;
        double r27261187 = r27261185 * r27261186;
        double r27261188 = y;
        double r27261189 = r27261187 * r27261188;
        double r27261190 = r27261185 - r27261188;
        double r27261191 = r27261189 / r27261190;
        return r27261191;
}

double f(double x, double y) {
        double r27261192 = x;
        double r27261193 = -5.017767382818573e-05;
        bool r27261194 = r27261192 <= r27261193;
        double r27261195 = y;
        double r27261196 = 2.0;
        double r27261197 = r27261195 * r27261196;
        double r27261198 = r27261192 - r27261195;
        double r27261199 = r27261192 / r27261198;
        double r27261200 = r27261197 * r27261199;
        double r27261201 = 3.623788386587476e-110;
        bool r27261202 = r27261192 <= r27261201;
        double r27261203 = r27261192 * r27261196;
        double r27261204 = r27261198 / r27261195;
        double r27261205 = r27261203 / r27261204;
        double r27261206 = r27261202 ? r27261205 : r27261200;
        double r27261207 = r27261194 ? r27261200 : r27261206;
        return r27261207;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original15.1
Target0.3
Herbie0.5
\[\begin{array}{l} \mathbf{if}\;x \lt -1.721044263414944729490876394165887012892 \cdot 10^{81}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x \lt 83645045635564432:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2 \cdot x}{x - y} \cdot y\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -5.017767382818573e-05 or 3.623788386587476e-110 < x

    1. Initial program 14.4

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

      \[\leadsto \color{blue}{\frac{x \cdot 2}{\frac{x - y}{y}}}\]
    4. Using strategy rm
    5. Applied div-inv12.9

      \[\leadsto \frac{x \cdot 2}{\color{blue}{\left(x - y\right) \cdot \frac{1}{y}}}\]
    6. Applied times-frac1.0

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

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

    if -5.017767382818573e-05 < x < 3.623788386587476e-110

    1. Initial program 16.2

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

      \[\leadsto \color{blue}{\frac{x \cdot 2}{\frac{x - y}{y}}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -5.01776738281857308254796379287654417567 \cdot 10^{-5}:\\ \;\;\;\;\left(y \cdot 2\right) \cdot \frac{x}{x - y}\\ \mathbf{elif}\;x \le 3.62378838658747611836253077264636734886 \cdot 10^{-110}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot 2\right) \cdot \frac{x}{x - y}\\ \end{array}\]

Reproduce

herbie shell --seed 2019169 +o rules:numerics
(FPCore (x y)
  :name "Linear.Projection:perspective from linear-1.19.1.3, B"

  :herbie-target
  (if (< x -1.7210442634149447e+81) (* (/ (* 2.0 x) (- x y)) y) (if (< x 8.364504563556443e+16) (/ (* x 2.0) (/ (- x y) y)) (* (/ (* 2.0 x) (- x y)) y)))

  (/ (* (* x 2.0) y) (- x y)))