Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B

Percentage Accurate: 100.0% → 100.0%
Time: 2.0s
Alternatives: 6
Speedup: 1.2×

Specification

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

\\
\left(x \cdot y + x\right) + y
\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 6 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 100.0% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 1.2× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \mathsf{fma}\left(y - -1, x, y\right) \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y) :precision binary64 (fma (- y -1.0) x y))
assert(x < y);
double code(double x, double y) {
	return fma((y - -1.0), x, y);
}
x, y = sort([x, y])
function code(x, y)
	return fma(Float64(y - -1.0), x, y)
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := N[(N[(y - -1.0), $MachinePrecision] * x + y), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\mathsf{fma}\left(y - -1, x, y\right)
\end{array}
Derivation
  1. Initial program 100.0%

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

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

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

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

      \[\leadsto \left(\color{blue}{y \cdot x} + x\right) + y \]
    5. distribute-lft1-inN/A

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(1 + y, x, y\right)} \]
    8. +-commutativeN/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{y + 1}, x, y\right) \]
    9. metadata-evalN/A

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

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

      \[\leadsto \mathsf{fma}\left(y - \color{blue}{-1} \cdot 1, x, y\right) \]
    12. metadata-evalN/A

      \[\leadsto \mathsf{fma}\left(y - \color{blue}{-1}, x, y\right) \]
    13. lower--.f64100.0

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

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

Alternative 2: 98.1% accurate, 0.5× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;\left(x \cdot y + x\right) + y \leq -1 \cdot 10^{-243}:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, x, y\right)\\ \end{array} \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
 :precision binary64
 (if (<= (+ (+ (* x y) x) y) -1e-243) (fma y x x) (fma y x y)))
assert(x < y);
double code(double x, double y) {
	double tmp;
	if ((((x * y) + x) + y) <= -1e-243) {
		tmp = fma(y, x, x);
	} else {
		tmp = fma(y, x, y);
	}
	return tmp;
}
x, y = sort([x, y])
function code(x, y)
	tmp = 0.0
	if (Float64(Float64(Float64(x * y) + x) + y) <= -1e-243)
		tmp = fma(y, x, x);
	else
		tmp = fma(y, x, y);
	end
	return tmp
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := If[LessEqual[N[(N[(N[(x * y), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision], -1e-243], N[(y * x + x), $MachinePrecision], N[(y * x + y), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(x \cdot y + x\right) + y \leq -1 \cdot 10^{-243}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, y\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (+.f64 (*.f64 x y) x) y) < -9.99999999999999995e-244

    1. Initial program 100.0%

      \[\left(x \cdot y + x\right) + y \]
    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.f6460.8

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

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

    if -9.99999999999999995e-244 < (+.f64 (+.f64 (*.f64 x y) x) y)

    1. Initial program 100.0%

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

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

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

        \[\leadsto y \cdot x + \color{blue}{y \cdot 1} \]
      3. *-rgt-identityN/A

        \[\leadsto y \cdot x + y \]
      4. lower-fma.f6466.7

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

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

Alternative 3: 99.0% accurate, 0.6× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y)
 :precision binary64
 (if (or (<= x -1.0) (not (<= x 1.0))) (fma y x x) (+ x y)))
assert(x < y);
double code(double x, double y) {
	double tmp;
	if ((x <= -1.0) || !(x <= 1.0)) {
		tmp = fma(y, x, x);
	} else {
		tmp = x + y;
	}
	return tmp;
}
x, y = sort([x, y])
function code(x, y)
	tmp = 0.0
	if ((x <= -1.0) || !(x <= 1.0))
		tmp = fma(y, x, x);
	else
		tmp = Float64(x + y);
	end
	return tmp
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(y * x + x), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\

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


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

    1. Initial program 100.0%

      \[\left(x \cdot y + x\right) + y \]
    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.f6499.1

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

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

    if -1 < x < 1

    1. Initial program 100.0%

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

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

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

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

    Alternative 4: 74.0% accurate, 0.7× speedup?

    \[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;\left(x \cdot y + x\right) + y \leq -1 \cdot 10^{-243}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \end{array} \]
    NOTE: x and y should be sorted in increasing order before calling this function.
    (FPCore (x y) :precision binary64 (if (<= (+ (+ (* x y) x) y) -1e-243) x y))
    assert(x < y);
    double code(double x, double y) {
    	double tmp;
    	if ((((x * y) + x) + y) <= -1e-243) {
    		tmp = x;
    	} else {
    		tmp = y;
    	}
    	return tmp;
    }
    
    NOTE: x and y should be sorted in increasing order before calling this function.
    module fmin_fmax_functions
        implicit none
        private
        public fmax
        public fmin
    
        interface fmax
            module procedure fmax88
            module procedure fmax44
            module procedure fmax84
            module procedure fmax48
        end interface
        interface fmin
            module procedure fmin88
            module procedure fmin44
            module procedure fmin84
            module procedure fmin48
        end interface
    contains
        real(8) function fmax88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(4) function fmax44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(8) function fmax84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmax48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
        end function
        real(8) function fmin88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(4) function fmin44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(8) function fmin84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmin48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
        end function
    end module
    
    real(8) function code(x, y)
    use fmin_fmax_functions
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        real(8) :: tmp
        if ((((x * y) + x) + y) <= (-1d-243)) then
            tmp = x
        else
            tmp = y
        end if
        code = tmp
    end function
    
    assert x < y;
    public static double code(double x, double y) {
    	double tmp;
    	if ((((x * y) + x) + y) <= -1e-243) {
    		tmp = x;
    	} else {
    		tmp = y;
    	}
    	return tmp;
    }
    
    [x, y] = sort([x, y])
    def code(x, y):
    	tmp = 0
    	if (((x * y) + x) + y) <= -1e-243:
    		tmp = x
    	else:
    		tmp = y
    	return tmp
    
    x, y = sort([x, y])
    function code(x, y)
    	tmp = 0.0
    	if (Float64(Float64(Float64(x * y) + x) + y) <= -1e-243)
    		tmp = x;
    	else
    		tmp = y;
    	end
    	return tmp
    end
    
    x, y = num2cell(sort([x, y])){:}
    function tmp_2 = code(x, y)
    	tmp = 0.0;
    	if ((((x * y) + x) + y) <= -1e-243)
    		tmp = x;
    	else
    		tmp = y;
    	end
    	tmp_2 = tmp;
    end
    
    NOTE: x and y should be sorted in increasing order before calling this function.
    code[x_, y_] := If[LessEqual[N[(N[(N[(x * y), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision], -1e-243], x, y]
    
    \begin{array}{l}
    [x, y] = \mathsf{sort}([x, y])\\
    \\
    \begin{array}{l}
    \mathbf{if}\;\left(x \cdot y + x\right) + y \leq -1 \cdot 10^{-243}:\\
    \;\;\;\;x\\
    
    \mathbf{else}:\\
    \;\;\;\;y\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (+.f64 (+.f64 (*.f64 x y) x) y) < -9.99999999999999995e-244

      1. Initial program 100.0%

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

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

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

        if -9.99999999999999995e-244 < (+.f64 (+.f64 (*.f64 x y) x) y)

        1. Initial program 100.0%

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

          \[\leadsto \color{blue}{y} \]
        4. Step-by-step derivation
          1. Applied rewrites41.6%

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

        Alternative 5: 75.2% accurate, 3.0× speedup?

        \[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ x + y \end{array} \]
        NOTE: x and y should be sorted in increasing order before calling this function.
        (FPCore (x y) :precision binary64 (+ x y))
        assert(x < y);
        double code(double x, double y) {
        	return x + y;
        }
        
        NOTE: x and y should be sorted in increasing order before calling this function.
        module fmin_fmax_functions
            implicit none
            private
            public fmax
            public fmin
        
            interface fmax
                module procedure fmax88
                module procedure fmax44
                module procedure fmax84
                module procedure fmax48
            end interface
            interface fmin
                module procedure fmin88
                module procedure fmin44
                module procedure fmin84
                module procedure fmin48
            end interface
        contains
            real(8) function fmax88(x, y) result (res)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
            end function
            real(4) function fmax44(x, y) result (res)
                real(4), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
            end function
            real(8) function fmax84(x, y) result(res)
                real(8), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
            end function
            real(8) function fmax48(x, y) result(res)
                real(4), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
            end function
            real(8) function fmin88(x, y) result (res)
                real(8), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
            end function
            real(4) function fmin44(x, y) result (res)
                real(4), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
            end function
            real(8) function fmin84(x, y) result(res)
                real(8), intent (in) :: x
                real(4), intent (in) :: y
                res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
            end function
            real(8) function fmin48(x, y) result(res)
                real(4), intent (in) :: x
                real(8), intent (in) :: y
                res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
            end function
        end module
        
        real(8) function code(x, y)
        use fmin_fmax_functions
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            code = x + y
        end function
        
        assert x < y;
        public static double code(double x, double y) {
        	return x + y;
        }
        
        [x, y] = sort([x, y])
        def code(x, y):
        	return x + y
        
        x, y = sort([x, y])
        function code(x, y)
        	return Float64(x + y)
        end
        
        x, y = num2cell(sort([x, y])){:}
        function tmp = code(x, y)
        	tmp = x + y;
        end
        
        NOTE: x and y should be sorted in increasing order before calling this function.
        code[x_, y_] := N[(x + y), $MachinePrecision]
        
        \begin{array}{l}
        [x, y] = \mathsf{sort}([x, y])\\
        \\
        x + y
        \end{array}
        
        Derivation
        1. Initial program 100.0%

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

          \[\leadsto \color{blue}{x} + y \]
        4. Step-by-step derivation
          1. Applied rewrites74.2%

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

          Alternative 6: 39.1% accurate, 12.0× speedup?

          \[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ x \end{array} \]
          NOTE: x and y should be sorted in increasing order before calling this function.
          (FPCore (x y) :precision binary64 x)
          assert(x < y);
          double code(double x, double y) {
          	return x;
          }
          
          NOTE: x and y should be sorted in increasing order before calling this function.
          module fmin_fmax_functions
              implicit none
              private
              public fmax
              public fmin
          
              interface fmax
                  module procedure fmax88
                  module procedure fmax44
                  module procedure fmax84
                  module procedure fmax48
              end interface
              interface fmin
                  module procedure fmin88
                  module procedure fmin44
                  module procedure fmin84
                  module procedure fmin48
              end interface
          contains
              real(8) function fmax88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(4) function fmax44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
              end function
              real(8) function fmax84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmax48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
              end function
              real(8) function fmin88(x, y) result (res)
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(4) function fmin44(x, y) result (res)
                  real(4), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
              end function
              real(8) function fmin84(x, y) result(res)
                  real(8), intent (in) :: x
                  real(4), intent (in) :: y
                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
              end function
              real(8) function fmin48(x, y) result(res)
                  real(4), intent (in) :: x
                  real(8), intent (in) :: y
                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
              end function
          end module
          
          real(8) function code(x, y)
          use fmin_fmax_functions
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              code = x
          end function
          
          assert x < y;
          public static double code(double x, double y) {
          	return x;
          }
          
          [x, y] = sort([x, y])
          def code(x, y):
          	return x
          
          x, y = sort([x, y])
          function code(x, y)
          	return x
          end
          
          x, y = num2cell(sort([x, y])){:}
          function tmp = code(x, y)
          	tmp = x;
          end
          
          NOTE: x and y should be sorted in increasing order before calling this function.
          code[x_, y_] := x
          
          \begin{array}{l}
          [x, y] = \mathsf{sort}([x, y])\\
          \\
          x
          \end{array}
          
          Derivation
          1. Initial program 100.0%

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

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

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

            Reproduce

            ?
            herbie shell --seed 2025057 
            (FPCore (x y)
              :name "Numeric.Log:$cexpm1 from log-domain-0.10.2.1, B"
              :precision binary64
              (+ (+ (* x y) x) y))