Average Error: 8.6 → 0.1
Time: 1.0s
Precision: binary64
\[\frac{x \cdot y}{y + 1} \]
\[\begin{array}{l} \mathbf{if}\;y \leq -6.330577992617213 \cdot 10^{+50} \lor \neg \left(y \leq 217570469.80289507\right):\\ \;\;\;\;x - \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{y + 1}\\ \end{array} \]
\frac{x \cdot y}{y + 1}
\begin{array}{l}
\mathbf{if}\;y \leq -6.330577992617213 \cdot 10^{+50} \lor \neg \left(y \leq 217570469.80289507\right):\\
\;\;\;\;x - \frac{x}{y}\\

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


\end{array}
(FPCore (x y) :precision binary64 (/ (* x y) (+ y 1.0)))
(FPCore (x y)
 :precision binary64
 (if (or (<= y -6.330577992617213e+50) (not (<= y 217570469.80289507)))
   (- x (/ x y))
   (/ (* y x) (+ y 1.0))))
double code(double x, double y) {
	return (x * y) / (y + 1.0);
}
double code(double x, double y) {
	double tmp;
	if ((y <= -6.330577992617213e+50) || !(y <= 217570469.80289507)) {
		tmp = x - (x / y);
	} else {
		tmp = (y * x) / (y + 1.0);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original8.6
Target0.0
Herbie0.1
\[\begin{array}{l} \mathbf{if}\;y < -3693.8482788297247:\\ \;\;\;\;\frac{x}{y \cdot y} - \left(\frac{x}{y} - x\right)\\ \mathbf{elif}\;y < 6799310503.41891:\\ \;\;\;\;\frac{x \cdot y}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y \cdot y} - \left(\frac{x}{y} - x\right)\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if y < -6.33057799261721289e50 or 217570469.80289507 < y

    1. Initial program 18.4

      \[\frac{x \cdot y}{y + 1} \]
    2. Taylor expanded in y around inf 0

      \[\leadsto \color{blue}{x - \frac{x}{y}} \]

    if -6.33057799261721289e50 < y < 217570469.80289507

    1. Initial program 0.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -6.330577992617213 \cdot 10^{+50} \lor \neg \left(y \leq 217570469.80289507\right):\\ \;\;\;\;x - \frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot x}{y + 1}\\ \end{array} \]

Reproduce

herbie shell --seed 2021275 
(FPCore (x y)
  :name "Diagrams.Trail:splitAtParam  from diagrams-lib-1.3.0.3, B"
  :precision binary64

  :herbie-target
  (if (< y -3693.8482788297247) (- (/ x (* y y)) (- (/ x y) x)) (if (< y 6799310503.41891) (/ (* x y) (+ y 1.0)) (- (/ x (* y y)) (- (/ x y) x))))

  (/ (* x y) (+ y 1.0)))