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

Percentage Accurate: 91.4% → 94.4%
Time: 3.9s
Alternatives: 5
Speedup: N/A×

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;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, t, a)
use fmin_fmax_functions
    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 5 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;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, t, a)
use fmin_fmax_functions
    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: 94.4% accurate, N/A× 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])\\\\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\ \\ \begin{array}{l} t_1 := \left(-z\right) \cdot \frac{t}{a\_m}\\ t_2 := \frac{x \cdot y - z \cdot t}{a\_m}\\ a\_s \cdot \begin{array}{l} \mathbf{if}\;t\_2 \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(\frac{y}{a\_m}, x, t\_1\right)\\ \mathbf{elif}\;t\_2 \leq 2 \cdot 10^{+178}:\\ \;\;\;\;t\_2\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{a\_m}, y, t\_1\right)\\ \end{array} \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.
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
 (let* ((t_1 (* (- z) (/ t a_m))) (t_2 (/ (- (* x y) (* z t)) a_m)))
   (*
    a_s
    (if (<= t_2 (- INFINITY))
      (fma (/ y a_m) x t_1)
      (if (<= t_2 2e+178) t_2 (fma (/ x a_m) y t_1))))))
a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
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 t_1 = -z * (t / a_m);
	double t_2 = ((x * y) - (z * t)) / a_m;
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = fma((y / a_m), x, t_1);
	} else if (t_2 <= 2e+178) {
		tmp = t_2;
	} else {
		tmp = fma((x / a_m), y, t_1);
	}
	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])
x, y, z, t, a_m = sort([x, y, z, t, a_m])
function code(a_s, x, y, z, t, a_m)
	t_1 = Float64(Float64(-z) * Float64(t / a_m))
	t_2 = Float64(Float64(Float64(x * y) - Float64(z * t)) / a_m)
	tmp = 0.0
	if (t_2 <= Float64(-Inf))
		tmp = fma(Float64(y / a_m), x, t_1);
	elseif (t_2 <= 2e+178)
		tmp = t_2;
	else
		tmp = fma(Float64(x / a_m), y, t_1);
	end
	return Float64(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.
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_] := Block[{t$95$1 = N[((-z) * N[(t / a$95$m), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision] / a$95$m), $MachinePrecision]}, N[(a$95$s * If[LessEqual[t$95$2, (-Infinity)], N[(N[(y / a$95$m), $MachinePrecision] * x + t$95$1), $MachinePrecision], If[LessEqual[t$95$2, 2e+178], t$95$2, N[(N[(x / a$95$m), $MachinePrecision] * y + t$95$1), $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])\\\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
\begin{array}{l}
t_1 := \left(-z\right) \cdot \frac{t}{a\_m}\\
t_2 := \frac{x \cdot y - z \cdot t}{a\_m}\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_2 \leq -\infty:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a\_m}, x, t\_1\right)\\

\mathbf{elif}\;t\_2 \leq 2 \cdot 10^{+178}:\\
\;\;\;\;t\_2\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{a\_m}, y, t\_1\right)\\


\end{array}
\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 82.7%

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{x \cdot y - z \cdot t}{a}} \]
      2. lift--.f64N/A

        \[\leadsto \frac{\color{blue}{x \cdot y - z \cdot t}}{a} \]
      3. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{x \cdot y} - z \cdot t}{a} \]
      4. lift-*.f64N/A

        \[\leadsto \frac{x \cdot y - \color{blue}{z \cdot t}}{a} \]
      5. frac-2negN/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left(x \cdot y - z \cdot t\right)\right)}{\mathsf{neg}\left(a\right)}} \]
      6. *-commutativeN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(x \cdot y - \color{blue}{t \cdot z}\right)\right)}{\mathsf{neg}\left(a\right)} \]
      7. frac-2negN/A

        \[\leadsto \color{blue}{\frac{x \cdot y - t \cdot z}{a}} \]
      8. *-commutativeN/A

        \[\leadsto \frac{x \cdot y - \color{blue}{z \cdot t}}{a} \]
      9. fp-cancel-sub-sign-invN/A

        \[\leadsto \frac{\color{blue}{x \cdot y + \left(\mathsf{neg}\left(z\right)\right) \cdot t}}{a} \]
      10. div-addN/A

        \[\leadsto \color{blue}{\frac{x \cdot y}{a} + \frac{\left(\mathsf{neg}\left(z\right)\right) \cdot t}{a}} \]
      11. *-commutativeN/A

        \[\leadsto \frac{\color{blue}{y \cdot x}}{a} + \frac{\left(\mathsf{neg}\left(z\right)\right) \cdot t}{a} \]
      12. associate-*l/N/A

        \[\leadsto \color{blue}{\frac{y}{a} \cdot x} + \frac{\left(\mathsf{neg}\left(z\right)\right) \cdot t}{a} \]
      13. distribute-lft-neg-inN/A

        \[\leadsto \frac{y}{a} \cdot x + \frac{\color{blue}{\mathsf{neg}\left(z \cdot t\right)}}{a} \]
      14. *-commutativeN/A

        \[\leadsto \frac{y}{a} \cdot x + \frac{\mathsf{neg}\left(\color{blue}{t \cdot z}\right)}{a} \]
      15. mul-1-negN/A

        \[\leadsto \frac{y}{a} \cdot x + \frac{\color{blue}{-1 \cdot \left(t \cdot z\right)}}{a} \]
      16. associate-*r/N/A

        \[\leadsto \frac{y}{a} \cdot x + \color{blue}{-1 \cdot \frac{t \cdot z}{a}} \]
      17. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{y}{a}, x, -1 \cdot \frac{t \cdot z}{a}\right)} \]
      18. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{y}{a}}, x, -1 \cdot \frac{t \cdot z}{a}\right) \]
      19. associate-*l/N/A

        \[\leadsto \mathsf{fma}\left(\frac{y}{a}, x, -1 \cdot \color{blue}{\left(\frac{t}{a} \cdot z\right)}\right) \]
      20. associate-*l*N/A

        \[\leadsto \mathsf{fma}\left(\frac{y}{a}, x, \color{blue}{\left(-1 \cdot \frac{t}{a}\right) \cdot z}\right) \]
      21. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{y}{a}, x, \color{blue}{z \cdot \left(-1 \cdot \frac{t}{a}\right)}\right) \]
      22. associate-*r*N/A

        \[\leadsto \mathsf{fma}\left(\frac{y}{a}, x, \color{blue}{\left(z \cdot -1\right) \cdot \frac{t}{a}}\right) \]
      23. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{y}{a}, x, \color{blue}{\left(-1 \cdot z\right)} \cdot \frac{t}{a}\right) \]
    4. Applied rewrites86.7%

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

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

    1. Initial program 99.0%

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

    if 2.0000000000000001e178 < (/.f64 (-.f64 (*.f64 x y) (*.f64 z t)) a)

    1. Initial program 84.3%

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{x \cdot y - z \cdot t}{a}} \]
      2. lift--.f64N/A

        \[\leadsto \frac{\color{blue}{x \cdot y - z \cdot t}}{a} \]
      3. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{x \cdot y} - z \cdot t}{a} \]
      4. lift-*.f64N/A

        \[\leadsto \frac{x \cdot y - \color{blue}{z \cdot t}}{a} \]
      5. frac-2negN/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left(x \cdot y - z \cdot t\right)\right)}{\mathsf{neg}\left(a\right)}} \]
      6. *-commutativeN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(x \cdot y - \color{blue}{t \cdot z}\right)\right)}{\mathsf{neg}\left(a\right)} \]
      7. frac-2negN/A

        \[\leadsto \color{blue}{\frac{x \cdot y - t \cdot z}{a}} \]
      8. *-commutativeN/A

        \[\leadsto \frac{x \cdot y - \color{blue}{z \cdot t}}{a} \]
      9. fp-cancel-sub-sign-invN/A

        \[\leadsto \frac{\color{blue}{x \cdot y + \left(\mathsf{neg}\left(z\right)\right) \cdot t}}{a} \]
      10. div-addN/A

        \[\leadsto \color{blue}{\frac{x \cdot y}{a} + \frac{\left(\mathsf{neg}\left(z\right)\right) \cdot t}{a}} \]
      11. associate-*l/N/A

        \[\leadsto \color{blue}{\frac{x}{a} \cdot y} + \frac{\left(\mathsf{neg}\left(z\right)\right) \cdot t}{a} \]
      12. distribute-lft-neg-inN/A

        \[\leadsto \frac{x}{a} \cdot y + \frac{\color{blue}{\mathsf{neg}\left(z \cdot t\right)}}{a} \]
      13. *-commutativeN/A

        \[\leadsto \frac{x}{a} \cdot y + \frac{\mathsf{neg}\left(\color{blue}{t \cdot z}\right)}{a} \]
      14. mul-1-negN/A

        \[\leadsto \frac{x}{a} \cdot y + \frac{\color{blue}{-1 \cdot \left(t \cdot z\right)}}{a} \]
      15. associate-*r/N/A

        \[\leadsto \frac{x}{a} \cdot y + \color{blue}{-1 \cdot \frac{t \cdot z}{a}} \]
      16. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{a}, y, -1 \cdot \frac{t \cdot z}{a}\right)} \]
      17. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{x}{a}}, y, -1 \cdot \frac{t \cdot z}{a}\right) \]
      18. associate-*l/N/A

        \[\leadsto \mathsf{fma}\left(\frac{x}{a}, y, -1 \cdot \color{blue}{\left(\frac{t}{a} \cdot z\right)}\right) \]
      19. associate-*l*N/A

        \[\leadsto \mathsf{fma}\left(\frac{x}{a}, y, \color{blue}{\left(-1 \cdot \frac{t}{a}\right) \cdot z}\right) \]
      20. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{x}{a}, y, \color{blue}{z \cdot \left(-1 \cdot \frac{t}{a}\right)}\right) \]
      21. associate-*r*N/A

        \[\leadsto \mathsf{fma}\left(\frac{x}{a}, y, \color{blue}{\left(z \cdot -1\right) \cdot \frac{t}{a}}\right) \]
      22. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{x}{a}, y, \color{blue}{\left(-1 \cdot z\right)} \cdot \frac{t}{a}\right) \]
      23. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{x}{a}, y, \color{blue}{\left(-1 \cdot z\right) \cdot \frac{t}{a}}\right) \]
    4. Applied rewrites94.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{a}, y, \left(-z\right) \cdot \frac{t}{a}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 2: 95.8% accurate, N/A× 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])\\\\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\ \\ \begin{array}{l} t_1 := x \cdot y - z \cdot t\\ a\_s \cdot \begin{array}{l} \mathbf{if}\;t\_1 \leq -4 \cdot 10^{+305} \lor \neg \left(t\_1 \leq 10^{+93}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{a\_m}, y, \left(-z\right) \cdot \frac{t}{a\_m}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{t\_1}{a\_m}\\ \end{array} \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.
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
 (let* ((t_1 (- (* x y) (* z t))))
   (*
    a_s
    (if (or (<= t_1 -4e+305) (not (<= t_1 1e+93)))
      (fma (/ x a_m) y (* (- z) (/ t a_m)))
      (/ t_1 a_m)))))
a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
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 t_1 = (x * y) - (z * t);
	double tmp;
	if ((t_1 <= -4e+305) || !(t_1 <= 1e+93)) {
		tmp = fma((x / a_m), y, (-z * (t / a_m)));
	} else {
		tmp = t_1 / 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])
x, y, z, t, a_m = sort([x, y, z, t, a_m])
function code(a_s, x, y, z, t, a_m)
	t_1 = Float64(Float64(x * y) - Float64(z * t))
	tmp = 0.0
	if ((t_1 <= -4e+305) || !(t_1 <= 1e+93))
		tmp = fma(Float64(x / a_m), y, Float64(Float64(-z) * Float64(t / a_m)));
	else
		tmp = Float64(t_1 / a_m);
	end
	return Float64(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.
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_] := Block[{t$95$1 = N[(N[(x * y), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision]}, N[(a$95$s * If[Or[LessEqual[t$95$1, -4e+305], N[Not[LessEqual[t$95$1, 1e+93]], $MachinePrecision]], N[(N[(x / a$95$m), $MachinePrecision] * y + N[((-z) * N[(t / a$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 / 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])\\\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
\begin{array}{l}
t_1 := x \cdot y - z \cdot t\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_1 \leq -4 \cdot 10^{+305} \lor \neg \left(t\_1 \leq 10^{+93}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{a\_m}, y, \left(-z\right) \cdot \frac{t}{a\_m}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{t\_1}{a\_m}\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (*.f64 x y) (*.f64 z t)) < -3.9999999999999998e305 or 1.00000000000000004e93 < (-.f64 (*.f64 x y) (*.f64 z t))

    1. Initial program 82.5%

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{x \cdot y - z \cdot t}{a}} \]
      2. lift--.f64N/A

        \[\leadsto \frac{\color{blue}{x \cdot y - z \cdot t}}{a} \]
      3. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{x \cdot y} - z \cdot t}{a} \]
      4. lift-*.f64N/A

        \[\leadsto \frac{x \cdot y - \color{blue}{z \cdot t}}{a} \]
      5. frac-2negN/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left(x \cdot y - z \cdot t\right)\right)}{\mathsf{neg}\left(a\right)}} \]
      6. *-commutativeN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(x \cdot y - \color{blue}{t \cdot z}\right)\right)}{\mathsf{neg}\left(a\right)} \]
      7. frac-2negN/A

        \[\leadsto \color{blue}{\frac{x \cdot y - t \cdot z}{a}} \]
      8. *-commutativeN/A

        \[\leadsto \frac{x \cdot y - \color{blue}{z \cdot t}}{a} \]
      9. fp-cancel-sub-sign-invN/A

        \[\leadsto \frac{\color{blue}{x \cdot y + \left(\mathsf{neg}\left(z\right)\right) \cdot t}}{a} \]
      10. div-addN/A

        \[\leadsto \color{blue}{\frac{x \cdot y}{a} + \frac{\left(\mathsf{neg}\left(z\right)\right) \cdot t}{a}} \]
      11. associate-*l/N/A

        \[\leadsto \color{blue}{\frac{x}{a} \cdot y} + \frac{\left(\mathsf{neg}\left(z\right)\right) \cdot t}{a} \]
      12. distribute-lft-neg-inN/A

        \[\leadsto \frac{x}{a} \cdot y + \frac{\color{blue}{\mathsf{neg}\left(z \cdot t\right)}}{a} \]
      13. *-commutativeN/A

        \[\leadsto \frac{x}{a} \cdot y + \frac{\mathsf{neg}\left(\color{blue}{t \cdot z}\right)}{a} \]
      14. mul-1-negN/A

        \[\leadsto \frac{x}{a} \cdot y + \frac{\color{blue}{-1 \cdot \left(t \cdot z\right)}}{a} \]
      15. associate-*r/N/A

        \[\leadsto \frac{x}{a} \cdot y + \color{blue}{-1 \cdot \frac{t \cdot z}{a}} \]
      16. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{a}, y, -1 \cdot \frac{t \cdot z}{a}\right)} \]
      17. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{x}{a}}, y, -1 \cdot \frac{t \cdot z}{a}\right) \]
      18. associate-*l/N/A

        \[\leadsto \mathsf{fma}\left(\frac{x}{a}, y, -1 \cdot \color{blue}{\left(\frac{t}{a} \cdot z\right)}\right) \]
      19. associate-*l*N/A

        \[\leadsto \mathsf{fma}\left(\frac{x}{a}, y, \color{blue}{\left(-1 \cdot \frac{t}{a}\right) \cdot z}\right) \]
      20. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{x}{a}, y, \color{blue}{z \cdot \left(-1 \cdot \frac{t}{a}\right)}\right) \]
      21. associate-*r*N/A

        \[\leadsto \mathsf{fma}\left(\frac{x}{a}, y, \color{blue}{\left(z \cdot -1\right) \cdot \frac{t}{a}}\right) \]
      22. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{x}{a}, y, \color{blue}{\left(-1 \cdot z\right)} \cdot \frac{t}{a}\right) \]
      23. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{x}{a}, y, \color{blue}{\left(-1 \cdot z\right) \cdot \frac{t}{a}}\right) \]
    4. Applied rewrites95.7%

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

    if -3.9999999999999998e305 < (-.f64 (*.f64 x y) (*.f64 z t)) < 1.00000000000000004e93

    1. Initial program 99.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y - z \cdot t \leq -4 \cdot 10^{+305} \lor \neg \left(x \cdot y - z \cdot t \leq 10^{+93}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{x}{a}, y, \left(-z\right) \cdot \frac{t}{a}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y - z \cdot t}{a}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 93.1% accurate, N/A× 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])\\\\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\ \\ a\_s \cdot \begin{array}{l} \mathbf{if}\;z \cdot t \leq 5 \cdot 10^{+270}:\\ \;\;\;\;\frac{\mathsf{fma}\left(y, x, \left(-z\right) \cdot t\right)}{a\_m}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{-1}{a\_m} \cdot t, z, \frac{x \cdot y}{a\_m}\right)\\ \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.
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 (<= (* z t) 5e+270)
    (/ (fma y x (* (- z) t)) a_m)
    (fma (* (/ -1.0 a_m) t) z (/ (* x y) a_m)))))
a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
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 ((z * t) <= 5e+270) {
		tmp = fma(y, x, (-z * t)) / a_m;
	} else {
		tmp = fma(((-1.0 / a_m) * t), z, ((x * y) / 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])
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(z * t) <= 5e+270)
		tmp = Float64(fma(y, x, Float64(Float64(-z) * t)) / a_m);
	else
		tmp = fma(Float64(Float64(-1.0 / a_m) * t), z, Float64(Float64(x * y) / a_m));
	end
	return Float64(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.
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[(z * t), $MachinePrecision], 5e+270], N[(N[(y * x + N[((-z) * t), $MachinePrecision]), $MachinePrecision] / a$95$m), $MachinePrecision], N[(N[(N[(-1.0 / a$95$m), $MachinePrecision] * t), $MachinePrecision] * z + N[(N[(x * y), $MachinePrecision] / 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])\\\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;z \cdot t \leq 5 \cdot 10^{+270}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y, x, \left(-z\right) \cdot t\right)}{a\_m}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{a\_m} \cdot t, z, \frac{x \cdot y}{a\_m}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 z t) < 4.99999999999999976e270

    1. Initial program 96.0%

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift--.f64N/A

        \[\leadsto \frac{\color{blue}{x \cdot y - z \cdot t}}{a} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{x \cdot y} - z \cdot t}{a} \]
      3. lift-*.f64N/A

        \[\leadsto \frac{x \cdot y - \color{blue}{z \cdot t}}{a} \]
      4. fp-cancel-sub-sign-invN/A

        \[\leadsto \frac{\color{blue}{x \cdot y + \left(\mathsf{neg}\left(z\right)\right) \cdot t}}{a} \]
      5. *-commutativeN/A

        \[\leadsto \frac{\color{blue}{y \cdot x} + \left(\mathsf{neg}\left(z\right)\right) \cdot t}{a} \]
      6. distribute-lft-neg-inN/A

        \[\leadsto \frac{y \cdot x + \color{blue}{\left(\mathsf{neg}\left(z \cdot t\right)\right)}}{a} \]
      7. *-commutativeN/A

        \[\leadsto \frac{y \cdot x + \left(\mathsf{neg}\left(\color{blue}{t \cdot z}\right)\right)}{a} \]
      8. mul-1-negN/A

        \[\leadsto \frac{y \cdot x + \color{blue}{-1 \cdot \left(t \cdot z\right)}}{a} \]
      9. lower-fma.f64N/A

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(y, x, -1 \cdot \left(t \cdot z\right)\right)}}{a} \]
      10. *-commutativeN/A

        \[\leadsto \frac{\mathsf{fma}\left(y, x, -1 \cdot \color{blue}{\left(z \cdot t\right)}\right)}{a} \]
      11. associate-*r*N/A

        \[\leadsto \frac{\mathsf{fma}\left(y, x, \color{blue}{\left(-1 \cdot z\right) \cdot t}\right)}{a} \]
      12. lower-*.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(y, x, \color{blue}{\left(-1 \cdot z\right) \cdot t}\right)}{a} \]
      13. mul-1-negN/A

        \[\leadsto \frac{\mathsf{fma}\left(y, x, \color{blue}{\left(\mathsf{neg}\left(z\right)\right)} \cdot t\right)}{a} \]
      14. lower-neg.f6496.4

        \[\leadsto \frac{\mathsf{fma}\left(y, x, \color{blue}{\left(-z\right)} \cdot t\right)}{a} \]
    4. Applied rewrites96.4%

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

    if 4.99999999999999976e270 < (*.f64 z t)

    1. Initial program 63.1%

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{x \cdot y - z \cdot t}{a}} \]
      2. lift--.f64N/A

        \[\leadsto \frac{\color{blue}{x \cdot y - z \cdot t}}{a} \]
      3. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{x \cdot y} - z \cdot t}{a} \]
      4. lift-*.f64N/A

        \[\leadsto \frac{x \cdot y - \color{blue}{z \cdot t}}{a} \]
      5. frac-2negN/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left(x \cdot y - z \cdot t\right)\right)}{\mathsf{neg}\left(a\right)}} \]
      6. *-commutativeN/A

        \[\leadsto \frac{\mathsf{neg}\left(\left(x \cdot y - \color{blue}{t \cdot z}\right)\right)}{\mathsf{neg}\left(a\right)} \]
      7. frac-2negN/A

        \[\leadsto \color{blue}{\frac{x \cdot y - t \cdot z}{a}} \]
      8. fp-cancel-sub-sign-invN/A

        \[\leadsto \frac{\color{blue}{x \cdot y + \left(\mathsf{neg}\left(t\right)\right) \cdot z}}{a} \]
      9. mul-1-negN/A

        \[\leadsto \frac{x \cdot y + \color{blue}{\left(-1 \cdot t\right)} \cdot z}{a} \]
      10. associate-*r*N/A

        \[\leadsto \frac{x \cdot y + \color{blue}{-1 \cdot \left(t \cdot z\right)}}{a} \]
      11. +-commutativeN/A

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(t \cdot z\right) + x \cdot y}}{a} \]
      12. div-add-revN/A

        \[\leadsto \color{blue}{\frac{-1 \cdot \left(t \cdot z\right)}{a} + \frac{x \cdot y}{a}} \]
      13. associate-*r/N/A

        \[\leadsto \color{blue}{-1 \cdot \frac{t \cdot z}{a}} + \frac{x \cdot y}{a} \]
      14. associate-/l*N/A

        \[\leadsto -1 \cdot \color{blue}{\left(t \cdot \frac{z}{a}\right)} + \frac{x \cdot y}{a} \]
      15. *-commutativeN/A

        \[\leadsto -1 \cdot \color{blue}{\left(\frac{z}{a} \cdot t\right)} + \frac{x \cdot y}{a} \]
      16. associate-*l*N/A

        \[\leadsto \color{blue}{\left(-1 \cdot \frac{z}{a}\right) \cdot t} + \frac{x \cdot y}{a} \]
      17. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(-1 \cdot \frac{z}{a}, t, \frac{x \cdot y}{a}\right)} \]
      18. associate-*r/N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{-1 \cdot z}{a}}, t, \frac{x \cdot y}{a}\right) \]
      19. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{-1 \cdot z}{a}}, t, \frac{x \cdot y}{a}\right) \]
      20. mul-1-negN/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{\mathsf{neg}\left(z\right)}}{a}, t, \frac{x \cdot y}{a}\right) \]
      21. lower-neg.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{\color{blue}{-z}}{a}, t, \frac{x \cdot y}{a}\right) \]
      22. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{-z}{a}, t, \color{blue}{\frac{x \cdot y}{a}}\right) \]
    4. Applied rewrites92.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-z}{a}, t, \frac{y \cdot x}{a}\right)} \]
    5. Step-by-step derivation
      1. lift-fma.f64N/A

        \[\leadsto \color{blue}{\frac{-z}{a} \cdot t + \frac{y \cdot x}{a}} \]
      2. lift-neg.f64N/A

        \[\leadsto \frac{\color{blue}{\mathsf{neg}\left(z\right)}}{a} \cdot t + \frac{y \cdot x}{a} \]
      3. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(z\right)}{a}} \cdot t + \frac{y \cdot x}{a} \]
      4. associate-*l/N/A

        \[\leadsto \color{blue}{\frac{\left(\mathsf{neg}\left(z\right)\right) \cdot t}{a}} + \frac{y \cdot x}{a} \]
      5. distribute-lft-neg-outN/A

        \[\leadsto \frac{\color{blue}{\mathsf{neg}\left(z \cdot t\right)}}{a} + \frac{y \cdot x}{a} \]
      6. *-commutativeN/A

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{t \cdot z}\right)}{a} + \frac{y \cdot x}{a} \]
      7. mul-1-negN/A

        \[\leadsto \frac{\color{blue}{-1 \cdot \left(t \cdot z\right)}}{a} + \frac{y \cdot x}{a} \]
      8. *-commutativeN/A

        \[\leadsto \frac{\color{blue}{\left(t \cdot z\right) \cdot -1}}{a} + \frac{y \cdot x}{a} \]
      9. associate-*r/N/A

        \[\leadsto \color{blue}{\left(t \cdot z\right) \cdot \frac{-1}{a}} + \frac{y \cdot x}{a} \]
      10. *-commutativeN/A

        \[\leadsto \color{blue}{\frac{-1}{a} \cdot \left(t \cdot z\right)} + \frac{y \cdot x}{a} \]
      11. associate-*r*N/A

        \[\leadsto \color{blue}{\left(\frac{-1}{a} \cdot t\right) \cdot z} + \frac{y \cdot x}{a} \]
      12. lift-*.f64N/A

        \[\leadsto \left(\frac{-1}{a} \cdot t\right) \cdot z + \frac{\color{blue}{y \cdot x}}{a} \]
      13. *-commutativeN/A

        \[\leadsto \left(\frac{-1}{a} \cdot t\right) \cdot z + \frac{\color{blue}{x \cdot y}}{a} \]
      14. lower-/.f64N/A

        \[\leadsto \left(\frac{-1}{a} \cdot t\right) \cdot z + \color{blue}{\frac{x \cdot y}{a}} \]
      15. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-1}{a} \cdot t, z, \frac{x \cdot y}{a}\right)} \]
      16. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{-1}{a} \cdot t}, z, \frac{x \cdot y}{a}\right) \]
      17. lift-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\frac{-1}{a}} \cdot t, z, \frac{x \cdot y}{a}\right) \]
      18. lower-/.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{-1}{a} \cdot t, z, \color{blue}{\frac{x \cdot y}{a}}\right) \]
      19. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{-1}{a} \cdot t, z, \frac{\color{blue}{y \cdot x}}{a}\right) \]
      20. lift-*.f6492.4

        \[\leadsto \mathsf{fma}\left(\frac{-1}{a} \cdot t, z, \frac{\color{blue}{y \cdot x}}{a}\right) \]
      21. lift-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{-1}{a} \cdot t, z, \frac{\color{blue}{y \cdot x}}{a}\right) \]
      22. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\frac{-1}{a} \cdot t, z, \frac{\color{blue}{x \cdot y}}{a}\right) \]
      23. lower-*.f6492.4

        \[\leadsto \mathsf{fma}\left(\frac{-1}{a} \cdot t, z, \frac{\color{blue}{x \cdot y}}{a}\right) \]
    6. Applied rewrites92.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-1}{a} \cdot t, z, \frac{x \cdot y}{a}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 91.8% accurate, N/A× 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])\\\\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\ \\ a\_s \cdot \frac{\mathsf{fma}\left(y, x, \left(-z\right) \cdot t\right)}{a\_m} \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.
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 (/ (fma y x (* (- z) t)) a_m)))
a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
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 * (fma(y, x, (-z * t)) / 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])
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(fma(y, x, Float64(Float64(-z) * t)) / 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.
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[(N[(y * x + N[((-z) * t), $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])\\\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
a\_s \cdot \frac{\mathsf{fma}\left(y, x, \left(-z\right) \cdot t\right)}{a\_m}
\end{array}
Derivation
  1. Initial program 92.6%

    \[\frac{x \cdot y - z \cdot t}{a} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift--.f64N/A

      \[\leadsto \frac{\color{blue}{x \cdot y - z \cdot t}}{a} \]
    2. lift-*.f64N/A

      \[\leadsto \frac{\color{blue}{x \cdot y} - z \cdot t}{a} \]
    3. lift-*.f64N/A

      \[\leadsto \frac{x \cdot y - \color{blue}{z \cdot t}}{a} \]
    4. fp-cancel-sub-sign-invN/A

      \[\leadsto \frac{\color{blue}{x \cdot y + \left(\mathsf{neg}\left(z\right)\right) \cdot t}}{a} \]
    5. *-commutativeN/A

      \[\leadsto \frac{\color{blue}{y \cdot x} + \left(\mathsf{neg}\left(z\right)\right) \cdot t}{a} \]
    6. distribute-lft-neg-inN/A

      \[\leadsto \frac{y \cdot x + \color{blue}{\left(\mathsf{neg}\left(z \cdot t\right)\right)}}{a} \]
    7. *-commutativeN/A

      \[\leadsto \frac{y \cdot x + \left(\mathsf{neg}\left(\color{blue}{t \cdot z}\right)\right)}{a} \]
    8. mul-1-negN/A

      \[\leadsto \frac{y \cdot x + \color{blue}{-1 \cdot \left(t \cdot z\right)}}{a} \]
    9. lower-fma.f64N/A

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(y, x, -1 \cdot \left(t \cdot z\right)\right)}}{a} \]
    10. *-commutativeN/A

      \[\leadsto \frac{\mathsf{fma}\left(y, x, -1 \cdot \color{blue}{\left(z \cdot t\right)}\right)}{a} \]
    11. associate-*r*N/A

      \[\leadsto \frac{\mathsf{fma}\left(y, x, \color{blue}{\left(-1 \cdot z\right) \cdot t}\right)}{a} \]
    12. lower-*.f64N/A

      \[\leadsto \frac{\mathsf{fma}\left(y, x, \color{blue}{\left(-1 \cdot z\right) \cdot t}\right)}{a} \]
    13. mul-1-negN/A

      \[\leadsto \frac{\mathsf{fma}\left(y, x, \color{blue}{\left(\mathsf{neg}\left(z\right)\right)} \cdot t\right)}{a} \]
    14. lower-neg.f6493.0

      \[\leadsto \frac{\mathsf{fma}\left(y, x, \color{blue}{\left(-z\right)} \cdot t\right)}{a} \]
  4. Applied rewrites93.0%

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

Alternative 5: 91.4% accurate, N/A× 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])\\\\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\ \\ a\_s \cdot \frac{x \cdot y - z \cdot t}{a\_m} \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.
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) (* z t)) a_m)))
a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
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) - (z * t)) / a_m);
}
a\_m =     private
a\_s =     private
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(a_s, x, y, z, t, a_m)
use fmin_fmax_functions
    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) - (z * t)) / 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;
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) - (z * t)) / 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])
[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) - (z * t)) / 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])
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(Float64(Float64(x * y) - Float64(z * t)) / 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])){:}
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) - (z * t)) / 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.
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[(N[(N[(x * y), $MachinePrecision] - N[(z * t), $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])\\\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
a\_s \cdot \frac{x \cdot y - z \cdot t}{a\_m}
\end{array}
Derivation
  1. Initial program 92.6%

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

Reproduce

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

  :alt
  (! :herbie-platform default (if (< z -246868496869954800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (- (* (/ y a) x) (* (/ t a) z)) (if (< z 6309831121978371/100000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (/ (- (* x y) (* z t)) a) (- (* (/ y a) x) (* (/ t a) z)))))

  (/ (- (* x y) (* z t)) a))