Average Error: 15.0 → 0.8
Time: 5.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 r1683 = x;
        double r1684 = 2.0;
        double r1685 = r1683 * r1684;
        double r1686 = y;
        double r1687 = r1685 * r1686;
        double r1688 = r1683 - r1686;
        double r1689 = r1687 / r1688;
        return r1689;
}

double f(double x, double y) {
        double r1690 = x;
        double r1691 = 2.0;
        double r1692 = r1690 * r1691;
        double r1693 = y;
        double r1694 = r1692 * r1693;
        double r1695 = r1690 - r1693;
        double r1696 = r1694 / r1695;
        double r1697 = -5.7976675937172084e-68;
        bool r1698 = r1696 <= r1697;
        double r1699 = r1695 / r1693;
        double r1700 = r1692 / r1699;
        double r1701 = -6.832690604332275e-308;
        bool r1702 = r1696 <= r1701;
        double r1703 = 1.0;
        double r1704 = r1695 / r1694;
        double r1705 = r1703 / r1704;
        double r1706 = 1.0974670677454873e-305;
        bool r1707 = r1696 <= r1706;
        double r1708 = 2.5491712206131216e-36;
        bool r1709 = r1696 <= r1708;
        double r1710 = r1693 / r1695;
        double r1711 = r1692 * r1710;
        double r1712 = r1709 ? r1696 : r1711;
        double r1713 = r1707 ? r1700 : r1712;
        double r1714 = r1702 ? r1705 : r1713;
        double r1715 = r1698 ? r1700 : r1714;
        return r1715;
}

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)))