Average Error: 14.9 → 0.5
Time: 30.7s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -5.795611421145836744402935774403637790937 \cdot 10^{-17} \lor \neg \left(x \le 3.247588547814785746124721995699073933232 \cdot 10^{-105}\right):\\ \;\;\;\;\left(y \cdot 2\right) \cdot \frac{x}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\frac{\frac{x}{y} - 1}{2}}{x}}\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;x \le -5.795611421145836744402935774403637790937 \cdot 10^{-17} \lor \neg \left(x \le 3.247588547814785746124721995699073933232 \cdot 10^{-105}\right):\\
\;\;\;\;\left(y \cdot 2\right) \cdot \frac{x}{x - y}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\frac{\frac{x}{y} - 1}{2}}{x}}\\

\end{array}
double f(double x, double y) {
        double r543068 = x;
        double r543069 = 2.0;
        double r543070 = r543068 * r543069;
        double r543071 = y;
        double r543072 = r543070 * r543071;
        double r543073 = r543068 - r543071;
        double r543074 = r543072 / r543073;
        return r543074;
}

double f(double x, double y) {
        double r543075 = x;
        double r543076 = -5.795611421145837e-17;
        bool r543077 = r543075 <= r543076;
        double r543078 = 3.2475885478147857e-105;
        bool r543079 = r543075 <= r543078;
        double r543080 = !r543079;
        bool r543081 = r543077 || r543080;
        double r543082 = y;
        double r543083 = 2.0;
        double r543084 = r543082 * r543083;
        double r543085 = r543075 - r543082;
        double r543086 = r543075 / r543085;
        double r543087 = r543084 * r543086;
        double r543088 = 1.0;
        double r543089 = r543075 / r543082;
        double r543090 = r543089 - r543088;
        double r543091 = r543090 / r543083;
        double r543092 = r543091 / r543075;
        double r543093 = r543088 / r543092;
        double r543094 = r543081 ? r543087 : r543093;
        return r543094;
}

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.9
Target0.4
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.795611421145837e-17 or 3.2475885478147857e-105 < x

    1. Initial program 14.4

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
    2. Simplified12.6

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

      \[\leadsto \frac{x \cdot 2}{\color{blue}{\left(x - y\right) \cdot \frac{1}{y}}}\]
    5. Applied times-frac0.8

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

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

    if -5.795611421145837e-17 < x < 3.2475885478147857e-105

    1. Initial program 15.6

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
    2. Simplified0.0

      \[\leadsto \color{blue}{\frac{x \cdot 2}{\frac{x - y}{y}}}\]
    3. Using strategy rm
    4. Applied clear-num0.2

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -5.795611421145836744402935774403637790937 \cdot 10^{-17} \lor \neg \left(x \le 3.247588547814785746124721995699073933232 \cdot 10^{-105}\right):\\ \;\;\;\;\left(y \cdot 2\right) \cdot \frac{x}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\frac{\frac{x}{y} - 1}{2}}{x}}\\ \end{array}\]

Reproduce

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