Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I

Percentage Accurate: 95.7% → 98.0%
Time: 2.5s
Alternatives: 8
Speedup: 0.7×

Specification

?
\[\begin{array}{l} \\ x \cdot \left(1 - y \cdot z\right) \end{array} \]
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
double code(double x, double y, double z) {
	return x * (1.0 - (y * z));
}
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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x * (1.0d0 - (y * z))
end function
public static double code(double x, double y, double z) {
	return x * (1.0 - (y * z));
}
def code(x, y, z):
	return x * (1.0 - (y * z))
function code(x, y, z)
	return Float64(x * Float64(1.0 - Float64(y * z)))
end
function tmp = code(x, y, z)
	tmp = x * (1.0 - (y * z));
end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \left(1 - y \cdot z\right)
\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 8 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.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x \cdot \left(1 - y \cdot z\right) \end{array} \]
(FPCore (x y z) :precision binary64 (* x (- 1.0 (* y z))))
double code(double x, double y, double z) {
	return x * (1.0 - (y * z));
}
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)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x * (1.0d0 - (y * z))
end function
public static double code(double x, double y, double z) {
	return x * (1.0 - (y * z));
}
def code(x, y, z):
	return x * (1.0 - (y * z))
function code(x, y, z)
	return Float64(x * Float64(1.0 - Float64(y * z)))
end
function tmp = code(x, y, z)
	tmp = x * (1.0 - (y * z));
end
code[x_, y_, z_] := N[(x * N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \left(1 - y \cdot z\right)
\end{array}

Alternative 1: 98.0% accurate, 0.7× speedup?

\[\begin{array}{l} x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ [x_m, y, z] = \mathsf{sort}([x_m, y, z])\\ \\ x\_s \cdot \begin{array}{l} \mathbf{if}\;x\_m \leq 9.5 \cdot 10^{+29}:\\ \;\;\;\;x\_m - \left(y \cdot x\_m\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\_m \cdot \mathsf{fma}\left(-z, y, 1\right)\\ \end{array} \end{array} \]
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z)
 :precision binary64
 (*
  x_s
  (if (<= x_m 9.5e+29) (- x_m (* (* y x_m) z)) (* x_m (fma (- z) y 1.0)))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
	double tmp;
	if (x_m <= 9.5e+29) {
		tmp = x_m - ((y * x_m) * z);
	} else {
		tmp = x_m * fma(-z, y, 1.0);
	}
	return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0, x)
x_m, y, z = sort([x_m, y, z])
function code(x_s, x_m, y, z)
	tmp = 0.0
	if (x_m <= 9.5e+29)
		tmp = Float64(x_m - Float64(Float64(y * x_m) * z));
	else
		tmp = Float64(x_m * fma(Float64(-z), y, 1.0));
	end
	return Float64(x_s * tmp)
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := N[(x$95$s * If[LessEqual[x$95$m, 9.5e+29], N[(x$95$m - N[(N[(y * x$95$m), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x$95$m * N[((-z) * y + 1.0), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;x\_m \leq 9.5 \cdot 10^{+29}:\\
\;\;\;\;x\_m - \left(y \cdot x\_m\right) \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 9.5000000000000003e29

    1. Initial program 92.1%

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x + -1 \cdot \left(x \cdot \left(y \cdot z\right)\right)} \]
    3. Step-by-step derivation
      1. fp-cancel-sign-sub-invN/A

        \[\leadsto x - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right) \cdot \left(x \cdot \left(y \cdot z\right)\right)} \]
      2. metadata-evalN/A

        \[\leadsto x - 1 \cdot \left(\color{blue}{x} \cdot \left(y \cdot z\right)\right) \]
      3. *-lft-identityN/A

        \[\leadsto x - x \cdot \color{blue}{\left(y \cdot z\right)} \]
      4. lower--.f64N/A

        \[\leadsto x - \color{blue}{x \cdot \left(y \cdot z\right)} \]
      5. *-commutativeN/A

        \[\leadsto x - \left(y \cdot z\right) \cdot \color{blue}{x} \]
      6. lower-*.f64N/A

        \[\leadsto x - \left(y \cdot z\right) \cdot \color{blue}{x} \]
      7. *-commutativeN/A

        \[\leadsto x - \left(z \cdot y\right) \cdot x \]
      8. lower-*.f6492.2

        \[\leadsto x - \left(z \cdot y\right) \cdot x \]
    4. Applied rewrites92.2%

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

        \[\leadsto x - \left(z \cdot y\right) \cdot \color{blue}{x} \]
      2. *-commutativeN/A

        \[\leadsto x - x \cdot \color{blue}{\left(z \cdot y\right)} \]
      3. lift-*.f64N/A

        \[\leadsto x - x \cdot \left(z \cdot \color{blue}{y}\right) \]
      4. *-commutativeN/A

        \[\leadsto x - x \cdot \left(y \cdot \color{blue}{z}\right) \]
      5. associate-*r*N/A

        \[\leadsto x - \left(x \cdot y\right) \cdot \color{blue}{z} \]
      6. lower-*.f64N/A

        \[\leadsto x - \left(x \cdot y\right) \cdot \color{blue}{z} \]
      7. *-commutativeN/A

        \[\leadsto x - \left(y \cdot x\right) \cdot z \]
      8. lower-*.f6496.3

        \[\leadsto x - \left(y \cdot x\right) \cdot z \]
    6. Applied rewrites96.3%

      \[\leadsto x - \left(y \cdot x\right) \cdot \color{blue}{z} \]

    if 9.5000000000000003e29 < x

    1. Initial program 99.9%

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto x \cdot \left(1 - \color{blue}{y \cdot z}\right) \]
      2. lift--.f64N/A

        \[\leadsto x \cdot \color{blue}{\left(1 - y \cdot z\right)} \]
      3. fp-cancel-sub-sign-invN/A

        \[\leadsto x \cdot \color{blue}{\left(1 + \left(\mathsf{neg}\left(y\right)\right) \cdot z\right)} \]
      4. lft-mult-inverseN/A

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

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

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

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

        \[\leadsto x \cdot \left(\frac{1}{y} \cdot y + \color{blue}{\left(-1 \cdot z\right) \cdot y}\right) \]
      9. distribute-rgt-inN/A

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

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

        \[\leadsto x \cdot \color{blue}{\left(y \cdot \left(-1 \cdot z\right) + y \cdot \frac{1}{y}\right)} \]
      12. flip-+N/A

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

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

        \[\leadsto x \cdot \frac{\left(\left(-1 \cdot z\right) \cdot y\right) \cdot \color{blue}{\left(\left(-1 \cdot z\right) \cdot y\right)} - \left(y \cdot \frac{1}{y}\right) \cdot \left(y \cdot \frac{1}{y}\right)}{y \cdot \left(-1 \cdot z\right) - y \cdot \frac{1}{y}} \]
      15. rgt-mult-inverseN/A

        \[\leadsto x \cdot \frac{\left(\left(-1 \cdot z\right) \cdot y\right) \cdot \left(\left(-1 \cdot z\right) \cdot y\right) - \color{blue}{1} \cdot \left(y \cdot \frac{1}{y}\right)}{y \cdot \left(-1 \cdot z\right) - y \cdot \frac{1}{y}} \]
      16. rgt-mult-inverseN/A

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

        \[\leadsto x \cdot \frac{\left(\left(-1 \cdot z\right) \cdot y\right) \cdot \left(\left(-1 \cdot z\right) \cdot y\right) - 1 \cdot 1}{\color{blue}{\left(-1 \cdot z\right) \cdot y} - y \cdot \frac{1}{y}} \]
      18. rgt-mult-inverseN/A

        \[\leadsto x \cdot \frac{\left(\left(-1 \cdot z\right) \cdot y\right) \cdot \left(\left(-1 \cdot z\right) \cdot y\right) - 1 \cdot 1}{\left(-1 \cdot z\right) \cdot y - \color{blue}{1}} \]
      19. flip-+N/A

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

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

        \[\leadsto x \cdot \mathsf{fma}\left(\color{blue}{\mathsf{neg}\left(z\right)}, y, 1\right) \]
      22. lower-neg.f6499.9

        \[\leadsto x \cdot \mathsf{fma}\left(\color{blue}{-z}, y, 1\right) \]
    3. Applied rewrites99.9%

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

Alternative 2: 98.0% accurate, 0.7× speedup?

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

\mathbf{else}:\\
\;\;\;\;x\_m \cdot \left(1 - y \cdot z\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 9.5000000000000003e29

    1. Initial program 92.1%

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x + -1 \cdot \left(x \cdot \left(y \cdot z\right)\right)} \]
    3. Step-by-step derivation
      1. fp-cancel-sign-sub-invN/A

        \[\leadsto x - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right) \cdot \left(x \cdot \left(y \cdot z\right)\right)} \]
      2. metadata-evalN/A

        \[\leadsto x - 1 \cdot \left(\color{blue}{x} \cdot \left(y \cdot z\right)\right) \]
      3. *-lft-identityN/A

        \[\leadsto x - x \cdot \color{blue}{\left(y \cdot z\right)} \]
      4. lower--.f64N/A

        \[\leadsto x - \color{blue}{x \cdot \left(y \cdot z\right)} \]
      5. *-commutativeN/A

        \[\leadsto x - \left(y \cdot z\right) \cdot \color{blue}{x} \]
      6. lower-*.f64N/A

        \[\leadsto x - \left(y \cdot z\right) \cdot \color{blue}{x} \]
      7. *-commutativeN/A

        \[\leadsto x - \left(z \cdot y\right) \cdot x \]
      8. lower-*.f6492.2

        \[\leadsto x - \left(z \cdot y\right) \cdot x \]
    4. Applied rewrites92.2%

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

        \[\leadsto x - \left(z \cdot y\right) \cdot \color{blue}{x} \]
      2. *-commutativeN/A

        \[\leadsto x - x \cdot \color{blue}{\left(z \cdot y\right)} \]
      3. lift-*.f64N/A

        \[\leadsto x - x \cdot \left(z \cdot \color{blue}{y}\right) \]
      4. *-commutativeN/A

        \[\leadsto x - x \cdot \left(y \cdot \color{blue}{z}\right) \]
      5. associate-*r*N/A

        \[\leadsto x - \left(x \cdot y\right) \cdot \color{blue}{z} \]
      6. lower-*.f64N/A

        \[\leadsto x - \left(x \cdot y\right) \cdot \color{blue}{z} \]
      7. *-commutativeN/A

        \[\leadsto x - \left(y \cdot x\right) \cdot z \]
      8. lower-*.f6496.3

        \[\leadsto x - \left(y \cdot x\right) \cdot z \]
    6. Applied rewrites96.3%

      \[\leadsto x - \left(y \cdot x\right) \cdot \color{blue}{z} \]

    if 9.5000000000000003e29 < x

    1. Initial program 99.9%

      \[x \cdot \left(1 - y \cdot z\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 97.9% accurate, 0.7× speedup?

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

\mathbf{else}:\\
\;\;\;\;x\_m - \left(z \cdot y\right) \cdot x\_m\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 3e-52

    1. Initial program 90.1%

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x + -1 \cdot \left(x \cdot \left(y \cdot z\right)\right)} \]
    3. Step-by-step derivation
      1. fp-cancel-sign-sub-invN/A

        \[\leadsto x - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right) \cdot \left(x \cdot \left(y \cdot z\right)\right)} \]
      2. metadata-evalN/A

        \[\leadsto x - 1 \cdot \left(\color{blue}{x} \cdot \left(y \cdot z\right)\right) \]
      3. *-lft-identityN/A

        \[\leadsto x - x \cdot \color{blue}{\left(y \cdot z\right)} \]
      4. lower--.f64N/A

        \[\leadsto x - \color{blue}{x \cdot \left(y \cdot z\right)} \]
      5. *-commutativeN/A

        \[\leadsto x - \left(y \cdot z\right) \cdot \color{blue}{x} \]
      6. lower-*.f64N/A

        \[\leadsto x - \left(y \cdot z\right) \cdot \color{blue}{x} \]
      7. *-commutativeN/A

        \[\leadsto x - \left(z \cdot y\right) \cdot x \]
      8. lower-*.f6490.1

        \[\leadsto x - \left(z \cdot y\right) \cdot x \]
    4. Applied rewrites90.1%

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

        \[\leadsto x - \left(z \cdot y\right) \cdot \color{blue}{x} \]
      2. *-commutativeN/A

        \[\leadsto x - x \cdot \color{blue}{\left(z \cdot y\right)} \]
      3. lift-*.f64N/A

        \[\leadsto x - x \cdot \left(z \cdot \color{blue}{y}\right) \]
      4. *-commutativeN/A

        \[\leadsto x - x \cdot \left(y \cdot \color{blue}{z}\right) \]
      5. associate-*r*N/A

        \[\leadsto x - \left(x \cdot y\right) \cdot \color{blue}{z} \]
      6. lower-*.f64N/A

        \[\leadsto x - \left(x \cdot y\right) \cdot \color{blue}{z} \]
      7. *-commutativeN/A

        \[\leadsto x - \left(y \cdot x\right) \cdot z \]
      8. lower-*.f6495.3

        \[\leadsto x - \left(y \cdot x\right) \cdot z \]
    6. Applied rewrites95.3%

      \[\leadsto x - \left(y \cdot x\right) \cdot \color{blue}{z} \]

    if 3e-52 < x

    1. Initial program 99.7%

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Taylor expanded in y around 0

      \[\leadsto \color{blue}{x + -1 \cdot \left(x \cdot \left(y \cdot z\right)\right)} \]
    3. Step-by-step derivation
      1. fp-cancel-sign-sub-invN/A

        \[\leadsto x - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right) \cdot \left(x \cdot \left(y \cdot z\right)\right)} \]
      2. metadata-evalN/A

        \[\leadsto x - 1 \cdot \left(\color{blue}{x} \cdot \left(y \cdot z\right)\right) \]
      3. *-lft-identityN/A

        \[\leadsto x - x \cdot \color{blue}{\left(y \cdot z\right)} \]
      4. lower--.f64N/A

        \[\leadsto x - \color{blue}{x \cdot \left(y \cdot z\right)} \]
      5. *-commutativeN/A

        \[\leadsto x - \left(y \cdot z\right) \cdot \color{blue}{x} \]
      6. lower-*.f64N/A

        \[\leadsto x - \left(y \cdot z\right) \cdot \color{blue}{x} \]
      7. *-commutativeN/A

        \[\leadsto x - \left(z \cdot y\right) \cdot x \]
      8. lower-*.f6499.7

        \[\leadsto x - \left(z \cdot y\right) \cdot x \]
    4. Applied rewrites99.7%

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

Alternative 4: 95.2% accurate, 1.0× speedup?

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

    \[x \cdot \left(1 - y \cdot z\right) \]
  2. Taylor expanded in y around 0

    \[\leadsto \color{blue}{x + -1 \cdot \left(x \cdot \left(y \cdot z\right)\right)} \]
  3. Step-by-step derivation
    1. fp-cancel-sign-sub-invN/A

      \[\leadsto x - \color{blue}{\left(\mathsf{neg}\left(-1\right)\right) \cdot \left(x \cdot \left(y \cdot z\right)\right)} \]
    2. metadata-evalN/A

      \[\leadsto x - 1 \cdot \left(\color{blue}{x} \cdot \left(y \cdot z\right)\right) \]
    3. *-lft-identityN/A

      \[\leadsto x - x \cdot \color{blue}{\left(y \cdot z\right)} \]
    4. lower--.f64N/A

      \[\leadsto x - \color{blue}{x \cdot \left(y \cdot z\right)} \]
    5. *-commutativeN/A

      \[\leadsto x - \left(y \cdot z\right) \cdot \color{blue}{x} \]
    6. lower-*.f64N/A

      \[\leadsto x - \left(y \cdot z\right) \cdot \color{blue}{x} \]
    7. *-commutativeN/A

      \[\leadsto x - \left(z \cdot y\right) \cdot x \]
    8. lower-*.f6495.7

      \[\leadsto x - \left(z \cdot y\right) \cdot x \]
  4. Applied rewrites95.7%

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

      \[\leadsto x - \left(z \cdot y\right) \cdot \color{blue}{x} \]
    2. *-commutativeN/A

      \[\leadsto x - x \cdot \color{blue}{\left(z \cdot y\right)} \]
    3. lift-*.f64N/A

      \[\leadsto x - x \cdot \left(z \cdot \color{blue}{y}\right) \]
    4. *-commutativeN/A

      \[\leadsto x - x \cdot \left(y \cdot \color{blue}{z}\right) \]
    5. associate-*r*N/A

      \[\leadsto x - \left(x \cdot y\right) \cdot \color{blue}{z} \]
    6. lower-*.f64N/A

      \[\leadsto x - \left(x \cdot y\right) \cdot \color{blue}{z} \]
    7. *-commutativeN/A

      \[\leadsto x - \left(y \cdot x\right) \cdot z \]
    8. lower-*.f6494.0

      \[\leadsto x - \left(y \cdot x\right) \cdot z \]
  6. Applied rewrites94.0%

    \[\leadsto x - \left(y \cdot x\right) \cdot \color{blue}{z} \]
  7. Add Preprocessing

Alternative 5: 94.5% accurate, 0.3× speedup?

\[\begin{array}{l} x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ [x_m, y, z] = \mathsf{sort}([x_m, y, z])\\ \\ \begin{array}{l} t_0 := 1 - y \cdot z\\ t_1 := \left(\left(-x\_m\right) \cdot y\right) \cdot z\\ x\_s \cdot \begin{array}{l} \mathbf{if}\;t\_0 \leq -20:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 2:\\ \;\;\;\;\frac{x\_m}{\mathsf{fma}\left(z, y, 1\right)}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \end{array} \]
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
(FPCore (x_s x_m y z)
 :precision binary64
 (let* ((t_0 (- 1.0 (* y z))) (t_1 (* (* (- x_m) y) z)))
   (*
    x_s
    (if (<= t_0 -20.0) t_1 (if (<= t_0 2.0) (/ x_m (fma z y 1.0)) t_1)))))
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y && y < z);
double code(double x_s, double x_m, double y, double z) {
	double t_0 = 1.0 - (y * z);
	double t_1 = (-x_m * y) * z;
	double tmp;
	if (t_0 <= -20.0) {
		tmp = t_1;
	} else if (t_0 <= 2.0) {
		tmp = x_m / fma(z, y, 1.0);
	} else {
		tmp = t_1;
	}
	return x_s * tmp;
}
x\_m = abs(x)
x\_s = copysign(1.0, x)
x_m, y, z = sort([x_m, y, z])
function code(x_s, x_m, y, z)
	t_0 = Float64(1.0 - Float64(y * z))
	t_1 = Float64(Float64(Float64(-x_m) * y) * z)
	tmp = 0.0
	if (t_0 <= -20.0)
		tmp = t_1;
	elseif (t_0 <= 2.0)
		tmp = Float64(x_m / fma(z, y, 1.0));
	else
		tmp = t_1;
	end
	return Float64(x_s * tmp)
end
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
code[x$95$s_, x$95$m_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[((-x$95$m) * y), $MachinePrecision] * z), $MachinePrecision]}, N[(x$95$s * If[LessEqual[t$95$0, -20.0], t$95$1, If[LessEqual[t$95$0, 2.0], N[(x$95$m / N[(z * y + 1.0), $MachinePrecision]), $MachinePrecision], t$95$1]]), $MachinePrecision]]]
\begin{array}{l}
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
\\
\begin{array}{l}
t_0 := 1 - y \cdot z\\
t_1 := \left(\left(-x\_m\right) \cdot y\right) \cdot z\\
x\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq -20:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq 2:\\
\;\;\;\;\frac{x\_m}{\mathsf{fma}\left(z, y, 1\right)}\\

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


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

    1. Initial program 91.4%

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

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

        \[\leadsto x \cdot \left(1 - \color{blue}{y \cdot z}\right) \]
      3. lift--.f64N/A

        \[\leadsto x \cdot \color{blue}{\left(1 - y \cdot z\right)} \]
      4. fp-cancel-sub-sign-invN/A

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

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

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

        \[\leadsto x \cdot \color{blue}{\left(-1 \cdot \left(y \cdot z\right) + 1\right)} \]
      8. distribute-lft-inN/A

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

        \[\leadsto x \cdot \color{blue}{\left(\mathsf{neg}\left(y \cdot z\right)\right)} + x \cdot 1 \]
      10. distribute-rgt-neg-inN/A

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{neg}\left(x \cdot y\right)}, z, x \cdot 1\right) \]
      16. distribute-lft-neg-inN/A

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{\left(-x\right)} \cdot y, z, x \cdot 1\right) \]
      19. lower-*.f6492.7

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(-x\right) \cdot y, z, x \cdot 1\right)} \]
    4. Taylor expanded in y around inf

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(y \cdot z\right)\right)} \]
    5. Step-by-step derivation
      1. *-commutativeN/A

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

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

        \[\leadsto \left(-1 \cdot \left(x \cdot z\right)\right) \cdot \color{blue}{y} \]
      4. lower-*.f64N/A

        \[\leadsto \left(-1 \cdot \left(x \cdot z\right)\right) \cdot \color{blue}{y} \]
      5. mul-1-negN/A

        \[\leadsto \left(\mathsf{neg}\left(x \cdot z\right)\right) \cdot y \]
      6. distribute-lft-neg-outN/A

        \[\leadsto \left(\left(\mathsf{neg}\left(x\right)\right) \cdot z\right) \cdot y \]
      7. lift-neg.f64N/A

        \[\leadsto \left(\left(-x\right) \cdot z\right) \cdot y \]
      8. *-commutativeN/A

        \[\leadsto \left(z \cdot \left(-x\right)\right) \cdot y \]
      9. lower-*.f6490.8

        \[\leadsto \left(z \cdot \left(-x\right)\right) \cdot y \]
    6. Applied rewrites90.8%

      \[\leadsto \color{blue}{\left(z \cdot \left(-x\right)\right) \cdot y} \]
    7. Step-by-step derivation
      1. lift-*.f64N/A

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

        \[\leadsto \left(z \cdot \left(-x\right)\right) \cdot y \]
      3. associate-*l*N/A

        \[\leadsto z \cdot \color{blue}{\left(\left(-x\right) \cdot y\right)} \]
      4. lift-neg.f64N/A

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

        \[\leadsto z \cdot \left(\mathsf{neg}\left(x \cdot y\right)\right) \]
      6. mul-1-negN/A

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

        \[\leadsto \left(-1 \cdot \left(x \cdot y\right)\right) \cdot \color{blue}{z} \]
      8. lower-*.f64N/A

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

        \[\leadsto \left(\mathsf{neg}\left(x \cdot y\right)\right) \cdot z \]
      10. distribute-lft-neg-outN/A

        \[\leadsto \left(\left(\mathsf{neg}\left(x\right)\right) \cdot y\right) \cdot z \]
      11. lift-neg.f64N/A

        \[\leadsto \left(\left(-x\right) \cdot y\right) \cdot z \]
      12. lower-*.f6491.2

        \[\leadsto \left(\left(-x\right) \cdot y\right) \cdot z \]
    8. Applied rewrites91.2%

      \[\leadsto \left(\left(-x\right) \cdot y\right) \cdot \color{blue}{z} \]

    if -20 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 2

    1. Initial program 100.0%

      \[x \cdot \left(1 - y \cdot z\right) \]
    2. Step-by-step derivation
      1. lift-*.f64N/A

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

        \[\leadsto x \cdot \left(1 - \color{blue}{y \cdot z}\right) \]
      3. lift--.f64N/A

        \[\leadsto x \cdot \color{blue}{\left(1 - y \cdot z\right)} \]
      4. *-commutativeN/A

        \[\leadsto \color{blue}{\left(1 - y \cdot z\right) \cdot x} \]
      5. fp-cancel-sub-sign-invN/A

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

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

        \[\leadsto \left(1 + \color{blue}{-1 \cdot \left(y \cdot z\right)}\right) \cdot x \]
      8. fp-cancel-sign-sub-invN/A

        \[\leadsto \color{blue}{\left(1 - \left(\mathsf{neg}\left(-1\right)\right) \cdot \left(y \cdot z\right)\right)} \cdot x \]
      9. metadata-evalN/A

        \[\leadsto \left(1 - \color{blue}{1} \cdot \left(y \cdot z\right)\right) \cdot x \]
      10. flip--N/A

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

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

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

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

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

        \[\leadsto \frac{1 - \left(y \cdot z\right) \cdot \left(y \cdot z\right)}{\color{blue}{1 - -1 \cdot \left(y \cdot z\right)}} \cdot x \]
      16. metadata-evalN/A

        \[\leadsto \frac{\color{blue}{1 \cdot 1} - \left(y \cdot z\right) \cdot \left(y \cdot z\right)}{1 - -1 \cdot \left(y \cdot z\right)} \cdot x \]
    3. Applied rewrites100.0%

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

      \[\leadsto \frac{\color{blue}{x}}{\mathsf{fma}\left(z, y, 1\right)} \]
    5. Step-by-step derivation
      1. Applied rewrites99.1%

        \[\leadsto \frac{\color{blue}{x}}{\mathsf{fma}\left(z, y, 1\right)} \]
    6. Recombined 2 regimes into one program.
    7. Add Preprocessing

    Alternative 6: 94.4% accurate, 0.4× speedup?

    \[\begin{array}{l} x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ [x_m, y, z] = \mathsf{sort}([x_m, y, z])\\ \\ \begin{array}{l} t_0 := 1 - y \cdot z\\ t_1 := \left(\left(-x\_m\right) \cdot y\right) \cdot z\\ x\_s \cdot \begin{array}{l} \mathbf{if}\;t\_0 \leq -20:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 10^{+15}:\\ \;\;\;\;x\_m\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \end{array} \]
    x\_m = (fabs.f64 x)
    x\_s = (copysign.f64 #s(literal 1 binary64) x)
    NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
    (FPCore (x_s x_m y z)
     :precision binary64
     (let* ((t_0 (- 1.0 (* y z))) (t_1 (* (* (- x_m) y) z)))
       (* x_s (if (<= t_0 -20.0) t_1 (if (<= t_0 1e+15) x_m t_1)))))
    x\_m = fabs(x);
    x\_s = copysign(1.0, x);
    assert(x_m < y && y < z);
    double code(double x_s, double x_m, double y, double z) {
    	double t_0 = 1.0 - (y * z);
    	double t_1 = (-x_m * y) * z;
    	double tmp;
    	if (t_0 <= -20.0) {
    		tmp = t_1;
    	} else if (t_0 <= 1e+15) {
    		tmp = x_m;
    	} else {
    		tmp = t_1;
    	}
    	return x_s * tmp;
    }
    
    x\_m =     private
    x\_s =     private
    NOTE: x_m, y, and z 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_s, x_m, y, z)
    use fmin_fmax_functions
        real(8), intent (in) :: x_s
        real(8), intent (in) :: x_m
        real(8), intent (in) :: y
        real(8), intent (in) :: z
        real(8) :: t_0
        real(8) :: t_1
        real(8) :: tmp
        t_0 = 1.0d0 - (y * z)
        t_1 = (-x_m * y) * z
        if (t_0 <= (-20.0d0)) then
            tmp = t_1
        else if (t_0 <= 1d+15) then
            tmp = x_m
        else
            tmp = t_1
        end if
        code = x_s * tmp
    end function
    
    x\_m = Math.abs(x);
    x\_s = Math.copySign(1.0, x);
    assert x_m < y && y < z;
    public static double code(double x_s, double x_m, double y, double z) {
    	double t_0 = 1.0 - (y * z);
    	double t_1 = (-x_m * y) * z;
    	double tmp;
    	if (t_0 <= -20.0) {
    		tmp = t_1;
    	} else if (t_0 <= 1e+15) {
    		tmp = x_m;
    	} else {
    		tmp = t_1;
    	}
    	return x_s * tmp;
    }
    
    x\_m = math.fabs(x)
    x\_s = math.copysign(1.0, x)
    [x_m, y, z] = sort([x_m, y, z])
    def code(x_s, x_m, y, z):
    	t_0 = 1.0 - (y * z)
    	t_1 = (-x_m * y) * z
    	tmp = 0
    	if t_0 <= -20.0:
    		tmp = t_1
    	elif t_0 <= 1e+15:
    		tmp = x_m
    	else:
    		tmp = t_1
    	return x_s * tmp
    
    x\_m = abs(x)
    x\_s = copysign(1.0, x)
    x_m, y, z = sort([x_m, y, z])
    function code(x_s, x_m, y, z)
    	t_0 = Float64(1.0 - Float64(y * z))
    	t_1 = Float64(Float64(Float64(-x_m) * y) * z)
    	tmp = 0.0
    	if (t_0 <= -20.0)
    		tmp = t_1;
    	elseif (t_0 <= 1e+15)
    		tmp = x_m;
    	else
    		tmp = t_1;
    	end
    	return Float64(x_s * tmp)
    end
    
    x\_m = abs(x);
    x\_s = sign(x) * abs(1.0);
    x_m, y, z = num2cell(sort([x_m, y, z])){:}
    function tmp_2 = code(x_s, x_m, y, z)
    	t_0 = 1.0 - (y * z);
    	t_1 = (-x_m * y) * z;
    	tmp = 0.0;
    	if (t_0 <= -20.0)
    		tmp = t_1;
    	elseif (t_0 <= 1e+15)
    		tmp = x_m;
    	else
    		tmp = t_1;
    	end
    	tmp_2 = x_s * tmp;
    end
    
    x\_m = N[Abs[x], $MachinePrecision]
    x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
    NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
    code[x$95$s_, x$95$m_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[((-x$95$m) * y), $MachinePrecision] * z), $MachinePrecision]}, N[(x$95$s * If[LessEqual[t$95$0, -20.0], t$95$1, If[LessEqual[t$95$0, 1e+15], x$95$m, t$95$1]]), $MachinePrecision]]]
    
    \begin{array}{l}
    x\_m = \left|x\right|
    \\
    x\_s = \mathsf{copysign}\left(1, x\right)
    \\
    [x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
    \\
    \begin{array}{l}
    t_0 := 1 - y \cdot z\\
    t_1 := \left(\left(-x\_m\right) \cdot y\right) \cdot z\\
    x\_s \cdot \begin{array}{l}
    \mathbf{if}\;t\_0 \leq -20:\\
    \;\;\;\;t\_1\\
    
    \mathbf{elif}\;t\_0 \leq 10^{+15}:\\
    \;\;\;\;x\_m\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_1\\
    
    
    \end{array}
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -20 or 1e15 < (-.f64 #s(literal 1 binary64) (*.f64 y z))

      1. Initial program 91.3%

        \[x \cdot \left(1 - y \cdot z\right) \]
      2. Step-by-step derivation
        1. lift-*.f64N/A

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

          \[\leadsto x \cdot \left(1 - \color{blue}{y \cdot z}\right) \]
        3. lift--.f64N/A

          \[\leadsto x \cdot \color{blue}{\left(1 - y \cdot z\right)} \]
        4. fp-cancel-sub-sign-invN/A

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

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

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

          \[\leadsto x \cdot \color{blue}{\left(-1 \cdot \left(y \cdot z\right) + 1\right)} \]
        8. distribute-lft-inN/A

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

          \[\leadsto x \cdot \color{blue}{\left(\mathsf{neg}\left(y \cdot z\right)\right)} + x \cdot 1 \]
        10. distribute-rgt-neg-inN/A

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{neg}\left(x \cdot y\right)}, z, x \cdot 1\right) \]
        16. distribute-lft-neg-inN/A

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

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

          \[\leadsto \mathsf{fma}\left(\color{blue}{\left(-x\right)} \cdot y, z, x \cdot 1\right) \]
        19. lower-*.f6493.0

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(\left(-x\right) \cdot y, z, x \cdot 1\right)} \]
      4. Taylor expanded in y around inf

        \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(y \cdot z\right)\right)} \]
      5. Step-by-step derivation
        1. *-commutativeN/A

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

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

          \[\leadsto \left(-1 \cdot \left(x \cdot z\right)\right) \cdot \color{blue}{y} \]
        4. lower-*.f64N/A

          \[\leadsto \left(-1 \cdot \left(x \cdot z\right)\right) \cdot \color{blue}{y} \]
        5. mul-1-negN/A

          \[\leadsto \left(\mathsf{neg}\left(x \cdot z\right)\right) \cdot y \]
        6. distribute-lft-neg-outN/A

          \[\leadsto \left(\left(\mathsf{neg}\left(x\right)\right) \cdot z\right) \cdot y \]
        7. lift-neg.f64N/A

          \[\leadsto \left(\left(-x\right) \cdot z\right) \cdot y \]
        8. *-commutativeN/A

          \[\leadsto \left(z \cdot \left(-x\right)\right) \cdot y \]
        9. lower-*.f6491.7

          \[\leadsto \left(z \cdot \left(-x\right)\right) \cdot y \]
      6. Applied rewrites91.7%

        \[\leadsto \color{blue}{\left(z \cdot \left(-x\right)\right) \cdot y} \]
      7. Step-by-step derivation
        1. lift-*.f64N/A

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

          \[\leadsto \left(z \cdot \left(-x\right)\right) \cdot y \]
        3. associate-*l*N/A

          \[\leadsto z \cdot \color{blue}{\left(\left(-x\right) \cdot y\right)} \]
        4. lift-neg.f64N/A

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

          \[\leadsto z \cdot \left(\mathsf{neg}\left(x \cdot y\right)\right) \]
        6. mul-1-negN/A

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

          \[\leadsto \left(-1 \cdot \left(x \cdot y\right)\right) \cdot \color{blue}{z} \]
        8. lower-*.f64N/A

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

          \[\leadsto \left(\mathsf{neg}\left(x \cdot y\right)\right) \cdot z \]
        10. distribute-lft-neg-outN/A

          \[\leadsto \left(\left(\mathsf{neg}\left(x\right)\right) \cdot y\right) \cdot z \]
        11. lift-neg.f64N/A

          \[\leadsto \left(\left(-x\right) \cdot y\right) \cdot z \]
        12. lower-*.f6492.1

          \[\leadsto \left(\left(-x\right) \cdot y\right) \cdot z \]
      8. Applied rewrites92.1%

        \[\leadsto \left(\left(-x\right) \cdot y\right) \cdot \color{blue}{z} \]

      if -20 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 1e15

      1. Initial program 100.0%

        \[x \cdot \left(1 - y \cdot z\right) \]
      2. Taylor expanded in y around 0

        \[\leadsto \color{blue}{x} \]
      3. Step-by-step derivation
        1. Applied rewrites96.6%

          \[\leadsto \color{blue}{x} \]
      4. Recombined 2 regimes into one program.
      5. Add Preprocessing

      Alternative 7: 94.0% accurate, 0.4× speedup?

      \[\begin{array}{l} x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ [x_m, y, z] = \mathsf{sort}([x_m, y, z])\\ \\ \begin{array}{l} t_0 := 1 - y \cdot z\\ t_1 := \left(z \cdot \left(-x\_m\right)\right) \cdot y\\ x\_s \cdot \begin{array}{l} \mathbf{if}\;t\_0 \leq -20:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 5:\\ \;\;\;\;x\_m\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \end{array} \]
      x\_m = (fabs.f64 x)
      x\_s = (copysign.f64 #s(literal 1 binary64) x)
      NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
      (FPCore (x_s x_m y z)
       :precision binary64
       (let* ((t_0 (- 1.0 (* y z))) (t_1 (* (* z (- x_m)) y)))
         (* x_s (if (<= t_0 -20.0) t_1 (if (<= t_0 5.0) x_m t_1)))))
      x\_m = fabs(x);
      x\_s = copysign(1.0, x);
      assert(x_m < y && y < z);
      double code(double x_s, double x_m, double y, double z) {
      	double t_0 = 1.0 - (y * z);
      	double t_1 = (z * -x_m) * y;
      	double tmp;
      	if (t_0 <= -20.0) {
      		tmp = t_1;
      	} else if (t_0 <= 5.0) {
      		tmp = x_m;
      	} else {
      		tmp = t_1;
      	}
      	return x_s * tmp;
      }
      
      x\_m =     private
      x\_s =     private
      NOTE: x_m, y, and z 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_s, x_m, y, z)
      use fmin_fmax_functions
          real(8), intent (in) :: x_s
          real(8), intent (in) :: x_m
          real(8), intent (in) :: y
          real(8), intent (in) :: z
          real(8) :: t_0
          real(8) :: t_1
          real(8) :: tmp
          t_0 = 1.0d0 - (y * z)
          t_1 = (z * -x_m) * y
          if (t_0 <= (-20.0d0)) then
              tmp = t_1
          else if (t_0 <= 5.0d0) then
              tmp = x_m
          else
              tmp = t_1
          end if
          code = x_s * tmp
      end function
      
      x\_m = Math.abs(x);
      x\_s = Math.copySign(1.0, x);
      assert x_m < y && y < z;
      public static double code(double x_s, double x_m, double y, double z) {
      	double t_0 = 1.0 - (y * z);
      	double t_1 = (z * -x_m) * y;
      	double tmp;
      	if (t_0 <= -20.0) {
      		tmp = t_1;
      	} else if (t_0 <= 5.0) {
      		tmp = x_m;
      	} else {
      		tmp = t_1;
      	}
      	return x_s * tmp;
      }
      
      x\_m = math.fabs(x)
      x\_s = math.copysign(1.0, x)
      [x_m, y, z] = sort([x_m, y, z])
      def code(x_s, x_m, y, z):
      	t_0 = 1.0 - (y * z)
      	t_1 = (z * -x_m) * y
      	tmp = 0
      	if t_0 <= -20.0:
      		tmp = t_1
      	elif t_0 <= 5.0:
      		tmp = x_m
      	else:
      		tmp = t_1
      	return x_s * tmp
      
      x\_m = abs(x)
      x\_s = copysign(1.0, x)
      x_m, y, z = sort([x_m, y, z])
      function code(x_s, x_m, y, z)
      	t_0 = Float64(1.0 - Float64(y * z))
      	t_1 = Float64(Float64(z * Float64(-x_m)) * y)
      	tmp = 0.0
      	if (t_0 <= -20.0)
      		tmp = t_1;
      	elseif (t_0 <= 5.0)
      		tmp = x_m;
      	else
      		tmp = t_1;
      	end
      	return Float64(x_s * tmp)
      end
      
      x\_m = abs(x);
      x\_s = sign(x) * abs(1.0);
      x_m, y, z = num2cell(sort([x_m, y, z])){:}
      function tmp_2 = code(x_s, x_m, y, z)
      	t_0 = 1.0 - (y * z);
      	t_1 = (z * -x_m) * y;
      	tmp = 0.0;
      	if (t_0 <= -20.0)
      		tmp = t_1;
      	elseif (t_0 <= 5.0)
      		tmp = x_m;
      	else
      		tmp = t_1;
      	end
      	tmp_2 = x_s * tmp;
      end
      
      x\_m = N[Abs[x], $MachinePrecision]
      x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
      NOTE: x_m, y, and z should be sorted in increasing order before calling this function.
      code[x$95$s_, x$95$m_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(z * (-x$95$m)), $MachinePrecision] * y), $MachinePrecision]}, N[(x$95$s * If[LessEqual[t$95$0, -20.0], t$95$1, If[LessEqual[t$95$0, 5.0], x$95$m, t$95$1]]), $MachinePrecision]]]
      
      \begin{array}{l}
      x\_m = \left|x\right|
      \\
      x\_s = \mathsf{copysign}\left(1, x\right)
      \\
      [x_m, y, z] = \mathsf{sort}([x_m, y, z])\\
      \\
      \begin{array}{l}
      t_0 := 1 - y \cdot z\\
      t_1 := \left(z \cdot \left(-x\_m\right)\right) \cdot y\\
      x\_s \cdot \begin{array}{l}
      \mathbf{if}\;t\_0 \leq -20:\\
      \;\;\;\;t\_1\\
      
      \mathbf{elif}\;t\_0 \leq 5:\\
      \;\;\;\;x\_m\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_1\\
      
      
      \end{array}
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (-.f64 #s(literal 1 binary64) (*.f64 y z)) < -20 or 5 < (-.f64 #s(literal 1 binary64) (*.f64 y z))

        1. Initial program 91.4%

          \[x \cdot \left(1 - y \cdot z\right) \]
        2. Step-by-step derivation
          1. lift-*.f64N/A

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

            \[\leadsto x \cdot \left(1 - \color{blue}{y \cdot z}\right) \]
          3. lift--.f64N/A

            \[\leadsto x \cdot \color{blue}{\left(1 - y \cdot z\right)} \]
          4. fp-cancel-sub-sign-invN/A

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

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

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

            \[\leadsto x \cdot \color{blue}{\left(-1 \cdot \left(y \cdot z\right) + 1\right)} \]
          8. distribute-lft-inN/A

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

            \[\leadsto x \cdot \color{blue}{\left(\mathsf{neg}\left(y \cdot z\right)\right)} + x \cdot 1 \]
          10. distribute-rgt-neg-inN/A

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

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

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

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

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

            \[\leadsto \mathsf{fma}\left(\color{blue}{\mathsf{neg}\left(x \cdot y\right)}, z, x \cdot 1\right) \]
          16. distribute-lft-neg-inN/A

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

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

            \[\leadsto \mathsf{fma}\left(\color{blue}{\left(-x\right)} \cdot y, z, x \cdot 1\right) \]
          19. lower-*.f6492.7

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

          \[\leadsto \color{blue}{\mathsf{fma}\left(\left(-x\right) \cdot y, z, x \cdot 1\right)} \]
        4. Taylor expanded in y around inf

          \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(y \cdot z\right)\right)} \]
        5. Step-by-step derivation
          1. *-commutativeN/A

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

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

            \[\leadsto \left(-1 \cdot \left(x \cdot z\right)\right) \cdot \color{blue}{y} \]
          4. lower-*.f64N/A

            \[\leadsto \left(-1 \cdot \left(x \cdot z\right)\right) \cdot \color{blue}{y} \]
          5. mul-1-negN/A

            \[\leadsto \left(\mathsf{neg}\left(x \cdot z\right)\right) \cdot y \]
          6. distribute-lft-neg-outN/A

            \[\leadsto \left(\left(\mathsf{neg}\left(x\right)\right) \cdot z\right) \cdot y \]
          7. lift-neg.f64N/A

            \[\leadsto \left(\left(-x\right) \cdot z\right) \cdot y \]
          8. *-commutativeN/A

            \[\leadsto \left(z \cdot \left(-x\right)\right) \cdot y \]
          9. lower-*.f6490.8

            \[\leadsto \left(z \cdot \left(-x\right)\right) \cdot y \]
        6. Applied rewrites90.8%

          \[\leadsto \color{blue}{\left(z \cdot \left(-x\right)\right) \cdot y} \]

        if -20 < (-.f64 #s(literal 1 binary64) (*.f64 y z)) < 5

        1. Initial program 100.0%

          \[x \cdot \left(1 - y \cdot z\right) \]
        2. Taylor expanded in y around 0

          \[\leadsto \color{blue}{x} \]
        3. Step-by-step derivation
          1. Applied rewrites98.1%

            \[\leadsto \color{blue}{x} \]
        4. Recombined 2 regimes into one program.
        5. Add Preprocessing

        Alternative 8: 50.9% accurate, 9.5× speedup?

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

          \[x \cdot \left(1 - y \cdot z\right) \]
        2. Taylor expanded in y around 0

          \[\leadsto \color{blue}{x} \]
        3. Step-by-step derivation
          1. Applied rewrites50.9%

            \[\leadsto \color{blue}{x} \]
          2. Add Preprocessing

          Reproduce

          ?
          herbie shell --seed 2025112 
          (FPCore (x y z)
            :name "Data.Colour.RGBSpace.HSV:hsv from colour-2.3.3, I"
            :precision binary64
            (* x (- 1.0 (* y z))))