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

Percentage Accurate: 98.3% → 98.3%
Time: 7.6s
Alternatives: 7
Speedup: 0.1×

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);
}
real(8) function code(x, y, z)
    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 7 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 98.3% 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);
}
real(8) function code(x, y, z)
    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.3% accurate, 0.1× speedup?

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

\\
\mathsf{fma}\left(z, z + z, x \cdot y + z \cdot z\right)
\end{array}
Derivation
  1. Initial program 97.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. associate-+l+N/A

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma.f64}\left(z, \mathsf{+.f64}\left(z, z\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(z \cdot z\right)\right)\right) \]
    9. *-lowering-*.f6497.6%

      \[\leadsto \mathsf{fma.f64}\left(z, \mathsf{+.f64}\left(z, z\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(z, z\right)\right)\right) \]
  4. Applied egg-rr97.6%

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

Alternative 2: 85.3% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{-10}:\\ \;\;\;\;x \cdot y + z \cdot z\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{\frac{0.3333333333333333}{z}}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= (* z z) 1e-10) (+ (* x y) (* z z)) (/ z (/ 0.3333333333333333 z))))
double code(double x, double y, double z) {
	double tmp;
	if ((z * z) <= 1e-10) {
		tmp = (x * y) + (z * z);
	} else {
		tmp = z / (0.3333333333333333 / z);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((z * z) <= 1d-10) then
        tmp = (x * y) + (z * z)
    else
        tmp = z / (0.3333333333333333d0 / z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z * z) <= 1e-10) {
		tmp = (x * y) + (z * z);
	} else {
		tmp = z / (0.3333333333333333 / z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z * z) <= 1e-10:
		tmp = (x * y) + (z * z)
	else:
		tmp = z / (0.3333333333333333 / z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (Float64(z * z) <= 1e-10)
		tmp = Float64(Float64(x * y) + Float64(z * z));
	else
		tmp = Float64(z / Float64(0.3333333333333333 / z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z * z) <= 1e-10)
		tmp = (x * y) + (z * z);
	else
		tmp = z / (0.3333333333333333 / z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e-10], N[(N[(x * y), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision], N[(z / N[(0.3333333333333333 / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{-10}:\\
\;\;\;\;x \cdot y + z \cdot z\\

\mathbf{else}:\\
\;\;\;\;\frac{z}{\frac{0.3333333333333333}{z}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 z z) < 1.00000000000000004e-10

    1. Initial program 99.9%

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

      \[\leadsto \mathsf{+.f64}\left(\color{blue}{\left(x \cdot y\right)}, \mathsf{*.f64}\left(z, z\right)\right) \]
    4. Step-by-step derivation
      1. *-lowering-*.f6490.0%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\color{blue}{z}, z\right)\right) \]
    5. Simplified90.0%

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

    if 1.00000000000000004e-10 < (*.f64 z z)

    1. Initial program 95.3%

      \[\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z \]
    2. Step-by-step derivation
      1. associate-+l+N/A

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

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

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(\color{blue}{z \cdot z} + \left(z \cdot z + z \cdot z\right)\right)\right) \]
      5. count-2N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(z \cdot z + 2 \cdot \color{blue}{\left(z \cdot z\right)}\right)\right) \]
      6. distribute-rgt1-inN/A

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(\left(z \cdot z\right) \cdot \color{blue}{\left(2 + 1\right)}\right)\right) \]
      8. *-lowering-*.f64N/A

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(z, z\right), \left(\color{blue}{2} + 1\right)\right)\right) \]
      10. metadata-eval95.3%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(z, z\right), 3\right)\right) \]
    3. Simplified95.3%

      \[\leadsto \color{blue}{x \cdot y + \left(z \cdot z\right) \cdot 3} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. associate-*l*N/A

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

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\left(z \cdot 3\right), \color{blue}{z}\right)\right) \]
      4. *-lowering-*.f6495.3%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(z, 3\right), z\right)\right) \]
    6. Applied egg-rr95.3%

      \[\leadsto x \cdot y + \color{blue}{\left(z \cdot 3\right) \cdot z} \]
    7. Step-by-step derivation
      1. flip3-+N/A

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

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

        \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{\left(x \cdot y\right) \cdot \left(x \cdot y\right) + \left(\left(\left(z \cdot 3\right) \cdot z\right) \cdot \left(\left(z \cdot 3\right) \cdot z\right) - \left(x \cdot y\right) \cdot \left(\left(z \cdot 3\right) \cdot z\right)\right)}{{\left(x \cdot y\right)}^{3} + {\left(\left(z \cdot 3\right) \cdot z\right)}^{3}}\right)}\right) \]
      4. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{1}{\color{blue}{\frac{{\left(x \cdot y\right)}^{3} + {\left(\left(z \cdot 3\right) \cdot z\right)}^{3}}{\left(x \cdot y\right) \cdot \left(x \cdot y\right) + \left(\left(\left(z \cdot 3\right) \cdot z\right) \cdot \left(\left(z \cdot 3\right) \cdot z\right) - \left(x \cdot y\right) \cdot \left(\left(z \cdot 3\right) \cdot z\right)\right)}}}\right)\right) \]
      5. flip3-+N/A

        \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{1}{x \cdot y + \color{blue}{\left(z \cdot 3\right) \cdot z}}\right)\right) \]
      6. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(1, \color{blue}{\left(x \cdot y + \left(z \cdot 3\right) \cdot z\right)}\right)\right) \]
      7. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\left(x \cdot y\right), \color{blue}{\left(\left(z \cdot 3\right) \cdot z\right)}\right)\right)\right) \]
      8. *-lowering-*.f64N/A

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

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(z \cdot \color{blue}{\left(z \cdot 3\right)}\right)\right)\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(z, \color{blue}{\left(z \cdot 3\right)}\right)\right)\right)\right) \]
      11. *-lowering-*.f6495.2%

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(z, \mathsf{*.f64}\left(z, \color{blue}{3}\right)\right)\right)\right)\right) \]
    8. Applied egg-rr95.2%

      \[\leadsto \color{blue}{\frac{1}{\frac{1}{x \cdot y + z \cdot \left(z \cdot 3\right)}}} \]
    9. Taylor expanded in x around 0

      \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{\frac{1}{3}}{{z}^{2}}\right)}\right) \]
    10. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\frac{1}{3}, \color{blue}{\left({z}^{2}\right)}\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\frac{1}{3}, \left(z \cdot \color{blue}{z}\right)\right)\right) \]
      3. *-lowering-*.f6485.5%

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\frac{1}{3}, \mathsf{*.f64}\left(z, \color{blue}{z}\right)\right)\right) \]
    11. Simplified85.5%

      \[\leadsto \frac{1}{\color{blue}{\frac{0.3333333333333333}{z \cdot z}}} \]
    12. Step-by-step derivation
      1. associate-/r*N/A

        \[\leadsto \frac{1}{\frac{\frac{\frac{1}{3}}{z}}{\color{blue}{z}}} \]
      2. clear-numN/A

        \[\leadsto \frac{z}{\color{blue}{\frac{\frac{1}{3}}{z}}} \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(z, \color{blue}{\left(\frac{\frac{1}{3}}{z}\right)}\right) \]
      4. /-lowering-/.f6485.6%

        \[\leadsto \mathsf{/.f64}\left(z, \mathsf{/.f64}\left(\frac{1}{3}, \color{blue}{z}\right)\right) \]
    13. Applied egg-rr85.6%

      \[\leadsto \color{blue}{\frac{z}{\frac{0.3333333333333333}{z}}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 84.3% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{-10}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;\frac{z}{\frac{0.3333333333333333}{z}}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= (* z z) 1e-10) (* x y) (/ z (/ 0.3333333333333333 z))))
double code(double x, double y, double z) {
	double tmp;
	if ((z * z) <= 1e-10) {
		tmp = x * y;
	} else {
		tmp = z / (0.3333333333333333 / z);
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((z * z) <= 1d-10) then
        tmp = x * y
    else
        tmp = z / (0.3333333333333333d0 / z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z * z) <= 1e-10) {
		tmp = x * y;
	} else {
		tmp = z / (0.3333333333333333 / z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z * z) <= 1e-10:
		tmp = x * y
	else:
		tmp = z / (0.3333333333333333 / z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (Float64(z * z) <= 1e-10)
		tmp = Float64(x * y);
	else
		tmp = Float64(z / Float64(0.3333333333333333 / z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z * z) <= 1e-10)
		tmp = x * y;
	else
		tmp = z / (0.3333333333333333 / z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e-10], N[(x * y), $MachinePrecision], N[(z / N[(0.3333333333333333 / z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{-10}:\\
\;\;\;\;x \cdot y\\

\mathbf{else}:\\
\;\;\;\;\frac{z}{\frac{0.3333333333333333}{z}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 z z) < 1.00000000000000004e-10

    1. Initial program 99.9%

      \[\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z \]
    2. Step-by-step derivation
      1. associate-+l+N/A

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

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

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(\color{blue}{z \cdot z} + \left(z \cdot z + z \cdot z\right)\right)\right) \]
      5. count-2N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(z \cdot z + 2 \cdot \color{blue}{\left(z \cdot z\right)}\right)\right) \]
      6. distribute-rgt1-inN/A

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(\left(z \cdot z\right) \cdot \color{blue}{\left(2 + 1\right)}\right)\right) \]
      8. *-lowering-*.f64N/A

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(z, z\right), \left(\color{blue}{2} + 1\right)\right)\right) \]
      10. metadata-eval99.9%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(z, z\right), 3\right)\right) \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{x \cdot y + \left(z \cdot z\right) \cdot 3} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf

      \[\leadsto \color{blue}{x \cdot y} \]
    6. Step-by-step derivation
      1. *-lowering-*.f6488.6%

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{y}\right) \]
    7. Simplified88.6%

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

    if 1.00000000000000004e-10 < (*.f64 z z)

    1. Initial program 95.3%

      \[\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z \]
    2. Step-by-step derivation
      1. associate-+l+N/A

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

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

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(\color{blue}{z \cdot z} + \left(z \cdot z + z \cdot z\right)\right)\right) \]
      5. count-2N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(z \cdot z + 2 \cdot \color{blue}{\left(z \cdot z\right)}\right)\right) \]
      6. distribute-rgt1-inN/A

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(\left(z \cdot z\right) \cdot \color{blue}{\left(2 + 1\right)}\right)\right) \]
      8. *-lowering-*.f64N/A

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(z, z\right), \left(\color{blue}{2} + 1\right)\right)\right) \]
      10. metadata-eval95.3%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(z, z\right), 3\right)\right) \]
    3. Simplified95.3%

      \[\leadsto \color{blue}{x \cdot y + \left(z \cdot z\right) \cdot 3} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. associate-*l*N/A

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

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\left(z \cdot 3\right), \color{blue}{z}\right)\right) \]
      4. *-lowering-*.f6495.3%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(z, 3\right), z\right)\right) \]
    6. Applied egg-rr95.3%

      \[\leadsto x \cdot y + \color{blue}{\left(z \cdot 3\right) \cdot z} \]
    7. Step-by-step derivation
      1. flip3-+N/A

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

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

        \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{\left(x \cdot y\right) \cdot \left(x \cdot y\right) + \left(\left(\left(z \cdot 3\right) \cdot z\right) \cdot \left(\left(z \cdot 3\right) \cdot z\right) - \left(x \cdot y\right) \cdot \left(\left(z \cdot 3\right) \cdot z\right)\right)}{{\left(x \cdot y\right)}^{3} + {\left(\left(z \cdot 3\right) \cdot z\right)}^{3}}\right)}\right) \]
      4. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{1}{\color{blue}{\frac{{\left(x \cdot y\right)}^{3} + {\left(\left(z \cdot 3\right) \cdot z\right)}^{3}}{\left(x \cdot y\right) \cdot \left(x \cdot y\right) + \left(\left(\left(z \cdot 3\right) \cdot z\right) \cdot \left(\left(z \cdot 3\right) \cdot z\right) - \left(x \cdot y\right) \cdot \left(\left(z \cdot 3\right) \cdot z\right)\right)}}}\right)\right) \]
      5. flip3-+N/A

        \[\leadsto \mathsf{/.f64}\left(1, \left(\frac{1}{x \cdot y + \color{blue}{\left(z \cdot 3\right) \cdot z}}\right)\right) \]
      6. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(1, \color{blue}{\left(x \cdot y + \left(z \cdot 3\right) \cdot z\right)}\right)\right) \]
      7. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\left(x \cdot y\right), \color{blue}{\left(\left(z \cdot 3\right) \cdot z\right)}\right)\right)\right) \]
      8. *-lowering-*.f64N/A

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

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(z \cdot \color{blue}{\left(z \cdot 3\right)}\right)\right)\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(z, \color{blue}{\left(z \cdot 3\right)}\right)\right)\right)\right) \]
      11. *-lowering-*.f6495.2%

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(z, \mathsf{*.f64}\left(z, \color{blue}{3}\right)\right)\right)\right)\right) \]
    8. Applied egg-rr95.2%

      \[\leadsto \color{blue}{\frac{1}{\frac{1}{x \cdot y + z \cdot \left(z \cdot 3\right)}}} \]
    9. Taylor expanded in x around 0

      \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{\frac{1}{3}}{{z}^{2}}\right)}\right) \]
    10. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\frac{1}{3}, \color{blue}{\left({z}^{2}\right)}\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\frac{1}{3}, \left(z \cdot \color{blue}{z}\right)\right)\right) \]
      3. *-lowering-*.f6485.5%

        \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\frac{1}{3}, \mathsf{*.f64}\left(z, \color{blue}{z}\right)\right)\right) \]
    11. Simplified85.5%

      \[\leadsto \frac{1}{\color{blue}{\frac{0.3333333333333333}{z \cdot z}}} \]
    12. Step-by-step derivation
      1. associate-/r*N/A

        \[\leadsto \frac{1}{\frac{\frac{\frac{1}{3}}{z}}{\color{blue}{z}}} \]
      2. clear-numN/A

        \[\leadsto \frac{z}{\color{blue}{\frac{\frac{1}{3}}{z}}} \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(z, \color{blue}{\left(\frac{\frac{1}{3}}{z}\right)}\right) \]
      4. /-lowering-/.f6485.6%

        \[\leadsto \mathsf{/.f64}\left(z, \mathsf{/.f64}\left(\frac{1}{3}, \color{blue}{z}\right)\right) \]
    13. Applied egg-rr85.6%

      \[\leadsto \color{blue}{\frac{z}{\frac{0.3333333333333333}{z}}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 84.4% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{-10}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;\left(z \cdot z\right) \cdot 3\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= (* z z) 1e-10) (* x y) (* (* z z) 3.0)))
double code(double x, double y, double z) {
	double tmp;
	if ((z * z) <= 1e-10) {
		tmp = x * y;
	} else {
		tmp = (z * z) * 3.0;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((z * z) <= 1d-10) then
        tmp = x * y
    else
        tmp = (z * z) * 3.0d0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z * z) <= 1e-10) {
		tmp = x * y;
	} else {
		tmp = (z * z) * 3.0;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z * z) <= 1e-10:
		tmp = x * y
	else:
		tmp = (z * z) * 3.0
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (Float64(z * z) <= 1e-10)
		tmp = Float64(x * y);
	else
		tmp = Float64(Float64(z * z) * 3.0);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z * z) <= 1e-10)
		tmp = x * y;
	else
		tmp = (z * z) * 3.0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e-10], N[(x * y), $MachinePrecision], N[(N[(z * z), $MachinePrecision] * 3.0), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{-10}:\\
\;\;\;\;x \cdot y\\

\mathbf{else}:\\
\;\;\;\;\left(z \cdot z\right) \cdot 3\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 z z) < 1.00000000000000004e-10

    1. Initial program 99.9%

      \[\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z \]
    2. Step-by-step derivation
      1. associate-+l+N/A

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

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

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(\color{blue}{z \cdot z} + \left(z \cdot z + z \cdot z\right)\right)\right) \]
      5. count-2N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(z \cdot z + 2 \cdot \color{blue}{\left(z \cdot z\right)}\right)\right) \]
      6. distribute-rgt1-inN/A

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(\left(z \cdot z\right) \cdot \color{blue}{\left(2 + 1\right)}\right)\right) \]
      8. *-lowering-*.f64N/A

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(z, z\right), \left(\color{blue}{2} + 1\right)\right)\right) \]
      10. metadata-eval99.9%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(z, z\right), 3\right)\right) \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{x \cdot y + \left(z \cdot z\right) \cdot 3} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf

      \[\leadsto \color{blue}{x \cdot y} \]
    6. Step-by-step derivation
      1. *-lowering-*.f6488.6%

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{y}\right) \]
    7. Simplified88.6%

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

    if 1.00000000000000004e-10 < (*.f64 z z)

    1. Initial program 95.3%

      \[\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z \]
    2. Step-by-step derivation
      1. associate-+l+N/A

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

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

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(\color{blue}{z \cdot z} + \left(z \cdot z + z \cdot z\right)\right)\right) \]
      5. count-2N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(z \cdot z + 2 \cdot \color{blue}{\left(z \cdot z\right)}\right)\right) \]
      6. distribute-rgt1-inN/A

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(\left(z \cdot z\right) \cdot \color{blue}{\left(2 + 1\right)}\right)\right) \]
      8. *-lowering-*.f64N/A

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(z, z\right), \left(\color{blue}{2} + 1\right)\right)\right) \]
      10. metadata-eval95.3%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(z, z\right), 3\right)\right) \]
    3. Simplified95.3%

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

      \[\leadsto \color{blue}{3 \cdot {z}^{2}} \]
    6. Step-by-step derivation
      1. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(3, \color{blue}{\left({z}^{2}\right)}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(3, \left(z \cdot \color{blue}{z}\right)\right) \]
      3. *-lowering-*.f6485.6%

        \[\leadsto \mathsf{*.f64}\left(3, \mathsf{*.f64}\left(z, \color{blue}{z}\right)\right) \]
    7. Simplified85.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{-10}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;\left(z \cdot z\right) \cdot 3\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 74.8% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \cdot z \leq 3.15 \cdot 10^{+262}:\\ \;\;\;\;x \cdot y\\ \mathbf{else}:\\ \;\;\;\;z \cdot z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= (* z z) 3.15e+262) (* x y) (* z z)))
double code(double x, double y, double z) {
	double tmp;
	if ((z * z) <= 3.15e+262) {
		tmp = x * y;
	} else {
		tmp = z * z;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((z * z) <= 3.15d+262) then
        tmp = x * y
    else
        tmp = z * z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z * z) <= 3.15e+262) {
		tmp = x * y;
	} else {
		tmp = z * z;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z * z) <= 3.15e+262:
		tmp = x * y
	else:
		tmp = z * z
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (Float64(z * z) <= 3.15e+262)
		tmp = Float64(x * y);
	else
		tmp = Float64(z * z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z * z) <= 3.15e+262)
		tmp = x * y;
	else
		tmp = z * z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[N[(z * z), $MachinePrecision], 3.15e+262], N[(x * y), $MachinePrecision], N[(z * z), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 3.15 \cdot 10^{+262}:\\
\;\;\;\;x \cdot y\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 z z) < 3.15000000000000002e262

    1. Initial program 99.8%

      \[\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z \]
    2. Step-by-step derivation
      1. associate-+l+N/A

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

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

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(\color{blue}{z \cdot z} + \left(z \cdot z + z \cdot z\right)\right)\right) \]
      5. count-2N/A

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(z \cdot z + 2 \cdot \color{blue}{\left(z \cdot z\right)}\right)\right) \]
      6. distribute-rgt1-inN/A

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(\left(z \cdot z\right) \cdot \color{blue}{\left(2 + 1\right)}\right)\right) \]
      8. *-lowering-*.f64N/A

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

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(z, z\right), \left(\color{blue}{2} + 1\right)\right)\right) \]
      10. metadata-eval99.8%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(z, z\right), 3\right)\right) \]
    3. Simplified99.8%

      \[\leadsto \color{blue}{x \cdot y + \left(z \cdot z\right) \cdot 3} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf

      \[\leadsto \color{blue}{x \cdot y} \]
    6. Step-by-step derivation
      1. *-lowering-*.f6470.3%

        \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{y}\right) \]
    7. Simplified70.3%

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

    if 3.15000000000000002e262 < (*.f64 z z)

    1. Initial program 92.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 inf

      \[\leadsto \mathsf{+.f64}\left(\color{blue}{\left(x \cdot y\right)}, \mathsf{*.f64}\left(z, z\right)\right) \]
    4. Step-by-step derivation
      1. *-lowering-*.f6482.4%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\color{blue}{z}, z\right)\right) \]
    5. Simplified82.4%

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

      \[\leadsto \color{blue}{{z}^{2}} \]
    7. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto z \cdot \color{blue}{z} \]
      2. *-lowering-*.f6486.3%

        \[\leadsto \mathsf{*.f64}\left(z, \color{blue}{z}\right) \]
    8. Simplified86.3%

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

Alternative 6: 98.3% accurate, 1.7× speedup?

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

\\
x \cdot y + z \cdot \left(z \cdot 3\right)
\end{array}
Derivation
  1. Initial program 97.5%

    \[\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z \]
  2. Step-by-step derivation
    1. associate-+l+N/A

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

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

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(\color{blue}{z \cdot z} + \left(z \cdot z + z \cdot z\right)\right)\right) \]
    5. count-2N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(z \cdot z + 2 \cdot \color{blue}{\left(z \cdot z\right)}\right)\right) \]
    6. distribute-rgt1-inN/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(\left(z \cdot z\right) \cdot \color{blue}{\left(2 + 1\right)}\right)\right) \]
    8. *-lowering-*.f64N/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(z, z\right), \left(\color{blue}{2} + 1\right)\right)\right) \]
    10. metadata-eval97.5%

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(z, z\right), 3\right)\right) \]
  3. Simplified97.5%

    \[\leadsto \color{blue}{x \cdot y + \left(z \cdot z\right) \cdot 3} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. associate-*l*N/A

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

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\left(z \cdot 3\right), \color{blue}{z}\right)\right) \]
    4. *-lowering-*.f6497.5%

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(z, 3\right), z\right)\right) \]
  6. Applied egg-rr97.5%

    \[\leadsto x \cdot y + \color{blue}{\left(z \cdot 3\right) \cdot z} \]
  7. Final simplification97.5%

    \[\leadsto x \cdot y + z \cdot \left(z \cdot 3\right) \]
  8. Add Preprocessing

Alternative 7: 52.6% accurate, 5.0× speedup?

\[\begin{array}{l} \\ x \cdot y \end{array} \]
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
	return x * y;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = x * y
end function
public static double code(double x, double y, double z) {
	return x * y;
}
def code(x, y, z):
	return x * y
function code(x, y, z)
	return Float64(x * y)
end
function tmp = code(x, y, z)
	tmp = x * y;
end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}

\\
x \cdot y
\end{array}
Derivation
  1. Initial program 97.5%

    \[\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z \]
  2. Step-by-step derivation
    1. associate-+l+N/A

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

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

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(\color{blue}{z \cdot z} + \left(z \cdot z + z \cdot z\right)\right)\right) \]
    5. count-2N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(z \cdot z + 2 \cdot \color{blue}{\left(z \cdot z\right)}\right)\right) \]
    6. distribute-rgt1-inN/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \left(\left(z \cdot z\right) \cdot \color{blue}{\left(2 + 1\right)}\right)\right) \]
    8. *-lowering-*.f64N/A

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

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(z, z\right), \left(\color{blue}{2} + 1\right)\right)\right) \]
    10. metadata-eval97.5%

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, y\right), \mathsf{*.f64}\left(\mathsf{*.f64}\left(z, z\right), 3\right)\right) \]
  3. Simplified97.5%

    \[\leadsto \color{blue}{x \cdot y + \left(z \cdot z\right) \cdot 3} \]
  4. Add Preprocessing
  5. Taylor expanded in x around inf

    \[\leadsto \color{blue}{x \cdot y} \]
  6. Step-by-step derivation
    1. *-lowering-*.f6452.3%

      \[\leadsto \mathsf{*.f64}\left(x, \color{blue}{y}\right) \]
  7. Simplified52.3%

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

Developer Target 1: 98.3% accurate, 1.7× 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);
}
real(8) function code(x, y, z)
    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 2024158 
(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)))