Average Error: 15.3 → 0.1
Time: 1.5s
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{0.5 \cdot \frac{y}{x} + 0.5}{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{0.5 \cdot \frac{y}{x} + 0.5}{y}\\

\end{array}
double f(double x, double y) {
        double r548081 = x;
        double r548082 = y;
        double r548083 = r548081 + r548082;
        double r548084 = 2.0;
        double r548085 = r548081 * r548084;
        double r548086 = r548085 * r548082;
        double r548087 = r548083 / r548086;
        return r548087;
}

double f(double x, double y) {
        double r548088 = x;
        double r548089 = -5.221187662641635e-12;
        bool r548090 = r548088 <= r548089;
        double r548091 = y;
        double r548092 = r548088 + r548091;
        double r548093 = 2.0;
        double r548094 = r548088 * r548093;
        double r548095 = r548092 / r548094;
        double r548096 = 1.0;
        double r548097 = r548096 / r548091;
        double r548098 = r548095 * r548097;
        double r548099 = 9.433587360001542e-18;
        bool r548100 = r548088 <= r548099;
        double r548101 = r548096 / r548088;
        double r548102 = r548092 / r548093;
        double r548103 = r548091 / r548102;
        double r548104 = r548101 / r548103;
        double r548105 = 0.5;
        double r548106 = r548091 / r548088;
        double r548107 = r548105 * r548106;
        double r548108 = r548107 + r548105;
        double r548109 = r548108 / r548091;
        double r548110 = r548100 ? r548104 : r548109;
        double r548111 = r548090 ? r548098 : r548110;
        return r548111;
}

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.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}\]
  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{0.5 \cdot \frac{y}{x} + 0.5}{y}\\ \end{array}\]

Reproduce

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