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

Percentage Accurate: 91.4% → 97.1%
Time: 6.6s
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.4% 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: 97.1% accurate, 0.3× speedup?

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

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

\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)) < -1.0000000000000001e272 or 1e280 < (-.f64 (*.f64 x y) (*.f64 z t))

    1. Initial program 73.0%

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

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

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

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

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

    if -1.0000000000000001e272 < (-.f64 (*.f64 x y) (*.f64 z t)) < 1e280

    1. Initial program 97.5%

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

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

Alternative 2: 93.4% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \cdot x \leq 2 \cdot 10^{+307}:\\
\;\;\;\;\frac{y \cdot x - t \cdot z}{a}\\

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


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

    1. Initial program 93.0%

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

    if 1.99999999999999997e307 < (*.f64 x y)

    1. Initial program 52.1%

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

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

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

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

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

Alternative 3: 87.2% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.24 \cdot 10^{-85}:\\
\;\;\;\;\frac{y}{\frac{a}{x}} - \frac{t}{a} \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 1.23999999999999995e-85

    1. Initial program 87.7%

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

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

        \[\leadsto \frac{\color{blue}{y \cdot x}}{a} - \frac{z \cdot t}{a} \]
      3. add-cube-cbrt85.0%

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

        \[\leadsto \color{blue}{\frac{y}{\sqrt[3]{a} \cdot \sqrt[3]{a}} \cdot \frac{x}{\sqrt[3]{a}}} - \frac{z \cdot t}{a} \]
      5. fma-neg90.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{\sqrt[3]{a} \cdot \sqrt[3]{a}}, \frac{x}{\sqrt[3]{a}}, -\frac{z \cdot t}{a}\right)} \]
      6. pow290.0%

        \[\leadsto \mathsf{fma}\left(\frac{y}{\color{blue}{{\left(\sqrt[3]{a}\right)}^{2}}}, \frac{x}{\sqrt[3]{a}}, -\frac{z \cdot t}{a}\right) \]
      7. associate-/l*91.1%

        \[\leadsto \mathsf{fma}\left(\frac{y}{{\left(\sqrt[3]{a}\right)}^{2}}, \frac{x}{\sqrt[3]{a}}, -\color{blue}{\frac{z}{\frac{a}{t}}}\right) \]
    3. Applied egg-rr91.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{{\left(\sqrt[3]{a}\right)}^{2}}, \frac{x}{\sqrt[3]{a}}, -\frac{z}{\frac{a}{t}}\right)} \]
    4. Step-by-step derivation
      1. fma-neg90.5%

        \[\leadsto \color{blue}{\frac{y}{{\left(\sqrt[3]{a}\right)}^{2}} \cdot \frac{x}{\sqrt[3]{a}} - \frac{z}{\frac{a}{t}}} \]
      2. associate-/l*89.4%

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

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

        \[\leadsto \frac{y}{{\left(\sqrt[3]{a}\right)}^{2}} \cdot \frac{x}{\sqrt[3]{a}} - \color{blue}{\frac{t}{\frac{a}{z}}} \]
      5. associate-/r/91.0%

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

      \[\leadsto \color{blue}{\frac{y}{{\left(\sqrt[3]{a}\right)}^{2}} \cdot \frac{x}{\sqrt[3]{a}} - \frac{t}{a} \cdot z} \]
    6. Step-by-step derivation
      1. frac-times86.1%

        \[\leadsto \color{blue}{\frac{y \cdot x}{{\left(\sqrt[3]{a}\right)}^{2} \cdot \sqrt[3]{a}}} - \frac{t}{a} \cdot z \]
      2. unpow286.1%

        \[\leadsto \frac{y \cdot x}{\color{blue}{\left(\sqrt[3]{a} \cdot \sqrt[3]{a}\right)} \cdot \sqrt[3]{a}} - \frac{t}{a} \cdot z \]
      3. add-cube-cbrt86.5%

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

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

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

    if 1.23999999999999995e-85 < y

    1. Initial program 94.1%

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

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

Alternative 4: 65.0% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;t \leq -2.7 \cdot 10^{-101} \lor \neg \left(t \leq 3.8 \cdot 10^{+67}\right):\\ \;\;\;\;\left(-t\right) \cdot \frac{z}{a}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \end{array} \end{array} \]
(FPCore (x y z t a)
 :precision binary64
 (if (or (<= t -2.7e-101) (not (<= t 3.8e+67)))
   (* (- t) (/ z a))
   (* y (/ x a))))
double code(double x, double y, double z, double t, double a) {
	double tmp;
	if ((t <= -2.7e-101) || !(t <= 3.8e+67)) {
		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 ((t <= (-2.7d-101)) .or. (.not. (t <= 3.8d+67))) 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 ((t <= -2.7e-101) || !(t <= 3.8e+67)) {
		tmp = -t * (z / a);
	} else {
		tmp = y * (x / a);
	}
	return tmp;
}
def code(x, y, z, t, a):
	tmp = 0
	if (t <= -2.7e-101) or not (t <= 3.8e+67):
		tmp = -t * (z / a)
	else:
		tmp = y * (x / a)
	return tmp
function code(x, y, z, t, a)
	tmp = 0.0
	if ((t <= -2.7e-101) || !(t <= 3.8e+67))
		tmp = Float64(Float64(-t) * 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 ((t <= -2.7e-101) || ~((t <= 3.8e+67)))
		tmp = -t * (z / a);
	else
		tmp = y * (x / a);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[t, -2.7e-101], N[Not[LessEqual[t, 3.8e+67]], $MachinePrecision]], N[((-t) * N[(z / a), $MachinePrecision]), $MachinePrecision], N[(y * N[(x / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;t \leq -2.7 \cdot 10^{-101} \lor \neg \left(t \leq 3.8 \cdot 10^{+67}\right):\\
\;\;\;\;\left(-t\right) \cdot \frac{z}{a}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if t < -2.7000000000000002e-101 or 3.8000000000000002e67 < t

    1. Initial program 87.0%

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

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

        \[\leadsto \color{blue}{-\frac{t \cdot z}{a}} \]
      2. *-commutative64.7%

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

        \[\leadsto -\color{blue}{\frac{z}{a} \cdot t} \]
      4. *-commutative69.0%

        \[\leadsto -\color{blue}{t \cdot \frac{z}{a}} \]
      5. distribute-lft-neg-in69.0%

        \[\leadsto \color{blue}{\left(-t\right) \cdot \frac{z}{a}} \]
    4. Simplified69.0%

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

    if -2.7000000000000002e-101 < t < 3.8000000000000002e67

    1. Initial program 93.6%

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

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

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

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

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

Alternative 5: 65.8% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;t \leq -2.6 \cdot 10^{-97}:\\
\;\;\;\;\left(-t\right) \cdot \frac{z}{a}\\

\mathbf{elif}\;t \leq 2.75 \cdot 10^{+23}:\\
\;\;\;\;y \cdot \frac{x}{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{t}{a} \cdot \left(-z\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if t < -2.60000000000000007e-97

    1. Initial program 92.2%

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

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

        \[\leadsto \color{blue}{-\frac{t \cdot z}{a}} \]
      2. *-commutative63.8%

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

        \[\leadsto -\color{blue}{\frac{z}{a} \cdot t} \]
      4. *-commutative66.7%

        \[\leadsto -\color{blue}{t \cdot \frac{z}{a}} \]
      5. distribute-lft-neg-in66.7%

        \[\leadsto \color{blue}{\left(-t\right) \cdot \frac{z}{a}} \]
    4. Simplified66.7%

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

    if -2.60000000000000007e-97 < t < 2.75000000000000002e23

    1. Initial program 93.3%

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

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

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

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

    if 2.75000000000000002e23 < t

    1. Initial program 81.0%

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

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

        \[\leadsto \color{blue}{\frac{-1 \cdot \left(t \cdot z\right)}{a}} \]
      2. associate-*r*65.1%

        \[\leadsto \frac{\color{blue}{\left(-1 \cdot t\right) \cdot z}}{a} \]
      3. neg-mul-165.1%

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

      \[\leadsto \color{blue}{\frac{\left(-t\right) \cdot z}{a}} \]
    5. Step-by-step derivation
      1. distribute-lft-neg-out65.1%

        \[\leadsto \frac{\color{blue}{-t \cdot z}}{a} \]
      2. distribute-frac-neg65.1%

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

        \[\leadsto -\color{blue}{\frac{t}{a} \cdot z} \]
      4. distribute-rgt-neg-in69.4%

        \[\leadsto \color{blue}{\frac{t}{a} \cdot \left(-z\right)} \]
    6. Applied egg-rr69.4%

      \[\leadsto \color{blue}{\frac{t}{a} \cdot \left(-z\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification69.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \leq -2.6 \cdot 10^{-97}:\\ \;\;\;\;\left(-t\right) \cdot \frac{z}{a}\\ \mathbf{elif}\;t \leq 2.75 \cdot 10^{+23}:\\ \;\;\;\;y \cdot \frac{x}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{t}{a} \cdot \left(-z\right)\\ \end{array} \]

Alternative 6: 51.7% 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 89.8%

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

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

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

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

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

Developer target: 91.1% 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 2023268 
(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))