Linear.Quaternion:$c/ from linear-1.19.1.3, A

Percentage Accurate: 98.4% → 98.9%
Time: 3.6s
Alternatives: 10
Speedup: 1.8×

Specification

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

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

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

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

Alternative 1: 98.9% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(z \cdot z + \color{blue}{z \cdot z}\right) + \left(x \cdot y + z \cdot z\right) \]
    15. distribute-lft-outN/A

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(z, z + z, \mathsf{fma}\left(z, z, \color{blue}{y \cdot x}\right)\right) \]
    23. lower-*.f6499.2

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

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

Alternative 2: 83.3% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -4 \cdot 10^{-45} \lor \neg \left(x \cdot y \leq 10^{-313}\right):\\ \;\;\;\;\mathsf{fma}\left(z, z + z, x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2 \cdot z, z, z \cdot z\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= (* x y) -4e-45) (not (<= (* x y) 1e-313)))
   (fma z (+ z z) (* x y))
   (fma (* 2.0 z) z (* z z))))
double code(double x, double y, double z) {
	double tmp;
	if (((x * y) <= -4e-45) || !((x * y) <= 1e-313)) {
		tmp = fma(z, (z + z), (x * y));
	} else {
		tmp = fma((2.0 * z), z, (z * z));
	}
	return tmp;
}
function code(x, y, z)
	tmp = 0.0
	if ((Float64(x * y) <= -4e-45) || !(Float64(x * y) <= 1e-313))
		tmp = fma(z, Float64(z + z), Float64(x * y));
	else
		tmp = fma(Float64(2.0 * z), z, Float64(z * z));
	end
	return tmp
end
code[x_, y_, z_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -4e-45], N[Not[LessEqual[N[(x * y), $MachinePrecision], 1e-313]], $MachinePrecision]], N[(z * N[(z + z), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * z), $MachinePrecision] * z + N[(z * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \cdot y \leq -4 \cdot 10^{-45} \lor \neg \left(x \cdot y \leq 10^{-313}\right):\\
\;\;\;\;\mathsf{fma}\left(z, z + z, x \cdot y\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2 \cdot z, z, z \cdot z\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -3.99999999999999994e-45 or 1.00000000001e-313 < (*.f64 x y)

    1. Initial program 96.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(z \cdot z + \color{blue}{z \cdot z}\right) + \left(x \cdot y + z \cdot z\right) \]
      15. distribute-lft-outN/A

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(z, z + z, \mathsf{fma}\left(z, z, \color{blue}{y \cdot x}\right)\right) \]
      23. lower-*.f6498.9

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

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

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

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

      if -3.99999999999999994e-45 < (*.f64 x y) < 1.00000000001e-313

      1. Initial program 99.8%

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

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

          \[\leadsto \color{blue}{3 \cdot \left(z \cdot z\right)} \]
        2. Step-by-step derivation
          1. Applied rewrites91.3%

            \[\leadsto \mathsf{fma}\left(2 \cdot z, \color{blue}{z}, z \cdot z\right) \]
        3. Recombined 2 regimes into one program.
        4. Final simplification87.8%

          \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -4 \cdot 10^{-45} \lor \neg \left(x \cdot y \leq 10^{-313}\right):\\ \;\;\;\;\mathsf{fma}\left(z, z + z, x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2 \cdot z, z, z \cdot z\right)\\ \end{array} \]
        5. Add Preprocessing

        Alternative 3: 83.2% accurate, 0.8× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot y \leq -4 \cdot 10^{-45} \lor \neg \left(x \cdot y \leq 10^{-313}\right):\\ \;\;\;\;\mathsf{fma}\left(z, z + z, x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;3 \cdot \left(z \cdot z\right)\\ \end{array} \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (if (or (<= (* x y) -4e-45) (not (<= (* x y) 1e-313)))
           (fma z (+ z z) (* x y))
           (* 3.0 (* z z))))
        double code(double x, double y, double z) {
        	double tmp;
        	if (((x * y) <= -4e-45) || !((x * y) <= 1e-313)) {
        		tmp = fma(z, (z + z), (x * y));
        	} else {
        		tmp = 3.0 * (z * z);
        	}
        	return tmp;
        }
        
        function code(x, y, z)
        	tmp = 0.0
        	if ((Float64(x * y) <= -4e-45) || !(Float64(x * y) <= 1e-313))
        		tmp = fma(z, Float64(z + z), Float64(x * y));
        	else
        		tmp = Float64(3.0 * Float64(z * z));
        	end
        	return tmp
        end
        
        code[x_, y_, z_] := If[Or[LessEqual[N[(x * y), $MachinePrecision], -4e-45], N[Not[LessEqual[N[(x * y), $MachinePrecision], 1e-313]], $MachinePrecision]], N[(z * N[(z + z), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision], N[(3.0 * N[(z * z), $MachinePrecision]), $MachinePrecision]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;x \cdot y \leq -4 \cdot 10^{-45} \lor \neg \left(x \cdot y \leq 10^{-313}\right):\\
        \;\;\;\;\mathsf{fma}\left(z, z + z, x \cdot y\right)\\
        
        \mathbf{else}:\\
        \;\;\;\;3 \cdot \left(z \cdot z\right)\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 2 regimes
        2. if (*.f64 x y) < -3.99999999999999994e-45 or 1.00000000001e-313 < (*.f64 x y)

          1. Initial program 96.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \left(z \cdot z + \color{blue}{z \cdot z}\right) + \left(x \cdot y + z \cdot z\right) \]
            15. distribute-lft-outN/A

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

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

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

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

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

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

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

              \[\leadsto \mathsf{fma}\left(z, z + z, \mathsf{fma}\left(z, z, \color{blue}{y \cdot x}\right)\right) \]
            23. lower-*.f6498.9

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

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

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

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

            if -3.99999999999999994e-45 < (*.f64 x y) < 1.00000000001e-313

            1. Initial program 99.8%

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

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

                \[\leadsto \color{blue}{3 \cdot \left(z \cdot z\right)} \]
            5. Recombined 2 regimes into one program.
            6. Final simplification87.8%

              \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y \leq -4 \cdot 10^{-45} \lor \neg \left(x \cdot y \leq 10^{-313}\right):\\ \;\;\;\;\mathsf{fma}\left(z, z + z, x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;3 \cdot \left(z \cdot z\right)\\ \end{array} \]
            7. Add Preprocessing

            Alternative 4: 82.0% accurate, 1.5× speedup?

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

              1. Initial program 96.8%

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

                \[\leadsto \color{blue}{x \cdot y} + z \cdot z \]
              4. Step-by-step derivation
                1. Applied rewrites79.6%

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

                if 1.75e20 < z

                1. Initial program 98.3%

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

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

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

                Alternative 5: 68.5% accurate, 1.8× speedup?

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

                  1. Initial program 96.8%

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

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

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

                    if 1.75e20 < z

                    1. Initial program 98.3%

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

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

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

                    Alternative 6: 98.8% accurate, 1.8× speedup?

                    \[\begin{array}{l} \\ \mathsf{fma}\left(3 \cdot z, z, y \cdot x\right) \end{array} \]
                    (FPCore (x y z) :precision binary64 (fma (* 3.0 z) z (* y x)))
                    double code(double x, double y, double z) {
                    	return fma((3.0 * z), z, (y * x));
                    }
                    
                    function code(x, y, z)
                    	return fma(Float64(3.0 * z), z, Float64(y * x))
                    end
                    
                    code[x_, y_, z_] := N[(N[(3.0 * z), $MachinePrecision] * z + N[(y * x), $MachinePrecision]), $MachinePrecision]
                    
                    \begin{array}{l}
                    
                    \\
                    \mathsf{fma}\left(3 \cdot z, z, y \cdot x\right)
                    \end{array}
                    
                    Derivation
                    1. Initial program 97.2%

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

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

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

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

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

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

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

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

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

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

                        \[\leadsto \color{blue}{\left(x \cdot y + \left({z}^{2} + {z}^{2}\right)\right)} + z \cdot z \]
                      11. count-2-revN/A

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

                        \[\leadsto \left(x \cdot y + 2 \cdot {z}^{2}\right) + \color{blue}{{z}^{2}} \]
                      13. associate-+r+N/A

                        \[\leadsto \color{blue}{x \cdot y + \left(2 \cdot {z}^{2} + {z}^{2}\right)} \]
                      14. distribute-lft1-inN/A

                        \[\leadsto x \cdot y + \color{blue}{\left(2 + 1\right) \cdot {z}^{2}} \]
                      15. metadata-evalN/A

                        \[\leadsto x \cdot y + \color{blue}{3} \cdot {z}^{2} \]
                      16. +-commutativeN/A

                        \[\leadsto \color{blue}{3 \cdot {z}^{2} + x \cdot y} \]
                      17. pow2N/A

                        \[\leadsto 3 \cdot \color{blue}{\left(z \cdot z\right)} + x \cdot y \]
                      18. associate-*r*N/A

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

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

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

                        \[\leadsto \mathsf{fma}\left(3 \cdot z, z, \color{blue}{y \cdot x}\right) \]
                      22. lower-*.f6499.1

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

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

                    Alternative 7: 63.3% accurate, 1.9× speedup?

                    \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq 1.1 \cdot 10^{+120}:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, z + z, 1\right)\\ \end{array} \end{array} \]
                    (FPCore (x y z)
                     :precision binary64
                     (if (<= z 1.1e+120) (* y x) (fma z (+ z z) 1.0)))
                    double code(double x, double y, double z) {
                    	double tmp;
                    	if (z <= 1.1e+120) {
                    		tmp = y * x;
                    	} else {
                    		tmp = fma(z, (z + z), 1.0);
                    	}
                    	return tmp;
                    }
                    
                    function code(x, y, z)
                    	tmp = 0.0
                    	if (z <= 1.1e+120)
                    		tmp = Float64(y * x);
                    	else
                    		tmp = fma(z, Float64(z + z), 1.0);
                    	end
                    	return tmp
                    end
                    
                    code[x_, y_, z_] := If[LessEqual[z, 1.1e+120], N[(y * x), $MachinePrecision], N[(z * N[(z + z), $MachinePrecision] + 1.0), $MachinePrecision]]
                    
                    \begin{array}{l}
                    
                    \\
                    \begin{array}{l}
                    \mathbf{if}\;z \leq 1.1 \cdot 10^{+120}:\\
                    \;\;\;\;y \cdot x\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;\mathsf{fma}\left(z, z + z, 1\right)\\
                    
                    
                    \end{array}
                    \end{array}
                    
                    Derivation
                    1. Split input into 2 regimes
                    2. if z < 1.1000000000000001e120

                      1. Initial program 97.0%

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

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

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

                        if 1.1000000000000001e120 < z

                        1. Initial program 97.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                            \[\leadsto \left(z \cdot z + \color{blue}{z \cdot z}\right) + \left(x \cdot y + z \cdot z\right) \]
                          15. distribute-lft-outN/A

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

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

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

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

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

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

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

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

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

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

                          \[\leadsto \mathsf{fma}\left(z, z + z, \color{blue}{{z}^{2}}\right) \]
                        6. Step-by-step derivation
                          1. Applied rewrites83.9%

                            \[\leadsto \mathsf{fma}\left(z, z + z, \color{blue}{1}\right) \]
                        7. Recombined 2 regimes into one program.
                        8. Add Preprocessing

                        Alternative 8: 63.2% accurate, 2.0× speedup?

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

                          1. Initial program 97.0%

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

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

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

                            if 1.1000000000000001e120 < z

                            1. Initial program 97.8%

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

                              \[\leadsto \color{blue}{x \cdot y} + z \cdot z \]
                            4. Step-by-step derivation
                              1. Applied rewrites83.5%

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

                                \[\leadsto \color{blue}{2 \cdot {z}^{2}} + z \cdot z \]
                              3. Step-by-step derivation
                                1. Applied rewrites83.5%

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

                              Alternative 9: 52.0% accurate, 5.0× speedup?

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

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

                                \[\leadsto \color{blue}{x \cdot y} \]
                              4. Step-by-step derivation
                                1. Applied rewrites53.9%

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

                                Alternative 10: 3.8% accurate, 30.0× speedup?

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

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

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

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

                                    \[\leadsto 3 \cdot \color{blue}{{z}^{2}} \]
                                  3. Step-by-step derivation
                                    1. Applied rewrites3.6%

                                      \[\leadsto 3 \]
                                    2. Add Preprocessing

                                    Developer Target 1: 98.4% accurate, 1.6× speedup?

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

                                    Reproduce

                                    ?
                                    herbie shell --seed 2025026 
                                    (FPCore (x y z)
                                      :name "Linear.Quaternion:$c/ from linear-1.19.1.3, A"
                                      :precision binary64
                                    
                                      :alt
                                      (! :herbie-platform default (+ (* (* 3 z) z) (* y x)))
                                    
                                      (+ (+ (+ (* x y) (* z z)) (* z z)) (* z z)))