Bouland and Aaronson, Equation (26)

Percentage Accurate: 99.9% → 100.0%
Time: 6.8s
Alternatives: 11
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 11 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: 100.0% accurate, 0.4× speedup?

\[\begin{array}{l} \\ {\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \mathsf{fma}\left(b, b \cdot 4, -1\right) \end{array} \]
(FPCore (a b)
 :precision binary64
 (+ (pow (hypot a b) 4.0) (fma b (* b 4.0) -1.0)))
double code(double a, double b) {
	return pow(hypot(a, b), 4.0) + fma(b, (b * 4.0), -1.0);
}
function code(a, b)
	return Float64((hypot(a, b) ^ 4.0) + fma(b, Float64(b * 4.0), -1.0))
end
code[a_, b_] := N[(N[Power[N[Sqrt[a ^ 2 + b ^ 2], $MachinePrecision], 4.0], $MachinePrecision] + N[(b * N[(b * 4.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
{\left(\mathsf{hypot}\left(a, b\right)\right)}^{4} + \mathsf{fma}\left(b, b \cdot 4, -1\right)
\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. Step-by-step derivation
    1. associate--l+99.9%

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

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

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

      \[\leadsto \left(a \cdot a + b \cdot b\right) \cdot \color{blue}{\left({\left(a \cdot a + b \cdot b\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(a \cdot a + b \cdot b\right)}^{\left(\frac{1}{2}\right)}\right)} + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
    5. associate-*r*99.9%

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

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

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

Alternative 2: 99.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ {\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}^{2} + \left(4 \cdot \left(b \cdot b\right) + -1\right) \end{array} \]
(FPCore (a b)
 :precision binary64
 (+ (pow (fma a a (* b b)) 2.0) (+ (* 4.0 (* b b)) -1.0)))
double code(double a, double b) {
	return pow(fma(a, a, (b * b)), 2.0) + ((4.0 * (b * b)) + -1.0);
}
function code(a, b)
	return Float64((fma(a, a, Float64(b * b)) ^ 2.0) + Float64(Float64(4.0 * Float64(b * b)) + -1.0))
end
code[a_, b_] := N[(N[Power[N[(a * a + N[(b * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(4.0 * N[(b * b), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
{\left(\mathsf{fma}\left(a, a, b \cdot b\right)\right)}^{2} + \left(4 \cdot \left(b \cdot b\right) + -1\right)
\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. Step-by-step derivation
    1. associate--l+99.9%

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

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

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

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

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

Alternative 3: 99.9% accurate, 1.0× speedup?

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

\\
\left({\left(b \cdot b + a \cdot a\right)}^{2} + 4 \cdot \left(b \cdot b\right)\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. Final simplification99.9%

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

Alternative 4: 98.1% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 a a) < 5.00000000000000036e-18

    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. Step-by-step derivation
      1. associate--l+100.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left({\left(b \cdot b\right)}^{2} + \left(b \cdot b\right) \cdot 4\right) - 1} \]
      2. unpow-prod-down100.0%

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

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

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

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

    if 5.00000000000000036e-18 < (*.f64 a a)

    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. Taylor expanded in b around 0 87.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(a \cdot a\right) \cdot \left(\left(b \cdot b\right) \cdot 2 + a \cdot a\right)} - 1 \]
      8. associate-*l*95.7%

        \[\leadsto \left(a \cdot a\right) \cdot \left(\color{blue}{b \cdot \left(b \cdot 2\right)} + a \cdot a\right) - 1 \]
      9. add-sqr-sqrt46.0%

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

        \[\leadsto \left(a \cdot a\right) \cdot \left(b \cdot \left(\color{blue}{\sqrt{b \cdot b}} \cdot 2\right) + a \cdot a\right) - 1 \]
      11. metadata-eval83.2%

        \[\leadsto \left(a \cdot a\right) \cdot \left(b \cdot \left(\sqrt{b \cdot b} \cdot \color{blue}{\sqrt{4}}\right) + a \cdot a\right) - 1 \]
      12. sqrt-prod83.2%

        \[\leadsto \left(a \cdot a\right) \cdot \left(b \cdot \color{blue}{\sqrt{\left(b \cdot b\right) \cdot 4}} + a \cdot a\right) - 1 \]
      13. *-commutative83.2%

        \[\leadsto \left(a \cdot a\right) \cdot \left(b \cdot \sqrt{\color{blue}{4 \cdot \left(b \cdot b\right)}} + a \cdot a\right) - 1 \]
      14. sqrt-prod83.2%

        \[\leadsto \left(a \cdot a\right) \cdot \left(b \cdot \color{blue}{\left(\sqrt{4} \cdot \sqrt{b \cdot b}\right)} + a \cdot a\right) - 1 \]
      15. metadata-eval83.2%

        \[\leadsto \left(a \cdot a\right) \cdot \left(b \cdot \left(\color{blue}{2} \cdot \sqrt{b \cdot b}\right) + a \cdot a\right) - 1 \]
      16. sqrt-prod46.0%

        \[\leadsto \left(a \cdot a\right) \cdot \left(b \cdot \left(2 \cdot \color{blue}{\left(\sqrt{b} \cdot \sqrt{b}\right)}\right) + a \cdot a\right) - 1 \]
      17. add-sqr-sqrt95.7%

        \[\leadsto \left(a \cdot a\right) \cdot \left(b \cdot \left(2 \cdot \color{blue}{b}\right) + a \cdot a\right) - 1 \]
    9. Applied egg-rr95.7%

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

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

Alternative 5: 68.1% accurate, 6.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;a \cdot a \leq 4.7 \cdot 10^{-123}:\\
\;\;\;\;-1\\

\mathbf{elif}\;a \cdot a \leq 2.1 \cdot 10^{-55}:\\
\;\;\;\;4 \cdot \left(b \cdot b\right)\\

\mathbf{elif}\;a \cdot a \leq 1:\\
\;\;\;\;-1\\

\mathbf{else}:\\
\;\;\;\;\left(a \cdot a\right) \cdot \left(a \cdot a\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 a a) < 4.7000000000000002e-123 or 2.1000000000000002e-55 < (*.f64 a a) < 1

    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. Step-by-step derivation
      1. associate--l+100.0%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1} \]

    if 4.7000000000000002e-123 < (*.f64 a a) < 2.1000000000000002e-55

    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. Step-by-step derivation
      1. associate--l+100.0%

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

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

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

        \[\leadsto \color{blue}{\left({\left(a \cdot a + b \cdot b\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(a \cdot a + b \cdot b\right)}^{\left(\frac{1}{2}\right)}\right)} \cdot \left(a \cdot a + b \cdot b\right) + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
      5. associate-*l*100.0%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{hypot}\left(a, b\right), {\left(\mathsf{hypot}\left(a, b\right)\right)}^{3}, \mathsf{fma}\left(b \cdot b, 4, -1\right)\right)} \]
    4. Taylor expanded in a around inf 83.8%

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

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

        \[\leadsto 4 \cdot \color{blue}{\left(b \cdot b\right)} \]
    7. Simplified63.5%

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

    if 1 < (*.f64 a a)

    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. Step-by-step derivation
      1. associate--l+99.8%

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

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

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

        \[\leadsto \color{blue}{\left({\left(a \cdot a + b \cdot b\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(a \cdot a + b \cdot b\right)}^{\left(\frac{1}{2}\right)}\right)} \cdot \left(a \cdot a + b \cdot b\right) + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
      5. associate-*l*99.8%

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

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

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

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

      \[\leadsto \color{blue}{{a}^{4}} \]
    6. Step-by-step derivation
      1. metadata-eval86.9%

        \[\leadsto {a}^{\color{blue}{\left(2 + 2\right)}} \]
      2. pow-prod-up86.8%

        \[\leadsto \color{blue}{{a}^{2} \cdot {a}^{2}} \]
      3. pow286.8%

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

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

      \[\leadsto \color{blue}{\left(a \cdot a\right) \cdot \left(a \cdot a\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification72.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot a \leq 4.7 \cdot 10^{-123}:\\ \;\;\;\;-1\\ \mathbf{elif}\;a \cdot a \leq 2.1 \cdot 10^{-55}:\\ \;\;\;\;4 \cdot \left(b \cdot b\right)\\ \mathbf{elif}\;a \cdot a \leq 1:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot a\right) \cdot \left(a \cdot a\right)\\ \end{array} \]

Alternative 6: 98.0% accurate, 6.1× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 a a) < 5.00000000000000036e-18

    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. Step-by-step derivation
      1. associate--l+100.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left({\left(b \cdot b\right)}^{2} + \left(b \cdot b\right) \cdot 4\right) - 1} \]
      2. unpow-prod-down100.0%

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

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

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

      \[\leadsto \color{blue}{\left({b}^{4} + \left(b \cdot b\right) \cdot 4\right) - 1} \]
    9. Step-by-step derivation
      1. +-commutative100.0%

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

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

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

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

        \[\leadsto \left(\left(b \cdot b\right) \cdot 4 + \left(b \cdot b\right) \cdot \color{blue}{\left(b \cdot b\right)}\right) - 1 \]
      6. distribute-lft-out100.0%

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

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

    if 5.00000000000000036e-18 < (*.f64 a a)

    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. Taylor expanded in b around 0 87.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(a \cdot a\right) \cdot \left(\left(b \cdot b\right) \cdot 2 + a \cdot a\right)} - 1 \]
      8. associate-*l*95.7%

        \[\leadsto \left(a \cdot a\right) \cdot \left(\color{blue}{b \cdot \left(b \cdot 2\right)} + a \cdot a\right) - 1 \]
      9. add-sqr-sqrt46.0%

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

        \[\leadsto \left(a \cdot a\right) \cdot \left(b \cdot \left(\color{blue}{\sqrt{b \cdot b}} \cdot 2\right) + a \cdot a\right) - 1 \]
      11. metadata-eval83.2%

        \[\leadsto \left(a \cdot a\right) \cdot \left(b \cdot \left(\sqrt{b \cdot b} \cdot \color{blue}{\sqrt{4}}\right) + a \cdot a\right) - 1 \]
      12. sqrt-prod83.2%

        \[\leadsto \left(a \cdot a\right) \cdot \left(b \cdot \color{blue}{\sqrt{\left(b \cdot b\right) \cdot 4}} + a \cdot a\right) - 1 \]
      13. *-commutative83.2%

        \[\leadsto \left(a \cdot a\right) \cdot \left(b \cdot \sqrt{\color{blue}{4 \cdot \left(b \cdot b\right)}} + a \cdot a\right) - 1 \]
      14. sqrt-prod83.2%

        \[\leadsto \left(a \cdot a\right) \cdot \left(b \cdot \color{blue}{\left(\sqrt{4} \cdot \sqrt{b \cdot b}\right)} + a \cdot a\right) - 1 \]
      15. metadata-eval83.2%

        \[\leadsto \left(a \cdot a\right) \cdot \left(b \cdot \left(\color{blue}{2} \cdot \sqrt{b \cdot b}\right) + a \cdot a\right) - 1 \]
      16. sqrt-prod46.0%

        \[\leadsto \left(a \cdot a\right) \cdot \left(b \cdot \left(2 \cdot \color{blue}{\left(\sqrt{b} \cdot \sqrt{b}\right)}\right) + a \cdot a\right) - 1 \]
      17. add-sqr-sqrt95.7%

        \[\leadsto \left(a \cdot a\right) \cdot \left(b \cdot \left(2 \cdot \color{blue}{b}\right) + a \cdot a\right) - 1 \]
    9. Applied egg-rr95.7%

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

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

Alternative 7: 94.5% accurate, 7.7× speedup?

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

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

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


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

    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. Step-by-step derivation
      1. associate--l+99.8%

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

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

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

        \[\leadsto \color{blue}{\left({\left(a \cdot a + b \cdot b\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(a \cdot a + b \cdot b\right)}^{\left(\frac{1}{2}\right)}\right)} \cdot \left(a \cdot a + b \cdot b\right) + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
      5. associate-*l*99.9%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{hypot}\left(a, b\right), {\left(\mathsf{hypot}\left(a, b\right)\right)}^{3}, \mathsf{fma}\left(b \cdot b, 4, -1\right)\right)} \]
    4. Taylor expanded in b around 0 98.6%

      \[\leadsto \color{blue}{{a}^{4} - 1} \]
    5. Step-by-step derivation
      1. metadata-eval48.7%

        \[\leadsto {a}^{\color{blue}{\left(2 + 2\right)}} \]
      2. pow-prod-up48.6%

        \[\leadsto \color{blue}{{a}^{2} \cdot {a}^{2}} \]
      3. pow248.6%

        \[\leadsto \color{blue}{\left(a \cdot a\right)} \cdot {a}^{2} \]
      4. pow248.6%

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

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

    if 6.6e20 < (*.f64 b b)

    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. Step-by-step derivation
      1. associate--l+100.0%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left({\left(b \cdot b\right)}^{2} + \left(b \cdot b\right) \cdot 4\right) - 1} \]
      2. unpow-prod-down91.8%

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

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

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

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

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

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

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

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

        \[\leadsto \left(\left(b \cdot b\right) \cdot 4 + \left(b \cdot b\right) \cdot \color{blue}{\left(b \cdot b\right)}\right) - 1 \]
      6. distribute-lft-out91.8%

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

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

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

Alternative 8: 84.5% accurate, 8.9× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;4 \cdot \left(b \cdot b\right)\\


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

    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. Step-by-step derivation
      1. associate--l+99.8%

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

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

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

        \[\leadsto \color{blue}{\left({\left(a \cdot a + b \cdot b\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(a \cdot a + b \cdot b\right)}^{\left(\frac{1}{2}\right)}\right)} \cdot \left(a \cdot a + b \cdot b\right) + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
      5. associate-*l*99.9%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{hypot}\left(a, b\right), {\left(\mathsf{hypot}\left(a, b\right)\right)}^{3}, \mathsf{fma}\left(b \cdot b, 4, -1\right)\right)} \]
    4. Taylor expanded in b around 0 82.1%

      \[\leadsto \color{blue}{{a}^{4} - 1} \]
    5. Step-by-step derivation
      1. metadata-eval47.2%

        \[\leadsto {a}^{\color{blue}{\left(2 + 2\right)}} \]
      2. pow-prod-up47.1%

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

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

        \[\leadsto \left(a \cdot a\right) \cdot \color{blue}{\left(a \cdot a\right)} \]
    6. Applied egg-rr82.0%

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

    if 2.60000000000000008e306 < (*.f64 b b)

    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. Step-by-step derivation
      1. associate--l+100.0%

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

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

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

        \[\leadsto \color{blue}{\left({\left(a \cdot a + b \cdot b\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(a \cdot a + b \cdot b\right)}^{\left(\frac{1}{2}\right)}\right)} \cdot \left(a \cdot a + b \cdot b\right) + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
      5. associate-*l*100.0%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{hypot}\left(a, b\right), {\left(\mathsf{hypot}\left(a, b\right)\right)}^{3}, \mathsf{fma}\left(b \cdot b, 4, -1\right)\right)} \]
    4. Taylor expanded in a around inf 81.4%

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

      \[\leadsto \color{blue}{4 \cdot {b}^{2}} \]
    6. Step-by-step derivation
      1. unpow2100.0%

        \[\leadsto 4 \cdot \color{blue}{\left(b \cdot b\right)} \]
    7. Simplified100.0%

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

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

Alternative 9: 82.6% accurate, 10.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\left(a \cdot a\right) \cdot \left(a \cdot a\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 a a) < 53

    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. Taylor expanded in b around 0 80.6%

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

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

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

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

        \[\leadsto {a}^{\color{blue}{\left(2 + 2\right)}} \]
      2. pow-prod-up2.4%

        \[\leadsto \color{blue}{{a}^{2} \cdot {a}^{2}} \]
      3. pow22.4%

        \[\leadsto \color{blue}{\left(a \cdot a\right)} \cdot {a}^{2} \]
      4. pow22.4%

        \[\leadsto \left(a \cdot a\right) \cdot \color{blue}{\left(a \cdot a\right)} \]
    6. Applied egg-rr80.6%

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

      \[\leadsto \color{blue}{4 \cdot {b}^{2}} - 1 \]
    8. Step-by-step derivation
      1. unpow280.3%

        \[\leadsto 4 \cdot \color{blue}{\left(b \cdot b\right)} - 1 \]
    9. Simplified80.3%

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

    if 53 < (*.f64 a a)

    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. Step-by-step derivation
      1. associate--l+99.8%

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

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

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

        \[\leadsto \color{blue}{\left({\left(a \cdot a + b \cdot b\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(a \cdot a + b \cdot b\right)}^{\left(\frac{1}{2}\right)}\right)} \cdot \left(a \cdot a + b \cdot b\right) + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
      5. associate-*l*99.8%

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

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

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

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

      \[\leadsto \color{blue}{{a}^{4}} \]
    6. Step-by-step derivation
      1. metadata-eval86.9%

        \[\leadsto {a}^{\color{blue}{\left(2 + 2\right)}} \]
      2. pow-prod-up86.8%

        \[\leadsto \color{blue}{{a}^{2} \cdot {a}^{2}} \]
      3. pow286.8%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \cdot a \leq 53:\\ \;\;\;\;4 \cdot \left(b \cdot b\right) + -1\\ \mathbf{else}:\\ \;\;\;\;\left(a \cdot a\right) \cdot \left(a \cdot a\right)\\ \end{array} \]

Alternative 10: 38.2% accurate, 16.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.49:\\
\;\;\;\;-1\\

\mathbf{else}:\\
\;\;\;\;4 \cdot \left(b \cdot b\right)\\


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

    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. Step-by-step derivation
      1. associate--l+99.8%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1} \]

    if 0.48999999999999999 < b

    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. Step-by-step derivation
      1. associate--l+100.0%

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

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

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

        \[\leadsto \color{blue}{\left({\left(a \cdot a + b \cdot b\right)}^{\left(\frac{1}{2}\right)} \cdot {\left(a \cdot a + b \cdot b\right)}^{\left(\frac{1}{2}\right)}\right)} \cdot \left(a \cdot a + b \cdot b\right) + \left(4 \cdot \left(b \cdot b\right) - 1\right) \]
      5. associate-*l*100.0%

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{hypot}\left(a, b\right), {\left(\mathsf{hypot}\left(a, b\right)\right)}^{3}, \mathsf{fma}\left(b \cdot b, 4, -1\right)\right)} \]
    4. Taylor expanded in a around inf 55.3%

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

      \[\leadsto \color{blue}{4 \cdot {b}^{2}} \]
    6. Step-by-step derivation
      1. unpow265.0%

        \[\leadsto 4 \cdot \color{blue}{\left(b \cdot b\right)} \]
    7. Simplified65.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq 0.49:\\ \;\;\;\;-1\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \left(b \cdot b\right)\\ \end{array} \]

Alternative 11: 24.9% 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. Step-by-step derivation
    1. associate--l+99.9%

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{-1} \]
  8. Final simplification26.3%

    \[\leadsto -1 \]

Reproduce

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