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

Percentage Accurate: 100.0% → 100.0%
Time: 1.4s
Alternatives: 7
Speedup: 1.0×

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}

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} \\ \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.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}
Derivation
  1. Initial program 100.0%

    \[\left(x \cdot y + x\right) + y \]
  2. Add Preprocessing

Alternative 2: 75.7% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(x \cdot y + x\right) + y\\ \mathbf{if}\;t\_0 \leq -4 \cdot 10^{+38}:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-28}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, x, y\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (+ (+ (* x y) x) y)))
   (if (<= t_0 -4e+38) (fma y x x) (if (<= t_0 2e-28) (+ x y) (fma y x y)))))
double code(double x, double y) {
	double t_0 = ((x * y) + x) + y;
	double tmp;
	if (t_0 <= -4e+38) {
		tmp = fma(y, x, x);
	} else if (t_0 <= 2e-28) {
		tmp = x + y;
	} else {
		tmp = fma(y, x, y);
	}
	return tmp;
}
function code(x, y)
	t_0 = Float64(Float64(Float64(x * y) + x) + y)
	tmp = 0.0
	if (t_0 <= -4e+38)
		tmp = fma(y, x, x);
	elseif (t_0 <= 2e-28)
		tmp = Float64(x + y);
	else
		tmp = fma(y, x, y);
	end
	return tmp
end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x * y), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision]}, If[LessEqual[t$95$0, -4e+38], N[(y * x + x), $MachinePrecision], If[LessEqual[t$95$0, 2e-28], N[(x + y), $MachinePrecision], N[(y * x + y), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(x \cdot y + x\right) + y\\
\mathbf{if}\;t\_0 \leq -4 \cdot 10^{+38}:\\
\;\;\;\;\mathsf{fma}\left(y, x, x\right)\\

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-28}:\\
\;\;\;\;x + y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (+.f64 (+.f64 (*.f64 x y) x) y) < -3.99999999999999991e38

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x \cdot \left(1 + y\right)} \]
    3. 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.f6469.4

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

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

    if -3.99999999999999991e38 < (+.f64 (+.f64 (*.f64 x y) x) y) < 1.99999999999999994e-28

    1. Initial program 100.0%

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

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

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

      if 1.99999999999999994e-28 < (+.f64 (+.f64 (*.f64 x y) x) y)

      1. Initial program 100.0%

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

        \[\leadsto \color{blue}{y \cdot \left(1 + x\right)} \]
      3. 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.f6465.7

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

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

    Alternative 3: 86.6% accurate, 0.3× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(x \cdot y + x\right) + y\\ \mathbf{if}\;t\_0 \leq -\infty:\\ \;\;\;\;y \cdot x\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+305}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \end{array} \]
    (FPCore (x y)
     :precision binary64
     (let* ((t_0 (+ (+ (* x y) x) y)))
       (if (<= t_0 (- INFINITY)) (* y x) (if (<= t_0 2e+305) (+ x y) (* y x)))))
    double code(double x, double y) {
    	double t_0 = ((x * y) + x) + y;
    	double tmp;
    	if (t_0 <= -((double) INFINITY)) {
    		tmp = y * x;
    	} else if (t_0 <= 2e+305) {
    		tmp = x + y;
    	} else {
    		tmp = y * x;
    	}
    	return tmp;
    }
    
    public static double code(double x, double y) {
    	double t_0 = ((x * y) + x) + y;
    	double tmp;
    	if (t_0 <= -Double.POSITIVE_INFINITY) {
    		tmp = y * x;
    	} else if (t_0 <= 2e+305) {
    		tmp = x + y;
    	} else {
    		tmp = y * x;
    	}
    	return tmp;
    }
    
    def code(x, y):
    	t_0 = ((x * y) + x) + y
    	tmp = 0
    	if t_0 <= -math.inf:
    		tmp = y * x
    	elif t_0 <= 2e+305:
    		tmp = x + y
    	else:
    		tmp = y * x
    	return tmp
    
    function code(x, y)
    	t_0 = Float64(Float64(Float64(x * y) + x) + y)
    	tmp = 0.0
    	if (t_0 <= Float64(-Inf))
    		tmp = Float64(y * x);
    	elseif (t_0 <= 2e+305)
    		tmp = Float64(x + y);
    	else
    		tmp = Float64(y * x);
    	end
    	return tmp
    end
    
    function tmp_2 = code(x, y)
    	t_0 = ((x * y) + x) + y;
    	tmp = 0.0;
    	if (t_0 <= -Inf)
    		tmp = y * x;
    	elseif (t_0 <= 2e+305)
    		tmp = x + y;
    	else
    		tmp = y * x;
    	end
    	tmp_2 = tmp;
    end
    
    code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x * y), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(y * x), $MachinePrecision], If[LessEqual[t$95$0, 2e+305], N[(x + y), $MachinePrecision], N[(y * x), $MachinePrecision]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \left(x \cdot y + x\right) + y\\
    \mathbf{if}\;t\_0 \leq -\infty:\\
    \;\;\;\;y \cdot x\\
    
    \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+305}:\\
    \;\;\;\;x + y\\
    
    \mathbf{else}:\\
    \;\;\;\;y \cdot x\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if (+.f64 (+.f64 (*.f64 x y) x) y) < -inf.0 or 1.9999999999999999e305 < (+.f64 (+.f64 (*.f64 x y) x) y)

      1. Initial program 100.0%

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

        \[\leadsto \color{blue}{y \cdot \left(1 + x\right)} \]
      3. 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.f6498.7

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

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

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

          \[\leadsto y \cdot x \]
        2. lower-*.f6497.8

          \[\leadsto y \cdot x \]
      7. Applied rewrites97.8%

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

      if -inf.0 < (+.f64 (+.f64 (*.f64 x y) x) y) < 1.9999999999999999e305

      1. Initial program 100.0%

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

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

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

      Alternative 4: 86.3% accurate, 0.7× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{elif}\;x \leq 680:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array} \end{array} \]
      (FPCore (x y)
       :precision binary64
       (if (<= x -1.0) (fma y x x) (if (<= x 680.0) (+ x y) (* y x))))
      double code(double x, double y) {
      	double tmp;
      	if (x <= -1.0) {
      		tmp = fma(y, x, x);
      	} else if (x <= 680.0) {
      		tmp = x + y;
      	} else {
      		tmp = y * x;
      	}
      	return tmp;
      }
      
      function code(x, y)
      	tmp = 0.0
      	if (x <= -1.0)
      		tmp = fma(y, x, x);
      	elseif (x <= 680.0)
      		tmp = Float64(x + y);
      	else
      		tmp = Float64(y * x);
      	end
      	return tmp
      end
      
      code[x_, y_] := If[LessEqual[x, -1.0], N[(y * x + x), $MachinePrecision], If[LessEqual[x, 680.0], N[(x + y), $MachinePrecision], N[(y * x), $MachinePrecision]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;x \leq -1:\\
      \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
      
      \mathbf{elif}\;x \leq 680:\\
      \;\;\;\;x + y\\
      
      \mathbf{else}:\\
      \;\;\;\;y \cdot x\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 regimes
      2. if x < -1

        1. Initial program 100.0%

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

          \[\leadsto \color{blue}{x \cdot \left(1 + y\right)} \]
        3. 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.f6498.8

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

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

        if -1 < x < 680

        1. Initial program 100.0%

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

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

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

          if 680 < x

          1. Initial program 100.0%

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

            \[\leadsto \color{blue}{y \cdot \left(1 + x\right)} \]
          3. 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.f6450.5

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

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

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

              \[\leadsto y \cdot x \]
            2. lower-*.f6449.8

              \[\leadsto y \cdot x \]
          7. Applied rewrites49.8%

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

        Alternative 5: 38.5% accurate, 0.7× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(x \cdot y + x\right) + y \leq -2 \cdot 10^{-244}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y\\ \end{array} \end{array} \]
        (FPCore (x y) :precision binary64 (if (<= (+ (+ (* x y) x) y) -2e-244) x y))
        double code(double x, double y) {
        	double tmp;
        	if ((((x * y) + x) + y) <= -2e-244) {
        		tmp = x;
        	} else {
        		tmp = 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)
        use fmin_fmax_functions
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            real(8) :: tmp
            if ((((x * y) + x) + y) <= (-2d-244)) then
                tmp = x
            else
                tmp = y
            end if
            code = tmp
        end function
        
        public static double code(double x, double y) {
        	double tmp;
        	if ((((x * y) + x) + y) <= -2e-244) {
        		tmp = x;
        	} else {
        		tmp = y;
        	}
        	return tmp;
        }
        
        def code(x, y):
        	tmp = 0
        	if (((x * y) + x) + y) <= -2e-244:
        		tmp = x
        	else:
        		tmp = y
        	return tmp
        
        function code(x, y)
        	tmp = 0.0
        	if (Float64(Float64(Float64(x * y) + x) + y) <= -2e-244)
        		tmp = x;
        	else
        		tmp = y;
        	end
        	return tmp
        end
        
        function tmp_2 = code(x, y)
        	tmp = 0.0;
        	if ((((x * y) + x) + y) <= -2e-244)
        		tmp = x;
        	else
        		tmp = y;
        	end
        	tmp_2 = tmp;
        end
        
        code[x_, y_] := If[LessEqual[N[(N[(N[(x * y), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision], -2e-244], x, y]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;\left(x \cdot y + x\right) + y \leq -2 \cdot 10^{-244}:\\
        \;\;\;\;x\\
        
        \mathbf{else}:\\
        \;\;\;\;y\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (+.f64 (+.f64 (*.f64 x y) x) y) < -1.9999999999999999e-244

          1. Initial program 100.0%

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

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

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

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

            1. Initial program 100.0%

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

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

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

            Alternative 6: 74.7% accurate, 3.0× speedup?

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

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

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

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

              Alternative 7: 38.8% accurate, 12.0× speedup?

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

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

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

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

                Reproduce

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