Average Error: 14.9 → 0.2
Time: 1.7s
Precision: 64
\[\frac{\left(x \cdot 2\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -11894198345334408230327762615508217626620:\\ \;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\ \mathbf{elif}\;y \le 3.827108002628365811088571233801504531292 \cdot 10^{68}:\\ \;\;\;\;\frac{x}{x - y} \cdot \left(y \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\ \end{array}\]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
\mathbf{if}\;y \le -11894198345334408230327762615508217626620:\\
\;\;\;\;\left(x \cdot 2\right) \cdot \frac{y}{x - y}\\

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

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

\end{array}
double f(double x, double y) {
        double r420212 = x;
        double r420213 = 2.0;
        double r420214 = r420212 * r420213;
        double r420215 = y;
        double r420216 = r420214 * r420215;
        double r420217 = r420212 - r420215;
        double r420218 = r420216 / r420217;
        return r420218;
}

double f(double x, double y) {
        double r420219 = y;
        double r420220 = -1.1894198345334408e+40;
        bool r420221 = r420219 <= r420220;
        double r420222 = x;
        double r420223 = 2.0;
        double r420224 = r420222 * r420223;
        double r420225 = r420222 - r420219;
        double r420226 = r420219 / r420225;
        double r420227 = r420224 * r420226;
        double r420228 = 3.827108002628366e+68;
        bool r420229 = r420219 <= r420228;
        double r420230 = r420222 / r420225;
        double r420231 = r420219 * r420223;
        double r420232 = r420230 * r420231;
        double r420233 = r420225 / r420219;
        double r420234 = r420224 / r420233;
        double r420235 = r420229 ? r420232 : r420234;
        double r420236 = r420221 ? r420227 : r420235;
        return r420236;
}

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.2
\[\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 3 regimes
  2. if y < -1.1894198345334408e+40

    1. Initial program 18.3

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

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

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

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

    if -1.1894198345334408e+40 < y < 3.827108002628366e+68

    1. Initial program 11.9

      \[\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.8

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

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

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

    if 3.827108002628366e+68 < y

    1. Initial program 20.2

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

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

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

Reproduce

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