Average Error: 14.8 → 0.5
Time: 7.3s
Precision: 64
\[\frac{\left(x \cdot 2.0\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -9.50828047314787 \cdot 10^{+45}:\\ \;\;\;\;\left(y \cdot 2.0\right) \cdot \frac{x}{x - y}\\ \mathbf{elif}\;x \le 9.799425869832502 \cdot 10^{+101}:\\ \;\;\;\;\frac{x \cdot 2.0}{\frac{x}{y} - 1}\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot 2.0\right) \cdot \frac{x}{x - y}\\ \end{array}\]
\frac{\left(x \cdot 2.0\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;x \le -9.50828047314787 \cdot 10^{+45}:\\
\;\;\;\;\left(y \cdot 2.0\right) \cdot \frac{x}{x - y}\\

\mathbf{elif}\;x \le 9.799425869832502 \cdot 10^{+101}:\\
\;\;\;\;\frac{x \cdot 2.0}{\frac{x}{y} - 1}\\

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

\end{array}
double f(double x, double y) {
        double r9256080 = x;
        double r9256081 = 2.0;
        double r9256082 = r9256080 * r9256081;
        double r9256083 = y;
        double r9256084 = r9256082 * r9256083;
        double r9256085 = r9256080 - r9256083;
        double r9256086 = r9256084 / r9256085;
        return r9256086;
}

double f(double x, double y) {
        double r9256087 = x;
        double r9256088 = -9.50828047314787e+45;
        bool r9256089 = r9256087 <= r9256088;
        double r9256090 = y;
        double r9256091 = 2.0;
        double r9256092 = r9256090 * r9256091;
        double r9256093 = r9256087 - r9256090;
        double r9256094 = r9256087 / r9256093;
        double r9256095 = r9256092 * r9256094;
        double r9256096 = 9.799425869832502e+101;
        bool r9256097 = r9256087 <= r9256096;
        double r9256098 = r9256087 * r9256091;
        double r9256099 = r9256087 / r9256090;
        double r9256100 = 1.0;
        double r9256101 = r9256099 - r9256100;
        double r9256102 = r9256098 / r9256101;
        double r9256103 = r9256097 ? r9256102 : r9256095;
        double r9256104 = r9256089 ? r9256095 : r9256103;
        return r9256104;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original14.8
Target0.4
Herbie0.5
\[\begin{array}{l} \mathbf{if}\;x \lt -1.7210442634149447 \cdot 10^{+81}:\\ \;\;\;\;\frac{2.0 \cdot x}{x - y} \cdot y\\ \mathbf{elif}\;x \lt 8.364504563556443 \cdot 10^{+16}:\\ \;\;\;\;\frac{x \cdot 2.0}{\frac{x - y}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{2.0 \cdot x}{x - y} \cdot y\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -9.50828047314787e+45 or 9.799425869832502e+101 < x

    1. Initial program 18.7

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

      \[\leadsto \color{blue}{\frac{x \cdot 2.0}{\frac{x - y}{y}}}\]
    4. Using strategy rm
    5. Applied div-inv19.0

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

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

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

    if -9.50828047314787e+45 < x < 9.799425869832502e+101

    1. Initial program 12.4

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

      \[\leadsto \color{blue}{\frac{x \cdot 2.0}{\frac{x - y}{y}}}\]
    4. Using strategy rm
    5. Applied div-sub0.8

      \[\leadsto \frac{x \cdot 2.0}{\color{blue}{\frac{x}{y} - \frac{y}{y}}}\]
    6. Simplified0.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -9.50828047314787 \cdot 10^{+45}:\\ \;\;\;\;\left(y \cdot 2.0\right) \cdot \frac{x}{x - y}\\ \mathbf{elif}\;x \le 9.799425869832502 \cdot 10^{+101}:\\ \;\;\;\;\frac{x \cdot 2.0}{\frac{x}{y} - 1}\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot 2.0\right) \cdot \frac{x}{x - y}\\ \end{array}\]

Reproduce

herbie shell --seed 2019156 +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)))