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

Percentage Accurate: 91.0% → 93.9%
Time: 2.9s
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;
}
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}

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.0% 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: 93.9% accurate, 0.6× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < 3.1999999999999999e108

    1. Initial program 91.0%

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

    if 3.1999999999999999e108 < a

    1. Initial program 91.0%

      \[\frac{x \cdot y - z \cdot t}{a} \]
    2. 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{x \cdot y - \color{blue}{z \cdot t}}{a} \]
      4. lift--.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{x}{a}, y, \left(-z\right) \cdot \left(t \cdot \color{blue}{\frac{-1}{\mathsf{neg}\left(a\right)}}\right)\right) \]
      8. lower-neg.f6487.6

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\frac{x}{a}, y, \frac{t \cdot \color{blue}{\left(\mathsf{neg}\left(z\right)\right)}}{a}\right) \]
      13. distribute-rgt-neg-outN/A

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

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

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

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

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

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

        \[\leadsto \frac{x}{a} \cdot y + \color{blue}{\left(\mathsf{neg}\left(t\right)\right) \cdot \frac{z}{a}} \]
      20. fp-cancel-sub-sign-invN/A

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

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

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

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

Alternative 2: 92.8% accurate, 0.7× speedup?

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

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


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

    1. Initial program 91.0%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{t \cdot z}{a}} \]
    5. Step-by-step derivation
      1. div-subN/A

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

        \[\leadsto -1 \cdot \frac{t \cdot z}{a} \]
      3. associate-/l*N/A

        \[\leadsto -1 \cdot \frac{t \cdot z}{a} \]
      4. fp-cancel-sub-signN/A

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

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

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

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

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

        \[\leadsto \left(-t\right) \cdot \frac{\color{blue}{z}}{a} \]
      10. lower-/.f6451.1

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

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

    if -inf.0 < (*.f64 z t)

    1. Initial program 91.0%

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

Alternative 3: 73.2% accurate, 0.6× speedup?

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

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

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


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 z t) < -9.99999999999999921e80 or 1.00000000000000005e26 < (*.f64 z t)

    1. Initial program 91.0%

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{t \cdot z}{a}} \]
    5. Step-by-step derivation
      1. div-subN/A

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

        \[\leadsto -1 \cdot \frac{t \cdot z}{a} \]
      3. associate-/l*N/A

        \[\leadsto -1 \cdot \frac{t \cdot z}{a} \]
      4. fp-cancel-sub-signN/A

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

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

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

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

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

        \[\leadsto \left(-t\right) \cdot \frac{\color{blue}{z}}{a} \]
      10. lower-/.f6451.1

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

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

    if -9.99999999999999921e80 < (*.f64 z t) < 1.00000000000000005e26

    1. Initial program 91.0%

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

      \[\leadsto \color{blue}{\frac{x \cdot y}{a}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

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

        \[\leadsto \frac{y \cdot x}{a} \]
      3. lower-*.f6450.7

        \[\leadsto \frac{y \cdot x}{a} \]
    4. Applied rewrites50.7%

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

Alternative 4: 51.8% accurate, 1.2× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if t < 2.90000000000000014e91

    1. Initial program 91.0%

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

      \[\leadsto \color{blue}{\frac{x \cdot y}{a}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

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

        \[\leadsto \frac{y \cdot x}{a} \]
      3. lower-*.f6450.7

        \[\leadsto \frac{y \cdot x}{a} \]
    4. Applied rewrites50.7%

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

    if 2.90000000000000014e91 < t

    1. Initial program 91.0%

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

      \[\leadsto \color{blue}{\frac{x \cdot y}{a}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

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

        \[\leadsto \frac{y \cdot x}{a} \]
      3. lower-*.f6450.7

        \[\leadsto \frac{y \cdot x}{a} \]
    4. Applied rewrites50.7%

      \[\leadsto \color{blue}{\frac{y \cdot x}{a}} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

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

        \[\leadsto \frac{y \cdot x}{\color{blue}{a}} \]
      3. associate-/l*N/A

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

        \[\leadsto \frac{x}{a} \cdot \color{blue}{y} \]
      5. lower-*.f64N/A

        \[\leadsto \frac{x}{a} \cdot \color{blue}{y} \]
      6. lift-/.f6451.8

        \[\leadsto \frac{x}{a} \cdot y \]
    6. Applied rewrites51.8%

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

Alternative 5: 51.8% accurate, 1.2× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.79999999999999997e242

    1. Initial program 91.0%

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

      \[\leadsto \color{blue}{\frac{x \cdot y}{a}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

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

        \[\leadsto \frac{y \cdot x}{a} \]
      3. lower-*.f6450.7

        \[\leadsto \frac{y \cdot x}{a} \]
    4. Applied rewrites50.7%

      \[\leadsto \color{blue}{\frac{y \cdot x}{a}} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

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

        \[\leadsto \frac{y \cdot x}{\color{blue}{a}} \]
      3. associate-*l/N/A

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

        \[\leadsto \frac{y}{a} \cdot \color{blue}{x} \]
      5. lower-/.f6451.7

        \[\leadsto \frac{y}{a} \cdot x \]
    6. Applied rewrites51.7%

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

    if -1.79999999999999997e242 < x

    1. Initial program 91.0%

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

      \[\leadsto \color{blue}{\frac{x \cdot y}{a}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

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

        \[\leadsto \frac{y \cdot x}{a} \]
      3. lower-*.f6450.7

        \[\leadsto \frac{y \cdot x}{a} \]
    4. Applied rewrites50.7%

      \[\leadsto \color{blue}{\frac{y \cdot x}{a}} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

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

        \[\leadsto \frac{y \cdot x}{\color{blue}{a}} \]
      3. associate-/l*N/A

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

        \[\leadsto \frac{x}{a} \cdot \color{blue}{y} \]
      5. lower-*.f64N/A

        \[\leadsto \frac{x}{a} \cdot \color{blue}{y} \]
      6. lift-/.f6451.8

        \[\leadsto \frac{x}{a} \cdot y \]
    6. Applied rewrites51.8%

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

Alternative 6: 51.1% accurate, 1.8× speedup?

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

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

    \[\leadsto \color{blue}{\frac{x \cdot y}{a}} \]
  3. Step-by-step derivation
    1. lower-/.f64N/A

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

      \[\leadsto \frac{y \cdot x}{a} \]
    3. lower-*.f6450.7

      \[\leadsto \frac{y \cdot x}{a} \]
  4. Applied rewrites50.7%

    \[\leadsto \color{blue}{\frac{y \cdot x}{a}} \]
  5. Step-by-step derivation
    1. lift-*.f64N/A

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

      \[\leadsto \frac{y \cdot x}{\color{blue}{a}} \]
    3. associate-/l*N/A

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

      \[\leadsto \frac{x}{a} \cdot \color{blue}{y} \]
    5. lower-*.f64N/A

      \[\leadsto \frac{x}{a} \cdot \color{blue}{y} \]
    6. lift-/.f6451.8

      \[\leadsto \frac{x}{a} \cdot y \]
  6. Applied rewrites51.8%

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

Reproduce

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