Average Error: 7.7 → 1.6
Time: 8.1s
Precision: binary64
Cost: 7944
\[ \begin{array}{c}[x, y] = \mathsf{sort}([x, y])\\ [z, t] = \mathsf{sort}([z, t])\\ \end{array} \]
\[\frac{x \cdot y - z \cdot t}{a} \]
\[\begin{array}{l} t_1 := x \cdot y - z \cdot t\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+92}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{x}{a}, \frac{-z}{\frac{a}{t}}\right)\\ \mathbf{elif}\;t_1 \leq 10^{+231}:\\ \;\;\;\;\frac{\mathsf{fma}\left(z, -t, x \cdot y\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\ \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 -1e+92)
     (fma y (/ x a) (/ (- z) (/ a t)))
     (if (<= t_1 1e+231)
       (/ (fma z (- t) (* x y)) a)
       (- (/ x (/ a y)) (/ z (/ a t)))))))
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 <= -1e+92) {
		tmp = fma(y, (x / a), (-z / (a / t)));
	} else if (t_1 <= 1e+231) {
		tmp = fma(z, -t, (x * y)) / a;
	} else {
		tmp = (x / (a / y)) - (z / (a / t));
	}
	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 <= -1e+92)
		tmp = fma(y, Float64(x / a), Float64(Float64(-z) / Float64(a / t)));
	elseif (t_1 <= 1e+231)
		tmp = Float64(fma(z, Float64(-t), Float64(x * y)) / a);
	else
		tmp = Float64(Float64(x / Float64(a / y)) - Float64(z / Float64(a / t)));
	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, -1e+92], N[(y * N[(x / a), $MachinePrecision] + N[((-z) / N[(a / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1e+231], N[(N[(z * (-t) + N[(x * y), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[(N[(x / N[(a / y), $MachinePrecision]), $MachinePrecision] - N[(z / N[(a / t), $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 -1 \cdot 10^{+92}:\\
\;\;\;\;\mathsf{fma}\left(y, \frac{x}{a}, \frac{-z}{\frac{a}{t}}\right)\\

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

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


\end{array}

Error

Target

Original7.7
Target5.5
Herbie1.6
\[\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)) < -1e92

    1. Initial program 16.2

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

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

    if -1e92 < (-.f64 (*.f64 x y) (*.f64 z t)) < 1.0000000000000001e231

    1. Initial program 0.7

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Simplified0.7

      \[\leadsto \color{blue}{\frac{\mathsf{fma}\left(z, -t, x \cdot y\right)}{a}} \]
      Proof
      (/.f64 (fma.f64 z (neg.f64 t) (*.f64 x y)) a): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 z (neg.f64 t)) (*.f64 x y))) a): 1 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 z t))) (*.f64 x y)) a): 0 points increase in error, 0 points decrease in error
      (/.f64 (+.f64 (Rewrite<= distribute-lft-neg-out_binary64 (*.f64 (neg.f64 z) t)) (*.f64 x y)) a): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 x y) (*.f64 (neg.f64 z) t))) a): 0 points increase in error, 0 points decrease in error
      (/.f64 (Rewrite<= cancel-sign-sub-inv_binary64 (-.f64 (*.f64 x y) (*.f64 z t))) a): 0 points increase in error, 0 points decrease in error

    if 1.0000000000000001e231 < (-.f64 (*.f64 x y) (*.f64 z t))

    1. Initial program 35.2

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

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

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

Alternatives

Alternative 1
Error0.6
Cost7944
\[\begin{array}{l} t_1 := \frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\ t_2 := x \cdot y - z \cdot t\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 10^{+231}:\\ \;\;\;\;\frac{\mathsf{fma}\left(z, -t, x \cdot y\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error4.3
Cost1864
\[\begin{array}{l} t_1 := \frac{x \cdot y - z \cdot t}{a}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+306}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \end{array} \]
Alternative 3
Error0.6
Cost1736
\[\begin{array}{l} t_1 := \frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\ t_2 := x \cdot y - z \cdot t\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 10^{+231}:\\ \;\;\;\;\frac{t_2}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error23.5
Cost1308
\[\begin{array}{l} t_1 := z \cdot \frac{-t}{a}\\ t_2 := \frac{-t}{\frac{a}{z}}\\ t_3 := y \cdot \frac{x}{a}\\ \mathbf{if}\;y \leq -4.8 \cdot 10^{-151}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 5.4 \cdot 10^{-252}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 8 \cdot 10^{-150}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 1.7 \cdot 10^{-56}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 390000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 5.8 \cdot 10^{+23}:\\ \;\;\;\;x \cdot \frac{y}{a}\\ \mathbf{elif}\;y \leq 5.9 \cdot 10^{+25}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 5
Error23.5
Cost1044
\[\begin{array}{l} t_1 := z \cdot \frac{-t}{a}\\ t_2 := t \cdot \frac{-z}{a}\\ t_3 := y \cdot \frac{x}{a}\\ \mathbf{if}\;y \leq -5 \cdot 10^{-151}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;y \leq 1.66 \cdot 10^{-252}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.4 \cdot 10^{-150}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 1.8 \cdot 10^{-57}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 5.5 \cdot 10^{+36}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 6
Error24.7
Cost912
\[\begin{array}{l} t_1 := \frac{-t}{\frac{a}{z}}\\ \mathbf{if}\;z \leq -8.2 \cdot 10^{+98}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.8 \cdot 10^{+73}:\\ \;\;\;\;x \cdot \frac{y}{a}\\ \mathbf{elif}\;z \leq -8 \cdot 10^{+43}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.1 \cdot 10^{-17}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error23.1
Cost648
\[\begin{array}{l} t_1 := y \cdot \frac{x}{a}\\ \mathbf{if}\;y \leq -5.4 \cdot 10^{-151}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 57000000000000:\\ \;\;\;\;\frac{-z \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error32.6
Cost584
\[\begin{array}{l} t_1 := y \cdot \frac{x}{a}\\ \mathbf{if}\;t \leq 8.6 \cdot 10^{-102}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.46 \cdot 10^{+146}:\\ \;\;\;\;x \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error32.5
Cost584
\[\begin{array}{l} \mathbf{if}\;t \leq 2.8 \cdot 10^{-94}:\\ \;\;\;\;\frac{y}{\frac{a}{x}}\\ \mathbf{elif}\;t \leq 5.5 \cdot 10^{+146}:\\ \;\;\;\;x \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \end{array} \]
Alternative 10
Error31.4
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.55 \cdot 10^{-31}:\\ \;\;\;\;\frac{y}{\frac{a}{x}}\\ \mathbf{elif}\;x \leq 3 \cdot 10^{-130}:\\ \;\;\;\;\frac{x \cdot y}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \end{array} \]
Alternative 11
Error32.6
Cost320
\[y \cdot \frac{x}{a} \]

Error

Reproduce

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