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

Percentage Accurate: 91.8% → 95.9%
Time: 11.7s
Alternatives: 6
Speedup: 0.7×

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.8% 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: 95.9% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{x \cdot y - z \cdot t}{a}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;x \cdot \frac{y}{a} - t \cdot \frac{z}{a}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+287}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{a}{x - \frac{t}{\frac{y}{z}}}}\\ \end{array} \end{array} \]
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (/ (- (* x y) (* z t)) a)))
   (if (<= t_1 (- INFINITY))
     (- (* x (/ y a)) (* t (/ z a)))
     (if (<= t_1 2e+287) t_1 (/ y (/ a (- x (/ t (/ y z)))))))))
double code(double x, double y, double z, double t, double a) {
	double t_1 = ((x * y) - (z * t)) / a;
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = (x * (y / a)) - (t * (z / a));
	} else if (t_1 <= 2e+287) {
		tmp = t_1;
	} else {
		tmp = y / (a / (x - (t / (y / z))));
	}
	return tmp;
}
public static double code(double x, double y, double z, double t, double a) {
	double t_1 = ((x * y) - (z * t)) / a;
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = (x * (y / a)) - (t * (z / a));
	} else if (t_1 <= 2e+287) {
		tmp = t_1;
	} else {
		tmp = y / (a / (x - (t / (y / z))));
	}
	return tmp;
}
def code(x, y, z, t, a):
	t_1 = ((x * y) - (z * t)) / a
	tmp = 0
	if t_1 <= -math.inf:
		tmp = (x * (y / a)) - (t * (z / a))
	elif t_1 <= 2e+287:
		tmp = t_1
	else:
		tmp = y / (a / (x - (t / (y / z))))
	return tmp
function code(x, y, z, t, a)
	t_1 = Float64(Float64(Float64(x * y) - Float64(z * t)) / a)
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(Float64(x * Float64(y / a)) - Float64(t * Float64(z / a)));
	elseif (t_1 <= 2e+287)
		tmp = t_1;
	else
		tmp = Float64(y / Float64(a / Float64(x - Float64(t / Float64(y / z)))));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a)
	t_1 = ((x * y) - (z * t)) / a;
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = (x * (y / a)) - (t * (z / a));
	elseif (t_1 <= 2e+287)
		tmp = t_1;
	else
		tmp = y / (a / (x - (t / (y / z))));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(x * N[(y / a), $MachinePrecision]), $MachinePrecision] - N[(t * N[(z / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e+287], t$95$1, N[(y / N[(a / N[(x - N[(t / N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{x \cdot y - z \cdot t}{a}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;x \cdot \frac{y}{a} - t \cdot \frac{z}{a}\\

\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+287}:\\
\;\;\;\;t_1\\

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


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

    1. Initial program 79.7%

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Step-by-step derivation
      1. div-sub75.8%

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

        \[\leadsto \color{blue}{\frac{x}{\frac{a}{y}}} - \frac{z \cdot t}{a} \]
      3. *-commutative86.9%

        \[\leadsto \frac{x}{\frac{a}{y}} - \frac{\color{blue}{t \cdot z}}{a} \]
      4. *-un-lft-identity86.9%

        \[\leadsto \frac{x}{\frac{a}{y}} - \frac{t \cdot z}{\color{blue}{1 \cdot a}} \]
      5. times-frac96.0%

        \[\leadsto \frac{x}{\frac{a}{y}} - \color{blue}{\frac{t}{1} \cdot \frac{z}{a}} \]
    3. Applied egg-rr96.0%

      \[\leadsto \color{blue}{\frac{x}{\frac{a}{y}} - t \cdot \frac{z}{a}} \]
    4. Step-by-step derivation
      1. div-inv96.0%

        \[\leadsto \color{blue}{x \cdot \frac{1}{\frac{a}{y}}} - t \cdot \frac{z}{a} \]
      2. *-commutative96.0%

        \[\leadsto \color{blue}{\frac{1}{\frac{a}{y}} \cdot x} - t \cdot \frac{z}{a} \]
      3. clear-num96.1%

        \[\leadsto \color{blue}{\frac{y}{a}} \cdot x - t \cdot \frac{z}{a} \]
    5. Applied egg-rr96.1%

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

    if -inf.0 < (/.f64 (-.f64 (*.f64 x y) (*.f64 z t)) a) < 2.0000000000000002e287

    1. Initial program 98.1%

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

    if 2.0000000000000002e287 < (/.f64 (-.f64 (*.f64 x y) (*.f64 z t)) a)

    1. Initial program 82.1%

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Step-by-step derivation
      1. div-sub77.9%

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

        \[\leadsto \color{blue}{\frac{x}{\frac{a}{y}}} - \frac{z \cdot t}{a} \]
      3. *-commutative79.4%

        \[\leadsto \frac{x}{\frac{a}{y}} - \frac{\color{blue}{t \cdot z}}{a} \]
      4. *-un-lft-identity79.4%

        \[\leadsto \frac{x}{\frac{a}{y}} - \frac{t \cdot z}{\color{blue}{1 \cdot a}} \]
      5. times-frac81.2%

        \[\leadsto \frac{x}{\frac{a}{y}} - \color{blue}{\frac{t}{1} \cdot \frac{z}{a}} \]
    3. Applied egg-rr81.2%

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

        \[\leadsto \frac{x}{\frac{a}{y}} - \color{blue}{\frac{t \cdot z}{a}} \]
      2. *-commutative79.4%

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

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

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

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

      \[\leadsto \color{blue}{\frac{y \cdot \left(x - \frac{t \cdot z}{y}\right)}{a}} \]
    7. Step-by-step derivation
      1. associate-/l*94.1%

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

        \[\leadsto \frac{y}{\frac{a}{x - \color{blue}{\frac{t}{\frac{y}{z}}}}} \]
    8. Simplified96.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x \cdot y - z \cdot t}{a} \leq -\infty:\\ \;\;\;\;x \cdot \frac{y}{a} - t \cdot \frac{z}{a}\\ \mathbf{elif}\;\frac{x \cdot y - z \cdot t}{a} \leq 2 \cdot 10^{+287}:\\ \;\;\;\;\frac{x \cdot y - z \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{a}{x - \frac{t}{\frac{y}{z}}}}\\ \end{array} \]

Alternative 2: 96.3% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := x \cdot y - z \cdot t\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{+221} \lor \neg \left(t_1 \leq 5 \cdot 10^{+259}\right):\\ \;\;\;\;x \cdot \frac{y}{a} - t \cdot \frac{z}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1}{a}\\ \end{array} \end{array} \]
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (- (* x y) (* z t))))
   (if (or (<= t_1 -5e+221) (not (<= t_1 5e+259)))
     (- (* x (/ y a)) (* t (/ z a)))
     (/ t_1 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+221) || !(t_1 <= 5e+259)) {
		tmp = (x * (y / a)) - (t * (z / a));
	} else {
		tmp = t_1 / a;
	}
	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 = (x * y) - (z * t)
    if ((t_1 <= (-5d+221)) .or. (.not. (t_1 <= 5d+259))) then
        tmp = (x * (y / a)) - (t * (z / a))
    else
        tmp = t_1 / a
    end if
    code = tmp
end function
public static 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+221) || !(t_1 <= 5e+259)) {
		tmp = (x * (y / a)) - (t * (z / a));
	} else {
		tmp = t_1 / a;
	}
	return tmp;
}
def code(x, y, z, t, a):
	t_1 = (x * y) - (z * t)
	tmp = 0
	if (t_1 <= -5e+221) or not (t_1 <= 5e+259):
		tmp = (x * (y / a)) - (t * (z / a))
	else:
		tmp = t_1 / a
	return tmp
function code(x, y, z, t, a)
	t_1 = Float64(Float64(x * y) - Float64(z * t))
	tmp = 0.0
	if ((t_1 <= -5e+221) || !(t_1 <= 5e+259))
		tmp = Float64(Float64(x * Float64(y / a)) - Float64(t * Float64(z / a)));
	else
		tmp = Float64(t_1 / a);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a)
	t_1 = (x * y) - (z * t);
	tmp = 0.0;
	if ((t_1 <= -5e+221) || ~((t_1 <= 5e+259)))
		tmp = (x * (y / a)) - (t * (z / a));
	else
		tmp = t_1 / a;
	end
	tmp_2 = tmp;
end
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+221], N[Not[LessEqual[t$95$1, 5e+259]], $MachinePrecision]], N[(N[(x * N[(y / a), $MachinePrecision]), $MachinePrecision] - N[(t * N[(z / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 / a), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := x \cdot y - z \cdot t\\
\mathbf{if}\;t_1 \leq -5 \cdot 10^{+221} \lor \neg \left(t_1 \leq 5 \cdot 10^{+259}\right):\\
\;\;\;\;x \cdot \frac{y}{a} - t \cdot \frac{z}{a}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (*.f64 x y) (*.f64 z t)) < -5.0000000000000002e221 or 5.00000000000000033e259 < (-.f64 (*.f64 x y) (*.f64 z t))

    1. Initial program 78.4%

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

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

        \[\leadsto \color{blue}{\frac{x}{\frac{a}{y}}} - \frac{z \cdot t}{a} \]
      3. *-commutative86.8%

        \[\leadsto \frac{x}{\frac{a}{y}} - \frac{\color{blue}{t \cdot z}}{a} \]
      4. *-un-lft-identity86.8%

        \[\leadsto \frac{x}{\frac{a}{y}} - \frac{t \cdot z}{\color{blue}{1 \cdot a}} \]
      5. times-frac94.2%

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

      \[\leadsto \color{blue}{\frac{x}{\frac{a}{y}} - t \cdot \frac{z}{a}} \]
    4. Step-by-step derivation
      1. div-inv94.2%

        \[\leadsto \color{blue}{x \cdot \frac{1}{\frac{a}{y}}} - t \cdot \frac{z}{a} \]
      2. *-commutative94.2%

        \[\leadsto \color{blue}{\frac{1}{\frac{a}{y}} \cdot x} - t \cdot \frac{z}{a} \]
      3. clear-num94.3%

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

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

    if -5.0000000000000002e221 < (-.f64 (*.f64 x y) (*.f64 z t)) < 5.00000000000000033e259

    1. Initial program 98.3%

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

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

Alternative 3: 96.5% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := x \cdot y - z \cdot t\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{+250}:\\ \;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+259}:\\ \;\;\;\;\frac{t_1}{a}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y}{a} - t \cdot \frac{z}{a}\\ \end{array} \end{array} \]
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (- (* x y) (* z t))))
   (if (<= t_1 -5e+250)
     (- (/ x (/ a y)) (/ z (/ a t)))
     (if (<= t_1 5e+259) (/ t_1 a) (- (* x (/ y a)) (* t (/ z 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+250) {
		tmp = (x / (a / y)) - (z / (a / t));
	} else if (t_1 <= 5e+259) {
		tmp = t_1 / a;
	} else {
		tmp = (x * (y / a)) - (t * (z / a));
	}
	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 = (x * y) - (z * t)
    if (t_1 <= (-5d+250)) then
        tmp = (x / (a / y)) - (z / (a / t))
    else if (t_1 <= 5d+259) then
        tmp = t_1 / a
    else
        tmp = (x * (y / a)) - (t * (z / a))
    end if
    code = tmp
end function
public static 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+250) {
		tmp = (x / (a / y)) - (z / (a / t));
	} else if (t_1 <= 5e+259) {
		tmp = t_1 / a;
	} else {
		tmp = (x * (y / a)) - (t * (z / a));
	}
	return tmp;
}
def code(x, y, z, t, a):
	t_1 = (x * y) - (z * t)
	tmp = 0
	if t_1 <= -5e+250:
		tmp = (x / (a / y)) - (z / (a / t))
	elif t_1 <= 5e+259:
		tmp = t_1 / a
	else:
		tmp = (x * (y / a)) - (t * (z / a))
	return tmp
function code(x, y, z, t, a)
	t_1 = Float64(Float64(x * y) - Float64(z * t))
	tmp = 0.0
	if (t_1 <= -5e+250)
		tmp = Float64(Float64(x / Float64(a / y)) - Float64(z / Float64(a / t)));
	elseif (t_1 <= 5e+259)
		tmp = Float64(t_1 / a);
	else
		tmp = Float64(Float64(x * Float64(y / a)) - Float64(t * Float64(z / a)));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a)
	t_1 = (x * y) - (z * t);
	tmp = 0.0;
	if (t_1 <= -5e+250)
		tmp = (x / (a / y)) - (z / (a / t));
	elseif (t_1 <= 5e+259)
		tmp = t_1 / a;
	else
		tmp = (x * (y / a)) - (t * (z / a));
	end
	tmp_2 = tmp;
end
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, -5e+250], N[(N[(x / N[(a / y), $MachinePrecision]), $MachinePrecision] - N[(z / N[(a / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e+259], N[(t$95$1 / a), $MachinePrecision], N[(N[(x * N[(y / a), $MachinePrecision]), $MachinePrecision] - N[(t * N[(z / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := x \cdot y - z \cdot t\\
\mathbf{if}\;t_1 \leq -5 \cdot 10^{+250}:\\
\;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\

\mathbf{elif}\;t_1 \leq 5 \cdot 10^{+259}:\\
\;\;\;\;\frac{t_1}{a}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (-.f64 (*.f64 x y) (*.f64 z t)) < -5.0000000000000002e250

    1. Initial program 76.5%

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Step-by-step derivation
      1. div-sub76.5%

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

        \[\leadsto \color{blue}{\frac{x}{\frac{a}{y}}} - \frac{z \cdot t}{a} \]
      3. *-commutative92.1%

        \[\leadsto \frac{x}{\frac{a}{y}} - \frac{\color{blue}{t \cdot z}}{a} \]
      4. *-un-lft-identity92.1%

        \[\leadsto \frac{x}{\frac{a}{y}} - \frac{t \cdot z}{\color{blue}{1 \cdot a}} \]
      5. times-frac97.1%

        \[\leadsto \frac{x}{\frac{a}{y}} - \color{blue}{\frac{t}{1} \cdot \frac{z}{a}} \]
    3. Applied egg-rr97.1%

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

        \[\leadsto \frac{x}{\frac{a}{y}} - \color{blue}{\frac{t \cdot z}{a}} \]
      2. *-commutative92.1%

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

        \[\leadsto \frac{x}{\frac{a}{y}} - \color{blue}{\frac{z}{\frac{a}{t}}} \]
    5. Applied egg-rr97.2%

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

    if -5.0000000000000002e250 < (-.f64 (*.f64 x y) (*.f64 z t)) < 5.00000000000000033e259

    1. Initial program 98.4%

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

    if 5.00000000000000033e259 < (-.f64 (*.f64 x y) (*.f64 z t))

    1. Initial program 74.9%

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Step-by-step derivation
      1. div-sub72.5%

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

        \[\leadsto \color{blue}{\frac{x}{\frac{a}{y}}} - \frac{z \cdot t}{a} \]
      3. *-commutative79.1%

        \[\leadsto \frac{x}{\frac{a}{y}} - \frac{\color{blue}{t \cdot z}}{a} \]
      4. *-un-lft-identity79.1%

        \[\leadsto \frac{x}{\frac{a}{y}} - \frac{t \cdot z}{\color{blue}{1 \cdot a}} \]
      5. times-frac90.3%

        \[\leadsto \frac{x}{\frac{a}{y}} - \color{blue}{\frac{t}{1} \cdot \frac{z}{a}} \]
    3. Applied egg-rr90.3%

      \[\leadsto \color{blue}{\frac{x}{\frac{a}{y}} - t \cdot \frac{z}{a}} \]
    4. Step-by-step derivation
      1. div-inv90.4%

        \[\leadsto \color{blue}{x \cdot \frac{1}{\frac{a}{y}}} - t \cdot \frac{z}{a} \]
      2. *-commutative90.4%

        \[\leadsto \color{blue}{\frac{1}{\frac{a}{y}} \cdot x} - t \cdot \frac{z}{a} \]
      3. clear-num90.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y - z \cdot t \leq -5 \cdot 10^{+250}:\\ \;\;\;\;\frac{x}{\frac{a}{y}} - \frac{z}{\frac{a}{t}}\\ \mathbf{elif}\;x \cdot y - z \cdot t \leq 5 \cdot 10^{+259}:\\ \;\;\;\;\frac{x \cdot y - z \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{y}{a} - t \cdot \frac{z}{a}\\ \end{array} \]

Alternative 4: 73.2% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+49}:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \mathbf{elif}\;x \cdot y \leq 10^{+35}:\\ \;\;\;\;t \cdot \frac{-z}{a}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \end{array} \end{array} \]
(FPCore (x y z t a)
 :precision binary64
 (if (<= (* x y) -1e+49)
   (/ x (/ a y))
   (if (<= (* x y) 1e+35) (* t (/ (- z) a)) (* y (/ x a)))))
double code(double x, double y, double z, double t, double a) {
	double tmp;
	if ((x * y) <= -1e+49) {
		tmp = x / (a / y);
	} else if ((x * y) <= 1e+35) {
		tmp = t * (-z / a);
	} else {
		tmp = y * (x / a);
	}
	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) :: tmp
    if ((x * y) <= (-1d+49)) then
        tmp = x / (a / y)
    else if ((x * y) <= 1d+35) then
        tmp = t * (-z / a)
    else
        tmp = y * (x / a)
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
	double tmp;
	if ((x * y) <= -1e+49) {
		tmp = x / (a / y);
	} else if ((x * y) <= 1e+35) {
		tmp = t * (-z / a);
	} else {
		tmp = y * (x / a);
	}
	return tmp;
}
def code(x, y, z, t, a):
	tmp = 0
	if (x * y) <= -1e+49:
		tmp = x / (a / y)
	elif (x * y) <= 1e+35:
		tmp = t * (-z / a)
	else:
		tmp = y * (x / a)
	return tmp
function code(x, y, z, t, a)
	tmp = 0.0
	if (Float64(x * y) <= -1e+49)
		tmp = Float64(x / Float64(a / y));
	elseif (Float64(x * y) <= 1e+35)
		tmp = Float64(t * Float64(Float64(-z) / a));
	else
		tmp = Float64(y * Float64(x / a));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a)
	tmp = 0.0;
	if ((x * y) <= -1e+49)
		tmp = x / (a / y);
	elseif ((x * y) <= 1e+35)
		tmp = t * (-z / a);
	else
		tmp = y * (x / a);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_] := If[LessEqual[N[(x * y), $MachinePrecision], -1e+49], N[(x / N[(a / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(x * y), $MachinePrecision], 1e+35], N[(t * N[((-z) / a), $MachinePrecision]), $MachinePrecision], N[(y * N[(x / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+49}:\\
\;\;\;\;\frac{x}{\frac{a}{y}}\\

\mathbf{elif}\;x \cdot y \leq 10^{+35}:\\
\;\;\;\;t \cdot \frac{-z}{a}\\

\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x}{a}\\


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

    1. Initial program 80.7%

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{1 \cdot y}{\frac{a}{x}}} \]
      3. *-un-lft-identity79.6%

        \[\leadsto \frac{\color{blue}{y}}{\frac{a}{x}} \]
    6. Applied egg-rr79.6%

      \[\leadsto \color{blue}{\frac{y}{\frac{a}{x}}} \]
    7. Step-by-step derivation
      1. div-inv79.5%

        \[\leadsto \color{blue}{y \cdot \frac{1}{\frac{a}{x}}} \]
      2. add-sqr-sqrt35.6%

        \[\leadsto \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \cdot \frac{1}{\frac{a}{x}} \]
      3. associate-*l*35.7%

        \[\leadsto \color{blue}{\sqrt{y} \cdot \left(\sqrt{y} \cdot \frac{1}{\frac{a}{x}}\right)} \]
      4. clear-num35.7%

        \[\leadsto \sqrt{y} \cdot \left(\sqrt{y} \cdot \color{blue}{\frac{x}{a}}\right) \]
    8. Applied egg-rr35.7%

      \[\leadsto \color{blue}{\sqrt{y} \cdot \left(\sqrt{y} \cdot \frac{x}{a}\right)} \]
    9. Step-by-step derivation
      1. associate-*r*35.6%

        \[\leadsto \color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right) \cdot \frac{x}{a}} \]
      2. *-commutative35.6%

        \[\leadsto \color{blue}{\frac{x}{a} \cdot \left(\sqrt{y} \cdot \sqrt{y}\right)} \]
    10. Simplified35.6%

      \[\leadsto \color{blue}{\frac{x}{a} \cdot \left(\sqrt{y} \cdot \sqrt{y}\right)} \]
    11. Step-by-step derivation
      1. rem-square-sqrt79.6%

        \[\leadsto \frac{x}{a} \cdot \color{blue}{y} \]
      2. associate-/r/80.9%

        \[\leadsto \color{blue}{\frac{x}{\frac{a}{y}}} \]
    12. Applied egg-rr80.9%

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

    if -9.99999999999999946e48 < (*.f64 x y) < 9.9999999999999997e34

    1. Initial program 93.5%

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

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

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

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

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

        \[\leadsto t \cdot \color{blue}{\frac{-z}{a}} \]
    4. Simplified79.2%

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

    if 9.9999999999999997e34 < (*.f64 x y)

    1. Initial program 94.3%

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

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

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

      \[\leadsto \color{blue}{\frac{x}{a} \cdot y} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification82.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+49}:\\ \;\;\;\;\frac{x}{\frac{a}{y}}\\ \mathbf{elif}\;x \cdot y \leq 10^{+35}:\\ \;\;\;\;t \cdot \frac{-z}{a}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \end{array} \]

Alternative 5: 93.5% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -\infty:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y - z \cdot t}{a}\\ \end{array} \end{array} \]
(FPCore (x y z t a)
 :precision binary64
 (if (<= (* x y) (- INFINITY)) (* y (/ x a)) (/ (- (* x y) (* z t)) a)))
double code(double x, double y, double z, double t, double a) {
	double tmp;
	if ((x * y) <= -((double) INFINITY)) {
		tmp = y * (x / a);
	} else {
		tmp = ((x * y) - (z * t)) / a;
	}
	return tmp;
}
public static double code(double x, double y, double z, double t, double a) {
	double tmp;
	if ((x * y) <= -Double.POSITIVE_INFINITY) {
		tmp = y * (x / a);
	} else {
		tmp = ((x * y) - (z * t)) / a;
	}
	return tmp;
}
def code(x, y, z, t, a):
	tmp = 0
	if (x * y) <= -math.inf:
		tmp = y * (x / a)
	else:
		tmp = ((x * y) - (z * t)) / a
	return tmp
function code(x, y, z, t, a)
	tmp = 0.0
	if (Float64(x * y) <= Float64(-Inf))
		tmp = Float64(y * Float64(x / a));
	else
		tmp = Float64(Float64(Float64(x * y) - Float64(z * t)) / a);
	end
	return tmp
end
function tmp_2 = code(x, y, z, t, a)
	tmp = 0.0;
	if ((x * y) <= -Inf)
		tmp = y * (x / a);
	else
		tmp = ((x * y) - (z * t)) / a;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_] := If[LessEqual[N[(x * y), $MachinePrecision], (-Infinity)], N[(y * N[(x / a), $MachinePrecision]), $MachinePrecision], N[(N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -\infty:\\
\;\;\;\;y \cdot \frac{x}{a}\\

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


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

    1. Initial program 52.2%

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

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

        \[\leadsto \color{blue}{\frac{x}{a} \cdot y} \]
    4. Simplified94.4%

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

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

    1. Initial program 94.4%

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

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

Alternative 6: 50.9% accurate, 1.8× speedup?

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

\\
y \cdot \frac{x}{a}
\end{array}
Derivation
  1. Initial program 91.4%

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

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

      \[\leadsto \color{blue}{\frac{x}{a} \cdot y} \]
  4. Simplified52.3%

    \[\leadsto \color{blue}{\frac{x}{a} \cdot y} \]
  5. Final simplification52.3%

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

Developer target: 91.2% accurate, 0.6× 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 2023301 
(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))