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

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

    \[\left(x \cdot 3\right) \cdot y - z \]
  2. Final simplification99.8%

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

Alternative 2: 68.5% accurate, 0.4× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;y \leq -1.5 \cdot 10^{+51} \lor \neg \left(y \leq 2.3 \cdot 10^{-16} \lor \neg \left(y \leq 2400\right) \land \left(y \leq 7.5 \cdot 10^{+77} \lor \neg \left(y \leq 4.1 \cdot 10^{+107}\right) \land y \leq 8.8 \cdot 10^{+134}\right)\right):\\ \;\;\;\;3 \cdot \left(x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y z)
 :precision binary64
 (if (or (<= y -1.5e+51)
         (not
          (or (<= y 2.3e-16)
              (and (not (<= y 2400.0))
                   (or (<= y 7.5e+77)
                       (and (not (<= y 4.1e+107)) (<= y 8.8e+134)))))))
   (* 3.0 (* x y))
   (- z)))
assert(x < y);
double code(double x, double y, double z) {
	double tmp;
	if ((y <= -1.5e+51) || !((y <= 2.3e-16) || (!(y <= 2400.0) && ((y <= 7.5e+77) || (!(y <= 4.1e+107) && (y <= 8.8e+134)))))) {
		tmp = 3.0 * (x * y);
	} else {
		tmp = -z;
	}
	return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if ((y <= (-1.5d+51)) .or. (.not. (y <= 2.3d-16) .or. (.not. (y <= 2400.0d0)) .and. (y <= 7.5d+77) .or. (.not. (y <= 4.1d+107)) .and. (y <= 8.8d+134))) then
        tmp = 3.0d0 * (x * y)
    else
        tmp = -z
    end if
    code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
	double tmp;
	if ((y <= -1.5e+51) || !((y <= 2.3e-16) || (!(y <= 2400.0) && ((y <= 7.5e+77) || (!(y <= 4.1e+107) && (y <= 8.8e+134)))))) {
		tmp = 3.0 * (x * y);
	} else {
		tmp = -z;
	}
	return tmp;
}
[x, y] = sort([x, y])
def code(x, y, z):
	tmp = 0
	if (y <= -1.5e+51) or not ((y <= 2.3e-16) or (not (y <= 2400.0) and ((y <= 7.5e+77) or (not (y <= 4.1e+107) and (y <= 8.8e+134))))):
		tmp = 3.0 * (x * y)
	else:
		tmp = -z
	return tmp
x, y = sort([x, y])
function code(x, y, z)
	tmp = 0.0
	if ((y <= -1.5e+51) || !((y <= 2.3e-16) || (!(y <= 2400.0) && ((y <= 7.5e+77) || (!(y <= 4.1e+107) && (y <= 8.8e+134))))))
		tmp = Float64(3.0 * Float64(x * y));
	else
		tmp = Float64(-z);
	end
	return tmp
end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((y <= -1.5e+51) || ~(((y <= 2.3e-16) || (~((y <= 2400.0)) && ((y <= 7.5e+77) || (~((y <= 4.1e+107)) && (y <= 8.8e+134)))))))
		tmp = 3.0 * (x * y);
	else
		tmp = -z;
	end
	tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_, z_] := If[Or[LessEqual[y, -1.5e+51], N[Not[Or[LessEqual[y, 2.3e-16], And[N[Not[LessEqual[y, 2400.0]], $MachinePrecision], Or[LessEqual[y, 7.5e+77], And[N[Not[LessEqual[y, 4.1e+107]], $MachinePrecision], LessEqual[y, 8.8e+134]]]]]], $MachinePrecision]], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{+51} \lor \neg \left(y \leq 2.3 \cdot 10^{-16} \lor \neg \left(y \leq 2400\right) \land \left(y \leq 7.5 \cdot 10^{+77} \lor \neg \left(y \leq 4.1 \cdot 10^{+107}\right) \land y \leq 8.8 \cdot 10^{+134}\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 y < -1.5e51 or 2.2999999999999999e-16 < y < 2400 or 7.49999999999999955e77 < y < 4.0999999999999999e107 or 8.8e134 < y

    1. Initial program 99.8%

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

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

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

    if -1.5e51 < y < 2.2999999999999999e-16 or 2400 < y < 7.49999999999999955e77 or 4.0999999999999999e107 < y < 8.8e134

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{-1 \cdot z} \]
    3. Step-by-step derivation
      1. mul-1-neg77.3%

        \[\leadsto \color{blue}{-z} \]
    4. Simplified77.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.5 \cdot 10^{+51} \lor \neg \left(y \leq 2.3 \cdot 10^{-16} \lor \neg \left(y \leq 2400\right) \land \left(y \leq 7.5 \cdot 10^{+77} \lor \neg \left(y \leq 4.1 \cdot 10^{+107}\right) \land y \leq 8.8 \cdot 10^{+134}\right)\right):\\ \;\;\;\;3 \cdot \left(x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;-z\\ \end{array} \]

Alternative 3: 68.4% accurate, 0.4× speedup?

\[\begin{array}{l} [x, y] = \mathsf{sort}([x, y])\\ \\ \begin{array}{l} \mathbf{if}\;y \leq -1.9 \cdot 10^{+54}:\\ \;\;\;\;3 \cdot \left(x \cdot y\right)\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{-16} \lor \neg \left(y \leq 3000\right) \land \left(y \leq 7.5 \cdot 10^{+77} \lor \neg \left(y \leq 4.1 \cdot 10^{+107}\right) \land y \leq 1.32 \cdot 10^{+135}\right):\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x \cdot 3\right)\\ \end{array} \end{array} \]
NOTE: x and y should be sorted in increasing order before calling this function.
(FPCore (x y z)
 :precision binary64
 (if (<= y -1.9e+54)
   (* 3.0 (* x y))
   (if (or (<= y 1.4e-16)
           (and (not (<= y 3000.0))
                (or (<= y 7.5e+77)
                    (and (not (<= y 4.1e+107)) (<= y 1.32e+135)))))
     (- z)
     (* y (* x 3.0)))))
assert(x < y);
double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.9e+54) {
		tmp = 3.0 * (x * y);
	} else if ((y <= 1.4e-16) || (!(y <= 3000.0) && ((y <= 7.5e+77) || (!(y <= 4.1e+107) && (y <= 1.32e+135))))) {
		tmp = -z;
	} else {
		tmp = y * (x * 3.0);
	}
	return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: tmp
    if (y <= (-1.9d+54)) then
        tmp = 3.0d0 * (x * y)
    else if ((y <= 1.4d-16) .or. (.not. (y <= 3000.0d0)) .and. (y <= 7.5d+77) .or. (.not. (y <= 4.1d+107)) .and. (y <= 1.32d+135)) then
        tmp = -z
    else
        tmp = y * (x * 3.0d0)
    end if
    code = tmp
end function
assert x < y;
public static double code(double x, double y, double z) {
	double tmp;
	if (y <= -1.9e+54) {
		tmp = 3.0 * (x * y);
	} else if ((y <= 1.4e-16) || (!(y <= 3000.0) && ((y <= 7.5e+77) || (!(y <= 4.1e+107) && (y <= 1.32e+135))))) {
		tmp = -z;
	} else {
		tmp = y * (x * 3.0);
	}
	return tmp;
}
[x, y] = sort([x, y])
def code(x, y, z):
	tmp = 0
	if y <= -1.9e+54:
		tmp = 3.0 * (x * y)
	elif (y <= 1.4e-16) or (not (y <= 3000.0) and ((y <= 7.5e+77) or (not (y <= 4.1e+107) and (y <= 1.32e+135)))):
		tmp = -z
	else:
		tmp = y * (x * 3.0)
	return tmp
x, y = sort([x, y])
function code(x, y, z)
	tmp = 0.0
	if (y <= -1.9e+54)
		tmp = Float64(3.0 * Float64(x * y));
	elseif ((y <= 1.4e-16) || (!(y <= 3000.0) && ((y <= 7.5e+77) || (!(y <= 4.1e+107) && (y <= 1.32e+135)))))
		tmp = Float64(-z);
	else
		tmp = Float64(y * Float64(x * 3.0));
	end
	return tmp
end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (y <= -1.9e+54)
		tmp = 3.0 * (x * y);
	elseif ((y <= 1.4e-16) || (~((y <= 3000.0)) && ((y <= 7.5e+77) || (~((y <= 4.1e+107)) && (y <= 1.32e+135)))))
		tmp = -z;
	else
		tmp = y * (x * 3.0);
	end
	tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function.
code[x_, y_, z_] := If[LessEqual[y, -1.9e+54], N[(3.0 * N[(x * y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 1.4e-16], And[N[Not[LessEqual[y, 3000.0]], $MachinePrecision], Or[LessEqual[y, 7.5e+77], And[N[Not[LessEqual[y, 4.1e+107]], $MachinePrecision], LessEqual[y, 1.32e+135]]]]], (-z), N[(y * N[(x * 3.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{+54}:\\
\;\;\;\;3 \cdot \left(x \cdot y\right)\\

\mathbf{elif}\;y \leq 1.4 \cdot 10^{-16} \lor \neg \left(y \leq 3000\right) \land \left(y \leq 7.5 \cdot 10^{+77} \lor \neg \left(y \leq 4.1 \cdot 10^{+107}\right) \land y \leq 1.32 \cdot 10^{+135}\right):\\
\;\;\;\;-z\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if y < -1.9000000000000001e54

    1. Initial program 99.8%

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

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

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

    if -1.9000000000000001e54 < y < 1.4000000000000001e-16 or 3e3 < y < 7.49999999999999955e77 or 4.0999999999999999e107 < y < 1.32e135

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{-1 \cdot z} \]
    3. Step-by-step derivation
      1. mul-1-neg77.3%

        \[\leadsto \color{blue}{-z} \]
    4. Simplified77.3%

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

    if 1.4000000000000001e-16 < y < 3e3 or 7.49999999999999955e77 < y < 4.0999999999999999e107 or 1.32e135 < y

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1.9 \cdot 10^{+54}:\\ \;\;\;\;3 \cdot \left(x \cdot y\right)\\ \mathbf{elif}\;y \leq 1.4 \cdot 10^{-16} \lor \neg \left(y \leq 3000\right) \land \left(y \leq 7.5 \cdot 10^{+77} \lor \neg \left(y \leq 4.1 \cdot 10^{+107}\right) \land y \leq 1.32 \cdot 10^{+135}\right):\\ \;\;\;\;-z\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(x \cdot 3\right)\\ \end{array} \]

Alternative 4: 99.8% accurate, 1.0× speedup?

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

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

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

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

Alternative 5: 99.8% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

Alternative 6: 50.6% accurate, 3.5× speedup?

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

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

    \[\leadsto \color{blue}{-1 \cdot z} \]
  3. Step-by-step derivation
    1. mul-1-neg57.1%

      \[\leadsto \color{blue}{-z} \]
  4. Simplified57.1%

    \[\leadsto \color{blue}{-z} \]
  5. Final simplification57.1%

    \[\leadsto -z \]

Alternative 7: 2.3% accurate, 7.0× speedup?

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(y \cdot x, 3, \color{blue}{\sqrt{z} \cdot \sqrt{z}}\right) \]
    8. add-sqr-sqrt43.3%

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

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

    \[\leadsto \color{blue}{z} \]
  5. Final simplification2.1%

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