Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, A

Percentage Accurate: 95.8% → 98.8%
Time: 3.9s
Alternatives: 5
Speedup: N/A×

Specification

?
\[\begin{array}{l} \\ \left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* (* a 27.0) b)))
double code(double x, double y, double z, double t, double a, double b) {
	return ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b);
}
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, b)
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
    real(8), intent (in) :: b
    code = ((x * 2.0d0) - (((y * 9.0d0) * z) * t)) + ((a * 27.0d0) * b)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	return ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b);
}
def code(x, y, z, t, a, b):
	return ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b)
function code(x, y, z, t, a, b)
	return Float64(Float64(Float64(x * 2.0) - Float64(Float64(Float64(y * 9.0) * z) * t)) + Float64(Float64(a * 27.0) * b))
end
function tmp = code(x, y, z, t, a, b)
	tmp = ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b);
end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * 2.0), $MachinePrecision] - N[(N[(N[(y * 9.0), $MachinePrecision] * z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision] + N[(N[(a * 27.0), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b
\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: 95.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* (* a 27.0) b)))
double code(double x, double y, double z, double t, double a, double b) {
	return ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b);
}
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, b)
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
    real(8), intent (in) :: b
    code = ((x * 2.0d0) - (((y * 9.0d0) * z) * t)) + ((a * 27.0d0) * b)
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	return ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b);
}
def code(x, y, z, t, a, b):
	return ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b)
function code(x, y, z, t, a, b)
	return Float64(Float64(Float64(x * 2.0) - Float64(Float64(Float64(y * 9.0) * z) * t)) + Float64(Float64(a * 27.0) * b))
end
function tmp = code(x, y, z, t, a, b)
	tmp = ((x * 2.0) - (((y * 9.0) * z) * t)) + ((a * 27.0) * b);
end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * 2.0), $MachinePrecision] - N[(N[(N[(y * 9.0), $MachinePrecision] * z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision] + N[(N[(a * 27.0), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b
\end{array}

Alternative 1: 98.8% accurate, N/A× speedup?

\[\begin{array}{l} [x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\\\ [x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\ \\ \begin{array}{l} \mathbf{if}\;t \leq 10^{-91}:\\ \;\;\;\;\left(x \cdot 2 - \left(t \cdot y\right) \cdot \left(z \cdot 9\right)\right) + \left(a \cdot 27\right) \cdot b\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(b \cdot 27, a, \mathsf{fma}\left(-9 \cdot t, z \cdot y, 2 \cdot x\right)\right)\\ \end{array} \end{array} \]
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
(FPCore (x y z t a b)
 :precision binary64
 (if (<= t 1e-91)
   (+ (- (* x 2.0) (* (* t y) (* z 9.0))) (* (* a 27.0) b))
   (fma (* b 27.0) a (fma (* -9.0 t) (* z y) (* 2.0 x)))))
assert(x < y && y < z && z < t && t < a && a < b);
assert(x < y && y < z && z < t && t < a && a < b);
double code(double x, double y, double z, double t, double a, double b) {
	double tmp;
	if (t <= 1e-91) {
		tmp = ((x * 2.0) - ((t * y) * (z * 9.0))) + ((a * 27.0) * b);
	} else {
		tmp = fma((b * 27.0), a, fma((-9.0 * t), (z * y), (2.0 * x)));
	}
	return tmp;
}
x, y, z, t, a, b = sort([x, y, z, t, a, b])
x, y, z, t, a, b = sort([x, y, z, t, a, b])
function code(x, y, z, t, a, b)
	tmp = 0.0
	if (t <= 1e-91)
		tmp = Float64(Float64(Float64(x * 2.0) - Float64(Float64(t * y) * Float64(z * 9.0))) + Float64(Float64(a * 27.0) * b));
	else
		tmp = fma(Float64(b * 27.0), a, fma(Float64(-9.0 * t), Float64(z * y), Float64(2.0 * x)));
	end
	return tmp
end
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_, a_, b_] := If[LessEqual[t, 1e-91], N[(N[(N[(x * 2.0), $MachinePrecision] - N[(N[(t * y), $MachinePrecision] * N[(z * 9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(a * 27.0), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision], N[(N[(b * 27.0), $MachinePrecision] * a + N[(N[(-9.0 * t), $MachinePrecision] * N[(z * y), $MachinePrecision] + N[(2.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\\\
[x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\
\\
\begin{array}{l}
\mathbf{if}\;t \leq 10^{-91}:\\
\;\;\;\;\left(x \cdot 2 - \left(t \cdot y\right) \cdot \left(z \cdot 9\right)\right) + \left(a \cdot 27\right) \cdot b\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(b \cdot 27, a, \mathsf{fma}\left(-9 \cdot t, z \cdot y, 2 \cdot x\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if t < 1.00000000000000002e-91

    1. Initial program 94.0%

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

        \[\leadsto \left(x \cdot 2 - \color{blue}{t \cdot \left(\left(y \cdot 9\right) \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b \]
      3. lift-*.f64N/A

        \[\leadsto \left(x \cdot 2 - t \cdot \color{blue}{\left(\left(y \cdot 9\right) \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b \]
      4. lift-*.f64N/A

        \[\leadsto \left(x \cdot 2 - t \cdot \left(\color{blue}{\left(y \cdot 9\right)} \cdot z\right)\right) + \left(a \cdot 27\right) \cdot b \]
      5. associate-*l*N/A

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

        \[\leadsto \left(x \cdot 2 - \color{blue}{\left(t \cdot y\right) \cdot \left(9 \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b \]
      7. lower-*.f64N/A

        \[\leadsto \left(x \cdot 2 - \color{blue}{\left(t \cdot y\right) \cdot \left(9 \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b \]
      8. lower-*.f64N/A

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

        \[\leadsto \left(x \cdot 2 - \left(t \cdot y\right) \cdot \color{blue}{\left(z \cdot 9\right)}\right) + \left(a \cdot 27\right) \cdot b \]
      10. lower-*.f6496.5

        \[\leadsto \left(x \cdot 2 - \left(t \cdot y\right) \cdot \color{blue}{\left(z \cdot 9\right)}\right) + \left(a \cdot 27\right) \cdot b \]
    4. Applied rewrites96.5%

      \[\leadsto \left(x \cdot 2 - \color{blue}{\left(t \cdot y\right) \cdot \left(z \cdot 9\right)}\right) + \left(a \cdot 27\right) \cdot b \]

    if 1.00000000000000002e-91 < t

    1. Initial program 96.1%

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto \color{blue}{\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b} \]
      2. lift--.f64N/A

        \[\leadsto \color{blue}{\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right)} + \left(a \cdot 27\right) \cdot b \]
      3. lift-*.f64N/A

        \[\leadsto \left(\color{blue}{x \cdot 2} - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
      4. lift-*.f64N/A

        \[\leadsto \left(x \cdot 2 - \color{blue}{\left(\left(y \cdot 9\right) \cdot z\right) \cdot t}\right) + \left(a \cdot 27\right) \cdot b \]
      5. lift-*.f64N/A

        \[\leadsto \left(x \cdot 2 - \color{blue}{\left(\left(y \cdot 9\right) \cdot z\right)} \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
      6. lift-*.f64N/A

        \[\leadsto \left(x \cdot 2 - \left(\color{blue}{\left(y \cdot 9\right)} \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
      7. +-commutativeN/A

        \[\leadsto \color{blue}{\left(a \cdot 27\right) \cdot b + \left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right)} \]
      8. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(a \cdot 27\right) \cdot b} + \left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) \]
      9. lift-*.f64N/A

        \[\leadsto \color{blue}{\left(a \cdot 27\right)} \cdot b + \left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) \]
      10. associate-*l*N/A

        \[\leadsto \color{blue}{a \cdot \left(27 \cdot b\right)} + \left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) \]
      11. *-commutativeN/A

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(27 \cdot b, a, x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right)} \]
      13. *-commutativeN/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{b \cdot 27}, a, x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) \]
      14. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{b \cdot 27}, a, x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) \]
      15. *-commutativeN/A

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

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

        \[\leadsto \mathsf{fma}\left(b \cdot 27, a, 2 \cdot x - \color{blue}{\left(9 \cdot \left(y \cdot z\right)\right)} \cdot t\right) \]
      18. cancel-sign-sub-invN/A

        \[\leadsto \mathsf{fma}\left(b \cdot 27, a, \color{blue}{2 \cdot x + \left(\mathsf{neg}\left(9 \cdot \left(y \cdot z\right)\right)\right) \cdot t}\right) \]
    4. Applied rewrites98.6%

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

Alternative 2: 96.3% accurate, N/A× speedup?

\[\begin{array}{l} [x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\\\ [x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\ \\ \mathsf{fma}\left(b \cdot 27, a, \mathsf{fma}\left(\left(z \cdot t\right) \cdot -9, y, 2 \cdot x\right)\right) \end{array} \]
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
(FPCore (x y z t a b)
 :precision binary64
 (fma (* b 27.0) a (fma (* (* z t) -9.0) y (* 2.0 x))))
assert(x < y && y < z && z < t && t < a && a < b);
assert(x < y && y < z && z < t && t < a && a < b);
double code(double x, double y, double z, double t, double a, double b) {
	return fma((b * 27.0), a, fma(((z * t) * -9.0), y, (2.0 * x)));
}
x, y, z, t, a, b = sort([x, y, z, t, a, b])
x, y, z, t, a, b = sort([x, y, z, t, a, b])
function code(x, y, z, t, a, b)
	return fma(Float64(b * 27.0), a, fma(Float64(Float64(z * t) * -9.0), y, Float64(2.0 * x)))
end
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_, a_, b_] := N[(N[(b * 27.0), $MachinePrecision] * a + N[(N[(N[(z * t), $MachinePrecision] * -9.0), $MachinePrecision] * y + N[(2.0 * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\\\
[x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\
\\
\mathsf{fma}\left(b \cdot 27, a, \mathsf{fma}\left(\left(z \cdot t\right) \cdot -9, y, 2 \cdot x\right)\right)
\end{array}
Derivation
  1. Initial program 94.7%

    \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-*.f64N/A

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

      \[\leadsto \left(x \cdot 2 - \color{blue}{t \cdot \left(\left(y \cdot 9\right) \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b \]
    3. lift-*.f64N/A

      \[\leadsto \left(x \cdot 2 - t \cdot \color{blue}{\left(\left(y \cdot 9\right) \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b \]
    4. lift-*.f64N/A

      \[\leadsto \left(x \cdot 2 - t \cdot \left(\color{blue}{\left(y \cdot 9\right)} \cdot z\right)\right) + \left(a \cdot 27\right) \cdot b \]
    5. associate-*l*N/A

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

      \[\leadsto \left(x \cdot 2 - \color{blue}{\left(t \cdot y\right) \cdot \left(9 \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b \]
    7. lower-*.f64N/A

      \[\leadsto \left(x \cdot 2 - \color{blue}{\left(t \cdot y\right) \cdot \left(9 \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b \]
    8. lower-*.f64N/A

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

      \[\leadsto \left(x \cdot 2 - \left(t \cdot y\right) \cdot \color{blue}{\left(z \cdot 9\right)}\right) + \left(a \cdot 27\right) \cdot b \]
    10. lower-*.f6495.6

      \[\leadsto \left(x \cdot 2 - \left(t \cdot y\right) \cdot \color{blue}{\left(z \cdot 9\right)}\right) + \left(a \cdot 27\right) \cdot b \]
  4. Applied rewrites95.6%

    \[\leadsto \left(x \cdot 2 - \color{blue}{\left(t \cdot y\right) \cdot \left(z \cdot 9\right)}\right) + \left(a \cdot 27\right) \cdot b \]
  5. Applied rewrites96.1%

    \[\leadsto \color{blue}{\mathsf{fma}\left(b \cdot 27, a, \mathsf{fma}\left(\left(z \cdot t\right) \cdot -9, y, 2 \cdot x\right)\right)} \]
  6. Add Preprocessing

Alternative 3: 96.3% accurate, N/A× speedup?

\[\begin{array}{l} [x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\\\ [x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\ \\ \mathsf{fma}\left(b \cdot 27, a, \mathsf{fma}\left(y \cdot \left(t \cdot z\right), -9, x \cdot 2\right)\right) \end{array} \]
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
(FPCore (x y z t a b)
 :precision binary64
 (fma (* b 27.0) a (fma (* y (* t z)) -9.0 (* x 2.0))))
assert(x < y && y < z && z < t && t < a && a < b);
assert(x < y && y < z && z < t && t < a && a < b);
double code(double x, double y, double z, double t, double a, double b) {
	return fma((b * 27.0), a, fma((y * (t * z)), -9.0, (x * 2.0)));
}
x, y, z, t, a, b = sort([x, y, z, t, a, b])
x, y, z, t, a, b = sort([x, y, z, t, a, b])
function code(x, y, z, t, a, b)
	return fma(Float64(b * 27.0), a, fma(Float64(y * Float64(t * z)), -9.0, Float64(x * 2.0)))
end
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_, a_, b_] := N[(N[(b * 27.0), $MachinePrecision] * a + N[(N[(y * N[(t * z), $MachinePrecision]), $MachinePrecision] * -9.0 + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\\\
[x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\
\\
\mathsf{fma}\left(b \cdot 27, a, \mathsf{fma}\left(y \cdot \left(t \cdot z\right), -9, x \cdot 2\right)\right)
\end{array}
Derivation
  1. Initial program 94.7%

    \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-*.f64N/A

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

      \[\leadsto \left(x \cdot 2 - \color{blue}{t \cdot \left(\left(y \cdot 9\right) \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b \]
    3. lift-*.f64N/A

      \[\leadsto \left(x \cdot 2 - t \cdot \color{blue}{\left(\left(y \cdot 9\right) \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b \]
    4. lift-*.f64N/A

      \[\leadsto \left(x \cdot 2 - t \cdot \left(\color{blue}{\left(y \cdot 9\right)} \cdot z\right)\right) + \left(a \cdot 27\right) \cdot b \]
    5. associate-*l*N/A

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

      \[\leadsto \left(x \cdot 2 - \color{blue}{\left(t \cdot y\right) \cdot \left(9 \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b \]
    7. lower-*.f64N/A

      \[\leadsto \left(x \cdot 2 - \color{blue}{\left(t \cdot y\right) \cdot \left(9 \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b \]
    8. lower-*.f64N/A

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

      \[\leadsto \left(x \cdot 2 - \left(t \cdot y\right) \cdot \color{blue}{\left(z \cdot 9\right)}\right) + \left(a \cdot 27\right) \cdot b \]
    10. lower-*.f6495.6

      \[\leadsto \left(x \cdot 2 - \left(t \cdot y\right) \cdot \color{blue}{\left(z \cdot 9\right)}\right) + \left(a \cdot 27\right) \cdot b \]
  4. Applied rewrites95.6%

    \[\leadsto \left(x \cdot 2 - \color{blue}{\left(t \cdot y\right) \cdot \left(z \cdot 9\right)}\right) + \left(a \cdot 27\right) \cdot b \]
  5. Applied rewrites96.1%

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

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

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

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

      \[\leadsto \mathsf{fma}\left(b \cdot 27, a, y \cdot \color{blue}{\left(\left(z \cdot t\right) \cdot -9\right)} + 2 \cdot x\right) \]
    5. associate-*r*N/A

      \[\leadsto \mathsf{fma}\left(b \cdot 27, a, \color{blue}{\left(y \cdot \left(z \cdot t\right)\right) \cdot -9} + 2 \cdot x\right) \]
    6. lower-fma.f64N/A

      \[\leadsto \mathsf{fma}\left(b \cdot 27, a, \color{blue}{\mathsf{fma}\left(y \cdot \left(z \cdot t\right), -9, 2 \cdot x\right)}\right) \]
    7. lower-*.f64N/A

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

      \[\leadsto \mathsf{fma}\left(b \cdot 27, a, \mathsf{fma}\left(y \cdot \color{blue}{\left(z \cdot t\right)}, -9, 2 \cdot x\right)\right) \]
    9. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(b \cdot 27, a, \mathsf{fma}\left(y \cdot \color{blue}{\left(t \cdot z\right)}, -9, 2 \cdot x\right)\right) \]
    10. lower-*.f64N/A

      \[\leadsto \mathsf{fma}\left(b \cdot 27, a, \mathsf{fma}\left(y \cdot \color{blue}{\left(t \cdot z\right)}, -9, 2 \cdot x\right)\right) \]
    11. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(b \cdot 27, a, \mathsf{fma}\left(y \cdot \left(t \cdot z\right), -9, \color{blue}{x \cdot 2}\right)\right) \]
    12. lower-*.f6496.1

      \[\leadsto \mathsf{fma}\left(b \cdot 27, a, \mathsf{fma}\left(y \cdot \left(t \cdot z\right), -9, \color{blue}{x \cdot 2}\right)\right) \]
  7. Applied rewrites96.1%

    \[\leadsto \mathsf{fma}\left(b \cdot 27, a, \color{blue}{\mathsf{fma}\left(y \cdot \left(t \cdot z\right), -9, x \cdot 2\right)}\right) \]
  8. Add Preprocessing

Alternative 4: 98.3% accurate, N/A× speedup?

\[\begin{array}{l} [x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\\\ [x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\ \\ \begin{array}{l} t_1 := \left(a \cdot 27\right) \cdot b\\ t_2 := \left(y \cdot 9\right) \cdot z\\ \mathbf{if}\;t\_2 \leq 10^{+121}:\\ \;\;\;\;\left(x \cdot 2 - t\_2 \cdot t\right) + t\_1\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot 2 - \left(t \cdot y\right) \cdot \left(z \cdot 9\right)\right) + t\_1\\ \end{array} \end{array} \]
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (* (* a 27.0) b)) (t_2 (* (* y 9.0) z)))
   (if (<= t_2 1e+121)
     (+ (- (* x 2.0) (* t_2 t)) t_1)
     (+ (- (* x 2.0) (* (* t y) (* z 9.0))) t_1))))
assert(x < y && y < z && z < t && t < a && a < b);
assert(x < y && y < z && z < t && t < a && a < b);
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (a * 27.0) * b;
	double t_2 = (y * 9.0) * z;
	double tmp;
	if (t_2 <= 1e+121) {
		tmp = ((x * 2.0) - (t_2 * t)) + t_1;
	} else {
		tmp = ((x * 2.0) - ((t * y) * (z * 9.0))) + t_1;
	}
	return tmp;
}
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, and b 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(x, y, z, t, a, b)
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
    real(8), intent (in) :: b
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = (a * 27.0d0) * b
    t_2 = (y * 9.0d0) * z
    if (t_2 <= 1d+121) then
        tmp = ((x * 2.0d0) - (t_2 * t)) + t_1
    else
        tmp = ((x * 2.0d0) - ((t * y) * (z * 9.0d0))) + t_1
    end if
    code = tmp
end function
assert x < y && y < z && z < t && t < a && a < b;
assert x < y && y < z && z < t && t < a && a < b;
public static double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = (a * 27.0) * b;
	double t_2 = (y * 9.0) * z;
	double tmp;
	if (t_2 <= 1e+121) {
		tmp = ((x * 2.0) - (t_2 * t)) + t_1;
	} else {
		tmp = ((x * 2.0) - ((t * y) * (z * 9.0))) + t_1;
	}
	return tmp;
}
[x, y, z, t, a, b] = sort([x, y, z, t, a, b])
[x, y, z, t, a, b] = sort([x, y, z, t, a, b])
def code(x, y, z, t, a, b):
	t_1 = (a * 27.0) * b
	t_2 = (y * 9.0) * z
	tmp = 0
	if t_2 <= 1e+121:
		tmp = ((x * 2.0) - (t_2 * t)) + t_1
	else:
		tmp = ((x * 2.0) - ((t * y) * (z * 9.0))) + t_1
	return tmp
x, y, z, t, a, b = sort([x, y, z, t, a, b])
x, y, z, t, a, b = sort([x, y, z, t, a, b])
function code(x, y, z, t, a, b)
	t_1 = Float64(Float64(a * 27.0) * b)
	t_2 = Float64(Float64(y * 9.0) * z)
	tmp = 0.0
	if (t_2 <= 1e+121)
		tmp = Float64(Float64(Float64(x * 2.0) - Float64(t_2 * t)) + t_1);
	else
		tmp = Float64(Float64(Float64(x * 2.0) - Float64(Float64(t * y) * Float64(z * 9.0))) + t_1);
	end
	return tmp
end
x, y, z, t, a, b = num2cell(sort([x, y, z, t, a, b])){:}
x, y, z, t, a, b = num2cell(sort([x, y, z, t, a, b])){:}
function tmp_2 = code(x, y, z, t, a, b)
	t_1 = (a * 27.0) * b;
	t_2 = (y * 9.0) * z;
	tmp = 0.0;
	if (t_2 <= 1e+121)
		tmp = ((x * 2.0) - (t_2 * t)) + t_1;
	else
		tmp = ((x * 2.0) - ((t * y) * (z * 9.0))) + t_1;
	end
	tmp_2 = tmp;
end
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(N[(a * 27.0), $MachinePrecision] * b), $MachinePrecision]}, Block[{t$95$2 = N[(N[(y * 9.0), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[t$95$2, 1e+121], N[(N[(N[(x * 2.0), $MachinePrecision] - N[(t$95$2 * t), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision], N[(N[(N[(x * 2.0), $MachinePrecision] - N[(N[(t * y), $MachinePrecision] * N[(z * 9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]]]]
\begin{array}{l}
[x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\\\
[x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\
\\
\begin{array}{l}
t_1 := \left(a \cdot 27\right) \cdot b\\
t_2 := \left(y \cdot 9\right) \cdot z\\
\mathbf{if}\;t\_2 \leq 10^{+121}:\\
\;\;\;\;\left(x \cdot 2 - t\_2 \cdot t\right) + t\_1\\

\mathbf{else}:\\
\;\;\;\;\left(x \cdot 2 - \left(t \cdot y\right) \cdot \left(z \cdot 9\right)\right) + t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (*.f64 y #s(literal 9 binary64)) z) < 1.00000000000000004e121

    1. Initial program 97.2%

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
    2. Add Preprocessing

    if 1.00000000000000004e121 < (*.f64 (*.f64 y #s(literal 9 binary64)) z)

    1. Initial program 83.2%

      \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

        \[\leadsto \left(x \cdot 2 - \color{blue}{t \cdot \left(\left(y \cdot 9\right) \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b \]
      3. lift-*.f64N/A

        \[\leadsto \left(x \cdot 2 - t \cdot \color{blue}{\left(\left(y \cdot 9\right) \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b \]
      4. lift-*.f64N/A

        \[\leadsto \left(x \cdot 2 - t \cdot \left(\color{blue}{\left(y \cdot 9\right)} \cdot z\right)\right) + \left(a \cdot 27\right) \cdot b \]
      5. associate-*l*N/A

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

        \[\leadsto \left(x \cdot 2 - \color{blue}{\left(t \cdot y\right) \cdot \left(9 \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b \]
      7. lower-*.f64N/A

        \[\leadsto \left(x \cdot 2 - \color{blue}{\left(t \cdot y\right) \cdot \left(9 \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b \]
      8. lower-*.f64N/A

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

        \[\leadsto \left(x \cdot 2 - \left(t \cdot y\right) \cdot \color{blue}{\left(z \cdot 9\right)}\right) + \left(a \cdot 27\right) \cdot b \]
      10. lower-*.f6491.3

        \[\leadsto \left(x \cdot 2 - \left(t \cdot y\right) \cdot \color{blue}{\left(z \cdot 9\right)}\right) + \left(a \cdot 27\right) \cdot b \]
    4. Applied rewrites91.3%

      \[\leadsto \left(x \cdot 2 - \color{blue}{\left(t \cdot y\right) \cdot \left(z \cdot 9\right)}\right) + \left(a \cdot 27\right) \cdot b \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 5: 93.2% accurate, N/A× speedup?

\[\begin{array}{l} [x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\\\ [x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\ \\ \left(x \cdot 2 - \left(t \cdot y\right) \cdot \left(z \cdot 9\right)\right) + \left(a \cdot 27\right) \cdot b \end{array} \]
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
(FPCore (x y z t a b)
 :precision binary64
 (+ (- (* x 2.0) (* (* t y) (* z 9.0))) (* (* a 27.0) b)))
assert(x < y && y < z && z < t && t < a && a < b);
assert(x < y && y < z && z < t && t < a && a < b);
double code(double x, double y, double z, double t, double a, double b) {
	return ((x * 2.0) - ((t * y) * (z * 9.0))) + ((a * 27.0) * b);
}
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, and b 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(x, y, z, t, a, b)
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
    real(8), intent (in) :: b
    code = ((x * 2.0d0) - ((t * y) * (z * 9.0d0))) + ((a * 27.0d0) * b)
end function
assert x < y && y < z && z < t && t < a && a < b;
assert x < y && y < z && z < t && t < a && a < b;
public static double code(double x, double y, double z, double t, double a, double b) {
	return ((x * 2.0) - ((t * y) * (z * 9.0))) + ((a * 27.0) * b);
}
[x, y, z, t, a, b] = sort([x, y, z, t, a, b])
[x, y, z, t, a, b] = sort([x, y, z, t, a, b])
def code(x, y, z, t, a, b):
	return ((x * 2.0) - ((t * y) * (z * 9.0))) + ((a * 27.0) * b)
x, y, z, t, a, b = sort([x, y, z, t, a, b])
x, y, z, t, a, b = sort([x, y, z, t, a, b])
function code(x, y, z, t, a, b)
	return Float64(Float64(Float64(x * 2.0) - Float64(Float64(t * y) * Float64(z * 9.0))) + Float64(Float64(a * 27.0) * b))
end
x, y, z, t, a, b = num2cell(sort([x, y, z, t, a, b])){:}
x, y, z, t, a, b = num2cell(sort([x, y, z, t, a, b])){:}
function tmp = code(x, y, z, t, a, b)
	tmp = ((x * 2.0) - ((t * y) * (z * 9.0))) + ((a * 27.0) * b);
end
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, a, and b should be sorted in increasing order before calling this function.
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(x * 2.0), $MachinePrecision] - N[(N[(t * y), $MachinePrecision] * N[(z * 9.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(a * 27.0), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\\\
[x, y, z, t, a, b] = \mathsf{sort}([x, y, z, t, a, b])\\
\\
\left(x \cdot 2 - \left(t \cdot y\right) \cdot \left(z \cdot 9\right)\right) + \left(a \cdot 27\right) \cdot b
\end{array}
Derivation
  1. Initial program 94.7%

    \[\left(x \cdot 2 - \left(\left(y \cdot 9\right) \cdot z\right) \cdot t\right) + \left(a \cdot 27\right) \cdot b \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-*.f64N/A

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

      \[\leadsto \left(x \cdot 2 - \color{blue}{t \cdot \left(\left(y \cdot 9\right) \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b \]
    3. lift-*.f64N/A

      \[\leadsto \left(x \cdot 2 - t \cdot \color{blue}{\left(\left(y \cdot 9\right) \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b \]
    4. lift-*.f64N/A

      \[\leadsto \left(x \cdot 2 - t \cdot \left(\color{blue}{\left(y \cdot 9\right)} \cdot z\right)\right) + \left(a \cdot 27\right) \cdot b \]
    5. associate-*l*N/A

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

      \[\leadsto \left(x \cdot 2 - \color{blue}{\left(t \cdot y\right) \cdot \left(9 \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b \]
    7. lower-*.f64N/A

      \[\leadsto \left(x \cdot 2 - \color{blue}{\left(t \cdot y\right) \cdot \left(9 \cdot z\right)}\right) + \left(a \cdot 27\right) \cdot b \]
    8. lower-*.f64N/A

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

      \[\leadsto \left(x \cdot 2 - \left(t \cdot y\right) \cdot \color{blue}{\left(z \cdot 9\right)}\right) + \left(a \cdot 27\right) \cdot b \]
    10. lower-*.f6495.6

      \[\leadsto \left(x \cdot 2 - \left(t \cdot y\right) \cdot \color{blue}{\left(z \cdot 9\right)}\right) + \left(a \cdot 27\right) \cdot b \]
  4. Applied rewrites95.6%

    \[\leadsto \left(x \cdot 2 - \color{blue}{\left(t \cdot y\right) \cdot \left(z \cdot 9\right)}\right) + \left(a \cdot 27\right) \cdot b \]
  5. Add Preprocessing

Reproduce

?
herbie shell --seed 2025057 
(FPCore (x y z t a b)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, A"
  :precision binary64

  :alt
  (! :herbie-platform default (if (< y 7590524218811189/100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) (+ (- (* x 2) (* (* (* y 9) z) t)) (* a (* 27 b))) (+ (- (* x 2) (* 9 (* y (* t z)))) (* (* a 27) b))))

  (+ (- (* x 2.0) (* (* (* y 9.0) z) t)) (* (* a 27.0) b)))