Bouland and Aaronson, Equation (26)

Percentage Accurate: 99.9% → 99.9%
Time: 4.7s
Alternatives: 8
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \end{array} \]
(FPCore (a b)
 :precision binary64
 (- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))
double code(double a, double b) {
	return (pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 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 * (b * b))) - 1.0d0
end function
public static double code(double a, double b) {
	return (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0;
}
def code(a, b):
	return (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0
function code(a, b)
	return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(b * b))) - 1.0)
end
function tmp = code(a, b)
	tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (b * b))) - 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[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}

\\
\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\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 8 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: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \end{array} \]
(FPCore (a b)
 :precision binary64
 (- (+ (pow (+ (* a a) (* b b)) 2.0) (* 4.0 (* b b))) 1.0))
double code(double a, double b) {
	return (pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 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 * (b * b))) - 1.0d0
end function
public static double code(double a, double b) {
	return (Math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0;
}
def code(a, b):
	return (math.pow(((a * a) + (b * b)), 2.0) + (4.0 * (b * b))) - 1.0
function code(a, b)
	return Float64(Float64((Float64(Float64(a * a) + Float64(b * b)) ^ 2.0) + Float64(4.0 * Float64(b * b))) - 1.0)
end
function tmp = code(a, b)
	tmp = ((((a * a) + (b * b)) ^ 2.0) + (4.0 * (b * b))) - 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[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 99.9% accurate, 1.0× speedup?

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

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

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

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

Alternative 2: 65.1% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(b \cdot b\right) \cdot 4 + -1\\ \mathbf{if}\;a \leq 2.4 \cdot 10^{-168}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;a \leq 4.9 \cdot 10^{-135}:\\ \;\;\;\;{b}^{4}\\ \mathbf{elif}\;a \leq 1.55 \cdot 10^{-55}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;a \leq 6.6 \cdot 10^{-31}:\\ \;\;\;\;{b}^{4}\\ \mathbf{elif}\;a \leq 63:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;{a}^{4}\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (let* ((t_0 (+ (* (* b b) 4.0) -1.0)))
   (if (<= a 2.4e-168)
     t_0
     (if (<= a 4.9e-135)
       (pow b 4.0)
       (if (<= a 1.55e-55)
         t_0
         (if (<= a 6.6e-31) (pow b 4.0) (if (<= a 63.0) t_0 (pow a 4.0))))))))
double code(double a, double b) {
	double t_0 = ((b * b) * 4.0) + -1.0;
	double tmp;
	if (a <= 2.4e-168) {
		tmp = t_0;
	} else if (a <= 4.9e-135) {
		tmp = pow(b, 4.0);
	} else if (a <= 1.55e-55) {
		tmp = t_0;
	} else if (a <= 6.6e-31) {
		tmp = pow(b, 4.0);
	} else if (a <= 63.0) {
		tmp = t_0;
	} else {
		tmp = pow(a, 4.0);
	}
	return tmp;
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: t_0
    real(8) :: tmp
    t_0 = ((b * b) * 4.0d0) + (-1.0d0)
    if (a <= 2.4d-168) then
        tmp = t_0
    else if (a <= 4.9d-135) then
        tmp = b ** 4.0d0
    else if (a <= 1.55d-55) then
        tmp = t_0
    else if (a <= 6.6d-31) then
        tmp = b ** 4.0d0
    else if (a <= 63.0d0) then
        tmp = t_0
    else
        tmp = a ** 4.0d0
    end if
    code = tmp
end function
public static double code(double a, double b) {
	double t_0 = ((b * b) * 4.0) + -1.0;
	double tmp;
	if (a <= 2.4e-168) {
		tmp = t_0;
	} else if (a <= 4.9e-135) {
		tmp = Math.pow(b, 4.0);
	} else if (a <= 1.55e-55) {
		tmp = t_0;
	} else if (a <= 6.6e-31) {
		tmp = Math.pow(b, 4.0);
	} else if (a <= 63.0) {
		tmp = t_0;
	} else {
		tmp = Math.pow(a, 4.0);
	}
	return tmp;
}
def code(a, b):
	t_0 = ((b * b) * 4.0) + -1.0
	tmp = 0
	if a <= 2.4e-168:
		tmp = t_0
	elif a <= 4.9e-135:
		tmp = math.pow(b, 4.0)
	elif a <= 1.55e-55:
		tmp = t_0
	elif a <= 6.6e-31:
		tmp = math.pow(b, 4.0)
	elif a <= 63.0:
		tmp = t_0
	else:
		tmp = math.pow(a, 4.0)
	return tmp
function code(a, b)
	t_0 = Float64(Float64(Float64(b * b) * 4.0) + -1.0)
	tmp = 0.0
	if (a <= 2.4e-168)
		tmp = t_0;
	elseif (a <= 4.9e-135)
		tmp = b ^ 4.0;
	elseif (a <= 1.55e-55)
		tmp = t_0;
	elseif (a <= 6.6e-31)
		tmp = b ^ 4.0;
	elseif (a <= 63.0)
		tmp = t_0;
	else
		tmp = a ^ 4.0;
	end
	return tmp
end
function tmp_2 = code(a, b)
	t_0 = ((b * b) * 4.0) + -1.0;
	tmp = 0.0;
	if (a <= 2.4e-168)
		tmp = t_0;
	elseif (a <= 4.9e-135)
		tmp = b ^ 4.0;
	elseif (a <= 1.55e-55)
		tmp = t_0;
	elseif (a <= 6.6e-31)
		tmp = b ^ 4.0;
	elseif (a <= 63.0)
		tmp = t_0;
	else
		tmp = a ^ 4.0;
	end
	tmp_2 = tmp;
end
code[a_, b_] := Block[{t$95$0 = N[(N[(N[(b * b), $MachinePrecision] * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]}, If[LessEqual[a, 2.4e-168], t$95$0, If[LessEqual[a, 4.9e-135], N[Power[b, 4.0], $MachinePrecision], If[LessEqual[a, 1.55e-55], t$95$0, If[LessEqual[a, 6.6e-31], N[Power[b, 4.0], $MachinePrecision], If[LessEqual[a, 63.0], t$95$0, N[Power[a, 4.0], $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(b \cdot b\right) \cdot 4 + -1\\
\mathbf{if}\;a \leq 2.4 \cdot 10^{-168}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;a \leq 4.9 \cdot 10^{-135}:\\
\;\;\;\;{b}^{4}\\

\mathbf{elif}\;a \leq 1.55 \cdot 10^{-55}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;a \leq 6.6 \cdot 10^{-31}:\\
\;\;\;\;{b}^{4}\\

\mathbf{elif}\;a \leq 63:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if a < 2.3999999999999999e-168 or 4.9000000000000003e-135 < a < 1.54999999999999998e-55 or 6.5999999999999998e-31 < a < 63

    1. Initial program 99.9%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Add Preprocessing
    3. Taylor expanded in a around inf 82.8%

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

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

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

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

    if 2.3999999999999999e-168 < a < 4.9000000000000003e-135 or 1.54999999999999998e-55 < a < 6.5999999999999998e-31

    1. Initial program 99.8%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0 100.0%

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

      \[\leadsto \color{blue}{{b}^{4}} - 1 \]
    5. Taylor expanded in b around inf 93.5%

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

    if 63 < a

    1. Initial program 100.0%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Add Preprocessing
    3. Taylor expanded in a around inf 94.7%

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

      \[\leadsto \color{blue}{{a}^{4}} - 1 \]
    5. Taylor expanded in a around inf 92.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq 2.4 \cdot 10^{-168}:\\ \;\;\;\;\left(b \cdot b\right) \cdot 4 + -1\\ \mathbf{elif}\;a \leq 4.9 \cdot 10^{-135}:\\ \;\;\;\;{b}^{4}\\ \mathbf{elif}\;a \leq 1.55 \cdot 10^{-55}:\\ \;\;\;\;\left(b \cdot b\right) \cdot 4 + -1\\ \mathbf{elif}\;a \leq 6.6 \cdot 10^{-31}:\\ \;\;\;\;{b}^{4}\\ \mathbf{elif}\;a \leq 63:\\ \;\;\;\;\left(b \cdot b\right) \cdot 4 + -1\\ \mathbf{else}:\\ \;\;\;\;{a}^{4}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 83.3% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < 4.0000000000000001e-8

    1. Initial program 99.8%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0 79.3%

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

    if 4.0000000000000001e-8 < a

    1. Initial program 100.0%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Add Preprocessing
    3. Taylor expanded in a around inf 95.1%

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

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

Alternative 4: 82.7% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < 4.0000000000000001e-8

    1. Initial program 99.8%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0 79.3%

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

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

    if 4.0000000000000001e-8 < a

    1. Initial program 100.0%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Add Preprocessing
    3. Taylor expanded in a around inf 95.1%

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

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

Alternative 5: 93.7% accurate, 1.0× speedup?

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

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

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


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

    1. Initial program 99.9%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Add Preprocessing
    3. Taylor expanded in a around inf 100.0%

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

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

    if 5.0000000000000004e-16 < (*.f64 b b)

    1. Initial program 99.9%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0 92.3%

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

      \[\leadsto \color{blue}{{b}^{4}} - 1 \]
    5. Taylor expanded in b around inf 91.4%

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

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

Alternative 6: 66.6% accurate, 1.1× speedup?

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

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

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


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

    1. Initial program 99.8%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Add Preprocessing
    3. Taylor expanded in a around inf 79.1%

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

      \[\leadsto \color{blue}{4 \cdot {b}^{2}} - 1 \]
    5. Step-by-step derivation
      1. unpow254.9%

        \[\leadsto 4 \cdot \color{blue}{\left(b \cdot b\right)} - 1 \]
    6. Applied egg-rr54.9%

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

    if 165 < a

    1. Initial program 100.0%

      \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
    2. Add Preprocessing
    3. Taylor expanded in a around inf 94.7%

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

      \[\leadsto \color{blue}{{a}^{4}} - 1 \]
    5. Taylor expanded in a around inf 92.7%

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

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

Alternative 7: 51.4% accurate, 16.6× speedup?

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

\\
\left(b \cdot b\right) \cdot 4 + -1
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
  2. Add Preprocessing
  3. Taylor expanded in a around inf 82.2%

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

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

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

    \[\leadsto 4 \cdot \color{blue}{\left(b \cdot b\right)} - 1 \]
  7. Final simplification48.7%

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

Alternative 8: 25.0% accurate, 116.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 99.9%

    \[\left({\left(a \cdot a + b \cdot b\right)}^{2} + 4 \cdot \left(b \cdot b\right)\right) - 1 \]
  2. Add Preprocessing
  3. Taylor expanded in a around inf 82.2%

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

    \[\leadsto \color{blue}{4 \cdot {b}^{2}} - 1 \]
  5. Taylor expanded in b around 0 21.9%

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

Reproduce

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