Average Error: 15.3 → 0.1
Time: 1.3s
Precision: 64
\[\frac{x + y}{\left(x \cdot 2\right) \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;x \le -5.2211876626416346 \cdot 10^{-12}:\\ \;\;\;\;\frac{x + y}{x \cdot 2} \cdot \frac{1}{y}\\ \mathbf{elif}\;x \le 9.43358736000154189 \cdot 10^{-18}:\\ \;\;\;\;\frac{\frac{1}{x}}{\frac{y}{\frac{x + y}{2}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(0.5, \frac{y}{x}, 0.5\right)}{y}\\ \end{array}\]
\frac{x + y}{\left(x \cdot 2\right) \cdot y}
\begin{array}{l}
\mathbf{if}\;x \le -5.2211876626416346 \cdot 10^{-12}:\\
\;\;\;\;\frac{x + y}{x \cdot 2} \cdot \frac{1}{y}\\

\mathbf{elif}\;x \le 9.43358736000154189 \cdot 10^{-18}:\\
\;\;\;\;\frac{\frac{1}{x}}{\frac{y}{\frac{x + y}{2}}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(0.5, \frac{y}{x}, 0.5\right)}{y}\\

\end{array}
double f(double x, double y) {
        double r537475 = x;
        double r537476 = y;
        double r537477 = r537475 + r537476;
        double r537478 = 2.0;
        double r537479 = r537475 * r537478;
        double r537480 = r537479 * r537476;
        double r537481 = r537477 / r537480;
        return r537481;
}

double f(double x, double y) {
        double r537482 = x;
        double r537483 = -5.221187662641635e-12;
        bool r537484 = r537482 <= r537483;
        double r537485 = y;
        double r537486 = r537482 + r537485;
        double r537487 = 2.0;
        double r537488 = r537482 * r537487;
        double r537489 = r537486 / r537488;
        double r537490 = 1.0;
        double r537491 = r537490 / r537485;
        double r537492 = r537489 * r537491;
        double r537493 = 9.433587360001542e-18;
        bool r537494 = r537482 <= r537493;
        double r537495 = r537490 / r537482;
        double r537496 = r537486 / r537487;
        double r537497 = r537485 / r537496;
        double r537498 = r537495 / r537497;
        double r537499 = 0.5;
        double r537500 = r537485 / r537482;
        double r537501 = fma(r537499, r537500, r537499);
        double r537502 = r537501 / r537485;
        double r537503 = r537494 ? r537498 : r537502;
        double r537504 = r537484 ? r537492 : r537503;
        return r537504;
}

Error

Bits error versus x

Bits error versus y

Target

Original15.3
Target0.0
Herbie0.1
\[\frac{0.5}{x} + \frac{0.5}{y}\]

Derivation

  1. Split input into 3 regimes
  2. if x < -5.221187662641635e-12

    1. Initial program 15.5

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

      \[\leadsto \color{blue}{\frac{\frac{x + y}{x \cdot 2}}{y}}\]
    4. Using strategy rm
    5. Applied div-inv0.2

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

    if -5.221187662641635e-12 < x < 9.433587360001542e-18

    1. Initial program 15.5

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

      \[\leadsto \color{blue}{\frac{\frac{x + y}{x \cdot 2}}{y}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity16.6

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

      \[\leadsto \frac{\color{blue}{\frac{1}{x} \cdot \frac{x + y}{2}}}{y}\]
    7. Applied associate-/l*0.1

      \[\leadsto \color{blue}{\frac{\frac{1}{x}}{\frac{y}{\frac{x + y}{2}}}}\]

    if 9.433587360001542e-18 < x

    1. Initial program 14.6

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

      \[\leadsto \color{blue}{\frac{\frac{x + y}{x \cdot 2}}{y}}\]
    4. Taylor expanded around 0 0.1

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

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(0.5, \frac{y}{x}, 0.5\right)}}{y}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -5.2211876626416346 \cdot 10^{-12}:\\ \;\;\;\;\frac{x + y}{x \cdot 2} \cdot \frac{1}{y}\\ \mathbf{elif}\;x \le 9.43358736000154189 \cdot 10^{-18}:\\ \;\;\;\;\frac{\frac{1}{x}}{\frac{y}{\frac{x + y}{2}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(0.5, \frac{y}{x}, 0.5\right)}{y}\\ \end{array}\]

Reproduce

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

  :herbie-target
  (+ (/ 0.5 x) (/ 0.5 y))

  (/ (+ x y) (* (* x 2) y)))