Data.Colour.Matrix:inverse from colour-2.3.3, B

Percentage Accurate: 91.3% → 93.2%
Time: 7.0s
Alternatives: 6
Speedup: 0.6×

Specification

?
\[\begin{array}{l} \\ \frac{x \cdot y - z \cdot t}{a} \end{array} \]
(FPCore (x y z t a) :precision binary64 (/ (- (* x y) (* z t)) a))
double code(double x, double y, double z, double t, double a) {
	return ((x * y) - (z * t)) / a;
}
real(8) function code(x, y, z, t, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    code = ((x * y) - (z * t)) / a
end function
public static double code(double x, double y, double z, double t, double a) {
	return ((x * y) - (z * t)) / a;
}
def code(x, y, z, t, a):
	return ((x * y) - (z * t)) / a
function code(x, y, z, t, a)
	return Float64(Float64(Float64(x * y) - Float64(z * t)) / a)
end
function tmp = code(x, y, z, t, a)
	tmp = ((x * y) - (z * t)) / a;
end
code[x_, y_, z_, t_, a_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
\begin{array}{l}

\\
\frac{x \cdot y - z \cdot t}{a}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 6 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 91.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{x \cdot y - z \cdot t}{a} \end{array} \]
(FPCore (x y z t a) :precision binary64 (/ (- (* x y) (* z t)) a))
double code(double x, double y, double z, double t, double a) {
	return ((x * y) - (z * t)) / a;
}
real(8) function code(x, y, z, t, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    code = ((x * y) - (z * t)) / a
end function
public static double code(double x, double y, double z, double t, double a) {
	return ((x * y) - (z * t)) / a;
}
def code(x, y, z, t, a):
	return ((x * y) - (z * t)) / a
function code(x, y, z, t, a)
	return Float64(Float64(Float64(x * y) - Float64(z * t)) / a)
end
function tmp = code(x, y, z, t, a)
	tmp = ((x * y) - (z * t)) / a;
end
code[x_, y_, z_, t_, a_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
\begin{array}{l}

\\
\frac{x \cdot y - z \cdot t}{a}
\end{array}

Alternative 1: 93.2% accurate, 0.6× speedup?

\[\begin{array}{l} a\_m = \left|a\right| \\ a\_s = \mathsf{copysign}\left(1, a\right) \\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\ \\ a\_s \cdot \begin{array}{l} \mathbf{if}\;a\_m \leq 2.1 \cdot 10^{-104}:\\ \;\;\;\;\frac{t \cdot \left(\frac{x \cdot y}{t} - z\right)}{a\_m}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y}{a\_m} - \frac{z}{\frac{a\_m}{t}}\\ \end{array} \end{array} \]
a\_m = (fabs.f64 a)
a\_s = (copysign.f64 #s(literal 1 binary64) a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
(FPCore (a_s x y z t a_m)
 :precision binary64
 (*
  a_s
  (if (<= a_m 2.1e-104)
    (/ (* t (- (/ (* x y) t) z)) a_m)
    (- (* x (/ y a_m)) (/ z (/ a_m t))))))
a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
	double tmp;
	if (a_m <= 2.1e-104) {
		tmp = (t * (((x * y) / t) - z)) / a_m;
	} else {
		tmp = (x * (y / a_m)) - (z / (a_m / t));
	}
	return a_s * tmp;
}
a\_m = abs(a)
a\_s = copysign(1.0d0, a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
real(8) function code(a_s, x, y, z, t, a_m)
    real(8), intent (in) :: a_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a_m
    real(8) :: tmp
    if (a_m <= 2.1d-104) then
        tmp = (t * (((x * y) / t) - z)) / a_m
    else
        tmp = (x * (y / a_m)) - (z / (a_m / t))
    end if
    code = a_s * tmp
end function
a\_m = Math.abs(a);
a\_s = Math.copySign(1.0, a);
assert x < y && y < z && z < t && t < a_m;
public static double code(double a_s, double x, double y, double z, double t, double a_m) {
	double tmp;
	if (a_m <= 2.1e-104) {
		tmp = (t * (((x * y) / t) - z)) / a_m;
	} else {
		tmp = (x * (y / a_m)) - (z / (a_m / t));
	}
	return a_s * tmp;
}
a\_m = math.fabs(a)
a\_s = math.copysign(1.0, a)
[x, y, z, t, a_m] = sort([x, y, z, t, a_m])
def code(a_s, x, y, z, t, a_m):
	tmp = 0
	if a_m <= 2.1e-104:
		tmp = (t * (((x * y) / t) - z)) / a_m
	else:
		tmp = (x * (y / a_m)) - (z / (a_m / t))
	return a_s * tmp
a\_m = abs(a)
a\_s = copysign(1.0, a)
x, y, z, t, a_m = sort([x, y, z, t, a_m])
function code(a_s, x, y, z, t, a_m)
	tmp = 0.0
	if (a_m <= 2.1e-104)
		tmp = Float64(Float64(t * Float64(Float64(Float64(x * y) / t) - z)) / a_m);
	else
		tmp = Float64(Float64(x * Float64(y / a_m)) - Float64(z / Float64(a_m / t)));
	end
	return Float64(a_s * tmp)
end
a\_m = abs(a);
a\_s = sign(a) * abs(1.0);
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
function tmp_2 = code(a_s, x, y, z, t, a_m)
	tmp = 0.0;
	if (a_m <= 2.1e-104)
		tmp = (t * (((x * y) / t) - z)) / a_m;
	else
		tmp = (x * (y / a_m)) - (z / (a_m / t));
	end
	tmp_2 = a_s * tmp;
end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := N[(a$95$s * If[LessEqual[a$95$m, 2.1e-104], N[(N[(t * N[(N[(N[(x * y), $MachinePrecision] / t), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision] / a$95$m), $MachinePrecision], N[(N[(x * N[(y / a$95$m), $MachinePrecision]), $MachinePrecision] - N[(z / N[(a$95$m / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;a\_m \leq 2.1 \cdot 10^{-104}:\\
\;\;\;\;\frac{t \cdot \left(\frac{x \cdot y}{t} - z\right)}{a\_m}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < 2.09999999999999999e-104

    1. Initial program 92.0%

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Add Preprocessing
    3. Taylor expanded in t around inf 89.8%

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

    if 2.09999999999999999e-104 < a

    1. Initial program 84.6%

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-sub84.6%

        \[\leadsto \color{blue}{\frac{x \cdot y}{a} - \frac{z \cdot t}{a}} \]
      2. associate-/l*94.1%

        \[\leadsto \color{blue}{x \cdot \frac{y}{a}} - \frac{z \cdot t}{a} \]
      3. associate-/l*95.8%

        \[\leadsto x \cdot \frac{y}{a} - \color{blue}{z \cdot \frac{t}{a}} \]
    4. Applied egg-rr95.8%

      \[\leadsto \color{blue}{x \cdot \frac{y}{a} - z \cdot \frac{t}{a}} \]
    5. Step-by-step derivation
      1. clear-num94.5%

        \[\leadsto x \cdot \frac{y}{a} - z \cdot \color{blue}{\frac{1}{\frac{a}{t}}} \]
      2. un-div-inv94.7%

        \[\leadsto x \cdot \frac{y}{a} - \color{blue}{\frac{z}{\frac{a}{t}}} \]
    6. Applied egg-rr94.7%

      \[\leadsto x \cdot \frac{y}{a} - \color{blue}{\frac{z}{\frac{a}{t}}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 74.4% accurate, 0.4× speedup?

\[\begin{array}{l} a\_m = \left|a\right| \\ a\_s = \mathsf{copysign}\left(1, a\right) \\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\ \\ a\_s \cdot \begin{array}{l} \mathbf{if}\;x \cdot y \leq -100000000000 \lor \neg \left(x \cdot y \leq 2000000000\right):\\ \;\;\;\;x \cdot \frac{y}{a\_m}\\ \mathbf{else}:\\ \;\;\;\;t \cdot \frac{-z}{a\_m}\\ \end{array} \end{array} \]
a\_m = (fabs.f64 a)
a\_s = (copysign.f64 #s(literal 1 binary64) a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
(FPCore (a_s x y z t a_m)
 :precision binary64
 (*
  a_s
  (if (or (<= (* x y) -100000000000.0) (not (<= (* x y) 2000000000.0)))
    (* x (/ y a_m))
    (* t (/ (- z) a_m)))))
a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
	double tmp;
	if (((x * y) <= -100000000000.0) || !((x * y) <= 2000000000.0)) {
		tmp = x * (y / a_m);
	} else {
		tmp = t * (-z / a_m);
	}
	return a_s * tmp;
}
a\_m = abs(a)
a\_s = copysign(1.0d0, a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
real(8) function code(a_s, x, y, z, t, a_m)
    real(8), intent (in) :: a_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a_m
    real(8) :: tmp
    if (((x * y) <= (-100000000000.0d0)) .or. (.not. ((x * y) <= 2000000000.0d0))) then
        tmp = x * (y / a_m)
    else
        tmp = t * (-z / a_m)
    end if
    code = a_s * tmp
end function
a\_m = Math.abs(a);
a\_s = Math.copySign(1.0, a);
assert x < y && y < z && z < t && t < a_m;
public static double code(double a_s, double x, double y, double z, double t, double a_m) {
	double tmp;
	if (((x * y) <= -100000000000.0) || !((x * y) <= 2000000000.0)) {
		tmp = x * (y / a_m);
	} else {
		tmp = t * (-z / a_m);
	}
	return a_s * tmp;
}
a\_m = math.fabs(a)
a\_s = math.copysign(1.0, a)
[x, y, z, t, a_m] = sort([x, y, z, t, a_m])
def code(a_s, x, y, z, t, a_m):
	tmp = 0
	if ((x * y) <= -100000000000.0) or not ((x * y) <= 2000000000.0):
		tmp = x * (y / a_m)
	else:
		tmp = t * (-z / a_m)
	return a_s * tmp
a\_m = abs(a)
a\_s = copysign(1.0, a)
x, y, z, t, a_m = sort([x, y, z, t, a_m])
function code(a_s, x, y, z, t, a_m)
	tmp = 0.0
	if ((Float64(x * y) <= -100000000000.0) || !(Float64(x * y) <= 2000000000.0))
		tmp = Float64(x * Float64(y / a_m));
	else
		tmp = Float64(t * Float64(Float64(-z) / a_m));
	end
	return Float64(a_s * tmp)
end
a\_m = abs(a);
a\_s = sign(a) * abs(1.0);
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
function tmp_2 = code(a_s, x, y, z, t, a_m)
	tmp = 0.0;
	if (((x * y) <= -100000000000.0) || ~(((x * y) <= 2000000000.0)))
		tmp = x * (y / a_m);
	else
		tmp = t * (-z / a_m);
	end
	tmp_2 = a_s * tmp;
end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := N[(a$95$s * If[Or[LessEqual[N[(x * y), $MachinePrecision], -100000000000.0], N[Not[LessEqual[N[(x * y), $MachinePrecision], 2000000000.0]], $MachinePrecision]], N[(x * N[(y / a$95$m), $MachinePrecision]), $MachinePrecision], N[(t * N[((-z) / a$95$m), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;x \cdot y \leq -100000000000 \lor \neg \left(x \cdot y \leq 2000000000\right):\\
\;\;\;\;x \cdot \frac{y}{a\_m}\\

\mathbf{else}:\\
\;\;\;\;t \cdot \frac{-z}{a\_m}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -1e11 or 2e9 < (*.f64 x y)

    1. Initial program 84.6%

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Add Preprocessing
    3. Taylor expanded in x around inf 70.4%

      \[\leadsto \color{blue}{\frac{x \cdot y}{a}} \]
    4. Step-by-step derivation
      1. associate-*r/77.6%

        \[\leadsto \color{blue}{x \cdot \frac{y}{a}} \]
    5. Simplified77.6%

      \[\leadsto \color{blue}{x \cdot \frac{y}{a}} \]

    if -1e11 < (*.f64 x y) < 2e9

    1. Initial program 94.1%

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 76.4%

      \[\leadsto \color{blue}{-1 \cdot \frac{t \cdot z}{a}} \]
    4. Step-by-step derivation
      1. mul-1-neg76.4%

        \[\leadsto \color{blue}{-\frac{t \cdot z}{a}} \]
      2. associate-/l*80.1%

        \[\leadsto -\color{blue}{t \cdot \frac{z}{a}} \]
      3. distribute-rgt-neg-in80.1%

        \[\leadsto \color{blue}{t \cdot \left(-\frac{z}{a}\right)} \]
      4. distribute-neg-frac280.1%

        \[\leadsto t \cdot \color{blue}{\frac{z}{-a}} \]
    5. Simplified80.1%

      \[\leadsto \color{blue}{t \cdot \frac{z}{-a}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification78.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -100000000000 \lor \neg \left(x \cdot y \leq 2000000000\right):\\ \;\;\;\;x \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;t \cdot \frac{-z}{a}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 93.7% accurate, 0.6× speedup?

\[\begin{array}{l} a\_m = \left|a\right| \\ a\_s = \mathsf{copysign}\left(1, a\right) \\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\ \\ a\_s \cdot \begin{array}{l} \mathbf{if}\;a\_m \leq 2.05 \cdot 10^{-104}:\\ \;\;\;\;\frac{x \cdot y - t \cdot z}{a\_m}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y}{a\_m} - \frac{z}{\frac{a\_m}{t}}\\ \end{array} \end{array} \]
a\_m = (fabs.f64 a)
a\_s = (copysign.f64 #s(literal 1 binary64) a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
(FPCore (a_s x y z t a_m)
 :precision binary64
 (*
  a_s
  (if (<= a_m 2.05e-104)
    (/ (- (* x y) (* t z)) a_m)
    (- (* x (/ y a_m)) (/ z (/ a_m t))))))
a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
	double tmp;
	if (a_m <= 2.05e-104) {
		tmp = ((x * y) - (t * z)) / a_m;
	} else {
		tmp = (x * (y / a_m)) - (z / (a_m / t));
	}
	return a_s * tmp;
}
a\_m = abs(a)
a\_s = copysign(1.0d0, a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
real(8) function code(a_s, x, y, z, t, a_m)
    real(8), intent (in) :: a_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a_m
    real(8) :: tmp
    if (a_m <= 2.05d-104) then
        tmp = ((x * y) - (t * z)) / a_m
    else
        tmp = (x * (y / a_m)) - (z / (a_m / t))
    end if
    code = a_s * tmp
end function
a\_m = Math.abs(a);
a\_s = Math.copySign(1.0, a);
assert x < y && y < z && z < t && t < a_m;
public static double code(double a_s, double x, double y, double z, double t, double a_m) {
	double tmp;
	if (a_m <= 2.05e-104) {
		tmp = ((x * y) - (t * z)) / a_m;
	} else {
		tmp = (x * (y / a_m)) - (z / (a_m / t));
	}
	return a_s * tmp;
}
a\_m = math.fabs(a)
a\_s = math.copysign(1.0, a)
[x, y, z, t, a_m] = sort([x, y, z, t, a_m])
def code(a_s, x, y, z, t, a_m):
	tmp = 0
	if a_m <= 2.05e-104:
		tmp = ((x * y) - (t * z)) / a_m
	else:
		tmp = (x * (y / a_m)) - (z / (a_m / t))
	return a_s * tmp
a\_m = abs(a)
a\_s = copysign(1.0, a)
x, y, z, t, a_m = sort([x, y, z, t, a_m])
function code(a_s, x, y, z, t, a_m)
	tmp = 0.0
	if (a_m <= 2.05e-104)
		tmp = Float64(Float64(Float64(x * y) - Float64(t * z)) / a_m);
	else
		tmp = Float64(Float64(x * Float64(y / a_m)) - Float64(z / Float64(a_m / t)));
	end
	return Float64(a_s * tmp)
end
a\_m = abs(a);
a\_s = sign(a) * abs(1.0);
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
function tmp_2 = code(a_s, x, y, z, t, a_m)
	tmp = 0.0;
	if (a_m <= 2.05e-104)
		tmp = ((x * y) - (t * z)) / a_m;
	else
		tmp = (x * (y / a_m)) - (z / (a_m / t));
	end
	tmp_2 = a_s * tmp;
end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := N[(a$95$s * If[LessEqual[a$95$m, 2.05e-104], N[(N[(N[(x * y), $MachinePrecision] - N[(t * z), $MachinePrecision]), $MachinePrecision] / a$95$m), $MachinePrecision], N[(N[(x * N[(y / a$95$m), $MachinePrecision]), $MachinePrecision] - N[(z / N[(a$95$m / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;a\_m \leq 2.05 \cdot 10^{-104}:\\
\;\;\;\;\frac{x \cdot y - t \cdot z}{a\_m}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < 2.04999999999999992e-104

    1. Initial program 92.0%

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Add Preprocessing

    if 2.04999999999999992e-104 < a

    1. Initial program 84.6%

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-sub84.6%

        \[\leadsto \color{blue}{\frac{x \cdot y}{a} - \frac{z \cdot t}{a}} \]
      2. associate-/l*94.1%

        \[\leadsto \color{blue}{x \cdot \frac{y}{a}} - \frac{z \cdot t}{a} \]
      3. associate-/l*95.8%

        \[\leadsto x \cdot \frac{y}{a} - \color{blue}{z \cdot \frac{t}{a}} \]
    4. Applied egg-rr95.8%

      \[\leadsto \color{blue}{x \cdot \frac{y}{a} - z \cdot \frac{t}{a}} \]
    5. Step-by-step derivation
      1. clear-num94.5%

        \[\leadsto x \cdot \frac{y}{a} - z \cdot \color{blue}{\frac{1}{\frac{a}{t}}} \]
      2. un-div-inv94.7%

        \[\leadsto x \cdot \frac{y}{a} - \color{blue}{\frac{z}{\frac{a}{t}}} \]
    6. Applied egg-rr94.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq 2.05 \cdot 10^{-104}:\\ \;\;\;\;\frac{x \cdot y - t \cdot z}{a}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y}{a} - \frac{z}{\frac{a}{t}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 93.7% accurate, 0.6× speedup?

\[\begin{array}{l} a\_m = \left|a\right| \\ a\_s = \mathsf{copysign}\left(1, a\right) \\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\ \\ a\_s \cdot \begin{array}{l} \mathbf{if}\;a\_m \leq 2.1 \cdot 10^{-104}:\\ \;\;\;\;\frac{x \cdot y - t \cdot z}{a\_m}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y}{a\_m} - z \cdot \frac{t}{a\_m}\\ \end{array} \end{array} \]
a\_m = (fabs.f64 a)
a\_s = (copysign.f64 #s(literal 1 binary64) a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
(FPCore (a_s x y z t a_m)
 :precision binary64
 (*
  a_s
  (if (<= a_m 2.1e-104)
    (/ (- (* x y) (* t z)) a_m)
    (- (* x (/ y a_m)) (* z (/ t a_m))))))
a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
	double tmp;
	if (a_m <= 2.1e-104) {
		tmp = ((x * y) - (t * z)) / a_m;
	} else {
		tmp = (x * (y / a_m)) - (z * (t / a_m));
	}
	return a_s * tmp;
}
a\_m = abs(a)
a\_s = copysign(1.0d0, a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
real(8) function code(a_s, x, y, z, t, a_m)
    real(8), intent (in) :: a_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a_m
    real(8) :: tmp
    if (a_m <= 2.1d-104) then
        tmp = ((x * y) - (t * z)) / a_m
    else
        tmp = (x * (y / a_m)) - (z * (t / a_m))
    end if
    code = a_s * tmp
end function
a\_m = Math.abs(a);
a\_s = Math.copySign(1.0, a);
assert x < y && y < z && z < t && t < a_m;
public static double code(double a_s, double x, double y, double z, double t, double a_m) {
	double tmp;
	if (a_m <= 2.1e-104) {
		tmp = ((x * y) - (t * z)) / a_m;
	} else {
		tmp = (x * (y / a_m)) - (z * (t / a_m));
	}
	return a_s * tmp;
}
a\_m = math.fabs(a)
a\_s = math.copysign(1.0, a)
[x, y, z, t, a_m] = sort([x, y, z, t, a_m])
def code(a_s, x, y, z, t, a_m):
	tmp = 0
	if a_m <= 2.1e-104:
		tmp = ((x * y) - (t * z)) / a_m
	else:
		tmp = (x * (y / a_m)) - (z * (t / a_m))
	return a_s * tmp
a\_m = abs(a)
a\_s = copysign(1.0, a)
x, y, z, t, a_m = sort([x, y, z, t, a_m])
function code(a_s, x, y, z, t, a_m)
	tmp = 0.0
	if (a_m <= 2.1e-104)
		tmp = Float64(Float64(Float64(x * y) - Float64(t * z)) / a_m);
	else
		tmp = Float64(Float64(x * Float64(y / a_m)) - Float64(z * Float64(t / a_m)));
	end
	return Float64(a_s * tmp)
end
a\_m = abs(a);
a\_s = sign(a) * abs(1.0);
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
function tmp_2 = code(a_s, x, y, z, t, a_m)
	tmp = 0.0;
	if (a_m <= 2.1e-104)
		tmp = ((x * y) - (t * z)) / a_m;
	else
		tmp = (x * (y / a_m)) - (z * (t / a_m));
	end
	tmp_2 = a_s * tmp;
end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := N[(a$95$s * If[LessEqual[a$95$m, 2.1e-104], N[(N[(N[(x * y), $MachinePrecision] - N[(t * z), $MachinePrecision]), $MachinePrecision] / a$95$m), $MachinePrecision], N[(N[(x * N[(y / a$95$m), $MachinePrecision]), $MachinePrecision] - N[(z * N[(t / a$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;a\_m \leq 2.1 \cdot 10^{-104}:\\
\;\;\;\;\frac{x \cdot y - t \cdot z}{a\_m}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < 2.09999999999999999e-104

    1. Initial program 92.0%

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Add Preprocessing

    if 2.09999999999999999e-104 < a

    1. Initial program 84.6%

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. div-sub84.6%

        \[\leadsto \color{blue}{\frac{x \cdot y}{a} - \frac{z \cdot t}{a}} \]
      2. associate-/l*94.1%

        \[\leadsto \color{blue}{x \cdot \frac{y}{a}} - \frac{z \cdot t}{a} \]
      3. associate-/l*95.8%

        \[\leadsto x \cdot \frac{y}{a} - \color{blue}{z \cdot \frac{t}{a}} \]
    4. Applied egg-rr95.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq 2.1 \cdot 10^{-104}:\\ \;\;\;\;\frac{x \cdot y - t \cdot z}{a}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y}{a} - z \cdot \frac{t}{a}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 93.2% accurate, 0.6× speedup?

\[\begin{array}{l} a\_m = \left|a\right| \\ a\_s = \mathsf{copysign}\left(1, a\right) \\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\ \\ a\_s \cdot \begin{array}{l} \mathbf{if}\;x \cdot y \leq -\infty:\\ \;\;\;\;y \cdot \frac{x}{a\_m}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y - t \cdot z}{a\_m}\\ \end{array} \end{array} \]
a\_m = (fabs.f64 a)
a\_s = (copysign.f64 #s(literal 1 binary64) a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
(FPCore (a_s x y z t a_m)
 :precision binary64
 (*
  a_s
  (if (<= (* x y) (- INFINITY)) (* y (/ x a_m)) (/ (- (* x y) (* t z)) a_m))))
a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
	double tmp;
	if ((x * y) <= -((double) INFINITY)) {
		tmp = y * (x / a_m);
	} else {
		tmp = ((x * y) - (t * z)) / a_m;
	}
	return a_s * tmp;
}
a\_m = Math.abs(a);
a\_s = Math.copySign(1.0, a);
assert x < y && y < z && z < t && t < a_m;
public static double code(double a_s, double x, double y, double z, double t, double a_m) {
	double tmp;
	if ((x * y) <= -Double.POSITIVE_INFINITY) {
		tmp = y * (x / a_m);
	} else {
		tmp = ((x * y) - (t * z)) / a_m;
	}
	return a_s * tmp;
}
a\_m = math.fabs(a)
a\_s = math.copysign(1.0, a)
[x, y, z, t, a_m] = sort([x, y, z, t, a_m])
def code(a_s, x, y, z, t, a_m):
	tmp = 0
	if (x * y) <= -math.inf:
		tmp = y * (x / a_m)
	else:
		tmp = ((x * y) - (t * z)) / a_m
	return a_s * tmp
a\_m = abs(a)
a\_s = copysign(1.0, a)
x, y, z, t, a_m = sort([x, y, z, t, a_m])
function code(a_s, x, y, z, t, a_m)
	tmp = 0.0
	if (Float64(x * y) <= Float64(-Inf))
		tmp = Float64(y * Float64(x / a_m));
	else
		tmp = Float64(Float64(Float64(x * y) - Float64(t * z)) / a_m);
	end
	return Float64(a_s * tmp)
end
a\_m = abs(a);
a\_s = sign(a) * abs(1.0);
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
function tmp_2 = code(a_s, x, y, z, t, a_m)
	tmp = 0.0;
	if ((x * y) <= -Inf)
		tmp = y * (x / a_m);
	else
		tmp = ((x * y) - (t * z)) / a_m;
	end
	tmp_2 = a_s * tmp;
end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := N[(a$95$s * If[LessEqual[N[(x * y), $MachinePrecision], (-Infinity)], N[(y * N[(x / a$95$m), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * y), $MachinePrecision] - N[(t * z), $MachinePrecision]), $MachinePrecision] / a$95$m), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;x \cdot y \leq -\infty:\\
\;\;\;\;y \cdot \frac{x}{a\_m}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -inf.0

    1. Initial program 56.6%

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Add Preprocessing
    3. Taylor expanded in y around inf 91.5%

      \[\leadsto \color{blue}{y \cdot \left(-1 \cdot \frac{t \cdot z}{a \cdot y} + \frac{x}{a}\right)} \]
    4. Step-by-step derivation
      1. +-commutative91.5%

        \[\leadsto y \cdot \color{blue}{\left(\frac{x}{a} + -1 \cdot \frac{t \cdot z}{a \cdot y}\right)} \]
      2. mul-1-neg91.5%

        \[\leadsto y \cdot \left(\frac{x}{a} + \color{blue}{\left(-\frac{t \cdot z}{a \cdot y}\right)}\right) \]
      3. unsub-neg91.5%

        \[\leadsto y \cdot \color{blue}{\left(\frac{x}{a} - \frac{t \cdot z}{a \cdot y}\right)} \]
      4. associate-/l*99.9%

        \[\leadsto y \cdot \left(\frac{x}{a} - \color{blue}{t \cdot \frac{z}{a \cdot y}}\right) \]
      5. associate-/r*91.5%

        \[\leadsto y \cdot \left(\frac{x}{a} - t \cdot \color{blue}{\frac{\frac{z}{a}}{y}}\right) \]
    5. Simplified91.5%

      \[\leadsto \color{blue}{y \cdot \left(\frac{x}{a} - t \cdot \frac{\frac{z}{a}}{y}\right)} \]
    6. Taylor expanded in x around inf 99.9%

      \[\leadsto y \cdot \color{blue}{\frac{x}{a}} \]

    if -inf.0 < (*.f64 x y)

    1. Initial program 92.9%

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification93.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -\infty:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y - t \cdot z}{a}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 51.4% accurate, 1.8× speedup?

\[\begin{array}{l} a\_m = \left|a\right| \\ a\_s = \mathsf{copysign}\left(1, a\right) \\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\ \\ a\_s \cdot \left(x \cdot \frac{y}{a\_m}\right) \end{array} \]
a\_m = (fabs.f64 a)
a\_s = (copysign.f64 #s(literal 1 binary64) a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
(FPCore (a_s x y z t a_m) :precision binary64 (* a_s (* x (/ y a_m))))
a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
	return a_s * (x * (y / a_m));
}
a\_m = abs(a)
a\_s = copysign(1.0d0, a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
real(8) function code(a_s, x, y, z, t, a_m)
    real(8), intent (in) :: a_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a_m
    code = a_s * (x * (y / a_m))
end function
a\_m = Math.abs(a);
a\_s = Math.copySign(1.0, a);
assert x < y && y < z && z < t && t < a_m;
public static double code(double a_s, double x, double y, double z, double t, double a_m) {
	return a_s * (x * (y / a_m));
}
a\_m = math.fabs(a)
a\_s = math.copysign(1.0, a)
[x, y, z, t, a_m] = sort([x, y, z, t, a_m])
def code(a_s, x, y, z, t, a_m):
	return a_s * (x * (y / a_m))
a\_m = abs(a)
a\_s = copysign(1.0, a)
x, y, z, t, a_m = sort([x, y, z, t, a_m])
function code(a_s, x, y, z, t, a_m)
	return Float64(a_s * Float64(x * Float64(y / a_m)))
end
a\_m = abs(a);
a\_s = sign(a) * abs(1.0);
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
function tmp = code(a_s, x, y, z, t, a_m)
	tmp = a_s * (x * (y / a_m));
end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := N[(a$95$s * N[(x * N[(y / a$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
a\_s \cdot \left(x \cdot \frac{y}{a\_m}\right)
\end{array}
Derivation
  1. Initial program 89.5%

    \[\frac{x \cdot y - z \cdot t}{a} \]
  2. Add Preprocessing
  3. Taylor expanded in x around inf 50.4%

    \[\leadsto \color{blue}{\frac{x \cdot y}{a}} \]
  4. Step-by-step derivation
    1. associate-*r/53.9%

      \[\leadsto \color{blue}{x \cdot \frac{y}{a}} \]
  5. Simplified53.9%

    \[\leadsto \color{blue}{x \cdot \frac{y}{a}} \]
  6. Add Preprocessing

Developer target: 91.9% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{y}{a} \cdot x - \frac{t}{a} \cdot z\\ \mathbf{if}\;z < -2.468684968699548 \cdot 10^{+170}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;z < 6.309831121978371 \cdot 10^{-71}:\\ \;\;\;\;\frac{x \cdot y - z \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (- (* (/ y a) x) (* (/ t a) z))))
   (if (< z -2.468684968699548e+170)
     t_1
     (if (< z 6.309831121978371e-71) (/ (- (* x y) (* z t)) a) t_1))))
double code(double x, double y, double z, double t, double a) {
	double t_1 = ((y / a) * x) - ((t / a) * z);
	double tmp;
	if (z < -2.468684968699548e+170) {
		tmp = t_1;
	} else if (z < 6.309831121978371e-71) {
		tmp = ((x * y) - (z * t)) / a;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(x, y, z, t, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8) :: t_1
    real(8) :: tmp
    t_1 = ((y / a) * x) - ((t / a) * z)
    if (z < (-2.468684968699548d+170)) then
        tmp = t_1
    else if (z < 6.309831121978371d-71) then
        tmp = ((x * y) - (z * t)) / a
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
	double t_1 = ((y / a) * x) - ((t / a) * z);
	double tmp;
	if (z < -2.468684968699548e+170) {
		tmp = t_1;
	} else if (z < 6.309831121978371e-71) {
		tmp = ((x * y) - (z * t)) / a;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z, t, a):
	t_1 = ((y / a) * x) - ((t / a) * z)
	tmp = 0
	if z < -2.468684968699548e+170:
		tmp = t_1
	elif z < 6.309831121978371e-71:
		tmp = ((x * y) - (z * t)) / a
	else:
		tmp = t_1
	return tmp
function code(x, y, z, t, a)
	t_1 = Float64(Float64(Float64(y / a) * x) - Float64(Float64(t / a) * z))
	tmp = 0.0
	if (z < -2.468684968699548e+170)
		tmp = t_1;
	elseif (z < 6.309831121978371e-71)
		tmp = Float64(Float64(Float64(x * y) - Float64(z * t)) / a);
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a)
	t_1 = ((y / a) * x) - ((t / a) * z);
	tmp = 0.0;
	if (z < -2.468684968699548e+170)
		tmp = t_1;
	elseif (z < 6.309831121978371e-71)
		tmp = ((x * y) - (z * t)) / a;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(N[(y / a), $MachinePrecision] * x), $MachinePrecision] - N[(N[(t / a), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]}, If[Less[z, -2.468684968699548e+170], t$95$1, If[Less[z, 6.309831121978371e-71], N[(N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], t$95$1]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{y}{a} \cdot x - \frac{t}{a} \cdot z\\
\mathbf{if}\;z < -2.468684968699548 \cdot 10^{+170}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;z < 6.309831121978371 \cdot 10^{-71}:\\
\;\;\;\;\frac{x \cdot y - z \cdot t}{a}\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}

Reproduce

?
herbie shell --seed 2024096 
(FPCore (x y z t a)
  :name "Data.Colour.Matrix:inverse from colour-2.3.3, B"
  :precision binary64

  :alt
  (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))