Bouland and Aaronson, Equation (24)

Percentage Accurate: 73.5% → 98.0%
Time: 6.8s
Alternatives: 7
Speedup: 6.4×

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 7 alternatives:

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

Initial Program: 73.5% 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.0% accurate, 1.0× speedup?

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

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

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


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

    1. Initial program 82.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. Add Preprocessing
    3. Taylor expanded in a around 0 96.4%

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

    if 9.99999999999999978e122 < (*.f64 b b)

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

        \[\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. fma-define57.8%

        \[\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) \]
      3. distribute-rgt-in56.8%

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

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

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

      \[\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, b \cdot \left(b \cdot \left(a + 3\right)\right)\right) - 1\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in a around 0 98.2%

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

        \[\leadsto \left(12 \cdot \color{blue}{\left(b \cdot b\right)} + {b}^{4}\right) - 1 \]
    7. Applied egg-rr98.2%

      \[\leadsto \left(12 \cdot \color{blue}{\left(b \cdot b\right)} + {b}^{4}\right) - 1 \]
    8. Taylor expanded in b around inf 98.2%

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

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

Alternative 2: 94.5% accurate, 1.1× speedup?

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

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

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


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

    1. Initial program 82.7%

      \[\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+82.7%

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

        \[\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) \]
      3. distribute-rgt-in82.7%

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

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

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

      \[\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, b \cdot \left(b \cdot \left(a + 3\right)\right)\right) - 1\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in b around 0 81.1%

      \[\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 98.2%

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

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

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

    if 5e10 < (*.f64 b b)

    1. Initial program 62.4%

      \[\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+62.4%

        \[\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. fma-define62.4%

        \[\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) \]
      3. distribute-rgt-in61.6%

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

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

        \[\leadsto {\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}^{2} + \left(\color{blue}{4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 - a\right) + \left(\left(-b\right) \cdot \left(-b\right)\right) \cdot \left(3 + a\right)\right)} - 1\right) \]
    3. Simplified65.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, b \cdot \left(b \cdot \left(a + 3\right)\right)\right) - 1\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in a around 0 92.6%

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

        \[\leadsto \left(12 \cdot \color{blue}{\left(b \cdot b\right)} + {b}^{4}\right) - 1 \]
    7. Applied egg-rr92.6%

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

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

Alternative 3: 94.4% accurate, 1.2× speedup?

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

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

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


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

    1. Initial program 82.7%

      \[\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+82.7%

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

        \[\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) \]
      3. distribute-rgt-in82.7%

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

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

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

      \[\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, b \cdot \left(b \cdot \left(a + 3\right)\right)\right) - 1\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in b around 0 81.1%

      \[\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 98.2%

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

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

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

    if 5e10 < (*.f64 b b)

    1. Initial program 62.4%

      \[\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+62.4%

        \[\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. fma-define62.4%

        \[\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) \]
      3. distribute-rgt-in61.6%

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

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

        \[\leadsto {\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}^{2} + \left(\color{blue}{4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 - a\right) + \left(\left(-b\right) \cdot \left(-b\right)\right) \cdot \left(3 + a\right)\right)} - 1\right) \]
    3. Simplified65.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, b \cdot \left(b \cdot \left(a + 3\right)\right)\right) - 1\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in a around 0 92.6%

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

        \[\leadsto \left(12 \cdot \color{blue}{\left(b \cdot b\right)} + {b}^{4}\right) - 1 \]
    7. Applied egg-rr92.6%

      \[\leadsto \left(12 \cdot \color{blue}{\left(b \cdot b\right)} + {b}^{4}\right) - 1 \]
    8. Taylor expanded in b around inf 92.6%

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

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

Alternative 4: 84.8% accurate, 6.4× speedup?

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

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

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


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

    1. Initial program 77.4%

      \[\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+77.4%

        \[\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. fma-define77.4%

        \[\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) \]
      3. distribute-rgt-in76.9%

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

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

        \[\leadsto {\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}^{2} + \left(\color{blue}{4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 - a\right) + \left(\left(-b\right) \cdot \left(-b\right)\right) \cdot \left(3 + a\right)\right)} - 1\right) \]
    3. Simplified78.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, b \cdot \left(b \cdot \left(a + 3\right)\right)\right) - 1\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in b around 0 64.4%

      \[\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 81.4%

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

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

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

    if 1.4999999999999999e307 < (*.f64 b b)

    1. Initial program 59.4%

      \[\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+59.4%

        \[\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. fma-define59.4%

        \[\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) \]
      3. distribute-rgt-in59.4%

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

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

        \[\leadsto {\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}^{2} + \left(\color{blue}{4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 - a\right) + \left(\left(-b\right) \cdot \left(-b\right)\right) \cdot \left(3 + a\right)\right)} - 1\right) \]
    3. Simplified62.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, b \cdot \left(b \cdot \left(a + 3\right)\right)\right) - 1\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in a around 0 100.0%

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

      \[\leadsto \color{blue}{12 \cdot {b}^{2}} - 1 \]
    7. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{{b}^{2} \cdot 12} - 1 \]
    8. Simplified100.0%

      \[\leadsto \color{blue}{{b}^{2} \cdot 12} - 1 \]
    9. Step-by-step derivation
      1. pow2100.0%

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

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

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

Alternative 5: 69.2% accurate, 9.1× speedup?

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

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

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


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

    1. Initial program 77.4%

      \[\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+77.4%

        \[\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. fma-define77.4%

        \[\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) \]
      3. distribute-rgt-in76.9%

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

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

        \[\leadsto {\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}^{2} + \left(\color{blue}{4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 - a\right) + \left(\left(-b\right) \cdot \left(-b\right)\right) \cdot \left(3 + a\right)\right)} - 1\right) \]
    3. Simplified78.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, b \cdot \left(b \cdot \left(a + 3\right)\right)\right) - 1\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in b around 0 64.4%

      \[\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 61.4%

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

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

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

    if 1.01999999999999998e306 < (*.f64 b b)

    1. Initial program 59.4%

      \[\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+59.4%

        \[\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. fma-define59.4%

        \[\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) \]
      3. distribute-rgt-in59.4%

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

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

        \[\leadsto {\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}^{2} + \left(\color{blue}{4 \cdot \left(\left(a \cdot a\right) \cdot \left(1 - a\right) + \left(\left(-b\right) \cdot \left(-b\right)\right) \cdot \left(3 + a\right)\right)} - 1\right) \]
    3. Simplified62.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, b \cdot \left(b \cdot \left(a + 3\right)\right)\right) - 1\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in a around 0 100.0%

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

      \[\leadsto \color{blue}{12 \cdot {b}^{2}} - 1 \]
    7. Step-by-step derivation
      1. *-commutative100.0%

        \[\leadsto \color{blue}{{b}^{2} \cdot 12} - 1 \]
    8. Simplified100.0%

      \[\leadsto \color{blue}{{b}^{2} \cdot 12} - 1 \]
    9. Step-by-step derivation
      1. pow2100.0%

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

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

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

Alternative 6: 51.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 72.6%

    \[\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+72.6%

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

      \[\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) \]
    3. distribute-rgt-in72.2%

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

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

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

    \[\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, b \cdot \left(b \cdot \left(a + 3\right)\right)\right) - 1\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in b around 0 51.6%

    \[\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 49.6%

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

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

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

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

Alternative 7: 25.0% accurate, 128.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 72.6%

    \[\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+72.6%

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

      \[\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) \]
    3. distribute-rgt-in72.2%

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

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

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

    \[\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, b \cdot \left(b \cdot \left(a + 3\right)\right)\right) - 1\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in a around 0 71.3%

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

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

Reproduce

?
herbie shell --seed 2024188 
(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))