Average Error: 7.6 → 0.4
Time: 11.6s
Precision: binary64
Cost: 8977
\[ \begin{array}{c}[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 -2 \cdot 10^{+296}:\\ \;\;\;\;\mathsf{fma}\left(-1, \frac{t}{\frac{a}{z}}, \frac{y}{\frac{a}{x}}\right)\\ \mathbf{elif}\;t_1 \leq -5 \cdot 10^{-148} \lor \neg \left(t_1 \leq 0\right) \land t_1 \leq 5 \cdot 10^{+268}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, y, t \cdot \left(-z\right)\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 -2e+296)
     (fma -1.0 (/ t (/ a z)) (/ y (/ a x)))
     (if (or (<= t_1 -5e-148) (and (not (<= t_1 0.0)) (<= t_1 5e+268)))
       (/ (fma x y (* t (- z))) 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 <= -2e+296) {
		tmp = fma(-1.0, (t / (a / z)), (y / (a / x)));
	} else if ((t_1 <= -5e-148) || (!(t_1 <= 0.0) && (t_1 <= 5e+268))) {
		tmp = fma(x, y, (t * -z)) / 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 <= -2e+296)
		tmp = fma(-1.0, Float64(t / Float64(a / z)), Float64(y / Float64(a / x)));
	elseif ((t_1 <= -5e-148) || (!(t_1 <= 0.0) && (t_1 <= 5e+268)))
		tmp = Float64(fma(x, y, Float64(t * Float64(-z))) / 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, -2e+296], N[(-1.0 * N[(t / N[(a / z), $MachinePrecision]), $MachinePrecision] + N[(y / N[(a / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[t$95$1, -5e-148], And[N[Not[LessEqual[t$95$1, 0.0]], $MachinePrecision], LessEqual[t$95$1, 5e+268]]], N[(N[(x * y + N[(t * (-z)), $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 -2 \cdot 10^{+296}:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{t}{\frac{a}{z}}, \frac{y}{\frac{a}{x}}\right)\\

\mathbf{elif}\;t_1 \leq -5 \cdot 10^{-148} \lor \neg \left(t_1 \leq 0\right) \land t_1 \leq 5 \cdot 10^{+268}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, y, t \cdot \left(-z\right)\right)}{a}\\

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


\end{array}

Error

Target

Original7.6
Target5.4
Herbie0.4
\[\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)) < -1.99999999999999996e296

    1. Initial program 57.7

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

      \[\leadsto \color{blue}{-1 \cdot \frac{t \cdot z}{a} + \frac{y \cdot x}{a}} \]
    3. Simplified0.3

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

      [Start]57.7

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

      fma-def [=>]57.7

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

      associate-/l* [=>]29.6

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

      associate-/l* [=>]0.3

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

    if -1.99999999999999996e296 < (-.f64 (*.f64 x y) (*.f64 z t)) < -4.9999999999999999e-148 or -0.0 < (-.f64 (*.f64 x y) (*.f64 z t)) < 5.0000000000000002e268

    1. Initial program 0.3

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

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

      [Start]0.3

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

      fma-neg [=>]0.3

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

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

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

    if -4.9999999999999999e-148 < (-.f64 (*.f64 x y) (*.f64 z t)) < -0.0 or 5.0000000000000002e268 < (-.f64 (*.f64 x y) (*.f64 z t))

    1. Initial program 27.3

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

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

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

Alternatives

Alternative 1
Error0.4
Cost8977
\[\begin{array}{l} t_1 := x \cdot y - z \cdot t\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+277}:\\ \;\;\;\;\frac{y}{\frac{a}{x}} - t \cdot \frac{z}{a}\\ \mathbf{elif}\;t_1 \leq -5 \cdot 10^{-148} \lor \neg \left(t_1 \leq 0\right) \land t_1 \leq 5 \cdot 10^{+268}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, y, t \cdot \left(-z\right)\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\ \end{array} \]
Alternative 2
Error0.3
Cost2770
\[\begin{array}{l} t_1 := x \cdot y - z \cdot t\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+262} \lor \neg \left(t_1 \leq -2 \cdot 10^{-233} \lor \neg \left(t_1 \leq 0\right) \land t_1 \leq 2 \cdot 10^{+271}\right):\\ \;\;\;\;y \cdot \frac{x}{a} - t \cdot \frac{z}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1}{a}\\ \end{array} \]
Alternative 3
Error0.4
Cost2769
\[\begin{array}{l} t_1 := x \cdot y - z \cdot t\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+262}:\\ \;\;\;\;y \cdot \frac{x}{a} - t \cdot \frac{z}{a}\\ \mathbf{elif}\;t_1 \leq -5 \cdot 10^{-148} \lor \neg \left(t_1 \leq 0\right) \land t_1 \leq 5 \cdot 10^{+268}:\\ \;\;\;\;\frac{t_1}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\ \end{array} \]
Alternative 4
Error0.4
Cost2769
\[\begin{array}{l} t_1 := x \cdot y - z \cdot t\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+277}:\\ \;\;\;\;\frac{y}{\frac{a}{x}} - t \cdot \frac{z}{a}\\ \mathbf{elif}\;t_1 \leq -5 \cdot 10^{-148} \lor \neg \left(t_1 \leq 0\right) \land t_1 \leq 5 \cdot 10^{+268}:\\ \;\;\;\;\frac{t_1}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\ \end{array} \]
Alternative 5
Error4.1
Cost1608
\[\begin{array}{l} t_1 := x \cdot y - z \cdot t\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+302}:\\ \;\;\;\;\frac{t_1}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{\frac{-a}{t}}\\ \end{array} \]
Alternative 6
Error25.0
Cost1441
\[\begin{array}{l} t_1 := x \cdot \frac{y}{a}\\ t_2 := t \cdot \frac{-z}{a}\\ \mathbf{if}\;z \leq -1.15 \cdot 10^{+190}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2.35 \cdot 10^{+160}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -8.5 \cdot 10^{+132}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -4.8 \cdot 10^{+118}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -8 \cdot 10^{+55}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -0.0155:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \mathbf{elif}\;z \leq -5 \cdot 10^{-9} \lor \neg \left(z \leq 6.5 \cdot 10^{-215}\right):\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y}{a}\\ \end{array} \]
Alternative 7
Error24.2
Cost1044
\[\begin{array}{l} t_1 := x \cdot \frac{y}{a}\\ t_2 := t \cdot \frac{-z}{a}\\ \mathbf{if}\;t \leq -1.7 \cdot 10^{-69}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -1.25 \cdot 10^{-170}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -7.6 \cdot 10^{-224}:\\ \;\;\;\;z \cdot \left(-\frac{t}{a}\right)\\ \mathbf{elif}\;t \leq 7.5 \cdot 10^{-64}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.3 \cdot 10^{+17}:\\ \;\;\;\;\frac{x \cdot y}{a}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 8
Error24.2
Cost1044
\[\begin{array}{l} t_1 := x \cdot \frac{y}{a}\\ t_2 := \frac{z}{\frac{-a}{t}}\\ \mathbf{if}\;t \leq -1.7 \cdot 10^{-69}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq -1.25 \cdot 10^{-170}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -7.6 \cdot 10^{-224}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 7.5 \cdot 10^{-64}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.8 \cdot 10^{+17}:\\ \;\;\;\;\frac{x \cdot y}{a}\\ \mathbf{else}:\\ \;\;\;\;t \cdot \frac{-z}{a}\\ \end{array} \]
Alternative 9
Error24.0
Cost1044
\[\begin{array}{l} t_1 := x \cdot \frac{y}{a}\\ \mathbf{if}\;t \leq -2.8 \cdot 10^{-68}:\\ \;\;\;\;\frac{z}{\frac{-a}{t}}\\ \mathbf{elif}\;t \leq -1.25 \cdot 10^{-170}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -7.6 \cdot 10^{-224}:\\ \;\;\;\;\frac{-1}{a} \cdot \frac{t}{\frac{1}{z}}\\ \mathbf{elif}\;t \leq 7.5 \cdot 10^{-64}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 3.1 \cdot 10^{+17}:\\ \;\;\;\;\frac{x \cdot y}{a}\\ \mathbf{else}:\\ \;\;\;\;t \cdot \frac{-z}{a}\\ \end{array} \]
Alternative 10
Error32.7
Cost452
\[\begin{array}{l} \mathbf{if}\;a \leq -2.3 \cdot 10^{-89}:\\ \;\;\;\;x \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \end{array} \]
Alternative 11
Error31.9
Cost452
\[\begin{array}{l} \mathbf{if}\;a \leq -3.2 \cdot 10^{-21}:\\ \;\;\;\;x \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y}{a}\\ \end{array} \]
Alternative 12
Error32.7
Cost320
\[y \cdot \frac{x}{a} \]

Error

Reproduce

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