ab-angle->ABCF D

Percentage Accurate: 82.2% → 99.7%
Time: 2.2min
Alternatives: 6
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 6 alternatives:

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

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

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

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

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

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

      \[\leadsto \frac{\mathsf{neg}\left(-1\right)}{\mathsf{neg}\left(\color{blue}{{\left(b \cdot a\right)}^{-2}}\right)} \]
    4. sqr-powN/A

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

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

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{neg}\left(-1\right)}{{\left(b \cdot a\right)}^{\left(\frac{-2}{2}\right)}}}{\mathsf{neg}\left({\left(b \cdot a\right)}^{\left(\frac{-2}{2}\right)}\right)}} \]
    7. metadata-evalN/A

      \[\leadsto \frac{\frac{\color{blue}{1}}{{\left(b \cdot a\right)}^{\left(\frac{-2}{2}\right)}}}{\mathsf{neg}\left({\left(b \cdot a\right)}^{\left(\frac{-2}{2}\right)}\right)} \]
    8. metadata-evalN/A

      \[\leadsto \frac{\frac{1}{{\left(b \cdot a\right)}^{\color{blue}{-1}}}}{\mathsf{neg}\left({\left(b \cdot a\right)}^{\left(\frac{-2}{2}\right)}\right)} \]
    9. unpow-1N/A

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{1}{b \cdot a}}}}{\mathsf{neg}\left({\left(b \cdot a\right)}^{\left(\frac{-2}{2}\right)}\right)} \]
    10. remove-double-divN/A

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

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

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

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

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

      \[\leadsto \frac{a \cdot b}{\mathsf{neg}\left({\left(b \cdot a\right)}^{\color{blue}{-1}}\right)} \]
    16. unpow-1N/A

      \[\leadsto \frac{a \cdot b}{\mathsf{neg}\left(\color{blue}{\frac{1}{b \cdot a}}\right)} \]
    17. metadata-evalN/A

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

      \[\leadsto \frac{a \cdot b}{\color{blue}{\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(-1\right)\right)\right)}{b \cdot a}}} \]
    19. metadata-evalN/A

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

      \[\leadsto \frac{a \cdot b}{\frac{\color{blue}{-1}}{b \cdot a}} \]
    21. lower-/.f6499.6

      \[\leadsto \frac{a \cdot b}{\color{blue}{\frac{-1}{b \cdot a}}} \]
    22. lift-*.f64N/A

      \[\leadsto \frac{a \cdot b}{\frac{-1}{\color{blue}{b \cdot a}}} \]
    23. *-commutativeN/A

      \[\leadsto \frac{a \cdot b}{\frac{-1}{\color{blue}{a \cdot b}}} \]
    24. lower-*.f6499.6

      \[\leadsto \frac{a \cdot b}{\frac{-1}{\color{blue}{a \cdot b}}} \]
  5. Applied rewrites99.6%

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

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

      \[\leadsto \frac{a \cdot b}{\frac{-1}{{\left(a \cdot b\right)}^{\color{blue}{\left(\mathsf{neg}\left(-1\right)\right)}}}} \]
    3. sqr-powN/A

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

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

      \[\leadsto \frac{a \cdot b}{\frac{-1}{{\left(a \cdot b\right)}^{\left(\frac{\color{blue}{1}}{2}\right)} \cdot {\left(a \cdot b\right)}^{\left(\frac{\mathsf{neg}\left(-1\right)}{2}\right)}}} \]
    6. metadata-evalN/A

      \[\leadsto \frac{a \cdot b}{\frac{-1}{{\left(a \cdot b\right)}^{\color{blue}{\frac{1}{2}}} \cdot {\left(a \cdot b\right)}^{\left(\frac{\mathsf{neg}\left(-1\right)}{2}\right)}}} \]
    7. unpow1/2N/A

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

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

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

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

      \[\leadsto \frac{a \cdot b}{\frac{-1}{\sqrt{\color{blue}{b \cdot a}} \cdot {\left(a \cdot b\right)}^{\left(\frac{\mathsf{neg}\left(-1\right)}{2}\right)}}} \]
    12. metadata-evalN/A

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

      \[\leadsto \frac{a \cdot b}{\frac{-1}{\sqrt{b \cdot a} \cdot {\left(a \cdot b\right)}^{\color{blue}{\frac{1}{2}}}}} \]
    14. unpow1/2N/A

      \[\leadsto \frac{a \cdot b}{\frac{-1}{\sqrt{b \cdot a} \cdot \color{blue}{\sqrt{a \cdot b}}}} \]
    15. lower-sqrt.f6454.1

      \[\leadsto \frac{a \cdot b}{\frac{-1}{\sqrt{b \cdot a} \cdot \color{blue}{\sqrt{a \cdot b}}}} \]
    16. lift-*.f64N/A

      \[\leadsto \frac{a \cdot b}{\frac{-1}{\sqrt{b \cdot a} \cdot \sqrt{\color{blue}{a \cdot b}}}} \]
    17. *-commutativeN/A

      \[\leadsto \frac{a \cdot b}{\frac{-1}{\sqrt{b \cdot a} \cdot \sqrt{\color{blue}{b \cdot a}}}} \]
    18. lower-*.f6454.1

      \[\leadsto \frac{a \cdot b}{\frac{-1}{\sqrt{b \cdot a} \cdot \sqrt{\color{blue}{b \cdot a}}}} \]
  7. Applied rewrites54.1%

    \[\leadsto \frac{a \cdot b}{\frac{-1}{\color{blue}{\sqrt{b \cdot a} \cdot \sqrt{b \cdot a}}}} \]
  8. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \frac{a \cdot b}{\color{blue}{\frac{-1}{\sqrt{b \cdot a} \cdot \sqrt{b \cdot a}}}} \]
    2. lift-*.f64N/A

      \[\leadsto \frac{a \cdot b}{\frac{-1}{\color{blue}{\sqrt{b \cdot a} \cdot \sqrt{b \cdot a}}}} \]
    3. lift-sqrt.f64N/A

      \[\leadsto \frac{a \cdot b}{\frac{-1}{\color{blue}{\sqrt{b \cdot a}} \cdot \sqrt{b \cdot a}}} \]
    4. lift-sqrt.f64N/A

      \[\leadsto \frac{a \cdot b}{\frac{-1}{\sqrt{b \cdot a} \cdot \color{blue}{\sqrt{b \cdot a}}}} \]
    5. rem-square-sqrtN/A

      \[\leadsto \frac{a \cdot b}{\frac{-1}{\color{blue}{b \cdot a}}} \]
    6. lift-*.f64N/A

      \[\leadsto \frac{a \cdot b}{\frac{-1}{\color{blue}{b \cdot a}}} \]
    7. associate-/l/N/A

      \[\leadsto \frac{a \cdot b}{\color{blue}{\frac{\frac{-1}{a}}{b}}} \]
    8. lower-/.f64N/A

      \[\leadsto \frac{a \cdot b}{\color{blue}{\frac{\frac{-1}{a}}{b}}} \]
    9. lower-/.f6499.7

      \[\leadsto \frac{a \cdot b}{\frac{\color{blue}{\frac{-1}{a}}}{b}} \]
  9. Applied rewrites99.7%

    \[\leadsto \frac{a \cdot b}{\color{blue}{\frac{\frac{-1}{a}}{b}}} \]
  10. Final simplification99.7%

    \[\leadsto \frac{b \cdot a}{\frac{\frac{-1}{a}}{b}} \]
  11. Add Preprocessing

Alternative 2: 92.0% accurate, 0.5× speedup?

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

    1. Initial program 85.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.00000000000000019e200 < (*.f64 (*.f64 (*.f64 a a) b) b)

    1. Initial program 81.6%

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

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

Alternative 3: 99.6% accurate, 0.5× speedup?

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

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

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

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

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

      \[\leadsto \frac{\mathsf{neg}\left(-1\right)}{\mathsf{neg}\left(\color{blue}{{\left(b \cdot a\right)}^{-2}}\right)} \]
    4. sqr-powN/A

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

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

      \[\leadsto \color{blue}{\frac{\frac{\mathsf{neg}\left(-1\right)}{{\left(b \cdot a\right)}^{\left(\frac{-2}{2}\right)}}}{\mathsf{neg}\left({\left(b \cdot a\right)}^{\left(\frac{-2}{2}\right)}\right)}} \]
    7. metadata-evalN/A

      \[\leadsto \frac{\frac{\color{blue}{1}}{{\left(b \cdot a\right)}^{\left(\frac{-2}{2}\right)}}}{\mathsf{neg}\left({\left(b \cdot a\right)}^{\left(\frac{-2}{2}\right)}\right)} \]
    8. metadata-evalN/A

      \[\leadsto \frac{\frac{1}{{\left(b \cdot a\right)}^{\color{blue}{-1}}}}{\mathsf{neg}\left({\left(b \cdot a\right)}^{\left(\frac{-2}{2}\right)}\right)} \]
    9. unpow-1N/A

      \[\leadsto \frac{\frac{1}{\color{blue}{\frac{1}{b \cdot a}}}}{\mathsf{neg}\left({\left(b \cdot a\right)}^{\left(\frac{-2}{2}\right)}\right)} \]
    10. remove-double-divN/A

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

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

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

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

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

      \[\leadsto \frac{a \cdot b}{\mathsf{neg}\left({\left(b \cdot a\right)}^{\color{blue}{-1}}\right)} \]
    16. unpow-1N/A

      \[\leadsto \frac{a \cdot b}{\mathsf{neg}\left(\color{blue}{\frac{1}{b \cdot a}}\right)} \]
    17. metadata-evalN/A

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

      \[\leadsto \frac{a \cdot b}{\color{blue}{\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(-1\right)\right)\right)}{b \cdot a}}} \]
    19. metadata-evalN/A

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

      \[\leadsto \frac{a \cdot b}{\frac{\color{blue}{-1}}{b \cdot a}} \]
    21. lower-/.f6499.6

      \[\leadsto \frac{a \cdot b}{\color{blue}{\frac{-1}{b \cdot a}}} \]
    22. lift-*.f64N/A

      \[\leadsto \frac{a \cdot b}{\frac{-1}{\color{blue}{b \cdot a}}} \]
    23. *-commutativeN/A

      \[\leadsto \frac{a \cdot b}{\frac{-1}{\color{blue}{a \cdot b}}} \]
    24. lower-*.f6499.6

      \[\leadsto \frac{a \cdot b}{\frac{-1}{\color{blue}{a \cdot b}}} \]
  5. Applied rewrites99.6%

    \[\leadsto \color{blue}{\frac{a \cdot b}{\frac{-1}{a \cdot b}}} \]
  6. Final simplification99.6%

    \[\leadsto \frac{b \cdot a}{\frac{-1}{b \cdot a}} \]
  7. Add Preprocessing

Alternative 4: 82.2% accurate, 1.0× speedup?

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

Alternative 5: 28.5% accurate, 1.1× speedup?

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

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

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

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

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

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

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

Alternative 6: 28.3% accurate, 1.1× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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