Average Error: 7.4 → 0.8
Time: 10.4s
Precision: binary64
Cost: 7944
\[\frac{x \cdot y - z \cdot t}{a} \]
\[\begin{array}{l} t_1 := x \cdot y - z \cdot t\\ t_2 := \frac{x}{\frac{a}{y}} - \frac{\frac{z}{a}}{\frac{1}{t}}\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+266}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 10^{+250}:\\ \;\;\;\;\frac{\mathsf{fma}\left(z, -t, x \cdot y\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \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)))
        (t_2 (- (/ x (/ a y)) (/ (/ z a) (/ 1.0 t)))))
   (if (<= t_1 -2e+266)
     t_2
     (if (<= t_1 1e+250) (/ (fma z (- t) (* x y)) a) t_2))))
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 t_2 = (x / (a / y)) - ((z / a) / (1.0 / t));
	double tmp;
	if (t_1 <= -2e+266) {
		tmp = t_2;
	} else if (t_1 <= 1e+250) {
		tmp = fma(z, -t, (x * y)) / a;
	} else {
		tmp = t_2;
	}
	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))
	t_2 = Float64(Float64(x / Float64(a / y)) - Float64(Float64(z / a) / Float64(1.0 / t)))
	tmp = 0.0
	if (t_1 <= -2e+266)
		tmp = t_2;
	elseif (t_1 <= 1e+250)
		tmp = Float64(fma(z, Float64(-t), Float64(x * y)) / a);
	else
		tmp = t_2;
	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]}, Block[{t$95$2 = N[(N[(x / N[(a / y), $MachinePrecision]), $MachinePrecision] - N[(N[(z / a), $MachinePrecision] / N[(1.0 / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+266], t$95$2, If[LessEqual[t$95$1, 1e+250], N[(N[(z * (-t) + N[(x * y), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], t$95$2]]]]
\frac{x \cdot y - z \cdot t}{a}
\begin{array}{l}
t_1 := x \cdot y - z \cdot t\\
t_2 := \frac{x}{\frac{a}{y}} - \frac{\frac{z}{a}}{\frac{1}{t}}\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+266}:\\
\;\;\;\;t_2\\

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

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}

Error

Target

Original7.4
Target6.0
Herbie0.8
\[\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)) < -2.0000000000000001e266 or 9.9999999999999992e249 < (-.f64 (*.f64 x y) (*.f64 z t))

    1. Initial program 42.8

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

      \[\leadsto \color{blue}{\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}} \]
    3. Applied egg-rr22.8

      \[\leadsto \frac{x}{\frac{a}{y}} - \color{blue}{\frac{1}{a} \cdot \frac{z}{\frac{1}{t}}} \]
    4. Applied egg-rr0.6

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

    if -2.0000000000000001e266 < (-.f64 (*.f64 x y) (*.f64 z t)) < 9.9999999999999992e249

    1. Initial program 0.9

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

      \[\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.8

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

Alternatives

Alternative 1
Error22.6
Cost1944
\[\begin{array}{l} t_1 := \frac{z \cdot \left(-t\right)}{a}\\ \mathbf{if}\;z \cdot t \leq -2 \cdot 10^{+177}:\\ \;\;\;\;t \cdot \left(-\frac{z}{a}\right)\\ \mathbf{elif}\;z \cdot t \leq -2 \cdot 10^{+43}:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \mathbf{elif}\;z \cdot t \leq -2 \cdot 10^{-78}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot t \leq 10^{-172}:\\ \;\;\;\;\frac{y}{\frac{a}{x}}\\ \mathbf{elif}\;z \cdot t \leq 10^{-127}:\\ \;\;\;\;z \cdot \frac{-t}{a}\\ \mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{-51}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error4.5
Cost1864
\[\begin{array}{l} t_1 := \frac{x \cdot y - z \cdot t}{a}\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+303}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{+292}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{a}{x}}\\ \end{array} \]
Alternative 3
Error0.8
Cost1864
\[\begin{array}{l} t_1 := x \cdot y - z \cdot t\\ t_2 := \frac{x}{\frac{a}{y}} - \frac{\frac{z}{a}}{\frac{1}{t}}\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+266}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 10^{+250}:\\ \;\;\;\;\frac{t_1}{a}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error0.8
Cost1736
\[\begin{array}{l} t_1 := x \cdot y - z \cdot t\\ t_2 := x \cdot \frac{y}{a} - \frac{t}{\frac{a}{z}}\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+266}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+305}:\\ \;\;\;\;\frac{t_1}{a}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error0.8
Cost1736
\[\begin{array}{l} t_1 := x \cdot y - z \cdot t\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+266}:\\ \;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+305}:\\ \;\;\;\;\frac{t_1}{a}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y}{a} - \frac{t}{\frac{a}{z}}\\ \end{array} \]
Alternative 6
Error26.1
Cost912
\[\begin{array}{l} t_1 := \frac{y}{\frac{a}{x}}\\ t_2 := \frac{-t}{\frac{a}{z}}\\ \mathbf{if}\;z \leq -1.05 \cdot 10^{+87}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 1.22 \cdot 10^{-207}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 7.5 \cdot 10^{-170}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 5 \cdot 10^{-93}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error26.5
Cost912
\[\begin{array}{l} t_1 := z \cdot \frac{-t}{a}\\ \mathbf{if}\;y \leq -7.1 \cdot 10^{-186}:\\ \;\;\;\;\frac{y}{\frac{a}{x}}\\ \mathbf{elif}\;y \leq 3.8 \cdot 10^{-53}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 27000:\\ \;\;\;\;\frac{x \cdot y}{a}\\ \mathbf{elif}\;y \leq 9.2 \cdot 10^{+36}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \end{array} \]
Alternative 8
Error32.1
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -4.4 \cdot 10^{+101}:\\ \;\;\;\;\frac{y}{\frac{a}{x}}\\ \mathbf{elif}\;x \leq 3.8 \cdot 10^{-35}:\\ \;\;\;\;\frac{x \cdot y}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \end{array} \]
Alternative 9
Error33.6
Cost452
\[\begin{array}{l} \mathbf{if}\;a \leq -1.35 \cdot 10^{-135}:\\ \;\;\;\;x \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \end{array} \]
Alternative 10
Error33.5
Cost320
\[y \cdot \frac{x}{a} \]

Error

Reproduce

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