Average Error: 9.1 → 0.4
Time: 6.9s
Precision: binary64
Cost: 968
\[\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1} \]
\[\begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{+100}:\\ \;\;\;\;1 + \frac{x}{y}\\ \mathbf{elif}\;x \leq 1899488754707.8545:\\ \;\;\;\;\frac{x + \frac{x}{\frac{y}{x}}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{x + -1}{y}\\ \end{array} \]
(FPCore (x y) :precision binary64 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))
(FPCore (x y)
 :precision binary64
 (if (<= x -1e+100)
   (+ 1.0 (/ x y))
   (if (<= x 1899488754707.8545)
     (/ (+ x (/ x (/ y x))) (+ x 1.0))
     (+ 1.0 (/ (+ x -1.0) y)))))
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 <= -1e+100) {
		tmp = 1.0 + (x / y);
	} else if (x <= 1899488754707.8545) {
		tmp = (x + (x / (y / x))) / (x + 1.0);
	} else {
		tmp = 1.0 + ((x + -1.0) / y);
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (x * ((x / y) + 1.0d0)) / (x + 1.0d0)
end function
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (x <= (-1d+100)) then
        tmp = 1.0d0 + (x / y)
    else if (x <= 1899488754707.8545d0) then
        tmp = (x + (x / (y / x))) / (x + 1.0d0)
    else
        tmp = 1.0d0 + ((x + (-1.0d0)) / y)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	return (x * ((x / y) + 1.0)) / (x + 1.0);
}
public static double code(double x, double y) {
	double tmp;
	if (x <= -1e+100) {
		tmp = 1.0 + (x / y);
	} else if (x <= 1899488754707.8545) {
		tmp = (x + (x / (y / x))) / (x + 1.0);
	} else {
		tmp = 1.0 + ((x + -1.0) / y);
	}
	return tmp;
}
def code(x, y):
	return (x * ((x / y) + 1.0)) / (x + 1.0)
def code(x, y):
	tmp = 0
	if x <= -1e+100:
		tmp = 1.0 + (x / y)
	elif x <= 1899488754707.8545:
		tmp = (x + (x / (y / x))) / (x + 1.0)
	else:
		tmp = 1.0 + ((x + -1.0) / y)
	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 <= -1e+100)
		tmp = Float64(1.0 + Float64(x / y));
	elseif (x <= 1899488754707.8545)
		tmp = Float64(Float64(x + Float64(x / Float64(y / x))) / Float64(x + 1.0));
	else
		tmp = Float64(1.0 + Float64(Float64(x + -1.0) / y));
	end
	return tmp
end
function tmp = code(x, y)
	tmp = (x * ((x / y) + 1.0)) / (x + 1.0);
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -1e+100)
		tmp = 1.0 + (x / y);
	elseif (x <= 1899488754707.8545)
		tmp = (x + (x / (y / x))) / (x + 1.0);
	else
		tmp = 1.0 + ((x + -1.0) / y);
	end
	tmp_2 = 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, -1e+100], N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1899488754707.8545], N[(N[(x + N[(x / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]]
\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{+100}:\\
\;\;\;\;1 + \frac{x}{y}\\

\mathbf{elif}\;x \leq 1899488754707.8545:\\
\;\;\;\;\frac{x + \frac{x}{\frac{y}{x}}}{x + 1}\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 3 regimes
  2. if x < -1.00000000000000002e100

    1. Initial program 32.4

      \[\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 \]

    if -1.00000000000000002e100 < x < 1899488754707.8545

    1. Initial program 0.6

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

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(x, \frac{x}{y}, x\right)}{x + 1}} \]
      Proof
      (/.f64 (fma.f64 x (/.f64 x y) x) (+.f64 x 1)): 0 points increase in error, 0 points decrease in error
      (/.f64 (fma.f64 x (/.f64 x y) (Rewrite<= *-rgt-identity_binary64 (*.f64 x 1))) (+.f64 x 1)): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x (/.f64 x y)) (*.f64 x 1))) (+.f64 x 1)): 0 points increase in error, 1 points decrease in error
      (/.f64 (Rewrite<= distribute-lft-in_binary64 (*.f64 x (+.f64 (/.f64 x y) 1))) (+.f64 x 1)): 2 points increase in error, 1 points decrease in error
    3. Applied egg-rr0.6

      \[\leadsto \frac{\color{blue}{x \cdot \frac{x}{y} + x}}{x + 1} \]
    4. Applied egg-rr0.6

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

    if 1899488754707.8545 < x

    1. Initial program 21.0

      \[\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} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1 \cdot 10^{+100}:\\ \;\;\;\;1 + \frac{x}{y}\\ \mathbf{elif}\;x \leq 1899488754707.8545:\\ \;\;\;\;\frac{x + \frac{x}{\frac{y}{x}}}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{x + -1}{y}\\ \end{array} \]

Alternatives

Alternative 1
Error0.1
Cost832
\[\frac{\frac{x}{x + 1}}{\frac{1}{1 + \frac{x}{y}}} \]
Alternative 2
Error19.4
Cost720
\[\begin{array}{l} \mathbf{if}\;x \leq -414.35499942650017:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;x \leq 199.03103017631403:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 9.631444681442554 \cdot 10^{+79}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;x \leq 8.6 \cdot 10^{+138}:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]
Alternative 3
Error9.5
Cost712
\[\begin{array}{l} t_0 := 1 + \frac{x + -1}{y}\\ \mathbf{if}\;x \leq -80069002.81634252:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 199.03103017631403:\\ \;\;\;\;\frac{x}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error10.2
Cost584
\[\begin{array}{l} t_0 := 1 + \frac{x}{y}\\ \mathbf{if}\;x \leq -414.35499942650017:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.0419886010838414 \cdot 10^{-15}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error9.6
Cost584
\[\begin{array}{l} t_0 := 1 + \frac{x}{y}\\ \mathbf{if}\;x \leq -80069002.81634252:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 199.03103017631403:\\ \;\;\;\;\frac{x}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error28.3
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -2.707388424470535 \cdot 10^{-23}:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 0.5680570380839297:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 7
Error53.8
Cost64
\[1 \]

Error

Reproduce

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