Numeric.Log:$clog1p from log-domain-0.10.2.1, A

Percentage Accurate: 99.9% → 99.9%
Time: 3.4s
Alternatives: 6
Speedup: 1.2×

Specification

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

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

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

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

Alternative 1: 99.9% accurate, 1.2× speedup?

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

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

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

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

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

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

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

      \[\leadsto \left(x \cdot 2 + x \cdot x\right) + \color{blue}{y \cdot y} \]
    6. cancel-sign-subN/A

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

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

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

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

      \[\leadsto \left({x}^{2} + 2 \cdot x\right) - \color{blue}{\left(\mathsf{neg}\left(y \cdot y\right)\right)} \]
    11. pow2N/A

      \[\leadsto \left({x}^{2} + 2 \cdot x\right) - \left(\mathsf{neg}\left(\color{blue}{{y}^{2}}\right)\right) \]
    12. associate--l+N/A

      \[\leadsto \color{blue}{{x}^{2} + \left(2 \cdot x - \left(\mathsf{neg}\left({y}^{2}\right)\right)\right)} \]
    13. pow2N/A

      \[\leadsto \color{blue}{x \cdot x} + \left(2 \cdot x - \left(\mathsf{neg}\left({y}^{2}\right)\right)\right) \]
    14. pow2N/A

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, 2 \cdot x + {y}^{2}\right)} \]
    19. +-commutativeN/A

      \[\leadsto \mathsf{fma}\left(x, x, \color{blue}{{y}^{2} + 2 \cdot x}\right) \]
    20. pow2N/A

      \[\leadsto \mathsf{fma}\left(x, x, \color{blue}{y \cdot y} + 2 \cdot x\right) \]
    21. lower-fma.f64N/A

      \[\leadsto \mathsf{fma}\left(x, x, \color{blue}{\mathsf{fma}\left(y, y, 2 \cdot x\right)}\right) \]
    22. lower-*.f64100.0

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

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

Alternative 2: 58.3% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left(x \cdot 2 + x \cdot x\right) + y \cdot y \leq 4 \cdot 10^{-39}:\\ \;\;\;\;x + x\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \end{array} \]
(FPCore (x y)
 :precision binary64
 (if (<= (+ (+ (* x 2.0) (* x x)) (* y y)) 4e-39) (+ x x) (* x x)))
double code(double x, double y) {
	double tmp;
	if ((((x * 2.0) + (x * x)) + (y * y)) <= 4e-39) {
		tmp = x + x;
	} else {
		tmp = x * x;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if ((((x * 2.0d0) + (x * x)) + (y * y)) <= 4d-39) then
        tmp = x + x
    else
        tmp = x * x
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if ((((x * 2.0) + (x * x)) + (y * y)) <= 4e-39) {
		tmp = x + x;
	} else {
		tmp = x * x;
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if (((x * 2.0) + (x * x)) + (y * y)) <= 4e-39:
		tmp = x + x
	else:
		tmp = x * x
	return tmp
function code(x, y)
	tmp = 0.0
	if (Float64(Float64(Float64(x * 2.0) + Float64(x * x)) + Float64(y * y)) <= 4e-39)
		tmp = Float64(x + x);
	else
		tmp = Float64(x * x);
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if ((((x * 2.0) + (x * x)) + (y * y)) <= 4e-39)
		tmp = x + x;
	else
		tmp = x * x;
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[N[(N[(N[(x * 2.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision], 4e-39], N[(x + x), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left(x \cdot 2 + x \cdot x\right) + y \cdot y \leq 4 \cdot 10^{-39}:\\
\;\;\;\;x + x\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (+.f64 (*.f64 x #s(literal 2 binary64)) (*.f64 x x)) (*.f64 y y)) < 3.99999999999999972e-39

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{2 \cdot x + {x}^{2}} \]
    4. Step-by-step derivation
      1. Applied rewrites76.8%

        \[\leadsto \color{blue}{\left(x - -2\right) \cdot x} \]
      2. Step-by-step derivation
        1. Applied rewrites76.8%

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

          \[\leadsto x + x \]
        3. Step-by-step derivation
          1. Applied rewrites76.8%

            \[\leadsto x + x \]

          if 3.99999999999999972e-39 < (+.f64 (+.f64 (*.f64 x #s(literal 2 binary64)) (*.f64 x x)) (*.f64 y y))

          1. Initial program 100.0%

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

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

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

          Alternative 3: 90.6% accurate, 0.8× speedup?

          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot 2 + x \cdot x \leq 1000000000:\\ \;\;\;\;\mathsf{fma}\left(y, y, x + x\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x - -2\right) \cdot x\\ \end{array} \end{array} \]
          (FPCore (x y)
           :precision binary64
           (if (<= (+ (* x 2.0) (* x x)) 1000000000.0)
             (fma y y (+ x x))
             (* (- x -2.0) x)))
          double code(double x, double y) {
          	double tmp;
          	if (((x * 2.0) + (x * x)) <= 1000000000.0) {
          		tmp = fma(y, y, (x + x));
          	} else {
          		tmp = (x - -2.0) * x;
          	}
          	return tmp;
          }
          
          function code(x, y)
          	tmp = 0.0
          	if (Float64(Float64(x * 2.0) + Float64(x * x)) <= 1000000000.0)
          		tmp = fma(y, y, Float64(x + x));
          	else
          		tmp = Float64(Float64(x - -2.0) * x);
          	end
          	return tmp
          end
          
          code[x_, y_] := If[LessEqual[N[(N[(x * 2.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], 1000000000.0], N[(y * y + N[(x + x), $MachinePrecision]), $MachinePrecision], N[(N[(x - -2.0), $MachinePrecision] * x), $MachinePrecision]]
          
          \begin{array}{l}
          
          \\
          \begin{array}{l}
          \mathbf{if}\;x \cdot 2 + x \cdot x \leq 1000000000:\\
          \;\;\;\;\mathsf{fma}\left(y, y, x + x\right)\\
          
          \mathbf{else}:\\
          \;\;\;\;\left(x - -2\right) \cdot x\\
          
          
          \end{array}
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if (+.f64 (*.f64 x #s(literal 2 binary64)) (*.f64 x x)) < 1e9

            1. Initial program 100.0%

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

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

                \[\leadsto \color{blue}{\mathsf{fma}\left(y, y, 2 \cdot x\right)} \]
              2. Step-by-step derivation
                1. Applied rewrites100.0%

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

                if 1e9 < (+.f64 (*.f64 x #s(literal 2 binary64)) (*.f64 x x))

                1. Initial program 100.0%

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

                  \[\leadsto \color{blue}{2 \cdot x + {x}^{2}} \]
                4. Step-by-step derivation
                  1. Applied rewrites85.0%

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

                Alternative 4: 72.5% accurate, 0.9× speedup?

                \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot 2 + x \cdot x \leq 1000000000:\\ \;\;\;\;y \cdot y\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \end{array} \]
                (FPCore (x y)
                 :precision binary64
                 (if (<= (+ (* x 2.0) (* x x)) 1000000000.0) (* y y) (* x x)))
                double code(double x, double y) {
                	double tmp;
                	if (((x * 2.0) + (x * x)) <= 1000000000.0) {
                		tmp = y * y;
                	} else {
                		tmp = x * x;
                	}
                	return tmp;
                }
                
                module fmin_fmax_functions
                    implicit none
                    private
                    public fmax
                    public fmin
                
                    interface fmax
                        module procedure fmax88
                        module procedure fmax44
                        module procedure fmax84
                        module procedure fmax48
                    end interface
                    interface fmin
                        module procedure fmin88
                        module procedure fmin44
                        module procedure fmin84
                        module procedure fmin48
                    end interface
                contains
                    real(8) function fmax88(x, y) result (res)
                        real(8), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                    end function
                    real(4) function fmax44(x, y) result (res)
                        real(4), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                    end function
                    real(8) function fmax84(x, y) result(res)
                        real(8), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                    end function
                    real(8) function fmax48(x, y) result(res)
                        real(4), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                    end function
                    real(8) function fmin88(x, y) result (res)
                        real(8), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                    end function
                    real(4) function fmin44(x, y) result (res)
                        real(4), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                    end function
                    real(8) function fmin84(x, y) result(res)
                        real(8), intent (in) :: x
                        real(4), intent (in) :: y
                        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                    end function
                    real(8) function fmin48(x, y) result(res)
                        real(4), intent (in) :: x
                        real(8), intent (in) :: y
                        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                    end function
                end module
                
                real(8) function code(x, y)
                use fmin_fmax_functions
                    real(8), intent (in) :: x
                    real(8), intent (in) :: y
                    real(8) :: tmp
                    if (((x * 2.0d0) + (x * x)) <= 1000000000.0d0) then
                        tmp = y * y
                    else
                        tmp = x * x
                    end if
                    code = tmp
                end function
                
                public static double code(double x, double y) {
                	double tmp;
                	if (((x * 2.0) + (x * x)) <= 1000000000.0) {
                		tmp = y * y;
                	} else {
                		tmp = x * x;
                	}
                	return tmp;
                }
                
                def code(x, y):
                	tmp = 0
                	if ((x * 2.0) + (x * x)) <= 1000000000.0:
                		tmp = y * y
                	else:
                		tmp = x * x
                	return tmp
                
                function code(x, y)
                	tmp = 0.0
                	if (Float64(Float64(x * 2.0) + Float64(x * x)) <= 1000000000.0)
                		tmp = Float64(y * y);
                	else
                		tmp = Float64(x * x);
                	end
                	return tmp
                end
                
                function tmp_2 = code(x, y)
                	tmp = 0.0;
                	if (((x * 2.0) + (x * x)) <= 1000000000.0)
                		tmp = y * y;
                	else
                		tmp = x * x;
                	end
                	tmp_2 = tmp;
                end
                
                code[x_, y_] := If[LessEqual[N[(N[(x * 2.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], 1000000000.0], N[(y * y), $MachinePrecision], N[(x * x), $MachinePrecision]]
                
                \begin{array}{l}
                
                \\
                \begin{array}{l}
                \mathbf{if}\;x \cdot 2 + x \cdot x \leq 1000000000:\\
                \;\;\;\;y \cdot y\\
                
                \mathbf{else}:\\
                \;\;\;\;x \cdot x\\
                
                
                \end{array}
                \end{array}
                
                Derivation
                1. Split input into 2 regimes
                2. if (+.f64 (*.f64 x #s(literal 2 binary64)) (*.f64 x x)) < 1e9

                  1. Initial program 100.0%

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

                    \[\leadsto \color{blue}{{y}^{2}} \]
                  4. Step-by-step derivation
                    1. Applied rewrites67.8%

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

                    if 1e9 < (+.f64 (*.f64 x #s(literal 2 binary64)) (*.f64 x x))

                    1. Initial program 100.0%

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

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

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

                    Alternative 5: 71.8% accurate, 1.5× speedup?

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

                      1. Initial program 100.0%

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

                        \[\leadsto \color{blue}{2 \cdot x + {x}^{2}} \]
                      4. Step-by-step derivation
                        1. Applied rewrites68.0%

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

                        if 1.55e-20 < y

                        1. Initial program 100.0%

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

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

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

                        Alternative 6: 20.8% accurate, 5.5× speedup?

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

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

                          \[\leadsto \color{blue}{2 \cdot x + {x}^{2}} \]
                        4. Step-by-step derivation
                          1. Applied rewrites59.9%

                            \[\leadsto \color{blue}{\left(x - -2\right) \cdot x} \]
                          2. Step-by-step derivation
                            1. Applied rewrites59.9%

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

                              \[\leadsto x + x \]
                            3. Step-by-step derivation
                              1. Applied rewrites19.4%

                                \[\leadsto x + x \]
                              2. Add Preprocessing

                              Developer Target 1: 99.9% accurate, 1.0× speedup?

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

                              Reproduce

                              ?
                              herbie shell --seed 2025026 
                              (FPCore (x y)
                                :name "Numeric.Log:$clog1p from log-domain-0.10.2.1, A"
                                :precision binary64
                              
                                :alt
                                (! :herbie-platform default (+ (* y y) (+ (* 2 x) (* x x))))
                              
                                (+ (+ (* x 2.0) (* x x)) (* y y)))