ab-angle->ABCF D

Percentage Accurate: 82.0% → 99.7%
Time: 6.8s
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: 82.0% 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.7× speedup?

\[\begin{array}{l} a_m = \left|a\right| \\ [a_m, b] = \mathsf{sort}([a_m, b])\\ \\ \left(a\_m \cdot b\right) \cdot \frac{1}{\frac{\frac{-1}{a\_m}}{b}} \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) (/ 1.0 (/ (/ -1.0 a_m) b))))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
	return (a_m * b) * (1.0 / ((-1.0 / 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) * (1.0d0 / (((-1.0d0) / 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) * (1.0 / ((-1.0 / a_m) / b));
}
a_m = math.fabs(a)
[a_m, b] = sort([a_m, b])
def code(a_m, b):
	return (a_m * b) * (1.0 / ((-1.0 / 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(1.0 / Float64(Float64(-1.0 / 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) * (1.0 / ((-1.0 / 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[(1.0 / N[(N[(-1.0 / a$95$m), $MachinePrecision] / b), $MachinePrecision]), $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 \frac{1}{\frac{\frac{-1}{a\_m}}{b}}
\end{array}
Derivation
  1. Initial program 84.2%

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

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

      \[\leadsto \color{blue}{-{a}^{2} \cdot {b}^{2}} \]
    2. unpow280.1%

      \[\leadsto -\color{blue}{\left(a \cdot a\right)} \cdot {b}^{2} \]
    3. unpow280.1%

      \[\leadsto -\left(a \cdot a\right) \cdot \color{blue}{\left(b \cdot b\right)} \]
    4. swap-sqr99.7%

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

      \[\leadsto -\color{blue}{{\left(a \cdot b\right)}^{2}} \]
  5. Simplified99.7%

    \[\leadsto \color{blue}{-{\left(a \cdot b\right)}^{2}} \]
  6. Step-by-step derivation
    1. unpow299.7%

      \[\leadsto -\color{blue}{\left(a \cdot b\right) \cdot \left(a \cdot b\right)} \]
    2. distribute-rgt-neg-in99.7%

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

    \[\leadsto \color{blue}{\left(a \cdot b\right) \cdot \left(-a \cdot b\right)} \]
  8. Step-by-step derivation
    1. add-sqr-sqrt54.4%

      \[\leadsto \color{blue}{\left(\sqrt{a \cdot b} \cdot \sqrt{a \cdot b}\right)} \cdot \left(-a \cdot b\right) \]
    2. sqrt-prod62.6%

      \[\leadsto \color{blue}{\sqrt{\left(a \cdot b\right) \cdot \left(a \cdot b\right)}} \cdot \left(-a \cdot b\right) \]
    3. unpow262.6%

      \[\leadsto \sqrt{\color{blue}{{\left(a \cdot b\right)}^{2}}} \cdot \left(-a \cdot b\right) \]
    4. add-sqr-sqrt62.6%

      \[\leadsto \sqrt{\color{blue}{\sqrt{{\left(a \cdot b\right)}^{2}} \cdot \sqrt{{\left(a \cdot b\right)}^{2}}}} \cdot \left(-a \cdot b\right) \]
    5. sqrt-prod56.5%

      \[\leadsto \sqrt{\color{blue}{\sqrt{{\left(a \cdot b\right)}^{2} \cdot {\left(a \cdot b\right)}^{2}}}} \cdot \left(-a \cdot b\right) \]
    6. sqr-neg56.5%

      \[\leadsto \sqrt{\sqrt{\color{blue}{\left(-{\left(a \cdot b\right)}^{2}\right) \cdot \left(-{\left(a \cdot b\right)}^{2}\right)}}} \cdot \left(-a \cdot b\right) \]
    7. sqrt-unprod25.0%

      \[\leadsto \sqrt{\color{blue}{\sqrt{-{\left(a \cdot b\right)}^{2}} \cdot \sqrt{-{\left(a \cdot b\right)}^{2}}}} \cdot \left(-a \cdot b\right) \]
    8. add-sqr-sqrt25.0%

      \[\leadsto \sqrt{\color{blue}{-{\left(a \cdot b\right)}^{2}}} \cdot \left(-a \cdot b\right) \]
    9. metadata-eval25.0%

      \[\leadsto \sqrt{-{\left(a \cdot b\right)}^{\color{blue}{\left(4 - 2\right)}}} \cdot \left(-a \cdot b\right) \]
    10. pow-div0.8%

      \[\leadsto \sqrt{-\color{blue}{\frac{{\left(a \cdot b\right)}^{4}}{{\left(a \cdot b\right)}^{2}}}} \cdot \left(-a \cdot b\right) \]
    11. distribute-frac-neg20.8%

      \[\leadsto \sqrt{\color{blue}{\frac{{\left(a \cdot b\right)}^{4}}{-{\left(a \cdot b\right)}^{2}}}} \cdot \left(-a \cdot b\right) \]
    12. clear-num0.8%

      \[\leadsto \sqrt{\color{blue}{\frac{1}{\frac{-{\left(a \cdot b\right)}^{2}}{{\left(a \cdot b\right)}^{4}}}}} \cdot \left(-a \cdot b\right) \]
    13. sqrt-div0.5%

      \[\leadsto \color{blue}{\frac{\sqrt{1}}{\sqrt{\frac{-{\left(a \cdot b\right)}^{2}}{{\left(a \cdot b\right)}^{4}}}}} \cdot \left(-a \cdot b\right) \]
    14. metadata-eval0.5%

      \[\leadsto \frac{\color{blue}{1}}{\sqrt{\frac{-{\left(a \cdot b\right)}^{2}}{{\left(a \cdot b\right)}^{4}}}} \cdot \left(-a \cdot b\right) \]
    15. clear-num0.5%

      \[\leadsto \frac{1}{\sqrt{\color{blue}{\frac{1}{\frac{{\left(a \cdot b\right)}^{4}}{-{\left(a \cdot b\right)}^{2}}}}}} \cdot \left(-a \cdot b\right) \]
    16. distribute-frac-neg20.5%

      \[\leadsto \frac{1}{\sqrt{\frac{1}{\color{blue}{-\frac{{\left(a \cdot b\right)}^{4}}{{\left(a \cdot b\right)}^{2}}}}}} \cdot \left(-a \cdot b\right) \]
    17. pow-div16.8%

      \[\leadsto \frac{1}{\sqrt{\frac{1}{-\color{blue}{{\left(a \cdot b\right)}^{\left(4 - 2\right)}}}}} \cdot \left(-a \cdot b\right) \]
    18. metadata-eval16.8%

      \[\leadsto \frac{1}{\sqrt{\frac{1}{-{\left(a \cdot b\right)}^{\color{blue}{2}}}}} \cdot \left(-a \cdot b\right) \]
  9. Applied egg-rr62.6%

    \[\leadsto \color{blue}{\frac{1}{\sqrt{\frac{1}{{\left(a \cdot b\right)}^{2}}}}} \cdot \left(-a \cdot b\right) \]
  10. Taylor expanded in a around 0 99.7%

    \[\leadsto \frac{1}{\color{blue}{\frac{1}{a \cdot b}}} \cdot \left(-a \cdot b\right) \]
  11. Step-by-step derivation
    1. associate-/r*99.7%

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

    \[\leadsto \frac{1}{\color{blue}{\frac{\frac{1}{a}}{b}}} \cdot \left(-a \cdot b\right) \]
  13. Final simplification99.7%

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

Alternative 2: 92.1% accurate, 0.4× speedup?

\[\begin{array}{l} a_m = \left|a\right| \\ [a_m, b] = \mathsf{sort}([a_m, b])\\ \\ \begin{array}{l} \mathbf{if}\;b \cdot \left(b \cdot \left(a\_m \cdot a\_m\right)\right) \leq 5 \cdot 10^{-251}:\\ \;\;\;\;a\_m \cdot \left(b \cdot \left(a\_m \cdot \left(-b\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(\left(a\_m \cdot a\_m\right) \cdot \left(-b\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 (<= (* b (* b (* a_m a_m))) 5e-251)
   (* a_m (* b (* a_m (- b))))
   (* b (* (* a_m a_m) (- b)))))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
	double tmp;
	if ((b * (b * (a_m * a_m))) <= 5e-251) {
		tmp = a_m * (b * (a_m * -b));
	} else {
		tmp = b * ((a_m * a_m) * -b);
	}
	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 ((b * (b * (a_m * a_m))) <= 5d-251) then
        tmp = a_m * (b * (a_m * -b))
    else
        tmp = b * ((a_m * a_m) * -b)
    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 ((b * (b * (a_m * a_m))) <= 5e-251) {
		tmp = a_m * (b * (a_m * -b));
	} else {
		tmp = b * ((a_m * a_m) * -b);
	}
	return tmp;
}
a_m = math.fabs(a)
[a_m, b] = sort([a_m, b])
def code(a_m, b):
	tmp = 0
	if (b * (b * (a_m * a_m))) <= 5e-251:
		tmp = a_m * (b * (a_m * -b))
	else:
		tmp = b * ((a_m * a_m) * -b)
	return tmp
a_m = abs(a)
a_m, b = sort([a_m, b])
function code(a_m, b)
	tmp = 0.0
	if (Float64(b * Float64(b * Float64(a_m * a_m))) <= 5e-251)
		tmp = Float64(a_m * Float64(b * Float64(a_m * Float64(-b))));
	else
		tmp = Float64(b * Float64(Float64(a_m * a_m) * Float64(-b)));
	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 ((b * (b * (a_m * a_m))) <= 5e-251)
		tmp = a_m * (b * (a_m * -b));
	else
		tmp = b * ((a_m * a_m) * -b);
	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[N[(b * N[(b * N[(a$95$m * a$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-251], N[(a$95$m * N[(b * N[(a$95$m * (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b * N[(N[(a$95$m * a$95$m), $MachinePrecision] * (-b)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
\begin{array}{l}
\mathbf{if}\;b \cdot \left(b \cdot \left(a\_m \cdot a\_m\right)\right) \leq 5 \cdot 10^{-251}:\\
\;\;\;\;a\_m \cdot \left(b \cdot \left(a\_m \cdot \left(-b\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (*.f64 (*.f64 a a) b) b) < 5.0000000000000003e-251

    1. Initial program 79.9%

      \[-\left(\left(a \cdot a\right) \cdot b\right) \cdot b \]
    2. Step-by-step derivation
      1. associate-*l*79.1%

        \[\leadsto -\color{blue}{\left(a \cdot a\right) \cdot \left(b \cdot b\right)} \]
      2. associate-*r*82.9%

        \[\leadsto -\color{blue}{a \cdot \left(a \cdot \left(b \cdot b\right)\right)} \]
      3. *-commutative82.9%

        \[\leadsto -a \cdot \color{blue}{\left(\left(b \cdot b\right) \cdot a\right)} \]
      4. distribute-rgt-neg-in82.9%

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

        \[\leadsto a \cdot \color{blue}{\left(\left(b \cdot b\right) \cdot \left(-a\right)\right)} \]
      6. associate-*r*97.7%

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

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

    if 5.0000000000000003e-251 < (*.f64 (*.f64 (*.f64 a a) b) b)

    1. Initial program 86.3%

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

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

Alternative 3: 99.6% accurate, 0.7× speedup?

\[\begin{array}{l} a_m = \left|a\right| \\ [a_m, b] = \mathsf{sort}([a_m, b])\\ \\ \left(a\_m \cdot b\right) \cdot \frac{-1}{\frac{1}{a\_m \cdot b}} \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) (/ -1.0 (/ 1.0 (* a_m b)))))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
	return (a_m * b) * (-1.0 / (1.0 / (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) * ((-1.0d0) / (1.0d0 / (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) * (-1.0 / (1.0 / (a_m * b)));
}
a_m = math.fabs(a)
[a_m, b] = sort([a_m, b])
def code(a_m, b):
	return (a_m * b) * (-1.0 / (1.0 / (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(-1.0 / Float64(1.0 / 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) * (-1.0 / (1.0 / (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[(-1.0 / N[(1.0 / N[(a$95$m * b), $MachinePrecision]), $MachinePrecision]), $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 \frac{-1}{\frac{1}{a\_m \cdot b}}
\end{array}
Derivation
  1. Initial program 84.2%

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

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

      \[\leadsto \color{blue}{-{a}^{2} \cdot {b}^{2}} \]
    2. unpow280.1%

      \[\leadsto -\color{blue}{\left(a \cdot a\right)} \cdot {b}^{2} \]
    3. unpow280.1%

      \[\leadsto -\left(a \cdot a\right) \cdot \color{blue}{\left(b \cdot b\right)} \]
    4. swap-sqr99.7%

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

      \[\leadsto -\color{blue}{{\left(a \cdot b\right)}^{2}} \]
  5. Simplified99.7%

    \[\leadsto \color{blue}{-{\left(a \cdot b\right)}^{2}} \]
  6. Step-by-step derivation
    1. unpow299.7%

      \[\leadsto -\color{blue}{\left(a \cdot b\right) \cdot \left(a \cdot b\right)} \]
    2. distribute-rgt-neg-in99.7%

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

    \[\leadsto \color{blue}{\left(a \cdot b\right) \cdot \left(-a \cdot b\right)} \]
  8. Step-by-step derivation
    1. add-cbrt-cube90.0%

      \[\leadsto \left(a \cdot b\right) \cdot \left(-\color{blue}{\sqrt[3]{\left(\left(a \cdot b\right) \cdot \left(a \cdot b\right)\right) \cdot \left(a \cdot b\right)}}\right) \]
    2. pow390.0%

      \[\leadsto \left(a \cdot b\right) \cdot \left(-\sqrt[3]{\color{blue}{{\left(a \cdot b\right)}^{3}}}\right) \]
  9. Applied egg-rr90.0%

    \[\leadsto \left(a \cdot b\right) \cdot \left(-\color{blue}{\sqrt[3]{{\left(a \cdot b\right)}^{3}}}\right) \]
  10. Step-by-step derivation
    1. rem-cbrt-cube99.7%

      \[\leadsto \left(a \cdot b\right) \cdot \left(-\color{blue}{a \cdot b}\right) \]
    2. add-sqr-sqrt56.0%

      \[\leadsto \left(a \cdot b\right) \cdot \color{blue}{\left(\sqrt{-a \cdot b} \cdot \sqrt{-a \cdot b}\right)} \]
    3. sqrt-unprod63.2%

      \[\leadsto \left(a \cdot b\right) \cdot \color{blue}{\sqrt{\left(-a \cdot b\right) \cdot \left(-a \cdot b\right)}} \]
    4. sqr-neg63.2%

      \[\leadsto \left(a \cdot b\right) \cdot \sqrt{\color{blue}{\left(a \cdot b\right) \cdot \left(a \cdot b\right)}} \]
    5. unpow263.2%

      \[\leadsto \left(a \cdot b\right) \cdot \sqrt{\color{blue}{{\left(a \cdot b\right)}^{2}}} \]
    6. /-rgt-identity63.2%

      \[\leadsto \left(a \cdot b\right) \cdot \sqrt{\color{blue}{\frac{{\left(a \cdot b\right)}^{2}}{1}}} \]
    7. clear-num63.1%

      \[\leadsto \left(a \cdot b\right) \cdot \sqrt{\color{blue}{\frac{1}{\frac{1}{{\left(a \cdot b\right)}^{2}}}}} \]
    8. metadata-eval63.1%

      \[\leadsto \left(a \cdot b\right) \cdot \sqrt{\frac{\color{blue}{1 \cdot 1}}{\frac{1}{{\left(a \cdot b\right)}^{2}}}} \]
    9. add-sqr-sqrt63.1%

      \[\leadsto \left(a \cdot b\right) \cdot \sqrt{\frac{1 \cdot 1}{\color{blue}{\sqrt{\frac{1}{{\left(a \cdot b\right)}^{2}}} \cdot \sqrt{\frac{1}{{\left(a \cdot b\right)}^{2}}}}}} \]
    10. frac-times63.1%

      \[\leadsto \left(a \cdot b\right) \cdot \sqrt{\color{blue}{\frac{1}{\sqrt{\frac{1}{{\left(a \cdot b\right)}^{2}}}} \cdot \frac{1}{\sqrt{\frac{1}{{\left(a \cdot b\right)}^{2}}}}}} \]
    11. sqrt-unprod63.1%

      \[\leadsto \left(a \cdot b\right) \cdot \color{blue}{\left(\sqrt{\frac{1}{\sqrt{\frac{1}{{\left(a \cdot b\right)}^{2}}}}} \cdot \sqrt{\frac{1}{\sqrt{\frac{1}{{\left(a \cdot b\right)}^{2}}}}}\right)} \]
    12. add-sqr-sqrt63.1%

      \[\leadsto \left(a \cdot b\right) \cdot \color{blue}{\frac{1}{\sqrt{\frac{1}{{\left(a \cdot b\right)}^{2}}}}} \]
    13. frac-2neg63.1%

      \[\leadsto \left(a \cdot b\right) \cdot \color{blue}{\frac{-1}{-\sqrt{\frac{1}{{\left(a \cdot b\right)}^{2}}}}} \]
    14. metadata-eval63.1%

      \[\leadsto \left(a \cdot b\right) \cdot \frac{\color{blue}{-1}}{-\sqrt{\frac{1}{{\left(a \cdot b\right)}^{2}}}} \]
    15. sqrt-div63.2%

      \[\leadsto \left(a \cdot b\right) \cdot \frac{-1}{-\color{blue}{\frac{\sqrt{1}}{\sqrt{{\left(a \cdot b\right)}^{2}}}}} \]
    16. metadata-eval63.2%

      \[\leadsto \left(a \cdot b\right) \cdot \frac{-1}{-\frac{\color{blue}{1}}{\sqrt{{\left(a \cdot b\right)}^{2}}}} \]
    17. sqrt-pow126.1%

      \[\leadsto \left(a \cdot b\right) \cdot \frac{-1}{-\frac{1}{\color{blue}{{\left(a \cdot b\right)}^{\left(\frac{2}{2}\right)}}}} \]
    18. metadata-eval26.1%

      \[\leadsto \left(a \cdot b\right) \cdot \frac{-1}{-\frac{1}{{\left(a \cdot b\right)}^{\color{blue}{1}}}} \]
    19. pow126.1%

      \[\leadsto \left(a \cdot b\right) \cdot \frac{-1}{-\frac{1}{\color{blue}{a \cdot b}}} \]
    20. distribute-neg-frac226.1%

      \[\leadsto \left(a \cdot b\right) \cdot \frac{-1}{\color{blue}{\frac{1}{-a \cdot b}}} \]
    21. add-sqr-sqrt19.0%

      \[\leadsto \left(a \cdot b\right) \cdot \frac{-1}{\frac{1}{\color{blue}{\sqrt{-a \cdot b} \cdot \sqrt{-a \cdot b}}}} \]
  11. Applied egg-rr99.7%

    \[\leadsto \left(a \cdot b\right) \cdot \color{blue}{\frac{-1}{\frac{1}{a \cdot b}}} \]
  12. 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 84.2%

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

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

      \[\leadsto \color{blue}{-{a}^{2} \cdot {b}^{2}} \]
    2. unpow280.1%

      \[\leadsto -\color{blue}{\left(a \cdot a\right)} \cdot {b}^{2} \]
    3. unpow280.1%

      \[\leadsto -\left(a \cdot a\right) \cdot \color{blue}{\left(b \cdot b\right)} \]
    4. swap-sqr99.7%

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

      \[\leadsto -\color{blue}{{\left(a \cdot b\right)}^{2}} \]
  5. Simplified99.7%

    \[\leadsto \color{blue}{-{\left(a \cdot b\right)}^{2}} \]
  6. Step-by-step derivation
    1. unpow299.7%

      \[\leadsto -\color{blue}{\left(a \cdot b\right) \cdot \left(a \cdot b\right)} \]
    2. distribute-rgt-neg-in99.7%

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

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

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

Alternative 5: 82.0% accurate, 1.0× speedup?

\[\begin{array}{l} a_m = \left|a\right| \\ [a_m, b] = \mathsf{sort}([a_m, b])\\ \\ b \cdot \left(\left(a\_m \cdot a\_m\right) \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 (* b (* (* a_m a_m) (- b))))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
	return b * ((a_m * 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 = b * ((a_m * a_m) * -b)
end function
a_m = Math.abs(a);
assert a_m < b;
public static double code(double a_m, double b) {
	return b * ((a_m * a_m) * -b);
}
a_m = math.fabs(a)
[a_m, b] = sort([a_m, b])
def code(a_m, b):
	return b * ((a_m * a_m) * -b)
a_m = abs(a)
a_m, b = sort([a_m, b])
function code(a_m, b)
	return Float64(b * Float64(Float64(a_m * a_m) * Float64(-b)))
end
a_m = abs(a);
a_m, b = num2cell(sort([a_m, b])){:}
function tmp = code(a_m, b)
	tmp = b * ((a_m * 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[(b * N[(N[(a$95$m * a$95$m), $MachinePrecision] * (-b)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
b \cdot \left(\left(a\_m \cdot a\_m\right) \cdot \left(-b\right)\right)
\end{array}
Derivation
  1. Initial program 84.2%

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

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

Alternative 6: 28.3% accurate, 1.1× speedup?

\[\begin{array}{l} a_m = \left|a\right| \\ [a_m, b] = \mathsf{sort}([a_m, b])\\ \\ b \cdot \left(a\_m \cdot \left(a\_m \cdot 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 (* b (* a_m (* a_m b))))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
	return b * (a_m * (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 = b * (a_m * (a_m * b))
end function
a_m = Math.abs(a);
assert a_m < b;
public static double code(double a_m, double b) {
	return b * (a_m * (a_m * b));
}
a_m = math.fabs(a)
[a_m, b] = sort([a_m, b])
def code(a_m, b):
	return b * (a_m * (a_m * b))
a_m = abs(a)
a_m, b = sort([a_m, b])
function code(a_m, b)
	return Float64(b * Float64(a_m * Float64(a_m * b)))
end
a_m = abs(a);
a_m, b = num2cell(sort([a_m, b])){:}
function tmp = code(a_m, b)
	tmp = b * (a_m * (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[(b * N[(a$95$m * N[(a$95$m * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
b \cdot \left(a\_m \cdot \left(a\_m \cdot b\right)\right)
\end{array}
Derivation
  1. Initial program 84.2%

    \[-\left(\left(a \cdot a\right) \cdot b\right) \cdot b \]
  2. Step-by-step derivation
    1. distribute-rgt-neg-in84.2%

      \[\leadsto \color{blue}{\left(\left(a \cdot a\right) \cdot b\right) \cdot \left(-b\right)} \]
    2. associate-*l*92.9%

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

    \[\leadsto \color{blue}{\left(a \cdot \left(a \cdot b\right)\right) \cdot \left(-b\right)} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. neg-sub092.9%

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

      \[\leadsto \left(a \cdot \left(a \cdot b\right)\right) \cdot \color{blue}{\left(0 + \left(-b\right)\right)} \]
    3. add-sqr-sqrt44.3%

      \[\leadsto \left(a \cdot \left(a \cdot b\right)\right) \cdot \left(0 + \color{blue}{\sqrt{-b} \cdot \sqrt{-b}}\right) \]
    4. sqrt-unprod54.2%

      \[\leadsto \left(a \cdot \left(a \cdot b\right)\right) \cdot \left(0 + \color{blue}{\sqrt{\left(-b\right) \cdot \left(-b\right)}}\right) \]
    5. sqr-neg54.2%

      \[\leadsto \left(a \cdot \left(a \cdot b\right)\right) \cdot \left(0 + \sqrt{\color{blue}{b \cdot b}}\right) \]
    6. sqrt-unprod14.9%

      \[\leadsto \left(a \cdot \left(a \cdot b\right)\right) \cdot \left(0 + \color{blue}{\sqrt{b} \cdot \sqrt{b}}\right) \]
    7. add-sqr-sqrt26.2%

      \[\leadsto \left(a \cdot \left(a \cdot b\right)\right) \cdot \left(0 + \color{blue}{b}\right) \]
  6. Applied egg-rr26.2%

    \[\leadsto \left(a \cdot \left(a \cdot b\right)\right) \cdot \color{blue}{\left(0 + b\right)} \]
  7. Step-by-step derivation
    1. +-lft-identity26.2%

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

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

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

Alternative 7: 28.2% 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 84.2%

    \[-\left(\left(a \cdot a\right) \cdot b\right) \cdot b \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. add-sqr-sqrt25.3%

      \[\leadsto \color{blue}{\sqrt{-\left(\left(a \cdot a\right) \cdot b\right) \cdot b} \cdot \sqrt{-\left(\left(a \cdot a\right) \cdot b\right) \cdot b}} \]
    2. sqrt-unprod26.2%

      \[\leadsto \color{blue}{\sqrt{\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)}} \]
    3. sqr-neg26.2%

      \[\leadsto \sqrt{\color{blue}{\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)}} \]
    4. sqrt-unprod26.2%

      \[\leadsto \color{blue}{\sqrt{\left(\left(a \cdot a\right) \cdot b\right) \cdot b} \cdot \sqrt{\left(\left(a \cdot a\right) \cdot b\right) \cdot b}} \]
    5. add-sqr-sqrt26.2%

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

      \[\leadsto \color{blue}{\left(a \cdot a\right) \cdot \left(b \cdot b\right)} \]
    7. swap-sqr26.1%

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

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

Alternative 8: 28.2% accurate, 1.1× speedup?

\[\begin{array}{l} a_m = \left|a\right| \\ [a_m, b] = \mathsf{sort}([a_m, b])\\ \\ a\_m \cdot \left(b \cdot \left(a\_m \cdot 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(a_m * Float64(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[(a$95$m * N[(b * N[(a$95$m * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
a\_m \cdot \left(b \cdot \left(a\_m \cdot b\right)\right)
\end{array}
Derivation
  1. Initial program 84.2%

    \[-\left(\left(a \cdot a\right) \cdot b\right) \cdot b \]
  2. Step-by-step derivation
    1. associate-*l*80.1%

      \[\leadsto -\color{blue}{\left(a \cdot a\right) \cdot \left(b \cdot b\right)} \]
    2. associate-*r*84.8%

      \[\leadsto -\color{blue}{a \cdot \left(a \cdot \left(b \cdot b\right)\right)} \]
    3. *-commutative84.8%

      \[\leadsto -a \cdot \color{blue}{\left(\left(b \cdot b\right) \cdot a\right)} \]
    4. distribute-rgt-neg-in84.8%

      \[\leadsto \color{blue}{a \cdot \left(-\left(b \cdot b\right) \cdot a\right)} \]
    5. distribute-rgt-neg-in84.8%

      \[\leadsto a \cdot \color{blue}{\left(\left(b \cdot b\right) \cdot \left(-a\right)\right)} \]
    6. associate-*r*96.2%

      \[\leadsto a \cdot \color{blue}{\left(b \cdot \left(b \cdot \left(-a\right)\right)\right)} \]
  3. Simplified96.2%

    \[\leadsto \color{blue}{a \cdot \left(b \cdot \left(b \cdot \left(-a\right)\right)\right)} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. neg-sub096.2%

      \[\leadsto a \cdot \left(b \cdot \left(b \cdot \color{blue}{\left(0 - a\right)}\right)\right) \]
    2. sub-neg96.2%

      \[\leadsto a \cdot \left(b \cdot \left(b \cdot \color{blue}{\left(0 + \left(-a\right)\right)}\right)\right) \]
    3. add-sqr-sqrt47.6%

      \[\leadsto a \cdot \left(b \cdot \left(b \cdot \left(0 + \color{blue}{\sqrt{-a} \cdot \sqrt{-a}}\right)\right)\right) \]
    4. sqrt-unprod55.3%

      \[\leadsto a \cdot \left(b \cdot \left(b \cdot \left(0 + \color{blue}{\sqrt{\left(-a\right) \cdot \left(-a\right)}}\right)\right)\right) \]
    5. sqr-neg55.3%

      \[\leadsto a \cdot \left(b \cdot \left(b \cdot \left(0 + \sqrt{\color{blue}{a \cdot a}}\right)\right)\right) \]
    6. sqrt-prod14.8%

      \[\leadsto a \cdot \left(b \cdot \left(b \cdot \left(0 + \color{blue}{\sqrt{a} \cdot \sqrt{a}}\right)\right)\right) \]
    7. add-sqr-sqrt26.1%

      \[\leadsto a \cdot \left(b \cdot \left(b \cdot \left(0 + \color{blue}{a}\right)\right)\right) \]
  6. Applied egg-rr26.1%

    \[\leadsto a \cdot \left(b \cdot \left(b \cdot \color{blue}{\left(0 + a\right)}\right)\right) \]
  7. Step-by-step derivation
    1. +-lft-identity26.1%

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

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

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

Reproduce

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