ab-angle->ABCF D

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

    \[-\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(\left(\color{blue}{\left(a \cdot a\right)} \cdot b\right) \cdot b\right) \]
    2. associate-*l*N/A

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

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

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

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

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(a \cdot b\right)\right) \cdot \left(a \cdot b\right)} \]
    7. 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) \]
    8. lower-*.f64N/A

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

      \[\leadsto \left(a \cdot \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}\right) \cdot \left(a \cdot b\right) \]
    10. 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. neg-sub0N/A

      \[\leadsto \left(a \cdot \color{blue}{\left(0 - b\right)}\right) \cdot \left(a \cdot b\right) \]
    2. 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) \]
    3. 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) \]
    4. 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) \]
    5. 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) \]
    6. 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) \]
    7. +-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) \]
    8. mul0-lftN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{a}{\color{blue}{\frac{\frac{b}{\mathsf{neg}\left(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: 96.1% accurate, 0.7× speedup?

\[\begin{array}{l} a_m = \left|a\right| \\ [a_m, b] = \mathsf{sort}([a_m, b])\\ \\ \begin{array}{l} t_0 := a\_m \cdot \left(-b\right)\\ \mathbf{if}\;a\_m \leq 3.2 \cdot 10^{-214}:\\ \;\;\;\;a\_m \cdot \left(b \cdot t\_0\right)\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(a\_m \cdot t\_0\right)\\ \end{array} \end{array} \]
a_m = (fabs.f64 a)
NOTE: a_m and b should be sorted in increasing order before calling this function.
(FPCore (a_m b)
 :precision binary64
 (let* ((t_0 (* a_m (- b))))
   (if (<= a_m 3.2e-214) (* a_m (* b t_0)) (* b (* a_m t_0)))))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
	double t_0 = a_m * -b;
	double tmp;
	if (a_m <= 3.2e-214) {
		tmp = a_m * (b * t_0);
	} else {
		tmp = b * (a_m * t_0);
	}
	return tmp;
}
a_m = abs(a)
NOTE: a_m and b should be sorted in increasing order before calling this function.
real(8) function code(a_m, b)
    real(8), intent (in) :: a_m
    real(8), intent (in) :: b
    real(8) :: t_0
    real(8) :: tmp
    t_0 = a_m * -b
    if (a_m <= 3.2d-214) then
        tmp = a_m * (b * t_0)
    else
        tmp = b * (a_m * t_0)
    end if
    code = tmp
end function
a_m = Math.abs(a);
assert a_m < b;
public static double code(double a_m, double b) {
	double t_0 = a_m * -b;
	double tmp;
	if (a_m <= 3.2e-214) {
		tmp = a_m * (b * t_0);
	} else {
		tmp = b * (a_m * t_0);
	}
	return tmp;
}
a_m = math.fabs(a)
[a_m, b] = sort([a_m, b])
def code(a_m, b):
	t_0 = a_m * -b
	tmp = 0
	if a_m <= 3.2e-214:
		tmp = a_m * (b * t_0)
	else:
		tmp = b * (a_m * t_0)
	return tmp
a_m = abs(a)
a_m, b = sort([a_m, b])
function code(a_m, b)
	t_0 = Float64(a_m * Float64(-b))
	tmp = 0.0
	if (a_m <= 3.2e-214)
		tmp = Float64(a_m * Float64(b * t_0));
	else
		tmp = Float64(b * Float64(a_m * t_0));
	end
	return tmp
end
a_m = abs(a);
a_m, b = num2cell(sort([a_m, b])){:}
function tmp_2 = code(a_m, b)
	t_0 = a_m * -b;
	tmp = 0.0;
	if (a_m <= 3.2e-214)
		tmp = a_m * (b * t_0);
	else
		tmp = b * (a_m * t_0);
	end
	tmp_2 = tmp;
end
a_m = N[Abs[a], $MachinePrecision]
NOTE: a_m and b should be sorted in increasing order before calling this function.
code[a$95$m_, b_] := Block[{t$95$0 = N[(a$95$m * (-b)), $MachinePrecision]}, If[LessEqual[a$95$m, 3.2e-214], N[(a$95$m * N[(b * t$95$0), $MachinePrecision]), $MachinePrecision], N[(b * N[(a$95$m * t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
\begin{array}{l}
t_0 := a\_m \cdot \left(-b\right)\\
\mathbf{if}\;a\_m \leq 3.2 \cdot 10^{-214}:\\
\;\;\;\;a\_m \cdot \left(b \cdot t\_0\right)\\

\mathbf{else}:\\
\;\;\;\;b \cdot \left(a\_m \cdot t\_0\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < 3.20000000000000013e-214

    1. Initial program 83.6%

      \[-\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(\left(\color{blue}{\left(a \cdot a\right)} \cdot b\right) \cdot b\right) \]
      2. associate-*l*N/A

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

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

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

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

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(a \cdot b\right)\right) \cdot \left(a \cdot b\right)} \]
      7. 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) \]
      8. lower-*.f64N/A

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

        \[\leadsto \left(a \cdot \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}\right) \cdot \left(a \cdot b\right) \]
      10. 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. neg-sub0N/A

        \[\leadsto \left(a \cdot \color{blue}{\left(0 - b\right)}\right) \cdot \left(a \cdot b\right) \]
      2. 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) \]
      3. 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) \]
      4. 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) \]
      5. 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) \]
      6. 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) \]
      7. +-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) \]
      8. mul0-lftN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{a}{\color{blue}{\frac{\frac{b}{\mathsf{neg}\left(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. Taylor expanded in a around 0

      \[\leadsto \color{blue}{-1 \cdot \left({a}^{2} \cdot {b}^{2}\right)} \]
    8. Step-by-step derivation
      1. mul-1-negN/A

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

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

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

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

        \[\leadsto \color{blue}{a \cdot \left(\mathsf{neg}\left(a \cdot {b}^{2}\right)\right)} \]
      6. unpow2N/A

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

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

        \[\leadsto a \cdot \color{blue}{\left(\left(\mathsf{neg}\left(a \cdot b\right)\right) \cdot b\right)} \]
      9. mul-1-negN/A

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

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

        \[\leadsto a \cdot \color{blue}{\left(b \cdot \left(-1 \cdot \left(a \cdot b\right)\right)\right)} \]
      12. mul-1-negN/A

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

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

        \[\leadsto a \cdot \left(b \cdot \color{blue}{\left(a \cdot \left(\mathsf{neg}\left(b\right)\right)\right)}\right) \]
      15. lower-neg.f6495.2

        \[\leadsto a \cdot \left(b \cdot \left(a \cdot \color{blue}{\left(-b\right)}\right)\right) \]
    9. Applied rewrites95.2%

      \[\leadsto \color{blue}{a \cdot \left(b \cdot \left(a \cdot \left(-b\right)\right)\right)} \]

    if 3.20000000000000013e-214 < a

    1. Initial program 84.0%

      \[-\left(\left(a \cdot a\right) \cdot b\right) \cdot b \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0

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

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

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

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

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

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

        \[\leadsto \color{blue}{b \cdot \left(\mathsf{neg}\left({a}^{2} \cdot b\right)\right)} \]
      7. unpow2N/A

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{b \cdot \left(a \cdot \left(a \cdot \left(-b\right)\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 95.6% accurate, 0.7× speedup?

\[\begin{array}{l} a_m = \left|a\right| \\ [a_m, b] = \mathsf{sort}([a_m, b])\\ \\ \begin{array}{l} \mathbf{if}\;a\_m \leq 1.9 \cdot 10^{-161}:\\ \;\;\;\;a\_m \cdot \left(b \cdot \left(a\_m \cdot \left(-b\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(b \cdot \left(a\_m \cdot \left(-a\_m\right)\right)\right)\\ \end{array} \end{array} \]
a_m = (fabs.f64 a)
NOTE: a_m and b should be sorted in increasing order before calling this function.
(FPCore (a_m b)
 :precision binary64
 (if (<= a_m 1.9e-161)
   (* a_m (* b (* a_m (- b))))
   (* b (* b (* a_m (- a_m))))))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
	double tmp;
	if (a_m <= 1.9e-161) {
		tmp = a_m * (b * (a_m * -b));
	} else {
		tmp = b * (b * (a_m * -a_m));
	}
	return tmp;
}
a_m = abs(a)
NOTE: a_m and b should be sorted in increasing order before calling this function.
real(8) function code(a_m, b)
    real(8), intent (in) :: a_m
    real(8), intent (in) :: b
    real(8) :: tmp
    if (a_m <= 1.9d-161) then
        tmp = a_m * (b * (a_m * -b))
    else
        tmp = b * (b * (a_m * -a_m))
    end if
    code = tmp
end function
a_m = Math.abs(a);
assert a_m < b;
public static double code(double a_m, double b) {
	double tmp;
	if (a_m <= 1.9e-161) {
		tmp = a_m * (b * (a_m * -b));
	} else {
		tmp = b * (b * (a_m * -a_m));
	}
	return tmp;
}
a_m = math.fabs(a)
[a_m, b] = sort([a_m, b])
def code(a_m, b):
	tmp = 0
	if a_m <= 1.9e-161:
		tmp = a_m * (b * (a_m * -b))
	else:
		tmp = b * (b * (a_m * -a_m))
	return tmp
a_m = abs(a)
a_m, b = sort([a_m, b])
function code(a_m, b)
	tmp = 0.0
	if (a_m <= 1.9e-161)
		tmp = Float64(a_m * Float64(b * Float64(a_m * Float64(-b))));
	else
		tmp = Float64(b * Float64(b * Float64(a_m * Float64(-a_m))));
	end
	return tmp
end
a_m = abs(a);
a_m, b = num2cell(sort([a_m, b])){:}
function tmp_2 = code(a_m, b)
	tmp = 0.0;
	if (a_m <= 1.9e-161)
		tmp = a_m * (b * (a_m * -b));
	else
		tmp = b * (b * (a_m * -a_m));
	end
	tmp_2 = tmp;
end
a_m = N[Abs[a], $MachinePrecision]
NOTE: a_m and b should be sorted in increasing order before calling this function.
code[a$95$m_, b_] := If[LessEqual[a$95$m, 1.9e-161], N[(a$95$m * N[(b * N[(a$95$m * (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b * N[(b * N[(a$95$m * (-a$95$m)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a\_m \leq 1.9 \cdot 10^{-161}:\\
\;\;\;\;a\_m \cdot \left(b \cdot \left(a\_m \cdot \left(-b\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;b \cdot \left(b \cdot \left(a\_m \cdot \left(-a\_m\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < 1.9000000000000001e-161

    1. Initial program 83.6%

      \[-\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(\left(\color{blue}{\left(a \cdot a\right)} \cdot b\right) \cdot b\right) \]
      2. associate-*l*N/A

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

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

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

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

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(a \cdot b\right)\right) \cdot \left(a \cdot b\right)} \]
      7. 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) \]
      8. lower-*.f64N/A

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

        \[\leadsto \left(a \cdot \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}\right) \cdot \left(a \cdot b\right) \]
      10. 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. neg-sub0N/A

        \[\leadsto \left(a \cdot \color{blue}{\left(0 - b\right)}\right) \cdot \left(a \cdot b\right) \]
      2. 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) \]
      3. 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) \]
      4. 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) \]
      5. 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) \]
      6. 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) \]
      7. +-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) \]
      8. mul0-lftN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{a}{\color{blue}{\frac{\frac{b}{\mathsf{neg}\left(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. Taylor expanded in a around 0

      \[\leadsto \color{blue}{-1 \cdot \left({a}^{2} \cdot {b}^{2}\right)} \]
    8. Step-by-step derivation
      1. mul-1-negN/A

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

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

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

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

        \[\leadsto \color{blue}{a \cdot \left(\mathsf{neg}\left(a \cdot {b}^{2}\right)\right)} \]
      6. unpow2N/A

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

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

        \[\leadsto a \cdot \color{blue}{\left(\left(\mathsf{neg}\left(a \cdot b\right)\right) \cdot b\right)} \]
      9. mul-1-negN/A

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

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

        \[\leadsto a \cdot \color{blue}{\left(b \cdot \left(-1 \cdot \left(a \cdot b\right)\right)\right)} \]
      12. mul-1-negN/A

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

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

        \[\leadsto a \cdot \left(b \cdot \color{blue}{\left(a \cdot \left(\mathsf{neg}\left(b\right)\right)\right)}\right) \]
      15. lower-neg.f6495.4

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

      \[\leadsto \color{blue}{a \cdot \left(b \cdot \left(a \cdot \left(-b\right)\right)\right)} \]

    if 1.9000000000000001e-161 < a

    1. Initial program 84.0%

      \[-\left(\left(a \cdot a\right) \cdot b\right) \cdot b \]
    2. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification90.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq 1.9 \cdot 10^{-161}:\\ \;\;\;\;a \cdot \left(b \cdot \left(a \cdot \left(-b\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(b \cdot \left(a \cdot \left(-a\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 99.7% accurate, 1.0× speedup?

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

    \[-\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(\left(\color{blue}{\left(a \cdot a\right)} \cdot b\right) \cdot b\right) \]
    2. associate-*l*N/A

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

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

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

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

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(a \cdot b\right)\right) \cdot \left(a \cdot b\right)} \]
    7. 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) \]
    8. lower-*.f64N/A

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

      \[\leadsto \left(a \cdot \color{blue}{\left(\mathsf{neg}\left(b\right)\right)}\right) \cdot \left(a \cdot b\right) \]
    10. 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 \left(-b\right)\right) \]
  6. Add Preprocessing

Alternative 5: 81.8% accurate, 1.0× speedup?

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

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

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

Alternative 6: 28.7% accurate, 1.1× speedup?

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

    \[-\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(\left(\color{blue}{\left(a \cdot a\right)} \cdot b\right) \cdot b\right) \]
    2. associate-*l*N/A

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

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

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

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

      \[\leadsto \mathsf{neg}\left(\color{blue}{\left(0 + \left(\left(a \cdot a\right) \cdot b\right) \cdot b\right)}\right) \]
    7. 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) \]
    8. 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.7%

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

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

Alternative 7: 28.5% accurate, 1.1× speedup?

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

    \[-\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(\left(\color{blue}{\left(a \cdot a\right)} \cdot b\right) \cdot b\right) \]
    2. associate-*l*N/A

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

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

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

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

      \[\leadsto \mathsf{neg}\left(\color{blue}{\left(0 + \left(\left(a \cdot a\right) \cdot b\right) \cdot b\right)}\right) \]
    7. 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) \]
    8. 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.7%

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

Reproduce

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