Average Error: 7.1 → 0.7
Time: 6.4s
Precision: binary64
\[ \begin{array}{c}[x, y] = \mathsf{sort}([x, y])\\ \end{array} \]
\[\frac{x \cdot y - z \cdot t}{a} \]
\[\begin{array}{l} t_1 := \frac{-z}{\frac{a}{t}}\\ t_2 := x \cdot y - z \cdot t\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{a}, t_1\right)\\ \mathbf{elif}\;t_2 \leq 2.855096886471254 \cdot 10^{+271}:\\ \;\;\;\;\frac{\mathsf{fma}\left(t, -z, x \cdot y\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{a}, t_1\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 (/ (- z) (/ a t))) (t_2 (- (* x y) (* z t))))
   (if (<= t_2 (- INFINITY))
     (fma y (/ x a) t_1)
     (if (<= t_2 2.855096886471254e+271)
       (/ (fma t (- z) (* x y)) a)
       (fma x (/ y a) t_1)))))
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 = -z / (a / t);
	double t_2 = (x * y) - (z * t);
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = fma(y, (x / a), t_1);
	} else if (t_2 <= 2.855096886471254e+271) {
		tmp = fma(t, -z, (x * y)) / a;
	} else {
		tmp = fma(x, (y / a), t_1);
	}
	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(-z) / Float64(a / t))
	t_2 = Float64(Float64(x * y) - Float64(z * t))
	tmp = 0.0
	if (t_2 <= Float64(-Inf))
		tmp = fma(y, Float64(x / a), t_1);
	elseif (t_2 <= 2.855096886471254e+271)
		tmp = Float64(fma(t, Float64(-z), Float64(x * y)) / a);
	else
		tmp = fma(x, Float64(y / a), t_1);
	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[((-z) / N[(a / t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], N[(y * N[(x / a), $MachinePrecision] + t$95$1), $MachinePrecision], If[LessEqual[t$95$2, 2.855096886471254e+271], N[(N[(t * (-z) + N[(x * y), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[(x * N[(y / a), $MachinePrecision] + t$95$1), $MachinePrecision]]]]]
\frac{x \cdot y - z \cdot t}{a}
\begin{array}{l}
t_1 := \frac{-z}{\frac{a}{t}}\\
t_2 := x \cdot y - z \cdot t\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{x}{a}, t_1\right)\\

\mathbf{elif}\;t_2 \leq 2.855096886471254 \cdot 10^{+271}:\\
\;\;\;\;\frac{\mathsf{fma}\left(t, -z, x \cdot y\right)}{a}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y}{a}, t_1\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.1
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 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-rr0.3

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

    if -inf.0 < (-.f64 (*.f64 x y) (*.f64 z t)) < 2.85509688647125402e271

    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. Simplified0.7

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

    if 2.85509688647125402e271 < (-.f64 (*.f64 x y) (*.f64 z t))

    1. Initial program 46.8

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{1}, \frac{y}{a}, -\frac{z}{\frac{a}{t}}\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:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{a}, \frac{-z}{\frac{a}{t}}\right)\\ \mathbf{elif}\;x \cdot y - z \cdot t \leq 2.855096886471254 \cdot 10^{+271}:\\ \;\;\;\;\frac{\mathsf{fma}\left(t, -z, x \cdot y\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{a}, \frac{-z}{\frac{a}{t}}\right)\\ \end{array} \]

Reproduce

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