Average Error: 2.1 → 2.4
Time: 4.2s
Precision: binary64
\[\frac{x}{y} \cdot \left(z - t\right) + t \]
\[\begin{array}{l} \mathbf{if}\;y \leq -9.356558566033457 \cdot 10^{+121}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{y}, z - t, t\right)\\ \mathbf{elif}\;y \leq 1.0008641094660794 \cdot 10^{+131}:\\ \;\;\;\;\left(t + \frac{x \cdot z}{y}\right) - \frac{x \cdot t}{y}\\ \mathbf{else}:\\ \;\;\;\;t + x \cdot \frac{z - t}{y}\\ \end{array} \]
\frac{x}{y} \cdot \left(z - t\right) + t
\begin{array}{l}
\mathbf{if}\;y \leq -9.356558566033457 \cdot 10^{+121}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y}, z - t, t\right)\\

\mathbf{elif}\;y \leq 1.0008641094660794 \cdot 10^{+131}:\\
\;\;\;\;\left(t + \frac{x \cdot z}{y}\right) - \frac{x \cdot t}{y}\\

\mathbf{else}:\\
\;\;\;\;t + x \cdot \frac{z - t}{y}\\


\end{array}
(FPCore (x y z t) :precision binary64 (+ (* (/ x y) (- z t)) t))
(FPCore (x y z t)
 :precision binary64
 (if (<= y -9.356558566033457e+121)
   (fma (/ x y) (- z t) t)
   (if (<= y 1.0008641094660794e+131)
     (- (+ t (/ (* x z) y)) (/ (* x t) y))
     (+ t (* x (/ (- z 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 <= -9.356558566033457e+121) {
		tmp = fma((x / y), (z - t), t);
	} else if (y <= 1.0008641094660794e+131) {
		tmp = (t + ((x * z) / y)) - ((x * t) / y);
	} else {
		tmp = t + (x * ((z - t) / y));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original2.1
Target2.2
Herbie2.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 3 regimes
  2. if y < -9.35655856603345706e121

    1. Initial program 1.0

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

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

    if -9.35655856603345706e121 < y < 1.00086410946607935e131

    1. Initial program 2.7

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

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

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

    if 1.00086410946607935e131 < y

    1. Initial program 1.1

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -9.356558566033457 \cdot 10^{+121}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{y}, z - t, t\right)\\ \mathbf{elif}\;y \leq 1.0008641094660794 \cdot 10^{+131}:\\ \;\;\;\;\left(t + \frac{x \cdot z}{y}\right) - \frac{x \cdot t}{y}\\ \mathbf{else}:\\ \;\;\;\;t + x \cdot \frac{z - t}{y}\\ \end{array} \]

Reproduce

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