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

Percentage Accurate: 98.2% → 98.9%
Time: 4.4s
Alternatives: 11
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 11 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.2% 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 99.1%

    \[\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. associate-+l+N/A

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(z, z + z, \mathsf{fma}\left(z, z, \color{blue}{y \cdot x}\right)\right) \]
    16. 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: 74.3% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z\\ \mathbf{if}\;t\_0 \leq -2 \cdot 10^{-218}:\\ \;\;\;\;\mathsf{fma}\left(y, x, z\right) + z\\ \mathbf{elif}\;t\_0 \leq 10^{+128}:\\ \;\;\;\;\left(3 \cdot z\right) \cdot z\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, z, \mathsf{fma}\left(x, y, 2\right)\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (+ (+ (+ (* x y) (* z z)) (* z z)) (* z z))))
   (if (<= t_0 -2e-218)
     (+ (fma y x z) z)
     (if (<= t_0 1e+128) (* (* 3.0 z) z) (fma z z (fma x y 2.0))))))
double code(double x, double y, double z) {
	double t_0 = (((x * y) + (z * z)) + (z * z)) + (z * z);
	double tmp;
	if (t_0 <= -2e-218) {
		tmp = fma(y, x, z) + z;
	} else if (t_0 <= 1e+128) {
		tmp = (3.0 * z) * z;
	} else {
		tmp = fma(z, z, fma(x, y, 2.0));
	}
	return tmp;
}
function code(x, y, z)
	t_0 = Float64(Float64(Float64(Float64(x * y) + Float64(z * z)) + Float64(z * z)) + Float64(z * z))
	tmp = 0.0
	if (t_0 <= -2e-218)
		tmp = Float64(fma(y, x, z) + z);
	elseif (t_0 <= 1e+128)
		tmp = Float64(Float64(3.0 * z) * z);
	else
		tmp = fma(z, z, fma(x, y, 2.0));
	end
	return tmp
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(N[(N[(x * y), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e-218], N[(N[(y * x + z), $MachinePrecision] + z), $MachinePrecision], If[LessEqual[t$95$0, 1e+128], N[(N[(3.0 * z), $MachinePrecision] * z), $MachinePrecision], N[(z * z + N[(x * y + 2.0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{-218}:\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right) + z\\

\mathbf{elif}\;t\_0 \leq 10^{+128}:\\
\;\;\;\;\left(3 \cdot z\right) \cdot z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (+.f64 (+.f64 (+.f64 (*.f64 x y) (*.f64 z z)) (*.f64 z z)) (*.f64 z z)) < -2.0000000000000001e-218

    1. Initial program 100.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. associate-+l+N/A

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(z, z + z, \mathsf{fma}\left(z, z, \color{blue}{y \cdot x}\right)\right) \]
      16. 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. Step-by-step derivation
      1. lift-fma.f64N/A

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

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(z, \left(z + z\right) + z, y \cdot x\right)} \]
    6. Applied rewrites93.1%

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

      \[\leadsto \color{blue}{2 \cdot z + x \cdot y} \]
    8. Step-by-step derivation
      1. lower-fma.f64N/A

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

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

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

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

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

      if -2.0000000000000001e-218 < (+.f64 (+.f64 (+.f64 (*.f64 x y) (*.f64 z z)) (*.f64 z z)) (*.f64 z z)) < 1.0000000000000001e128

      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. distribute-lft1-inN/A

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

          \[\leadsto \color{blue}{3} \cdot {z}^{2} \]
        3. lower-*.f64N/A

          \[\leadsto \color{blue}{3 \cdot {z}^{2}} \]
        4. unpow2N/A

          \[\leadsto 3 \cdot \color{blue}{\left(z \cdot z\right)} \]
        5. lower-*.f6460.2

          \[\leadsto 3 \cdot \color{blue}{\left(z \cdot z\right)} \]
      5. Applied rewrites60.2%

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

          \[\leadsto \left(3 \cdot z\right) \cdot \color{blue}{z} \]

        if 1.0000000000000001e128 < (+.f64 (+.f64 (+.f64 (*.f64 x y) (*.f64 z z)) (*.f64 z z)) (*.f64 z 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. 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. associate-+l+N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto z \cdot \color{blue}{\left(z + z\right)} + \mathsf{fma}\left(z, z, y \cdot x\right) \]
          3. distribute-lft-inN/A

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

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

            \[\leadsto \left(z \cdot z + \color{blue}{z \cdot z}\right) + \mathsf{fma}\left(z, z, y \cdot x\right) \]
          6. associate-+r+N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      Alternative 3: 82.6% accurate, 0.8× speedup?

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

        1. Initial program 98.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. associate-+l+N/A

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \mathsf{fma}\left(z, z + z, \mathsf{fma}\left(z, z, \color{blue}{y \cdot x}\right)\right) \]
          16. 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. Step-by-step derivation
          1. lift-fma.f64N/A

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

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

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

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

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

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

            \[\leadsto \color{blue}{\mathsf{fma}\left(z, \left(z + z\right) + z, y \cdot x\right)} \]
        6. Applied rewrites88.7%

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

        if -3.99999999999999977e-67 < (*.f64 x y) < 5.00000000000000015e-140

        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. 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. associate-+l+N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \mathsf{fma}\left(z, z + z, \mathsf{fma}\left(z, z, \color{blue}{y \cdot x}\right)\right) \]
        4. Applied rewrites99.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 0

          \[\leadsto \mathsf{fma}\left(z, z + z, \color{blue}{{z}^{2}}\right) \]
        6. Step-by-step derivation
          1. unpow2N/A

            \[\leadsto \mathsf{fma}\left(z, z + z, \color{blue}{z \cdot z}\right) \]
          2. lower-*.f6479.6

            \[\leadsto \mathsf{fma}\left(z, z + z, \color{blue}{z \cdot z}\right) \]
        7. Applied rewrites79.6%

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

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

      Alternative 4: 82.6% accurate, 0.8× speedup?

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

        1. Initial program 98.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. associate-+l+N/A

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \mathsf{fma}\left(z, z + z, \mathsf{fma}\left(z, z, \color{blue}{y \cdot x}\right)\right) \]
          16. 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. Step-by-step derivation
          1. lift-fma.f64N/A

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

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

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

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

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

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

            \[\leadsto \color{blue}{\mathsf{fma}\left(z, \left(z + z\right) + z, y \cdot x\right)} \]
        6. Applied rewrites88.7%

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

        if -3.99999999999999977e-67 < (*.f64 x y) < 5.00000000000000015e-140

        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. distribute-lft1-inN/A

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

            \[\leadsto \color{blue}{3} \cdot {z}^{2} \]
          3. lower-*.f64N/A

            \[\leadsto \color{blue}{3 \cdot {z}^{2}} \]
          4. unpow2N/A

            \[\leadsto 3 \cdot \color{blue}{\left(z \cdot z\right)} \]
          5. lower-*.f6479.5

            \[\leadsto 3 \cdot \color{blue}{\left(z \cdot z\right)} \]
        5. Applied rewrites79.5%

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

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

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

        Alternative 5: 61.7% accurate, 1.8× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq 1.2 \cdot 10^{-24}:\\ \;\;\;\;\mathsf{fma}\left(y, x, z\right) + z\\ \mathbf{else}:\\ \;\;\;\;3 \cdot \left(z \cdot z\right)\\ \end{array} \end{array} \]
        (FPCore (x y z)
         :precision binary64
         (if (<= z 1.2e-24) (+ (fma y x z) z) (* 3.0 (* z z))))
        double code(double x, double y, double z) {
        	double tmp;
        	if (z <= 1.2e-24) {
        		tmp = fma(y, x, z) + z;
        	} else {
        		tmp = 3.0 * (z * z);
        	}
        	return tmp;
        }
        
        function code(x, y, z)
        	tmp = 0.0
        	if (z <= 1.2e-24)
        		tmp = Float64(fma(y, x, z) + z);
        	else
        		tmp = Float64(3.0 * Float64(z * z));
        	end
        	return tmp
        end
        
        code[x_, y_, z_] := If[LessEqual[z, 1.2e-24], N[(N[(y * x + z), $MachinePrecision] + z), $MachinePrecision], N[(3.0 * N[(z * z), $MachinePrecision]), $MachinePrecision]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        \mathbf{if}\;z \leq 1.2 \cdot 10^{-24}:\\
        \;\;\;\;\mathsf{fma}\left(y, x, z\right) + 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.1999999999999999e-24

          1. Initial program 99.4%

            \[\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. associate-+l+N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \color{blue}{\mathsf{fma}\left(z, \left(z + z\right) + z, y \cdot x\right)} \]
          6. Applied rewrites74.5%

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

            \[\leadsto \color{blue}{2 \cdot z + x \cdot y} \]
          8. Step-by-step derivation
            1. lower-fma.f64N/A

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

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

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

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

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

            if 1.1999999999999999e-24 < z

            1. Initial program 98.4%

              \[\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. distribute-lft1-inN/A

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

                \[\leadsto \color{blue}{3} \cdot {z}^{2} \]
              3. lower-*.f64N/A

                \[\leadsto \color{blue}{3 \cdot {z}^{2}} \]
              4. unpow2N/A

                \[\leadsto 3 \cdot \color{blue}{\left(z \cdot z\right)} \]
              5. lower-*.f6476.8

                \[\leadsto 3 \cdot \color{blue}{\left(z \cdot z\right)} \]
            5. Applied rewrites76.8%

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

          Alternative 6: 98.8% accurate, 1.8× speedup?

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

            \[\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} + \left(x \cdot y + {z}^{2}\right)} \]
          4. Step-by-step derivation
            1. +-commutativeN/A

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

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

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

              \[\leadsto \color{blue}{3} \cdot {z}^{2} + x \cdot y \]
            5. lower-fma.f64N/A

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

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

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

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

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

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

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

            Alternative 7: 98.2% accurate, 1.8× speedup?

            \[\begin{array}{l} \\ \mathsf{fma}\left(3, z \cdot 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(3.0, Float64(z * z), Float64(y * x))
            end
            
            code[x_, y_, z_] := N[(3.0 * N[(z * z), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision]
            
            \begin{array}{l}
            
            \\
            \mathsf{fma}\left(3, z \cdot z, y \cdot x\right)
            \end{array}
            
            Derivation
            1. Initial program 99.1%

              \[\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} + \left(x \cdot y + {z}^{2}\right)} \]
            4. Step-by-step derivation
              1. +-commutativeN/A

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

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

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

                \[\leadsto \color{blue}{3} \cdot {z}^{2} + x \cdot y \]
              5. lower-fma.f64N/A

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

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

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

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

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

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

            Alternative 8: 57.3% accurate, 1.9× speedup?

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

              1. Initial program 99.5%

                \[\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. associate-+l+N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \color{blue}{2 \cdot z + x \cdot y} \]
              8. Step-by-step derivation
                1. lower-fma.f64N/A

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

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

                  \[\leadsto \mathsf{fma}\left(2, z, \color{blue}{y \cdot x}\right) \]
              9. Applied rewrites53.3%

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

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

                if 9.4999999999999995e153 < z

                1. Initial program 96.7%

                  \[\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. associate-+l+N/A

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

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

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

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

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

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

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

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

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

                    \[\leadsto \mathsf{fma}\left(z, z + z, \color{blue}{z \cdot z} + x \cdot y\right) \]
                  13. lower-fma.f6496.7

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

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

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

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

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

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

                    \[\leadsto z \cdot \color{blue}{\left(z + z\right)} + \mathsf{fma}\left(z, z, y \cdot x\right) \]
                  3. distribute-lft-inN/A

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

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

                    \[\leadsto \left(z \cdot z + \color{blue}{z \cdot z}\right) + \mathsf{fma}\left(z, z, y \cdot x\right) \]
                  6. associate-+r+N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    \[\leadsto \mathsf{fma}\left(z, z, x \cdot y + \color{blue}{z \cdot \left(z + z\right)}\right) \]
                6. Applied rewrites96.7%

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

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

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

                Alternative 9: 29.3% accurate, 3.3× speedup?

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

                  \[\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. associate-+l+N/A

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

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

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

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

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

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

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

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

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

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

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

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

                    \[\leadsto \mathsf{fma}\left(z, z + z, \mathsf{fma}\left(z, z, \color{blue}{y \cdot x}\right)\right) \]
                  16. 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. Step-by-step derivation
                  1. lift-fma.f64N/A

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

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

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

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

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

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

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

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

                  \[\leadsto \color{blue}{z \cdot \left(2 + z\right)} \]
                8. Step-by-step derivation
                  1. *-commutativeN/A

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

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

                    \[\leadsto \color{blue}{\left(z + 2\right)} \cdot z \]
                  4. metadata-evalN/A

                    \[\leadsto \left(z + \color{blue}{2 \cdot 1}\right) \cdot z \]
                  5. fp-cancel-sign-sub-invN/A

                    \[\leadsto \color{blue}{\left(z - \left(\mathsf{neg}\left(2\right)\right) \cdot 1\right)} \cdot z \]
                  6. *-rgt-identityN/A

                    \[\leadsto \left(z - \color{blue}{\left(\mathsf{neg}\left(2\right)\right)}\right) \cdot z \]
                  7. lower--.f64N/A

                    \[\leadsto \color{blue}{\left(z - \left(\mathsf{neg}\left(2\right)\right)\right)} \cdot z \]
                  8. metadata-eval32.1

                    \[\leadsto \left(z - \color{blue}{-2}\right) \cdot z \]
                9. Applied rewrites32.1%

                  \[\leadsto \color{blue}{\left(z - -2\right) \cdot z} \]
                10. Add Preprocessing

                Alternative 10: 29.4% accurate, 4.3× speedup?

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

                  \[\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. associate-+l+N/A

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

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

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

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

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

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

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

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

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

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

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

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

                    \[\leadsto \mathsf{fma}\left(z, z + z, \mathsf{fma}\left(z, z, \color{blue}{y \cdot x}\right)\right) \]
                  16. 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. Step-by-step derivation
                  1. lift-fma.f64N/A

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

                    \[\leadsto z \cdot \color{blue}{\left(z + z\right)} + \mathsf{fma}\left(z, z, y \cdot x\right) \]
                  3. distribute-lft-inN/A

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

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

                    \[\leadsto \left(z \cdot z + \color{blue}{z \cdot z}\right) + \mathsf{fma}\left(z, z, y \cdot x\right) \]
                  6. associate-+r+N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                  \[\leadsto \mathsf{fma}\left(z, z, \color{blue}{2}\right) \]
                8. Step-by-step derivation
                  1. Applied rewrites32.2%

                    \[\leadsto \mathsf{fma}\left(z, z, \color{blue}{2}\right) \]
                  2. Add Preprocessing

                  Alternative 11: 3.7% accurate, 5.0× speedup?

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

                    \[\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. associate-+l+N/A

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

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

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

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

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

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

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

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

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

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

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

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

                      \[\leadsto \mathsf{fma}\left(z, z + z, \mathsf{fma}\left(z, z, \color{blue}{y \cdot x}\right)\right) \]
                    16. 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. Step-by-step derivation
                    1. lift-fma.f64N/A

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

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

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

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

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

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

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

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

                    \[\leadsto \color{blue}{2 \cdot z + x \cdot y} \]
                  8. Step-by-step derivation
                    1. lower-fma.f64N/A

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

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

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

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

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

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

                    Developer Target 1: 98.2% 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 2025017 
                    (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)))