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

Percentage Accurate: 99.8% → 99.8%
Time: 7.1s
Alternatives: 7
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 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: 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} \\ \mathsf{fma}\left(y \cdot 3, x, -z\right) \end{array} \]
(FPCore (x y z) :precision binary64 (fma (* y 3.0) x (- z)))
double code(double x, double y, double z) {
	return fma((y * 3.0), x, -z);
}
function code(x, y, z)
	return fma(Float64(y * 3.0), x, Float64(-z))
end
code[x_, y_, z_] := N[(N[(y * 3.0), $MachinePrecision] * x + (-z)), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(y \cdot 3, x, -z\right)
\end{array}
Derivation
  1. Initial program 99.4%

    \[\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. Add Preprocessing

Alternative 2: 78.2% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(x \cdot 3\right) \cdot y\\ \mathbf{if}\;t\_0 \leq -2 \cdot 10^{+75} \lor \neg \left(t\_0 \leq 10^{-14}\right):\\ \;\;\;\;\left(3 \cdot y\right) \cdot x\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* (* x 3.0) y)))
   (if (or (<= t_0 -2e+75) (not (<= t_0 1e-14))) (* (* 3.0 y) x) (- z))))
double code(double x, double y, double z) {
	double t_0 = (x * 3.0) * y;
	double tmp;
	if ((t_0 <= -2e+75) || !(t_0 <= 1e-14)) {
		tmp = (3.0 * y) * x;
	} else {
		tmp = -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) :: t_0
    real(8) :: tmp
    t_0 = (x * 3.0d0) * y
    if ((t_0 <= (-2d+75)) .or. (.not. (t_0 <= 1d-14))) then
        tmp = (3.0d0 * y) * x
    else
        tmp = -z
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = (x * 3.0) * y;
	double tmp;
	if ((t_0 <= -2e+75) || !(t_0 <= 1e-14)) {
		tmp = (3.0 * y) * x;
	} else {
		tmp = -z;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = (x * 3.0) * y
	tmp = 0
	if (t_0 <= -2e+75) or not (t_0 <= 1e-14):
		tmp = (3.0 * y) * x
	else:
		tmp = -z
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(x * 3.0) * y)
	tmp = 0.0
	if ((t_0 <= -2e+75) || !(t_0 <= 1e-14))
		tmp = Float64(Float64(3.0 * y) * x);
	else
		tmp = Float64(-z);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = (x * 3.0) * y;
	tmp = 0.0;
	if ((t_0 <= -2e+75) || ~((t_0 <= 1e-14)))
		tmp = (3.0 * y) * x;
	else
		tmp = -z;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -2e+75], N[Not[LessEqual[t$95$0, 1e-14]], $MachinePrecision]], N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision], (-z)]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(x \cdot 3\right) \cdot y\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+75} \lor \neg \left(t\_0 \leq 10^{-14}\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) < -1.99999999999999985e75 or 9.99999999999999999e-15 < (*.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. lift--.f64N/A

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{\left(9 \cdot \left(x \cdot x\right)\right) \cdot y}{\mathsf{fma}\left(y, 3 \cdot x, z\right)}, -z \cdot \frac{z}{\mathsf{fma}\left(y, 3 \cdot x, z\right)}\right)} \]
    5. Taylor expanded in x around 0

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

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

        \[\leadsto \color{blue}{3 \cdot \left(x \cdot y\right)} \]
      3. 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-*.f6485.4

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

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

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

        if -1.99999999999999985e75 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 9.99999999999999999e-15

        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.f6476.2

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

          \[\leadsto \color{blue}{-z} \]
      6. Recombined 2 regimes into one program.
      7. Final simplification80.9%

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

      Alternative 3: 78.2% accurate, 0.3× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(x \cdot 3\right) \cdot y\\ \mathbf{if}\;t\_0 \leq -2 \cdot 10^{+75}:\\ \;\;\;\;\left(3 \cdot x\right) \cdot y\\ \mathbf{elif}\;t\_0 \leq 10^{-14}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;\left(3 \cdot y\right) \cdot x\\ \end{array} \end{array} \]
      (FPCore (x y z)
       :precision binary64
       (let* ((t_0 (* (* x 3.0) y)))
         (if (<= t_0 -2e+75)
           (* (* 3.0 x) y)
           (if (<= t_0 1e-14) (- z) (* (* 3.0 y) x)))))
      double code(double x, double y, double z) {
      	double t_0 = (x * 3.0) * y;
      	double tmp;
      	if (t_0 <= -2e+75) {
      		tmp = (3.0 * x) * y;
      	} else if (t_0 <= 1e-14) {
      		tmp = -z;
      	} else {
      		tmp = (3.0 * y) * x;
      	}
      	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) :: t_0
          real(8) :: tmp
          t_0 = (x * 3.0d0) * y
          if (t_0 <= (-2d+75)) then
              tmp = (3.0d0 * x) * y
          else if (t_0 <= 1d-14) then
              tmp = -z
          else
              tmp = (3.0d0 * y) * x
          end if
          code = tmp
      end function
      
      public static double code(double x, double y, double z) {
      	double t_0 = (x * 3.0) * y;
      	double tmp;
      	if (t_0 <= -2e+75) {
      		tmp = (3.0 * x) * y;
      	} else if (t_0 <= 1e-14) {
      		tmp = -z;
      	} else {
      		tmp = (3.0 * y) * x;
      	}
      	return tmp;
      }
      
      def code(x, y, z):
      	t_0 = (x * 3.0) * y
      	tmp = 0
      	if t_0 <= -2e+75:
      		tmp = (3.0 * x) * y
      	elif t_0 <= 1e-14:
      		tmp = -z
      	else:
      		tmp = (3.0 * y) * x
      	return tmp
      
      function code(x, y, z)
      	t_0 = Float64(Float64(x * 3.0) * y)
      	tmp = 0.0
      	if (t_0 <= -2e+75)
      		tmp = Float64(Float64(3.0 * x) * y);
      	elseif (t_0 <= 1e-14)
      		tmp = Float64(-z);
      	else
      		tmp = Float64(Float64(3.0 * y) * x);
      	end
      	return tmp
      end
      
      function tmp_2 = code(x, y, z)
      	t_0 = (x * 3.0) * y;
      	tmp = 0.0;
      	if (t_0 <= -2e+75)
      		tmp = (3.0 * x) * y;
      	elseif (t_0 <= 1e-14)
      		tmp = -z;
      	else
      		tmp = (3.0 * y) * x;
      	end
      	tmp_2 = tmp;
      end
      
      code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * 3.0), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+75], N[(N[(3.0 * x), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[t$95$0, 1e-14], (-z), N[(N[(3.0 * y), $MachinePrecision] * x), $MachinePrecision]]]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      t_0 := \left(x \cdot 3\right) \cdot y\\
      \mathbf{if}\;t\_0 \leq -2 \cdot 10^{+75}:\\
      \;\;\;\;\left(3 \cdot x\right) \cdot y\\
      
      \mathbf{elif}\;t\_0 \leq 10^{-14}:\\
      \;\;\;\;-z\\
      
      \mathbf{else}:\\
      \;\;\;\;\left(3 \cdot y\right) \cdot x\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 regimes
      2. if (*.f64 (*.f64 x #s(literal 3 binary64)) y) < -1.99999999999999985e75

        1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

            \[\leadsto \left(3 \cdot x\right) \cdot y + \color{blue}{\left(0 - z\right)} \]
          8. flip3--N/A

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

            \[\leadsto \left(3 \cdot x\right) \cdot y + \frac{\color{blue}{0} - {z}^{3}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)} \]
          10. neg-sub0N/A

            \[\leadsto \left(3 \cdot x\right) \cdot y + \frac{\color{blue}{\mathsf{neg}\left({z}^{3}\right)}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)} \]
          11. distribute-neg-fracN/A

            \[\leadsto \left(3 \cdot x\right) \cdot y + \color{blue}{\left(\mathsf{neg}\left(\frac{{z}^{3}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}\right)\right)} \]
          12. sqr-powN/A

            \[\leadsto \left(3 \cdot x\right) \cdot y + \left(\mathsf{neg}\left(\frac{\color{blue}{{z}^{\left(\frac{3}{2}\right)} \cdot {z}^{\left(\frac{3}{2}\right)}}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}\right)\right) \]
          13. pow-prod-downN/A

            \[\leadsto \left(3 \cdot x\right) \cdot y + \left(\mathsf{neg}\left(\frac{\color{blue}{{\left(z \cdot z\right)}^{\left(\frac{3}{2}\right)}}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}\right)\right) \]
          14. sqr-negN/A

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

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

            \[\leadsto \left(3 \cdot x\right) \cdot y + \left(\mathsf{neg}\left(\frac{{\left(\left(-z\right) \cdot \color{blue}{\left(-z\right)}\right)}^{\left(\frac{3}{2}\right)}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}\right)\right) \]
          17. pow-prod-downN/A

            \[\leadsto \left(3 \cdot x\right) \cdot y + \left(\mathsf{neg}\left(\frac{\color{blue}{{\left(-z\right)}^{\left(\frac{3}{2}\right)} \cdot {\left(-z\right)}^{\left(\frac{3}{2}\right)}}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}\right)\right) \]
          18. sqr-powN/A

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

            \[\leadsto \left(3 \cdot x\right) \cdot y + \left(\mathsf{neg}\left(\frac{{\color{blue}{\left(\mathsf{neg}\left(z\right)\right)}}^{3}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}\right)\right) \]
          20. cube-negN/A

            \[\leadsto \left(3 \cdot x\right) \cdot y + \left(\mathsf{neg}\left(\frac{\color{blue}{\mathsf{neg}\left({z}^{3}\right)}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}\right)\right) \]
          21. neg-sub0N/A

            \[\leadsto \left(3 \cdot x\right) \cdot y + \left(\mathsf{neg}\left(\frac{\color{blue}{0 - {z}^{3}}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}\right)\right) \]
          22. metadata-evalN/A

            \[\leadsto \left(3 \cdot x\right) \cdot y + \left(\mathsf{neg}\left(\frac{\color{blue}{{0}^{3}} - {z}^{3}}{0 \cdot 0 + \left(z \cdot z + 0 \cdot z\right)}\right)\right) \]
          23. flip3--N/A

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

            \[\leadsto \left(3 \cdot x\right) \cdot y + \left(\mathsf{neg}\left(\color{blue}{\left(\mathsf{neg}\left(z\right)\right)}\right)\right) \]
        6. Applied rewrites90.4%

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

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

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

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

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

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

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

          \[\leadsto \left(3 \cdot x\right) \cdot y \]
        11. Step-by-step derivation
          1. Applied rewrites90.8%

            \[\leadsto \left(3 \cdot x\right) \cdot y \]

          if -1.99999999999999985e75 < (*.f64 (*.f64 x #s(literal 3 binary64)) y) < 9.99999999999999999e-15

          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.f6476.2

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

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

          if 9.99999999999999999e-15 < (*.f64 (*.f64 x #s(literal 3 binary64)) y)

          1. Initial program 98.5%

            \[\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. flip--N/A

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

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

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

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

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

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

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

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

            \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{\left(9 \cdot \left(x \cdot x\right)\right) \cdot y}{\mathsf{fma}\left(y, 3 \cdot x, z\right)}, -z \cdot \frac{z}{\mathsf{fma}\left(y, 3 \cdot x, z\right)}\right)} \]
          5. Taylor expanded in x around 0

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

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

              \[\leadsto \color{blue}{3 \cdot \left(x \cdot y\right)} \]
            3. 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-*.f6481.5

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

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

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

            Alternative 4: 99.8% accurate, 1.0× speedup?

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

              \[\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. *-commutativeN/A

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

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

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

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

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

              \[\leadsto \color{blue}{\left(y \cdot x\right) \cdot 3} - z \]
            5. Add Preprocessing

            Alternative 5: 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}
            
            Derivation
            1. Initial program 99.4%

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

            Alternative 6: 50.9% accurate, 4.7× speedup?

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

              \[\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.f6445.3

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

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

            Alternative 7: 2.3% accurate, 14.0× speedup?

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

              \[\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.f6445.3

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

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

                \[\leadsto 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 2024313 
              (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))