Bouland and Aaronson, Equation (25)

Percentage Accurate: 74.0% → 98.3%
Time: 8.5s
Alternatives: 6
Speedup: 1.1×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 6 alternatives:

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

Initial Program: 74.0% accurate, 1.0× speedup?

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

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

Alternative 1: 98.3% accurate, 0.5× speedup?

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

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


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

    1. Initial program 99.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(1 - 3 \cdot a\right)\right)\right) - 1 \]
    2. Add Preprocessing

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

    1. Initial program 0.0%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{{a}^{4} \cdot \left(1 + 4 \cdot \frac{1}{a}\right)} + -1 \]
    6. Step-by-step derivation
      1. associate-*r/97.2%

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

        \[\leadsto {a}^{4} \cdot \left(1 + \frac{\color{blue}{4}}{a}\right) + -1 \]
    7. Simplified97.2%

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

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

Alternative 2: 93.9% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \leq -290 \lor \neg \left(a \leq 42000000000\right):\\
\;\;\;\;{a}^{3} \cdot \left(a + 4\right) + -1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -290 or 4.2e10 < a

    1. Initial program 45.8%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{{a}^{4} \cdot \left(1 + 4 \cdot \frac{1}{a}\right)} + -1 \]
    6. Step-by-step derivation
      1. associate-*r/95.7%

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

        \[\leadsto {a}^{4} \cdot \left(1 + \frac{\color{blue}{4}}{a}\right) + -1 \]
    7. Simplified95.7%

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

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

    if -290 < a < 4.2e10

    1. Initial program 99.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 93.9% accurate, 1.1× speedup?

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

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

\mathbf{elif}\;a \leq 21000000000:\\
\;\;\;\;-1 + {b}^{4}\\

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


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

    1. Initial program 29.0%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{{a}^{4} \cdot \left(1 + 4 \cdot \frac{1}{a}\right)} + -1 \]
    6. Step-by-step derivation
      1. associate-*r/96.0%

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

        \[\leadsto {a}^{4} \cdot \left(1 + \frac{\color{blue}{4}}{a}\right) + -1 \]
    7. Simplified96.0%

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

    if -290 < a < 2.1e10

    1. Initial program 99.2%

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.1e10 < a

    1. Initial program 63.2%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{{a}^{4} \cdot \left(1 + 4 \cdot \frac{1}{a}\right)} + -1 \]
    6. Step-by-step derivation
      1. associate-*r/95.3%

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

        \[\leadsto {a}^{4} \cdot \left(1 + \frac{\color{blue}{4}}{a}\right) + -1 \]
    7. Simplified95.3%

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

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

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

Alternative 4: 93.7% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \leq -200 \lor \neg \left(a \leq 55000000000\right):\\
\;\;\;\;{a}^{4} + -1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -200 or 5.5e10 < a

    1. Initial program 45.8%

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

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

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

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

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

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

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

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

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

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

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

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

    if -200 < a < 5.5e10

    1. Initial program 99.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 68.4% accurate, 1.3× speedup?

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

\\
{a}^{4} + -1
\end{array}
Derivation
  1. Initial program 73.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(1 - 3 \cdot a\right)\right)\right) - 1 \]
  2. Step-by-step derivation
    1. sub-neg73.7%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{{a}^{4}} + -1 \]
  6. Final simplification69.9%

    \[\leadsto {a}^{4} + -1 \]
  7. Add Preprocessing

Alternative 6: 25.3% accurate, 130.0× speedup?

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

\\
-1
\end{array}
Derivation
  1. Initial program 73.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(1 - 3 \cdot a\right)\right)\right) - 1 \]
  2. Step-by-step derivation
    1. sub-neg73.7%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{{a}^{4} \cdot \left(1 + 4 \cdot \frac{1}{a}\right)} + -1 \]
  6. Step-by-step derivation
    1. associate-*r/70.3%

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

      \[\leadsto {a}^{4} \cdot \left(1 + \frac{\color{blue}{4}}{a}\right) + -1 \]
  7. Simplified70.3%

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

    \[\leadsto \color{blue}{-1} \]
  9. Final simplification24.9%

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

Reproduce

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