Bouland and Aaronson, Equation (25)

Percentage Accurate: 73.7% → 98.4%
Time: 8.4s
Alternatives: 6
Speedup: 1.2×

Specification

?
\[\begin{array}{l} \\ \left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \end{array} \]
(FPCore (a b)
 :precision binary64
 (-
  (+
   (pow (+ (* a a) (* b b)) 2.0)
   (* 4.0 (+ (* (* a a) (+ 1.0 a)) (* (* b b) (- 1.0 (* 3.0 a))))))
  1.0))
double code(double a, double b) {
	return (pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 1.0;
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = ((((a * a) + (b * b)) ** 2.0d0) + (4.0d0 * (((a * a) * (1.0d0 + a)) + ((b * b) * (1.0d0 - (3.0d0 * a)))))) - 1.0d0
end function
public static double code(double a, double b) {
	return (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 1.0;
}
def code(a, b):
	return (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 1.0
function code(a, b)
	return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(Float64(Float64(a * a) * Float64(1.0 + a)) + Float64(Float64(b * b) * Float64(1.0 - Float64(3.0 * a)))))) - 1.0)
end
function tmp = code(a, b)
	tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 1.0;
end
code[a_, b_] := N[(N[(N[Power[N[(N[(a * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(N[(N[(a * a), $MachinePrecision] * N[(1.0 + a), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(1.0 - N[(3.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}

\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 6 alternatives:

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

Initial Program: 73.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \end{array} \]
(FPCore (a b)
 :precision binary64
 (-
  (+
   (pow (+ (* a a) (* b b)) 2.0)
   (* 4.0 (+ (* (* a a) (+ 1.0 a)) (* (* b b) (- 1.0 (* 3.0 a))))))
  1.0))
double code(double a, double b) {
	return (pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 1.0;
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = ((((a * a) + (b * b)) ** 2.0d0) + (4.0d0 * (((a * a) * (1.0d0 + a)) + ((b * b) * (1.0d0 - (3.0d0 * a)))))) - 1.0d0
end function
public static double code(double a, double b) {
	return (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 1.0;
}
def code(a, b):
	return (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 1.0
function code(a, b)
	return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(Float64(Float64(a * a) * Float64(1.0 + a)) + Float64(Float64(b * b) * Float64(1.0 - Float64(3.0 * a)))))) - 1.0)
end
function tmp = code(a, b)
	tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (((a * a) * (1.0 + a)) + ((b * b) * (1.0 - (3.0 * a)))))) - 1.0;
end
code[a_, b_] := N[(N[(N[Power[N[(N[(a * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(N[(N[(a * a), $MachinePrecision] * N[(1.0 + a), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(1.0 - N[(3.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}

\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1
\end{array}

Alternative 1: 98.4% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := a \cdot \left(a + 2\right)\\ t_1 := {\left(\mathsf{hypot}\left(a, b\right)\right)}^{2}\\ \mathbf{if}\;{\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(a + 1\right) + \left(b \cdot b\right) \cdot \left(1 - a \cdot 3\right)\right) \leq \infty:\\ \;\;\;\;\mathsf{fma}\left(t\_1, t\_1, 4 \cdot \mathsf{fma}\left({b}^{2}, \mathsf{fma}\left(a, -3, 1\right), \mathsf{fma}\left(a, a, {a}^{3}\right)\right)\right) + -1\\ \mathbf{else}:\\ \;\;\;\;-1 + t\_0 \cdot t\_0\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (let* ((t_0 (* a (+ a 2.0))) (t_1 (pow (hypot a b) 2.0)))
   (if (<=
        (+
         (pow (+ (* a a) (* b b)) 2.0)
         (* 4.0 (+ (* (* a a) (+ a 1.0)) (* (* b b) (- 1.0 (* a 3.0))))))
        INFINITY)
     (+
      (fma
       t_1
       t_1
       (* 4.0 (fma (pow b 2.0) (fma a -3.0 1.0) (fma a a (pow a 3.0)))))
      -1.0)
     (+ -1.0 (* t_0 t_0)))))
double code(double a, double b) {
	double t_0 = a * (a + 2.0);
	double t_1 = pow(hypot(a, b), 2.0);
	double tmp;
	if ((pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (a + 1.0)) + ((b * b) * (1.0 - (a * 3.0)))))) <= ((double) INFINITY)) {
		tmp = fma(t_1, t_1, (4.0 * fma(pow(b, 2.0), fma(a, -3.0, 1.0), fma(a, a, pow(a, 3.0))))) + -1.0;
	} else {
		tmp = -1.0 + (t_0 * t_0);
	}
	return tmp;
}
function code(a, b)
	t_0 = Float64(a * Float64(a + 2.0))
	t_1 = hypot(a, b) ^ 2.0
	tmp = 0.0
	if (Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(Float64(Float64(a * a) * Float64(a + 1.0)) + Float64(Float64(b * b) * Float64(1.0 - Float64(a * 3.0)))))) <= Inf)
		tmp = Float64(fma(t_1, t_1, Float64(4.0 * fma((b ^ 2.0), fma(a, -3.0, 1.0), fma(a, a, (a ^ 3.0))))) + -1.0);
	else
		tmp = Float64(-1.0 + Float64(t_0 * t_0));
	end
	return tmp
end
code[a_, b_] := Block[{t$95$0 = N[(a * N[(a + 2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision], 2.0], $MachinePrecision]}, If[LessEqual[N[(N[Power[N[(N[(a * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(N[(N[(a * a), $MachinePrecision] * N[(a + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(1.0 - N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], Infinity], N[(N[(t$95$1 * t$95$1 + N[(4.0 * N[(N[Power[b, 2.0], $MachinePrecision] * N[(a * -3.0 + 1.0), $MachinePrecision] + N[(a * a + N[Power[a, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], N[(-1.0 + N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := a \cdot \left(a + 2\right)\\
t_1 := {\left(\mathsf{hypot}\left(a, b\right)\right)}^{2}\\
\mathbf{if}\;{\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(a + 1\right) + \left(b \cdot b\right) \cdot \left(1 - a \cdot 3\right)\right) \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(t\_1, t\_1, 4 \cdot \mathsf{fma}\left({b}^{2}, \mathsf{fma}\left(a, -3, 1\right), \mathsf{fma}\left(a, a, {a}^{3}\right)\right)\right) + -1\\

\mathbf{else}:\\
\;\;\;\;-1 + t\_0 \cdot t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (pow.f64 (+.f64 (*.f64 a a) (*.f64 b b)) 2) (*.f64 4 (+.f64 (*.f64 (*.f64 a a) (+.f64 1 a)) (*.f64 (*.f64 b b) (-.f64 1 (*.f64 3 a)))))) < +inf.0

    1. Initial program 99.8%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    2. Step-by-step derivation
      1. sub-neg99.8%

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

      \[\leadsto \color{blue}{\left(4 \cdot \mathsf{fma}\left(a \cdot a, a + 1, b \cdot \left(b \cdot \left(1 + -3 \cdot a\right)\right)\right) + {\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}^{2}\right) + -1} \]
    4. Add Preprocessing
    5. Applied egg-rr99.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left({\left(\mathsf{hypot}\left(a, b\right)\right)}^{2}, {\left(\mathsf{hypot}\left(a, b\right)\right)}^{2}, 4 \cdot \mathsf{fma}\left({b}^{2}, \mathsf{fma}\left(a, -3, 1\right), \mathsf{fma}\left(a, a, {a}^{3}\right)\right)\right)} + -1 \]

    if +inf.0 < (+.f64 (pow.f64 (+.f64 (*.f64 a a) (*.f64 b b)) 2) (*.f64 4 (+.f64 (*.f64 (*.f64 a a) (+.f64 1 a)) (*.f64 (*.f64 b b) (-.f64 1 (*.f64 3 a))))))

    1. Initial program 0.0%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    2. Step-by-step derivation
      1. sub-neg0.0%

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

      \[\leadsto \color{blue}{\left(4 \cdot \mathsf{fma}\left(a \cdot a, a + 1, b \cdot \left(b \cdot \left(1 + -3 \cdot a\right)\right)\right) + {\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}^{2}\right) + -1} \]
    4. Add Preprocessing
    5. Taylor expanded in a around inf 32.1%

      \[\leadsto \color{blue}{\left(4 \cdot {a}^{3} + {a}^{4}\right)} + -1 \]
    6. Step-by-step derivation
      1. add-sqr-sqrt32.1%

        \[\leadsto \color{blue}{\sqrt{4 \cdot {a}^{3} + {a}^{4}} \cdot \sqrt{4 \cdot {a}^{3} + {a}^{4}}} + -1 \]
      2. pow232.1%

        \[\leadsto \color{blue}{{\left(\sqrt{4 \cdot {a}^{3} + {a}^{4}}\right)}^{2}} + -1 \]
      3. +-commutative32.1%

        \[\leadsto {\left(\sqrt{\color{blue}{{a}^{4} + 4 \cdot {a}^{3}}}\right)}^{2} + -1 \]
      4. metadata-eval32.1%

        \[\leadsto {\left(\sqrt{{a}^{\color{blue}{\left(2 \cdot 2\right)}} + 4 \cdot {a}^{3}}\right)}^{2} + -1 \]
      5. pow-sqr32.1%

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

        \[\leadsto {\left(\sqrt{{a}^{2} \cdot {a}^{2} + \color{blue}{\sqrt{4 \cdot {a}^{3}} \cdot \sqrt{4 \cdot {a}^{3}}}}\right)}^{2} + -1 \]
      7. hypot-define82.1%

        \[\leadsto {\color{blue}{\left(\mathsf{hypot}\left({a}^{2}, \sqrt{4 \cdot {a}^{3}}\right)\right)}}^{2} + -1 \]
      8. sqrt-prod82.1%

        \[\leadsto {\left(\mathsf{hypot}\left({a}^{2}, \color{blue}{\sqrt{4} \cdot \sqrt{{a}^{3}}}\right)\right)}^{2} + -1 \]
      9. metadata-eval82.1%

        \[\leadsto {\left(\mathsf{hypot}\left({a}^{2}, \color{blue}{2} \cdot \sqrt{{a}^{3}}\right)\right)}^{2} + -1 \]
      10. sqrt-pow182.1%

        \[\leadsto {\left(\mathsf{hypot}\left({a}^{2}, 2 \cdot \color{blue}{{a}^{\left(\frac{3}{2}\right)}}\right)\right)}^{2} + -1 \]
      11. metadata-eval82.1%

        \[\leadsto {\left(\mathsf{hypot}\left({a}^{2}, 2 \cdot {a}^{\color{blue}{1.5}}\right)\right)}^{2} + -1 \]
    7. Applied egg-rr82.1%

      \[\leadsto \color{blue}{{\left(\mathsf{hypot}\left({a}^{2}, 2 \cdot {a}^{1.5}\right)\right)}^{2}} + -1 \]
    8. Taylor expanded in a around inf 94.2%

      \[\leadsto {\color{blue}{\left(2 \cdot a + {a}^{2}\right)}}^{2} + -1 \]
    9. Step-by-step derivation
      1. unpow294.2%

        \[\leadsto {\left(2 \cdot a + \color{blue}{a \cdot a}\right)}^{2} + -1 \]
      2. distribute-rgt-out94.2%

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

        \[\leadsto {\left(a \cdot \color{blue}{\left(a + 2\right)}\right)}^{2} + -1 \]
    10. Simplified94.2%

      \[\leadsto {\color{blue}{\left(a \cdot \left(a + 2\right)\right)}}^{2} + -1 \]
    11. Step-by-step derivation
      1. unpow294.2%

        \[\leadsto \color{blue}{\left(a \cdot \left(a + 2\right)\right) \cdot \left(a \cdot \left(a + 2\right)\right)} + -1 \]
    12. Applied egg-rr94.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;{\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(a + 1\right) + \left(b \cdot b\right) \cdot \left(1 - a \cdot 3\right)\right) \leq \infty:\\ \;\;\;\;\mathsf{fma}\left({\left(\mathsf{hypot}\left(a, b\right)\right)}^{2}, {\left(\mathsf{hypot}\left(a, b\right)\right)}^{2}, 4 \cdot \mathsf{fma}\left({b}^{2}, \mathsf{fma}\left(a, -3, 1\right), \mathsf{fma}\left(a, a, {a}^{3}\right)\right)\right) + -1\\ \mathbf{else}:\\ \;\;\;\;-1 + \left(a \cdot \left(a + 2\right)\right) \cdot \left(a \cdot \left(a + 2\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 98.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(a + 1\right) + \left(b \cdot b\right) \cdot \left(1 - a \cdot 3\right)\right)\\ t_1 := a \cdot \left(a + 2\right)\\ \mathbf{if}\;t\_0 \leq \infty:\\ \;\;\;\;t\_0 + -1\\ \mathbf{else}:\\ \;\;\;\;-1 + t\_1 \cdot t\_1\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (let* ((t_0
         (+
          (pow (+ (* a a) (* b b)) 2.0)
          (* 4.0 (+ (* (* a a) (+ a 1.0)) (* (* b b) (- 1.0 (* a 3.0)))))))
        (t_1 (* a (+ a 2.0))))
   (if (<= t_0 INFINITY) (+ t_0 -1.0) (+ -1.0 (* t_1 t_1)))))
double code(double a, double b) {
	double t_0 = pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (a + 1.0)) + ((b * b) * (1.0 - (a * 3.0)))));
	double t_1 = a * (a + 2.0);
	double tmp;
	if (t_0 <= ((double) INFINITY)) {
		tmp = t_0 + -1.0;
	} else {
		tmp = -1.0 + (t_1 * t_1);
	}
	return tmp;
}
public static double code(double a, double b) {
	double t_0 = Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (a + 1.0)) + ((b * b) * (1.0 - (a * 3.0)))));
	double t_1 = a * (a + 2.0);
	double tmp;
	if (t_0 <= Double.POSITIVE_INFINITY) {
		tmp = t_0 + -1.0;
	} else {
		tmp = -1.0 + (t_1 * t_1);
	}
	return tmp;
}
def code(a, b):
	t_0 = math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (a + 1.0)) + ((b * b) * (1.0 - (a * 3.0)))))
	t_1 = a * (a + 2.0)
	tmp = 0
	if t_0 <= math.inf:
		tmp = t_0 + -1.0
	else:
		tmp = -1.0 + (t_1 * t_1)
	return tmp
function code(a, b)
	t_0 = Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(Float64(Float64(a * a) * Float64(a + 1.0)) + Float64(Float64(b * b) * Float64(1.0 - Float64(a * 3.0))))))
	t_1 = Float64(a * Float64(a + 2.0))
	tmp = 0.0
	if (t_0 <= Inf)
		tmp = Float64(t_0 + -1.0);
	else
		tmp = Float64(-1.0 + Float64(t_1 * t_1));
	end
	return tmp
end
function tmp_2 = code(a, b)
	t_0 = (((a * a) + (b * b)) ^ 2.0) + (4.0 * (((a * a) * (a + 1.0)) + ((b * b) * (1.0 - (a * 3.0)))));
	t_1 = a * (a + 2.0);
	tmp = 0.0;
	if (t_0 <= Inf)
		tmp = t_0 + -1.0;
	else
		tmp = -1.0 + (t_1 * t_1);
	end
	tmp_2 = tmp;
end
code[a_, b_] := Block[{t$95$0 = N[(N[Power[N[(N[(a * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[(N[(N[(a * a), $MachinePrecision] * N[(a + 1.0), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(1.0 - N[(a * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(a * N[(a + 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, Infinity], N[(t$95$0 + -1.0), $MachinePrecision], N[(-1.0 + N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(a + 1\right) + \left(b \cdot b\right) \cdot \left(1 - a \cdot 3\right)\right)\\
t_1 := a \cdot \left(a + 2\right)\\
\mathbf{if}\;t\_0 \leq \infty:\\
\;\;\;\;t\_0 + -1\\

\mathbf{else}:\\
\;\;\;\;-1 + t\_1 \cdot t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (+.f64 (pow.f64 (+.f64 (*.f64 a a) (*.f64 b b)) 2) (*.f64 4 (+.f64 (*.f64 (*.f64 a a) (+.f64 1 a)) (*.f64 (*.f64 b b) (-.f64 1 (*.f64 3 a)))))) < +inf.0

    1. Initial program 99.8%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    2. Add Preprocessing

    if +inf.0 < (+.f64 (pow.f64 (+.f64 (*.f64 a a) (*.f64 b b)) 2) (*.f64 4 (+.f64 (*.f64 (*.f64 a a) (+.f64 1 a)) (*.f64 (*.f64 b b) (-.f64 1 (*.f64 3 a))))))

    1. Initial program 0.0%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    2. Step-by-step derivation
      1. sub-neg0.0%

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

      \[\leadsto \color{blue}{\left(4 \cdot \mathsf{fma}\left(a \cdot a, a + 1, b \cdot \left(b \cdot \left(1 + -3 \cdot a\right)\right)\right) + {\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}^{2}\right) + -1} \]
    4. Add Preprocessing
    5. Taylor expanded in a around inf 32.1%

      \[\leadsto \color{blue}{\left(4 \cdot {a}^{3} + {a}^{4}\right)} + -1 \]
    6. Step-by-step derivation
      1. add-sqr-sqrt32.1%

        \[\leadsto \color{blue}{\sqrt{4 \cdot {a}^{3} + {a}^{4}} \cdot \sqrt{4 \cdot {a}^{3} + {a}^{4}}} + -1 \]
      2. pow232.1%

        \[\leadsto \color{blue}{{\left(\sqrt{4 \cdot {a}^{3} + {a}^{4}}\right)}^{2}} + -1 \]
      3. +-commutative32.1%

        \[\leadsto {\left(\sqrt{\color{blue}{{a}^{4} + 4 \cdot {a}^{3}}}\right)}^{2} + -1 \]
      4. metadata-eval32.1%

        \[\leadsto {\left(\sqrt{{a}^{\color{blue}{\left(2 \cdot 2\right)}} + 4 \cdot {a}^{3}}\right)}^{2} + -1 \]
      5. pow-sqr32.1%

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

        \[\leadsto {\left(\sqrt{{a}^{2} \cdot {a}^{2} + \color{blue}{\sqrt{4 \cdot {a}^{3}} \cdot \sqrt{4 \cdot {a}^{3}}}}\right)}^{2} + -1 \]
      7. hypot-define82.1%

        \[\leadsto {\color{blue}{\left(\mathsf{hypot}\left({a}^{2}, \sqrt{4 \cdot {a}^{3}}\right)\right)}}^{2} + -1 \]
      8. sqrt-prod82.1%

        \[\leadsto {\left(\mathsf{hypot}\left({a}^{2}, \color{blue}{\sqrt{4} \cdot \sqrt{{a}^{3}}}\right)\right)}^{2} + -1 \]
      9. metadata-eval82.1%

        \[\leadsto {\left(\mathsf{hypot}\left({a}^{2}, \color{blue}{2} \cdot \sqrt{{a}^{3}}\right)\right)}^{2} + -1 \]
      10. sqrt-pow182.1%

        \[\leadsto {\left(\mathsf{hypot}\left({a}^{2}, 2 \cdot \color{blue}{{a}^{\left(\frac{3}{2}\right)}}\right)\right)}^{2} + -1 \]
      11. metadata-eval82.1%

        \[\leadsto {\left(\mathsf{hypot}\left({a}^{2}, 2 \cdot {a}^{\color{blue}{1.5}}\right)\right)}^{2} + -1 \]
    7. Applied egg-rr82.1%

      \[\leadsto \color{blue}{{\left(\mathsf{hypot}\left({a}^{2}, 2 \cdot {a}^{1.5}\right)\right)}^{2}} + -1 \]
    8. Taylor expanded in a around inf 94.2%

      \[\leadsto {\color{blue}{\left(2 \cdot a + {a}^{2}\right)}}^{2} + -1 \]
    9. Step-by-step derivation
      1. unpow294.2%

        \[\leadsto {\left(2 \cdot a + \color{blue}{a \cdot a}\right)}^{2} + -1 \]
      2. distribute-rgt-out94.2%

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

        \[\leadsto {\left(a \cdot \color{blue}{\left(a + 2\right)}\right)}^{2} + -1 \]
    10. Simplified94.2%

      \[\leadsto {\color{blue}{\left(a \cdot \left(a + 2\right)\right)}}^{2} + -1 \]
    11. Step-by-step derivation
      1. unpow294.2%

        \[\leadsto \color{blue}{\left(a \cdot \left(a + 2\right)\right) \cdot \left(a \cdot \left(a + 2\right)\right)} + -1 \]
    12. Applied egg-rr94.2%

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

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

Alternative 3: 82.1% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq 11200000000000:\\ \;\;\;\;-1 + a \cdot \left(\left(a + 2\right) \cdot \left(a \cdot \left(a + 2\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-1 + {b}^{4}\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= b 11200000000000.0)
   (+ -1.0 (* a (* (+ a 2.0) (* a (+ a 2.0)))))
   (+ -1.0 (pow b 4.0))))
double code(double a, double b) {
	double tmp;
	if (b <= 11200000000000.0) {
		tmp = -1.0 + (a * ((a + 2.0) * (a * (a + 2.0))));
	} else {
		tmp = -1.0 + pow(b, 4.0);
	}
	return tmp;
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if (b <= 11200000000000.0d0) then
        tmp = (-1.0d0) + (a * ((a + 2.0d0) * (a * (a + 2.0d0))))
    else
        tmp = (-1.0d0) + (b ** 4.0d0)
    end if
    code = tmp
end function
public static double code(double a, double b) {
	double tmp;
	if (b <= 11200000000000.0) {
		tmp = -1.0 + (a * ((a + 2.0) * (a * (a + 2.0))));
	} else {
		tmp = -1.0 + Math.pow(b, 4.0);
	}
	return tmp;
}
def code(a, b):
	tmp = 0
	if b <= 11200000000000.0:
		tmp = -1.0 + (a * ((a + 2.0) * (a * (a + 2.0))))
	else:
		tmp = -1.0 + math.pow(b, 4.0)
	return tmp
function code(a, b)
	tmp = 0.0
	if (b <= 11200000000000.0)
		tmp = Float64(-1.0 + Float64(a * Float64(Float64(a + 2.0) * Float64(a * Float64(a + 2.0)))));
	else
		tmp = Float64(-1.0 + (b ^ 4.0));
	end
	return tmp
end
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (b <= 11200000000000.0)
		tmp = -1.0 + (a * ((a + 2.0) * (a * (a + 2.0))));
	else
		tmp = -1.0 + (b ^ 4.0);
	end
	tmp_2 = tmp;
end
code[a_, b_] := If[LessEqual[b, 11200000000000.0], N[(-1.0 + N[(a * N[(N[(a + 2.0), $MachinePrecision] * N[(a * N[(a + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 + N[Power[b, 4.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq 11200000000000:\\
\;\;\;\;-1 + a \cdot \left(\left(a + 2\right) \cdot \left(a \cdot \left(a + 2\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;-1 + {b}^{4}\\


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

    1. Initial program 81.5%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    2. Step-by-step derivation
      1. sub-neg81.5%

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

      \[\leadsto \color{blue}{\left(4 \cdot \mathsf{fma}\left(a \cdot a, a + 1, b \cdot \left(b \cdot \left(1 + -3 \cdot a\right)\right)\right) + {\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}^{2}\right) + -1} \]
    4. Add Preprocessing
    5. Taylor expanded in a around inf 64.0%

      \[\leadsto \color{blue}{\left(4 \cdot {a}^{3} + {a}^{4}\right)} + -1 \]
    6. Step-by-step derivation
      1. add-sqr-sqrt57.0%

        \[\leadsto \color{blue}{\sqrt{4 \cdot {a}^{3} + {a}^{4}} \cdot \sqrt{4 \cdot {a}^{3} + {a}^{4}}} + -1 \]
      2. pow257.0%

        \[\leadsto \color{blue}{{\left(\sqrt{4 \cdot {a}^{3} + {a}^{4}}\right)}^{2}} + -1 \]
      3. +-commutative57.0%

        \[\leadsto {\left(\sqrt{\color{blue}{{a}^{4} + 4 \cdot {a}^{3}}}\right)}^{2} + -1 \]
      4. metadata-eval57.0%

        \[\leadsto {\left(\sqrt{{a}^{\color{blue}{\left(2 \cdot 2\right)}} + 4 \cdot {a}^{3}}\right)}^{2} + -1 \]
      5. pow-sqr57.0%

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

        \[\leadsto {\left(\sqrt{{a}^{2} \cdot {a}^{2} + \color{blue}{\sqrt{4 \cdot {a}^{3}} \cdot \sqrt{4 \cdot {a}^{3}}}}\right)}^{2} + -1 \]
      7. hypot-define61.7%

        \[\leadsto {\color{blue}{\left(\mathsf{hypot}\left({a}^{2}, \sqrt{4 \cdot {a}^{3}}\right)\right)}}^{2} + -1 \]
      8. sqrt-prod61.7%

        \[\leadsto {\left(\mathsf{hypot}\left({a}^{2}, \color{blue}{\sqrt{4} \cdot \sqrt{{a}^{3}}}\right)\right)}^{2} + -1 \]
      9. metadata-eval61.7%

        \[\leadsto {\left(\mathsf{hypot}\left({a}^{2}, \color{blue}{2} \cdot \sqrt{{a}^{3}}\right)\right)}^{2} + -1 \]
      10. sqrt-pow152.3%

        \[\leadsto {\left(\mathsf{hypot}\left({a}^{2}, 2 \cdot \color{blue}{{a}^{\left(\frac{3}{2}\right)}}\right)\right)}^{2} + -1 \]
      11. metadata-eval52.3%

        \[\leadsto {\left(\mathsf{hypot}\left({a}^{2}, 2 \cdot {a}^{\color{blue}{1.5}}\right)\right)}^{2} + -1 \]
    7. Applied egg-rr52.3%

      \[\leadsto \color{blue}{{\left(\mathsf{hypot}\left({a}^{2}, 2 \cdot {a}^{1.5}\right)\right)}^{2}} + -1 \]
    8. Taylor expanded in a around inf 78.2%

      \[\leadsto {\color{blue}{\left(2 \cdot a + {a}^{2}\right)}}^{2} + -1 \]
    9. Step-by-step derivation
      1. unpow278.2%

        \[\leadsto {\left(2 \cdot a + \color{blue}{a \cdot a}\right)}^{2} + -1 \]
      2. distribute-rgt-out78.2%

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

        \[\leadsto {\left(a \cdot \color{blue}{\left(a + 2\right)}\right)}^{2} + -1 \]
    10. Simplified78.2%

      \[\leadsto {\color{blue}{\left(a \cdot \left(a + 2\right)\right)}}^{2} + -1 \]
    11. Step-by-step derivation
      1. unpow278.2%

        \[\leadsto \color{blue}{\left(a \cdot \left(a + 2\right)\right) \cdot \left(a \cdot \left(a + 2\right)\right)} + -1 \]
      2. *-commutative78.2%

        \[\leadsto \left(a \cdot \left(a + 2\right)\right) \cdot \color{blue}{\left(\left(a + 2\right) \cdot a\right)} + -1 \]
      3. associate-*r*78.2%

        \[\leadsto \color{blue}{\left(\left(a \cdot \left(a + 2\right)\right) \cdot \left(a + 2\right)\right) \cdot a} + -1 \]
    12. Applied egg-rr78.2%

      \[\leadsto \color{blue}{\left(\left(a \cdot \left(a + 2\right)\right) \cdot \left(a + 2\right)\right) \cdot a} + -1 \]

    if 1.12e13 < b

    1. Initial program 52.2%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
    2. Step-by-step derivation
      1. sub-neg52.2%

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

      \[\leadsto \color{blue}{\left(4 \cdot \mathsf{fma}\left(a \cdot a, a + 1, b \cdot \left(b \cdot \left(1 + -3 \cdot a\right)\right)\right) + {\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}^{2}\right) + -1} \]
    4. Add Preprocessing
    5. Taylor expanded in b around inf 91.3%

      \[\leadsto \color{blue}{{b}^{4}} + -1 \]
  3. Recombined 2 regimes into one program.
  4. Final simplification81.6%

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

Alternative 4: 69.8% accurate, 10.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := a \cdot \left(a + 2\right)\\ -1 + t\_0 \cdot t\_0 \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (let* ((t_0 (* a (+ a 2.0)))) (+ -1.0 (* t_0 t_0))))
double code(double a, double b) {
	double t_0 = a * (a + 2.0);
	return -1.0 + (t_0 * t_0);
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: t_0
    t_0 = a * (a + 2.0d0)
    code = (-1.0d0) + (t_0 * t_0)
end function
public static double code(double a, double b) {
	double t_0 = a * (a + 2.0);
	return -1.0 + (t_0 * t_0);
}
def code(a, b):
	t_0 = a * (a + 2.0)
	return -1.0 + (t_0 * t_0)
function code(a, b)
	t_0 = Float64(a * Float64(a + 2.0))
	return Float64(-1.0 + Float64(t_0 * t_0))
end
function tmp = code(a, b)
	t_0 = a * (a + 2.0);
	tmp = -1.0 + (t_0 * t_0);
end
code[a_, b_] := Block[{t$95$0 = N[(a * N[(a + 2.0), $MachinePrecision]), $MachinePrecision]}, N[(-1.0 + N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := a \cdot \left(a + 2\right)\\
-1 + t\_0 \cdot t\_0
\end{array}
\end{array}
Derivation
  1. Initial program 74.1%

    \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
  2. Step-by-step derivation
    1. sub-neg74.1%

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

    \[\leadsto \color{blue}{\left(4 \cdot \mathsf{fma}\left(a \cdot a, a + 1, b \cdot \left(b \cdot \left(1 + -3 \cdot a\right)\right)\right) + {\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}^{2}\right) + -1} \]
  4. Add Preprocessing
  5. Taylor expanded in a around inf 52.7%

    \[\leadsto \color{blue}{\left(4 \cdot {a}^{3} + {a}^{4}\right)} + -1 \]
  6. Step-by-step derivation
    1. add-sqr-sqrt47.4%

      \[\leadsto \color{blue}{\sqrt{4 \cdot {a}^{3} + {a}^{4}} \cdot \sqrt{4 \cdot {a}^{3} + {a}^{4}}} + -1 \]
    2. pow247.4%

      \[\leadsto \color{blue}{{\left(\sqrt{4 \cdot {a}^{3} + {a}^{4}}\right)}^{2}} + -1 \]
    3. +-commutative47.4%

      \[\leadsto {\left(\sqrt{\color{blue}{{a}^{4} + 4 \cdot {a}^{3}}}\right)}^{2} + -1 \]
    4. metadata-eval47.4%

      \[\leadsto {\left(\sqrt{{a}^{\color{blue}{\left(2 \cdot 2\right)}} + 4 \cdot {a}^{3}}\right)}^{2} + -1 \]
    5. pow-sqr47.4%

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

      \[\leadsto {\left(\sqrt{{a}^{2} \cdot {a}^{2} + \color{blue}{\sqrt{4 \cdot {a}^{3}} \cdot \sqrt{4 \cdot {a}^{3}}}}\right)}^{2} + -1 \]
    7. hypot-define55.5%

      \[\leadsto {\color{blue}{\left(\mathsf{hypot}\left({a}^{2}, \sqrt{4 \cdot {a}^{3}}\right)\right)}}^{2} + -1 \]
    8. sqrt-prod55.5%

      \[\leadsto {\left(\mathsf{hypot}\left({a}^{2}, \color{blue}{\sqrt{4} \cdot \sqrt{{a}^{3}}}\right)\right)}^{2} + -1 \]
    9. metadata-eval55.5%

      \[\leadsto {\left(\mathsf{hypot}\left({a}^{2}, \color{blue}{2} \cdot \sqrt{{a}^{3}}\right)\right)}^{2} + -1 \]
    10. sqrt-pow148.5%

      \[\leadsto {\left(\mathsf{hypot}\left({a}^{2}, 2 \cdot \color{blue}{{a}^{\left(\frac{3}{2}\right)}}\right)\right)}^{2} + -1 \]
    11. metadata-eval48.5%

      \[\leadsto {\left(\mathsf{hypot}\left({a}^{2}, 2 \cdot {a}^{\color{blue}{1.5}}\right)\right)}^{2} + -1 \]
  7. Applied egg-rr48.5%

    \[\leadsto \color{blue}{{\left(\mathsf{hypot}\left({a}^{2}, 2 \cdot {a}^{1.5}\right)\right)}^{2}} + -1 \]
  8. Taylor expanded in a around inf 69.5%

    \[\leadsto {\color{blue}{\left(2 \cdot a + {a}^{2}\right)}}^{2} + -1 \]
  9. Step-by-step derivation
    1. unpow269.5%

      \[\leadsto {\left(2 \cdot a + \color{blue}{a \cdot a}\right)}^{2} + -1 \]
    2. distribute-rgt-out69.5%

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

      \[\leadsto {\left(a \cdot \color{blue}{\left(a + 2\right)}\right)}^{2} + -1 \]
  10. Simplified69.5%

    \[\leadsto {\color{blue}{\left(a \cdot \left(a + 2\right)\right)}}^{2} + -1 \]
  11. Step-by-step derivation
    1. unpow269.5%

      \[\leadsto \color{blue}{\left(a \cdot \left(a + 2\right)\right) \cdot \left(a \cdot \left(a + 2\right)\right)} + -1 \]
  12. Applied egg-rr69.5%

    \[\leadsto \color{blue}{\left(a \cdot \left(a + 2\right)\right) \cdot \left(a \cdot \left(a + 2\right)\right)} + -1 \]
  13. Final simplification69.5%

    \[\leadsto -1 + \left(a \cdot \left(a + 2\right)\right) \cdot \left(a \cdot \left(a + 2\right)\right) \]
  14. Add Preprocessing

Alternative 5: 69.8% accurate, 10.0× speedup?

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

\\
-1 + a \cdot \left(\left(a + 2\right) \cdot \left(a \cdot \left(a + 2\right)\right)\right)
\end{array}
Derivation
  1. Initial program 74.1%

    \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
  2. Step-by-step derivation
    1. sub-neg74.1%

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

    \[\leadsto \color{blue}{\left(4 \cdot \mathsf{fma}\left(a \cdot a, a + 1, b \cdot \left(b \cdot \left(1 + -3 \cdot a\right)\right)\right) + {\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}^{2}\right) + -1} \]
  4. Add Preprocessing
  5. Taylor expanded in a around inf 52.7%

    \[\leadsto \color{blue}{\left(4 \cdot {a}^{3} + {a}^{4}\right)} + -1 \]
  6. Step-by-step derivation
    1. add-sqr-sqrt47.4%

      \[\leadsto \color{blue}{\sqrt{4 \cdot {a}^{3} + {a}^{4}} \cdot \sqrt{4 \cdot {a}^{3} + {a}^{4}}} + -1 \]
    2. pow247.4%

      \[\leadsto \color{blue}{{\left(\sqrt{4 \cdot {a}^{3} + {a}^{4}}\right)}^{2}} + -1 \]
    3. +-commutative47.4%

      \[\leadsto {\left(\sqrt{\color{blue}{{a}^{4} + 4 \cdot {a}^{3}}}\right)}^{2} + -1 \]
    4. metadata-eval47.4%

      \[\leadsto {\left(\sqrt{{a}^{\color{blue}{\left(2 \cdot 2\right)}} + 4 \cdot {a}^{3}}\right)}^{2} + -1 \]
    5. pow-sqr47.4%

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

      \[\leadsto {\left(\sqrt{{a}^{2} \cdot {a}^{2} + \color{blue}{\sqrt{4 \cdot {a}^{3}} \cdot \sqrt{4 \cdot {a}^{3}}}}\right)}^{2} + -1 \]
    7. hypot-define55.5%

      \[\leadsto {\color{blue}{\left(\mathsf{hypot}\left({a}^{2}, \sqrt{4 \cdot {a}^{3}}\right)\right)}}^{2} + -1 \]
    8. sqrt-prod55.5%

      \[\leadsto {\left(\mathsf{hypot}\left({a}^{2}, \color{blue}{\sqrt{4} \cdot \sqrt{{a}^{3}}}\right)\right)}^{2} + -1 \]
    9. metadata-eval55.5%

      \[\leadsto {\left(\mathsf{hypot}\left({a}^{2}, \color{blue}{2} \cdot \sqrt{{a}^{3}}\right)\right)}^{2} + -1 \]
    10. sqrt-pow148.5%

      \[\leadsto {\left(\mathsf{hypot}\left({a}^{2}, 2 \cdot \color{blue}{{a}^{\left(\frac{3}{2}\right)}}\right)\right)}^{2} + -1 \]
    11. metadata-eval48.5%

      \[\leadsto {\left(\mathsf{hypot}\left({a}^{2}, 2 \cdot {a}^{\color{blue}{1.5}}\right)\right)}^{2} + -1 \]
  7. Applied egg-rr48.5%

    \[\leadsto \color{blue}{{\left(\mathsf{hypot}\left({a}^{2}, 2 \cdot {a}^{1.5}\right)\right)}^{2}} + -1 \]
  8. Taylor expanded in a around inf 69.5%

    \[\leadsto {\color{blue}{\left(2 \cdot a + {a}^{2}\right)}}^{2} + -1 \]
  9. Step-by-step derivation
    1. unpow269.5%

      \[\leadsto {\left(2 \cdot a + \color{blue}{a \cdot a}\right)}^{2} + -1 \]
    2. distribute-rgt-out69.5%

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

      \[\leadsto {\left(a \cdot \color{blue}{\left(a + 2\right)}\right)}^{2} + -1 \]
  10. Simplified69.5%

    \[\leadsto {\color{blue}{\left(a \cdot \left(a + 2\right)\right)}}^{2} + -1 \]
  11. Step-by-step derivation
    1. unpow269.5%

      \[\leadsto \color{blue}{\left(a \cdot \left(a + 2\right)\right) \cdot \left(a \cdot \left(a + 2\right)\right)} + -1 \]
    2. *-commutative69.5%

      \[\leadsto \left(a \cdot \left(a + 2\right)\right) \cdot \color{blue}{\left(\left(a + 2\right) \cdot a\right)} + -1 \]
    3. associate-*r*69.5%

      \[\leadsto \color{blue}{\left(\left(a \cdot \left(a + 2\right)\right) \cdot \left(a + 2\right)\right) \cdot a} + -1 \]
  12. Applied egg-rr69.5%

    \[\leadsto \color{blue}{\left(\left(a \cdot \left(a + 2\right)\right) \cdot \left(a + 2\right)\right) \cdot a} + -1 \]
  13. Final simplification69.5%

    \[\leadsto -1 + a \cdot \left(\left(a + 2\right) \cdot \left(a \cdot \left(a + 2\right)\right)\right) \]
  14. Add Preprocessing

Alternative 6: 24.2% accurate, 130.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 74.1%

    \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 + a\right) + \left(b \cdot b\right) \cdot \left(1 - 3 \cdot a\right)\right)\right) - 1 \]
  2. Step-by-step derivation
    1. sub-neg74.1%

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

    \[\leadsto \color{blue}{\left(4 \cdot \mathsf{fma}\left(a \cdot a, a + 1, b \cdot \left(b \cdot \left(1 + -3 \cdot a\right)\right)\right) + {\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}^{2}\right) + -1} \]
  4. Add Preprocessing
  5. Taylor expanded in b around inf 70.9%

    \[\leadsto \color{blue}{{b}^{4}} + -1 \]
  6. Taylor expanded in b around 0 25.6%

    \[\leadsto \color{blue}{-1} \]
  7. Final simplification25.6%

    \[\leadsto -1 \]
  8. Add Preprocessing

Reproduce

?
herbie shell --seed 2024050 
(FPCore (a b)
  :name "Bouland and Aaronson, Equation (25)"
  :precision binary64
  (- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (+ (* (* a a) (+ 1.0 a)) (* (* b b) (- 1.0 (* 3.0 a)))))) 1.0))