Average Error: 1.9 → 1.7
Time: 9.4s
Precision: binary64
\[x + \left(y - x\right) \cdot \frac{z}{t} \]
\[\begin{array}{l} \mathbf{if}\;\frac{z}{t} \leq -4.620299765818223 \cdot 10^{+242}:\\ \;\;\;\;\mathsf{fma}\left(z, \frac{y}{t} - \frac{x}{t}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_1 := \mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \mathbf{if}\;\frac{z}{t} \leq -1.2829284567762299 \cdot 10^{-64}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{z}{t} \leq 5.322646425016115 \cdot 10^{-141}:\\ \;\;\;\;x + z \cdot \frac{\frac{1}{t}}{\frac{1}{y - x}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array}\\ \end{array} \]
x + \left(y - x\right) \cdot \frac{z}{t}
\begin{array}{l}
\mathbf{if}\;\frac{z}{t} \leq -4.620299765818223 \cdot 10^{+242}:\\
\;\;\;\;\mathsf{fma}\left(z, \frac{y}{t} - \frac{x}{t}, x\right)\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_1 := \mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\
\mathbf{if}\;\frac{z}{t} \leq -1.2829284567762299 \cdot 10^{-64}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\frac{z}{t} \leq 5.322646425016115 \cdot 10^{-141}:\\
\;\;\;\;x + z \cdot \frac{\frac{1}{t}}{\frac{1}{y - x}}\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}\\


\end{array}
(FPCore (x y z t) :precision binary64 (+ x (* (- y x) (/ z t))))
(FPCore (x y z t)
 :precision binary64
 (if (<= (/ z t) -4.620299765818223e+242)
   (fma z (- (/ y t) (/ x t)) x)
   (let* ((t_1 (fma (- y x) (/ z t) x)))
     (if (<= (/ z t) -1.2829284567762299e-64)
       t_1
       (if (<= (/ z t) 5.322646425016115e-141)
         (+ x (* z (/ (/ 1.0 t) (/ 1.0 (- y x)))))
         t_1)))))
double code(double x, double y, double z, double t) {
	return x + ((y - x) * (z / t));
}
double code(double x, double y, double z, double t) {
	double tmp;
	if ((z / t) <= -4.620299765818223e+242) {
		tmp = fma(z, ((y / t) - (x / t)), x);
	} else {
		double t_1 = fma((y - x), (z / t), x);
		double tmp_1;
		if ((z / t) <= -1.2829284567762299e-64) {
			tmp_1 = t_1;
		} else if ((z / t) <= 5.322646425016115e-141) {
			tmp_1 = x + (z * ((1.0 / t) / (1.0 / (y - x))));
		} else {
			tmp_1 = t_1;
		}
		tmp = tmp_1;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original1.9
Target2.2
Herbie1.7
\[\begin{array}{l} \mathbf{if}\;\left(y - x\right) \cdot \frac{z}{t} < -1013646692435.8867:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{elif}\;\left(y - x\right) \cdot \frac{z}{t} < 0:\\ \;\;\;\;x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if (/.f64 z t) < -4.6202997658182231e242

    1. Initial program 27.8

      \[x + \left(y - x\right) \cdot \frac{z}{t} \]
    2. Simplified27.8

      \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)} \]
    3. Applied fma-udef_binary6427.8

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

      \[\leadsto \color{blue}{z \cdot \frac{y - x}{t}} + x \]
    5. Taylor expanded in y around 0 0.7

      \[\leadsto z \cdot \color{blue}{\left(\frac{y}{t} - \frac{x}{t}\right)} + x \]
    6. Applied fma-def_binary640.7

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

    if -4.6202997658182231e242 < (/.f64 z t) < -1.2829284567762299e-64 or 5.3226464250161154e-141 < (/.f64 z t)

    1. Initial program 1.4

      \[x + \left(y - x\right) \cdot \frac{z}{t} \]
    2. Simplified1.4

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

    if -1.2829284567762299e-64 < (/.f64 z t) < 5.3226464250161154e-141

    1. Initial program 1.4

      \[x + \left(y - x\right) \cdot \frac{z}{t} \]
    2. Simplified1.4

      \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)} \]
    3. Applied fma-udef_binary641.4

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

      \[\leadsto \color{blue}{z \cdot \frac{y - x}{t}} + x \]
    5. Applied clear-num_binary642.1

      \[\leadsto z \cdot \color{blue}{\frac{1}{\frac{t}{y - x}}} + x \]
    6. Applied div-inv_binary642.1

      \[\leadsto z \cdot \frac{1}{\color{blue}{t \cdot \frac{1}{y - x}}} + x \]
    7. Applied associate-/r*_binary642.1

      \[\leadsto z \cdot \color{blue}{\frac{\frac{1}{t}}{\frac{1}{y - x}}} + x \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{z}{t} \leq -4.620299765818223 \cdot 10^{+242}:\\ \;\;\;\;\mathsf{fma}\left(z, \frac{y}{t} - \frac{x}{t}, x\right)\\ \mathbf{elif}\;\frac{z}{t} \leq -1.2829284567762299 \cdot 10^{-64}:\\ \;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \mathbf{elif}\;\frac{z}{t} \leq 5.322646425016115 \cdot 10^{-141}:\\ \;\;\;\;x + z \cdot \frac{\frac{1}{t}}{\frac{1}{y - x}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022077 
(FPCore (x y z t)
  :name "Graphics.Rendering.Plot.Render.Plot.Axis:tickPosition from plot-0.2.3.4"
  :precision binary64

  :herbie-target
  (if (< (* (- y x) (/ z t)) -1013646692435.8867) (+ x (/ (- y x) (/ t z))) (if (< (* (- y x) (/ z t)) 0.0) (+ x (/ (* (- y x) z) t)) (+ x (/ (- y x) (/ t z)))))

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