ab-angle->ABCF D

Percentage Accurate: 82.4% → 99.7%
Time: 5.7s
Alternatives: 7
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ -\left(\left(a \cdot a\right) \cdot b\right) \cdot b \end{array} \]
(FPCore (a b) :precision binary64 (- (* (* (* a a) b) b)))
double code(double a, double b) {
	return -(((a * a) * b) * b);
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = -(((a * a) * b) * b)
end function
public static double code(double a, double b) {
	return -(((a * a) * b) * b);
}
def code(a, b):
	return -(((a * a) * b) * b)
function code(a, b)
	return Float64(-Float64(Float64(Float64(a * a) * b) * b))
end
function tmp = code(a, b)
	tmp = -(((a * a) * b) * b);
end
code[a_, b_] := (-N[(N[(N[(a * a), $MachinePrecision] * b), $MachinePrecision] * b), $MachinePrecision])
\begin{array}{l}

\\
-\left(\left(a \cdot a\right) \cdot b\right) \cdot b
\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: 82.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ -\left(\left(a \cdot a\right) \cdot b\right) \cdot b \end{array} \]
(FPCore (a b) :precision binary64 (- (* (* (* a a) b) b)))
double code(double a, double b) {
	return -(((a * a) * b) * b);
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = -(((a * a) * b) * b)
end function
public static double code(double a, double b) {
	return -(((a * a) * b) * b);
}
def code(a, b):
	return -(((a * a) * b) * b)
function code(a, b)
	return Float64(-Float64(Float64(Float64(a * a) * b) * b))
end
function tmp = code(a, b)
	tmp = -(((a * a) * b) * b);
end
code[a_, b_] := (-N[(N[(N[(a * a), $MachinePrecision] * b), $MachinePrecision] * b), $MachinePrecision])
\begin{array}{l}

\\
-\left(\left(a \cdot a\right) \cdot b\right) \cdot b
\end{array}

Alternative 1: 99.7% accurate, 0.5× speedup?

\[\begin{array}{l} b_m = \left|b\right| \\ a_m = \left|a\right| \\ [a_m, b_m] = \mathsf{sort}([a_m, b_m])\\ \\ \frac{a\_m}{\frac{-1}{b\_m}} \cdot \left(a\_m \cdot b\_m\right) \end{array} \]
b_m = (fabs.f64 b)
a_m = (fabs.f64 a)
NOTE: a_m and b_m should be sorted in increasing order before calling this function.
(FPCore (a_m b_m) :precision binary64 (* (/ a_m (/ -1.0 b_m)) (* a_m b_m)))
b_m = fabs(b);
a_m = fabs(a);
assert(a_m < b_m);
double code(double a_m, double b_m) {
	return (a_m / (-1.0 / b_m)) * (a_m * b_m);
}
b_m = abs(b)
a_m = abs(a)
NOTE: a_m and b_m should be sorted in increasing order before calling this function.
real(8) function code(a_m, b_m)
    real(8), intent (in) :: a_m
    real(8), intent (in) :: b_m
    code = (a_m / ((-1.0d0) / b_m)) * (a_m * b_m)
end function
b_m = Math.abs(b);
a_m = Math.abs(a);
assert a_m < b_m;
public static double code(double a_m, double b_m) {
	return (a_m / (-1.0 / b_m)) * (a_m * b_m);
}
b_m = math.fabs(b)
a_m = math.fabs(a)
[a_m, b_m] = sort([a_m, b_m])
def code(a_m, b_m):
	return (a_m / (-1.0 / b_m)) * (a_m * b_m)
b_m = abs(b)
a_m = abs(a)
a_m, b_m = sort([a_m, b_m])
function code(a_m, b_m)
	return Float64(Float64(a_m / Float64(-1.0 / b_m)) * Float64(a_m * b_m))
end
b_m = abs(b);
a_m = abs(a);
a_m, b_m = num2cell(sort([a_m, b_m])){:}
function tmp = code(a_m, b_m)
	tmp = (a_m / (-1.0 / b_m)) * (a_m * b_m);
end
b_m = N[Abs[b], $MachinePrecision]
a_m = N[Abs[a], $MachinePrecision]
NOTE: a_m and b_m should be sorted in increasing order before calling this function.
code[a$95$m_, b$95$m_] := N[(N[(a$95$m / N[(-1.0 / b$95$m), $MachinePrecision]), $MachinePrecision] * N[(a$95$m * b$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
b_m = \left|b\right|
\\
a_m = \left|a\right|
\\
[a_m, b_m] = \mathsf{sort}([a_m, b_m])\\
\\
\frac{a\_m}{\frac{-1}{b\_m}} \cdot \left(a\_m \cdot b\_m\right)
\end{array}
Derivation
  1. Initial program 80.1%

    \[-\left(\left(a \cdot a\right) \cdot b\right) \cdot b \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-neg.f64N/A

      \[\leadsto \color{blue}{\mathsf{neg}\left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right)} \]
    2. lift-*.f64N/A

      \[\leadsto \mathsf{neg}\left(\color{blue}{\left(\left(a \cdot a\right) \cdot b\right) \cdot b}\right) \]
    3. lift-*.f64N/A

      \[\leadsto \mathsf{neg}\left(\color{blue}{\left(\left(a \cdot a\right) \cdot b\right)} \cdot b\right) \]
    4. associate-*l*N/A

      \[\leadsto \mathsf{neg}\left(\color{blue}{\left(a \cdot a\right) \cdot \left(b \cdot b\right)}\right) \]
    5. lift-*.f64N/A

      \[\leadsto \mathsf{neg}\left(\color{blue}{\left(a \cdot a\right)} \cdot \left(b \cdot b\right)\right) \]
    6. unswap-sqrN/A

      \[\leadsto \mathsf{neg}\left(\color{blue}{\left(a \cdot b\right) \cdot \left(a \cdot b\right)}\right) \]
    7. distribute-lft-neg-inN/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(a \cdot b\right)\right) \cdot \left(a \cdot b\right)} \]
    8. lower-*.f64N/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(a \cdot b\right)\right) \cdot \left(a \cdot b\right)} \]
    9. distribute-rgt-neg-inN/A

      \[\leadsto \color{blue}{\left(a \cdot \left(\mathsf{neg}\left(b\right)\right)\right)} \cdot \left(a \cdot b\right) \]
    10. lower-*.f64N/A

      \[\leadsto \color{blue}{\left(a \cdot \left(\mathsf{neg}\left(b\right)\right)\right)} \cdot \left(a \cdot b\right) \]
    11. lower-neg.f64N/A

      \[\leadsto \left(a \cdot \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}\right) \cdot \left(a \cdot b\right) \]
    12. lower-*.f6499.6

      \[\leadsto \left(a \cdot \left(-b\right)\right) \cdot \color{blue}{\left(a \cdot b\right)} \]
  4. Applied rewrites99.6%

    \[\leadsto \color{blue}{\left(a \cdot \left(-b\right)\right) \cdot \left(a \cdot b\right)} \]
  5. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \color{blue}{\left(a \cdot \left(\mathsf{neg}\left(b\right)\right)\right)} \cdot \left(a \cdot b\right) \]
    2. lift-neg.f64N/A

      \[\leadsto \left(a \cdot \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}\right) \cdot \left(a \cdot b\right) \]
    3. neg-sub0N/A

      \[\leadsto \left(a \cdot \color{blue}{\left(0 - b\right)}\right) \cdot \left(a \cdot b\right) \]
    4. flip3--N/A

      \[\leadsto \left(a \cdot \color{blue}{\frac{{0}^{3} - {b}^{3}}{0 \cdot 0 + \left(b \cdot b + 0 \cdot b\right)}}\right) \cdot \left(a \cdot b\right) \]
    5. clear-numN/A

      \[\leadsto \left(a \cdot \color{blue}{\frac{1}{\frac{0 \cdot 0 + \left(b \cdot b + 0 \cdot b\right)}{{0}^{3} - {b}^{3}}}}\right) \cdot \left(a \cdot b\right) \]
    6. un-div-invN/A

      \[\leadsto \color{blue}{\frac{a}{\frac{0 \cdot 0 + \left(b \cdot b + 0 \cdot b\right)}{{0}^{3} - {b}^{3}}}} \cdot \left(a \cdot b\right) \]
    7. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{a}{\frac{0 \cdot 0 + \left(b \cdot b + 0 \cdot b\right)}{{0}^{3} - {b}^{3}}}} \cdot \left(a \cdot b\right) \]
    8. metadata-evalN/A

      \[\leadsto \frac{a}{\frac{\color{blue}{0} + \left(b \cdot b + 0 \cdot b\right)}{{0}^{3} - {b}^{3}}} \cdot \left(a \cdot b\right) \]
    9. +-lft-identityN/A

      \[\leadsto \frac{a}{\frac{\color{blue}{b \cdot b + 0 \cdot b}}{{0}^{3} - {b}^{3}}} \cdot \left(a \cdot b\right) \]
    10. lift-*.f64N/A

      \[\leadsto \frac{a}{\frac{\color{blue}{b \cdot b} + 0 \cdot b}{{0}^{3} - {b}^{3}}} \cdot \left(a \cdot b\right) \]
    11. mul0-lftN/A

      \[\leadsto \frac{a}{\frac{b \cdot b + \color{blue}{0}}{{0}^{3} - {b}^{3}}} \cdot \left(a \cdot b\right) \]
    12. +-rgt-identityN/A

      \[\leadsto \frac{a}{\frac{\color{blue}{b \cdot b}}{{0}^{3} - {b}^{3}}} \cdot \left(a \cdot b\right) \]
    13. clear-numN/A

      \[\leadsto \frac{a}{\color{blue}{\frac{1}{\frac{{0}^{3} - {b}^{3}}{b \cdot b}}}} \cdot \left(a \cdot b\right) \]
    14. lift-*.f64N/A

      \[\leadsto \frac{a}{\frac{1}{\frac{{0}^{3} - {b}^{3}}{\color{blue}{b \cdot b}}}} \cdot \left(a \cdot b\right) \]
    15. metadata-evalN/A

      \[\leadsto \frac{a}{\frac{1}{\frac{\color{blue}{0} - {b}^{3}}{b \cdot b}}} \cdot \left(a \cdot b\right) \]
    16. mul0-lftN/A

      \[\leadsto \frac{a}{\frac{1}{\frac{\color{blue}{0 \cdot b} - {b}^{3}}{b \cdot b}}} \cdot \left(a \cdot b\right) \]
    17. cube-multN/A

      \[\leadsto \frac{a}{\frac{1}{\frac{0 \cdot b - \color{blue}{b \cdot \left(b \cdot b\right)}}{b \cdot b}}} \cdot \left(a \cdot b\right) \]
    18. lift-*.f64N/A

      \[\leadsto \frac{a}{\frac{1}{\frac{0 \cdot b - b \cdot \color{blue}{\left(b \cdot b\right)}}{b \cdot b}}} \cdot \left(a \cdot b\right) \]
    19. frac-subN/A

      \[\leadsto \frac{a}{\frac{1}{\color{blue}{\frac{0}{b} - \frac{b \cdot b}{b}}}} \cdot \left(a \cdot b\right) \]
    20. sub-divN/A

      \[\leadsto \frac{a}{\frac{1}{\color{blue}{\frac{0 - b \cdot b}{b}}}} \cdot \left(a \cdot b\right) \]
    21. neg-sub0N/A

      \[\leadsto \frac{a}{\frac{1}{\frac{\color{blue}{\mathsf{neg}\left(b \cdot b\right)}}{b}}} \cdot \left(a \cdot b\right) \]
  6. Applied rewrites99.7%

    \[\leadsto \color{blue}{\frac{a}{\frac{-1}{b}}} \cdot \left(a \cdot b\right) \]
  7. Add Preprocessing

Alternative 2: 99.7% accurate, 1.0× speedup?

\[\begin{array}{l} b_m = \left|b\right| \\ a_m = \left|a\right| \\ [a_m, b_m] = \mathsf{sort}([a_m, b_m])\\ \\ \left(a\_m \cdot b\_m\right) \cdot \left(-a\_m \cdot b\_m\right) \end{array} \]
b_m = (fabs.f64 b)
a_m = (fabs.f64 a)
NOTE: a_m and b_m should be sorted in increasing order before calling this function.
(FPCore (a_m b_m) :precision binary64 (* (* a_m b_m) (- (* a_m b_m))))
b_m = fabs(b);
a_m = fabs(a);
assert(a_m < b_m);
double code(double a_m, double b_m) {
	return (a_m * b_m) * -(a_m * b_m);
}
b_m = abs(b)
a_m = abs(a)
NOTE: a_m and b_m should be sorted in increasing order before calling this function.
real(8) function code(a_m, b_m)
    real(8), intent (in) :: a_m
    real(8), intent (in) :: b_m
    code = (a_m * b_m) * -(a_m * b_m)
end function
b_m = Math.abs(b);
a_m = Math.abs(a);
assert a_m < b_m;
public static double code(double a_m, double b_m) {
	return (a_m * b_m) * -(a_m * b_m);
}
b_m = math.fabs(b)
a_m = math.fabs(a)
[a_m, b_m] = sort([a_m, b_m])
def code(a_m, b_m):
	return (a_m * b_m) * -(a_m * b_m)
b_m = abs(b)
a_m = abs(a)
a_m, b_m = sort([a_m, b_m])
function code(a_m, b_m)
	return Float64(Float64(a_m * b_m) * Float64(-Float64(a_m * b_m)))
end
b_m = abs(b);
a_m = abs(a);
a_m, b_m = num2cell(sort([a_m, b_m])){:}
function tmp = code(a_m, b_m)
	tmp = (a_m * b_m) * -(a_m * b_m);
end
b_m = N[Abs[b], $MachinePrecision]
a_m = N[Abs[a], $MachinePrecision]
NOTE: a_m and b_m should be sorted in increasing order before calling this function.
code[a$95$m_, b$95$m_] := N[(N[(a$95$m * b$95$m), $MachinePrecision] * (-N[(a$95$m * b$95$m), $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
b_m = \left|b\right|
\\
a_m = \left|a\right|
\\
[a_m, b_m] = \mathsf{sort}([a_m, b_m])\\
\\
\left(a\_m \cdot b\_m\right) \cdot \left(-a\_m \cdot b\_m\right)
\end{array}
Derivation
  1. Initial program 80.1%

    \[-\left(\left(a \cdot a\right) \cdot b\right) \cdot b \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-neg.f64N/A

      \[\leadsto \color{blue}{\mathsf{neg}\left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right)} \]
    2. lift-*.f64N/A

      \[\leadsto \mathsf{neg}\left(\color{blue}{\left(\left(a \cdot a\right) \cdot b\right) \cdot b}\right) \]
    3. lift-*.f64N/A

      \[\leadsto \mathsf{neg}\left(\color{blue}{\left(\left(a \cdot a\right) \cdot b\right)} \cdot b\right) \]
    4. associate-*l*N/A

      \[\leadsto \mathsf{neg}\left(\color{blue}{\left(a \cdot a\right) \cdot \left(b \cdot b\right)}\right) \]
    5. lift-*.f64N/A

      \[\leadsto \mathsf{neg}\left(\color{blue}{\left(a \cdot a\right)} \cdot \left(b \cdot b\right)\right) \]
    6. unswap-sqrN/A

      \[\leadsto \mathsf{neg}\left(\color{blue}{\left(a \cdot b\right) \cdot \left(a \cdot b\right)}\right) \]
    7. distribute-lft-neg-inN/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(a \cdot b\right)\right) \cdot \left(a \cdot b\right)} \]
    8. lower-*.f64N/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(a \cdot b\right)\right) \cdot \left(a \cdot b\right)} \]
    9. distribute-rgt-neg-inN/A

      \[\leadsto \color{blue}{\left(a \cdot \left(\mathsf{neg}\left(b\right)\right)\right)} \cdot \left(a \cdot b\right) \]
    10. lower-*.f64N/A

      \[\leadsto \color{blue}{\left(a \cdot \left(\mathsf{neg}\left(b\right)\right)\right)} \cdot \left(a \cdot b\right) \]
    11. lower-neg.f64N/A

      \[\leadsto \left(a \cdot \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}\right) \cdot \left(a \cdot b\right) \]
    12. lower-*.f6499.6

      \[\leadsto \left(a \cdot \left(-b\right)\right) \cdot \color{blue}{\left(a \cdot b\right)} \]
  4. Applied rewrites99.6%

    \[\leadsto \color{blue}{\left(a \cdot \left(-b\right)\right) \cdot \left(a \cdot b\right)} \]
  5. Final simplification99.6%

    \[\leadsto \left(a \cdot b\right) \cdot \left(-a \cdot b\right) \]
  6. Add Preprocessing

Alternative 3: 94.6% accurate, 1.0× speedup?

\[\begin{array}{l} b_m = \left|b\right| \\ a_m = \left|a\right| \\ [a_m, b_m] = \mathsf{sort}([a_m, b_m])\\ \\ \left(-b\_m\right) \cdot \left(a\_m \cdot \left(a\_m \cdot b\_m\right)\right) \end{array} \]
b_m = (fabs.f64 b)
a_m = (fabs.f64 a)
NOTE: a_m and b_m should be sorted in increasing order before calling this function.
(FPCore (a_m b_m) :precision binary64 (* (- b_m) (* a_m (* a_m b_m))))
b_m = fabs(b);
a_m = fabs(a);
assert(a_m < b_m);
double code(double a_m, double b_m) {
	return -b_m * (a_m * (a_m * b_m));
}
b_m = abs(b)
a_m = abs(a)
NOTE: a_m and b_m should be sorted in increasing order before calling this function.
real(8) function code(a_m, b_m)
    real(8), intent (in) :: a_m
    real(8), intent (in) :: b_m
    code = -b_m * (a_m * (a_m * b_m))
end function
b_m = Math.abs(b);
a_m = Math.abs(a);
assert a_m < b_m;
public static double code(double a_m, double b_m) {
	return -b_m * (a_m * (a_m * b_m));
}
b_m = math.fabs(b)
a_m = math.fabs(a)
[a_m, b_m] = sort([a_m, b_m])
def code(a_m, b_m):
	return -b_m * (a_m * (a_m * b_m))
b_m = abs(b)
a_m = abs(a)
a_m, b_m = sort([a_m, b_m])
function code(a_m, b_m)
	return Float64(Float64(-b_m) * Float64(a_m * Float64(a_m * b_m)))
end
b_m = abs(b);
a_m = abs(a);
a_m, b_m = num2cell(sort([a_m, b_m])){:}
function tmp = code(a_m, b_m)
	tmp = -b_m * (a_m * (a_m * b_m));
end
b_m = N[Abs[b], $MachinePrecision]
a_m = N[Abs[a], $MachinePrecision]
NOTE: a_m and b_m should be sorted in increasing order before calling this function.
code[a$95$m_, b$95$m_] := N[((-b$95$m) * N[(a$95$m * N[(a$95$m * b$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
b_m = \left|b\right|
\\
a_m = \left|a\right|
\\
[a_m, b_m] = \mathsf{sort}([a_m, b_m])\\
\\
\left(-b\_m\right) \cdot \left(a\_m \cdot \left(a\_m \cdot b\_m\right)\right)
\end{array}
Derivation
  1. Initial program 80.1%

    \[-\left(\left(a \cdot a\right) \cdot b\right) \cdot b \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \mathsf{neg}\left(\color{blue}{\left(\left(a \cdot a\right) \cdot b\right)} \cdot b\right) \]
    2. lift-*.f64N/A

      \[\leadsto \mathsf{neg}\left(\left(\color{blue}{\left(a \cdot a\right)} \cdot b\right) \cdot b\right) \]
    3. associate-*l*N/A

      \[\leadsto \mathsf{neg}\left(\color{blue}{\left(a \cdot \left(a \cdot b\right)\right)} \cdot b\right) \]
    4. *-commutativeN/A

      \[\leadsto \mathsf{neg}\left(\color{blue}{\left(\left(a \cdot b\right) \cdot a\right)} \cdot b\right) \]
    5. lower-*.f64N/A

      \[\leadsto \mathsf{neg}\left(\color{blue}{\left(\left(a \cdot b\right) \cdot a\right)} \cdot b\right) \]
    6. lower-*.f6492.3

      \[\leadsto -\left(\color{blue}{\left(a \cdot b\right)} \cdot a\right) \cdot b \]
  4. Applied rewrites92.3%

    \[\leadsto -\color{blue}{\left(\left(a \cdot b\right) \cdot a\right)} \cdot b \]
  5. Final simplification92.3%

    \[\leadsto \left(-b\right) \cdot \left(a \cdot \left(a \cdot b\right)\right) \]
  6. Add Preprocessing

Alternative 4: 82.4% accurate, 1.0× speedup?

\[\begin{array}{l} b_m = \left|b\right| \\ a_m = \left|a\right| \\ [a_m, b_m] = \mathsf{sort}([a_m, b_m])\\ \\ -b\_m \cdot \left(b\_m \cdot \left(a\_m \cdot a\_m\right)\right) \end{array} \]
b_m = (fabs.f64 b)
a_m = (fabs.f64 a)
NOTE: a_m and b_m should be sorted in increasing order before calling this function.
(FPCore (a_m b_m) :precision binary64 (- (* b_m (* b_m (* a_m a_m)))))
b_m = fabs(b);
a_m = fabs(a);
assert(a_m < b_m);
double code(double a_m, double b_m) {
	return -(b_m * (b_m * (a_m * a_m)));
}
b_m = abs(b)
a_m = abs(a)
NOTE: a_m and b_m should be sorted in increasing order before calling this function.
real(8) function code(a_m, b_m)
    real(8), intent (in) :: a_m
    real(8), intent (in) :: b_m
    code = -(b_m * (b_m * (a_m * a_m)))
end function
b_m = Math.abs(b);
a_m = Math.abs(a);
assert a_m < b_m;
public static double code(double a_m, double b_m) {
	return -(b_m * (b_m * (a_m * a_m)));
}
b_m = math.fabs(b)
a_m = math.fabs(a)
[a_m, b_m] = sort([a_m, b_m])
def code(a_m, b_m):
	return -(b_m * (b_m * (a_m * a_m)))
b_m = abs(b)
a_m = abs(a)
a_m, b_m = sort([a_m, b_m])
function code(a_m, b_m)
	return Float64(-Float64(b_m * Float64(b_m * Float64(a_m * a_m))))
end
b_m = abs(b);
a_m = abs(a);
a_m, b_m = num2cell(sort([a_m, b_m])){:}
function tmp = code(a_m, b_m)
	tmp = -(b_m * (b_m * (a_m * a_m)));
end
b_m = N[Abs[b], $MachinePrecision]
a_m = N[Abs[a], $MachinePrecision]
NOTE: a_m and b_m should be sorted in increasing order before calling this function.
code[a$95$m_, b$95$m_] := (-N[(b$95$m * N[(b$95$m * N[(a$95$m * a$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision])
\begin{array}{l}
b_m = \left|b\right|
\\
a_m = \left|a\right|
\\
[a_m, b_m] = \mathsf{sort}([a_m, b_m])\\
\\
-b\_m \cdot \left(b\_m \cdot \left(a\_m \cdot a\_m\right)\right)
\end{array}
Derivation
  1. Initial program 80.1%

    \[-\left(\left(a \cdot a\right) \cdot b\right) \cdot b \]
  2. Add Preprocessing
  3. Final simplification80.1%

    \[\leadsto -b \cdot \left(b \cdot \left(a \cdot a\right)\right) \]
  4. Add Preprocessing

Alternative 5: 29.6% accurate, 1.1× speedup?

\[\begin{array}{l} b_m = \left|b\right| \\ a_m = \left|a\right| \\ [a_m, b_m] = \mathsf{sort}([a_m, b_m])\\ \\ b\_m \cdot \left(b\_m \cdot \left(a\_m \cdot a\_m\right)\right) \end{array} \]
b_m = (fabs.f64 b)
a_m = (fabs.f64 a)
NOTE: a_m and b_m should be sorted in increasing order before calling this function.
(FPCore (a_m b_m) :precision binary64 (* b_m (* b_m (* a_m a_m))))
b_m = fabs(b);
a_m = fabs(a);
assert(a_m < b_m);
double code(double a_m, double b_m) {
	return b_m * (b_m * (a_m * a_m));
}
b_m = abs(b)
a_m = abs(a)
NOTE: a_m and b_m should be sorted in increasing order before calling this function.
real(8) function code(a_m, b_m)
    real(8), intent (in) :: a_m
    real(8), intent (in) :: b_m
    code = b_m * (b_m * (a_m * a_m))
end function
b_m = Math.abs(b);
a_m = Math.abs(a);
assert a_m < b_m;
public static double code(double a_m, double b_m) {
	return b_m * (b_m * (a_m * a_m));
}
b_m = math.fabs(b)
a_m = math.fabs(a)
[a_m, b_m] = sort([a_m, b_m])
def code(a_m, b_m):
	return b_m * (b_m * (a_m * a_m))
b_m = abs(b)
a_m = abs(a)
a_m, b_m = sort([a_m, b_m])
function code(a_m, b_m)
	return Float64(b_m * Float64(b_m * Float64(a_m * a_m)))
end
b_m = abs(b);
a_m = abs(a);
a_m, b_m = num2cell(sort([a_m, b_m])){:}
function tmp = code(a_m, b_m)
	tmp = b_m * (b_m * (a_m * a_m));
end
b_m = N[Abs[b], $MachinePrecision]
a_m = N[Abs[a], $MachinePrecision]
NOTE: a_m and b_m should be sorted in increasing order before calling this function.
code[a$95$m_, b$95$m_] := N[(b$95$m * N[(b$95$m * N[(a$95$m * a$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
b_m = \left|b\right|
\\
a_m = \left|a\right|
\\
[a_m, b_m] = \mathsf{sort}([a_m, b_m])\\
\\
b\_m \cdot \left(b\_m \cdot \left(a\_m \cdot a\_m\right)\right)
\end{array}
Derivation
  1. Initial program 80.1%

    \[-\left(\left(a \cdot a\right) \cdot b\right) \cdot b \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-neg.f64N/A

      \[\leadsto \color{blue}{\mathsf{neg}\left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right)} \]
    2. +-lft-identityN/A

      \[\leadsto \mathsf{neg}\left(\color{blue}{\left(0 + \left(\left(a \cdot a\right) \cdot b\right) \cdot b\right)}\right) \]
    3. flip3-+N/A

      \[\leadsto \mathsf{neg}\left(\color{blue}{\frac{{0}^{3} + {\left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right)}^{3}}{0 \cdot 0 + \left(\left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right) \cdot \left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right) - 0 \cdot \left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right)\right)}}\right) \]
    4. distribute-neg-fracN/A

      \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left({0}^{3} + {\left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right)}^{3}\right)\right)}{0 \cdot 0 + \left(\left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right) \cdot \left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right) - 0 \cdot \left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right)\right)}} \]
  4. Applied rewrites29.4%

    \[\leadsto \color{blue}{\left(\left(a \cdot a\right) \cdot b\right) \cdot b} \]
  5. Final simplification29.4%

    \[\leadsto b \cdot \left(b \cdot \left(a \cdot a\right)\right) \]
  6. Add Preprocessing

Alternative 6: 29.4% accurate, 1.1× speedup?

\[\begin{array}{l} b_m = \left|b\right| \\ a_m = \left|a\right| \\ [a_m, b_m] = \mathsf{sort}([a_m, b_m])\\ \\ b\_m \cdot \left(a\_m \cdot \left(a\_m \cdot b\_m\right)\right) \end{array} \]
b_m = (fabs.f64 b)
a_m = (fabs.f64 a)
NOTE: a_m and b_m should be sorted in increasing order before calling this function.
(FPCore (a_m b_m) :precision binary64 (* b_m (* a_m (* a_m b_m))))
b_m = fabs(b);
a_m = fabs(a);
assert(a_m < b_m);
double code(double a_m, double b_m) {
	return b_m * (a_m * (a_m * b_m));
}
b_m = abs(b)
a_m = abs(a)
NOTE: a_m and b_m should be sorted in increasing order before calling this function.
real(8) function code(a_m, b_m)
    real(8), intent (in) :: a_m
    real(8), intent (in) :: b_m
    code = b_m * (a_m * (a_m * b_m))
end function
b_m = Math.abs(b);
a_m = Math.abs(a);
assert a_m < b_m;
public static double code(double a_m, double b_m) {
	return b_m * (a_m * (a_m * b_m));
}
b_m = math.fabs(b)
a_m = math.fabs(a)
[a_m, b_m] = sort([a_m, b_m])
def code(a_m, b_m):
	return b_m * (a_m * (a_m * b_m))
b_m = abs(b)
a_m = abs(a)
a_m, b_m = sort([a_m, b_m])
function code(a_m, b_m)
	return Float64(b_m * Float64(a_m * Float64(a_m * b_m)))
end
b_m = abs(b);
a_m = abs(a);
a_m, b_m = num2cell(sort([a_m, b_m])){:}
function tmp = code(a_m, b_m)
	tmp = b_m * (a_m * (a_m * b_m));
end
b_m = N[Abs[b], $MachinePrecision]
a_m = N[Abs[a], $MachinePrecision]
NOTE: a_m and b_m should be sorted in increasing order before calling this function.
code[a$95$m_, b$95$m_] := N[(b$95$m * N[(a$95$m * N[(a$95$m * b$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
b_m = \left|b\right|
\\
a_m = \left|a\right|
\\
[a_m, b_m] = \mathsf{sort}([a_m, b_m])\\
\\
b\_m \cdot \left(a\_m \cdot \left(a\_m \cdot b\_m\right)\right)
\end{array}
Derivation
  1. Initial program 80.1%

    \[-\left(\left(a \cdot a\right) \cdot b\right) \cdot b \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-neg.f64N/A

      \[\leadsto \color{blue}{\mathsf{neg}\left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right)} \]
    2. +-lft-identityN/A

      \[\leadsto \mathsf{neg}\left(\color{blue}{\left(0 + \left(\left(a \cdot a\right) \cdot b\right) \cdot b\right)}\right) \]
    3. flip3-+N/A

      \[\leadsto \mathsf{neg}\left(\color{blue}{\frac{{0}^{3} + {\left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right)}^{3}}{0 \cdot 0 + \left(\left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right) \cdot \left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right) - 0 \cdot \left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right)\right)}}\right) \]
    4. distribute-neg-fracN/A

      \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left({0}^{3} + {\left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right)}^{3}\right)\right)}{0 \cdot 0 + \left(\left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right) \cdot \left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right) - 0 \cdot \left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right)\right)}} \]
  4. Applied rewrites29.5%

    \[\leadsto \color{blue}{\left(a \cdot \left(b \cdot b\right)\right) \cdot a} \]
  5. Step-by-step derivation
    1. lift-*.f64N/A

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

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

      \[\leadsto a \cdot \color{blue}{\left(a \cdot \left(b \cdot b\right)\right)} \]
    4. lift-*.f64N/A

      \[\leadsto a \cdot \left(a \cdot \color{blue}{\left(b \cdot b\right)}\right) \]
    5. associate-*r*N/A

      \[\leadsto a \cdot \color{blue}{\left(\left(a \cdot b\right) \cdot b\right)} \]
    6. lift-*.f64N/A

      \[\leadsto a \cdot \left(\color{blue}{\left(a \cdot b\right)} \cdot b\right) \]
    7. associate-*r*N/A

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

      \[\leadsto \color{blue}{\left(\left(a \cdot b\right) \cdot a\right)} \cdot b \]
    9. rem-square-sqrtN/A

      \[\leadsto \left(\left(a \cdot b\right) \cdot \color{blue}{\left(\sqrt{a} \cdot \sqrt{a}\right)}\right) \cdot b \]
    10. lift-sqrt.f64N/A

      \[\leadsto \left(\left(a \cdot b\right) \cdot \left(\color{blue}{\sqrt{a}} \cdot \sqrt{a}\right)\right) \cdot b \]
    11. lift-sqrt.f64N/A

      \[\leadsto \left(\left(a \cdot b\right) \cdot \left(\sqrt{a} \cdot \color{blue}{\sqrt{a}}\right)\right) \cdot b \]
    12. associate-*l*N/A

      \[\leadsto \color{blue}{\left(\left(\left(a \cdot b\right) \cdot \sqrt{a}\right) \cdot \sqrt{a}\right)} \cdot b \]
    13. lift-*.f64N/A

      \[\leadsto \left(\color{blue}{\left(\left(a \cdot b\right) \cdot \sqrt{a}\right)} \cdot \sqrt{a}\right) \cdot b \]
    14. lift-*.f64N/A

      \[\leadsto \color{blue}{\left(\left(\left(a \cdot b\right) \cdot \sqrt{a}\right) \cdot \sqrt{a}\right)} \cdot b \]
    15. lift-*.f6412.4

      \[\leadsto \color{blue}{\left(\left(\left(a \cdot b\right) \cdot \sqrt{a}\right) \cdot \sqrt{a}\right) \cdot b} \]
    16. lift-*.f64N/A

      \[\leadsto \color{blue}{\left(\left(\left(a \cdot b\right) \cdot \sqrt{a}\right) \cdot \sqrt{a}\right)} \cdot b \]
    17. lift-*.f64N/A

      \[\leadsto \left(\color{blue}{\left(\left(a \cdot b\right) \cdot \sqrt{a}\right)} \cdot \sqrt{a}\right) \cdot b \]
    18. associate-*l*N/A

      \[\leadsto \color{blue}{\left(\left(a \cdot b\right) \cdot \left(\sqrt{a} \cdot \sqrt{a}\right)\right)} \cdot b \]
    19. lift-sqrt.f64N/A

      \[\leadsto \left(\left(a \cdot b\right) \cdot \left(\color{blue}{\sqrt{a}} \cdot \sqrt{a}\right)\right) \cdot b \]
    20. lift-sqrt.f64N/A

      \[\leadsto \left(\left(a \cdot b\right) \cdot \left(\sqrt{a} \cdot \color{blue}{\sqrt{a}}\right)\right) \cdot b \]
    21. rem-square-sqrtN/A

      \[\leadsto \left(\left(a \cdot b\right) \cdot \color{blue}{a}\right) \cdot b \]
    22. *-commutativeN/A

      \[\leadsto \color{blue}{\left(a \cdot \left(a \cdot b\right)\right)} \cdot b \]
    23. lower-*.f6429.4

      \[\leadsto \color{blue}{\left(a \cdot \left(a \cdot b\right)\right)} \cdot b \]
  6. Applied rewrites29.4%

    \[\leadsto \color{blue}{\left(a \cdot \left(a \cdot b\right)\right) \cdot b} \]
  7. Final simplification29.4%

    \[\leadsto b \cdot \left(a \cdot \left(a \cdot b\right)\right) \]
  8. Add Preprocessing

Alternative 7: 29.3% accurate, 1.1× speedup?

\[\begin{array}{l} b_m = \left|b\right| \\ a_m = \left|a\right| \\ [a_m, b_m] = \mathsf{sort}([a_m, b_m])\\ \\ \left(a\_m \cdot b\_m\right) \cdot \left(a\_m \cdot b\_m\right) \end{array} \]
b_m = (fabs.f64 b)
a_m = (fabs.f64 a)
NOTE: a_m and b_m should be sorted in increasing order before calling this function.
(FPCore (a_m b_m) :precision binary64 (* (* a_m b_m) (* a_m b_m)))
b_m = fabs(b);
a_m = fabs(a);
assert(a_m < b_m);
double code(double a_m, double b_m) {
	return (a_m * b_m) * (a_m * b_m);
}
b_m = abs(b)
a_m = abs(a)
NOTE: a_m and b_m should be sorted in increasing order before calling this function.
real(8) function code(a_m, b_m)
    real(8), intent (in) :: a_m
    real(8), intent (in) :: b_m
    code = (a_m * b_m) * (a_m * b_m)
end function
b_m = Math.abs(b);
a_m = Math.abs(a);
assert a_m < b_m;
public static double code(double a_m, double b_m) {
	return (a_m * b_m) * (a_m * b_m);
}
b_m = math.fabs(b)
a_m = math.fabs(a)
[a_m, b_m] = sort([a_m, b_m])
def code(a_m, b_m):
	return (a_m * b_m) * (a_m * b_m)
b_m = abs(b)
a_m = abs(a)
a_m, b_m = sort([a_m, b_m])
function code(a_m, b_m)
	return Float64(Float64(a_m * b_m) * Float64(a_m * b_m))
end
b_m = abs(b);
a_m = abs(a);
a_m, b_m = num2cell(sort([a_m, b_m])){:}
function tmp = code(a_m, b_m)
	tmp = (a_m * b_m) * (a_m * b_m);
end
b_m = N[Abs[b], $MachinePrecision]
a_m = N[Abs[a], $MachinePrecision]
NOTE: a_m and b_m should be sorted in increasing order before calling this function.
code[a$95$m_, b$95$m_] := N[(N[(a$95$m * b$95$m), $MachinePrecision] * N[(a$95$m * b$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
b_m = \left|b\right|
\\
a_m = \left|a\right|
\\
[a_m, b_m] = \mathsf{sort}([a_m, b_m])\\
\\
\left(a\_m \cdot b\_m\right) \cdot \left(a\_m \cdot b\_m\right)
\end{array}
Derivation
  1. Initial program 80.1%

    \[-\left(\left(a \cdot a\right) \cdot b\right) \cdot b \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-neg.f64N/A

      \[\leadsto \color{blue}{\mathsf{neg}\left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right)} \]
    2. +-lft-identityN/A

      \[\leadsto \mathsf{neg}\left(\color{blue}{\left(0 + \left(\left(a \cdot a\right) \cdot b\right) \cdot b\right)}\right) \]
    3. flip3-+N/A

      \[\leadsto \mathsf{neg}\left(\color{blue}{\frac{{0}^{3} + {\left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right)}^{3}}{0 \cdot 0 + \left(\left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right) \cdot \left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right) - 0 \cdot \left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right)\right)}}\right) \]
    4. distribute-neg-fracN/A

      \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\left({0}^{3} + {\left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right)}^{3}\right)\right)}{0 \cdot 0 + \left(\left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right) \cdot \left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right) - 0 \cdot \left(\left(\left(a \cdot a\right) \cdot b\right) \cdot b\right)\right)}} \]
  4. Applied rewrites29.4%

    \[\leadsto \color{blue}{\left(a \cdot b\right) \cdot \left(a \cdot b\right)} \]
  5. Add Preprocessing

Reproduce

?
herbie shell --seed 2024227 
(FPCore (a b)
  :name "ab-angle->ABCF D"
  :precision binary64
  (- (* (* (* a a) b) b)))