Bouland and Aaronson, Equation (26)

Percentage Accurate: 99.9% → 100.0%
Time: 6.1s
Alternatives: 14
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 14 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: 98.0% accurate, 1.0× speedup?

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

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

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


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

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

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

    if 0.0050000000000000001 < (*.f64 b b)

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

        \[\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. Taylor expanded in b around inf 96.6%

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

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

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

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

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

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

Alternative 3: 99.9% accurate, 1.0× speedup?

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

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

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

Alternative 4: 94.2% accurate, 1.0× speedup?

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

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

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


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

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

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

    if 0.0050000000000000001 < (*.f64 b b)

    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 a around 0 51.2%

      \[\leadsto \mathsf{fma}\left(\mathsf{hypot}\left(a, b\right), \color{blue}{{b}^{3}}, \mathsf{fma}\left(b \cdot b, 4, -1\right)\right) \]
    5. Step-by-step derivation
      1. fma-udef51.2%

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

        \[\leadsto \mathsf{hypot}\left(a, b\right) \cdot {b}^{3} + \color{blue}{\left(\left(b \cdot b\right) \cdot 4 + -1\right)} \]
      3. associate-+r+51.2%

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 94.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \cdot b \leq 0.005:\\ \;\;\;\;-1 + {a}^{4}\\ \mathbf{else}:\\ \;\;\;\;-1 + b \cdot \left(b \cdot \mathsf{fma}\left(b, b, 4\right)\right)\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= (* b b) 0.005)
   (+ -1.0 (pow a 4.0))
   (+ -1.0 (* b (* b (fma b b 4.0))))))
double code(double a, double b) {
	double tmp;
	if ((b * b) <= 0.005) {
		tmp = -1.0 + pow(a, 4.0);
	} else {
		tmp = -1.0 + (b * (b * fma(b, b, 4.0)));
	}
	return tmp;
}
function code(a, b)
	tmp = 0.0
	if (Float64(b * b) <= 0.005)
		tmp = Float64(-1.0 + (a ^ 4.0));
	else
		tmp = Float64(-1.0 + Float64(b * Float64(b * fma(b, b, 4.0))));
	end
	return tmp
end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 0.005], N[(-1.0 + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision], N[(-1.0 + N[(b * N[(b * N[(b * b + 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


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

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

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

    if 0.0050000000000000001 < (*.f64 b b)

    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 a around 0 51.2%

      \[\leadsto \mathsf{fma}\left(\mathsf{hypot}\left(a, b\right), \color{blue}{{b}^{3}}, \mathsf{fma}\left(b \cdot b, 4, -1\right)\right) \]
    5. Step-by-step derivation
      1. fma-udef51.2%

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

        \[\leadsto \mathsf{hypot}\left(a, b\right) \cdot {b}^{3} + \color{blue}{\left(\left(b \cdot b\right) \cdot 4 + -1\right)} \]
      3. associate-+r+51.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left({b}^{3} \cdot b + \color{blue}{\left(b \cdot 4\right) \cdot b}\right) + -1 \]
      7. distribute-rgt-in92.1%

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

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

        \[\leadsto b \cdot \color{blue}{\left(b \cdot \left(b \cdot b + 4\right)\right)} + -1 \]
      10. fma-udef92.1%

        \[\leadsto b \cdot \left(b \cdot \color{blue}{\mathsf{fma}\left(b, b, 4\right)}\right) + -1 \]
    11. Simplified92.1%

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

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

Alternative 6: 94.1% accurate, 1.0× speedup?

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

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

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


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

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

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

    if 0.0050000000000000001 < (*.f64 b b)

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

        \[\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. Taylor expanded in b around inf 96.6%

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

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

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

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

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

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

        \[\leadsto {b}^{4} + 4 \cdot \color{blue}{\left(b \cdot b\right)} \]
    9. Simplified90.9%

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

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

Alternative 7: 94.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \cdot b \leq 0.005:\\ \;\;\;\;-1 + {a}^{4}\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(b \cdot \mathsf{fma}\left(b, b, 4\right)\right)\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= (* b b) 0.005) (+ -1.0 (pow a 4.0)) (* b (* b (fma b b 4.0)))))
double code(double a, double b) {
	double tmp;
	if ((b * b) <= 0.005) {
		tmp = -1.0 + pow(a, 4.0);
	} else {
		tmp = b * (b * fma(b, b, 4.0));
	}
	return tmp;
}
function code(a, b)
	tmp = 0.0
	if (Float64(b * b) <= 0.005)
		tmp = Float64(-1.0 + (a ^ 4.0));
	else
		tmp = Float64(b * Float64(b * fma(b, b, 4.0)));
	end
	return tmp
end
code[a_, b_] := If[LessEqual[N[(b * b), $MachinePrecision], 0.005], N[(-1.0 + N[Power[a, 4.0], $MachinePrecision]), $MachinePrecision], N[(b * N[(b * N[(b * b + 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


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

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

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

    if 0.0050000000000000001 < (*.f64 b b)

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

        \[\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. Taylor expanded in b around inf 96.6%

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

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

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

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

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

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

        \[\leadsto {b}^{4} + 4 \cdot \color{blue}{\left(b \cdot b\right)} \]
    9. Simplified90.9%

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

      \[\leadsto \color{blue}{{b}^{4} + 4 \cdot {b}^{2}} \]
    11. Step-by-step derivation
      1. metadata-eval90.9%

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

        \[\leadsto \color{blue}{{b}^{2} \cdot {b}^{2}} + 4 \cdot {b}^{2} \]
      3. unpow290.8%

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

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

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

        \[\leadsto \color{blue}{\left(b \cdot b\right) \cdot \left(b \cdot b + 4\right)} \]
      7. fma-udef90.8%

        \[\leadsto \left(b \cdot b\right) \cdot \color{blue}{\mathsf{fma}\left(b, b, 4\right)} \]
      8. associate-*l*90.8%

        \[\leadsto \color{blue}{b \cdot \left(b \cdot \mathsf{fma}\left(b, b, 4\right)\right)} \]
    12. Simplified90.8%

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

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

Alternative 8: 63.6% accurate, 1.1× speedup?

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

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

\mathbf{elif}\;a \leq 8.5 \cdot 10^{-108}:\\
\;\;\;\;\left(b \cdot b\right) \cdot \left(4 + b \cdot b\right)\\

\mathbf{elif}\;a \leq 8:\\
\;\;\;\;-1 + \left(b \cdot b\right) \cdot \left(4 + a \cdot b\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if a < 7.8000000000000002e-156

    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 \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.9%

        \[\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 a around 0 55.7%

      \[\leadsto \mathsf{fma}\left(\mathsf{hypot}\left(a, b\right), \color{blue}{{b}^{3}}, \mathsf{fma}\left(b \cdot b, 4, -1\right)\right) \]
    5. Step-by-step derivation
      1. fma-udef55.7%

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

        \[\leadsto \mathsf{hypot}\left(a, b\right) \cdot {b}^{3} + \color{blue}{\left(\left(b \cdot b\right) \cdot 4 + -1\right)} \]
      3. associate-+r+55.7%

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

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

        \[\leadsto \mathsf{fma}\left(\mathsf{hypot}\left(a, b\right), {b}^{3}, \color{blue}{b \cdot \left(b \cdot 4\right)}\right) + -1 \]
    6. Applied egg-rr55.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{hypot}\left(a, b\right), {b}^{3}, b \cdot \left(b \cdot 4\right)\right) + -1} \]
    7. Step-by-step derivation
      1. fma-udef55.7%

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

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

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

        \[\leadsto \left(\color{blue}{\mathsf{hypot}\left(b, a\right)} \cdot {b}^{3} + b \cdot \left(b \cdot 4\right)\right) + -1 \]
    8. Applied egg-rr55.7%

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

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

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

        \[\leadsto \color{blue}{\left(b \cdot b\right) \cdot 4} + -1 \]
      3. associate-*r*53.8%

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

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

    if 7.8000000000000002e-156 < a < 8.49999999999999986e-108

    1. Initial program 99.6%

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

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

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

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

        \[\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. Taylor expanded in b around inf 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \left(b \cdot b\right) \cdot \color{blue}{\left(b \cdot b\right)} \]
      7. distribute-rgt-out99.6%

        \[\leadsto \color{blue}{\left(b \cdot b\right) \cdot \left(4 + b \cdot b\right)} \]
    11. Applied egg-rr99.6%

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

    if 8.49999999999999986e-108 < a < 8

    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. 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 0 79.6%

      \[\leadsto \mathsf{fma}\left(\mathsf{hypot}\left(a, b\right), \color{blue}{{b}^{3}}, \mathsf{fma}\left(b \cdot b, 4, -1\right)\right) \]
    5. Step-by-step derivation
      1. fma-udef79.6%

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

        \[\leadsto \mathsf{hypot}\left(a, b\right) \cdot {b}^{3} + \color{blue}{\left(\left(b \cdot b\right) \cdot 4 + -1\right)} \]
      3. associate-+r+79.6%

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{hypot}\left(a, b\right), {b}^{3}, b \cdot \left(b \cdot 4\right)\right) + -1} \]
    7. Step-by-step derivation
      1. fma-udef79.6%

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

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

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

        \[\leadsto \left(\color{blue}{\mathsf{hypot}\left(b, a\right)} \cdot {b}^{3} + b \cdot \left(b \cdot 4\right)\right) + -1 \]
    8. Applied egg-rr79.6%

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

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

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

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

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

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

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

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

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

    if 8 < 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 \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.8%

        \[\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. Taylor expanded in a around inf 89.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq 7.8 \cdot 10^{-156}:\\ \;\;\;\;-1 + b \cdot \left(b \cdot 4\right)\\ \mathbf{elif}\;a \leq 8.5 \cdot 10^{-108}:\\ \;\;\;\;\left(b \cdot b\right) \cdot \left(4 + b \cdot b\right)\\ \mathbf{elif}\;a \leq 8:\\ \;\;\;\;-1 + \left(b \cdot b\right) \cdot \left(4 + a \cdot b\right)\\ \mathbf{else}:\\ \;\;\;\;{a}^{4}\\ \end{array} \]

Alternative 9: 94.0% accurate, 1.1× speedup?

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

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

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


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

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

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

    if 0.0050000000000000001 < (*.f64 b b)

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

        \[\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. Taylor expanded in b around inf 96.6%

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

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

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

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

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

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

        \[\leadsto {b}^{4} + 4 \cdot \color{blue}{\left(b \cdot b\right)} \]
    9. Simplified90.9%

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

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

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

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

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

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

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \left(b \cdot b\right) \cdot \color{blue}{\left(b \cdot b\right)} \]
      7. distribute-rgt-out90.8%

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

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

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

Alternative 10: 55.6% accurate, 8.9× speedup?

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

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

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


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

    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 a around 0 28.6%

      \[\leadsto \mathsf{fma}\left(\mathsf{hypot}\left(a, b\right), \color{blue}{{b}^{3}}, \mathsf{fma}\left(b \cdot b, 4, -1\right)\right) \]
    5. Step-by-step derivation
      1. fma-udef28.6%

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

        \[\leadsto \mathsf{hypot}\left(a, b\right) \cdot {b}^{3} + \color{blue}{\left(\left(b \cdot b\right) \cdot 4 + -1\right)} \]
      3. associate-+r+28.6%

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{hypot}\left(a, b\right), {b}^{3}, b \cdot \left(b \cdot 4\right)\right) + -1} \]
    7. Step-by-step derivation
      1. fma-udef28.6%

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

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

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

        \[\leadsto \left(\color{blue}{\mathsf{hypot}\left(b, a\right)} \cdot {b}^{3} + b \cdot \left(b \cdot 4\right)\right) + -1 \]
    8. Applied egg-rr28.6%

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

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

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

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

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

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

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

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

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

    if 1.21999999999999997 < 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. 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*100.0%

        \[\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. Taylor expanded in b around inf 97.5%

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

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

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

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

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

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

        \[\leadsto {b}^{4} + 4 \cdot \color{blue}{\left(b \cdot b\right)} \]
    9. Simplified90.7%

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

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

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

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

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

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

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \left(b \cdot b\right) \cdot \color{blue}{\left(b \cdot b\right)} \]
      7. distribute-rgt-out90.6%

        \[\leadsto \color{blue}{\left(b \cdot b\right) \cdot \left(4 + b \cdot b\right)} \]
    11. Applied egg-rr90.6%

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

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

Alternative 11: 59.1% accurate, 10.5× speedup?

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

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

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


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

    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 a around 0 28.6%

      \[\leadsto \mathsf{fma}\left(\mathsf{hypot}\left(a, b\right), \color{blue}{{b}^{3}}, \mathsf{fma}\left(b \cdot b, 4, -1\right)\right) \]
    5. Step-by-step derivation
      1. fma-udef28.6%

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

        \[\leadsto \mathsf{hypot}\left(a, b\right) \cdot {b}^{3} + \color{blue}{\left(\left(b \cdot b\right) \cdot 4 + -1\right)} \]
      3. associate-+r+28.6%

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{hypot}\left(a, b\right), {b}^{3}, b \cdot \left(b \cdot 4\right)\right) + -1} \]
    7. Step-by-step derivation
      1. fma-udef28.6%

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

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

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

        \[\leadsto \left(\color{blue}{\mathsf{hypot}\left(b, a\right)} \cdot {b}^{3} + b \cdot \left(b \cdot 4\right)\right) + -1 \]
    8. Applied egg-rr28.6%

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

      \[\leadsto \color{blue}{4 \cdot {b}^{2}} + -1 \]
    10. Step-by-step derivation
      1. unpow244.1%

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

        \[\leadsto \color{blue}{\left(b \cdot b\right) \cdot 4} + -1 \]
      3. associate-*r*44.1%

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

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

    if 0.0570000000000000021 < 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. 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*100.0%

        \[\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. Taylor expanded in b around inf 97.5%

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

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

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

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

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

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

        \[\leadsto {b}^{4} + 4 \cdot \color{blue}{\left(b \cdot b\right)} \]
    9. Simplified90.7%

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

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

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

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

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

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

        \[\leadsto 4 \cdot \left(b \cdot b\right) + \left(b \cdot b\right) \cdot \color{blue}{\left(b \cdot b\right)} \]
      7. distribute-rgt-out90.6%

        \[\leadsto \color{blue}{\left(b \cdot b\right) \cdot \left(4 + b \cdot b\right)} \]
    11. Applied egg-rr90.6%

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

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

Alternative 12: 37.1% accurate, 16.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b \leq 0.057:\\
\;\;\;\;-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.0570000000000000021

    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 a around 0 28.6%

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

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

    if 0.0570000000000000021 < 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. 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*100.0%

        \[\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. Taylor expanded in b around inf 97.5%

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

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

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

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

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

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

        \[\leadsto {b}^{4} + 4 \cdot \color{blue}{\left(b \cdot b\right)} \]
    9. Simplified90.7%

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

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

        \[\leadsto 4 \cdot \color{blue}{\left(b \cdot b\right)} \]
    12. Simplified54.1%

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

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

Alternative 13: 50.5% accurate, 16.6× speedup?

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

\\
-1 + b \cdot \left(b \cdot 4\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 \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.9%

      \[\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 a around 0 47.5%

    \[\leadsto \mathsf{fma}\left(\mathsf{hypot}\left(a, b\right), \color{blue}{{b}^{3}}, \mathsf{fma}\left(b \cdot b, 4, -1\right)\right) \]
  5. Step-by-step derivation
    1. fma-udef47.5%

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

      \[\leadsto \mathsf{hypot}\left(a, b\right) \cdot {b}^{3} + \color{blue}{\left(\left(b \cdot b\right) \cdot 4 + -1\right)} \]
    3. associate-+r+47.5%

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

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

      \[\leadsto \mathsf{fma}\left(\mathsf{hypot}\left(a, b\right), {b}^{3}, \color{blue}{b \cdot \left(b \cdot 4\right)}\right) + -1 \]
  6. Applied egg-rr47.5%

    \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{hypot}\left(a, b\right), {b}^{3}, b \cdot \left(b \cdot 4\right)\right) + -1} \]
  7. Step-by-step derivation
    1. fma-udef47.5%

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

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

      \[\leadsto \left(\sqrt{\color{blue}{b \cdot b + a \cdot a}} \cdot {b}^{3} + b \cdot \left(b \cdot 4\right)\right) + -1 \]
    4. hypot-def47.5%

      \[\leadsto \left(\color{blue}{\mathsf{hypot}\left(b, a\right)} \cdot {b}^{3} + b \cdot \left(b \cdot 4\right)\right) + -1 \]
  8. Applied egg-rr47.5%

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

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

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

      \[\leadsto \color{blue}{\left(b \cdot b\right) \cdot 4} + -1 \]
    3. associate-*r*46.8%

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

    \[\leadsto \color{blue}{b \cdot \left(b \cdot 4\right)} + -1 \]
  12. Final simplification46.8%

    \[\leadsto -1 + b \cdot \left(b \cdot 4\right) \]

Alternative 14: 24.6% 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. 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 \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.9%

      \[\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 a around 0 47.5%

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

    \[\leadsto \color{blue}{-1} \]
  6. Final simplification21.2%

    \[\leadsto -1 \]

Reproduce

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