ab-angle->ABCF D

Percentage Accurate: 81.7% → 99.7%
Time: 4.9s
Alternatives: 8
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 8 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.7% 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 81.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 egg-rr30.8%

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

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

Alternative 2: 96.6% 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])\\ \\ \begin{array}{l} t_0 := b\_m \cdot \left(a\_m \cdot a\_m\right)\\ \mathbf{if}\;b\_m \cdot t\_0 \leq 4 \cdot 10^{+182}:\\ \;\;\;\;a\_m \cdot \left(-b\_m \cdot \left(a\_m \cdot b\_m\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-b\_m\right) \cdot t\_0\\ \end{array} \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
 (let* ((t_0 (* b_m (* a_m a_m))))
   (if (<= (* b_m t_0) 4e+182)
     (* a_m (- (* b_m (* a_m b_m))))
     (* (- b_m) t_0))))
b_m = fabs(b);
a_m = fabs(a);
assert(a_m < b_m);
double code(double a_m, double b_m) {
	double t_0 = b_m * (a_m * a_m);
	double tmp;
	if ((b_m * t_0) <= 4e+182) {
		tmp = a_m * -(b_m * (a_m * b_m));
	} else {
		tmp = -b_m * t_0;
	}
	return tmp;
}
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
    real(8) :: t_0
    real(8) :: tmp
    t_0 = b_m * (a_m * a_m)
    if ((b_m * t_0) <= 4d+182) then
        tmp = a_m * -(b_m * (a_m * b_m))
    else
        tmp = -b_m * t_0
    end if
    code = tmp
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) {
	double t_0 = b_m * (a_m * a_m);
	double tmp;
	if ((b_m * t_0) <= 4e+182) {
		tmp = a_m * -(b_m * (a_m * b_m));
	} else {
		tmp = -b_m * t_0;
	}
	return tmp;
}
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):
	t_0 = b_m * (a_m * a_m)
	tmp = 0
	if (b_m * t_0) <= 4e+182:
		tmp = a_m * -(b_m * (a_m * b_m))
	else:
		tmp = -b_m * t_0
	return tmp
b_m = abs(b)
a_m = abs(a)
a_m, b_m = sort([a_m, b_m])
function code(a_m, b_m)
	t_0 = Float64(b_m * Float64(a_m * a_m))
	tmp = 0.0
	if (Float64(b_m * t_0) <= 4e+182)
		tmp = Float64(a_m * Float64(-Float64(b_m * Float64(a_m * b_m))));
	else
		tmp = Float64(Float64(-b_m) * t_0);
	end
	return tmp
end
b_m = abs(b);
a_m = abs(a);
a_m, b_m = num2cell(sort([a_m, b_m])){:}
function tmp_2 = code(a_m, b_m)
	t_0 = b_m * (a_m * a_m);
	tmp = 0.0;
	if ((b_m * t_0) <= 4e+182)
		tmp = a_m * -(b_m * (a_m * b_m));
	else
		tmp = -b_m * t_0;
	end
	tmp_2 = tmp;
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_] := Block[{t$95$0 = N[(b$95$m * N[(a$95$m * a$95$m), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(b$95$m * t$95$0), $MachinePrecision], 4e+182], N[(a$95$m * (-N[(b$95$m * N[(a$95$m * b$95$m), $MachinePrecision]), $MachinePrecision])), $MachinePrecision], N[((-b$95$m) * t$95$0), $MachinePrecision]]]
\begin{array}{l}
b_m = \left|b\right|
\\
a_m = \left|a\right|
\\
[a_m, b_m] = \mathsf{sort}([a_m, b_m])\\
\\
\begin{array}{l}
t_0 := b\_m \cdot \left(a\_m \cdot a\_m\right)\\
\mathbf{if}\;b\_m \cdot t\_0 \leq 4 \cdot 10^{+182}:\\
\;\;\;\;a\_m \cdot \left(-b\_m \cdot \left(a\_m \cdot b\_m\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (*.f64 (*.f64 a a) b) b) < 4.0000000000000003e182

    1. Initial program 83.4%

      \[-\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 egg-rr99.6%

      \[\leadsto \color{blue}{\left(a \cdot \left(-b\right)\right) \cdot \left(a \cdot b\right)} \]
    5. Taylor expanded in a around 0

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto -a \cdot \left(b \cdot \color{blue}{\left(a \cdot b\right)}\right) \]
    7. Simplified94.6%

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

    if 4.0000000000000003e182 < (*.f64 (*.f64 (*.f64 a a) b) b)

    1. Initial program 79.6%

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

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

Alternative 3: 97.8% accurate, 0.7× speedup?

\[\begin{array}{l} b_m = \left|b\right| \\ a_m = \left|a\right| \\ [a_m, b_m] = \mathsf{sort}([a_m, b_m])\\ \\ \begin{array}{l} \mathbf{if}\;a\_m \leq 3.2 \cdot 10^{-222}:\\ \;\;\;\;a\_m \cdot \left(-b\_m \cdot \left(a\_m \cdot b\_m\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-b\_m\right) \cdot \left(a\_m \cdot \left(a\_m \cdot b\_m\right)\right)\\ \end{array} \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
 (if (<= a_m 3.2e-222)
   (* a_m (- (* b_m (* a_m b_m))))
   (* (- 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) {
	double tmp;
	if (a_m <= 3.2e-222) {
		tmp = a_m * -(b_m * (a_m * b_m));
	} else {
		tmp = -b_m * (a_m * (a_m * b_m));
	}
	return tmp;
}
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
    real(8) :: tmp
    if (a_m <= 3.2d-222) then
        tmp = a_m * -(b_m * (a_m * b_m))
    else
        tmp = -b_m * (a_m * (a_m * b_m))
    end if
    code = tmp
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) {
	double tmp;
	if (a_m <= 3.2e-222) {
		tmp = a_m * -(b_m * (a_m * b_m));
	} else {
		tmp = -b_m * (a_m * (a_m * b_m));
	}
	return tmp;
}
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):
	tmp = 0
	if a_m <= 3.2e-222:
		tmp = a_m * -(b_m * (a_m * b_m))
	else:
		tmp = -b_m * (a_m * (a_m * b_m))
	return tmp
b_m = abs(b)
a_m = abs(a)
a_m, b_m = sort([a_m, b_m])
function code(a_m, b_m)
	tmp = 0.0
	if (a_m <= 3.2e-222)
		tmp = Float64(a_m * Float64(-Float64(b_m * Float64(a_m * b_m))));
	else
		tmp = Float64(Float64(-b_m) * Float64(a_m * Float64(a_m * b_m)));
	end
	return tmp
end
b_m = abs(b);
a_m = abs(a);
a_m, b_m = num2cell(sort([a_m, b_m])){:}
function tmp_2 = code(a_m, b_m)
	tmp = 0.0;
	if (a_m <= 3.2e-222)
		tmp = a_m * -(b_m * (a_m * b_m));
	else
		tmp = -b_m * (a_m * (a_m * b_m));
	end
	tmp_2 = tmp;
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_] := If[LessEqual[a$95$m, 3.2e-222], N[(a$95$m * (-N[(b$95$m * N[(a$95$m * b$95$m), $MachinePrecision]), $MachinePrecision])), $MachinePrecision], 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])\\
\\
\begin{array}{l}
\mathbf{if}\;a\_m \leq 3.2 \cdot 10^{-222}:\\
\;\;\;\;a\_m \cdot \left(-b\_m \cdot \left(a\_m \cdot b\_m\right)\right)\\

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


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

    1. Initial program 80.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 egg-rr99.6%

      \[\leadsto \color{blue}{\left(a \cdot \left(-b\right)\right) \cdot \left(a \cdot b\right)} \]
    5. Taylor expanded in a around 0

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{neg}\left(a \cdot \color{blue}{\left(b \cdot \left(a \cdot b\right)\right)}\right) \]
      11. lower-*.f6497.9

        \[\leadsto -a \cdot \left(b \cdot \color{blue}{\left(a \cdot b\right)}\right) \]
    7. Simplified97.9%

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

    if 3.1999999999999999e-222 < a

    1. Initial program 83.5%

      \[-\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.f6498.9

        \[\leadsto b \cdot \left(a \cdot \left(a \cdot \color{blue}{\left(-b\right)}\right)\right) \]
    5. Simplified98.9%

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

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

Alternative 4: 99.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(a\_m \cdot b\_m\right) \cdot \left(a\_m \cdot \left(-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 (* (* 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 * Float64(-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 \left(-b\_m\right)\right)
\end{array}
Derivation
  1. Initial program 81.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 egg-rr99.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: 93.5% 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])\\ \\ a\_m \cdot \left(-b\_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 (* 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(a_m * Float64(-Float64(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[(a$95$m * (-N[(b$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])\\
\\
a\_m \cdot \left(-b\_m \cdot \left(a\_m \cdot b\_m\right)\right)
\end{array}
Derivation
  1. Initial program 81.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 egg-rr99.6%

    \[\leadsto \color{blue}{\left(a \cdot \left(-b\right)\right) \cdot \left(a \cdot b\right)} \]
  5. Taylor expanded in a around 0

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{neg}\left(a \cdot \color{blue}{\left(b \cdot \left(a \cdot b\right)\right)}\right) \]
    11. lower-*.f6493.9

      \[\leadsto -a \cdot \left(b \cdot \color{blue}{\left(a \cdot b\right)}\right) \]
  7. Simplified93.9%

    \[\leadsto \color{blue}{-a \cdot \left(b \cdot \left(a \cdot b\right)\right)} \]
  8. Final simplification93.9%

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

Alternative 6: 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 81.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 egg-rr30.9%

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

    \[\leadsto b \cdot \left(b \cdot \left(a \cdot a\right)\right) \]
  6. 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 81.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 egg-rr30.8%

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

Alternative 8: 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])\\ \\ a\_m \cdot \left(b\_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 (* 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(a_m * Float64(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[(a$95$m * N[(b$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])\\
\\
a\_m \cdot \left(b\_m \cdot \left(a\_m \cdot b\_m\right)\right)
\end{array}
Derivation
  1. Initial program 81.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 egg-rr30.8%

    \[\leadsto \color{blue}{\left(a \cdot b\right) \cdot \left(a \cdot b\right)} \]
  5. Taylor expanded in a around 0

    \[\leadsto \color{blue}{{a}^{2} \cdot {b}^{2}} \]
  6. Step-by-step derivation
    1. unpow2N/A

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

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

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

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

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

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

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

      \[\leadsto a \cdot \color{blue}{\left(b \cdot \left(a \cdot b\right)\right)} \]
    9. lower-*.f6430.8

      \[\leadsto a \cdot \left(b \cdot \color{blue}{\left(a \cdot b\right)}\right) \]
  7. Simplified30.8%

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

Reproduce

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