ab-angle->ABCF D

Percentage Accurate: 82.3% → 99.7%
Time: 7.5s
Alternatives: 7
Speedup: 0.9×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 7 alternatives:

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

Initial Program: 82.3% 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.9× speedup?

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

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

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

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

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

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(a \cdot \left(b \cdot b\right)\right), a\right)\right) \]
    5. associate-*r*N/A

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(\left(a \cdot b\right) \cdot b\right), a\right)\right) \]
    6. *-commutativeN/A

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot \left(a \cdot b\right)\right), a\right)\right) \]
    7. *-lowering-*.f64N/A

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(b, \left(a \cdot b\right)\right), a\right)\right) \]
    8. *-lowering-*.f6494.6%

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(b, \mathsf{*.f64}\left(a, b\right)\right), a\right)\right) \]
  4. Applied egg-rr94.6%

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

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(\left(\left(\mathsf{neg}\left(a\right)\right) \cdot b\right), \left(\color{blue}{a} \cdot b\right)\right) \]
    7. /-rgt-identityN/A

      \[\leadsto \mathsf{*.f64}\left(\left(\left(\mathsf{neg}\left(a\right)\right) \cdot \frac{b}{1}\right), \left(a \cdot b\right)\right) \]
    8. clear-numN/A

      \[\leadsto \mathsf{*.f64}\left(\left(\left(\mathsf{neg}\left(a\right)\right) \cdot \frac{1}{\frac{1}{b}}\right), \left(a \cdot b\right)\right) \]
    9. div-invN/A

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

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(a\right)\right)\right)}{\mathsf{neg}\left(\frac{1}{b}\right)}\right), \left(\color{blue}{a} \cdot b\right)\right) \]
    11. remove-double-negN/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{a}{\mathsf{neg}\left(\frac{1}{b}\right)}\right), \left(a \cdot b\right)\right) \]
    12. /-lowering-/.f64N/A

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(a, \left(\frac{\mathsf{neg}\left(1\right)}{b}\right)\right), \left(a \cdot b\right)\right) \]
    14. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(a, \left(\frac{-1}{b}\right)\right), \left(a \cdot b\right)\right) \]
    15. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(a, \mathsf{/.f64}\left(-1, b\right)\right), \left(a \cdot b\right)\right) \]
    16. *-lowering-*.f6499.7%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(a, \mathsf{/.f64}\left(-1, b\right)\right), \mathsf{*.f64}\left(a, \color{blue}{b}\right)\right) \]
  6. Applied egg-rr99.7%

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

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

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

Alternative 2: 99.7% accurate, 0.9× speedup?

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

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

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

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

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

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(a \cdot \left(b \cdot b\right)\right), a\right)\right) \]
    5. associate-*r*N/A

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(\left(a \cdot b\right) \cdot b\right), a\right)\right) \]
    6. *-commutativeN/A

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot \left(a \cdot b\right)\right), a\right)\right) \]
    7. *-lowering-*.f64N/A

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(b, \left(a \cdot b\right)\right), a\right)\right) \]
    8. *-lowering-*.f6494.6%

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(b, \mathsf{*.f64}\left(a, b\right)\right), a\right)\right) \]
  4. Applied egg-rr94.6%

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

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(\left(\left(\mathsf{neg}\left(a\right)\right) \cdot b\right), \left(\color{blue}{a} \cdot b\right)\right) \]
    7. /-rgt-identityN/A

      \[\leadsto \mathsf{*.f64}\left(\left(\left(\mathsf{neg}\left(a\right)\right) \cdot \frac{b}{1}\right), \left(a \cdot b\right)\right) \]
    8. clear-numN/A

      \[\leadsto \mathsf{*.f64}\left(\left(\left(\mathsf{neg}\left(a\right)\right) \cdot \frac{1}{\frac{1}{b}}\right), \left(a \cdot b\right)\right) \]
    9. div-invN/A

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

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{\mathsf{neg}\left(\left(\mathsf{neg}\left(a\right)\right)\right)}{\mathsf{neg}\left(\frac{1}{b}\right)}\right), \left(\color{blue}{a} \cdot b\right)\right) \]
    11. remove-double-negN/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{a}{\mathsf{neg}\left(\frac{1}{b}\right)}\right), \left(a \cdot b\right)\right) \]
    12. /-lowering-/.f64N/A

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(a, \left(\frac{\mathsf{neg}\left(1\right)}{b}\right)\right), \left(a \cdot b\right)\right) \]
    14. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(a, \left(\frac{-1}{b}\right)\right), \left(a \cdot b\right)\right) \]
    15. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(a, \mathsf{/.f64}\left(-1, b\right)\right), \left(a \cdot b\right)\right) \]
    16. *-lowering-*.f6499.7%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(a, \mathsf{/.f64}\left(-1, b\right)\right), \mathsf{*.f64}\left(a, \color{blue}{b}\right)\right) \]
  6. Applied egg-rr99.7%

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

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

Alternative 3: 99.6% accurate, 0.9× speedup?

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

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

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

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

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(a \cdot b\right), \left(a \cdot b\right)\right)\right) \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a, b\right), \left(a \cdot b\right)\right)\right) \]
    5. *-lowering-*.f6499.7%

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a, b\right), \mathsf{*.f64}\left(a, b\right)\right)\right) \]
  4. Applied egg-rr99.7%

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

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

Alternative 4: 81.4% accurate, 0.9× speedup?

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

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

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

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

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

      \[\leadsto \mathsf{neg.f64}\left(\left(a \cdot \left({b}^{2} \cdot a\right)\right)\right) \]
    4. *-lowering-*.f64N/A

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

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

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(a, \mathsf{*.f64}\left(a, \left({b}^{2}\right)\right)\right)\right) \]
    7. unpow2N/A

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(a, \mathsf{*.f64}\left(a, \left(b \cdot b\right)\right)\right)\right) \]
    8. *-lowering-*.f6479.2%

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(a, \mathsf{*.f64}\left(a, \mathsf{*.f64}\left(b, b\right)\right)\right)\right) \]
  5. Simplified79.2%

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

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

Alternative 5: 28.9% accurate, 1.1× speedup?

\[\begin{array}{l} a_m = \left|a\right| \\ b_m = \left|b\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} \]
a_m = (fabs.f64 a)
b_m = (fabs.f64 b)
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))))
a_m = fabs(a);
b_m = fabs(b);
assert(a_m < b_m);
double code(double a_m, double b_m) {
	return b_m * (b_m * (a_m * a_m));
}
a_m = abs(a)
b_m = abs(b)
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
a_m = Math.abs(a);
b_m = Math.abs(b);
assert a_m < b_m;
public static double code(double a_m, double b_m) {
	return b_m * (b_m * (a_m * a_m));
}
a_m = math.fabs(a)
b_m = math.fabs(b)
[a_m, b_m] = sort([a_m, b_m])
def code(a_m, b_m):
	return b_m * (b_m * (a_m * a_m))
a_m = abs(a)
b_m = abs(b)
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
a_m = abs(a);
b_m = abs(b);
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
a_m = N[Abs[a], $MachinePrecision]
b_m = N[Abs[b], $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}
a_m = \left|a\right|
\\
b_m = \left|b\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.6%

    \[-\left(\left(a \cdot a\right) \cdot b\right) \cdot b \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. +-lft-identityN/A

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

      \[\leadsto \mathsf{neg}\left(\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) \]
    3. distribute-neg-fracN/A

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

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

      \[\leadsto \mathsf{*.f64}\left(\left(\left(a \cdot a\right) \cdot b\right), b\right) \]
    2. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(a \cdot a\right), b\right), b\right) \]
    3. *-lowering-*.f6426.1%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a, a\right), b\right), b\right) \]
  6. Applied egg-rr26.1%

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

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

Alternative 6: 28.7% accurate, 1.1× speedup?

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

    \[-\left(\left(a \cdot a\right) \cdot b\right) \cdot b \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. +-lft-identityN/A

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

      \[\leadsto \mathsf{neg}\left(\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) \]
    3. distribute-neg-fracN/A

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

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

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

Alternative 7: 28.7% accurate, 1.1× speedup?

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

    \[-\left(\left(a \cdot a\right) \cdot b\right) \cdot b \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. +-lft-identityN/A

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

      \[\leadsto \mathsf{neg}\left(\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) \]
    3. distribute-neg-fracN/A

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

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

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

Reproduce

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