Average Error: 14.7 → 0.4
Time: 3.7s
Precision: 64
\[\frac{x + y}{\left(x \cdot 2\right) \cdot y}\]
\[\begin{array}{l} \mathbf{if}\;y \le -1.10625282481159711 \cdot 10^{-58} \lor \neg \left(y \le 1.39601892208603475 \cdot 10^{-57}\right):\\ \;\;\;\;\frac{\frac{-\left(x + y\right)}{y}}{-x \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{y} \cdot \frac{x + y}{x \cdot 2}\\ \end{array}\]
\frac{x + y}{\left(x \cdot 2\right) \cdot y}
\begin{array}{l}
\mathbf{if}\;y \le -1.10625282481159711 \cdot 10^{-58} \lor \neg \left(y \le 1.39601892208603475 \cdot 10^{-57}\right):\\
\;\;\;\;\frac{\frac{-\left(x + y\right)}{y}}{-x \cdot 2}\\

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

\end{array}
double code(double x, double y) {
	return ((double) (((double) (x + y)) / ((double) (((double) (x * 2.0)) * y))));
}
double code(double x, double y) {
	double VAR;
	if (((y <= -1.1062528248115971e-58) || !(y <= 1.3960189220860347e-57))) {
		VAR = ((double) (((double) (((double) -(((double) (x + y)))) / y)) / ((double) -(((double) (x * 2.0))))));
	} else {
		VAR = ((double) (((double) (1.0 / y)) * ((double) (((double) (x + y)) / ((double) (x * 2.0))))));
	}
	return VAR;
}

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.7
Target0.0
Herbie0.4
\[\frac{0.5}{x} + \frac{0.5}{y}\]

Derivation

  1. Split input into 2 regimes
  2. if y < -1.1062528248115971e-58 or 1.3960189220860347e-57 < y

    1. Initial program 12.8

      \[\frac{x + y}{\left(x \cdot 2\right) \cdot y}\]
    2. Using strategy rm
    3. Applied *-commutative12.8

      \[\leadsto \frac{x + y}{\color{blue}{y \cdot \left(x \cdot 2\right)}}\]
    4. Applied *-un-lft-identity12.8

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

      \[\leadsto \color{blue}{\frac{1}{y} \cdot \frac{x + y}{x \cdot 2}}\]
    6. Using strategy rm
    7. Applied frac-2neg13.8

      \[\leadsto \frac{1}{y} \cdot \color{blue}{\frac{-\left(x + y\right)}{-x \cdot 2}}\]
    8. Applied associate-*r/0.6

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

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

    if -1.1062528248115971e-58 < y < 1.3960189220860347e-57

    1. Initial program 17.5

      \[\frac{x + y}{\left(x \cdot 2\right) \cdot y}\]
    2. Using strategy rm
    3. Applied *-commutative17.5

      \[\leadsto \frac{x + y}{\color{blue}{y \cdot \left(x \cdot 2\right)}}\]
    4. Applied *-un-lft-identity17.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \le -1.10625282481159711 \cdot 10^{-58} \lor \neg \left(y \le 1.39601892208603475 \cdot 10^{-57}\right):\\ \;\;\;\;\frac{\frac{-\left(x + y\right)}{y}}{-x \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{y} \cdot \frac{x + y}{x \cdot 2}\\ \end{array}\]

Reproduce

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