Examples.Basics.ProofTests:f4 from sbv-4.4

Percentage Accurate: 94.0% → 100.0%
Time: 1.7s
Alternatives: 3
Speedup: 1.9×

Specification

?
\[\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y \]
(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]
\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y

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 3 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: 94.0% accurate, 1.0× speedup?

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

Alternative 1: 100.0% accurate, 1.9× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left({x}^{2} + 2 \cdot \left(x \cdot y\right)\right) + \color{blue}{{y}^{2}} \]
    14. sum-square-pow-revN/A

      \[\leadsto \color{blue}{{\left(x + y\right)}^{2}} \]
    15. unpow2N/A

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

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

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

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

      \[\leadsto \left(y + x\right) \cdot \color{blue}{\left(y + x\right)} \]
    20. lower-+.f64100.0%

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

    \[\leadsto \color{blue}{\left(y + x\right) \cdot \left(y + x\right)} \]
  4. Add Preprocessing

Alternative 2: 87.2% accurate, 1.1× speedup?

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

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

real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8) :: tmp
    if (fmax(x, y) <= 9.6d-143) then
        tmp = fmin(x, y) * fmin(x, y)
    else
        tmp = fmax(x, y) * fmax(x, y)
    end if
    code = tmp
end function
public static double code(double x, double y) {
	double tmp;
	if (fmax(x, y) <= 9.6e-143) {
		tmp = fmin(x, y) * fmin(x, y);
	} else {
		tmp = fmax(x, y) * fmax(x, y);
	}
	return tmp;
}
def code(x, y):
	tmp = 0
	if fmax(x, y) <= 9.6e-143:
		tmp = fmin(x, y) * fmin(x, y)
	else:
		tmp = fmax(x, y) * fmax(x, y)
	return tmp
function code(x, y)
	tmp = 0.0
	if (fmax(x, y) <= 9.6e-143)
		tmp = Float64(fmin(x, y) * fmin(x, y));
	else
		tmp = Float64(fmax(x, y) * fmax(x, y));
	end
	return tmp
end
function tmp_2 = code(x, y)
	tmp = 0.0;
	if (max(x, y) <= 9.6e-143)
		tmp = min(x, y) * min(x, y);
	else
		tmp = max(x, y) * max(x, y);
	end
	tmp_2 = tmp;
end
code[x_, y_] := If[LessEqual[N[Max[x, y], $MachinePrecision], 9.6e-143], N[(N[Min[x, y], $MachinePrecision] * N[Min[x, y], $MachinePrecision]), $MachinePrecision], N[(N[Max[x, y], $MachinePrecision] * N[Max[x, y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\mathsf{max}\left(x, y\right) \leq 9.6 \cdot 10^{-143}:\\
\;\;\;\;\mathsf{min}\left(x, y\right) \cdot \mathsf{min}\left(x, y\right)\\

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


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

    1. Initial program 94.0%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left({x}^{2} + 2 \cdot \left(x \cdot y\right)\right) + \color{blue}{{y}^{2}} \]
      14. sum-square-pow-revN/A

        \[\leadsto \color{blue}{{\left(x + y\right)}^{2}} \]
      15. unpow2N/A

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

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

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

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

        \[\leadsto \left(y + x\right) \cdot \color{blue}{\left(y + x\right)} \]
      20. lower-+.f64100.0%

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

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

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

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

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

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

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

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

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

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

            if 9.5999999999999995e-143 < y

            1. Initial program 94.0%

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \left({x}^{2} + 2 \cdot \left(x \cdot y\right)\right) + \color{blue}{{y}^{2}} \]
              14. sum-square-pow-revN/A

                \[\leadsto \color{blue}{{\left(x + y\right)}^{2}} \]
              15. unpow2N/A

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

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

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

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

                \[\leadsto \left(y + x\right) \cdot \color{blue}{\left(y + x\right)} \]
              20. lower-+.f64100.0%

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

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

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

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

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

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

              Alternative 3: 57.3% accurate, 1.8× speedup?

              \[\mathsf{min}\left(x, y\right) \cdot \mathsf{min}\left(x, y\right) \]
              (FPCore (x y) :precision binary64 (* (fmin x y) (fmin x y)))
              double code(double x, double y) {
              	return fmin(x, y) * fmin(x, y);
              }
              
              module fmin_fmax_functions
                  implicit none
                  private
                  public fmax
                  public fmin
              
                  interface fmax
                      module procedure fmax88
                      module procedure fmax44
                      module procedure fmax84
                      module procedure fmax48
                  end interface
                  interface fmin
                      module procedure fmin88
                      module procedure fmin44
                      module procedure fmin84
                      module procedure fmin48
                  end interface
              contains
                  real(8) function fmax88(x, y) result (res)
                      real(8), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                  end function
                  real(4) function fmax44(x, y) result (res)
                      real(4), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                  end function
                  real(8) function fmax84(x, y) result(res)
                      real(8), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                  end function
                  real(8) function fmax48(x, y) result(res)
                      real(4), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                  end function
                  real(8) function fmin88(x, y) result (res)
                      real(8), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                  end function
                  real(4) function fmin44(x, y) result (res)
                      real(4), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                  end function
                  real(8) function fmin84(x, y) result(res)
                      real(8), intent (in) :: x
                      real(4), intent (in) :: y
                      res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                  end function
                  real(8) function fmin48(x, y) result(res)
                      real(4), intent (in) :: x
                      real(8), intent (in) :: y
                      res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                  end function
              end module
              
              real(8) function code(x, y)
              use fmin_fmax_functions
                  real(8), intent (in) :: x
                  real(8), intent (in) :: y
                  code = fmin(x, y) * fmin(x, y)
              end function
              
              public static double code(double x, double y) {
              	return fmin(x, y) * fmin(x, y);
              }
              
              def code(x, y):
              	return fmin(x, y) * fmin(x, y)
              
              function code(x, y)
              	return Float64(fmin(x, y) * fmin(x, y))
              end
              
              function tmp = code(x, y)
              	tmp = min(x, y) * min(x, y);
              end
              
              code[x_, y_] := N[(N[Min[x, y], $MachinePrecision] * N[Min[x, y], $MachinePrecision]), $MachinePrecision]
              
              \mathsf{min}\left(x, y\right) \cdot \mathsf{min}\left(x, y\right)
              
              Derivation
              1. Initial program 94.0%

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

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

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto \left({x}^{2} + 2 \cdot \left(x \cdot y\right)\right) + \color{blue}{{y}^{2}} \]
                14. sum-square-pow-revN/A

                  \[\leadsto \color{blue}{{\left(x + y\right)}^{2}} \]
                15. unpow2N/A

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

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

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

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

                  \[\leadsto \left(y + x\right) \cdot \color{blue}{\left(y + x\right)} \]
                20. lower-+.f64100.0%

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

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

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

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

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

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

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

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

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

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

                      Reproduce

                      ?
                      herbie shell --seed 2025188 
                      (FPCore (x y)
                        :name "Examples.Basics.ProofTests:f4 from sbv-4.4"
                        :precision binary64
                        (+ (+ (* x x) (* (* x 2.0) y)) (* y y)))