Average Error: 7.2 → 0.7
Time: 7.7s
Precision: binary64
\[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
\[\begin{array}{l} t_1 := \frac{y}{x + 1}\\ t_2 := z \cdot t - x\\ \mathbf{if}\;\frac{x + \frac{y \cdot z - x}{t_2}}{x + 1} \leq \infty:\\ \;\;\;\;\mathsf{fma}\left(t_1, \frac{z}{t_2}, \frac{x - \frac{x}{t_2}}{x + 1}\right)\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_3 := t \cdot \left(x + 1\right)\\ \mathsf{fma}\left(t_1, \frac{x}{t \cdot \left(z \cdot t\right)}, \frac{x}{x + 1}\right) + \left(\frac{y}{t_3} - \frac{x}{z \cdot t_3}\right) \end{array}\\ \end{array} \]
\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1}
\begin{array}{l}
t_1 := \frac{y}{x + 1}\\
t_2 := z \cdot t - x\\
\mathbf{if}\;\frac{x + \frac{y \cdot z - x}{t_2}}{x + 1} \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(t_1, \frac{z}{t_2}, \frac{x - \frac{x}{t_2}}{x + 1}\right)\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_3 := t \cdot \left(x + 1\right)\\
\mathsf{fma}\left(t_1, \frac{x}{t \cdot \left(z \cdot t\right)}, \frac{x}{x + 1}\right) + \left(\frac{y}{t_3} - \frac{x}{z \cdot t_3}\right)
\end{array}\\


\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 (/ y (+ x 1.0))) (t_2 (- (* z t) x)))
   (if (<= (/ (+ x (/ (- (* y z) x) t_2)) (+ x 1.0)) INFINITY)
     (fma t_1 (/ z t_2) (/ (- x (/ x t_2)) (+ x 1.0)))
     (let* ((t_3 (* t (+ x 1.0))))
       (+
        (fma t_1 (/ x (* t (* z t))) (/ x (+ x 1.0)))
        (- (/ y t_3) (/ x (* z t_3))))))))
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 = y / (x + 1.0);
	double t_2 = (z * t) - x;
	double tmp;
	if (((x + (((y * z) - x) / t_2)) / (x + 1.0)) <= ((double) INFINITY)) {
		tmp = fma(t_1, (z / t_2), ((x - (x / t_2)) / (x + 1.0)));
	} else {
		double t_3 = t * (x + 1.0);
		tmp = fma(t_1, (x / (t * (z * t))), (x / (x + 1.0))) + ((y / t_3) - (x / (z * t_3)));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original7.2
Target0.4
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.7

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

      \[\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 z around inf 20.1

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{x + 1}, \frac{x}{t \cdot \left(t \cdot z\right)}, \frac{x}{x + 1}\right) + \left(\frac{y}{t \cdot \left(x + 1\right)} - \frac{x}{z \cdot \left(t \cdot \left(x + 1\right)\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}:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{x + 1}, \frac{x}{t \cdot \left(z \cdot t\right)}, \frac{x}{x + 1}\right) + \left(\frac{y}{t \cdot \left(x + 1\right)} - \frac{x}{z \cdot \left(t \cdot \left(x + 1\right)\right)}\right)\\ \end{array} \]

Reproduce

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