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

Percentage Accurate: 98.3% → 99.8%
Time: 7.1s
Alternatives: 6
Speedup: 0.7×

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 6 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: 99.8% accurate, 0.1× speedup?

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

\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + \frac{1}{\frac{\frac{y}{z}}{z \cdot 3}}\right)\\


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

    1. Initial program 97.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+97.8%

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

        \[\leadsto \color{blue}{x \cdot y + \left(z \cdot z + \left(z \cdot z + z \cdot z\right)\right)} \]
      3. fma-define98.8%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, y, z \cdot z + \left(z \cdot z + z \cdot z\right)\right)} \]
      4. associate-+r+98.8%

        \[\leadsto \mathsf{fma}\left(x, y, \color{blue}{\left(z \cdot z + z \cdot z\right) + z \cdot z}\right) \]
      5. distribute-lft-out98.8%

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

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

        \[\leadsto \mathsf{fma}\left(x, y, z \cdot \left(\left(z + z\right) + \color{blue}{\left(-\left(-z\right)\right)}\right)\right) \]
      8. unsub-neg98.9%

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

        \[\leadsto \mathsf{fma}\left(x, y, z \cdot \left(\color{blue}{2 \cdot z} - \left(-z\right)\right)\right) \]
      10. neg-mul-198.9%

        \[\leadsto \mathsf{fma}\left(x, y, z \cdot \left(2 \cdot z - \color{blue}{-1 \cdot z}\right)\right) \]
      11. distribute-rgt-out--98.9%

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

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

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

    if 2.35e-23 < y

    1. Initial program 93.5%

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

      \[\leadsto \color{blue}{y \cdot \left(x + \left(2 \cdot \frac{{z}^{2}}{y} + \frac{{z}^{2}}{y}\right)\right)} \]
    4. Simplified96.7%

      \[\leadsto \color{blue}{y \cdot \left(x + \frac{{z}^{2}}{y} \cdot 3\right)} \]
    5. Step-by-step derivation
      1. unpow296.7%

        \[\leadsto y \cdot \left(x + \frac{\color{blue}{z \cdot z}}{y} \cdot 3\right) \]
      2. associate-/l*100.0%

        \[\leadsto y \cdot \left(x + \color{blue}{\left(z \cdot \frac{z}{y}\right)} \cdot 3\right) \]
    6. Applied egg-rr100.0%

      \[\leadsto y \cdot \left(x + \color{blue}{\left(z \cdot \frac{z}{y}\right)} \cdot 3\right) \]
    7. Step-by-step derivation
      1. clear-num100.0%

        \[\leadsto y \cdot \left(x + \left(z \cdot \color{blue}{\frac{1}{\frac{y}{z}}}\right) \cdot 3\right) \]
      2. un-div-inv99.9%

        \[\leadsto y \cdot \left(x + \color{blue}{\frac{z}{\frac{y}{z}}} \cdot 3\right) \]
    8. Applied egg-rr99.9%

      \[\leadsto y \cdot \left(x + \color{blue}{\frac{z}{\frac{y}{z}}} \cdot 3\right) \]
    9. Step-by-step derivation
      1. associate-*l/99.9%

        \[\leadsto y \cdot \left(x + \color{blue}{\frac{z \cdot 3}{\frac{y}{z}}}\right) \]
      2. clear-num100.0%

        \[\leadsto y \cdot \left(x + \color{blue}{\frac{1}{\frac{\frac{y}{z}}{z \cdot 3}}}\right) \]
    10. Applied egg-rr100.0%

      \[\leadsto y \cdot \left(x + \color{blue}{\frac{1}{\frac{\frac{y}{z}}{z \cdot 3}}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 99.8% accurate, 0.7× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;y \leq 2 \cdot 10^{-21}:\\ \;\;\;\;z \cdot z + \left(z \cdot z + \left(y \cdot x + z \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x + \frac{1}{\frac{\frac{y}{z}}{z \cdot 3}}\right)\\ \end{array} \end{array} \]
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
 :precision binary64
 (if (<= y 2e-21)
   (+ (* z z) (+ (* z z) (+ (* y x) (* z z))))
   (* y (+ x (/ 1.0 (/ (/ y z) (* z 3.0)))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double tmp;
	if (y <= 2e-21) {
		tmp = (z * z) + ((z * z) + ((y * x) + (z * z)));
	} else {
		tmp = y * (x + (1.0 / ((y / z) / (z * 3.0))));
	}
	return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
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 (y <= 2d-21) then
        tmp = (z * z) + ((z * z) + ((y * x) + (z * z)))
    else
        tmp = y * (x + (1.0d0 / ((y / z) / (z * 3.0d0))))
    end if
    code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= 2e-21) {
		tmp = (z * z) + ((z * z) + ((y * x) + (z * z)));
	} else {
		tmp = y * (x + (1.0 / ((y / z) / (z * 3.0))));
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	tmp = 0
	if y <= 2e-21:
		tmp = (z * z) + ((z * z) + ((y * x) + (z * z)))
	else:
		tmp = y * (x + (1.0 / ((y / z) / (z * 3.0))))
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	tmp = 0.0
	if (y <= 2e-21)
		tmp = Float64(Float64(z * z) + Float64(Float64(z * z) + Float64(Float64(y * x) + Float64(z * z))));
	else
		tmp = Float64(y * Float64(x + Float64(1.0 / Float64(Float64(y / z) / Float64(z * 3.0)))));
	end
	return tmp
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= 2e-21)
		tmp = (z * z) + ((z * z) + ((y * x) + (z * z)));
	else
		tmp = y * (x + (1.0 / ((y / z) / (z * 3.0))));
	end
	tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := If[LessEqual[y, 2e-21], N[(N[(z * z), $MachinePrecision] + N[(N[(z * z), $MachinePrecision] + N[(N[(y * x), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(x + N[(1.0 / N[(N[(y / z), $MachinePrecision] / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2 \cdot 10^{-21}:\\
\;\;\;\;z \cdot z + \left(z \cdot z + \left(y \cdot x + z \cdot z\right)\right)\\

\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + \frac{1}{\frac{\frac{y}{z}}{z \cdot 3}}\right)\\


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

    1. Initial program 97.8%

      \[\left(\left(x \cdot y + z \cdot z\right) + z \cdot z\right) + z \cdot z \]
    2. Add Preprocessing

    if 1.99999999999999982e-21 < y

    1. Initial program 93.5%

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

      \[\leadsto \color{blue}{y \cdot \left(x + \left(2 \cdot \frac{{z}^{2}}{y} + \frac{{z}^{2}}{y}\right)\right)} \]
    4. Simplified96.7%

      \[\leadsto \color{blue}{y \cdot \left(x + \frac{{z}^{2}}{y} \cdot 3\right)} \]
    5. Step-by-step derivation
      1. unpow296.7%

        \[\leadsto y \cdot \left(x + \frac{\color{blue}{z \cdot z}}{y} \cdot 3\right) \]
      2. associate-/l*100.0%

        \[\leadsto y \cdot \left(x + \color{blue}{\left(z \cdot \frac{z}{y}\right)} \cdot 3\right) \]
    6. Applied egg-rr100.0%

      \[\leadsto y \cdot \left(x + \color{blue}{\left(z \cdot \frac{z}{y}\right)} \cdot 3\right) \]
    7. Step-by-step derivation
      1. clear-num100.0%

        \[\leadsto y \cdot \left(x + \left(z \cdot \color{blue}{\frac{1}{\frac{y}{z}}}\right) \cdot 3\right) \]
      2. un-div-inv99.9%

        \[\leadsto y \cdot \left(x + \color{blue}{\frac{z}{\frac{y}{z}}} \cdot 3\right) \]
    8. Applied egg-rr99.9%

      \[\leadsto y \cdot \left(x + \color{blue}{\frac{z}{\frac{y}{z}}} \cdot 3\right) \]
    9. Step-by-step derivation
      1. associate-*l/99.9%

        \[\leadsto y \cdot \left(x + \color{blue}{\frac{z \cdot 3}{\frac{y}{z}}}\right) \]
      2. clear-num100.0%

        \[\leadsto y \cdot \left(x + \color{blue}{\frac{1}{\frac{\frac{y}{z}}{z \cdot 3}}}\right) \]
    10. Applied egg-rr100.0%

      \[\leadsto y \cdot \left(x + \color{blue}{\frac{1}{\frac{\frac{y}{z}}{z \cdot 3}}}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.3%

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

Alternative 3: 78.2% accurate, 1.1× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;y \cdot x \leq -\infty:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot x + z \cdot z\\ \end{array} \end{array} \]
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
 :precision binary64
 (if (<= (* y x) (- INFINITY)) (* y x) (+ (* y x) (* z z))))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double tmp;
	if ((y * x) <= -((double) INFINITY)) {
		tmp = y * x;
	} else {
		tmp = (y * x) + (z * z);
	}
	return tmp;
}
assert x < y && y < z;
public static double code(double x, double y, double z) {
	double tmp;
	if ((y * x) <= -Double.POSITIVE_INFINITY) {
		tmp = y * x;
	} else {
		tmp = (y * x) + (z * z);
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	tmp = 0
	if (y * x) <= -math.inf:
		tmp = y * x
	else:
		tmp = (y * x) + (z * z)
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	tmp = 0.0
	if (Float64(y * x) <= Float64(-Inf))
		tmp = Float64(y * x);
	else
		tmp = Float64(Float64(y * x) + Float64(z * z));
	end
	return tmp
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y * x) <= -Inf)
		tmp = y * x;
	else
		tmp = (y * x) + (z * z);
	end
	tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := If[LessEqual[N[(y * x), $MachinePrecision], (-Infinity)], N[(y * x), $MachinePrecision], N[(N[(y * x), $MachinePrecision] + N[(z * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot x \leq -\infty:\\
\;\;\;\;y \cdot x\\

\mathbf{else}:\\
\;\;\;\;y \cdot x + z \cdot z\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -inf.0

    1. Initial program 46.7%

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

      \[\leadsto \color{blue}{y \cdot \left(x + \left(2 \cdot \frac{{z}^{2}}{y} + \frac{{z}^{2}}{y}\right)\right)} \]
    4. Simplified73.3%

      \[\leadsto \color{blue}{y \cdot \left(x + \frac{{z}^{2}}{y} \cdot 3\right)} \]
    5. Taylor expanded in y around inf 73.3%

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

    if -inf.0 < (*.f64 x y)

    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 inf 77.7%

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

      \[\leadsto \color{blue}{x \cdot y} + z \cdot z \]
  3. Recombined 2 regimes into one program.
  4. Final simplification76.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot x \leq -\infty:\\ \;\;\;\;y \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot x + z \cdot z\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 93.7% accurate, 1.2× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ y \cdot \left(x + \frac{1}{\frac{\frac{y}{z}}{z \cdot 3}}\right) \end{array} \]
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z) :precision binary64 (* y (+ x (/ 1.0 (/ (/ y z) (* z 3.0))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
	return y * (x + (1.0 / ((y / z) / (z * 3.0))));
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = y * (x + (1.0d0 / ((y / z) / (z * 3.0d0))))
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
	return y * (x + (1.0 / ((y / z) / (z * 3.0))));
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	return y * (x + (1.0 / ((y / z) / (z * 3.0))))
x, y, z = sort([x, y, z])
function code(x, y, z)
	return Float64(y * Float64(x + Float64(1.0 / Float64(Float64(y / z) / Float64(z * 3.0)))))
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
	tmp = y * (x + (1.0 / ((y / z) / (z * 3.0))));
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := N[(y * N[(x + N[(1.0 / N[(N[(y / z), $MachinePrecision] / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
y \cdot \left(x + \frac{1}{\frac{\frac{y}{z}}{z \cdot 3}}\right)
\end{array}
Derivation
  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. Taylor expanded in y around inf 93.5%

    \[\leadsto \color{blue}{y \cdot \left(x + \left(2 \cdot \frac{{z}^{2}}{y} + \frac{{z}^{2}}{y}\right)\right)} \]
  4. Simplified93.5%

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

      \[\leadsto y \cdot \left(x + \frac{\color{blue}{z \cdot z}}{y} \cdot 3\right) \]
    2. associate-/l*95.1%

      \[\leadsto y \cdot \left(x + \color{blue}{\left(z \cdot \frac{z}{y}\right)} \cdot 3\right) \]
  6. Applied egg-rr95.1%

    \[\leadsto y \cdot \left(x + \color{blue}{\left(z \cdot \frac{z}{y}\right)} \cdot 3\right) \]
  7. Step-by-step derivation
    1. clear-num95.1%

      \[\leadsto y \cdot \left(x + \left(z \cdot \color{blue}{\frac{1}{\frac{y}{z}}}\right) \cdot 3\right) \]
    2. un-div-inv95.1%

      \[\leadsto y \cdot \left(x + \color{blue}{\frac{z}{\frac{y}{z}}} \cdot 3\right) \]
  8. Applied egg-rr95.1%

    \[\leadsto y \cdot \left(x + \color{blue}{\frac{z}{\frac{y}{z}}} \cdot 3\right) \]
  9. Step-by-step derivation
    1. associate-*l/95.1%

      \[\leadsto y \cdot \left(x + \color{blue}{\frac{z \cdot 3}{\frac{y}{z}}}\right) \]
    2. clear-num95.1%

      \[\leadsto y \cdot \left(x + \color{blue}{\frac{1}{\frac{\frac{y}{z}}{z \cdot 3}}}\right) \]
  10. Applied egg-rr95.1%

    \[\leadsto y \cdot \left(x + \color{blue}{\frac{1}{\frac{\frac{y}{z}}{z \cdot 3}}}\right) \]
  11. Add Preprocessing

Alternative 5: 93.7% accurate, 1.4× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ y \cdot \left(x + 3 \cdot \left(z \cdot \frac{z}{y}\right)\right) \end{array} \]
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z) :precision binary64 (* y (+ x (* 3.0 (* z (/ z y))))))
assert(x < y && y < z);
double code(double x, double y, double z) {
	return y * (x + (3.0 * (z * (z / y))));
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = y * (x + (3.0d0 * (z * (z / y))))
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
	return y * (x + (3.0 * (z * (z / y))));
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	return y * (x + (3.0 * (z * (z / y))))
x, y, z = sort([x, y, z])
function code(x, y, z)
	return Float64(y * Float64(x + Float64(3.0 * Float64(z * Float64(z / y)))))
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
	tmp = y * (x + (3.0 * (z * (z / y))));
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := N[(y * N[(x + N[(3.0 * N[(z * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
y \cdot \left(x + 3 \cdot \left(z \cdot \frac{z}{y}\right)\right)
\end{array}
Derivation
  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. Taylor expanded in y around inf 93.5%

    \[\leadsto \color{blue}{y \cdot \left(x + \left(2 \cdot \frac{{z}^{2}}{y} + \frac{{z}^{2}}{y}\right)\right)} \]
  4. Simplified93.5%

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

      \[\leadsto y \cdot \left(x + \frac{\color{blue}{z \cdot z}}{y} \cdot 3\right) \]
    2. associate-/l*95.1%

      \[\leadsto y \cdot \left(x + \color{blue}{\left(z \cdot \frac{z}{y}\right)} \cdot 3\right) \]
  6. Applied egg-rr95.1%

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

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

Alternative 6: 52.7% accurate, 5.0× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ y \cdot x \end{array} \]
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z) :precision binary64 (* y x))
assert(x < y && y < z);
double code(double x, double y, double z) {
	return y * x;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = y * x
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
	return y * x;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	return y * x
x, y, z = sort([x, y, z])
function code(x, y, z)
	return Float64(y * x)
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
	tmp = y * x;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := N[(y * x), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
y \cdot x
\end{array}
Derivation
  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. Taylor expanded in y around inf 93.5%

    \[\leadsto \color{blue}{y \cdot \left(x + \left(2 \cdot \frac{{z}^{2}}{y} + \frac{{z}^{2}}{y}\right)\right)} \]
  4. Simplified93.5%

    \[\leadsto \color{blue}{y \cdot \left(x + \frac{{z}^{2}}{y} \cdot 3\right)} \]
  5. Taylor expanded in y around inf 51.4%

    \[\leadsto \color{blue}{x \cdot y} \]
  6. Final simplification51.4%

    \[\leadsto y \cdot x \]
  7. Add Preprocessing

Developer target: 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 2024106 
(FPCore (x y z)
  :name "Linear.Quaternion:$c/ from linear-1.19.1.3, A"
  :precision binary64

  :alt
  (+ (* (* 3.0 z) z) (* y x))

  (+ (+ (+ (* x y) (* z z)) (* z z)) (* z z)))