Average Error: 9.2 → 0.1
Time: 21.8s
Precision: binary64
Cost: 7240
\[\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -4800000000:\\ \;\;\;\;\frac{x + -1}{y} - -1\\ \mathbf{elif}\;x \leq 10^{+16}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, \frac{x}{y}, x\right)}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} - -1\\ \end{array} \]
(FPCore (x y) :precision binary64 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))
(FPCore (x y)
 :precision binary64
 (if (<= x -4800000000.0)
   (- (/ (+ x -1.0) y) -1.0)
   (if (<= x 1e+16) (/ (fma x (/ x y) x) (+ x 1.0)) (- (/ x y) -1.0))))
double code(double x, double y) {
	return (x * ((x / y) + 1.0)) / (x + 1.0);
}
double code(double x, double y) {
	double tmp;
	if (x <= -4800000000.0) {
		tmp = ((x + -1.0) / y) - -1.0;
	} else if (x <= 1e+16) {
		tmp = fma(x, (x / y), x) / (x + 1.0);
	} else {
		tmp = (x / y) - -1.0;
	}
	return tmp;
}
function code(x, y)
	return Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0))
end
function code(x, y)
	tmp = 0.0
	if (x <= -4800000000.0)
		tmp = Float64(Float64(Float64(x + -1.0) / y) - -1.0);
	elseif (x <= 1e+16)
		tmp = Float64(fma(x, Float64(x / y), x) / Float64(x + 1.0));
	else
		tmp = Float64(Float64(x / y) - -1.0);
	end
	return tmp
end
code[x_, y_] := N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := If[LessEqual[x, -4800000000.0], N[(N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision] - -1.0), $MachinePrecision], If[LessEqual[x, 1e+16], N[(N[(x * N[(x / y), $MachinePrecision] + x), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(x / y), $MachinePrecision] - -1.0), $MachinePrecision]]]
\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}
\begin{array}{l}
\mathbf{if}\;x \leq -4800000000:\\
\;\;\;\;\frac{x + -1}{y} - -1\\

\mathbf{elif}\;x \leq 10^{+16}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, \frac{x}{y}, x\right)}{x + 1}\\

\mathbf{else}:\\
\;\;\;\;\frac{x}{y} - -1\\


\end{array}

Error

Target

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

Derivation

  1. Split input into 3 regimes
  2. if x < -4.8e9

    1. Initial program 23.4

      \[\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1} \]
    2. Taylor expanded in x around inf 0.1

      \[\leadsto \color{blue}{\left(1 + \frac{x}{y}\right) - \frac{1}{y}} \]
    3. Applied egg-rr0.1

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

    if -4.8e9 < x < 1e16

    1. Initial program 0.1

      \[\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1} \]
    2. Simplified0.1

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, \frac{x}{y}, x\right)}{x + 1}} \]
      Proof

    if 1e16 < x

    1. Initial program 21.8

      \[\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1} \]
    2. Taylor expanded in x around inf 0.0

      \[\leadsto \color{blue}{\left(1 + \frac{x}{y}\right) - \frac{1}{y}} \]
    3. Applied egg-rr0.0

      \[\leadsto \color{blue}{\frac{x + -1}{y} - -1} \]
    4. Taylor expanded in x around inf 0.0

      \[\leadsto \color{blue}{\frac{x}{y}} - -1 \]
  3. Recombined 3 regimes into one program.

Alternatives

Alternative 1
Error0.1
Cost968
\[\begin{array}{l} \mathbf{if}\;x \leq -4800000000:\\ \;\;\;\;\frac{x + -1}{y} - -1\\ \mathbf{elif}\;x \leq 2 \cdot 10^{+16}:\\ \;\;\;\;\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} - -1\\ \end{array} \]
Alternative 2
Error20.1
Cost852
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;x \leq -4.1 \cdot 10^{-66}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.45 \cdot 10^{-118}:\\ \;\;\;\;x \cdot \frac{x}{y}\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{-7}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5 \cdot 10^{+65}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]
Alternative 3
Error11.6
Cost848
\[\begin{array}{l} t_0 := \frac{x}{y} - -1\\ \mathbf{if}\;x \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -4.1 \cdot 10^{-66}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.45 \cdot 10^{-118}:\\ \;\;\;\;x \cdot \frac{x}{y}\\ \mathbf{elif}\;x \leq 4.7 \cdot 10^{-14}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error11.1
Cost848
\[\begin{array}{l} t_0 := \frac{x}{y} - -1\\ t_1 := \frac{x}{1 + x}\\ \mathbf{if}\;x \leq -76:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.55 \cdot 10^{-61}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.45 \cdot 10^{-118}:\\ \;\;\;\;x \cdot \frac{x}{y}\\ \mathbf{elif}\;x \leq 3100000000000:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error11.1
Cost848
\[\begin{array}{l} t_0 := \frac{x}{y} - -1\\ t_1 := \frac{x}{1 + x}\\ \mathbf{if}\;x \leq -75:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -7.8 \cdot 10^{-59}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.45 \cdot 10^{-118}:\\ \;\;\;\;\frac{x \cdot x}{y}\\ \mathbf{elif}\;x \leq 3100000000000:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error11.0
Cost848
\[\begin{array}{l} t_0 := \frac{x}{1 + x}\\ \mathbf{if}\;x \leq -76:\\ \;\;\;\;\frac{x + -1}{y} - -1\\ \mathbf{elif}\;x \leq -1.2 \cdot 10^{-65}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.45 \cdot 10^{-118}:\\ \;\;\;\;\frac{x \cdot x}{y}\\ \mathbf{elif}\;x \leq 3100000000000:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} - -1\\ \end{array} \]
Alternative 7
Error19.4
Cost588
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{-7}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.4 \cdot 10^{+66}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]
Alternative 8
Error28.8
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -450000:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{-7}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 9
Error53.9
Cost64
\[1 \]

Error

Reproduce

herbie shell --seed 2023010 
(FPCore (x y)
  :name "Codec.Picture.Types:toneMapping from JuicyPixels-3.2.6.1"
  :precision binary64

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

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