Average Error: 7.6 → 0.7
Time: 10.8s
Precision: binary64
\[[z, t] = \mathsf{sort}([z, t]) \\]
\[\frac{x \cdot y - z \cdot t}{a} \]
\[\begin{array}{l} t_1 := x \cdot y - z \cdot t\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;y \cdot \frac{x}{a} - \frac{t}{\frac{a}{z}}\\ \mathbf{elif}\;t_1 \leq 3.547676409310532 \cdot 10^{+242}:\\ \;\;\;\;\frac{x \cdot y}{a} - \frac{z \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{a}, t \cdot \left(z \cdot \frac{-1}{a}\right)\right)\\ \end{array} \]
(FPCore (x y z t a) :precision binary64 (/ (- (* x y) (* z t)) a))
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (- (* x y) (* z t))))
   (if (<= t_1 (- INFINITY))
     (- (* y (/ x a)) (/ t (/ a z)))
     (if (<= t_1 3.547676409310532e+242)
       (- (/ (* x y) a) (/ (* z t) a))
       (fma y (/ x a) (* t (* z (/ -1.0 a))))))))
double code(double x, double y, double z, double t, double a) {
	return ((x * y) - (z * t)) / a;
}
double code(double x, double y, double z, double t, double a) {
	double t_1 = (x * y) - (z * t);
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = (y * (x / a)) - (t / (a / z));
	} else if (t_1 <= 3.547676409310532e+242) {
		tmp = ((x * y) / a) - ((z * t) / a);
	} else {
		tmp = fma(y, (x / a), (t * (z * (-1.0 / a))));
	}
	return tmp;
}
function code(x, y, z, t, a)
	return Float64(Float64(Float64(x * y) - Float64(z * t)) / a)
end
function code(x, y, z, t, a)
	t_1 = Float64(Float64(x * y) - Float64(z * t))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(Float64(y * Float64(x / a)) - Float64(t / Float64(a / z)));
	elseif (t_1 <= 3.547676409310532e+242)
		tmp = Float64(Float64(Float64(x * y) / a) - Float64(Float64(z * t) / a));
	else
		tmp = fma(y, Float64(x / a), Float64(t * Float64(z * Float64(-1.0 / a))));
	end
	return tmp
end
code[x_, y_, z_, t_, a_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(y * N[(x / a), $MachinePrecision]), $MachinePrecision] - N[(t / N[(a / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 3.547676409310532e+242], N[(N[(N[(x * y), $MachinePrecision] / a), $MachinePrecision] - N[(N[(z * t), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(y * N[(x / a), $MachinePrecision] + N[(t * N[(z * N[(-1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\frac{x \cdot y - z \cdot t}{a}
\begin{array}{l}
t_1 := x \cdot y - z \cdot t\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;y \cdot \frac{x}{a} - \frac{t}{\frac{a}{z}}\\

\mathbf{elif}\;t_1 \leq 3.547676409310532 \cdot 10^{+242}:\\
\;\;\;\;\frac{x \cdot y}{a} - \frac{z \cdot t}{a}\\

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


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original7.6
Target5.9
Herbie0.7
\[\begin{array}{l} \mathbf{if}\;z < -2.468684968699548 \cdot 10^{+170}:\\ \;\;\;\;\frac{y}{a} \cdot x - \frac{t}{a} \cdot z\\ \mathbf{elif}\;z < 6.309831121978371 \cdot 10^{-71}:\\ \;\;\;\;\frac{x \cdot y - z \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a} \cdot x - \frac{t}{a} \cdot z\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if (-.f64 (*.f64 x y) (*.f64 z t)) < -inf.0

    1. Initial program 64.0

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Applied egg-rr34.2

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

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

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

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

    if -inf.0 < (-.f64 (*.f64 x y) (*.f64 z t)) < 3.5476764093105318e242

    1. Initial program 0.7

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Taylor expanded in x around 0 0.7

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

    if 3.5476764093105318e242 < (-.f64 (*.f64 x y) (*.f64 z t))

    1. Initial program 37.2

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Applied egg-rr21.4

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

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

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

Reproduce

herbie shell --seed 2022133 
(FPCore (x y z t a)
  :name "Data.Colour.Matrix:inverse from colour-2.3.3, B"
  :precision binary64

  :herbie-target
  (if (< z -2.468684968699548e+170) (- (* (/ y a) x) (* (/ t a) z)) (if (< z 6.309831121978371e-71) (/ (- (* x y) (* z t)) a) (- (* (/ y a) x) (* (/ t a) z))))

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