Average Error: 9.0 → 0.1
Time: 3.9s
Precision: 64
\[\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}\]
\[\begin{array}{l} \mathbf{if}\;x \le -28471394463391.582 \lor \neg \left(x \le 125769773969809.797\right):\\ \;\;\;\;\left(1 + \frac{x}{y}\right) - 1 \cdot \frac{1}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x \cdot x - 1 \cdot 1} \cdot \left(x - 1\right)\\ \end{array}\]
\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}
\begin{array}{l}
\mathbf{if}\;x \le -28471394463391.582 \lor \neg \left(x \le 125769773969809.797\right):\\
\;\;\;\;\left(1 + \frac{x}{y}\right) - 1 \cdot \frac{1}{x}\\

\mathbf{else}:\\
\;\;\;\;\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x \cdot x - 1 \cdot 1} \cdot \left(x - 1\right)\\

\end{array}
double code(double x, double y) {
	return ((x * ((x / y) + 1.0)) / (x + 1.0));
}
double code(double x, double y) {
	double temp;
	if (((x <= -28471394463391.582) || !(x <= 125769773969809.8))) {
		temp = ((1.0 + (x / y)) - (1.0 * (1.0 / x)));
	} else {
		temp = (((x * ((x / y) + 1.0)) / ((x * x) - (1.0 * 1.0))) * (x - 1.0));
	}
	return temp;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original9.0
Target0.1
Herbie0.1
\[\frac{x}{1} \cdot \frac{\frac{x}{y} + 1}{x + 1}\]

Derivation

  1. Split input into 2 regimes
  2. if x < -28471394463391.582 or 125769773969809.8 < x

    1. Initial program 22.8

      \[\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}\]
    2. Using strategy rm
    3. Applied flip-+27.7

      \[\leadsto \frac{x \cdot \color{blue}{\frac{\frac{x}{y} \cdot \frac{x}{y} - 1 \cdot 1}{\frac{x}{y} - 1}}}{x + 1}\]
    4. Applied associate-*r/33.5

      \[\leadsto \frac{\color{blue}{\frac{x \cdot \left(\frac{x}{y} \cdot \frac{x}{y} - 1 \cdot 1\right)}{\frac{x}{y} - 1}}}{x + 1}\]
    5. Taylor expanded around inf 0.0

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

    if -28471394463391.582 < x < 125769773969809.8

    1. Initial program 0.1

      \[\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}\]
    2. Using strategy rm
    3. Applied flip-+0.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -28471394463391.582 \lor \neg \left(x \le 125769773969809.797\right):\\ \;\;\;\;\left(1 + \frac{x}{y}\right) - 1 \cdot \frac{1}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x \cdot x - 1 \cdot 1} \cdot \left(x - 1\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020066 +o rules:numerics
(FPCore (x y)
  :name "Codec.Picture.Types:toneMapping from JuicyPixels-3.2.6.1"
  :precision binary64

  :herbie-target
  (* (/ x 1) (/ (+ (/ x y) 1) (+ x 1)))

  (/ (* x (+ (/ x y) 1)) (+ x 1)))