Bouland and Aaronson, Equation (24)

Percentage Accurate: 74.1% → 98.5%
Time: 6.9s
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(3 + 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) (+ 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) * (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) * (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) * (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) * (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(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) * (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[(3.0 + a), $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(3 + 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: 74.1% 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(3 + 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) (+ 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) * (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) * (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) * (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) * (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(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) * (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[(3.0 + a), $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(3 + a\right)\right)\right) - 1
\end{array}

Alternative 1: 98.5% 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(1 - a\right) + \left(b \cdot b\right) \cdot \left(a + 3\right)\right)\\ \mathbf{if}\;t\_0 \leq \infty:\\ \;\;\;\;t\_0 + -1\\ \mathbf{else}:\\ \;\;\;\;{a}^{4}\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (let* ((t_0
         (+
          (pow (+ (* a a) (* b b)) 2.0)
          (* 4.0 (+ (* (* a a) (- 1.0 a)) (* (* b b) (+ a 3.0)))))))
   (if (<= t_0 INFINITY) (+ t_0 -1.0) (pow a 4.0))))
double code(double a, double b) {
	double t_0 = pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 - a)) + ((b * b) * (a + 3.0))));
	double tmp;
	if (t_0 <= ((double) INFINITY)) {
		tmp = t_0 + -1.0;
	} else {
		tmp = pow(a, 4.0);
	}
	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) * (1.0 - a)) + ((b * b) * (a + 3.0))));
	double tmp;
	if (t_0 <= Double.POSITIVE_INFINITY) {
		tmp = t_0 + -1.0;
	} else {
		tmp = Math.pow(a, 4.0);
	}
	return tmp;
}
def code(a, b):
	t_0 = math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (((a * a) * (1.0 - a)) + ((b * b) * (a + 3.0))))
	tmp = 0
	if t_0 <= math.inf:
		tmp = t_0 + -1.0
	else:
		tmp = math.pow(a, 4.0)
	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(1.0 - a)) + Float64(Float64(b * b) * Float64(a + 3.0)))))
	tmp = 0.0
	if (t_0 <= Inf)
		tmp = Float64(t_0 + -1.0);
	else
		tmp = a ^ 4.0;
	end
	return tmp
end
function tmp_2 = code(a, b)
	t_0 = (((a * a) + (b * b)) ^ 2.0) + (4.0 * (((a * a) * (1.0 - a)) + ((b * b) * (a + 3.0))));
	tmp = 0.0;
	if (t_0 <= Inf)
		tmp = t_0 + -1.0;
	else
		tmp = a ^ 4.0;
	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[(1.0 - a), $MachinePrecision]), $MachinePrecision] + N[(N[(b * b), $MachinePrecision] * N[(a + 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, Infinity], N[(t$95$0 + -1.0), $MachinePrecision], N[Power[a, 4.0], $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(1 - a\right) + \left(b \cdot b\right) \cdot \left(a + 3\right)\right)\\
\mathbf{if}\;t\_0 \leq \infty:\\
\;\;\;\;t\_0 + -1\\

\mathbf{else}:\\
\;\;\;\;{a}^{4}\\


\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 3 a))))) < +inf.0

    1. Initial program 99.9%

      \[\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(3 + 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 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(3 + a\right)\right)\right) - 1 \]
    2. Step-by-step derivation
      1. associate--l+0.0%

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

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

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

        \[\leadsto {\color{blue}{\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}}^{2} + \left(4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 - a\right) + \left(b \cdot b\right) \cdot \left(3 + a\right)\right) - 1\right) \]
      5. sqr-neg0.0%

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

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

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

    \[\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(1 - a\right) + \left(b \cdot b\right) \cdot \left(a + 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(1 - a\right) + \left(b \cdot b\right) \cdot \left(a + 3\right)\right)\right) + -1\\ \mathbf{else}:\\ \;\;\;\;{a}^{4}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 69.8% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \leq -4.8 \lor \neg \left(a \leq 2.5\right):\\
\;\;\;\;{a}^{4}\\

\mathbf{else}:\\
\;\;\;\;4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 - a\right)\right) + -1\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -4.79999999999999982 or 2.5 < a

    1. Initial program 44.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(3 + a\right)\right)\right) - 1 \]
    2. Step-by-step derivation
      1. associate--l+44.0%

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

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

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

        \[\leadsto {\color{blue}{\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}}^{2} + \left(4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 - a\right) + \left(b \cdot b\right) \cdot \left(3 + a\right)\right) - 1\right) \]
      5. sqr-neg44.0%

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

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

      \[\leadsto \color{blue}{{a}^{4}} \]

    if -4.79999999999999982 < a < 2.5

    1. Initial program 99.9%

      \[\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(3 + a\right)\right)\right) - 1 \]
    2. Step-by-step derivation
      1. associate--l+99.9%

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

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

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

        \[\leadsto {\color{blue}{\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}}^{2} + \left(4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 - a\right) + \left(b \cdot b\right) \cdot \left(3 + a\right)\right) - 1\right) \]
      5. sqr-neg99.9%

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

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

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

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

      \[\leadsto \left(4 \cdot \left(\color{blue}{\left(a \cdot a\right)} \cdot \left(1 - a\right)\right) + {a}^{4}\right) - 1 \]
    8. Taylor expanded in a around 0 51.3%

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

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

        \[\leadsto \left(4 \cdot {a}^{2} + \color{blue}{\left(-4\right)} \cdot {a}^{3}\right) - 1 \]
      3. cancel-sign-sub-inv51.3%

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

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

        \[\leadsto \left(4 \cdot {a}^{2} - 4 \cdot \left(\color{blue}{{a}^{2}} \cdot a\right)\right) - 1 \]
      6. associate-*l*51.3%

        \[\leadsto \left(4 \cdot {a}^{2} - \color{blue}{\left(4 \cdot {a}^{2}\right) \cdot a}\right) - 1 \]
      7. unsub-neg51.3%

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

        \[\leadsto \left(\color{blue}{\left(4 \cdot {a}^{2}\right) \cdot 1} + \left(-\left(4 \cdot {a}^{2}\right) \cdot a\right)\right) - 1 \]
      9. distribute-rgt-neg-out51.3%

        \[\leadsto \left(\left(4 \cdot {a}^{2}\right) \cdot 1 + \color{blue}{\left(4 \cdot {a}^{2}\right) \cdot \left(-a\right)}\right) - 1 \]
      10. distribute-lft-in51.3%

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

        \[\leadsto \left(4 \cdot {a}^{2}\right) \cdot \color{blue}{\left(1 - a\right)} - 1 \]
      12. associate-*r*51.3%

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

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

        \[\leadsto 4 \cdot \color{blue}{\left(a \cdot a\right)} - 1 \]
    12. Applied egg-rr51.3%

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

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

Alternative 3: 81.5% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq 1.8 \cdot 10^{+18}:\\ \;\;\;\;{a}^{4} + -1\\ \mathbf{else}:\\ \;\;\;\;{b}^{4}\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= b 1.8e+18) (+ (pow a 4.0) -1.0) (pow b 4.0)))
double code(double a, double b) {
	double tmp;
	if (b <= 1.8e+18) {
		tmp = pow(a, 4.0) + -1.0;
	} else {
		tmp = 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 <= 1.8d+18) then
        tmp = (a ** 4.0d0) + (-1.0d0)
    else
        tmp = b ** 4.0d0
    end if
    code = tmp
end function
public static double code(double a, double b) {
	double tmp;
	if (b <= 1.8e+18) {
		tmp = Math.pow(a, 4.0) + -1.0;
	} else {
		tmp = Math.pow(b, 4.0);
	}
	return tmp;
}
def code(a, b):
	tmp = 0
	if b <= 1.8e+18:
		tmp = math.pow(a, 4.0) + -1.0
	else:
		tmp = math.pow(b, 4.0)
	return tmp
function code(a, b)
	tmp = 0.0
	if (b <= 1.8e+18)
		tmp = Float64((a ^ 4.0) + -1.0);
	else
		tmp = b ^ 4.0;
	end
	return tmp
end
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (b <= 1.8e+18)
		tmp = (a ^ 4.0) + -1.0;
	else
		tmp = b ^ 4.0;
	end
	tmp_2 = tmp;
end
code[a_, b_] := If[LessEqual[b, 1.8e+18], N[(N[Power[a, 4.0], $MachinePrecision] + -1.0), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.8 \cdot 10^{+18}:\\
\;\;\;\;{a}^{4} + -1\\

\mathbf{else}:\\
\;\;\;\;{b}^{4}\\


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

    1. Initial program 76.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(3 + a\right)\right)\right) - 1 \]
    2. Step-by-step derivation
      1. associate--l+76.1%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(4 \cdot \left({a}^{2} \cdot \left(1 - a\right)\right) + {a}^{4}\right) - 1} \]
    6. Taylor expanded in a around inf 79.8%

      \[\leadsto \color{blue}{{a}^{4}} - 1 \]

    if 1.8e18 < b

    1. Initial program 68.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(3 + a\right)\right)\right) - 1 \]
    2. Step-by-step derivation
      1. associate--l+68.2%

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

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

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

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

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

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

      \[\leadsto \color{blue}{{b}^{4}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification83.7%

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

Alternative 4: 67.0% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq 1.8 \cdot 10^{+18}:\\ \;\;\;\;\left(a \cdot a\right) \cdot 4 + -1\\ \mathbf{else}:\\ \;\;\;\;{b}^{4}\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= b 1.8e+18) (+ (* (* a a) 4.0) -1.0) (pow b 4.0)))
double code(double a, double b) {
	double tmp;
	if (b <= 1.8e+18) {
		tmp = ((a * a) * 4.0) + -1.0;
	} else {
		tmp = 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 <= 1.8d+18) then
        tmp = ((a * a) * 4.0d0) + (-1.0d0)
    else
        tmp = b ** 4.0d0
    end if
    code = tmp
end function
public static double code(double a, double b) {
	double tmp;
	if (b <= 1.8e+18) {
		tmp = ((a * a) * 4.0) + -1.0;
	} else {
		tmp = Math.pow(b, 4.0);
	}
	return tmp;
}
def code(a, b):
	tmp = 0
	if b <= 1.8e+18:
		tmp = ((a * a) * 4.0) + -1.0
	else:
		tmp = math.pow(b, 4.0)
	return tmp
function code(a, b)
	tmp = 0.0
	if (b <= 1.8e+18)
		tmp = Float64(Float64(Float64(a * a) * 4.0) + -1.0);
	else
		tmp = b ^ 4.0;
	end
	return tmp
end
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (b <= 1.8e+18)
		tmp = ((a * a) * 4.0) + -1.0;
	else
		tmp = b ^ 4.0;
	end
	tmp_2 = tmp;
end
code[a_, b_] := If[LessEqual[b, 1.8e+18], N[(N[(N[(a * a), $MachinePrecision] * 4.0), $MachinePrecision] + -1.0), $MachinePrecision], N[Power[b, 4.0], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.8 \cdot 10^{+18}:\\
\;\;\;\;\left(a \cdot a\right) \cdot 4 + -1\\

\mathbf{else}:\\
\;\;\;\;{b}^{4}\\


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

    1. Initial program 76.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(3 + a\right)\right)\right) - 1 \]
    2. Step-by-step derivation
      1. associate--l+76.1%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(4 \cdot \left({a}^{2} \cdot \left(1 - a\right)\right) + {a}^{4}\right) - 1} \]
    6. Taylor expanded in a around 0 62.7%

      \[\leadsto \color{blue}{4 \cdot {a}^{2}} - 1 \]
    7. Step-by-step derivation
      1. pow262.7%

        \[\leadsto 4 \cdot \color{blue}{\left(a \cdot a\right)} - 1 \]
    8. Applied egg-rr62.7%

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

    if 1.8e18 < b

    1. Initial program 68.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(3 + a\right)\right)\right) - 1 \]
    2. Step-by-step derivation
      1. associate--l+68.2%

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

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

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

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

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

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

      \[\leadsto \color{blue}{{b}^{4}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification70.8%

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

Alternative 5: 56.3% accurate, 8.0× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\left(a \cdot a\right) \cdot 4 + -1\\


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

    1. Initial program 88.3%

      \[\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(3 + a\right)\right)\right) - 1 \]
    2. Step-by-step derivation
      1. associate--l+88.3%

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

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

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

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

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

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

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

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

      \[\leadsto \left(4 \cdot \left(\color{blue}{\left(a \cdot a\right)} \cdot \left(1 - a\right)\right) + {a}^{4}\right) - 1 \]
    8. Taylor expanded in a around 0 55.8%

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

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

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

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

        \[\leadsto \left(4 \cdot {a}^{2} - 4 \cdot \color{blue}{\left(\left(a \cdot a\right) \cdot a\right)}\right) - 1 \]
      5. unpow255.8%

        \[\leadsto \left(4 \cdot {a}^{2} - 4 \cdot \left(\color{blue}{{a}^{2}} \cdot a\right)\right) - 1 \]
      6. associate-*l*55.8%

        \[\leadsto \left(4 \cdot {a}^{2} - \color{blue}{\left(4 \cdot {a}^{2}\right) \cdot a}\right) - 1 \]
      7. unsub-neg55.8%

        \[\leadsto \color{blue}{\left(4 \cdot {a}^{2} + \left(-\left(4 \cdot {a}^{2}\right) \cdot a\right)\right)} - 1 \]
      8. *-rgt-identity55.8%

        \[\leadsto \left(\color{blue}{\left(4 \cdot {a}^{2}\right) \cdot 1} + \left(-\left(4 \cdot {a}^{2}\right) \cdot a\right)\right) - 1 \]
      9. distribute-rgt-neg-out55.8%

        \[\leadsto \left(\left(4 \cdot {a}^{2}\right) \cdot 1 + \color{blue}{\left(4 \cdot {a}^{2}\right) \cdot \left(-a\right)}\right) - 1 \]
      10. distribute-lft-in55.8%

        \[\leadsto \color{blue}{\left(4 \cdot {a}^{2}\right) \cdot \left(1 + \left(-a\right)\right)} - 1 \]
      11. sub-neg55.8%

        \[\leadsto \left(4 \cdot {a}^{2}\right) \cdot \color{blue}{\left(1 - a\right)} - 1 \]
      12. associate-*r*55.8%

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

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

        \[\leadsto 4 \cdot \color{blue}{\left(a \cdot a\right)} - 1 \]
    12. Applied egg-rr55.8%

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

    if 2.5 < a

    1. Initial program 33.3%

      \[\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(3 + a\right)\right)\right) - 1 \]
    2. Step-by-step derivation
      1. associate--l+33.3%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(4 \cdot \left({a}^{2} \cdot \left(1 - a\right)\right) + {a}^{4}\right) - 1} \]
    6. Taylor expanded in a around 0 55.7%

      \[\leadsto \color{blue}{4 \cdot {a}^{2}} - 1 \]
    7. Step-by-step derivation
      1. pow255.7%

        \[\leadsto 4 \cdot \color{blue}{\left(a \cdot a\right)} - 1 \]
    8. Applied egg-rr55.7%

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

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

Alternative 6: 52.1% accurate, 18.3× speedup?

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

\\
\left(a \cdot a\right) \cdot 4 + -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(3 + a\right)\right)\right) - 1 \]
  2. Step-by-step derivation
    1. associate--l+74.1%

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

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

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

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

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

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

    \[\leadsto \color{blue}{\left(4 \cdot \left({a}^{2} \cdot \left(1 - a\right)\right) + {a}^{4}\right) - 1} \]
  6. Taylor expanded in a around 0 53.8%

    \[\leadsto \color{blue}{4 \cdot {a}^{2}} - 1 \]
  7. Step-by-step derivation
    1. pow253.8%

      \[\leadsto 4 \cdot \color{blue}{\left(a \cdot a\right)} - 1 \]
  8. Applied egg-rr53.8%

    \[\leadsto 4 \cdot \color{blue}{\left(a \cdot a\right)} - 1 \]
  9. Final simplification53.8%

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

Reproduce

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