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

Percentage Accurate: 99.8% → 99.8%
Time: 6.4s
Alternatives: 4
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 4 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])\\ \\ \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.5%

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

Alternative 2: 78.1% 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 -5 \cdot 10^{-71} \lor \neg \left(t\_0 \leq 5 \cdot 10^{+80}\right):\\ \;\;\;\;\left(3 \cdot y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;-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
 (let* ((t_0 (* (* x 3.0) y)))
   (if (or (<= t_0 -5e-71) (not (<= t_0 5e+80))) (* (* 3.0 y) x) (- z))))
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 <= -5e-71) || !(t_0 <= 5e+80)) {
		tmp = (3.0 * y) * x;
	} else {
		tmp = -z;
	}
	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 <= (-5d-71)) .or. (.not. (t_0 <= 5d+80))) then
        tmp = (3.0d0 * y) * x
    else
        tmp = -z
    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 <= -5e-71) || !(t_0 <= 5e+80)) {
		tmp = (3.0 * y) * x;
	} else {
		tmp = -z;
	}
	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 <= -5e-71) or not (t_0 <= 5e+80):
		tmp = (3.0 * y) * x
	else:
		tmp = -z
	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 <= -5e-71) || !(t_0 <= 5e+80))
		tmp = Float64(Float64(3.0 * y) * x);
	else
		tmp = Float64(-z);
	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 <= -5e-71) || ~((t_0 <= 5e+80)))
		tmp = (3.0 * y) * x;
	else
		tmp = -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_] := Block[{t$95$0 = N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -5e-71], N[Not[LessEqual[t$95$0, 5e+80]], $MachinePrecision]], N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision], (-z)]]
\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 -5 \cdot 10^{-71} \lor \neg \left(t\_0 \leq 5 \cdot 10^{+80}\right):\\
\;\;\;\;\left(3 \cdot y\right) \cdot x\\

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


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

    1. Initial program 99.0%

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

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

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

        \[\leadsto \color{blue}{\sqrt{{\left(\left(x \cdot 3\right) \cdot y\right)}^{2}}} - z \]
      4. pow2N/A

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{\left(\left(\left(x \cdot 3\right) \cdot y\right) \cdot x\right) \cdot \left(3 \cdot y\right)}} - z \]
      9. sqrt-prodN/A

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\left(y \cdot \left(3 \cdot x\right)\right) \cdot x} \cdot \sqrt{\color{blue}{y \cdot 3}} - z \]
      21. lower-*.f6419.4

        \[\leadsto \sqrt{\left(y \cdot \left(3 \cdot x\right)\right) \cdot x} \cdot \sqrt{\color{blue}{y \cdot 3}} - z \]
    4. Applied rewrites19.4%

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

      \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(y \cdot {\left(\sqrt{-3}\right)}^{2}\right)\right)} \]
    6. Step-by-step derivation
      1. mul-1-negN/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(x \cdot \left(y \cdot {\left(\sqrt{-3}\right)}^{2}\right)\right)} \]
      2. distribute-rgt-neg-inN/A

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

        \[\leadsto x \cdot \left(\mathsf{neg}\left(\color{blue}{{\left(\sqrt{-3}\right)}^{2} \cdot y}\right)\right) \]
      4. unpow2N/A

        \[\leadsto x \cdot \left(\mathsf{neg}\left(\color{blue}{\left(\sqrt{-3} \cdot \sqrt{-3}\right)} \cdot y\right)\right) \]
      5. rem-square-sqrtN/A

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

        \[\leadsto x \cdot \color{blue}{\left(\left(\mathsf{neg}\left(-3\right)\right) \cdot y\right)} \]
      7. metadata-evalN/A

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

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

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

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

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

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

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

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

        if -4.99999999999999998e-71 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 4.99999999999999961e80

        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.f6483.4

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

          \[\leadsto \color{blue}{-z} \]
      3. Recombined 2 regimes into one program.
      4. Final simplification82.7%

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

      Alternative 3: 78.1% 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 -5 \cdot 10^{-71}:\\ \;\;\;\;\left(3 \cdot y\right) \cdot x\\ \mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+80}:\\ \;\;\;\;-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 -5e-71) (* (* 3.0 y) x) (if (<= t_0 5e+80) (- 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 <= -5e-71) {
      		tmp = (3.0 * y) * x;
      	} else if (t_0 <= 5e+80) {
      		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 <= (-5d-71)) then
              tmp = (3.0d0 * y) * x
          else if (t_0 <= 5d+80) 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 <= -5e-71) {
      		tmp = (3.0 * y) * x;
      	} else if (t_0 <= 5e+80) {
      		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 <= -5e-71:
      		tmp = (3.0 * y) * x
      	elif t_0 <= 5e+80:
      		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 <= -5e-71)
      		tmp = Float64(Float64(3.0 * y) * x);
      	elseif (t_0 <= 5e+80)
      		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 <= -5e-71)
      		tmp = (3.0 * y) * x;
      	elseif (t_0 <= 5e+80)
      		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, -5e-71], N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[t$95$0, 5e+80], (-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 -5 \cdot 10^{-71}:\\
      \;\;\;\;\left(3 \cdot y\right) \cdot x\\
      
      \mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+80}:\\
      \;\;\;\;-z\\
      
      \mathbf{else}:\\
      \;\;\;\;t\_0\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 regimes
      2. if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -4.99999999999999998e-71

        1. Initial program 99.7%

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

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

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

            \[\leadsto \color{blue}{\sqrt{{\left(\left(x \cdot 3\right) \cdot y\right)}^{2}}} - z \]
          4. pow2N/A

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

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

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

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

            \[\leadsto \sqrt{\color{blue}{\left(\left(\left(x \cdot 3\right) \cdot y\right) \cdot x\right) \cdot \left(3 \cdot y\right)}} - z \]
          9. sqrt-prodN/A

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

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

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

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

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

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

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

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

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

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

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

            \[\leadsto \sqrt{\left(y \cdot \left(3 \cdot x\right)\right) \cdot x} \cdot \sqrt{\color{blue}{y \cdot 3}} - z \]
          21. lower-*.f648.1

            \[\leadsto \sqrt{\left(y \cdot \left(3 \cdot x\right)\right) \cdot x} \cdot \sqrt{\color{blue}{y \cdot 3}} - z \]
        4. Applied rewrites8.1%

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

          \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(y \cdot {\left(\sqrt{-3}\right)}^{2}\right)\right)} \]
        6. Step-by-step derivation
          1. mul-1-negN/A

            \[\leadsto \color{blue}{\mathsf{neg}\left(x \cdot \left(y \cdot {\left(\sqrt{-3}\right)}^{2}\right)\right)} \]
          2. distribute-rgt-neg-inN/A

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

            \[\leadsto x \cdot \left(\mathsf{neg}\left(\color{blue}{{\left(\sqrt{-3}\right)}^{2} \cdot y}\right)\right) \]
          4. unpow2N/A

            \[\leadsto x \cdot \left(\mathsf{neg}\left(\color{blue}{\left(\sqrt{-3} \cdot \sqrt{-3}\right)} \cdot y\right)\right) \]
          5. rem-square-sqrtN/A

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

            \[\leadsto x \cdot \color{blue}{\left(\left(\mathsf{neg}\left(-3\right)\right) \cdot y\right)} \]
          7. metadata-evalN/A

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

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

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

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

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

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

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

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

            if -4.99999999999999998e-71 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 4.99999999999999961e80

            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.f6483.4

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

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

            if 4.99999999999999961e80 < (*.f64 (*.f64 x #s(literal 3 binary64)) y)

            1. Initial program 97.8%

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

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

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

                \[\leadsto \color{blue}{\sqrt{{\left(\left(x \cdot 3\right) \cdot y\right)}^{2}}} - z \]
              4. pow2N/A

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

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

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

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

                \[\leadsto \sqrt{\color{blue}{\left(\left(\left(x \cdot 3\right) \cdot y\right) \cdot x\right) \cdot \left(3 \cdot y\right)}} - z \]
              9. sqrt-prodN/A

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

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

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

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

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

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

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

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

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

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

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

                \[\leadsto \sqrt{\left(y \cdot \left(3 \cdot x\right)\right) \cdot x} \cdot \sqrt{\color{blue}{y \cdot 3}} - z \]
              21. lower-*.f6436.2

                \[\leadsto \sqrt{\left(y \cdot \left(3 \cdot x\right)\right) \cdot x} \cdot \sqrt{\color{blue}{y \cdot 3}} - z \]
            4. Applied rewrites36.2%

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

              \[\leadsto \color{blue}{-1 \cdot \left(x \cdot \left(y \cdot {\left(\sqrt{-3}\right)}^{2}\right)\right)} \]
            6. Step-by-step derivation
              1. mul-1-negN/A

                \[\leadsto \color{blue}{\mathsf{neg}\left(x \cdot \left(y \cdot {\left(\sqrt{-3}\right)}^{2}\right)\right)} \]
              2. distribute-rgt-neg-inN/A

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

                \[\leadsto x \cdot \left(\mathsf{neg}\left(\color{blue}{{\left(\sqrt{-3}\right)}^{2} \cdot y}\right)\right) \]
              4. unpow2N/A

                \[\leadsto x \cdot \left(\mathsf{neg}\left(\color{blue}{\left(\sqrt{-3} \cdot \sqrt{-3}\right)} \cdot y\right)\right) \]
              5. rem-square-sqrtN/A

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

                \[\leadsto x \cdot \color{blue}{\left(\left(\mathsf{neg}\left(-3\right)\right) \cdot y\right)} \]
              7. metadata-evalN/A

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

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

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

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

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

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

                \[\leadsto \left(x \cdot 3\right) \cdot \color{blue}{y} \]
            9. Recombined 3 regimes into one program.
            10. Add Preprocessing

            Alternative 4: 51.1% 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.5%

              \[\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.f6455.5

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

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

            Developer Target 1: 99.7% 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 2024338 
            (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))