Average Error: 7.2 → 1.5
Time: 10.4s
Precision: binary64
\[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
\[\begin{array}{l} \mathbf{if}\;t \leq -2.0677804913452024 \cdot 10^{+84}:\\ \;\;\;\;\begin{array}{l} t_1 := t \cdot \left(x + 1\right)\\ \left(\frac{x}{x + 1} + \frac{y}{t_1}\right) - \frac{x}{t_1 \cdot z} \end{array}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_2 := \frac{y}{x + 1}\\ t_3 := t \cdot z - x\\ t_4 := \frac{x - \frac{x}{t_3}}{x + 1}\\ \mathbf{if}\;t \leq 3.633970818777441 \cdot 10^{+41}:\\ \;\;\;\;t_2 \cdot \frac{z}{t_3} + t_4\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(t_2, \frac{1}{t}, t_4\right)\\ \end{array}\\ \end{array} \]
\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1}
\begin{array}{l}
\mathbf{if}\;t \leq -2.0677804913452024 \cdot 10^{+84}:\\
\;\;\;\;\begin{array}{l}
t_1 := t \cdot \left(x + 1\right)\\
\left(\frac{x}{x + 1} + \frac{y}{t_1}\right) - \frac{x}{t_1 \cdot z}
\end{array}\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_2 := \frac{y}{x + 1}\\
t_3 := t \cdot z - x\\
t_4 := \frac{x - \frac{x}{t_3}}{x + 1}\\
\mathbf{if}\;t \leq 3.633970818777441 \cdot 10^{+41}:\\
\;\;\;\;t_2 \cdot \frac{z}{t_3} + t_4\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t_2, \frac{1}{t}, t_4\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
 (if (<= t -2.0677804913452024e+84)
   (let* ((t_1 (* t (+ x 1.0))))
     (- (+ (/ x (+ x 1.0)) (/ y t_1)) (/ x (* t_1 z))))
   (let* ((t_2 (/ y (+ x 1.0)))
          (t_3 (- (* t z) x))
          (t_4 (/ (- x (/ x t_3)) (+ x 1.0))))
     (if (<= t 3.633970818777441e+41)
       (+ (* t_2 (/ z t_3)) t_4)
       (fma t_2 (/ 1.0 t) t_4)))))
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 tmp;
	if (t <= -2.0677804913452024e+84) {
		double t_1_1 = t * (x + 1.0);
		tmp = ((x / (x + 1.0)) + (y / t_1_1)) - (x / (t_1_1 * z));
	} else {
		double t_2 = y / (x + 1.0);
		double t_3 = (t * z) - x;
		double t_4 = (x - (x / t_3)) / (x + 1.0);
		double tmp_2;
		if (t <= 3.633970818777441e+41) {
			tmp_2 = (t_2 * (z / t_3)) + t_4;
		} else {
			tmp_2 = fma(t_2, (1.0 / t), t_4);
		}
		tmp = tmp_2;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original7.2
Target0.3
Herbie1.5
\[\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 t < -2.06778049134520244e84

    1. Initial program 9.0

      \[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
    2. Taylor expanded in y around 0 9.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. Simplified4.5

      \[\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 8.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. Simplified4.8

      \[\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)}} \]

    if -2.06778049134520244e84 < t < 3.6339708187774408e41

    1. Initial program 5.9

      \[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
    2. Taylor expanded in y around 0 5.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.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. Applied fma-udef_binary640.3

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

    if 3.6339708187774408e41 < t

    1. Initial program 8.9

      \[\frac{x + \frac{y \cdot z - x}{t \cdot z - x}}{x + 1} \]
    2. Taylor expanded in y around 0 8.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. Simplified4.4

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

      \[\leadsto \mathsf{fma}\left(\frac{y}{x + 1}, \color{blue}{\frac{1}{t}}, \frac{x - \frac{x}{t \cdot z - x}}{x + 1}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.5

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

Reproduce

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