Main:bigenough2 from A

Percentage Accurate: 100.0% → 100.0%
Time: 2.5s
Alternatives: 7
Speedup: 1.2×

Specification

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

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

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

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

Alternative 1: 100.0% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(z + x, y, x\right) \end{array} \]
(FPCore (x y z) :precision binary64 (fma (+ z x) y x))
double code(double x, double y, double z) {
	return fma((z + x), y, x);
}
function code(x, y, z)
	return fma(Float64(z + x), y, x)
end
code[x_, y_, z_] := N[(N[(z + x), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(z + x, y, x\right)
\end{array}
Derivation
  1. Initial program 100.0%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(z + x, y, x\right)} \]
    7. lift-+.f64100.0

      \[\leadsto \mathsf{fma}\left(\color{blue}{z + x}, y, x\right) \]
  4. Applied rewrites100.0%

    \[\leadsto \color{blue}{\mathsf{fma}\left(z + x, y, x\right)} \]
  5. Add Preprocessing

Alternative 2: 60.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.7 \cdot 10^{-64}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;y \leq 4.1 \cdot 10^{-60}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.7 \cdot 10^{+39} \lor \neg \left(y \leq 6.5 \cdot 10^{+210}\right):\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= y -1.7e-64)
   (* z y)
   (if (<= y 4.1e-60)
     x
     (if (or (<= y 1.7e+39) (not (<= y 6.5e+210))) (* z y) (* x y)))))
double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.7e-64) {
		tmp = z * y;
	} else if (y <= 4.1e-60) {
		tmp = x;
	} else if ((y <= 1.7e+39) || !(y <= 6.5e+210)) {
		tmp = z * y;
	} else {
		tmp = x * y;
	}
	return tmp;
}
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
    real(8) :: tmp
    if (y <= (-1.7d-64)) then
        tmp = z * y
    else if (y <= 4.1d-60) then
        tmp = x
    else if ((y <= 1.7d+39) .or. (.not. (y <= 6.5d+210))) then
        tmp = z * y
    else
        tmp = x * y
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.7e-64) {
		tmp = z * y;
	} else if (y <= 4.1e-60) {
		tmp = x;
	} else if ((y <= 1.7e+39) || !(y <= 6.5e+210)) {
		tmp = z * y;
	} else {
		tmp = x * y;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if y <= -1.7e-64:
		tmp = z * y
	elif y <= 4.1e-60:
		tmp = x
	elif (y <= 1.7e+39) or not (y <= 6.5e+210):
		tmp = z * y
	else:
		tmp = x * y
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (y <= -1.7e-64)
		tmp = Float64(z * y);
	elseif (y <= 4.1e-60)
		tmp = x;
	elseif ((y <= 1.7e+39) || !(y <= 6.5e+210))
		tmp = Float64(z * y);
	else
		tmp = Float64(x * y);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -1.7e-64)
		tmp = z * y;
	elseif (y <= 4.1e-60)
		tmp = x;
	elseif ((y <= 1.7e+39) || ~((y <= 6.5e+210)))
		tmp = z * y;
	else
		tmp = x * y;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[y, -1.7e-64], N[(z * y), $MachinePrecision], If[LessEqual[y, 4.1e-60], x, If[Or[LessEqual[y, 1.7e+39], N[Not[LessEqual[y, 6.5e+210]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(x * y), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.7 \cdot 10^{-64}:\\
\;\;\;\;z \cdot y\\

\mathbf{elif}\;y \leq 4.1 \cdot 10^{-60}:\\
\;\;\;\;x\\

\mathbf{elif}\;y \leq 1.7 \cdot 10^{+39} \lor \neg \left(y \leq 6.5 \cdot 10^{+210}\right):\\
\;\;\;\;z \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.70000000000000006e-64 or 4.10000000000000013e-60 < y < 1.6999999999999999e39 or 6.4999999999999996e210 < y

    1. Initial program 99.9%

      \[x + y \cdot \left(z + x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0

      \[\leadsto \color{blue}{y \cdot z} \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto z \cdot \color{blue}{y} \]
      2. lower-*.f6461.4

        \[\leadsto z \cdot \color{blue}{y} \]
    5. Applied rewrites61.4%

      \[\leadsto \color{blue}{z \cdot y} \]

    if -1.70000000000000006e-64 < y < 4.10000000000000013e-60

    1. Initial program 100.0%

      \[x + y \cdot \left(z + x\right) \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0

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

        \[\leadsto \color{blue}{x} \]

      if 1.6999999999999999e39 < y < 6.4999999999999996e210

      1. Initial program 100.0%

        \[x + y \cdot \left(z + x\right) \]
      2. Add Preprocessing
      3. Taylor expanded in y around inf

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

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

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

          \[\leadsto \left(z + x\right) \cdot \color{blue}{y} \]
        4. lift-+.f64100.0

          \[\leadsto \left(z + x\right) \cdot y \]
      5. Applied rewrites100.0%

        \[\leadsto \color{blue}{\left(z + x\right) \cdot y} \]
      6. Taylor expanded in x around inf

        \[\leadsto x \cdot y \]
      7. Step-by-step derivation
        1. Applied rewrites73.3%

          \[\leadsto x \cdot y \]
      8. Recombined 3 regimes into one program.
      9. Final simplification69.2%

        \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.7 \cdot 10^{-64}:\\ \;\;\;\;z \cdot y\\ \mathbf{elif}\;y \leq 4.1 \cdot 10^{-60}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.7 \cdot 10^{+39} \lor \neg \left(y \leq 6.5 \cdot 10^{+210}\right):\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \]
      10. Add Preprocessing

      Alternative 3: 98.7% accurate, 0.6× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\ \;\;\;\;\left(z + x\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, y, x\right)\\ \end{array} \end{array} \]
      (FPCore (x y z)
       :precision binary64
       (if (or (<= y -1.0) (not (<= y 1.0))) (* (+ z x) y) (fma z y x)))
      double code(double x, double y, double z) {
      	double tmp;
      	if ((y <= -1.0) || !(y <= 1.0)) {
      		tmp = (z + x) * y;
      	} else {
      		tmp = fma(z, y, x);
      	}
      	return tmp;
      }
      
      function code(x, y, z)
      	tmp = 0.0
      	if ((y <= -1.0) || !(y <= 1.0))
      		tmp = Float64(Float64(z + x) * y);
      	else
      		tmp = fma(z, y, x);
      	end
      	return tmp
      end
      
      code[x_, y_, z_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(N[(z + x), $MachinePrecision] * y), $MachinePrecision], N[(z * y + x), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
      \;\;\;\;\left(z + x\right) \cdot y\\
      
      \mathbf{else}:\\
      \;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if y < -1 or 1 < y

        1. Initial program 99.9%

          \[x + y \cdot \left(z + x\right) \]
        2. Add Preprocessing
        3. Taylor expanded in y around inf

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

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

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

            \[\leadsto \left(z + x\right) \cdot \color{blue}{y} \]
          4. lift-+.f6498.7

            \[\leadsto \left(z + x\right) \cdot y \]
        5. Applied rewrites98.7%

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

        if -1 < y < 1

        1. Initial program 100.0%

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

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

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

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

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

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

            \[\leadsto \color{blue}{\mathsf{fma}\left(z + x, y, x\right)} \]
          7. lift-+.f64100.0

            \[\leadsto \mathsf{fma}\left(\color{blue}{z + x}, y, x\right) \]
        4. Applied rewrites100.0%

          \[\leadsto \color{blue}{\mathsf{fma}\left(z + x, y, x\right)} \]
        5. Taylor expanded in x around 0

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

            \[\leadsto \mathsf{fma}\left(\color{blue}{z}, y, x\right) \]
        7. Recombined 2 regimes into one program.
        8. Final simplification99.1%

          \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\ \;\;\;\;\left(z + x\right) \cdot y\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, y, x\right)\\ \end{array} \]
        9. Add Preprocessing

        Alternative 4: 86.8% accurate, 0.6× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -2.2 \cdot 10^{+18} \lor \neg \left(x \leq 8.5 \cdot 10^{+71}\right):\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, y, x\right)\\ \end{array} \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (if (or (<= x -2.2e+18) (not (<= x 8.5e+71))) (fma y x x) (fma z y x)))
        double code(double x, double y, double z) {
        	double tmp;
        	if ((x <= -2.2e+18) || !(x <= 8.5e+71)) {
        		tmp = fma(y, x, x);
        	} else {
        		tmp = fma(z, y, x);
        	}
        	return tmp;
        }
        
        function code(x, y, z)
        	tmp = 0.0
        	if ((x <= -2.2e+18) || !(x <= 8.5e+71))
        		tmp = fma(y, x, x);
        	else
        		tmp = fma(z, y, x);
        	end
        	return tmp
        end
        
        code[x_, y_, z_] := If[Or[LessEqual[x, -2.2e+18], N[Not[LessEqual[x, 8.5e+71]], $MachinePrecision]], N[(y * x + x), $MachinePrecision], N[(z * y + x), $MachinePrecision]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;x \leq -2.2 \cdot 10^{+18} \lor \neg \left(x \leq 8.5 \cdot 10^{+71}\right):\\
        \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if x < -2.2e18 or 8.4999999999999996e71 < x

          1. Initial program 100.0%

            \[x + y \cdot \left(z + x\right) \]
          2. Add Preprocessing
          3. Taylor expanded in x around inf

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

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

              \[\leadsto \left(y + 1\right) \cdot x \]
            3. distribute-lft1-inN/A

              \[\leadsto y \cdot x + \color{blue}{x} \]
            4. lower-fma.f6492.2

              \[\leadsto \mathsf{fma}\left(y, \color{blue}{x}, x\right) \]
          5. Applied rewrites92.2%

            \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, x\right)} \]

          if -2.2e18 < x < 8.4999999999999996e71

          1. Initial program 99.9%

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

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

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

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

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

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

              \[\leadsto \color{blue}{\mathsf{fma}\left(z + x, y, x\right)} \]
            7. lift-+.f64100.0

              \[\leadsto \mathsf{fma}\left(\color{blue}{z + x}, y, x\right) \]
          4. Applied rewrites100.0%

            \[\leadsto \color{blue}{\mathsf{fma}\left(z + x, y, x\right)} \]
          5. Taylor expanded in x around 0

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

              \[\leadsto \mathsf{fma}\left(\color{blue}{z}, y, x\right) \]
          7. Recombined 2 regimes into one program.
          8. Final simplification88.3%

            \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -2.2 \cdot 10^{+18} \lor \neg \left(x \leq 8.5 \cdot 10^{+71}\right):\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, y, x\right)\\ \end{array} \]
          9. Add Preprocessing

          Alternative 5: 72.9% accurate, 0.6× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -1.25 \cdot 10^{+165} \lor \neg \left(z \leq 1.3 \cdot 10^{-29}\right):\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \end{array} \end{array} \]
          (FPCore (x y z)
           :precision binary64
           (if (or (<= z -1.25e+165) (not (<= z 1.3e-29))) (* z y) (fma y x x)))
          double code(double x, double y, double z) {
          	double tmp;
          	if ((z <= -1.25e+165) || !(z <= 1.3e-29)) {
          		tmp = z * y;
          	} else {
          		tmp = fma(y, x, x);
          	}
          	return tmp;
          }
          
          function code(x, y, z)
          	tmp = 0.0
          	if ((z <= -1.25e+165) || !(z <= 1.3e-29))
          		tmp = Float64(z * y);
          	else
          		tmp = fma(y, x, x);
          	end
          	return tmp
          end
          
          code[x_, y_, z_] := If[Or[LessEqual[z, -1.25e+165], N[Not[LessEqual[z, 1.3e-29]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(y * x + x), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;z \leq -1.25 \cdot 10^{+165} \lor \neg \left(z \leq 1.3 \cdot 10^{-29}\right):\\
          \;\;\;\;z \cdot y\\
          
          \mathbf{else}:\\
          \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if z < -1.24999999999999993e165 or 1.3000000000000001e-29 < z

            1. Initial program 100.0%

              \[x + y \cdot \left(z + x\right) \]
            2. Add Preprocessing
            3. Taylor expanded in x around 0

              \[\leadsto \color{blue}{y \cdot z} \]
            4. Step-by-step derivation
              1. *-commutativeN/A

                \[\leadsto z \cdot \color{blue}{y} \]
              2. lower-*.f6480.7

                \[\leadsto z \cdot \color{blue}{y} \]
            5. Applied rewrites80.7%

              \[\leadsto \color{blue}{z \cdot y} \]

            if -1.24999999999999993e165 < z < 1.3000000000000001e-29

            1. Initial program 99.9%

              \[x + y \cdot \left(z + x\right) \]
            2. Add Preprocessing
            3. Taylor expanded in x around inf

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

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

                \[\leadsto \left(y + 1\right) \cdot x \]
              3. distribute-lft1-inN/A

                \[\leadsto y \cdot x + \color{blue}{x} \]
              4. lower-fma.f6477.8

                \[\leadsto \mathsf{fma}\left(y, \color{blue}{x}, x\right) \]
            5. Applied rewrites77.8%

              \[\leadsto \color{blue}{\mathsf{fma}\left(y, x, x\right)} \]
          3. Recombined 2 regimes into one program.
          4. Final simplification78.8%

            \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.25 \cdot 10^{+165} \lor \neg \left(z \leq 1.3 \cdot 10^{-29}\right):\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \end{array} \]
          5. Add Preprocessing

          Alternative 6: 60.3% accurate, 0.7× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;y \leq -1.7 \cdot 10^{-64} \lor \neg \left(y \leq 4.1 \cdot 10^{-60}\right):\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \end{array} \]
          (FPCore (x y z)
           :precision binary64
           (if (or (<= y -1.7e-64) (not (<= y 4.1e-60))) (* z y) x))
          double code(double x, double y, double z) {
          	double tmp;
          	if ((y <= -1.7e-64) || !(y <= 4.1e-60)) {
          		tmp = z * y;
          	} else {
          		tmp = x;
          	}
          	return tmp;
          }
          
          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
              real(8) :: tmp
              if ((y <= (-1.7d-64)) .or. (.not. (y <= 4.1d-60))) then
                  tmp = z * y
              else
                  tmp = x
              end if
              code = tmp
          end function
          
          public static double code(double x, double y, double z) {
          	double tmp;
          	if ((y <= -1.7e-64) || !(y <= 4.1e-60)) {
          		tmp = z * y;
          	} else {
          		tmp = x;
          	}
          	return tmp;
          }
          
          def code(x, y, z):
          	tmp = 0
          	if (y <= -1.7e-64) or not (y <= 4.1e-60):
          		tmp = z * y
          	else:
          		tmp = x
          	return tmp
          
          function code(x, y, z)
          	tmp = 0.0
          	if ((y <= -1.7e-64) || !(y <= 4.1e-60))
          		tmp = Float64(z * y);
          	else
          		tmp = x;
          	end
          	return tmp
          end
          
          function tmp_2 = code(x, y, z)
          	tmp = 0.0;
          	if ((y <= -1.7e-64) || ~((y <= 4.1e-60)))
          		tmp = z * y;
          	else
          		tmp = x;
          	end
          	tmp_2 = tmp;
          end
          
          code[x_, y_, z_] := If[Or[LessEqual[y, -1.7e-64], N[Not[LessEqual[y, 4.1e-60]], $MachinePrecision]], N[(z * y), $MachinePrecision], x]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;y \leq -1.7 \cdot 10^{-64} \lor \neg \left(y \leq 4.1 \cdot 10^{-60}\right):\\
          \;\;\;\;z \cdot y\\
          
          \mathbf{else}:\\
          \;\;\;\;x\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if y < -1.70000000000000006e-64 or 4.10000000000000013e-60 < y

            1. Initial program 100.0%

              \[x + y \cdot \left(z + x\right) \]
            2. Add Preprocessing
            3. Taylor expanded in x around 0

              \[\leadsto \color{blue}{y \cdot z} \]
            4. Step-by-step derivation
              1. *-commutativeN/A

                \[\leadsto z \cdot \color{blue}{y} \]
              2. lower-*.f6454.3

                \[\leadsto z \cdot \color{blue}{y} \]
            5. Applied rewrites54.3%

              \[\leadsto \color{blue}{z \cdot y} \]

            if -1.70000000000000006e-64 < y < 4.10000000000000013e-60

            1. Initial program 100.0%

              \[x + y \cdot \left(z + x\right) \]
            2. Add Preprocessing
            3. Taylor expanded in y around 0

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

                \[\leadsto \color{blue}{x} \]
            5. Recombined 2 regimes into one program.
            6. Final simplification63.4%

              \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.7 \cdot 10^{-64} \lor \neg \left(y \leq 4.1 \cdot 10^{-60}\right):\\ \;\;\;\;z \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
            7. Add Preprocessing

            Alternative 7: 36.7% accurate, 12.0× speedup?

            \[\begin{array}{l} \\ x \end{array} \]
            (FPCore (x y z) :precision binary64 x)
            double code(double x, double y, double z) {
            	return x;
            }
            
            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
            end function
            
            public static double code(double x, double y, double z) {
            	return x;
            }
            
            def code(x, y, z):
            	return x
            
            function code(x, y, z)
            	return x
            end
            
            function tmp = code(x, y, z)
            	tmp = x;
            end
            
            code[x_, y_, z_] := x
            
            \begin{array}{l}
            
            \\
            x
            \end{array}
            
            Derivation
            1. Initial program 100.0%

              \[x + y \cdot \left(z + x\right) \]
            2. Add Preprocessing
            3. Taylor expanded in y around 0

              \[\leadsto \color{blue}{x} \]
            4. Step-by-step derivation
              1. Applied rewrites37.0%

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

              Reproduce

              ?
              herbie shell --seed 2025051 
              (FPCore (x y z)
                :name "Main:bigenough2 from A"
                :precision binary64
                (+ x (* y (+ z x))))