Examples.Basics.ProofTests:f4 from sbv-4.4

Percentage Accurate: 93.5% → 96.6%
Time: 4.8s
Alternatives: 7
Speedup: 1.5×

Specification

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

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

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

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

Alternative 1: 96.6% accurate, 1.5× speedup?

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(x, x, \color{blue}{\left(x \cdot 2\right) \cdot y} + y \cdot y\right) \]
    8. distribute-rgt-outN/A

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

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

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

      \[\leadsto \mathsf{fma}\left(x, x, y \cdot \left(\color{blue}{2 \cdot x} + y\right)\right) \]
    12. lower-fma.f6495.7

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

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

Alternative 2: 86.8% accurate, 1.3× speedup?

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 9.0000000000000002e-110

    1. Initial program 92.8%

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(x, x, \color{blue}{\left(x \cdot 2\right) \cdot y} + y \cdot y\right) \]
      8. distribute-rgt-outN/A

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

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

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

        \[\leadsto \mathsf{fma}\left(x, x, y \cdot \left(\color{blue}{2 \cdot x} + y\right)\right) \]
      12. lower-fma.f6494.1

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

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

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

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

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

        if 9.0000000000000002e-110 < y

        1. Initial program 93.1%

          \[\left(x \cdot x + \left(x \cdot 2\right) \cdot y\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 rewrites64.9%

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

        Alternative 3: 86.8% accurate, 1.3× speedup?

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

          1. Initial program 92.8%

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

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

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

                \[\leadsto \left(\left(x + y\right) + y\right) \cdot x \]
              2. Step-by-step derivation
                1. Applied rewrites71.0%

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

                if 9.0000000000000002e-110 < y

                1. Initial program 93.1%

                  \[\left(x \cdot x + \left(x \cdot 2\right) \cdot y\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 rewrites64.9%

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

                Alternative 4: 86.8% accurate, 1.5× speedup?

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

                  1. Initial program 92.8%

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

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

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

                        \[\leadsto \left(\left(x + y\right) + y\right) \cdot x \]

                      if 9.0000000000000002e-110 < y

                      1. Initial program 93.1%

                        \[\left(x \cdot x + \left(x \cdot 2\right) \cdot y\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 rewrites64.9%

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

                      Alternative 5: 86.6% accurate, 1.8× speedup?

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

                        1. Initial program 92.8%

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

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

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

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

                              \[\leadsto \left(x + y\right) \cdot x \]
                            3. Step-by-step derivation
                              1. Applied rewrites70.1%

                                \[\leadsto \left(x + y\right) \cdot x \]

                              if 9.0000000000000002e-110 < y

                              1. Initial program 93.1%

                                \[\left(x \cdot x + \left(x \cdot 2\right) \cdot y\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 rewrites64.9%

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

                              Alternative 6: 86.6% accurate, 2.2× speedup?

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

                                1. Initial program 92.8%

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

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

                                  if 9.0000000000000002e-110 < y

                                  1. Initial program 93.1%

                                    \[\left(x \cdot x + \left(x \cdot 2\right) \cdot y\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 rewrites64.9%

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

                                  Alternative 7: 58.0% accurate, 4.5× speedup?

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

                                    \[\left(x \cdot x + \left(x \cdot 2\right) \cdot y\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 rewrites59.6%

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

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

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

                                    Reproduce

                                    ?
                                    herbie shell --seed 2025019 
                                    (FPCore (x y)
                                      :name "Examples.Basics.ProofTests:f4 from sbv-4.4"
                                      :precision binary64
                                    
                                      :alt
                                      (! :herbie-platform default (+ (* x x) (+ (* y y) (* (* x y) 2))))
                                    
                                      (+ (+ (* x x) (* (* x 2.0) y)) (* y y)))