Average Error: 7.5 → 0.2
Time: 7.7s
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 := \mathsf{fma}\left(\frac{y}{x + 1}, \frac{z}{t_1}, \frac{x - \frac{x}{t_1}}{x + 1}\right)\\ t_3 := \frac{x + \frac{y \cdot z - x}{t_1}}{x + 1}\\ t_4 := x + \frac{y}{t}\\ \mathbf{if}\;t_3 \leq -0.0021035457814129388:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_3 \leq 2.881325035097028 \cdot 10^{-114}:\\ \;\;\;\;\frac{t_4 - \frac{x}{z \cdot t}}{x + 1}\\ \mathbf{elif}\;t_3 \leq \infty:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{t_4}{x + 1}\\ \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 (fma (/ y (+ x 1.0)) (/ z t_1) (/ (- x (/ x t_1)) (+ x 1.0))))
        (t_3 (/ (+ x (/ (- (* y z) x) t_1)) (+ x 1.0)))
        (t_4 (+ x (/ y t))))
   (if (<= t_3 -0.0021035457814129388)
     t_2
     (if (<= t_3 2.881325035097028e-114)
       (/ (- t_4 (/ x (* z t))) (+ x 1.0))
       (if (<= t_3 INFINITY) t_2 (/ t_4 (+ x 1.0)))))))
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 = fma((y / (x + 1.0)), (z / t_1), ((x - (x / t_1)) / (x + 1.0)));
	double t_3 = (x + (((y * z) - x) / t_1)) / (x + 1.0);
	double t_4 = x + (y / t);
	double tmp;
	if (t_3 <= -0.0021035457814129388) {
		tmp = t_2;
	} else if (t_3 <= 2.881325035097028e-114) {
		tmp = (t_4 - (x / (z * t))) / (x + 1.0);
	} else if (t_3 <= ((double) INFINITY)) {
		tmp = t_2;
	} else {
		tmp = t_4 / (x + 1.0);
	}
	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 = fma(Float64(y / Float64(x + 1.0)), Float64(z / t_1), Float64(Float64(x - Float64(x / t_1)) / Float64(x + 1.0)))
	t_3 = Float64(Float64(x + Float64(Float64(Float64(y * z) - x) / t_1)) / Float64(x + 1.0))
	t_4 = Float64(x + Float64(y / t))
	tmp = 0.0
	if (t_3 <= -0.0021035457814129388)
		tmp = t_2;
	elseif (t_3 <= 2.881325035097028e-114)
		tmp = Float64(Float64(t_4 - Float64(x / Float64(z * t))) / Float64(x + 1.0));
	elseif (t_3 <= Inf)
		tmp = t_2;
	else
		tmp = Float64(t_4 / Float64(x + 1.0));
	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[(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]}, Block[{t$95$3 = N[(N[(x + N[(N[(N[(y * z), $MachinePrecision] - x), $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(x + N[(y / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -0.0021035457814129388], t$95$2, If[LessEqual[t$95$3, 2.881325035097028e-114], N[(N[(t$95$4 - N[(x / N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, Infinity], t$95$2, N[(t$95$4 / N[(x + 1.0), $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 := \mathsf{fma}\left(\frac{y}{x + 1}, \frac{z}{t_1}, \frac{x - \frac{x}{t_1}}{x + 1}\right)\\
t_3 := \frac{x + \frac{y \cdot z - x}{t_1}}{x + 1}\\
t_4 := x + \frac{y}{t}\\
\mathbf{if}\;t_3 \leq -0.0021035457814129388:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_3 \leq 2.881325035097028 \cdot 10^{-114}:\\
\;\;\;\;\frac{t_4 - \frac{x}{z \cdot t}}{x + 1}\\

\mathbf{elif}\;t_3 \leq \infty:\\
\;\;\;\;t_2\\

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


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

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

Derivation

  1. Split input into 3 regimes
  2. if (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x 1)) < -0.0021035457814129388 or 2.88132503509702808e-114 < (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x 1)) < +inf.0

    1. Initial program 5.1

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

      \[\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.1

      \[\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 -0.0021035457814129388 < (/.f64 (+.f64 x (/.f64 (-.f64 (*.f64 y z) x) (-.f64 (*.f64 t z) x))) (+.f64 x 1)) < 2.88132503509702808e-114

    1. Initial program 3.8

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

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

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

    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. Applied egg-rr64.0

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

      \[\leadsto \color{blue}{\frac{\frac{y}{t} + x}{1 + x}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x + \frac{y \cdot z - x}{z \cdot t - x}}{x + 1} \leq -0.0021035457814129388:\\ \;\;\;\;\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{elif}\;\frac{x + \frac{y \cdot z - x}{z \cdot t - x}}{x + 1} \leq 2.881325035097028 \cdot 10^{-114}:\\ \;\;\;\;\frac{\left(x + \frac{y}{t}\right) - \frac{x}{z \cdot t}}{x + 1}\\ \mathbf{elif}\;\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}:\\ \;\;\;\;\frac{x + \frac{y}{t}}{x + 1}\\ \end{array} \]

Reproduce

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