Average Error: 2.0 → 1.4
Time: 3.5s
Precision: binary64
\[\frac{x}{y} \cdot \left(z - t\right) + t \]
\[\begin{array}{l} \mathbf{if}\;y \leq -5.760128296672811 \cdot 10^{-87} \lor \neg \left(y \leq 1.0179439283731854 \cdot 10^{-38}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{y}, z - t, t\right)\\ \mathbf{else}:\\ \;\;\;\;\left(t + \frac{x \cdot z}{y}\right) - \frac{x \cdot t}{y}\\ \end{array} \]
\frac{x}{y} \cdot \left(z - t\right) + t
\begin{array}{l}
\mathbf{if}\;y \leq -5.760128296672811 \cdot 10^{-87} \lor \neg \left(y \leq 1.0179439283731854 \cdot 10^{-38}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y}, z - t, t\right)\\

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


\end{array}
(FPCore (x y z t) :precision binary64 (+ (* (/ x y) (- z t)) t))
(FPCore (x y z t)
 :precision binary64
 (if (or (<= y -5.760128296672811e-87) (not (<= y 1.0179439283731854e-38)))
   (fma (/ x y) (- z t) t)
   (- (+ t (/ (* x z) y)) (/ (* x t) y))))
double code(double x, double y, double z, double t) {
	return ((x / y) * (z - t)) + t;
}
double code(double x, double y, double z, double t) {
	double tmp;
	if ((y <= -5.760128296672811e-87) || !(y <= 1.0179439283731854e-38)) {
		tmp = fma((x / y), (z - t), t);
	} else {
		tmp = (t + ((x * z) / y)) - ((x * t) / y);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original2.0
Target2.3
Herbie1.4
\[\begin{array}{l} \mathbf{if}\;z < 2.759456554562692 \cdot 10^{-282}:\\ \;\;\;\;\frac{x}{y} \cdot \left(z - t\right) + t\\ \mathbf{elif}\;z < 2.326994450874436 \cdot 10^{-110}:\\ \;\;\;\;x \cdot \frac{z - t}{y} + t\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{y} \cdot \left(z - t\right) + t\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if y < -5.7601282966728112e-87 or 1.0179439283731854e-38 < y

    1. Initial program 0.9

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

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

    if -5.7601282966728112e-87 < y < 1.0179439283731854e-38

    1. Initial program 4.7

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{y}, z - t, t\right)} \]
    3. Taylor expanded in x around 0 2.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -5.760128296672811 \cdot 10^{-87} \lor \neg \left(y \leq 1.0179439283731854 \cdot 10^{-38}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{y}, z - t, t\right)\\ \mathbf{else}:\\ \;\;\;\;\left(t + \frac{x \cdot z}{y}\right) - \frac{x \cdot t}{y}\\ \end{array} \]

Reproduce

herbie shell --seed 2021280 
(FPCore (x y z t)
  :name "Numeric.Signal.Multichannel:$cget from hsignal-0.2.7.1"
  :precision binary64

  :herbie-target
  (if (< z 2.759456554562692e-282) (+ (* (/ x y) (- z t)) t) (if (< z 2.326994450874436e-110) (+ (* x (/ (- z t) y)) t) (+ (* (/ x y) (- z t)) t)))

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