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

Percentage Accurate: 99.7% → 99.7%
Time: 4.0s
Alternatives: 6
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \left(x \cdot 27\right) \cdot y \end{array} \]
(FPCore (x y) :precision binary64 (* (* x 27.0) y))
double code(double x, double y) {
	return (x * 27.0) * y;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (x * 27.0d0) * y
end function
public static double code(double x, double y) {
	return (x * 27.0) * y;
}
def code(x, y):
	return (x * 27.0) * y
function code(x, y)
	return Float64(Float64(x * 27.0) * y)
end
function tmp = code(x, y)
	tmp = (x * 27.0) * y;
end
code[x_, y_] := N[(N[(x * 27.0), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}

\\
\left(x \cdot 27\right) \cdot y
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 6 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(x \cdot 27\right) \cdot y \end{array} \]
(FPCore (x y) :precision binary64 (* (* x 27.0) y))
double code(double x, double y) {
	return (x * 27.0) * y;
}
real(8) function code(x, y)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (x * 27.0d0) * y
end function
public static double code(double x, double y) {
	return (x * 27.0) * y;
}
def code(x, y):
	return (x * 27.0) * y
function code(x, y)
	return Float64(Float64(x * 27.0) * y)
end
function tmp = code(x, y)
	tmp = (x * 27.0) * y;
end
code[x_, y_] := N[(N[(x * 27.0), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}

\\
\left(x \cdot 27\right) \cdot y
\end{array}

Alternative 1: 99.7% accurate, 1.0× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ [x_m, y_m] = \mathsf{sort}([x_m, y_m])\\ \\ x\_s \cdot \left(y\_s \cdot \left(\left(x\_m \cdot 27\right) \cdot y\_m\right)\right) \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m and y_m should be sorted in increasing order before calling this function.
(FPCore (x_s y_s x_m y_m)
 :precision binary64
 (* x_s (* y_s (* (* x_m 27.0) y_m))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y_m);
double code(double x_s, double y_s, double x_m, double y_m) {
	return x_s * (y_s * ((x_m * 27.0) * y_m));
}
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
NOTE: x_m and y_m should be sorted in increasing order before calling this function.
real(8) function code(x_s, y_s, x_m, y_m)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y_m
    code = x_s * (y_s * ((x_m * 27.0d0) * y_m))
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y_m;
public static double code(double x_s, double y_s, double x_m, double y_m) {
	return x_s * (y_s * ((x_m * 27.0) * y_m));
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
x\_m = math.fabs(x)
x\_s = math.copysign(1.0, x)
[x_m, y_m] = sort([x_m, y_m])
def code(x_s, y_s, x_m, y_m):
	return x_s * (y_s * ((x_m * 27.0) * y_m))
y\_m = abs(y)
y\_s = copysign(1.0, y)
x\_m = abs(x)
x\_s = copysign(1.0, x)
x_m, y_m = sort([x_m, y_m])
function code(x_s, y_s, x_m, y_m)
	return Float64(x_s * Float64(y_s * Float64(Float64(x_m * 27.0) * y_m)))
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y_m = num2cell(sort([x_m, y_m])){:}
function tmp = code(x_s, y_s, x_m, y_m)
	tmp = x_s * (y_s * ((x_m * 27.0) * y_m));
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m and y_m should be sorted in increasing order before calling this function.
code[x$95$s_, y$95$s_, x$95$m_, y$95$m_] := N[(x$95$s * N[(y$95$s * N[(N[(x$95$m * 27.0), $MachinePrecision] * y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y_m] = \mathsf{sort}([x_m, y_m])\\
\\
x\_s \cdot \left(y\_s \cdot \left(\left(x\_m \cdot 27\right) \cdot y\_m\right)\right)
\end{array}
Derivation
  1. Initial program 99.0%

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

Alternative 2: 17.2% accurate, 0.5× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ [x_m, y_m] = \mathsf{sort}([x_m, y_m])\\ \\ x\_s \cdot \left(y\_s \cdot \begin{array}{l} \mathbf{if}\;\left(x\_m \cdot 27\right) \cdot y\_m \leq 4 \cdot 10^{-223}:\\ \;\;\;\;x\_m \cdot \left(-y\_m\right)\\ \mathbf{else}:\\ \;\;\;\;27 \cdot y\_m\\ \end{array}\right) \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m and y_m should be sorted in increasing order before calling this function.
(FPCore (x_s y_s x_m y_m)
 :precision binary64
 (*
  x_s
  (* y_s (if (<= (* (* x_m 27.0) y_m) 4e-223) (* x_m (- y_m)) (* 27.0 y_m)))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y_m);
double code(double x_s, double y_s, double x_m, double y_m) {
	double tmp;
	if (((x_m * 27.0) * y_m) <= 4e-223) {
		tmp = x_m * -y_m;
	} else {
		tmp = 27.0 * y_m;
	}
	return x_s * (y_s * tmp);
}
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
NOTE: x_m and y_m should be sorted in increasing order before calling this function.
real(8) function code(x_s, y_s, x_m, y_m)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y_m
    real(8) :: tmp
    if (((x_m * 27.0d0) * y_m) <= 4d-223) then
        tmp = x_m * -y_m
    else
        tmp = 27.0d0 * y_m
    end if
    code = x_s * (y_s * tmp)
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y_m;
public static double code(double x_s, double y_s, double x_m, double y_m) {
	double tmp;
	if (((x_m * 27.0) * y_m) <= 4e-223) {
		tmp = x_m * -y_m;
	} else {
		tmp = 27.0 * y_m;
	}
	return x_s * (y_s * tmp);
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
x\_m = math.fabs(x)
x\_s = math.copysign(1.0, x)
[x_m, y_m] = sort([x_m, y_m])
def code(x_s, y_s, x_m, y_m):
	tmp = 0
	if ((x_m * 27.0) * y_m) <= 4e-223:
		tmp = x_m * -y_m
	else:
		tmp = 27.0 * y_m
	return x_s * (y_s * tmp)
y\_m = abs(y)
y\_s = copysign(1.0, y)
x\_m = abs(x)
x\_s = copysign(1.0, x)
x_m, y_m = sort([x_m, y_m])
function code(x_s, y_s, x_m, y_m)
	tmp = 0.0
	if (Float64(Float64(x_m * 27.0) * y_m) <= 4e-223)
		tmp = Float64(x_m * Float64(-y_m));
	else
		tmp = Float64(27.0 * y_m);
	end
	return Float64(x_s * Float64(y_s * tmp))
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y_m = num2cell(sort([x_m, y_m])){:}
function tmp_2 = code(x_s, y_s, x_m, y_m)
	tmp = 0.0;
	if (((x_m * 27.0) * y_m) <= 4e-223)
		tmp = x_m * -y_m;
	else
		tmp = 27.0 * y_m;
	end
	tmp_2 = x_s * (y_s * tmp);
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m and y_m should be sorted in increasing order before calling this function.
code[x$95$s_, y$95$s_, x$95$m_, y$95$m_] := N[(x$95$s * N[(y$95$s * If[LessEqual[N[(N[(x$95$m * 27.0), $MachinePrecision] * y$95$m), $MachinePrecision], 4e-223], N[(x$95$m * (-y$95$m)), $MachinePrecision], N[(27.0 * y$95$m), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y_m] = \mathsf{sort}([x_m, y_m])\\
\\
x\_s \cdot \left(y\_s \cdot \begin{array}{l}
\mathbf{if}\;\left(x\_m \cdot 27\right) \cdot y\_m \leq 4 \cdot 10^{-223}:\\
\;\;\;\;x\_m \cdot \left(-y\_m\right)\\

\mathbf{else}:\\
\;\;\;\;27 \cdot y\_m\\


\end{array}\right)
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (*.f64 x #s(literal 27 binary64)) y) < 3.9999999999999999e-223

    1. Initial program 99.2%

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

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

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(x\right)\right)} \cdot y \]
      2. lower-neg.f6421.4

        \[\leadsto \color{blue}{\left(-x\right)} \cdot y \]
    5. Simplified21.4%

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

    if 3.9999999999999999e-223 < (*.f64 (*.f64 x #s(literal 27 binary64)) y)

    1. Initial program 98.8%

      \[\left(x \cdot 27\right) \cdot y \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. associate-*l*N/A

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

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

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

        \[\leadsto \color{blue}{\left(27 \cdot y\right)} \cdot x \]
    4. Applied egg-rr99.8%

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

      \[\leadsto \color{blue}{27 \cdot y} \]
    6. Step-by-step derivation
      1. lower-*.f643.6

        \[\leadsto \color{blue}{27 \cdot y} \]
    7. Simplified3.6%

      \[\leadsto \color{blue}{27 \cdot y} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification14.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(x \cdot 27\right) \cdot y \leq 4 \cdot 10^{-223}:\\ \;\;\;\;x \cdot \left(-y\right)\\ \mathbf{else}:\\ \;\;\;\;27 \cdot y\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 99.5% accurate, 1.0× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ [x_m, y_m] = \mathsf{sort}([x_m, y_m])\\ \\ x\_s \cdot \left(y\_s \cdot \left(x\_m \cdot \left(27 \cdot y\_m\right)\right)\right) \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m and y_m should be sorted in increasing order before calling this function.
(FPCore (x_s y_s x_m y_m)
 :precision binary64
 (* x_s (* y_s (* x_m (* 27.0 y_m)))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y_m);
double code(double x_s, double y_s, double x_m, double y_m) {
	return x_s * (y_s * (x_m * (27.0 * y_m)));
}
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
NOTE: x_m and y_m should be sorted in increasing order before calling this function.
real(8) function code(x_s, y_s, x_m, y_m)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y_m
    code = x_s * (y_s * (x_m * (27.0d0 * y_m)))
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y_m;
public static double code(double x_s, double y_s, double x_m, double y_m) {
	return x_s * (y_s * (x_m * (27.0 * y_m)));
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
x\_m = math.fabs(x)
x\_s = math.copysign(1.0, x)
[x_m, y_m] = sort([x_m, y_m])
def code(x_s, y_s, x_m, y_m):
	return x_s * (y_s * (x_m * (27.0 * y_m)))
y\_m = abs(y)
y\_s = copysign(1.0, y)
x\_m = abs(x)
x\_s = copysign(1.0, x)
x_m, y_m = sort([x_m, y_m])
function code(x_s, y_s, x_m, y_m)
	return Float64(x_s * Float64(y_s * Float64(x_m * Float64(27.0 * y_m))))
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y_m = num2cell(sort([x_m, y_m])){:}
function tmp = code(x_s, y_s, x_m, y_m)
	tmp = x_s * (y_s * (x_m * (27.0 * y_m)));
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m and y_m should be sorted in increasing order before calling this function.
code[x$95$s_, y$95$s_, x$95$m_, y$95$m_] := N[(x$95$s * N[(y$95$s * N[(x$95$m * N[(27.0 * y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y_m] = \mathsf{sort}([x_m, y_m])\\
\\
x\_s \cdot \left(y\_s \cdot \left(x\_m \cdot \left(27 \cdot y\_m\right)\right)\right)
\end{array}
Derivation
  1. Initial program 99.0%

    \[\left(x \cdot 27\right) \cdot y \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. associate-*l*N/A

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

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

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

      \[\leadsto \color{blue}{\left(27 \cdot y\right)} \cdot x \]
  4. Applied egg-rr99.7%

    \[\leadsto \color{blue}{\left(27 \cdot y\right) \cdot x} \]
  5. Final simplification99.7%

    \[\leadsto x \cdot \left(27 \cdot y\right) \]
  6. Add Preprocessing

Alternative 4: 6.2% accurate, 1.8× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ [x_m, y_m] = \mathsf{sort}([x_m, y_m])\\ \\ x\_s \cdot \left(y\_s \cdot \left(27 \cdot y\_m\right)\right) \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m and y_m should be sorted in increasing order before calling this function.
(FPCore (x_s y_s x_m y_m) :precision binary64 (* x_s (* y_s (* 27.0 y_m))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y_m);
double code(double x_s, double y_s, double x_m, double y_m) {
	return x_s * (y_s * (27.0 * y_m));
}
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
NOTE: x_m and y_m should be sorted in increasing order before calling this function.
real(8) function code(x_s, y_s, x_m, y_m)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y_m
    code = x_s * (y_s * (27.0d0 * y_m))
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y_m;
public static double code(double x_s, double y_s, double x_m, double y_m) {
	return x_s * (y_s * (27.0 * y_m));
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
x\_m = math.fabs(x)
x\_s = math.copysign(1.0, x)
[x_m, y_m] = sort([x_m, y_m])
def code(x_s, y_s, x_m, y_m):
	return x_s * (y_s * (27.0 * y_m))
y\_m = abs(y)
y\_s = copysign(1.0, y)
x\_m = abs(x)
x\_s = copysign(1.0, x)
x_m, y_m = sort([x_m, y_m])
function code(x_s, y_s, x_m, y_m)
	return Float64(x_s * Float64(y_s * Float64(27.0 * y_m)))
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y_m = num2cell(sort([x_m, y_m])){:}
function tmp = code(x_s, y_s, x_m, y_m)
	tmp = x_s * (y_s * (27.0 * y_m));
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m and y_m should be sorted in increasing order before calling this function.
code[x$95$s_, y$95$s_, x$95$m_, y$95$m_] := N[(x$95$s * N[(y$95$s * N[(27.0 * y$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y_m] = \mathsf{sort}([x_m, y_m])\\
\\
x\_s \cdot \left(y\_s \cdot \left(27 \cdot y\_m\right)\right)
\end{array}
Derivation
  1. Initial program 99.0%

    \[\left(x \cdot 27\right) \cdot y \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. associate-*l*N/A

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

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

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

      \[\leadsto \color{blue}{\left(27 \cdot y\right)} \cdot x \]
  4. Applied egg-rr99.7%

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

    \[\leadsto \color{blue}{27 \cdot y} \]
  6. Step-by-step derivation
    1. lower-*.f644.1

      \[\leadsto \color{blue}{27 \cdot y} \]
  7. Simplified4.1%

    \[\leadsto \color{blue}{27 \cdot y} \]
  8. Add Preprocessing

Alternative 5: 5.9% accurate, 1.8× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ [x_m, y_m] = \mathsf{sort}([x_m, y_m])\\ \\ x\_s \cdot \left(y\_s \cdot \left(x\_m \cdot 27\right)\right) \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m and y_m should be sorted in increasing order before calling this function.
(FPCore (x_s y_s x_m y_m) :precision binary64 (* x_s (* y_s (* x_m 27.0))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y_m);
double code(double x_s, double y_s, double x_m, double y_m) {
	return x_s * (y_s * (x_m * 27.0));
}
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
NOTE: x_m and y_m should be sorted in increasing order before calling this function.
real(8) function code(x_s, y_s, x_m, y_m)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y_m
    code = x_s * (y_s * (x_m * 27.0d0))
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y_m;
public static double code(double x_s, double y_s, double x_m, double y_m) {
	return x_s * (y_s * (x_m * 27.0));
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
x\_m = math.fabs(x)
x\_s = math.copysign(1.0, x)
[x_m, y_m] = sort([x_m, y_m])
def code(x_s, y_s, x_m, y_m):
	return x_s * (y_s * (x_m * 27.0))
y\_m = abs(y)
y\_s = copysign(1.0, y)
x\_m = abs(x)
x\_s = copysign(1.0, x)
x_m, y_m = sort([x_m, y_m])
function code(x_s, y_s, x_m, y_m)
	return Float64(x_s * Float64(y_s * Float64(x_m * 27.0)))
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y_m = num2cell(sort([x_m, y_m])){:}
function tmp = code(x_s, y_s, x_m, y_m)
	tmp = x_s * (y_s * (x_m * 27.0));
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m and y_m should be sorted in increasing order before calling this function.
code[x$95$s_, y$95$s_, x$95$m_, y$95$m_] := N[(x$95$s * N[(y$95$s * N[(x$95$m * 27.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y_m] = \mathsf{sort}([x_m, y_m])\\
\\
x\_s \cdot \left(y\_s \cdot \left(x\_m \cdot 27\right)\right)
\end{array}
Derivation
  1. Initial program 99.0%

    \[\left(x \cdot 27\right) \cdot y \]
  2. Add Preprocessing
  3. Taylor expanded in x around inf

    \[\leadsto \color{blue}{27 \cdot x} \]
  4. Step-by-step derivation
    1. lower-*.f644.5

      \[\leadsto \color{blue}{27 \cdot x} \]
  5. Simplified4.5%

    \[\leadsto \color{blue}{27 \cdot x} \]
  6. Final simplification4.5%

    \[\leadsto x \cdot 27 \]
  7. Add Preprocessing

Alternative 6: 2.9% accurate, 3.7× speedup?

\[\begin{array}{l} y\_m = \left|y\right| \\ y\_s = \mathsf{copysign}\left(1, y\right) \\ x\_m = \left|x\right| \\ x\_s = \mathsf{copysign}\left(1, x\right) \\ [x_m, y_m] = \mathsf{sort}([x_m, y_m])\\ \\ x\_s \cdot \left(y\_s \cdot \left(-x\_m\right)\right) \end{array} \]
y\_m = (fabs.f64 y)
y\_s = (copysign.f64 #s(literal 1 binary64) y)
x\_m = (fabs.f64 x)
x\_s = (copysign.f64 #s(literal 1 binary64) x)
NOTE: x_m and y_m should be sorted in increasing order before calling this function.
(FPCore (x_s y_s x_m y_m) :precision binary64 (* x_s (* y_s (- x_m))))
y\_m = fabs(y);
y\_s = copysign(1.0, y);
x\_m = fabs(x);
x\_s = copysign(1.0, x);
assert(x_m < y_m);
double code(double x_s, double y_s, double x_m, double y_m) {
	return x_s * (y_s * -x_m);
}
y\_m = abs(y)
y\_s = copysign(1.0d0, y)
x\_m = abs(x)
x\_s = copysign(1.0d0, x)
NOTE: x_m and y_m should be sorted in increasing order before calling this function.
real(8) function code(x_s, y_s, x_m, y_m)
    real(8), intent (in) :: x_s
    real(8), intent (in) :: y_s
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y_m
    code = x_s * (y_s * -x_m)
end function
y\_m = Math.abs(y);
y\_s = Math.copySign(1.0, y);
x\_m = Math.abs(x);
x\_s = Math.copySign(1.0, x);
assert x_m < y_m;
public static double code(double x_s, double y_s, double x_m, double y_m) {
	return x_s * (y_s * -x_m);
}
y\_m = math.fabs(y)
y\_s = math.copysign(1.0, y)
x\_m = math.fabs(x)
x\_s = math.copysign(1.0, x)
[x_m, y_m] = sort([x_m, y_m])
def code(x_s, y_s, x_m, y_m):
	return x_s * (y_s * -x_m)
y\_m = abs(y)
y\_s = copysign(1.0, y)
x\_m = abs(x)
x\_s = copysign(1.0, x)
x_m, y_m = sort([x_m, y_m])
function code(x_s, y_s, x_m, y_m)
	return Float64(x_s * Float64(y_s * Float64(-x_m)))
end
y\_m = abs(y);
y\_s = sign(y) * abs(1.0);
x\_m = abs(x);
x\_s = sign(x) * abs(1.0);
x_m, y_m = num2cell(sort([x_m, y_m])){:}
function tmp = code(x_s, y_s, x_m, y_m)
	tmp = x_s * (y_s * -x_m);
end
y\_m = N[Abs[y], $MachinePrecision]
y\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[y]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
x\_m = N[Abs[x], $MachinePrecision]
x\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x_m and y_m should be sorted in increasing order before calling this function.
code[x$95$s_, y$95$s_, x$95$m_, y$95$m_] := N[(x$95$s * N[(y$95$s * (-x$95$m)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y\_m = \left|y\right|
\\
y\_s = \mathsf{copysign}\left(1, y\right)
\\
x\_m = \left|x\right|
\\
x\_s = \mathsf{copysign}\left(1, x\right)
\\
[x_m, y_m] = \mathsf{sort}([x_m, y_m])\\
\\
x\_s \cdot \left(y\_s \cdot \left(-x\_m\right)\right)
\end{array}
Derivation
  1. Initial program 99.0%

    \[\left(x \cdot 27\right) \cdot y \]
  2. Add Preprocessing
  3. Taylor expanded in x around inf

    \[\leadsto \color{blue}{27 \cdot x} \]
  4. Step-by-step derivation
    1. lower-*.f644.5

      \[\leadsto \color{blue}{27 \cdot x} \]
  5. Simplified4.5%

    \[\leadsto \color{blue}{27 \cdot x} \]
  6. Taylor expanded in x around -inf

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

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

      \[\leadsto \color{blue}{-x} \]
  8. Simplified4.2%

    \[\leadsto \color{blue}{-x} \]
  9. Add Preprocessing

Reproduce

?
herbie shell --seed 2024214 
(FPCore (x y)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, F"
  :precision binary64
  (* (* x 27.0) y))