Average Error: 7.2 → 0.7
Time: 12.3s
Precision: binary64
\[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
\[\begin{array}{l} t_1 := z \cdot t - x\\ t_2 := t \cdot \left(x + 1\right)\\ \mathbf{if}\;\frac{x + \frac{y \cdot z - x}{t_1}}{x + 1} \leq \infty:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{x + 1}, \frac{z}{t_1}, \frac{x - \frac{x}{t_1}}{x + 1}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{x}{x + 1} + \frac{y}{t_2}\right) - \frac{x}{z \cdot t_2}\\ \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (/ (+ x (/ (- (* y z) x) (- (* t z) x))) (+ x 1.0)))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (- (* z t) x)) (t_2 (* t (+ x 1.0))))
   (if (<= (/ (+ x (/ (- (* y z) x) t_1)) (+ x 1.0)) INFINITY)
     (fma (/ y (+ x 1.0)) (/ z t_1) (/ (- x (/ x t_1)) (+ x 1.0)))
     (- (+ (/ x (+ x 1.0)) (/ y t_2)) (/ x (* z t_2))))))
double code(double x, double y, double z, double t) {
	return (x + (((y * z) - x) / ((t * z) - x))) / (x + 1.0);
}
double code(double x, double y, double z, double t) {
	double t_1 = (z * t) - x;
	double t_2 = t * (x + 1.0);
	double tmp;
	if (((x + (((y * z) - x) / t_1)) / (x + 1.0)) <= ((double) INFINITY)) {
		tmp = fma((y / (x + 1.0)), (z / t_1), ((x - (x / t_1)) / (x + 1.0)));
	} else {
		tmp = ((x / (x + 1.0)) + (y / t_2)) - (x / (z * t_2));
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(Float64(x + Float64(Float64(Float64(y * z) - x) / Float64(Float64(t * z) - x))) / Float64(x + 1.0))
end
function code(x, y, z, t)
	t_1 = Float64(Float64(z * t) - x)
	t_2 = Float64(t * Float64(x + 1.0))
	tmp = 0.0
	if (Float64(Float64(x + Float64(Float64(Float64(y * z) - x) / t_1)) / Float64(x + 1.0)) <= Inf)
		tmp = fma(Float64(y / Float64(x + 1.0)), Float64(z / t_1), Float64(Float64(x - Float64(x / t_1)) / Float64(x + 1.0)));
	else
		tmp = Float64(Float64(Float64(x / Float64(x + 1.0)) + Float64(y / t_2)) - Float64(x / Float64(z * t_2)));
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(N[(x + N[(N[(N[(y * z), $MachinePrecision] - x), $MachinePrecision] / N[(N[(t * z), $MachinePrecision] - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(z * t), $MachinePrecision] - x), $MachinePrecision]}, Block[{t$95$2 = N[(t * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(x + N[(N[(N[(y * z), $MachinePrecision] - x), $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(y / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] * N[(z / t$95$1), $MachinePrecision] + N[(N[(x - N[(x / t$95$1), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x / N[(x + 1.0), $MachinePrecision]), $MachinePrecision] + N[(y / t$95$2), $MachinePrecision]), $MachinePrecision] - N[(x / N[(z * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1}
\begin{array}{l}
t_1 := z \cdot t - x\\
t_2 := t \cdot \left(x + 1\right)\\
\mathbf{if}\;\frac{x + \frac{y \cdot z - x}{t_1}}{x + 1} \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{x + 1}, \frac{z}{t_1}, \frac{x - \frac{x}{t_1}}{x + 1}\right)\\

\mathbf{else}:\\
\;\;\;\;\left(\frac{x}{x + 1} + \frac{y}{t_2}\right) - \frac{x}{z \cdot t_2}\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original7.2
Target0.3
Herbie0.7
\[\frac{x + \left(\frac{y}{t - \frac{x}{z}} - \frac{x}{t \cdot z - x}\right)}{x + 1} \]

Derivation

  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x 1)) < +inf.0

    1. Initial program 4.8

      \[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
    2. Taylor expanded in y around 0 4.9

      \[\leadsto \color{blue}{\left(\frac{y \cdot z}{\left(1 + x\right) \cdot \left(t \cdot z - x\right)} + \frac{x}{1 + x}\right) - \frac{x}{\left(1 + x\right) \cdot \left(t \cdot z - x\right)}} \]
    3. Simplified0.7

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

    if +inf.0 < (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x 1))

    1. Initial program 64.0

      \[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
    2. Taylor expanded in y around 0 64.0

      \[\leadsto \color{blue}{\left(\frac{y \cdot z}{\left(1 + x\right) \cdot \left(t \cdot z - x\right)} + \frac{x}{1 + x}\right) - \frac{x}{\left(1 + x\right) \cdot \left(t \cdot z - x\right)}} \]
    3. Simplified33.3

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

      \[\leadsto \color{blue}{\left(\frac{x}{1 + x} + \frac{y}{\left(1 + x\right) \cdot t}\right) - \frac{x}{\left(1 + x\right) \cdot \left(t \cdot z\right)}} \]
    5. Simplified0.0

      \[\leadsto \color{blue}{\left(\frac{x}{x + 1} + \frac{y}{t \cdot \left(x + 1\right)}\right) - \frac{x}{z \cdot \left(t \cdot \left(x + 1\right)\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x + \frac{y \cdot z - x}{z \cdot t - x}}{x + 1} \leq \infty:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{x + 1}, \frac{z}{z \cdot t - x}, \frac{x - \frac{x}{z \cdot t - x}}{x + 1}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{x}{x + 1} + \frac{y}{t \cdot \left(x + 1\right)}\right) - \frac{x}{z \cdot \left(t \cdot \left(x + 1\right)\right)}\\ \end{array} \]

Reproduce

herbie shell --seed 2022130 
(FPCore (x y z t)
  :name "Diagrams.Trail:splitAtParam  from diagrams-lib-1.3.0.3, A"
  :precision binary64

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

  (/ (+ x (/ (- (* y z) x) (- (* t z) x))) (+ x 1.0)))