ab-angle->ABCF D

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

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

\\
\left(a \cdot b\right) \cdot \left(0 - a \cdot b\right)
\end{array}
Derivation
  1. Initial program 82.4%

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

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

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

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

Alternative 2: 31.7% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq 2 \cdot 10^{+110}:\\ \;\;\;\;\left(b \cdot b\right) \cdot \left(a \cdot a\right)\\ \mathbf{else}:\\ \;\;\;\;0 - a \cdot b\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= b 2e+110) (* (* b b) (* a a)) (- 0.0 (* a b))))
double code(double a, double b) {
	double tmp;
	if (b <= 2e+110) {
		tmp = (b * b) * (a * a);
	} else {
		tmp = 0.0 - (a * b);
	}
	return tmp;
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if (b <= 2d+110) then
        tmp = (b * b) * (a * a)
    else
        tmp = 0.0d0 - (a * b)
    end if
    code = tmp
end function
public static double code(double a, double b) {
	double tmp;
	if (b <= 2e+110) {
		tmp = (b * b) * (a * a);
	} else {
		tmp = 0.0 - (a * b);
	}
	return tmp;
}
def code(a, b):
	tmp = 0
	if b <= 2e+110:
		tmp = (b * b) * (a * a)
	else:
		tmp = 0.0 - (a * b)
	return tmp
function code(a, b)
	tmp = 0.0
	if (b <= 2e+110)
		tmp = Float64(Float64(b * b) * Float64(a * a));
	else
		tmp = Float64(0.0 - Float64(a * b));
	end
	return tmp
end
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (b <= 2e+110)
		tmp = (b * b) * (a * a);
	else
		tmp = 0.0 - (a * b);
	end
	tmp_2 = tmp;
end
code[a_, b_] := If[LessEqual[b, 2e+110], N[(N[(b * b), $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision], N[(0.0 - N[(a * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq 2 \cdot 10^{+110}:\\
\;\;\;\;\left(b \cdot b\right) \cdot \left(a \cdot a\right)\\

\mathbf{else}:\\
\;\;\;\;0 - a \cdot b\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < 2e110

    1. Initial program 82.9%

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

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

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

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

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

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

    if 2e110 < b

    1. Initial program 79.9%

      \[-\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-*r*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. *-lowering-*.f64N/A

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

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

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

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

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

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

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

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot \left(a \cdot b\right)\right), a\right)\right) \]
      2. rem-exp-logN/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot e^{\log \left(a \cdot b\right)}\right), a\right)\right) \]
      3. *-rgt-identityN/A

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

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot e^{\log \left(a \cdot b\right) \cdot \left(\frac{1}{2} + \frac{1}{2}\right)}\right), a\right)\right) \]
      5. distribute-lft-outN/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot e^{\log \left(a \cdot b\right) \cdot \frac{1}{2} + \log \left(a \cdot b\right) \cdot \frac{1}{2}}\right), a\right)\right) \]
      6. count-2N/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot e^{2 \cdot \left(\log \left(a \cdot b\right) \cdot \frac{1}{2}\right)}\right), a\right)\right) \]
      7. exp-prodN/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\left(\log \left(a \cdot b\right) \cdot \frac{1}{2}\right)}\right), a\right)\right) \]
      8. rem-log-expN/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\log \left(e^{\log \left(a \cdot b\right) \cdot \frac{1}{2}}\right)}\right), a\right)\right) \]
      9. pow-to-expN/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\log \left({\left(a \cdot b\right)}^{\frac{1}{2}}\right)}\right), a\right)\right) \]
      10. sqr-powN/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)} \cdot {\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right)}\right), a\right)\right) \]
      11. log-prodN/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\left(\log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) + \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right)\right)}\right), a\right)\right) \]
      12. flip-+N/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\left(\frac{\log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) \cdot \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) - \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) \cdot \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right)}{\log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) - \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right)}\right)}\right), a\right)\right) \]
    8. Applied egg-rr23.0%

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

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

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(b, a\right)\right) \]
    10. Applied egg-rr23.0%

      \[\leadsto -\color{blue}{b \cdot a} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification28.0%

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

Alternative 3: 31.8% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq 3.25 \cdot 10^{+109}:\\ \;\;\;\;b \cdot \left(a \cdot \left(a \cdot b\right)\right)\\ \mathbf{else}:\\ \;\;\;\;0 - a \cdot b\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= b 3.25e+109) (* b (* a (* a b))) (- 0.0 (* a b))))
double code(double a, double b) {
	double tmp;
	if (b <= 3.25e+109) {
		tmp = b * (a * (a * b));
	} else {
		tmp = 0.0 - (a * b);
	}
	return tmp;
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if (b <= 3.25d+109) then
        tmp = b * (a * (a * b))
    else
        tmp = 0.0d0 - (a * b)
    end if
    code = tmp
end function
public static double code(double a, double b) {
	double tmp;
	if (b <= 3.25e+109) {
		tmp = b * (a * (a * b));
	} else {
		tmp = 0.0 - (a * b);
	}
	return tmp;
}
def code(a, b):
	tmp = 0
	if b <= 3.25e+109:
		tmp = b * (a * (a * b))
	else:
		tmp = 0.0 - (a * b)
	return tmp
function code(a, b)
	tmp = 0.0
	if (b <= 3.25e+109)
		tmp = Float64(b * Float64(a * Float64(a * b)));
	else
		tmp = Float64(0.0 - Float64(a * b));
	end
	return tmp
end
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (b <= 3.25e+109)
		tmp = b * (a * (a * b));
	else
		tmp = 0.0 - (a * b);
	end
	tmp_2 = tmp;
end
code[a_, b_] := If[LessEqual[b, 3.25e+109], N[(b * N[(a * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.0 - N[(a * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.25 \cdot 10^{+109}:\\
\;\;\;\;b \cdot \left(a \cdot \left(a \cdot b\right)\right)\\

\mathbf{else}:\\
\;\;\;\;0 - a \cdot b\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < 3.25e109

    1. Initial program 82.9%

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

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

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

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

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

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

    if 3.25e109 < b

    1. Initial program 79.9%

      \[-\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-*r*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. *-lowering-*.f64N/A

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

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

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

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

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

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

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

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot \left(a \cdot b\right)\right), a\right)\right) \]
      2. rem-exp-logN/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot e^{\log \left(a \cdot b\right)}\right), a\right)\right) \]
      3. *-rgt-identityN/A

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

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot e^{\log \left(a \cdot b\right) \cdot \left(\frac{1}{2} + \frac{1}{2}\right)}\right), a\right)\right) \]
      5. distribute-lft-outN/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot e^{\log \left(a \cdot b\right) \cdot \frac{1}{2} + \log \left(a \cdot b\right) \cdot \frac{1}{2}}\right), a\right)\right) \]
      6. count-2N/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot e^{2 \cdot \left(\log \left(a \cdot b\right) \cdot \frac{1}{2}\right)}\right), a\right)\right) \]
      7. exp-prodN/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\left(\log \left(a \cdot b\right) \cdot \frac{1}{2}\right)}\right), a\right)\right) \]
      8. rem-log-expN/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\log \left(e^{\log \left(a \cdot b\right) \cdot \frac{1}{2}}\right)}\right), a\right)\right) \]
      9. pow-to-expN/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\log \left({\left(a \cdot b\right)}^{\frac{1}{2}}\right)}\right), a\right)\right) \]
      10. sqr-powN/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)} \cdot {\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right)}\right), a\right)\right) \]
      11. log-prodN/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\left(\log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) + \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right)\right)}\right), a\right)\right) \]
      12. flip-+N/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\left(\frac{\log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) \cdot \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) - \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) \cdot \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right)}{\log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) - \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right)}\right)}\right), a\right)\right) \]
    8. Applied egg-rr23.0%

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

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

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(b, a\right)\right) \]
    10. Applied egg-rr23.0%

      \[\leadsto -\color{blue}{b \cdot a} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification28.0%

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

Alternative 4: 31.8% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq 3.8 \cdot 10^{+109}:\\ \;\;\;\;\left(a \cdot b\right) \cdot \left(a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;0 - a \cdot b\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= b 3.8e+109) (* (* a b) (* a b)) (- 0.0 (* a b))))
double code(double a, double b) {
	double tmp;
	if (b <= 3.8e+109) {
		tmp = (a * b) * (a * b);
	} else {
		tmp = 0.0 - (a * b);
	}
	return tmp;
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if (b <= 3.8d+109) then
        tmp = (a * b) * (a * b)
    else
        tmp = 0.0d0 - (a * b)
    end if
    code = tmp
end function
public static double code(double a, double b) {
	double tmp;
	if (b <= 3.8e+109) {
		tmp = (a * b) * (a * b);
	} else {
		tmp = 0.0 - (a * b);
	}
	return tmp;
}
def code(a, b):
	tmp = 0
	if b <= 3.8e+109:
		tmp = (a * b) * (a * b)
	else:
		tmp = 0.0 - (a * b)
	return tmp
function code(a, b)
	tmp = 0.0
	if (b <= 3.8e+109)
		tmp = Float64(Float64(a * b) * Float64(a * b));
	else
		tmp = Float64(0.0 - Float64(a * b));
	end
	return tmp
end
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (b <= 3.8e+109)
		tmp = (a * b) * (a * b);
	else
		tmp = 0.0 - (a * b);
	end
	tmp_2 = tmp;
end
code[a_, b_] := If[LessEqual[b, 3.8e+109], N[(N[(a * b), $MachinePrecision] * N[(a * b), $MachinePrecision]), $MachinePrecision], N[(0.0 - N[(a * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.8 \cdot 10^{+109}:\\
\;\;\;\;\left(a \cdot b\right) \cdot \left(a \cdot b\right)\\

\mathbf{else}:\\
\;\;\;\;0 - a \cdot b\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < 3.80000000000000039e109

    1. Initial program 82.9%

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

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

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

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

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

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

    if 3.80000000000000039e109 < b

    1. Initial program 79.9%

      \[-\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-*r*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. *-lowering-*.f64N/A

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

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

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

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

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

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

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

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot \left(a \cdot b\right)\right), a\right)\right) \]
      2. rem-exp-logN/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot e^{\log \left(a \cdot b\right)}\right), a\right)\right) \]
      3. *-rgt-identityN/A

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

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot e^{\log \left(a \cdot b\right) \cdot \left(\frac{1}{2} + \frac{1}{2}\right)}\right), a\right)\right) \]
      5. distribute-lft-outN/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot e^{\log \left(a \cdot b\right) \cdot \frac{1}{2} + \log \left(a \cdot b\right) \cdot \frac{1}{2}}\right), a\right)\right) \]
      6. count-2N/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot e^{2 \cdot \left(\log \left(a \cdot b\right) \cdot \frac{1}{2}\right)}\right), a\right)\right) \]
      7. exp-prodN/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\left(\log \left(a \cdot b\right) \cdot \frac{1}{2}\right)}\right), a\right)\right) \]
      8. rem-log-expN/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\log \left(e^{\log \left(a \cdot b\right) \cdot \frac{1}{2}}\right)}\right), a\right)\right) \]
      9. pow-to-expN/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\log \left({\left(a \cdot b\right)}^{\frac{1}{2}}\right)}\right), a\right)\right) \]
      10. sqr-powN/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)} \cdot {\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right)}\right), a\right)\right) \]
      11. log-prodN/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\left(\log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) + \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right)\right)}\right), a\right)\right) \]
      12. flip-+N/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\left(\frac{\log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) \cdot \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) - \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) \cdot \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right)}{\log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) - \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right)}\right)}\right), a\right)\right) \]
    8. Applied egg-rr23.0%

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

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

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(b, a\right)\right) \]
    10. Applied egg-rr23.0%

      \[\leadsto -\color{blue}{b \cdot a} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification28.0%

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

Alternative 5: 18.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq 1.65 \cdot 10^{-15}:\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \end{array} \]
(FPCore (a b) :precision binary64 (if (<= b 1.65e-15) (* a b) -1.0))
double code(double a, double b) {
	double tmp;
	if (b <= 1.65e-15) {
		tmp = a * b;
	} else {
		tmp = -1.0;
	}
	return tmp;
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if (b <= 1.65d-15) then
        tmp = a * b
    else
        tmp = -1.0d0
    end if
    code = tmp
end function
public static double code(double a, double b) {
	double tmp;
	if (b <= 1.65e-15) {
		tmp = a * b;
	} else {
		tmp = -1.0;
	}
	return tmp;
}
def code(a, b):
	tmp = 0
	if b <= 1.65e-15:
		tmp = a * b
	else:
		tmp = -1.0
	return tmp
function code(a, b)
	tmp = 0.0
	if (b <= 1.65e-15)
		tmp = Float64(a * b);
	else
		tmp = -1.0;
	end
	return tmp
end
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (b <= 1.65e-15)
		tmp = a * b;
	else
		tmp = -1.0;
	end
	tmp_2 = tmp;
end
code[a_, b_] := If[LessEqual[b, 1.65e-15], N[(a * b), $MachinePrecision], -1.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.65 \cdot 10^{-15}:\\
\;\;\;\;a \cdot b\\

\mathbf{else}:\\
\;\;\;\;-1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < 1.65e-15

    1. Initial program 81.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\left(b \cdot e^{\log \left(a \cdot b\right)}\right), a\right) \]
      3. *-rgt-identityN/A

        \[\leadsto \mathsf{*.f64}\left(\left(b \cdot e^{\log \left(a \cdot b\right) \cdot 1}\right), a\right) \]
      4. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\left(b \cdot e^{\log \left(a \cdot b\right) \cdot \left(\frac{1}{2} + \frac{1}{2}\right)}\right), a\right) \]
      5. distribute-lft-outN/A

        \[\leadsto \mathsf{*.f64}\left(\left(b \cdot e^{\log \left(a \cdot b\right) \cdot \frac{1}{2} + \log \left(a \cdot b\right) \cdot \frac{1}{2}}\right), a\right) \]
      6. count-2N/A

        \[\leadsto \mathsf{*.f64}\left(\left(b \cdot e^{2 \cdot \left(\log \left(a \cdot b\right) \cdot \frac{1}{2}\right)}\right), a\right) \]
      7. exp-prodN/A

        \[\leadsto \mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\left(\log \left(a \cdot b\right) \cdot \frac{1}{2}\right)}\right), a\right) \]
      8. rem-log-expN/A

        \[\leadsto \mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\log \left(e^{\log \left(a \cdot b\right) \cdot \frac{1}{2}}\right)}\right), a\right) \]
      9. pow-to-expN/A

        \[\leadsto \mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\log \left({\left(a \cdot b\right)}^{\frac{1}{2}}\right)}\right), a\right) \]
      10. sqr-powN/A

        \[\leadsto \mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)} \cdot {\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right)}\right), a\right) \]
      11. log-prodN/A

        \[\leadsto \mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\left(\log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) + \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right)\right)}\right), a\right) \]
      12. flip-+N/A

        \[\leadsto \mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\left(\frac{\log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) \cdot \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) - \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) \cdot \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right)}{\log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) - \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right)}\right)}\right), a\right) \]
    8. Applied egg-rr25.1%

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

        \[\leadsto b \cdot a \]
      2. *-lowering-*.f6425.1%

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

      \[\leadsto \color{blue}{b \cdot a} \]

    if 1.65e-15 < b

    1. Initial program 85.3%

      \[-\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. Step-by-step derivation
      1. unpow1N/A

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

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left({\left(a \cdot b\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(a \cdot b\right)}^{\left(\frac{1}{2}\right)}\right), \mathsf{*.f64}\left(a, b\right)\right)\right) \]
      3. pow2N/A

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

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

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

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{pow.f64}\left(\mathsf{*.f64}\left(a, b\right), \left(\frac{1}{2}\right)\right), 2\right), \mathsf{*.f64}\left(a, b\right)\right)\right) \]
      7. metadata-eval45.5%

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{pow.f64}\left(\mathsf{*.f64}\left(a, b\right), \frac{1}{2}\right), 2\right), \mathsf{*.f64}\left(a, b\right)\right)\right) \]
    6. Applied egg-rr45.5%

      \[\leadsto -\color{blue}{{\left({\left(a \cdot b\right)}^{0.5}\right)}^{2}} \cdot \left(a \cdot b\right) \]
    7. Applied egg-rr4.4%

      \[\leadsto \color{blue}{-1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification19.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq 1.65 \cdot 10^{-15}:\\ \;\;\;\;a \cdot b\\ \mathbf{else}:\\ \;\;\;\;-1\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 21.5% accurate, 1.6× speedup?

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

\\
0 - a \cdot b
\end{array}
Derivation
  1. Initial program 82.4%

    \[-\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-*r*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. *-lowering-*.f64N/A

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

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

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

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

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

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

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

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot \left(a \cdot b\right)\right), a\right)\right) \]
    2. rem-exp-logN/A

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot e^{\log \left(a \cdot b\right)}\right), a\right)\right) \]
    3. *-rgt-identityN/A

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

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot e^{\log \left(a \cdot b\right) \cdot \left(\frac{1}{2} + \frac{1}{2}\right)}\right), a\right)\right) \]
    5. distribute-lft-outN/A

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot e^{\log \left(a \cdot b\right) \cdot \frac{1}{2} + \log \left(a \cdot b\right) \cdot \frac{1}{2}}\right), a\right)\right) \]
    6. count-2N/A

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot e^{2 \cdot \left(\log \left(a \cdot b\right) \cdot \frac{1}{2}\right)}\right), a\right)\right) \]
    7. exp-prodN/A

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\left(\log \left(a \cdot b\right) \cdot \frac{1}{2}\right)}\right), a\right)\right) \]
    8. rem-log-expN/A

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\log \left(e^{\log \left(a \cdot b\right) \cdot \frac{1}{2}}\right)}\right), a\right)\right) \]
    9. pow-to-expN/A

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\log \left({\left(a \cdot b\right)}^{\frac{1}{2}}\right)}\right), a\right)\right) \]
    10. sqr-powN/A

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)} \cdot {\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right)}\right), a\right)\right) \]
    11. log-prodN/A

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\left(\log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) + \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right)\right)}\right), a\right)\right) \]
    12. flip-+N/A

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left(b \cdot {\left(e^{2}\right)}^{\left(\frac{\log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) \cdot \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) - \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) \cdot \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right)}{\log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right) - \log \left({\left(a \cdot b\right)}^{\left(\frac{\frac{1}{2}}{2}\right)}\right)}\right)}\right), a\right)\right) \]
  8. Applied egg-rr23.6%

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

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

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

    \[\leadsto -\color{blue}{b \cdot a} \]
  11. Final simplification23.6%

    \[\leadsto 0 - a \cdot b \]
  12. Add Preprocessing

Alternative 7: 4.2% accurate, 8.0× speedup?

\[\begin{array}{l} \\ -1 \end{array} \]
(FPCore (a b) :precision binary64 -1.0)
double code(double a, double b) {
	return -1.0;
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = -1.0d0
end function
public static double code(double a, double b) {
	return -1.0;
}
def code(a, b):
	return -1.0
function code(a, b)
	return -1.0
end
function tmp = code(a, b)
	tmp = -1.0;
end
code[a_, b_] := -1.0
\begin{array}{l}

\\
-1
\end{array}
Derivation
  1. Initial program 82.4%

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

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

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

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

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\left({\left(a \cdot b\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(a \cdot b\right)}^{\left(\frac{1}{2}\right)}\right), \mathsf{*.f64}\left(a, b\right)\right)\right) \]
    3. pow2N/A

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

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

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

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{pow.f64}\left(\mathsf{*.f64}\left(a, b\right), \left(\frac{1}{2}\right)\right), 2\right), \mathsf{*.f64}\left(a, b\right)\right)\right) \]
    7. metadata-eval56.7%

      \[\leadsto \mathsf{neg.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{pow.f64}\left(\mathsf{*.f64}\left(a, b\right), \frac{1}{2}\right), 2\right), \mathsf{*.f64}\left(a, b\right)\right)\right) \]
  6. Applied egg-rr56.7%

    \[\leadsto -\color{blue}{{\left({\left(a \cdot b\right)}^{0.5}\right)}^{2}} \cdot \left(a \cdot b\right) \]
  7. Applied egg-rr4.3%

    \[\leadsto \color{blue}{-1} \]
  8. Add Preprocessing

Reproduce

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