?

Average Error: 9.1 → 0.1
Time: 1.6min
Precision: binary64
Cost: 2248

?

\[\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1} \]
\[\begin{array}{l} t_0 := \frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}\\ \mathbf{if}\;t_0 \leq -1 \cdot 10^{+119}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;x \ne 0:\\ \;\;\;\;\frac{\frac{x}{\frac{y}{-x} - y}}{-1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y + x}{y} \cdot x}{x - -1}\\ \end{array}\\ \mathbf{elif}\;t_0 \leq 10^{+182}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{1 + x} \cdot x}{y}\\ \end{array} \]
(FPCore (x y) :precision binary64 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0))))
   (if (<= t_0 -1e+119)
     (if (!= x 0.0)
       (/ (/ x (- (/ y (- x)) y)) -1.0)
       (/ (* (/ (+ y x) y) x) (- x -1.0)))
     (if (<= t_0 1e+182) t_0 (/ (* (/ x (+ 1.0 x)) x) y)))))
double code(double x, double y) {
	return (x * ((x / y) + 1.0)) / (x + 1.0);
}
double code(double x, double y) {
	double t_0 = (x * ((x / y) + 1.0)) / (x + 1.0);
	double tmp_1;
	if (t_0 <= -1e+119) {
		double tmp_2;
		if (x != 0.0) {
			tmp_2 = (x / ((y / -x) - y)) / -1.0;
		} else {
			tmp_2 = (((y + x) / y) * x) / (x - -1.0);
		}
		tmp_1 = tmp_2;
	} else if (t_0 <= 1e+182) {
		tmp_1 = t_0;
	} else {
		tmp_1 = ((x / (1.0 + x)) * x) / y;
	}
	return tmp_1;
}
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) :: t_0
    real(8) :: tmp
    real(8) :: tmp_1
    real(8) :: tmp_2
    t_0 = (x * ((x / y) + 1.0d0)) / (x + 1.0d0)
    if (t_0 <= (-1d+119)) then
        if (x /= 0.0d0) then
            tmp_2 = (x / ((y / -x) - y)) / (-1.0d0)
        else
            tmp_2 = (((y + x) / y) * x) / (x - (-1.0d0))
        end if
        tmp_1 = tmp_2
    else if (t_0 <= 1d+182) then
        tmp_1 = t_0
    else
        tmp_1 = ((x / (1.0d0 + x)) * x) / y
    end if
    code = tmp_1
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 t_0 = (x * ((x / y) + 1.0)) / (x + 1.0);
	double tmp_1;
	if (t_0 <= -1e+119) {
		double tmp_2;
		if (x != 0.0) {
			tmp_2 = (x / ((y / -x) - y)) / -1.0;
		} else {
			tmp_2 = (((y + x) / y) * x) / (x - -1.0);
		}
		tmp_1 = tmp_2;
	} else if (t_0 <= 1e+182) {
		tmp_1 = t_0;
	} else {
		tmp_1 = ((x / (1.0 + x)) * x) / y;
	}
	return tmp_1;
}
def code(x, y):
	return (x * ((x / y) + 1.0)) / (x + 1.0)
def code(x, y):
	t_0 = (x * ((x / y) + 1.0)) / (x + 1.0)
	tmp_1 = 0
	if t_0 <= -1e+119:
		tmp_2 = 0
		if x != 0.0:
			tmp_2 = (x / ((y / -x) - y)) / -1.0
		else:
			tmp_2 = (((y + x) / y) * x) / (x - -1.0)
		tmp_1 = tmp_2
	elif t_0 <= 1e+182:
		tmp_1 = t_0
	else:
		tmp_1 = ((x / (1.0 + x)) * x) / y
	return tmp_1
function code(x, y)
	return Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0))
end
function code(x, y)
	t_0 = Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0))
	tmp_1 = 0.0
	if (t_0 <= -1e+119)
		tmp_2 = 0.0
		if (x != 0.0)
			tmp_2 = Float64(Float64(x / Float64(Float64(y / Float64(-x)) - y)) / -1.0);
		else
			tmp_2 = Float64(Float64(Float64(Float64(y + x) / y) * x) / Float64(x - -1.0));
		end
		tmp_1 = tmp_2;
	elseif (t_0 <= 1e+182)
		tmp_1 = t_0;
	else
		tmp_1 = Float64(Float64(Float64(x / Float64(1.0 + x)) * x) / y);
	end
	return tmp_1
end
function tmp = code(x, y)
	tmp = (x * ((x / y) + 1.0)) / (x + 1.0);
end
function tmp_4 = code(x, y)
	t_0 = (x * ((x / y) + 1.0)) / (x + 1.0);
	tmp_2 = 0.0;
	if (t_0 <= -1e+119)
		tmp_3 = 0.0;
		if (x ~= 0.0)
			tmp_3 = (x / ((y / -x) - y)) / -1.0;
		else
			tmp_3 = (((y + x) / y) * x) / (x - -1.0);
		end
		tmp_2 = tmp_3;
	elseif (t_0 <= 1e+182)
		tmp_2 = t_0;
	else
		tmp_2 = ((x / (1.0 + x)) * x) / y;
	end
	tmp_4 = tmp_2;
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_] := Block[{t$95$0 = N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+119], If[Unequal[x, 0.0], N[(N[(x / N[(N[(y / (-x)), $MachinePrecision] - y), $MachinePrecision]), $MachinePrecision] / -1.0), $MachinePrecision], N[(N[(N[(N[(y + x), $MachinePrecision] / y), $MachinePrecision] * x), $MachinePrecision] / N[(x - -1.0), $MachinePrecision]), $MachinePrecision]], If[LessEqual[t$95$0, 1e+182], t$95$0, N[(N[(N[(x / N[(1.0 + x), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] / y), $MachinePrecision]]]]
\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}
\begin{array}{l}
t_0 := \frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{+119}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;x \ne 0:\\
\;\;\;\;\frac{\frac{x}{\frac{y}{-x} - y}}{-1}\\

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


\end{array}\\

\mathbf{elif}\;t_0 \leq 10^{+182}:\\
\;\;\;\;t_0\\

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


\end{array}

Error?

Target

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

Derivation?

  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 x (+.f64 (/.f64 x y) 1)) (+.f64 x 1)) < -9.99999999999999944e118

    1. Initial program 39.8

      \[\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1} \]
    2. Applied egg-rr0.1

      \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;x \ne 0:\\ \;\;\;\;\frac{\frac{y + x}{y}}{1 + {x}^{-1}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{y}, x, x\right)}{1 + x}\\ } \end{array}} \]
    3. Simplified0.1

      \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;x \ne 0:\\ \;\;\;\;\frac{y + x}{\left({x}^{-1} - -1\right) \cdot y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{y}, x, x\right)}{x - -1}\\ } \end{array}} \]
      Proof
    4. Applied egg-rr0.0

      \[\leadsto \begin{array}{l} \mathbf{if}\;x \ne 0:\\ \;\;\;\;\color{blue}{\frac{\frac{\left(-x\right) - y}{\frac{y}{x} + y}}{-1}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{x}{y}, x, x\right)}{x - -1}\\ \end{array} \]
    5. Applied egg-rr0.0

      \[\leadsto \begin{array}{l} \mathbf{if}\;x \ne 0:\\ \;\;\;\;\frac{\frac{\left(-x\right) - y}{\frac{y}{x} + y}}{-1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y + x}{y} \cdot x}{x - -1}\\ \end{array} \]
    6. Taylor expanded in y around 0 0.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;x \ne 0:\\ \;\;\;\;\frac{\color{blue}{-1 \cdot \frac{x}{y \cdot \left(1 + \frac{1}{x}\right)}}}{-1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y + x}{y} \cdot x}{x - -1}\\ \end{array} \]
    7. Simplified0.1

      \[\leadsto \begin{array}{l} \mathbf{if}\;x \ne 0:\\ \;\;\;\;\frac{\color{blue}{\frac{x}{\frac{y}{-x} - y}}}{-1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y + x}{y} \cdot x}{x - -1}\\ \end{array} \]
      Proof

    if -9.99999999999999944e118 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) 1)) (+.f64 x 1)) < 1.0000000000000001e182

    1. Initial program 0.1

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

    if 1.0000000000000001e182 < (/.f64 (*.f64 x (+.f64 (/.f64 x y) 1)) (+.f64 x 1))

    1. Initial program 51.4

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

      \[\leadsto \color{blue}{\frac{{x}^{2}}{y \cdot \left(1 + x\right)}} \]
    3. Simplified51.4

      \[\leadsto \color{blue}{\frac{\frac{{x}^{2}}{y}}{x - -1}} \]
      Proof
    4. Applied egg-rr0.1

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

Alternatives

Alternative 1
Error10.7
Cost1104
\[\begin{array}{l} t_0 := 1 + \frac{x}{y}\\ t_1 := \frac{\frac{x}{y} \cdot x}{x - -1}\\ \mathbf{if}\;x \leq -115000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -7.7 \cdot 10^{-28}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.2 \cdot 10^{-56}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -5.6 \cdot 10^{-120}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.95 \cdot 10^{-8}:\\ \;\;\;\;\frac{x}{x - -1}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.2
Cost968
\[\begin{array}{l} t_0 := 1 + \frac{x}{y}\\ \mathbf{if}\;x \leq -6.6 \cdot 10^{+45}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 3.4 \cdot 10^{+15}:\\ \;\;\;\;\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error9.8
Cost584
\[\begin{array}{l} t_0 := 1 + \frac{x}{y}\\ \mathbf{if}\;x \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.95 \cdot 10^{-8}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error9.6
Cost584
\[\begin{array}{l} t_0 := 1 + \frac{x}{y}\\ \mathbf{if}\;x \leq -88000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq 2.95 \cdot 10^{-8}:\\ \;\;\;\;\frac{x}{x - -1}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error9.5
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -85000:\\ \;\;\;\;1 + \frac{x - 1}{y}\\ \mathbf{elif}\;x \leq 2.95 \cdot 10^{-8}:\\ \;\;\;\;\frac{x}{x - -1}\\ \mathbf{else}:\\ \;\;\;\;1 + \frac{x}{y}\\ \end{array} \]
Alternative 6
Error18.8
Cost456
\[\begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;x \leq 2.95 \cdot 10^{-8}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]
Alternative 7
Error35.8
Cost64
\[x \]

Error

Reproduce?

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