Average Error: 2.2 → 2.1
Time: 3.7s
Precision: binary64
\[\frac{x}{y} \cdot \left(z - t\right) + t \]
\[\begin{array}{l} \mathbf{if}\;t \leq -1.5 \cdot 10^{-56}:\\ \;\;\;\;t + \frac{z - t}{\frac{y}{x}}\\ \mathbf{elif}\;t \leq 6.2 \cdot 10^{-126}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{z - t}{y}, t\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{y}, z - t, t\right)\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (+ (* (/ x y) (- z t)) t))
(FPCore (x y z t)
 :precision binary64
 (if (<= t -1.5e-56)
   (+ t (/ (- z t) (/ y x)))
   (if (<= t 6.2e-126) (fma x (/ (- z t) y) t) (fma (/ x y) (- z t) t))))
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 (t <= -1.5e-56) {
		tmp = t + ((z - t) / (y / x));
	} else if (t <= 6.2e-126) {
		tmp = fma(x, ((z - t) / y), t);
	} else {
		tmp = fma((x / y), (z - t), t);
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(Float64(Float64(x / y) * Float64(z - t)) + t)
end
function code(x, y, z, t)
	tmp = 0.0
	if (t <= -1.5e-56)
		tmp = Float64(t + Float64(Float64(z - t) / Float64(y / x)));
	elseif (t <= 6.2e-126)
		tmp = fma(x, Float64(Float64(z - t) / y), t);
	else
		tmp = fma(Float64(x / y), Float64(z - t), t);
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(N[(N[(x / y), $MachinePrecision] * N[(z - t), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision]
code[x_, y_, z_, t_] := If[LessEqual[t, -1.5e-56], N[(t + N[(N[(z - t), $MachinePrecision] / N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 6.2e-126], N[(x * N[(N[(z - t), $MachinePrecision] / y), $MachinePrecision] + t), $MachinePrecision], N[(N[(x / y), $MachinePrecision] * N[(z - t), $MachinePrecision] + t), $MachinePrecision]]]
\frac{x}{y} \cdot \left(z - t\right) + t
\begin{array}{l}
\mathbf{if}\;t \leq -1.5 \cdot 10^{-56}:\\
\;\;\;\;t + \frac{z - t}{\frac{y}{x}}\\

\mathbf{elif}\;t \leq 6.2 \cdot 10^{-126}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{z - t}{y}, t\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{y}, z - t, t\right)\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original2.2
Target2.4
Herbie2.1
\[\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 t < -1.49999999999999995e-56

    1. Initial program 0.4

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

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

    if -1.49999999999999995e-56 < t < 6.2000000000000003e-126

    1. Initial program 4.7

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

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

    if 6.2000000000000003e-126 < t

    1. Initial program 0.6

      \[\frac{x}{y} \cdot \left(z - t\right) + t \]
    2. Applied egg-rr0.6

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

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

Reproduce

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