Difference of squares

Percentage Accurate: 93.7% → 98.9%
Time: 4.6s
Alternatives: 5
Speedup: 0.5×

Specification

?
\[\begin{array}{l} \\ a \cdot a - b \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(a * a) - Float64(b * b))
end
function tmp = code(a, b)
	tmp = (a * a) - (b * b);
end
code[a_, b_] := N[(N[(a * a), $MachinePrecision] - N[(b * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
a \cdot a - b \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 5 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: 93.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ a \cdot a - b \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(a * a) - Float64(b * b))
end
function tmp = code(a, b)
	tmp = (a * a) - (b * b);
end
code[a_, b_] := N[(N[(a * a), $MachinePrecision] - N[(b * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
a \cdot a - b \cdot b
\end{array}

Alternative 1: 98.9% accurate, 0.1× speedup?

\[\begin{array}{l} a_m = \left|a\right| \\ \begin{array}{l} \mathbf{if}\;a\_m \leq 1.35 \cdot 10^{+218}:\\ \;\;\;\;\mathsf{fma}\left(a\_m, a\_m, b \cdot \left(-b\right)\right)\\ \mathbf{else}:\\ \;\;\;\;a\_m \cdot \left(a\_m + b\right)\\ \end{array} \end{array} \]
a_m = (fabs.f64 a)
(FPCore (a_m b)
 :precision binary64
 (if (<= a_m 1.35e+218) (fma a_m a_m (* b (- b))) (* a_m (+ a_m b))))
a_m = fabs(a);
double code(double a_m, double b) {
	double tmp;
	if (a_m <= 1.35e+218) {
		tmp = fma(a_m, a_m, (b * -b));
	} else {
		tmp = a_m * (a_m + b);
	}
	return tmp;
}
a_m = abs(a)
function code(a_m, b)
	tmp = 0.0
	if (a_m <= 1.35e+218)
		tmp = fma(a_m, a_m, Float64(b * Float64(-b)));
	else
		tmp = Float64(a_m * Float64(a_m + b));
	end
	return tmp
end
a_m = N[Abs[a], $MachinePrecision]
code[a$95$m_, b_] := If[LessEqual[a$95$m, 1.35e+218], N[(a$95$m * a$95$m + N[(b * (-b)), $MachinePrecision]), $MachinePrecision], N[(a$95$m * N[(a$95$m + b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
a_m = \left|a\right|

\\
\begin{array}{l}
\mathbf{if}\;a\_m \leq 1.35 \cdot 10^{+218}:\\
\;\;\;\;\mathsf{fma}\left(a\_m, a\_m, b \cdot \left(-b\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < 1.35000000000000006e218

    1. Initial program 94.3%

      \[a \cdot a - b \cdot b \]
    2. Step-by-step derivation
      1. sqr-neg94.3%

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(a, a, b \cdot \left(-b\right)\right)} \]
    3. Simplified98.4%

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

    if 1.35000000000000006e218 < a

    1. Initial program 72.7%

      \[a \cdot a - b \cdot b \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. difference-of-squares100.0%

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

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

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

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

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

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

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

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

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

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

Alternative 2: 96.6% accurate, 0.5× speedup?

\[\begin{array}{l} a_m = \left|a\right| \\ \begin{array}{l} \mathbf{if}\;b \cdot b \leq 2 \cdot 10^{+301}:\\ \;\;\;\;a\_m \cdot a\_m - b \cdot b\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(-b\right)\\ \end{array} \end{array} \]
a_m = (fabs.f64 a)
(FPCore (a_m b)
 :precision binary64
 (if (<= (* b b) 2e+301) (- (* a_m a_m) (* b b)) (* b (- b))))
a_m = fabs(a);
double code(double a_m, double b) {
	double tmp;
	if ((b * b) <= 2e+301) {
		tmp = (a_m * a_m) - (b * b);
	} else {
		tmp = b * -b;
	}
	return tmp;
}
a_m = abs(a)
real(8) function code(a_m, b)
    real(8), intent (in) :: a_m
    real(8), intent (in) :: b
    real(8) :: tmp
    if ((b * b) <= 2d+301) then
        tmp = (a_m * a_m) - (b * b)
    else
        tmp = b * -b
    end if
    code = tmp
end function
a_m = Math.abs(a);
public static double code(double a_m, double b) {
	double tmp;
	if ((b * b) <= 2e+301) {
		tmp = (a_m * a_m) - (b * b);
	} else {
		tmp = b * -b;
	}
	return tmp;
}
a_m = math.fabs(a)
def code(a_m, b):
	tmp = 0
	if (b * b) <= 2e+301:
		tmp = (a_m * a_m) - (b * b)
	else:
		tmp = b * -b
	return tmp
a_m = abs(a)
function code(a_m, b)
	tmp = 0.0
	if (Float64(b * b) <= 2e+301)
		tmp = Float64(Float64(a_m * a_m) - Float64(b * b));
	else
		tmp = Float64(b * Float64(-b));
	end
	return tmp
end
a_m = abs(a);
function tmp_2 = code(a_m, b)
	tmp = 0.0;
	if ((b * b) <= 2e+301)
		tmp = (a_m * a_m) - (b * b);
	else
		tmp = b * -b;
	end
	tmp_2 = tmp;
end
a_m = N[Abs[a], $MachinePrecision]
code[a$95$m_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 2e+301], N[(N[(a$95$m * a$95$m), $MachinePrecision] - N[(b * b), $MachinePrecision]), $MachinePrecision], N[(b * (-b)), $MachinePrecision]]
\begin{array}{l}
a_m = \left|a\right|

\\
\begin{array}{l}
\mathbf{if}\;b \cdot b \leq 2 \cdot 10^{+301}:\\
\;\;\;\;a\_m \cdot a\_m - b \cdot b\\

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


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

    1. Initial program 100.0%

      \[a \cdot a - b \cdot b \]
    2. Add Preprocessing

    if 2.00000000000000011e301 < (*.f64 b b)

    1. Initial program 74.6%

      \[a \cdot a - b \cdot b \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0 89.6%

      \[\leadsto \color{blue}{-1 \cdot {b}^{2}} \]
    4. Step-by-step derivation
      1. neg-mul-189.6%

        \[\leadsto \color{blue}{-{b}^{2}} \]
    5. Simplified89.6%

      \[\leadsto \color{blue}{-{b}^{2}} \]
    6. Step-by-step derivation
      1. unpow289.6%

        \[\leadsto -\color{blue}{b \cdot b} \]
      2. distribute-lft-neg-in89.6%

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

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

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

Alternative 3: 78.4% accurate, 0.6× speedup?

\[\begin{array}{l} a_m = \left|a\right| \\ \begin{array}{l} \mathbf{if}\;b \cdot b \leq 2 \cdot 10^{-23}:\\ \;\;\;\;a\_m \cdot \left(a\_m + b\right)\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(-b\right)\\ \end{array} \end{array} \]
a_m = (fabs.f64 a)
(FPCore (a_m b)
 :precision binary64
 (if (<= (* b b) 2e-23) (* a_m (+ a_m b)) (* b (- b))))
a_m = fabs(a);
double code(double a_m, double b) {
	double tmp;
	if ((b * b) <= 2e-23) {
		tmp = a_m * (a_m + b);
	} else {
		tmp = b * -b;
	}
	return tmp;
}
a_m = abs(a)
real(8) function code(a_m, b)
    real(8), intent (in) :: a_m
    real(8), intent (in) :: b
    real(8) :: tmp
    if ((b * b) <= 2d-23) then
        tmp = a_m * (a_m + b)
    else
        tmp = b * -b
    end if
    code = tmp
end function
a_m = Math.abs(a);
public static double code(double a_m, double b) {
	double tmp;
	if ((b * b) <= 2e-23) {
		tmp = a_m * (a_m + b);
	} else {
		tmp = b * -b;
	}
	return tmp;
}
a_m = math.fabs(a)
def code(a_m, b):
	tmp = 0
	if (b * b) <= 2e-23:
		tmp = a_m * (a_m + b)
	else:
		tmp = b * -b
	return tmp
a_m = abs(a)
function code(a_m, b)
	tmp = 0.0
	if (Float64(b * b) <= 2e-23)
		tmp = Float64(a_m * Float64(a_m + b));
	else
		tmp = Float64(b * Float64(-b));
	end
	return tmp
end
a_m = abs(a);
function tmp_2 = code(a_m, b)
	tmp = 0.0;
	if ((b * b) <= 2e-23)
		tmp = a_m * (a_m + b);
	else
		tmp = b * -b;
	end
	tmp_2 = tmp;
end
a_m = N[Abs[a], $MachinePrecision]
code[a$95$m_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 2e-23], N[(a$95$m * N[(a$95$m + b), $MachinePrecision]), $MachinePrecision], N[(b * (-b)), $MachinePrecision]]
\begin{array}{l}
a_m = \left|a\right|

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

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


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

    1. Initial program 100.0%

      \[a \cdot a - b \cdot b \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. difference-of-squares100.0%

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

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

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

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

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

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

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

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

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

    if 1.99999999999999992e-23 < (*.f64 b b)

    1. Initial program 87.4%

      \[a \cdot a - b \cdot b \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0 80.4%

      \[\leadsto \color{blue}{-1 \cdot {b}^{2}} \]
    4. Step-by-step derivation
      1. neg-mul-180.4%

        \[\leadsto \color{blue}{-{b}^{2}} \]
    5. Simplified80.4%

      \[\leadsto \color{blue}{-{b}^{2}} \]
    6. Step-by-step derivation
      1. unpow280.4%

        \[\leadsto -\color{blue}{b \cdot b} \]
      2. distribute-lft-neg-in80.4%

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

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

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

Alternative 4: 56.3% accurate, 0.8× speedup?

\[\begin{array}{l} a_m = \left|a\right| \\ \begin{array}{l} \mathbf{if}\;a\_m \leq 7.8 \cdot 10^{+217}:\\ \;\;\;\;b \cdot \left(-b\right)\\ \mathbf{else}:\\ \;\;\;\;a\_m \cdot b\\ \end{array} \end{array} \]
a_m = (fabs.f64 a)
(FPCore (a_m b)
 :precision binary64
 (if (<= a_m 7.8e+217) (* b (- b)) (* a_m b)))
a_m = fabs(a);
double code(double a_m, double b) {
	double tmp;
	if (a_m <= 7.8e+217) {
		tmp = b * -b;
	} else {
		tmp = a_m * b;
	}
	return tmp;
}
a_m = abs(a)
real(8) function code(a_m, b)
    real(8), intent (in) :: a_m
    real(8), intent (in) :: b
    real(8) :: tmp
    if (a_m <= 7.8d+217) then
        tmp = b * -b
    else
        tmp = a_m * b
    end if
    code = tmp
end function
a_m = Math.abs(a);
public static double code(double a_m, double b) {
	double tmp;
	if (a_m <= 7.8e+217) {
		tmp = b * -b;
	} else {
		tmp = a_m * b;
	}
	return tmp;
}
a_m = math.fabs(a)
def code(a_m, b):
	tmp = 0
	if a_m <= 7.8e+217:
		tmp = b * -b
	else:
		tmp = a_m * b
	return tmp
a_m = abs(a)
function code(a_m, b)
	tmp = 0.0
	if (a_m <= 7.8e+217)
		tmp = Float64(b * Float64(-b));
	else
		tmp = Float64(a_m * b);
	end
	return tmp
end
a_m = abs(a);
function tmp_2 = code(a_m, b)
	tmp = 0.0;
	if (a_m <= 7.8e+217)
		tmp = b * -b;
	else
		tmp = a_m * b;
	end
	tmp_2 = tmp;
end
a_m = N[Abs[a], $MachinePrecision]
code[a$95$m_, b_] := If[LessEqual[a$95$m, 7.8e+217], N[(b * (-b)), $MachinePrecision], N[(a$95$m * b), $MachinePrecision]]
\begin{array}{l}
a_m = \left|a\right|

\\
\begin{array}{l}
\mathbf{if}\;a\_m \leq 7.8 \cdot 10^{+217}:\\
\;\;\;\;b \cdot \left(-b\right)\\

\mathbf{else}:\\
\;\;\;\;a\_m \cdot b\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < 7.79999999999999986e217

    1. Initial program 94.3%

      \[a \cdot a - b \cdot b \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0 58.6%

      \[\leadsto \color{blue}{-1 \cdot {b}^{2}} \]
    4. Step-by-step derivation
      1. neg-mul-158.6%

        \[\leadsto \color{blue}{-{b}^{2}} \]
    5. Simplified58.6%

      \[\leadsto \color{blue}{-{b}^{2}} \]
    6. Step-by-step derivation
      1. unpow258.6%

        \[\leadsto -\color{blue}{b \cdot b} \]
      2. distribute-lft-neg-in58.6%

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

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

    if 7.79999999999999986e217 < a

    1. Initial program 72.7%

      \[a \cdot a - b \cdot b \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. difference-of-squares100.0%

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 15.3% accurate, 2.3× speedup?

\[\begin{array}{l} a_m = \left|a\right| \\ a\_m \cdot b \end{array} \]
a_m = (fabs.f64 a)
(FPCore (a_m b) :precision binary64 (* a_m b))
a_m = fabs(a);
double code(double a_m, double b) {
	return a_m * b;
}
a_m = abs(a)
real(8) function code(a_m, b)
    real(8), intent (in) :: a_m
    real(8), intent (in) :: b
    code = a_m * b
end function
a_m = Math.abs(a);
public static double code(double a_m, double b) {
	return a_m * b;
}
a_m = math.fabs(a)
def code(a_m, b):
	return a_m * b
a_m = abs(a)
function code(a_m, b)
	return Float64(a_m * b)
end
a_m = abs(a);
function tmp = code(a_m, b)
	tmp = a_m * b;
end
a_m = N[Abs[a], $MachinePrecision]
code[a$95$m_, b_] := N[(a$95$m * b), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|

\\
a\_m \cdot b
\end{array}
Derivation
  1. Initial program 93.4%

    \[a \cdot a - b \cdot b \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. difference-of-squares100.0%

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{a \cdot b} \]
  7. Add Preprocessing

Developer target: 100.0% accurate, 1.0× speedup?

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

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

Reproduce

?
herbie shell --seed 2024111 
(FPCore (a b)
  :name "Difference of squares"
  :precision binary64

  :alt
  (* (+ a b) (- a b))

  (- (* a a) (* b b)))