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

Percentage Accurate: 99.8% → 99.8%
Time: 4.9s
Alternatives: 5
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 5 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])\\ \\ x \cdot \left(3 \cdot y\right) - 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(x * Float64(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[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x \cdot \left(3 \cdot y\right) - z
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(x \cdot 3\right) \cdot y - z \]
  2. Step-by-step derivation
    1. associate-*l*99.8%

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

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

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

Alternative 2: 71.3% accurate, 0.5× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} \mathbf{if}\;x \leq -9.5 \cdot 10^{+87} \lor \neg \left(x \leq -6.2 \cdot 10^{+53}\right) \land \left(x \leq -4.9 \cdot 10^{+25} \lor \neg \left(x \leq 1.35 \cdot 10^{-74}\right)\right):\\ \;\;\;\;3 \cdot \left(x \cdot y\right)\\ \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
 (if (or (<= x -9.5e+87)
         (and (not (<= x -6.2e+53))
              (or (<= x -4.9e+25) (not (<= x 1.35e-74)))))
   (* 3.0 (* x y))
   (- z)))
assert(x < y && y < z);
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -9.5e+87) || (!(x <= -6.2e+53) && ((x <= -4.9e+25) || !(x <= 1.35e-74)))) {
		tmp = 3.0 * (x * y);
	} 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) :: tmp
    if ((x <= (-9.5d+87)) .or. (.not. (x <= (-6.2d+53))) .and. (x <= (-4.9d+25)) .or. (.not. (x <= 1.35d-74))) then
        tmp = 3.0d0 * (x * y)
    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 tmp;
	if ((x <= -9.5e+87) || (!(x <= -6.2e+53) && ((x <= -4.9e+25) || !(x <= 1.35e-74)))) {
		tmp = 3.0 * (x * y);
	} else {
		tmp = -z;
	}
	return tmp;
}
[x, y, z] = sort([x, y, z])
def code(x, y, z):
	tmp = 0
	if (x <= -9.5e+87) or (not (x <= -6.2e+53) and ((x <= -4.9e+25) or not (x <= 1.35e-74))):
		tmp = 3.0 * (x * y)
	else:
		tmp = -z
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	tmp = 0.0
	if ((x <= -9.5e+87) || (!(x <= -6.2e+53) && ((x <= -4.9e+25) || !(x <= 1.35e-74))))
		tmp = Float64(3.0 * Float64(x * y));
	else
		tmp = Float64(-z);
	end
	return tmp
end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x <= -9.5e+87) || (~((x <= -6.2e+53)) && ((x <= -4.9e+25) || ~((x <= 1.35e-74)))))
		tmp = 3.0 * (x * y);
	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_] := If[Or[LessEqual[x, -9.5e+87], And[N[Not[LessEqual[x, -6.2e+53]], $MachinePrecision], Or[LessEqual[x, -4.9e+25], N[Not[LessEqual[x, 1.35e-74]], $MachinePrecision]]]], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{+87} \lor \neg \left(x \leq -6.2 \cdot 10^{+53}\right) \land \left(x \leq -4.9 \cdot 10^{+25} \lor \neg \left(x \leq 1.35 \cdot 10^{-74}\right)\right):\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -9.4999999999999992e87 or -6.20000000000000038e53 < x < -4.9000000000000001e25 or 1.35000000000000009e-74 < x

    1. Initial program 99.8%

      \[\left(x \cdot 3\right) \cdot y - z \]
    2. Step-by-step derivation
      1. associate-*l*99.8%

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

      \[\leadsto \color{blue}{x \cdot \left(3 \cdot y\right) - z} \]
    4. Step-by-step derivation
      1. associate-*r*99.8%

        \[\leadsto \color{blue}{\left(x \cdot 3\right) \cdot y} - z \]
      2. *-commutative99.8%

        \[\leadsto \color{blue}{y \cdot \left(x \cdot 3\right)} - z \]
      3. associate-*r*99.7%

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

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

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

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

    if -9.4999999999999992e87 < x < -6.20000000000000038e53 or -4.9000000000000001e25 < x < 1.35000000000000009e-74

    1. Initial program 99.9%

      \[\left(x \cdot 3\right) \cdot y - z \]
    2. Step-by-step derivation
      1. associate-*l*99.8%

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

      \[\leadsto \color{blue}{x \cdot \left(3 \cdot y\right) - z} \]
    4. Taylor expanded in x around 0 75.7%

      \[\leadsto \color{blue}{-1 \cdot z} \]
    5. Step-by-step derivation
      1. neg-mul-175.7%

        \[\leadsto \color{blue}{-z} \]
    6. Simplified75.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -9.5 \cdot 10^{+87} \lor \neg \left(x \leq -6.2 \cdot 10^{+53}\right) \land \left(x \leq -4.9 \cdot 10^{+25} \lor \neg \left(x \leq 1.35 \cdot 10^{-74}\right)\right):\\ \;\;\;\;3 \cdot \left(x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]

Alternative 3: 71.3% accurate, 0.5× speedup?

\[\begin{array}{l} [x, y, z] = \mathsf{sort}([x, y, z])\\ \\ \begin{array}{l} t_0 := x \cdot \left(3 \cdot y\right)\\ \mathbf{if}\;x \leq -6 \cdot 10^{+87}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;x \leq -1.25 \cdot 10^{+54}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq -1.95 \cdot 10^{+21}:\\ \;\;\;\;3 \cdot \left(x \cdot y\right)\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{-72}:\\ \;\;\;\;-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 (<= x -6e+87)
     t_0
     (if (<= x -1.25e+54)
       (- z)
       (if (<= x -1.95e+21) (* 3.0 (* x y)) (if (<= x 1.35e-72) (- 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 (x <= -6e+87) {
		tmp = t_0;
	} else if (x <= -1.25e+54) {
		tmp = -z;
	} else if (x <= -1.95e+21) {
		tmp = 3.0 * (x * y);
	} else if (x <= 1.35e-72) {
		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 (x <= (-6d+87)) then
        tmp = t_0
    else if (x <= (-1.25d+54)) then
        tmp = -z
    else if (x <= (-1.95d+21)) then
        tmp = 3.0d0 * (x * y)
    else if (x <= 1.35d-72) 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 (x <= -6e+87) {
		tmp = t_0;
	} else if (x <= -1.25e+54) {
		tmp = -z;
	} else if (x <= -1.95e+21) {
		tmp = 3.0 * (x * y);
	} else if (x <= 1.35e-72) {
		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 x <= -6e+87:
		tmp = t_0
	elif x <= -1.25e+54:
		tmp = -z
	elif x <= -1.95e+21:
		tmp = 3.0 * (x * y)
	elif x <= 1.35e-72:
		tmp = -z
	else:
		tmp = t_0
	return tmp
x, y, z = sort([x, y, z])
function code(x, y, z)
	t_0 = Float64(x * Float64(3.0 * y))
	tmp = 0.0
	if (x <= -6e+87)
		tmp = t_0;
	elseif (x <= -1.25e+54)
		tmp = Float64(-z);
	elseif (x <= -1.95e+21)
		tmp = Float64(3.0 * Float64(x * y));
	elseif (x <= 1.35e-72)
		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 (x <= -6e+87)
		tmp = t_0;
	elseif (x <= -1.25e+54)
		tmp = -z;
	elseif (x <= -1.95e+21)
		tmp = 3.0 * (x * y);
	elseif (x <= 1.35e-72)
		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[(x * N[(3.0 * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -6e+87], t$95$0, If[LessEqual[x, -1.25e+54], (-z), If[LessEqual[x, -1.95e+21], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.35e-72], (-z), t$95$0]]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
t_0 := x \cdot \left(3 \cdot y\right)\\
\mathbf{if}\;x \leq -6 \cdot 10^{+87}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;x \leq -1.25 \cdot 10^{+54}:\\
\;\;\;\;-z\\

\mathbf{elif}\;x \leq -1.95 \cdot 10^{+21}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\

\mathbf{elif}\;x \leq 1.35 \cdot 10^{-72}:\\
\;\;\;\;-z\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < -5.9999999999999998e87 or 1.35e-72 < x

    1. Initial program 99.8%

      \[\left(x \cdot 3\right) \cdot y - z \]
    2. Step-by-step derivation
      1. associate-*l*99.8%

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

      \[\leadsto \color{blue}{x \cdot \left(3 \cdot y\right) - z} \]
    4. Step-by-step derivation
      1. associate-*r*99.8%

        \[\leadsto \color{blue}{\left(x \cdot 3\right) \cdot y} - z \]
      2. *-commutative99.8%

        \[\leadsto \color{blue}{y \cdot \left(x \cdot 3\right)} - z \]
      3. associate-*r*99.7%

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

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

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

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

        \[\leadsto 3 \cdot \color{blue}{\left(y \cdot x\right)} \]
      2. associate-*l*64.8%

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

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

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

    if -5.9999999999999998e87 < x < -1.25000000000000001e54 or -1.95e21 < x < 1.35e-72

    1. Initial program 99.9%

      \[\left(x \cdot 3\right) \cdot y - z \]
    2. Step-by-step derivation
      1. associate-*l*99.8%

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

      \[\leadsto \color{blue}{x \cdot \left(3 \cdot y\right) - z} \]
    4. Taylor expanded in x around 0 75.7%

      \[\leadsto \color{blue}{-1 \cdot z} \]
    5. Step-by-step derivation
      1. neg-mul-175.7%

        \[\leadsto \color{blue}{-z} \]
    6. Simplified75.7%

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

    if -1.25000000000000001e54 < x < -1.95e21

    1. Initial program 99.2%

      \[\left(x \cdot 3\right) \cdot y - z \]
    2. Step-by-step derivation
      1. associate-*l*99.5%

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

      \[\leadsto \color{blue}{x \cdot \left(3 \cdot y\right) - z} \]
    4. Step-by-step derivation
      1. associate-*r*99.2%

        \[\leadsto \color{blue}{\left(x \cdot 3\right) \cdot y} - z \]
      2. *-commutative99.2%

        \[\leadsto \color{blue}{y \cdot \left(x \cdot 3\right)} - z \]
      3. associate-*r*99.5%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -6 \cdot 10^{+87}:\\ \;\;\;\;x \cdot \left(3 \cdot y\right)\\ \mathbf{elif}\;x \leq -1.25 \cdot 10^{+54}:\\ \;\;\;\;-z\\ \mathbf{elif}\;x \leq -1.95 \cdot 10^{+21}:\\ \;\;\;\;3 \cdot \left(x \cdot y\right)\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{-72}:\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(3 \cdot y\right)\\ \end{array} \]

Alternative 4: 99.8% accurate, 1.0× speedup?

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

    \[\left(x \cdot 3\right) \cdot y - z \]
  2. Step-by-step derivation
    1. associate-*l*99.8%

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

    \[\leadsto \color{blue}{x \cdot \left(3 \cdot y\right) - z} \]
  4. Taylor expanded in x around 0 99.8%

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

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

Alternative 5: 51.7% accurate, 3.5× 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. Step-by-step derivation
    1. associate-*l*99.8%

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

    \[\leadsto \color{blue}{x \cdot \left(3 \cdot y\right) - z} \]
  4. Taylor expanded in x around 0 55.6%

    \[\leadsto \color{blue}{-1 \cdot z} \]
  5. Step-by-step derivation
    1. neg-mul-155.6%

      \[\leadsto \color{blue}{-z} \]
  6. Simplified55.6%

    \[\leadsto \color{blue}{-z} \]
  7. Final simplification55.6%

    \[\leadsto -z \]

Developer target: 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 2023322 
(FPCore (x y z)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, B"
  :precision binary64

  :herbie-target
  (- (* x (* 3.0 y)) z)

  (- (* (* x 3.0) y) z))