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

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

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Target

Original7.5
Target5.5
Herbie0.9
\[\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 4.00000000000000003e155 < (-.f64 (*.f64 x y) (*.f64 z t))

    1. Initial program 31.8

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(-1, \frac{t}{\frac{a}{z}}, \frac{y}{\frac{a}{x}}\right)} \]
      Proof
      (fma.f64 -1 (/.f64 t (/.f64 a z)) (/.f64 y (/.f64 a x))): 0 points increase in error, 0 points decrease in error
      (fma.f64 -1 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 t z) a)) (/.f64 y (/.f64 a x))): 27 points increase in error, 28 points decrease in error
      (fma.f64 -1 (/.f64 (*.f64 t z) a) (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 y x) a))): 28 points increase in error, 35 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 -1 (/.f64 (*.f64 t z) a)) (/.f64 (*.f64 y x) a))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> +-commutative_binary64 (+.f64 (/.f64 (*.f64 y x) a) (*.f64 -1 (/.f64 (*.f64 t z) a)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 (*.f64 y x) a) (Rewrite=> mul-1-neg_binary64 (neg.f64 (/.f64 (*.f64 t z) a)))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> unsub-neg_binary64 (-.f64 (/.f64 (*.f64 y x) a) (/.f64 (*.f64 t z) a))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= div-sub_binary64 (/.f64 (-.f64 (*.f64 y x) (*.f64 t z)) a)): 3 points increase in error, 0 points decrease in error

    if -inf.0 < (-.f64 (*.f64 x y) (*.f64 z t)) < 4.00000000000000003e155

    1. Initial program 0.8

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

      \[\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
  3. Recombined 2 regimes into one program.
  4. Final simplification0.9

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

Alternatives

Alternative 1
Error0.9
Cost7944
\[\begin{array}{l} t_1 := x \cdot y - z \cdot t\\ t_2 := x \cdot \frac{y}{a} - t \cdot \frac{z}{a}\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+295}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+186}:\\ \;\;\;\;\frac{\mathsf{fma}\left(z, -t, x \cdot y\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error0.9
Cost1736
\[\begin{array}{l} t_1 := x \cdot y - z \cdot t\\ t_2 := x \cdot \frac{y}{a} - t \cdot \frac{z}{a}\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+295}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+186}:\\ \;\;\;\;\frac{t_1}{a}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error5.0
Cost1616
\[\begin{array}{l} t_1 := \frac{x \cdot y - z \cdot t}{a}\\ \mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+260}:\\ \;\;\;\;x \cdot \frac{y}{a}\\ \mathbf{elif}\;x \cdot y \leq -5 \cdot 10^{-248}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot y \leq 10^{-286}:\\ \;\;\;\;z \cdot \frac{-t}{a}\\ \mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+166}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \end{array} \]
Alternative 4
Error25.3
Cost1308
\[\begin{array}{l} t_1 := \frac{x \cdot y}{a}\\ t_2 := \frac{z \cdot \left(-t\right)}{a}\\ t_3 := \left(-t\right) \cdot \frac{z}{a}\\ \mathbf{if}\;t \leq -5.85359458060245 \cdot 10^{-148}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq -1.1779036652231413 \cdot 10^{-212}:\\ \;\;\;\;x \cdot \frac{y}{a}\\ \mathbf{elif}\;t \leq -2.558165781408206 \cdot 10^{-261}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 1.002540525872801 \cdot 10^{-213}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \mathbf{elif}\;t \leq 9.015409728353137 \cdot 10^{-61}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 0.0015936287165032163:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 2.5025612795693455 \cdot 10^{+90}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 5
Error24.5
Cost1176
\[\begin{array}{l} t_1 := z \cdot \frac{-t}{a}\\ t_2 := y \cdot \frac{x}{a}\\ \mathbf{if}\;y \leq -6.354032882263329 \cdot 10^{-56}:\\ \;\;\;\;\frac{y}{\frac{a}{x}}\\ \mathbf{elif}\;y \leq 5.166029344279285 \cdot 10^{-153}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.7921218978498782 \cdot 10^{-129}:\\ \;\;\;\;\frac{x \cdot y}{a}\\ \mathbf{elif}\;y \leq 915723733.3627294:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.05 \cdot 10^{+97}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq 9.5 \cdot 10^{+113}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error24.9
Cost1176
\[\begin{array}{l} t_1 := \frac{-t}{\frac{a}{z}}\\ \mathbf{if}\;y \leq -6.354032882263329 \cdot 10^{-56}:\\ \;\;\;\;\frac{y}{\frac{a}{x}}\\ \mathbf{elif}\;y \leq 5.166029344279285 \cdot 10^{-153}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.7921218978498782 \cdot 10^{-129}:\\ \;\;\;\;\frac{x \cdot y}{a}\\ \mathbf{elif}\;y \leq 1.4058976376539905 \cdot 10^{+59}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 2.05 \cdot 10^{+97}:\\ \;\;\;\;x \cdot \frac{y}{a}\\ \mathbf{elif}\;y \leq 9.5 \cdot 10^{+113}:\\ \;\;\;\;z \cdot \frac{-t}{a}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \end{array} \]
Alternative 7
Error25.0
Cost1176
\[\begin{array}{l} \mathbf{if}\;y \leq -6.354032882263329 \cdot 10^{-56}:\\ \;\;\;\;\frac{y}{\frac{a}{x}}\\ \mathbf{elif}\;y \leq 5.166029344279285 \cdot 10^{-153}:\\ \;\;\;\;\left(-t\right) \cdot \frac{z}{a}\\ \mathbf{elif}\;y \leq 1.7921218978498782 \cdot 10^{-129}:\\ \;\;\;\;\frac{x \cdot y}{a}\\ \mathbf{elif}\;y \leq 1.4058976376539905 \cdot 10^{+59}:\\ \;\;\;\;\frac{-t}{\frac{a}{z}}\\ \mathbf{elif}\;y \leq 2.05 \cdot 10^{+97}:\\ \;\;\;\;x \cdot \frac{y}{a}\\ \mathbf{elif}\;y \leq 9.5 \cdot 10^{+113}:\\ \;\;\;\;z \cdot \frac{-t}{a}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \end{array} \]
Alternative 8
Error31.2
Cost584
\[\begin{array}{l} \mathbf{if}\;a \leq -1.2517220257133 \cdot 10^{+104}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \mathbf{elif}\;a \leq 2.5304296693206015 \cdot 10^{+69}:\\ \;\;\;\;\frac{x \cdot y}{a}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y}{a}\\ \end{array} \]
Alternative 9
Error32.5
Cost320
\[y \cdot \frac{x}{a} \]
Alternative 10
Error32.4
Cost320
\[\frac{y}{\frac{a}{x}} \]

Error

Reproduce

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