?

Average Error: 11.77% → 1.22%
Time: 10.4s
Precision: binary64
Cost: 7945

?

\[ \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 -5 \cdot 10^{+276} \lor \neg \left(t_1 \leq 2 \cdot 10^{+210}\right):\\ \;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, y, z \cdot \left(-t\right)\right)}{a}\\ \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 (or (<= t_1 -5e+276) (not (<= t_1 2e+210)))
     (- (/ x (/ a y)) (/ z (/ a t)))
     (/ (fma x y (* 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 <= -5e+276) || !(t_1 <= 2e+210)) {
		tmp = (x / (a / y)) - (z / (a / t));
	} else {
		tmp = fma(x, y, (z * -t)) / 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 <= -5e+276) || !(t_1 <= 2e+210))
		tmp = Float64(Float64(x / Float64(a / y)) - Float64(z / Float64(a / t)));
	else
		tmp = Float64(fma(x, y, Float64(z * Float64(-t))) / 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[Or[LessEqual[t$95$1, -5e+276], N[Not[LessEqual[t$95$1, 2e+210]], $MachinePrecision]], N[(N[(x / N[(a / y), $MachinePrecision]), $MachinePrecision] - N[(z / N[(a / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * y + N[(z * (-t)), $MachinePrecision]), $MachinePrecision] / a), $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 -5 \cdot 10^{+276} \lor \neg \left(t_1 \leq 2 \cdot 10^{+210}\right):\\
\;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\

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


\end{array}

Error?

Target

Original11.77%
Target8.85%
Herbie1.22%
\[\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)) < -5.00000000000000001e276 or 1.99999999999999985e210 < (-.f64 (*.f64 x y) (*.f64 z t))

    1. Initial program 57.48

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

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

    if -5.00000000000000001e276 < (-.f64 (*.f64 x y) (*.f64 z t)) < 1.99999999999999985e210

    1. Initial program 1.17

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Simplified1.16

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

      [Start]1.17

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

      fma-neg [=>]1.16

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

      distribute-rgt-neg-in [=>]1.16

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

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

Alternatives

Alternative 1
Error7.43%
Cost1864
\[\begin{array}{l} t_1 := \frac{x \cdot y - z \cdot t}{a}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;x \cdot \frac{y}{a}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+290}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{-z}{\frac{a}{t}}\\ \end{array} \]
Alternative 2
Error1.22%
Cost1737
\[\begin{array}{l} t_1 := x \cdot y - z \cdot t\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{+276} \lor \neg \left(t_1 \leq 2 \cdot 10^{+210}\right):\\ \;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1}{a}\\ \end{array} \]
Alternative 3
Error29.96%
Cost1684
\[\begin{array}{l} t_1 := \frac{-z}{\frac{a}{t}}\\ \mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+20}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot t \leq -2 \cdot 10^{-118}:\\ \;\;\;\;\frac{y}{\frac{a}{x}}\\ \mathbf{elif}\;z \cdot t \leq -5 \cdot 10^{-149}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot t \leq 10^{-68}:\\ \;\;\;\;x \cdot \frac{y}{a}\\ \mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{+262}:\\ \;\;\;\;\frac{z \cdot \left(-t\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error37.06%
Cost914
\[\begin{array}{l} \mathbf{if}\;z \leq -1.16 \cdot 10^{+28} \lor \neg \left(z \leq -1.12 \cdot 10^{-27} \lor \neg \left(z \leq -6.2 \cdot 10^{-51}\right) \land z \leq 6.8 \cdot 10^{-136}\right):\\ \;\;\;\;t \cdot \frac{-z}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \end{array} \]
Alternative 5
Error38.07%
Cost913
\[\begin{array}{l} \mathbf{if}\;z \leq -1.15 \cdot 10^{+24}:\\ \;\;\;\;t \cdot \frac{-z}{a}\\ \mathbf{elif}\;z \leq -1.05 \cdot 10^{-27} \lor \neg \left(z \leq -1.7 \cdot 10^{-69}\right) \land z \leq 2.9 \cdot 10^{-207}:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{-t}{a}\\ \end{array} \]
Alternative 6
Error37.86%
Cost913
\[\begin{array}{l} \mathbf{if}\;z \leq -1.1 \cdot 10^{+26}:\\ \;\;\;\;\frac{-t}{\frac{a}{z}}\\ \mathbf{elif}\;z \leq -5.8 \cdot 10^{-24} \lor \neg \left(z \leq -1.65 \cdot 10^{-69}\right) \land z \leq 2.9 \cdot 10^{-207}:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \mathbf{else}:\\ \;\;\;\;z \cdot \frac{-t}{a}\\ \end{array} \]
Alternative 7
Error37.78%
Cost913
\[\begin{array}{l} \mathbf{if}\;z \leq -1.4 \cdot 10^{+27}:\\ \;\;\;\;\frac{-t}{\frac{a}{z}}\\ \mathbf{elif}\;z \leq -2.7 \cdot 10^{-23} \lor \neg \left(z \leq -7 \cdot 10^{-73}\right) \land z \leq 2.8 \cdot 10^{-207}:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-z}{\frac{a}{t}}\\ \end{array} \]
Alternative 8
Error51.96%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -4.5 \cdot 10^{-306} \lor \neg \left(x \leq 2.65 \cdot 10^{-152}\right):\\ \;\;\;\;x \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \end{array} \]
Alternative 9
Error50.31%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -4.2 \cdot 10^{-104} \lor \neg \left(x \leq 8.5 \cdot 10^{-135}\right):\\ \;\;\;\;x \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y}{a}\\ \end{array} \]
Alternative 10
Error52.11%
Cost320
\[y \cdot \frac{x}{a} \]

Error

Reproduce?

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