Average Error: 15.0 → 0.8
Time: 3.4s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -5.79766759371720844 \cdot 10^{-68}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -6.832690604332275 \cdot 10^{-308}:\\ \;\;\;\;\frac{1}{\frac{x - y}{\left(x \cdot 2\right) \cdot y}}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le 1.0974670677454873 \cdot 10^{-305}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le 2.5491712206131216 \cdot 10^{-36}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -5.79766759371720844 \cdot 10^{-68}:\\
\;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\

\mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -6.832690604332275 \cdot 10^{-308}:\\
\;\;\;\;\frac{1}{\frac{x - y}{\left(x \cdot 2\right) \cdot y}}\\

\mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le 1.0974670677454873 \cdot 10^{-305}:\\
\;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\

\mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le 2.5491712206131216 \cdot 10^{-36}:\\
\;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\

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

\end{array}
double f(double x, double y) {
        double r1045046 = x;
        double r1045047 = 2.0;
        double r1045048 = r1045046 * r1045047;
        double r1045049 = y;
        double r1045050 = r1045048 * r1045049;
        double r1045051 = r1045046 - r1045049;
        double r1045052 = r1045050 / r1045051;
        return r1045052;
}

double f(double x, double y) {
        double r1045053 = x;
        double r1045054 = 2.0;
        double r1045055 = r1045053 * r1045054;
        double r1045056 = y;
        double r1045057 = r1045055 * r1045056;
        double r1045058 = r1045053 - r1045056;
        double r1045059 = r1045057 / r1045058;
        double r1045060 = -5.7976675937172084e-68;
        bool r1045061 = r1045059 <= r1045060;
        double r1045062 = r1045058 / r1045056;
        double r1045063 = r1045055 / r1045062;
        double r1045064 = -6.832690604332275e-308;
        bool r1045065 = r1045059 <= r1045064;
        double r1045066 = 1.0;
        double r1045067 = r1045058 / r1045057;
        double r1045068 = r1045066 / r1045067;
        double r1045069 = 1.0974670677454873e-305;
        bool r1045070 = r1045059 <= r1045069;
        double r1045071 = 2.5491712206131216e-36;
        bool r1045072 = r1045059 <= r1045071;
        double r1045073 = r1045056 / r1045058;
        double r1045074 = r1045055 * r1045073;
        double r1045075 = r1045072 ? r1045059 : r1045074;
        double r1045076 = r1045070 ? r1045063 : r1045075;
        double r1045077 = r1045065 ? r1045068 : r1045076;
        double r1045078 = r1045061 ? r1045063 : r1045077;
        return r1045078;
}

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.0
Target0.3
Herbie0.8
\[\begin{array}{l} \mathbf{if}\;x \lt -1.7210442634149447 \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 4 regimes
  2. if (/ (* (* x 2.0) y) (- x y)) < -5.7976675937172084e-68 or -6.832690604332275e-308 < (/ (* (* x 2.0) y) (- x y)) < 1.0974670677454873e-305

    1. Initial program 34.7

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

      \[\leadsto \color{blue}{\frac{x \cdot 2}{\frac{x - y}{y}}}\]

    if -5.7976675937172084e-68 < (/ (* (* x 2.0) y) (- x y)) < -6.832690604332275e-308

    1. Initial program 0.8

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
    2. Using strategy rm
    3. Applied clear-num1.0

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

    if 1.0974670677454873e-305 < (/ (* (* x 2.0) y) (- x y)) < 2.5491712206131216e-36

    1. Initial program 0.7

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

    if 2.5491712206131216e-36 < (/ (* (* x 2.0) y) (- x y))

    1. Initial program 27.3

      \[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity27.3

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -5.79766759371720844 \cdot 10^{-68}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le -6.832690604332275 \cdot 10^{-308}:\\ \;\;\;\;\frac{1}{\frac{x - y}{\left(x \cdot 2\right) \cdot y}}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le 1.0974670677454873 \cdot 10^{-305}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \mathbf{elif}\;\frac{\left(x \cdot 2\right) \cdot y}{x - y} \le 2.5491712206131216 \cdot 10^{-36}:\\ \;\;\;\;\frac{\left(x \cdot 2\right) \cdot y}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\ \end{array}\]

Reproduce

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

  :herbie-target
  (if (< x -1.7210442634149447e+81) (* (/ (* 2 x) (- x y)) y) (if (< x 83645045635564432) (/ (* x 2) (/ (- x y) y)) (* (/ (* 2 x) (- x y)) y)))

  (/ (* (* x 2) y) (- x y)))