Average Error: 14.5 → 0.1
Time: 8.3s
Precision: 64
\[\frac{\left(x \cdot 2.0\right) \cdot y}{x - y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -2.781519413694764 \cdot 10^{-10}:\\ \;\;\;\;\left(y \cdot 2.0\right) \cdot \frac{x}{x - y}\\ \mathbf{elif}\;x \le 1.7651574500804557 \cdot 10^{+52}:\\ \;\;\;\;\left(x \cdot 2.0\right) \cdot \frac{y}{x - y}\\ \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 -2.781519413694764 \cdot 10^{-10}:\\
\;\;\;\;\left(y \cdot 2.0\right) \cdot \frac{x}{x - y}\\

\mathbf{elif}\;x \le 1.7651574500804557 \cdot 10^{+52}:\\
\;\;\;\;\left(x \cdot 2.0\right) \cdot \frac{y}{x - y}\\

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

\end{array}
double f(double x, double y) {
        double r23994657 = x;
        double r23994658 = 2.0;
        double r23994659 = r23994657 * r23994658;
        double r23994660 = y;
        double r23994661 = r23994659 * r23994660;
        double r23994662 = r23994657 - r23994660;
        double r23994663 = r23994661 / r23994662;
        return r23994663;
}

double f(double x, double y) {
        double r23994664 = x;
        double r23994665 = -2.781519413694764e-10;
        bool r23994666 = r23994664 <= r23994665;
        double r23994667 = y;
        double r23994668 = 2.0;
        double r23994669 = r23994667 * r23994668;
        double r23994670 = r23994664 - r23994667;
        double r23994671 = r23994664 / r23994670;
        double r23994672 = r23994669 * r23994671;
        double r23994673 = 1.7651574500804557e+52;
        bool r23994674 = r23994664 <= r23994673;
        double r23994675 = r23994664 * r23994668;
        double r23994676 = r23994667 / r23994670;
        double r23994677 = r23994675 * r23994676;
        double r23994678 = r23994674 ? r23994677 : r23994672;
        double r23994679 = r23994666 ? r23994672 : r23994678;
        return r23994679;
}

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.5
Target0.4
Herbie0.1
\[\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 < -2.781519413694764e-10 or 1.7651574500804557e+52 < x

    1. Initial program 15.2

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

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

      \[\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(2.0 \cdot y\right)}\]

    if -2.781519413694764e-10 < x < 1.7651574500804557e+52

    1. Initial program 13.8

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -2.781519413694764 \cdot 10^{-10}:\\ \;\;\;\;\left(y \cdot 2.0\right) \cdot \frac{x}{x - y}\\ \mathbf{elif}\;x \le 1.7651574500804557 \cdot 10^{+52}:\\ \;\;\;\;\left(x \cdot 2.0\right) \cdot \frac{y}{x - y}\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot 2.0\right) \cdot \frac{x}{x - y}\\ \end{array}\]

Reproduce

herbie shell --seed 2019164 
(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)))