Codec.Picture.Types:toneMapping from JuicyPixels-3.2.6.1

Percentage Accurate: 88.0% → 97.7%
Time: 6.2s
Alternatives: 9
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1} \end{array} \]
(FPCore (x y) :precision binary64 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))
double code(double x, double y) {
	return (x * ((x / y) + 1.0)) / (x + 1.0);
}
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
public static double code(double x, double y) {
	return (x * ((x / y) + 1.0)) / (x + 1.0);
}
def code(x, y):
	return (x * ((x / y) + 1.0)) / (x + 1.0)
function code(x, y)
	return Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0))
end
function tmp = code(x, y)
	tmp = (x * ((x / y) + 1.0)) / (x + 1.0);
end
code[x_, y_] := N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 9 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 88.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1} \end{array} \]
(FPCore (x y) :precision binary64 (/ (* x (+ (/ x y) 1.0)) (+ x 1.0)))
double code(double x, double y) {
	return (x * ((x / y) + 1.0)) / (x + 1.0);
}
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
public static double code(double x, double y) {
	return (x * ((x / y) + 1.0)) / (x + 1.0);
}
def code(x, y):
	return (x * ((x / y) + 1.0)) / (x + 1.0)
function code(x, y)
	return Float64(Float64(x * Float64(Float64(x / y) + 1.0)) / Float64(x + 1.0))
end
function tmp = code(x, y)
	tmp = (x * ((x / y) + 1.0)) / (x + 1.0);
end
code[x_, y_] := N[(N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1}
\end{array}

Alternative 1: 97.7% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{y} + 1\\ \mathbf{if}\;x \leq -1.45 \cdot 10^{+162} \lor \neg \left(x \leq 10\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot t_0}{x + 1}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (+ (/ x y) 1.0)))
   (if (or (<= x -1.45e+162) (not (<= x 10.0))) t_0 (/ (* x t_0) (+ x 1.0)))))
double code(double x, double y) {
	double t_0 = (x / y) + 1.0;
	double tmp;
	if ((x <= -1.45e+162) || !(x <= 10.0)) {
		tmp = t_0;
	} else {
		tmp = (x * t_0) / (x + 1.0);
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (x / y) + 1.0d0
    if ((x <= (-1.45d+162)) .or. (.not. (x <= 10.0d0))) then
        tmp = t_0
    else
        tmp = (x * t_0) / (x + 1.0d0)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = (x / y) + 1.0;
	double tmp;
	if ((x <= -1.45e+162) || !(x <= 10.0)) {
		tmp = t_0;
	} else {
		tmp = (x * t_0) / (x + 1.0);
	}
	return tmp;
}
def code(x, y):
	t_0 = (x / y) + 1.0
	tmp = 0
	if (x <= -1.45e+162) or not (x <= 10.0):
		tmp = t_0
	else:
		tmp = (x * t_0) / (x + 1.0)
	return tmp
function code(x, y)
	t_0 = Float64(Float64(x / y) + 1.0)
	tmp = 0.0
	if ((x <= -1.45e+162) || !(x <= 10.0))
		tmp = t_0;
	else
		tmp = Float64(Float64(x * t_0) / Float64(x + 1.0));
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = (x / y) + 1.0;
	tmp = 0.0;
	if ((x <= -1.45e+162) || ~((x <= 10.0)))
		tmp = t_0;
	else
		tmp = (x * t_0) / (x + 1.0);
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]}, If[Or[LessEqual[x, -1.45e+162], N[Not[LessEqual[x, 10.0]], $MachinePrecision]], t$95$0, N[(N[(x * t$95$0), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x}{y} + 1\\
\mathbf{if}\;x \leq -1.45 \cdot 10^{+162} \lor \neg \left(x \leq 10\right):\\
\;\;\;\;t_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.45000000000000003e162 or 10 < x

    1. Initial program 60.8%

      \[\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1} \]
    2. Step-by-step derivation
      1. *-commutative60.8%

        \[\leadsto \frac{\color{blue}{\left(\frac{x}{y} + 1\right) \cdot x}}{x + 1} \]
      2. associate-/l*100.0%

        \[\leadsto \color{blue}{\frac{\frac{x}{y} + 1}{\frac{x + 1}{x}}} \]
      3. +-commutative100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{1 + x}}{x}} \]
      4. remove-double-neg100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1 + \color{blue}{\left(-\left(-x\right)\right)}}{x}} \]
      5. unsub-neg100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{1 - \left(-x\right)}}{x}} \]
      6. div-sub100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\color{blue}{\frac{1}{x} - \frac{-x}{x}}} \]
      7. distribute-frac-neg100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \color{blue}{\left(-\frac{x}{x}\right)}} \]
      8. *-inverses100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \left(-\color{blue}{1}\right)} \]
      9. metadata-eval100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \color{blue}{-1}} \]
    3. Simplified100.0%

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

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

    if -1.45000000000000003e162 < x < 10

    1. Initial program 99.9%

      \[\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.9%

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

Alternative 2: 85.6% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -3.6 \cdot 10^{+78}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;x \leq -1.6 \cdot 10^{-8}:\\ \;\;\;\;\frac{x}{x + 1}\\ \mathbf{elif}\;x \leq 6.8:\\ \;\;\;\;x \cdot \left(\frac{x}{y} + 1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x -3.6e+78)
   (/ x y)
   (if (<= x -1.6e-8)
     (/ x (+ x 1.0))
     (if (<= x 6.8) (* x (+ (/ x y) 1.0)) (/ x y)))))
double code(double x, double y) {
	double tmp;
	if (x <= -3.6e+78) {
		tmp = x / y;
	} else if (x <= -1.6e-8) {
		tmp = x / (x + 1.0);
	} else if (x <= 6.8) {
		tmp = x * ((x / y) + 1.0);
	} else {
		tmp = x / y;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (x <= (-3.6d+78)) then
        tmp = x / y
    else if (x <= (-1.6d-8)) then
        tmp = x / (x + 1.0d0)
    else if (x <= 6.8d0) then
        tmp = x * ((x / y) + 1.0d0)
    else
        tmp = x / y
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= -3.6e+78) {
		tmp = x / y;
	} else if (x <= -1.6e-8) {
		tmp = x / (x + 1.0);
	} else if (x <= 6.8) {
		tmp = x * ((x / y) + 1.0);
	} else {
		tmp = x / y;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -3.6e+78:
		tmp = x / y
	elif x <= -1.6e-8:
		tmp = x / (x + 1.0)
	elif x <= 6.8:
		tmp = x * ((x / y) + 1.0)
	else:
		tmp = x / y
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -3.6e+78)
		tmp = Float64(x / y);
	elseif (x <= -1.6e-8)
		tmp = Float64(x / Float64(x + 1.0));
	elseif (x <= 6.8)
		tmp = Float64(x * Float64(Float64(x / y) + 1.0));
	else
		tmp = Float64(x / y);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -3.6e+78)
		tmp = x / y;
	elseif (x <= -1.6e-8)
		tmp = x / (x + 1.0);
	elseif (x <= 6.8)
		tmp = x * ((x / y) + 1.0);
	else
		tmp = x / y;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -3.6e+78], N[(x / y), $MachinePrecision], If[LessEqual[x, -1.6e-8], N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 6.8], N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(x / y), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{+78}:\\
\;\;\;\;\frac{x}{y}\\

\mathbf{elif}\;x \leq -1.6 \cdot 10^{-8}:\\
\;\;\;\;\frac{x}{x + 1}\\

\mathbf{elif}\;x \leq 6.8:\\
\;\;\;\;x \cdot \left(\frac{x}{y} + 1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -3.6000000000000002e78 or 6.79999999999999982 < x

    1. Initial program 67.7%

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

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

    if -3.6000000000000002e78 < x < -1.6000000000000001e-8

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{\frac{x}{1 + x}} \]
    3. Step-by-step derivation
      1. +-commutative69.9%

        \[\leadsto \frac{x}{\color{blue}{x + 1}} \]
    4. Simplified69.9%

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

    if -1.6000000000000001e-8 < x < 6.79999999999999982

    1. Initial program 99.9%

      \[\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1} \]
    2. Step-by-step derivation
      1. *-commutative99.9%

        \[\leadsto \frac{\color{blue}{\left(\frac{x}{y} + 1\right) \cdot x}}{x + 1} \]
      2. associate-/l*99.7%

        \[\leadsto \color{blue}{\frac{\frac{x}{y} + 1}{\frac{x + 1}{x}}} \]
      3. +-commutative99.7%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{1 + x}}{x}} \]
      4. remove-double-neg99.7%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1 + \color{blue}{\left(-\left(-x\right)\right)}}{x}} \]
      5. unsub-neg99.7%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{1 - \left(-x\right)}}{x}} \]
      6. div-sub99.7%

        \[\leadsto \frac{\frac{x}{y} + 1}{\color{blue}{\frac{1}{x} - \frac{-x}{x}}} \]
      7. distribute-frac-neg99.7%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \color{blue}{\left(-\frac{x}{x}\right)}} \]
      8. *-inverses99.7%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \left(-\color{blue}{1}\right)} \]
      9. metadata-eval99.7%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \color{blue}{-1}} \]
    3. Simplified99.7%

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

      \[\leadsto \frac{\frac{x}{y} + 1}{\color{blue}{\frac{1}{x}}} \]
    5. Step-by-step derivation
      1. associate-/r/97.4%

        \[\leadsto \color{blue}{\frac{\frac{x}{y} + 1}{1} \cdot x} \]
      2. /-rgt-identity97.4%

        \[\leadsto \color{blue}{\left(\frac{x}{y} + 1\right)} \cdot x \]
    6. Applied egg-rr97.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -3.6 \cdot 10^{+78}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;x \leq -1.6 \cdot 10^{-8}:\\ \;\;\;\;\frac{x}{x + 1}\\ \mathbf{elif}\;x \leq 6.8:\\ \;\;\;\;x \cdot \left(\frac{x}{y} + 1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \]

Alternative 3: 85.9% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -8.5 \cdot 10^{+77}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;x \leq -6.2 \cdot 10^{-8}:\\ \;\;\;\;\frac{x}{x + 1}\\ \mathbf{elif}\;x \leq 5 \cdot 10^{-9}:\\ \;\;\;\;x \cdot \left(\frac{x}{y} + 1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y + \frac{y}{x}}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x -8.5e+77)
   (/ x y)
   (if (<= x -6.2e-8)
     (/ x (+ x 1.0))
     (if (<= x 5e-9) (* x (+ (/ x y) 1.0)) (/ x (+ y (/ y x)))))))
double code(double x, double y) {
	double tmp;
	if (x <= -8.5e+77) {
		tmp = x / y;
	} else if (x <= -6.2e-8) {
		tmp = x / (x + 1.0);
	} else if (x <= 5e-9) {
		tmp = x * ((x / y) + 1.0);
	} else {
		tmp = x / (y + (y / x));
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (x <= (-8.5d+77)) then
        tmp = x / y
    else if (x <= (-6.2d-8)) then
        tmp = x / (x + 1.0d0)
    else if (x <= 5d-9) then
        tmp = x * ((x / y) + 1.0d0)
    else
        tmp = x / (y + (y / x))
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= -8.5e+77) {
		tmp = x / y;
	} else if (x <= -6.2e-8) {
		tmp = x / (x + 1.0);
	} else if (x <= 5e-9) {
		tmp = x * ((x / y) + 1.0);
	} else {
		tmp = x / (y + (y / x));
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -8.5e+77:
		tmp = x / y
	elif x <= -6.2e-8:
		tmp = x / (x + 1.0)
	elif x <= 5e-9:
		tmp = x * ((x / y) + 1.0)
	else:
		tmp = x / (y + (y / x))
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -8.5e+77)
		tmp = Float64(x / y);
	elseif (x <= -6.2e-8)
		tmp = Float64(x / Float64(x + 1.0));
	elseif (x <= 5e-9)
		tmp = Float64(x * Float64(Float64(x / y) + 1.0));
	else
		tmp = Float64(x / Float64(y + Float64(y / x)));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -8.5e+77)
		tmp = x / y;
	elseif (x <= -6.2e-8)
		tmp = x / (x + 1.0);
	elseif (x <= 5e-9)
		tmp = x * ((x / y) + 1.0);
	else
		tmp = x / (y + (y / x));
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -8.5e+77], N[(x / y), $MachinePrecision], If[LessEqual[x, -6.2e-8], N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 5e-9], N[(x * N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(x / N[(y + N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.5 \cdot 10^{+77}:\\
\;\;\;\;\frac{x}{y}\\

\mathbf{elif}\;x \leq -6.2 \cdot 10^{-8}:\\
\;\;\;\;\frac{x}{x + 1}\\

\mathbf{elif}\;x \leq 5 \cdot 10^{-9}:\\
\;\;\;\;x \cdot \left(\frac{x}{y} + 1\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if x < -8.50000000000000018e77

    1. Initial program 66.5%

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

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

    if -8.50000000000000018e77 < x < -6.2e-8

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{\frac{x}{1 + x}} \]
    3. Step-by-step derivation
      1. +-commutative69.9%

        \[\leadsto \frac{x}{\color{blue}{x + 1}} \]
    4. Simplified69.9%

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

    if -6.2e-8 < x < 5.0000000000000001e-9

    1. Initial program 99.9%

      \[\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1} \]
    2. Step-by-step derivation
      1. *-commutative99.9%

        \[\leadsto \frac{\color{blue}{\left(\frac{x}{y} + 1\right) \cdot x}}{x + 1} \]
      2. associate-/l*99.7%

        \[\leadsto \color{blue}{\frac{\frac{x}{y} + 1}{\frac{x + 1}{x}}} \]
      3. +-commutative99.7%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{1 + x}}{x}} \]
      4. remove-double-neg99.7%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1 + \color{blue}{\left(-\left(-x\right)\right)}}{x}} \]
      5. unsub-neg99.7%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{1 - \left(-x\right)}}{x}} \]
      6. div-sub99.7%

        \[\leadsto \frac{\frac{x}{y} + 1}{\color{blue}{\frac{1}{x} - \frac{-x}{x}}} \]
      7. distribute-frac-neg99.7%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \color{blue}{\left(-\frac{x}{x}\right)}} \]
      8. *-inverses99.7%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \left(-\color{blue}{1}\right)} \]
      9. metadata-eval99.7%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \color{blue}{-1}} \]
    3. Simplified99.7%

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

      \[\leadsto \frac{\frac{x}{y} + 1}{\color{blue}{\frac{1}{x}}} \]
    5. Step-by-step derivation
      1. associate-/r/99.9%

        \[\leadsto \color{blue}{\frac{\frac{x}{y} + 1}{1} \cdot x} \]
      2. /-rgt-identity99.9%

        \[\leadsto \color{blue}{\left(\frac{x}{y} + 1\right)} \cdot x \]
    6. Applied egg-rr99.9%

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

    if 5.0000000000000001e-9 < x

    1. Initial program 71.5%

      \[\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1} \]
    2. Step-by-step derivation
      1. *-commutative71.5%

        \[\leadsto \frac{\color{blue}{\left(\frac{x}{y} + 1\right) \cdot x}}{x + 1} \]
      2. associate-/l*99.9%

        \[\leadsto \color{blue}{\frac{\frac{x}{y} + 1}{\frac{x + 1}{x}}} \]
      3. +-commutative99.9%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{1 + x}}{x}} \]
      4. remove-double-neg99.9%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1 + \color{blue}{\left(-\left(-x\right)\right)}}{x}} \]
      5. unsub-neg99.9%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{1 - \left(-x\right)}}{x}} \]
      6. div-sub100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\color{blue}{\frac{1}{x} - \frac{-x}{x}}} \]
      7. distribute-frac-neg100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \color{blue}{\left(-\frac{x}{x}\right)}} \]
      8. *-inverses100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \left(-\color{blue}{1}\right)} \]
      9. metadata-eval100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \color{blue}{-1}} \]
    3. Simplified100.0%

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

      \[\leadsto \color{blue}{\frac{x}{y \cdot \left(1 + \frac{1}{x}\right)}} \]
    5. Step-by-step derivation
      1. distribute-lft-in80.5%

        \[\leadsto \frac{x}{\color{blue}{y \cdot 1 + y \cdot \frac{1}{x}}} \]
      2. *-rgt-identity80.5%

        \[\leadsto \frac{x}{\color{blue}{y} + y \cdot \frac{1}{x}} \]
      3. associate-*r/80.5%

        \[\leadsto \frac{x}{y + \color{blue}{\frac{y \cdot 1}{x}}} \]
      4. *-rgt-identity80.5%

        \[\leadsto \frac{x}{y + \frac{\color{blue}{y}}{x}} \]
    6. Simplified80.5%

      \[\leadsto \color{blue}{\frac{x}{y + \frac{y}{x}}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification88.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -8.5 \cdot 10^{+77}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;x \leq -6.2 \cdot 10^{-8}:\\ \;\;\;\;\frac{x}{x + 1}\\ \mathbf{elif}\;x \leq 5 \cdot 10^{-9}:\\ \;\;\;\;x \cdot \left(\frac{x}{y} + 1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y + \frac{y}{x}}\\ \end{array} \]

Alternative 4: 98.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{y} + 1\\ \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;x \cdot t_0\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (+ (/ x y) 1.0)))
   (if (or (<= x -1.0) (not (<= x 1.0))) t_0 (* x t_0))))
double code(double x, double y) {
	double t_0 = (x / y) + 1.0;
	double tmp;
	if ((x <= -1.0) || !(x <= 1.0)) {
		tmp = t_0;
	} else {
		tmp = x * t_0;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (x / y) + 1.0d0
    if ((x <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
        tmp = t_0
    else
        tmp = x * t_0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double t_0 = (x / y) + 1.0;
	double tmp;
	if ((x <= -1.0) || !(x <= 1.0)) {
		tmp = t_0;
	} else {
		tmp = x * t_0;
	}
	return tmp;
}
def code(x, y):
	t_0 = (x / y) + 1.0
	tmp = 0
	if (x <= -1.0) or not (x <= 1.0):
		tmp = t_0
	else:
		tmp = x * t_0
	return tmp
function code(x, y)
	t_0 = Float64(Float64(x / y) + 1.0)
	tmp = 0.0
	if ((x <= -1.0) || !(x <= 1.0))
		tmp = t_0;
	else
		tmp = Float64(x * t_0);
	end
	return tmp
end
function tmp_2 = code(x, y)
	t_0 = (x / y) + 1.0;
	tmp = 0.0;
	if ((x <= -1.0) || ~((x <= 1.0)))
		tmp = t_0;
	else
		tmp = x * t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := Block[{t$95$0 = N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision]}, If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], t$95$0, N[(x * t$95$0), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x}{y} + 1\\
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;x \cdot t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1 or 1 < x

    1. Initial program 72.1%

      \[\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1} \]
    2. Step-by-step derivation
      1. *-commutative72.1%

        \[\leadsto \frac{\color{blue}{\left(\frac{x}{y} + 1\right) \cdot x}}{x + 1} \]
      2. associate-/l*100.0%

        \[\leadsto \color{blue}{\frac{\frac{x}{y} + 1}{\frac{x + 1}{x}}} \]
      3. +-commutative100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{1 + x}}{x}} \]
      4. remove-double-neg100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1 + \color{blue}{\left(-\left(-x\right)\right)}}{x}} \]
      5. unsub-neg100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{1 - \left(-x\right)}}{x}} \]
      6. div-sub100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\color{blue}{\frac{1}{x} - \frac{-x}{x}}} \]
      7. distribute-frac-neg100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \color{blue}{\left(-\frac{x}{x}\right)}} \]
      8. *-inverses100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \left(-\color{blue}{1}\right)} \]
      9. metadata-eval100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \color{blue}{-1}} \]
    3. Simplified100.0%

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

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

    if -1 < x < 1

    1. Initial program 99.9%

      \[\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1} \]
    2. Step-by-step derivation
      1. *-commutative99.9%

        \[\leadsto \frac{\color{blue}{\left(\frac{x}{y} + 1\right) \cdot x}}{x + 1} \]
      2. associate-/l*99.7%

        \[\leadsto \color{blue}{\frac{\frac{x}{y} + 1}{\frac{x + 1}{x}}} \]
      3. +-commutative99.7%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{1 + x}}{x}} \]
      4. remove-double-neg99.7%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1 + \color{blue}{\left(-\left(-x\right)\right)}}{x}} \]
      5. unsub-neg99.7%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{1 - \left(-x\right)}}{x}} \]
      6. div-sub99.7%

        \[\leadsto \frac{\frac{x}{y} + 1}{\color{blue}{\frac{1}{x} - \frac{-x}{x}}} \]
      7. distribute-frac-neg99.7%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \color{blue}{\left(-\frac{x}{x}\right)}} \]
      8. *-inverses99.7%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \left(-\color{blue}{1}\right)} \]
      9. metadata-eval99.7%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \color{blue}{-1}} \]
    3. Simplified99.7%

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

      \[\leadsto \frac{\frac{x}{y} + 1}{\color{blue}{\frac{1}{x}}} \]
    5. Step-by-step derivation
      1. associate-/r/96.3%

        \[\leadsto \color{blue}{\frac{\frac{x}{y} + 1}{1} \cdot x} \]
      2. /-rgt-identity96.3%

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

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

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

Alternative 5: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\frac{x}{y} + 1}{\frac{1}{x} - -1} \end{array} \]
(FPCore (x y) :precision binary64 (/ (+ (/ x y) 1.0) (- (/ 1.0 x) -1.0)))
double code(double x, double y) {
	return ((x / y) + 1.0) / ((1.0 / x) - -1.0);
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = ((x / y) + 1.0d0) / ((1.0d0 / x) - (-1.0d0))
end function
public static double code(double x, double y) {
	return ((x / y) + 1.0) / ((1.0 / x) - -1.0);
}
def code(x, y):
	return ((x / y) + 1.0) / ((1.0 / x) - -1.0)
function code(x, y)
	return Float64(Float64(Float64(x / y) + 1.0) / Float64(Float64(1.0 / x) - -1.0))
end
function tmp = code(x, y)
	tmp = ((x / y) + 1.0) / ((1.0 / x) - -1.0);
end
code[x_, y_] := N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] / N[(N[(1.0 / x), $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\frac{x}{y} + 1}{\frac{1}{x} - -1}
\end{array}
Derivation
  1. Initial program 86.5%

    \[\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1} \]
  2. Step-by-step derivation
    1. *-commutative86.5%

      \[\leadsto \frac{\color{blue}{\left(\frac{x}{y} + 1\right) \cdot x}}{x + 1} \]
    2. associate-/l*99.8%

      \[\leadsto \color{blue}{\frac{\frac{x}{y} + 1}{\frac{x + 1}{x}}} \]
    3. +-commutative99.8%

      \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{1 + x}}{x}} \]
    4. remove-double-neg99.8%

      \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1 + \color{blue}{\left(-\left(-x\right)\right)}}{x}} \]
    5. unsub-neg99.8%

      \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{1 - \left(-x\right)}}{x}} \]
    6. div-sub99.8%

      \[\leadsto \frac{\frac{x}{y} + 1}{\color{blue}{\frac{1}{x} - \frac{-x}{x}}} \]
    7. distribute-frac-neg99.8%

      \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \color{blue}{\left(-\frac{x}{x}\right)}} \]
    8. *-inverses99.8%

      \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \left(-\color{blue}{1}\right)} \]
    9. metadata-eval99.8%

      \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \color{blue}{-1}} \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{\frac{\frac{x}{y} + 1}{\frac{1}{x} - -1}} \]
  4. Final simplification99.8%

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

Alternative 6: 73.6% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -3 \cdot 10^{+78}:\\ \;\;\;\;\frac{x}{y}\\ \mathbf{elif}\;x \leq -2000000000:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 4.8:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x -3e+78)
   (/ x y)
   (if (<= x -2000000000.0) 1.0 (if (<= x 4.8) x (/ x y)))))
double code(double x, double y) {
	double tmp;
	if (x <= -3e+78) {
		tmp = x / y;
	} else if (x <= -2000000000.0) {
		tmp = 1.0;
	} else if (x <= 4.8) {
		tmp = x;
	} else {
		tmp = x / y;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (x <= (-3d+78)) then
        tmp = x / y
    else if (x <= (-2000000000.0d0)) then
        tmp = 1.0d0
    else if (x <= 4.8d0) then
        tmp = x
    else
        tmp = x / y
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= -3e+78) {
		tmp = x / y;
	} else if (x <= -2000000000.0) {
		tmp = 1.0;
	} else if (x <= 4.8) {
		tmp = x;
	} else {
		tmp = x / y;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -3e+78:
		tmp = x / y
	elif x <= -2000000000.0:
		tmp = 1.0
	elif x <= 4.8:
		tmp = x
	else:
		tmp = x / y
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -3e+78)
		tmp = Float64(x / y);
	elseif (x <= -2000000000.0)
		tmp = 1.0;
	elseif (x <= 4.8)
		tmp = x;
	else
		tmp = Float64(x / y);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -3e+78)
		tmp = x / y;
	elseif (x <= -2000000000.0)
		tmp = 1.0;
	elseif (x <= 4.8)
		tmp = x;
	else
		tmp = x / y;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -3e+78], N[(x / y), $MachinePrecision], If[LessEqual[x, -2000000000.0], 1.0, If[LessEqual[x, 4.8], x, N[(x / y), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -3 \cdot 10^{+78}:\\
\;\;\;\;\frac{x}{y}\\

\mathbf{elif}\;x \leq -2000000000:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq 4.8:\\
\;\;\;\;x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -2.99999999999999982e78 or 4.79999999999999982 < x

    1. Initial program 67.7%

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

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

    if -2.99999999999999982e78 < x < -2e9

    1. Initial program 100.0%

      \[\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1} \]
    2. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \frac{\color{blue}{\left(\frac{x}{y} + 1\right) \cdot x}}{x + 1} \]
      2. associate-/l*100.0%

        \[\leadsto \color{blue}{\frac{\frac{x}{y} + 1}{\frac{x + 1}{x}}} \]
      3. +-commutative100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{1 + x}}{x}} \]
      4. remove-double-neg100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1 + \color{blue}{\left(-\left(-x\right)\right)}}{x}} \]
      5. unsub-neg100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{1 - \left(-x\right)}}{x}} \]
      6. div-sub100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\color{blue}{\frac{1}{x} - \frac{-x}{x}}} \]
      7. distribute-frac-neg100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \color{blue}{\left(-\frac{x}{x}\right)}} \]
      8. *-inverses100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \left(-\color{blue}{1}\right)} \]
      9. metadata-eval100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \color{blue}{-1}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{\frac{x}{y} + 1}{\frac{1}{x} - -1}} \]
    4. Step-by-step derivation
      1. flip--100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\color{blue}{\frac{\frac{1}{x} \cdot \frac{1}{x} - -1 \cdot -1}{\frac{1}{x} + -1}}} \]
      2. metadata-eval100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\frac{1}{x} \cdot \frac{1}{x} - \color{blue}{1}}{\frac{1}{x} + -1}} \]
      3. sub-neg100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{\frac{1}{x} \cdot \frac{1}{x} + \left(-1\right)}}{\frac{1}{x} + -1}} \]
      4. inv-pow100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{{x}^{-1}} \cdot \frac{1}{x} + \left(-1\right)}{\frac{1}{x} + -1}} \]
      5. inv-pow100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{{x}^{-1} \cdot \color{blue}{{x}^{-1}} + \left(-1\right)}{\frac{1}{x} + -1}} \]
      6. pow-prod-up100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{{x}^{\left(-1 + -1\right)}} + \left(-1\right)}{\frac{1}{x} + -1}} \]
      7. metadata-eval100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{{x}^{\color{blue}{-2}} + \left(-1\right)}{\frac{1}{x} + -1}} \]
      8. metadata-eval100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{{x}^{-2} + \color{blue}{-1}}{\frac{1}{x} + -1}} \]
    5. Applied egg-rr100.0%

      \[\leadsto \frac{\frac{x}{y} + 1}{\color{blue}{\frac{{x}^{-2} + -1}{\frac{1}{x} + -1}}} \]
    6. Taylor expanded in y around inf 75.1%

      \[\leadsto \color{blue}{\frac{\frac{1}{x} - 1}{\frac{1}{{x}^{2}} - 1}} \]
    7. Taylor expanded in x around inf 75.1%

      \[\leadsto \color{blue}{1} \]

    if -2e9 < x < 4.79999999999999982

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{x} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification75.6%

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

Alternative 7: 74.5% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.6 \cdot 10^{+78} \lor \neg \left(x \leq 7\right):\\ \;\;\;\;\frac{x}{y}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{x + 1}\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (or (<= x -1.6e+78) (not (<= x 7.0))) (/ x y) (/ x (+ x 1.0))))
double code(double x, double y) {
	double tmp;
	if ((x <= -1.6e+78) || !(x <= 7.0)) {
		tmp = x / y;
	} else {
		tmp = x / (x + 1.0);
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((x <= (-1.6d+78)) .or. (.not. (x <= 7.0d0))) then
        tmp = x / y
    else
        tmp = x / (x + 1.0d0)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((x <= -1.6e+78) || !(x <= 7.0)) {
		tmp = x / y;
	} else {
		tmp = x / (x + 1.0);
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (x <= -1.6e+78) or not (x <= 7.0):
		tmp = x / y
	else:
		tmp = x / (x + 1.0)
	return tmp
function code(x, y)
	tmp = 0.0
	if ((x <= -1.6e+78) || !(x <= 7.0))
		tmp = Float64(x / y);
	else
		tmp = Float64(x / Float64(x + 1.0));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((x <= -1.6e+78) || ~((x <= 7.0)))
		tmp = x / y;
	else
		tmp = x / (x + 1.0);
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[Or[LessEqual[x, -1.6e+78], N[Not[LessEqual[x, 7.0]], $MachinePrecision]], N[(x / y), $MachinePrecision], N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{+78} \lor \neg \left(x \leq 7\right):\\
\;\;\;\;\frac{x}{y}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.59999999999999997e78 or 7 < x

    1. Initial program 67.7%

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

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

    if -1.59999999999999997e78 < x < 7

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{\frac{x}{1 + x}} \]
    3. Step-by-step derivation
      1. +-commutative74.8%

        \[\leadsto \frac{x}{\color{blue}{x + 1}} \]
    4. Simplified74.8%

      \[\leadsto \color{blue}{\frac{x}{x + 1}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification76.7%

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

Alternative 8: 47.6% accurate, 2.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2000000000:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 4.8 \cdot 10^{+52}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= x -2000000000.0) 1.0 (if (<= x 4.8e+52) x 1.0)))
double code(double x, double y) {
	double tmp;
	if (x <= -2000000000.0) {
		tmp = 1.0;
	} else if (x <= 4.8e+52) {
		tmp = x;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (x <= (-2000000000.0d0)) then
        tmp = 1.0d0
    else if (x <= 4.8d+52) then
        tmp = x
    else
        tmp = 1.0d0
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (x <= -2000000000.0) {
		tmp = 1.0;
	} else if (x <= 4.8e+52) {
		tmp = x;
	} else {
		tmp = 1.0;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if x <= -2000000000.0:
		tmp = 1.0
	elif x <= 4.8e+52:
		tmp = x
	else:
		tmp = 1.0
	return tmp
function code(x, y)
	tmp = 0.0
	if (x <= -2000000000.0)
		tmp = 1.0;
	elseif (x <= 4.8e+52)
		tmp = x;
	else
		tmp = 1.0;
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (x <= -2000000000.0)
		tmp = 1.0;
	elseif (x <= 4.8e+52)
		tmp = x;
	else
		tmp = 1.0;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[x, -2000000000.0], 1.0, If[LessEqual[x, 4.8e+52], x, 1.0]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -2000000000:\\
\;\;\;\;1\\

\mathbf{elif}\;x \leq 4.8 \cdot 10^{+52}:\\
\;\;\;\;x\\

\mathbf{else}:\\
\;\;\;\;1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -2e9 or 4.8e52 < x

    1. Initial program 71.0%

      \[\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1} \]
    2. Step-by-step derivation
      1. *-commutative71.0%

        \[\leadsto \frac{\color{blue}{\left(\frac{x}{y} + 1\right) \cdot x}}{x + 1} \]
      2. associate-/l*100.0%

        \[\leadsto \color{blue}{\frac{\frac{x}{y} + 1}{\frac{x + 1}{x}}} \]
      3. +-commutative100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{1 + x}}{x}} \]
      4. remove-double-neg100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1 + \color{blue}{\left(-\left(-x\right)\right)}}{x}} \]
      5. unsub-neg100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{1 - \left(-x\right)}}{x}} \]
      6. div-sub100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\color{blue}{\frac{1}{x} - \frac{-x}{x}}} \]
      7. distribute-frac-neg100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \color{blue}{\left(-\frac{x}{x}\right)}} \]
      8. *-inverses100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \left(-\color{blue}{1}\right)} \]
      9. metadata-eval100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \color{blue}{-1}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{\frac{x}{y} + 1}{\frac{1}{x} - -1}} \]
    4. Step-by-step derivation
      1. flip--100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\color{blue}{\frac{\frac{1}{x} \cdot \frac{1}{x} - -1 \cdot -1}{\frac{1}{x} + -1}}} \]
      2. metadata-eval100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\frac{1}{x} \cdot \frac{1}{x} - \color{blue}{1}}{\frac{1}{x} + -1}} \]
      3. sub-neg100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{\frac{1}{x} \cdot \frac{1}{x} + \left(-1\right)}}{\frac{1}{x} + -1}} \]
      4. inv-pow100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{{x}^{-1}} \cdot \frac{1}{x} + \left(-1\right)}{\frac{1}{x} + -1}} \]
      5. inv-pow100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{{x}^{-1} \cdot \color{blue}{{x}^{-1}} + \left(-1\right)}{\frac{1}{x} + -1}} \]
      6. pow-prod-up100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{{x}^{\left(-1 + -1\right)}} + \left(-1\right)}{\frac{1}{x} + -1}} \]
      7. metadata-eval100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{{x}^{\color{blue}{-2}} + \left(-1\right)}{\frac{1}{x} + -1}} \]
      8. metadata-eval100.0%

        \[\leadsto \frac{\frac{x}{y} + 1}{\frac{{x}^{-2} + \color{blue}{-1}}{\frac{1}{x} + -1}} \]
    5. Applied egg-rr100.0%

      \[\leadsto \frac{\frac{x}{y} + 1}{\color{blue}{\frac{{x}^{-2} + -1}{\frac{1}{x} + -1}}} \]
    6. Taylor expanded in y around inf 26.3%

      \[\leadsto \color{blue}{\frac{\frac{1}{x} - 1}{\frac{1}{{x}^{2}} - 1}} \]
    7. Taylor expanded in x around inf 26.3%

      \[\leadsto \color{blue}{1} \]

    if -2e9 < x < 4.8e52

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification50.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2000000000:\\ \;\;\;\;1\\ \mathbf{elif}\;x \leq 4.8 \cdot 10^{+52}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]

Alternative 9: 14.2% accurate, 11.0× speedup?

\[\begin{array}{l} \\ 1 \end{array} \]
(FPCore (x y) :precision binary64 1.0)
double code(double x, double y) {
	return 1.0;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = 1.0d0
end function
public static double code(double x, double y) {
	return 1.0;
}
def code(x, y):
	return 1.0
function code(x, y)
	return 1.0
end
function tmp = code(x, y)
	tmp = 1.0;
end
code[x_, y_] := 1.0
\begin{array}{l}

\\
1
\end{array}
Derivation
  1. Initial program 86.5%

    \[\frac{x \cdot \left(\frac{x}{y} + 1\right)}{x + 1} \]
  2. Step-by-step derivation
    1. *-commutative86.5%

      \[\leadsto \frac{\color{blue}{\left(\frac{x}{y} + 1\right) \cdot x}}{x + 1} \]
    2. associate-/l*99.8%

      \[\leadsto \color{blue}{\frac{\frac{x}{y} + 1}{\frac{x + 1}{x}}} \]
    3. +-commutative99.8%

      \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{1 + x}}{x}} \]
    4. remove-double-neg99.8%

      \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1 + \color{blue}{\left(-\left(-x\right)\right)}}{x}} \]
    5. unsub-neg99.8%

      \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{1 - \left(-x\right)}}{x}} \]
    6. div-sub99.8%

      \[\leadsto \frac{\frac{x}{y} + 1}{\color{blue}{\frac{1}{x} - \frac{-x}{x}}} \]
    7. distribute-frac-neg99.8%

      \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \color{blue}{\left(-\frac{x}{x}\right)}} \]
    8. *-inverses99.8%

      \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \left(-\color{blue}{1}\right)} \]
    9. metadata-eval99.8%

      \[\leadsto \frac{\frac{x}{y} + 1}{\frac{1}{x} - \color{blue}{-1}} \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{\frac{\frac{x}{y} + 1}{\frac{1}{x} - -1}} \]
  4. Step-by-step derivation
    1. flip--76.2%

      \[\leadsto \frac{\frac{x}{y} + 1}{\color{blue}{\frac{\frac{1}{x} \cdot \frac{1}{x} - -1 \cdot -1}{\frac{1}{x} + -1}}} \]
    2. metadata-eval76.2%

      \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\frac{1}{x} \cdot \frac{1}{x} - \color{blue}{1}}{\frac{1}{x} + -1}} \]
    3. sub-neg76.2%

      \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{\frac{1}{x} \cdot \frac{1}{x} + \left(-1\right)}}{\frac{1}{x} + -1}} \]
    4. inv-pow76.2%

      \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{{x}^{-1}} \cdot \frac{1}{x} + \left(-1\right)}{\frac{1}{x} + -1}} \]
    5. inv-pow76.2%

      \[\leadsto \frac{\frac{x}{y} + 1}{\frac{{x}^{-1} \cdot \color{blue}{{x}^{-1}} + \left(-1\right)}{\frac{1}{x} + -1}} \]
    6. pow-prod-up76.1%

      \[\leadsto \frac{\frac{x}{y} + 1}{\frac{\color{blue}{{x}^{\left(-1 + -1\right)}} + \left(-1\right)}{\frac{1}{x} + -1}} \]
    7. metadata-eval76.1%

      \[\leadsto \frac{\frac{x}{y} + 1}{\frac{{x}^{\color{blue}{-2}} + \left(-1\right)}{\frac{1}{x} + -1}} \]
    8. metadata-eval76.1%

      \[\leadsto \frac{\frac{x}{y} + 1}{\frac{{x}^{-2} + \color{blue}{-1}}{\frac{1}{x} + -1}} \]
  5. Applied egg-rr76.1%

    \[\leadsto \frac{\frac{x}{y} + 1}{\color{blue}{\frac{{x}^{-2} + -1}{\frac{1}{x} + -1}}} \]
  6. Taylor expanded in y around inf 31.4%

    \[\leadsto \color{blue}{\frac{\frac{1}{x} - 1}{\frac{1}{{x}^{2}} - 1}} \]
  7. Taylor expanded in x around inf 14.4%

    \[\leadsto \color{blue}{1} \]
  8. Final simplification14.4%

    \[\leadsto 1 \]

Developer target: 99.9% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \frac{x}{1} \cdot \frac{\frac{x}{y} + 1}{x + 1} \end{array} \]
(FPCore (x y) :precision binary64 (* (/ x 1.0) (/ (+ (/ x y) 1.0) (+ x 1.0))))
double code(double x, double y) {
	return (x / 1.0) * (((x / y) + 1.0) / (x + 1.0));
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (x / 1.0d0) * (((x / y) + 1.0d0) / (x + 1.0d0))
end function
public static double code(double x, double y) {
	return (x / 1.0) * (((x / y) + 1.0) / (x + 1.0));
}
def code(x, y):
	return (x / 1.0) * (((x / y) + 1.0) / (x + 1.0))
function code(x, y)
	return Float64(Float64(x / 1.0) * Float64(Float64(Float64(x / y) + 1.0) / Float64(x + 1.0)))
end
function tmp = code(x, y)
	tmp = (x / 1.0) * (((x / y) + 1.0) / (x + 1.0));
end
code[x_, y_] := N[(N[(x / 1.0), $MachinePrecision] * N[(N[(N[(x / y), $MachinePrecision] + 1.0), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x}{1} \cdot \frac{\frac{x}{y} + 1}{x + 1}
\end{array}

Reproduce

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