Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, D

Percentage Accurate: 65.4% → 98.7%
Time: 9.6s
Alternatives: 13
Speedup: 2.0×

Specification

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

\\
1 - \frac{\left(1 - x\right) \cdot y}{y + 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 13 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: 65.4% accurate, 1.0× speedup?

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

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

Alternative 1: 98.7% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{y}{1 + y}\\ t_1 := \frac{\left(1 - x\right) \cdot y}{1 + y}\\ t_2 := \left(1 - x\right) \cdot \left(-1 + \frac{1}{y}\right)\\ \mathbf{if}\;t\_1 \leq 0.0001:\\ \;\;\;\;\mathsf{fma}\left(x, \left(1 + \frac{-1}{x}\right) \cdot t\_0, 1\right)\\ \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+17}:\\ \;\;\;\;x + \frac{\frac{\frac{t\_2 \cdot t\_2}{y \cdot y} + \left(1 - x\right) \cdot \left(x + -1\right)}{\mathsf{fma}\left(\frac{x + -1}{y}, 1 + \frac{-1}{y}, x + -1\right)}}{y}\\ \mathbf{else}:\\ \;\;\;\;x \cdot t\_0\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (/ y (+ 1.0 y)))
        (t_1 (/ (* (- 1.0 x) y) (+ 1.0 y)))
        (t_2 (* (- 1.0 x) (+ -1.0 (/ 1.0 y)))))
   (if (<= t_1 0.0001)
     (fma x (* (+ 1.0 (/ -1.0 x)) t_0) 1.0)
     (if (<= t_1 2e+17)
       (+
        x
        (/
         (/
          (+ (/ (* t_2 t_2) (* y y)) (* (- 1.0 x) (+ x -1.0)))
          (fma (/ (+ x -1.0) y) (+ 1.0 (/ -1.0 y)) (+ x -1.0)))
         y))
       (* x t_0)))))
double code(double x, double y) {
	double t_0 = y / (1.0 + y);
	double t_1 = ((1.0 - x) * y) / (1.0 + y);
	double t_2 = (1.0 - x) * (-1.0 + (1.0 / y));
	double tmp;
	if (t_1 <= 0.0001) {
		tmp = fma(x, ((1.0 + (-1.0 / x)) * t_0), 1.0);
	} else if (t_1 <= 2e+17) {
		tmp = x + (((((t_2 * t_2) / (y * y)) + ((1.0 - x) * (x + -1.0))) / fma(((x + -1.0) / y), (1.0 + (-1.0 / y)), (x + -1.0))) / y);
	} else {
		tmp = x * t_0;
	}
	return tmp;
}
function code(x, y)
	t_0 = Float64(y / Float64(1.0 + y))
	t_1 = Float64(Float64(Float64(1.0 - x) * y) / Float64(1.0 + y))
	t_2 = Float64(Float64(1.0 - x) * Float64(-1.0 + Float64(1.0 / y)))
	tmp = 0.0
	if (t_1 <= 0.0001)
		tmp = fma(x, Float64(Float64(1.0 + Float64(-1.0 / x)) * t_0), 1.0);
	elseif (t_1 <= 2e+17)
		tmp = Float64(x + Float64(Float64(Float64(Float64(Float64(t_2 * t_2) / Float64(y * y)) + Float64(Float64(1.0 - x) * Float64(x + -1.0))) / fma(Float64(Float64(x + -1.0) / y), Float64(1.0 + Float64(-1.0 / y)), Float64(x + -1.0))) / y));
	else
		tmp = Float64(x * t_0);
	end
	return tmp
end
code[x_, y_] := Block[{t$95$0 = N[(y / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(1.0 - x), $MachinePrecision] * N[(-1.0 + N[(1.0 / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 0.0001], N[(x * N[(N[(1.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[t$95$1, 2e+17], N[(x + N[(N[(N[(N[(N[(t$95$2 * t$95$2), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 - x), $MachinePrecision] * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision] * N[(1.0 + N[(-1.0 / y), $MachinePrecision]), $MachinePrecision] + N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x * t$95$0), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{y}{1 + y}\\
t_1 := \frac{\left(1 - x\right) \cdot y}{1 + y}\\
t_2 := \left(1 - x\right) \cdot \left(-1 + \frac{1}{y}\right)\\
\mathbf{if}\;t\_1 \leq 0.0001:\\
\;\;\;\;\mathsf{fma}\left(x, \left(1 + \frac{-1}{x}\right) \cdot t\_0, 1\right)\\

\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+17}:\\
\;\;\;\;x + \frac{\frac{\frac{t\_2 \cdot t\_2}{y \cdot y} + \left(1 - x\right) \cdot \left(x + -1\right)}{\mathsf{fma}\left(\frac{x + -1}{y}, 1 + \frac{-1}{y}, x + -1\right)}}{y}\\

\mathbf{else}:\\
\;\;\;\;x \cdot t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 (-.f64 #s(literal 1 binary64) x) y) (+.f64 y #s(literal 1 binary64))) < 1.00000000000000005e-4

    1. Initial program 89.7%

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

      \[\leadsto \color{blue}{1} \]
    4. Step-by-step derivation
      1. Applied rewrites68.9%

        \[\leadsto \color{blue}{1} \]
      2. Taylor expanded in x around inf

        \[\leadsto \color{blue}{x \cdot \left(\frac{1}{x} - \left(-1 \cdot \frac{y}{1 + y} + \frac{y}{x \cdot \left(1 + y\right)}\right)\right)} \]
      3. Step-by-step derivation
        1. sub-negN/A

          \[\leadsto x \cdot \color{blue}{\left(\frac{1}{x} + \left(\mathsf{neg}\left(\left(-1 \cdot \frac{y}{1 + y} + \frac{y}{x \cdot \left(1 + y\right)}\right)\right)\right)\right)} \]
        2. +-commutativeN/A

          \[\leadsto x \cdot \color{blue}{\left(\left(\mathsf{neg}\left(\left(-1 \cdot \frac{y}{1 + y} + \frac{y}{x \cdot \left(1 + y\right)}\right)\right)\right) + \frac{1}{x}\right)} \]
        3. distribute-lft-inN/A

          \[\leadsto \color{blue}{x \cdot \left(\mathsf{neg}\left(\left(-1 \cdot \frac{y}{1 + y} + \frac{y}{x \cdot \left(1 + y\right)}\right)\right)\right) + x \cdot \frac{1}{x}} \]
        4. rgt-mult-inverseN/A

          \[\leadsto x \cdot \left(\mathsf{neg}\left(\left(-1 \cdot \frac{y}{1 + y} + \frac{y}{x \cdot \left(1 + y\right)}\right)\right)\right) + \color{blue}{1} \]
        5. lower-fma.f64N/A

          \[\leadsto \color{blue}{\mathsf{fma}\left(x, \mathsf{neg}\left(\left(-1 \cdot \frac{y}{1 + y} + \frac{y}{x \cdot \left(1 + y\right)}\right)\right), 1\right)} \]
      4. Applied rewrites100.0%

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

      if 1.00000000000000005e-4 < (/.f64 (*.f64 (-.f64 #s(literal 1 binary64) x) y) (+.f64 y #s(literal 1 binary64))) < 2e17

      1. Initial program 18.1%

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

        \[\leadsto \color{blue}{1} \]
      4. Step-by-step derivation
        1. Applied rewrites4.7%

          \[\leadsto \color{blue}{1} \]
        2. Taylor expanded in x around inf

          \[\leadsto \color{blue}{x \cdot \left(\frac{1}{x} - \left(-1 \cdot \frac{y}{1 + y} + \frac{y}{x \cdot \left(1 + y\right)}\right)\right)} \]
        3. Step-by-step derivation
          1. sub-negN/A

            \[\leadsto x \cdot \color{blue}{\left(\frac{1}{x} + \left(\mathsf{neg}\left(\left(-1 \cdot \frac{y}{1 + y} + \frac{y}{x \cdot \left(1 + y\right)}\right)\right)\right)\right)} \]
          2. +-commutativeN/A

            \[\leadsto x \cdot \color{blue}{\left(\left(\mathsf{neg}\left(\left(-1 \cdot \frac{y}{1 + y} + \frac{y}{x \cdot \left(1 + y\right)}\right)\right)\right) + \frac{1}{x}\right)} \]
          3. distribute-lft-inN/A

            \[\leadsto \color{blue}{x \cdot \left(\mathsf{neg}\left(\left(-1 \cdot \frac{y}{1 + y} + \frac{y}{x \cdot \left(1 + y\right)}\right)\right)\right) + x \cdot \frac{1}{x}} \]
          4. rgt-mult-inverseN/A

            \[\leadsto x \cdot \left(\mathsf{neg}\left(\left(-1 \cdot \frac{y}{1 + y} + \frac{y}{x \cdot \left(1 + y\right)}\right)\right)\right) + \color{blue}{1} \]
          5. lower-fma.f64N/A

            \[\leadsto \color{blue}{\mathsf{fma}\left(x, \mathsf{neg}\left(\left(-1 \cdot \frac{y}{1 + y} + \frac{y}{x \cdot \left(1 + y\right)}\right)\right), 1\right)} \]
        4. Applied rewrites17.9%

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

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

          \[\leadsto \color{blue}{x + \frac{\mathsf{fma}\left(\frac{-1 + x}{y}, \frac{-1}{y} - -1, 1 - x\right)}{y}} \]
        7. Step-by-step derivation
          1. Applied rewrites99.8%

            \[\leadsto x + \frac{\frac{\frac{\left(\left(x + -1\right) \cdot \left(\frac{-1}{y} + 1\right)\right) \cdot \left(\left(x + -1\right) \cdot \left(\frac{-1}{y} + 1\right)\right)}{y \cdot y} - \left(x + -1\right) \cdot \left(x + -1\right)}{\mathsf{fma}\left(\frac{x + -1}{y}, \frac{-1}{y} + 1, -\left(1 - x\right)\right)}}{y} \]

          if 2e17 < (/.f64 (*.f64 (-.f64 #s(literal 1 binary64) x) y) (+.f64 y #s(literal 1 binary64)))

          1. Initial program 75.8%

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

            \[\leadsto \color{blue}{\frac{x \cdot y}{1 + y}} \]
          4. Step-by-step derivation
            1. *-commutativeN/A

              \[\leadsto \frac{\color{blue}{y \cdot x}}{1 + y} \]
            2. associate-*l/N/A

              \[\leadsto \color{blue}{\frac{y}{1 + y} \cdot x} \]
            3. lower-*.f64N/A

              \[\leadsto \color{blue}{\frac{y}{1 + y} \cdot x} \]
            4. lower-/.f64N/A

              \[\leadsto \color{blue}{\frac{y}{1 + y}} \cdot x \]
            5. lower-+.f64100.0

              \[\leadsto \frac{y}{\color{blue}{1 + y}} \cdot x \]
          5. Applied rewrites100.0%

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

          \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(1 - x\right) \cdot y}{1 + y} \leq 0.0001:\\ \;\;\;\;\mathsf{fma}\left(x, \left(1 + \frac{-1}{x}\right) \cdot \frac{y}{1 + y}, 1\right)\\ \mathbf{elif}\;\frac{\left(1 - x\right) \cdot y}{1 + y} \leq 2 \cdot 10^{+17}:\\ \;\;\;\;x + \frac{\frac{\frac{\left(\left(1 - x\right) \cdot \left(-1 + \frac{1}{y}\right)\right) \cdot \left(\left(1 - x\right) \cdot \left(-1 + \frac{1}{y}\right)\right)}{y \cdot y} + \left(1 - x\right) \cdot \left(x + -1\right)}{\mathsf{fma}\left(\frac{x + -1}{y}, 1 + \frac{-1}{y}, x + -1\right)}}{y}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y}{1 + y}\\ \end{array} \]
        10. Add Preprocessing

        Alternative 2: 98.7% accurate, 0.2× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{y}{1 + y}\\ t_1 := \frac{\left(1 - x\right) \cdot y}{1 + y}\\ \mathbf{if}\;t\_1 \leq 0.0001:\\ \;\;\;\;\mathsf{fma}\left(x, \left(1 + \frac{-1}{x}\right) \cdot t\_0, 1\right)\\ \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+17}:\\ \;\;\;\;x + \frac{1 - \mathsf{fma}\left(\frac{x + -1}{y}, -1 + \frac{1}{y}, x\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;x \cdot t\_0\\ \end{array} \end{array} \]
        (FPCore (x y)
         :precision binary64
         (let* ((t_0 (/ y (+ 1.0 y))) (t_1 (/ (* (- 1.0 x) y) (+ 1.0 y))))
           (if (<= t_1 0.0001)
             (fma x (* (+ 1.0 (/ -1.0 x)) t_0) 1.0)
             (if (<= t_1 2e+17)
               (+ x (/ (- 1.0 (fma (/ (+ x -1.0) y) (+ -1.0 (/ 1.0 y)) x)) y))
               (* x t_0)))))
        double code(double x, double y) {
        	double t_0 = y / (1.0 + y);
        	double t_1 = ((1.0 - x) * y) / (1.0 + y);
        	double tmp;
        	if (t_1 <= 0.0001) {
        		tmp = fma(x, ((1.0 + (-1.0 / x)) * t_0), 1.0);
        	} else if (t_1 <= 2e+17) {
        		tmp = x + ((1.0 - fma(((x + -1.0) / y), (-1.0 + (1.0 / y)), x)) / y);
        	} else {
        		tmp = x * t_0;
        	}
        	return tmp;
        }
        
        function code(x, y)
        	t_0 = Float64(y / Float64(1.0 + y))
        	t_1 = Float64(Float64(Float64(1.0 - x) * y) / Float64(1.0 + y))
        	tmp = 0.0
        	if (t_1 <= 0.0001)
        		tmp = fma(x, Float64(Float64(1.0 + Float64(-1.0 / x)) * t_0), 1.0);
        	elseif (t_1 <= 2e+17)
        		tmp = Float64(x + Float64(Float64(1.0 - fma(Float64(Float64(x + -1.0) / y), Float64(-1.0 + Float64(1.0 / y)), x)) / y));
        	else
        		tmp = Float64(x * t_0);
        	end
        	return tmp
        end
        
        code[x_, y_] := Block[{t$95$0 = N[(y / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] / N[(1.0 + y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 0.0001], N[(x * N[(N[(1.0 + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[t$95$1, 2e+17], N[(x + N[(N[(1.0 - N[(N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision] * N[(-1.0 + N[(1.0 / y), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x * t$95$0), $MachinePrecision]]]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_0 := \frac{y}{1 + y}\\
        t_1 := \frac{\left(1 - x\right) \cdot y}{1 + y}\\
        \mathbf{if}\;t\_1 \leq 0.0001:\\
        \;\;\;\;\mathsf{fma}\left(x, \left(1 + \frac{-1}{x}\right) \cdot t\_0, 1\right)\\
        
        \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+17}:\\
        \;\;\;\;x + \frac{1 - \mathsf{fma}\left(\frac{x + -1}{y}, -1 + \frac{1}{y}, x\right)}{y}\\
        
        \mathbf{else}:\\
        \;\;\;\;x \cdot t\_0\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if (/.f64 (*.f64 (-.f64 #s(literal 1 binary64) x) y) (+.f64 y #s(literal 1 binary64))) < 1.00000000000000005e-4

          1. Initial program 88.5%

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

            \[\leadsto \color{blue}{1} \]
          4. Step-by-step derivation
            1. Applied rewrites65.2%

              \[\leadsto \color{blue}{1} \]
            2. Taylor expanded in x around inf

              \[\leadsto \color{blue}{x \cdot \left(\frac{1}{x} - \left(-1 \cdot \frac{y}{1 + y} + \frac{y}{x \cdot \left(1 + y\right)}\right)\right)} \]
            3. Step-by-step derivation
              1. sub-negN/A

                \[\leadsto x \cdot \color{blue}{\left(\frac{1}{x} + \left(\mathsf{neg}\left(\left(-1 \cdot \frac{y}{1 + y} + \frac{y}{x \cdot \left(1 + y\right)}\right)\right)\right)\right)} \]
              2. +-commutativeN/A

                \[\leadsto x \cdot \color{blue}{\left(\left(\mathsf{neg}\left(\left(-1 \cdot \frac{y}{1 + y} + \frac{y}{x \cdot \left(1 + y\right)}\right)\right)\right) + \frac{1}{x}\right)} \]
              3. distribute-lft-inN/A

                \[\leadsto \color{blue}{x \cdot \left(\mathsf{neg}\left(\left(-1 \cdot \frac{y}{1 + y} + \frac{y}{x \cdot \left(1 + y\right)}\right)\right)\right) + x \cdot \frac{1}{x}} \]
              4. rgt-mult-inverseN/A

                \[\leadsto x \cdot \left(\mathsf{neg}\left(\left(-1 \cdot \frac{y}{1 + y} + \frac{y}{x \cdot \left(1 + y\right)}\right)\right)\right) + \color{blue}{1} \]
              5. lower-fma.f64N/A

                \[\leadsto \color{blue}{\mathsf{fma}\left(x, \mathsf{neg}\left(\left(-1 \cdot \frac{y}{1 + y} + \frac{y}{x \cdot \left(1 + y\right)}\right)\right), 1\right)} \]
            4. Applied rewrites100.0%

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

            if 1.00000000000000005e-4 < (/.f64 (*.f64 (-.f64 #s(literal 1 binary64) x) y) (+.f64 y #s(literal 1 binary64))) < 2e17

            1. Initial program 15.9%

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

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

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

            if 2e17 < (/.f64 (*.f64 (-.f64 #s(literal 1 binary64) x) y) (+.f64 y #s(literal 1 binary64)))

            1. Initial program 67.7%

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

              \[\leadsto \color{blue}{\frac{x \cdot y}{1 + y}} \]
            4. Step-by-step derivation
              1. *-commutativeN/A

                \[\leadsto \frac{\color{blue}{y \cdot x}}{1 + y} \]
              2. associate-*l/N/A

                \[\leadsto \color{blue}{\frac{y}{1 + y} \cdot x} \]
              3. lower-*.f64N/A

                \[\leadsto \color{blue}{\frac{y}{1 + y} \cdot x} \]
              4. lower-/.f64N/A

                \[\leadsto \color{blue}{\frac{y}{1 + y}} \cdot x \]
              5. lower-+.f64100.0

                \[\leadsto \frac{y}{\color{blue}{1 + y}} \cdot x \]
            5. Applied rewrites100.0%

              \[\leadsto \color{blue}{\frac{y}{1 + y} \cdot x} \]
          5. Recombined 3 regimes into one program.
          6. Final simplification98.7%

            \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\left(1 - x\right) \cdot y}{1 + y} \leq 0.0001:\\ \;\;\;\;\mathsf{fma}\left(x, \left(1 + \frac{-1}{x}\right) \cdot \frac{y}{1 + y}, 1\right)\\ \mathbf{elif}\;\frac{\left(1 - x\right) \cdot y}{1 + y} \leq 2 \cdot 10^{+17}:\\ \;\;\;\;x + \frac{1 - \mathsf{fma}\left(\frac{x + -1}{y}, -1 + \frac{1}{y}, x\right)}{y}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y}{1 + y}\\ \end{array} \]
          7. Add Preprocessing

          Developer Target 1: 99.7% accurate, 0.6× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{y} - \left(\frac{x}{y} - x\right)\\ \mathbf{if}\;y < -3693.8482788297247:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;y < 6799310503.41891:\\ \;\;\;\;1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
          (FPCore (x y)
           :precision binary64
           (let* ((t_0 (- (/ 1.0 y) (- (/ x y) x))))
             (if (< y -3693.8482788297247)
               t_0
               (if (< y 6799310503.41891) (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))) t_0))))
          double code(double x, double y) {
          	double t_0 = (1.0 / y) - ((x / y) - x);
          	double tmp;
          	if (y < -3693.8482788297247) {
          		tmp = t_0;
          	} else if (y < 6799310503.41891) {
          		tmp = 1.0 - (((1.0 - x) * y) / (y + 1.0));
          	} else {
          		tmp = 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 = (1.0d0 / y) - ((x / y) - x)
              if (y < (-3693.8482788297247d0)) then
                  tmp = t_0
              else if (y < 6799310503.41891d0) then
                  tmp = 1.0d0 - (((1.0d0 - x) * y) / (y + 1.0d0))
              else
                  tmp = t_0
              end if
              code = tmp
          end function
          
          public static double code(double x, double y) {
          	double t_0 = (1.0 / y) - ((x / y) - x);
          	double tmp;
          	if (y < -3693.8482788297247) {
          		tmp = t_0;
          	} else if (y < 6799310503.41891) {
          		tmp = 1.0 - (((1.0 - x) * y) / (y + 1.0));
          	} else {
          		tmp = t_0;
          	}
          	return tmp;
          }
          
          def code(x, y):
          	t_0 = (1.0 / y) - ((x / y) - x)
          	tmp = 0
          	if y < -3693.8482788297247:
          		tmp = t_0
          	elif y < 6799310503.41891:
          		tmp = 1.0 - (((1.0 - x) * y) / (y + 1.0))
          	else:
          		tmp = t_0
          	return tmp
          
          function code(x, y)
          	t_0 = Float64(Float64(1.0 / y) - Float64(Float64(x / y) - x))
          	tmp = 0.0
          	if (y < -3693.8482788297247)
          		tmp = t_0;
          	elseif (y < 6799310503.41891)
          		tmp = Float64(1.0 - Float64(Float64(Float64(1.0 - x) * y) / Float64(y + 1.0)));
          	else
          		tmp = t_0;
          	end
          	return tmp
          end
          
          function tmp_2 = code(x, y)
          	t_0 = (1.0 / y) - ((x / y) - x);
          	tmp = 0.0;
          	if (y < -3693.8482788297247)
          		tmp = t_0;
          	elseif (y < 6799310503.41891)
          		tmp = 1.0 - (((1.0 - x) * y) / (y + 1.0));
          	else
          		tmp = t_0;
          	end
          	tmp_2 = tmp;
          end
          
          code[x_, y_] := Block[{t$95$0 = N[(N[(1.0 / y), $MachinePrecision] - N[(N[(x / y), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]}, If[Less[y, -3693.8482788297247], t$95$0, If[Less[y, 6799310503.41891], N[(1.0 - N[(N[(N[(1.0 - x), $MachinePrecision] * y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          t_0 := \frac{1}{y} - \left(\frac{x}{y} - x\right)\\
          \mathbf{if}\;y < -3693.8482788297247:\\
          \;\;\;\;t\_0\\
          
          \mathbf{elif}\;y < 6799310503.41891:\\
          \;\;\;\;1 - \frac{\left(1 - x\right) \cdot y}{y + 1}\\
          
          \mathbf{else}:\\
          \;\;\;\;t\_0\\
          
          
          \end{array}
          \end{array}
          

          Reproduce

          ?
          herbie shell --seed 2024228 
          (FPCore (x y)
            :name "Diagrams.Trail:splitAtParam  from diagrams-lib-1.3.0.3, D"
            :precision binary64
          
            :alt
            (! :herbie-platform default (if (< y -36938482788297247/10000000000000) (- (/ 1 y) (- (/ x y) x)) (if (< y 679931050341891/100000) (- 1 (/ (* (- 1 x) y) (+ y 1))) (- (/ 1 y) (- (/ x y) x)))))
          
            (- 1.0 (/ (* (- 1.0 x) y) (+ y 1.0))))