Average Error: 7.5 → 0.7
Time: 9.6s
Precision: binary64
\[[x, y] = \mathsf{sort}([x, y]) \[z, t] = \mathsf{sort}([z, t]) \\]
\[\frac{x \cdot y - z \cdot t}{a} \]
\[\begin{array}{l} \mathbf{if}\;\begin{array}{l} t_1 := x \cdot y - z \cdot t\\ t_1 \leq -\infty \lor \neg \left(t_1 \leq 2.6521813933633685 \cdot 10^{+232}\right) \end{array}:\\ \;\;\;\;\begin{array}{l} t_2 := t \cdot \frac{z}{a}\\ \mathsf{fma}\left(y, \frac{x}{a}, -t_2\right) + \mathsf{fma}\left(-\frac{z}{a}, t, t_2\right) \end{array}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y}{a} + \frac{z \cdot t}{-a}\\ \end{array} \]
\frac{x \cdot y - z \cdot t}{a}
\begin{array}{l}
\mathbf{if}\;\begin{array}{l}
t_1 := x \cdot y - z \cdot t\\
t_1 \leq -\infty \lor \neg \left(t_1 \leq 2.6521813933633685 \cdot 10^{+232}\right)
\end{array}:\\
\;\;\;\;\begin{array}{l}
t_2 := t \cdot \frac{z}{a}\\
\mathsf{fma}\left(y, \frac{x}{a}, -t_2\right) + \mathsf{fma}\left(-\frac{z}{a}, t, t_2\right)
\end{array}\\

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


\end{array}
(FPCore (x y z t a) :precision binary64 (/ (- (* x y) (* z t)) a))
(FPCore (x y z t a)
 :precision binary64
 (if (let* ((t_1 (- (* x y) (* z t))))
       (or (<= t_1 (- INFINITY)) (not (<= t_1 2.6521813933633685e+232))))
   (let* ((t_2 (* t (/ z a))))
     (+ (fma y (/ x a) (- t_2)) (fma (- (/ z a)) t t_2)))
   (+ (/ (* x y) a) (/ (* z t) (- 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)) || !(t_1 <= 2.6521813933633685e+232)) {
		double t_2_1 = t * (z / a);
		tmp = fma(y, (x / a), -t_2_1) + fma(-(z / a), t, t_2_1);
	} else {
		tmp = ((x * y) / a) + ((z * t) / -a);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original7.5
Target5.5
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 2 regimes
  2. if (-.f64 (*.f64 x y) (*.f64 z t)) < -inf.0 or 2.65218139336336853e232 < (-.f64 (*.f64 x y) (*.f64 z t))

    1. Initial program 45.0

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

      \[\leadsto \color{blue}{\frac{y \cdot x}{a} - \frac{t \cdot z}{a}} \]
    3. Applied *-un-lft-identity_binary6445.0

      \[\leadsto \frac{y \cdot x}{a} - \frac{t \cdot z}{\color{blue}{1 \cdot a}} \]
    4. Applied times-frac_binary6424.0

      \[\leadsto \frac{y \cdot x}{a} - \color{blue}{\frac{t}{1} \cdot \frac{z}{a}} \]
    5. Applied *-un-lft-identity_binary6424.0

      \[\leadsto \frac{y \cdot x}{\color{blue}{1 \cdot a}} - \frac{t}{1} \cdot \frac{z}{a} \]
    6. Applied times-frac_binary640.5

      \[\leadsto \color{blue}{\frac{y}{1} \cdot \frac{x}{a}} - \frac{t}{1} \cdot \frac{z}{a} \]
    7. Applied prod-diff_binary640.5

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

    if -inf.0 < (-.f64 (*.f64 x y) (*.f64 z t)) < 2.65218139336336853e232

    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}} \]
    3. Applied frac-2neg_binary640.7

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

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

Reproduce

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