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

Percentage Accurate: 100.0% → 100.0%
Time: 1.6s
Alternatives: 7
Speedup: 1.1×

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: 100.0% accurate, 1.1× speedup?

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

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

    \[\left(x \cdot y + x\right) + y \]
  2. 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. lower-fma.f64N/A

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

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

      \[\leadsto \mathsf{fma}\left(\color{blue}{y - \left(\mathsf{neg}\left(1\right)\right)}, x, y\right) \]
    9. metadata-eval100.0

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

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

Alternative 3: 62.6% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(x \cdot y + x\right) + y \leq -2 \cdot 10^{-251}:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, x, y\right)\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= (+ (+ (* x y) x) y) -2e-251) (fma y x x) (fma y x y)))
double code(double x, double y) {
	double tmp;
	if ((((x * y) + x) + y) <= -2e-251) {
		tmp = fma(y, x, x);
	} else {
		tmp = fma(y, x, y);
	}
	return tmp;
}
function code(x, y)
	tmp = 0.0
	if (Float64(Float64(Float64(x * y) + x) + y) <= -2e-251)
		tmp = fma(y, x, x);
	else
		tmp = fma(y, x, y);
	end
	return tmp
end
code[x_, y_] := If[LessEqual[N[(N[(N[(x * y), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision], -2e-251], N[(y * x + x), $MachinePrecision], N[(y * x + y), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left(x \cdot y + x\right) + y \leq -2 \cdot 10^{-251}:\\
\;\;\;\;\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) < -2.00000000000000003e-251

    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.9%

        \[\leadsto \color{blue}{y} \]
      2. Taylor expanded in x around inf

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

          \[\leadsto x \cdot \color{blue}{\left(1 + y\right)} \]
        2. lower-+.f6462.3

          \[\leadsto x \cdot \left(1 + \color{blue}{y}\right) \]
      4. Applied rewrites62.3%

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

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

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

          \[\leadsto \left(1 + y\right) \cdot x \]
        4. +-commutativeN/A

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

          \[\leadsto y \cdot x + \color{blue}{x} \]
        6. lower-fma.f6462.3

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

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

      if -2.00000000000000003e-251 < (+.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. lower-*.f64N/A

          \[\leadsto y \cdot \color{blue}{\left(1 + x\right)} \]
        2. lower-+.f6463.4

          \[\leadsto y \cdot \left(1 + \color{blue}{x}\right) \]
      4. Applied rewrites63.4%

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

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

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

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

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

          \[\leadsto x \cdot y + y \]
        6. add-flip-revN/A

          \[\leadsto x \cdot y - \color{blue}{\left(\mathsf{neg}\left(y\right)\right)} \]
        7. sub-flipN/A

          \[\leadsto x \cdot y + \color{blue}{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)\right)} \]
        8. remove-double-negN/A

          \[\leadsto x \cdot y + y \]
        9. +-lft-identityN/A

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

          \[\leadsto x \cdot y + \left(y + \color{blue}{0}\right) \]
        11. remove-double-negN/A

          \[\leadsto x \cdot \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)\right) + \left(y + 0\right) \]
        12. remove-double-negN/A

          \[\leadsto \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) \cdot \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)\right) + \left(y + 0\right) \]
        13. remove-double-negN/A

          \[\leadsto \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) \cdot y + \left(y + 0\right) \]
        14. remove-double-negN/A

          \[\leadsto x \cdot y + \left(y + 0\right) \]
        15. *-rgt-identityN/A

          \[\leadsto \left(x \cdot 1\right) \cdot y + \left(y + 0\right) \]
        16. metadata-evalN/A

          \[\leadsto \left(x \cdot \left(\mathsf{neg}\left(-1\right)\right)\right) \cdot y + \left(y + 0\right) \]
        17. distribute-rgt-neg-outN/A

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

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

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

          \[\leadsto \left(\mathsf{neg}\left(x\right)\right) \cdot \left(-1 \cdot y\right) + \left(0 + \color{blue}{y}\right) \]
        21. +-lft-identityN/A

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

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

          \[\leadsto \left(\mathsf{neg}\left(x \cdot -1\right)\right) \cdot y + y \]
        24. distribute-rgt-neg-outN/A

          \[\leadsto \left(x \cdot \left(\mathsf{neg}\left(-1\right)\right)\right) \cdot y + y \]
        25. metadata-evalN/A

          \[\leadsto \left(x \cdot 1\right) \cdot y + y \]
        26. *-rgt-identityN/A

          \[\leadsto x \cdot y + y \]
        27. remove-double-negN/A

          \[\leadsto \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(x\right)\right)\right)\right) \cdot y + y \]
        28. remove-double-negN/A

          \[\leadsto x \cdot y + y \]
        29. remove-double-negN/A

          \[\leadsto x \cdot \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(y\right)\right)\right)\right) + y \]
        30. remove-double-negN/A

          \[\leadsto x \cdot y + y \]
        31. *-commutativeN/A

          \[\leadsto y \cdot x + y \]
      6. Applied rewrites63.4%

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

    Alternative 4: 61.8% accurate, 0.3× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(x \cdot y + x\right) + y\\ \mathbf{if}\;t\_0 \leq -2 \cdot 10^{-251}:\\ \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\ \mathbf{elif}\;t\_0 \leq 10^{+270}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
    (FPCore (x y)
     :precision binary64
     (let* ((t_0 (+ (+ (* x y) x) y)))
       (if (<= t_0 -2e-251) (fma y x x) (if (<= t_0 1e+270) y (* x y)))))
    double code(double x, double y) {
    	double t_0 = ((x * y) + x) + y;
    	double tmp;
    	if (t_0 <= -2e-251) {
    		tmp = fma(y, x, x);
    	} else if (t_0 <= 1e+270) {
    		tmp = y;
    	} else {
    		tmp = x * y;
    	}
    	return tmp;
    }
    
    function code(x, y)
    	t_0 = Float64(Float64(Float64(x * y) + x) + y)
    	tmp = 0.0
    	if (t_0 <= -2e-251)
    		tmp = fma(y, x, x);
    	elseif (t_0 <= 1e+270)
    		tmp = y;
    	else
    		tmp = Float64(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, -2e-251], N[(y * x + x), $MachinePrecision], If[LessEqual[t$95$0, 1e+270], y, N[(x * y), $MachinePrecision]]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \left(x \cdot y + x\right) + y\\
    \mathbf{if}\;t\_0 \leq -2 \cdot 10^{-251}:\\
    \;\;\;\;\mathsf{fma}\left(y, x, x\right)\\
    
    \mathbf{elif}\;t\_0 \leq 10^{+270}:\\
    \;\;\;\;y\\
    
    \mathbf{else}:\\
    \;\;\;\;x \cdot y\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if (+.f64 (+.f64 (*.f64 x y) x) y) < -2.00000000000000003e-251

      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.9%

          \[\leadsto \color{blue}{y} \]
        2. Taylor expanded in x around inf

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

            \[\leadsto x \cdot \color{blue}{\left(1 + y\right)} \]
          2. lower-+.f6462.3

            \[\leadsto x \cdot \left(1 + \color{blue}{y}\right) \]
        4. Applied rewrites62.3%

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

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

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

            \[\leadsto \left(1 + y\right) \cdot x \]
          4. +-commutativeN/A

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

            \[\leadsto y \cdot x + \color{blue}{x} \]
          6. lower-fma.f6462.3

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

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

        if -2.00000000000000003e-251 < (+.f64 (+.f64 (*.f64 x y) x) y) < 1e270

        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.9%

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

          if 1e270 < (+.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. lower-*.f64N/A

              \[\leadsto y \cdot \color{blue}{\left(1 + x\right)} \]
            2. lower-+.f6463.4

              \[\leadsto y \cdot \left(1 + \color{blue}{x}\right) \]
          4. Applied rewrites63.4%

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

            \[\leadsto x \cdot \color{blue}{y} \]
          6. Step-by-step derivation
            1. lower-*.f6426.7

              \[\leadsto x \cdot y \]
          7. Applied rewrites26.7%

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

        Alternative 5: 56.3% accurate, 0.2× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(x \cdot y + x\right) + y\\ \mathbf{if}\;t\_0 \leq -1 \cdot 10^{+306}:\\ \;\;\;\;x \cdot y\\ \mathbf{elif}\;t\_0 \leq -2 \cdot 10^{-251}:\\ \;\;\;\;x \cdot 1\\ \mathbf{elif}\;t\_0 \leq 10^{+270}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x \cdot y\\ \end{array} \end{array} \]
        (FPCore (x y)
         :precision binary64
         (let* ((t_0 (+ (+ (* x y) x) y)))
           (if (<= t_0 -1e+306)
             (* x y)
             (if (<= t_0 -2e-251) (* x 1.0) (if (<= t_0 1e+270) y (* x y))))))
        double code(double x, double y) {
        	double t_0 = ((x * y) + x) + y;
        	double tmp;
        	if (t_0 <= -1e+306) {
        		tmp = x * y;
        	} else if (t_0 <= -2e-251) {
        		tmp = x * 1.0;
        	} else if (t_0 <= 1e+270) {
        		tmp = 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)
        use fmin_fmax_functions
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            real(8) :: t_0
            real(8) :: tmp
            t_0 = ((x * y) + x) + y
            if (t_0 <= (-1d+306)) then
                tmp = x * y
            else if (t_0 <= (-2d-251)) then
                tmp = x * 1.0d0
            else if (t_0 <= 1d+270) then
                tmp = y
            else
                tmp = x * y
            end if
            code = tmp
        end function
        
        public static double code(double x, double y) {
        	double t_0 = ((x * y) + x) + y;
        	double tmp;
        	if (t_0 <= -1e+306) {
        		tmp = x * y;
        	} else if (t_0 <= -2e-251) {
        		tmp = x * 1.0;
        	} else if (t_0 <= 1e+270) {
        		tmp = y;
        	} else {
        		tmp = x * y;
        	}
        	return tmp;
        }
        
        def code(x, y):
        	t_0 = ((x * y) + x) + y
        	tmp = 0
        	if t_0 <= -1e+306:
        		tmp = x * y
        	elif t_0 <= -2e-251:
        		tmp = x * 1.0
        	elif t_0 <= 1e+270:
        		tmp = y
        	else:
        		tmp = x * y
        	return tmp
        
        function code(x, y)
        	t_0 = Float64(Float64(Float64(x * y) + x) + y)
        	tmp = 0.0
        	if (t_0 <= -1e+306)
        		tmp = Float64(x * y);
        	elseif (t_0 <= -2e-251)
        		tmp = Float64(x * 1.0);
        	elseif (t_0 <= 1e+270)
        		tmp = y;
        	else
        		tmp = Float64(x * y);
        	end
        	return tmp
        end
        
        function tmp_2 = code(x, y)
        	t_0 = ((x * y) + x) + y;
        	tmp = 0.0;
        	if (t_0 <= -1e+306)
        		tmp = x * y;
        	elseif (t_0 <= -2e-251)
        		tmp = x * 1.0;
        	elseif (t_0 <= 1e+270)
        		tmp = y;
        	else
        		tmp = x * y;
        	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, -1e+306], N[(x * y), $MachinePrecision], If[LessEqual[t$95$0, -2e-251], N[(x * 1.0), $MachinePrecision], If[LessEqual[t$95$0, 1e+270], y, N[(x * y), $MachinePrecision]]]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_0 := \left(x \cdot y + x\right) + y\\
        \mathbf{if}\;t\_0 \leq -1 \cdot 10^{+306}:\\
        \;\;\;\;x \cdot y\\
        
        \mathbf{elif}\;t\_0 \leq -2 \cdot 10^{-251}:\\
        \;\;\;\;x \cdot 1\\
        
        \mathbf{elif}\;t\_0 \leq 10^{+270}:\\
        \;\;\;\;y\\
        
        \mathbf{else}:\\
        \;\;\;\;x \cdot y\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 3 regimes
        2. if (+.f64 (+.f64 (*.f64 x y) x) y) < -1.00000000000000002e306 or 1e270 < (+.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. lower-*.f64N/A

              \[\leadsto y \cdot \color{blue}{\left(1 + x\right)} \]
            2. lower-+.f6463.4

              \[\leadsto y \cdot \left(1 + \color{blue}{x}\right) \]
          4. Applied rewrites63.4%

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

            \[\leadsto x \cdot \color{blue}{y} \]
          6. Step-by-step derivation
            1. lower-*.f6426.7

              \[\leadsto x \cdot y \]
          7. Applied rewrites26.7%

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

          if -1.00000000000000002e306 < (+.f64 (+.f64 (*.f64 x y) x) y) < -2.00000000000000003e-251

          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.9%

              \[\leadsto \color{blue}{y} \]
            2. Taylor expanded in x around inf

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

                \[\leadsto x \cdot \color{blue}{\left(1 + y\right)} \]
              2. lower-+.f6462.3

                \[\leadsto x \cdot \left(1 + \color{blue}{y}\right) \]
            4. Applied rewrites62.3%

              \[\leadsto \color{blue}{x \cdot \left(1 + y\right)} \]
            5. Taylor expanded in y around 0

              \[\leadsto x \cdot 1 \]
            6. Step-by-step derivation
              1. Applied rewrites37.9%

                \[\leadsto x \cdot 1 \]

              if -2.00000000000000003e-251 < (+.f64 (+.f64 (*.f64 x y) x) y) < 1e270

              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.9%

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

              Alternative 6: 50.0% accurate, 0.8× speedup?

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

                    \[\leadsto y \cdot \color{blue}{\left(1 + x\right)} \]
                  2. lower-+.f6463.4

                    \[\leadsto y \cdot \left(1 + \color{blue}{x}\right) \]
                4. Applied rewrites63.4%

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

                  \[\leadsto x \cdot \color{blue}{y} \]
                6. Step-by-step derivation
                  1. lower-*.f6426.7

                    \[\leadsto x \cdot y \]
                7. Applied rewrites26.7%

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

                if -4.1e17 < x < 1

                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.9%

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

                Alternative 7: 38.9% accurate, 9.4× speedup?

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

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

                  Reproduce

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