Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, B

Percentage Accurate: 99.8% → 99.8%
Time: 5.8s
Alternatives: 6
Speedup: 1.0×

Specification

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

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

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

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

Alternative 1: 99.8% accurate, 1.0× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \mathsf{fma}\left(3 \cdot y, x, -z\right) \end{array} \]
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z) :precision binary64 (fma (* 3.0 y) x (- z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
	return fma((3.0 * y), x, -z);
}
x, y, z = sort([x, y, z])
function code(x, y, z)
	return fma(Float64(3.0 * y), x, Float64(-z))
end
NOTE: x, y, and z should be sorted in increasing order before calling this function.
code[x_, y_, z_] := N[(N[(3.0 * y), $MachinePrecision] * x + (-z)), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(3 \cdot y, x, -z\right)
\end{array}
Derivation
  1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(y \cdot 3, x, -z\right)} \]
  5. Final simplification99.8%

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

Alternative 2: 77.4% accurate, 0.3× speedup?

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

\mathbf{elif}\;t\_0 \leq 10^{+73}:\\
\;\;\;\;-z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -9.99999999999999997e-74

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{y \cdot x}} \cdot {\left(y \cdot x\right)}^{\left(\frac{1}{2}\right)}, 3, -z\right) \]
      6. lower-sqrt.f64N/A

        \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{y \cdot x}} \cdot {\left(y \cdot x\right)}^{\left(\frac{1}{2}\right)}, 3, -z\right) \]
      7. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(\sqrt{y \cdot x} \cdot {\left(y \cdot x\right)}^{\color{blue}{\frac{1}{2}}}, 3, -z\right) \]
      8. unpow1/2N/A

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

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

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

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

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

        \[\leadsto \color{blue}{\left(x \cdot y\right) \cdot 3} \]
      3. lower-*.f6478.9

        \[\leadsto \color{blue}{\left(x \cdot y\right)} \cdot 3 \]
    9. Applied rewrites78.9%

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

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

      if -9.99999999999999997e-74 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 9.99999999999999983e72

      1. Initial program 100.0%

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

        \[\leadsto \color{blue}{-1 \cdot z} \]
      4. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto \color{blue}{\mathsf{neg}\left(z\right)} \]
        2. lower-neg.f6484.2

          \[\leadsto \color{blue}{-z} \]
      5. Applied rewrites84.2%

        \[\leadsto \color{blue}{-z} \]

      if 9.99999999999999983e72 < (*.f64 (*.f64 x #s(literal 3 binary64)) y)

      1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

          \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{y \cdot x}} \cdot {\left(y \cdot x\right)}^{\left(\frac{1}{2}\right)}, 3, -z\right) \]
        6. lower-sqrt.f64N/A

          \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{y \cdot x}} \cdot {\left(y \cdot x\right)}^{\left(\frac{1}{2}\right)}, 3, -z\right) \]
        7. metadata-evalN/A

          \[\leadsto \mathsf{fma}\left(\sqrt{y \cdot x} \cdot {\left(y \cdot x\right)}^{\color{blue}{\frac{1}{2}}}, 3, -z\right) \]
        8. unpow1/2N/A

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

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

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

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

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

          \[\leadsto \color{blue}{\left(x \cdot y\right) \cdot 3} \]
        3. lower-*.f6491.8

          \[\leadsto \color{blue}{\left(x \cdot y\right)} \cdot 3 \]
      9. Applied rewrites91.8%

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

          \[\leadsto \left(y \cdot 3\right) \cdot \color{blue}{x} \]
      11. Recombined 3 regimes into one program.
      12. Final simplification84.0%

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

      Alternative 3: 77.4% accurate, 0.3× speedup?

      \[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} t_0 := \left(x \cdot 3\right) \cdot y\\ \mathbf{if}\;t\_0 \leq -1 \cdot 10^{-73}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;t\_0 \leq 10^{+73}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \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
       (let* ((t_0 (* (* x 3.0) y)))
         (if (<= t_0 -1e-73) t_0 (if (<= t_0 1e+73) (- z) t_0))))
      assert(x < y && y < z);
      double code(double x, double y, double z) {
      	double t_0 = (x * 3.0) * y;
      	double tmp;
      	if (t_0 <= -1e-73) {
      		tmp = t_0;
      	} else if (t_0 <= 1e+73) {
      		tmp = -z;
      	} else {
      		tmp = t_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) :: t_0
          real(8) :: tmp
          t_0 = (x * 3.0d0) * y
          if (t_0 <= (-1d-73)) then
              tmp = t_0
          else if (t_0 <= 1d+73) then
              tmp = -z
          else
              tmp = t_0
          end if
          code = tmp
      end function
      
      assert x < y && y < z;
      public static double code(double x, double y, double z) {
      	double t_0 = (x * 3.0) * y;
      	double tmp;
      	if (t_0 <= -1e-73) {
      		tmp = t_0;
      	} else if (t_0 <= 1e+73) {
      		tmp = -z;
      	} else {
      		tmp = t_0;
      	}
      	return tmp;
      }
      
      [x, y, z] = sort([x, y, z])
      def code(x, y, z):
      	t_0 = (x * 3.0) * y
      	tmp = 0
      	if t_0 <= -1e-73:
      		tmp = t_0
      	elif t_0 <= 1e+73:
      		tmp = -z
      	else:
      		tmp = t_0
      	return tmp
      
      x, y, z = sort([x, y, z])
      function code(x, y, z)
      	t_0 = Float64(Float64(x * 3.0) * y)
      	tmp = 0.0
      	if (t_0 <= -1e-73)
      		tmp = t_0;
      	elseif (t_0 <= 1e+73)
      		tmp = Float64(-z);
      	else
      		tmp = t_0;
      	end
      	return tmp
      end
      
      x, y, z = num2cell(sort([x, y, z])){:}
      function tmp_2 = code(x, y, z)
      	t_0 = (x * 3.0) * y;
      	tmp = 0.0;
      	if (t_0 <= -1e-73)
      		tmp = t_0;
      	elseif (t_0 <= 1e+73)
      		tmp = -z;
      	else
      		tmp = t_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_] := Block[{t$95$0 = N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$0, -1e-73], t$95$0, If[LessEqual[t$95$0, 1e+73], (-z), t$95$0]]]
      
      \begin{array}{l}
      [x, y, z] = \mathsf{sort}([x, y, z])\\
      \\
      \begin{array}{l}
      t_0 := \left(x \cdot 3\right) \cdot y\\
      \mathbf{if}\;t\_0 \leq -1 \cdot 10^{-73}:\\
      \;\;\;\;t\_0\\
      
      \mathbf{elif}\;t\_0 \leq 10^{+73}:\\
      \;\;\;\;-z\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_0\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -9.99999999999999997e-74 or 9.99999999999999983e72 < (*.f64 (*.f64 x #s(literal 3 binary64)) y)

        1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{y \cdot x}} \cdot {\left(y \cdot x\right)}^{\left(\frac{1}{2}\right)}, 3, -z\right) \]
          6. lower-sqrt.f64N/A

            \[\leadsto \mathsf{fma}\left(\color{blue}{\sqrt{y \cdot x}} \cdot {\left(y \cdot x\right)}^{\left(\frac{1}{2}\right)}, 3, -z\right) \]
          7. metadata-evalN/A

            \[\leadsto \mathsf{fma}\left(\sqrt{y \cdot x} \cdot {\left(y \cdot x\right)}^{\color{blue}{\frac{1}{2}}}, 3, -z\right) \]
          8. unpow1/2N/A

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

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

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

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

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

            \[\leadsto \color{blue}{\left(x \cdot y\right) \cdot 3} \]
          3. lower-*.f6483.7

            \[\leadsto \color{blue}{\left(x \cdot y\right)} \cdot 3 \]
        9. Applied rewrites83.7%

          \[\leadsto \color{blue}{\left(x \cdot y\right) \cdot 3} \]
        10. Step-by-step derivation
          1. Applied rewrites83.9%

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

          if -9.99999999999999997e-74 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 9.99999999999999983e72

          1. Initial program 100.0%

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

            \[\leadsto \color{blue}{-1 \cdot z} \]
          4. Step-by-step derivation
            1. mul-1-negN/A

              \[\leadsto \color{blue}{\mathsf{neg}\left(z\right)} \]
            2. lower-neg.f6484.2

              \[\leadsto \color{blue}{-z} \]
          5. Applied rewrites84.2%

            \[\leadsto \color{blue}{-z} \]
        11. Recombined 2 regimes into one program.
        12. Final simplification84.1%

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

        Alternative 4: 99.8% accurate, 1.0× speedup?

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

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

        Alternative 5: 51.9% accurate, 4.7× speedup?

        \[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ -z \end{array} \]
        NOTE: x, y, and z should be sorted in increasing order before calling this function.
        (FPCore (x y z) :precision binary64 (- z))
        assert(x < y && y < z);
        double code(double x, double y, double z) {
        	return -z;
        }
        
        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 = -z
        end function
        
        assert x < y && y < z;
        public static double code(double x, double y, double z) {
        	return -z;
        }
        
        [x, y, z] = sort([x, y, z])
        def code(x, y, z):
        	return -z
        
        x, y, z = sort([x, y, z])
        function code(x, y, z)
        	return Float64(-z)
        end
        
        x, y, z = num2cell(sort([x, y, z])){:}
        function tmp = code(x, y, z)
        	tmp = -z;
        end
        
        NOTE: x, y, and z should be sorted in increasing order before calling this function.
        code[x_, y_, z_] := (-z)
        
        \begin{array}{l}
        [x, y, z] = \mathsf{sort}([x, y, z])\\
        \\
        -z
        \end{array}
        
        Derivation
        1. Initial program 99.9%

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

          \[\leadsto \color{blue}{-1 \cdot z} \]
        4. Step-by-step derivation
          1. mul-1-negN/A

            \[\leadsto \color{blue}{\mathsf{neg}\left(z\right)} \]
          2. lower-neg.f6450.5

            \[\leadsto \color{blue}{-z} \]
        5. Applied rewrites50.5%

          \[\leadsto \color{blue}{-z} \]
        6. Add Preprocessing

        Alternative 6: 2.2% accurate, 14.0× speedup?

        \[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ z \end{array} \]
        NOTE: x, y, and z should be sorted in increasing order before calling this function.
        (FPCore (x y z) :precision binary64 z)
        assert(x < y && y < z);
        double code(double x, double y, double z) {
        	return z;
        }
        
        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 = z
        end function
        
        assert x < y && y < z;
        public static double code(double x, double y, double z) {
        	return z;
        }
        
        [x, y, z] = sort([x, y, z])
        def code(x, y, z):
        	return z
        
        x, y, z = sort([x, y, z])
        function code(x, y, z)
        	return z
        end
        
        x, y, z = num2cell(sort([x, y, z])){:}
        function tmp = code(x, y, z)
        	tmp = z;
        end
        
        NOTE: x, y, and z should be sorted in increasing order before calling this function.
        code[x_, y_, z_] := z
        
        \begin{array}{l}
        [x, y, z] = \mathsf{sort}([x, y, z])\\
        \\
        z
        \end{array}
        
        Derivation
        1. Initial program 99.9%

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

          \[\leadsto \color{blue}{-1 \cdot z} \]
        4. Step-by-step derivation
          1. mul-1-negN/A

            \[\leadsto \color{blue}{\mathsf{neg}\left(z\right)} \]
          2. lower-neg.f6450.5

            \[\leadsto \color{blue}{-z} \]
        5. Applied rewrites50.5%

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

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

          Developer Target 1: 99.8% accurate, 1.0× speedup?

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

          Reproduce

          ?
          herbie shell --seed 2024332 
          (FPCore (x y z)
            :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, B"
            :precision binary64
          
            :alt
            (! :herbie-platform default (- (* x (* 3 y)) z))
          
            (- (* (* x 3.0) y) z))